SDK Params
fillOrKillParams
The fillOrKillParams
object sets two different types of slippage protection when initiating a swap.
- minimum accepted price This protects the swapper against price changes between a quote and the execution of a swap by setting a minimum accepted price. If the minimum price cannot be met with the available liquidity during the specified number of blocks, deposited assets will be refunded to the specified refund address.
- live price protection This protects the swapper from getting an execution price that significantly deviates from the global index price of the asset (as determined by an oracle) ensuring the LPs are offering competitive pricing. Similar to other slippage settings, the execution of the swap will be paused until an LP offers a price that is within the specified deviation or the swap deadline is reached - in which case the swap will be refunded. This setting is especially useful during longer DCA swaps where the price of the asset is moving in favor of the swapper. i.e the slippage tolerance will “follow” the global price of the asset. In case the price moves against the swapper, it will still execute as long as the execution price is above the minimum accepted price.
Param | Description | Data type |
---|---|---|
slippageTolerancePercent | The percent of slippage that is acceptable for the swap. The estimatedPrice field from the quote is used to calculate the minimum price for the channel. This field must be left out when specifying a minPrice . | string |
minPrice | Minimum accepted price for swaps triggered through the deposit channel. This field must be left out when specifying a slippageTolerancePercent . | string |
livePriceSlippageTolerancePercent (optional) | The percentage of deviation from the global index price that is acceptable for the swap to execute. If the deviation is exceeded, the swap will be refunded to the specified refund address. If not set, the default value from the quote will be used. Set the value to false to disable live price protection. If the quote does not have a recommended live price slippage tolerance, this setting is not available for the asset pair and should not be set. | string false undefined |
refundAddress | Address on the source chain to which the refund will be sent, if the minimum price cannot be met. | string |
retryDurationBlocks | Number of State Chain blocks after which a deposit is refunded, if the minimum price cannot be met. One State Chain block corresponds to 6 seconds. | number |
Slippage tolerance can be specified by using the slippageTolerancePercent
property. slippageTolerancePercent
must be a number between 0 and 100. This
percent is used together with the estimatedPrice
of the quote to calculate a
minimum accepted swap price:
const minimumPrice =
quote.estimatedPrice * (1 - Number(slippageTolerancePercent) / 100);
Alternatively, you can manually provide a minPrice
value. The minimum price is
the ratio between the human readable destination amount and the human readable
source amount, e.g. 3500
for a swap from ETH to USDC if you want to receive
at least 3500
USDC per ETH after fees.
Live price slippage can be specified by using the livePriceSlippageTolerancePercent
property. It must be a number between 0 and 100. The default behavior is to use the recommended
value from the quote but can be overridden or set to false
to disable live price protection.
If the quote does not have a recommended live price slippage tolerance, this setting is not
available for the asset pair and should not be set.
If either of the slippage tolerance properties are invalidated, the swap will be refunded to the specified refund address. Refunds are subject to a broadcast fee on the source chain to pay for the transactions sent by the Chainflip protocol. The boost or deposit fee paid will not not be refunded.
Slippage tolerance is applied relative to the quoted price unlike live price slippage which is applied relative to the global index price. Prices are checked on the AMM level and do not include deposit or broadcast fees.
Example
const fillOrKillParams = {
refundAddress: "0xa56A6be23b6Cf39D9448FF6e897C29c41c8fbDFF", // address to which assets are refunded
retryDurationBlocks: 100, // 100 blocks * 6 seconds = 10 minutes before deposits are refunded
slippageTolerancePercent: quote.recommendedSlippageTolerancePercent, // use recommended slippage tolerance from quote
livePriceSlippageTolerancePercent:
quote.recommendedLivePriceSlippageTolerancePercent, // use recommended live price slippage tolerance from quote
};
ccmParams
The Cross-Chain Messaging optional ccmParams
object enables to pass a Cross-Chain Message
to a receiver contract/program on the destination chain.
Param | Description | Data type |
---|---|---|
message (required) | Message (bytes) that is passed to the destination address on the destination chain. | string |
gasBudget (required) | Gas budget for the call on the destination chain. This amount is the amount of gas or compute units required by the user logic on the destination chain. | number |
ccmAdditionalData (optional) | Additional bytes required for the CCM call on the destination chain. This is required for Solana to pass the accounts that are required for the call. | string |
Example
const ccmParams = {
message: "0xdeadc0de",
gasBudget: 250_000,
};