@@ -91,6 +91,13 @@ const setPrices = async (options) => {
9191 // Base asset decimals used to scale aggregator quote amounts. Legacy ARM
9292 // configs don't expose baseAssetDecimals as all their assets are 18 decimals.
9393 const baseDecimals = Number ( config . baseAssetDecimals ?? 18 ) ;
94+ const liquidityDecimals = Number (
95+ await new Contract (
96+ liquidityAddress ,
97+ [ "function decimals() view returns (uint8)" ] ,
98+ signer ,
99+ ) . decimals ( ) ,
100+ ) ;
94101
95102 log ( `Getting current ARM prices:` ) ;
96103 log ( `base asset : ${ baseSymbol } ` ) ;
@@ -114,17 +121,6 @@ const setPrices = async (options) => {
114121 ? 10n
115122 : 30n ;
116123
117- // The liquidity asset decimals are not in the base asset config so read
118- // them on-chain. Can differ from the base asset decimals, eg an 18
119- // decimals base asset over a 6 decimals USDC liquidity asset.
120- const liquidityDecimals = Number (
121- await new Contract (
122- liquidityAddress ,
123- [ "function decimals() view returns (uint8)" ] ,
124- signer ,
125- ) . decimals ( ) ,
126- ) ;
127-
128124 // 2.1 Get reference prices
129125 let referencePrices ;
130126 if ( midPrice ) {
@@ -152,8 +148,8 @@ const setPrices = async (options) => {
152148 amount : options . amount ,
153149 liquidityAssets : reserves ?. liquidityAssets ?? reserves ?. [ 0 ] ,
154150 baseAssetReserve : reserves ?. baseAssetReserve ?? reserves ?. [ 1 ] ,
155- buyLiquidity : parseSwapCap ( buyAmount ) ,
156- sellLiquidity : parseSwapCap ( sellAmount ) ,
151+ buyLiquidity : parseSwapCap ( buyAmount , liquidityDecimals ) ,
152+ sellLiquidity : parseSwapCap ( sellAmount , baseDecimals ) ,
157153 liquidityDecimals,
158154 baseDecimals,
159155 } ) ;
@@ -392,8 +388,8 @@ const setPrices = async (options) => {
392388 const toleranceScaled = parseUnits ( tolerance . toString ( ) , 36 - 4 ) ;
393389 log ( `tolerance : ${ formatUnits ( toleranceScaled , 32 ) } basis points` ) ;
394390
395- const targetBuyAmount = parseSwapCap ( buyAmount ) ;
396- const targetSellAmount = parseSwapCap ( sellAmount ) ;
391+ const targetBuyAmount = parseSwapCap ( buyAmount , liquidityDecimals ) ;
392+ const targetSellAmount = parseSwapCap ( sellAmount , baseDecimals ) ;
397393 const swapCapsChanged = haveSwapCapsChanged (
398394 baseContext ,
399395 targetBuyAmount ,
0 commit comments