Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
feat(redacted-cartel): add support for claimable rewards (#2274)
Browse files Browse the repository at this point in the history
* feat(redacted-cartel): remove old fetcher

* feat(redacted-cartel): add new fetcher

---------

Co-authored-by: William Poulin <[email protected]>
  • Loading branch information
0xalecks and wpoulin authored Feb 10, 2023
1 parent 98c48e9 commit 99efbbb
Showing 1 changed file with 54 additions and 18 deletions.
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];
}
}

0 comments on commit 99efbbb

Please sign in to comment.