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.
fix(pool-together): Split PoolTogether app into v3 and v4 (#797)
- Loading branch information
Showing
78 changed files
with
2,535 additions
and
383 deletions.
There are no files selected for viewing
File renamed without changes
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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
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
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
84 changes: 84 additions & 0 deletions
84
src/apps/pool-together-v3/ethereum/pool-together-v3.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,84 @@ | ||
import { Inject } from '@nestjs/common'; | ||
|
||
import { IAppToolkit, APP_TOOLKIT } 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 { Network } from '~types/network.interface'; | ||
|
||
import { PoolTogetherV3AirdropTokenBalancesHelper } from '../helpers/pool-together-v3.airdrop.balance-helper'; | ||
import { PoolTogetherV3ClaimableTokenBalancesHelper } from '../helpers/pool-together-v3.claimable.balance-helper'; | ||
import { POOL_TOGETHER_V3_DEFINITION } from '../pool-together-v3.definition'; | ||
|
||
const network = Network.ETHEREUM_MAINNET; | ||
|
||
@Register.BalanceFetcher(POOL_TOGETHER_V3_DEFINITION.id, network) | ||
export class EthereumPoolTogetherV3BalanceFetcher implements BalanceFetcher { | ||
constructor( | ||
@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit, | ||
@Inject(PoolTogetherV3ClaimableTokenBalancesHelper) | ||
private readonly claimableTokenBalancesHelper: PoolTogetherV3ClaimableTokenBalancesHelper, | ||
@Inject(PoolTogetherV3AirdropTokenBalancesHelper) | ||
private readonly airdropTokenBalancesHelper: PoolTogetherV3AirdropTokenBalancesHelper, | ||
) {} | ||
|
||
async getTicketBalances(address: string) { | ||
return this.appToolkit.helpers.tokenBalanceHelper.getTokenBalances({ | ||
network, | ||
appId: POOL_TOGETHER_V3_DEFINITION.id, | ||
groupId: POOL_TOGETHER_V3_DEFINITION.groups.ticket.id, | ||
address, | ||
}); | ||
} | ||
|
||
async getPodTokenBalances(address: string) { | ||
return this.appToolkit.helpers.tokenBalanceHelper.getTokenBalances({ | ||
network, | ||
appId: POOL_TOGETHER_V3_DEFINITION.id, | ||
groupId: POOL_TOGETHER_V3_DEFINITION.groups.pod.id, | ||
address, | ||
}); | ||
} | ||
|
||
async getClaimableBalances(address: string) { | ||
return this.claimableTokenBalancesHelper.getBalances({ | ||
address, | ||
network, | ||
}); | ||
} | ||
|
||
async getAirdropBalances(address: string) { | ||
return this.airdropTokenBalancesHelper.getBalances({ | ||
address, | ||
network, | ||
}); | ||
} | ||
|
||
async getBalances(address: string) { | ||
const [ticketBalances, podTokenBalances, claimableBalances, airdropBalances] = await Promise.all([ | ||
this.getTicketBalances(address), | ||
this.getPodTokenBalances(address), | ||
this.getClaimableBalances(address), | ||
this.getAirdropBalances(address), | ||
]); | ||
|
||
return presentBalanceFetcherResponse([ | ||
{ | ||
label: 'Prize Pools', | ||
assets: ticketBalances, | ||
}, | ||
{ | ||
label: 'Prize Pods', | ||
assets: podTokenBalances, | ||
}, | ||
{ | ||
label: 'Rewards', | ||
assets: claimableBalances, | ||
}, | ||
{ | ||
label: 'Airdrops', | ||
assets: airdropBalances, | ||
}, | ||
]); | ||
} | ||
} |
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
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
78 changes: 78 additions & 0 deletions
78
src/apps/pool-together-v3/helpers/pool-together-v3.airdrop.balance-helper.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,78 @@ | ||
import { Inject } from '@nestjs/common'; | ||
import axios from 'axios'; | ||
import { ethers } from 'ethers'; | ||
|
||
import { drillBalance } from '~app-toolkit'; | ||
import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; | ||
import { buildDollarDisplayItem } from '~app-toolkit/helpers/presentation/display-item.present'; | ||
import { getTokenImg } from '~app-toolkit/helpers/presentation/image.present'; | ||
import { ContractType } from '~position/contract.interface'; | ||
import { ContractPositionBalance } from '~position/position-balance.interface'; | ||
import { Network } from '~types/network.interface'; | ||
|
||
import { PoolTogetherV3ContractFactory } from '../contracts'; | ||
import { POOL_TOGETHER_V3_DEFINITION } from '../pool-together-v3.definition'; | ||
|
||
type GetAirdropTokenBalanceParams = { | ||
address: string; | ||
network: Network; | ||
airDropAddressDataUrl?: string; | ||
airDropToken?: string; | ||
}; | ||
|
||
export class PoolTogetherV3AirdropTokenBalancesHelper { | ||
constructor( | ||
@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit, | ||
@Inject(PoolTogetherV3ContractFactory) private readonly contractFactory: PoolTogetherV3ContractFactory, | ||
) {} | ||
|
||
async getBalances({ address, network, airDropAddressDataUrl }: GetAirdropTokenBalanceParams) { | ||
const baseTokens = await this.appToolkit.getBaseTokenPrices(network); | ||
|
||
const checksumAddress = ethers.utils.getAddress(address); // Checksum | ||
const url = `${airDropAddressDataUrl}?address=${checksumAddress}`; | ||
const merkleResponseData = await axios | ||
.get<{ index: number; amount: string; proof: string[] }>(url) | ||
.then(({ data }) => data) | ||
.catch(() => null); | ||
if (!merkleResponseData) return []; | ||
|
||
const merkleAddress = '0xbe1a33519f586a4c8aa37525163df8d67997016f'; | ||
const distributorContract = this.contractFactory.poolTogetherMerkleDistributor({ address: merkleAddress, network }); | ||
const isClaimed = await distributorContract.isClaimed(merkleResponseData.index); | ||
if (isClaimed) return []; | ||
|
||
const claimableToken = baseTokens.find(p => p.symbol === 'POOL'); | ||
if (!claimableToken) return []; | ||
|
||
const claimableBalanceRaw = String(parseInt(merkleResponseData.amount, 16)); | ||
const claimableTokenBalance = drillBalance(claimableToken, claimableBalanceRaw); | ||
const tokens = [claimableTokenBalance]; | ||
const balanceUSD = claimableTokenBalance.balanceUSD; | ||
|
||
// Display Props | ||
const label = `Claimable ${claimableToken.symbol}`; | ||
const secondaryLabel = buildDollarDisplayItem(claimableToken.price); | ||
const images = [getTokenImg(claimableToken.address, network)]; | ||
|
||
const positionBalance: ContractPositionBalance = { | ||
type: ContractType.POSITION, | ||
address: merkleAddress, | ||
appId: POOL_TOGETHER_V3_DEFINITION.id, | ||
groupId: POOL_TOGETHER_V3_DEFINITION.groups.claimable.id, | ||
network, | ||
tokens, | ||
balanceUSD, | ||
|
||
dataProps: {}, | ||
|
||
displayProps: { | ||
label, | ||
secondaryLabel, | ||
images, | ||
}, | ||
}; | ||
|
||
return [positionBalance]; | ||
} | ||
} |
Oops, something went wrong.