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(velodrome): Move to templates (#1310)
- Loading branch information
1 parent
6ea68eb
commit aabbda6
Showing
7 changed files
with
204 additions
and
245 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
81 changes: 81 additions & 0 deletions
81
src/apps/velodrome/optimism/velodrome.farm.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,81 @@ | ||
import { Inject } from '@nestjs/common'; | ||
import axios from 'axios'; | ||
import { range } from 'lodash'; | ||
|
||
import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface'; | ||
import { Register } from '~app-toolkit/decorators'; | ||
import { isClaimable } from '~position/position.utils'; | ||
import { | ||
GetTokenDefinitionsParams, | ||
GetDataPropsParams, | ||
GetTokenBalancesParams, | ||
} from '~position/template/contract-position.template.types'; | ||
import { | ||
SingleStakingFarmDataProps, | ||
SingleStakingFarmDynamicTemplateContractPositionFetcher, | ||
} from '~position/template/single-staking.dynamic.template.contract-position-fetcher'; | ||
import { Network } from '~types/network.interface'; | ||
|
||
import { VelodromeContractFactory, VelodromeGauge } from '../contracts'; | ||
import { VELODROME_DEFINITION } from '../velodrome.definition'; | ||
|
||
import { VelodromeApiPairData } from './velodrome.pool.token-fetcher'; | ||
|
||
const appId = VELODROME_DEFINITION.id; | ||
const groupId = VELODROME_DEFINITION.groups.farm.id; | ||
const network = Network.OPTIMISM_MAINNET; | ||
|
||
@Register.ContractPositionFetcher({ appId, groupId, network }) | ||
export class OptimismVelodromeStakingContractPositionFetcher extends SingleStakingFarmDynamicTemplateContractPositionFetcher<VelodromeGauge> { | ||
appId = appId; | ||
groupId = groupId; | ||
network = network; | ||
groupLabel = 'Staking'; | ||
|
||
constructor( | ||
@Inject(APP_TOOLKIT) protected readonly appToolkit: IAppToolkit, | ||
@Inject(VelodromeContractFactory) protected readonly contractFactory: VelodromeContractFactory, | ||
) { | ||
super(appToolkit); | ||
} | ||
|
||
getContract(address: string): VelodromeGauge { | ||
return this.contractFactory.velodromeGauge({ address, network: this.network }); | ||
} | ||
|
||
async getFarmAddresses() { | ||
const { data } = await axios.get<{ data: VelodromeApiPairData[] }>('https://api.velodrome.finance/api/v1/pairs'); | ||
const gaugeAddresses = data.data.map(pool => pool.gauge_address).filter(v => !!v); | ||
return gaugeAddresses; | ||
} | ||
|
||
async getStakedTokenAddress({ contract }: GetTokenDefinitionsParams<VelodromeGauge>) { | ||
return contract.stake(); | ||
} | ||
|
||
async getRewardTokenAddresses({ contract }: GetTokenDefinitionsParams<VelodromeGauge>) { | ||
const numRewards = Number(await contract.rewardsListLength()); | ||
return Promise.all(range(numRewards).map(async n => await contract.rewards(n))); | ||
} | ||
|
||
getRewardRates({ contract, contractPosition }: GetDataPropsParams<VelodromeGauge, SingleStakingFarmDataProps>) { | ||
const rewardTokens = contractPosition.tokens.filter(isClaimable); | ||
return Promise.all(rewardTokens.map(rt => contract.rewardPerToken(rt.address))); | ||
} | ||
|
||
async getStakedTokenBalance({ | ||
address, | ||
contract, | ||
}: GetTokenBalancesParams<VelodromeGauge, SingleStakingFarmDataProps>) { | ||
return contract.balanceOf(address); | ||
} | ||
|
||
getRewardTokenBalances({ | ||
address, | ||
contract, | ||
contractPosition, | ||
}: GetTokenBalancesParams<VelodromeGauge, SingleStakingFarmDataProps>) { | ||
const rewardTokens = contractPosition.tokens.filter(isClaimable); | ||
return Promise.all(rewardTokens.map(rt => contract.earned(rt.address, address))); | ||
} | ||
} |
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
70 changes: 0 additions & 70 deletions
70
src/apps/velodrome/optimism/velodrome.staking.contract-position-fetcher.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.