This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(llama-airforce): Support uFXS claimable
- Loading branch information
1 parent
9c62102
commit ab4a3af
Showing
6 changed files
with
115 additions
and
161 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
src/apps/llama-airforce/ethereum/llama-airforce.airdrop.contract-position-balance-fetcher.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))]; | ||
}, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 0 additions & 53 deletions
53
src/apps/llama-airforce/ethereum/llama-airforce.balance-fetcher.ts
This file was deleted.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
src/apps/llama-airforce/ethereum/llama-airforce.merkle-cache.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
} | ||
} |
72 changes: 0 additions & 72 deletions
72
src/apps/llama-airforce/helpers/llama-airforce.airdrop.balance-helper.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters