Function: initialize
Simply initializes SwapEndpointDataAccount to default values.
Accounts
swap_endpoint_data_accountValidation: Account being initialized — no validation required.
Impact: N/A.
signerValidation: Account is signer.
Impact: N/A.
Instruction parameters
N/A.
Function: x_swap_native
This function does the following:
Checks that the number of open event accounts is larger than the maximum-allowed event accounts
Adds the event-account pubkey to the list of open event accounts
Transfers lamports from the signer to the aggregate key account
Updates the event-data account with the params
Accounts
data_accountValidation: Account owner and discriminator are checked. Checked if swaps are suspended.
Impact: N/A.
agg_keyValidation: Key validated through
data_account.Impact: Lamports from the native swap are sent to this account.
fromValidation: Account is a signer.
Impact: Lamports are sent from this account.
event_data_accountValidation: Newly initialized account — no validation required.
Impact: Stores data for the swap.
swap_endpoint_data_accountValidation: Account owner and discriminator are checked.
Impact: Stores the pubkey for the event-data account.
Instruction parameters
swap_native_paramsThe
amountanddecimalsvalues in the structure are used to transfer lamports from the signer.The amount is checked to be larger than the minimum native swap amount.
The remaining values are stored in the event-data account, and no validation is performed.
Function: x_swap_token
This function does the following:
Checks that the number of open event accounts is larger than the maximum-allowed event accounts
Adds the event-account pubkey to the list of open event accounts
Transfers lamports from the signer to the aggregate key account
Updates the event-data account with the params
Accounts
data_accountValidation: Account owner and discriminator are checked. Checked if swaps are suspended.
Impact: N/A.
agg_keyValidation: Key validated through
data_account.Impact: Lamports from the native swap are sent to this account.
fromValidation: Account is a signer.
Impact: Lamports are sent from this account.
event_data_accountValidation: Newly initialized account — no validation required.
Impact: Stores data for the swap.
swap_endpoint_data_accountValidation: Account owner and discriminator are checked.
Impact: Stores the pubkey for the event-data account.
Instruction parameters
x_swap_tokenThe
amountanddecimalsvalues in the structure are used to transfer lamports from the signer.The amount is checked to be larger than the minimum native swap amount.
The remaining values are stored in the event-data account, and no validation is performed.
Function: x_swap_token
This function does the following:
Checks the mint from the
SupportedTokenaccountChecks that the number of open event accounts is larger than the maximum-allowed event accounts
Adds the event-account pubkey to the list of open event accounts
Transfers tokens from the user to the token vault
Updates the event-data account with the params
Accounts
data_accountValidation: Account owner and discriminator are checked. Checked if swaps are suspended.
Impact: N/A.
token_vault_associated_token_accountValidation: Checked to be the correct ATA through the mint and authority from the data account.
Impact: Tokens to swap are transferred to this token account.
fromValidation: Account is a signer.
Impact: Signer for the token account.
from_token_accountValidation: Account checked to be owned by the signer.
Impact: Tokens to be swapped are sent from this token account.
event_data_accountValidation: Newly initialized account — no validation required.
Impact: Stores data for the swap.
swap_endpoint_data_accountValidation: Account owner and discriminator are checked.
Impact: Stores the pubkey for the event-data account.
token_supported_accountValidation: Account owner and discriminator are checked.
Impact: Used to check if the token swapped from is supported.
mintValidation: Mint is checked within the instruction logic.
Impact: N/A.
Instruction parameters
swap_native_paramsThe
amountanddecimalsvalues in the structure are used to transfer lamports from the signer.The amount is checked to be larger than the minimum native swap amount.
The remaining values are stored in the event data account, and no validation is performed.
close_event_accounts
This function does the following:
Iterates through the remaining accounts to fetch
SwapEventaccounts and payee accountsChecks that both accounts are writable
Tries to deserialize the event account but emits a failure in case of failed deserialization due to a reorg
Checks that the payee key is equal to
event_account.senderCloses the event account and refunds the rent to the original payee
Gets the index for the event account key from
swap_endpoint_data_accountDeletes the index from
swap_endpoint_data_accountComputes the new size by subtracting the pubkey size
Verifies that the new size is larger or equal to the minimum size
Reallocates
swap_endpoint_data_accountwith the new size and transfers the rent difference to the original payee
Accounts
data_accountValidation: Account owner and discriminator are checked. Checked if swaps are suspended.
Impact: N/A.
agg_keyValidation: Key validated through
data_account.Impact: N/A.
swap_endpoint_data_accountValidation: Account owner and discriminator are checked.
Impact: Used to check if pubkeys for event accounts are valid.
Instruction parameters
N/A.