Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

feat: Balancer v2 to studio #318

Merged
merged 5 commits into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/apps/balancer-v2/arbitrum/balancer-v2.balance-fetcher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Inject } from '@nestjs/common';

import { TokenBalanceHelper } from '~app-toolkit';
import { Register } from '~app-toolkit/decorators';
import { presentBalanceFetcherResponse } from '~app-toolkit/helpers/presentation/balance-fetcher-response.present';
import { BalanceFetcher } from '~balance/balance-fetcher.interface';
import { Network } from '~types/network.interface';

import { BALANCER_V2_DEFINITION } from '../balancer-v2.definition';
import { BalancerV2ClaimableContractPositionBalanceHelper } from '../helpers/balancer-v2.claimable.contract-position-balance-helper';

const appId = BALANCER_V2_DEFINITION.id;
const network = Network.ARBITRUM_MAINNET;

@Register.BalanceFetcher(appId, network)
export class ArbitrumBalancerV2BalanceFetcher implements BalanceFetcher {
constructor(
@Inject(TokenBalanceHelper) private readonly tokenBalanceHelper: TokenBalanceHelper,
@Inject(BalancerV2ClaimableContractPositionBalanceHelper)
private readonly balancerV2ClaimableContractPositionBalanceHelper: BalancerV2ClaimableContractPositionBalanceHelper,
) {}

async getPoolBalances(address: string) {
return this.tokenBalanceHelper.getTokenBalances({
address,
network,
appId,
groupId: BALANCER_V2_DEFINITION.groups.pool.id,
});
}

async getClaimableBalances(address: string) {
return this.balancerV2ClaimableContractPositionBalanceHelper.getContractPositionBalances({
address,
network,
});
}

async getBalances(address: string) {
const [poolBalances, claimableBalances] = await Promise.all([
this.getPoolBalances(address),
this.getClaimableBalances(address),
]);

return presentBalanceFetcherResponse([
{
label: 'Pools',
assets: poolBalances,
},
{
label: 'Claimable',
assets: claimableBalances,
},
]);
}
}
35 changes: 35 additions & 0 deletions src/apps/balancer-v2/arbitrum/balancer-v2.pool.token-fetcher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Inject } from '@nestjs/common';

import { Register } from '~app-toolkit/decorators';
import { PositionFetcher } from '~position/position-fetcher.interface';
import { AppTokenPosition } from '~position/position.interface';
import { Network } from '~types/network.interface';

import { BALANCER_V2_DEFINITION } from '../balancer-v2.definition';
import { BalancerV2PoolTokensHelper } from '../helpers/balancer-v2.pool.token-helper';
import { BalancerV2TheGraphPoolTokenDataStrategy } from '../helpers/balancer-v2.the-graph.pool-token-address-strategy';

const appId = BALANCER_V2_DEFINITION.id;
const groupId = BALANCER_V2_DEFINITION.groups.pool.id;
const network = Network.ARBITRUM_MAINNET;

@Register.TokenPositionFetcher({ appId, groupId, network })
export class ArbitrumBalancerV2PoolTokenFetcher implements PositionFetcher<AppTokenPosition> {
constructor(
@Inject(BalancerV2PoolTokensHelper) private readonly poolTokensHelper: BalancerV2PoolTokensHelper,
@Inject(BalancerV2TheGraphPoolTokenDataStrategy)
private readonly balancerV2TheGraphPoolTokenDataStrategy: BalancerV2TheGraphPoolTokenDataStrategy,
) {}

getPositions() {
return this.poolTokensHelper.getTokenMarketData({
network,
appId,
groupId,
vaultAddress: '0xba12222222228d8ba445958a75a0704d566bf2c8',
resolvePoolTokenAddresses: this.balancerV2TheGraphPoolTokenDataStrategy.build({
subgraphUrl: 'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-arbitrum-v2',
}),
});
}
}
Binary file added src/apps/balancer-v2/assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
105 changes: 105 additions & 0 deletions src/apps/balancer-v2/balancer-v2.claimables.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { Network } from '~types/network.interface';

export type ClaimableTokenConfig = {
label: string;
network: Network;
legacyMerkleRedeemAddress?: string;
distributorAddress?: string;
merkleOrchardAddress?: string;
rewardTokenAddress: string;
manifestUrl: string;
weekStart?: number;
};

export const BALANCER_V2_CLAIMABLE_CONFIG: ClaimableTokenConfig[] = [
// Ethereum
{
label: 'BAL',
network: Network.ETHEREUM_MAINNET,
distributorAddress: '0xd2eb7bd802a7ca68d9acd209bec4e664a9abdd7b',
legacyMerkleRedeemAddress: '0x6d19b2bf3a36a61530909ae65445a906d98a2fa8',
merkleOrchardAddress: '0xdae7e32adc5d490a43ccba1f0c736033f2b4efca',
rewardTokenAddress: '0xba100000625a3754423978a60c9317c58a424e3d',
manifestUrl: 'https://raw.githubusercontent.com/balancer-labs/bal-mining-scripts/master/reports/_current.json',
weekStart: 52,
},
{
label: 'UNN',
network: Network.ETHEREUM_MAINNET,
distributorAddress: '0xbfbd6e720ffdf0497f69c95e5c03a4861c65a6e7',
merkleOrchardAddress: '0xdae7e32adc5d490a43ccba1f0c736033f2b4efca',
rewardTokenAddress: '0x226f7b842e0f0120b7e194d05432b3fd14773a9d',
manifestUrl:
'https://raw.githubusercontent.com/balancer-labs/bal-mining-scripts/master/reports/_current-union.json',
weekStart: 1,
},
{
label: 'BANK',
network: Network.ETHEREUM_MAINNET,
distributorAddress: '0x9d20fe66ec5dd15a3d3213556534c77ca20318be',
merkleOrchardAddress: '0xdae7e32adc5d490a43ccba1f0c736033f2b4efca',
rewardTokenAddress: '0x2d94aa3e47d9d5024503ca8491fce9a2fb4da198',
manifestUrl:
'https://raw.githubusercontent.com/balancer-labs/bal-mining-scripts/master/reports/_current-bankless.json',
weekStart: 1,
},
{
label: 'LIDO',
network: Network.ETHEREUM_MAINNET,
legacyMerkleRedeemAddress: '0x884226c9f7b7205f607922e0431419276a64cf8f',
rewardTokenAddress: '0x5a98fcbea516cf06857215779fd812ca3bef1b32',
manifestUrl: 'https://raw.githubusercontent.com/balancer-labs/bal-mining-scripts/master/reports/_current-lido.json',
},
{
label: 'VITA',
network: Network.ETHEREUM_MAINNET,
legacyMerkleRedeemAddress: '0x575bff0aca7638c573bc57bb7c91b5bdfe2462c8',
rewardTokenAddress: '0x81f8f0bb1cb2a06649e51913a151f0e7ef6fa321',
manifestUrl: 'https://raw.githubusercontent.com/balancer-labs/bal-mining-scripts/master/reports/_current-vita.json',
},
// Polygon
{
label: 'BAL',
network: Network.POLYGON_MAINNET,
distributorAddress: '0xd2eb7bd802a7ca68d9acd209bec4e664a9abdd7b',
merkleOrchardAddress: '0x0f3e0c4218b7b0108a3643cfe9d3ec0d4f57c54e',
rewardTokenAddress: '0x9a71012b13ca4d3d0cdc72a177df3ef03b0e76a3',
manifestUrl:
'https://raw.githubusercontent.com/balancer-labs/bal-mining-scripts/master/reports/_current-polygon.json',
weekStart: 1,
},
// Arbitrum
{
label: 'BAL',
network: Network.ARBITRUM_MAINNET,
legacyMerkleRedeemAddress: '0x6bd0b17713aaa29a2d7c9a39ddc120114f9fd809',
distributorAddress: '0xd2eb7bd802a7ca68d9acd209bec4e664a9abdd7b',
merkleOrchardAddress: '0x751a0bc0e3f75b38e01cf25bfce7ff36de1c87de',
rewardTokenAddress: '0x040d1edc9569d4bab2d15287dc5a4f10f56a56b8',
manifestUrl:
'https://raw.githubusercontent.com/balancer-labs/bal-mining-scripts/master/reports/_current-arbitrum.json',
weekStart: 6,
},
{
label: 'MCB',
network: Network.ARBITRUM_MAINNET,
legacyMerkleRedeemAddress: '0xc6bd2497332d24094ec16a7261eec5c412b5a2c1',
distributorAddress: '0x25c646adf184051b35a405b9aaeba321e8d5342a',
merkleOrchardAddress: '0x751a0bc0e3f75b38e01cf25bfce7ff36de1c87de',
rewardTokenAddress: '0x4e352cf164e64adcbad318c3a1e222e9eba4ce42',
manifestUrl:
'https://raw.githubusercontent.com/balancer-labs/bal-mining-scripts/master/reports/_current-mcdex-arbitrum.json',
weekStart: 4,
},
{
label: 'PICKLE',
network: Network.ARBITRUM_MAINNET,
legacyMerkleRedeemAddress: '0xe3fb4f33fdb4ecc874a842c5ca2ee6a2e547328c',
distributorAddress: '0xf02ceb58d549e4b403e8f85fbbaee4c5dfa47c01',
merkleOrchardAddress: '0x751a0bc0e3f75b38e01cf25bfce7ff36de1c87de',
rewardTokenAddress: '0x965772e0e9c84b6f359c8597c891108dcf1c5b1a',
manifestUrl:
'https://raw.githubusercontent.com/balancer-labs/bal-mining-scripts/master/reports/_current-pickle-arbitrum.json',
weekStart: 4,
},
];
44 changes: 44 additions & 0 deletions src/apps/balancer-v2/balancer-v2.definition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Register } from '~app-toolkit/decorators';
import { AppDefinition } from '~app/app.definition';
import { GroupType, ProtocolAction, ProtocolTag } from '~app/app.interface';
import { Network } from '~types/network.interface';

export const BALANCER_V2_DEFINITION = {
id: 'balancer-v2',
name: 'Balancer V2',
description:
'Balancer is a flexible and versatile Automated Market Maker, giving developers customizability over the weights of the underlying tokens in AMM pools.',
url: 'https://app.balancer.fi/',
links: {
github: 'https://github.com/balancer-labs/',
twitter: 'https://twitter.com/BalancerLabs',
discord: 'https://discord.balancer.fi/',
medium: 'https://medium.com/balancer-protocol',
},
groups: {
pool: { id: 'pool', type: GroupType.TOKEN },
farm: { id: 'farm', type: GroupType.POSITION },
votingEscrow: { id: 'voting-escrow', type: GroupType.POSITION },
claimable: { id: 'claimable', type: GroupType.POSITION },
},
tags: [ProtocolTag.LIQUIDITY_POOL],
supportedNetworks: {
[Network.ETHEREUM_MAINNET]: [ProtocolAction.VIEW],
[Network.POLYGON_MAINNET]: [ProtocolAction.VIEW],
[Network.ARBITRUM_MAINNET]: [ProtocolAction.VIEW],
},
primaryColor: '#1c1d26',
token: {
address: '0xba100000625a3754423978a60c9317c58a424e3d',
network: Network.ETHEREUM_MAINNET,
},
};

@Register.AppDefinition(BALANCER_V2_DEFINITION.id)
export class BalancerV2AppDefinition extends AppDefinition {
constructor() {
super(BALANCER_V2_DEFINITION);
}
}

export default BALANCER_V2_DEFINITION;
50 changes: 50 additions & 0 deletions src/apps/balancer-v2/balancer-v2.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Register } from '~app-toolkit/decorators';
import { AbstractApp } from '~app/app.dynamic-module';
import { CurveAppModule } from '~apps/curve';

import { ArbitrumBalancerV2BalanceFetcher } from './arbitrum/balancer-v2.balance-fetcher';
import { ArbitrumBalancerV2PoolTokenFetcher } from './arbitrum/balancer-v2.pool.token-fetcher';
import BALANCER_V2_DEFINITION, { BalancerV2AppDefinition } from './balancer-v2.definition';
import { BalancerV2ContractFactory } from './contracts';
import { EthereumBalancerV2BalanceFetcher } from './ethereum/balancer-v2.balance-fetcher';
import { EthereumBalancerV2PoolTokenFetcher } from './ethereum/balancer-v2.pool.token-fetcher';
import { EthereumBalancerV2StakedfContractPositionFetcher } from './ethereum/balancer-v2.staked.contract-position-fetcher';
import { EthereumBalancerV2VotingEscrowContractPositionFetcher } from './ethereum/balancer-v2.voting-escrow.contract-position-fetcher';
import { BalancerV2CacheManager } from './helpers/balancer-v2.cache-manager';
import { BalancerV2ClaimableContractPositionBalanceHelper } from './helpers/balancer-v2.claimable.contract-position-balance-helper';
import { BalancerV2EventsPoolTokenDataStrategy } from './helpers/balancer-v2.events.pool-token-address-strategy';
import { BalancerV2GaugeAddressesGetter } from './helpers/balancer-v2.gauge-addresses-getter';
import { BalancerV2PoolTokensHelper } from './helpers/balancer-v2.pool.token-helper';
import { BalancerV2SpotPriceHelper } from './helpers/balancer-v2.spot-price.helper';
import { BalancerV2TheGraphPoolTokenDataStrategy } from './helpers/balancer-v2.the-graph.pool-token-address-strategy';
import { PolygonBalancerV2BalanceFetcher } from './polygon/balancer-v2.balance-fetcher';
import { PolygonBalancerV2PoolTokenFetcher } from './polygon/balancer-v2.pool.token-fetcher';

@Register.AppModule({
appId: BALANCER_V2_DEFINITION.id,
imports: [CurveAppModule],
providers: [
BalancerV2AppDefinition,
BalancerV2ContractFactory,
// Arbitrum
ArbitrumBalancerV2BalanceFetcher,
ArbitrumBalancerV2PoolTokenFetcher,
// Ethereum
EthereumBalancerV2BalanceFetcher,
EthereumBalancerV2PoolTokenFetcher,
EthereumBalancerV2VotingEscrowContractPositionFetcher,
EthereumBalancerV2StakedfContractPositionFetcher,
// Polygon
PolygonBalancerV2BalanceFetcher,
PolygonBalancerV2PoolTokenFetcher,
// Helpers
BalancerV2CacheManager,
BalancerV2PoolTokensHelper,
BalancerV2SpotPriceHelper,
BalancerV2TheGraphPoolTokenDataStrategy,
BalancerV2ClaimableContractPositionBalanceHelper,
BalancerV2EventsPoolTokenDataStrategy,
BalancerV2GaugeAddressesGetter,
],
})
export class BalancerV2AppModule extends AbstractApp() {}
Loading