Skip to content

Conversation

@fusmanii
Copy link
Contributor

@fusmanii fusmanii commented Dec 12, 2025

Added support for:

  • any token -> PERP, not just -> SPOT
  • account creation on the fly from user funds

@fusmanii fusmanii marked this pull request as ready for review December 15, 2025 17:20
Signed-off-by: Faisal Usmani <[email protected]>
Signed-off-by: Faisal Usmani <[email protected]>
@fusmanii fusmanii requested a review from tbwebb22 December 15, 2025 19:27
fusmanii and others added 6 commits December 16, 2025 16:30
Signed-off-by: Faisal Usmani <[email protected]>
Signed-off-by: Faisal Usmani <[email protected]>
Signed-off-by: Faisal Usmani <[email protected]>
Signed-off-by: Faisal Usmani <[email protected]>
* plan out the code

Signed-off-by: Ihor Farion <[email protected]>

* dst side impl

Signed-off-by: Ihor Farion <[email protected]>

* remove redundant var

Signed-off-by: Ihor Farion <[email protected]>

* add account creation mode to encoded / decoded data

Signed-off-by: Ihor Farion <[email protected]>

* fix tests and build

Signed-off-by: Ihor Farion <[email protected]>

---------

Signed-off-by: Ihor Farion <[email protected]>
uint64 accountActivationFeeCore;
if (!userAccountExists) {
if (params.accountCreationMode == AccountCreationMode.Standard) {
if (!HyperCoreLib.coreUserExists(params.finalRecipient)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why repeated call and userAccountExists=false in this branch already

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, great call, thank you!

For standard mode, I just copied the existing logic and didn't update it based on the new outter if I added. Fixed in 2e5bb7e

bool userAccountExists = HyperCoreLib.coreUserExists(params.finalRecipient);
if (!userAccountExists) {
if (params.accountCreationMode == AccountCreationMode.Standard) {
if (!HyperCoreLib.coreUserExists(params.finalRecipient)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

userAccountExists=false in this branch already

@grasphoper grasphoper changed the title feat: Perp destination dex support feat: transfer into Perp + account creation on the fly support Dec 18, 2025
@grasphoper grasphoper changed the title feat: transfer into Perp + account creation on the fly support feat: audit follow up Dec 18, 2025
@fusmanii fusmanii added do not merge do not merge need to audit This PR needs to be audited externally before deploying labels Dec 18, 2025
Comment on lines 612 to 634
bool userAccountExists = HyperCoreLib.coreUserExists(params.finalRecipient);
if (!userAccountExists) {
if (params.accountCreationMode == AccountCreationMode.Standard) {
if (params.maxBpsToSponsor > 0) {
revert AccountNotActivatedError(params.finalRecipient);
} else {
emit AccountNotActivated(params.quoteNonce, params.finalRecipient);
params.finalToken = initialToken;
_fallbackHyperEVMFlow(params);
return;
}
} else {
// In the FromUserFunds logic for the swap flow, we only allow account creation if the final token is
// usable for it. Finilazing the swap flow should handle account creation automatically when doing the
// final transfer of tokens to the user
if (!finalCoreTokenInfo.canBeUsedForAccountActivation) {
emit AccountNotActivated(params.quoteNonce, params.finalRecipient);
params.finalToken = initialToken;
_fallbackHyperEVMFlow(params);
return;
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also this could be simplified to something like:

if (!HyperCoreLib.coreUserExists(params.finalRecipient)) {
    bool isStandard = params.accountCreationMode == AccountCreationMode.Standard;
    
    if (isStandard && params.maxBpsToSponsor > 0) {
        revert AccountNotActivatedError(params.finalRecipient);
    }
    
    // Fall back unless FromUserFunds mode with an eligible activation token
    if (isStandard || !finalCoreTokenInfo.canBeUsedForAccountActivation) {
        emit AccountNotActivated(params.quoteNonce, params.finalRecipient);
        params.finalToken = initialToken;
        _fallbackHyperEVMFlow(params);
        return;
    }
}

Comment on lines 517 to 520
if (!coreTokenInfo.canBeUsedForAccountActivation) {
_fallbackHyperEVMFlow(params);
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to emit the AccountNotActivated event here?
If so, we could probably simplify this in a similar way to my other comment

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added events in 2c97a95

Looking into simplification

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not merge do not merge need to audit This PR needs to be audited externally before deploying

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants