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

Commit

Permalink
feat(llama-airforce): Support uFXS claimable
Browse files Browse the repository at this point in the history
  • Loading branch information
immasandwich committed Jun 12, 2022
1 parent 9c62102 commit ab4a3af
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 161 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { Inject } from '@nestjs/common';
import BigNumber from 'bignumber.js';

import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface';
import { Register } from '~app-toolkit/decorators';
import { drillBalance } from '~app-toolkit/helpers/balance/token-balance.helper';
import { PositionBalanceFetcher } from '~position/position-balance-fetcher.interface';
import { ContractPositionBalance } from '~position/position-balance.interface';
import { isClaimable } from '~position/position.utils';
import { Network } from '~types/network.interface';

import { LlamaAirforceContractFactory } from '../contracts';
import { LLAMA_AIRFORCE_DEFINITION } from '../llama-airforce.definition';

import { EthereumLlamaAirforceMerkleCache } from './llama-airforce.merkle-cache';

@Register.ContractPositionBalanceFetcher({
appId: LLAMA_AIRFORCE_DEFINITION.id,
groupId: LLAMA_AIRFORCE_DEFINITION.groups.airdrop.id,
network: Network.ETHEREUM_MAINNET,
})
export class EthereumLlamaAirforceAirdropContractPositionBalanceFetcher
implements PositionBalanceFetcher<ContractPositionBalance>
{
constructor(
@Inject(APP_TOOLKIT)
private readonly appToolkit: IAppToolkit,
@Inject(EthereumLlamaAirforceMerkleCache)
private readonly merkleCache: EthereumLlamaAirforceMerkleCache,
@Inject(LlamaAirforceContractFactory) private readonly contractFactory: LlamaAirforceContractFactory,
) {}

async getBalances(address: string) {
return this.appToolkit.helpers.contractPositionBalanceHelper.getContractPositionBalances({
address,
appId: LLAMA_AIRFORCE_DEFINITION.id,
groupId: LLAMA_AIRFORCE_DEFINITION.groups.airdrop.id,
network: Network.ETHEREUM_MAINNET,
resolveBalances: async ({ contractPosition, multicall }) => {
const contract = this.contractFactory.llamaAirforceMerkleDistributor(contractPosition);
const rewardToken = contractPosition.tokens.find(isClaimable)!;
const rewardsData = await this.merkleCache.getClaim(rewardToken.address, address);
if (!rewardsData) return [drillBalance(rewardToken, '0')];

const { index, amount } = rewardsData;
const isClaimed = await multicall.wrap(contract).isClaimed(index);

const balanceRaw = new BigNumber(isClaimed ? '0' : amount);
return [drillBalance(rewardToken, balanceRaw.toFixed(0))];
},
});
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { Inject } from '@nestjs/common';

import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface';
import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface';
import { Register } from '~app-toolkit/decorators';
import { buildDollarDisplayItem } from '~app-toolkit/helpers/presentation/display-item.present';
import { getImagesFromToken, getLabelFromToken } from '~app-toolkit/helpers/presentation/image.present';
import { ContractType } from '~position/contract.interface';
import { PositionFetcher } from '~position/position-fetcher.interface';
import { ContractPosition } from '~position/position.interface';
import { claimable } from '~position/position.utils';
import { Network } from '~types/network.interface';

import { LLAMA_AIRFORCE_DEFINITION } from '../llama-airforce.definition';
Expand All @@ -16,37 +12,21 @@ const appId = LLAMA_AIRFORCE_DEFINITION.id;
const groupId = LLAMA_AIRFORCE_DEFINITION.groups.airdrop.id;
const network = Network.ETHEREUM_MAINNET;

const MERKLE_CLAIM_ADDRESS = '0xa83043df401346a67eddeb074679b4570b956183';

@Register.ContractPositionFetcher({ appId, groupId, network })
export class EthereumLlamaAirforceAirdropContractPositionFetcher implements PositionFetcher<ContractPosition> {
constructor(@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit) {}

async getPositions(): Promise<ContractPosition[]> {
const appTokens = await this.appToolkit.getAppTokenPositions({
appId: LLAMA_AIRFORCE_DEFINITION.id,
groupIds: [LLAMA_AIRFORCE_DEFINITION.groups.vault.id],
network,
});

const rewardToken = appTokens.find(v => v.symbol === 'uCRV');
if (!rewardToken) return [];

const contractPositionBalance: ContractPosition = {
type: ContractType.POSITION,
address: MERKLE_CLAIM_ADDRESS,
async getPositions() {
return this.appToolkit.helpers.merkleContractPositionHelper.getContractPositions({
address: '0xa83043df401346a67eddeb074679b4570b956183', // Merkle Claim
appId,
groupId,
network,
tokens: [claimable(rewardToken)],
dataProps: {},
displayProps: {
label: `Claimable ${getLabelFromToken(rewardToken)}`,
secondaryLabel: buildDollarDisplayItem(rewardToken.price),
images: getImagesFromToken(rewardToken),
},
};

return [contractPositionBalance];
dependencies: [{ appId, groupIds: [LLAMA_AIRFORCE_DEFINITION.groups.vault.id], network }],
rewardTokenAddresses: [
'0x83507cc8c8b67ed48badd1f59f684d5d02884c81', // uCRV
'0xf964b0e3ffdea659c44a5a52bc0b82a24b89ce0e', // uFXS
],
});
}
}
53 changes: 0 additions & 53 deletions src/apps/llama-airforce/ethereum/llama-airforce.balance-fetcher.ts

This file was deleted.

45 changes: 45 additions & 0 deletions src/apps/llama-airforce/ethereum/llama-airforce.merkle-cache.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Injectable } from '@nestjs/common';
import Axios from 'axios';

import { MerkleCache } from '~app-toolkit/helpers/merkle/merkle.cache';
import { Network } from '~types/network.interface';

import { LLAMA_AIRFORCE_DEFINITION } from '../llama-airforce.definition';

type LlamaAirforceMerkleClaim = {
index: number;
amount: string;
proof: string[];
};

type LlamaAirforceMerkleData = {
merkleRoot: string;
tokenTotal: string;
claims: Record<string, LlamaAirforceMerkleClaim>;
};

@Injectable()
export class EthereumLlamaAirforceMerkleCache extends MerkleCache<LlamaAirforceMerkleClaim> {
appId = LLAMA_AIRFORCE_DEFINITION.id;
groupId = LLAMA_AIRFORCE_DEFINITION.groups.airdrop.id;
network = Network.ETHEREUM_MAINNET;

async resolveMerkleData() {
const [{ data: uCrvData }, { data: uFxsData }] = await Promise.all([
Axios.get<LlamaAirforceMerkleData>(
'https://raw.githubusercontent.com/0xAlunara/Llama-Airforce-Airdrops/master/ucrv/latest.json',
),
Axios.get<LlamaAirforceMerkleData>(
'https://raw.githubusercontent.com/0xAlunara/Llama-Airforce-Airdrops/master/ufxs/latest.json',
),
]);

const uCrvTokenAddress = '0x83507cc8c8b67ed48badd1f59f684d5d02884c81';
const uFxsTokenAddress = '0xf964b0e3ffdea659c44a5a52bc0b82a24b89ce0e';

return {
[uCrvTokenAddress]: uCrvData.claims,
[uFxsTokenAddress]: uFxsData.claims,
};
}
}

This file was deleted.

13 changes: 7 additions & 6 deletions src/apps/llama-airforce/llama-airforce.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@ import { Register } from '~app-toolkit/decorators';
import { AbstractApp } from '~app/app.dynamic-module';

import { LlamaAirforceContractFactory } from './contracts';
import { EthereumLlamaAirforceAirdropContractPositionBalanceFetcher } from './ethereum/llama-airforce.airdrop.contract-position-balance-fetcher';
import { EthereumLlamaAirforceAirdropContractPositionFetcher } from './ethereum/llama-airforce.airdrop.contract-position-fetcher';
import { EthereumLlamaAirforceBalanceFetcher } from './ethereum/llama-airforce.balance-fetcher';
import { EthereumLlamaAirforceMerkleCache } from './ethereum/llama-airforce.merkle-cache';
import { EthereumLlamaAirforceVaultTokenFetcher } from './ethereum/llama-airforce.vault.token-fetcher';
import { LlamaAirforceAirdropBalancesHelper } from './helpers/llama-airforce.airdrop.balance-helper';
import { LlamaAirforceAppDefinition, LLAMA_AIRFORCE_DEFINITION } from './llama-airforce.definition';

@Register.AppModule({
appId: LLAMA_AIRFORCE_DEFINITION.id,
providers: [
EthereumLlamaAirforceAirdropContractPositionFetcher,
EthereumLlamaAirforceBalanceFetcher,
EthereumLlamaAirforceVaultTokenFetcher,
LlamaAirforceAirdropBalancesHelper,
LlamaAirforceAppDefinition,
LlamaAirforceContractFactory,
// Ethereum
EthereumLlamaAirforceMerkleCache,
EthereumLlamaAirforceAirdropContractPositionFetcher,
EthereumLlamaAirforceAirdropContractPositionBalanceFetcher,
EthereumLlamaAirforceVaultTokenFetcher,
],
})
export class LlamaAirforceAppModule extends AbstractApp() {}

0 comments on commit ab4a3af

Please sign in to comment.