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

Commit

Permalink
fix(studio): More failing position fetchers (#3046)
Browse files Browse the repository at this point in the history
  • Loading branch information
immasandwich authored Nov 14, 2023
1 parent 2d6c240 commit fac3641
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ export const ARBITRUM_CAULDRONS: AbracadabraCauldronContractPositionDefinition[]
{ version: 'V4', type: 'REGULAR', address: '0x726413d7402ff180609d0ebc79506df8633701b1' }, // magicGLP
];

export const ARBITRUM_GLP_TOKEN_ADDRESS = '0x4277f8f2c384827b5273592ff7cebd9f2c1ac258';
export const AVALANCHE_GLP_TOKEN_ADDRESS = '0x01234181085565ed162a948b6a5e88758cd7c7b8';

export const CURVE_MIM_3POOL_FARM = '0x839de324a1ab773f76a53900d70ac1b913d2b387';

export const M_SPELL_ADDRESS = '0x1df188958a8674b5177f77667b8d173c3cdd9e51';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { PositionTemplate } from '~app-toolkit/decorators/position-template.deco
import { AbracadabraMagicGlpTokenFetcher } from '../common/abracadabra.magic-glp.token-fetcher';

import {
ARBITRUM_GLP_TOKEN_ADDRESS,
GLP_REWARD_TRACKER_ADDRESSES,
MAGIC_GLP_ADDRESS,
MAGIC_GLP_ANNUAL_HARVESTS,
Expand All @@ -15,4 +16,5 @@ export class ArbitrumAbracadabraMagicGlpTokenFetcher extends AbracadabraMagicGlp
rewardTrackerAddresses = GLP_REWARD_TRACKER_ADDRESSES;
magicGlpHarvestorAddress = MAGIC_GLP_HARVESTOR_ADDRESS;
magicGlpAnnualHarvests = MAGIC_GLP_ANNUAL_HARVESTS;
glpTokenAddress = ARBITRUM_GLP_TOKEN_ADDRESS;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator';

import { AVALANCHE_GLP_TOKEN_ADDRESS } from '../arbitrum/abracadabra.arbitrum.constants';
import { HOURS_PER_YEAR } from '../common/abracadabra.common.constants';
import { AbracadabraMagicGlpTokenFetcher } from '../common/abracadabra.magic-glp.token-fetcher';

Expand All @@ -9,4 +10,5 @@ export class AvalancheAbracadabraMagicGlpTokenFetcher extends AbracadabraMagicGl
rewardTrackerAddresses = ['0xd2d1162512f927a7e282ef43a362659e4f2a728f', '0x9e295b5b976a184b14ad8cd72413ad846c299660'];
magicGlpHarvestorAddress = '0x05b3b96df07b4630373ae7506e51777b547335b0';
magicGlpAnnualHarvests = HOURS_PER_YEAR;
glpTokenAddress = AVALANCHE_GLP_TOKEN_ADDRESS;
}
13 changes: 3 additions & 10 deletions src/apps/abracadabra/common/abracadabra.magic-glp.token-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const BASIS_POINTS_DIVISOR = 10000;

export abstract class AbracadabraMagicGlpTokenFetcher extends Erc4626VaultTemplateTokenFetcher {
groupLabel = 'Magic GLP';
abstract glpTokenAddress: string;
abstract get rewardTrackerAddresses(): string[] | Promise<string>[];
abstract get magicGlpHarvestorAddress(): string | Promise<string>;
abstract get magicGlpAnnualHarvests(): number | Promise<number>;
Expand All @@ -32,17 +33,9 @@ export abstract class AbracadabraMagicGlpTokenFetcher extends Erc4626VaultTempla
super(appToolkit);
}

// Override as the underlying is sGLP, but users expect to see GLP
async getUnderlyingTokenDefinitions(): Promise<UnderlyingTokenDefinition[]> {
const glpTokenDefinitions = await this.appToolkit.getAppTokenPositionsFromDatabase({
appId: 'gmx',
groupIds: ['glp'],
network: this.network,
});

const glpUnderlying = glpTokenDefinitions[0];

return [{ address: glpUnderlying.address, network: this.network }];
// Override as the underlying is sGLP, but users expect to see GLP
return [{ address: this.glpTokenAddress, network: this.network }];
}

async getLabel({ contract }: GetDisplayPropsParams<Erc4626>): Promise<string> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { TeahouseVaultsTokenFetcher } from '../common/teahouse.vaults.token-fetc
export class ArbitrumTeahouseVaultsTokenFetcher extends TeahouseVaultsTokenFetcher {
groupLabel = 'Vault share';

queryFilterFromBlock = 84086498;
fromBlock = 84086498;

async getAddresses() {
return ['0x9f4fff022ebff0cbfa3faf702911d0f658a4ba9b'];
Expand Down
13 changes: 8 additions & 5 deletions src/apps/teahouse/common/teahouse.vaults.token-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { TeahouseViemContractFactory } from '../contracts';
import { TeahouseVault } from '../contracts/viem';

export abstract class TeahouseVaultsTokenFetcher extends AppTokenTemplatePositionFetcher<TeahouseVault> {
fromBlock: number | null;
fromBlock: number;

constructor(
@Inject(APP_TOOLKIT) protected readonly appToolkit: IAppToolkit,
Expand All @@ -32,20 +32,23 @@ export abstract class TeahouseVaultsTokenFetcher extends AppTokenTemplatePositio
const globalState = await contract.read.globalState();
const currentIndex = globalState[2];

const enterNextCycleEvent = await contract.getEvents.EnterNextCycle(
const enterNextCycleEvents = await contract.getEvents.EnterNextCycle(
{ cycleIndex: currentIndex - 1 },
{ fromBlock: this.fromBlock ? BigInt(this.fromBlock) : undefined, toBlock: 'latest' },
{ fromBlock: BigInt(this.fromBlock), toBlock: 'latest' },
);

const priceNumerator = enterNextCycleEvent[0].args.priceNumerator;
const priceDenominator = enterNextCycleEvent[0].args.priceDenominator;
if (!enterNextCycleEvents.length) return [0];

const priceNumerator = enterNextCycleEvents[0].args.priceNumerator;
const priceDenominator = enterNextCycleEvents[0].args.priceDenominator;
const pricePerShare =
BigNumber.from(priceNumerator)
.mul('1' + '0'.repeat(shareDecimals))
.mul(100000000)
.div(BigNumber.from(priceDenominator))
.div('1' + '0'.repeat(assetDecimals))
.toNumber() / 100000000;

return [pricePerShare];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { TeahouseVaultsTokenFetcher } from '../common/teahouse.vaults.token-fetc
@PositionTemplate()
export class EthereumTeahouseVaultsTokenFetcher extends TeahouseVaultsTokenFetcher {
groupLabel = 'Vault share';
fromBlock = 15615676;

async getAddresses() {
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { TeahouseVaultsTokenFetcher } from '../common/teahouse.vaults.token-fetc
export class OptimismTeahouseVaultsTokenFetcher extends TeahouseVaultsTokenFetcher {
groupLabel = 'Vault share';

queryFilterFromBlock = 53274656;
fromBlock = 53274656;

async getAddresses() {
return ['0x9ae039f9de94542f6f1b3fba60223e6aa4f411af', '0xee1e02609a480bdc9d9651c200d90222b6691f03'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
GetDisplayPropsParams,
} from '~position/template/app-token.template.types';

import { UmamiFinanceYieldResolver } from '../common/umami-finance.yield-resolver';
import { UmamiFinanceViemContractFactory } from '../contracts';
import { UmamiFinanceCompound } from '../contracts/viem';

Expand All @@ -20,8 +19,6 @@ export class ArbitrumUmamiFinanceCompoundTokenFetcher extends AppTokenTemplatePo

constructor(
@Inject(APP_TOOLKIT) protected readonly appToolkit: IAppToolkit,
@Inject(UmamiFinanceYieldResolver)
private readonly yieldResolver: UmamiFinanceYieldResolver,
@Inject(UmamiFinanceViemContractFactory) protected readonly contractFactory: UmamiFinanceViemContractFactory,
) {
super(appToolkit);
Expand Down Expand Up @@ -62,11 +59,6 @@ export class ArbitrumUmamiFinanceCompoundTokenFetcher extends AppTokenTemplatePo
return [reserve];
}

async getApy(_params: GetDataPropsParams<UmamiFinanceCompound>) {
const { apy } = await this.yieldResolver.getStakingYield();
return Number(apy);
}

async getImages({ appToken }: GetDisplayPropsParams<UmamiFinanceCompound>): Promise<string[]> {
return [getTokenImg(appToken.address, this.network)];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ import {
GetPricePerShareParams,
DefaultAppTokenDataProps,
GetDisplayPropsParams,
GetDataPropsParams,
} from '~position/template/app-token.template.types';

import { UmamiFinanceGlpVaultAddress } from '../common/umami-finance.constants';
import { UmamiFinanceYieldResolver } from '../common/umami-finance.yield-resolver';
import { UmamiFinanceViemContractFactory } from '../contracts';
import { UmamiFinanceGlpVault } from '../contracts/viem/UmamiFinanceGlpVault';

Expand All @@ -35,8 +33,6 @@ export class ArbitrumUmamiFinanceGlpVaultsTokenFetcher extends AppTokenTemplateP

constructor(
@Inject(APP_TOOLKIT) protected readonly appToolkit: IAppToolkit,
@Inject(UmamiFinanceYieldResolver)
private readonly yieldResolver: UmamiFinanceYieldResolver,
@Inject(UmamiFinanceViemContractFactory)
private readonly umamiFinanceContractFactory: UmamiFinanceViemContractFactory,
) {
Expand Down Expand Up @@ -93,10 +89,4 @@ export class ArbitrumUmamiFinanceGlpVaultsTokenFetcher extends AppTokenTemplateP
>): Promise<string[]> {
return [getTokenImg(appToken.address, this.network)];
}

async getApy(
_params: GetDataPropsParams<UmamiFinanceGlpVault, DefaultAppTokenDataProps, UmamiFinanceGlpVaultAppTokenDefinition>,
): Promise<number> {
return this.yieldResolver.getVaultYield(_params.address);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface';
import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator';
import { getTokenImg } from '~app-toolkit/helpers/presentation/image.present';
import { AppTokenTemplatePositionFetcher } from '~position/template/app-token.template.position-fetcher';
import { GetDataPropsParams, GetDisplayPropsParams } from '~position/template/app-token.template.types';
import { GetDisplayPropsParams } from '~position/template/app-token.template.types';

import { UmamiFinanceYieldResolver } from '../common/umami-finance.yield-resolver';
import { UmamiFinanceViemContractFactory } from '../contracts';
import { UmamiFinanceMarinate } from '../contracts/viem';

Expand All @@ -17,8 +16,6 @@ export class ArbitrumUmamiFinanceMarinateUmamiTokenFetcher extends AppTokenTempl

constructor(
@Inject(APP_TOOLKIT) protected readonly appToolkit: IAppToolkit,
@Inject(UmamiFinanceYieldResolver)
private readonly yieldResolver: UmamiFinanceYieldResolver,
@Inject(UmamiFinanceViemContractFactory) protected readonly contractFactory: UmamiFinanceViemContractFactory,
) {
super(appToolkit);
Expand All @@ -40,11 +37,6 @@ export class ArbitrumUmamiFinanceMarinateUmamiTokenFetcher extends AppTokenTempl
return [1];
}

async getApy(_params: GetDataPropsParams<UmamiFinanceMarinate>) {
const { apr } = await this.yieldResolver.getStakingYield();
return Number(apr);
}

async getImages({ appToken }: GetDisplayPropsParams<UmamiFinanceMarinate>): Promise<string[]> {
return [getTokenImg(appToken.address, this.network)];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ import {
UnderlyingTokenDefinition,
GetPricePerShareParams,
GetDisplayPropsParams,
GetDataPropsParams,
} from '~position/template/app-token.template.types';

import { UmamiFinanceTimelockedGlpVaultAddress } from '../common/umami-finance.constants';
import { UmamiFinanceYieldResolver } from '../common/umami-finance.yield-resolver';
import { UmamiFinanceViemContractFactory } from '../contracts';
import { UmamiFinanceTimelockedGlpVault } from '../contracts/viem/UmamiFinanceTimelockedGlpVault';

Expand All @@ -25,8 +23,6 @@ export class ArbitrumUmamiFinanceTimelockedGlpVaultsTokenFetcher extends AppToke

constructor(
@Inject(APP_TOOLKIT) protected readonly appToolkit: IAppToolkit,
@Inject(UmamiFinanceYieldResolver)
private readonly yieldResolver: UmamiFinanceYieldResolver,
@Inject(UmamiFinanceViemContractFactory)
private readonly umamiFinanceContractFactory: UmamiFinanceViemContractFactory,
) {
Expand Down Expand Up @@ -73,8 +69,4 @@ export class ArbitrumUmamiFinanceTimelockedGlpVaultsTokenFetcher extends AppToke
async getImages({ appToken }: GetDisplayPropsParams<UmamiFinanceTimelockedGlpVault>): Promise<string[]> {
return [getTokenImg(appToken.address, this.network)];
}

async getApy({ address }: GetDataPropsParams<UmamiFinanceTimelockedGlpVault>): Promise<number> {
return this.yieldResolver.getVaultYield(address, true);
}
}
54 changes: 0 additions & 54 deletions src/apps/umami-finance/common/umami-finance.yield-resolver.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/apps/umami-finance/umami-finance.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { ArbitrumUmamiFinanceGlpVaultsTokenFetcher } from './arbitrum/umami-fina
import { ArbitrumUmamiFinanceMarinateUmamiTokenFetcher } from './arbitrum/umami-finance.marinate-umami.token-fetcher';
import { ArbitrumUmamiFinanceMarinateContractPositionFetcher } from './arbitrum/umami-finance.marinate.contract-position-fetcher';
import { ArbitrumUmamiFinanceTimelockedGlpVaultsTokenFetcher } from './arbitrum/umami-finance.timelocked-glp-vaults.token-fetcher';
import { UmamiFinanceYieldResolver } from './common/umami-finance.yield-resolver';
import { UmamiFinanceViemContractFactory } from './contracts';

@Module({
Expand All @@ -18,7 +17,6 @@ import { UmamiFinanceViemContractFactory } from './contracts';
ArbitrumUmamiFinanceMarinateUmamiTokenFetcher,
ArbitrumUmamiFinanceTimelockedGlpVaultsTokenFetcher,
UmamiFinanceViemContractFactory,
UmamiFinanceYieldResolver,
],
})
export class UmamiFinanceAppModule extends AbstractApp() {}

0 comments on commit fac3641

Please sign in to comment.