Skip to content

Commit

Permalink
Merge pull request #93 from balancer-labs/develop
Browse files Browse the repository at this point in the history
Release 0.1.13
  • Loading branch information
johngrantuk committed Jun 14, 2022
2 parents 6cd88df + d844918 commit 0ef463f
Show file tree
Hide file tree
Showing 47 changed files with 13,936 additions and 1,561 deletions.
4 changes: 4 additions & 0 deletions balancer-js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ const swaps = new swapService({
});
```

## Examples

You can run each example with `npm run examples:run -- examples/exampleName.ts`

### #queryBatchSwap

The Balancer Vault provides a [method to simulate a call to batchSwap](https://github.com/balancer-labs/balancer-v2-monorepo/blob/master/pkg/vault/contracts/interfaces/IVault.sol#L644).
Expand Down
20 changes: 20 additions & 0 deletions balancer-js/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Start frontend referencing SDK in development:
# yarn build
# FRONTEND_DIR=$(pwd)/../../frontend-v2 docker-compose up

version: "3.7"

services:
web:
build:
context: ${FRONTEND_DIR}
dockerfile: Dockerfile.dev
restart: always
command: npm run serve
volumes:
- ${FRONTEND_DIR}:/app
- ./:/app/node_modules/@balancer-labs/sdk/
ports:
- 8080:8080
env_file:
- ${FRONTEND_DIR}/.env.development
81 changes: 81 additions & 0 deletions balancer-js/examples/pools/calculateLiquidity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import {
Liquidity,
StaticPoolProvider,
StaticTokenPriceProvider,
Pool,
TokenPrices,
} from '../../src';
import { parseFixed, formatFixed } from '@ethersproject/bignumber';
import { FallbackPoolProvider } from '../../src/modules/data-providers/pool/fallback.provider';
import POOLS from './pools.json';
import DECORATED_POOLS from './decorated-pools.json';
import TOKENS from './tokens.json';

const tokenPrices: TokenPrices = {};
TOKENS.forEach((token) => {
// Strip price down to max 18 decimals.
if (token.price) {
const tokenPriceMatch = token.price.match(/[0-9]+\.[0-9]{0,18}/);
const tokenPrice = tokenPriceMatch ? tokenPriceMatch[0] : '';
const priceInETH = formatFixed(
parseFixed('1', 36).div(parseFixed(tokenPrice, 18)),
18
);
tokenPrices[token.address] = {
eth: priceInETH,
};
}
});

// const sorPoolProvider = new SORPoolProvider(config);
const staticPoolProvider = new StaticPoolProvider(POOLS as Pool[]);
const poolProvider = new FallbackPoolProvider([
// sorPoolProvider,
staticPoolProvider,
]);
const tokenPriceProvider = new StaticTokenPriceProvider(tokenPrices);

const liquidity = new Liquidity(poolProvider, tokenPriceProvider);

const poolIds = [
'0x32296969ef14eb0c6d29669c550d4a0449130230000200000000000000000080',
'0x7b50775383d3d6f0215a8f290f2c9e2eebbeceb20000000000000000000000fe',
'0x06df3b2bbb68adc8b0e302443692037ed9f91b42000000000000000000000063',
'0xa6f548df93de924d73be7d25dc02554c6bd66db500020000000000000000000e',
'0x96646936b91d6b9d7d0c47c496afbf3d6ec7b6f8000200000000000000000019',
'0x5c6ee304399dbdb9c8ef030ab642b10820db8f56000200000000000000000014',
'0x90291319f1d4ea3ad4db0dd8fe9e12baf749e84500020000000000000000013c',
'0x186084ff790c65088ba694df11758fae4943ee9e000200000000000000000013',
'0xf4c0dd9b82da36c07605df83c8a416f11724d88b000200000000000000000026',
'0x0b09dea16768f0799065c475be02919503cb2a3500020000000000000000001a',
];

const staticPools: Record<string, any> = {};
poolIds.forEach((poolId) => {
staticPools[poolId] = POOLS.find((p) => p.id === poolId);
});

async function getLiquidity(poolIds: string[]) {
for (const poolId of poolIds) {
const pool = await poolProvider.find(poolId);
if (!pool) {
console.error('Could not find pool: ' + poolId);
continue;
}

const totalLiquidity = await liquidity.getLiquidity(pool);
const decoratedPool = DECORATED_POOLS.find((p) => p.id == pool.id);

console.log(
`Pool: ${pool.id} - ${staticPools[poolId].symbol} - ${pool.poolType}`
);
console.log('Calculated liquidity: \t\t', totalLiquidity);
console.log('Pool Liqudidity: \t\t', staticPools[poolId].totalLiquidity);
console.log('Decorated Pool Liqudity: \t', decoratedPool?.totalLiquidity);
console.log('---');
}

process.exit(0);
}

getLiquidity(poolIds);
Loading

0 comments on commit 0ef463f

Please sign in to comment.