Skip to content

Commit

Permalink
Merge pull request #281 from balancer-labs/4.0.1-beta.3
Browse files Browse the repository at this point in the history
4.0.1 beta.3
  • Loading branch information
John Grant authored Aug 23, 2022
2 parents 57b0682 + 9ec3c63 commit 3721c27
Show file tree
Hide file tree
Showing 19 changed files with 39 additions and 37 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/poolCacher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/pools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/pools/metaStablePool/metaStablePool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
13 changes: 2 additions & 11 deletions src/pools/phantomStablePool/phantomStableMath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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;

Expand All @@ -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)
Expand Down
9 changes: 2 additions & 7 deletions src/pools/phantomStablePool/phantomStablePool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/pools/stablePool/stablePool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export class StablePool implements PoolBase {
1
);
} catch (err) {
console.error(`_evmoutGivenIn: ${err.message}`);
// console.error(`_evmoutGivenIn: ${err.message}`);
return ZERO;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export enum PoolFilter {
ERC4626Linear = 'ERC4626Linear',
Gyro2 = 'Gyro2',
Gyro3 = 'Gyro3',
ComposableStable = 'ComposableStable',
}

export interface PoolBase {
Expand Down
6 changes: 4 additions & 2 deletions test/lib/onchainData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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}`);
Expand Down
2 changes: 1 addition & 1 deletion test/phantomStableMath.spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
4 changes: 2 additions & 2 deletions test/testData/boostedPools/boostedPoolsWithWstETH.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"0x6a8c3239695613c0710dc971310b36f9b81e115e",
"0xcd32a460b6fecd053582e43b07ed6e2c04e15369"
],
"totalShares": "0",
"totalShares": "14473.09292830139671902",
"totalWeight": "0",
"wrappedIndex": 0
},
Expand Down Expand Up @@ -364,7 +364,7 @@
"0x0000000000000000000000000000000000211111",
"0x0000000000000000000000000000000000000000"
],
"totalShares": "0",
"totalShares": "14473.09292830139671902",
"totalWeight": "0",
"wrappedIndex": 0
},
Expand Down
4 changes: 2 additions & 2 deletions test/testData/boostedPools/genericBoosted.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"0x6a8c3239695613c0710dc971310b36f9b81e115e",
"0xcd32a460b6fecd053582e43b07ed6e2c04e15369"
],
"totalShares": "0",
"totalShares": "14473.09292830139671902",
"totalWeight": "0",
"wrappedIndex": 0
},
Expand Down Expand Up @@ -364,7 +364,7 @@
"0x0000000000000000000000000000000000211111",
"0x0000000000000000000000000000000000000000"
],
"totalShares": "0",
"totalShares": "14473.09292830139671902",
"totalWeight": "0",
"wrappedIndex": 0
},
Expand Down
2 changes: 1 addition & 1 deletion test/testData/boostedPools/multipleBoosted.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"0x6a8c3239695613c0710dc971310b36f9b81e115e",
"0xcd32a460b6fecd053582e43b07ed6e2c04e15369"
],
"totalShares": "0",
"totalShares": "14473.09292830139671902",
"totalWeight": "0",
"wrappedIndex": 0
},
Expand Down
2 changes: 1 addition & 1 deletion test/testData/linearPools/fullKovan.json
Original file line number Diff line number Diff line change
Expand Up @@ -14518,7 +14518,7 @@
"0x6a8c3239695613c0710dc971310b36f9b81e115e",
"0xcd32a460b6fecd053582e43b07ed6e2c04e15369"
],
"totalShares": "4500",
"totalShares": "18973.09292830139671902",
"totalWeight": "0",
"unitSeconds": 0,
"upperTarget": "null",
Expand Down
2 changes: 1 addition & 1 deletion test/testData/linearPools/kovan.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"0x6a8c3239695613c0710dc971310b36f9b81e115e",
"0xcd32a460b6fecd053582e43b07ed6e2c04e15369"
],
"totalShares": "0",
"totalShares": "14473.09292830139671902",
"totalWeight": "0",
"wrappedIndex": 0
},
Expand Down
2 changes: 1 addition & 1 deletion test/testData/linearPools/smallLinear.json
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@
"0x0000000000000000000000000000000000000003",
"0x8fd162f338b770f7e879030830cde9173367f301"
],
"totalShares": "10000000",
"totalShares": "3692296858534827.628530496329220095",
"poolType": "StablePhantom"
},
{
Expand Down
2 changes: 1 addition & 1 deletion test/testData/phantomStablePools/phantomStablePool.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
"0x6a8c3239695613c0710dc971310b36f9b81e115e",
"0xcd32a460b6fecd053582e43b07ed6e2c04e15369"
],
"totalShares": "5192296858534827.628530496329220095",
"totalShares": "14473.09292830139671902",
"totalWeight": "0",
"unitSeconds": 0,
"upperTarget": "0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"0x6a8c3239695613c0710dc971310b36f9b81e115e",
"0xcd32a460b6fecd053582e43b07ed6e2c04e15369"
],
"totalShares": "5192296858534827.628530496329220095",
"totalShares": "14473.09292830139671902",
"totalWeight": "0",
"unitSeconds": 0,
"upperTarget": "0",
Expand Down
12 changes: 11 additions & 1 deletion test/testScripts/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3721c27

Please sign in to comment.