Contracts

Here is the Contract Application Binary Interface (ABI) of Mayan Swap Bridge.

In the below table you can find the deployed contract addresses of Swap Bridge:

Swap From EVM

If the input token is not the native currency of network, to initiate a swap we need to first approve the Swap Bridge to spend that token on our behalf

tokenContract.approve(swapBridgeAddress, amountIn);

Then we can call the swap function:

function swap(
    RelayerFees memory relayerFees,
    Recepient memory recipient,
    bytes32 tokenOutAddr,
    uint16 tokenOutChainId,
    Criteria memory criteria,
    address tokenIn,
    uint256 amountIn
) public payable returns (uint64 sequence)

In case the input token is the native currency of network you have to call the wrapAndSwapETH function:

function wrapAndSwapETH(
    RelayerFees memory relayerFees,
    Recepient memory recipient,
    bytes32 tokenOutAddr,
    uint16 tokenOutChainId,
    Criteria memory criteria
) public payable returns (uint64 sequence)

We are going over each parameter and understand what they mean:

RelayerFees:

struct RelayerFees {
    uint64 swapFee;
    uint64 redeemFee;
    uint64 refundFee;
}

relayerFees is a struct that contains the fees that user is willing to pay to relayers for transfering and committing VAA messages into blockchains, to get a fair value and ensure that relayer will transfer we can use Quote API

Recepient:

struct Recepient {
    bytes32 mayanAddr;
    uint16 mayanChainId;
    bytes32 auctionAddr;
    bytes32 destAddr;
    uint16 destChainId;
    bytes32 referrer;
    bytes32 refundAddr;
}

recepient is a struct that holds the info about the destination.

mayanAddr is ATA of main state PDA of Mayan program for the output token. Here is a sample js code to calculate mayanAddr for a given output token mint address (mintAddr):

import { PublicKey } from '@solana/web3.js';
import { getAssociatedTokenAddress } from '@solana/spl-token';

const [mayanMainAccount] = await PublicKey.findProgramAddress([Buffer.from('MAIN')], mayanProgramAddr);
const mayanAddr = await getAssociatedTokenAddress(mintAddr, mayanMainAccount, true);

mayanChainId: field must be set to 1 which is wormhole chainId of Wormhole

auctionAddr is auction program address of Mayan: 4U6MNAMRbYeTD4HumavhJ1ah9NQ5pNPhTNxcFdeybXFy destAddr field is the address of user's destination wallet.

destChainId is the Wormhole chain id of user's destination wallet.

tokenOutAddr: origin address of input token

tokenOutChain: origin Wormhole chain of output token

Criteria:

struct Criteria {
    uint256 transferDeadline;
    uint64 swapDeadline;
    uint64 amountOutMin;
    bool unwrap;
    uint64 gasDrop;
    bytes customPayload;
}

transferDeadline is the timestamp (in seconds) that shows the deadline of transaction on EVM and it must be based on EVM clock.

swapDeadline is the timestamp (in seconds) that shows deadline of swap on Solana and therefore it should be based on Solana clock. You can read the Solona clock from the clock account (SysvarC1ock11111111111111111111111111111111) using Solana web3 package. Or you can use this API. amountOutMin shows the minimum acceptable amount of output token after slippage (this is the starting price in auction). unwrap In case the output token is the native token of destination chain this boolean determines if the output token should be unwrapped.

gasDrop: the amount of native token that must be dropped into destination wallet.

tokenIn: Contract address of input token.

amountIn: Amount of input token.

Last updated