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 vaults on Arbitrum (#2773)
Browse files Browse the repository at this point in the history
  • Loading branch information
wpoulin committed Jun 26, 2023
1 parent 105da1f commit ae60595
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
53 changes: 53 additions & 0 deletions src/apps/teahouse/arbitrum/teahouse.vaults.token-fetcher.ts
@@ -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 ArbitrumTeahouseVaultsTokenFetcher 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 ['0x9f4fff022ebff0cbfa3faf702911d0f658a4ba9b'];
}

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];
}
}
8 changes: 7 additions & 1 deletion src/apps/teahouse/teahouse.module.ts
Expand Up @@ -2,11 +2,17 @@ import { Module } from '@nestjs/common';

import { AbstractApp } from '~app/app.dynamic-module';

import { ArbitrumTeahouseVaultsTokenFetcher } from './arbitrum/teahouse.vaults.token-fetcher';
import { TeahouseContractFactory } from './contracts';
import { EthereumTeahouseVaultsTokenFetcher } from './ethereum/teahouse.vaults.token-fetcher';
import { OptimismTeahouseVaultsTokenFetcher } from './optimism/teahouse.vaults.token-fetcher';

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

0 comments on commit ae60595

Please sign in to comment.