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

Commit

Permalink
feat(teahouse): Add token-fetcher for Teahouse Vaults on Ethereum and…
Browse files Browse the repository at this point in the history
… Optimism (#2455)

* feature (teahouse): add token-fetcher for Teahouse Vaults on Ethereum and Optimism

* feat(teahouse):Add token-fetcher for Teahouse Vaults on Ethereum and Optimism

---------

Co-authored-by: William Poulin <[email protected]>
  • Loading branch information
ajak1124 and wpoulin authored Mar 22, 2023
1 parent 876d77c commit 7c0d32b
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 64 deletions.
2 changes: 1 addition & 1 deletion src/apps/teahouse/contracts/ethers/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* Autogenerated file. Do not edit manually. */
/* tslint:disable */
/* eslint-disable */
export type { TeahouseVault } from './TeahouseVault';
export type { TeahouseVault} from './TeahouseVault';
export * as factories from './factories';
export { TeahouseVault__factory } from './factories/TeahouseVault__factory';
58 changes: 58 additions & 0 deletions src/apps/teahouse/ethereum/teahouse.vaults.token-fetcher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { Inject } from '@nestjs/common';

import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface';
import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator';
import { AppTokenTemplatePositionFetcher } from '~position/template/app-token.template.position-fetcher';
import { GetUnderlyingTokensParams } from '~position/template/app-token.template.types';

import { TeahouseVault, TeahouseContractFactory } from '../contracts';

@PositionTemplate()
export class EthereumTeahouseVaultsTokenFetcher extends AppTokenTemplatePositionFetcher<TeahouseVault> {
groupLabel = 'Vault share';

constructor(
@Inject(APP_TOOLKIT) protected readonly appToolkit: IAppToolkit,
@Inject(TeahouseContractFactory) protected readonly contractFactory: TeahouseContractFactory,
) {
super(appToolkit);
}

getContract(address: string) {
return this.contractFactory.teahouseVault({ network: this.network, address });
}

async getAddresses() {
return [
'0xe1b3c128c0d0a9e41ab3ff8f0984e5d5bef81677',
'0xb54e2764bef6994245527f75eb8f180c484c404d',
'0x478afa95f40bf5504cff32796c20bfd0b4e38330',
'0x9ed9c1c0f1c68666668a7aedec5fec95abc7f943',
];
}

async getUnderlyingTokenDefinitions({ contract }: GetUnderlyingTokensParams<TeahouseVault>) {
return [{ address: await contract.asset(), network: this.network }];
}

async getPricePerShare({ contract }) {
const assetAddress = await contract.asset();
const assetContract = this.getContract(assetAddress);
const assetDecimals = await assetContract.decimals();
const shareDecimals = await contract.decimals();
const globalState = await contract.globalState();
const currentIndex = globalState[2];
const enterNextCycleEventFilter = await contract.filters.EnterNextCycle(null, currentIndex - 1);
const enterNextCycleEvent = await contract.queryFilter(enterNextCycleEventFilter, null, null);
const priceNumerator = enterNextCycleEvent[0].args.priceNumerator;
const priceDenominator = enterNextCycleEvent[0].args.priceDenominator;
const pricePerShare =
priceNumerator
.mul('1' + '0'.repeat(shareDecimals))
.mul(100000000)
.div(priceDenominator)
.div('1' + '0'.repeat(assetDecimals))
.toNumber() / 100000000;
return [pricePerShare];
}
}

This file was deleted.

53 changes: 53 additions & 0 deletions src/apps/teahouse/optimism/teahouse.vaults.token-fetcher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { Inject } from '@nestjs/common';

import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface';
import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator';
import { AppTokenTemplatePositionFetcher } from '~position/template/app-token.template.position-fetcher';
import { GetUnderlyingTokensParams } from '~position/template/app-token.template.types';

import { TeahouseVault, TeahouseContractFactory } from '../contracts';

@PositionTemplate()
export class OptimismTeahouseVaultsTokenFetcher extends AppTokenTemplatePositionFetcher<TeahouseVault> {
groupLabel = 'Vault share';

constructor(
@Inject(APP_TOOLKIT) protected readonly appToolkit: IAppToolkit,
@Inject(TeahouseContractFactory) protected readonly contractFactory: TeahouseContractFactory,
) {
super(appToolkit);
}

getContract(address: string) {
return this.contractFactory.teahouseVault({ network: this.network, address });
}

async getAddresses() {
return ['0x9ae039f9de94542f6f1b3fba60223e6aa4f411af', '0xee1e02609a480bdc9d9651c200d90222b6691f03'];
}

async getUnderlyingTokenDefinitions({ contract }: GetUnderlyingTokensParams<TeahouseVault>) {
return [{ address: await contract.asset(), network: this.network }];
}

async getPricePerShare({ contract }) {
const assetAddress = await contract.asset();
const assetContract = this.getContract(assetAddress);
const assetDecimals = await assetContract.decimals();
const shareDecimals = await contract.decimals();
const globalState = await contract.globalState();
const currentIndex = globalState[2];
const enterNextCycleEventFilter = await contract.filters.EnterNextCycle(null, currentIndex - 1);
const enterNextCycleEvent = await contract.queryFilter(enterNextCycleEventFilter, null, null);
const priceNumerator = enterNextCycleEvent[0].args.priceNumerator;
const priceDenominator = enterNextCycleEvent[0].args.priceDenominator;
const pricePerShare =
priceNumerator
.mul('1' + '0'.repeat(shareDecimals))
.mul(100000000)
.div(priceDenominator)
.div('1' + '0'.repeat(assetDecimals))
.toNumber() / 100000000;
return [pricePerShare];
}
}
10 changes: 4 additions & 6 deletions src/apps/teahouse/teahouse.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import { Module } from '@nestjs/common';
import { AbstractApp } from '~app/app.dynamic-module';

import { TeahouseContractFactory } from './contracts';
import { OptimismTeahouseVaultsContractPositionFetcher } from './optimism/teahouse.vaults.contract-position-fetcher';
import { EthereumTeahouseVaultsTokenFetcher } from './ethereum/teahouse.vaults.token-fetcher';
import { OptimismTeahouseVaultsTokenFetcher } from './optimism/teahouse.vaults.token-fetcher';

@Module({
providers: [
TeahouseContractFactory,
OptimismTeahouseVaultsContractPositionFetcher,
],
providers: [TeahouseContractFactory, EthereumTeahouseVaultsTokenFetcher, OptimismTeahouseVaultsTokenFetcher],
})
export class TeahouseAppModule extends AbstractApp() { }
export class TeahouseAppModule extends AbstractApp() {}

0 comments on commit 7c0d32b

Please sign in to comment.