-
Notifications
You must be signed in to change notification settings - Fork 93
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 #262 from balancer-labs/develop
Release 0.1.44
- Loading branch information
Showing
34 changed files
with
391 additions
and
92 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Display weekly BAL emissiosn for a pool | ||
* Run command: yarn examples:run ./examples/pools/emissions.ts | ||
*/ | ||
import { BalancerSDK } from '@/.' | ||
|
||
const sdk = new BalancerSDK({ | ||
network: 1, | ||
rpcUrl: 'https://rpc.ankr.com/eth', | ||
}) | ||
|
||
const { pools } = sdk | ||
|
||
const main = async () => { | ||
if (pools.emissionsService) { | ||
const emissions = await pools.emissionsService.weekly('0x334c96d792e4b26b841d28f53235281cec1be1f200020000000000000000038a') | ||
console.log(emissions) | ||
} | ||
} | ||
|
||
main() |
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 |
---|---|---|
|
@@ -6,6 +6,7 @@ export enum Network { | |
GÖRLI = 5, | ||
OPTIMISM = 10, | ||
KOVAN = 42, | ||
GNOSIS = 100, | ||
POLYGON = 137, | ||
ARBITRUM = 42161, | ||
} |
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,112 @@ | ||
import { Findable, Searchable } from '../types'; | ||
import { Provider } from '@ethersproject/providers'; | ||
import { PoolAttribute, PoolsRepositoryFetchOptions } from './types'; | ||
import { GraphQLQuery, Pool } from '@/types'; | ||
import { Network } from '@/lib/constants/network'; | ||
import { getOnChainBalances } from '../../../modules/sor/pool-data/onChainData'; | ||
import { PoolsSubgraphRepository } from './subgraph'; | ||
|
||
interface PoolsSubgraphOnChainRepositoryOptions { | ||
url: string; | ||
chainId: Network; | ||
provider: Provider; | ||
multicall: string; | ||
vault: string; | ||
blockHeight?: () => Promise<number | undefined>; | ||
query?: GraphQLQuery; | ||
} | ||
|
||
/** | ||
* Access pools using generated subgraph client and multicall. | ||
*/ | ||
export class PoolsSubgraphOnChainRepository | ||
implements Findable<Pool, PoolAttribute>, Searchable<Pool> | ||
{ | ||
private poolsSubgraph: PoolsSubgraphRepository; | ||
private provider: Provider; | ||
private pools?: Promise<Pool[]>; | ||
private multicall: string; | ||
private vault: string; | ||
public skip = 0; | ||
|
||
/** | ||
* Repository using multicall to get onchain data. | ||
* | ||
* @param url subgraph URL | ||
* @param chainId current network, needed for L2s logic | ||
* @param blockHeight lazy loading blockHeigh resolver | ||
* @param multicall multicall address | ||
* @param valt vault address | ||
*/ | ||
constructor(options: PoolsSubgraphOnChainRepositoryOptions) { | ||
this.poolsSubgraph = new PoolsSubgraphRepository({ | ||
url: options.url, | ||
chainId: options.chainId, | ||
blockHeight: options.blockHeight, | ||
query: options.query, | ||
}); | ||
this.provider = options.provider; | ||
this.multicall = options.multicall; | ||
this.vault = options.vault; | ||
} | ||
|
||
/** | ||
* We need a list of all the pools, for calculating APRs (nested pools), and for SOR (path finding). | ||
* All the pools are fetched on page load and cachced for speedy lookups. | ||
* | ||
* @returns Promise resolving to pools list | ||
*/ | ||
private async fetchDefault(): Promise<Pool[]> { | ||
console.time('fetching pools SG'); | ||
const pools = await this.poolsSubgraph.fetch(); | ||
console.timeEnd('fetching pools SG'); | ||
console.time('fetching pools onchain'); | ||
const onchainPools = await getOnChainBalances( | ||
pools, | ||
this.multicall, | ||
this.vault, | ||
this.provider | ||
); | ||
console.timeEnd('fetching pools onchain'); | ||
|
||
return onchainPools; | ||
} | ||
|
||
async fetch(options?: PoolsRepositoryFetchOptions): Promise<Pool[]> { | ||
const pools = await this.poolsSubgraph.fetch(options); | ||
const onchainPools = await getOnChainBalances( | ||
pools, | ||
this.multicall, | ||
this.vault, | ||
this.provider | ||
); | ||
return onchainPools; | ||
} | ||
|
||
async find(id: string): Promise<Pool | undefined> { | ||
return await this.findBy('id', id); | ||
} | ||
|
||
async findBy(param: PoolAttribute, value: string): Promise<Pool | undefined> { | ||
if (!this.pools) { | ||
this.pools = this.fetchDefault(); | ||
} | ||
|
||
return (await this.pools).find((pool) => pool[param] == value); | ||
} | ||
|
||
async all(): Promise<Pool[]> { | ||
if (!this.pools) { | ||
this.pools = this.fetchDefault(); | ||
} | ||
return this.pools; | ||
} | ||
|
||
async where(filter: (pool: Pool) => boolean): Promise<Pool[]> { | ||
if (!this.pools) { | ||
this.pools = this.fetchDefault(); | ||
} | ||
|
||
return (await this.pools).filter(filter); | ||
} | ||
} |
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
Oops, something went wrong.