This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 383
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tenderize): integrate tenderTokens and swapTokens
- Loading branch information
Showing
14 changed files
with
634 additions
and
0 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,52 @@ | ||
import { Inject } from '@nestjs/common'; | ||
|
||
import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface'; | ||
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 { TENDERIZE_DEFINITION } from '../tenderize.definition'; | ||
|
||
const network = Network.ARBITRUM_MAINNET; | ||
|
||
@Register.BalanceFetcher(TENDERIZE_DEFINITION.id, network) | ||
export class ArbitrumTenderizeBalanceFetcher implements BalanceFetcher { | ||
constructor(@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit) {} | ||
|
||
async getTenderTokenBalances(address: string) { | ||
return this.appToolkit.helpers.tokenBalanceHelper.getTokenBalances({ | ||
address, | ||
appId: TENDERIZE_DEFINITION.id, | ||
groupId: TENDERIZE_DEFINITION.groups.tendertokens.id, | ||
network, | ||
}); | ||
} | ||
|
||
async getSwapTokenBalances(address: string) { | ||
return this.appToolkit.helpers.tokenBalanceHelper.getTokenBalances({ | ||
address, | ||
appId: TENDERIZE_DEFINITION.id, | ||
groupId: TENDERIZE_DEFINITION.groups.swaptokens.id, | ||
network, | ||
}); | ||
} | ||
|
||
async getBalances(address: string) { | ||
const [tenderTokenBalances, swapTokenBalances] = await Promise.all([ | ||
this.getTenderTokenBalances(address), | ||
this.getSwapTokenBalances(address), | ||
]); | ||
|
||
return presentBalanceFetcherResponse([ | ||
{ | ||
label: 'TenderTokens', | ||
assets: tenderTokenBalances, | ||
}, | ||
{ | ||
label: 'SwapTokens', | ||
assets: swapTokenBalances, | ||
}, | ||
]); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
src/apps/tenderize/arbitrum/tenderize.swaptokens.token-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,75 @@ | ||
import { Inject } from '@nestjs/common'; | ||
|
||
import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface'; | ||
import { Register } from '~app-toolkit/decorators'; | ||
import { buildDollarDisplayItem } from '~app-toolkit/helpers/presentation/display-item.present'; | ||
import { ContractType } from '~position/contract.interface'; | ||
import { PositionFetcher } from '~position/position-fetcher.interface'; | ||
import { AppTokenPosition } from '~position/position.interface'; | ||
import { Network } from '~types/network.interface'; | ||
|
||
import { TenderizeContractFactory } from '../contracts'; | ||
import { arbitrumEndpoint } from '../helpers/constants'; | ||
import { ConfigResponse, configQuery } from '../helpers/queries'; | ||
import { TENDERIZE_DEFINITION } from '../tenderize.definition'; | ||
|
||
const appId = TENDERIZE_DEFINITION.id; | ||
const groupId = TENDERIZE_DEFINITION.groups.swaptokens.id; | ||
const network = Network.ARBITRUM_MAINNET; | ||
|
||
@Register.TokenPositionFetcher({ appId, groupId, network }) | ||
export class ArbitrumTenderizeSwaptokensTokenFetcher implements PositionFetcher<AppTokenPosition> { | ||
constructor( | ||
@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit, | ||
@Inject(TenderizeContractFactory) private readonly tenderizeContractFactory: TenderizeContractFactory, | ||
) {} | ||
|
||
async getPosition(address: string, steak: string) { | ||
const multicall = this.appToolkit.getMulticall(network); | ||
const contract = this.tenderizeContractFactory.erc20({ address, network }); | ||
const baseTokens = await this.appToolkit.getBaseTokenPrices(network); | ||
const underlyingToken = baseTokens.find(v => v.address === steak)!; | ||
|
||
const [symbol, decimals, totalSupply] = await Promise.all([ | ||
multicall.wrap(contract).symbol(), | ||
multicall.wrap(contract).decimals(), | ||
multicall.wrap(contract).totalSupply(), | ||
]); | ||
const supply = Number(totalSupply) / 10 ** decimals; | ||
const price = underlyingToken.price; | ||
const token: AppTokenPosition = { | ||
address, | ||
network, | ||
appId, | ||
groupId, | ||
symbol, | ||
decimals, | ||
supply, | ||
tokens: [], | ||
dataProps: {}, | ||
pricePerShare: 1, | ||
price, | ||
type: ContractType.APP_TOKEN, | ||
displayProps: { | ||
label: symbol, | ||
secondaryLabel: buildDollarDisplayItem(price), | ||
images: [], | ||
statsItems: [], | ||
}, | ||
}; | ||
|
||
return token; | ||
} | ||
|
||
async getPositions() { | ||
const data = await this.appToolkit.helpers.theGraphHelper.request<ConfigResponse>({ | ||
endpoint: arbitrumEndpoint, | ||
query: configQuery, | ||
}); | ||
|
||
const positions = await Promise.all( | ||
data.configs.map(async config => await this.getPosition(config.lpToken, config.steak, config.symbol)), | ||
); | ||
return positions; | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
src/apps/tenderize/arbitrum/tenderize.tender-tokens.token-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,85 @@ | ||
import { Inject } from '@nestjs/common'; | ||
import Axios from 'axios'; | ||
|
||
import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface'; | ||
import { Register } from '~app-toolkit/decorators'; | ||
import { buildDollarDisplayItem } from '~app-toolkit/helpers/presentation/display-item.present'; | ||
import { ContractType } from '~position/contract.interface'; | ||
import { PositionFetcher } from '~position/position-fetcher.interface'; | ||
import { AppTokenPosition } from '~position/position.interface'; | ||
import { Network } from '~types/network.interface'; | ||
|
||
import { TenderizeContractFactory } from '../contracts'; | ||
import { arbitrumEndpoint } from '../helpers/constants'; | ||
import { tenderTokenFetcherQuery, TenderTokenFetcherResponse } from '../helpers/queries'; | ||
import { APYResponse } from '../helpers/types'; | ||
import { TENDERIZE_DEFINITION } from '../tenderize.definition'; | ||
|
||
const appId = TENDERIZE_DEFINITION.id; | ||
const groupId = TENDERIZE_DEFINITION.groups.tendertokens.id; | ||
const network = Network.ARBITRUM_MAINNET; | ||
|
||
@Register.TokenPositionFetcher({ appId, groupId, network }) | ||
export class ArbitrumTenderizeTenderTokensTokenFetcher implements PositionFetcher<AppTokenPosition> { | ||
constructor( | ||
@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit, | ||
@Inject(TenderizeContractFactory) private readonly tenderizeContractFactory: TenderizeContractFactory, | ||
) {} | ||
|
||
async getPosition(address: string, steak: string, virtualPrice: string, apy: string) { | ||
const multicall = this.appToolkit.getMulticall(network); | ||
const contract = this.tenderizeContractFactory.erc20({ address, network }); | ||
const baseTokens = await this.appToolkit.getBaseTokenPrices(network); | ||
const underlyingToken = baseTokens.find(v => v.address === steak)!; | ||
|
||
const [symbol, decimals, totalSupply] = await Promise.all([ | ||
multicall.wrap(contract).symbol(), | ||
multicall.wrap(contract).decimals(), | ||
multicall.wrap(contract).totalSupply(), | ||
]); | ||
const supply = Number(totalSupply) / 10 ** decimals; | ||
const price = underlyingToken.price * (Number(virtualPrice) / 10 ** decimals); | ||
const token: AppTokenPosition = { | ||
address, | ||
network, | ||
appId, | ||
groupId, | ||
symbol, | ||
decimals, | ||
supply, | ||
tokens: [], | ||
dataProps: {}, | ||
pricePerShare: 1, | ||
price, | ||
type: ContractType.APP_TOKEN, | ||
displayProps: { | ||
label: symbol, | ||
secondaryLabel: buildDollarDisplayItem(price), | ||
tertiaryLabel: `${apy}% APY`, | ||
images: [`https://app.tenderize.me/tender${symbol}.svg`], | ||
statsItems: [], | ||
}, | ||
}; | ||
|
||
return token; | ||
} | ||
|
||
async getPositions() { | ||
const data = await this.appToolkit.helpers.theGraphHelper.request<TenderTokenFetcherResponse>({ | ||
endpoint: arbitrumEndpoint, | ||
query: tenderTokenFetcherQuery, | ||
}); | ||
|
||
const { data: apyData } = await Axios.get<APYResponse>('https://www.tenderize.me/api/apy'); | ||
const apyArr = Object.values(apyData); | ||
const positions = await Promise.all( | ||
data.configs.map(async config => { | ||
const apy = apyArr.find(item => item.subgraphId === config.id)?.apy; | ||
const virtualPrice = | ||
data.tenderSwaps.find(item => item.id === config.id)?.virtualPrice ?? '1000000000000000000'; | ||
return await this.getPosition(config.tenderToken, config.steak, virtualPrice, apy ?? '0'); | ||
}), | ||
); | ||
return positions; | ||
} | ||
} |
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,15 @@ | ||
import { Injectable, Inject } from '@nestjs/common'; | ||
|
||
import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface'; | ||
import { ContractFactory } from '~contract/contracts'; | ||
import { Network } from '~types/network.interface'; | ||
|
||
// eslint-disable-next-line | ||
type ContractOpts = { address: string; network: Network }; | ||
|
||
@Injectable() | ||
export class TenderizeContractFactory extends ContractFactory { | ||
constructor(@Inject(APP_TOOLKIT) protected readonly appToolkit: IAppToolkit) { | ||
super((network: Network) => appToolkit.getNetworkProvider(network)); | ||
} | ||
} |
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,52 @@ | ||
import { Inject } from '@nestjs/common'; | ||
|
||
import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface'; | ||
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 { TENDERIZE_DEFINITION } from '../tenderize.definition'; | ||
|
||
const network = Network.ETHEREUM_MAINNET; | ||
|
||
@Register.BalanceFetcher(TENDERIZE_DEFINITION.id, network) | ||
export class EthereumTenderizeBalanceFetcher implements BalanceFetcher { | ||
constructor(@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit) {} | ||
|
||
async getTenderTokenBalances(address: string) { | ||
return this.appToolkit.helpers.tokenBalanceHelper.getTokenBalances({ | ||
address, | ||
appId: TENDERIZE_DEFINITION.id, | ||
groupId: TENDERIZE_DEFINITION.groups.tendertokens.id, | ||
network, | ||
}); | ||
} | ||
|
||
async getSwapTokenBalances(address: string) { | ||
return this.appToolkit.helpers.tokenBalanceHelper.getTokenBalances({ | ||
address, | ||
appId: TENDERIZE_DEFINITION.id, | ||
groupId: TENDERIZE_DEFINITION.groups.swaptokens.id, | ||
network, | ||
}); | ||
} | ||
|
||
async getBalances(address: string) { | ||
const [tenderTokenBalances, swapTokenBalances] = await Promise.all([ | ||
this.getTenderTokenBalances(address), | ||
this.getSwapTokenBalances(address), | ||
]); | ||
|
||
return presentBalanceFetcherResponse([ | ||
{ | ||
label: 'TenderTokens', | ||
assets: tenderTokenBalances, | ||
}, | ||
{ | ||
label: 'SwapTokens', | ||
assets: swapTokenBalances, | ||
}, | ||
]); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
src/apps/tenderize/ethereum/tenderize.swaptokens.token-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,74 @@ | ||
import { Inject } from '@nestjs/common'; | ||
|
||
import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface'; | ||
import { Register } from '~app-toolkit/decorators'; | ||
import { buildDollarDisplayItem } from '~app-toolkit/helpers/presentation/display-item.present'; | ||
import { ContractType } from '~position/contract.interface'; | ||
import { PositionFetcher } from '~position/position-fetcher.interface'; | ||
import { AppTokenPosition } from '~position/position.interface'; | ||
import { Network } from '~types/network.interface'; | ||
|
||
import { TenderizeContractFactory } from '../contracts'; | ||
import { ethereumEndpoint } from '../helpers/constants'; | ||
import { ConfigResponse, configQuery } from '../helpers/queries'; | ||
import { TENDERIZE_DEFINITION } from '../tenderize.definition'; | ||
|
||
const appId = TENDERIZE_DEFINITION.id; | ||
const groupId = TENDERIZE_DEFINITION.groups.swaptokens.id; | ||
const network = Network.ETHEREUM_MAINNET; | ||
|
||
@Register.TokenPositionFetcher({ appId, groupId, network }) | ||
export class EthereumTenderizeSwapTokensTokenFetcher implements PositionFetcher<AppTokenPosition> { | ||
constructor( | ||
@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit, | ||
@Inject(TenderizeContractFactory) private readonly tenderizeContractFactory: TenderizeContractFactory, | ||
) {} | ||
|
||
async getPosition(address: string, steak: string) { | ||
const multicall = this.appToolkit.getMulticall(network); | ||
const contract = this.tenderizeContractFactory.erc20({ address, network }); | ||
const baseTokens = await this.appToolkit.getBaseTokenPrices(network); | ||
const underlyingToken = baseTokens.find(v => v.address === steak)!; | ||
const [symbol, decimals, totalSupply] = await Promise.all([ | ||
multicall.wrap(contract).symbol(), | ||
multicall.wrap(contract).decimals(), | ||
multicall.wrap(contract).totalSupply(), | ||
]); | ||
const supply = Number(totalSupply) / 10 ** decimals; | ||
const price = underlyingToken.price; | ||
const token: AppTokenPosition = { | ||
address, | ||
network, | ||
appId, | ||
groupId, | ||
symbol, | ||
decimals, | ||
supply, | ||
tokens: [], | ||
dataProps: {}, | ||
pricePerShare: 1, | ||
price, | ||
type: ContractType.APP_TOKEN, | ||
displayProps: { | ||
label: symbol, | ||
secondaryLabel: buildDollarDisplayItem(price), | ||
images: [], | ||
statsItems: [], | ||
}, | ||
}; | ||
|
||
return token; | ||
} | ||
|
||
async getPositions() { | ||
const data = await this.appToolkit.helpers.theGraphHelper.request<ConfigResponse>({ | ||
endpoint: ethereumEndpoint, | ||
query: configQuery, | ||
}); | ||
|
||
const positions = await Promise.all( | ||
data.configs.map(async config => await this.getPosition(config.lpToken, config.steak)), | ||
); | ||
return positions; | ||
} | ||
} |
Oops, something went wrong.