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

Commit

Permalink
fix(vela): Fix VLP and esVela app tokens (#2851)
Browse files Browse the repository at this point in the history
  • Loading branch information
wpoulin authored Jul 29, 2023
1 parent 3313710 commit 4f533b3
Show file tree
Hide file tree
Showing 8 changed files with 1,380 additions and 2,533 deletions.
2 changes: 1 addition & 1 deletion src/apps/vela/arbitrum/vela.es-vela.token-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import { VelaEsVelaTokenFetcher } from '../common/vela.es-vela.token-fetcher';

@PositionTemplate()
export class ArbitrumVelaEsVelaTokenFetcher extends VelaEsVelaTokenFetcher {
esVelaAddress = '0xa9f5606c3e6aab998fd4f4bc54a18d9fe13a0dd8';
esVelaAddress = '0xefd5a713c5bd85e9ced46070b2532e4a47a18102';
velaAddress = '0x088cd8f5ef3652623c22d48b1605dcfe860cd704';
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,7 @@ import { VelaVlpTokenFetcher } from '../common/vela.vlp.token-fetcher';

@PositionTemplate()
export class ArbitrumVelaVlpTokenFetcher extends VelaVlpTokenFetcher {
vlpAddress = '0x4e0d4a5a5b4faf5c2ecc1c63c8d19bb0804a96f1';
vlpAddress = '0xc5b2d9fda8a82e8dcecd5e9e6e99b78a9188eb05';
usdcAddress = '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8';
velaVaultAddress = '0x5957582f020301a2f732ad17a69ab2d8b2741241';

async getApy(): Promise<number> {
return 0;
}

async getPricePerShare(): Promise<number[]> {
return [0];
}
vaultAddress = '0xc4abade3a15064f9e3596943c699032748b13352';
}
10 changes: 4 additions & 6 deletions src/apps/vela/common/vela.es-vela.token-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { VelaContractFactory } from '../contracts';
export abstract class VelaEsVelaTokenFetcher extends AppTokenTemplatePositionFetcher<Erc20> {
groupLabel = 'esVELA';

abstract get esVelaAddress(): string | Promise<string>;
abstract get velaAddress(): string | Promise<string>;
abstract esVelaAddress: string;
abstract velaAddress: string;

constructor(
@Inject(APP_TOOLKIT) protected readonly appToolkit: IAppToolkit,
Expand All @@ -28,13 +28,11 @@ export abstract class VelaEsVelaTokenFetcher extends AppTokenTemplatePositionFet
}

async getAddresses(): Promise<string[]> {
const esVelaAddress = await this.esVelaAddress;
return [esVelaAddress];
return [this.esVelaAddress];
}

async getUnderlyingTokenDefinitions(): Promise<UnderlyingTokenDefinition[]> {
const velaAddress = await this.velaAddress;
return [{ address: velaAddress, network: this.network }];
return [{ address: this.velaAddress, network: this.network }];
}

async getPricePerShare(): Promise<number[]> {
Expand Down
57 changes: 13 additions & 44 deletions src/apps/vela/common/vela.vlp.token-fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,18 @@
import { Inject } from '@nestjs/common';
import axios from 'axios';

import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface';
import { Erc20 } from '~contract/contracts';
import { AppTokenTemplatePositionFetcher } from '~position/template/app-token.template.position-fetcher';
import {
DefaultAppTokenDefinition,
UnderlyingTokenDefinition,
GetPricePerShareParams,
DefaultAppTokenDataProps,
} from '~position/template/app-token.template.types';
import { NETWORK_IDS } from '~types';
import { UnderlyingTokenDefinition, GetPricePerShareParams } from '~position/template/app-token.template.types';

import { VelaContractFactory } from '../contracts';

interface VelaGetVlpAprResponse {
VLP_APR: number;
VELA_APR: number;
TOTAL_APR: number;
}

export abstract class VelaVlpTokenFetcher extends AppTokenTemplatePositionFetcher<Erc20> {
groupLabel = 'vlp';
groupLabel = 'VLP';

abstract get vlpAddress(): string | Promise<string>;
abstract get usdcAddress(): string | Promise<string>;
abstract get velaVaultAddress(): string | Promise<string>;
abstract vlpAddress: string;
abstract usdcAddress: string;
abstract vaultAddress: string;

constructor(
@Inject(APP_TOOLKIT) protected readonly appToolkit: IAppToolkit,
Expand All @@ -42,43 +29,25 @@ export abstract class VelaVlpTokenFetcher extends AppTokenTemplatePositionFetche
}

async getAddresses(): Promise<string[]> {
const vlpAddress = await this.vlpAddress;
return [vlpAddress];
return [this.vlpAddress];
}

async getUnderlyingTokenDefinitions(): Promise<UnderlyingTokenDefinition[]> {
const usdcAddress = await this.usdcAddress;
return [{ address: usdcAddress, network: this.network }];
}

async getApy(): Promise<number> {
try {
const {
data: { VLP_APR },
} = await axios.get<VelaGetVlpAprResponse>(
`https://vela-public-server-prod-qxq2l.ondigitalocean.app/market/vlp-apr/${NETWORK_IDS[this.network]}`,
);
return VLP_APR;
} catch {
return 0;
}
return [{ address: this.usdcAddress, network: this.network }];
}

async getPricePerShare({
multicall,
}: GetPricePerShareParams<Erc20, DefaultAppTokenDataProps, DefaultAppTokenDefinition>): Promise<number[]> {
const velaVaultAddress = await this.velaVaultAddress;
async getPricePerShare({ multicall }: GetPricePerShareParams<Erc20>): Promise<number[]> {
const velaVault = multicall.wrap(
this.velaContractFactory.velaVault({
address: velaVaultAddress,
address: this.vaultAddress,
network: this.network,
}),
);
const [vlpPrice, basisPointsDivisor] = await Promise.all([
velaVault.getVLPPrice(),
velaVault.BASIS_POINTS_DIVISOR(),
]);
const basisPointsDivisor = 100000;

const vlpPrice = await velaVault.getVLPPrice();
const pricePerShare = Number(vlpPrice) / Number(basisPointsDivisor);

return [pricePerShare];
}
}
Loading

0 comments on commit 4f533b3

Please sign in to comment.