Skip to content

Commit

Permalink
Merge pull request #391 from balancer/develop
Browse files Browse the repository at this point in the history
4.1.1-beta.11
  • Loading branch information
John Grant authored May 23, 2023
2 parents 58866f5 + f823c5d commit 3d6890a
Show file tree
Hide file tree
Showing 12 changed files with 2,564 additions and 2,352 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- name: Install node
uses: actions/setup-node@v3
with:
node-version: 16.15.1
node-version: 14.16.1
- name: Cache
uses: actions/cache@v2
id: cache
Expand All @@ -31,7 +31,7 @@ jobs:
- name: Install node
uses: actions/setup-node@v3
with:
node-version: 16.15.1
node-version: 14.16.1
- name: Cache
uses: actions/cache@v2
id: cache
Expand All @@ -51,7 +51,7 @@ jobs:
- name: Install node
uses: actions/setup-node@v3
with:
node-version: 16.15.1
node-version: 14.16.1
- name: Cache
uses: actions/cache@v2
id: cache
Expand Down
38 changes: 15 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
{
"name": "@balancer-labs/sor",
"version": "4.1.1-beta.10",
"engines": {
"node": ">=14",
"npm": ">=8"
},
"version": "4.1.1-beta.11",
"license": "GPL-3.0-only",
"module": "./dist/esm/index.js",
"main": "./dist/cjs/index.js",
"sideEffects": false,
"main": "dist/index.js",
"module": "dist/index.esm.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "rimraf dist && rollup --config rollup.config.ts --configPlugin typescript",
"build": "rollup -c",
"prepack": "yarn build",
"test": "TS_NODE_PROJECT='tsconfig.testing.json' nyc mocha -r ts-node/register test/*.spec.ts --timeout 20000",
"test:only": "TS_NODE_PROJECT='tsconfig.testing.json' npx mocha -r ts-node/register --timeout 20000",
Expand Down Expand Up @@ -43,17 +38,17 @@
"@ethersproject/wallet": "^5.4.0",
"@georgeroman/balancer-v2-pools": "0.0.7",
"@nomiclabs/hardhat-ethers": "^2.0.6",
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-terser": "^0.4.0",
"@rollup/plugin-typescript": "^11.0.0",
"@rollup/plugin-commonjs": "^20.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.0.4",
"@rollup/plugin-typescript": "^8.2.5",
"@types/chai": "^4.2.10",
"@types/lodash.clonedeep": "^4.5.6",
"@types/mocha": "^7.0.2",
"@types/node": "^14.0.20",
"@typescript-eslint/eslint-plugin": "^5.54.1",
"@typescript-eslint/parser": "^5.54.1",
"@typescript-eslint/eslint-plugin": "^4.29.2",
"@typescript-eslint/parser": "^4.29.2",
"bignumber.js": "^9.0.1",
"chai": "^4.2.0",
"dotenv": "^8.2.0",
"eslint": "^7.32.0",
Expand All @@ -68,12 +63,10 @@
"perf_hooks": "^0.0.1",
"prettier": "^2.3.2",
"pretty-quick": "^2.0.1",
"rimraf": "^5.0.0",
"rollup": "^3.18.0",
"rollup-plugin-analyzer": "^4.0.0",
"rollup-plugin-dts": "^5.2.0",
"rollup": "^2.56.3",
"rollup-plugin-dts": "^4.0.0",
"ts-node": "^10.0.0",
"typescript": "^4.9.5"
"typescript": "^4.3.5"
},
"dependencies": {
"isomorphic-fetch": "^2.2.1"
Expand All @@ -84,7 +77,6 @@
"@ethersproject/bignumber": "^5.4.2",
"@ethersproject/constants": "^5.4.0",
"@ethersproject/contracts": "^5.4.1",
"@ethersproject/providers": "^5.4.4",
"bignumber.js": "^9.0.1"
"@ethersproject/providers": "^5.4.4"
}
}
50 changes: 5 additions & 45 deletions rollup.config.ts
Original file line number Diff line number Diff line change
@@ -1,69 +1,29 @@
import { nodeResolve } from '@rollup/plugin-node-resolve';
import { readFileSync } from 'node:fs';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import typescript from '@rollup/plugin-typescript';
import dts from 'rollup-plugin-dts';
import analyze from 'rollup-plugin-analyzer';
import terser from '@rollup/plugin-terser';

const pkg = JSON.parse(
readFileSync(new URL('./package.json', import.meta.url)).toString()
);
import pkg from './package.json';

const external = [
...Object.keys(pkg.dependencies),
...Object.keys(pkg.peerDependencies),
];

export default [
{
treeshake: { moduleSideEffects: false },
input: 'src/index.ts',
output: [
{
format: 'cjs',
sourcemap: true,
file: 'dist/cjs/index.js',
},
{
format: 'es',
sourcemap: true,
dir: 'dist/esm',
preserveModules: true,
// preserveModulesRoot is needed to be compatible with nodeResolve plugin:
// https://github.com/rollup/rollup/issues/3684
preserveModulesRoot: 'src',
},
],
plugins: [
json(),
nodeResolve(),
commonjs(),
typescript(),
terser({
compress: true,
}),
analyze({
hideDeps: true,
limit: 5,
summaryOnly: true,
onAnalysis,
}),
{ file: pkg.main, format: 'cjs', sourcemap: true },
{ file: pkg.module, format: 'es', sourcemap: true },
],
plugins: [nodeResolve(), json(), commonjs(), typescript()],
external,
},
{
treeshake: { moduleSideEffects: false },
input: 'src/index.ts',
output: [{ file: 'dist/index.d.ts', format: 'es' }],
plugins: [dts()],
},
];

const limitKB = 750;

function onAnalysis({ bundleSize }) {
if (bundleSize / 1000 < limitKB) return;
console.warn(`Bundle size exceeds ${limitKB} KB: ${bundleSize / 1000} KB`);
return process.exit(1);
}
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,3 @@ export {
Vector2,
} from './pools/gyroEPool/gyroEMath/gyroEMathHelpers';
export * as LinearMaths from './pools/linearPool/linearMath';
export const ISOLATED_CONST = 'isolated';
4 changes: 2 additions & 2 deletions src/pools/composableStable/composableStablePool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class ComposableStablePool extends PhantomStablePool {
.mul(poolPairData.tokenInPriceRate)
.div(ONE);

let returnEvm: bigint;
let returnEvm: BigInt;

if (poolPairData.pairType === PairTypes.TokenToBpt) {
const amountsInBigInt = Array(
Expand Down Expand Up @@ -125,7 +125,7 @@ export class ComposableStablePool extends PhantomStablePool {
.mul(poolPairData.tokenOutPriceRate)
.div(ONE);

let returnEvm: bigint;
let returnEvm: BigInt;

if (poolPairData.pairType === PairTypes.TokenToBpt) {
returnEvm = _calcTokenInGivenExactBptOut(
Expand Down
4 changes: 2 additions & 2 deletions src/pools/phantomStablePool/phantomStablePool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export class PhantomStablePool implements PoolBase<PhantomStablePoolPairData> {
.mul(poolPairData.tokenInPriceRate)
.div(ONE);

let returnEvm: bigint;
let returnEvm: BigInt;

if (poolPairData.pairType === PairTypes.TokenToBpt) {
const amountsInBigInt = Array(
Expand Down Expand Up @@ -320,7 +320,7 @@ export class PhantomStablePool implements PoolBase<PhantomStablePoolPairData> {
.mul(poolPairData.tokenOutPriceRate)
.div(ONE);

let returnEvm: bigint;
let returnEvm: BigInt;

if (poolPairData.pairType === PairTypes.TokenToBpt) {
returnEvm = _calcTokenInGivenExactBptOut(
Expand Down
18 changes: 8 additions & 10 deletions test/gyro2Pool.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import testPools from './testData/gyro2Pools/gyro2TestPool.json';
import { MockPoolDataService } from './lib/mockPoolDataService';
import { mockTokenPriceService } from './lib/mockTokenPriceService';

const maxDelta = bnum('0.00001');

describe('Gyro2Pool tests USDC > DAI', () => {
const testPool = cloneDeep(testPools).pools[0];
const pool = Gyro2Pool.fromPool(testPool);
Expand Down Expand Up @@ -77,20 +75,20 @@ describe('Gyro2Pool tests USDC > DAI', () => {
const normalizedLiquidity =
pool.getNormalizedLiquidity(poolPairData);

const delta = normalizedLiquidity
.minus(bnum('1116333.916257166990921337'))
.abs();
expect(delta.lt(maxDelta)).to.be.true;
expect(Number(normalizedLiquidity.toString())).to.be.approximately(
1116333.916257166990921337,
0.00001
);
});

it(`should correctly calculate normalized liquidity, DAI > USDC`, async () => {
const normalizedLiquidity =
pool.getNormalizedLiquidity(poolPairData2);

const delta = normalizedLiquidity
.minus(bnum('1116217.358286598731855228'))
.abs();
expect(delta.lt(maxDelta)).to.be.true;
expect(Number(normalizedLiquidity.toString())).to.be.approximately(
1116217.358286598731855228,
0.00001
);
});
});

Expand Down
14 changes: 8 additions & 6 deletions test/gyroEMath.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ const TEST_POOL_PAIR_DATA: GyroEPoolPairData = {
tokenInIsToken0: true,
};

const maxDelta = '10000000000000';

describe('gyroEMath tests', () => {
const poolPairData = TEST_POOL_PAIR_DATA;

Expand Down Expand Up @@ -100,8 +98,10 @@ describe('gyroEMath tests', () => {
DERIVED_GYRO_E_PARAMS,
invariant
);
const delta = a.sub('211290746521816255142').abs();
expect(delta.lt(maxDelta)).to.be.true;
expect(Number(formatFixed(a, 18))).to.be.approximately(
211.290746521816255142,
0.00001
);
});
});

Expand All @@ -128,8 +128,10 @@ describe('gyroEMath tests', () => {
DERIVED_GYRO_E_PARAMS,
invariant
);
const delta = b.sub('65500131431538418723').abs();
expect(delta.lt(maxDelta)).to.be.true;
expect(Number(formatFixed(b, 18))).to.be.approximately(
65.500131431538418723,
0.00001
);
});
});
});
44 changes: 24 additions & 20 deletions test/gyroEPool.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ const POOL = GyroEPool.fromPool({
dSq: '1.00000000000000002140811391783216360000',
});

const maxDelta = '0.00001';

describe('gyroEPool tests', () => {
const poolPairData = TEST_POOL_PAIR_DATA;

Expand All @@ -88,10 +86,11 @@ describe('gyroEPool tests', () => {
poolPairData,
SwapTypes.SwapExactIn
);
const delta = limitAmount
.minus(bnum('354.48480273457726733583'))
.abs();
expect(delta.lt(maxDelta)).to.be.true;

expect(Number(limitAmount)).to.be.approximately(
354.48480273457726733583,
0.00001
);
});

it(`should correctly calculate limit amount for swap exact out`, async () => {
Expand All @@ -110,8 +109,11 @@ describe('gyroEPool tests', () => {
poolPairData,
bnum('10')
);
const delta = swapAmount.minus(bnum('2.821007799187925949')).abs();
expect(delta.lt(maxDelta)).to.be.true;

expect(Number(swapAmount)).to.be.approximately(
2.821007799187925949,
0.00001
);
});

it(`should correctly calculate swap amount for swap exact out`, async () => {
Expand All @@ -128,10 +130,10 @@ describe('gyroEPool tests', () => {
18
);

const delta = bnum(reduced)
.minus(bnum('32.257987339909373037'))
.abs();
expect(delta.lt(maxDelta)).to.be.true;
expect(Number(reduced)).to.be.approximately(
32.257987339909373037,
0.00001
);
});
});

Expand All @@ -142,10 +144,11 @@ describe('gyroEPool tests', () => {
poolPairData,
bnum('10')
);
const delta = priceAfterSwap
.minus(bnum('3.544833007099248968'))
.abs();
expect(delta.lt(maxDelta)).to.be.true;

expect(Number(priceAfterSwap)).to.be.approximately(
3.544833007099248968,
0.00001
);
});

it(`should correctly calculate price after swap exact out`, async () => {
Expand All @@ -154,10 +157,11 @@ describe('gyroEPool tests', () => {
poolPairData,
bnum('10')
);
const delta = priceAfterSwap
.minus(bnum('3.544835504848199306'))
.abs();
expect(delta.lt(maxDelta)).to.be.true;

expect(Number(priceAfterSwap)).to.be.approximately(
3.544835504848199306,
0.00001
);
});
});

Expand Down
Loading

0 comments on commit 3d6890a

Please sign in to comment.