Skip to content

Commit

Permalink
Merge pull request #250 from balancer-labs/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
John Grant authored Apr 27, 2022
2 parents ff584ab + cc9adad commit 53526eb
Show file tree
Hide file tree
Showing 10 changed files with 1,021 additions and 117 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.0-beta.2",
"version": "4.0.0-beta.3",
"license": "GPL-3.0-only",
"main": "dist/index.js",
"module": "dist/index.esm.js",
Expand Down
32 changes: 17 additions & 15 deletions src/pools/weightedPool/weightedPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
} from './weightedMath';
import { BigNumber, formatFixed, parseFixed } from '@ethersproject/bignumber';
import { WeiPerEther as ONE } from '@ethersproject/constants';
import { takeToPrecision18 } from '../../router/helpersClass';

export type WeightedPoolToken = Pick<
NoNullableField<SubgraphToken>,
Expand Down Expand Up @@ -182,22 +183,23 @@ export class WeightedPool implements PoolBase {
amount: OldBigNumber
): OldBigNumber {
if (amount.isNaN()) return amount;
const balanceIn = poolPairData.balanceIn;
const balanceOut = poolPairData.balanceOut;
const decimalsIn = poolPairData.decimalsIn;
const decimalsOut = poolPairData.decimalsOut;

try {
const amt = _calcOutGivenIn(
poolPairData.balanceIn.toBigInt(),
takeToPrecision18(balanceIn, decimalsIn).toBigInt(),
poolPairData.weightIn.toBigInt(),
poolPairData.balanceOut.toBigInt(),
takeToPrecision18(balanceOut, decimalsOut).toBigInt(),
poolPairData.weightOut.toBigInt(),
parseFixed(
amount.dp(poolPairData.decimalsIn, 1).toString(),
poolPairData.decimalsIn
).toBigInt(),
parseFixed(amount.dp(18, 1).toString(), 18).toBigInt(),
poolPairData.swapFee.toBigInt()
);
// return human scaled
const amtOldBn = bnum(amt.toString());
return scale(amtOldBn, -poolPairData.decimalsOut);
return scale(amtOldBn, -18);
} catch (err) {
return ZERO;
}
Expand All @@ -212,22 +214,22 @@ export class WeightedPool implements PoolBase {
amount: OldBigNumber
): OldBigNumber {
if (amount.isNaN()) return amount;

const balanceIn = poolPairData.balanceIn;
const balanceOut = poolPairData.balanceOut;
const decimalsIn = poolPairData.decimalsIn;
const decimalsOut = poolPairData.decimalsOut;
try {
const amt = _calcInGivenOut(
poolPairData.balanceIn.toBigInt(),
takeToPrecision18(balanceIn, decimalsIn).toBigInt(),
poolPairData.weightIn.toBigInt(),
poolPairData.balanceOut.toBigInt(),
takeToPrecision18(balanceOut, decimalsOut).toBigInt(),
poolPairData.weightOut.toBigInt(),
parseFixed(
amount.dp(poolPairData.decimalsOut, 1).toString(),
poolPairData.decimalsOut
).toBigInt(),
parseFixed(amount.dp(18, 1).toString(), 18).toBigInt(),
poolPairData.swapFee.toBigInt()
);
// return human scaled
const amtOldBn = bnum(amt.toString());
return scale(amtOldBn, -poolPairData.decimalsIn);
return scale(amtOldBn, -18);
} catch (err) {
return ZERO;
}
Expand Down
Loading

0 comments on commit 53526eb

Please sign in to comment.