forked from Zapper-fi/studio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from 0xoats/develop
feat: add token fetcher
- Loading branch information
Showing
5 changed files
with
100 additions
and
7 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,18 @@ | ||
# Control which apps you wish to have active | ||
# This is particularly useful to reduce the local build time | ||
# The name of the apps MUST correspond to their folder name | ||
# Apps must also activate their dependents. For example, | ||
# Tokemak requires Synthetix, so you will need to activate both those | ||
# apps. Multiple apps MUST be comma seperated. | ||
# e.g: ENABLED_APPS="tokemak,synthetix" | ||
|
||
ENABLED_APPS= | ||
|
||
|
||
# Control which apps' positions should be resolved from Zapper API | ||
# This is particularly useful when you're trying to write an app | ||
# having position dependencies on other apps present on Studio that are failing/slow. | ||
# This helps to scope your work purely on your app, resolving its dependencies externally. | ||
# The name of the apps MUST correspond to their folder name | ||
# e.g: API_RESOLVED_POSITIONS="tokemak,synthetix" | ||
API_RESOLVED_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
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
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
72 changes: 72 additions & 0 deletions
72
src/apps/argo-finance/cronos/argo-finance.pledging.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,72 @@ | ||
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 { buildDollarDisplayItem } from '~app-toolkit/helpers/presentation/display-item.present'; | ||
import { getImagesFromToken } from '~app-toolkit/helpers/presentation/image.present'; | ||
import { ContractType } from '~position/contract.interface'; | ||
import { AppTokenPosition } from '~position/position.interface'; | ||
import { Network } from '~types/network.interface'; | ||
|
||
import { ARGO_FINANCE_DEFINITION } from '../argo-finance.definition'; | ||
import { ArgoFinanceContractFactory } from '../contracts'; | ||
|
||
import { ADDRESSES } from './consts'; | ||
|
||
const appId = ARGO_FINANCE_DEFINITION.id; | ||
const groupId = ARGO_FINANCE_DEFINITION.groups.pledging.id; | ||
const network = Network.CRONOS_MAINNET; | ||
|
||
@Register.TokenPositionFetcher({ appId, groupId, network }) | ||
export class CronosArgoFinancePledgingTokenFetcher implements PositionFetcher<AppTokenPosition> { | ||
constructor( | ||
@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit, | ||
@Inject(ArgoFinanceContractFactory) private readonly argoFinanceContractFactory: ArgoFinanceContractFactory, | ||
) { } | ||
|
||
async getVePosition(address: string, baseAddress: string) { | ||
const multicall = this.appToolkit.getMulticall(network); | ||
const baseTokens = await this.appToolkit.getBaseTokenPrices(network); | ||
const baseToken = baseTokens.find(t => t.address === baseAddress)!; | ||
const veToken = multicall.wrap(this.appToolkit.globalContracts.erc20({ address, network })); | ||
const [supplyRaw, decimals, symbol] = await Promise.all([ | ||
veToken.totalSupply(), | ||
veToken.decimals(), | ||
veToken.symbol(), | ||
]); | ||
const supply = Number(supplyRaw) / 10 ** decimals; | ||
const pricePerShare = 1; // Note: Consult liquidity pools for peg once set up | ||
const price = baseToken.price * pricePerShare; | ||
const liquidity = supply * price; | ||
|
||
const token: AppTokenPosition = { | ||
type: ContractType.APP_TOKEN, | ||
appId, | ||
groupId, | ||
address, | ||
network, | ||
symbol, | ||
decimals, | ||
supply, | ||
price, | ||
pricePerShare, | ||
tokens: [baseToken], | ||
dataProps: { liquidity }, | ||
displayProps: { | ||
label: symbol, | ||
secondaryLabel: buildDollarDisplayItem(price), | ||
images: getImagesFromToken(baseToken), | ||
statsItems: [{ label: 'Liquidity', value: buildDollarDisplayItem(liquidity) }], | ||
}, | ||
}; | ||
return token; | ||
} | ||
|
||
async getPositions() { | ||
const [argo] = await Promise.all([ | ||
this.getVePosition(ADDRESSES.xargo, ADDRESSES.argo), | ||
]); | ||
return [argo]; | ||
} | ||
} |