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

Commit

Permalink
Fix native investment (#2123)
Browse files Browse the repository at this point in the history
# Summary

Fixing bug with Native investment

Example of a successful claim using ETH https://rinkeby.etherscan.io/tx/0x63b9138efd234380362babc8bb2e6566750a2e9ea83ce10fe9b4862c6ad31f0f

The issue was that `parseUnits` adds X zeroes to the value passed in, but what I wanted is to remove them.
Switched back to JSBI.divide by 10**18 and now it gives us the proper amount :)

# Test

1. On rinkeby, connect your account and go to the claim page
2. Pick one account from the list below and check for the balance
3. If it has not been claimed yet, you should be able to claim it now :)
4. Trigger the claim - make sure you have the required amount of ETH + gas costs
* Your ETH claim should go through without issues

**Notes** this change might break the investor flow. I can revert that, it's on only to make sure the claiming is working

# Accounts

I filtered this list based on accounts that ONLY have ETH claims to make sure you don't need anything else (GNO/USDC)

- 0xb5434A86d09144da8854D1c40e3Cc54d78738695
- 0x9B827cc7Af79d71A2ca0f75343754935BfaF92D3
- 0x5d42D4Cd8B9D6141B1084E8eAD92e8F76b08705E
- 0x3320b6c454d0361dd3dF4912e8a06F3C945b8C60
- 0xCe0E37Bf2fC4B5c14D881f36712efB5Dcee203E8
- 0x030905cc078F3c71434fea1175615Bcc2c91FEf8
- 0xb0fE1FcEC3fE9f16c984b7A5668DF89bc7592B9D
- 0x6aBBaD8bd6Aced3649d52DFd32d2Ee04f3BE4aFB
- 0xF925FDd0de74d75Dd9C71095865c1511863092a9
- 0x26bC2B4D5DA4dc437F581AEFf490E2DdDa0aCFAa
- 0xA78266E26a6087566b17C64dE1Ed1D9533E1B36b
- 0x3877f08a4b722F48345B0e771c579fF335B533DA
- 0x1F1430C14595442c683cF3d3033a726ADecd6179
- 0xD5a0a16AA1ed668c45b29E905bafcb76C21a90BA
- 0xE6EA6d415e7Cb32bee6Db8Ad03e3749FEF23c9cd
- 0x3011862E85dDf0851f651E7d04e61e97E20a65CF
- 0x7f43A4C9E787Ba6A270e67b0D1bE77263cc47a08
- 0xCD2802122F04265791A3E4568A3f24BD1Df821a2
- 0x050f5403EB197DdE4BFE07da6e4aDE19A22db00B
- 0xe05206Ba64e59bF94c3dc3E1775Ec3FE04c33D08
- 0xC8249FB3b37fF0788462F1d20263ae373fbe68BB
- 0x01A72692ffE0A80029DE7982227A186F2787046f
- 0xDb3a676b8Eb7dBBC43b68C7Fb149f565343e850C
  • Loading branch information
alfetopito authored Jan 17, 2022
1 parent 2f2f1cb commit 0b6b4b7
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/custom/state/claim/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ export const USDC_PRICE = '150000' // '0.15' USDC (6 decimals) per vCOW, in atom
const TWO_WEEKS = ms`2 weeks`
const SIX_WEEKS = ms`6 weeks`

// For native token price calculation
const DENOMINATOR = JSBI.exponentiate(JSBI.BigInt(10), JSBI.BigInt(18))

export enum ClaimType {
Airdrop, // free, no vesting, can be available on both mainnet and gchain
GnoOption, // paid, with vesting, must use GNO, can be available on both mainnet and gchain
Expand Down Expand Up @@ -434,7 +437,7 @@ export function useClaimCallback(account: string | null | undefined): {

const vCowAmount = CurrencyAmount.fromRawAmount(vCowToken, totalClaimedAmount)

return vCowContract.estimateGas['claimMany'](...args).then((estimatedGas) => {
return vCowContract.estimateGas.claimMany(...args).then((estimatedGas) => {
// Last item in the array contains the call overrides
const extendedArgs = _extendFinalArg(args, {
from: connectedAccount, // add the `from` as the connected account
Expand Down Expand Up @@ -541,6 +544,7 @@ function _getClaimManyArgs({
})

const value = totalValue.toString() === '0' ? undefined : totalValue.toString()

const args: GetClaimManyArgsResult['args'] =
indices.length > 0
? [indices, claimTypes, claimants, claimableAmounts, claimedAmounts, merkleProofs, sendEth, { value }]
Expand Down Expand Up @@ -619,9 +623,11 @@ function _getClaimValue(claim: UserClaimData, vCowAmount: string, chainId: Suppo

const price = NATIVE_TOKEN_PRICE[chainId]

const claimValueInAtoms = JSBI.multiply(JSBI.BigInt(vCowAmount), JSBI.BigInt(price))

return parseUnits(claimValueInAtoms.toString(), 18).toString()
// Why InAtomsSquared? because we are multiplying vCowAmount (which is in atoms == * 10**18)
// by the price (which is also in atoms == * 10**18)
const claimValueInAtomsSquared = JSBI.multiply(JSBI.BigInt(vCowAmount), JSBI.BigInt(price))
// Then it's divided by 10**18 to return the value in the native currency atoms
return JSBI.divide(claimValueInAtomsSquared, DENOMINATOR).toString()
}

type LastAddress = string
Expand Down

0 comments on commit 0b6b4b7

Please sign in to comment.