From b62ab16bab92e6fe6b830ef75310953faacc806a Mon Sep 17 00:00:00 2001 From: Luiz Gustavo Abou Hatem De Liz Date: Thu, 21 Sep 2023 19:26:43 -0300 Subject: [PATCH 01/11] Creating a provider to fetch data from the Balancer API; --- .gitignore | 2 + .../balancer-api-provider/client/index.ts | 22 +++++ .../providers/balancer-api-provider/index.ts | 16 ++++ .../modules/join/index.ts | 88 +++++++++++++++++++ .../modules/join/types.ts | 14 +++ 5 files changed, 142 insertions(+) create mode 100644 src/data/providers/balancer-api-provider/client/index.ts create mode 100644 src/data/providers/balancer-api-provider/index.ts create mode 100644 src/data/providers/balancer-api-provider/modules/join/index.ts create mode 100644 src/data/providers/balancer-api-provider/modules/join/types.ts diff --git a/.gitignore b/.gitignore index 3e819cac..c1308de5 100644 --- a/.gitignore +++ b/.gitignore @@ -80,3 +80,5 @@ typechain-types cache artifacts +#IDE +.idea diff --git a/src/data/providers/balancer-api-provider/client/index.ts b/src/data/providers/balancer-api-provider/client/index.ts new file mode 100644 index 00000000..d1bd5ab9 --- /dev/null +++ b/src/data/providers/balancer-api-provider/client/index.ts @@ -0,0 +1,22 @@ +export class BalancerApiClient { + subgraphUrl: string; + chainId: number; + constructor(subgraphUrl: string, chainId: number) { + this.subgraphUrl = subgraphUrl; + this.chainId = chainId; + } + + async fetch(operationName: string, query: any, variables: any) { + const requestQuery = { + operationName, + query, + variables, + }; + const response = await fetch(this.subgraphUrl, { + method: 'post', + body: JSON.stringify(requestQuery), + headers: { 'Content-Type': 'application/json', ChainId: this.chainId.toString() }, + }); + return response.json(); + } +} diff --git a/src/data/providers/balancer-api-provider/index.ts b/src/data/providers/balancer-api-provider/index.ts new file mode 100644 index 00000000..5468e7d1 --- /dev/null +++ b/src/data/providers/balancer-api-provider/index.ts @@ -0,0 +1,16 @@ +import { JoinData } from "./modules/join"; +import { BalancerApiClient } from "./client"; + +export default class BalancerApi { + + balancerApiClient: BalancerApiClient; + joinData: JoinData; + + + constructor(balancerApiUrl: string, chainId: number){ + this.balancerApiClient = new BalancerApiClient(balancerApiUrl, chainId); + this.joinData = new JoinData(this.balancerApiClient); + } + + +} \ No newline at end of file diff --git a/src/data/providers/balancer-api-provider/modules/join/index.ts b/src/data/providers/balancer-api-provider/modules/join/index.ts new file mode 100644 index 00000000..60a9c8cc --- /dev/null +++ b/src/data/providers/balancer-api-provider/modules/join/index.ts @@ -0,0 +1,88 @@ +import { BalancerApiClient } from '../../client'; +import { PoolState } from './types'; + +export class JoinData { + readonly poolStateQuery = `query GetPool($id: String!){ + poolGetPool(id:$id) { + id + address + name + type + version + ... on GqlPoolWeighted { + tokens { + ... on GqlPoolTokenBase { + address + decimals + index + } + } + } + ... on GqlPoolStable { + tokens { + ... on GqlPoolTokenBase { + address + decimals + index + } + } + } + ... on GqlPoolPhantomStable { + tokens { + ... on GqlPoolTokenBase { + address + decimals + index + } + } + } + ... on GqlPoolGyro { + tokens { + ... on GqlPoolTokenBase { + address + decimals + index + } + } + } + ... on GqlPoolLiquidityBootstrapping { + tokens { + ... on GqlPoolTokenBase { + address + decimals + index + } + } + } + ... on GqlPoolElement { + tokens { + ... on GqlPoolTokenBase { + address + decimals + index + } + } + } + ... on GqlPoolLiquidityBootstrapping { + tokens { + ... on GqlPoolTokenBase { + address + decimals + index + } + } + } + } +}`; + + constructor(private readonly balancerApiClient: BalancerApiClient) {} + + async fetchPoolState(id: string): Promise { + const { + data: { poolGetPool }, + } = await this.balancerApiClient.fetch('GetPool', this.poolStateQuery, { + id, + }); + return poolGetPool; + } +} diff --git a/src/data/providers/balancer-api-provider/modules/join/types.ts b/src/data/providers/balancer-api-provider/modules/join/types.ts new file mode 100644 index 00000000..5b23f242 --- /dev/null +++ b/src/data/providers/balancer-api-provider/modules/join/types.ts @@ -0,0 +1,14 @@ +import { Address } from "viem"; + +export type PoolState = { + id: Address; + address: Address; + type: string; + version: string; + tokens: { + address: Address; + decimals: number; + index: number; + }; +}[]; + From 5702561423d095a7ea1c535597498ec58d5e66ab Mon Sep 17 00:00:00 2001 From: Luiz Gustavo Abou Hatem De Liz Date: Mon, 25 Sep 2023 10:22:23 -0300 Subject: [PATCH 02/11] Adding Example; Changing variable names; Changing class names; --- README.md | 60 +++++++++++++++++++ .../client/index.ts | 8 +-- .../index.ts | 6 +- .../modules/pool-state}/index.ts | 4 +- .../modules/pool-state}/types.ts | 0 src/entities/join/index.ts | 2 +- src/entities/join/parser.ts | 2 +- test/lib/utils/helper.ts | 2 +- test/weightedJoin.integration.test.ts | 20 +++---- 9 files changed, 82 insertions(+), 22 deletions(-) rename src/data/providers/{balancer-api-provider => balancer-api}/client/index.ts (72%) rename src/data/providers/{balancer-api-provider => balancer-api}/index.ts (69%) rename src/data/providers/{balancer-api-provider/modules/join => balancer-api/modules/pool-state}/index.ts (95%) rename src/data/providers/{balancer-api-provider/modules/join => balancer-api/modules/pool-state}/types.ts (100%) diff --git a/README.md b/README.md index 0c0e32ce..3e79f119 100644 --- a/README.md +++ b/README.md @@ -21,3 +21,63 @@ If your platform does not support one of the required features, it is also possi Testing requires access to an archive node for onchain quote comparisons. This can be done using Infura. `pnpm test` + +## Examples + +### Balancer Api Provider + +Joining with pool state: +```ts + import BalancerApi from "@balancer/sdk/data/providers/balancer-api"; + ... + const joinInput: ProportionalJoinInput = { + bptOut, + chainId, + rpcUrl, + kind: JoinKind.Proportional, + }; + + const balancerApi = new BalancerApi('https://api-v3.balancer.fi/', 1); + const poolState = await balancerApi.pools.fetchSimplePoolState('0x5f1d6874cb1e7156e79a7563d2b61c6cbce03150000200000000000000000586'); + const joinParser = new JoinParser(); + const poolJoin = joinParser.getJoin(poolState.type); + const queryResult = await weightedJoin.query(joinInput, poolState); + +``` + +Exiting with pool state: +```ts +import BalancerApi from "@balancer/sdk/data/providers/balancer-api"; +... +const joinInput: ProportionalJoinInput = { + bptOut, + chainId, + rpcUrl, + kind: JoinKind.Proportional, +}; + +const balancerApi = new BalancerApi('https://api-v3.balancer.fi/', 1); +const poolState = await balancerApi.pools.fetchSimplePoolState('0x5f1d6874cb1e7156e79a7563d2b61c6cbce03150000200000000000000000586'); +const joinParser = new JoinParser(); +const poolJoin = joinParser.getJoin(poolState.type); +const queryResult = await weightedJoin.query(joinInput, poolState); +const slippage = Slippage.fromPercentage('1'); // 1% +const { call, to, value, maxAmountsIn, minBptOut } = + weightedJoin.buildCall({ + ...queryResult, + slippage, + sender, + recipient, + }); +const client = createClient({ + ... +}) + +await client.sendTransaction({ + account, + chain: client.chain, + data, + to, + value, +}); +``` \ No newline at end of file diff --git a/src/data/providers/balancer-api-provider/client/index.ts b/src/data/providers/balancer-api/client/index.ts similarity index 72% rename from src/data/providers/balancer-api-provider/client/index.ts rename to src/data/providers/balancer-api/client/index.ts index d1bd5ab9..40ac1ab3 100644 --- a/src/data/providers/balancer-api-provider/client/index.ts +++ b/src/data/providers/balancer-api/client/index.ts @@ -1,8 +1,8 @@ export class BalancerApiClient { - subgraphUrl: string; + apiUrl: string; chainId: number; - constructor(subgraphUrl: string, chainId: number) { - this.subgraphUrl = subgraphUrl; + constructor(apiUrl: string, chainId: number) { + this.apiUrl = apiUrl; this.chainId = chainId; } @@ -12,7 +12,7 @@ export class BalancerApiClient { query, variables, }; - const response = await fetch(this.subgraphUrl, { + const response = await fetch(this.apiUrl, { method: 'post', body: JSON.stringify(requestQuery), headers: { 'Content-Type': 'application/json', ChainId: this.chainId.toString() }, diff --git a/src/data/providers/balancer-api-provider/index.ts b/src/data/providers/balancer-api/index.ts similarity index 69% rename from src/data/providers/balancer-api-provider/index.ts rename to src/data/providers/balancer-api/index.ts index 5468e7d1..d854c6ba 100644 --- a/src/data/providers/balancer-api-provider/index.ts +++ b/src/data/providers/balancer-api/index.ts @@ -1,15 +1,15 @@ -import { JoinData } from "./modules/join"; +import { Pools } from "./modules/pool-state"; import { BalancerApiClient } from "./client"; export default class BalancerApi { balancerApiClient: BalancerApiClient; - joinData: JoinData; + pools: Pools; constructor(balancerApiUrl: string, chainId: number){ this.balancerApiClient = new BalancerApiClient(balancerApiUrl, chainId); - this.joinData = new JoinData(this.balancerApiClient); + this.pools = new Pools(this.balancerApiClient); } diff --git a/src/data/providers/balancer-api-provider/modules/join/index.ts b/src/data/providers/balancer-api/modules/pool-state/index.ts similarity index 95% rename from src/data/providers/balancer-api-provider/modules/join/index.ts rename to src/data/providers/balancer-api/modules/pool-state/index.ts index 60a9c8cc..b78aa25b 100644 --- a/src/data/providers/balancer-api-provider/modules/join/index.ts +++ b/src/data/providers/balancer-api/modules/pool-state/index.ts @@ -1,7 +1,7 @@ import { BalancerApiClient } from '../../client'; import { PoolState } from './types'; -export class JoinData { +export class Pools { readonly poolStateQuery = `query GetPool($id: String!){ poolGetPool(id:$id) { id @@ -77,7 +77,7 @@ export class JoinData { constructor(private readonly balancerApiClient: BalancerApiClient) {} - async fetchPoolState(id: string): Promise { + async fetchSimplePoolState(id: string): Promise { const { data: { poolGetPool }, } = await this.balancerApiClient.fetch('GetPool', this.poolStateQuery, { diff --git a/src/data/providers/balancer-api-provider/modules/join/types.ts b/src/data/providers/balancer-api/modules/pool-state/types.ts similarity index 100% rename from src/data/providers/balancer-api-provider/modules/join/types.ts rename to src/data/providers/balancer-api/modules/pool-state/types.ts diff --git a/src/entities/join/index.ts b/src/entities/join/index.ts index b968ca7a..bff8b24e 100644 --- a/src/entities/join/index.ts +++ b/src/entities/join/index.ts @@ -45,7 +45,7 @@ export type JoinInput = | SingleAssetJoinInput | ProportionalJoinInput; -// Returned from a join query +// Returned from a pool-state query export type JoinQueryResult = { poolId: Hex; joinKind: JoinKind; diff --git a/src/entities/join/parser.ts b/src/entities/join/parser.ts index 7506e603..c9f81a98 100644 --- a/src/entities/join/parser.ts +++ b/src/entities/join/parser.ts @@ -1,7 +1,7 @@ import { BaseJoin } from '.'; import { WeightedJoin } from './weighted/weightedJoin'; -/*********************** Basic Helper to get join class from pool type *************/ +/*********************** Basic Helper to get pool-state class from pool type *************/ export type JoinConfig = { customPoolJoins: Record; }; diff --git a/test/lib/utils/helper.ts b/test/lib/utils/helper.ts index 9b3ffa22..1571aa18 100644 --- a/test/lib/utils/helper.ts +++ b/test/lib/utils/helper.ts @@ -291,7 +291,7 @@ export const forkSetup = async ( } for (let i = 0; i < tokens.length; i++) { - // Set initial account balance for each token that will be used to join pool + // Set initial account balance for each token that will be used to pool-state pool await setTokenBalance( client, accountAddress, diff --git a/test/weightedJoin.integration.test.ts b/test/weightedJoin.integration.test.ts index 7ee6ffa9..26f91e6e 100644 --- a/test/weightedJoin.integration.test.ts +++ b/test/weightedJoin.integration.test.ts @@ -41,7 +41,7 @@ const slippage = Slippage.fromPercentage('1'); // 1% const poolId = '0x68e3266c9c8bbd44ad9dca5afbfe629022aee9fe000200000000000000000512'; // Balancer 50COMP-50wstETH -describe('weighted join test', () => { +describe('weighted pool-state test', () => { let api: MockApi; let client: Client & PublicActions & TestActions & WalletActions; let poolFromApi: PoolState; @@ -63,7 +63,7 @@ describe('weighted join test', () => { // get pool state from api poolFromApi = await api.getPool(poolId); - // setup join helper + // setup pool-state helper const joinParser = new JoinParser(); weightedJoin = joinParser.getJoin(poolFromApi.type); @@ -86,7 +86,7 @@ describe('weighted join test', () => { ); }); - test('unbalanced join', async () => { + test('unbalanced pool-state', async () => { const poolTokens = poolFromApi.tokens.map( (t) => new Token(chainId, t.address, t.decimals), ); @@ -94,7 +94,7 @@ describe('weighted join test', () => { TokenAmount.fromHumanAmount(t, '1'), ); - // perform join query to get expected bpt out + // perform pool-state query to get expected bpt out const joinInput: UnbalancedJoinInput = { amountsIn, chainId, @@ -127,7 +127,7 @@ describe('weighted join test', () => { expect(expectedMaxAmountsIn).to.deep.eq(maxAmountsIn); }); - test('native asset join', async () => { + test('native asset pool-state', async () => { const poolTokens = poolFromApi.tokens.map( (t) => new Token(chainId, t.address, t.decimals), ); @@ -135,7 +135,7 @@ describe('weighted join test', () => { TokenAmount.fromHumanAmount(t, '1'), ); - // perform join query to get expected bpt out + // perform pool-state query to get expected bpt out const joinInput: UnbalancedJoinInput = { amountsIn, chainId, @@ -171,11 +171,11 @@ describe('weighted join test', () => { expect(expectedMaxAmountsIn).to.deep.eq(maxAmountsIn); }); - test('single asset join', async () => { + test('single asset pool-state', async () => { const bptOut = TokenAmount.fromHumanAmount(bpt, '1'); const tokenIn = '0x198d7387fa97a73f05b8578cdeff8f2a1f34cd1f'; - // perform join query to get expected bpt out + // perform pool-state query to get expected bpt out const joinInput: SingleAssetJoinInput = { bptOut, tokenIn, @@ -214,10 +214,10 @@ describe('weighted join test', () => { expect(minBptOut).to.eq(bptOut.amount); }); - test('proportional join', async () => { + test('proportional pool-state', async () => { const bptOut = TokenAmount.fromHumanAmount(bpt, '1'); - // perform join query to get expected bpt out + // perform pool-state query to get expected bpt out const joinInput: ProportionalJoinInput = { bptOut, chainId, From 16376b789dcada6c0fa4d9bd6668c1122ad770eb Mon Sep 17 00:00:00 2001 From: Luiz Gustavo Abou Hatem De Liz Date: Mon, 25 Sep 2023 10:35:31 -0300 Subject: [PATCH 03/11] Fixing wrong replacements --- .../client/index.ts | 0 .../index.ts | 0 .../modules/pool-state/index.ts | 0 .../modules/pool-state/types.ts | 0 src/entities/join/index.ts | 2 +- src/entities/join/parser.ts | 2 +- test/lib/utils/helper.ts | 2 +- test/weightedJoin.integration.test.ts | 20 +++++++++---------- 8 files changed, 13 insertions(+), 13 deletions(-) rename src/data/providers/{balancer-api => balancer-api-provider}/client/index.ts (100%) rename src/data/providers/{balancer-api => balancer-api-provider}/index.ts (100%) rename src/data/providers/{balancer-api => balancer-api-provider}/modules/pool-state/index.ts (100%) rename src/data/providers/{balancer-api => balancer-api-provider}/modules/pool-state/types.ts (100%) diff --git a/src/data/providers/balancer-api/client/index.ts b/src/data/providers/balancer-api-provider/client/index.ts similarity index 100% rename from src/data/providers/balancer-api/client/index.ts rename to src/data/providers/balancer-api-provider/client/index.ts diff --git a/src/data/providers/balancer-api/index.ts b/src/data/providers/balancer-api-provider/index.ts similarity index 100% rename from src/data/providers/balancer-api/index.ts rename to src/data/providers/balancer-api-provider/index.ts diff --git a/src/data/providers/balancer-api/modules/pool-state/index.ts b/src/data/providers/balancer-api-provider/modules/pool-state/index.ts similarity index 100% rename from src/data/providers/balancer-api/modules/pool-state/index.ts rename to src/data/providers/balancer-api-provider/modules/pool-state/index.ts diff --git a/src/data/providers/balancer-api/modules/pool-state/types.ts b/src/data/providers/balancer-api-provider/modules/pool-state/types.ts similarity index 100% rename from src/data/providers/balancer-api/modules/pool-state/types.ts rename to src/data/providers/balancer-api-provider/modules/pool-state/types.ts diff --git a/src/entities/join/index.ts b/src/entities/join/index.ts index bff8b24e..b968ca7a 100644 --- a/src/entities/join/index.ts +++ b/src/entities/join/index.ts @@ -45,7 +45,7 @@ export type JoinInput = | SingleAssetJoinInput | ProportionalJoinInput; -// Returned from a pool-state query +// Returned from a join query export type JoinQueryResult = { poolId: Hex; joinKind: JoinKind; diff --git a/src/entities/join/parser.ts b/src/entities/join/parser.ts index c9f81a98..7506e603 100644 --- a/src/entities/join/parser.ts +++ b/src/entities/join/parser.ts @@ -1,7 +1,7 @@ import { BaseJoin } from '.'; import { WeightedJoin } from './weighted/weightedJoin'; -/*********************** Basic Helper to get pool-state class from pool type *************/ +/*********************** Basic Helper to get join class from pool type *************/ export type JoinConfig = { customPoolJoins: Record; }; diff --git a/test/lib/utils/helper.ts b/test/lib/utils/helper.ts index 1571aa18..9b3ffa22 100644 --- a/test/lib/utils/helper.ts +++ b/test/lib/utils/helper.ts @@ -291,7 +291,7 @@ export const forkSetup = async ( } for (let i = 0; i < tokens.length; i++) { - // Set initial account balance for each token that will be used to pool-state pool + // Set initial account balance for each token that will be used to join pool await setTokenBalance( client, accountAddress, diff --git a/test/weightedJoin.integration.test.ts b/test/weightedJoin.integration.test.ts index 26f91e6e..7ee6ffa9 100644 --- a/test/weightedJoin.integration.test.ts +++ b/test/weightedJoin.integration.test.ts @@ -41,7 +41,7 @@ const slippage = Slippage.fromPercentage('1'); // 1% const poolId = '0x68e3266c9c8bbd44ad9dca5afbfe629022aee9fe000200000000000000000512'; // Balancer 50COMP-50wstETH -describe('weighted pool-state test', () => { +describe('weighted join test', () => { let api: MockApi; let client: Client & PublicActions & TestActions & WalletActions; let poolFromApi: PoolState; @@ -63,7 +63,7 @@ describe('weighted pool-state test', () => { // get pool state from api poolFromApi = await api.getPool(poolId); - // setup pool-state helper + // setup join helper const joinParser = new JoinParser(); weightedJoin = joinParser.getJoin(poolFromApi.type); @@ -86,7 +86,7 @@ describe('weighted pool-state test', () => { ); }); - test('unbalanced pool-state', async () => { + test('unbalanced join', async () => { const poolTokens = poolFromApi.tokens.map( (t) => new Token(chainId, t.address, t.decimals), ); @@ -94,7 +94,7 @@ describe('weighted pool-state test', () => { TokenAmount.fromHumanAmount(t, '1'), ); - // perform pool-state query to get expected bpt out + // perform join query to get expected bpt out const joinInput: UnbalancedJoinInput = { amountsIn, chainId, @@ -127,7 +127,7 @@ describe('weighted pool-state test', () => { expect(expectedMaxAmountsIn).to.deep.eq(maxAmountsIn); }); - test('native asset pool-state', async () => { + test('native asset join', async () => { const poolTokens = poolFromApi.tokens.map( (t) => new Token(chainId, t.address, t.decimals), ); @@ -135,7 +135,7 @@ describe('weighted pool-state test', () => { TokenAmount.fromHumanAmount(t, '1'), ); - // perform pool-state query to get expected bpt out + // perform join query to get expected bpt out const joinInput: UnbalancedJoinInput = { amountsIn, chainId, @@ -171,11 +171,11 @@ describe('weighted pool-state test', () => { expect(expectedMaxAmountsIn).to.deep.eq(maxAmountsIn); }); - test('single asset pool-state', async () => { + test('single asset join', async () => { const bptOut = TokenAmount.fromHumanAmount(bpt, '1'); const tokenIn = '0x198d7387fa97a73f05b8578cdeff8f2a1f34cd1f'; - // perform pool-state query to get expected bpt out + // perform join query to get expected bpt out const joinInput: SingleAssetJoinInput = { bptOut, tokenIn, @@ -214,10 +214,10 @@ describe('weighted pool-state test', () => { expect(minBptOut).to.eq(bptOut.amount); }); - test('proportional pool-state', async () => { + test('proportional join', async () => { const bptOut = TokenAmount.fromHumanAmount(bpt, '1'); - // perform pool-state query to get expected bpt out + // perform join query to get expected bpt out const joinInput: ProportionalJoinInput = { bptOut, chainId, From 581478e5cdee26887d539764268b91201bf36c2d Mon Sep 17 00:00:00 2001 From: Luiz Gustavo Abou Hatem De Liz Date: Mon, 25 Sep 2023 11:21:06 -0300 Subject: [PATCH 04/11] Changing folder name "balancer-api-provider" to "balancer-api --- package.json | 3 ++- .../{balancer-api-provider => balancer-api}/client/index.ts | 0 .../providers/{balancer-api-provider => balancer-api}/index.ts | 0 .../modules/pool-state/index.ts | 0 .../modules/pool-state/types.ts | 0 5 files changed, 2 insertions(+), 1 deletion(-) rename src/data/providers/{balancer-api-provider => balancer-api}/client/index.ts (100%) rename src/data/providers/{balancer-api-provider => balancer-api}/index.ts (100%) rename src/data/providers/{balancer-api-provider => balancer-api}/modules/pool-state/index.ts (100%) rename src/data/providers/{balancer-api-provider => balancer-api}/modules/pool-state/types.ts (100%) diff --git a/package.json b/package.json index f6ccb0ba..f04ddbd2 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,8 @@ "test:ci": "vitest run", "changeset": "changeset", "changeset:release": "pnpm build && changeset publish", - "node": "npx hardhat node --tsconfig tsconfig.testing.json --fork $(. ./.env && echo $ETHEREUM_RPC_URL)" + "node": "npx hardhat node --tsconfig tsconfig.testing.json --fork $(. ./.env && echo $ETHEREUM_RPC_URL)", + "example": "npx ts-node -P tsconfig.testing.json -r tsconfig-paths/register" }, "dependencies": { "async-retry": "^1.3.3", diff --git a/src/data/providers/balancer-api-provider/client/index.ts b/src/data/providers/balancer-api/client/index.ts similarity index 100% rename from src/data/providers/balancer-api-provider/client/index.ts rename to src/data/providers/balancer-api/client/index.ts diff --git a/src/data/providers/balancer-api-provider/index.ts b/src/data/providers/balancer-api/index.ts similarity index 100% rename from src/data/providers/balancer-api-provider/index.ts rename to src/data/providers/balancer-api/index.ts diff --git a/src/data/providers/balancer-api-provider/modules/pool-state/index.ts b/src/data/providers/balancer-api/modules/pool-state/index.ts similarity index 100% rename from src/data/providers/balancer-api-provider/modules/pool-state/index.ts rename to src/data/providers/balancer-api/modules/pool-state/index.ts diff --git a/src/data/providers/balancer-api-provider/modules/pool-state/types.ts b/src/data/providers/balancer-api/modules/pool-state/types.ts similarity index 100% rename from src/data/providers/balancer-api-provider/modules/pool-state/types.ts rename to src/data/providers/balancer-api/modules/pool-state/types.ts From 8f52f44a2f68449ba3c9fdacedcd30131cca6110 Mon Sep 17 00:00:00 2001 From: Luiz Gustavo Abou Hatem De Liz Date: Mon, 25 Sep 2023 14:16:48 -0300 Subject: [PATCH 05/11] [WIP] Creating example for api integration; Changing function name; --- examples/join.ts | 12 ++++++++++++ package.json | 1 + src/data/providers/balancer-api/index.ts | 2 +- .../balancer-api/modules/pool-state/index.ts | 2 +- 4 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 examples/join.ts diff --git a/examples/join.ts b/examples/join.ts new file mode 100644 index 00000000..262f1df0 --- /dev/null +++ b/examples/join.ts @@ -0,0 +1,12 @@ + +import { BalancerApi } from "../src/data/providers/balancer-api"; + +const balancerApiUrl = 'https://backend-v3-canary.beets-ftm-node.com/graphql'; +const poolId = '0x481c5fc05d63a58aa2f0f2aa417c021b5d419cb200000000000000000000056a'; +const join = async () => { + const balancerApi = new BalancerApi(balancerApiUrl, 1); + const poolState = await balancerApi.pools.fetchPoolState(poolId); + console.log(poolState); +} + +join(); \ No newline at end of file diff --git a/package.json b/package.json index f04ddbd2..5418c9a7 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "pino-pretty": "^10.0.0", "rome": "12.1.3", "ts-node": "^10.9.1", + "tsconfig-paths": "^4.2.0", "tsup": "^6.6.0", "typescript": "^5.0.4", "vite": "^4.4.2", diff --git a/src/data/providers/balancer-api/index.ts b/src/data/providers/balancer-api/index.ts index d854c6ba..13f85a0a 100644 --- a/src/data/providers/balancer-api/index.ts +++ b/src/data/providers/balancer-api/index.ts @@ -1,7 +1,7 @@ import { Pools } from "./modules/pool-state"; import { BalancerApiClient } from "./client"; -export default class BalancerApi { +export class BalancerApi { balancerApiClient: BalancerApiClient; pools: Pools; diff --git a/src/data/providers/balancer-api/modules/pool-state/index.ts b/src/data/providers/balancer-api/modules/pool-state/index.ts index b78aa25b..2f3a273d 100644 --- a/src/data/providers/balancer-api/modules/pool-state/index.ts +++ b/src/data/providers/balancer-api/modules/pool-state/index.ts @@ -77,7 +77,7 @@ export class Pools { constructor(private readonly balancerApiClient: BalancerApiClient) {} - async fetchSimplePoolState(id: string): Promise { + async fetchPoolState(id: string): Promise { const { data: { poolGetPool }, } = await this.balancerApiClient.fetch('GetPool', this.poolStateQuery, { From 5e01345e1ddef86442583c504ddff0f34275db20 Mon Sep 17 00:00:00 2001 From: Luiz Gustavo Abou Hatem De Liz Date: Mon, 25 Sep 2023 23:43:41 -0300 Subject: [PATCH 06/11] Changing "Weighted" to "WEIGHTED" (format that comes from the API); Creating example for Join Weighted Pool; --- examples/join.ts | 12 --- examples/join/weighted.ts | 94 +++++++++++++++++++ .../balancer-api/modules/pool-state/index.ts | 2 +- .../balancer-api/modules/pool-state/types.ts | 4 +- src/entities/exit/parser.ts | 2 +- src/entities/join/parser.ts | 2 +- test/weightedExit.integration.test.ts | 3 +- test/weightedJoin.integration.test.ts | 2 +- 8 files changed, 102 insertions(+), 19 deletions(-) delete mode 100644 examples/join.ts create mode 100644 examples/join/weighted.ts diff --git a/examples/join.ts b/examples/join.ts deleted file mode 100644 index 262f1df0..00000000 --- a/examples/join.ts +++ /dev/null @@ -1,12 +0,0 @@ - -import { BalancerApi } from "../src/data/providers/balancer-api"; - -const balancerApiUrl = 'https://backend-v3-canary.beets-ftm-node.com/graphql'; -const poolId = '0x481c5fc05d63a58aa2f0f2aa417c021b5d419cb200000000000000000000056a'; -const join = async () => { - const balancerApi = new BalancerApi(balancerApiUrl, 1); - const poolState = await balancerApi.pools.fetchPoolState(poolId); - console.log(poolState); -} - -join(); \ No newline at end of file diff --git a/examples/join/weighted.ts b/examples/join/weighted.ts new file mode 100644 index 00000000..7869847c --- /dev/null +++ b/examples/join/weighted.ts @@ -0,0 +1,94 @@ +import dotenv from 'dotenv'; +dotenv.config(); + +import { BalancerApi } from "../../src/data/providers/balancer-api"; +import { ChainId, CHAINS, JoinKind, Slippage, Token, TokenAmount, UnbalancedJoinInput } from "../../src"; +import { + Client, + createTestClient, + http, + parseUnits, + PublicActions, + publicActions, + TestActions, WalletActions, + walletActions +} from "viem"; +import { PoolState } from "../../src/data/providers/balancer-api/modules/pool-state/types"; +import { forkSetup, sendTransactionGetBalances } from "../../test/lib/utils/helper"; +import { JoinParser } from "../../src/entities/join/parser"; + +const balancerApiUrl = 'https://backend-v3-canary.beets-ftm-node.com/graphql'; +const poolId = '0x5c6ee304399dbdb9c8ef030ab642b10820db8f56000200000000000000000014'; // 80BAL-20WETH +const chainId = ChainId.MAINNET; +const rpcUrl = 'http://127.0.0.1:8545/'; +const blockNumber = BigInt(18043296); +const testAddress = '0x10A19e7eE7d7F8a52822f6817de8ea18204F2e4f'; // Balancer DAO Multisig +const slippage = Slippage.fromPercentage('1'); // 1% + +const join = async () => { + const balancerApi = new BalancerApi(balancerApiUrl, 1); + const poolState: PoolState = await balancerApi.pools.fetchPoolState(poolId); + let client: Client & PublicActions & TestActions & WalletActions; + client = createTestClient({ + mode: 'hardhat', + chain: CHAINS[chainId], + transport: http(rpcUrl), + }) + .extend(publicActions) + .extend(walletActions); + + await forkSetup( + client, + testAddress, + [...poolState.tokens.map((t) => t.address), poolState.address], + undefined, // TODO: hardcode these values to improve test performance + [ + ...poolState.tokens.map((t) => parseUnits('100', t.decimals)), + parseUnits('100', 18), + ], + process.env.ETHEREUM_RPC_URL as string, + blockNumber, + ); + + + const joinParser = new JoinParser(); + const weightedJoin = joinParser.getJoin(poolState.type); + + const poolTokens = poolState.tokens.map( + (t) => new Token(chainId, t.address, t.decimals), + ); + const amountsIn = poolTokens.map((t) => + TokenAmount.fromHumanAmount(t, '1'), + ); + + // perform join query to get expected bpt out + const joinInput: UnbalancedJoinInput = { + amountsIn, + chainId, + rpcUrl, + kind: JoinKind.Unbalanced, + }; + + const queryResult = await weightedJoin.query(joinInput, poolState); + + const { call, to, value, maxAmountsIn, minBptOut } = + weightedJoin.buildCall({ + ...queryResult, + slippage, + sender: testAddress, + recipient: testAddress, + }); + const { transactionReceipt, balanceDeltas } = + await sendTransactionGetBalances( + [...poolState.tokens.map(({address})=>address), poolState.address /*BPT*/], + client, + testAddress, + to, + call, + value, + ); + console.log(transactionReceipt); + console.log(balanceDeltas); +} + +join(); \ No newline at end of file diff --git a/src/data/providers/balancer-api/modules/pool-state/index.ts b/src/data/providers/balancer-api/modules/pool-state/index.ts index 2f3a273d..938c1329 100644 --- a/src/data/providers/balancer-api/modules/pool-state/index.ts +++ b/src/data/providers/balancer-api/modules/pool-state/index.ts @@ -77,7 +77,7 @@ export class Pools { constructor(private readonly balancerApiClient: BalancerApiClient) {} - async fetchPoolState(id: string): Promise { + async fetchPoolState(id: string): Promise { const { data: { poolGetPool }, } = await this.balancerApiClient.fetch('GetPool', this.poolStateQuery, { diff --git a/src/data/providers/balancer-api/modules/pool-state/types.ts b/src/data/providers/balancer-api/modules/pool-state/types.ts index 5b23f242..88f908da 100644 --- a/src/data/providers/balancer-api/modules/pool-state/types.ts +++ b/src/data/providers/balancer-api/modules/pool-state/types.ts @@ -9,6 +9,6 @@ export type PoolState = { address: Address; decimals: number; index: number; - }; -}[]; + }[]; +}; diff --git a/src/entities/exit/parser.ts b/src/entities/exit/parser.ts index b2cf670b..ff9627fa 100644 --- a/src/entities/exit/parser.ts +++ b/src/entities/exit/parser.ts @@ -9,7 +9,7 @@ export class ExitParser { constructor(config?: ExitConfig) { const { customPoolExits } = config || {}; this.poolExits = { - Weighted: new WeightedExit(), + WEIGHTED: new WeightedExit(), // custom pool Exits take precedence over base Exits ...customPoolExits, }; diff --git a/src/entities/join/parser.ts b/src/entities/join/parser.ts index 7506e603..2dfd87b8 100644 --- a/src/entities/join/parser.ts +++ b/src/entities/join/parser.ts @@ -12,7 +12,7 @@ export class JoinParser { constructor(config?: JoinConfig) { const { customPoolJoins } = config || {}; this.poolJoins = { - Weighted: new WeightedJoin(), + WEIGHTED: new WeightedJoin(), // custom pool Joins take precedence over base Joins ...customPoolJoins, }; diff --git a/test/weightedExit.integration.test.ts b/test/weightedExit.integration.test.ts index 95aeff1b..c3fd4512 100644 --- a/test/weightedExit.integration.test.ts +++ b/test/weightedExit.integration.test.ts @@ -93,6 +93,7 @@ describe('weighted exit test', () => { tokenOut, kind: ExitKind.SINGLE_ASSET, }; + const { queryResult, maxBptIn, minAmountsOut } = await doTransaction( exitInput, poolFromApi.tokens.map((t) => t.address), @@ -317,7 +318,7 @@ export class MockApi { return { id, address: getPoolAddress(id) as Address, - type: 'Weighted', + type: 'WEIGHTED', tokens, }; } diff --git a/test/weightedJoin.integration.test.ts b/test/weightedJoin.integration.test.ts index 7ee6ffa9..d993f511 100644 --- a/test/weightedJoin.integration.test.ts +++ b/test/weightedJoin.integration.test.ts @@ -323,7 +323,7 @@ export class MockApi { return { id, address: getPoolAddress(id) as Address, - type: 'Weighted', + type: 'WEIGHTED', tokens, }; } From d0c111623a080f6e7883c810ab6f33ec14aae1e4 Mon Sep 17 00:00:00 2001 From: Luiz Gustavo Abou Hatem De Liz Date: Tue, 26 Sep 2023 19:39:54 -0300 Subject: [PATCH 07/11] Added example for exit; --- examples/exit/weighted.ts | 99 +++++++++++++++++++++++++++++++++++++++ examples/join/weighted.ts | 6 +-- tsconfig.json | 2 +- 3 files changed, 103 insertions(+), 4 deletions(-) create mode 100644 examples/exit/weighted.ts diff --git a/examples/exit/weighted.ts b/examples/exit/weighted.ts new file mode 100644 index 00000000..9839e601 --- /dev/null +++ b/examples/exit/weighted.ts @@ -0,0 +1,99 @@ +import dotenv from 'dotenv'; +dotenv.config(); + +import { BalancerApi } from "../../src/data/providers/balancer-api"; +import { + ChainId, + CHAINS, ExitKind, + SingleAssetExitInput, + Slippage, + Token, + TokenAmount, +} from "../../src"; +import { + Client, + createTestClient, + http, + parseUnits, + PublicActions, + publicActions, + TestActions, WalletActions, + walletActions +} from "viem"; +import { PoolState } from "../../src/data/providers/balancer-api/modules/pool-state/types"; +import { forkSetup, sendTransactionGetBalances } from "../../test/lib/utils/helper"; +import { ExitParser } from "../../src/entities/exit/parser"; + +const balancerApiUrl = 'https://backend-v3-canary.beets-ftm-node.com/graphql'; +const poolId = '0x5c6ee304399dbdb9c8ef030ab642b10820db8f56000200000000000000000014'; // 80BAL-20WETH +const chainId = ChainId.MAINNET; +const rpcUrl = 'http://127.0.0.1:8545/'; +const blockNumber = BigInt(18043296); +const testAddress = '0x10A19e7eE7d7F8a52822f6817de8ea18204F2e4f'; // Balancer DAO Multisig +const slippage = Slippage.fromPercentage('1'); // 1% + +const exit = async () => { + const balancerApi = new BalancerApi(balancerApiUrl, 1); + const poolState: PoolState = await balancerApi.pools.fetchPoolState(poolId); + let client: Client & PublicActions & TestActions & WalletActions; + let bpt: Token; + // setup BPT token + bpt = new Token(chainId, poolState.address, 18, 'BPT'); + client = createTestClient({ + mode: 'hardhat', + chain: CHAINS[chainId], + transport: http(rpcUrl), + }) + .extend(publicActions) + .extend(walletActions); + + await forkSetup( + client, + testAddress, + [poolState.address], + [0], + [ + parseUnits('100', 18), + ], + process.env.ETHEREUM_RPC_URL as string, + blockNumber, + ); + + + const exitParser = new ExitParser(); + const weightedExit = exitParser.getExit(poolState.type); + + const bptIn = TokenAmount.fromHumanAmount(bpt, '1'); + const tokenOut = '0xba100000625a3754423978a60c9317c58a424e3D'; // BAL + + const exitInput: SingleAssetExitInput = { + chainId, + rpcUrl, + bptIn, + tokenOut, + kind: ExitKind.SINGLE_ASSET, + }; + + const queryResult = await weightedExit.query(exitInput, poolState); + + const { call, to, value, maxBptIn, minAmountsOut } = + weightedExit.buildCall({ + ...queryResult, + slippage, + sender: testAddress, + recipient: testAddress, + }); + const { transactionReceipt, balanceDeltas } = + await sendTransactionGetBalances( + [...poolState.tokens.map(({address})=>address), bpt.address], + client, + testAddress, + to, + call, + value, + ); + console.log("transaction status: " + transactionReceipt.status); + console.log("token amounts deltas per token: " + balanceDeltas); +} + +exit(); \ No newline at end of file diff --git a/examples/join/weighted.ts b/examples/join/weighted.ts index 7869847c..d87a5431 100644 --- a/examples/join/weighted.ts +++ b/examples/join/weighted.ts @@ -41,7 +41,7 @@ const join = async () => { client, testAddress, [...poolState.tokens.map((t) => t.address), poolState.address], - undefined, // TODO: hardcode these values to improve test performance + [1,3,0], [ ...poolState.tokens.map((t) => parseUnits('100', t.decimals)), parseUnits('100', 18), @@ -87,8 +87,8 @@ const join = async () => { call, value, ); - console.log(transactionReceipt); - console.log(balanceDeltas); + console.log("transaction status: " + transactionReceipt.status); + console.log("token amounts deltas per token: " + balanceDeltas); } join(); \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 21a749b5..1bbfcb59 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,5 @@ { - "include": ["src"], + "include": ["src", "examples"], "compilerOptions": { "target": "ESNext", "module": "ESNext", From 55eed3b68f98431984934d69d126389e42650821 Mon Sep 17 00:00:00 2001 From: Luiz Gustavo Abou Hatem De Liz Date: Wed, 27 Sep 2023 20:15:14 -0300 Subject: [PATCH 08/11] Removing Parser; Replacing Type PoolState for PoolStateInput; Updating README.md examples section; --- README.md | 76 ++++++++++++------- examples/exit/weighted.ts | 5 +- examples/join/weighted.ts | 16 +++- src/data/index.ts | 1 + src/data/providers/balancer-api/index.ts | 2 +- .../balancer-api/modules/pool-state/index.ts | 4 +- src/entities/exit/parser.ts | 0 src/entities/join/parser.ts | 0 8 files changed, 67 insertions(+), 37 deletions(-) delete mode 100644 src/entities/exit/parser.ts delete mode 100644 src/entities/join/parser.ts diff --git a/README.md b/README.md index 3e79f119..a94a8c8f 100644 --- a/README.md +++ b/README.md @@ -22,13 +22,18 @@ Testing requires access to an archive node for onchain quote comparisons. This c `pnpm test` -## Examples +## Balancer Api Provider -### Balancer Api Provider +The Balancer API Provider is a provider that facilitates +data fetching from the Balancer API, +it can be used for: +- Fetch Pool State for Joins; +- Fetch Pool State for Exits. + +### Usage for Joining Pool -Joining with pool state: ```ts - import BalancerApi from "@balancer/sdk/data/providers/balancer-api"; + import { BalancerApi, PoolJoin } from "@balancer/sdk"; ... const joinInput: ProportionalJoinInput = { bptOut, @@ -37,47 +42,64 @@ Joining with pool state: kind: JoinKind.Proportional, }; - const balancerApi = new BalancerApi('https://api-v3.balancer.fi/', 1); - const poolState = await balancerApi.pools.fetchSimplePoolState('0x5f1d6874cb1e7156e79a7563d2b61c6cbce03150000200000000000000000586'); - const joinParser = new JoinParser(); - const poolJoin = joinParser.getJoin(poolState.type); - const queryResult = await weightedJoin.query(joinInput, poolState); - + const balancerApi = new BalancerApi('https://backend-v3-canary.beets-ftm-node.com/graphql', 1); + const poolState = await balancerApi.pools.fetchPoolState('0x5f1d6874cb1e7156e79a7563d2b61c6cbce03150000200000000000000000586'); + const poolJoin = new PoolJoin(); + const queryResult = await poolJoin.query(joinInput, poolState); + const { call, to, value, maxAmountsIn, minBptOut } = + poolJoin.buildCall({ + ...queryResult, + slippage, + sender: signerAddress, + recipient: signerAddress, + }); + const client = createClient({ + ... + }) + + await client.sendTransaction({ + account: signerAddress, + chain: client.chain, + data: call, + to, + value, + }); ``` +Full working join example: [examples/join/weighted.ts](./examples/join/weighted.ts) -Exiting with pool state: +### Usage for Exiting Pool ```ts -import BalancerApi from "@balancer/sdk/data/providers/balancer-api"; +import { BalancerApi, PoolExit } from "@balancer/sdk"; ... -const joinInput: ProportionalJoinInput = { - bptOut, +const exitInput: SingleAssetExitInput = { chainId, rpcUrl, - kind: JoinKind.Proportional, + bptIn, + tokenOut, + kind: ExitKind.SINGLE_ASSET, }; -const balancerApi = new BalancerApi('https://api-v3.balancer.fi/', 1); -const poolState = await balancerApi.pools.fetchSimplePoolState('0x5f1d6874cb1e7156e79a7563d2b61c6cbce03150000200000000000000000586'); -const joinParser = new JoinParser(); -const poolJoin = joinParser.getJoin(poolState.type); -const queryResult = await weightedJoin.query(joinInput, poolState); -const slippage = Slippage.fromPercentage('1'); // 1% +const balancerApi = new BalancerApi('https://backend-v3-canary.beets-ftm-node.com/graphql', 1); +const poolState = await balancerApi.pools.fetchPoolState('0x5f1d6874cb1e7156e79a7563d2b61c6cbce03150000200000000000000000586'); +const poolExit = new PoolExit(); +const queryResult = await poolExit.query(exitInput, poolState); const { call, to, value, maxAmountsIn, minBptOut } = - weightedJoin.buildCall({ + poolExit.buildCall({ ...queryResult, slippage, - sender, - recipient, + sender: signerAddress, + recipient: signerAddress, }); const client = createClient({ ... }) await client.sendTransaction({ - account, + account: signerAddress, chain: client.chain, - data, + data: call, to, value, }); -``` \ No newline at end of file +``` +Full working exit example: [examples/exit/weighted.ts](./examples/exit/weighted.ts) diff --git a/examples/exit/weighted.ts b/examples/exit/weighted.ts index a25857fe..e7691dda 100644 --- a/examples/exit/weighted.ts +++ b/examples/exit/weighted.ts @@ -4,7 +4,7 @@ dotenv.config(); import { BalancerApi } from "../../src/data/providers/balancer-api"; import { ChainId, - CHAINS, ExitKind, PoolExit, + CHAINS, ExitKind, PoolExit, PoolStateInput, SingleAssetExitInput, Slippage, Token, @@ -20,7 +20,6 @@ import { TestActions, WalletActions, walletActions } from "viem"; -import { PoolState } from "../../src/data/providers/balancer-api/modules/pool-state/types"; import { forkSetup, sendTransactionGetBalances } from "../../test/lib/utils/helper"; const balancerApiUrl = 'https://backend-v3-canary.beets-ftm-node.com/graphql'; @@ -33,7 +32,7 @@ const slippage = Slippage.fromPercentage('1'); // 1% const exit = async () => { const balancerApi = new BalancerApi(balancerApiUrl, 1); - const poolState: PoolState = await balancerApi.pools.fetchPoolState(poolId); + const poolState: PoolStateInput = await balancerApi.pools.fetchPoolState(poolId); let client: Client & PublicActions & TestActions & WalletActions; let bpt: Token; // setup BPT token diff --git a/examples/join/weighted.ts b/examples/join/weighted.ts index f972aff3..b1aed8f5 100644 --- a/examples/join/weighted.ts +++ b/examples/join/weighted.ts @@ -1,8 +1,17 @@ import dotenv from 'dotenv'; dotenv.config(); -import { BalancerApi } from "../../src/data/providers/balancer-api"; -import { ChainId, CHAINS, JoinKind, PoolJoin, Slippage, Token, TokenAmount, UnbalancedJoinInput } from "../../src"; +import { + BalancerApi, + ChainId, + CHAINS, + JoinKind, + PoolJoin, PoolStateInput, + Slippage, + Token, + TokenAmount, + UnbalancedJoinInput +} from "../../src"; import { Client, createTestClient, @@ -13,7 +22,6 @@ import { TestActions, WalletActions, walletActions } from "viem"; -import { PoolState } from "../../src/data/providers/balancer-api/modules/pool-state/types"; import { forkSetup, sendTransactionGetBalances } from "../../test/lib/utils/helper"; const balancerApiUrl = 'https://backend-v3-canary.beets-ftm-node.com/graphql'; @@ -26,7 +34,7 @@ const slippage = Slippage.fromPercentage('1'); // 1% const join = async () => { const balancerApi = new BalancerApi(balancerApiUrl, 1); - const poolState: PoolState = await balancerApi.pools.fetchPoolState(poolId); + const poolState: PoolStateInput = await balancerApi.pools.fetchPoolState(poolId); let client: Client & PublicActions & TestActions & WalletActions; client = createTestClient({ mode: 'hardhat', diff --git a/src/data/index.ts b/src/data/index.ts index e02a4aa2..ed1dbc6a 100644 --- a/src/data/index.ts +++ b/src/data/index.ts @@ -1,3 +1,4 @@ export * from './enrichers/onChainPoolDataEnricher'; export * from './providers/subgraphPoolProvider'; +export * from './providers/balancer-api'; export * from './types'; diff --git a/src/data/providers/balancer-api/index.ts b/src/data/providers/balancer-api/index.ts index 13f85a0a..bc18ae52 100644 --- a/src/data/providers/balancer-api/index.ts +++ b/src/data/providers/balancer-api/index.ts @@ -13,4 +13,4 @@ export class BalancerApi { } -} \ No newline at end of file +} diff --git a/src/data/providers/balancer-api/modules/pool-state/index.ts b/src/data/providers/balancer-api/modules/pool-state/index.ts index 938c1329..38ca9403 100644 --- a/src/data/providers/balancer-api/modules/pool-state/index.ts +++ b/src/data/providers/balancer-api/modules/pool-state/index.ts @@ -1,5 +1,5 @@ import { BalancerApiClient } from '../../client'; -import { PoolState } from './types'; +import { PoolStateInput } from "../../../../../entities"; export class Pools { readonly poolStateQuery = `query GetPool($id: String!){ @@ -77,7 +77,7 @@ export class Pools { constructor(private readonly balancerApiClient: BalancerApiClient) {} - async fetchPoolState(id: string): Promise { + async fetchPoolState(id: string): Promise { const { data: { poolGetPool }, } = await this.balancerApiClient.fetch('GetPool', this.poolStateQuery, { diff --git a/src/entities/exit/parser.ts b/src/entities/exit/parser.ts deleted file mode 100644 index e69de29b..00000000 diff --git a/src/entities/join/parser.ts b/src/entities/join/parser.ts deleted file mode 100644 index e69de29b..00000000 From a4a2dde524321e64b44afdf73a521a9a0049d440 Mon Sep 17 00:00:00 2001 From: Luiz Gustavo Abou Hatem De Liz Date: Fri, 29 Sep 2023 17:40:13 -0300 Subject: [PATCH 09/11] Adapting tests for anvil node; Obs.: Still working with hardhat; --- package.json | 1 + pnpm-lock.yaml | 139 +++++++++++++++++++++++--- test/lib/utils/helper.ts | 6 +- test/weightedExit.integration.test.ts | 2 +- test/weightedJoin.integration.test.ts | 2 +- tsconfig.json | 2 +- 6 files changed, 131 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index 5418c9a7..0c83d95c 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "changeset": "changeset", "changeset:release": "pnpm build && changeset publish", "node": "npx hardhat node --tsconfig tsconfig.testing.json --fork $(. ./.env && echo $ETHEREUM_RPC_URL)", + "node:anvil": "anvil --fork-url $(. ./.env && echo $ETHEREUM_RPC_URL)", "example": "npx ts-node -P tsconfig.testing.json -r tsconfig-paths/register" }, "dependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0a294b89..25463b64 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5,6 +5,9 @@ settings: excludeLinksFromLockfile: false dependencies: + '@viem/anvil': + specifier: ^0.0.6 + version: 0.0.6 async-retry: specifier: ^1.3.3 version: 1.3.3 @@ -46,6 +49,9 @@ devDependencies: ts-node: specifier: ^10.9.1 version: 10.9.1(@types/node@18.15.11)(typescript@5.1.3) + tsconfig-paths: + specifier: ^4.2.0 + version: 4.2.0 tsup: specifier: ^6.6.0 version: 6.7.0(ts-node@10.9.1)(typescript@5.1.3) @@ -1650,6 +1656,19 @@ packages: '@types/node': 18.15.11 dev: false + /@viem/anvil@0.0.6: + resolution: {integrity: sha512-OjKR/+FVwzuygXYFqP8MBal1SXG8bT2gbZwqqB0XuLw81LNBBvmE/Repm6+5kkBh4IUj0PhYdrqOsnayS14Gtg==} + dependencies: + execa: 7.2.0 + get-port: 6.1.2 + http-proxy: 1.18.1 + ws: 8.14.2 + transitivePeerDependencies: + - bufferutil + - debug + - utf-8-validate + dev: false + /@vitest/expect@0.30.1: resolution: {integrity: sha512-c3kbEtN8XXJSeN81iDGq29bUzSjQhjES2WR3aColsS4lPGbivwLtas4DNUe0jD9gg/FYGIteqOenfU95EFituw==} dependencies: @@ -2290,7 +2309,6 @@ packages: path-key: 3.1.1 shebang-command: 2.0.0 which: 2.0.2 - dev: true /csv-generate@3.4.3: resolution: {integrity: sha512-w/T+rqR0vwvHqWs/1ZyMDWtHHSJaN06klRqJXBEpDJaM/+dZkso0OKh1VcuuYvK3XM53KysVNq8Ko/epCK8wOw==} @@ -2336,7 +2354,6 @@ packages: dependencies: ms: 2.1.2 supports-color: 8.1.1 - dev: true /decamelize-keys@1.1.1: resolution: {integrity: sha512-WiPxgEirIV0/eIOMcnFBA3/IJZAZqKnwAwWyvvdi4lsr1WCN22nhdf/3db3DoZcUjTV2SqfzIwNyp6y2xs3nmg==} @@ -2701,6 +2718,10 @@ packages: resolution: {integrity: sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==} engines: {node: '>=6'} + /eventemitter3@4.0.7: + resolution: {integrity: sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==} + dev: false + /events@3.3.0: resolution: {integrity: sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==} engines: {node: '>=0.8.x'} @@ -2727,6 +2748,21 @@ packages: strip-final-newline: 2.0.0 dev: true + /execa@7.2.0: + resolution: {integrity: sha512-UduyVP7TLB5IcAQl+OzLyLcS/l32W/GLg+AhHJ+ow40FOk2U3SAllPwR44v4vmdFwIWqpdwxxpQbF1n5ta9seA==} + engines: {node: ^14.18.0 || ^16.14.0 || >=18.0.0} + dependencies: + cross-spawn: 7.0.3 + get-stream: 6.0.1 + human-signals: 4.3.1 + is-stream: 3.0.0 + merge-stream: 2.0.0 + npm-run-path: 5.1.0 + onetime: 6.0.0 + signal-exit: 3.0.7 + strip-final-newline: 3.0.0 + dev: false + /extendable-error@0.1.7: resolution: {integrity: sha512-UOiS2in6/Q0FK0R0q6UY9vYpQ21mr/Qn1KOnte7vsACuNJf514WvCCUHSRCPcgjPT2bAhNIJdlE6bVap1GKmeg==} dev: true @@ -2826,7 +2862,6 @@ packages: optional: true dependencies: debug: 4.3.4(supports-color@8.1.1) - dev: true /for-each@0.3.3: resolution: {integrity: sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==} @@ -2918,10 +2953,14 @@ packages: has-symbols: 1.0.3 dev: true + /get-port@6.1.2: + resolution: {integrity: sha512-BrGGraKm2uPqurfGVj/z97/zv8dPleC6x9JBNRTrDNtCkkRF4rPwrQXFgL7+I+q8QSdU4ntLQX2D7KIxSy8nGw==} + engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} + dev: false + /get-stream@6.0.1: resolution: {integrity: sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==} engines: {node: '>=10'} - dev: true /get-symbol-description@1.0.0: resolution: {integrity: sha512-2EmdH1YvIQiZpltCNgkuiUnyukzxM/R6NDJX31Ke3BG1Nq5b0S2PhX59UKi9vZpPDQVdqn+1IcaAwnzTT5vCjw==} @@ -3089,7 +3128,6 @@ packages: /has-flag@4.0.0: resolution: {integrity: sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==} engines: {node: '>=8'} - dev: true /has-property-descriptors@1.0.0: resolution: {integrity: sha512-62DVLZGoiEBDHQyqG4w9xCuZ7eJEwNmJRWw2VY84Oedb7WFcA27fiEVe8oUQx9hAUJ4ekurquucTGwsyO1XGdQ==} @@ -3172,6 +3210,17 @@ packages: toidentifier: 1.0.1 dev: true + /http-proxy@1.18.1: + resolution: {integrity: sha512-7mz/721AbnJwIVbnaSv1Cz3Am0ZLT/UBwkC92VlxhXv/k/BBQfM2fXElQNC27BVGr0uwUpplYPQM9LnaBMR5NQ==} + engines: {node: '>=8.0.0'} + dependencies: + eventemitter3: 4.0.7 + follow-redirects: 1.15.2(debug@4.3.4) + requires-port: 1.0.0 + transitivePeerDependencies: + - debug + dev: false + /https-proxy-agent@5.0.1: resolution: {integrity: sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==} engines: {node: '>= 6'} @@ -3191,6 +3240,11 @@ packages: engines: {node: '>=10.17.0'} dev: true + /human-signals@4.3.1: + resolution: {integrity: sha512-nZXjEF2nbo7lIw3mgYjItAfgQXog3OjJogSbKa2CQIIvSGWcKgeJnQlNXip6NglNzYH45nSRiEVimMvYL8DDqQ==} + engines: {node: '>=14.18.0'} + dev: false + /iconv-lite@0.4.24: resolution: {integrity: sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==} engines: {node: '>=0.10.0'} @@ -3372,6 +3426,11 @@ packages: engines: {node: '>=8'} dev: true + /is-stream@3.0.0: + resolution: {integrity: sha512-LnQR4bZ9IADDRSkvpqMGvt/tEJWclzklNgSw48V5EAaAeDd6qGvN8ei6k5p0tvxSR171VmGyHuTiAOfxAbr8kA==} + engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} + dev: false + /is-string@1.0.7: resolution: {integrity: sha512-tE2UXzivje6ofPW7l23cjDOMa09gb7xlAqG6jG5ej6uPV32TlWP3NKPigtaGeHNu9fohccRYvIiZMfOOnOYUtg==} engines: {node: '>= 0.4'} @@ -3422,7 +3481,6 @@ packages: /isexe@2.0.0: resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==} - dev: true /isomorphic-ws@5.0.0(ws@8.12.0): resolution: {integrity: sha512-muId7Zzn9ywDsyXgTIafTry2sV3nySZeUDe6YedVd1Hvuuep5AsIlqK+XefWpYTyJG5e503F2xIuT2lcU6rCSw==} @@ -3473,6 +3531,12 @@ packages: resolution: {integrity: sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==} dev: true + /json5@2.2.3: + resolution: {integrity: sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==} + engines: {node: '>=6'} + hasBin: true + dev: true + /jsonc-parser@3.2.0: resolution: {integrity: sha512-gfFQZrcTc8CnKXp6Y4/CBT3fTc0OVuDofpre4aEeEpSBPV5X5v4+Vmx+8snU7RLPrNHPKSgLxGo9YuQzz20o+w==} dev: true @@ -3711,7 +3775,6 @@ packages: /merge-stream@2.0.0: resolution: {integrity: sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==} - dev: true /merge2@1.4.1: resolution: {integrity: sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==} @@ -3731,6 +3794,11 @@ packages: engines: {node: '>=6'} dev: true + /mimic-fn@4.0.0: + resolution: {integrity: sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw==} + engines: {node: '>=12'} + dev: false + /min-indent@1.0.1: resolution: {integrity: sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg==} engines: {node: '>=4'} @@ -3832,7 +3900,6 @@ packages: /ms@2.1.2: resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==} - dev: true /ms@2.1.3: resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==} @@ -3892,6 +3959,13 @@ packages: path-key: 3.1.1 dev: true + /npm-run-path@5.1.0: + resolution: {integrity: sha512-sJOdmRGrY2sjNTRMbSvluQqg+8X7ZK61yvzBEIDhz4f8z1TZFYABsqjjCBd/0PUNE9M6QDgHJXQkGUEm7Q+l9Q==} + engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} + dependencies: + path-key: 4.0.0 + dev: false + /object-assign@4.1.1: resolution: {integrity: sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==} engines: {node: '>=0.10.0'} @@ -3936,6 +4010,13 @@ packages: mimic-fn: 2.1.0 dev: true + /onetime@6.0.0: + resolution: {integrity: sha512-1FlR+gjXK7X+AsAHso35MnyN5KqGwJRi/31ft6x0M194ht7S+rWAvd7PHss9xSKMzE0asv1pyIHaJYq+BbacAQ==} + engines: {node: '>=12'} + dependencies: + mimic-fn: 4.0.0 + dev: false + /os-tmpdir@1.0.2: resolution: {integrity: sha512-D2FR03Vir7FIu45XBY20mTb+/ZSWB00sjU9jdQXt83gDrI4Ztz5Fs7/yy74g2N5SVQY4xY1qDr4rNddwYRVX0g==} engines: {node: '>=0.10.0'} @@ -4051,7 +4132,11 @@ packages: /path-key@3.1.1: resolution: {integrity: sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==} engines: {node: '>=8'} - dev: true + + /path-key@4.0.0: + resolution: {integrity: sha512-haREypq7xkM7ErfgIyA0z+Bj4AGKlMSdlQE2jvJo6huWD1EdkKYV+G/T4nq0YEF2vgTT8kqMFKo1uHn950r4SQ==} + engines: {node: '>=12'} + dev: false /path-parse@1.0.7: resolution: {integrity: sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==} @@ -4364,6 +4449,10 @@ packages: resolution: {integrity: sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==} dev: true + /requires-port@1.0.0: + resolution: {integrity: sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==} + dev: false + /resolve-from@5.0.0: resolution: {integrity: sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==} engines: {node: '>=8'} @@ -4560,7 +4649,6 @@ packages: engines: {node: '>=8'} dependencies: shebang-regex: 3.0.0 - dev: true /shebang-regex@1.0.0: resolution: {integrity: sha512-wpoSFAxys6b2a2wHZ1XpDSgD7N9iVjg29Ph9uV/uaP9Ex/KXlkTZTeddxDPSYQpgvzKLGJke2UU0AzoGCjNIvQ==} @@ -4570,7 +4658,6 @@ packages: /shebang-regex@3.0.0: resolution: {integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==} engines: {node: '>=8'} - dev: true /side-channel@1.0.4: resolution: {integrity: sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==} @@ -4586,7 +4673,6 @@ packages: /signal-exit@3.0.7: resolution: {integrity: sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==} - dev: true /slash@3.0.0: resolution: {integrity: sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==} @@ -4778,6 +4864,11 @@ packages: engines: {node: '>=6'} dev: true + /strip-final-newline@3.0.0: + resolution: {integrity: sha512-dOESqjYr96iWYylGObzd39EuNTa5VJxyvVAEm5Jnh7KGo75V43Hk1odPQkNDyXNmUR6k+gEiDVXnjB8HJ3crXw==} + engines: {node: '>=12'} + dev: false + /strip-hex-prefix@1.0.0: resolution: {integrity: sha512-q8d4ue7JGEiVcypji1bALTos+0pWtyGlivAWyPuTkHzuTCJqrK9sWxYQZUq6Nq3cuyv3bm734IhHvHtGGURU6A==} engines: {node: '>=6.5.0', npm: '>=3'} @@ -4835,7 +4926,6 @@ packages: engines: {node: '>=10'} dependencies: has-flag: 4.0.0 - dev: true /supports-preserve-symlinks-flag@1.0.0: resolution: {integrity: sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==} @@ -4955,6 +5045,15 @@ packages: yn: 3.1.1 dev: true + /tsconfig-paths@4.2.0: + resolution: {integrity: sha512-NoZ4roiN7LnbKn9QqE1amc9DJfzvZXxF4xDavcOWt1BPkdx+m+0gJuPM+S0vCe7zTJMYUP0R8pO2XMr+Y8oLIg==} + engines: {node: '>=6'} + dependencies: + json5: 2.2.3 + minimist: 1.2.8 + strip-bom: 3.0.0 + dev: true + /tslib@1.14.1: resolution: {integrity: sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==} dev: true @@ -5333,7 +5432,6 @@ packages: hasBin: true dependencies: isexe: 2.0.0 - dev: true /why-is-node-running@2.2.2: resolution: {integrity: sha512-6tSwToZxTOcotxHeA+qGCq1mVzKR3CwcJGmVcY+QE8SHy6TnpFnh8PAvPNHYr7EcuVeG0QSMxtYCuO1ta/G/oA==} @@ -5409,6 +5507,19 @@ packages: optional: true dev: false + /ws@8.14.2: + resolution: {integrity: sha512-wEBG1ftX4jcglPxgFCMJmZ2PLtSbJ2Peg6TmpJFTbe9GZYOQCDPdMYu/Tm0/bGZkw8paZnJY45J4K2PZrLYq8g==} + engines: {node: '>=10.0.0'} + peerDependencies: + bufferutil: ^4.0.1 + utf-8-validate: '>=5.0.2' + peerDependenciesMeta: + bufferutil: + optional: true + utf-8-validate: + optional: true + dev: false + /y18n@4.0.3: resolution: {integrity: sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==} dev: true diff --git a/test/lib/utils/helper.ts b/test/lib/utils/helper.ts index 9b3ffa22..3976c002 100644 --- a/test/lib/utils/helper.ts +++ b/test/lib/utils/helper.ts @@ -34,7 +34,7 @@ export const approveToken = async ( args: [BALANCER_VAULT, amount], }); - const txReceipt = await client.getTransactionReceipt({ + const txReceipt = await client.waitForTransactionReceipt({ hash, }); return txReceipt.status === 'success'; @@ -107,9 +107,7 @@ export async function sendTransactionGetBalances( to, value, }); - const transactionReceipt = await client.getTransactionReceipt({ - hash, - }); + const transactionReceipt = await client.waitForTransactionReceipt({ hash }); const { gasUsed, effectiveGasPrice } = transactionReceipt; const gasPrice = gasUsed * effectiveGasPrice; diff --git a/test/weightedExit.integration.test.ts b/test/weightedExit.integration.test.ts index b7bffb3d..591e57d9 100644 --- a/test/weightedExit.integration.test.ts +++ b/test/weightedExit.integration.test.ts @@ -61,7 +61,7 @@ describe('weighted exit test', () => { const poolInput = await api.getPool(poolId); const client = createTestClient({ - mode: 'hardhat', + mode: 'anvil', chain: CHAINS[chainId], transport: http(rpcUrl), }) diff --git a/test/weightedJoin.integration.test.ts b/test/weightedJoin.integration.test.ts index 3177a20d..c131809b 100644 --- a/test/weightedJoin.integration.test.ts +++ b/test/weightedJoin.integration.test.ts @@ -63,7 +63,7 @@ describe('weighted join test', () => { const poolInput = await api.getPool(poolId); const client = createTestClient({ - mode: 'hardhat', + mode: 'anvil', chain: CHAINS[chainId], transport: http(rpcUrl), }) diff --git a/tsconfig.json b/tsconfig.json index 1bbfcb59..24fd2db5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,5 @@ { - "include": ["src", "examples"], + "include": ["src", "examples", "test"], "compilerOptions": { "target": "ESNext", "module": "ESNext", From 18f7acc8978695379f3d6056467466841d7ab576 Mon Sep 17 00:00:00 2001 From: Luiz Gustavo Abou Hatem De Liz Date: Fri, 29 Sep 2023 17:42:24 -0300 Subject: [PATCH 10/11] removing @viem/anvil from pnpm-lock.yaml --- pnpm-lock.yaml | 121 ++++++------------------------------------------- 1 file changed, 14 insertions(+), 107 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 25463b64..4128f02e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5,9 +5,6 @@ settings: excludeLinksFromLockfile: false dependencies: - '@viem/anvil': - specifier: ^0.0.6 - version: 0.0.6 async-retry: specifier: ^1.3.3 version: 1.3.3 @@ -1656,19 +1653,6 @@ packages: '@types/node': 18.15.11 dev: false - /@viem/anvil@0.0.6: - resolution: {integrity: sha512-OjKR/+FVwzuygXYFqP8MBal1SXG8bT2gbZwqqB0XuLw81LNBBvmE/Repm6+5kkBh4IUj0PhYdrqOsnayS14Gtg==} - dependencies: - execa: 7.2.0 - get-port: 6.1.2 - http-proxy: 1.18.1 - ws: 8.14.2 - transitivePeerDependencies: - - bufferutil - - debug - - utf-8-validate - dev: false - /@vitest/expect@0.30.1: resolution: {integrity: sha512-c3kbEtN8XXJSeN81iDGq29bUzSjQhjES2WR3aColsS4lPGbivwLtas4DNUe0jD9gg/FYGIteqOenfU95EFituw==} dependencies: @@ -2309,6 +2293,7 @@ packages: path-key: 3.1.1 shebang-command: 2.0.0 which: 2.0.2 + dev: true /csv-generate@3.4.3: resolution: {integrity: sha512-w/T+rqR0vwvHqWs/1ZyMDWtHHSJaN06klRqJXBEpDJaM/+dZkso0OKh1VcuuYvK3XM53KysVNq8Ko/epCK8wOw==} @@ -2354,6 +2339,7 @@ packages: dependencies: ms: 2.1.2 supports-color: 8.1.1 + dev: true /decamelize-keys@1.1.1: resolution: {integrity: sha512-WiPxgEirIV0/eIOMcnFBA3/IJZAZqKnwAwWyvvdi4lsr1WCN22nhdf/3db3DoZcUjTV2SqfzIwNyp6y2xs3nmg==} @@ -2718,10 +2704,6 @@ packages: resolution: {integrity: sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==} engines: {node: '>=6'} - /eventemitter3@4.0.7: - resolution: {integrity: sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==} - dev: false - /events@3.3.0: resolution: {integrity: sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==} engines: {node: '>=0.8.x'} @@ -2748,21 +2730,6 @@ packages: strip-final-newline: 2.0.0 dev: true - /execa@7.2.0: - resolution: {integrity: sha512-UduyVP7TLB5IcAQl+OzLyLcS/l32W/GLg+AhHJ+ow40FOk2U3SAllPwR44v4vmdFwIWqpdwxxpQbF1n5ta9seA==} - engines: {node: ^14.18.0 || ^16.14.0 || >=18.0.0} - dependencies: - cross-spawn: 7.0.3 - get-stream: 6.0.1 - human-signals: 4.3.1 - is-stream: 3.0.0 - merge-stream: 2.0.0 - npm-run-path: 5.1.0 - onetime: 6.0.0 - signal-exit: 3.0.7 - strip-final-newline: 3.0.0 - dev: false - /extendable-error@0.1.7: resolution: {integrity: sha512-UOiS2in6/Q0FK0R0q6UY9vYpQ21mr/Qn1KOnte7vsACuNJf514WvCCUHSRCPcgjPT2bAhNIJdlE6bVap1GKmeg==} dev: true @@ -2862,6 +2829,7 @@ packages: optional: true dependencies: debug: 4.3.4(supports-color@8.1.1) + dev: true /for-each@0.3.3: resolution: {integrity: sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==} @@ -2953,14 +2921,10 @@ packages: has-symbols: 1.0.3 dev: true - /get-port@6.1.2: - resolution: {integrity: sha512-BrGGraKm2uPqurfGVj/z97/zv8dPleC6x9JBNRTrDNtCkkRF4rPwrQXFgL7+I+q8QSdU4ntLQX2D7KIxSy8nGw==} - engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} - dev: false - /get-stream@6.0.1: resolution: {integrity: sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==} engines: {node: '>=10'} + dev: true /get-symbol-description@1.0.0: resolution: {integrity: sha512-2EmdH1YvIQiZpltCNgkuiUnyukzxM/R6NDJX31Ke3BG1Nq5b0S2PhX59UKi9vZpPDQVdqn+1IcaAwnzTT5vCjw==} @@ -3128,6 +3092,7 @@ packages: /has-flag@4.0.0: resolution: {integrity: sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==} engines: {node: '>=8'} + dev: true /has-property-descriptors@1.0.0: resolution: {integrity: sha512-62DVLZGoiEBDHQyqG4w9xCuZ7eJEwNmJRWw2VY84Oedb7WFcA27fiEVe8oUQx9hAUJ4ekurquucTGwsyO1XGdQ==} @@ -3210,17 +3175,6 @@ packages: toidentifier: 1.0.1 dev: true - /http-proxy@1.18.1: - resolution: {integrity: sha512-7mz/721AbnJwIVbnaSv1Cz3Am0ZLT/UBwkC92VlxhXv/k/BBQfM2fXElQNC27BVGr0uwUpplYPQM9LnaBMR5NQ==} - engines: {node: '>=8.0.0'} - dependencies: - eventemitter3: 4.0.7 - follow-redirects: 1.15.2(debug@4.3.4) - requires-port: 1.0.0 - transitivePeerDependencies: - - debug - dev: false - /https-proxy-agent@5.0.1: resolution: {integrity: sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==} engines: {node: '>= 6'} @@ -3240,11 +3194,6 @@ packages: engines: {node: '>=10.17.0'} dev: true - /human-signals@4.3.1: - resolution: {integrity: sha512-nZXjEF2nbo7lIw3mgYjItAfgQXog3OjJogSbKa2CQIIvSGWcKgeJnQlNXip6NglNzYH45nSRiEVimMvYL8DDqQ==} - engines: {node: '>=14.18.0'} - dev: false - /iconv-lite@0.4.24: resolution: {integrity: sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==} engines: {node: '>=0.10.0'} @@ -3426,11 +3375,6 @@ packages: engines: {node: '>=8'} dev: true - /is-stream@3.0.0: - resolution: {integrity: sha512-LnQR4bZ9IADDRSkvpqMGvt/tEJWclzklNgSw48V5EAaAeDd6qGvN8ei6k5p0tvxSR171VmGyHuTiAOfxAbr8kA==} - engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} - dev: false - /is-string@1.0.7: resolution: {integrity: sha512-tE2UXzivje6ofPW7l23cjDOMa09gb7xlAqG6jG5ej6uPV32TlWP3NKPigtaGeHNu9fohccRYvIiZMfOOnOYUtg==} engines: {node: '>= 0.4'} @@ -3481,6 +3425,7 @@ packages: /isexe@2.0.0: resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==} + dev: true /isomorphic-ws@5.0.0(ws@8.12.0): resolution: {integrity: sha512-muId7Zzn9ywDsyXgTIafTry2sV3nySZeUDe6YedVd1Hvuuep5AsIlqK+XefWpYTyJG5e503F2xIuT2lcU6rCSw==} @@ -3775,6 +3720,7 @@ packages: /merge-stream@2.0.0: resolution: {integrity: sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==} + dev: true /merge2@1.4.1: resolution: {integrity: sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==} @@ -3794,11 +3740,6 @@ packages: engines: {node: '>=6'} dev: true - /mimic-fn@4.0.0: - resolution: {integrity: sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw==} - engines: {node: '>=12'} - dev: false - /min-indent@1.0.1: resolution: {integrity: sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg==} engines: {node: '>=4'} @@ -3900,6 +3841,7 @@ packages: /ms@2.1.2: resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==} + dev: true /ms@2.1.3: resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==} @@ -3959,13 +3901,6 @@ packages: path-key: 3.1.1 dev: true - /npm-run-path@5.1.0: - resolution: {integrity: sha512-sJOdmRGrY2sjNTRMbSvluQqg+8X7ZK61yvzBEIDhz4f8z1TZFYABsqjjCBd/0PUNE9M6QDgHJXQkGUEm7Q+l9Q==} - engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} - dependencies: - path-key: 4.0.0 - dev: false - /object-assign@4.1.1: resolution: {integrity: sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==} engines: {node: '>=0.10.0'} @@ -4010,13 +3945,6 @@ packages: mimic-fn: 2.1.0 dev: true - /onetime@6.0.0: - resolution: {integrity: sha512-1FlR+gjXK7X+AsAHso35MnyN5KqGwJRi/31ft6x0M194ht7S+rWAvd7PHss9xSKMzE0asv1pyIHaJYq+BbacAQ==} - engines: {node: '>=12'} - dependencies: - mimic-fn: 4.0.0 - dev: false - /os-tmpdir@1.0.2: resolution: {integrity: sha512-D2FR03Vir7FIu45XBY20mTb+/ZSWB00sjU9jdQXt83gDrI4Ztz5Fs7/yy74g2N5SVQY4xY1qDr4rNddwYRVX0g==} engines: {node: '>=0.10.0'} @@ -4132,11 +4060,7 @@ packages: /path-key@3.1.1: resolution: {integrity: sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==} engines: {node: '>=8'} - - /path-key@4.0.0: - resolution: {integrity: sha512-haREypq7xkM7ErfgIyA0z+Bj4AGKlMSdlQE2jvJo6huWD1EdkKYV+G/T4nq0YEF2vgTT8kqMFKo1uHn950r4SQ==} - engines: {node: '>=12'} - dev: false + dev: true /path-parse@1.0.7: resolution: {integrity: sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==} @@ -4449,10 +4373,6 @@ packages: resolution: {integrity: sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==} dev: true - /requires-port@1.0.0: - resolution: {integrity: sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==} - dev: false - /resolve-from@5.0.0: resolution: {integrity: sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==} engines: {node: '>=8'} @@ -4649,6 +4569,7 @@ packages: engines: {node: '>=8'} dependencies: shebang-regex: 3.0.0 + dev: true /shebang-regex@1.0.0: resolution: {integrity: sha512-wpoSFAxys6b2a2wHZ1XpDSgD7N9iVjg29Ph9uV/uaP9Ex/KXlkTZTeddxDPSYQpgvzKLGJke2UU0AzoGCjNIvQ==} @@ -4658,6 +4579,7 @@ packages: /shebang-regex@3.0.0: resolution: {integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==} engines: {node: '>=8'} + dev: true /side-channel@1.0.4: resolution: {integrity: sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==} @@ -4673,6 +4595,7 @@ packages: /signal-exit@3.0.7: resolution: {integrity: sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==} + dev: true /slash@3.0.0: resolution: {integrity: sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==} @@ -4864,11 +4787,6 @@ packages: engines: {node: '>=6'} dev: true - /strip-final-newline@3.0.0: - resolution: {integrity: sha512-dOESqjYr96iWYylGObzd39EuNTa5VJxyvVAEm5Jnh7KGo75V43Hk1odPQkNDyXNmUR6k+gEiDVXnjB8HJ3crXw==} - engines: {node: '>=12'} - dev: false - /strip-hex-prefix@1.0.0: resolution: {integrity: sha512-q8d4ue7JGEiVcypji1bALTos+0pWtyGlivAWyPuTkHzuTCJqrK9sWxYQZUq6Nq3cuyv3bm734IhHvHtGGURU6A==} engines: {node: '>=6.5.0', npm: '>=3'} @@ -4926,6 +4844,7 @@ packages: engines: {node: '>=10'} dependencies: has-flag: 4.0.0 + dev: true /supports-preserve-symlinks-flag@1.0.0: resolution: {integrity: sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==} @@ -5432,6 +5351,7 @@ packages: hasBin: true dependencies: isexe: 2.0.0 + dev: true /why-is-node-running@2.2.2: resolution: {integrity: sha512-6tSwToZxTOcotxHeA+qGCq1mVzKR3CwcJGmVcY+QE8SHy6TnpFnh8PAvPNHYr7EcuVeG0QSMxtYCuO1ta/G/oA==} @@ -5507,19 +5427,6 @@ packages: optional: true dev: false - /ws@8.14.2: - resolution: {integrity: sha512-wEBG1ftX4jcglPxgFCMJmZ2PLtSbJ2Peg6TmpJFTbe9GZYOQCDPdMYu/Tm0/bGZkw8paZnJY45J4K2PZrLYq8g==} - engines: {node: '>=10.0.0'} - peerDependencies: - bufferutil: ^4.0.1 - utf-8-validate: '>=5.0.2' - peerDependenciesMeta: - bufferutil: - optional: true - utf-8-validate: - optional: true - dev: false - /y18n@4.0.3: resolution: {integrity: sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==} dev: true From 36e684f43c46f7595f2bbb978cc72c5955a230c4 Mon Sep 17 00:00:00 2001 From: Luiz Gustavo Abou Hatem De Liz Date: Mon, 2 Oct 2023 21:07:09 +0200 Subject: [PATCH 11/11] fixing lint errors --- examples/exit/weighted.ts | 13 +++++-------- examples/join/weighted.ts | 9 ++++----- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/examples/exit/weighted.ts b/examples/exit/weighted.ts index e7691dda..0f7e4a92 100644 --- a/examples/exit/weighted.ts +++ b/examples/exit/weighted.ts @@ -33,17 +33,14 @@ const slippage = Slippage.fromPercentage('1'); // 1% const exit = async () => { const balancerApi = new BalancerApi(balancerApiUrl, 1); const poolState: PoolStateInput = await balancerApi.pools.fetchPoolState(poolId); - let client: Client & PublicActions & TestActions & WalletActions; - let bpt: Token; - // setup BPT token - bpt = new Token(chainId, poolState.address, 18, 'BPT'); - client = createTestClient({ + const client: Client & PublicActions & TestActions & WalletActions = createTestClient({ mode: 'hardhat', chain: CHAINS[chainId], transport: http(rpcUrl), }) .extend(publicActions) .extend(walletActions); + const bpt = new Token(chainId, poolState.address, 18, 'BPT'); await forkSetup( client, @@ -72,7 +69,7 @@ const exit = async () => { const queryResult = await poolExit.query(exitInput, poolState); - const { call, to, value, maxBptIn, minAmountsOut } = + const { call, to, value } = poolExit.buildCall({ ...queryResult, slippage, @@ -88,8 +85,8 @@ const exit = async () => { call, value, ); - console.log("transaction status: " + transactionReceipt.status); - console.log("token amounts deltas per token: " + balanceDeltas); + console.log(`transaction status: ${transactionReceipt.status}`); + console.log(`token amounts deltas per token: ${balanceDeltas}`); } exit(); \ No newline at end of file diff --git a/examples/join/weighted.ts b/examples/join/weighted.ts index b1aed8f5..72d38c0e 100644 --- a/examples/join/weighted.ts +++ b/examples/join/weighted.ts @@ -35,8 +35,7 @@ const slippage = Slippage.fromPercentage('1'); // 1% const join = async () => { const balancerApi = new BalancerApi(balancerApiUrl, 1); const poolState: PoolStateInput = await balancerApi.pools.fetchPoolState(poolId); - let client: Client & PublicActions & TestActions & WalletActions; - client = createTestClient({ + const client: Client & PublicActions & TestActions & WalletActions = createTestClient({ mode: 'hardhat', chain: CHAINS[chainId], transport: http(rpcUrl), @@ -76,7 +75,7 @@ const join = async () => { const queryResult = await poolJoin.query(joinInput, poolState); - const { call, to, value, maxAmountsIn, minBptOut } = + const { call, to, value } = poolJoin.buildCall({ ...queryResult, slippage, @@ -92,8 +91,8 @@ const join = async () => { call, value, ); - console.log("transaction status: " + transactionReceipt.status); - console.log("token amounts deltas per token: " + balanceDeltas); + console.log(`transaction status: ${transactionReceipt.status}`); + console.log(`token amounts deltas per token: ${balanceDeltas}`); } join(); \ No newline at end of file