forked from balancer/balancer-exchange
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request balancer#57 from balancer-labs/develop
add tokens, updated maxBalancers
- Loading branch information
Showing
9 changed files
with
220 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { Web3Provider } from 'ethers/providers'; | ||
import { parsePoolDataOnChain } from '@balancer-labs/sor'; | ||
import { Pool } from '../stores/Proxy'; | ||
import { toChecksum } from './helpers'; | ||
import * as allPools from 'allPublicPools.json'; | ||
|
||
// Replicates Subgraph Subgraph getPoolsWithTokens retrieval using allPublicPools.json | ||
function getPoolsWithTokensBackup(tokenIn: string, tokenOut: string): any { | ||
let poolData = { pools: [] }; | ||
|
||
allPools.pools.forEach(p => { | ||
let tI: any = p.tokens.find( | ||
t => toChecksum(t.address) === toChecksum(tokenIn) | ||
); | ||
let tO: any = p.tokens.find( | ||
t => toChecksum(t.address) === toChecksum(tokenOut) | ||
); | ||
|
||
if (tI && tO && p.finalized) poolData.pools.push(p); | ||
}); | ||
|
||
return poolData; | ||
} | ||
|
||
export async function findPoolsWithTokensBackup( | ||
tokenIn: string, | ||
tokenOut: string, | ||
provider: Web3Provider, | ||
multiAddress: string | ||
): Promise<Pool[]> { | ||
const pools = getPoolsWithTokensBackup(tokenIn, tokenOut); | ||
|
||
let poolsWithTokens = await parsePoolDataOnChain( | ||
pools.pools, | ||
tokenIn, | ||
tokenOut, | ||
multiAddress, | ||
provider | ||
); | ||
|
||
let poolsWithBalances = []; | ||
|
||
// Current SOR doesn't return decimals or check balances so filter locally | ||
poolsWithTokens.forEach(pool => { | ||
if (pool.balanceIn.gt(0) && pool.balanceOut.gt(0)) { | ||
let subgraphPool = pools.pools.find( | ||
p => toChecksum(p.id) === toChecksum(pool.id) | ||
); | ||
|
||
let tI: any = subgraphPool.tokens.find( | ||
t => toChecksum(t.address) === toChecksum(tokenIn) | ||
); | ||
let tO: any = subgraphPool.tokens.find( | ||
t => toChecksum(t.address) === toChecksum(tokenOut) | ||
); | ||
|
||
let obj: Pool = { | ||
id: toChecksum(pool.id), | ||
decimalsIn: tI.decimals, | ||
decimalsOut: tO.decimals, | ||
balanceIn: pool.balanceIn, | ||
balanceOut: pool.balanceOut, | ||
weightIn: pool.weightIn, | ||
weightOut: pool.weightOut, | ||
swapFee: pool.swapFee, | ||
}; | ||
|
||
poolsWithBalances.push(obj); | ||
} | ||
}); | ||
|
||
return poolsWithBalances; | ||
} | ||
|
||
// Replicates Subgraph Subgraph getTokenPairs retrieval using allPublicPools.json | ||
export function getTokenPairsBackup(token: string): any { | ||
let poolData = { pools: [] }; | ||
|
||
allPools.pools.forEach(p => { | ||
if (p.publicSwap && p.finalized) { | ||
let tI: any = p.tokensList.find( | ||
t => toChecksum(t) === toChecksum(token) | ||
); | ||
|
||
if (tI) { | ||
poolData.pools.push({ tokensList: p.tokensList }); | ||
} | ||
} | ||
}); | ||
|
||
return poolData; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1025,10 +1025,10 @@ | |
lodash "^4.17.13" | ||
to-fast-properties "^2.0.0" | ||
|
||
"@balancer-labs/[email protected].4-5": | ||
version "0.2.4-5" | ||
resolved "https://registry.yarnpkg.com/@balancer-labs/sor/-/sor-0.2.4-5.tgz#63d47976c154a223ced29e3e0f60e0acd981cd3b" | ||
integrity sha512-nsli5CiskNs6wJDdytblQibgeMqtAgJCZW5Xnz2uc5Kkuxzu4AvKueV3CFLkNbqg8VnVmEPUtmYRfO9liCCjwQ== | ||
"@balancer-labs/sor@^0.2.8": | ||
version "0.2.8" | ||
resolved "https://registry.yarnpkg.com/@balancer-labs/sor/-/sor-0.2.8.tgz#bbff3627ea1d9faa74955dbb61f6e40359ebef09" | ||
integrity sha512-WIdlpOuf+V6aEs8S4M0LVcxHx0MXtSxCo2Z7acxHsS6sSwLMyhk80/om/OwZJ4L9+zmpiX5DoUlTcj7DM1Mc3w== | ||
dependencies: | ||
bignumber.js "^9.0.0" | ||
ethers "^4.0.39" | ||
|