Request Deposit Address
Chainflip allows to open a deposit channel for a given set of swap details. This deposit channel is assigned to a unique address on the source chain of the swap and allows users to initiate the swap by sending the source asset to this address. Deposit channels expire after a fixed period of time (24hs).
Learn more about deposit channels in the Deposit Channels & Brokers documentation.
Once a deposit channel is open, the user can send the funds from any wallet to its deposit address to initiate the swap process. No need to connect a wallet.
Compared to vault swaps, using deposit channels can be cheaper for the user because it doesn't require token approvals.
requestDepositAddressV2
Requests a deposit address for the given DepositAddressRequestV2
.
This method uses the broker_request_swap_deposit_address
RPC method of the configured Broker API
to open a deposit channel.
function requestDepositAddressV2(depositAddressRequest: DepositAddressRequestV2): Promise<DepositAddressResponse>
type DepositAddressRequestV2 = {
quote: Quote;
destAddress: string;
fillOrKillParams: {
retryDurationBlocks: number,
refundAddress: string,
slippageTolerancePercent: number;
};
srcAddress?: string;
brokerCommissionBps?: number;
affiliateBrokers?: {
account: `cF${string}` | `0x${string}`;
commissionBps: number
}[];
ccmParams?: {
gasBudget: string,
message: string,
additionalData?: string,
};
};
The depositAddressRequest
object describes the swap for which a deposit address is requested.
Param | Description | Data type |
---|---|---|
quote (required) | The object returned by getQuoteV2 . This object will be used to set the input and output assets, the DCA parameters (if it is a DCA quote), and the boost parameters (if it is a boost quote). | Quote |
destAddress (required) | Address where the swapped tokens will be sent to on the destination chain. | string |
fillOrKillParams (required) | Parameters to set a minimum accepted price. This allows to protect against price changes between a quote and the execution of a swap (also known as slippage protection). | Object |
brokerCommissionBps (optional) | Commission charged by the broker creating the channel, in basis points. This option is only available when the SDK is initialized with a brokerUrl | number |
affiliateBrokers (optional) | An array of objects defining affiliate accounts that take a commission in addition to brokerCommissionBps . This option is only available when the SDK is initialized with a brokerUrl | Array |
ccmParams (optional) | Optional parameters for passing a message to a reciever contract/program on the destination chain. | Object |
Result type
type DepositAddressRequestV2 = {
srcChain: Chain;
srcAsset: Asset;
destChain: Chain;
destAsset: Asset;
amount: string;
destAddress: string;
ccmParams?: {
gasBudget: string,
message: string,
additionalData?: string,
};
maxBoostFeeBps?: number;
srcAddress?: string;
dcaParams?: {
numberOfChunks: number,
chunkIntervalBlocks: number,
};
fillOrKillParams: {
retryDurationBlocks: number,
refundAddress: string,
slippageTolerancePercent: number;
};
depositChannelId: string;
depositAddress: string;
brokerCommissionBps: number;
affiliateBrokers?: {
account: `cF${string}` | `0x${string}`;
commissionBps: number
}[];
depositChannelExpiryBlock: bigint;
estimatedDepositChannelExpiryTime: number | undefined;
channelOpeningFee: bigint;
};
Configure your Broker API
If you want to earn broker fees or use affiliates, you need to run your own Broker API. You can configure the URL of your Broker API when initializing the SDK.
import { SwapSDK } from '@chainflip/sdk/swap';
const sdk = new SDK({
network: 'perseverance',
broker: { url: 'https://my.broker.io' },
});
Example
Regular Deposit Address
import { Chains, Assets } from "@chainflip/sdk/swap";
const { quotes } = await swapSDK.getQuoteV2({
srcChain: Chains.Ethereum,
srcAsset: Assets.ETH,
destChain: Chains.Bitcoin,
destAsset: Assets.BTC,
amount: (1.5e18).toString(), // 1.5 ETH
});
const quote = quotes.find((quote) => quote.type === 'REGULAR');
const swapDepositAddressRequest = {
quote,
destAddress: 'bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq',
fillOrKillParams: {
slippageTolerancePercent: quote.recommendedSlippageTolerancePercent, // use recommended slippage tolerance from quote
refundAddress: '0xa56A6be23b6Cf39D9448FF6e897C29c41c8fbDFF', // address to which assets are refunded
retryDurationBlocks: 100, // 100 blocks * 6 seconds = 10 minutes before deposits are refunded
},
brokerCommissionBps: 100, // 100 basis point = 1%
affiliateBrokers: [
{ account: 'cFM8kRvLBXagj6ZXvrt7wCM4jGmHvb5842jTtXXg3mRHjrvKy', commissionBps: 50 },
], // total commission 150 bps = 1.5%
};
console.log(await swapSDK.requestDepositAddressV2(swapDepositAddressRequest));
// console output:
{
srcAsset: 'ETH',
srcChain: 'Ethereum',
destAsset: 'BTC',
destChain: 'Bitcoin',
srcAddress: undefined,
destAddress: 'bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq',
dcaParams: undefined,
fillOrKillParams: {
slippageTolerancePercent: 0.5,
refundAddress: '0xa56A6be23b6Cf39D9448FF6e897C29c41c8fbDFF',
retryDurationBlocks: 100
},
maxBoostFeeBps: 0,
ccmParams: undefined,
amount: '1500000000000000000', // 1.5 ETH
depositChannelId: '6739624-Ethereum-2562', // Identifies the deposit channel for this swap
depositAddress: '0x6284c66ebf4110ae3cc4da45fb9b1c2143417092', // Address where funds need to be deposited to start the swap
brokerCommissionBps: 100,
affiliateBrokers: [
{ account: 'cFM8kRvLBXagj6ZXvrt7wCM4jGmHvb5842jTtXXg3mRHjrvKy', commissionBps: 50 }
],
depositChannelExpiryBlock: 21930372n,
estimatedDepositChannelExpiryTime: 1630000000, // Estimated expiry time of the deposit channel
channelOpeningFee: 0n
}
Boostable Deposit Address
Check the Introduction to Boost section for more information about the Boost feature.
import { Chains, Assets } from "@chainflip/sdk/swap";
const { quotes } = await swapSDK.getQuoteV2({
srcChain: Chains.Bitcoin,
srcAsset: Assets.BTC,
destChain: Chains.Ethereum,
destAsset: Assets.ETH,
amount: (1.5e8).toString(), // 1.5 BTC
});
const quote = quotes.find((quote) => quote.type === 'REGULAR');
const swapDepositAddressRequest = {
// `boostQuote` may be undefined depending on asset and liquidity conditions
quote: quote.boostQuote,
destAddress: "0xa56A6be23b6Cf39D9448FF6e897C29c41c8fbDFF",
fillOrKillParams: {
slippageTolerancePercent: quote.recommendedSlippageTolerancePercent,
refundAddress: 'bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq',
retryDurationBlocks: 100,
},
};
console.log(await swapSDK.requestDepositAddressV2(swapDepositAddressRequest));
DCA deposit address
Check the Dollar Cost Average section for more information about the DCA feature.
import { Chains, Assets } from "@chainflip/sdk/swap";
const { quotes } = await swapSDK.getQuoteV2({
srcChain: Chains.Ethereum,
srcAsset: Assets.ETH,
destChain: Chains.Bitcoin,
destAsset: Assets.BTC,
amount: (1.5e18).toString(), // 1.5 ETH
});
// ❗ the DCA feature must be enabled when the SDK is instantiated to receive DCA quotes ❗
const quote = quotes.find((quote) => quote.type === 'DCA');
const swapDepositAddressRequest = {
quote,
destAddress: "bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq",
brokerCommissionBps: 100,
fillOrKillParams: {
slippageTolerancePercent: quote.recommendedSlippageTolerancePercent,
refundAddress: '0xa56A6be23b6Cf39D9448FF6e897C29c41c8fbDFF',
retryDurationBlocks: 100,
},
};
console.log(await swapSDK.requestDepositAddressV2(swapDepositAddressRequest));