Skip to content

Commit

Permalink
Merge branch 'develop' into dependabot/npm_and_yarn/ansi-regex-3.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
johngrantuk committed Jul 28, 2023
2 parents f43e8ed + 8998223 commit 0547fef
Show file tree
Hide file tree
Showing 31 changed files with 103 additions and 82 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,13 @@ jobs:
if: steps.cache.outputs.cache-hit != 'true'
- name: Compile
run: yarn build
- name: Run node in background for integration tests
run: npx hardhat --tsconfig tsconfig.testing.json node --hostname 127.0.0.1 --fork https://mainnet.infura.io/v3/${{ secrets.INFURA }} &
- name: Run mainnet node in background for integration tests
run: npx hardhat --tsconfig tsconfig.testing.json node --hostname 127.0.0.1 --fork ${{ secrets.RPC_URL_MAINNET }} &
- name: Run Polygon node in background for integration tests
run: npx hardhat --tsconfig tsconfig.testing.json --config hardhat.config.polygon.ts node --hostname 127.0.0.1 --fork ${{ secrets.RPC_URL_POLYGON }} --port 8137 &
- name: Test
run: yarn test
env:
CI: true
INFURA: ${{ secrets.INFURA }}
RPC_URL_MAINNET: ${{ secrets.RPC_URL_MAINNET }}
RPC_URL_POLYGON: ${{ secrets.RPC_URL_POLYGON }}
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,51 @@ The example file `swapExample.ts` in: [./testScripts](test/testScripts/), demons

To Run:

Create a .env file in root dir with your infura provider key: `INFURA=your_key`
Create a .env file in root dir. Depending on network being used add an RPC URL (e.g. Alchemy, Infura), e.g.: `RPC_URL_MAINNET=alchemy/infura`

Supported networks out of box for example are:

```
RPC_URL_MAINNET
RPC_URL_POLYGON
RPC_URL_ARBITRUM
RPC_URL_GNOSIS
RPC_URL_ZKEVM
RPC_URL_GOERLI
```

Install dependencies: `$ yarn install`

Run example: `$ ts-node ./test/testScripts/swapExample.ts`

## Contributing/Adding New Pools

Running tests locally:

1. Add .env and add following RPC URLs (e.g. Alchemy, Infura)

```
RPC_URL_MAINNET=
RPC_URL_POLYGON=
```

2. Start local forked nodes to test against:

`$ yarn run node`

`$ yarn run node:polygon`

3. Run tests:
`$ yarn test`

To run a single test file use `test:only`, e.g.:

`$ yarn test:only test/composableStable.integration.spec.ts`

Adding New Pools:

See info [here](https://www.notion.so/SOR-Adding-New-Pools-fa073ec6fecb4c22b1ba13504b04f5bf?pvs=4)

## Environment Variables

Optional config values can be set in the .env file:
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"example": "TS_NODE_PROJECT='tsconfig.testing.json' ts-node",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"lint": "eslint ./src ./test --ext .ts --max-warnings 0",
"node": "npx hardhat node --tsconfig tsconfig.testing.json --fork $(. ./.env && echo $ALCHEMY_URL)",
"node:polygon": "npx hardhat --tsconfig tsconfig.testing.json --config hardhat.config.polygon.ts node --fork $(. ./.env && echo $ALCHEMY_URL_POLYGON) --port 8137"
"node": "npx hardhat node --tsconfig tsconfig.testing.json --fork $(. ./.env && echo $RPC_URL_MAINNET)",
"node:polygon": "npx hardhat --tsconfig tsconfig.testing.json --config hardhat.config.polygon.ts node --fork $(. ./.env && echo $RPC_URL_POLYGON) --port 8137"
},
"husky": {
"hooks": {
Expand Down
9 changes: 9 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export { SOR } from './wrapper';
export { BPTForTokensZeroPriceImpact as weightedBPTForTokensZeroPriceImpact } from './frontendHelpers/weightedHelpers';
export { BPTForTokensZeroPriceImpact as stableBPTForTokensZeroPriceImpact } from './frontendHelpers/stableHelpers';
export * from './types';
export { safeParseFixed } from './utils';
export { formatSequence, getTokenAddressesForSwap } from './formatSwaps';
export { RouteProposer } from './routeProposal';
export { parseToPoolsDict } from './routeProposal/filtering';
Expand All @@ -12,17 +13,25 @@ export { MetaStablePool } from './pools/metaStablePool/metaStablePool';
export { PhantomStablePool } from './pools/phantomStablePool/phantomStablePool';
export { ComposableStablePool } from './pools/composableStable/composableStablePool';
export { LinearPool } from './pools/linearPool/linearPool';
export { Gyro2Pool } from './pools/gyro2Pool/gyro2Pool';
export { Gyro3Pool } from './pools/gyro3Pool/gyro3Pool';
export { GyroEV2Pool } from './pools/gyroEV2Pool/gyroEV2Pool';
export { FxPool } from './pools/xaveFxPool/fxPool';
export { getSpotPriceAfterSwapForPath } from './router/helpersClass';
export * as WeightedMaths from './pools/weightedPool/weightedMath';
export * as StableMaths from './pools/stablePool/stableMath';
export * as StableMathBigInt from './pools/stablePool/stableMathBigInt';
export * as Gyro2Maths from './pools/gyro2Pool/gyro2Math';
export * as Gyro3Maths from './pools/gyro3Pool/gyro3Math';
export * as GyroEMaths from './pools/gyroEPool/gyroEMath/gyroEMath';
export * as FxMaths from './pools/xaveFxPool/fxPoolMath';
export {
balancesFromTokenInOut,
GyroEParams,
DerivedGyroEParams,
Vector2,
} from './pools/gyroEPool/gyroEMath/gyroEMathHelpers';
export * as GyroEMathFunctions from './pools/gyroEPool/gyroEMath/gyroEMathFunctions';
export * as GyroHelpersSignedFixedPoint from './pools/gyroHelpers/gyroSignedFixedPoint';
export * as GyroHelpers from './pools/gyroHelpers/helpers';
export * as LinearMaths from './pools/linearPool/linearMath';
2 changes: 1 addition & 1 deletion test/ComposableStable.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dotenv.config();

let sor: SOR;
const networkId = Network.MAINNET;
const jsonRpcUrl = 'https://mainnet.infura.io/v3/' + process.env.INFURA;
const jsonRpcUrl = process.env.RPC_URL_MAINNET;
const rpcUrl = 'http://127.0.0.1:8545';
const blockNumber = 16990000;
const provider = new JsonRpcProvider(rpcUrl, networkId);
Expand Down
2 changes: 1 addition & 1 deletion test/MetaStable.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const testPool: SubgraphPoolBase = {
};

const networkId = Network.MAINNET;
const jsonRpcUrl = 'https://mainnet.infura.io/v3/' + process.env.INFURA;
const jsonRpcUrl = process.env.RPC_URL_MAINNET;
const rpcUrl = 'http://127.0.0.1:8545';
const blockNumber = 16447247;
const provider = new JsonRpcProvider(rpcUrl, networkId);
Expand Down
2 changes: 1 addition & 1 deletion test/PhantomStable.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dotenv.config();

let sor: SOR;
const networkId = Network.MAINNET;
const jsonRpcUrl = 'https://mainnet.infura.io/v3/' + process.env.INFURA;
const jsonRpcUrl = process.env.RPC_URL_MAINNET;
const rpcUrl = 'http://127.0.0.1:8545';
const blockNumber = 16447247;
const provider = new JsonRpcProvider(rpcUrl, networkId);
Expand Down
4 changes: 1 addition & 3 deletions test/boostedPaths.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -606,9 +606,7 @@ export async function checkBestPath(
const swapAmount = parseFixed(amount.toString(), tokenIn.decimals);
const costOutputToken = BigNumber.from('0');
const gasPrice = BigNumber.from(`10000000000`);
const provider = new JsonRpcProvider(
`https://mainnet.infura.io/v3/${process.env.INFURA}`
);
const provider = new JsonRpcProvider(``);
const swapGas = BigNumber.from(`32500`);
const swapInfo = await getFullSwap(
cloneDeep(pools),
Expand Down
4 changes: 1 addition & 3 deletions test/elementPools.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ import { MockPoolDataService } from './lib/mockPoolDataService';

const gasPrice = parseFixed('30', 9);
const maxPools = 4;
const provider = new JsonRpcProvider(
`https://mainnet.infura.io/v3/${process.env.INFURA}`
);
const provider = new JsonRpcProvider(``);

// npx mocha -r ts-node/register test/elementPools.spec.ts
describe(`Tests for Element Pools.`, () => {
Expand Down
4 changes: 1 addition & 3 deletions test/elementTrades.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ import { parseFixed } from '@ethersproject/bignumber';

const gasPrice = parseFixed('30', 9);
const maxPools = 4;
const provider = new JsonRpcProvider(
`https://mainnet.infura.io/v3/${process.env.INFURA}`
);
const provider = new JsonRpcProvider(``);

interface TradeData {
input: {
Expand Down
4 changes: 1 addition & 3 deletions test/fullSwaps.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ const ANT = '0x960b236a07cf122663c4303350609a66a7b288c0'; // ANT lower case
const MKR2 = '0xef13C0c8abcaf5767160018d268f9697aE4f5375'.toLowerCase();
const yUSD = '0xb2fdd60ad80ca7ba89b9bab3b5336c2601c020b4';

const provider = new JsonRpcProvider(
`https://mainnet.infura.io/v3/${process.env.INFURA}`
);
const provider = new JsonRpcProvider(``);

describe('Tests full swaps against known values', () => {
const gasPrice = parseFixed('30', 9);
Expand Down
4 changes: 1 addition & 3 deletions test/gyro2Pool.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,7 @@ describe('Gyro2Pool tests USDC > DAI', () => {

const gasPrice = parseFixed('30', 9);
const maxPools = 4;
const provider = new JsonRpcProvider(
`https://mainnet.infura.io/v3/${process.env.INFURA}`
);
const provider = new JsonRpcProvider(``);

const sor = new SOR(
provider,
Expand Down
2 changes: 1 addition & 1 deletion test/gyroEV2.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { setUp } from './testScripts/utils';
dotenv.config();

const networkId = Network.POLYGON;
const jsonRpcUrl = 'https://polygon-mainnet.infura.io/v3/' + process.env.INFURA;
const jsonRpcUrl = '';
const rpcUrl = 'http://127.0.0.1:8137';
const provider = new JsonRpcProvider(rpcUrl, networkId);
const blocknumber = 42173266;
Expand Down
4 changes: 1 addition & 3 deletions test/helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import { BAL, DAI, GUSD, sorConfigEth, USDC, WETH } from './lib/constants';

const marketSp = '7';

const provider = new JsonRpcProvider(
`https://mainnet.infura.io/v3/${process.env.INFURA}`
);
const provider = new JsonRpcProvider(process.env.RPC_URL_MAINNET);

// TS_NODE_PROJECT='tsconfig.testing.json' npx mocha -r ts-node/register test/helpers.spec.ts
describe(`Tests for Helpers.`, () => {
Expand Down
4 changes: 1 addition & 3 deletions test/lbp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ import { MockPoolDataService } from './lib/mockPoolDataService';

const gasPrice = parseFixed('30', 9);
const maxPools = 4;
const provider = new JsonRpcProvider(
`https://mainnet.infura.io/v3/${process.env.INFURA}`
);
const provider = new JsonRpcProvider(``);

// npx mocha -r ts-node/register test/lbp.spec.ts
describe(`Tests for LBP Pools.`, () => {
Expand Down
4 changes: 1 addition & 3 deletions test/lido.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import { parseFixed } from '@ethersproject/bignumber';
const gasPrice = parseFixed('30', 9);
const maxPools = 4;
const chainId = 1;
const provider = new JsonRpcProvider(
`https://mainnet.infura.io/v3/${process.env.INFURA}`
);
const provider = new JsonRpcProvider(process.env.RPC_URL_MAINNET);
const USDC = Lido.USDC[chainId];
const DAI = Lido.DAI[chainId];
const USDT = Lido.USDT[chainId];
Expand Down
4 changes: 1 addition & 3 deletions test/linear.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -900,9 +900,7 @@ export async function testFullSwap(
// const costOutputToken = BigNumber.from('1000000000000000000');
const costOutputToken = BigNumber.from('0');
const gasPrice = BigNumber.from(`10000000000`);
const provider = new JsonRpcProvider(
`https://mainnet.infura.io/v3/${process.env.INFURA}`
);
const provider = new JsonRpcProvider(``);
const swapGas = BigNumber.from(`32500`);

const swapInfo = await getFullSwap(
Expand Down
4 changes: 1 addition & 3 deletions test/metaStablePools.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ import { MockPoolDataService } from './lib/mockPoolDataService';

const gasPrice = parseFixed('30', 9);
const maxPools = 4;
const provider = new JsonRpcProvider(
`https://mainnet.infura.io/v3/${process.env.INFURA}`
);
const provider = new JsonRpcProvider(``);

async function getStableComparrison(
stablePools: SubgraphPoolBase[],
Expand Down
4 changes: 1 addition & 3 deletions test/phantomStablePools.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,7 @@ async function testFullSwap(
// const costOutputToken = BigNumber.from('1000000000000000000');
const costOutputToken = BigNumber.from('0');
const gasPrice = BigNumber.from(`10000000000`);
const provider = new JsonRpcProvider(
`https://kovan.infura.io/v3/${process.env.INFURA}`
);
const provider = new JsonRpcProvider(``);
const swapGas = BigNumber.from(`32500`);

const swapInfo = await getFullSwap(
Expand Down
2 changes: 1 addition & 1 deletion test/stable.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const testPool: SubgraphPoolBase = {
};

const networkId = Network.MAINNET;
const jsonRpcUrl = 'https://mainnet.infura.io/v3/' + process.env.INFURA;
const jsonRpcUrl = process.env.RPC_URL_MAINNET;
const rpcUrl = 'http://127.0.0.1:8545';
const blockNumber = 16447247;
const provider = new JsonRpcProvider(rpcUrl, networkId);
Expand Down
4 changes: 1 addition & 3 deletions test/stablePools.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ const multihopPoolsFromFile: {

const gasPrice = parseFixed('30', 9);
const maxPools = 4;
const provider = new JsonRpcProvider(
`https://mainnet.infura.io/v3/${process.env.INFURA}`
);
const provider = new JsonRpcProvider(``);

describe(`Tests for Stable Pools.`, () => {
context('limit amounts', () => {
Expand Down
12 changes: 6 additions & 6 deletions test/testScripts/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ export const SOR_CONFIG: Record<Network, SorConfig> = {
};

export const PROVIDER_URLS = {
[Network.MAINNET]: `https://mainnet.infura.io/v3/${process.env.INFURA}`,
[Network.GOERLI]: `https://goerli.infura.io/v3/${process.env.INFURA}`,
[Network.POLYGON]: `https://polygon-mainnet.infura.io/v3/${process.env.INFURA}`,
[Network.ARBITRUM]: `https://arbitrum-mainnet.infura.io/v3/${process.env.INFURA}`,
[Network.GNOSIS]: `https://poa-xdai.gateway.pokt.network/v1/lb/91bc0e12a76e7a84dd76189d`,
[Network.ZKEVM]: `${process.env.RPC_URL_ZKEVM}`,
[Network.MAINNET]: process.env.RPC_URL_MAINNET,
[Network.GOERLI]: process.env.RPC_URL_GOERLI,
[Network.POLYGON]: process.env.RPC_URL_POLYGON,
[Network.ARBITRUM]: process.env.RPC_URL_ARBITRUM,
[Network.GNOSIS]: process.env.RPC_URL_GNOSIS,
[Network.ZKEVM]: process.env.RPC_URL_ZKEVM,
};

export const MULTIADDR: { [chainId: number]: string } = {
Expand Down
2 changes: 1 addition & 1 deletion test/testScripts/swapExample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,5 @@ export async function swap(): Promise<void> {
}
}

// $ TS_NODE_PROJECT='tsconfig.testing.json' ts-node ./test/testScripts/swapExample.ts
// $ TS_NODE_PROJECT='tsconfig.testing.json' npx ts-node ./test/testScripts/swapExample.ts
swap();
4 changes: 1 addition & 3 deletions test/v1-v2-compare-testPools.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { JsonRpcProvider } from '@ethersproject/providers';
import { loadTestFile } from './lib/testHelpers';
import { compareTest } from './lib/compareHelper';

const provider = new JsonRpcProvider(
`https://mainnet.infura.io/v3/${process.env.INFURA}`
);
const provider = new JsonRpcProvider(``);

// This must be updated with pools of interest (see ./test/testData/testPools)
const testFiles = [
Expand Down
2 changes: 1 addition & 1 deletion test/weighted.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const testPool: SubgraphPoolBase = {
};

const networkId = Network.MAINNET;
const jsonRpcUrl = 'https://mainnet.infura.io/v3/' + process.env.INFURA;
const jsonRpcUrl = process.env.RPC_URL_MAINNET;
const rpcUrl = 'http://127.0.0.1:8545';
const blockNumber = 16447247;
const provider = new JsonRpcProvider(rpcUrl, networkId);
Expand Down
4 changes: 1 addition & 3 deletions test/weightedPools.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,7 @@ async function getSwapInfo(
swapAmount: BigNumber,
useBpts?: boolean
) {
const provider = new JsonRpcProvider(
`https://mainnet.infura.io/v3/${process.env.INFURA}`
);
const provider = new JsonRpcProvider(``);
const maxPools = 4;
const gasPrice = BigNumber.from('0');
const sor = new SOR(
Expand Down
4 changes: 1 addition & 3 deletions test/wrapper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ const subgraphPoolsSmallWithTrade: {
// eslint-disable-next-line @typescript-eslint/no-var-requires
} = require('./testData/testPools/subgraphPoolsSmallWithTrade.json');

const provider = new JsonRpcProvider(
`https://mainnet.infura.io/v3/${process.env.INFURA}`
);
const provider = new JsonRpcProvider(``);
const gasPrice = parseFixed('30', 9);
const maxPools = 4;

Expand Down
2 changes: 1 addition & 1 deletion test/xaveFxPool.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dotenv.config();

let sor: SOR;
const networkId = Network.MAINNET;
const jsonRpcUrl = 'https://mainnet.infura.io/v3/' + process.env.INFURA;
const jsonRpcUrl = process.env.RPC_URL_MAINNET;
const rpcUrl = 'http://127.0.0.1:8545';
const provider = new JsonRpcProvider(rpcUrl, networkId);
const blocknumber = 16797531;
Expand Down
2 changes: 1 addition & 1 deletion test/xaveFxPool.polygon.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dotenv.config();

let sor: SOR;
const networkId = Network.POLYGON;
const jsonRpcUrl = 'https://polygon-mainnet.infura.io/v3/' + process.env.INFURA;
const jsonRpcUrl = process.env.RPC_URL_POLYGON;
const rpcUrl = 'http://127.0.0.1:8137';
const provider = new JsonRpcProvider(rpcUrl, networkId);
const blocknumber = 43667355;
Expand Down
2 changes: 1 addition & 1 deletion test/xaveFxPool.wStable.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dotenv.config();

let sor: SOR;
const networkId = Network.MAINNET;
const jsonRpcUrl = 'https://mainnet.infura.io/v3/' + process.env.INFURA;
const jsonRpcUrl = process.env.RPC_URL_MAINNET;
const rpcUrl = 'http://127.0.0.1:8545';
const provider = new JsonRpcProvider(rpcUrl, networkId);
const blocknumber = 17129117;
Expand Down
Loading

0 comments on commit 0547fef

Please sign in to comment.