Skip to content

Commit

Permalink
Feat: Phase 2.5 for treasury grant
Browse files Browse the repository at this point in the history
  • Loading branch information
viet-nv committed Mar 6, 2024
1 parent 4f5ef67 commit 75ad041
Show file tree
Hide file tree
Showing 5 changed files with 5,259 additions and 387 deletions.
39 changes: 24 additions & 15 deletions src/pages/ElasticSnapshot/components/InstantClaim.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ import { formatDisplayNumber } from 'utils/numbers'
import avalanche from '../data/instant/avalanche.json'
import ethereum from '../data/instant/ethereum.json'
import optimism from '../data/instant/optimism.json'
import user3rd from '../data/instant/pendle_dappos_instant_polygon.json'
import userPhase2 from '../data/instant/pendle_dappos_instant_polygon.json'
import userPhase2_5 from '../data/instant/phase2.5.json'
import polygon from '../data/instant/polygon.json'
import InstantClaimModal from './InstantClaimModal'

const format = (value: number) => formatDisplayNumber(value, { style: 'currency', significantDigits: 6 })

export default function InstantClaim() {
const theme = useTheme()
const [show, setShow] = useState<'3rd' | 'kyber' | null>(null)
const [phase, setShow] = useState<'1' | '2' | '2.5' | null>(null)
const { account } = useActiveWeb3React()

const userData = useMemo(() => {
Expand All @@ -30,26 +31,34 @@ export default function InstantClaim() {
)
}, [account])

const user3rdData = useMemo(() => {
return user3rd.find(info => info.claimData.receiver.toLowerCase() === account?.toLowerCase())
const phase2Data = useMemo(() => {
return userPhase2.find(info => info.claimData.receiver.toLowerCase() === account?.toLowerCase())
}, [account])

const kyberValue = userData.reduce(
const phase2_5Data = useMemo(() => {
return userPhase2_5.find(info => info.claimData.receiver.toLowerCase() === account?.toLowerCase())
}, [account])

const phase1Value = userData.reduce(
(acc, cur) => acc + (cur?.claimData?.tokenInfo?.reduce((total, item) => total + item.value, 0) || 0),
0,
)
const phase2Value = phase2Data?.claimData.tokenInfo.reduce((acc, cur) => acc + cur.value, 0) || 0
const phase2_5Value = phase2_5Data?.claimData.tokenInfo.reduce((acc, cur) => acc + cur.value, 0) || 0

// no overlap user, ensure that only phase 2 or phase 2.5
const valuePhase2 = phase2_5Value || phase2Value

const value3rd = user3rdData?.claimData.tokenInfo.reduce((acc, cur) => acc + cur.value, 0) || 0
const totalValue = kyberValue + value3rd
const totalValue = phase1Value + phase2Value + phase2_5Value

const upToMedium = useMedia(`(max-width: ${MEDIA_WIDTHS.upToMedium}px)`)

const onDismiss = useCallback(() => setShow(null), [])
if (!userData.filter(Boolean).length && !user3rdData) return null
if (!userData.filter(Boolean).length && !phase2Data && !phase2_5Data) return null

return (
<Flex flexDirection="column">
{show && <InstantClaimModal onDismiss={onDismiss} is3rd={show === '3rd'} />}
{phase && <InstantClaimModal onDismiss={onDismiss} phase={phase} />}
<Text fontSize={20} fontWeight="500">
<Trans>Available assets for claiming</Trans>
</Text>
Expand Down Expand Up @@ -82,17 +91,17 @@ export default function InstantClaim() {
</Text>
<Flex sx={{ gap: '1rem' }} alignItems="flex-end">
<Text fontWeight="500" fontSize={upToMedium ? 16 : 20}>
{format(kyberValue)}
{format(phase1Value)}
</Text>
{kyberValue !== 0 && (
{phase1Value !== 0 && (
<Text
sx={{ fontSize: '14px', cursor: 'pointer' }}
fontWeight="500"
role="button"
color={theme.primary}
mb="2px"
onClick={() => {
setShow('kyber')
setShow('1')
}}
>
<Trans>Details</Trans>
Expand All @@ -114,17 +123,17 @@ export default function InstantClaim() {
</Text>
<Flex sx={{ gap: '1rem' }} alignItems="flex-end">
<Text fontWeight="500" fontSize={upToMedium ? 16 : 20}>
{format(value3rd || 0)}
{format(valuePhase2 || 0)}
</Text>
{value3rd !== 0 && (
{valuePhase2 !== 0 && (
<Text
sx={{ fontSize: '14px', cursor: 'pointer' }}
fontWeight="500"
role="button"
color={theme.primary}
mb="2px"
onClick={() => {
setShow('3rd')
setShow(phase2Data ? '2' : '2.5')
}}
>
<Trans>Details</Trans>
Expand Down
49 changes: 29 additions & 20 deletions src/pages/ElasticSnapshot/components/InstantClaimModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import InstantAbi from '../data/abis/instantClaimAbi.json'
import avalanche from '../data/instant/avalanche.json'
import ethereum from '../data/instant/ethereum.json'
import optimism from '../data/instant/optimism.json'
import user3rd from '../data/instant/pendle_dappos_instant_polygon.json'
import userPhase2 from '../data/instant/pendle_dappos_instant_polygon.json'
import userPhase2_5 from '../data/instant/phase2.5.json'
import polygon from '../data/instant/polygon.json'

const Total = styled.div`
Expand Down Expand Up @@ -66,6 +67,8 @@ const format = (value: number) => formatDisplayNumber(value, { style: 'currency'

const contractAddress = '0xD0806364e9672EF21039Dc4DC84651B9b535E535'
const phase2ContractAddress = '0x3771cb0e40f55316a9cf9a79a60b562946a39d8b'
// TODO: update
const phase2_5ContractAddress = '0x3771cb0e40f55316a9cf9a79a60b562946a39d8b'

const ContractInterface = new Interface(InstantAbi)

Expand All @@ -84,18 +87,17 @@ const snapshotPrices: { [key: string]: number } = {
'0x5cc8d49984834314f54211b1d872318cf766d466': 1,
}

export default function InstantClaimModal({ onDismiss, is3rd }: { onDismiss: () => void; is3rd: boolean }) {
export default function InstantClaimModal({ onDismiss, phase }: { onDismiss: () => void; phase: '1' | '2' | '2.5' }) {
const theme = useTheme()
const { account, chainId } = useActiveWeb3React()
const { library } = useWeb3React()

const polygonContractAddress =
phase === '2' ? phase2ContractAddress : phase === '2.5' ? phase2_5ContractAddress : contractAddress

const ethereumContract = useReadingContract(contractAddress, ContractInterface, ChainId.MAINNET)
const optimismContract = useReadingContract(contractAddress, ContractInterface, ChainId.OPTIMISM)
const polygonContract = useReadingContract(
is3rd ? phase2ContractAddress : contractAddress,
ContractInterface,
ChainId.MATIC,
)
const polygonContract = useReadingContract(polygonContractAddress, ContractInterface, ChainId.MATIC)
const avalancheContract = useReadingContract(contractAddress, ContractInterface, ChainId.AVAXMAINNET)

const [claimed, setClaimed] = useState([true, true, true, true])
Expand All @@ -107,17 +109,21 @@ export default function InstantClaimModal({ onDismiss, is3rd }: { onDismiss: ()

const allTokens = [ethereumTokens, optimismTokens, polygonTokens, avalancheTokens]

const user3rdData = useMemo(() => {
return user3rd.find(info => info.claimData.receiver.toLowerCase() === account?.toLowerCase())
const phase2Data = useMemo(() => {
return userPhase2.find(info => info.claimData.receiver.toLowerCase() === account?.toLowerCase())
}, [account])

const phase2_5Data = useMemo(() => {
return userPhase2_5.find(info => info.claimData.receiver.toLowerCase() === account?.toLowerCase())
}, [account])

const userData = useMemo(() => {
if (!account) return []
if (is3rd) return [undefined, undefined, user3rdData, undefined]
if (phase !== '1') return [undefined, undefined, phase2Data || phase2_5Data, undefined]
return [ethereum, optimism, polygon, avalanche].map(data =>
data.find(info => info.claimData.receiver.toLowerCase() === account.toLowerCase()),
)
}, [account, is3rd, user3rdData])
}, [account, phase, phase2Data, phase2_5Data])

useEffect(() => {
;(() => {
Expand Down Expand Up @@ -167,9 +173,10 @@ export default function InstantClaimModal({ onDismiss, is3rd }: { onDismiss: ()
const addTransactionWithType = useTransactionAdder()

const [signing, setSigning] = useState(false)
const ipfsLink = is3rd
? 'https://bafkreibjr6w7fahoj5rbe4utot3xqeffedyxxgiw4xvryw4d6n6pb6sxzq.ipfs.w3s.link'
: 'https://bafkreiclpbxs5phtgmdicdxp4v6iul5agoadbd4u7vtut23dmoifiirqli.ipfs.w3s.link'
const ipfsLink =
phase !== '1'
? 'https://bafkreibjr6w7fahoj5rbe4utot3xqeffedyxxgiw4xvryw4d6n6pb6sxzq.ipfs.w3s.link'
: 'https://bafkreiclpbxs5phtgmdicdxp4v6iul5agoadbd4u7vtut23dmoifiirqli.ipfs.w3s.link'
const signAndClaim = useCallback(() => {
setAutoSign(false)
setSigning(true)
Expand Down Expand Up @@ -213,13 +220,14 @@ export default function InstantClaimModal({ onDismiss, is3rd }: { onDismiss: ()
name: 'Kyberswap Instant Grant',
version: '1',
chainId: selectedNetworkToClaim,
verifyingContract: is3rd ? phase2ContractAddress : contractAddress,
verifyingContract: phase !== '1' ? polygonContractAddress : contractAddress,
},
message: {
leafIndex: userData[selectedIndex]?.claimData?.index,
termsAndConditions: is3rd
? 'By confirming this transaction, I agree to the KyberSwap Elastic Recovered Asset Redemption Terms and Conditions which can be found at this link https://bafkreibjr6w7fahoj5rbe4utot3xqeffedyxxgiw4xvryw4d6n6pb6sxzq.ipfs.w3s.link'
: `By confirming this transaction, I agree to the KyberSwap Elastic Recovered Asset Redemption Terms which can be found at this link ${ipfsLink}`,
termsAndConditions:
phase !== '1'
? 'By confirming this transaction, I agree to the KyberSwap Elastic Recovered Asset Redemption Terms and Conditions which can be found at this link https://bafkreibjr6w7fahoj5rbe4utot3xqeffedyxxgiw4xvryw4d6n6pb6sxzq.ipfs.w3s.link'
: `By confirming this transaction, I agree to the KyberSwap Elastic Recovered Asset Redemption Terms which can be found at this link ${ipfsLink}`,
},
}),
])
Expand All @@ -239,7 +247,7 @@ export default function InstantClaimModal({ onDismiss, is3rd }: { onDismiss: ()
library
?.getSigner()
.sendTransaction({
to: is3rd ? phase2ContractAddress : contractAddress,
to: phase !== '1' ? polygonContractAddress : contractAddress,
data: encodedData,
})
.then(tx => {
Expand Down Expand Up @@ -270,7 +278,8 @@ export default function InstantClaimModal({ onDismiss, is3rd }: { onDismiss: ()
})
})
}, [
is3rd,
phase,
polygonContractAddress,
ipfsLink,
account,
library,
Expand Down
Loading

0 comments on commit 75ad041

Please sign in to comment.