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

Commit

Permalink
fix(sushiswap-bentobox): Migrate to template (#1968)
Browse files Browse the repository at this point in the history
* fix(sushiswap-bentobox): Migration to template

* feat(sushiswap-bentobox): Add bentobox vaults on avalanche and fantom
  • Loading branch information
wpoulin committed Dec 21, 2022
1 parent 929aaf0 commit b722434
Show file tree
Hide file tree
Showing 17 changed files with 200 additions and 405 deletions.

This file was deleted.

@@ -1,29 +1,10 @@
import { Inject } from '@nestjs/common';
import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator';

import { Register } from '~app-toolkit/decorators';
import { PositionFetcher } from '~position/position-fetcher.interface';
import { ContractPosition } from '~position/position.interface';
import { Network } from '~types/network.interface';
import { SushiswapBentoboxVaultContractPositionFetcher } from '../common/sushiswap-bentobox.vault.contract-position-fetcher';

import { SushiSwapBentoBoxContractPositionHelper } from '../helpers/sushiswap-bentobox.vault.contract-position-helper';
import { SUSHISWAP_BENTOBOX_DEFINITION } from '../sushiswap-bentobox.definition';

const appId = SUSHISWAP_BENTOBOX_DEFINITION.id;
const groupId = SUSHISWAP_BENTOBOX_DEFINITION.groups.vault.id;
const network = Network.ARBITRUM_MAINNET;

@Register.ContractPositionFetcher({ appId, groupId, network })
export class ArbitrumSushiSwapBentoBoxContractPositionFetcher implements PositionFetcher<ContractPosition> {
constructor(
@Inject(SushiSwapBentoBoxContractPositionHelper)
private readonly positionHelper: SushiSwapBentoBoxContractPositionHelper,
) {}

async getPositions() {
return this.positionHelper.getPositions({
bentoBoxAddress: '0x74c764d41b77dbbb4fe771dab1939b00b146894a',
network,
subgraphUrl: 'https://api.thegraph.com/subgraphs/name/sushiswap/arbitrum-bentobox',
});
}
@PositionTemplate()
export class ArbitrumSushiSwapBentoBoxContractPositionFetcher extends SushiswapBentoboxVaultContractPositionFetcher {
groupLabel = 'BentoBox';
subgraphUrl = 'https://api.thegraph.com/subgraphs/name/sushiswap/bentobox-arbitrum';
bentoboxAddress = '0x74c764d41b77dbbb4fe771dab1939b00b146894a';
}
@@ -0,0 +1,10 @@
import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator';

import { SushiswapBentoboxVaultContractPositionFetcher } from '../common/sushiswap-bentobox.vault.contract-position-fetcher';

@PositionTemplate()
export class AvalancheSushiSwapBentoBoxContractPositionFetcher extends SushiswapBentoboxVaultContractPositionFetcher {
groupLabel = 'BentoBox';
subgraphUrl = 'https://api.thegraph.com/subgraphs/name/sushiswap/bentobox-avalanche';
bentoboxAddress = '0x0711b6026068f736bae6b213031fce978d48e026';
}

This file was deleted.

@@ -1,29 +1,10 @@
import { Inject } from '@nestjs/common';
import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator';

import { Register } from '~app-toolkit/decorators';
import { PositionFetcher } from '~position/position-fetcher.interface';
import { ContractPosition } from '~position/position.interface';
import { Network } from '~types/network.interface';
import { SushiswapBentoboxVaultContractPositionFetcher } from '../common/sushiswap-bentobox.vault.contract-position-fetcher';

import { SushiSwapBentoBoxContractPositionHelper } from '../helpers/sushiswap-bentobox.vault.contract-position-helper';
import { SUSHISWAP_BENTOBOX_DEFINITION } from '../sushiswap-bentobox.definition';

const appId = SUSHISWAP_BENTOBOX_DEFINITION.id;
const groupId = SUSHISWAP_BENTOBOX_DEFINITION.groups.vault.id;
const network = Network.BINANCE_SMART_CHAIN_MAINNET;

@Register.ContractPositionFetcher({ appId, groupId, network })
export class BscSushiSwapBentoBoxContractPositionFetcher implements PositionFetcher<ContractPosition> {
constructor(
@Inject(SushiSwapBentoBoxContractPositionHelper)
private readonly positionHelper: SushiSwapBentoBoxContractPositionHelper,
) {}

async getPositions() {
return this.positionHelper.getPositions({
bentoBoxAddress: '0xf5bce5077908a1b7370b9ae04adc565ebd643966',
network,
subgraphUrl: 'https://api.thegraph.com/subgraphs/name/sushiswap/bsc-bentobox',
});
}
@PositionTemplate()
export class BinanceSmartChainSushiSwapBentoBoxContractPositionFetcher extends SushiswapBentoboxVaultContractPositionFetcher {
groupLabel = 'BentoBox';
subgraphUrl = 'https://api.thegraph.com/subgraphs/name/sushiswap/bentobox-bsc';
bentoboxAddress = '0xf5bce5077908a1b7370b9ae04adc565ebd643966';
}
@@ -0,0 +1,62 @@
import { Inject, Injectable } from '@nestjs/common';
import { gql } from 'graphql-request';

import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface';
import { Cache } from '~cache/cache.decorator';
import { Network } from '~types/network.interface';

import { SUSHISWAP_BENTOBOX_DEFINITION } from '../sushiswap-bentobox.definition';

export type UnipilotVaultDefinition = {
address: string;
token0Address: string;
token1Address: string;
feeTier: string;
token0Symbol: string;
token1Symbol: string;
strategyId?: string;
totalLockedToken0: string;
totalLockedToken1: string;
};

type TokensResponse = {
tokens: {
id: string;
}[];
};

const ALL_TOKENS_QUERY = gql`
{
tokens(first: 500) {
id
}
}
`;

@Injectable()
export class SushiswapBentoboxVaultTokensResolver {
constructor(@Inject(APP_TOOLKIT) protected readonly appToolkit: IAppToolkit) {}

@Cache({
key: _network => `studio:${SUSHISWAP_BENTOBOX_DEFINITION.id}:${_network}:vault-data`,
ttl: 5 * 60, // 5 minutes
})
private async getVaultTokensData(subgraphUrl: string, _network: Network) {
const data = await this.appToolkit.helpers.theGraphHelper.request<TokensResponse>({
endpoint: subgraphUrl,
query: ALL_TOKENS_QUERY,
});

return data.tokens;
}

async getVaultTokens(subgraphUrl: string, network: Network) {
const vaultTokenData = await this.getVaultTokensData(subgraphUrl, network);

const vaultTokens = vaultTokenData.map(token => {
return token.id;
});

return vaultTokens;
}
}
@@ -0,0 +1,78 @@
import { Inject } from '@nestjs/common';
import { BigNumberish } from 'ethers';

import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface';
import { getLabelFromToken } from '~app-toolkit/helpers/presentation/image.present';
import { MetaType } from '~position/position.interface';
import { ContractPositionTemplatePositionFetcher } from '~position/template/contract-position.template.position-fetcher';
import {
GetDisplayPropsParams,
GetTokenBalancesParams,
GetTokenDefinitionsParams,
} from '~position/template/contract-position.template.types';

import { SushiswapBentobox, SushiswapBentoboxContractFactory } from '../contracts';

import { SushiswapBentoboxVaultTokensResolver } from './sushiswap-bentobox.vault-tokens-resolver';

export type SushiswapBentoboxVaultDefinition = {
address: string;
underlyingTokenAddress: string;
};

export abstract class SushiswapBentoboxVaultContractPositionFetcher extends ContractPositionTemplatePositionFetcher<SushiswapBentobox> {
abstract subgraphUrl: string;
abstract bentoboxAddress: string;

constructor(
@Inject(APP_TOOLKIT) protected readonly appToolkit: IAppToolkit,
@Inject(SushiswapBentoboxContractFactory) private readonly contractFactory: SushiswapBentoboxContractFactory,
@Inject(SushiswapBentoboxVaultTokensResolver)
private readonly vaultTokenResolver: SushiswapBentoboxVaultTokensResolver,
) {
super(appToolkit);
}

async getDefinitions(): Promise<SushiswapBentoboxVaultDefinition[]> {
const bentoboxTokens = await this.vaultTokenResolver.getVaultTokens(this.subgraphUrl, this.network);

const vaultDefinitons = bentoboxTokens.map(underlyingTokenAddress => {
return {
address: this.bentoboxAddress,
underlyingTokenAddress,
};
});

return vaultDefinitons;
}

async getTokenDefinitions({
definition,
}: GetTokenDefinitionsParams<SushiswapBentobox, SushiswapBentoboxVaultDefinition>) {
return [
{
metaType: MetaType.SUPPLIED,
address: definition.underlyingTokenAddress,
network: this.network,
},
];
}

getContract(address: string): SushiswapBentobox {
return this.contractFactory.sushiswapBentobox({ network: this.network, address });
}

async getLabel({ contractPosition }: GetDisplayPropsParams<SushiswapBentobox>): Promise<string> {
return `${getLabelFromToken(contractPosition.tokens[0])} Deposit`;
}

async getTokenBalancesPerPosition({
address,
contract,
contractPosition,
}: GetTokenBalancesParams<SushiswapBentobox>): Promise<BigNumberish[]> {
const balance = await contract.balanceOf(contractPosition.tokens[0].address, address);

return [balance];
}
}

This file was deleted.

@@ -1,30 +1,10 @@
import { Inject } from '@nestjs/common';
import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator';

import { Register } from '~app-toolkit/decorators';
import { PositionFetcher } from '~position/position-fetcher.interface';
import { ContractPosition } from '~position/position.interface';
import { Network } from '~types/network.interface';
import { SushiswapBentoboxVaultContractPositionFetcher } from '../common/sushiswap-bentobox.vault.contract-position-fetcher';

import { SushiSwapBentoBoxContractPositionHelper } from '../helpers/sushiswap-bentobox.vault.contract-position-helper';
import { SUSHISWAP_BENTOBOX_DEFINITION } from '../sushiswap-bentobox.definition';

const appId = SUSHISWAP_BENTOBOX_DEFINITION.id;
const groupId = SUSHISWAP_BENTOBOX_DEFINITION.groups.vault.id;
const network = Network.ETHEREUM_MAINNET;

@Register.ContractPositionFetcher({ appId, groupId, network })
export class EthereumSushiSwapBentoBoxContractPositionFetcher implements PositionFetcher<ContractPosition> {
constructor(
@Inject(SushiSwapBentoBoxContractPositionHelper)
private readonly positionHelper: SushiSwapBentoBoxContractPositionHelper,
) {}

async getPositions() {
return this.positionHelper.getPositions({
bentoBoxAddress: '0xf5bce5077908a1b7370b9ae04adc565ebd643966',
network,
subgraphUrl: 'https://api.thegraph.com/subgraphs/name/sushiswap/bentobox',
dependencies: [{ appId: 'sushiswap', groupIds: ['x-sushi', 'meowshi'], network }],
});
}
@PositionTemplate()
export class EthereumSushiSwapBentoBoxContractPositionFetcher extends SushiswapBentoboxVaultContractPositionFetcher {
groupLabel = 'BentoBox';
subgraphUrl = 'https://api.thegraph.com/subgraphs/name/sushiswap/bentobox';
bentoboxAddress = '0xf5bce5077908a1b7370b9ae04adc565ebd643966';
}
@@ -0,0 +1,10 @@
import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator';

import { SushiswapBentoboxVaultContractPositionFetcher } from '../common/sushiswap-bentobox.vault.contract-position-fetcher';

@PositionTemplate()
export class FantomSushiSwapBentoBoxContractPositionFetcher extends SushiswapBentoboxVaultContractPositionFetcher {
groupLabel = 'BentoBox';
subgraphUrl = 'https://api.thegraph.com/subgraphs/name/sushiswap/bentobox-fantom';
bentoboxAddress = '0xf5bce5077908a1b7370b9ae04adc565ebd643966';
}

0 comments on commit b722434

Please sign in to comment.