This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 383
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(teahouse): Add token-fetcher for Teahouse Vaults on Ethereum and…
… 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
Showing
5 changed files
with
116 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
58
src/apps/teahouse/ethereum/teahouse.vaults.token-fetcher.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} | ||
} |
57 changes: 0 additions & 57 deletions
57
src/apps/teahouse/optimism/teahouse.vaults.contract-position-fetcher.ts
This file was deleted.
Oops, something went wrong.
53 changes: 53 additions & 0 deletions
53
src/apps/teahouse/optimism/teahouse.vaults.token-fetcher.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters