Skip to content

Commit

Permalink
Merge pull request #538 from balancer/develop
Browse files Browse the repository at this point in the history
Release 1.1.5
  • Loading branch information
johngrantuk committed Sep 26, 2023
2 parents fad3b49 + 3059111 commit b0fe922
Show file tree
Hide file tree
Showing 21 changed files with 937 additions and 41 deletions.
102 changes: 102 additions & 0 deletions balancer-js/examples/data/onchain-multicall3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import {
PoolsSubgraphRepository,
SubgraphPoolBase,
Network,
BALANCER_NETWORK_CONFIG,
getOnChainBalances as getOnChainBalances3,
} from '@balancer-labs/sdk';
import { JsonRpcProvider } from '@ethersproject/providers';
// import _ from 'lodash';

// Importing legacy multicall fetcher for comparison
// import { getOnChainBalances } from '@/modules/sor/pool-data/onChainData';

const network = Network.POLYGON;

const pools = new PoolsSubgraphRepository({
url: BALANCER_NETWORK_CONFIG[network].urls.subgraph,
chainId: network,
query: {
args: {
first: 10,
skip: 0,
orderBy: 'totalLiquidity',
orderDirection: 'desc',
where: {
poolType: {
eq: 'GyroE',
},
},
},
attrs: {},
},
});

const providers: Record<number, JsonRpcProvider> = {
[Network.MAINNET]: new JsonRpcProvider('https://rpc.ankr.com/eth'),
[Network.POLYGON]: new JsonRpcProvider('https://rpc.ankr.com/polygon'),
[Network.ARBITRUM]: new JsonRpcProvider('https://rpc.ankr.com/arbitrum'),
[Network.OPTIMISM]: new JsonRpcProvider('https://rpc.ankr.com/optimism'),
[Network.BASE]: new JsonRpcProvider('https://rpc.ankr.com/base'),
[Network.FANTOM]: new JsonRpcProvider('https://rpc.ankr.com/fantom'),
[Network.ZKEVM]: new JsonRpcProvider('https://rpc.ankr.com/polygon_zkevm'),
};

const provider = providers[network];

/**
* Recursively finds differences between two objects. Use to compare onchain data from 2 different fetchers.
*/
// function diffObjects(
// object1: any,
// object2: any,
// path = ''
// ): any {
// const allKeys = _.union(Object.keys(object1), Object.keys(object2));

// const differences = [];

// for (const key of allKeys) {
// const newPath = path ? `${path}.${key}` : key;

// if (_.isObject(object1[key]) && _.isObject(object2[key])) {
// differences.push(...diffObjects(object1[key], object2[key], newPath));
// } else if (!_.isEqual(object1[key], object2[key])) {
// differences.push({
// path: newPath,
// value1: object1[key],
// value2: object2[key],
// });
// }
// }

// return differences;
// }

async function main() {
const subgraph = (await pools.fetch()) as SubgraphPoolBase[];
const onchain3 = await getOnChainBalances3(
subgraph,
'',
'0xBA12222222228d8Ba445958a75a0704d566BF2C8',
provider
);
console.log(onchain3.length);
console.log(JSON.stringify(onchain3, null, 2));
// const onchain = await getOnChainBalances(subgraph, '0xeefba1e63905ef1d7acba5a8513c70307c1ce441', '0xBA12222222228d8Ba445958a75a0704d566BF2C8', provider);
// console.log(onchain.length)
// for(const i in subgraph) {
// const one = onchain3.find((x) => x.id === subgraph[i].id)
// const two = onchain.find((x) => x.id === subgraph[i].id)
// console.log('Pool', subgraph[i].id)
// if (!two) {
// console.log('two missing')
// continue
// }
// console.log(JSON.stringify(findNestedValueDifferences(one, two), null, 2));
// }
}

main();

// yarn example ./debug/onchain-multicall3.ts
11 changes: 6 additions & 5 deletions balancer-js/examples/swaps/advanced.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Run command:
* yarn example ./examples/swaps/advanced.ts
*/
import { FORK_NODES } from '@/test/lib/utils';
import {
BalancerSDK,
Network,
Expand Down Expand Up @@ -119,12 +120,12 @@ async function getAndProcessSwaps(
}

async function swapExample() {
const network = Network.POLYGON;
const rpcUrl = 'https://rpc.ankr.com/polygon';
const tokenIn = '0x3A58a54C066FdC0f2D55FC9C89F0415C92eBf3C4'; // stMatic
const tokenOut = AddressZero; // Matic
const network = Network.GNOSIS;
const rpcUrl = FORK_NODES[network];
const tokenIn = '0xe91d153e0b41518a2ce8dd3d7944fa863463a97d';
const tokenOut = '0x6A023CCd1ff6F2045C3309768eAd9E68F978f6e1';
const swapType = SwapTypes.SwapExactIn;
const amount = parseFixed('20', 18);
const amount = parseFixed('20000', 18);
// Currently Relayer only suitable for ExactIn and non-eth swaps
const canUseJoinExitPaths = canUseJoinExit(swapType, tokenIn, tokenOut);

Expand Down
2 changes: 1 addition & 1 deletion balancer-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@balancer-labs/sdk",
"version": "1.1.4",
"version": "1.1.5",
"description": "JavaScript SDK for interacting with the Balancer Protocol V2",
"license": "GPL-3.0-only",
"homepage": "https://github.com/balancer-labs/balancer-sdk#readme",
Expand Down
Loading

0 comments on commit b0fe922

Please sign in to comment.