Affiliate fee can be specified by anyone who integrates with DLN API or uses a deSwap widget. The fee is received by the beneficiary at the moment when the market maker unlocks liquidity from the fulfilled trade (usually a few hours after the trade is fulfilled).
Withdrawal
EVM chains
For cross-chain transfers initiated from EVM chains, the affiliate fee is transferred to the beneficiary address automatically in the same transaction where the market maker unlocks liquidity from the fulfilled trade.
Solana
For trades initiated from Solana, the affiliate fee is not transferred automatically and should be claimed by the beneficiary by interacting with the DLN program on Solana. withdrawAffiliateFee the method should be called. Here is how it can be done using DLN Client:
import { Solana } from"@debridge-finance/dln-client"import { Connection, PublicKey, clusterApiUrl } from"@solana/web3.js";functionfindAssociatedTokenAddress(wallet:PublicKey, tokenMint:PublicKey): [PublicKey,number] { return PublicKey.findProgramAddressSync([wallet.toBytes(), new PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA").toBytes(), tokenMint.toBytes()], new PublicKey("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"));
}constsolanaClient=newSolana.DlnClient(newConnection(clusterApiUrl("mainnet-beta")),// better use your own RPCnewPublicKey("src5qyZHqTqecJV4aY6Cb6zDZLMDzrDKKezs22MPHr4"),newPublicKey("dst5MGcFPoBeREFAA5E3tU5ij8m5uVYwkzkSAbsLbNo"),newPublicKey("DEbrdGj3HsRsAzx6uH4MKyREKxVAfBydijLUF3ygsFfh"),newPublicKey("DeSetTwWhjZq6Pz9Kfdo1KoS5NqtsM6G8ERbX4SSCSft"),)typeOrder= { orderId:string; beneficiary:PublicKey; giveToken:PublicKey;}// load order in expected formatconstorder:Order; // order could also be loaded from chain by order creation tx hash// const order = solanaClient.getOrderFromTransaction({ giveChain: ChainId.Solana, txHash: "create tx hash" }, {});// build withdraw txconst tx = await solanaClient.source.withdrawAffiliateFee(order.orderId, order.beneficiary, findAssociatedTokenAddress(order.beneficiary, order.giveToken)[0]);
// send withdraw tx
Withdrawal batch of Solana affiliate fees
You can withdraw fees by using CLI ready script below:
This script gets all transactions with unclaimed fees by beneficiary address, generates claim instructions and packs them into a minimum number of transactions.
How to use:
Install following npm packages: @solana/web3.js, @debridge-finance/solana-utils, @debridge-finance/dln-client, bs58.
Create typescript file and copy script above (e.g. withdrawAffiliateFees.ts).
Run script. You need to pass PrivateKey (base58) for transaction signature as first argument and beneficiary address PubKey (string) as second argument. Optionally you can pass Solana RPC URL as third argument.