Swap
The DLMM contract only provides two basic methods for flash swaps: flash_swap and repay_flash_swap. To execute a complete swap operation, developers need to compose these primitive functions together with additional logic, handling the borrowing, trading, and repayment sequences within a single transaction.
1. Using Existing Swap Methods
DLMM Router Contract
Function Parameters
pool: Pool object ID
coin_a: Input Coin object. This method is swap A to B, so input Coin A.
config: Reference to the global config for validations
by_amount_in: Fix input coin amount or output coin amout.
amount: If by_amount_in equals true, it means input amount coin A, else it means output amount coin B.
amount_limit: If by_amount_in equals true, it means the min output amount for coin B , else it means the max amount for coin A.
confg: Reference to the global config for validations
mainnet
0xf31b605d117f959b9730e8c07b08b856cb05143c5e81d5751c90d2979e82f599
testnet
0x88bb33e9eff2fccab980a0e4b43fc4572abd08f08304d47a20d3e4e99d94d159
versioned: Versioned object for version checking
mainnet
0x05370b2d656612dd5759cbe80463de301e3b94a921dfc72dd9daa2ecdeb2d0a8
testnet
0xa710caae87b2129acc97fbb98ea7011e3137c3291b02c0fcce866d67d5d9e8d0
clock: Clock object for timestamp operations. (0x6)
Location
swap module
Contract Code
2. Construct Your Own Swap Method.
Function Parameters
pool : one mutable reference of the pool.
a2b: the swap direction, a2b equals true means sold coin a then get coin b.
by_amount_in: when it equal true means want to fix the amount of input coin. when it equal false means want to fix the amount of output coin.
amount: when by_amount_in equals true, amount means the quantity of input coin, when by_amount_in equals false, amount means the quantity of output coin.
confg: Reference to the global config for validations
networkglobal config object idmainnet
0xf31b605d117f959b9730e8c07b08b856cb05143c5e81d5751c90d2979e82f599
testnet
0x88bb33e9eff2fccab980a0e4b43fc4572abd08f08304d47a20d3e4e99d94d159
versioned: Versioned object for version checking
networkversioned config object idmainnet
0x05370b2d656612dd5759cbe80463de301e3b94a921dfc72dd9daa2ecdeb2d0a8
testnet
0xa710caae87b2129acc97fbb98ea7011e3137c3291b02c0fcce866d67d5d9e8d0
clock: Clock object for timestamp operations. (0x6)
You can implement swaps like the following examples. This is divided into two instances: one with a partner and the other without.
Last updated