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

Commit

Permalink
feat(stargate): Add wrapped ETH and Voting Escrow positions (#947)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonzgao authored Jul 25, 2022
1 parent b91d797 commit 50f83d5
Show file tree
Hide file tree
Showing 30 changed files with 4,403 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Inject } from '@nestjs/common';
import { Register } from '~app-toolkit/decorators';
import { CURVE_DEFINITION } from '~apps/curve';
import { OLYMPUS_DEFINITION } from '~apps/olympus';
import { STARGATE_DEFINITION } from '~apps/stargate/stargate.definition';
import { YEARN_DEFINITION } from '~apps/yearn/yearn.definition';
import { PositionFetcher } from '~position/position-fetcher.interface';
import { ContractPosition } from '~position/position.interface';
Expand Down Expand Up @@ -72,10 +73,10 @@ export class EthereumAbracadabraCauldronContractPositionFetcher implements Posit
groupIds: [YEARN_DEFINITION.groups.v1Vault.id, YEARN_DEFINITION.groups.v2Vault.id],
network,
},
{ appId: STARGATE_DEFINITION.id, groupIds: [STARGATE_DEFINITION.groups.pool.id], network },
// @TODO: Migrate these over
{ appId: 'convex', groupIds: ['deposit'], network },
{ appId: 'sushiswap', groupIds: ['pool'], network },
{ appId: 'stargate', groupIds: ['pool'], network },
],
});
}
Expand Down
30 changes: 29 additions & 1 deletion src/apps/stargate/arbitrum/stargate.balance-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,24 @@ export class ArbitrumStargateBalanceFetcher implements BalanceFetcher {
@Inject(StargateContractFactory) private readonly contractFactory: StargateContractFactory,
) {}

private async getEthBalances(address: string) {
return this.appToolkit.helpers.tokenBalanceHelper.getTokenBalances({
appId: STARGATE_DEFINITION.id,
groupId: STARGATE_DEFINITION.groups.eth.id,
network,
address,
});
}

private async getVeBalances(address: string) {
return this.appToolkit.helpers.tokenBalanceHelper.getTokenBalances({
appId: STARGATE_DEFINITION.id,
groupId: STARGATE_DEFINITION.groups.ve.id,
network,
address,
});
}

async getPoolTokenBalances(address: string) {
return this.appToolkit.helpers.tokenBalanceHelper.getTokenBalances({
address,
Expand Down Expand Up @@ -50,12 +68,22 @@ export class ArbitrumStargateBalanceFetcher implements BalanceFetcher {
}

async getBalances(address: string) {
const [poolTokenBalances, stakedBalances] = await Promise.all([
const [ethTokenBalances, veTokenBalances, poolTokenBalances, stakedBalances] = await Promise.all([
this.getEthBalances(address),
this.getVeBalances(address),
this.getPoolTokenBalances(address),
this.getStakedBalances(address),
]);

return presentBalanceFetcherResponse([
{
label: 'VotedEscrow',
assets: veTokenBalances,
},
{
label: 'Wrapper',
assets: ethTokenBalances,
},
{
label: 'Pools',
assets: poolTokenBalances,
Expand Down
38 changes: 38 additions & 0 deletions src/apps/stargate/arbitrum/stargate.eth.token-fetcher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Inject } from '@nestjs/common';

import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface';
import { ZERO_ADDRESS } from '~app-toolkit/constants/address';
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 { StargateContractFactory, StargateEth } from '../contracts';
import { STARGATE_DEFINITION } from '../stargate.definition';

const appId = STARGATE_DEFINITION.id;
const groupId = STARGATE_DEFINITION.groups.eth.id;
const network = Network.ARBITRUM_MAINNET;

const address = '0x915a55e36a01285a14f05de6e81ed9ce89772f8e'.toLowerCase();

@Register.TokenPositionFetcher({ appId, groupId, network })
export class ArbitrumStargateEthTokenFetcher implements PositionFetcher<AppTokenPosition> {
constructor(
@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit,
@Inject(StargateContractFactory) private readonly contractFactory: StargateContractFactory,
) {}

async getPositions() {
return await this.appToolkit.helpers.vaultTokenHelper.getTokens<StargateEth>({
appId,
groupId,
network,
resolveVaultAddresses: () => [address],
resolveContract: ({ address, network }) => this.contractFactory.stargateEth({ address, network }),
resolveUnderlyingTokenAddress: () => ZERO_ADDRESS,
resolveReserve: ({ multicall, contract }) => multicall.wrap(contract).totalSupply().then(Number),
resolvePricePerShare: ({ underlyingToken }) => underlyingToken.price,
});
}
}
37 changes: 37 additions & 0 deletions src/apps/stargate/arbitrum/stargate.ve.token-fetcher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Inject } from '@nestjs/common';

import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface';
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 { StargateContractFactory, StargateVe } from '../contracts';
import { STARGATE_DEFINITION } from '../stargate.definition';

const appId = STARGATE_DEFINITION.id;
const groupId = STARGATE_DEFINITION.groups.ve.id;
const network = Network.ARBITRUM_MAINNET;

const address = '0xfbd849e6007f9bc3cc2d6eb159c045b8dc660268'.toLowerCase();

@Register.TokenPositionFetcher({ appId, groupId, network })
export class ArbitrumStargateVeTokenFetcher implements PositionFetcher<AppTokenPosition> {
constructor(
@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit,
@Inject(StargateContractFactory) private readonly contractFactory: StargateContractFactory,
) {}

async getPositions() {
return await this.appToolkit.helpers.vaultTokenHelper.getTokens<StargateVe>({
appId,
groupId,
network,
resolveVaultAddresses: () => [address],
resolveContract: ({ address, network }) => this.contractFactory.stargateVe({ address, network }),
resolveUnderlyingTokenAddress: ({ multicall, contract }) => multicall.wrap(contract).token(),
resolveReserve: ({ multicall, contract }) => multicall.wrap(contract).totalSupply().then(Number),
resolvePricePerShare: ({ underlyingToken }) => underlyingToken.price,
});
}
}
16 changes: 15 additions & 1 deletion src/apps/stargate/avalanche/stargate.balance-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ export class AvalancheStargateBalanceFetcher implements BalanceFetcher {
@Inject(StargateContractFactory) private readonly contractFactory: StargateContractFactory,
) {}

private async getVeBalances(address: string) {
return this.appToolkit.helpers.tokenBalanceHelper.getTokenBalances({
appId: STARGATE_DEFINITION.id,
groupId: STARGATE_DEFINITION.groups.ve.id,
network,
address,
});
}

async getPoolTokenBalances(address: string) {
return this.appToolkit.helpers.tokenBalanceHelper.getTokenBalances({
address,
Expand Down Expand Up @@ -50,12 +59,17 @@ export class AvalancheStargateBalanceFetcher implements BalanceFetcher {
}

async getBalances(address: string) {
const [poolTokenBalances, stakedBalances] = await Promise.all([
const [veTokenBalances, poolTokenBalances, stakedBalances] = await Promise.all([
this.getVeBalances(address),
this.getPoolTokenBalances(address),
this.getStakedBalances(address),
]);

return presentBalanceFetcherResponse([
{
label: 'VotedEscrow',
assets: veTokenBalances,
},
{
label: 'Pools',
assets: poolTokenBalances,
Expand Down
37 changes: 37 additions & 0 deletions src/apps/stargate/avalanche/stargate.ve.token-fetcher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Inject } from '@nestjs/common';

import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface';
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 { StargateContractFactory, StargateVe } from '../contracts';
import { STARGATE_DEFINITION } from '../stargate.definition';

const appId = STARGATE_DEFINITION.id;
const groupId = STARGATE_DEFINITION.groups.ve.id;
const network = Network.AVALANCHE_MAINNET;

const address = '0xca0f57d295bbce554da2c07b005b7d6565a58fce'.toLowerCase();

@Register.TokenPositionFetcher({ appId, groupId, network })
export class AvalancheStargateVeTokenFetcher implements PositionFetcher<AppTokenPosition> {
constructor(
@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit,
@Inject(StargateContractFactory) private readonly contractFactory: StargateContractFactory,
) {}

async getPositions() {
return await this.appToolkit.helpers.vaultTokenHelper.getTokens<StargateVe>({
appId,
groupId,
network,
resolveVaultAddresses: () => [address],
resolveContract: ({ address, network }) => this.contractFactory.stargateVe({ address, network }),
resolveUnderlyingTokenAddress: ({ multicall, contract }) => multicall.wrap(contract).token(),
resolveReserve: ({ multicall, contract }) => multicall.wrap(contract).totalSupply().then(Number),
resolvePricePerShare: ({ underlyingToken }) => underlyingToken.price,
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ export class BinanceSmartChainStargateBalanceFetcher implements BalanceFetcher {
@Inject(StargateContractFactory) private readonly contractFactory: StargateContractFactory,
) {}

private async getVeBalances(address: string) {
return this.appToolkit.helpers.tokenBalanceHelper.getTokenBalances({
appId: STARGATE_DEFINITION.id,
groupId: STARGATE_DEFINITION.groups.ve.id,
network,
address,
});
}

async getPoolTokenBalances(address: string) {
return this.appToolkit.helpers.tokenBalanceHelper.getTokenBalances({
address,
Expand Down Expand Up @@ -50,12 +59,17 @@ export class BinanceSmartChainStargateBalanceFetcher implements BalanceFetcher {
}

async getBalances(address: string) {
const [poolTokenBalances, stakedBalances] = await Promise.all([
const [veTokenBalances, poolTokenBalances, stakedBalances] = await Promise.all([
this.getVeBalances(address),
this.getPoolTokenBalances(address),
this.getStakedBalances(address),
]);

return presentBalanceFetcherResponse([
{
label: 'VotedEscrow',
assets: veTokenBalances,
},
{
label: 'Pools',
assets: poolTokenBalances,
Expand Down
37 changes: 37 additions & 0 deletions src/apps/stargate/binance-smart-chain/stargate.ve.token-fetcher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Inject } from '@nestjs/common';

import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface';
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 { StargateContractFactory, StargateVe } from '../contracts';
import { STARGATE_DEFINITION } from '../stargate.definition';

const appId = STARGATE_DEFINITION.id;
const groupId = STARGATE_DEFINITION.groups.ve.id;
const network = Network.BINANCE_SMART_CHAIN_MAINNET;

const address = '0xd4888870c8686c748232719051b677791dbda26d'.toLowerCase();

@Register.TokenPositionFetcher({ appId, groupId, network })
export class BinanceSmartChainStargateVeTokenFetcher implements PositionFetcher<AppTokenPosition> {
constructor(
@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit,
@Inject(StargateContractFactory) private readonly contractFactory: StargateContractFactory,
) {}

async getPositions() {
return await this.appToolkit.helpers.vaultTokenHelper.getTokens<StargateVe>({
appId,
groupId,
network,
resolveVaultAddresses: () => [address],
resolveContract: ({ address, network }) => this.contractFactory.stargateVe({ address, network }),
resolveUnderlyingTokenAddress: ({ multicall, contract }) => multicall.wrap(contract).token(),
resolveReserve: ({ multicall, contract }) => multicall.wrap(contract).totalSupply().then(Number),
resolvePricePerShare: ({ underlyingToken }) => underlyingToken.price,
});
}
}
Loading

0 comments on commit 50f83d5

Please sign in to comment.