This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(sushiswap-bentobox): Migrate to template (#1968)
* fix(sushiswap-bentobox): Migration to template * feat(sushiswap-bentobox): Add bentobox vaults on avalanche and fantom
- Loading branch information
Showing
17 changed files
with
200 additions
and
405 deletions.
There are no files selected for viewing
34 changes: 0 additions & 34 deletions
34
src/apps/sushiswap-bentobox/arbitrum/sushiswap-bentobox.balance-fetcher.ts
This file was deleted.
Oops, something went wrong.
33 changes: 7 additions & 26 deletions
33
src/apps/sushiswap-bentobox/arbitrum/sushiswap-bentobox.vault.contract-position-fetcher.ts
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 |
---|---|---|
@@ -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'; | ||
} |
10 changes: 10 additions & 0 deletions
10
src/apps/sushiswap-bentobox/avalanche/sushiswap-bentobox.vault.contract-position-fetcher.ts
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,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'; | ||
} |
34 changes: 0 additions & 34 deletions
34
src/apps/sushiswap-bentobox/binance-smart-chain/sushiswap-bentobox.balance-fetcher.ts
This file was deleted.
Oops, something went wrong.
33 changes: 7 additions & 26 deletions
33
...hiswap-bentobox/binance-smart-chain/sushiswap-bentobox.vault.contract-position-fetcher.ts
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 |
---|---|---|
@@ -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'; | ||
} |
62 changes: 62 additions & 0 deletions
62
src/apps/sushiswap-bentobox/common/sushiswap-bentobox.vault-tokens-resolver.ts
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,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; | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
src/apps/sushiswap-bentobox/common/sushiswap-bentobox.vault.contract-position-fetcher.ts
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,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]; | ||
} | ||
} |
34 changes: 0 additions & 34 deletions
34
src/apps/sushiswap-bentobox/ethereum/sushiswap-bentobox.balance-fetcher.ts
This file was deleted.
Oops, something went wrong.
34 changes: 7 additions & 27 deletions
34
src/apps/sushiswap-bentobox/ethereum/sushiswap-bentobox.vault.contract-position-fetcher.ts
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 |
---|---|---|
@@ -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'; | ||
} |
10 changes: 10 additions & 0 deletions
10
src/apps/sushiswap-bentobox/fantom/sushiswap-bentobox.vault.contract-position-fetcher.ts
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,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'; | ||
} |
Oops, something went wrong.