From 374f1e2fc7cb310f837b447f605f46329439df0b Mon Sep 17 00:00:00 2001 From: Another Date: Mon, 22 Jan 2024 11:57:26 -0500 Subject: [PATCH] feat: implement celo campaigns flow --- .env.development | 3 +- src/assets/data/contracts/celo.json | 5 +- src/composables/campaigns/useAllocations.ts | 7 ++- src/composables/campaigns/useRFNFT.ts | 7 ++- src/lib/abi/KolektivoRNFT.json | 67 +++++++++++++++++++-- src/lib/config/celo/contracts.ts | 3 + src/services/campaigns/campaigns.service.ts | 8 +-- 7 files changed, 84 insertions(+), 16 deletions(-) diff --git a/.env.development b/.env.development index fec94fc6d..15f07d2fd 100644 --- a/.env.development +++ b/.env.development @@ -3,7 +3,8 @@ VITE_DOMAIN=localhost:8080 VITE_IPFS_NODE=cloudflare-ipfs.com VITE_BLOCKNATIVE_DAPP_ID=032e2fb8-6c66-46a5-bf1c-a049ac7eded2 VITE_FATHOM_SITE_ID=xxx -VITE_COINGECKO_API_KEY= +VITE_COINGECKO_API_KEY="CG-hvqpJ5VxrKZr6zVNX9eJMotW" + diff --git a/src/assets/data/contracts/celo.json b/src/assets/data/contracts/celo.json index 932cae2a3..552cfda0f 100644 --- a/src/assets/data/contracts/celo.json +++ b/src/assets/data/contracts/celo.json @@ -68,5 +68,8 @@ "WeightedPool2TokensFactory": "", "WeightedPoolFactory": "0xEB1055c017a1427726F01368C8247649c5A79bF9", "YearnLinearPoolFactory": "", - "Multicall": "0xca11bde05977b3631167028862be2a173976ca11" + "Multicall": "0xca11bde05977b3631167028862be2a173976ca11", + "SimpleMinter": "0xd437fa025E43ca4578aD682Bcfb1B003041d48D1", + "RFNFT": "0xBA7d3fB1BBD73f4289C7FB42e8EC268EC9C32bE3", + "RFP": "0x74072b693f1Da8B74b24563Cbded727228c0A898" } diff --git a/src/composables/campaigns/useAllocations.ts b/src/composables/campaigns/useAllocations.ts index 25972ef87..44545fb4a 100644 --- a/src/composables/campaigns/useAllocations.ts +++ b/src/composables/campaigns/useAllocations.ts @@ -3,10 +3,13 @@ import { campaignsService } from '@/services/campaigns/campaigns.service'; import useWeb3 from '@/services/web3/useWeb3'; export function useAllocations() { - const { account } = useWeb3(); + const { account, chainId } = useWeb3(); const queryKey = reactive(['currentAllocation']); const queryFn = async () => { - return await campaignsService.getCurrentAllocation(account.value); + return await campaignsService.getCurrentAllocation( + chainId.value, + account.value + ); }; const { data: currentAllocation, isLoading } = useQuery( diff --git a/src/composables/campaigns/useRFNFT.ts b/src/composables/campaigns/useRFNFT.ts index 75c5148f4..0f06607bc 100644 --- a/src/composables/campaigns/useRFNFT.ts +++ b/src/composables/campaigns/useRFNFT.ts @@ -10,7 +10,7 @@ import useTransactions from '../useTransactions'; export function useRFNFT() { const { addNotification } = useNotifications(); const { addTransaction } = useTransactions(); - const { account } = useWeb3(); + const { account, chainId } = useWeb3(); const isMintingNFT = ref(false); const fetchNFTImage = async (ipfsHash: string) => { @@ -28,7 +28,10 @@ export function useRFNFT() { const queryFn = async () => { try { - const data = await campaignsService.getCurrentNFT(account.value); + const data = await campaignsService.getCurrentNFT( + chainId.value, + account.value + ); if (data?.image) { const ipfsHash = data.image.split('ipfs://')[1]; const imageData = await fetchNFTImage(ipfsHash); diff --git a/src/lib/abi/KolektivoRNFT.json b/src/lib/abi/KolektivoRNFT.json index bfd18cdea..02987ca4d 100644 --- a/src/lib/abi/KolektivoRNFT.json +++ b/src/lib/abi/KolektivoRNFT.json @@ -20,6 +20,11 @@ "stateMutability": "nonpayable", "type": "constructor" }, + { + "inputs": [], + "name": "InsufficientPoints", + "type": "error" + }, { "inputs": [], "name": "InvalidTier", @@ -85,6 +90,25 @@ "name": "ApprovalForAll", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "LevelUp", + "type": "event" + }, { "anonymous": false, "inputs": [ @@ -137,12 +161,6 @@ "internalType": "uint256", "name": "points", "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "newTier", - "type": "uint256" } ], "name": "PointsAdded", @@ -254,6 +272,30 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "canLevelUp", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -376,6 +418,19 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "levelUp", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { diff --git a/src/lib/config/celo/contracts.ts b/src/lib/config/celo/contracts.ts index 5ee0fd553..e8633e05a 100644 --- a/src/lib/config/celo/contracts.ts +++ b/src/lib/config/celo/contracts.ts @@ -26,6 +26,9 @@ const contracts: Contracts = { gaugeRewardsHelper: '', gaugeWorkingBalanceHelper: '', gaugeCheckpointer: '', + simpleMinter: celo.SimpleMinter, + RFNFT: celo.RFNFT, + RFP: celo.RFP, }; export default contracts; diff --git a/src/services/campaigns/campaigns.service.ts b/src/services/campaigns/campaigns.service.ts index efe83fed8..28714e32a 100644 --- a/src/services/campaigns/campaigns.service.ts +++ b/src/services/campaigns/campaigns.service.ts @@ -28,8 +28,8 @@ export default class CampaignsService { this.addresses = configService.network.addresses; } - public async getCurrentAllocation(userAddress?: Address) { - const provider = getRpcProviderService().getJsonProvider(Network.ALFAJORES); + public async getCurrentAllocation(chainId: Network, userAddress?: Address) { + const provider = getRpcProviderService().getJsonProvider(chainId); if (!userAddress) return 0; const currentUserAddress = await this.walletService.getUserAddress(); if (!currentUserAddress) return 0; @@ -48,8 +48,8 @@ export default class CampaignsService { return 0; } - public async getCurrentNFT(userAddress?: Address) { - const provider = getRpcProviderService().getJsonProvider(Network.ALFAJORES); + public async getCurrentNFT(chainId: Network, userAddress?: Address) { + const provider = getRpcProviderService().getJsonProvider(chainId); if (this.addresses.RFNFT) { const currentNFTId = await call(provider, RFNFTAbi, [ this.addresses.RFNFT,