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

feat(abracadabra): Add support for new cauldrons and mSPELL #367

Merged
merged 7 commits into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 2 additions & 0 deletions src/apps/abracadabra/abracadabra.definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const ABRACADABRA_DEFINITION = appDefinition({
id: 'abracadabra',
groups: {
stakedSpell: { id: 'staked-spell', type: GroupType.TOKEN },
mSpell: { id: 'm-spell', type: GroupType.POSITION },
cauldron: { id: 'cauldron', type: GroupType.POSITION },
farm: { id: 'farm', type: GroupType.POSITION },
},
Expand All @@ -26,6 +27,7 @@ export const ABRACADABRA_DEFINITION = appDefinition({
[Network.AVALANCHE_MAINNET]: [AppAction.VIEW],
[Network.ETHEREUM_MAINNET]: [AppAction.VIEW],
[Network.FANTOM_OPERA_MAINNET]: [AppAction.VIEW],
[Network.BINANCE_SMART_CHAIN_MAINNET]: [AppAction.VIEW],
},
});

Expand Down
13 changes: 13 additions & 0 deletions src/apps/abracadabra/abracadabra.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,24 @@ import { AbracadabraAppDefinition, ABRACADABRA_DEFINITION } from './abracadabra.
import { ArbitrumAbracadabraBalanceFetcher } from './arbitrum/abracadabra.balance-fetcher';
import { ArbitrumAbracadabraCauldronContractPositionFetcher } from './arbitrum/abracadabra.cauldron.contract-position-fetcher';
import { ArbitrumAbracadabraFarmContractPositionFetcher } from './arbitrum/abracadabra.farm.contract-position-fetcher';
import { ArbitrumAbracadabraMspellContractPositionFetcher } from './arbitrum/abracadabra.m-spell.contract-position-fetcher';
import { ArbitrumAbracadabraStakedSpellTokenFetcher } from './arbitrum/abracadabra.staked-spell.token-fetcher';
import { AvalancheAbracadabraBalanceFetcher } from './avalanche/abracadabra.balance-fetcher';
import { AvalancheAbracadabraCauldronContractPositionFetcher } from './avalanche/abracadabra.cauldron.contract-position-fetcher';
import { AvalancheAbracadabraFarmContractPositionFetcher } from './avalanche/abracadabra.farm.contract-position-fetcher';
import { AvalancheAbracadabraMspellContractPositionFetcher } from './avalanche/abracadabra.m-spell.contract-position-fetcher';
import { AvalancheAbracadabraStakedSpellTokenFetcher } from './avalanche/abracadabra.staked-spell.token-fetcher';
import { BinanceSmartChainAbracadabraBalanceFetcher } from './binance-smart-chain/abracadabra.balance-fetcher';
import { BinanceSmartChainAbracadabraCauldronContractPositionFetcher } from './binance-smart-chain/abracadabra.cauldron.contract-position-fetcher';
import { AbracadabraContractFactory } from './contracts';
import { EthereumAbracadabraBalanceFetcher } from './ethereum/abracadabra.balance-fetcher';
import { EthereumAbracadabraCauldronContractPositionFetcher } from './ethereum/abracadabra.cauldron.contract-position-fetcher';
import { EthereumAbracadabraFarmContractPositionFetcher } from './ethereum/abracadabra.farm.contract-position-fetcher';
import { EthereumAbracadabraMspellContractPositionFetcher } from './ethereum/abracadabra.m-spell.contract-position-fetcher';
import { EthereumAbracadabraStakedSpellTokenFetcher } from './ethereum/abracadabra.staked-spell.token-fetcher';
import { FantomAbracadabraBalanceFetcher } from './fantom/abracadabra.balance-fetcher';
import { FantomAbracadabraCauldronContractPositionFetcher } from './fantom/abracadabra.cauldron.contract-position-fetcher';
import { FantomAbracadabraMspellContractPositionFetcher } from './fantom/abracadabra.m-spell.contract-position-fetcher';
import { FantomAbracadabraFarmContractPositionFetcher } from './fantom/abracadbra.farm.contract-position-fetcher';
import { FantomAbracadabraStakedSpellTokenFetcher } from './fantom/abracadbra.staked-spell.token-fetcher';
import { AbracadabraCauldronBalanceHelper } from './helpers/abracadabra.cauldron.balance-helper';
Expand All @@ -34,21 +40,28 @@ import { AbracadabraCauldronContractPositionHelper } from './helpers/abracadabra
ArbitrumAbracadabraCauldronContractPositionFetcher,
ArbitrumAbracadabraFarmContractPositionFetcher,
ArbitrumAbracadabraBalanceFetcher,
ArbitrumAbracadabraMspellContractPositionFetcher,
// Avalanche
AvalancheAbracadabraStakedSpellTokenFetcher,
AvalancheAbracadabraCauldronContractPositionFetcher,
AvalancheAbracadabraFarmContractPositionFetcher,
AvalancheAbracadabraBalanceFetcher,
AvalancheAbracadabraMspellContractPositionFetcher,
// Ethereum
EthereumAbracadabraStakedSpellTokenFetcher,
EthereumAbracadabraCauldronContractPositionFetcher,
EthereumAbracadabraFarmContractPositionFetcher,
EthereumAbracadabraBalanceFetcher,
EthereumAbracadabraMspellContractPositionFetcher,
// Fantom
FantomAbracadabraStakedSpellTokenFetcher,
FantomAbracadabraCauldronContractPositionFetcher,
FantomAbracadabraFarmContractPositionFetcher,
FantomAbracadabraBalanceFetcher,
FantomAbracadabraMspellContractPositionFetcher,
// Binance Smart Chain
BinanceSmartChainAbracadabraCauldronContractPositionFetcher,
BinanceSmartChainAbracadabraBalanceFetcher,
// Helpers
AbracadabraCauldronBalanceHelper,
AbracadabraCauldronContractPositionHelper,
Expand Down
38 changes: 36 additions & 2 deletions src/apps/abracadabra/arbitrum/abracadabra.balance-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface';
import { Register } from '~app-toolkit/decorators';
import { presentBalanceFetcherResponse } from '~app-toolkit/helpers/presentation/balance-fetcher-response.present';
import { BalanceFetcher } from '~balance/balance-fetcher.interface';
import { MetaType } from '~position/position.interface';
import { Network } from '~types/network.interface';

import { ABRACADABRA_DEFINITION } from '../abracadabra.definition';
import { AbracadabraContractFactory, PopsicleChef } from '../contracts';
import { AbracadabraContractFactory, PopsicleChef, AbracadabraMspell } from '../contracts';
import { AbracadabraCauldronBalanceHelper } from '../helpers/abracadabra.cauldron.balance-helper';

const appId = ABRACADABRA_DEFINITION.id;
const network = Network.ARBITRUM_MAINNET;

@Register.BalanceFetcher(ABRACADABRA_DEFINITION.id, network)
Expand All @@ -19,6 +21,7 @@ export class ArbitrumAbracadabraBalanceFetcher implements BalanceFetcher {
@Inject(AbracadabraCauldronBalanceHelper)
private readonly abracadabraCauldronBalanceHelper: AbracadabraCauldronBalanceHelper,
@Inject(AbracadabraContractFactory) private readonly contractFactory: AbracadabraContractFactory,
@Inject(AbracadabraContractFactory) private readonly abracadabraContractFactory: AbracadabraContractFactory,
melenxyz marked this conversation as resolved.
Show resolved Hide resolved
) {}

private async getStakedSpellBalances(address: string) {
Expand Down Expand Up @@ -57,10 +60,11 @@ export class ArbitrumAbracadabraBalanceFetcher implements BalanceFetcher {
}

async getBalances(address: string) {
const [stakedSpellBalances, cauldronBalances, farmBalances] = await Promise.all([
const [stakedSpellBalances, cauldronBalances, farmBalances, mspellBalances] = await Promise.all([
this.getStakedSpellBalances(address),
this.getCauldronBalances(address),
this.getFarmBalances(address),
this.getMspellBalance(address),
]);

return presentBalanceFetcherResponse([
Expand All @@ -76,6 +80,36 @@ export class ArbitrumAbracadabraBalanceFetcher implements BalanceFetcher {
label: 'Farms',
assets: farmBalances,
},
{
label: 'mSPELL',
assets: mspellBalances,
},
]);
}
private async getMspellBalance(address: string) {
return this.appToolkit.helpers.singleStakingContractPositionBalanceHelper.getBalances<AbracadabraMspell>({
address,
appId,
network,
groupId: ABRACADABRA_DEFINITION.groups.mSpell.id,
resolveContract: opts => this.abracadabraContractFactory.abracadabraMspell(opts),
resolveStakedTokenBalance: ({ multicall, contract, contractPosition }) => {
const tokenAddress = contractPosition.tokens.find(v => v.metaType === MetaType.CLAIMABLE)?.address;
if (!tokenAddress) {
throw new Error(`Could not find claimable token for ${contractPosition.address} ${contractPosition.network}`);
}
melenxyz marked this conversation as resolved.
Show resolved Hide resolved
return multicall
.wrap(contract)
.userInfo(address)
.then(v => v[0]);
},
resolveRewardTokenBalances: ({ multicall, contract, contractPosition }) => {
const tokenAddress = contractPosition.tokens.find(v => v.metaType === MetaType.CLAIMABLE)?.address;
if (!tokenAddress) {
throw new Error(`Could not find claimable token for ${contractPosition.address} ${contractPosition.network}`);
}
melenxyz marked this conversation as resolved.
Show resolved Hide resolved
return multicall.wrap(contract).pendingReward(address);
},
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Inject } from '@nestjs/common';

import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface';
import { Register } from '~app-toolkit/decorators';
import { PositionFetcher } from '~position/position-fetcher.interface';
import { ContractPosition } from '~position/position.interface';
import { Network } from '~types/network.interface';

import { ABRACADABRA_DEFINITION } from '../abracadabra.definition';
import { AbracadabraContractFactory, AbracadabraMspell } from '../contracts';

const appId = ABRACADABRA_DEFINITION.id;
const groupId = ABRACADABRA_DEFINITION.groups.mSpell.id;
const network = Network.ARBITRUM_MAINNET;
@Register.ContractPositionFetcher({ appId, groupId, network })
export class ArbitrumAbracadabraMspellContractPositionFetcher implements PositionFetcher<ContractPosition> {
constructor(
@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit,
@Inject(AbracadabraContractFactory)
private readonly contractFactory: AbracadabraContractFactory,
) {}

async getPositions() {
return this.appToolkit.helpers.singleStakingFarmContractPositionHelper.getContractPositions<AbracadabraMspell>({
appId,
groupId,
network,
resolveFarmAddresses: async () => ['0x1df188958a8674b5177f77667b8d173c3cdd9e51'],
resolveStakedTokenAddress: async ({ multicall, contract }) => multicall.wrap(contract).spell(),
resolveFarmContract: opts => this.contractFactory.abracadabraMspell(opts),
resolveRewardTokenAddresses: async ({ multicall, contract }) => multicall.wrap(contract).mim(),
resolveRois: () => ({ dailyROI: 0, weeklyROI: 0, yearlyROI: 0 }),
});
}
}
38 changes: 36 additions & 2 deletions src/apps/abracadabra/avalanche/abracadabra.balance-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface';
import { Register } from '~app-toolkit/decorators';
import { presentBalanceFetcherResponse } from '~app-toolkit/helpers/presentation/balance-fetcher-response.present';
import { BalanceFetcher } from '~balance/balance-fetcher.interface';
import { MetaType } from '~position/position.interface';
import { Network } from '~types/network.interface';

import { ABRACADABRA_DEFINITION } from '../abracadabra.definition';
import { AbracadabraContractFactory, PopsicleChef } from '../contracts';
import { AbracadabraContractFactory, PopsicleChef, AbracadabraMspell } from '../contracts';
import { AbracadabraCauldronBalanceHelper } from '../helpers/abracadabra.cauldron.balance-helper';

const appId = ABRACADABRA_DEFINITION.id;
const network = Network.AVALANCHE_MAINNET;

@Register.BalanceFetcher(ABRACADABRA_DEFINITION.id, network)
Expand All @@ -19,6 +21,7 @@ export class AvalancheAbracadabraBalanceFetcher implements BalanceFetcher {
@Inject(AbracadabraCauldronBalanceHelper)
private readonly abracadabraCauldronBalanceHelper: AbracadabraCauldronBalanceHelper,
@Inject(AbracadabraContractFactory) private readonly contractFactory: AbracadabraContractFactory,
@Inject(AbracadabraContractFactory) private readonly abracadabraContractFactory: AbracadabraContractFactory,
melenxyz marked this conversation as resolved.
Show resolved Hide resolved
) {}

private async getStakedSpellBalances(address: string) {
Expand Down Expand Up @@ -57,10 +60,11 @@ export class AvalancheAbracadabraBalanceFetcher implements BalanceFetcher {
}

async getBalances(address: string) {
const [stakedSpellBalances, cauldronBalances, farmBalances] = await Promise.all([
const [stakedSpellBalances, cauldronBalances, farmBalances, mspellBalances] = await Promise.all([
this.getStakedSpellBalances(address),
this.getCauldronBalances(address),
this.getFarmBalances(address),
this.getMspellBalance(address),
]);

return presentBalanceFetcherResponse([
Expand All @@ -76,6 +80,36 @@ export class AvalancheAbracadabraBalanceFetcher implements BalanceFetcher {
label: 'Farms',
assets: farmBalances,
},
{
label: 'mSPELL',
assets: mspellBalances,
},
]);
}
private async getMspellBalance(address: string) {
return this.appToolkit.helpers.singleStakingContractPositionBalanceHelper.getBalances<AbracadabraMspell>({
address,
appId,
network,
groupId: ABRACADABRA_DEFINITION.groups.mSpell.id,
resolveContract: opts => this.abracadabraContractFactory.abracadabraMspell(opts),
resolveStakedTokenBalance: ({ multicall, contract, contractPosition }) => {
const tokenAddress = contractPosition.tokens.find(v => v.metaType === MetaType.CLAIMABLE)?.address;
if (!tokenAddress) {
throw new Error(`Could not find claimable token for ${contractPosition.address} ${contractPosition.network}`);
}
melenxyz marked this conversation as resolved.
Show resolved Hide resolved
return multicall
.wrap(contract)
.userInfo(address)
.then(v => v[0]);
},
resolveRewardTokenBalances: ({ multicall, contract, contractPosition }) => {
const tokenAddress = contractPosition.tokens.find(v => v.metaType === MetaType.CLAIMABLE)?.address;
if (!tokenAddress) {
throw new Error(`Could not find claimable token for ${contractPosition.address} ${contractPosition.network}`);
}
melenxyz marked this conversation as resolved.
Show resolved Hide resolved
return multicall.wrap(contract).pendingReward(address);
},
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Inject } from '@nestjs/common';

import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface';
import { Register } from '~app-toolkit/decorators';
import { PositionFetcher } from '~position/position-fetcher.interface';
import { ContractPosition } from '~position/position.interface';
import { Network } from '~types/network.interface';

import { ABRACADABRA_DEFINITION } from '../abracadabra.definition';
import { AbracadabraContractFactory, AbracadabraMspell } from '../contracts';

const appId = ABRACADABRA_DEFINITION.id;
const groupId = ABRACADABRA_DEFINITION.groups.mSpell.id;
const network = Network.AVALANCHE_MAINNET;
@Register.ContractPositionFetcher({ appId, groupId, network })
export class AvalancheAbracadabraMspellContractPositionFetcher implements PositionFetcher<ContractPosition> {
constructor(
@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit,
@Inject(AbracadabraContractFactory)
private readonly contractFactory: AbracadabraContractFactory,
) {}

async getPositions() {
return this.appToolkit.helpers.singleStakingFarmContractPositionHelper.getContractPositions<AbracadabraMspell>({
appId,
groupId,
network,
resolveFarmAddresses: async () => ['0xbd84472b31d947314fdfa2ea42460a2727f955af'],
resolveStakedTokenAddress: async ({ multicall, contract }) => multicall.wrap(contract).spell(),
resolveFarmContract: opts => this.contractFactory.abracadabraMspell(opts),
resolveRewardTokenAddresses: async ({ multicall, contract }) => multicall.wrap(contract).mim(),
resolveRois: () => ({ dailyROI: 0, weeklyROI: 0, yearlyROI: 0 }),
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Inject } from '@nestjs/common';

import { Register } from '~app-toolkit/decorators';
import { presentBalanceFetcherResponse } from '~app-toolkit/helpers/presentation/balance-fetcher-response.present';
import { BalanceFetcher } from '~balance/balance-fetcher.interface';
import { APP_TOOLKIT, IAppToolkit } from '~lib';
import { Network } from '~types/network.interface';

import { ABRACADABRA_DEFINITION } from '../abracadabra.definition';
import { AbracadabraContractFactory, PopsicleChef } from '../contracts';
import { AbracadabraCauldronBalanceHelper } from '../helpers/abracadabra.cauldron.balance-helper';

const network = Network.BINANCE_SMART_CHAIN_MAINNET;

@Register.BalanceFetcher(ABRACADABRA_DEFINITION.id, network)
export class BinanceSmartChainAbracadabraBalanceFetcher implements BalanceFetcher {
constructor(
@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit,
@Inject(AbracadabraCauldronBalanceHelper)
private readonly abracadabraCauldronBalanceHelper: AbracadabraCauldronBalanceHelper,
@Inject(AbracadabraContractFactory) private readonly contractFactory: AbracadabraContractFactory,
melenxyz marked this conversation as resolved.
Show resolved Hide resolved
) {}

private async getCauldronBalances(address: string) {
return this.abracadabraCauldronBalanceHelper.getBalances({ address, network });
}

async getBalances(address: string) {
const [cauldronBalances] = await Promise.all([this.getCauldronBalances(address)]);

return presentBalanceFetcherResponse([
{
label: 'Cauldrons',
assets: cauldronBalances,
},
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Inject } from '@nestjs/common';

import { Register } from '~app-toolkit/decorators';
import { PositionFetcher } from '~position/position-fetcher.interface';
import { ContractPosition } from '~position/position.interface';
import { Network } from '~types/network.interface';

import { ABRACADABRA_DEFINITION } from '../abracadabra.definition';
import { AbracadabraCauldronContractPositionHelper } from '../helpers/abracadabra.cauldron.contract-position-helper';

const CAULDRONS = [
'0x692cf15f80415d83e8c0e139cabcda67fcc12c90', // wBNB
'0xf8049467f3a9d50176f4816b20cddd9bb8a93319', // CAKE
];

const appId = ABRACADABRA_DEFINITION.id;
const groupId = ABRACADABRA_DEFINITION.groups.cauldron.id;
const network = Network.BINANCE_SMART_CHAIN_MAINNET;

@Register.ContractPositionFetcher({ appId, groupId, network })
export class BinanceSmartChainAbracadabraCauldronContractPositionFetcher implements PositionFetcher<ContractPosition> {
constructor(
@Inject(AbracadabraCauldronContractPositionHelper)
private readonly abracadabraCauldronContractPositionHelper: AbracadabraCauldronContractPositionHelper,
) {}

async getPositions() {
return this.abracadabraCauldronContractPositionHelper.getContractPositions({
cauldronAddresses: CAULDRONS,
network,
dependencies: [
{ appId: ABRACADABRA_DEFINITION.id, groupIds: [ABRACADABRA_DEFINITION.groups.stakedSpell.id], network },
],
melenxyz marked this conversation as resolved.
Show resolved Hide resolved
});
}
}
Loading