-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable op rewards claim (#949)
- Loading branch information
Showing
13 changed files
with
224 additions
and
116 deletions.
There are no files selected for viewing
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,95 @@ | ||
import { useQuery } from "react-query"; | ||
import { BigNumber } from "ethers"; | ||
import { utils } from "@across-protocol/sdk-v2"; | ||
|
||
import { useConnection } from "hooks"; | ||
import { fetchIsClaimed, fetchAirdropProofs } from "utils/merkle-distributor"; | ||
import { getUnclaimedProofsQueryKey, rewardProgramTypes } from "utils"; | ||
|
||
export function useUnclaimedProofs(rewardsType: rewardProgramTypes) { | ||
const { isConnected, account } = useConnection(); | ||
|
||
return useQuery( | ||
getUnclaimedProofsQueryKey(rewardsType, account), | ||
() => fetchUnclaimedProofs(rewardsType, account), | ||
{ | ||
enabled: isConnected && !!account, | ||
} | ||
); | ||
} | ||
|
||
export function useUnclaimedReferralProofs() { | ||
const { isConnected, account } = useConnection(); | ||
|
||
return useQuery( | ||
getUnclaimedProofsQueryKey("referrals", account), | ||
() => fetchUnclaimedProofs("referrals", account), | ||
{ | ||
enabled: isConnected && !!account, | ||
} | ||
); | ||
} | ||
|
||
export function useUnclaimedOpRewardsProofs() { | ||
const { isConnected, account } = useConnection(); | ||
|
||
return useQuery( | ||
getUnclaimedProofsQueryKey("op-rebates", account), | ||
() => fetchUnclaimedProofs("op-rebates", account), | ||
{ | ||
enabled: isConnected && !!account, | ||
} | ||
); | ||
} | ||
|
||
async function fetchUnclaimedProofs( | ||
rewardsType: rewardProgramTypes, | ||
account?: string | ||
) { | ||
const allProofs = await fetchAirdropProofs(rewardsType, account); | ||
const isClaimedResults = await fetchIsClaimedForIndices( | ||
allProofs, | ||
rewardsType | ||
); | ||
|
||
const unclaimed = allProofs.filter( | ||
(proof) => | ||
isClaimedResults.findIndex( | ||
(isClaimedResult) => | ||
!isClaimedResult.isClaimed && | ||
proof.accountIndex === isClaimedResult.accountIndex && | ||
proof.windowIndex === isClaimedResult.windowIndex | ||
) >= 0 | ||
); | ||
const claimableAmount = unclaimed.reduce( | ||
(sum, { amount }) => sum.add(amount), | ||
BigNumber.from(0) | ||
); | ||
return { | ||
claimableAmount, | ||
unclaimed, | ||
}; | ||
} | ||
|
||
async function fetchIsClaimedForIndices( | ||
indices: { accountIndex: number; windowIndex: number }[], | ||
rewardsType: rewardProgramTypes | ||
) { | ||
const isClaimedResults = await utils.mapAsync( | ||
indices, | ||
async ({ accountIndex, windowIndex }) => { | ||
const isClaimed = await fetchIsClaimed( | ||
windowIndex, | ||
accountIndex, | ||
rewardsType | ||
); | ||
return { | ||
isClaimed, | ||
windowIndex, | ||
accountIndex, | ||
}; | ||
} | ||
); | ||
|
||
return isClaimedResults; | ||
} |
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
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
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
Oops, something went wrong.
4d752be
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
goerli-frontend-v2 – ./
goerli-frontend-v2.vercel.app
goerli-frontend-v2-uma.vercel.app
goerli-frontend-v2-git-master-uma.vercel.app
4d752be
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
frontend-v2 – ./
frontend-v2-uma.vercel.app
frontend-v2-git-master-uma.vercel.app
frontend-v2-seven.vercel.app
v2.across.to
across.to