Swap

1. Standard Swap (Without Partner)

1.1 Using Router Contract

Location: dlmm_router::swap module

swap_a2b

Swap Coin A to Coin B.

public fun swap_a2b<CoinTypeA, CoinTypeB>(
    pool: &mut Pool<CoinTypeA, CoinTypeB>,
    coin_a: &mut Coin<CoinTypeA>,
    by_amount_in: bool,
    amount: u64,
    amount_limit: u64,
    config: &GlobalConfig,
    versioned: &Versioned,
    clock: &Clock,
    ctx: &mut TxContext,
)

swap_b2a

Swap Coin B to Coin A.

Parameters

Parameter
Type
Description

pool

&mut Pool

Pool object (mutable)

coin_a / coin_b

&mut Coin

Input coin object

by_amount_in

bool

true: fix input amount, false: fix output amount

amount

u64

If by_amount_in=true: input amount; else: output amount

amount_limit

u64

If by_amount_in=true: min output; else: max input

config

&GlobalConfig

Global config for validations

versioned

&Versioned

Versioned object for version checking

clock

&Clock

Clock object (0x6)

1.2 Build Custom Swap (Using Flash Swap)


2. Partner Swap (With Referral Fee)

Partners can earn referral fees by using partner-specific swap functions. See Partner Integration Guidearrow-up-right for complete partner setup.

2.1 Using Router Contract

Location: dlmm_router::swap module

swap_a2b_with_partner

swap_b2a_with_partner

Additional Parameter

Parameter
Type
Description

partner

&mut Partner

Partner object (shared, mutable)

Other parameters are the same as standard swap.

2.2 Build Custom Swap with Partner (Using Flash Swap)

2.3 Key Differences from Standard Swap

Aspect
Standard Swap
Partner Swap

Function

flash_swap / repay_flash_swap

flash_swap_with_partner / repay_flash_swap_with_partner

Partner param

Not required

Required (&mut Partner)

Referral fee

None

Calculated and deposited to partner

Fee collection

N/A

Partner must manually claim

Related Documentation


Last updated