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

feat(gamma-strategies): add some farm contracts #2467

Merged
merged 4 commits into from
Mar 27, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
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 {
MasterChefTemplateContractPositionFetcher,
GetMasterChefDataPropsParams,
GetMasterChefTokenBalancesParams,
RewardRateUnit,
} from '~position/template/master-chef.template.contract-position-fetcher';

import { GammaStrategiesContractFactory, GammaStrategiesZyberswapMasterchef } from '../contracts';

@PositionTemplate()
export class ArbitrumGammaStrategiesZyberFarmContractPositionFetcher extends MasterChefTemplateContractPositionFetcher<GammaStrategiesZyberswapMasterchef> {
groupLabel = 'Farms';
chefAddress = '0x9ba666165867e916ee7ed3a3ae6c19415c2fbddd';
rewardRateUnit = RewardRateUnit.SECOND;

constructor(
@Inject(APP_TOOLKIT) protected readonly appToolkit: IAppToolkit,
@Inject(GammaStrategiesContractFactory) protected readonly contractFactory: GammaStrategiesContractFactory,
) {
super(appToolkit);
}

getContract(address: string): GammaStrategiesZyberswapMasterchef {
return this.contractFactory.gammaStrategiesZyberswapMasterchef({ address, network: this.network });
}

async getPoolLength(contract: GammaStrategiesZyberswapMasterchef) {
return contract.poolLength();
}

async getStakedTokenAddress(contract: GammaStrategiesZyberswapMasterchef, poolIndex: number) {
return contract.poolInfo(poolIndex).then(v => v.lpToken.toLowerCase());
}

async getRewardTokenAddress(contract: GammaStrategiesZyberswapMasterchef) {
return (await contract.zyber()).toLowerCase();
}

async getTotalAllocPoints({
contract,
}: GetMasterChefDataPropsParams<GammaStrategiesZyberswapMasterchef>): Promise<BigNumberish> {
return contract.totalAllocPoint();
}

async getTotalRewardRate({
contract,
}: GetMasterChefDataPropsParams<GammaStrategiesZyberswapMasterchef>): Promise<BigNumberish> {
return contract.zyberPerSec();
}

async getPoolAllocPoints({
contract,
definition,
}: GetMasterChefDataPropsParams<GammaStrategiesZyberswapMasterchef>): Promise<BigNumberish> {
return contract.poolInfo(definition.poolIndex).then(v => v.allocPoint);
}

async getStakedTokenBalance({
address,
contract,
contractPosition,
}: GetMasterChefTokenBalancesParams<GammaStrategiesZyberswapMasterchef>): Promise<BigNumberish> {
const result = await contract.userInfo(contractPosition.dataProps.poolIndex, address).then(v => v.amount);
return result;
}

async getRewardTokenBalance(): Promise<BigNumberish> {
// TODO: this is actually a non-standard masterchefv2
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,29 @@ type Pool = {
};
};

const dataSources = {
[Network.ARBITRUM_MAINNET]: ['/arbitrum', '/zyberswap/arbitrum'],
[Network.ETHEREUM_MAINNET]: [''],
[Network.OPTIMISM_MAINNET]: ['/optimism'],
[Network.POLYGON_MAINNET]: ['/polygon', '/quickswap/polygon'],
[Network.CELO_MAINNET]: ['/celo'],
};

@Injectable()
export class GammaStrategiesDefinitionResolver {
@Cache({
key: (network: Network) => `studio:gamma:${network}:vaults`,
ttl: 30 * 60, // 30 min
})
async getPoolDefinitionsData(network: Network) {
const url =
network == Network.ETHEREUM_MAINNET
? 'https://wire2.gamma.xyz/hypervisors/allData'
: `https://gammawire.net/${network}/hypervisors/allData`;
const urls = dataSources[network];
const data = await Promise.all(
urls.map((path: string) => this._getPoolDefinitionsData(`https://wire2.gamma.xyz${path}/hypervisors/allData`)),
);
return Object.assign({}, ...data) as GammaApiTokensResponse;
}

async _getPoolDefinitionsData(url: string) {
const { data } = await Axios.get<GammaApiTokensResponse>(url);
return data;
}
Expand All @@ -39,7 +50,6 @@ export class GammaStrategiesDefinitionResolver {
const defintionsRaw = definitionsDataRaw.map(([key, value]) => {
return Number(value.returns.allTime.feeApy) > 0 ? { address: key.toLowerCase() } : null;
});

return _.compact(defintionsRaw);
}
}
Loading