Skip to content

Commit

Permalink
Merge pull request #15 from balancer/use-balancesLiveScaled18
Browse files Browse the repository at this point in the history
refactor: Use use balancesLiveScaled18.
  • Loading branch information
johngrantuk authored Jul 12, 2024
2 parents cf3e56e + ad7666c commit 4763e9f
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion testData/src/stablePool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class StablePool {
return {
swapFee: multicallResult[0].toString(),
totalSupply: multicallResult[1].toString(),
balances: multicallResult[2].map((b) => b.toString()),
balancesLiveScaled18: multicallResult[2].map((b) => b.toString()),
tokenRates: multicallResult[3][1].map((b) => b.toString()),
amp: multicallResult[4][0].toString(),
};
Expand Down
2 changes: 1 addition & 1 deletion testData/src/weightedPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class WeightedPool {
return {
swapFee: multicallResult[0].toString(),
totalSupply: multicallResult[1].toString(),
balances: multicallResult[2].map((b) => b.toString()),
balancesLiveScaled18: multicallResult[2].map((b) => b.toString()),
tokenRates: multicallResult[3][1].map((b) => b.toString()),
};
}
Expand Down
2 changes: 1 addition & 1 deletion testData/testData/11155111-5955145-Weighted.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
],
"swapFee": "10000000000000000",
"totalSupply": "141421356237306671",
"balances": [
"balancesLiveScaled18": [
"5000000000000000",
"4000000000000000000"
],
Expand Down
2 changes: 1 addition & 1 deletion testData/testData/11155111-5955146-Weighted.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
],
"swapFee": "10000000000000000",
"totalSupply": "141421356237306671",
"balances": [
"balancesLiveScaled18": [
"5000000000000000",
"4000000000000000000"
],
Expand Down
2 changes: 1 addition & 1 deletion testData/testData/11155111-6113328-Stable.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
],
"swapFee": "10000000000000000",
"totalSupply": "1048229851439035843046",
"balances": [
"balancesLiveScaled18": [
"514790820812959778500",
"536527062318691819000"
],
Expand Down
2 changes: 1 addition & 1 deletion typescript/src/stable/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ type PoolType = 'Stable';

export type StableMutable = {
swapFee: bigint;
balances: bigint[];
balancesLiveScaled18: bigint[];
tokenRates: bigint[];
totalSupply: bigint;
amp: bigint;
Expand Down
2 changes: 1 addition & 1 deletion typescript/src/stable/stablePool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class Stable implements PoolBase {
onSwap(swapParams: SwapParams): bigint {
const {
swapKind,
balancesScaled18,
balancesLiveScaled18: balancesScaled18,
indexIn,
indexOut,
amountGivenScaled18,
Expand Down
2 changes: 1 addition & 1 deletion typescript/src/vault/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface PoolBase {
export type SwapParams = {
swapKind: SwapKind;
amountGivenScaled18: bigint;
balancesScaled18: bigint[];
balancesLiveScaled18: bigint[];
indexIn: number;
indexOut: number;
};
Expand Down
12 changes: 6 additions & 6 deletions typescript/src/vault/vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class Vault {
const swapParams: SwapParams = {
swapKind: input.swapKind,
amountGivenScaled18,
balancesScaled18: poolState.balances,
balancesLiveScaled18: poolState.balancesLiveScaled18,
indexIn: inputIndex,
indexOut: outputIndex,
};
Expand Down Expand Up @@ -153,7 +153,7 @@ export class Vault {
if (input.kind === AddKind.UNBALANCED) {
amountsInScaled18 = maxAmountsInScaled18;
const computed = computeAddLiquidityUnbalanced(
poolState.balances, // should be liveScaled18
poolState.balancesLiveScaled18,
maxAmountsInScaled18,
poolState.totalSupply,
poolState.swapFee,
Expand All @@ -166,7 +166,7 @@ export class Vault {
amountsInScaled18 = maxAmountsInScaled18;
bptAmountOut = input.minBptAmountOut;
const computed = computeAddLiquiditySingleTokenExactOut(
poolState.balances, // should be liveScaled18
poolState.balancesLiveScaled18,
tokenIndex,
bptAmountOut,
poolState.totalSupply,
Expand Down Expand Up @@ -231,7 +231,7 @@ export class Vault {
if (input.kind === RemoveKind.PROPORTIONAL) {
bptAmountIn = input.maxBptAmountIn;
amountsOutScaled18 = computeProportionalAmountsOut(
poolState.balances,
poolState.balancesLiveScaled18,
poolState.totalSupply,
input.maxBptAmountIn,
);
Expand All @@ -240,7 +240,7 @@ export class Vault {
amountsOutScaled18 = minAmountsOutScaled18;
tokenOutIndex = this._getSingleInputIndex(input.minAmountsOut);
const computed = computeRemoveLiquiditySingleTokenExactIn(
poolState.balances,
poolState.balancesLiveScaled18,
tokenOutIndex,
input.maxBptAmountIn,
poolState.totalSupply,
Expand All @@ -257,7 +257,7 @@ export class Vault {
amountsOutScaled18 = minAmountsOutScaled18;
tokenOutIndex = this._getSingleInputIndex(input.minAmountsOut);
const computed = computeRemoveLiquiditySingleTokenExactOut(
poolState.balances,
poolState.balancesLiveScaled18,
tokenOutIndex,
amountsOutScaled18[tokenOutIndex],
poolState.totalSupply,
Expand Down
2 changes: 1 addition & 1 deletion typescript/src/weighted/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ type PoolType = 'Weighted';

export type WeightedMutable = {
swapFee: bigint;
balances: bigint[];
balancesLiveScaled18: bigint[];
tokenRates: bigint[];
totalSupply: bigint;
};
Expand Down
2 changes: 1 addition & 1 deletion typescript/src/weighted/weightedPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class Weighted implements PoolBase {
onSwap(swapParams: SwapParams): bigint {
const {
swapKind,
balancesScaled18,
balancesLiveScaled18: balancesScaled18,
indexIn,
indexOut,
amountGivenScaled18,
Expand Down
4 changes: 2 additions & 2 deletions typescript/test/utils/readTestData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function mapPool(
...pool,
scalingFactors: pool.scalingFactors.map((sf) => BigInt(sf)),
swapFee: BigInt(pool.swapFee),
balances: pool.balances.map((b) => BigInt(b)),
balancesLiveScaled18: pool.balancesLiveScaled18.map((b) => BigInt(b)),
tokenRates: pool.tokenRates.map((r) => BigInt(r)),
totalSupply: BigInt(pool.totalSupply),
weights: (
Expand All @@ -156,7 +156,7 @@ function mapPool(
...pool,
scalingFactors: pool.scalingFactors.map((sf) => BigInt(sf)),
swapFee: BigInt(pool.swapFee),
balances: pool.balances.map((b) => BigInt(b)),
balancesLiveScaled18: pool.balancesLiveScaled18.map((b) => BigInt(b)),
tokenRates: pool.tokenRates.map((r) => BigInt(r)),
totalSupply: BigInt(pool.totalSupply),
amp: BigInt((pool as TransformBigintToString<StablePool>).amp),
Expand Down

0 comments on commit 4763e9f

Please sign in to comment.