diff --git a/package.json b/package.json index 47ce6f7c..bdc9cfb8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@balancer-labs/sor", - "version": "4.0.1-beta.2", + "version": "4.0.1-beta.3", "license": "GPL-3.0-only", "main": "dist/index.js", "module": "dist/index.esm.js", diff --git a/src/poolCacher.ts b/src/poolCacher.ts index ac59b35c..b6fac414 100644 --- a/src/poolCacher.ts +++ b/src/poolCacher.ts @@ -28,7 +28,7 @@ export class PoolCacher { // On error clear all caches and return false so user knows to try again. this._finishedFetching = false; this.pools = []; - console.error(`Error: fetchPools(): ${err.message}`); + console.error(`Error: fetchPools(): ${err}`); return false; } } diff --git a/src/pools/index.ts b/src/pools/index.ts index f6fc832f..37c0dcda 100644 --- a/src/pools/index.ts +++ b/src/pools/index.ts @@ -60,7 +60,10 @@ export function parseNewPool( newPool.setCurrentBlockTimestamp(currentBlockTimestamp); } else if (pool.poolType.toString().includes('Linear')) newPool = LinearPool.fromPool(pool); - else if (pool.poolType === 'StablePhantom') + else if ( + pool.poolType === 'StablePhantom' || + pool.poolType === 'ComposableStable' + ) newPool = PhantomStablePool.fromPool(pool); else if (pool.poolType === 'Gyro2') newPool = Gyro2Pool.fromPool(pool); else if (pool.poolType === 'Gyro3') newPool = Gyro3Pool.fromPool(pool); diff --git a/src/pools/metaStablePool/metaStablePool.ts b/src/pools/metaStablePool/metaStablePool.ts index f0ae920a..18b35a71 100644 --- a/src/pools/metaStablePool/metaStablePool.ts +++ b/src/pools/metaStablePool/metaStablePool.ts @@ -228,7 +228,7 @@ export class MetaStablePool implements PoolBase { return bnum(formatFixed(returnEvmWithRate, 18)); } catch (err) { - console.error(`_evmoutGivenIn: ${err.message}`); + // console.error(`_evmoutGivenIn: ${err.message}`); return ZERO; } } diff --git a/src/pools/phantomStablePool/phantomStableMath.ts b/src/pools/phantomStablePool/phantomStableMath.ts index 1e857147..b5b03ee0 100644 --- a/src/pools/phantomStablePool/phantomStableMath.ts +++ b/src/pools/phantomStablePool/phantomStableMath.ts @@ -8,11 +8,6 @@ import { } from '../../utils/bignumber'; import { PhantomStablePoolPairData } from './phantomStablePool'; -const MAX_TOKEN_BALANCE = bnum(2) - .pow(112) - .minus(1) - .div(10 ** 18); - // All functions are adapted from the solidity ones to be found on: // https://github.com/balancer-labs/balancer-core-v2/blob/master/contracts/pools/stable/StableMath.sol @@ -474,8 +469,7 @@ export function _exactBPTInForTokenOut( // we input zero the output should be zero if (amount.isZero()) return amount; - const { amp, allBalances, balanceIn, tokenIndexOut, decimalsIn, swapFee } = - poolPairData; + const { amp, allBalances, tokenIndexOut, swapFee } = poolPairData; const balances = [...allBalances]; const bptAmountIn = amount; @@ -486,10 +480,7 @@ export function _exactBPTInForTokenOut( // Get current invariant const currentInvariant = _invariant(amp, balances); // Calculate new invariant - - const bnumBalanceIn = MAX_TOKEN_BALANCE.minus( - bnum(formatFixed(balanceIn, decimalsIn)) - ); + const bnumBalanceIn = bnum(formatFixed(poolPairData.virtualBptSupply, 18)); const newInvariant = bnumBalanceIn .minus(bptAmountIn) .div(bnumBalanceIn) diff --git a/src/pools/phantomStablePool/phantomStablePool.ts b/src/pools/phantomStablePool/phantomStablePool.ts index 0d2d2ded..8b18ac8b 100644 --- a/src/pools/phantomStablePool/phantomStablePool.ts +++ b/src/pools/phantomStablePool/phantomStablePool.ts @@ -49,8 +49,6 @@ export class PhantomStablePool implements PoolBase { tokens: PhantomStablePoolToken[]; tokensList: string[]; ALMOST_ONE = parseFixed('0.99', 18); - // Used for VirutalBpt and can be removed if SG is updated with VirtualBpt value - MAX_TOKEN_BALANCE = BigNumber.from('2').pow('112').sub('1'); static AMP_DECIMALS = 3; @@ -151,10 +149,7 @@ export class PhantomStablePool implements PoolBase { const bptIndex = this.tokensList.indexOf(this.address); // VirtualBPTSupply must be used for the maths - // TO DO - SG should be updated to so that totalShares should return VirtualSupply - const virtualBptSupply = this.MAX_TOKEN_BALANCE.sub( - allBalancesScaled[bptIndex] - ); + const virtualBptSupply = this.totalShares; const poolPairData: PhantomStablePoolPairData = { id: this.id, @@ -293,7 +288,7 @@ export class PhantomStablePool implements PoolBase { // Return human scaled return bnum(formatFixed(returnEvmWithRate, 18)); } catch (err) { - console.error(`PhantomStable _evmoutGivenIn: ${err.message}`); + // console.error(`PhantomStable _evmoutGivenIn: ${err.message}`); return ZERO; } } diff --git a/src/pools/stablePool/stablePool.ts b/src/pools/stablePool/stablePool.ts index e4b1d43d..981df362 100644 --- a/src/pools/stablePool/stablePool.ts +++ b/src/pools/stablePool/stablePool.ts @@ -211,7 +211,7 @@ export class StablePool implements PoolBase { 1 ); } catch (err) { - console.error(`_evmoutGivenIn: ${err.message}`); + // console.error(`_evmoutGivenIn: ${err.message}`); return ZERO; } } diff --git a/src/types.ts b/src/types.ts index 3d6e5fc1..007ec5ab 100644 --- a/src/types.ts +++ b/src/types.ts @@ -165,6 +165,7 @@ export enum PoolFilter { ERC4626Linear = 'ERC4626Linear', Gyro2 = 'Gyro2', Gyro3 = 'Gyro3', + ComposableStable = 'ComposableStable', } export interface PoolBase { diff --git a/test/lib/onchainData.ts b/test/lib/onchainData.ts index a3c4d5b0..849c0760 100644 --- a/test/lib/onchainData.ts +++ b/test/lib/onchainData.ts @@ -71,7 +71,8 @@ export async function getOnChainBalances( } else if ( pool.poolType === 'Stable' || pool.poolType === 'MetaStable' || - pool.poolType === 'StablePhantom' + pool.poolType === 'StablePhantom' || + pool.poolType === 'ComposableStable' ) { // MetaStable & StablePhantom is the same as Stable for multicall purposes multiPool.call( @@ -150,7 +151,8 @@ export async function getOnChainBalances( if ( subgraphPools[index].poolType === 'Stable' || subgraphPools[index].poolType === 'MetaStable' || - subgraphPools[index].poolType === 'StablePhantom' + subgraphPools[index].poolType === 'StablePhantom' || + subgraphPools[index].poolType === 'ComposableStable' ) { if (!onchainData.amp) { console.error(`Stable Pool Missing Amp: ${poolId}`); diff --git a/test/phantomStableMath.spec.ts b/test/phantomStableMath.spec.ts index c1afdc1b..26d603f1 100644 --- a/test/phantomStableMath.spec.ts +++ b/test/phantomStableMath.spec.ts @@ -1,4 +1,4 @@ -// TS_NODE_PROJECT='tsconfig.testing.json' npx mocha -r ts-node/register test/math.spec.ts +// TS_NODE_PROJECT='tsconfig.testing.json' npx mocha -r ts-node/register test/phantomStableMath.spec.ts import { assert } from 'chai'; import { formatFixed } from '@ethersproject/bignumber'; import { BigNumber as OldBigNumber } from '../src/utils/bignumber'; diff --git a/test/testData/boostedPools/boostedPoolsWithWstETH.json b/test/testData/boostedPools/boostedPoolsWithWstETH.json index bd7e58a2..887d3e6b 100644 --- a/test/testData/boostedPools/boostedPoolsWithWstETH.json +++ b/test/testData/boostedPools/boostedPoolsWithWstETH.json @@ -48,7 +48,7 @@ "0x6a8c3239695613c0710dc971310b36f9b81e115e", "0xcd32a460b6fecd053582e43b07ed6e2c04e15369" ], - "totalShares": "0", + "totalShares": "14473.09292830139671902", "totalWeight": "0", "wrappedIndex": 0 }, @@ -364,7 +364,7 @@ "0x0000000000000000000000000000000000211111", "0x0000000000000000000000000000000000000000" ], - "totalShares": "0", + "totalShares": "14473.09292830139671902", "totalWeight": "0", "wrappedIndex": 0 }, diff --git a/test/testData/boostedPools/genericBoosted.json b/test/testData/boostedPools/genericBoosted.json index 370cca77..fa3c39cb 100644 --- a/test/testData/boostedPools/genericBoosted.json +++ b/test/testData/boostedPools/genericBoosted.json @@ -48,7 +48,7 @@ "0x6a8c3239695613c0710dc971310b36f9b81e115e", "0xcd32a460b6fecd053582e43b07ed6e2c04e15369" ], - "totalShares": "0", + "totalShares": "14473.09292830139671902", "totalWeight": "0", "wrappedIndex": 0 }, @@ -364,7 +364,7 @@ "0x0000000000000000000000000000000000211111", "0x0000000000000000000000000000000000000000" ], - "totalShares": "0", + "totalShares": "14473.09292830139671902", "totalWeight": "0", "wrappedIndex": 0 }, diff --git a/test/testData/boostedPools/multipleBoosted.json b/test/testData/boostedPools/multipleBoosted.json index 8003fd87..552b4e36 100644 --- a/test/testData/boostedPools/multipleBoosted.json +++ b/test/testData/boostedPools/multipleBoosted.json @@ -48,7 +48,7 @@ "0x6a8c3239695613c0710dc971310b36f9b81e115e", "0xcd32a460b6fecd053582e43b07ed6e2c04e15369" ], - "totalShares": "0", + "totalShares": "14473.09292830139671902", "totalWeight": "0", "wrappedIndex": 0 }, diff --git a/test/testData/linearPools/fullKovan.json b/test/testData/linearPools/fullKovan.json index b533d99c..fd42620d 100644 --- a/test/testData/linearPools/fullKovan.json +++ b/test/testData/linearPools/fullKovan.json @@ -14518,7 +14518,7 @@ "0x6a8c3239695613c0710dc971310b36f9b81e115e", "0xcd32a460b6fecd053582e43b07ed6e2c04e15369" ], - "totalShares": "4500", + "totalShares": "18973.09292830139671902", "totalWeight": "0", "unitSeconds": 0, "upperTarget": "null", diff --git a/test/testData/linearPools/kovan.json b/test/testData/linearPools/kovan.json index 5aac91e1..6d947e48 100644 --- a/test/testData/linearPools/kovan.json +++ b/test/testData/linearPools/kovan.json @@ -48,7 +48,7 @@ "0x6a8c3239695613c0710dc971310b36f9b81e115e", "0xcd32a460b6fecd053582e43b07ed6e2c04e15369" ], - "totalShares": "0", + "totalShares": "14473.09292830139671902", "totalWeight": "0", "wrappedIndex": 0 }, diff --git a/test/testData/linearPools/smallLinear.json b/test/testData/linearPools/smallLinear.json index dab451a7..f1265265 100644 --- a/test/testData/linearPools/smallLinear.json +++ b/test/testData/linearPools/smallLinear.json @@ -323,7 +323,7 @@ "0x0000000000000000000000000000000000000003", "0x8fd162f338b770f7e879030830cde9173367f301" ], - "totalShares": "10000000", + "totalShares": "3692296858534827.628530496329220095", "poolType": "StablePhantom" }, { diff --git a/test/testData/phantomStablePools/phantomStablePool.json b/test/testData/phantomStablePools/phantomStablePool.json index 7f4bed75..cb1f2006 100644 --- a/test/testData/phantomStablePools/phantomStablePool.json +++ b/test/testData/phantomStablePools/phantomStablePool.json @@ -109,7 +109,7 @@ "0x6a8c3239695613c0710dc971310b36f9b81e115e", "0xcd32a460b6fecd053582e43b07ed6e2c04e15369" ], - "totalShares": "5192296858534827.628530496329220095", + "totalShares": "14473.09292830139671902", "totalWeight": "0", "unitSeconds": 0, "upperTarget": "0", diff --git a/test/testData/phantomStablePools/phantomStableStabal3WithPriceRates.json b/test/testData/phantomStablePools/phantomStableStabal3WithPriceRates.json index 2c4ff8c8..e0695887 100644 --- a/test/testData/phantomStablePools/phantomStableStabal3WithPriceRates.json +++ b/test/testData/phantomStablePools/phantomStableStabal3WithPriceRates.json @@ -48,7 +48,7 @@ "0x6a8c3239695613c0710dc971310b36f9b81e115e", "0xcd32a460b6fecd053582e43b07ed6e2c04e15369" ], - "totalShares": "5192296858534827.628530496329220095", + "totalShares": "14473.09292830139671902", "totalWeight": "0", "unitSeconds": 0, "upperTarget": "0", diff --git a/test/testScripts/constants.ts b/test/testScripts/constants.ts index a7fef816..35974fa4 100644 --- a/test/testScripts/constants.ts +++ b/test/testScripts/constants.ts @@ -66,7 +66,7 @@ export const MULTIADDR: { [chainId: number]: string } = { export const SUBGRAPH_URLS = { [Network.MAINNET]: - 'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-v2', + 'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-v2-beta', [Network.GOERLI]: 'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-goerli-v2', [Network.KOVAN]: @@ -149,6 +149,16 @@ export const ADDRESSES = { decimals: 6, symbol: 'waUSDC', }, + bbausd2: { + address: '0x9b532ab955417afd0d012eb9f7389457cd0ea712', + decimals: 18, + symbol: 'bbausd2', + }, + bbadai2: { + address: '0xae37d54ae477268b9997d4161b96b8200755935c', + decimals: 18, + symbol: 'bb-a-dai2', + }, }, [Network.KOVAN]: { // Visit https://balancer-faucet.on.fleek.co/#/faucet for test tokens