Skip to content

Commit

Permalink
Merge pull request #155 from balancer-labs/develop
Browse files Browse the repository at this point in the history
Version 0.1.25
  • Loading branch information
gmbronco authored Sep 23, 2022
2 parents 2ad6c99 + c23b550 commit 162cea1
Show file tree
Hide file tree
Showing 44 changed files with 1,081 additions and 178 deletions.
4 changes: 3 additions & 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": "0.1.24",
"version": "0.1.25",
"description": "JavaScript SDK for interacting with the Balancer Protocol V2",
"license": "GPL-3.0-only",
"homepage": "https://github.com/balancer-labs/balancer-sdk/balancer-js#readme",
Expand Down Expand Up @@ -79,6 +79,7 @@
"rimraf": "^3.0.2",
"rollup": "^2.52.8",
"rollup-plugin-dts": "^3.0.2",
"rollup-plugin-terser": "^7.0.2",
"tiny-invariant": "^1.1.0",
"ts-mocha": "^9.0.2",
"ts-node": "^10.4.0",
Expand All @@ -92,6 +93,7 @@
"axios": "^0.24.0",
"graphql": "^15.6.1",
"graphql-request": "^3.5.0",
"json-to-graphql-query": "^2.2.4",
"lodash": "^4.17.21"
},
"peerDependencies": {
Expand Down
10 changes: 10 additions & 0 deletions balancer-js/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import typescript from '@rollup/plugin-typescript';
import { terser } from 'rollup-plugin-terser';
import dts from 'rollup-plugin-dts';
import pkg from './package.json';

Expand Down Expand Up @@ -31,6 +32,7 @@ export default [
'@balancer-labs/typechain': 'typechain',
'@ethersproject/providers': 'providers',
'graphql-request': 'graphqlRequest',
'json-to-graphql-query': 'jsonToGraphqlQuery',
graphql: 'graphql',
lodash: 'lodash',
axios: 'axios',
Expand All @@ -46,6 +48,14 @@ export default [
typescript({
exclude: ['node_modules', '**/*.spec.ts'],
}),
terser({
format: {
comments: false
},
compress: {
pure_funcs: ['console.log', 'console.time', 'console.timeEnd']
}
}),
],
external,
},
Expand Down
1 change: 1 addition & 0 deletions balancer-js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export * from './pool-weighted';
export * from './pool-composable-stable';
export * from './pool-utils';
export * from './lib/utils';
export * from './lib/graphql';
export * from './types';
export * from './modules/swaps/types';
export * from './modules/swaps/helpers';
Expand Down
30 changes: 1 addition & 29 deletions balancer-js/src/lib/constants/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,9 @@ export const BALANCER_NETWORK_CONFIG: Record<Network, BalancerNetworkConfig> = {
contracts: {
vault: '0xBA12222222228d8Ba445958a75a0704d566BF2C8',
multicall: '0xa1B2b503959aedD81512C37e9dce48164ec6a94d',
gaugeController: '',
feeDistributor: '',
},
tokens: {
wrappedNativeAsset: '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270',
bal: '',
veBal: '',
bbaUsd: '',
},
},
urls: {
Expand All @@ -75,14 +70,9 @@ export const BALANCER_NETWORK_CONFIG: Record<Network, BalancerNetworkConfig> = {
contracts: {
vault: '0xBA12222222228d8Ba445958a75a0704d566BF2C8',
multicall: '0x269ff446d9892c9e19082564df3f5e8741e190a1',
gaugeController: '',
feeDistributor: '',
},
tokens: {
wrappedNativeAsset: '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1',
bal: '',
veBal: '',
bbaUsd: '',
},
},
urls: {
Expand All @@ -101,14 +91,9 @@ export const BALANCER_NETWORK_CONFIG: Record<Network, BalancerNetworkConfig> = {
contracts: {
vault: '0xBA12222222228d8Ba445958a75a0704d566BF2C8',
multicall: '0x2cc8688C5f75E365aaEEb4ea8D6a480405A48D2A',
gaugeController: '',
feeDistributor: '',
},
tokens: {
wrappedNativeAsset: '0xdFCeA9088c8A88A76FF74892C1457C17dfeef9C1',
bal: '',
veBal: '',
bbaUsd: '',
},
},
urls: {
Expand All @@ -125,14 +110,9 @@ export const BALANCER_NETWORK_CONFIG: Record<Network, BalancerNetworkConfig> = {
contracts: {
vault: '0xBA12222222228d8Ba445958a75a0704d566BF2C8',
multicall: '0x53c43764255c17bd724f74c4ef150724ac50a3ed',
gaugeController: '',
feeDistributor: '',
},
tokens: {
wrappedNativeAsset: '0xdFCeA9088c8A88A76FF74892C1457C17dfeef9C1',
bal: '',
veBal: '',
bbaUsd: '',
},
},
urls: {
Expand All @@ -148,14 +128,9 @@ export const BALANCER_NETWORK_CONFIG: Record<Network, BalancerNetworkConfig> = {
contracts: {
vault: '0xBA12222222228d8Ba445958a75a0704d566BF2C8',
multicall: '0x42ad527de7d4e9d9d011ac45b31d8551f8fe9821',
gaugeController: '',
feeDistributor: '',
},
tokens: {
wrappedNativeAsset: '0xdFCeA9088c8A88A76FF74892C1457C17dfeef9C1',
bal: '',
veBal: '',
bbaUsd: '',
},
},
urls: {
Expand All @@ -173,13 +148,9 @@ export const BALANCER_NETWORK_CONFIG: Record<Network, BalancerNetworkConfig> = {
vault: '0xBA12222222228d8Ba445958a75a0704d566BF2C8',
multicall: '0x77dCa2C955b15e9dE4dbBCf1246B4B85b651e50e',
gaugeController: '0xBB1CE49b16d55A1f2c6e88102f32144C7334B116',
feeDistributor: '',
},
tokens: {
wrappedNativeAsset: '0xdFCeA9088c8A88A76FF74892C1457C17dfeef9C1',
bal: '',
veBal: '',
bbaUsd: '',
},
},
urls: {
Expand All @@ -206,6 +177,7 @@ export const BALANCER_NETWORK_CONFIG: Record<Network, BalancerNetworkConfig> = {
urls: {
subgraph:
'https://api.thegraph.com/subgraphs/name/beethovenxfi/beethovenx-optimism',
gaugesSubgraph: '',
},
pools: {},
},
Expand Down
200 changes: 200 additions & 0 deletions balancer-js/src/lib/graphql/args-builder.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
import { expect } from 'chai';
import {
BalancerAPIArgsFormatter,
GraphQLArgsBuilder,
SubgraphArgsFormatter,
} from './args-builder';

describe('Pool Query', () => {
it('should be able to assemble a query for the subgraph', () => {
const query = new GraphQLArgsBuilder({
first: 10,
skip: 0,
orderBy: 'totalLiquidity',
orderDirection: 'desc',
where: {
totalShares: {
gt: 0.01,
},
id: {
not_in: ['0xBAD', '0xDEF'],
},
tokensList: {
contains: ['0xBAL'],
},
poolType: {
not_in: ['Linear'],
},
},
});

const expectedSubgraphQuery = {
first: 10,
skip: 0,
orderBy: 'totalLiquidity',
orderDirection: 'desc',
where: {
totalShares_gt: 0.01,
id_not_in: ['0xBAD', '0xDEF'],
tokensList_contains: ['0xBAL'],
poolType_not_in: ['Linear'],
},
};

const result = query.format(new SubgraphArgsFormatter());
expect(result).to.deep.equal(expectedSubgraphQuery);
});

it('should be able to assemble a query for the Balancer API', () => {
const query = new GraphQLArgsBuilder({
first: 10,
skip: 0,
orderBy: 'totalLiquidity',
orderDirection: 'desc',
where: {
totalShares: {
gt: 0.01,
},
id: {
not_in: ['0xBAD', '0xDEF'],
},
tokensList: {
contains: ['0xBAL'],
},
poolType: {
not_in: ['Linear'],
},
},
});

const expectedSubgraphQuery = {
first: 10,
skip: 0,
orderBy: 'totalLiquidity',
orderDirection: 'desc',
where: {
totalShares: {
gt: 0.01,
},
id: {
not_in: ['0xBAD', '0xDEF'],
},
tokensList: {
contains: ['0xBAL'],
},
poolType: {
not_in: ['Linear'],
},
},
};

const result = query.format(new BalancerAPIArgsFormatter());
expect(result).to.deep.equal(expectedSubgraphQuery);
});

describe('merge', () => {
it('Should merge both query arguments into one', () => {
const query = new GraphQLArgsBuilder({
first: 10,
orderBy: 'totalLiquidity',
where: {
totalShares: {
gt: 0.01,
},
id: {
not_in: ['0xBAD', '0xDEF'],
},
},
});

const queryToMerge = new GraphQLArgsBuilder({
skip: 20,
orderDirection: 'asc',
where: {
tokensList: {
contains: ['0xBAL'],
},
poolType: {
not_in: ['Linear'],
},
},
});

const expectedMergedQuery = new GraphQLArgsBuilder({
first: 10,
orderBy: 'totalLiquidity',
skip: 20,
orderDirection: 'asc',
where: {
totalShares: {
gt: 0.01,
},
id: {
not_in: ['0xBAD', '0xDEF'],
},
tokensList: {
contains: ['0xBAL'],
},
poolType: {
not_in: ['Linear'],
},
},
});

const mergedQuery = query.merge(queryToMerge);

expect(mergedQuery).to.deep.equal(expectedMergedQuery);
});

it('Should overwrite query arguments from the query being merged in, and merge arrays', () => {
const query = new GraphQLArgsBuilder({
first: 10,
orderBy: 'totalLiquidity',
orderDirection: 'desc',
where: {
totalShares: {
gt: 0.01,
},
id: {
not_in: ['0xBAD', '0xDEF'],
},
},
});

const queryToMerge = new GraphQLArgsBuilder({
first: 20,
orderBy: 'totalShares',
orderDirection: 'asc',
where: {
tokensList: {
contains: ['0xBAL'],
},
id: {
not_in: ['0xNEW'],
},
},
});

const expectedMergedQuery = new GraphQLArgsBuilder({
first: 20,
orderBy: 'totalShares',
orderDirection: 'asc',
where: {
totalShares: {
gt: 0.01,
},
tokensList: {
contains: ['0xBAL'],
},
id: {
not_in: ['0xBAD', '0xDEF', '0xNEW'],
},
},
});

const mergedQuery = query.merge(queryToMerge);

expect(mergedQuery).to.deep.equal(expectedMergedQuery);
});
});
});
26 changes: 26 additions & 0 deletions balancer-js/src/lib/graphql/args-builder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { mergeWith } from 'lodash';
import { GraphQLArgs, GraphQLArgsFormatter } from './types';

export * from './formatters';

export class GraphQLArgsBuilder {
constructor(readonly args: GraphQLArgs) {}

merge(other: GraphQLArgsBuilder): GraphQLArgsBuilder {
const mergedArgs = mergeWith(
this.args,
other.args,
(objValue: unknown, srcValue: unknown) => {
if (Array.isArray(objValue)) {
return objValue.concat(srcValue);
}
}
);

return new GraphQLArgsBuilder(mergedArgs);
}

format(formatter: GraphQLArgsFormatter): unknown {
return formatter.format(this.args);
}
}
7 changes: 7 additions & 0 deletions balancer-js/src/lib/graphql/formatters/balancer-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { GraphQLArgs, GraphQLArgsFormatter } from '../types';

export class BalancerAPIArgsFormatter implements GraphQLArgsFormatter {
format(args: GraphQLArgs): GraphQLArgs {
return args;
}
}
2 changes: 2 additions & 0 deletions balancer-js/src/lib/graphql/formatters/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './balancer-api';
export * from './subgraph';
Loading

0 comments on commit 162cea1

Please sign in to comment.