diff --git a/src/pools/phantomStablePool/phantomStablePool.ts b/src/pools/phantomStablePool/phantomStablePool.ts index 9a93f78c..794d77cb 100644 --- a/src/pools/phantomStablePool/phantomStablePool.ts +++ b/src/pools/phantomStablePool/phantomStablePool.ts @@ -228,11 +228,8 @@ export class PhantomStablePool implements PoolBase { // All values should use 1e18 fixed point // i.e. 1USDC => 1e18 not 1e6 // In Phantom Pools every time there is a swap (token per token, bpt per token or token per bpt), we substract the fee from the amount in - const amtWithFeeEvm = this.subtractSwapFeeAmount( - parseFixed(amount.dp(18).toString(), 18), - poolPairData.swapFee - ); - const amountConvertedEvm = amtWithFeeEvm + + const amountConverted = parseFixed(amount.dp(18).toString(), 18) .mul(tokenInPriceRate) .div(ONE); @@ -243,23 +240,23 @@ export class PhantomStablePool implements PoolBase { poolPairData.allBalancesScaled.length ).fill(BigInt(0)); amountsInBigInt[poolPairData.tokenIndexIn] = - amountConvertedEvm.toBigInt(); + amountConverted.toBigInt(); returnEvm = _calcBptOutGivenExactTokensIn( this.amp.toBigInt(), poolPairData.allBalancesScaled.map((b) => b.toBigInt()), amountsInBigInt, this.totalShares.toBigInt(), - BigInt(0) + poolPairData.swapFee.toBigInt() ); } else if (poolPairData.pairType === PairTypes.BptToToken) { returnEvm = _calcTokenOutGivenExactBptIn( this.amp.toBigInt(), poolPairData.allBalancesScaled.map((b) => b.toBigInt()), poolPairData.tokenIndexOut, - amountConvertedEvm.toBigInt(), + amountConverted.toBigInt(), this.totalShares.toBigInt(), - BigInt(0) + poolPairData.swapFee.toBigInt() ); } else { returnEvm = _calcOutGivenIn( @@ -267,8 +264,8 @@ export class PhantomStablePool implements PoolBase { poolPairData.allBalancesScaled.map((b) => b.toBigInt()), poolPairData.tokenIndexIn, poolPairData.tokenIndexOut, - amountConvertedEvm.toBigInt(), - BigInt(0) + amountConverted.toBigInt(), + poolPairData.swapFee.toBigInt() ); } @@ -309,7 +306,7 @@ export class PhantomStablePool implements PoolBase { poolPairData.tokenIndexIn, amountConvertedEvm.toBigInt(), this.totalShares.toBigInt(), - BigInt(0) + poolPairData.swapFee.toBigInt() ); } else if (poolPairData.pairType === PairTypes.BptToToken) { const amountsOutBigInt = Array( @@ -323,7 +320,7 @@ export class PhantomStablePool implements PoolBase { poolPairData.allBalancesScaled.map((b) => b.toBigInt()), amountsOutBigInt, this.totalShares.toBigInt(), - BigInt(0) // Fee is handled below + poolPairData.swapFee.toBigInt() ); } else { returnEvm = _calcInGivenOut( @@ -332,7 +329,7 @@ export class PhantomStablePool implements PoolBase { poolPairData.tokenIndexIn, poolPairData.tokenIndexOut, amountConvertedEvm.toBigInt(), - BigInt(0) // Fee is handled below + poolPairData.swapFee.toBigInt() ); } // In Phantom Pools every time there is a swap (token per token, bpt per token or token per bpt), we substract the fee from the amount in @@ -340,13 +337,8 @@ export class PhantomStablePool implements PoolBase { .mul(ONE) .div(tokenInPriceRate); - const returnEvmWithFee = this.addSwapFeeAmount( - returnEvmWithRate, - poolPairData.swapFee - ); - // return human number - return bnum(formatFixed(returnEvmWithFee, 18)); + return bnum(formatFixed(returnEvmWithRate, 18)); } catch (err) { console.error(`PhantomStable _evminGivenOut: ${err.message}`); return ZERO; diff --git a/test/composableStablePool.spec.ts b/test/composableStablePool.spec.ts index dcfd3f36..879da7fa 100644 --- a/test/composableStablePool.spec.ts +++ b/test/composableStablePool.spec.ts @@ -19,8 +19,8 @@ describe('composable stable pool', () => { // parsePoolPairData contains pool's allBalances and allBalancesScaled // both already multiplied by the price rates. const poolPairData = composableStablePool.parsePoolPairData( - ADDRESSES[Network.MAINNET].bbausdt2.address, - ADDRESSES[Network.MAINNET].bbausd2.address + ADDRESSES[Network.MAINNET].bbausdt.address, + ADDRESSES[Network.MAINNET].bbausd.address ); it('token -> BPT spot price with no rate', () => { // spot prices diff --git a/test/linear.spec.ts b/test/linear.spec.ts index 5b5e8b4b..dcff0f2f 100644 --- a/test/linear.spec.ts +++ b/test/linear.spec.ts @@ -718,7 +718,7 @@ describe('linear pool tests', () => { fullKovanPools.pools, sorConfigFullKovan ); - expect(returnAmount).to.eq('6606146264948964392'); + expect(returnAmount).to.eq('6638439512219283357'); }); it('BAL>USDT, SwapExactIn', async () => { @@ -756,7 +756,7 @@ describe('linear pool tests', () => { fullKovanPools.pools, sorConfigFullKovan ); - expect(returnAmount).to.eq('702055'); + expect(returnAmount).to.eq('698604'); }); it('BAL>USDT, SwapExactOut', async () => { @@ -768,7 +768,7 @@ describe('linear pool tests', () => { fullKovanPools.pools, sorConfigFullKovan ); - expect(returnAmount).to.eq('81899098582251741376'); + expect(returnAmount).to.eq('81419601531090714841'); }); }); @@ -784,7 +784,7 @@ describe('linear pool tests', () => { pools, sorConfigKovan ); - expect(returnAmount).to.eq('989985749906811070'); + expect(returnAmount).to.eq('993338125331362114'); }); it('USDT>staBAL3, SwapExactOut', async () => { @@ -796,7 +796,7 @@ describe('linear pool tests', () => { kovanPools.pools, sorConfigKovan ); - expect(returnAmount).to.eq('1009969'); + expect(returnAmount).to.eq('1006617'); }); it('staBAL3>USDT, SwapExactIn', async () => { @@ -808,7 +808,7 @@ describe('linear pool tests', () => { kovanPools.pools, sorConfigKovan ); - expect(returnAmount).to.eq('989869'); + expect(returnAmount).to.eq('993188'); }); it('staBAL3>USDT, SwapExactOut', async () => { @@ -820,7 +820,7 @@ describe('linear pool tests', () => { kovanPools.pools, sorConfigKovan ); - expect(returnAmount).to.eq('1010233805404347502'); + expect(returnAmount).to.eq('1006881038845023935'); }); // it('aUSDT>staBAL3, SwapExactIn', async () => { diff --git a/test/phantomStablePools.spec.ts b/test/phantomStablePools.spec.ts index 10452663..7f3d80df 100644 --- a/test/phantomStablePools.spec.ts +++ b/test/phantomStablePools.spec.ts @@ -174,7 +174,7 @@ describe(`Tests for PhantomStable Pools.`, () => { parseFixed('0.010001000098489046', 18), [pool] ); - expect(returnAmount).to.eq('9901097957797894'); + expect(returnAmount).to.eq('9934289675943491'); }); it('BPT>Token, SwapExactIn', async () => { @@ -185,7 +185,7 @@ describe(`Tests for PhantomStable Pools.`, () => { parseFixed('401.873', 18), [pool] ); - expect(returnAmount).to.eq('397821023707679256401'); + expect(returnAmount).to.eq('399154341172470359058'); }); }); @@ -209,7 +209,7 @@ describe(`Tests for PhantomStable Pools.`, () => { parseFixed('654.98', 18), [pool] ); - expect(returnAmount).to.eq('661659057984436270211'); + expect(returnAmount).to.eq('659463141422133620208'); }); it('BPT>Token, SwapExactIn', async () => { @@ -220,7 +220,7 @@ describe(`Tests for PhantomStable Pools.`, () => { parseFixed('0.007321', 18), [pool] ); - expect(returnAmount).to.eq('7395030076860800'); + expect(returnAmount).to.eq('7370487423382863'); }); }); }); diff --git a/test/testScripts/constants.ts b/test/testScripts/constants.ts index fdb59f0f..a41b3c48 100644 --- a/test/testScripts/constants.ts +++ b/test/testScripts/constants.ts @@ -124,16 +124,21 @@ export const ADDRESSES = { decimals: 18, symbol: 'wSTETH', }, - bbausd: { + bbausdOld: { address: '0x7b50775383d3d6f0215a8f290f2c9e2eebbeceb2', decimals: 18, symbol: 'bbausd', }, - bbausdc: { + bbausdcOld: { address: '0x9210F1204b5a24742Eba12f710636D76240dF3d0', decimals: 18, symbol: 'bbausdc', }, + bbausdc: { + address: '0x82698aecc9e28e9bb27608bd52cf57f704bd1b83', + decimals: 18, + symbol: 'bbausdc', + }, bbadai: { address: '0x804cdb9116a10bb78768d3252355a1b18067bf8f', decimals: 18, @@ -149,20 +154,20 @@ export const ADDRESSES = { decimals: 6, symbol: 'waUSDC', }, - bbausd2: { + bbausd: { address: '0xA13a9247ea42D743238089903570127DdA72fE44', decimals: 18, - symbol: 'bbausd2', + symbol: 'bbausd', }, bbadai2: { address: '0xae37d54ae477268b9997d4161b96b8200755935c', decimals: 18, symbol: 'bb-a-dai2', }, - bbausdt2: { + bbausdt: { address: '0x2F4eb100552ef93840d5aDC30560E5513DFfFACb', decimals: 18, - symbol: 'bb-a-usdt2', + symbol: 'bb-a-usdt', }, RPL: { address: '0xD33526068D116cE69F19A9ee46F0bd304F21A51f', @@ -189,7 +194,7 @@ export const ADDRESSES = { decimals: 6, symbol: 'USDT', }, - bbausdt: { + bbausdtOld: { address: '0x2f4eb100552ef93840d5adc30560e5513dfffacb', decimals: 18, symbol: 'bbaUSDT', diff --git a/test/testScripts/swapExample.ts b/test/testScripts/swapExample.ts index a95f81b7..1dfea51b 100644 --- a/test/testScripts/swapExample.ts +++ b/test/testScripts/swapExample.ts @@ -65,10 +65,10 @@ export async function swap(): Promise { const gasPrice = BigNumber.from('14000000000'); // This determines the max no of pools the SOR will use to swap. const maxPools = 4; - const tokenIn = ADDRESSES[networkId].USDT; - const tokenOut = ADDRESSES[networkId].bbausdt; - const swapType: SwapTypes = SwapTypes.SwapExactIn; - const swapAmount = parseFixed('10', 6); + const tokenIn = ADDRESSES[networkId].bbausdt; + const tokenOut = ADDRESSES[networkId].bbausd; + const swapType: SwapTypes = SwapTypes.SwapExactOut; + const swapAmount = parseFixed('10', 18); const sor = setUp(networkId, provider);