|
|
@@ -127,12 +127,15 @@ async function testCopy() {
|
|
|
const tokenA = calculation.tokenA;
|
|
|
const tokenB = calculation.tokenB;
|
|
|
const BUFFER_PCT = 1.2;
|
|
|
- const prices = await swapper.getTokenPrices([tokenA.address, tokenB.address]);
|
|
|
|
|
|
const needSwapUsd = async (token, valueUsd) => {
|
|
|
const requiredWithBuffer = valueUsd * BUFFER_PCT;
|
|
|
const balance = await swapper.getTokenBalance(token.address);
|
|
|
- const price = prices[token.address]?.price ?? 0;
|
|
|
+ const price = parseFloat(token.priceUsd) || 0;
|
|
|
+ if (price <= 0) {
|
|
|
+ console.log(` Warning: Token ${token.symbol || token.address} priceUsd is ${token.priceUsd}, will swap full amount`);
|
|
|
+ return { skip: false, swapUsd: requiredWithBuffer, currentValueUsd: 0, requiredWithBuffer };
|
|
|
+ }
|
|
|
const currentValueUsd = balance * price;
|
|
|
if (currentValueUsd >= requiredWithBuffer) {
|
|
|
return { skip: true, currentValueUsd, requiredWithBuffer };
|