@@ -49,7 +49,6 @@ export async function buildUserAddresses(
4949const nobleForwardingModule = 'https://api.noble.xyz/noble/forwarding/v1/address/channel' ;
5050const skipMessagesTimeoutSeconds = '60' ;
5151const dydxNobleChannel = 33 ;
52- const slippageTolerancePercent = config . SKIP_SLIPPAGE_TOLERANCE_PERCENTAGE ;
5352// Grabs the raw skip route data to carry out the bridge on our own.
5453export async function getSkipCallData (
5554 sourceAddress : string ,
@@ -63,7 +62,6 @@ export async function getSkipCallData(
6362 if ( amount . startsWith ( '0x' ) ) {
6463 amountToUse = parseInt ( amount , 16 ) . toString ( ) ;
6564 }
66-
6765 const routeResult = await route ( {
6866 amountIn : amountToUse , // Desired amount in smallest denomination (e.g., uatom)
6967 sourceAssetDenom,
@@ -88,13 +86,6 @@ export async function getSkipCallData(
8886 throw new Error ( 'Failed to find a route' ) ;
8987 }
9088
91- logger . info ( {
92- at : 'skip-helper#getSkipCallData' ,
93- message : 'Route result obtained' ,
94- routeResult,
95- dydxAddress,
96- } ) ;
97-
9889 const userAddresses = await buildUserAddresses (
9990 routeResult . requiredChainAddresses ,
10091 sourceAddress ,
@@ -121,6 +112,9 @@ export async function getSkipCallData(
121112 throw new Error ( 'executeRoute error: invalid address list' ) ;
122113 }
123114
115+ // acceptable slippage is smallest of SKIP_SLIPPAGE_TOLERANCE_USDC (Default $100) divided
116+ // by the estimatedAmountOut or the SKIP_SLIPPAGE_TOLERANCE_PERCENTAGE.
117+ const slippageTolerancePercent = getSlippageTolerancePercent ( routeResult . estimatedAmountOut ) ;
124118 const response = await messages ( {
125119 timeoutSeconds : skipMessagesTimeoutSeconds ,
126120 amountIn : routeResult ?. amountIn ,
@@ -394,3 +388,13 @@ export async function limitAmount(
394388 const maxDepositInUsdc = config . MAXIMUM_BRIDGE_AMOUNT_USDC ;
395389 return min ( [ amountToUse , BigInt ( maxDepositInUsdc * ETH_USDC_QUANTUM ) ] ) ! . toString ( ) ;
396390}
391+
392+ // getSlippageTolerancePercent returns the acceptable slippage is smallest of
393+ // SKIP_SLIPPAGE_TOLERANCE_USDC (Default $100) divided by the estimatedAmountOut
394+ // or the SKIP_SLIPPAGE_TOLERANCE_PERCENTAGE.
395+ export function getSlippageTolerancePercent ( estAmountOut : string ) : string {
396+ return min ( [
397+ ( 100 * ( config . SKIP_SLIPPAGE_TOLERANCE_USDC * ETH_USDC_QUANTUM ) ) / parseInt ( estAmountOut , 10 ) ,
398+ parseFloat ( config . SKIP_SLIPPAGE_TOLERANCE_PERCENTAGE ) ,
399+ ] ) ! . toString ( ) ;
400+ }
0 commit comments