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(redacted-cartel): add support for claimable rewards (#2274)
* feat(redacted-cartel): remove old fetcher * feat(redacted-cartel): add new fetcher --------- Co-authored-by: William Poulin <[email protected]>
- Loading branch information
Showing
1 changed file
with
54 additions
and
18 deletions.
There are no files selected for viewing
72 changes: 54 additions & 18 deletions
72
src/apps/redacted-cartel/ethereum/redacted-cartel.revenue-lock.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 |
---|---|---|
@@ -1,50 +1,86 @@ | ||
import { Inject } from '@nestjs/common'; | ||
import { BigNumberish } from 'ethers'; | ||
import axios from 'axios'; | ||
import { BigNumberish, Contract } from 'ethers'; | ||
|
||
import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; | ||
import { ZERO_ADDRESS } from '~app-toolkit/constants/address'; | ||
import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; | ||
import { getLabelFromToken } from '~app-toolkit/helpers/presentation/image.present'; | ||
import { DefaultDataProps } from '~position/display.interface'; | ||
import { MetaType } from '~position/position.interface'; | ||
import { isSupplied } from '~position/position.utils'; | ||
import { ContractPositionTemplatePositionFetcher } from '~position/template/contract-position.template.position-fetcher'; | ||
import { | ||
GetDefinitionsParams, | ||
DefaultContractPositionDefinition, | ||
GetTokenDefinitionsParams, | ||
GetTokenBalancesParams, | ||
UnderlyingTokenDefinition, | ||
GetDisplayPropsParams, | ||
GetTokenBalancesParams, | ||
} from '~position/template/contract-position.template.types'; | ||
import { VotingEscrowTemplateContractPositionFetcher } from '~position/template/voting-escrow.template.contract-position-fetcher'; | ||
|
||
import { RedactedCartelContractFactory, RedactedRevenueLock } from '../contracts'; | ||
|
||
@PositionTemplate() | ||
export class EthereumRedactedCartelRevenueLockContractPositionFetcher extends VotingEscrowTemplateContractPositionFetcher<RedactedRevenueLock> { | ||
export class EthereumRedactedCartelRevenueLockContractPositionFetcher extends ContractPositionTemplatePositionFetcher<RedactedRevenueLock> { | ||
groupLabel = 'Revenue Lock'; | ||
|
||
veTokenAddress = '0x742b70151cd3bc7ab598aaff1d54b90c3ebc6027'; | ||
rewardAddress = '0x74c6cade3ef61d64dcc9b97490d9fbb231e4bdcc'; | ||
rlBTRFLY = '0x742b70151cd3bc7ab598aaff1d54b90c3ebc6027'; | ||
BTRFLYv2 = '0xc55126051b22ebb829d00368f4b12bde432de5da'; | ||
|
||
constructor( | ||
@Inject(APP_TOOLKIT) protected readonly appToolkit: IAppToolkit, | ||
@Inject(RedactedCartelContractFactory) protected readonly contractFactory: RedactedCartelContractFactory, | ||
@Inject(RedactedCartelContractFactory) | ||
protected readonly contractFactory: RedactedCartelContractFactory, | ||
) { | ||
super(appToolkit); | ||
} | ||
|
||
getEscrowContract(address: string): RedactedRevenueLock { | ||
getContract(address: string): RedactedRevenueLock { | ||
return this.contractFactory.redactedRevenueLock({ address, network: this.network }); | ||
} | ||
|
||
async getEscrowedTokenAddress({ contract }: GetTokenDefinitionsParams<RedactedRevenueLock>) { | ||
return contract.btrflyV2(); | ||
async getDefinitions(_params: GetDefinitionsParams): Promise<DefaultContractPositionDefinition[]> { | ||
return [{ address: this.rlBTRFLY }]; | ||
} | ||
|
||
async getEscrowedTokenBalance({ | ||
address, | ||
contract, | ||
}: GetTokenBalancesParams<RedactedRevenueLock>): Promise<BigNumberish> { | ||
return (await contract.lockedBalances(address)).locked; | ||
async getTokenDefinitions( | ||
_params: GetTokenDefinitionsParams<Contract, DefaultContractPositionDefinition>, | ||
): Promise<UnderlyingTokenDefinition[] | null> { | ||
return [ | ||
{ | ||
metaType: MetaType.SUPPLIED, | ||
address: this.BTRFLYv2, | ||
network: this.network, | ||
}, | ||
{ | ||
metaType: MetaType.CLAIMABLE, | ||
address: this.BTRFLYv2, | ||
network: this.network, | ||
}, | ||
{ | ||
metaType: MetaType.CLAIMABLE, | ||
address: ZERO_ADDRESS, | ||
network: this.network, | ||
}, | ||
]; | ||
} | ||
|
||
async getLabel({ contractPosition }: GetDisplayPropsParams<RedactedRevenueLock>) { | ||
async getLabel({ | ||
contractPosition, | ||
}: GetDisplayPropsParams<Contract, DefaultDataProps, DefaultContractPositionDefinition>): Promise<string> { | ||
const suppliedToken = contractPosition.tokens.find(isSupplied)!; | ||
return `Revenue Lock ${getLabelFromToken(suppliedToken)}`; | ||
return `Voting Escrow ${getLabelFromToken(suppliedToken)}`; | ||
} | ||
|
||
async getTokenBalancesPerPosition({ | ||
address, | ||
contract, | ||
}: GetTokenBalancesParams<Contract, DefaultDataProps>): Promise<BigNumberish[]> { | ||
const lockedBalances = await contract.lockedBalances(address); | ||
const { data } = await axios.get(`https://app.redacted.finance/api/rewards/1/${address}`, { headers: {} }); | ||
const ethRewards = data?.data?.find(t => t.symbol === 'ETH'); | ||
const btrRewards = data?.data?.find(t => t.symbol === 'BTRFLY'); | ||
|
||
return [lockedBalances.total, btrRewards?.claimable, ethRewards?.claimable]; | ||
} | ||
} |