diff --git a/src/dex/wombat/utils.ts b/src/dex/wombat/utils.ts index 0a7ffffe0..251912cc7 100644 --- a/src/dex/wombat/utils.ts +++ b/src/dex/wombat/utils.ts @@ -43,6 +43,7 @@ function swapQuoteFunc( return 0n; } // int256 D = Ax + Ay - A.wmul((Lx * Lx) / Ax + (Ly * Ly) / Ay); // flattened _invariantFunc + const d = assetX + assetY - diff --git a/src/dex/wombat/wombat-e2e.test.ts b/src/dex/wombat/wombat-e2e.test.ts index 10d5e3039..02fe27be6 100644 --- a/src/dex/wombat/wombat-e2e.test.ts +++ b/src/dex/wombat/wombat-e2e.test.ts @@ -11,128 +11,203 @@ import { Network, ContractMethod, SwapSide } from '../../constants'; import { StaticJsonRpcProvider } from '@ethersproject/providers'; import { generateConfig } from '../../config'; +// function testForNetwork( +// network: Network, +// dexKey: string, +// tokenASymbol: string, +// tokenBSymbol: string, +// tokenAAmount: string, +// tokenBAmount: string, +// nativeTokenAmount: string, +// ) { +// const provider = new StaticJsonRpcProvider( +// generateConfig(network).privateHttpProvider, +// network, +// ); +// const tokens = Tokens[network]; +// const holders = Holders[network]; +// const nativeTokenSymbol = NativeTokenSymbols[network]; +// +// const sideToContractMethods = new Map([ +// [ +// SwapSide.SELL, +// [ +// ContractMethod.simpleSwap, +// // ContractMethod.multiSwap, +// // ContractMethod.megaSwap, +// ], +// ], +// ]); +// +// describe(`${network}`, () => { +// sideToContractMethods.forEach((contractMethods, side) => +// describe(`${side}`, () => { +// contractMethods.forEach((contractMethod: ContractMethod) => { +// describe(`${contractMethod}`, () => { +// it(`${nativeTokenSymbol} -> ${tokenASymbol}`, async () => { +// await testE2E( +// tokens[nativeTokenSymbol], +// tokens[tokenASymbol], +// holders[nativeTokenSymbol], +// side === SwapSide.SELL ? nativeTokenAmount : tokenAAmount, +// side, +// dexKey, +// contractMethod, +// network, +// provider, +// ); +// }); +// it(`${tokenASymbol} -> ${nativeTokenSymbol}`, async () => { +// await testE2E( +// tokens[tokenASymbol], +// tokens[nativeTokenSymbol], +// holders[tokenASymbol], +// side === SwapSide.SELL ? tokenAAmount : nativeTokenAmount, +// side, +// dexKey, +// contractMethod, +// network, +// provider, +// ); +// }); +// it(`${tokenASymbol} -> ${tokenBSymbol}`, async () => { +// await testE2E( +// tokens[tokenASymbol], +// tokens[tokenBSymbol], +// holders[tokenASymbol], +// side === SwapSide.SELL ? tokenAAmount : tokenBAmount, +// side, +// dexKey, +// contractMethod, +// network, +// provider, +// ); +// }); +// }); +// }); +// }), +// ); +// }); +// } -function testForNetwork( - network: Network, - dexKey: string, - tokenASymbol: string, - tokenBSymbol: string, - tokenAAmount: string, - tokenBAmount: string, - nativeTokenAmount: string, -) { - const provider = new StaticJsonRpcProvider( - generateConfig(network).privateHttpProvider, - network, - ); - const tokens = Tokens[network]; - const holders = Holders[network]; - const nativeTokenSymbol = NativeTokenSymbols[network]; +describe('Wombat E2E', () => { + const dexKey = 'Wombat'; + + describe('BSC', () => { + const network = Network.BSC; + const tokens = Tokens[network]; + const holders = Holders[network]; + const provider = new StaticJsonRpcProvider( + generateConfig(network).privateHttpProvider, + network, + ); - const sideToContractMethods = new Map([ - [ - SwapSide.SELL, + const sideToContractMethods = new Map([ + [ + SwapSide.SELL, + [ + ContractMethod.simpleSwap, + // ContractMethod.multiSwap, + // ContractMethod.megaSwap, + ], + ], [ - ContractMethod.simpleSwap, - // ContractMethod.multiSwap, - // ContractMethod.megaSwap, + SwapSide.BUY, + [ + ContractMethod.simpleBuy, + // ContractMethod.buy, + ], ], - ], - ]); + ]); + + const pairs: { name: string; sellAmount: string; buyAmount: string }[][] = + [ + [ + { + name: 'USDC', + sellAmount: '100000000000000000000', + buyAmount: '100000000000000000000', + }, + { + name: 'USDT', + sellAmount: '100000000000000000000', + buyAmount: '100000000000000000000', + }, + ], + [ + { + name: 'BNB', + sellAmount: '1000000000000000000', + buyAmount: '1000000000', + }, + { + name: 'BNBx', + sellAmount: '1000000000', + buyAmount: '1000000000000000000', + }, + ], + ]; - describe(`${network}`, () => { sideToContractMethods.forEach((contractMethods, side) => describe(`${side}`, () => { contractMethods.forEach((contractMethod: ContractMethod) => { - describe(`${contractMethod}`, () => { - it(`${nativeTokenSymbol} -> ${tokenASymbol}`, async () => { - await testE2E( - tokens[nativeTokenSymbol], - tokens[tokenASymbol], - holders[nativeTokenSymbol], - side === SwapSide.SELL ? nativeTokenAmount : tokenAAmount, - side, - dexKey, - contractMethod, - network, - provider, - ); - }); - it(`${tokenASymbol} -> ${nativeTokenSymbol}`, async () => { - await testE2E( - tokens[tokenASymbol], - tokens[nativeTokenSymbol], - holders[tokenASymbol], - side === SwapSide.SELL ? tokenAAmount : nativeTokenAmount, - side, - dexKey, - contractMethod, - network, - provider, - ); - }); - it(`${tokenASymbol} -> ${tokenBSymbol}`, async () => { - await testE2E( - tokens[tokenASymbol], - tokens[tokenBSymbol], - holders[tokenASymbol], - side === SwapSide.SELL ? tokenAAmount : tokenBAmount, - side, - dexKey, - contractMethod, - network, - provider, - ); + pairs.forEach(pair => { + describe(`${contractMethod}`, () => { + it(`${pair[0].name} -> ${pair[1].name}`, async () => { + await testE2E( + tokens[pair[0].name], + tokens[pair[1].name], + holders[pair[0].name], + side === SwapSide.SELL + ? pair[0].sellAmount + : pair[0].buyAmount, + side, + dexKey, + contractMethod, + network, + provider, + ); + }); + it(`${pair[1].name} -> ${pair[0].name}`, async () => { + await testE2E( + tokens[pair[1].name], + tokens[pair[0].name], + holders[pair[1].name], + side === SwapSide.SELL + ? pair[1].sellAmount + : pair[1].buyAmount, + side, + dexKey, + contractMethod, + network, + provider, + ); + }); }); }); }); }), ); }); -} - -describe('Wombat E2E', () => { - const dexKey = 'Wombat'; - describe('BSC', () => { - const network = Network.BSC; - - const tokenASymbol: string = 'USDC'; - const tokenBSymbol: string = 'USDT'; - - const tokenAAmount: string = '100000000'; - const tokenBAmount: string = '100000000'; - const nativeTokenAmount = '1000000000000000000'; - - testForNetwork( - network, - dexKey, - tokenASymbol, - tokenBSymbol, - tokenAAmount, - tokenBAmount, - nativeTokenAmount, - ); - }); - - describe('Arbitrum', () => { - const network = Network.ARBITRUM; - - const tokenASymbol: string = 'USDC'; - const tokenBSymbol: string = 'USDT'; - - const tokenAAmount: string = '100000000'; - const tokenBAmount: string = '100000000'; - const nativeTokenAmount = '1000000000000000000'; - - testForNetwork( - network, - dexKey, - tokenASymbol, - tokenBSymbol, - tokenAAmount, - tokenBAmount, - nativeTokenAmount, - ); - }); + // describe('Arbitrum', () => { + // const network = Network.ARBITRUM; + // + // const tokenASymbol: string = 'USDC'; + // const tokenBSymbol: string = 'USDT'; + // + // const tokenAAmount: string = '100000000'; + // const tokenBAmount: string = '100000000'; + // const nativeTokenAmount = '1000000000000000000'; + // + // testForNetwork( + // network, + // dexKey, + // tokenASymbol, + // tokenBSymbol, + // tokenAAmount, + // tokenBAmount, + // nativeTokenAmount, + // ); + // }); }); diff --git a/src/dex/wombat/wombat-integration.test.ts b/src/dex/wombat/wombat-integration.test.ts index 21e97cd80..f3976ac4b 100644 --- a/src/dex/wombat/wombat-integration.test.ts +++ b/src/dex/wombat/wombat-integration.test.ts @@ -150,16 +150,16 @@ describe('Wombat', function () { let blockNumber: number; let wombat: Wombat; - describe('Mainnet', () => { - const network = Network.MAINNET; + describe('BSC', () => { + const network = Network.BSC; const dexHelper = new DummyDexHelper(network); const tokens = Tokens[network]; // TODO: Put here token Symbol to check against // Don't forget to update relevant tokens in constant-e2e.ts - const srcTokenSymbol = 'srcTokenSymbol'; - const destTokenSymbol = 'destTokenSymbol'; + const srcTokenSymbol = 'USDC'; + const destTokenSymbol = 'USDT'; const amountsForSell = [ 0n, diff --git a/src/dex/wombat/wombat-pool.ts b/src/dex/wombat/wombat-pool.ts index 7fcf0e627..c21d3ea9a 100644 --- a/src/dex/wombat/wombat-pool.ts +++ b/src/dex/wombat/wombat-pool.ts @@ -145,14 +145,14 @@ export class WombatEventPool extends StatefulEventSubscriber { let i = 0; // 2 A. decode pool params - const ampFactor = WombatEventPool.poolInterface.decodeFunctionResult( + const ampFactor = BigInt(WombatEventPool.poolInterface.decodeFunctionResult( 'ampFactor', returnData[i++], - )[0]; - const haircutRate = WombatEventPool.poolInterface.decodeFunctionResult( + )[0]); + const haircutRate = BigInt(WombatEventPool.poolInterface.decodeFunctionResult( 'haircutRate', returnData[i++], - )[0]; + )[0]); const poolState: PoolState = { params: { ampFactor, @@ -165,14 +165,14 @@ export class WombatEventPool extends StatefulEventSubscriber { for (const [tokenAddress, tokenInfo] of Object.entries( this.poolCfg.tokens, )) { - const cash = WombatEventPool.assetInterface.decodeFunctionResult( + const cash = BigInt(WombatEventPool.assetInterface.decodeFunctionResult( 'cash', returnData[i++], - )[0]; - const liability = WombatEventPool.assetInterface.decodeFunctionResult( + )[0]); + const liability = BigInt(WombatEventPool.assetInterface.decodeFunctionResult( 'liability', returnData[i++], - )[0]; + )[0]); poolState.underlyingAddresses.push(tokenAddress); poolState.asset[tokenAddress] = { cash, diff --git a/tests/constants-e2e.ts b/tests/constants-e2e.ts index 599e38882..81c1fa858 100644 --- a/tests/constants-e2e.ts +++ b/tests/constants-e2e.ts @@ -526,6 +526,10 @@ export const Tokens: { address: '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c', decimals: 18, }, + BNBx: { + address: '0xab824b47806fea52276fef231e5e2d5fb3d4cf4e', + decimals: 9, + }, BUSD: { address: '0xe9e7cea3dedca5984780bafc599bd69add087d56', decimals: 18, diff --git a/tests/utils-e2e.ts b/tests/utils-e2e.ts index ece7ac264..539002508 100644 --- a/tests/utils-e2e.ts +++ b/tests/utils-e2e.ts @@ -35,6 +35,7 @@ import { SmartToken, StateOverrides } from './smart-tokens'; import { GIFTER_ADDRESS } from './constants-e2e'; import { generateDeployBytecode, sleep } from './utils'; import { assert } from 'ts-essentials'; +import * as util from 'util'; export const testingEndpoint = process.env.E2E_TEST_ENDPOINT; @@ -378,6 +379,7 @@ export async function testE2E( poolIdentifiers, transferFees, ); + console.log('price route: ', util.inspect(priceRoute, false, null, true)); expect(parseFloat(priceRoute.destAmount)).toBeGreaterThan(0); // Calculate slippage. Default is 1%