From d923e4a671d103a8ddc30cebe9d207d1f746fa02 Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Wed, 8 Nov 2023 15:20:12 -0300 Subject: [PATCH 01/16] Add test cases for ABA price impact comparison --- .../pricing/priceImpact.compare.spec.ts | 224 ++++++++++++++++++ 1 file changed, 224 insertions(+) create mode 100644 balancer-js/src/modules/pricing/priceImpact.compare.spec.ts diff --git a/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts b/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts new file mode 100644 index 000000000..55381f69c --- /dev/null +++ b/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts @@ -0,0 +1,224 @@ +// yarn test:only ./src/modules/pricing/picompare.integration.spec.ts +import { BigNumber, formatFixed, parseFixed } from '@ethersproject/bignumber'; +import dotenv from 'dotenv'; +import hardhat from 'hardhat'; + +import { + Address, + BalancerSDK, + Network, + PoolToken, + PoolWithMethods, + SwapType, +} from '@/.'; +import { forkSetup, TestPoolHelper } from '@/test/lib/utils'; +import { ADDRESSES, TEST_BLOCK } from '@/test/lib/constants'; +import { queryBatchSwap } from '../swaps/queryBatchSwap'; + +dotenv.config(); + +const { ALCHEMY_URL: jsonRpcUrl } = process.env; +const { ethers } = hardhat; + +const rpcUrl = 'http://127.0.0.1:8545'; +const network = Network.MAINNET; +const sdk = new BalancerSDK({ network, rpcUrl }); +const { contracts } = sdk; +const provider = new ethers.providers.JsonRpcProvider(rpcUrl, 1); +const signer = provider.getSigner(); +const { balancerHelpers, vault } = contracts; + +// Slots used to set the account balance for each token through hardhat_setStorageAt +// Info fetched using npm package slot20 +const slots = [ADDRESSES[network].WBTC.slot, ADDRESSES[network].WETH.slot]; +const initialBalance = '100000'; +const testPoolId = + '0x5c6ee304399dbdb9c8ef030ab642b10820db8f56000200000000000000000014'; // B_50WBTC_50WETH +const blockNumber = TEST_BLOCK[network]; +const slippage = '0'; // does not affect result + +describe('Weighted Pool - Join Functions', async () => { + let pool: PoolWithMethods; + let signerAddress: Address; + let testPoolHelper: TestPoolHelper; + + before(async () => { + signerAddress = await signer.getAddress(); + testPoolHelper = new TestPoolHelper( + testPoolId, + network, + rpcUrl, + blockNumber + ); + pool = await testPoolHelper.getPool(); + }); + + context('Integration Tests', async () => { + // Setup chain + beforeEach(async function () { + const balances = pool.tokens.map((token) => + parseFixed(initialBalance, token.decimals).toString() + ); + await forkSetup( + signer, + pool.tokensList, + slots, + balances, + jsonRpcUrl as string, + blockNumber + ); + pool = await testPoolHelper.getPool(); // update the pool after the forkSetup; + }); + + context('single token join', async () => { + let tokenIn: PoolToken; + let amountIn: BigNumber; + + before(() => { + tokenIn = pool.tokens[0]; + amountIn = parseFixed('10', tokenIn.decimals); + }); + + it('should calculate price impact - spot price method', async () => { + const amountsIn = Array(pool.tokensList.length).fill('0'); + amountsIn[pool.tokensList.indexOf(tokenIn.address)] = + amountIn.toString(); + + const { priceImpact } = pool.buildJoin( + signerAddress, + pool.tokensList, + amountsIn, + slippage + ); + + const priceImpactFloat = parseFloat( + formatFixed(BigNumber.from(priceImpact), 18) + ); + console.log(`priceImpactFloat: ${priceImpactFloat}`); + }); + + it('should calculate price impact - ABA method', async () => { + const maxAmountsInByToken = new Map([ + [tokenIn.address, amountIn], + ]); + + const joinParams = pool.buildQueryJoinExactIn({ + maxAmountsInByToken, + }); + + const { bptOut } = await balancerHelpers.callStatic.queryJoin( + ...joinParams + ); + + const exitParams = pool.buildQueryExitToSingleToken({ + bptIn: bptOut, + tokenOut: tokenIn.address, + }); + + const { amountsOut } = await balancerHelpers.callStatic.queryExit( + ...exitParams + ); + + const initialA = parseFloat(formatFixed(amountIn, 8)); + const finalA = parseFloat(formatFixed(amountsOut[0], 8)); + const priceImpactABA = (initialA - finalA) / initialA / 2; + console.log(`priceImpactABA : ${priceImpactABA}`); + }); + }); + + context('unbalanced join - 2 tokens', async () => { + let amountsIn: BigNumber[]; + + before(() => { + amountsIn = pool.tokens.map((token) => + parseFixed('10000', token.decimals) + ); + }); + + it('should calculate price impact - spot price method', async () => { + const { priceImpact } = pool.buildJoin( + signerAddress, + pool.tokensList, + amountsIn.map((amount) => amount.toString()), + slippage + ); + + const priceImpactFloat = parseFloat( + formatFixed(BigNumber.from(priceImpact), 18) + ); + console.log(`priceImpactFloat: ${priceImpactFloat}`); + }); + + it('should calculate price impact - ABA method', async () => { + const maxAmountsInByToken = new Map( + amountsIn.map((a, i) => [pool.tokensList[i], a]) + ); + + // query unbalanced join + const { bptOut } = await balancerHelpers.callStatic.queryJoin( + ...pool.buildQueryJoinExactIn({ + maxAmountsInByToken, + }) + ); + + // calculate proportional amounts out + const { amountsOut } = await balancerHelpers.callStatic.queryExit( + ...pool.buildQueryExitProportionally({ + bptIn: bptOut, + }) + ); + + // diff between unbalanced and proportional amounts for token 1 + const diffs = amountsOut.map((a, i) => a.sub(amountsIn[i])); + const excessIndex = diffs.findIndex((a) => a.gt(0)); + const otherIndex = diffs.findIndex((a) => a.lt(0)); + const diff1 = amountsOut[excessIndex].sub(amountsIn[excessIndex]); + + // swap that diff to token 0 + const returnAmounts = await queryBatchSwap( + vault, + SwapType.SwapExactIn, + [ + { + poolId: pool.id, + assetInIndex: excessIndex, + assetOutIndex: otherIndex, + amount: diff1.toString(), + userData: '0x', + }, + ], + pool.tokensList + ); + + // calculate final token 0 amount (using sub because returnAmounts[0] is negative) + const token0Final = amountsOut[otherIndex].sub( + BigNumber.from(returnAmounts[otherIndex]) + ); + + // diff between unbalanced and proportional amounts for token 0 + const diff0 = amountsIn[otherIndex].sub(token0Final); + + // query join with diff0 in order to get BPT difference between unbalanced and proportional + const diffAmounts = new Map([ + [pool.tokensList[otherIndex], diff0], + ]); + + const { bptOut: bptOutDiff } = + await balancerHelpers.callStatic.queryJoin( + ...pool.buildQueryJoinExactIn({ + maxAmountsInByToken: diffAmounts, + }) + ); + + const initialA = parseFloat( + formatFixed(bptOut, pool.tokens[otherIndex].decimals) + ); + const finalA = parseFloat( + formatFixed(bptOut.sub(bptOutDiff), pool.tokens[otherIndex].decimals) + ); + const priceImpactABA = (initialA - finalA) / initialA / 2; + console.log(`priceImpactABA : ${priceImpactABA}`); + }); + }); + }); +}); From bdc44dd00cc4052da1b2835af08b5df54921fe31 Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Wed, 8 Nov 2023 17:09:05 -0300 Subject: [PATCH 02/16] Add swap comparison --- .../pricing/priceImpact.compare.spec.ts | 110 +++++++++++++++++- 1 file changed, 105 insertions(+), 5 deletions(-) diff --git a/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts b/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts index 55381f69c..2bf44aaec 100644 --- a/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts +++ b/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts @@ -1,4 +1,4 @@ -// yarn test:only ./src/modules/pricing/picompare.integration.spec.ts +// yarn test:only ./src/modules/pricing/priceImpact.compare.spec.ts import { BigNumber, formatFixed, parseFixed } from '@ethersproject/bignumber'; import dotenv from 'dotenv'; import hardhat from 'hardhat'; @@ -9,6 +9,7 @@ import { Network, PoolToken, PoolWithMethods, + SubgraphPoolBase, SwapType, } from '@/.'; import { forkSetup, TestPoolHelper } from '@/test/lib/utils'; @@ -23,7 +24,7 @@ const { ethers } = hardhat; const rpcUrl = 'http://127.0.0.1:8545'; const network = Network.MAINNET; const sdk = new BalancerSDK({ network, rpcUrl }); -const { contracts } = sdk; +const { contracts, pricing } = sdk; const provider = new ethers.providers.JsonRpcProvider(rpcUrl, 1); const signer = provider.getSigner(); const { balancerHelpers, vault } = contracts; @@ -37,7 +38,7 @@ const testPoolId = const blockNumber = TEST_BLOCK[network]; const slippage = '0'; // does not affect result -describe('Weighted Pool - Join Functions', async () => { +describe('Price impact comparison tests', async () => { let pool: PoolWithMethods; let signerAddress: Address; let testPoolHelper: TestPoolHelper; @@ -53,7 +54,7 @@ describe('Weighted Pool - Join Functions', async () => { pool = await testPoolHelper.getPool(); }); - context('Integration Tests', async () => { + context('Price impact comparison tests', async () => { // Setup chain beforeEach(async function () { const balances = pool.tokens.map((token) => @@ -70,7 +71,106 @@ describe('Weighted Pool - Join Functions', async () => { pool = await testPoolHelper.getPool(); // update the pool after the forkSetup; }); - context('single token join', async () => { + context('swap', async () => { + const assetInIndex = 0; + const assetOutIndex = 1; + let swapAmount: BigNumber; + + before(() => { + swapAmount = parseFixed('2', pool.tokens[assetInIndex].decimals); // 200 WETH + }); + + it('should calculate price impact - spot price method', async () => { + const swapAmounts = await queryBatchSwap( + vault, + SwapType.SwapExactIn, + [ + { + poolId: pool.id, + assetInIndex, + assetOutIndex, + amount: swapAmount.toString(), + userData: '0x', + }, + ], + pool.tokensList + ); + + const amountIn = parseFloat( + formatFixed( + swapAmounts[assetInIndex], + pool.tokens[assetInIndex].decimals + ) + ); + console.log(`amountIn: ${amountIn}`); + + const amountOut = + -1 * + parseFloat( + formatFixed( + swapAmounts[assetOutIndex], + pool.tokens[assetOutIndex].decimals + ) + ); + console.log(`amountOut: ${amountOut}`); + + const effectivePrice = amountIn / amountOut; + console.log(`effectivePrice: ${effectivePrice}`); + + const subgraphPool: SubgraphPoolBase = pool as SubgraphPoolBase; + + const spotPrice = await pricing.getSpotPrice( + pool.tokensList[assetInIndex], + pool.tokensList[assetOutIndex], + [subgraphPool] + ); + console.log(`spotPrice: ${spotPrice}`); + + const priceRatio = parseFloat(spotPrice) / effectivePrice; + const priceImpact = 1 - priceRatio; + console.log(`priceImpact: ${priceImpact}`); + }); + + it('should calculate price impact - spot price method', async () => { + const swapAmounts = await queryBatchSwap( + vault, + SwapType.SwapExactIn, + [ + { + poolId: pool.id, + assetInIndex, + assetOutIndex, + amount: swapAmount.toString(), + userData: '0x', + }, + { + poolId: pool.id, + assetInIndex: assetOutIndex, + assetOutIndex: assetInIndex, + amount: '0', + userData: '0x', + }, + ], + pool.tokensList + ); + const diff = parseFloat( + formatFixed( + swapAmounts[assetInIndex], + pool.tokens[assetInIndex].decimals + ) + ); + console.log(`diff lost by price impact: ${diff}`); + + const initialA = parseFloat( + formatFixed(swapAmount, pool.tokens[assetInIndex].decimals) + ); + console.log(`initialA: ${initialA}`); + + const priceImpactABA = diff / initialA / 2; + console.log(`priceImpactABA : ${priceImpactABA}`); + }); + }); + let tokenIn: PoolToken; let amountIn: BigNumber; From 4abd57872b130a261ee066c9aabf7d4bc810df88 Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Thu, 9 Nov 2023 10:04:46 -0300 Subject: [PATCH 03/16] Fix --- balancer-js/src/modules/pricing/priceImpact.compare.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts b/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts index 2bf44aaec..cc7c42e0a 100644 --- a/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts +++ b/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts @@ -171,6 +171,7 @@ describe('Price impact comparison tests', async () => { }); }); + context('single token join', async () => { let tokenIn: PoolToken; let amountIn: BigNumber; From 93d11ffb99f55da052af8ef06af3805bdb560144 Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Thu, 9 Nov 2023 10:40:32 -0300 Subject: [PATCH 04/16] Minor refactor to improve results readability --- .../pricing/priceImpact.compare.spec.ts | 456 +++++++++--------- 1 file changed, 228 insertions(+), 228 deletions(-) diff --git a/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts b/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts index cc7c42e0a..78dc9e972 100644 --- a/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts +++ b/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts @@ -54,272 +54,272 @@ describe('Price impact comparison tests', async () => { pool = await testPoolHelper.getPool(); }); - context('Price impact comparison tests', async () => { - // Setup chain - beforeEach(async function () { - const balances = pool.tokens.map((token) => - parseFixed(initialBalance, token.decimals).toString() - ); - await forkSetup( - signer, - pool.tokensList, - slots, - balances, - jsonRpcUrl as string, - blockNumber - ); - pool = await testPoolHelper.getPool(); // update the pool after the forkSetup; - }); + // Setup chain + beforeEach(async function () { + const balances = pool.tokens.map((token) => + parseFixed(initialBalance, token.decimals).toString() + ); + await forkSetup( + signer, + pool.tokensList, + slots, + balances, + jsonRpcUrl as string, + blockNumber + ); + pool = await testPoolHelper.getPool(); // update the pool after the forkSetup; + }); - context('swap', async () => { - const assetInIndex = 0; - const assetOutIndex = 1; - let swapAmount: BigNumber; + context('swap', async () => { + const assetInIndex = 1; + const assetOutIndex = 0; + let swapAmount: BigNumber; - before(() => { - swapAmount = parseFixed('2', pool.tokens[assetInIndex].decimals); // 200 WETH - }); + before(() => { + swapAmount = parseFixed('200', pool.tokens[assetInIndex].decimals); // 200 WETH + }); - it('should calculate price impact - spot price method', async () => { - const swapAmounts = await queryBatchSwap( - vault, - SwapType.SwapExactIn, - [ - { - poolId: pool.id, - assetInIndex, - assetOutIndex, - amount: swapAmount.toString(), - userData: '0x', - }, - ], - pool.tokensList - ); + it('should calculate price impact - spot price method', async () => { + const swapAmounts = await queryBatchSwap( + vault, + SwapType.SwapExactIn, + [ + { + poolId: pool.id, + assetInIndex, + assetOutIndex, + amount: swapAmount.toString(), + userData: '0x', + }, + ], + pool.tokensList + ); - const amountIn = parseFloat( + const amountIn = parseFloat( + formatFixed( + swapAmounts[assetInIndex], + pool.tokens[assetInIndex].decimals + ) + ); + + const amountOut = + -1 * + parseFloat( formatFixed( - swapAmounts[assetInIndex], - pool.tokens[assetInIndex].decimals + swapAmounts[assetOutIndex], + pool.tokens[assetOutIndex].decimals ) ); - console.log(`amountIn: ${amountIn}`); - - const amountOut = - -1 * - parseFloat( - formatFixed( - swapAmounts[assetOutIndex], - pool.tokens[assetOutIndex].decimals - ) - ); - console.log(`amountOut: ${amountOut}`); - - const effectivePrice = amountIn / amountOut; - console.log(`effectivePrice: ${effectivePrice}`); - - const subgraphPool: SubgraphPoolBase = pool as SubgraphPoolBase; - - const spotPrice = await pricing.getSpotPrice( - pool.tokensList[assetInIndex], - pool.tokensList[assetOutIndex], - [subgraphPool] - ); - console.log(`spotPrice: ${spotPrice}`); - const priceRatio = parseFloat(spotPrice) / effectivePrice; - const priceImpact = 1 - priceRatio; - console.log(`priceImpact: ${priceImpact}`); - }); + const effectivePrice = amountIn / amountOut; - it('should calculate price impact - spot price method', async () => { - const swapAmounts = await queryBatchSwap( - vault, - SwapType.SwapExactIn, - [ - { - poolId: pool.id, - assetInIndex, - assetOutIndex, - amount: swapAmount.toString(), - userData: '0x', - }, - { - poolId: pool.id, - assetInIndex: assetOutIndex, - assetOutIndex: assetInIndex, - amount: '0', - userData: '0x', - }, - ], - pool.tokensList - ); - const diff = parseFloat( - formatFixed( - swapAmounts[assetInIndex], - pool.tokens[assetInIndex].decimals - ) - ); - console.log(`diff lost by price impact: ${diff}`); + const subgraphPool: SubgraphPoolBase = pool as SubgraphPoolBase; - const initialA = parseFloat( - formatFixed(swapAmount, pool.tokens[assetInIndex].decimals) - ); - console.log(`initialA: ${initialA}`); + const spotPrice = await pricing.getSpotPrice( + pool.tokensList[assetInIndex], + pool.tokensList[assetOutIndex], + [subgraphPool] + ); - const priceImpactABA = diff / initialA / 2; - console.log(`priceImpactABA : ${priceImpactABA}`); - }); + const priceRatio = parseFloat(spotPrice) / effectivePrice; + const priceImpact = 1 - priceRatio; + console.log(`priceImpactSpotPrice: ${priceImpact}`); }); - context('single token join', async () => { - let tokenIn: PoolToken; - let amountIn: BigNumber; + it('should calculate price impact - ABA method', async () => { + const swapAtoB = await queryBatchSwap( + vault, + SwapType.SwapExactIn, + [ + { + poolId: pool.id, + assetInIndex, + assetOutIndex, + amount: swapAmount.toString(), + userData: '0x', + }, + ], + pool.tokensList + ); + const B = BigNumber.from(-1).mul(swapAtoB[assetOutIndex]); + + const swapBtoA = await queryBatchSwap( + vault, + SwapType.SwapExactIn, + [ + { + poolId: pool.id, + assetInIndex: assetOutIndex, + assetOutIndex: assetInIndex, + amount: B.toString(), + userData: '0x', + }, + ], + pool.tokensList + ); + const finalA = parseFloat( + formatFixed( + BigNumber.from(-1).mul(swapBtoA[assetInIndex]), + pool.tokens[assetInIndex].decimals + ) + ); - before(() => { - tokenIn = pool.tokens[0]; - amountIn = parseFixed('10', tokenIn.decimals); - }); + const initialA = parseFloat( + formatFixed(swapAmount, pool.tokens[assetInIndex].decimals) + ); - it('should calculate price impact - spot price method', async () => { - const amountsIn = Array(pool.tokensList.length).fill('0'); - amountsIn[pool.tokensList.indexOf(tokenIn.address)] = - amountIn.toString(); + const priceImpactABA = + (initialA - finalA) / initialA / 2 - parseFloat(pool.swapFee); + console.log(`priceImpactABA : ${priceImpactABA}`); + }); + }); - const { priceImpact } = pool.buildJoin( - signerAddress, - pool.tokensList, - amountsIn, - slippage - ); + context('single token join', async () => { + let tokenIn: PoolToken; + let amountIn: BigNumber; - const priceImpactFloat = parseFloat( - formatFixed(BigNumber.from(priceImpact), 18) - ); - console.log(`priceImpactFloat: ${priceImpactFloat}`); - }); + before(() => { + tokenIn = pool.tokens[0]; + amountIn = parseFixed('10', tokenIn.decimals); + }); - it('should calculate price impact - ABA method', async () => { - const maxAmountsInByToken = new Map([ - [tokenIn.address, amountIn], - ]); + it('should calculate price impact - spot price method', async () => { + const amountsIn = Array(pool.tokensList.length).fill('0'); + amountsIn[pool.tokensList.indexOf(tokenIn.address)] = amountIn.toString(); - const joinParams = pool.buildQueryJoinExactIn({ - maxAmountsInByToken, - }); + const { priceImpact } = pool.buildJoin( + signerAddress, + pool.tokensList, + amountsIn, + slippage + ); - const { bptOut } = await balancerHelpers.callStatic.queryJoin( - ...joinParams - ); + const priceImpactFloat = parseFloat( + formatFixed(BigNumber.from(priceImpact), 18) + ); + console.log(`priceImpactSpotPrice: ${priceImpactFloat}`); + }); - const exitParams = pool.buildQueryExitToSingleToken({ - bptIn: bptOut, - tokenOut: tokenIn.address, - }); + it('should calculate price impact - ABA method', async () => { + const maxAmountsInByToken = new Map([ + [tokenIn.address, amountIn], + ]); - const { amountsOut } = await balancerHelpers.callStatic.queryExit( - ...exitParams - ); + const joinParams = pool.buildQueryJoinExactIn({ + maxAmountsInByToken, + }); + + const { bptOut } = await balancerHelpers.callStatic.queryJoin( + ...joinParams + ); - const initialA = parseFloat(formatFixed(amountIn, 8)); - const finalA = parseFloat(formatFixed(amountsOut[0], 8)); - const priceImpactABA = (initialA - finalA) / initialA / 2; - console.log(`priceImpactABA : ${priceImpactABA}`); + const exitParams = pool.buildQueryExitToSingleToken({ + bptIn: bptOut, + tokenOut: tokenIn.address, }); + + const { amountsOut } = await balancerHelpers.callStatic.queryExit( + ...exitParams + ); + + const initialA = parseFloat(formatFixed(amountIn, 8)); + const finalA = parseFloat(formatFixed(amountsOut[0], 8)); + const priceImpactABA = (initialA - finalA) / initialA / 2; + console.log(`priceImpactABA : ${priceImpactABA}`); }); + }); - context('unbalanced join - 2 tokens', async () => { - let amountsIn: BigNumber[]; + context('unbalanced join - 2 tokens', async () => { + let amountsIn: BigNumber[]; - before(() => { - amountsIn = pool.tokens.map((token) => - parseFixed('10000', token.decimals) - ); - }); + before(() => { + amountsIn = pool.tokens.map((token) => + parseFixed('10000', token.decimals) + ); + }); - it('should calculate price impact - spot price method', async () => { - const { priceImpact } = pool.buildJoin( - signerAddress, - pool.tokensList, - amountsIn.map((amount) => amount.toString()), - slippage - ); + it('should calculate price impact - spot price method', async () => { + const { priceImpact } = pool.buildJoin( + signerAddress, + pool.tokensList, + amountsIn.map((amount) => amount.toString()), + slippage + ); - const priceImpactFloat = parseFloat( - formatFixed(BigNumber.from(priceImpact), 18) - ); - console.log(`priceImpactFloat: ${priceImpactFloat}`); - }); + const priceImpactFloat = parseFloat( + formatFixed(BigNumber.from(priceImpact), 18) + ); + console.log(`priceImpactSpotPrice: ${priceImpactFloat}`); + }); - it('should calculate price impact - ABA method', async () => { - const maxAmountsInByToken = new Map( - amountsIn.map((a, i) => [pool.tokensList[i], a]) - ); + it('should calculate price impact - ABA method', async () => { + const maxAmountsInByToken = new Map( + amountsIn.map((a, i) => [pool.tokensList[i], a]) + ); - // query unbalanced join - const { bptOut } = await balancerHelpers.callStatic.queryJoin( - ...pool.buildQueryJoinExactIn({ - maxAmountsInByToken, - }) - ); + // query unbalanced join + const { bptOut } = await balancerHelpers.callStatic.queryJoin( + ...pool.buildQueryJoinExactIn({ + maxAmountsInByToken, + }) + ); - // calculate proportional amounts out - const { amountsOut } = await balancerHelpers.callStatic.queryExit( - ...pool.buildQueryExitProportionally({ - bptIn: bptOut, - }) - ); + // calculate proportional amounts out + const { amountsOut } = await balancerHelpers.callStatic.queryExit( + ...pool.buildQueryExitProportionally({ + bptIn: bptOut, + }) + ); - // diff between unbalanced and proportional amounts for token 1 - const diffs = amountsOut.map((a, i) => a.sub(amountsIn[i])); - const excessIndex = diffs.findIndex((a) => a.gt(0)); - const otherIndex = diffs.findIndex((a) => a.lt(0)); - const diff1 = amountsOut[excessIndex].sub(amountsIn[excessIndex]); - - // swap that diff to token 0 - const returnAmounts = await queryBatchSwap( - vault, - SwapType.SwapExactIn, - [ - { - poolId: pool.id, - assetInIndex: excessIndex, - assetOutIndex: otherIndex, - amount: diff1.toString(), - userData: '0x', - }, - ], - pool.tokensList - ); + // diff between unbalanced and proportional amounts for token 1 + const diffs = amountsOut.map((a, i) => a.sub(amountsIn[i])); + const excessIndex = diffs.findIndex((a) => a.gt(0)); + const otherIndex = diffs.findIndex((a) => a.lt(0)); + const diff1 = amountsOut[excessIndex].sub(amountsIn[excessIndex]); + + // swap that diff to token 0 + const returnAmounts = await queryBatchSwap( + vault, + SwapType.SwapExactIn, + [ + { + poolId: pool.id, + assetInIndex: excessIndex, + assetOutIndex: otherIndex, + amount: diff1.toString(), + userData: '0x', + }, + ], + pool.tokensList + ); - // calculate final token 0 amount (using sub because returnAmounts[0] is negative) - const token0Final = amountsOut[otherIndex].sub( - BigNumber.from(returnAmounts[otherIndex]) - ); + // calculate final token 0 amount (using sub because returnAmounts[0] is negative) + const token0Final = amountsOut[otherIndex].sub( + BigNumber.from(returnAmounts[otherIndex]) + ); - // diff between unbalanced and proportional amounts for token 0 - const diff0 = amountsIn[otherIndex].sub(token0Final); + // diff between unbalanced and proportional amounts for token 0 + const diff0 = amountsIn[otherIndex].sub(token0Final); - // query join with diff0 in order to get BPT difference between unbalanced and proportional - const diffAmounts = new Map([ - [pool.tokensList[otherIndex], diff0], - ]); + // query join with diff0 in order to get BPT difference between unbalanced and proportional + const diffAmounts = new Map([ + [pool.tokensList[otherIndex], diff0], + ]); - const { bptOut: bptOutDiff } = - await balancerHelpers.callStatic.queryJoin( - ...pool.buildQueryJoinExactIn({ - maxAmountsInByToken: diffAmounts, - }) - ); + const { bptOut: bptOutDiff } = await balancerHelpers.callStatic.queryJoin( + ...pool.buildQueryJoinExactIn({ + maxAmountsInByToken: diffAmounts, + }) + ); - const initialA = parseFloat( - formatFixed(bptOut, pool.tokens[otherIndex].decimals) - ); - const finalA = parseFloat( - formatFixed(bptOut.sub(bptOutDiff), pool.tokens[otherIndex].decimals) - ); - const priceImpactABA = (initialA - finalA) / initialA / 2; - console.log(`priceImpactABA : ${priceImpactABA}`); - }); + const initialA = parseFloat( + formatFixed(bptOut, pool.tokens[otherIndex].decimals) + ); + const finalA = parseFloat( + formatFixed(bptOut.sub(bptOutDiff), pool.tokens[otherIndex].decimals) + ); + const priceImpactABA = (initialA - finalA) / initialA / 2; + console.log(`priceImpactABA : ${priceImpactABA}`); }); }); }); From e60c881bb363cc8e6f077ed23a02f4ee1aa2ae7c Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Thu, 9 Nov 2023 12:01:51 -0300 Subject: [PATCH 05/16] Move test config at the top of the file --- .../pricing/priceImpact.compare.spec.ts | 64 +++++++++---------- 1 file changed, 30 insertions(+), 34 deletions(-) diff --git a/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts b/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts index 78dc9e972..9f20f7bda 100644 --- a/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts +++ b/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts @@ -1,7 +1,7 @@ // yarn test:only ./src/modules/pricing/priceImpact.compare.spec.ts import { BigNumber, formatFixed, parseFixed } from '@ethersproject/bignumber'; +import { JsonRpcProvider } from '@ethersproject/providers'; import dotenv from 'dotenv'; -import hardhat from 'hardhat'; import { Address, @@ -13,30 +13,36 @@ import { SwapType, } from '@/.'; import { forkSetup, TestPoolHelper } from '@/test/lib/utils'; -import { ADDRESSES, TEST_BLOCK } from '@/test/lib/constants'; +import { TEST_BLOCK } from '@/test/lib/constants'; import { queryBatchSwap } from '../swaps/queryBatchSwap'; dotenv.config(); const { ALCHEMY_URL: jsonRpcUrl } = process.env; -const { ethers } = hardhat; const rpcUrl = 'http://127.0.0.1:8545'; const network = Network.MAINNET; const sdk = new BalancerSDK({ network, rpcUrl }); const { contracts, pricing } = sdk; -const provider = new ethers.providers.JsonRpcProvider(rpcUrl, 1); +const provider = new JsonRpcProvider(rpcUrl, 1); const signer = provider.getSigner(); const { balancerHelpers, vault } = contracts; -// Slots used to set the account balance for each token through hardhat_setStorageAt -// Info fetched using npm package slot20 -const slots = [ADDRESSES[network].WBTC.slot, ADDRESSES[network].WETH.slot]; -const initialBalance = '100000'; -const testPoolId = - '0x5c6ee304399dbdb9c8ef030ab642b10820db8f56000200000000000000000014'; // B_50WBTC_50WETH const blockNumber = TEST_BLOCK[network]; -const slippage = '0'; // does not affect result +const testPoolId = + '0x5c6ee304399dbdb9c8ef030ab642b10820db8f56000200000000000000000014'; // 80BAL/20WETH + +// swap config +const swapAmountFloat = '2'; +const assetInIndex = 1; +const assetOutIndex = 0; + +// single token join config +const joinAmountFloat = '1000'; +const tokenInIndex = 0; + +// unbalanced join config +const amountsInFloat = ['1000', '1000']; describe('Price impact comparison tests', async () => { let pool: PoolWithMethods; @@ -56,27 +62,18 @@ describe('Price impact comparison tests', async () => { // Setup chain beforeEach(async function () { - const balances = pool.tokens.map((token) => - parseFixed(initialBalance, token.decimals).toString() - ); - await forkSetup( - signer, - pool.tokensList, - slots, - balances, - jsonRpcUrl as string, - blockNumber - ); + await forkSetup(signer, [], [], [], jsonRpcUrl as string, blockNumber); pool = await testPoolHelper.getPool(); // update the pool after the forkSetup; }); context('swap', async () => { - const assetInIndex = 1; - const assetOutIndex = 0; let swapAmount: BigNumber; before(() => { - swapAmount = parseFixed('200', pool.tokens[assetInIndex].decimals); // 200 WETH + swapAmount = parseFixed( + swapAmountFloat, + pool.tokens[assetInIndex].decimals + ); }); it('should calculate price impact - spot price method', async () => { @@ -122,7 +119,7 @@ describe('Price impact comparison tests', async () => { ); const priceRatio = parseFloat(spotPrice) / effectivePrice; - const priceImpact = 1 - priceRatio; + const priceImpact = 1 - priceRatio + parseFloat(pool.swapFee); // remove swapFee to have results similar to the UI console.log(`priceImpactSpotPrice: ${priceImpact}`); }); @@ -168,8 +165,7 @@ describe('Price impact comparison tests', async () => { formatFixed(swapAmount, pool.tokens[assetInIndex].decimals) ); - const priceImpactABA = - (initialA - finalA) / initialA / 2 - parseFloat(pool.swapFee); + const priceImpactABA = (initialA - finalA) / initialA / 2; console.log(`priceImpactABA : ${priceImpactABA}`); }); }); @@ -179,8 +175,8 @@ describe('Price impact comparison tests', async () => { let amountIn: BigNumber; before(() => { - tokenIn = pool.tokens[0]; - amountIn = parseFixed('10', tokenIn.decimals); + tokenIn = pool.tokens[tokenInIndex]; + amountIn = parseFixed(joinAmountFloat, tokenIn.decimals); }); it('should calculate price impact - spot price method', async () => { @@ -191,7 +187,7 @@ describe('Price impact comparison tests', async () => { signerAddress, pool.tokensList, amountsIn, - slippage + '0' // slippage ); const priceImpactFloat = parseFloat( @@ -233,8 +229,8 @@ describe('Price impact comparison tests', async () => { let amountsIn: BigNumber[]; before(() => { - amountsIn = pool.tokens.map((token) => - parseFixed('10000', token.decimals) + amountsIn = pool.tokens.map((token, i) => + parseFixed(amountsInFloat[i], token.decimals) ); }); @@ -243,7 +239,7 @@ describe('Price impact comparison tests', async () => { signerAddress, pool.tokensList, amountsIn.map((amount) => amount.toString()), - slippage + '0' // slippage ); const priceImpactFloat = parseFloat( From 9f5605d85a7ebcb370b59b2f381bb5f733be150b Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Thu, 9 Nov 2023 14:58:08 -0300 Subject: [PATCH 06/16] Fix hardcoded token index and decimals --- balancer-js/src/modules/pricing/priceImpact.compare.spec.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts b/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts index 9f20f7bda..97db125c5 100644 --- a/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts +++ b/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts @@ -218,8 +218,10 @@ describe('Price impact comparison tests', async () => { ...exitParams ); - const initialA = parseFloat(formatFixed(amountIn, 8)); - const finalA = parseFloat(formatFixed(amountsOut[0], 8)); + const initialA = parseFloat(formatFixed(amountIn, tokenIn.decimals)); + const finalA = parseFloat( + formatFixed(amountsOut[tokenInIndex], tokenIn.decimals) + ); const priceImpactABA = (initialA - finalA) / initialA / 2; console.log(`priceImpactABA : ${priceImpactABA}`); }); From 9134964e326e23aaa2593e0493120f7e8c640c29 Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Thu, 9 Nov 2023 16:46:52 -0300 Subject: [PATCH 07/16] Rename proportional exit on ComposableStable encoder --- balancer-js/src/modules/exits/exits.module.ts | 2 +- .../pools/pool-types/concerns/composableStable/exit.concern.ts | 2 +- balancer-js/src/modules/relayer/actions.ts | 2 +- balancer-js/src/pool-composable-stable/encoder.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/balancer-js/src/modules/exits/exits.module.ts b/balancer-js/src/modules/exits/exits.module.ts index 7a4ce1f11..ff09479ad 100644 --- a/balancer-js/src/modules/exits/exits.module.ts +++ b/balancer-js/src/modules/exits/exits.module.ts @@ -1132,7 +1132,7 @@ export class Exit { userData = WeightedPoolEncoder.exitExactBPTInForTokensOut(amountIn); } else if (node.type === PoolType.ComposableStable) { userData = - ComposableStablePoolEncoder.exitExactBPTInForAllTokensOut(amountIn); + ComposableStablePoolEncoder.exitExactBPTInForTokensOut(amountIn); } else { // TODO: double check if it's ok to set the Stable Pool Encoder as the default/else case userData = StablePoolEncoder.exitExactBPTInForTokensOut(amountIn); diff --git a/balancer-js/src/modules/pools/pool-types/concerns/composableStable/exit.concern.ts b/balancer-js/src/modules/pools/pool-types/concerns/composableStable/exit.concern.ts index 2d3e9e936..cd316583a 100644 --- a/balancer-js/src/modules/pools/pool-types/concerns/composableStable/exit.concern.ts +++ b/balancer-js/src/modules/pools/pool-types/concerns/composableStable/exit.concern.ts @@ -123,7 +123,7 @@ export class ComposableStablePoolExit implements ExitConcern { bptIn, sortedValues.singleTokenOutIndexWithoutBpt ) - : ComposableStablePoolEncoder.exitExactBPTInForAllTokensOut(bptIn); + : ComposableStablePoolEncoder.exitExactBPTInForTokensOut(bptIn); // MinAmounts needs a value for BPT for encoding const minAmountsOutWithBpt = insert( diff --git a/balancer-js/src/modules/relayer/actions.ts b/balancer-js/src/modules/relayer/actions.ts index 16bc73fd5..b53ed51d7 100644 --- a/balancer-js/src/modules/relayer/actions.ts +++ b/balancer-js/src/modules/relayer/actions.ts @@ -76,7 +76,7 @@ export const exit = ( ); } else { const encoder = isComposable - ? ComposableStablePoolEncoder.exitExactBPTInForAllTokensOut + ? ComposableStablePoolEncoder.exitExactBPTInForTokensOut : StablePoolEncoder.exitExactBPTInForTokensOut; userData = encoder(amount); } diff --git a/balancer-js/src/pool-composable-stable/encoder.ts b/balancer-js/src/pool-composable-stable/encoder.ts index 8b8a182a0..2b2f2d67d 100644 --- a/balancer-js/src/pool-composable-stable/encoder.ts +++ b/balancer-js/src/pool-composable-stable/encoder.ts @@ -99,7 +99,7 @@ export class ComposableStablePoolEncoder { * Encodes the userData parameter for exiting a StablePool by removing tokens in return for an exact amount of BPT * @param bptAmountIn - the amount of BPT to be burned */ - static exitExactBPTInForAllTokensOut = (bptAmountIn: BigNumberish): string => + static exitExactBPTInForTokensOut = (bptAmountIn: BigNumberish): string => defaultAbiCoder.encode( ['uint256', 'uint256'], [ From 8c83585b81029c51fcec117c4093ecfa4c8b6a79 Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Thu, 9 Nov 2023 16:47:28 -0300 Subject: [PATCH 08/16] Refactor price impact tests to support pools with phantom BPT --- .../pricing/priceImpact.compare.spec.ts | 72 +++++++++++-------- 1 file changed, 44 insertions(+), 28 deletions(-) diff --git a/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts b/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts index 97db125c5..b1fe3c971 100644 --- a/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts +++ b/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts @@ -13,7 +13,6 @@ import { SwapType, } from '@/.'; import { forkSetup, TestPoolHelper } from '@/test/lib/utils'; -import { TEST_BLOCK } from '@/test/lib/constants'; import { queryBatchSwap } from '../swaps/queryBatchSwap'; dotenv.config(); @@ -28,21 +27,25 @@ const provider = new JsonRpcProvider(rpcUrl, 1); const signer = provider.getSigner(); const { balancerHelpers, vault } = contracts; -const blockNumber = TEST_BLOCK[network]; +const blockNumber = 18536155; const testPoolId = - '0x5c6ee304399dbdb9c8ef030ab642b10820db8f56000200000000000000000014'; // 80BAL/20WETH + '0x93d199263632a4ef4bb438f1feb99e57b4b5f0bd0000000000000000000005c2'; // 80BAL/20WETH + +/** + * When testing pools with phantom BPT (e.g. ComposableStable), indexes should consider pool tokens with BPT + */ // swap config -const swapAmountFloat = '2'; -const assetInIndex = 1; -const assetOutIndex = 0; +const swapAmountFloat = '200'; +const assetInIndex = 0; +const assetOutIndex = 2; // single token join config const joinAmountFloat = '1000'; const tokenInIndex = 0; // unbalanced join config -const amountsInFloat = ['1000', '1000']; +const amountsInFloat = ['10', '0', '1000']; // should add value for BPT if present describe('Price impact comparison tests', async () => { let pool: PoolWithMethods; @@ -180,12 +183,20 @@ describe('Price impact comparison tests', async () => { }); it('should calculate price impact - spot price method', async () => { + const tokensIn = [...pool.tokensList]; const amountsIn = Array(pool.tokensList.length).fill('0'); - amountsIn[pool.tokensList.indexOf(tokenIn.address)] = amountIn.toString(); + + amountsIn[tokenInIndex] = amountIn.toString(); + + const bptIndex = tokensIn.findIndex((t) => t === pool.address); + if (bptIndex > -1) { + tokensIn.splice(bptIndex, 1); + amountsIn.splice(bptIndex, 1); + } const { priceImpact } = pool.buildJoin( signerAddress, - pool.tokensList, + tokensIn, amountsIn, '0' // slippage ); @@ -228,18 +239,26 @@ describe('Price impact comparison tests', async () => { }); context('unbalanced join - 2 tokens', async () => { + let tokensIn: string[]; let amountsIn: BigNumber[]; - before(() => { + beforeEach(() => { + tokensIn = [...pool.tokensList]; amountsIn = pool.tokens.map((token, i) => parseFixed(amountsInFloat[i], token.decimals) ); }); it('should calculate price impact - spot price method', async () => { + const bptIndex = tokensIn.findIndex((t) => t === pool.address); + if (bptIndex > -1) { + tokensIn.splice(bptIndex, 1); + amountsIn.splice(bptIndex, 1); + } + const { priceImpact } = pool.buildJoin( signerAddress, - pool.tokensList, + tokensIn, amountsIn.map((amount) => amount.toString()), '0' // slippage ); @@ -252,7 +271,7 @@ describe('Price impact comparison tests', async () => { it('should calculate price impact - ABA method', async () => { const maxAmountsInByToken = new Map( - amountsIn.map((a, i) => [pool.tokensList[i], a]) + amountsIn.map((a, i) => [tokensIn[i], a]) ); // query unbalanced join @@ -271,11 +290,11 @@ describe('Price impact comparison tests', async () => { // diff between unbalanced and proportional amounts for token 1 const diffs = amountsOut.map((a, i) => a.sub(amountsIn[i])); - const excessIndex = diffs.findIndex((a) => a.gt(0)); + const excessIndex = diffs.findIndex((a) => a.gt(0)); // token index that has excess amount on proportional compared to unbalanced const otherIndex = diffs.findIndex((a) => a.lt(0)); - const diff1 = amountsOut[excessIndex].sub(amountsIn[excessIndex]); + const diffExcess = amountsOut[excessIndex].sub(amountsIn[excessIndex]); - // swap that diff to token 0 + // swap that diff to token other (non-excess) const returnAmounts = await queryBatchSwap( vault, SwapType.SwapExactIn, @@ -284,24 +303,24 @@ describe('Price impact comparison tests', async () => { poolId: pool.id, assetInIndex: excessIndex, assetOutIndex: otherIndex, - amount: diff1.toString(), + amount: diffExcess.toString(), userData: '0x', }, ], pool.tokensList ); - // calculate final token 0 amount (using sub because returnAmounts[0] is negative) - const token0Final = amountsOut[otherIndex].sub( + // calculate final other token amount (using sub because returnAmounts[0] is negative) + const otherTokenFinal = amountsOut[otherIndex].sub( BigNumber.from(returnAmounts[otherIndex]) ); // diff between unbalanced and proportional amounts for token 0 - const diff0 = amountsIn[otherIndex].sub(token0Final); + const diffOther = amountsIn[otherIndex].sub(otherTokenFinal); - // query join with diff0 in order to get BPT difference between unbalanced and proportional + // query join with diffOther in order to get BPT difference between unbalanced and proportional const diffAmounts = new Map([ - [pool.tokensList[otherIndex], diff0], + [pool.tokensList[otherIndex], diffOther], ]); const { bptOut: bptOutDiff } = await balancerHelpers.callStatic.queryJoin( @@ -310,13 +329,10 @@ describe('Price impact comparison tests', async () => { }) ); - const initialA = parseFloat( - formatFixed(bptOut, pool.tokens[otherIndex].decimals) - ); - const finalA = parseFloat( - formatFixed(bptOut.sub(bptOutDiff), pool.tokens[otherIndex].decimals) - ); - const priceImpactABA = (initialA - finalA) / initialA / 2; + const initialBPT = parseFloat(formatFixed(bptOut, 18)); + const finalBPT = parseFloat(formatFixed(bptOut.sub(bptOutDiff), 18)); + + const priceImpactABA = (initialBPT - finalBPT) / initialBPT / 2; console.log(`priceImpactABA : ${priceImpactABA}`); }); }); From 8bf2608314f2ab5201a55501ea74446eecb4b736 Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Tue, 14 Nov 2023 11:55:24 -0300 Subject: [PATCH 09/16] Add Zen's multiple test plus csv report --- .../pricing/priceImpact.compare.spec.ts | 546 ++++++++++-------- 1 file changed, 307 insertions(+), 239 deletions(-) diff --git a/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts b/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts index b1fe3c971..e8917ba37 100644 --- a/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts +++ b/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts @@ -2,6 +2,7 @@ import { BigNumber, formatFixed, parseFixed } from '@ethersproject/bignumber'; import { JsonRpcProvider } from '@ethersproject/providers'; import dotenv from 'dotenv'; +import * as fs from 'fs'; import { Address, @@ -26,31 +27,60 @@ const { contracts, pricing } = sdk; const provider = new JsonRpcProvider(rpcUrl, 1); const signer = provider.getSigner(); const { balancerHelpers, vault } = contracts; +const csvFilePath = 'results.csv'; +// Write the header to the CSV file +const csvLine = 'action,test,spot price,ABA,error abs,error rel\n'; +fs.writeFileSync(csvFilePath, csvLine, { flag: 'w' }); -const blockNumber = 18536155; +const blockNumber = 18559730; const testPoolId = - '0x93d199263632a4ef4bb438f1feb99e57b4b5f0bd0000000000000000000005c2'; // 80BAL/20WETH + '0x42ed016f826165c2e5976fe5bc3df540c5ad0af700000000000000000000058b'; // 80BAL/20WETH /** * When testing pools with phantom BPT (e.g. ComposableStable), indexes should consider pool tokens with BPT */ // swap config -const swapAmountFloat = '200'; -const assetInIndex = 0; +const swapAmountFloat = '10'; +const swapAmountFloats = [ + swapAmountFloat, + String(Number(swapAmountFloat) * 2), + String(Number(swapAmountFloat) * 5), + String(Number(swapAmountFloat) * 10), + String(Number(swapAmountFloat) * 25), + String(Number(swapAmountFloat) * 50), + String(Number(swapAmountFloat) * 100), +]; +const assetInIndex = 1; const assetOutIndex = 2; // single token join config -const joinAmountFloat = '1000'; -const tokenInIndex = 0; +const joinAmountFloat = '10'; +// const tokenInIndex = 1; +const singleTokenJoinTests = [ + { amountFloat: joinAmountFloat, tokenIndex: 1 }, + { amountFloat: String(Number(joinAmountFloat) * 2), tokenIndex: 1 }, + { amountFloat: String(Number(joinAmountFloat) * 5), tokenIndex: 1 }, + { amountFloat: String(Number(joinAmountFloat) * 10), tokenIndex: 1 }, + { amountFloat: String(Number(joinAmountFloat) * 25), tokenIndex: 1 }, + { amountFloat: String(Number(joinAmountFloat) * 50), tokenIndex: 1 }, + { amountFloat: String(Number(joinAmountFloat) * 100), tokenIndex: 1 }, +]; // unbalanced join config -const amountsInFloat = ['10', '0', '1000']; // should add value for BPT if present +// const amountsInFloat = ['0', '200', '100', '10']; // should add value for BPT if present +const unbalancedJoinTests = [ + { amountsInFloat: ['0', '200', '100', '10'] }, + { amountsInFloat: ['0', '2000', '100', '10'] }, + // Add more test scenarios as needed +]; describe('Price impact comparison tests', async () => { let pool: PoolWithMethods; let signerAddress: Address; let testPoolHelper: TestPoolHelper; + let priceImpactSpot: number; + let priceImpactABA: number; before(async () => { signerAddress = await signer.getAddress(); @@ -69,271 +99,309 @@ describe('Price impact comparison tests', async () => { pool = await testPoolHelper.getPool(); // update the pool after the forkSetup; }); - context('swap', async () => { - let swapAmount: BigNumber; + swapAmountFloats.forEach((swapAmountFloat, index) => { + context('swap', async () => { + let swapAmount: BigNumber; - before(() => { - swapAmount = parseFixed( - swapAmountFloat, - pool.tokens[assetInIndex].decimals - ); - }); - - it('should calculate price impact - spot price method', async () => { - const swapAmounts = await queryBatchSwap( - vault, - SwapType.SwapExactIn, - [ - { - poolId: pool.id, - assetInIndex, - assetOutIndex, - amount: swapAmount.toString(), - userData: '0x', - }, - ], - pool.tokensList - ); - - const amountIn = parseFloat( - formatFixed( - swapAmounts[assetInIndex], + before(() => { + swapAmount = parseFixed( + swapAmountFloat, pool.tokens[assetInIndex].decimals - ) - ); + ); + }); + + after(() => { + const csvLine = `swap,${ + index + 1 + },${priceImpactSpot},${priceImpactABA},${ + priceImpactABA - priceImpactSpot + },${(priceImpactABA - priceImpactSpot) / priceImpactSpot}\n`; + fs.writeFileSync(csvFilePath, csvLine, { flag: 'a' }); + }); + + it(`should calculate price impact - spot price method - Test ${ + index + 1 + }`, async () => { + const swapAmounts = await queryBatchSwap( + vault, + SwapType.SwapExactIn, + [ + { + poolId: pool.id, + assetInIndex, + assetOutIndex, + amount: swapAmount.toString(), + userData: '0x', + }, + ], + pool.tokensList + ); - const amountOut = - -1 * - parseFloat( + const amountIn = parseFloat( formatFixed( - swapAmounts[assetOutIndex], - pool.tokens[assetOutIndex].decimals + swapAmounts[assetInIndex], + pool.tokens[assetInIndex].decimals ) ); - const effectivePrice = amountIn / amountOut; + const amountOut = + -1 * + parseFloat( + formatFixed( + swapAmounts[assetOutIndex], + pool.tokens[assetOutIndex].decimals + ) + ); - const subgraphPool: SubgraphPoolBase = pool as SubgraphPoolBase; + const effectivePrice = amountIn / amountOut; - const spotPrice = await pricing.getSpotPrice( - pool.tokensList[assetInIndex], - pool.tokensList[assetOutIndex], - [subgraphPool] - ); + const subgraphPool: SubgraphPoolBase = pool as SubgraphPoolBase; - const priceRatio = parseFloat(spotPrice) / effectivePrice; - const priceImpact = 1 - priceRatio + parseFloat(pool.swapFee); // remove swapFee to have results similar to the UI - console.log(`priceImpactSpotPrice: ${priceImpact}`); - }); + const spotPrice = await pricing.getSpotPrice( + pool.tokensList[assetInIndex], + pool.tokensList[assetOutIndex], + [subgraphPool] + ); - it('should calculate price impact - ABA method', async () => { - const swapAtoB = await queryBatchSwap( - vault, - SwapType.SwapExactIn, - [ - { - poolId: pool.id, - assetInIndex, - assetOutIndex, - amount: swapAmount.toString(), - userData: '0x', - }, - ], - pool.tokensList - ); - const B = BigNumber.from(-1).mul(swapAtoB[assetOutIndex]); - - const swapBtoA = await queryBatchSwap( - vault, - SwapType.SwapExactIn, - [ - { - poolId: pool.id, - assetInIndex: assetOutIndex, - assetOutIndex: assetInIndex, - amount: B.toString(), - userData: '0x', - }, - ], - pool.tokensList - ); - const finalA = parseFloat( - formatFixed( - BigNumber.from(-1).mul(swapBtoA[assetInIndex]), - pool.tokens[assetInIndex].decimals - ) - ); + const priceRatio = parseFloat(spotPrice) / effectivePrice; + priceImpactSpot = 1 - priceRatio + parseFloat(pool.swapFee); // remove swapFee to have results similar to the UI + console.log(`priceImpactSpotPrice: ${priceImpactSpot}`); + }); + + it(`should calculate price impact - ABA method - Test ${ + index + 1 + }`, async () => { + const swapAtoB = await queryBatchSwap( + vault, + SwapType.SwapExactIn, + [ + { + poolId: pool.id, + assetInIndex, + assetOutIndex, + amount: swapAmount.toString(), + userData: '0x', + }, + ], + pool.tokensList + ); + const B = BigNumber.from(-1).mul(swapAtoB[assetOutIndex]); + + const swapBtoA = await queryBatchSwap( + vault, + SwapType.SwapExactIn, + [ + { + poolId: pool.id, + assetInIndex: assetOutIndex, + assetOutIndex: assetInIndex, + amount: B.toString(), + userData: '0x', + }, + ], + pool.tokensList + ); + const finalA = parseFloat( + formatFixed( + BigNumber.from(-1).mul(swapBtoA[assetInIndex]), + pool.tokens[assetInIndex].decimals + ) + ); - const initialA = parseFloat( - formatFixed(swapAmount, pool.tokens[assetInIndex].decimals) - ); + const initialA = parseFloat( + formatFixed(swapAmount, pool.tokens[assetInIndex].decimals) + ); - const priceImpactABA = (initialA - finalA) / initialA / 2; - console.log(`priceImpactABA : ${priceImpactABA}`); + priceImpactABA = (initialA - finalA) / initialA / 2; + console.log(`priceImpactABA : ${priceImpactABA}`); + }); }); }); - context('single token join', async () => { - let tokenIn: PoolToken; - let amountIn: BigNumber; + singleTokenJoinTests.forEach((test, index) => { + context('single token join', async () => { + let tokenIn: PoolToken; + let amountIn: BigNumber; - before(() => { - tokenIn = pool.tokens[tokenInIndex]; - amountIn = parseFixed(joinAmountFloat, tokenIn.decimals); - }); + before(() => { + tokenIn = pool.tokens[test.tokenIndex]; + amountIn = parseFixed(test.amountFloat, tokenIn.decimals); + }); - it('should calculate price impact - spot price method', async () => { - const tokensIn = [...pool.tokensList]; - const amountsIn = Array(pool.tokensList.length).fill('0'); - - amountsIn[tokenInIndex] = amountIn.toString(); - - const bptIndex = tokensIn.findIndex((t) => t === pool.address); - if (bptIndex > -1) { - tokensIn.splice(bptIndex, 1); - amountsIn.splice(bptIndex, 1); - } - - const { priceImpact } = pool.buildJoin( - signerAddress, - tokensIn, - amountsIn, - '0' // slippage - ); - - const priceImpactFloat = parseFloat( - formatFixed(BigNumber.from(priceImpact), 18) - ); - console.log(`priceImpactSpotPrice: ${priceImpactFloat}`); - }); + after(() => { + const csvLine = `single token join,${ + index + 1 + },${priceImpactSpot},${priceImpactABA},${ + priceImpactABA - priceImpactSpot + },${(priceImpactABA - priceImpactSpot) / priceImpactSpot}\n`; + fs.writeFileSync(csvFilePath, csvLine, { flag: 'a' }); + }); - it('should calculate price impact - ABA method', async () => { - const maxAmountsInByToken = new Map([ - [tokenIn.address, amountIn], - ]); + it('should calculate price impact - spot price method', async () => { + const tokensIn = [...pool.tokensList]; + const amountsIn = Array(pool.tokensList.length).fill('0'); - const joinParams = pool.buildQueryJoinExactIn({ - maxAmountsInByToken, - }); + amountsIn[test.tokenIndex] = amountIn.toString(); // Use the index specified in the test scenario + + const bptIndex = tokensIn.findIndex((t) => t === pool.address); + if (bptIndex > -1) { + tokensIn.splice(bptIndex, 1); + amountsIn.splice(bptIndex, 1); + } - const { bptOut } = await balancerHelpers.callStatic.queryJoin( - ...joinParams - ); + const { priceImpact } = pool.buildJoin( + signerAddress, + tokensIn, + amountsIn, + '0' // slippage + ); - const exitParams = pool.buildQueryExitToSingleToken({ - bptIn: bptOut, - tokenOut: tokenIn.address, + priceImpactSpot = parseFloat( + formatFixed(BigNumber.from(priceImpact), 18) + ); + console.log(`priceImpactSpotPrice: ${priceImpactSpot}`); }); - const { amountsOut } = await balancerHelpers.callStatic.queryExit( - ...exitParams - ); + it('should calculate price impact - ABA method', async () => { + const maxAmountsInByToken = new Map([ + [tokenIn.address, amountIn], + ]); + + const joinParams = pool.buildQueryJoinExactIn({ + maxAmountsInByToken, + }); + + const { bptOut } = await balancerHelpers.callStatic.queryJoin( + ...joinParams + ); - const initialA = parseFloat(formatFixed(amountIn, tokenIn.decimals)); - const finalA = parseFloat( - formatFixed(amountsOut[tokenInIndex], tokenIn.decimals) - ); - const priceImpactABA = (initialA - finalA) / initialA / 2; - console.log(`priceImpactABA : ${priceImpactABA}`); + const exitParams = pool.buildQueryExitToSingleToken({ + bptIn: bptOut, + tokenOut: tokenIn.address, + }); + + const { amountsOut } = await balancerHelpers.callStatic.queryExit( + ...exitParams + ); + + const initialA = parseFloat(formatFixed(amountIn, tokenIn.decimals)); + const finalA = parseFloat( + formatFixed(amountsOut[test.tokenIndex], tokenIn.decimals) // Use the index specified in the test scenario + ); + priceImpactABA = (initialA - finalA) / initialA / 2; + console.log(`priceImpactABA : ${priceImpactABA}`); + }); }); }); - context('unbalanced join - 2 tokens', async () => { - let tokensIn: string[]; - let amountsIn: BigNumber[]; + unbalancedJoinTests.forEach((test, index) => { + context('unbalanced join - 2 tokens', async () => { + let tokensIn: string[]; + let amountsIn: BigNumber[]; - beforeEach(() => { - tokensIn = [...pool.tokensList]; - amountsIn = pool.tokens.map((token, i) => - parseFixed(amountsInFloat[i], token.decimals) - ); - }); + beforeEach(() => { + tokensIn = [...pool.tokensList]; + amountsIn = pool.tokens.map((token, i) => + parseFixed(test.amountsInFloat[i], token.decimals) + ); + }); - it('should calculate price impact - spot price method', async () => { - const bptIndex = tokensIn.findIndex((t) => t === pool.address); - if (bptIndex > -1) { - tokensIn.splice(bptIndex, 1); - amountsIn.splice(bptIndex, 1); - } - - const { priceImpact } = pool.buildJoin( - signerAddress, - tokensIn, - amountsIn.map((amount) => amount.toString()), - '0' // slippage - ); - - const priceImpactFloat = parseFloat( - formatFixed(BigNumber.from(priceImpact), 18) - ); - console.log(`priceImpactSpotPrice: ${priceImpactFloat}`); - }); + after(() => { + const csvLine = `unbalanced join,${ + index + 1 + },${priceImpactSpot},${priceImpactABA},${ + priceImpactABA - priceImpactSpot + },${(priceImpactABA - priceImpactSpot) / priceImpactSpot}\n`; + fs.writeFileSync(csvFilePath, csvLine, { flag: 'a' }); + }); - it('should calculate price impact - ABA method', async () => { - const maxAmountsInByToken = new Map( - amountsIn.map((a, i) => [tokensIn[i], a]) - ); + it('should calculate price impact - spot price method', async () => { + const bptIndex = tokensIn.findIndex((t) => t === pool.address); + if (bptIndex > -1) { + tokensIn.splice(bptIndex, 1); + amountsIn.splice(bptIndex, 1); + } + + const { priceImpact } = pool.buildJoin( + signerAddress, + tokensIn, + amountsIn.map((amount) => amount.toString()), + '0' // slippage + ); - // query unbalanced join - const { bptOut } = await balancerHelpers.callStatic.queryJoin( - ...pool.buildQueryJoinExactIn({ - maxAmountsInByToken, - }) - ); + priceImpactSpot = parseFloat( + formatFixed(BigNumber.from(priceImpact), 18) + ); + console.log(`priceImpactSpotPrice: ${priceImpactSpot}`); + }); - // calculate proportional amounts out - const { amountsOut } = await balancerHelpers.callStatic.queryExit( - ...pool.buildQueryExitProportionally({ - bptIn: bptOut, - }) - ); - - // diff between unbalanced and proportional amounts for token 1 - const diffs = amountsOut.map((a, i) => a.sub(amountsIn[i])); - const excessIndex = diffs.findIndex((a) => a.gt(0)); // token index that has excess amount on proportional compared to unbalanced - const otherIndex = diffs.findIndex((a) => a.lt(0)); - const diffExcess = amountsOut[excessIndex].sub(amountsIn[excessIndex]); - - // swap that diff to token other (non-excess) - const returnAmounts = await queryBatchSwap( - vault, - SwapType.SwapExactIn, - [ - { - poolId: pool.id, - assetInIndex: excessIndex, - assetOutIndex: otherIndex, - amount: diffExcess.toString(), - userData: '0x', - }, - ], - pool.tokensList - ); - - // calculate final other token amount (using sub because returnAmounts[0] is negative) - const otherTokenFinal = amountsOut[otherIndex].sub( - BigNumber.from(returnAmounts[otherIndex]) - ); - - // diff between unbalanced and proportional amounts for token 0 - const diffOther = amountsIn[otherIndex].sub(otherTokenFinal); - - // query join with diffOther in order to get BPT difference between unbalanced and proportional - const diffAmounts = new Map([ - [pool.tokensList[otherIndex], diffOther], - ]); - - const { bptOut: bptOutDiff } = await balancerHelpers.callStatic.queryJoin( - ...pool.buildQueryJoinExactIn({ - maxAmountsInByToken: diffAmounts, - }) - ); - - const initialBPT = parseFloat(formatFixed(bptOut, 18)); - const finalBPT = parseFloat(formatFixed(bptOut.sub(bptOutDiff), 18)); - - const priceImpactABA = (initialBPT - finalBPT) / initialBPT / 2; - console.log(`priceImpactABA : ${priceImpactABA}`); + it('should calculate price impact - ABA method', async () => { + const maxAmountsInByToken = new Map( + amountsIn.map((a, i) => [tokensIn[i], a]) + ); + + // query unbalanced join + const { bptOut } = await balancerHelpers.callStatic.queryJoin( + ...pool.buildQueryJoinExactIn({ + maxAmountsInByToken, + }) + ); + + // calculate proportional amounts out + const { amountsOut } = await balancerHelpers.callStatic.queryExit( + ...pool.buildQueryExitProportionally({ + bptIn: bptOut, + }) + ); + + // diff between unbalanced and proportional amounts for token 1 + const diffs = amountsOut.map((a, i) => a.sub(amountsIn[i])); + const excessIndex = diffs.findIndex((a) => a.gt(0)); // token index that has excess amount on proportional compared to unbalanced + const otherIndex = diffs.findIndex((a) => a.lt(0)); + const diffExcess = amountsOut[excessIndex].sub(amountsIn[excessIndex]); + + // swap that diff to token other (non-excess) + const returnAmounts = await queryBatchSwap( + vault, + SwapType.SwapExactIn, + [ + { + poolId: pool.id, + assetInIndex: excessIndex, + assetOutIndex: otherIndex, + amount: diffExcess.toString(), + userData: '0x', + }, + ], + pool.tokensList + ); + + // calculate final other token amount (using sub because returnAmounts[0] is negative) + const otherTokenFinal = amountsOut[otherIndex].sub( + BigNumber.from(returnAmounts[otherIndex]) + ); + + // diff between unbalanced and proportional amounts for token 0 + const diffOther = amountsIn[otherIndex].sub(otherTokenFinal); + + // query join with diffOther in order to get BPT difference between unbalanced and proportional + const diffAmounts = new Map([ + [pool.tokensList[otherIndex], diffOther], + ]); + + const { bptOut: bptOutDiff } = + await balancerHelpers.callStatic.queryJoin( + ...pool.buildQueryJoinExactIn({ + maxAmountsInByToken: diffAmounts, + }) + ); + + const initialBPT = parseFloat(formatFixed(bptOut, 18)); + const finalBPT = parseFloat(formatFixed(bptOut.sub(bptOutDiff), 18)); + + priceImpactABA = (initialBPT - finalBPT) / initialBPT / 2; + console.log(`priceImpactABA : ${priceImpactABA}`); + }); }); }); }); From 15aa513b971977494607c5e4bb0bfac4c5b2eeb6 Mon Sep 17 00:00:00 2001 From: jogeorgeou Date: Thu, 16 Nov 2023 15:53:40 -0500 Subject: [PATCH 10/16] Expand test report details Writes the token addresses, balances in pool, and relative proportion being added or swapped in each report. This puts each test in perspective to focus on practical scenarios. May need to roll back some changes in yarn and package. results2.csv can be written over or deleted. --- .DS_Store | Bin 0 -> 8196 bytes balancer-js/package.json | 4 +- balancer-js/results2.csv | 113 ++++++++++++++++++ .../pricing/priceImpact.compare.spec.ts | 70 ++++++++++- balancer-js/yarn.lock | 11 +- 5 files changed, 190 insertions(+), 8 deletions(-) create mode 100644 .DS_Store create mode 100644 balancer-js/results2.csv diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..aad9d43c910d2e358266626103f326d60d8bf551 GIT binary patch literal 8196 zcmeHMU2GIp6u#fIz>FQ}6eyGxx(h2m>Iy9dLPcO#C@_?ku5&`txEy=O*`_ zIrseBIcL6eZ|{~dhL(cf$XFd?Os3AMRz<^28kh5aLz9A;N}?cp#%z{j2FtVi*xnno z!-+5hVFtnsgc%4k5N6<3$N-($yvdWC`$8IyVFtns{4X=W_lFpDPLly06V%^2Xz;H9 zMEMoKZ}d#}0N*AS&}2Zz1ochHr?@>JFhy|1fG{U{jH?q(26RkNVa_1T8G@A&+)&`J zPIfV0ogpb`IEEPrGjL-Dc==SZEXy#9`t|pBH(PQ?vX+x2jnml?%XGblhVzgrDyK}H zCd+b_yel>2lu};CE4VG0`~c^=9mmR+pEKEB(>X*(*zc7cjT5E& zT_^9g`pyP5t>7Bl4f16cjW+T~u4eMpx<Ll6UI#GM$djEp=ZKsgK+x%L9DAHE+-;rq!j9 zyA>@Xce|7b;Ub|fS2S1Y-bY_um^P|SvZgCNRwip$Vrq@LR@OR{zM_awOs-Sc%QZ+S z>6|k>Oz-WA>13ou);^IR;cIWrxL((YVbk(FinjVlWCx$$sOyFv1QBVEbjaFSx!)bi zdIMIUy;z-|n|gpCsR;~++H7*FFUp24$t5y$ZoUcsw)18?IU zoW{HO6ld`@zQIL&hs*dLKj3HlE-?wxENQ;9K&qD-rIpe;sZHvX`lSI8jZ`kIfG@`= z?V_hi_6;hmVBe5lzjmbh4s}8UP`lO*Up(6LcAN78fO@u2I+@13msL>uO3uFJpLM<1tHjNj6e2!}`T%<;|DO5OuU9yzesZ=zA zy*Ck!Y7*6|U>h2vs#ZajsQ9+46T~85n(tRtt&(a|$TmDkEaTgO;9J|s6R$A&?_>Q> zk^Tj{z%H@N>?d{=Q&9yCQ7pr9tRh@Lgw5!{R&)}!)9A;5kMBK%?!DLt4@E-w0mAs> zcmhx22%f@ocpfkKIDgs4`D-|VH}Muu;uOx{eSClq@ew}8=lBwr@Z$tDcb0K1D6UM7 z=3**uTaLYlG|IIw-uU+AD#WYT@%#U#$$$U9eFF^NJj_6tfxpZED%(iPc% D { + fs.writeFileSync(csvFilePath, `${header}\n`, { flag: 'a' }); +}; const blockNumber = 18559730; const testPoolId = @@ -110,13 +113,30 @@ describe('Price impact comparison tests', async () => { ); }); - after(() => { + after(async () => { const csvLine = `swap,${ index + 1 },${priceImpactSpot},${priceImpactABA},${ priceImpactABA - priceImpactSpot },${(priceImpactABA - priceImpactSpot) / priceImpactSpot}\n`; fs.writeFileSync(csvFilePath, csvLine, { flag: 'a' }); + + writeNewTable('Swap Summary'); + + // Query and write the token balances + for (let i = 0; i < pool.tokensList.length; i++) { + const token = pool.tokensList[i]; + const amount = + i === assetInIndex ? swapAmountFloats[index].toString() : '0'; + const balance = await pool.tokens[i].balance; + const relativeValue = (Number(amount) / Number(balance)).toString(); + fs.writeFileSync( + csvFilePath, + `${token},${amount},${balance.toString()},${relativeValue}\n`, + { flag: 'a' } + ); + } + fs.writeFileSync(csvFilePath, '\n', { flag: 'a' }); }); it(`should calculate price impact - spot price method - Test ${ @@ -228,13 +248,34 @@ describe('Price impact comparison tests', async () => { amountIn = parseFixed(test.amountFloat, tokenIn.decimals); }); - after(() => { + after(async () => { const csvLine = `single token join,${ index + 1 },${priceImpactSpot},${priceImpactABA},${ priceImpactABA - priceImpactSpot },${(priceImpactABA - priceImpactSpot) / priceImpactSpot}\n`; fs.writeFileSync(csvFilePath, csvLine, { flag: 'a' }); + + writeNewTable('Single-Sided Join Summary'); + + // Query and write the token balances for single-sided join summary + for (let i = 0; i < pool.tokensList.length; i++) { + const token = pool.tokensList[i]; + const amount = + i === singleTokenJoinTests[i].tokenIndex + ? singleTokenJoinTests[index].amountFloat + : '0'; + const balance = await pool.tokens[i].balance; + const relativeValue = (Number(amount) / Number(balance)).toString(); + fs.writeFileSync( + csvFilePath, + `${token},${amount},${balance.toString()},${relativeValue}\n`, + { flag: 'a' } + ); + } + + // Write an empty line after single-sided join summary + fs.writeFileSync(csvFilePath, '\n', { flag: 'a' }); }); it('should calculate price impact - spot price method', async () => { @@ -306,13 +347,32 @@ describe('Price impact comparison tests', async () => { ); }); - after(() => { + after(async () => { const csvLine = `unbalanced join,${ index + 1 },${priceImpactSpot},${priceImpactABA},${ priceImpactABA - priceImpactSpot },${(priceImpactABA - priceImpactSpot) / priceImpactSpot}\n`; fs.writeFileSync(csvFilePath, csvLine, { flag: 'a' }); + + // Write unbalanced join summary table + writeNewTable('Unbalanced Join Summary'); + + // Query and write the token balances for unbalanced join summary + for (let i = 0; i < pool.tokensList.length; i++) { + const token = pool.tokensList[i]; + const amount = unbalancedJoinTests[index].amountsInFloat[i]; + const balance = await pool.tokens[i].balance; + const relativeValue = (Number(amount) / Number(balance)).toString(); + fs.writeFileSync( + csvFilePath, + `${token},${amount},${balance.toString()},${relativeValue}\n`, + { flag: 'a' } + ); + } + + // Write an empty line after unbalanced join summary + fs.writeFileSync(csvFilePath, '\n', { flag: 'a' }); }); it('should calculate price impact - spot price method', async () => { diff --git a/balancer-js/yarn.lock b/balancer-js/yarn.lock index afb0ee1af..8109cde3b 100644 --- a/balancer-js/yarn.lock +++ b/balancer-js/yarn.lock @@ -6006,7 +6006,7 @@ ts-node@^10.9.1: v8-compile-cache-lib "^3.0.1" yn "3.1.1" -tsconfig-paths@^3.14.1, tsconfig-paths@^3.5.0: +tsconfig-paths@^3.5.0: version "3.14.1" resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.14.1.tgz#ba0734599e8ea36c862798e920bcf163277b137a" integrity sha512-fxDhWnFSLt3VuTwtvJt5fpwxBHg5AdKWMsgcPOOIilyjymcYVZoCQF8fvFRezCNfblEXmi+PcM1eYHeOAgXCOQ== @@ -6016,6 +6016,15 @@ tsconfig-paths@^3.14.1, tsconfig-paths@^3.5.0: minimist "^1.2.6" strip-bom "^3.0.0" +tsconfig-paths@^4.2.0: + version "4.2.0" + resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-4.2.0.tgz#ef78e19039133446d244beac0fd6a1632e2d107c" + integrity sha512-NoZ4roiN7LnbKn9QqE1amc9DJfzvZXxF4xDavcOWt1BPkdx+m+0gJuPM+S0vCe7zTJMYUP0R8pO2XMr+Y8oLIg== + dependencies: + json5 "^2.2.2" + minimist "^1.2.6" + strip-bom "^3.0.0" + tslib@^1.8.1, tslib@^1.9.3: version "1.14.1" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00" From db5e58220586be93457188f7d2a398c1ec35d6b1 Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Fri, 17 Nov 2023 15:30:09 -0300 Subject: [PATCH 11/16] Update tests with 2 token pool (while more tokens are not supported) --- balancer-js/results2.csv | 150 ++++++++---------- .../pricing/priceImpact.compare.spec.ts | 25 +-- 2 files changed, 83 insertions(+), 92 deletions(-) diff --git a/balancer-js/results2.csv b/balancer-js/results2.csv index 9689b08b0..aaa650e27 100644 --- a/balancer-js/results2.csv +++ b/balancer-js/results2.csv @@ -1,113 +1,103 @@ action,test,spot price,ABA,error abs,error rel, -swap,1,0.00040377556888164767,0.00040370224878127914,-7.332010036853161e-8,-0.0001815862722244663 +swap,1,0.00010203132704046372,0.0001020165954047414,-1.4731635722319762e-8,-0.00014438345701881804 Swap Summary -0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 -0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,10,3049.113080910972561465,0.0032796422220629272 -0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 -0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,10,6362.008495713109070421,0.0015718306579971192 +0x93d199263632a4ef4bb438f1feb99e57b4b5f0bd,0,2596148429267497.565961631357824627,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,2396.382388769465741917,0 -swap,2,0.00040752761462463616,0.00040748466224682645,-4.2952377809709914e-8,-0.00010539746576258964 +swap,2,0.00010408136281737637,0.00010403844483262148,-4.291798475488599e-8,-0.0004123503343263376 Swap Summary -0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 -0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,20,3049.113080910972561465,0.0065592844441258544 -0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 -0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,20,6362.008495713109070421,0.0031436613159942384 +0x93d199263632a4ef4bb438f1feb99e57b4b5f0bd,0,2596148429267497.565961631357824627,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,2396.382388769465741917,0 -swap,3,0.00041865039101878187,0.00041883520209616163,1.848110773797619e-7,0.00044144489374541327 +swap,3,0.00011034651005504817,0.00011010820494391283,-2.3830511113533842e-7,-0.0021596071413264996 Swap Summary -0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 -0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,50,3049.113080910972561465,0.016398211110314635 -0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 -0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,50,6362.008495713109070421,0.007859153289985597 +0x93d199263632a4ef4bb438f1feb99e57b4b5f0bd,0,2596148429267497.565961631357824627,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,2396.382388769465741917,0 -swap,4,0.0004367569669131873,0.0004377776577118198,0.0000010206907986324491,0.002336976570393961 +swap,4,0.00012118944764728515,0.00012025470167984054,-9.347459674446094e-7,-0.007713097019512238 Swap Summary -0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 -0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,100,3049.113080910972561465,0.03279642222062927 -0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 -0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,100,6362.008495713109070421,0.015718306579971194 +0x93d199263632a4ef4bb438f1feb99e57b4b5f0bd,0,2596148429267497.565961631357824627,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,2396.382388769465741917,0 -swap,5,0.0004880753174956617,0.0004950607027807906,0.000006985385285128876,0.014312105191000499 +swap,5,0.00015710608274611672,0.0001512385280007038,-0.0000058675547454129125,-0.03734772481658063 Swap Summary -0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 -0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,250,3049.113080910972561465,0.08199105555157317 -0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 -0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,250,6362.008495713109070421,0.03929576644992799 +0x93d199263632a4ef4bb438f1feb99e57b4b5f0bd,0,2596148429267497.565961631357824627,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,2396.382388769465741917,0 -swap,6,0.0005649246215843502,0.0005938876298481546,0.000028963008263804368,0.0512688014598773 +swap,6,0.0002314821066110694,0.00020698231852213668,-0.00002449978808893272,-0.10583879872018215 Swap Summary -0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 -0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,500,3049.113080910972561465,0.16398211110314634 -0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 -0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,500,6362.008495713109070421,0.07859153289985597 +0x93d199263632a4ef4bb438f1feb99e57b4b5f0bd,0,2596148429267497.565961631357824627,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,2396.382388769465741917,0 -swap,7,0.0006937172565830037,0.0008207671867847921,0.00012704993020178838,0.18314367848882648 +swap,7,0.000479722116118808,0.00035992193995207345,-0.00011980017616673456,-0.24972827422670846 Swap Summary -0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 -0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,1000,3049.113080910972561465,0.3279642222062927 -0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 -0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,1000,6362.008495713109070421,0.15718306579971195 +0x93d199263632a4ef4bb438f1feb99e57b4b5f0bd,0,2596148429267497.565961631357824627,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,2396.382388769465741917,0 -single token join,1,0.000299821876819659,0.0002997818706826472,-4.000613701183068e-8,-0.00013343301508279907 +single token join,1,0.0000248560962244,0.00002485579400062221,-3.0222377778963165e-10,-0.000012158939805396856 Single-Sided Join Summary -0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 -0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,10,3049.113080910972561465,0.0032796422220629272 -0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 -0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,10,6362.008495713109070421,0.0015718306579971192 +0x93d199263632a4ef4bb438f1feb99e57b4b5f0bd,0,2596148429267497.565961631357824627,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,2396.382388769465741917,0 -single token join,2,0.000301646893391609,0.00030162116023273454,-2.573315887444529e-8,-0.00008530888080799017 +single token join,2,0.000024979837617604,0.000024979552376258597,-2.852413454022015e-10,-0.000011418863075442245 Single-Sided Join Summary -0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 -0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,20,3049.113080910972561465,0.0065592844441258544 -0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 -0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,20,6362.008495713109070421,0.0031436613159942384 +0x93d199263632a4ef4bb438f1feb99e57b4b5f0bd,0,2596148429267497.565961631357824627,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,2396.382388769465741917,0 -single token join,3,0.000307064127222337,0.00030714052265715,7.639543481299067e-8,0.00024879309577466454 +single token join,3,0.000025350982252748,0.00002535082814219436,-1.5411055364041915e-10,-0.000006079076230812076 Single-Sided Join Summary -0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 -0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,50,3049.113080910972561465,0.016398211110314635 -0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 -0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,50,6362.008495713109070421,0.007859153289985597 +0x93d199263632a4ef4bb438f1feb99e57b4b5f0bd,0,2596148429267497.565961631357824627,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,2396.382388769465741917,0 -single token join,4,0.000315905711879544,0.0003163503571391857,4.446452596417231e-7,0.001407525229588973 +single token join,4,0.000025969295166748,0.00002596962698859784,3.3182184983995334e-10,0.00001277746845685784 Single-Sided Join Summary -0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 -0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,100,3049.113080910972561465,0.03279642222062927 -0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 -0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,100,6362.008495713109070421,0.015718306579971194 +0x93d199263632a4ef4bb438f1feb99e57b4b5f0bd,0,2596148429267497.565961631357824627,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,2396.382388769465741917,0 -single token join,5,0.000341126126129627,0.00034417624561956475,0.0000030501194899377397,0.008941324795447366 +single token join,5,0.000027822340587477,0.000027826140328045314,3.799740568314404e-9,0.00013657156400510352 Single-Sided Join Summary -0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 -0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,250,3049.113080910972561465,0.08199105555157317 -0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 -0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,250,6362.008495713109070421,0.03929576644992799 +0x93d199263632a4ef4bb438f1feb99e57b4b5f0bd,0,2596148429267497.565961631357824627,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,2396.382388769465741917,0 -single token join,6,0.000379371869200906,0.0003919909344199368,0.000012619065219030814,0.033263049381102285 +single token join,6,0.000030904849593443,0.00003092119674937521,1.634715593220996e-8,0.0005289511564449836 Single-Sided Join Summary -0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 -0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,500,3049.113080910972561465,0.16398211110314634 -0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 -0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,500,6362.008495713109070421,0.07859153289985597 +0x93d199263632a4ef4bb438f1feb99e57b4b5f0bd,0,2596148429267497.565961631357824627,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,2396.382388769465741917,0 -single token join,7,0.00044486981991085,0.00050014069422582,0.00005527087431496998,0.12424055721749348 +single token join,7,0.000037050427523012,0.00003711831248284625,6.788495983425205e-8,0.00183223148483479 Single-Sided Join Summary -0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 -0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,1000,3049.113080910972561465,0.3279642222062927 -0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 -0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,1000,6362.008495713109070421,0.15718306579971195 +0x93d199263632a4ef4bb438f1feb99e57b4b5f0bd,0,2596148429267497.565961631357824627,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,2396.382388769465741917,0 -unbalanced join,1,0.000178526680305002,0.03263980055813362,0.032461273877828614,181.82869822241975 +unbalanced join,1,0.000022327376681204,0.00002231709619529593,-1.0280485908070958e-8,-0.0004604430719675834 Unbalanced Join Summary -0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 -0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,200,3049.113080910972561465,0.06559284444125854 -0xac3e018457b222d93114458476f3e3416abbe38f,100,8353.098667955846370862,0.011971605265914068 -0xae78736cd615f374d3085123a210448e74fc6393,10,1210.62732888482209938,0.00826018028951285 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,200,6362.008495713109070421,0.03143661315994239 +0x93d199263632a4ef4bb438f1feb99e57b4b5f0bd,0,2596148429267497.565961631357824627,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,10,2396.382388769465741917,0.004172956722960632 -unbalanced join,2,0.000507605549763369,0.04657651569142629,0.04606891014166292,90.75730193087706 +unbalanced join,2,0.000047998171932481,0.00004598857211443448,-0.0000020095998180465167,-0.041868257417666234 Unbalanced Join Summary -0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 -0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,2000,3049.113080910972561465,0.6559284444125854 -0xac3e018457b222d93114458476f3e3416abbe38f,100,8353.098667955846370862,0.011971605265914068 -0xae78736cd615f374d3085123a210448e74fc6393,10,1210.62732888482209938,0.00826018028951285 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,2000,6362.008495713109070421,0.3143661315994239 +0x93d199263632a4ef4bb438f1feb99e57b4b5f0bd,0,2596148429267497.565961631357824627,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,10,2396.382388769465741917,0.004172956722960632 + +unbalanced join,3,0.000072410665828736,0.00006546308697802712,-0.000006947578850708875,-0.09594689913694654 +Unbalanced Join Summary +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,4000,6362.008495713109070421,0.6287322631988478 +0x93d199263632a4ef4bb438f1feb99e57b4b5f0bd,0,2596148429267497.565961631357824627,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,10,2396.382388769465741917,0.004172956722960632 diff --git a/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts b/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts index ad115a423..c86008e52 100644 --- a/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts +++ b/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts @@ -37,7 +37,7 @@ const writeNewTable = (header: string) => { const blockNumber = 18559730; const testPoolId = - '0x42ed016f826165c2e5976fe5bc3df540c5ad0af700000000000000000000058b'; // 80BAL/20WETH + '0x93d199263632a4ef4bb438f1feb99e57b4b5f0bd0000000000000000000005c2'; // 80BAL/20WETH /** * When testing pools with phantom BPT (e.g. ComposableStable), indexes should consider pool tokens with BPT @@ -54,27 +54,28 @@ const swapAmountFloats = [ String(Number(swapAmountFloat) * 50), String(Number(swapAmountFloat) * 100), ]; -const assetInIndex = 1; +const assetInIndex = 0; const assetOutIndex = 2; // single token join config const joinAmountFloat = '10'; -// const tokenInIndex = 1; +const tokenIndex = 0; const singleTokenJoinTests = [ - { amountFloat: joinAmountFloat, tokenIndex: 1 }, - { amountFloat: String(Number(joinAmountFloat) * 2), tokenIndex: 1 }, - { amountFloat: String(Number(joinAmountFloat) * 5), tokenIndex: 1 }, - { amountFloat: String(Number(joinAmountFloat) * 10), tokenIndex: 1 }, - { amountFloat: String(Number(joinAmountFloat) * 25), tokenIndex: 1 }, - { amountFloat: String(Number(joinAmountFloat) * 50), tokenIndex: 1 }, - { amountFloat: String(Number(joinAmountFloat) * 100), tokenIndex: 1 }, + { amountFloat: joinAmountFloat, tokenIndex }, + { amountFloat: String(Number(joinAmountFloat) * 2), tokenIndex }, + { amountFloat: String(Number(joinAmountFloat) * 5), tokenIndex }, + { amountFloat: String(Number(joinAmountFloat) * 10), tokenIndex }, + { amountFloat: String(Number(joinAmountFloat) * 25), tokenIndex }, + { amountFloat: String(Number(joinAmountFloat) * 50), tokenIndex }, + { amountFloat: String(Number(joinAmountFloat) * 100), tokenIndex }, ]; // unbalanced join config // const amountsInFloat = ['0', '200', '100', '10']; // should add value for BPT if present const unbalancedJoinTests = [ - { amountsInFloat: ['0', '200', '100', '10'] }, - { amountsInFloat: ['0', '2000', '100', '10'] }, + { amountsInFloat: ['200', '0', '10'] }, + { amountsInFloat: ['2000', '0', '10'] }, + { amountsInFloat: ['4000', '0', '10'] }, // Add more test scenarios as needed ]; From 396aa3608549478ce6d60ffe1963a48b7ee00b7e Mon Sep 17 00:00:00 2001 From: jogeorgeou Date: Mon, 20 Nov 2023 08:33:42 -0500 Subject: [PATCH 12/16] First set weighted pool tests Set of tests with printed CSVs for BAL/WETH and COIL/USDC in each direction of swaps, single side, and unbalanced deposits. --- .DS_Store | Bin 8196 -> 8196 bytes balancer-js/50COIL50USDC_COIL.csv | 96 ++++++++++++++++++ balancer-js/50COIL50USDC_USDC.csv | 96 ++++++++++++++++++ balancer-js/80BAL20WETH_BAL.csv | 96 ++++++++++++++++++ balancer-js/80BAL20WETH_WETH.csv | 96 ++++++++++++++++++ .../pricing/priceImpact.compare.spec.ts | 22 ++-- 6 files changed, 396 insertions(+), 10 deletions(-) create mode 100644 balancer-js/50COIL50USDC_COIL.csv create mode 100644 balancer-js/50COIL50USDC_USDC.csv create mode 100644 balancer-js/80BAL20WETH_BAL.csv create mode 100644 balancer-js/80BAL20WETH_WETH.csv diff --git a/.DS_Store b/.DS_Store index aad9d43c910d2e358266626103f326d60d8bf551..b3556c68fc501a4ba8ec6e77d4688238bb72d1e2 100644 GIT binary patch delta 287 zcmZp1XmQwJD8RU5vXMX`w?uWdk%^^_f{~@sjs4b56?1 zPhwzT)|f0PD9I8U&J(#=Pf(1Bn*j=x9W*9K2p?AtWD0_aFfl@9qF_p(;vpa-C&!6! zGtLE?CB`oA;pySUV>($+aN%YRQ4U5FBVEK+D?ULp&jj)JkV<>Yk&(v01cPYK8~_DtpxkmAWHE^|)G z$xmWnU^bpCASlTa9>Ei}SyxbuNyH)L0RspqJ7|Du24x0@$$rAeRehPFn4%# { const blockNumber = 18559730; const testPoolId = - '0x93d199263632a4ef4bb438f1feb99e57b4b5f0bd0000000000000000000005c2'; // 80BAL/20WETH + '0x42fbd9f666aacc0026ca1b88c94259519e03dd67000200000000000000000507'; // 80BAL/20WETH /** * When testing pools with phantom BPT (e.g. ComposableStable), indexes should consider pool tokens with BPT */ // swap config -const swapAmountFloat = '10'; +const swapAmountFloat = '500'; const swapAmountFloats = [ swapAmountFloat, String(Number(swapAmountFloat) * 2), @@ -54,12 +54,12 @@ const swapAmountFloats = [ String(Number(swapAmountFloat) * 50), String(Number(swapAmountFloat) * 100), ]; -const assetInIndex = 0; -const assetOutIndex = 2; +const assetInIndex = 1; +const assetOutIndex = 0; // single token join config -const joinAmountFloat = '10'; -const tokenIndex = 0; +const joinAmountFloat = '500'; +const tokenIndex = 1; const singleTokenJoinTests = [ { amountFloat: joinAmountFloat, tokenIndex }, { amountFloat: String(Number(joinAmountFloat) * 2), tokenIndex }, @@ -73,9 +73,11 @@ const singleTokenJoinTests = [ // unbalanced join config // const amountsInFloat = ['0', '200', '100', '10']; // should add value for BPT if present const unbalancedJoinTests = [ - { amountsInFloat: ['200', '0', '10'] }, - { amountsInFloat: ['2000', '0', '10'] }, - { amountsInFloat: ['4000', '0', '10'] }, + { amountsInFloat: ['10', '10'] }, + { amountsInFloat: ['10', '100'] }, + { amountsInFloat: ['10', '1000'] }, + { amountsInFloat: ['10', '10000'] }, + { amountsInFloat: ['10', '100000'] }, // Add more test scenarios as needed ]; From cb5a5ff42c68d573fa5354a487893e18e1d393e3 Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Tue, 21 Nov 2023 11:20:05 -0300 Subject: [PATCH 13/16] Add generalized approach for unbalanced join --- balancer-js/src/lib/utils/math.ts | 6 + .../pricing/priceImpact.compare.spec.ts | 167 ++++++++++++------ balancer-js/wstETH-rETH-sfrxETH.csv | 120 +++++++++++++ 3 files changed, 242 insertions(+), 51 deletions(-) create mode 100644 balancer-js/wstETH-rETH-sfrxETH.csv diff --git a/balancer-js/src/lib/utils/math.ts b/balancer-js/src/lib/utils/math.ts index e4ea33b33..00b80ec21 100644 --- a/balancer-js/src/lib/utils/math.ts +++ b/balancer-js/src/lib/utils/math.ts @@ -50,3 +50,9 @@ export function formatFromBigInt18(value: bigint): string { * Like parseEther but for numbers. Converts floating point to BigNumber using 18 decimals */ export const bn = (value: number): BigNumber => _parseFixed(`${value}`, 18); + +export const min = (values: BigNumber[]): BigNumber => + values.reduce((a, b) => (a.lt(b) ? a : b)); + +export const max = (values: BigNumber[]): BigNumber => + values.reduce((a, b) => (a.gt(b) ? a : b)); diff --git a/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts b/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts index 7936dbda9..510ccf2b4 100644 --- a/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts +++ b/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts @@ -7,14 +7,18 @@ import * as fs from 'fs'; import { Address, BalancerSDK, + BatchSwapStep, Network, PoolToken, PoolWithMethods, SubgraphPoolBase, SwapType, + max, + min, } from '@/.'; import { forkSetup, TestPoolHelper } from '@/test/lib/utils'; import { queryBatchSwap } from '../swaps/queryBatchSwap'; +import { Zero } from '@ethersproject/constants'; dotenv.config(); @@ -27,7 +31,7 @@ const { contracts, pricing } = sdk; const provider = new JsonRpcProvider(rpcUrl, 1); const signer = provider.getSigner(); const { balancerHelpers, vault } = contracts; -const csvFilePath = '50COIL50USDC_USDC.csv'; +const csvFilePath = 'wstETH-rETH-sfrxETH.csv'; // Write the header to the CSV file const csvLine = 'action,test,spot price,ABA,error abs,error rel,\n'; fs.writeFileSync(csvFilePath, csvLine, { flag: 'w' }); @@ -37,14 +41,14 @@ const writeNewTable = (header: string) => { const blockNumber = 18559730; const testPoolId = - '0x42fbd9f666aacc0026ca1b88c94259519e03dd67000200000000000000000507'; // 80BAL/20WETH + '0x42ed016f826165c2e5976fe5bc3df540c5ad0af700000000000000000000058b'; // 80BAL/20WETH /** * When testing pools with phantom BPT (e.g. ComposableStable), indexes should consider pool tokens with BPT */ // swap config -const swapAmountFloat = '500'; +const swapAmountFloat = '10'; const swapAmountFloats = [ swapAmountFloat, String(Number(swapAmountFloat) * 2), @@ -55,10 +59,10 @@ const swapAmountFloats = [ String(Number(swapAmountFloat) * 100), ]; const assetInIndex = 1; -const assetOutIndex = 0; +const assetOutIndex = 2; // single token join config -const joinAmountFloat = '500'; +const joinAmountFloat = '10'; const tokenIndex = 1; const singleTokenJoinTests = [ { amountFloat: joinAmountFloat, tokenIndex }, @@ -73,11 +77,9 @@ const singleTokenJoinTests = [ // unbalanced join config // const amountsInFloat = ['0', '200', '100', '10']; // should add value for BPT if present const unbalancedJoinTests = [ - { amountsInFloat: ['10', '10'] }, - { amountsInFloat: ['10', '100'] }, - { amountsInFloat: ['10', '1000'] }, - { amountsInFloat: ['10', '10000'] }, - { amountsInFloat: ['10', '100000'] }, + { amountsInFloat: ['0', '10', '100', '1000'] }, + { amountsInFloat: ['0', '100', '1000', '10'] }, + { amountsInFloat: ['0', '1000', '100', '10'] }, // Add more test scenarios as needed ]; @@ -339,7 +341,7 @@ describe('Price impact comparison tests', async () => { }); unbalancedJoinTests.forEach((test, index) => { - context('unbalanced join - 2 tokens', async () => { + context('unbalanced join - generalized (multi-token)', async () => { let tokensIn: string[]; let amountsIn: BigNumber[]; @@ -398,7 +400,7 @@ describe('Price impact comparison tests', async () => { console.log(`priceImpactSpotPrice: ${priceImpactSpot}`); }); - it('should calculate price impact - ABA method', async () => { + it('should calculate price impact - ABA method - generalized (multi-token)', async () => { const maxAmountsInByToken = new Map( amountsIn.map((a, i) => [tokensIn[i], a]) ); @@ -419,50 +421,113 @@ describe('Price impact comparison tests', async () => { // diff between unbalanced and proportional amounts for token 1 const diffs = amountsOut.map((a, i) => a.sub(amountsIn[i])); - const excessIndex = diffs.findIndex((a) => a.gt(0)); // token index that has excess amount on proportional compared to unbalanced - const otherIndex = diffs.findIndex((a) => a.lt(0)); - const diffExcess = amountsOut[excessIndex].sub(amountsIn[excessIndex]); - - // swap that diff to token other (non-excess) - const returnAmounts = await queryBatchSwap( - vault, - SwapType.SwapExactIn, - [ - { - poolId: pool.id, - assetInIndex: excessIndex, - assetOutIndex: otherIndex, - amount: diffExcess.toString(), - userData: '0x', - }, - ], - pool.tokensList - ); - - // calculate final other token amount (using sub because returnAmounts[0] is negative) - const otherTokenFinal = amountsOut[otherIndex].sub( - BigNumber.from(returnAmounts[otherIndex]) - ); - // diff between unbalanced and proportional amounts for token 0 - const diffOther = amountsIn[otherIndex].sub(otherTokenFinal); - - // query join with diffOther in order to get BPT difference between unbalanced and proportional - const diffAmounts = new Map([ - [pool.tokensList[otherIndex], diffOther], - ]); + const diffBPTs: BigNumber[] = []; + for (let i = 0; i < diffs.length; i++) { + if (diffs[i].eq(Zero)) { + diffBPTs.push(Zero); + } else { + const diffQuery = await balancerHelpers.callStatic.queryJoin( + ...pool.buildQueryJoinExactIn({ + maxAmountsInByToken: new Map([ + [tokensIn[i], diffs[i].abs()], + ]), + }) + ); + const diffBPT = diffQuery.bptOut.mul(diffs[i].gte(0) ? 1 : -1); + diffBPTs.push(diffBPT); + } + } + let minPositiveDiffIndex = 0; + let minNegativeDiffIndex = 1; - const { bptOut: bptOutDiff } = - await balancerHelpers.callStatic.queryJoin( - ...pool.buildQueryJoinExactIn({ - maxAmountsInByToken: diffAmounts, - }) + const nonZeroDiffs = diffs.filter((a) => !a.eq(Zero)); + for (let i = 0; i < nonZeroDiffs.length - 1; i++) { + minPositiveDiffIndex = diffBPTs.findIndex((diffBPT) => + diffBPT.eq(min(diffBPTs.filter((a) => a.gt(0)))) ); + minNegativeDiffIndex = diffBPTs.findIndex((diffBPT) => + diffBPT.eq(max(diffBPTs.filter((a) => a.lt(0)))) + ); + + let returnAmounts: string[]; + if ( + diffBPTs[minPositiveDiffIndex] < + diffBPTs[minNegativeDiffIndex].abs() + ) { + // swap that diff to token other (non-excess) + returnAmounts = await queryBatchSwap( + vault, + SwapType.SwapExactIn, + [ + { + poolId: pool.id, + assetInIndex: minPositiveDiffIndex, + assetOutIndex: minNegativeDiffIndex, + amount: diffs[minPositiveDiffIndex].toString(), + userData: '0x', + }, + ], + pool.tokensList + ); + diffs[minPositiveDiffIndex] = Zero; + diffBPTs[minPositiveDiffIndex] = Zero; + diffs[minNegativeDiffIndex] = diffs[minNegativeDiffIndex].sub( + BigNumber.from(returnAmounts[minNegativeDiffIndex]) + ); + const diffQuery = await balancerHelpers.callStatic.queryJoin( + ...pool.buildQueryJoinExactIn({ + maxAmountsInByToken: new Map([ + [ + tokensIn[minNegativeDiffIndex], + diffs[minNegativeDiffIndex].abs(), + ], + ]), + }) + ); + diffBPTs[minNegativeDiffIndex] = diffQuery.bptOut.mul(-1); + } else { + returnAmounts = await queryBatchSwap( + vault, + SwapType.SwapExactOut, + [ + { + poolId: pool.id, + assetInIndex: minPositiveDiffIndex, + assetOutIndex: minNegativeDiffIndex, + amount: diffs[minNegativeDiffIndex].abs().toString(), + userData: '0x', + }, + ], + pool.tokensList + ); + diffs[minNegativeDiffIndex] = Zero; + diffBPTs[minNegativeDiffIndex] = Zero; + diffs[minPositiveDiffIndex] = diffs[minPositiveDiffIndex].add( + BigNumber.from(returnAmounts[minPositiveDiffIndex]) + ); + const diffQuery = await balancerHelpers.callStatic.queryJoin( + ...pool.buildQueryJoinExactIn({ + maxAmountsInByToken: new Map([ + [ + tokensIn[minPositiveDiffIndex], + diffs[minPositiveDiffIndex].abs(), + ], + ]), + }) + ); + diffBPTs[minPositiveDiffIndex] = diffQuery.bptOut; + } + } - const initialBPT = parseFloat(formatFixed(bptOut, 18)); - const finalBPT = parseFloat(formatFixed(bptOut.sub(bptOutDiff), 18)); + const amountInitial = parseFloat( + amountsIn[minNegativeDiffIndex].toString() + ); + const amountDiff = parseFloat( + diffs[minNegativeDiffIndex].abs().toString() + ); - priceImpactABA = (initialBPT - finalBPT) / initialBPT / 2; + priceImpactABA = amountDiff / amountInitial / 2; console.log(`priceImpactABA : ${priceImpactABA}`); }); }); diff --git a/balancer-js/wstETH-rETH-sfrxETH.csv b/balancer-js/wstETH-rETH-sfrxETH.csv new file mode 100644 index 000000000..e182154e6 --- /dev/null +++ b/balancer-js/wstETH-rETH-sfrxETH.csv @@ -0,0 +1,120 @@ +action,test,spot price,ABA,error abs,error rel, +swap,1,0.00040377556888164767,0.00040370224878127914,-7.332010036853161e-8,-0.0001815862722244663 +Swap Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,10,3049.113080910972561465,0.0032796422220629272 +0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 +0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 + +swap,2,0.00040752761462463616,0.00040748466224682645,-4.2952377809709914e-8,-0.00010539746576258964 +Swap Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,20,3049.113080910972561465,0.0065592844441258544 +0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 +0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 + +swap,3,0.00041865039101878187,0.00041883520209616163,1.848110773797619e-7,0.00044144489374541327 +Swap Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,50,3049.113080910972561465,0.016398211110314635 +0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 +0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 + +swap,4,0.0004367569669131873,0.0004377776577118198,0.0000010206907986324491,0.002336976570393961 +Swap Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,100,3049.113080910972561465,0.03279642222062927 +0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 +0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 + +swap,5,0.0004880753174956617,0.0004950607027807906,0.000006985385285128876,0.014312105191000499 +Swap Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,250,3049.113080910972561465,0.08199105555157317 +0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 +0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 + +swap,6,0.0005649246215843502,0.0005938876298481546,0.000028963008263804368,0.0512688014598773 +Swap Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,500,3049.113080910972561465,0.16398211110314634 +0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 +0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 + +swap,7,0.0006937172565830037,0.0008207671867847921,0.00012704993020178838,0.18314367848882648 +Swap Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,1000,3049.113080910972561465,0.3279642222062927 +0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 +0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 + +single token join,1,0.000299821876819659,0.0002997818706826472,-4.000613701183068e-8,-0.00013343301508279907 +Single-Sided Join Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,10,3049.113080910972561465,0.0032796422220629272 +0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 +0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 + +single token join,2,0.000301646893391609,0.00030162116023273454,-2.573315887444529e-8,-0.00008530888080799017 +Single-Sided Join Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,20,3049.113080910972561465,0.0065592844441258544 +0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 +0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 + +single token join,3,0.000307064127222337,0.00030714052265715,7.639543481299067e-8,0.00024879309577466454 +Single-Sided Join Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,50,3049.113080910972561465,0.016398211110314635 +0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 +0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 + +single token join,4,0.000315905711879544,0.0003163503571391857,4.446452596417231e-7,0.001407525229588973 +Single-Sided Join Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,100,3049.113080910972561465,0.03279642222062927 +0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 +0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 + +single token join,5,0.000341126126129627,0.00034417624561956475,0.0000030501194899377397,0.008941324795447366 +Single-Sided Join Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,250,3049.113080910972561465,0.08199105555157317 +0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 +0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 + +single token join,6,0.000379371869200906,0.0003919909344199368,0.000012619065219030814,0.033263049381102285 +Single-Sided Join Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,500,3049.113080910972561465,0.16398211110314634 +0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 +0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 + +single token join,7,0.00044486981991085,0.00050014069422582,0.00005527087431496998,0.12424055721749348 +Single-Sided Join Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,1000,3049.113080910972561465,0.3279642222062927 +0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 +0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 + +unbalanced join,1,0.001395038034686279,0.002192811273091142,0.000797773238404863,0.5718648657377066 +Unbalanced Join Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,10,3049.113080910972561465,0.0032796422220629272 +0xac3e018457b222d93114458476f3e3416abbe38f,100,8353.098667955846370862,0.011971605265914068 +0xae78736cd615f374d3085123a210448e74fc6393,1000,1210.62732888482209938,0.8260180289512851 + +unbalanced join,2,0.000143047857261436,0.00015267199507975335,0.000009624137818317347,0.0672791470111164 +Unbalanced Join Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,100,3049.113080910972561465,0.03279642222062927 +0xac3e018457b222d93114458476f3e3416abbe38f,1000,8353.098667955846370862,0.11971605265914068 +0xae78736cd615f374d3085123a210448e74fc6393,10,1210.62732888482209938,0.00826018028951285 + +unbalanced join,3,0.00038505679898757,0.00045787494478876696,0.00007281814580119696,0.18911014165353718 +Unbalanced Join Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,1000,3049.113080910972561465,0.3279642222062927 +0xac3e018457b222d93114458476f3e3416abbe38f,100,8353.098667955846370862,0.011971605265914068 +0xae78736cd615f374d3085123a210448e74fc6393,10,1210.62732888482209938,0.00826018028951285 + From 1241586c9b6901231c7018af22e77f0ce3807907 Mon Sep 17 00:00:00 2001 From: jogeorgeou Date: Tue, 28 Nov 2023 23:06:01 -0500 Subject: [PATCH 14/16] Various_Tests Testing for sfrxeth/wsteth/reth, 80BAL/20WETH, 50COIL/50USDC, 35OATH/35GRAIN/15USDC/15WETH with each token in and different unbalanced circumstances. Pending a review of the results. --- balancer-js/50COIL50USDC_COIL.csv | 20 +-- balancer-js/50COIL50USDC_USDC.csv | 28 ++-- balancer-js/80BAL20WETH_BAL.csv | 16 +-- balancer-js/80BAL20WETH_WETH.csv | 74 +++++----- balancer-js/OATH_GRAIN_USDC_WETH_0.csv | 134 ++++++++++++++++++ balancer-js/OATH_GRAIN_USDC_WETH_1.csv | 134 ++++++++++++++++++ balancer-js/OATH_GRAIN_USDC_WETH_2.csv | 134 ++++++++++++++++++ balancer-js/OATH_GRAIN_USDC_WETH_3.csv | 134 ++++++++++++++++++ .../pricing/priceImpact.compare.spec.ts | 22 +-- balancer-js/wstETH-rETH-sfrxETH.csv | 14 ++ balancer-js/wstETH-rETH-sfrxETH2.csv | 134 ++++++++++++++++++ balancer-js/wstETH-rETH-sfrxETH3.csv | 134 ++++++++++++++++++ 12 files changed, 899 insertions(+), 79 deletions(-) create mode 100644 balancer-js/OATH_GRAIN_USDC_WETH_0.csv create mode 100644 balancer-js/OATH_GRAIN_USDC_WETH_1.csv create mode 100644 balancer-js/OATH_GRAIN_USDC_WETH_2.csv create mode 100644 balancer-js/OATH_GRAIN_USDC_WETH_3.csv create mode 100644 balancer-js/wstETH-rETH-sfrxETH2.csv create mode 100644 balancer-js/wstETH-rETH-sfrxETH3.csv diff --git a/balancer-js/50COIL50USDC_COIL.csv b/balancer-js/50COIL50USDC_COIL.csv index 436713a10..27a03f57a 100644 --- a/balancer-js/50COIL50USDC_COIL.csv +++ b/balancer-js/50COIL50USDC_COIL.csv @@ -69,28 +69,28 @@ Single-Sided Join Summary 0x823e1b82ce1dc147bbdb25a203f046afab1ce918,50000,228129.25829022804482744,0.21917399098536303 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,309823.996679,0 -unbalanced join,1,0.000228231241183176,0.00022778255577379848,-4.4868540937750855e-7,-0.0019659245905664525 -Unbalanced Join Summary -0x823e1b82ce1dc147bbdb25a203f046afab1ce918,10,228129.25829022804482744,0.00004383479819707261 -0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,10,309823.996679,0.00003227638952176039 - -unbalanced join,2,0.001381564085214109,0.0013800965246460444,-0.000001467560568064628,-0.0010622457429017428 +unbalanced join,1,0.001381564085214109,0.001481891915669705,0.00010032783045559588,0.07261902037649415 Unbalanced Join Summary 0x823e1b82ce1dc147bbdb25a203f046afab1ce918,100,228129.25829022804482744,0.0004383479819707261 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,10,309823.996679,0.00003227638952176039 -unbalanced join,3,0.002544407598200952,0.0025408218380210505,-0.000003585760179901625,-0.001409271133460288 +unbalanced join,2,0.002544407598200952,0.0025568674917006875,0.000012459893499735392,0.004896972288773733 Unbalanced Join Summary 0x823e1b82ce1dc147bbdb25a203f046afab1ce918,1000,228129.25829022804482744,0.00438347981970726 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,10,309823.996679,0.00003227638952176039 -unbalanced join,4,0.01216711270349539,0.012140775486510115,-0.000026337216985274775,-0.002164623409603872 +unbalanced join,3,0.01216711270349539,0.012023079736120917,-0.00014403296737447273,-0.011837892101804456 Unbalanced Join Summary 0x823e1b82ce1dc147bbdb25a203f046afab1ce918,10000,228129.25829022804482744,0.04383479819707261 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,10,309823.996679,0.00003227638952176039 -unbalanced join,5,0.0918538321850902,0.09080426330943722,-0.0010495688756529814,-0.011426511563916528 +unbalanced join,4,0.050838482362310984,0.048356686935959695,-0.0024817954263512895,-0.04881726029239543 +Unbalanced Join Summary +0x823e1b82ce1dc147bbdb25a203f046afab1ce918,50000,228129.25829022804482744,0.21917399098536303 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,10,309823.996679,0.00003227638952176039 + +unbalanced join,5,0.1268080243492715,0.11248693006189495,-0.014321094287376546,-0.1129352370314633 Unbalanced Join Summary -0x823e1b82ce1dc147bbdb25a203f046afab1ce918,100000,228129.25829022804482744,0.43834798197072605 +0x823e1b82ce1dc147bbdb25a203f046afab1ce918,150000,228129.25829022804482744,0.6575219729560892 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,10,309823.996679,0.00003227638952176039 diff --git a/balancer-js/50COIL50USDC_USDC.csv b/balancer-js/50COIL50USDC_USDC.csv index ec06fad39..5c5e7f346 100644 --- a/balancer-js/50COIL50USDC_USDC.csv +++ b/balancer-js/50COIL50USDC_USDC.csv @@ -69,28 +69,28 @@ Single-Sided Join Summary 0x823e1b82ce1dc147bbdb25a203f046afab1ce918,0,228129.25829022804482744,0 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,50000,309823.996679,0.16138194760880195 -unbalanced join,1,0.000228231241183176,0.00022778255577379848,-4.4868540937750855e-7,-0.0019659245905664525 +unbalanced join,1,0.001537020102404201,0.001556495,0.000019474897595798913,0.012670554903827446 Unbalanced Join Summary -0x823e1b82ce1dc147bbdb25a203f046afab1ce918,10,228129.25829022804482744,0.00004383479819707261 -0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,10,309823.996679,0.00003227638952176039 - -unbalanced join,2,0.001194172801590613,0.0011927556885435666,-0.0000014171130470464182,-0.0011866901047811954 -Unbalanced Join Summary -0x823e1b82ce1dc147bbdb25a203f046afab1ce918,10,228129.25829022804482744,0.00004383479819707261 +0x823e1b82ce1dc147bbdb25a203f046afab1ce918,1,228129.25829022804482744,0.000004383479819707261 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,100,309823.996679,0.0003227638952176039 -unbalanced join,3,0.002230842692445502,0.0022278939326570023,-0.00000294875978849949,-0.0013218143074297142 +unbalanced join,2,0.002295859970807763,0.0022942195,-0.0000016404708077632363,-0.0007145343481841629 Unbalanced Join Summary -0x823e1b82ce1dc147bbdb25a203f046afab1ce918,10,228129.25829022804482744,0.00004383479819707261 +0x823e1b82ce1dc147bbdb25a203f046afab1ce918,1,228129.25829022804482744,0.000004383479819707261 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,1000,309823.996679,0.0032276389521760387 -unbalanced join,4,0.009381384417036403,0.00936199875233271,-0.000019385664703693364,-0.00206639700943172 +unbalanced join,3,0.009414176353483334,0.0093229879,-0.00009118845348333494,-0.00968629119100731 Unbalanced Join Summary -0x823e1b82ce1dc147bbdb25a203f046afab1ce918,10,228129.25829022804482744,0.00004383479819707261 +0x823e1b82ce1dc147bbdb25a203f046afab1ce918,1,228129.25829022804482744,0.000004383479819707261 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,10000,309823.996679,0.03227638952176039 -unbalanced join,5,0.07109122765655039,0.07055729792526921,-0.0005339297312811769,-0.007510486861482414 +unbalanced join,4,0.038773986715493355,0.03730464448,-0.0014693422354933525,-0.037895051810760305 +Unbalanced Join Summary +0x823e1b82ce1dc147bbdb25a203f046afab1ce918,1,228129.25829022804482744,0.000004383479819707261 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,50000,309823.996679,0.16138194760880195 + +unbalanced join,5,0.09961903442349677,0.09054620707333333,-0.009072827350163445,-0.09107523881021949 Unbalanced Join Summary -0x823e1b82ce1dc147bbdb25a203f046afab1ce918,10,228129.25829022804482744,0.00004383479819707261 -0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,100000,309823.996679,0.3227638952176039 +0x823e1b82ce1dc147bbdb25a203f046afab1ce918,1,228129.25829022804482744,0.000004383479819707261 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,150000,309823.996679,0.4841458428264058 diff --git a/balancer-js/80BAL20WETH_BAL.csv b/balancer-js/80BAL20WETH_BAL.csv index 194da9ea3..e85d36cfe 100644 --- a/balancer-js/80BAL20WETH_BAL.csv +++ b/balancer-js/80BAL20WETH_BAL.csv @@ -69,28 +69,28 @@ Single-Sided Join Summary 0xba100000625a3754423978a60c9317c58a424e3d,1000000,33209420.429177837538000946,0.03011193772961478 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,16591.168598583701574685,0 -unbalanced join,1,0.001337128450564294,0.001323089699760126,-0.000014038750804167823,-0.010499178892082657 +unbalanced join,1,0.001337128450564294,0.00399376732611911,0.0026566388755548155,1.986823984213082 Unbalanced Join Summary 0xba100000625a3754423978a60c9317c58a424e3d,1000,33209420.429177837538000946,0.00003011193772961478 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,1,16591.168598583701574685,0.00006027302983861935 -unbalanced join,2,0.001541709034511661,0.0015390222210303606,-0.0000026868134813003413,-0.0017427500398292692 +unbalanced join,2,0.001541709034511661,0.0016167781702511766,0.00007506913573951564,0.048692155302374494 Unbalanced Join Summary 0xba100000625a3754423978a60c9317c58a424e3d,10000,33209420.429177837538000946,0.0003011193772961478 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,1,16591.168598583701574685,0.00006027302983861935 -unbalanced join,3,0.003467200386994319,0.003449560518652892,-0.000017639868341427258,-0.005087640278189713 +unbalanced join,3,0.002236449744451255,0.0022420464754017862,0.000005596730950531079,0.0025025069149963467 Unbalanced Join Summary -0xba100000625a3754423978a60c9317c58a424e3d,500000,33209420.429177837538000946,0.01505596886480739 +0xba100000625a3754423978a60c9317c58a424e3d,100000,33209420.429177837538000946,0.003011193772961478 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,1,16591.168598583701574685,0.00006027302983861935 -unbalanced join,4,0.009266092442513224,0.009149615607675602,-0.00011647683483762168,-0.01257022154270996 +unbalanced join,4,0.02887389817541518,0.02728338766874008,-0.001590510506675101,-0.05508471689594545 Unbalanced Join Summary -0xba100000625a3754423978a60c9317c58a424e3d,2500000,33209420.429177837538000946,0.07527984432403695 +0xba100000625a3754423978a60c9317c58a424e3d,10000000,33209420.429177837538000946,0.3011193772961478 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,1,16591.168598583701574685,0.00006027302983861935 -unbalanced join,5,0.02887389817541518,0.027991321116631815,-0.000882577058783366,-0.030566605638820202 +unbalanced join,5,0.040431008786043,0,-0.040431008786043,-1 Unbalanced Join Summary -0xba100000625a3754423978a60c9317c58a424e3d,10000000,33209420.429177837538000946,0.3011193772961478 +0xba100000625a3754423978a60c9317c58a424e3d,15000000,33209420.429177837538000946,0.4516790659442217 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,1,16591.168598583701574685,0.00006027302983861935 diff --git a/balancer-js/80BAL20WETH_WETH.csv b/balancer-js/80BAL20WETH_WETH.csv index 3b73fa813..1b778af9a 100644 --- a/balancer-js/80BAL20WETH_WETH.csv +++ b/balancer-js/80BAL20WETH_WETH.csv @@ -1,96 +1,96 @@ action,test,spot price,ABA,error abs,error rel, -swap,1,0.011860534449803386,0.011761721621604977,-0.00009881282819840936,-0.00833122896920108 +swap,1,0.010372772619513295,0.010313420345242541,-0.00005935227427075404,-0.00572192956000022 +Swap Summary +0xba100000625a3754423978a60c9317c58a424e3d,0,33209420.429177837538000946,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,10,16591.168598583701574685,0.0006027302983861936 + +swap,2,0.010745211822326786,0.010676301452090264,-0.00006891037023652215,-0.006413123480110249 +Swap Summary +0xba100000625a3754423978a60c9317c58a424e3d,0,33209420.429177837538000946,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,20,16591.168598583701574685,0.0012054605967723871 + +swap,3,0.011860534449803386,0.011761721621604977,-0.00009881282819840936,-0.00833122896920108 Swap Summary 0xba100000625a3754423978a60c9317c58a424e3d,0,33209420.429177837538000946,0 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,50,16591.168598583701574685,0.0030136514919309678 -swap,2,0.01371278418356158,0.013560081896159133,-0.00015270228740244668,-0.011135761006543149 +swap,4,0.01371278418356158,0.013560081896159133,-0.00015270228740244668,-0.011135761006543149 Swap Summary 0xba100000625a3754423978a60c9317c58a424e3d,0,33209420.429177837538000946,0 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,100,16591.168598583701574685,0.0060273029838619355 -swap,3,0.019220419976055496,0.01887644329261758,-0.0003439766834379167,-0.01789641869774113 +swap,5,0.019220419976055496,0.01887644329261758,-0.0003439766834379167,-0.01789641869774113 Swap Summary 0xba100000625a3754423978a60c9317c58a424e3d,0,33209420.429177837538000946,0 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,250,16591.168598583701574685,0.015068257459654838 -swap,4,0.028239581913104488,0.02748303329196142,-0.0007565486211430668,-0.0267903619632553 +swap,6,0.028239581913104488,0.02748303329196142,-0.0007565486211430668,-0.0267903619632553 Swap Summary 0xba100000625a3754423978a60c9317c58a424e3d,0,33209420.429177837538000946,0 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,500,16591.168598583701574685,0.030136514919309677 -swap,5,0.05415823497205329,0.051545544253458864,-0.002612690718594428,-0.04824179960707042 +swap,7,0.045701948186298795,0.043802498731486596,-0.0018994494548121993,-0.04156167363083319 Swap Summary 0xba100000625a3754423978a60c9317c58a424e3d,0,33209420.429177837538000946,0 -0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,1250,16591.168598583701574685,0.07534128729827419 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,1000,16591.168598583701574685,0.06027302983861935 -swap,6,0.09392604097152411,0.08661339685718039,-0.007312644114343722,-0.07785534276442804 -Swap Summary +single token join,1,0.008237165164621378,0.008203239645555804,-0.00003392551906557413,-0.004118591577025094 +Single-Sided Join Summary 0xba100000625a3754423978a60c9317c58a424e3d,0,33209420.429177837538000946,0 -0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,2500,16591.168598583701574685,0.15068257459654838 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,10,16591.168598583701574685,0.0006027302983861936 -swap,7,0.16282325082737736,0.14245355098408408,-0.020369699843293287,-0.12510313938449075 -Swap Summary +single token join,2,0.008474160069212144,0.008438254337720963,-0.000035905731491181134,-0.004237084406941034 +Single-Sided Join Summary 0xba100000625a3754423978a60c9317c58a424e3d,0,33209420.429177837538000946,0 -0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,5000,16591.168598583701574685,0.30136514919309676 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,20,16591.168598583701574685,0.0012054605967723871 -single token join,1,0.009184127045242301,0.009141952935596933,-0.00004217410964536816,-0.0045920651399542455 +single token join,3,0.009184127045242301,0.009141952935596933,-0.00004217410964536816,-0.0045920651399542455 Single-Sided Join Summary 0xba100000625a3754423978a60c9317c58a424e3d,0,33209420.429177837538000946,0 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,50,16591.168598583701574685,0.0030136514919309678 -single token join,2,0.010364025001894933,0.010310318486956476,-0.000053706514938457045,-0.005182013255336366 +single token join,4,0.010364025001894933,0.010310318486956476,-0.000053706514938457045,-0.005182013255336366 Single-Sided Join Summary 0xba100000625a3754423978a60c9317c58a424e3d,0,33209420.429177837538000946,0 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,100,16591.168598583701574685,0.0060273029838619355 -single token join,3,0.013878607059261146,0.013782299174161097,-0.00009630788510004915,-0.006939304837208661 +single token join,5,0.013878607059261146,0.013782299174161097,-0.00009630788510004915,-0.006939304837208661 Single-Sided Join Summary 0xba100000625a3754423978a60c9317c58a424e3d,0,33209420.429177837538000946,0 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,250,16591.168598583701574685,0.015068257459654838 -single token join,4,0.019654077040931205,0.0194609354329599,-0.00019314160797130608,-0.00982705051827532 +single token join,6,0.019654077040931205,0.0194609354329599,-0.00019314160797130608,-0.00982705051827532 Single-Sided Join Summary 0xba100000625a3754423978a60c9317c58a424e3d,0,33209420.429177837538000946,0 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,500,16591.168598583701574685,0.030136514919309677 -single token join,5,0.0363922256609502,0.035730020362565666,-0.0006622052983845314,-0.0181963396400648 +single token join,7,0.030907962182798458,0.030430307621035695,-0.0004776545617627623,-0.015454094286054114 Single-Sided Join Summary 0xba100000625a3754423978a60c9317c58a424e3d,0,33209420.429177837538000946,0 -0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,1250,16591.168598583701574685,0.07534128729827419 - -single token join,6,0.06249310145927306,0.06054029563068843,-0.0019528058285846264,-0.031248342344751056 -Single-Sided Join Summary -0xba100000625a3754423978a60c9317c58a424e3d,0,33209420.429177837538000946,0 -0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,2500,16591.168598583701574685,0.15068257459654838 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,1000,16591.168598583701574685,0.06027302983861935 -single token join,7,0.10898221065393847,0.10304233062791104,-0.005939880026027425,-0.05450320736187751 -Single-Sided Join Summary -0xba100000625a3754423978a60c9317c58a424e3d,0,33209420.429177837538000946,0 -0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,5000,16591.168598583701574685,0.30136514919309676 +unbalanced join,1,0.008003711011527437,0.007988734182401437,-0.000014976829126000374,-0.0018712356186311354 +Unbalanced Join Summary +0xba100000625a3754423978a60c9317c58a424e3d,1,33209420.429177837538000946,3.011193772961478e-8 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,1,16591.168598583701574685,0.00006027302983861935 -unbalanced join,1,0.008235096115354116,0.008203010922176823,-0.00003208519317729301,-0.0038961528472595515 +unbalanced join,2,0.008235096115354116,0.008202738022824525,-0.00003235809252959132,-0.003929291422508175 Unbalanced Join Summary 0xba100000625a3754423978a60c9317c58a424e3d,1,33209420.429177837538000946,3.011193772961478e-8 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,10,16591.168598583701574685,0.0006027302983861936 -unbalanced join,2,0.010363754278797079,0.010320087429444194,-0.000043666849352884396,-0.004213419980655196 +unbalanced join,3,0.010363754278797079,0.01029620934865045,-0.0000675449301466291,-0.006517419106010399 Unbalanced Join Summary 0xba100000625a3754423978a60c9317c58a424e3d,1,33209420.429177837538000946,3.011193772961478e-8 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,100,16591.168598583701574685,0.0060273029838619355 -unbalanced join,3,0.019653967065790912,0.019582384061296997,-0.00007158300449391572,-0.003642165688702658 +unbalanced join,4,0.019653967065790912,0.019361367645071122,-0.0002925994207197899,-0.0148875501694047 Unbalanced Join Summary 0xba100000625a3754423978a60c9317c58a424e3d,1,33209420.429177837538000946,3.011193772961478e-8 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,500,16591.168598583701574685,0.030136514919309677 -unbalanced join,4,0.030907873257172015,0.030844442457088714,-0.00006343080008330143,-0.00205225379163164 -Unbalanced Join Summary -0xba100000625a3754423978a60c9317c58a424e3d,1,33209420.429177837538000946,3.011193772961478e-8 -0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,1000,16591.168598583701574685,0.06027302983861935 - -unbalanced join,5,0.10898214498398899,0.10918294496230005,0.00020079997831105867,0.0018425034517402738 +unbalanced join,5,0.04178498209257003,0.04045662512442082,-0.0013283569681492163,-0.03179029645642512 Unbalanced Join Summary 0xba100000625a3754423978a60c9317c58a424e3d,1,33209420.429177837538000946,3.011193772961478e-8 -0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,5000,16591.168598583701574685,0.30136514919309676 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,1500,16591.168598583701574685,0.09040954475792903 diff --git a/balancer-js/OATH_GRAIN_USDC_WETH_0.csv b/balancer-js/OATH_GRAIN_USDC_WETH_0.csv new file mode 100644 index 000000000..aae04fc88 --- /dev/null +++ b/balancer-js/OATH_GRAIN_USDC_WETH_0.csv @@ -0,0 +1,134 @@ +action,test,spot price,ABA,error abs,error rel, +swap,1,0.020053755009550405,0.01985111958815551,-0.0002026354213948943,-0.010104612392960378 +Swap Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,100,3042066.965305608883632939,0.0000328723861573356 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +swap,2,0.020107397435545554,0.019902095151109193,-0.00020530228443636084,-0.010210286293612049 +Swap Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,200,3042066.965305608883632939,0.0000657447723146712 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +swap,3,0.020268423290730957,0.020055132424014233,-0.0002132908667167241,-0.010523308283889308 +Swap Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,500,3042066.965305608883632939,0.00016436193078667798 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +swap,4,0.02053666827977361,0.020309959100646608,-0.00022670917912700345,-0.011039238499571393 +Swap Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,1000,3042066.965305608883632939,0.00032872386157335596 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +swap,5,0.02134073292194592,0.02107286720314569,-0.0002678657188002302,-0.012551851887184638 +Swap Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,2500,3042066.965305608883632939,0.0008218096539333899 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +swap,6,0.022678346655755504,0.02233901186476842,-0.000339334790987085,-0.014962942234634452 +Swap Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,5000,3042066.965305608883632939,0.0016436193078667798 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +swap,7,0.02534427993642661,0.02485135780150613,-0.0004929221349204808,-0.019449048706726833 +Swap Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,10000,3042066.965305608883632939,0.0032872386157335597 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +single token join,1,0.013010410851050142,0.012925773910714256,-0.00008463694033588633,-0.00650532418267597 +Single-Sided Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,100,3042066.965305608883632939,0.0000328723861573356 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +single token join,2,0.013020816114554983,0.01293604458877681,-0.00008477152577817358,-0.006510461789212577 +Single-Sided Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,200,3042066.965305608883632939,0.0000657447723146712 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +single token join,3,0.01305203384974993,0.012966856263397573,-0.00008517758635235607,-0.0065260010304055436 +Single-Sided Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,500,3042066.965305608883632939,0.00016436193078667798 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +single token join,4,0.013104057373248624,0.013018201138964059,-0.00008585623428456444,-0.006551881744644701 +Single-Sided Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,1000,3042066.965305608883632939,0.00032872386157335596 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +single token join,5,0.013260073109966158,0.013172171283058469,-0.0000879018269076895,-0.006629060502058863 +Single-Sided Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,2500,3042066.965305608883632939,0.0008218096539333899 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +single token join,6,0.013519914234311262,0.013428572128495943,-0.00009134210581531951,-0.006756115773538611 +Single-Sided Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,5000,3042066.965305608883632939,0.0016436193078667798 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +single token join,7,0.014038902747275187,0.013940564763186558,-0.00009833798408862872,-0.0070046773497106215 +Single-Sided Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,10000,3042066.965305608883632939,0.0032872386157335597 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +unbalanced join,1,0.027207605091119583,0.024191867397961392,-0.0030157376931581915,-0.11084171808060064 +Unbalanced Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,100,3042066.965305608883632939,0.0000328723861573356 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,1,80973.084641,0.000012349782701666512 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,1,39.154958239677801248,0.025539549649848604 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,10,9700119.984474651850337175,0.000001030915083112922 + +unbalanced join,2,0.026322299940913504,0.02403595290577276,-0.002286347035140742,-0.08685969844097884 +Unbalanced Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,1000,3042066.965305608883632939,0.00032872386157335596 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,1,80973.084641,0.000012349782701666512 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,1,39.154958239677801248,0.025539549649848604 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,10,9700119.984474651850337175,0.000001030915083112922 + +unbalanced join,3,0.024529115535142806,0.023724524566055713,-0.0008045909690870927,-0.032801466809284544 +Unbalanced Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,3000,3042066.965305608883632939,0.0009861715847200678 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,1,80973.084641,0.000012349782701666512 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,1,39.154958239677801248,0.025539549649848604 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,10,9700119.984474651850337175,0.000001030915083112922 + +unbalanced join,4,0.01971207353740396,0.023015624224122733,0.003303550686718771,0.1675902172569635 +Unbalanced Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,10000,3042066.965305608883632939,0.0032872386157335597 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,1,80973.084641,0.000012349782701666512 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,1,39.154958239677801248,0.025539549649848604 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,10,9700119.984474651850337175,0.000001030915083112922 + +unbalanced join,5,0.01586572326762862,0.02558032056562632,0.009714597297997701,0.6123009417300709 +Unbalanced Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,20000,3042066.965305608883632939,0.006574477231467119 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,1,80973.084641,0.000012349782701666512 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,1,39.154958239677801248,0.025539549649848604 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,10,9700119.984474651850337175,0.000001030915083112922 + diff --git a/balancer-js/OATH_GRAIN_USDC_WETH_1.csv b/balancer-js/OATH_GRAIN_USDC_WETH_1.csv new file mode 100644 index 000000000..91cbd09ac --- /dev/null +++ b/balancer-js/OATH_GRAIN_USDC_WETH_1.csv @@ -0,0 +1,134 @@ +action,test,spot price,ABA,error abs,error rel, +swap,1,0.021208815700863175,0.020947979999999974,-0.00026083570086320174,-0.01229845666736526 +Swap Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,100,80973.084641,0.001234978270166651 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +swap,2,0.02241471245939151,0.022090480000000027,-0.0003242324593914839,-0.014465162556909541 +Swap Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,200,80973.084641,0.002469956540333302 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +swap,3,0.02601499442550446,0.025485519000000012,-0.0005294754255044491,-0.0203527018627905 +Swap Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,500,80973.084641,0.006174891350833256 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +swap,4,0.031958061179673244,0.031037980000000003,-0.0009200811796732412,-0.028790269049815014 +Swap Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,1000,80973.084641,0.012349782701666511 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +swap,5,0.0493683698048719,0.04694215039999999,-0.002426219404871907,-0.049145220197902434 +Swap Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,2500,80973.084641,0.03087445675416628 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +swap,6,0.0770609524565805,0.07118016049999996,-0.005880791956580533,-0.07631351247434981 +Swap Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,5000,80973.084641,0.06174891350833256 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +swap,7,0.12796151787457918,0.11262796800000001,-0.015333549874579175,-0.11982938409349188 +Swap Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,10000,80973.084641,0.12349782701666512 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +single token join,1,0.017506792878366612,0.01735354000000001,-0.00015325287836660123,-0.008753909378569158 +Single-Sided Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,100,80973.084641,0.001234978270166651 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +single token join,2,0.018012828037408182,0.017850547500000005,-0.00016228053740817774,-0.009009164861351103 +Single-Sided Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,200,80973.084641,0.002469956540333302 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +single token join,3,0.019526408959676902,0.01933545700000002,-0.00019095195967688133,-0.009779164211463947 +Single-Sided Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,500,80973.084641,0.006174891350833256 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +single token join,4,0.022034077465822165,0.021790092000000014,-0.00024398546582215033,-0.011073096488863888 +Single-Sided Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,1000,80973.084641,0.012349782701666511 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +single token join,5,0.02944701426732974,0.02900596180000002,-0.0004410524673297174,-0.014977833179476098 +Single-Sided Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,2500,80973.084641,0.03087445675416628 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +single token join,6,0.04144862103138693,0.040561123099999985,-0.0008874979313869477,-0.021412001396014856 +Single-Sided Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,5000,80973.084641,0.06174891350833256 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +single token join,7,0.06422084073525065,0.062055097000000024,-0.002165743735250629,-0.033723378742095134 +Single-Sided Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,10000,80973.084641,0.12349782701666512 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +unbalanced join,1,0.02716421348606031,0.02419471180993948,-0.002969501676120829,-0.10931668158346163 +Unbalanced Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,1,3042066.965305608883632939,3.28723861573356e-7 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,10,80973.084641,0.0001234978270166651 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,1,39.154958239677801248,0.025539549649848604 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,1,9700119.984474651850337175,1.0309150831129219e-7 + +unbalanced join,2,0.022112505650785794,0.02803017051954543,0.005917664868759637,0.267616206060725 +Unbalanced Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,1,3042066.965305608883632939,3.28723861573356e-7 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,500,80973.084641,0.006174891350833256 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,1,39.154958239677801248,0.025539549649848604 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,1,9700119.984474651850337175,1.0309150831129219e-7 + +unbalanced join,3,0.02144631361192695,0,-0.02144631361192695,-1 +Unbalanced Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,1,3042066.965305608883632939,3.28723861573356e-7 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,1000,80973.084641,0.012349782701666511 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,1,39.154958239677801248,0.025539549649848604 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,1,9700119.984474651850337175,1.0309150831129219e-7 + +unbalanced join,4,0.0224319211009759,0,-0.0224319211009759,-1 +Unbalanced Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,1,3042066.965305608883632939,3.28723861573356e-7 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,2000,80973.084641,0.024699565403333023 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,1,39.154958239677801248,0.025539549649848604 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,1,9700119.984474651850337175,1.0309150831129219e-7 + +unbalanced join,5,0.024948087256284925,0.39484962,0.36990153274371507,14.82684940708348 +Unbalanced Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,1,3042066.965305608883632939,3.28723861573356e-7 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,3000,80973.084641,0.03704934810499953 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,1,39.154958239677801248,0.025539549649848604 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,1,9700119.984474651850337175,1.0309150831129219e-7 + diff --git a/balancer-js/OATH_GRAIN_USDC_WETH_2.csv b/balancer-js/OATH_GRAIN_USDC_WETH_2.csv new file mode 100644 index 000000000..22e6934bc --- /dev/null +++ b/balancer-js/OATH_GRAIN_USDC_WETH_2.csv @@ -0,0 +1,134 @@ +action,test,spot price,ABA,error abs,error rel, +swap,1,0.02178415397360343,0.021493799170580058,-0.0002903548030233731,-0.013328716064677356 +Swap Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0.1,39.154958239677801248,0.0025539549649848605 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +swap,2,0.023561109788893014,0.02317567418303565,-0.0003854356058573642,-0.016358974993574502 +Swap Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0.2,39.154958239677801248,0.005107909929969721 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +swap,3,0.02884924647525176,0.028150989174731023,-0.0006982573005207375,-0.02420365818288306 +Swap Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0.5,39.154958239677801248,0.012769774824924302 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +swap,4,0.03752306073224475,0.03621597392789144,-0.0013070868043533052,-0.03483422670875258 +Swap Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,1,39.154958239677801248,0.025539549649848604 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +swap,5,0.06254534804326682,0.058833560563534705,-0.0037117874797321163,-0.05934554040956688 +Swap Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,2.5,39.154958239677801248,0.06384887412462151 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +swap,6,0.10120739472685412,0.09198011942098487,-0.009227275305869254,-0.09117194776895991 +Swap Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,5,39.154958239677801248,0.12769774824924301 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +swap,7,0.16891976137906692,0.14521929579499235,-0.02370046558407457,-0.1403060565003356 +Swap Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,10,39.154958239677801248,0.25539549649848603 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +single token join,1,0.018047219126648622,0.01788431432277457,-0.00016290480387405257,-0.009026587571794175 +Single-Sided Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0.1,39.154958239677801248,0.0025539549649848605 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +single token join,2,0.019091207891303995,0.018908756887669673,-0.00018245100363432215,-0.009556807755334759 +Single-Sided Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0.2,39.154958239677801248,0.005107909929969721 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +single token join,3,0.022203964688067294,0.021956136851912,-0.0002478278361552934,-0.011161422729539799 +Single-Sided Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0.5,39.154958239677801248,0.012769774824924302 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +single token join,4,0.027328870811383472,0.026950267762154423,-0.0003786030492290496,-0.013853592848459278 +Single-Sided Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,1,39.154958239677801248,0.025539549649848604 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +single token join,5,0.04224943274852523,0.04132655140052499,-0.0009228813480002401,-0.021843638789030947 +Single-Sided Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,2.5,39.154958239677801248,0.06384887412462151 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +single token join,6,0.06571375102118364,0.06344455439421762,-0.002269196626966022,-0.034531533989507285 +Single-Sided Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,5,39.154958239677801248,0.12769774824924301 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +single token join,7,0.10808353720465008,0.10187657018064104,-0.0062069670240090385,-0.05742749714284884 +Single-Sided Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,10,39.154958239677801248,0.25539549649848603 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,0,9700119.984474651850337175,0 + +unbalanced join,1,0.01793581405967206,0.017587682068353986,-0.0003481319913180743,-0.019409879593970298 +Unbalanced Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,1,3042066.965305608883632939,3.28723861573356e-7 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,1,80973.084641,0.000012349782701666512 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0.1,39.154958239677801248,0.0025539549649848605 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,1,9700119.984474651850337175,1.0309150831129219e-7 + +unbalanced join,2,0.027311104254834375,0.024210123232769398,-0.0031009810220649775,-0.11354286495084023 +Unbalanced Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,1,3042066.965305608883632939,3.28723861573356e-7 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,1,80973.084641,0.000012349782701666512 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,1,39.154958239677801248,0.025539549649848604 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,1,9700119.984474651850337175,1.0309150831129219e-7 + +unbalanced join,3,0.0657047229884663,0.024210123232769398,-0.0414945997556969,-0.6315314617943187 +Unbalanced Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,1,3042066.965305608883632939,3.28723861573356e-7 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,1,80973.084641,0.000012349782701666512 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,5,39.154958239677801248,0.12769774824924301 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,1,9700119.984474651850337175,1.0309150831129219e-7 + +unbalanced join,4,0.10807596826811319,0.024210123232769398,-0.08386584503534379,-0.7759897633051105 +Unbalanced Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,1,3042066.965305608883632939,3.28723861573356e-7 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,1,80973.084641,0.000012349782701666512 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,10,39.154958239677801248,0.25539549649848603 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,1,9700119.984474651850337175,1.0309150831129219e-7 + +unbalanced join,5,0.14540358652938534,0.10482877333775917,-0.040574813191626175,-0.2790496036590281 +Unbalanced Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,1,3042066.965305608883632939,3.28723861573356e-7 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,1,80973.084641,0.000012349782701666512 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,15,39.154958239677801248,0.3830932447477291 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,1,9700119.984474651850337175,1.0309150831129219e-7 + diff --git a/balancer-js/OATH_GRAIN_USDC_WETH_3.csv b/balancer-js/OATH_GRAIN_USDC_WETH_3.csv new file mode 100644 index 000000000..16de415e5 --- /dev/null +++ b/balancer-js/OATH_GRAIN_USDC_WETH_3.csv @@ -0,0 +1,134 @@ +action,test,spot price,ABA,error abs,error rel, +swap,1,0.020084253476206775,0.019880090958205584,-0.00020416251800119134,-0.010165302795200065 +Swap Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,500,9700119.984474651850337175,0.000051545754155646097 + +swap,2,0.020168388941786502,0.01996005919605119,-0.00020832974573531046,-0.010329518452694851 +Swap Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,1000,9700119.984474651850337175,0.00010309150831129219 + +swap,3,0.0204208162938093,0.020199921838625325,-0.00022089445518397657,-0.010817121705900764 +Swap Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,2500,9700119.984474651850337175,0.00025772877077823045 + +swap,4,0.020841305024150474,0.020599162941324266,-0.00024214208282620844,-0.011618374307444721 +Swap Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,5000,9700119.984474651850337175,0.0005154575415564609 + +swap,5,0.022100952296515746,0.021792929447295318,-0.00030802284922042816,-0.013937084931357846 +Swap Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,12500,9700119.984474651850337175,0.0012886438538911524 + +swap,6,0.024194265730948166,0.023769409650960006,-0.0004248560799881597,-0.017560197309261748 +Swap Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,25000,9700119.984474651850337175,0.0025772877077823047 + +swap,7,0.02835812049260365,0.02767385431697876,-0.000684266175624889,-0.024129461464251798 +Swap Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,50000,9700119.984474651850337175,0.005154575415564609 + +single token join,1,0.013016321400542435,0.012931608141783159,-0.00008471325875927631,-0.006508233482598702 +Single-Sided Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,500,9700119.984474651850337175,0.000051545754155646097 + +single token join,2,0.013032638561581322,0.01294771343317808,-0.00008492512840324248,-0.0065163418752048965 +Single-Sided Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,1000,9700119.984474651850337175,0.00010309150831129219 + +single token join,3,0.013081587227350791,0.012996024345440218,-0.00008556288191057318,-0.006540711033266633 +Single-Sided Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,2500,9700119.984474651850337175,0.00025772877077823045 + +single token join,4,0.013163150968480482,0.013076521715246873,-0.00008662925323360895,-0.006581194232372251 +Single-Sided Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,5000,9700119.984474651850337175,0.0005154575415564609 + +single token join,5,0.013407705913575756,0.013317854542709538,-0.00008985137086621811,-0.006701472380539057 +Single-Sided Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,12500,9700119.984474651850337175,0.0012886438538911524 + +single token join,6,0.013814842321593312,0.01371954498864543,-0.0000952973329478822,-0.006898184628493917 +Single-Sided Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,25000,9700119.984474651850337175,0.0025772877077823047 + +single token join,7,0.014627412821221621,0.014520941012501717,-0.00010647180871990389,-0.007278922802085229 +Single-Sided Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,0,3042066.965305608883632939,0 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0,80973.084641,0 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,39.154958239677801248,0 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,50000,9700119.984474651850337175,0.005154575415564609 + +unbalanced join,1,0.027308225913156965,0.024209615360102757,-0.0030986105530542082,-0.11346802838485796 +Unbalanced Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,1,3042066.965305608883632939,3.28723861573356e-7 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,1,80973.084641,0.000012349782701666512 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,1,39.154958239677801248,0.025539549649848604 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,10,9700119.984474651850337175,0.000001030915083112922 + +unbalanced join,2,0.027279472105495285,0.024204544601682736,-0.003074927503812549,-0.11271946509526198 +Unbalanced Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,1,3042066.965305608883632939,3.28723861573356e-7 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,1,80973.084641,0.000012349782701666512 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,1,39.154958239677801248,0.025539549649848604 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,100,9700119.984474651850337175,0.000010309150831129219 + +unbalanced join,3,0.02699486733869889,0.024154365751315965,-0.0028405015873829258,-0.10522376538264676 +Unbalanced Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,1,3042066.965305608883632939,3.28723861573356e-7 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,1,80973.084641,0.000012349782701666512 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,1,39.154958239677801248,0.025539549649848604 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,1000,9700119.984474651850337175,0.00010309150831129219 + +unbalanced join,4,0.024416923646421666,0.023705527225589024,-0.0007113964208326426,-0.029135382947265705 +Unbalanced Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,1,3042066.965305608883632939,3.28723861573356e-7 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,1,80973.084641,0.000012349782701666512 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,1,39.154958239677801248,0.025539549649848604 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,10000,9700119.984474651850337175,0.0010309150831129218 + +unbalanced join,5,0.015455756905113935,0,-0.015455756905113935,-1 +Unbalanced Join Summary +0x6f9c26fa731c7ea4139fa669962cf8f1ce6c8b0b,1,3042066.965305608883632939,3.28723861573356e-7 +0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,1,80973.084641,0.000012349782701666512 +0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,1,39.154958239677801248,0.025539549649848604 +0xf88baf18fab7e330fa0c4f83949e23f52fececce,200000,9700119.984474651850337175,0.020618301662258438 + diff --git a/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts b/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts index 510ccf2b4..b87c629b6 100644 --- a/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts +++ b/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts @@ -31,7 +31,7 @@ const { contracts, pricing } = sdk; const provider = new JsonRpcProvider(rpcUrl, 1); const signer = provider.getSigner(); const { balancerHelpers, vault } = contracts; -const csvFilePath = 'wstETH-rETH-sfrxETH.csv'; +const csvFilePath = 'OATH_GRAIN_USDC_WETH_3.csv'; // Write the header to the CSV file const csvLine = 'action,test,spot price,ABA,error abs,error rel,\n'; fs.writeFileSync(csvFilePath, csvLine, { flag: 'w' }); @@ -41,14 +41,14 @@ const writeNewTable = (header: string) => { const blockNumber = 18559730; const testPoolId = - '0x42ed016f826165c2e5976fe5bc3df540c5ad0af700000000000000000000058b'; // 80BAL/20WETH + '0x67f117350eab45983374f4f83d275d8a5d62b1bf0001000000000000000004f2'; // 80BAL/20WETH /** * When testing pools with phantom BPT (e.g. ComposableStable), indexes should consider pool tokens with BPT */ // swap config -const swapAmountFloat = '10'; +const swapAmountFloat = '500'; const swapAmountFloats = [ swapAmountFloat, String(Number(swapAmountFloat) * 2), @@ -58,12 +58,12 @@ const swapAmountFloats = [ String(Number(swapAmountFloat) * 50), String(Number(swapAmountFloat) * 100), ]; -const assetInIndex = 1; -const assetOutIndex = 2; +const assetInIndex = 3; +const assetOutIndex = 1; // single token join config -const joinAmountFloat = '10'; -const tokenIndex = 1; +const joinAmountFloat = '500'; +const tokenIndex = 3; const singleTokenJoinTests = [ { amountFloat: joinAmountFloat, tokenIndex }, { amountFloat: String(Number(joinAmountFloat) * 2), tokenIndex }, @@ -77,9 +77,11 @@ const singleTokenJoinTests = [ // unbalanced join config // const amountsInFloat = ['0', '200', '100', '10']; // should add value for BPT if present const unbalancedJoinTests = [ - { amountsInFloat: ['0', '10', '100', '1000'] }, - { amountsInFloat: ['0', '100', '1000', '10'] }, - { amountsInFloat: ['0', '1000', '100', '10'] }, + { amountsInFloat: ['1', '1', '1', '10'] }, + { amountsInFloat: ['1', '1', '1', '100'] }, + { amountsInFloat: ['1', '1', '1', '1000'] }, + { amountsInFloat: ['1', '1', '1', '10000'] }, + { amountsInFloat: ['1', '1', '1', '200000'] }, // Add more test scenarios as needed ]; diff --git a/balancer-js/wstETH-rETH-sfrxETH.csv b/balancer-js/wstETH-rETH-sfrxETH.csv index e182154e6..566777e14 100644 --- a/balancer-js/wstETH-rETH-sfrxETH.csv +++ b/balancer-js/wstETH-rETH-sfrxETH.csv @@ -118,3 +118,17 @@ Unbalanced Join Summary 0xac3e018457b222d93114458476f3e3416abbe38f,100,8353.098667955846370862,0.011971605265914068 0xae78736cd615f374d3085123a210448e74fc6393,10,1210.62732888482209938,0.00826018028951285 +unbalanced join,4,0.001013680814663362,0.17080316632882703,0.16978948551416367,167.497976737924 +Unbalanced Join Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,10000,3049.113080910972561465,3.279642222062927 +0xac3e018457b222d93114458476f3e3416abbe38f,100,8353.098667955846370862,0.011971605265914068 +0xae78736cd615f374d3085123a210448e74fc6393,10,1210.62732888482209938,0.00826018028951285 + +unbalanced join,5,0.000392060534909374,0.00048104049267803326,0.00008897995776865924,0.22695464053587344 +Unbalanced Join Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,1000,3049.113080910972561465,0.3279642222062927 +0xac3e018457b222d93114458476f3e3416abbe38f,10,8353.098667955846370862,0.0011971605265914068 +0xae78736cd615f374d3085123a210448e74fc6393,100,1210.62732888482209938,0.08260180289512851 + diff --git a/balancer-js/wstETH-rETH-sfrxETH2.csv b/balancer-js/wstETH-rETH-sfrxETH2.csv new file mode 100644 index 000000000..1b7313a58 --- /dev/null +++ b/balancer-js/wstETH-rETH-sfrxETH2.csv @@ -0,0 +1,134 @@ +action,test,spot price,ABA,error abs,error rel, +swap,1,0.0004283912778082929,0.00042806104367647534,-3.302341318175495e-7,-0.0007708703442961572 +Swap Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,0,3049.113080910972561465,0 +0xac3e018457b222d93114458476f3e3416abbe38f,10,8353.098667955846370862,0.0011971605265914068 +0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 + +swap,2,0.0004572448473324938,0.0004562098909301149,-0.0000010349564023789145,-0.002263462143787325 +Swap Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,0,3049.113080910972561465,0 +0xac3e018457b222d93114458476f3e3416abbe38f,20,8353.098667955846370862,0.0023943210531828137 +0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 + +swap,3,0.0005466729048109627,0.000540811384178923,-0.000005861520632039667,-0.01072217148582946 +Swap Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,0,3049.113080910972561465,0 +0xac3e018457b222d93114458476f3e3416abbe38f,50,8353.098667955846370862,0.005985802632957034 +0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 + +swap,4,0.0007060207535101611,0.0006829855658425288,-0.000023035187667632328,-0.03262678547777392 +Swap Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,0,3049.113080910972561465,0 +0xac3e018457b222d93114458476f3e3416abbe38f,100,8353.098667955846370862,0.011971605265914068 +0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 + +swap,5,0.0012789410837668487,0.0011316562951678862,-0.00014728478859896252,-0.1151615117133985 +Swap Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,0,3049.113080910972561465,0 +0xac3e018457b222d93114458476f3e3416abbe38f,250,8353.098667955846370862,0.02992901316478517 +0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 + +swap,6,0.0027369118309386485,0.0020680185874056745,-0.000668893243532974,-0.24439707409338468 +Swap Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,0,3049.113080910972561465,0 +0xac3e018457b222d93114458476f3e3416abbe38f,500,8353.098667955846370862,0.05985802632957034 +0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 + +swap,7,0.01362716608677421,0.007774804253618072,-0.005852361833156139,-0.42946286820677443 +Swap Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,0,3049.113080910972561465,0 +0xac3e018457b222d93114458476f3e3416abbe38f,1000,8353.098667955846370862,0.11971605265914068 +0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 + +single token join,1,0.000141160724287733,0.000141150623579378,-1.0100708354980224e-8,-0.00007155466512336382 +Single-Sided Join Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,0,3049.113080910972561465,0 +0xac3e018457b222d93114458476f3e3416abbe38f,10,8353.098667955846370862,0.0011971605265914068 +0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 + +single token join,2,0.000141824665531002,0.00014181405828148642,-1.0607249515586295e-8,-0.00007479128877809774 +Single-Sided Join Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,0,3049.113080910972561465,0 +0xac3e018457b222d93114458476f3e3416abbe38f,20,8353.098667955846370862,0.0023943210531828137 +0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 + +single token join,3,0.000143818133399513,0.00014380435328391174,-1.378011560125591e-8,-0.0000958162595740001 +Single-Sided Join Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,0,3049.113080910972561465,0 +0xac3e018457b222d93114458476f3e3416abbe38f,50,8353.098667955846370862,0.005985802632957034 +0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 + +single token join,4,0.000147146065555781,0.00014712148674476567,-2.457881101533728e-8,-0.00016703682101523672 +Single-Sided Join Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,0,3049.113080910972561465,0 +0xac3e018457b222d93114458476f3e3416abbe38f,100,8353.098667955846370862,0.011971605265914068 +0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 + +single token join,5,0.000157171102666413,0.00015707280568142323,-9.829698498976694e-8,-0.0006254138535783952 +Single-Sided Join Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,0,3049.113080910972561465,0 +0xac3e018457b222d93114458476f3e3416abbe38f,250,8353.098667955846370862,0.02992901316478517 +0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 + +single token join,6,0.000174017568235215,0.0001736587557152802,-3.588125199347966e-7,-0.0020619327322733247 +Single-Sided Join Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,0,3049.113080910972561465,0 +0xac3e018457b222d93114458476f3e3416abbe38f,500,8353.098667955846370862,0.05985802632957034 +0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 + +single token join,7,0.000208232290938202,0.00020683753645317891,-0.0000013947544850230898,-0.006698070115537543 +Single-Sided Join Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,0,3049.113080910972561465,0 +0xac3e018457b222d93114458476f3e3416abbe38f,1000,8353.098667955846370862,0.11971605265914068 +0xae78736cd615f374d3085123a210448e74fc6393,0,1210.62732888482209938,0 + +unbalanced join,1,0.001528041636788634,0.002348638488951725,0.0008205968521630912,0.5370251912033469 +Unbalanced Join Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,10,3049.113080910972561465,0.0032796422220629272 +0xac3e018457b222d93114458476f3e3416abbe38f,20,8353.098667955846370862,0.0023943210531828137 +0xae78736cd615f374d3085123a210448e74fc6393,1000,1210.62732888482209938,0.8260180289512851 + +unbalanced join,2,0.000090273444101954,0.00019133342671715545,0.00010105998261520144,1.119487393225689 +Unbalanced Join Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,100,3049.113080910972561465,0.03279642222062927 +0xac3e018457b222d93114458476f3e3416abbe38f,100,8353.098667955846370862,0.011971605265914068 +0xae78736cd615f374d3085123a210448e74fc6393,20,1210.62732888482209938,0.0165203605790257 + +unbalanced join,3,0.00022740264423605,0,-0.00022740264423605,-1 +Unbalanced Join Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,70,3049.113080910972561465,0.022957495554440488 +0xac3e018457b222d93114458476f3e3416abbe38f,10,8353.098667955846370862,0.0011971605265914068 +0xae78736cd615f374d3085123a210448e74fc6393,10,1210.62732888482209938,0.00826018028951285 + +unbalanced join,4,0.000426465472236124,0.00047581041108316595,0.00004934493884704193,0.1157067618822862 +Unbalanced Join Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,1000,3049.113080910972561465,0.3279642222062927 +0xac3e018457b222d93114458476f3e3416abbe38f,20,8353.098667955846370862,0.0023943210531828137 +0xae78736cd615f374d3085123a210448e74fc6393,10,1210.62732888482209938,0.00826018028951285 + +unbalanced join,5,0.000407509868197791,0,-0.000407509868197791,-1 +Unbalanced Join Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,1000,3049.113080910972561465,0.3279642222062927 +0xac3e018457b222d93114458476f3e3416abbe38f,10,8353.098667955846370862,0.0011971605265914068 +0xae78736cd615f374d3085123a210448e74fc6393,200,1210.62732888482209938,0.16520360579025703 + diff --git a/balancer-js/wstETH-rETH-sfrxETH3.csv b/balancer-js/wstETH-rETH-sfrxETH3.csv new file mode 100644 index 000000000..1f228bebf --- /dev/null +++ b/balancer-js/wstETH-rETH-sfrxETH3.csv @@ -0,0 +1,134 @@ +action,test,spot price,ABA,error abs,error rel, +swap,1,0.00042513897108358256,0.00042522406651457345,8.509543099089216e-8,0.000200159093328949 +Swap Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,0,3049.113080910972561465,0 +0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 +0xae78736cd615f374d3085123a210448e74fc6393,10,1210.62732888482209938,0.00826018028951285 + +swap,2,0.000449896614815137,0.00045053520436804105,6.385895529040708e-7,0.0014194139984059849 +Swap Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,0,3049.113080910972561465,0 +0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 +0xae78736cd615f374d3085123a210448e74fc6393,20,1210.62732888482209938,0.0165203605790257 + +swap,3,0.0005219892862547311,0.0005266091246364368,0.0000046198383817057246,0.008850446749305962 +Swap Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,0,3049.113080910972561465,0 +0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 +0xae78736cd615f374d3085123a210448e74fc6393,50,1210.62732888482209938,0.04130090144756426 + +swap,4,0.0006353908140078076,0.0006544619688385467,0.000019071154830739112,0.030014841905638204 +Swap Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,0,3049.113080910972561465,0 +0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 +0xae78736cd615f374d3085123a210448e74fc6393,100,1210.62732888482209938,0.08260180289512851 + +swap,5,0.0009332151386645556,0.001058156804968405,0.0001249416663038495,0.13388302560398113 +Swap Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,0,3049.113080910972561465,0 +0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 +0xae78736cd615f374d3085123a210448e74fc6393,250,1210.62732888482209938,0.20650450723782127 + +swap,6,0.0013274142607690327,0.0019040648029946966,0.0005766505422256638,0.43441641337466375 +Swap Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,0,3049.113080910972561465,0 +0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 +0xae78736cd615f374d3085123a210448e74fc6393,500,1210.62732888482209938,0.41300901447564253 + +swap,7,0.0019048211142684175,0.007441533203378242,0.005536712089109825,2.9066834925526868 +Swap Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,0,3049.113080910972561465,0 +0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 +0xae78736cd615f374d3085123a210448e74fc6393,1000,1210.62732888482209938,0.8260180289512851 + +single token join,1,0.000383513812105359,0.00038362141092074253,1.0759881538351373e-7,0.00028056047002018836 +Single-Sided Join Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,0,3049.113080910972561465,0 +0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 +0xae78736cd615f374d3085123a210448e74fc6393,10,1210.62732888482209938,0.00826018028951285 + +single token join,2,0.000405156684750136,0.00040579925211066127,6.425673605252855e-7,0.0015859725007908063 +Single-Sided Join Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,0,3049.113080910972561465,0 +0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 +0xae78736cd615f374d3085123a210448e74fc6393,20,1210.62732888482209938,0.0165203605790257 + +single token join,3,0.000468039324886439,0.000472464032825286,0.000004424707938847027,0.00945370977090568 +Single-Sided Join Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,0,3049.113080910972561465,0 +0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 +0xae78736cd615f374d3085123a210448e74fc6393,50,1210.62732888482209938,0.04130090144756426 + +single token join,4,0.000566491533663987,0.0005845522225693856,0.00001806068890539852,0.031881657239578746 +Single-Sided Join Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,0,3049.113080910972561465,0 +0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 +0xae78736cd615f374d3085123a210448e74fc6393,100,1210.62732888482209938,0.08260180289512851 + +single token join,5,0.000821700419180966,0.0009392830235303791,0.00011758260434941315,0.14309668293295288 +Single-Sided Join Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,0,3049.113080910972561465,0 +0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 +0xae78736cd615f374d3085123a210448e74fc6393,250,1210.62732888482209938,0.20650450723782127 + +single token join,6,0.001148395863294284,0.0016892046510799332,0.0005408087877856493,0.47092540566480906 +Single-Sided Join Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,0,3049.113080910972561465,0 +0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 +0xae78736cd615f374d3085123a210448e74fc6393,500,1210.62732888482209938,0.41300901447564253 + +single token join,7,0.001582365470886681,0.006761664642277254,0.005179299171390573,3.2731371270938716 +Single-Sided Join Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,0,3049.113080910972561465,0 +0xac3e018457b222d93114458476f3e3416abbe38f,0,8353.098667955846370862,0 +0xae78736cd615f374d3085123a210448e74fc6393,1000,1210.62732888482209938,0.8260180289512851 + +unbalanced join,1,0.000130729624292453,0.0004013075526808268,0.0002705779283883738,2.0697522069142384 +Unbalanced Join Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,10,3049.113080910972561465,0.0032796422220629272 +0xac3e018457b222d93114458476f3e3416abbe38f,200,8353.098667955846370862,0.023943210531828137 +0xae78736cd615f374d3085123a210448e74fc6393,100,1210.62732888482209938,0.08260180289512851 + +unbalanced join,2,0.000227153595183896,0,-0.000227153595183896,-1 +Unbalanced Join Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,10,3049.113080910972561465,0.0032796422220629272 +0xac3e018457b222d93114458476f3e3416abbe38f,5,8353.098667955846370862,0.0005985802632957034 +0xae78736cd615f374d3085123a210448e74fc6393,20,1210.62732888482209938,0.0165203605790257 + +unbalanced join,3,0.000133310891266468,0,-0.000133310891266468,-1 +Unbalanced Join Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,5,3049.113080910972561465,0.0016398211110314636 +0xac3e018457b222d93114458476f3e3416abbe38f,5,8353.098667955846370862,0.0005985802632957034 +0xae78736cd615f374d3085123a210448e74fc6393,5,1210.62732888482209938,0.004130090144756425 + +unbalanced join,4,0.001389759125006863,0.0027240022993653213,0.0013342431743584584,0.9600535447837909 +Unbalanced Join Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,100,3049.113080910972561465,0.03279642222062927 +0xac3e018457b222d93114458476f3e3416abbe38f,20,8353.098667955846370862,0.0023943210531828137 +0xae78736cd615f374d3085123a210448e74fc6393,1000,1210.62732888482209938,0.8260180289512851 + +unbalanced join,5,0.000219440059850442,0,-0.000219440059850442,-1 +Unbalanced Join Summary +0x42ed016f826165c2e5976fe5bc3df540c5ad0af7,0,2596148429267391.797360501734824291,0 +0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0,100,3049.113080910972561465,0.03279642222062927 +0xac3e018457b222d93114458476f3e3416abbe38f,20,8353.098667955846370862,0.0023943210531828137 +0xae78736cd615f374d3085123a210448e74fc6393,20,1210.62732888482209938,0.0165203605790257 + From 3f381f6f2a9d94f90d2044029a28af6a7a5b16d0 Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Wed, 29 Nov 2023 15:49:05 -0300 Subject: [PATCH 15/16] Add single token exit scenarios --- .../pricing/priceImpact.compare.spec.ts | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts b/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts index b87c629b6..00f13226d 100644 --- a/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts +++ b/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts @@ -85,6 +85,19 @@ const unbalancedJoinTests = [ // Add more test scenarios as needed ]; +const exitAmountFloat = '10'; +const tokenOutIndex = 1; +const singleTokenExitTests = [ + { amountFloat: exitAmountFloat, tokenOutIndex }, + { amountFloat: String(Number(exitAmountFloat) * 2), tokenOutIndex }, + { amountFloat: String(Number(exitAmountFloat) * 5), tokenOutIndex }, + { amountFloat: String(Number(exitAmountFloat) * 10), tokenOutIndex }, + { amountFloat: String(Number(exitAmountFloat) * 25), tokenOutIndex }, + { amountFloat: String(Number(exitAmountFloat) * 50), tokenOutIndex }, + { amountFloat: String(Number(exitAmountFloat) * 100), tokenOutIndex }, + // Add more test scenarios as needed +]; + describe('Price impact comparison tests', async () => { let pool: PoolWithMethods; let signerAddress: Address; @@ -534,4 +547,91 @@ describe('Price impact comparison tests', async () => { }); }); }); + + singleTokenExitTests.forEach((test, index) => { + context('single token exit', async () => { + let tokenOut: PoolToken; + let amountIn: BigNumber; + + before(() => { + tokenOut = pool.tokens[test.tokenOutIndex]; + amountIn = parseFixed(test.amountFloat, 18); + }); + + after(async () => { + const csvLine = `single token exit,${ + index + 1 + },${priceImpactSpot},${priceImpactABA},${ + priceImpactABA - priceImpactSpot + },${(priceImpactABA - priceImpactSpot) / priceImpactSpot}\n`; + fs.writeFileSync(csvFilePath, csvLine, { flag: 'a' }); + + writeNewTable('Single-Sided Exit Summary'); + + // Query and write the token balances for single-sided exit summary + for (let i = 0; i < pool.tokensList.length; i++) { + const token = pool.tokensList[i]; + const amount = + i === singleTokenExitTests[i].tokenOutIndex + ? singleTokenExitTests[index].amountFloat + : '0'; + const balance = await pool.tokens[i].balance; + const relativeValue = (Number(amount) / Number(balance)).toString(); + fs.writeFileSync( + csvFilePath, + `${token},${amount},${balance.toString()},${relativeValue}\n`, + { flag: 'a' } + ); + } + + // Write an empty line after single-sided join summary + fs.writeFileSync(csvFilePath, '\n', { flag: 'a' }); + }); + + it('should calculate price impact - spot price method', async () => { + const { priceImpact } = pool.buildExitExactBPTIn( + signerAddress, + amountIn.toString(), + '0', + false, + tokenOut.address + ); + + priceImpactSpot = parseFloat( + formatFixed(BigNumber.from(priceImpact), 18) + ); + console.log(`priceImpactSpotPrice: ${priceImpactSpot}`); + }); + + it('should calculate price impact - ABA method', async () => { + const exitParams = pool.buildQueryExitToSingleToken({ + bptIn: amountIn, + tokenOut: tokenOut.address, + }); + + const { amountsOut } = await balancerHelpers.callStatic.queryExit( + ...exitParams + ); + + const tokensOut = [...pool.tokensList]; + + const maxAmountsInByToken = new Map( + amountsOut.map((a, i) => [tokensOut[i], a]) + ); + + const joinParams = pool.buildQueryJoinExactIn({ + maxAmountsInByToken, + }); + + const { bptOut } = await balancerHelpers.callStatic.queryJoin( + ...joinParams + ); + + const initialA = parseFloat(formatFixed(amountIn, 18)); + const finalA = parseFloat(formatFixed(bptOut, 18)); + priceImpactABA = (initialA - finalA) / initialA / 2; + console.log(`priceImpactABA : ${priceImpactABA}`); + }); + }); + }); }); From 36e9118cf26286de352bedcbabdd1706d90abd14 Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Tue, 20 Feb 2024 15:52:37 -0300 Subject: [PATCH 16/16] Add generalisedJoin scenario to be compared with b-sdk results --- .../priceImpact.compare.nested.spec.ts | 120 ++++++++++++++++++ .../pricing/priceImpact.compare.spec.ts | 1 - balancer-js/src/test/lib/constants.ts | 7 + 3 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 balancer-js/src/modules/pricing/priceImpact.compare.nested.spec.ts diff --git a/balancer-js/src/modules/pricing/priceImpact.compare.nested.spec.ts b/balancer-js/src/modules/pricing/priceImpact.compare.nested.spec.ts new file mode 100644 index 000000000..c4f232925 --- /dev/null +++ b/balancer-js/src/modules/pricing/priceImpact.compare.nested.spec.ts @@ -0,0 +1,120 @@ +// yarn test:only ./src/modules/pricing/priceImpact.compare.nested.spec.ts +import dotenv from 'dotenv'; + +import { BalancerSDK, GraphQLQuery, Network, SimulationType } from '@/.'; +import { parseFixed } from '@ethersproject/bignumber'; +import { JsonRpcProvider } from '@ethersproject/providers'; +import { FORK_NODES, createSubgraphQuery, forkSetup } from '@/test/lib/utils'; +import { ADDRESSES, TestAddress, TestAddresses } from '@/test/lib/constants'; +import { JsonRpcSigner } from '@ethersproject/providers'; +import { RPC_URLS } from '@/test/lib/utils'; +import { testGeneralisedJoin } from '../joins/testHelper'; + +/** + * -- Integration tests for generalisedJoin -- + * + * It compares results from local fork transactions with simulated results from + * the Simulation module, which can be of 3 different types: + * 1. Tenderly: uses Tenderly Simulation API (third party service) + * 2. VaultModel: uses TS math, which may be less accurate (min. 99% accuracy) + * 3. Static: uses staticCall, which is 100% accurate but requires vault approval + */ + +dotenv.config(); + +// mainnet +const TEST_JOIN_WITH_ETH_JOIN_FIRST = true; + +describe('generalised join execution', async function () { + this.timeout(30000); + const simulationType = SimulationType.Static; + let network: Network; + let blockNumber: number; + let jsonRpcUrl: string; + let rpcUrl: string; + let addresses: TestAddresses; + let subgraphQuery: GraphQLQuery; + let sdk: BalancerSDK; + let signer: JsonRpcSigner; + let userAddress: string; + let tokens: TestAddress[]; + let balances: string[]; + let testPool: TestAddress; + + beforeEach(async () => { + await forkSetup( + signer, + tokens.map((t) => t.address), + tokens.map((t) => t.slot as number), + balances, + jsonRpcUrl, + blockNumber + ); + }); + + context('mainnet', async () => { + before(async () => { + network = Network.MAINNET; + blockNumber = 18559730; + jsonRpcUrl = FORK_NODES[network]; + rpcUrl = RPC_URLS[network]; + const provider = new JsonRpcProvider(rpcUrl, network); + signer = provider.getSigner(1); + userAddress = await signer.getAddress(); + addresses = ADDRESSES[network]; + subgraphQuery = createSubgraphQuery( + [ + '0x08775ccb6674d6bdceb0797c364c2653ed84f384', + '0x79c58f70905f734641735bc61e45c19dd9ad60bc', + ], + blockNumber + ); + // // Uncomment and set tenderlyConfig on sdk instantiation in order to test using tenderly simulations + // const tenderlyConfig = { + // accessKey: process.env.TENDERLY_ACCESS_KEY as string, + // user: process.env.TENDERLY_USER as string, + // project: process.env.TENDERLY_PROJECT as string, + // blockNumber, + // }; + sdk = new BalancerSDK({ + network, + rpcUrl, + subgraphQuery, + }); + }); + + context('join with all tokens - unbalanced', async () => { + if (!TEST_JOIN_WITH_ETH_JOIN_FIRST) return true; + + before(async () => { + testPool = addresses.WETH_3POOL; + tokens = [ + addresses.DAI, + addresses.USDC, + addresses.USDT, + addresses.WETH, + ]; + balances = [ + parseFixed('100000', addresses.DAI.decimals).toString(), + parseFixed('1000', addresses.USDC.decimals).toString(), + parseFixed('10', addresses.USDT.decimals).toString(), + parseFixed('0.1', addresses.WETH.decimals).toString(), + ]; + }); + + it('should join with all tokens', async () => { + const tokensIn = tokens.map((t) => t.address); + const amountsIn = balances; + await testGeneralisedJoin( + sdk, + signer, + userAddress, + testPool, + tokensIn, + amountsIn, + simulationType + ); + }); + }); + }); +}); diff --git a/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts b/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts index 00f13226d..41afa826f 100644 --- a/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts +++ b/balancer-js/src/modules/pricing/priceImpact.compare.spec.ts @@ -7,7 +7,6 @@ import * as fs from 'fs'; import { Address, BalancerSDK, - BatchSwapStep, Network, PoolToken, PoolWithMethods, diff --git a/balancer-js/src/test/lib/constants.ts b/balancer-js/src/test/lib/constants.ts index 48f89bf1a..2f320e637 100644 --- a/balancer-js/src/test/lib/constants.ts +++ b/balancer-js/src/test/lib/constants.ts @@ -408,6 +408,13 @@ export const ADDRESSES = { symbol: 'bveth', slot: 0, }, + WETH_3POOL: { + id: '0x08775ccb6674d6bdceb0797c364c2653ed84f3840002000000000000000004f0', + address: '0x08775ccb6674d6bdceb0797c364c2653ed84f384', + decimals: 18, + symbol: 'weth_3pool', + slot: 0, + }, }, [Network.POLYGON]: { MATIC: {