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

feat: add trader-joe app #265

Merged
merged 5 commits into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/app-toolkit/app-toolkit.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import { MasterChefContractPositionHelper } from './helpers/master-chef/master-c
import { MasterChefDefaultClaimableBalanceStrategy } from './helpers/master-chef/master-chef.default.claimable-token-balances-strategy';
import { MasterChefDefaultRewardRateStrategy } from './helpers/master-chef/master-chef.default.reward-token-reward-rate-strategy';
import { MasterChefDefaultStakedBalanceStrategy } from './helpers/master-chef/master-chef.default.staked-token-balance-strategy';
import { MasterChefRewarderClaimableBalanceStrategy } from './helpers/master-chef/master-chef.rewarder.claimable-token-balances-strategy';
import { MasterChefRewarderClaimableTokenStrategy } from './helpers/master-chef/master-chef.rewarder.claimable-token-strategy';
import { MasterChefV2ClaimableBalanceStrategy } from './helpers/master-chef/master-chef.v2.claimable-token-balance-strategy';
import { MasterChefV2ClaimableTokenStrategy } from './helpers/master-chef/master-chef.v2.claimable-token-strategy';
import { MasterChefV2RewardRateStrategy } from './helpers/master-chef/master-chef.v2.reward-rate-strategy';
import { SingleStakingFarmContractPositionHelper } from './helpers/position/single-staking-farm.contract-position-helper';
import { SingleVaultTokenHelper } from './helpers/position/single-vault.token-helper';
import { TheGraphHelper } from './helpers/the-graph/the-graph.helper';
Expand All @@ -26,8 +27,9 @@ export const AppToolkitHelpers = [
MasterChefDefaultClaimableBalanceStrategy,
MasterChefDefaultRewardRateStrategy,
MasterChefDefaultStakedBalanceStrategy,
MasterChefRewarderClaimableBalanceStrategy,
MasterChefRewarderClaimableTokenStrategy,
MasterChefV2ClaimableBalanceStrategy,
MasterChefV2ClaimableTokenStrategy,
MasterChefV2RewardRateStrategy,
];

@Injectable()
Expand All @@ -52,9 +54,11 @@ export class AppToolkitHelperRegistry {
public readonly masterChefDefaultRewardsPerBlockStrategy: MasterChefDefaultRewardRateStrategy,
@Inject(MasterChefDefaultStakedBalanceStrategy)
public readonly masterChefDefaultStakedBalanceStrategy: MasterChefDefaultStakedBalanceStrategy,
@Inject(MasterChefRewarderClaimableBalanceStrategy)
public readonly masterChefRewarderClaimableBalanceStrategy: MasterChefRewarderClaimableBalanceStrategy,
@Inject(MasterChefRewarderClaimableTokenStrategy)
public readonly masterChefRewarderClaimableTokenStrategy: MasterChefRewarderClaimableTokenStrategy,
@Inject(MasterChefV2ClaimableBalanceStrategy)
public readonly masterChefV2ClaimableBalanceStrategy: MasterChefV2ClaimableBalanceStrategy,
@Inject(MasterChefV2ClaimableTokenStrategy)
public readonly masterChefV2ClaimableTokenStrategy: MasterChefV2ClaimableTokenStrategy,
@Inject(MasterChefV2RewardRateStrategy)
public readonly masterChefV2RewardRateStrategy: MasterChefV2RewardRateStrategy,
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { MasterChefClaimableTokenBalanceStrategy } from './master-chef.contract-
import { MasterChefContractPositionDataProps } from './master-chef.contract-position-helper';
import { MasterChefDefaultClaimableBalanceStrategy } from './master-chef.default.claimable-token-balances-strategy';

export type MasterChefRewarderClaimableBalanceStrategyParams<T, V> = {
export type MasterChefV2ClaimableBalanceStrategyParams<T, V> = {
resolvePrimaryClaimableBalance: (opts: {
address: string;
multicall: Multicall;
Expand All @@ -34,7 +34,7 @@ export type MasterChefRewarderClaimableBalanceStrategyParams<T, V> = {
};

@Injectable()
export class MasterChefRewarderClaimableBalanceStrategy {
export class MasterChefV2ClaimableBalanceStrategy {
constructor(
@Inject(forwardRef(() => MasterChefDefaultClaimableBalanceStrategy))
private readonly masterChefDefaultClaimableBalanceStrategy: MasterChefDefaultClaimableBalanceStrategy,
Expand All @@ -45,7 +45,7 @@ export class MasterChefRewarderClaimableBalanceStrategy {
resolveRewarderAddress,
resolveRewarderContract,
resolveSecondaryClaimableBalance,
}: MasterChefRewarderClaimableBalanceStrategyParams<T, V>): MasterChefClaimableTokenBalanceStrategy<T> {
}: MasterChefV2ClaimableBalanceStrategyParams<T, V>): MasterChefClaimableTokenBalanceStrategy<T> {
const primaryStrategy = this.masterChefDefaultClaimableBalanceStrategy.build({
resolveClaimableBalance: resolvePrimaryClaimableBalance,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Network } from '~types/network.interface';

import { MasterChefRewardTokenAddressesStrategy } from './master-chef.contract-position-helper';

export type MasterChefRewarderClaimableTokenStrategyParams<T, V> = {
export type MasterChefV2ClaimableTokenStrategyParams<T, V> = {
resolvePrimaryClaimableToken: (opts: { multicall: Multicall; contract: T }) => Promise<string>;
resolveRewarderAddress: (opts: { multicall: Multicall; poolIndex: number; contract: T }) => Promise<string>;
resolveRewarderContract: (opts: { rewarderAddress: string; network: Network }) => V;
Expand All @@ -19,13 +19,13 @@ export type MasterChefRewarderClaimableTokenStrategyParams<T, V> = {
};

@Injectable()
export class MasterChefRewarderClaimableTokenStrategy {
export class MasterChefV2ClaimableTokenStrategy {
build<T, V>({
resolvePrimaryClaimableToken,
resolveRewarderAddress,
resolveRewarderContract,
resolveSecondaryClaimableToken,
}: MasterChefRewarderClaimableTokenStrategyParams<T, V>): MasterChefRewardTokenAddressesStrategy<T> {
}: MasterChefV2ClaimableTokenStrategyParams<T, V>): MasterChefRewardTokenAddressesStrategy<T> {
return async opts => {
// Resolve the reward token address from the primary chef contract
const primaryRewardTokenAddress = await resolvePrimaryClaimableToken(opts);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { Injectable } from '@nestjs/common';
import { BigNumberish } from 'ethers';
import { isArray } from 'lodash';

import { ZERO_ADDRESS } from '~app-toolkit/constants/address';
import { EthersMulticall as Multicall } from '~multicall/multicall.ethers';
import { Network } from '~types/network.interface';

import { MasterChefRewardRateStrategy } from './master-chef.contract-position-helper';

export type MasterChefV2RewardRateStrategyParams<T, V> = {
resolveTotalAllocPoints: (opts: {
network: Network;
contract: T;
multicall: Multicall;
poolIndex: number;
}) => BigNumberish | Promise<BigNumberish>;
resolvePoolAllocPoints: (opts: {
network: Network;
contract: T;
multicall: Multicall;
poolIndex: number;
}) => BigNumberish | Promise<BigNumberish>;
resolvePrimaryTotalRewardRate: (opts: {
network: Network;
contract: T;
multicall: Multicall;
poolIndex: number;
}) => Promise<BigNumberish | BigNumberish[]>;
resolveRewarderAddress: (opts: { multicall: Multicall; poolIndex: number; contract: T }) => Promise<string>;
resolveRewarderContract: (opts: { rewarderAddress: string; network: Network }) => V;
resolveSecondaryTotalRewardRate: (opts: {
multicall: Multicall;
poolIndex: number;
rewarderContract: V;
}) => Promise<BigNumberish | BigNumberish[]>;
resolveRewardMultiplier?: (opts: {
network: Network;
contract: T;
multicall: Multicall;
poolIndex: number;
}) => Promise<BigNumberish | BigNumberish[]>;
};

@Injectable()
export class MasterChefV2RewardRateStrategy {
build<T, V>({
resolvePoolAllocPoints,
resolveTotalAllocPoints,
resolvePrimaryTotalRewardRate,
resolveRewarderAddress,
resolveRewarderContract,
resolveSecondaryTotalRewardRate,
resolveRewardMultiplier = async () => [1],
}: MasterChefV2RewardRateStrategyParams<T, V>): MasterChefRewardRateStrategy<T> {
return async opts => {
// Resolve the reward allocations and reward per block from the primary chef contract
const [totalAllocPoints, primaryTotalRewardRate, poolAllocPoints, rewardMultiplier] = await Promise.all([
resolveTotalAllocPoints(opts),
resolvePrimaryTotalRewardRate(opts),
resolvePoolAllocPoints(opts),
resolveRewardMultiplier(opts),
]);

// Resolve additional rewarder address
const rewarderAddressRaw = await resolveRewarderAddress(opts);
const rewarderAddress = rewarderAddressRaw.toLowerCase();

// Retrieve bonus token total reward per block if there's a valid rewarder
const totalRewardRate = [primaryTotalRewardRate];
if (rewarderAddress !== ZERO_ADDRESS) {
const rewarderContract = resolveRewarderContract({ rewarderAddress, ...opts });
const secondaryTotalRewardRate = await resolveSecondaryTotalRewardRate({ rewarderContract, ...opts });
const secondaryTotalRewardRates = isArray(secondaryTotalRewardRate)
? secondaryTotalRewardRate
: [secondaryTotalRewardRate];
totalRewardRate.push(...secondaryTotalRewardRates);
}

// Calculate reward per block for the given pool's share
const share = Number(poolAllocPoints) / Number(totalAllocPoints);
const rewardRate = totalRewardRate.map((v, i) => share * Number(v) * Number(rewardMultiplier[i] ?? 1));
return rewardRate;
};
}
}
8 changes: 4 additions & 4 deletions src/app-toolkit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export { MasterChefContractPositionHelper } from './helpers/master-chef/master-c
export { MasterChefDefaultClaimableBalanceStrategy } from './helpers/master-chef/master-chef.default.claimable-token-balances-strategy';
export { MasterChefDefaultRewardRateStrategy as MasterChefDefaultRewardsPerBlockStrategy } from './helpers/master-chef/master-chef.default.reward-token-reward-rate-strategy';
export { MasterChefDefaultStakedBalanceStrategy } from './helpers/master-chef/master-chef.default.staked-token-balance-strategy';
export { MasterChefRewarderClaimableBalanceStrategy } from './helpers/master-chef/master-chef.rewarder.claimable-token-balances-strategy';
export { MasterChefRewarderClaimableTokenStrategy } from './helpers/master-chef/master-chef.rewarder.claimable-token-strategy';
export { MasterChefV2ClaimableBalanceStrategy } from './helpers/master-chef/master-chef.v2.claimable-token-balance-strategy';
export { MasterChefV2ClaimableTokenStrategy } from './helpers/master-chef/master-chef.v2.claimable-token-strategy';
export { SingleStakingFarmContractPositionHelper } from './helpers/position/single-staking-farm.contract-position-helper';
export { SingleVaultTokenHelper } from './helpers/position/single-vault.token-helper';

Expand All @@ -33,8 +33,8 @@ export type {
export type { MasterChefDefaultClaimableBalanceStrategyParams } from './helpers/master-chef/master-chef.default.claimable-token-balances-strategy';
export type { MasterChefDefaultRewardRateStrategyParams as MasterChefDefaultRewardsPerBlockStrategyParams } from './helpers/master-chef/master-chef.default.reward-token-reward-rate-strategy';
export type { MasterChefDefaultStakedBalanceStrategyParams } from './helpers/master-chef/master-chef.default.staked-token-balance-strategy';
export type { MasterChefRewarderClaimableBalanceStrategyParams } from './helpers/master-chef/master-chef.rewarder.claimable-token-balances-strategy';
export type { MasterChefRewarderClaimableTokenStrategyParams } from './helpers/master-chef/master-chef.rewarder.claimable-token-strategy';
export type { MasterChefV2ClaimableBalanceStrategyParams } from './helpers/master-chef/master-chef.v2.claimable-token-balance-strategy';
export type { MasterChefV2ClaimableTokenStrategyParams } from './helpers/master-chef/master-chef.v2.claimable-token-strategy';
export type {
SingleStakingContractStrategy,
SingleStakingStakedTokenBalanceStrategy,
Expand Down
2 changes: 1 addition & 1 deletion src/apps/pickle/arbitrum/pickle.balance-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class ArbitrumPickleBalanceFetcher implements BalanceFetcher {
.userInfo(contractPosition.dataProps.poolIndex, address)
.then(v => v.amount),
}),
resolveClaimableTokenBalances: this.appToolkit.helpers.masterChefRewarderClaimableBalanceStrategy.build<
resolveClaimableTokenBalances: this.appToolkit.helpers.masterChefV2ClaimableBalanceStrategy.build<
PickleMiniChefV2,
PickleRewarder
>({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class ArbitrumPickleFarmContractPositionFetcher implements PositionFetche
}),
resolvePoolLength: ({ multicall, contract }) => multicall.wrap(contract).poolLength(),
resolveDepositTokenAddress: ({ poolIndex, contract, multicall }) => multicall.wrap(contract).lpToken(poolIndex),
resolveRewardTokenAddresses: this.appToolkit.helpers.masterChefRewarderClaimableTokenStrategy.build<
resolveRewardTokenAddresses: this.appToolkit.helpers.masterChefV2ClaimableTokenStrategy.build<
PickleMiniChefV2,
PickleRewarder
>({
Expand Down
2 changes: 1 addition & 1 deletion src/apps/pickle/polygon/pickle.balance-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class PolygonPickleBalanceFetcher implements BalanceFetcher {
.userInfo(contractPosition.dataProps.poolIndex, address)
.then(v => v.amount),
}),
resolveClaimableTokenBalances: this.appToolkit.helpers.masterChefRewarderClaimableBalanceStrategy.build<
resolveClaimableTokenBalances: this.appToolkit.helpers.masterChefV2ClaimableBalanceStrategy.build<
PickleMiniChefV2,
PickleRewarder
>({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class PolygonPickleFarmContractPositionFetcher implements PositionFetcher
}),
resolvePoolLength: ({ multicall, contract }) => multicall.wrap(contract).poolLength(),
resolveDepositTokenAddress: ({ poolIndex, contract, multicall }) => multicall.wrap(contract).lpToken(poolIndex),
resolveRewardTokenAddresses: this.appToolkit.helpers.masterChefRewarderClaimableTokenStrategy.build<
resolveRewardTokenAddresses: this.appToolkit.helpers.masterChefV2ClaimableTokenStrategy.build<
PickleMiniChefV2,
PickleRewarder
>({
Expand Down
Loading