Skip to content

Commit

Permalink
Merge pull request #2 from 0xoats/develop
Browse files Browse the repository at this point in the history
feat: add token fetcher
  • Loading branch information
0xKratos authored Jun 18, 2022
2 parents 68e5561 + f13ec51 commit e1485a3
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 7 deletions.
18 changes: 18 additions & 0 deletions .env.sample
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=
2 changes: 0 additions & 2 deletions src/apps/argo-finance/argo-finance.definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ export const ARGO_FINANCE_DEFINITION = appDefinition({
url: 'https://www.argofinance.money/',

groups: {

pledging: {
id: 'pledging',
type: GroupType.POSITION,
label: 'Pledging',
},

},

tags: [AppTag.LIQUID_STAKING],
Expand Down
6 changes: 4 additions & 2 deletions src/apps/argo-finance/argo-finance.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ import { ArgoFinanceAppDefinition, ARGO_FINANCE_DEFINITION } from './argo-financ
import { ArgoFinanceContractFactory } from './contracts';
import { CronosArgoFinanceBalanceFetcher } from './cronos/argo-finance.balance-fetcher';
import { CronosArgoFinancePledgingContractPositionFetcher } from './cronos/argo-finance.pledging.contract-position-fetcher';
import { CronosArgoFinancePledgingTokenFetcher } from './cronos/argo-finance.pledging.token-fetcher';

@Register.AppModule({
appId: ARGO_FINANCE_DEFINITION.id,
providers: [
ArgoFinanceAppDefinition,
ArgoFinanceContractFactory,
CronosArgoFinanceBalanceFetcher,
CronosArgoFinancePledgingContractPositionFetcher
CronosArgoFinancePledgingContractPositionFetcher,
CronosArgoFinancePledgingTokenFetcher,
],
})
export class ArgoFinanceAppModule extends AbstractApp() { }
export class ArgoFinanceAppModule extends AbstractApp() {}
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ export class CronosArgoFinancePledgingContractPositionFetcher implements Positio
async getVePosition(address: string, baseAddress: string) {
const multicall = this.appToolkit.getMulticall(network);
const baseTokens = await this.appToolkit.getBaseTokenPrices(network);
let baseToken = baseTokens.find(t => t.address === baseAddress)!;
const contractTokens = await this.appToolkit.getAppTokenPositions({
appId,
groupIds: [groupId],
network,
})
let baseToken = contractTokens.find(t => t.symbol === 'xARGO')!;
let croToken = baseTokens.find(t => t.symbol === "WCRO")!;
baseToken.symbol = "xARGO";
baseToken.address = "0xb966B5D6A0fCd5b373B180Bbe072BBFbbEe10552";
const veToken = multicall.wrap(this.appToolkit.globalContracts.erc20({ address, network }));
const [supplyRaw, decimals, symbol] = await Promise.all([
veToken.totalSupply(),
Expand Down
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];
}
}

0 comments on commit e1485a3

Please sign in to comment.