Skip to content

Commit

Permalink
Merge pull request #101 from balancer/replace-onchainPoolData
Browse files Browse the repository at this point in the history
Replace dataQueries with multicallV3 (with batching)
  • Loading branch information
johngrantuk authored Oct 12, 2023
2 parents b1ed9e4 + 4fdfb72 commit 558ffc0
Show file tree
Hide file tree
Showing 18 changed files with 1,206 additions and 1,019 deletions.
5 changes: 5 additions & 0 deletions .changeset/eleven-trains-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@balancer/sdk": minor
---

Add Fantom config. Update to have network specific vault addr.
10 changes: 10 additions & 0 deletions .changeset/few-mayflies-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@balancer/sdk": minor
---

Replace dataQueries with multicall (using Viem):

- Add `BATCHSIZE` config per network
- Onchain calls correctly mapped to pool/version
- Filter bricked pools from vulnerability
- Fix scalingFactor scaling
1 change: 1 addition & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ jobs:
env:
ETHEREUM_RPC_URL: ${{ secrets.ETHEREUM_RPC_URL }}
POLYGON_RPC_URL: ${{ secrets.POLYGON_RPC_URL }}
FANTOM_RPC_URL: ${{ secrets.FANTOM_RPC_URL }}

build:
name: Build
Expand Down
59 changes: 59 additions & 0 deletions debug/multicall.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// bun run debug/multicall.ts
import {
OnChainPoolDataEnricher,
BATCHSIZE,
ProviderSwapOptions,
VAULT,
} from '../src';
// rome-ignore lint/correctness/noUnusedVariables: <this is a test file>
import { mainnet, polygonZkEvm } from 'viem/chains';

const chain = polygonZkEvm;
const rpc = 'https://rpc.ankr.com/polygon_zkevm';

const poolsQuery = `{
pools(first: 10, orderBy: id, orderDirection: desc, where: { totalShares_gt: 0, poolType_contains: "ComposableStable" }) {
id
address
poolType
wrappedIndex
tokens {
address
decimals
index
}
}
}`;

const pools = await fetch(
'https://api.studio.thegraph.com/query/24660/balancer-polygon-zk-v2/version/latest',
// 'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-v2',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ query: poolsQuery }),
},
)
.then((res) => res.json())
.then((res) => res.data);

const onChainEnricher = new OnChainPoolDataEnricher(
chain.id,
rpc,
BATCHSIZE[chain.id],
VAULT[chain.id],
);
// const blockNumber =
const providerOptions: ProviderSwapOptions = {
// block: blockNumber,
timestamp: BigInt(Date.now()),
};
const data = await onChainEnricher.fetchAdditionalPoolData(
pools,
providerOptions,
);
const enriched = onChainEnricher.enrichPoolsWithData(pools.pools, data);

console.log(enriched, data.length);
Loading

0 comments on commit 558ffc0

Please sign in to comment.