This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(y2k finance): add y2k positions adapter for v1 and v2, add vlY2k…
… adapter, add farms adapter for v1 (#2880) Co-authored-by: dev <dev@dev.dev>
- Loading branch information
Showing
31 changed files
with
21,374 additions
and
0 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
src/apps/y2k-finance/arbitrum/y2k-finance.farm-v1.contract-position-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,82 @@ | ||
import { Inject } from '@nestjs/common'; | ||
import { BigNumberish } from 'ethers'; | ||
|
||
import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; | ||
import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; | ||
import { DefaultDataProps } from '~position/display.interface'; | ||
import { MetaType } from '~position/position.interface'; | ||
import { ContractPositionTemplatePositionFetcher } from '~position/template/contract-position.template.position-fetcher'; | ||
import { | ||
GetDefinitionsParams, | ||
DefaultContractPositionDefinition, | ||
GetTokenDefinitionsParams, | ||
UnderlyingTokenDefinition, | ||
GetDisplayPropsParams, | ||
GetTokenBalancesParams, | ||
} from '~position/template/contract-position.template.types'; | ||
|
||
import { Y2KFinanceContractFactory, Y2KFinanceStakingRewards } from '../contracts'; | ||
|
||
const rewardsFactory = '0x9889fca1d9a5d131f5d4306a2bc2f293cafad2f3'; | ||
const fromBlock = 33934362; | ||
|
||
@PositionTemplate() | ||
export class ArbitrumY2KFinanceFarmV1ContractPositionFetcher extends ContractPositionTemplatePositionFetcher<Y2KFinanceStakingRewards> { | ||
groupLabel = 'Farms'; | ||
|
||
constructor( | ||
@Inject(APP_TOOLKIT) protected readonly appToolkit: IAppToolkit, | ||
@Inject(Y2KFinanceContractFactory) protected readonly contractFactory: Y2KFinanceContractFactory, | ||
) { | ||
super(appToolkit); | ||
} | ||
|
||
getContract(address: string): Y2KFinanceStakingRewards { | ||
return this.contractFactory.y2KFinanceStakingRewards({ address, network: this.network }); | ||
} | ||
|
||
async getDefinitions(_params: GetDefinitionsParams): Promise<DefaultContractPositionDefinition[]> { | ||
const factory = this.contractFactory.y2KFinanceRewardsFactory({ address: rewardsFactory, network: this.network }); | ||
const filter = factory.filters.CreatedStakingReward(); | ||
const events = await factory.queryFilter(filter, fromBlock); | ||
const farms = events.map(e => [e.args.hedgeFarm, e.args.riskFarm]).flat(); | ||
return farms.map(farm => ({ address: farm })); | ||
} | ||
|
||
async getTokenDefinitions( | ||
params: GetTokenDefinitionsParams<Y2KFinanceStakingRewards, DefaultContractPositionDefinition>, | ||
): Promise<UnderlyingTokenDefinition[] | null> { | ||
return [ | ||
{ | ||
metaType: MetaType.SUPPLIED, | ||
address: await params.contract.stakingToken(), | ||
network: this.network, | ||
tokenId: (await params.contract.id()).toNumber(), | ||
}, | ||
{ | ||
metaType: MetaType.CLAIMABLE, | ||
address: await params.contract.rewardsToken(), | ||
network: this.network, | ||
}, | ||
]; | ||
} | ||
|
||
async getLabel( | ||
params: GetDisplayPropsParams<Y2KFinanceStakingRewards, DefaultDataProps, DefaultContractPositionDefinition>, | ||
): Promise<string> { | ||
const vault = this.contractFactory.y2KFinanceVaultV1({ | ||
address: await params.contract.stakingToken(), | ||
network: this.network, | ||
}); | ||
const name = await vault.name(); | ||
return `${name} Farming`; | ||
} | ||
|
||
async getTokenBalancesPerPosition( | ||
params: GetTokenBalancesParams<Y2KFinanceStakingRewards, DefaultDataProps>, | ||
): Promise<BigNumberish[]> { | ||
const supply = await params.contract.balanceOf(params.address); | ||
const rewards = await params.contract.earned(params.address); | ||
return [supply, rewards]; | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
src/apps/y2k-finance/arbitrum/y2k-finance.mint-v1.contract-position-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,102 @@ | ||
import { Inject } from '@nestjs/common'; | ||
import { BigNumber, BigNumberish } from 'ethers'; | ||
|
||
import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; | ||
import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; | ||
import { IMulticallWrapper } from '~multicall'; | ||
import { DefaultDataProps } from '~position/display.interface'; | ||
import { MetaType } from '~position/position.interface'; | ||
import { ContractPositionTemplatePositionFetcher } from '~position/template/contract-position.template.position-fetcher'; | ||
import { | ||
GetDefinitionsParams, | ||
DefaultContractPositionDefinition, | ||
GetTokenDefinitionsParams, | ||
UnderlyingTokenDefinition, | ||
GetDisplayPropsParams, | ||
GetTokenBalancesParams, | ||
} from '~position/template/contract-position.template.types'; | ||
|
||
import { Y2KFinanceContractFactory, Y2KFinanceVaultV1 } from '../contracts'; | ||
|
||
const vaultFactory = '0x984e0eb8fb687afa53fc8b33e12e04967560e092'; | ||
|
||
@PositionTemplate() | ||
export class ArbitrumY2KFinanceMintV1ContractPositionFetcher extends ContractPositionTemplatePositionFetcher<Y2KFinanceVaultV1> { | ||
groupLabel = 'Positions'; | ||
|
||
constructor( | ||
@Inject(APP_TOOLKIT) protected readonly appToolkit: IAppToolkit, | ||
@Inject(Y2KFinanceContractFactory) protected readonly contractFactory: Y2KFinanceContractFactory, | ||
) { | ||
super(appToolkit); | ||
} | ||
|
||
async getEpochIds(multicall: IMulticallWrapper, contract: Y2KFinanceVaultV1): Promise<BigNumber[]> { | ||
const vault = multicall.wrap(contract); | ||
const epochsLength = await vault.epochsLength(); | ||
const epochIds = await Promise.all( | ||
Array.from(Array(Number(epochsLength)).keys()).map(async i => await vault.epochs(i)), | ||
); | ||
return epochIds; | ||
} | ||
|
||
getContract(address: string): Y2KFinanceVaultV1 { | ||
return this.contractFactory.y2KFinanceVaultV1({ address, network: this.network }); | ||
} | ||
|
||
async getDefinitions(params: GetDefinitionsParams): Promise<DefaultContractPositionDefinition[]> { | ||
const factory = params.multicall.wrap( | ||
this.contractFactory.y2KFinanceVaultFactoryV1({ address: vaultFactory, network: this.network }), | ||
); | ||
const poolLength = await factory.marketIndex(); | ||
const vaults = ( | ||
await Promise.all(Array.from(Array(Number(poolLength)).keys()).map(async i => await factory.getVaults(i))) | ||
).flat(); | ||
return vaults.map(vault => ({ address: vault })); | ||
} | ||
|
||
async getTokenDefinitions( | ||
params: GetTokenDefinitionsParams<Y2KFinanceVaultV1, DefaultContractPositionDefinition>, | ||
): Promise<UnderlyingTokenDefinition[] | null> { | ||
const epochIds = await this.getEpochIds(params.multicall, params.contract); | ||
const claimableAsset = await params.contract.asset(); | ||
return epochIds | ||
.map(id => [ | ||
{ | ||
metaType: MetaType.SUPPLIED, | ||
address: params.contract.address, | ||
network: this.network, | ||
tokenId: id.toNumber(), | ||
}, | ||
{ | ||
metaType: MetaType.CLAIMABLE, | ||
address: claimableAsset, | ||
network: this.network, | ||
tokenId: id.toNumber(), | ||
}, | ||
]) | ||
.flat(); | ||
} | ||
|
||
async getLabel( | ||
params: GetDisplayPropsParams<Y2KFinanceVaultV1, DefaultDataProps, DefaultContractPositionDefinition>, | ||
): Promise<string> { | ||
const name = await params.contract.name(); | ||
return name; | ||
} | ||
|
||
async getTokenBalancesPerPosition( | ||
params: GetTokenBalancesParams<Y2KFinanceVaultV1, DefaultDataProps>, | ||
): Promise<BigNumberish[]> { | ||
const epochIds = await this.getEpochIds(params.multicall, params.contract); | ||
const vault = params.multicall.wrap(params.contract); | ||
const results = await Promise.all( | ||
epochIds.map(async id => { | ||
const balance = await vault.balanceOf(params.address, id); | ||
const claimable = await vault.previewWithdraw(id, balance); | ||
return [balance, claimable]; | ||
}), | ||
); | ||
return results.flat(); | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
src/apps/y2k-finance/arbitrum/y2k-finance.mint-v2.contract-position-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,97 @@ | ||
import { Inject } from '@nestjs/common'; | ||
import { BigNumberish } from 'ethers'; | ||
|
||
import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; | ||
import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; | ||
import { DefaultDataProps } from '~position/display.interface'; | ||
import { MetaType } from '~position/position.interface'; | ||
import { ContractPositionTemplatePositionFetcher } from '~position/template/contract-position.template.position-fetcher'; | ||
import { | ||
GetDefinitionsParams, | ||
DefaultContractPositionDefinition, | ||
GetTokenDefinitionsParams, | ||
UnderlyingTokenDefinition, | ||
GetDisplayPropsParams, | ||
GetTokenBalancesParams, | ||
} from '~position/template/contract-position.template.types'; | ||
|
||
import { Y2KFinanceCarousel, Y2KFinanceContractFactory } from '../contracts'; | ||
|
||
const carouselFactory = '0xc3179ac01b7d68aed4f27a19510ffe2bfb78ab3e'; | ||
const fromBlock = 96059531; | ||
|
||
@PositionTemplate() | ||
export class ArbitrumY2KFinanceMintV2ContractPositionFetcher extends ContractPositionTemplatePositionFetcher<Y2KFinanceCarousel> { | ||
groupLabel = 'Positions'; | ||
|
||
constructor( | ||
@Inject(APP_TOOLKIT) protected readonly appToolkit: IAppToolkit, | ||
@Inject(Y2KFinanceContractFactory) protected readonly contractFactory: Y2KFinanceContractFactory, | ||
) { | ||
super(appToolkit); | ||
} | ||
|
||
getContract(address: string): Y2KFinanceCarousel { | ||
return this.contractFactory.y2KFinanceCarousel({ address, network: this.network }); | ||
} | ||
|
||
async getDefinitions(_params: GetDefinitionsParams): Promise<DefaultContractPositionDefinition[]> { | ||
const factory = this.contractFactory.y2KFinanceCarouselFactory({ address: carouselFactory, network: this.network }); | ||
const filter = factory.filters.MarketCreated(); | ||
const events = await factory.queryFilter(filter, fromBlock); | ||
const vaults = events.map(e => [e.args.premium, e.args.collateral]).flat(); | ||
return vaults.map(vault => ({ address: vault })); | ||
} | ||
|
||
async getTokenDefinitions( | ||
params: GetTokenDefinitionsParams<Y2KFinanceCarousel, DefaultContractPositionDefinition>, | ||
): Promise<UnderlyingTokenDefinition[] | null> { | ||
const epochIds = await params.contract.getAllEpochs(); | ||
const claimableAsset = await params.contract.asset(); | ||
const emission = await params.contract.emissionsToken(); | ||
return epochIds | ||
.map(id => [ | ||
{ | ||
metaType: MetaType.SUPPLIED, | ||
address: params.contract.address, | ||
network: this.network, | ||
tokenId: id.toNumber(), | ||
}, | ||
{ | ||
metaType: MetaType.CLAIMABLE, | ||
address: claimableAsset, | ||
network: this.network, | ||
tokenId: id.toNumber(), | ||
}, | ||
{ | ||
metaType: MetaType.CLAIMABLE, | ||
address: emission, | ||
network: this.network, | ||
}, | ||
]) | ||
.flat(); | ||
} | ||
|
||
async getLabel( | ||
params: GetDisplayPropsParams<Y2KFinanceCarousel, DefaultDataProps, DefaultContractPositionDefinition>, | ||
): Promise<string> { | ||
const name = await params.contract.name(); | ||
return name; | ||
} | ||
|
||
async getTokenBalancesPerPosition( | ||
params: GetTokenBalancesParams<Y2KFinanceCarousel, DefaultDataProps>, | ||
): Promise<BigNumberish[]> { | ||
const epochIds = await params.contract.getAllEpochs(); | ||
const vault = params.multicall.wrap(params.contract); | ||
const results = await Promise.all( | ||
epochIds.map(async id => { | ||
const balance = await vault.balanceOf(params.address, id); | ||
const claimable = await vault.previewWithdraw(id, balance); | ||
const emission = await vault.previewEmissionsWithdraw(id, balance); | ||
return [balance, claimable, emission]; | ||
}), | ||
); | ||
return results.flat(); | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
src/apps/y2k-finance/arbitrum/y2k-finance.voting-locked.contract-position-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,83 @@ | ||
import { Inject } from '@nestjs/common'; | ||
import { BigNumberish } from 'ethers'; | ||
|
||
import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; | ||
import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; | ||
import { DefaultDataProps } from '~position/display.interface'; | ||
import { MetaType } from '~position/position.interface'; | ||
import { ContractPositionTemplatePositionFetcher } from '~position/template/contract-position.template.position-fetcher'; | ||
import { | ||
GetDefinitionsParams, | ||
DefaultContractPositionDefinition, | ||
GetTokenDefinitionsParams, | ||
UnderlyingTokenDefinition, | ||
GetDisplayPropsParams, | ||
GetTokenBalancesParams, | ||
} from '~position/template/contract-position.template.types'; | ||
|
||
import { Y2KFinanceContractFactory, Y2KFinanceVotingLocked } from '../contracts'; | ||
|
||
const VLY2K = [ | ||
{ | ||
address: '0xbdaa858fd7b0dc05f8256330facb35de86283ca0', | ||
}, | ||
{ | ||
address: '0xaefd22d0153e69f3316dca9095e7279b3a2f8af2', | ||
}, | ||
]; | ||
|
||
@PositionTemplate() | ||
export class ArbitrumY2KFinanceVotingLockedContractPositionFetcher extends ContractPositionTemplatePositionFetcher<Y2KFinanceVotingLocked> { | ||
groupLabel = 'Vote Locked Y2K'; | ||
|
||
constructor( | ||
@Inject(APP_TOOLKIT) protected readonly appToolkit: IAppToolkit, | ||
@Inject(Y2KFinanceContractFactory) protected readonly contractFactory: Y2KFinanceContractFactory, | ||
) { | ||
super(appToolkit); | ||
} | ||
|
||
getContract(address: string): Y2KFinanceVotingLocked { | ||
return this.contractFactory.y2KFinanceVotingLocked({ address, network: this.network }); | ||
} | ||
|
||
async getDefinitions(_params: GetDefinitionsParams): Promise<DefaultContractPositionDefinition[]> { | ||
return VLY2K; | ||
} | ||
|
||
async getTokenDefinitions( | ||
params: GetTokenDefinitionsParams<Y2KFinanceVotingLocked, DefaultContractPositionDefinition>, | ||
): Promise<UnderlyingTokenDefinition[] | null> { | ||
return [ | ||
{ | ||
metaType: MetaType.SUPPLIED, | ||
address: await params.contract.lockToken(), | ||
network: this.network, | ||
}, | ||
{ | ||
metaType: MetaType.CLAIMABLE, | ||
address: (await params.contract.rewardToken(0)).addr, | ||
network: this.network, | ||
}, | ||
{ | ||
metaType: MetaType.CLAIMABLE, | ||
address: (await params.contract.rewardToken(1)).addr, | ||
network: this.network, | ||
}, | ||
]; | ||
} | ||
|
||
async getLabel( | ||
params: GetDisplayPropsParams<Y2KFinanceVotingLocked, DefaultDataProps, DefaultContractPositionDefinition>, | ||
): Promise<string> { | ||
const epochs = await params.contract.minEpochs(); | ||
return `Lock${epochs.toString()}Rewards`; | ||
} | ||
|
||
async getTokenBalancesPerPosition( | ||
params: GetTokenBalancesParams<Y2KFinanceVotingLocked, DefaultDataProps>, | ||
): Promise<BigNumberish[]> { | ||
const info = await params.contract.getAccount(params.address); | ||
return [info.balance, info.rewards1, info.rewards2]; | ||
} | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.