From 9bd35017c6ca7009ddc7422b7afa3d17fc5c6166 Mon Sep 17 00:00:00 2001 From: MIDAV0 Date: Wed, 27 Sep 2023 11:14:23 +0100 Subject: [PATCH 1/5] New contracts --- src/renderer/contracts/flockV2.ts | 366 ++++++++++++++++++++++++ src/renderer/contracts/migrateTokens.ts | 87 ++++++ 2 files changed, 453 insertions(+) create mode 100644 src/renderer/contracts/flockV2.ts create mode 100644 src/renderer/contracts/migrateTokens.ts diff --git a/src/renderer/contracts/flockV2.ts b/src/renderer/contracts/flockV2.ts new file mode 100644 index 0000000..84b0338 --- /dev/null +++ b/src/renderer/contracts/flockV2.ts @@ -0,0 +1,366 @@ +export const FLOCK_V2_ADDRESS = '0x45Ef45b77199a48416330d1e461b89a64b4a3CA4'; +export const FLOCK_V2_ABI = [ + { + inputs: [], + stateMutability: 'nonpayable', + type: 'constructor', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'owner', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'spender', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'value', + type: 'uint256', + }, + ], + name: 'Approval', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'previousOwner', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'newOwner', + type: 'address', + }, + ], + name: 'OwnershipTransferred', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'from', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'to', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'value', + type: 'uint256', + }, + ], + name: 'Transfer', + type: 'event', + }, + { + inputs: [ + { + internalType: 'address', + name: 'owner', + type: 'address', + }, + { + internalType: 'address', + name: 'spender', + type: 'address', + }, + ], + name: 'allowance', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'spender', + type: 'address', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'approve', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'account', + type: 'address', + }, + ], + name: 'balanceOf', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_account', + type: 'address', + }, + { + internalType: 'uint256', + name: '_amount', + type: 'uint256', + }, + ], + name: 'burn', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'decimals', + outputs: [ + { + internalType: 'uint8', + name: '', + type: 'uint8', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'spender', + type: 'address', + }, + { + internalType: 'uint256', + name: 'subtractedValue', + type: 'uint256', + }, + ], + name: 'decreaseAllowance', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'spender', + type: 'address', + }, + { + internalType: 'uint256', + name: 'addedValue', + type: 'uint256', + }, + ], + name: 'increaseAllowance', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_account', + type: 'address', + }, + { + internalType: 'uint256', + name: '_amount', + type: 'uint256', + }, + ], + name: 'mint', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'name', + outputs: [ + { + internalType: 'string', + name: '', + type: 'string', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'owner', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'renounceOwnership', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'symbol', + outputs: [ + { + internalType: 'string', + name: '', + type: 'string', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'totalSupply', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'to', + type: 'address', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'transfer', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'from', + type: 'address', + }, + { + internalType: 'address', + name: 'to', + type: 'address', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'transferFrom', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'newOwner', + type: 'address', + }, + ], + name: 'transferOwnership', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, +]; diff --git a/src/renderer/contracts/migrateTokens.ts b/src/renderer/contracts/migrateTokens.ts new file mode 100644 index 0000000..2b61edf --- /dev/null +++ b/src/renderer/contracts/migrateTokens.ts @@ -0,0 +1,87 @@ +export const MIGRATE_TOKENS_ADDRESS = + '0x1f808c9d65D992f822Ab1Fc33cc76Cda7334687c'; + +export const MIGRATE_TOKENS_ABI = [ + { + inputs: [ + { + internalType: 'address', + name: '_oldTokenAddress', + type: 'address', + }, + { + internalType: 'address', + name: '_newTokenAddress', + type: 'address', + }, + ], + stateMutability: 'nonpayable', + type: 'constructor', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'previousOwner', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'newOwner', + type: 'address', + }, + ], + name: 'OwnershipTransferred', + type: 'event', + }, + { + inputs: [], + name: 'migrate', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'owner', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'renounceOwnership', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'newOwner', + type: 'address', + }, + ], + name: 'transferOwnership', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'withdraw', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, +]; From cd9c48a442c2663634ab6d0dbf201e9e6745e2b1 Mon Sep 17 00:00:00 2001 From: MIDAV0 Date: Wed, 27 Sep 2023 11:14:32 +0100 Subject: [PATCH 2/5] Updated context --- src/renderer/context/walletContext.tsx | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/renderer/context/walletContext.tsx b/src/renderer/context/walletContext.tsx index e7d8503..4d86c7b 100644 --- a/src/renderer/context/walletContext.tsx +++ b/src/renderer/context/walletContext.tsx @@ -1,13 +1,15 @@ import { ReactNode, createContext, useMemo } from 'react'; import { useAccount, useBalance } from 'wagmi'; import { FLOCK_ADDRESS } from 'renderer/contracts/flock'; +import { FLOCK_V2_ADDRESS } from 'renderer/contracts/flockV2'; interface WalletContextProviderProps { children: ReactNode; } interface IWalletContext { - flockTokenBalance: any; + FLCTokenBalance: any; + FLOTokenBalance: any; nativeTokenBalance: any; } @@ -25,18 +27,25 @@ export function WalletContextProvider({ watch: true, }); - const { data: flockTokenBalance } = useBalance({ + const { data: FLCTokenBalance } = useBalance({ address: address as `0x${string}`, - token: FLOCK_ADDRESS, + token: FLOCK_ADDRESS as `0x${string}`, + watch: true, + }); + + const { data: FLOTokenBalance } = useBalance({ + address: address as `0x${string}`, + token: FLOCK_V2_ADDRESS as `0x${string}`, watch: true, }); const value = useMemo( () => ({ nativeTokenBalance, - flockTokenBalance, + FLCTokenBalance, + FLOTokenBalance, }), - [nativeTokenBalance, flockTokenBalance] + [nativeTokenBalance, FLCTokenBalance, FLOTokenBalance] ); return ( From fb31a03a07f22bb0a4704ed2446b892a2fbcfaa8 Mon Sep 17 00:00:00 2001 From: MIDAV0 Date: Wed, 27 Sep 2023 11:14:58 +0100 Subject: [PATCH 3/5] Added FLO --- src/renderer/components/Task.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/renderer/components/Task.tsx b/src/renderer/components/Task.tsx index 6335a9f..61c2f4d 100644 --- a/src/renderer/components/Task.tsx +++ b/src/renderer/components/Task.tsx @@ -100,7 +100,8 @@ function Task({ task, goBack }: TaskProps) { const navigate = useNavigate(); const { address } = useAccount(); - const { nativeTokenBalance, flockTokenBalance } = useContext(WalletContext); + const { nativeTokenBalance, FLCTokenBalance, FLOTokenBalance } = + useContext(WalletContext); const { runningTasks, runTask, logs } = useContext(RunnerContext); const [file, setFile] = useState({} as File); const [step, setStep] = useState('DETAIL'); @@ -471,7 +472,7 @@ function Task({ task, goBack }: TaskProps) { )} {Number(nativeTokenBalance?.value) !== 0 && - Number(flockTokenBalance?.value) === 0 && ( + Number(FLCTokenBalance?.value) === 0 && ( From 3479f12d04670841017222d92e61e893c39bf0ba Mon Sep 17 00:00:00 2001 From: MIDAV0 Date: Wed, 27 Sep 2023 11:15:10 +0100 Subject: [PATCH 4/5] New token --- src/renderer/components/Wallet.tsx | 24 +++-- src/renderer/pages/Faucet.tsx | 144 ++++++++++++----------------- 2 files changed, 77 insertions(+), 91 deletions(-) diff --git a/src/renderer/components/Wallet.tsx b/src/renderer/components/Wallet.tsx index 8b2640e..e67ce7c 100644 --- a/src/renderer/components/Wallet.tsx +++ b/src/renderer/components/Wallet.tsx @@ -18,6 +18,7 @@ import { useWaitForTransaction, } from 'wagmi'; import { FLOCK_ABI, FLOCK_ADDRESS } from 'renderer/contracts/flock'; +import { FLOCK_V2_ABI, FLOCK_V2_ADDRESS } from 'renderer/contracts/flockV2'; import { ToastContainer, toast } from 'react-toastify'; import { web3AuthInstance } from '../Web3AuthInstance'; import 'react-toastify/dist/ReactToastify.css'; @@ -33,7 +34,8 @@ function Wallet() { const { connectAsync, connectors, pendingConnector, isSuccess } = useConnect(); const { disconnect: wagmiDisconnect } = useDisconnect(); - const { nativeTokenBalance, flockTokenBalance } = useContext(WalletContext); + const { nativeTokenBalance, FLCTokenBalance, FLOTokenBalance } = + useContext(WalletContext); const [privateKey, setPrivateKey] = useState(''); const [userEmail, setUserEmail] = useState(''); const [showEmailImport, setShowEmailImport] = useState(false); @@ -162,8 +164,8 @@ function Wallet() { const { data: dataTransfer, writeAsync: writeAsyncApprove } = useContractWrite({ - address: FLOCK_ADDRESS as `0x${string}`, - abi: FLOCK_ABI, + address: FLOCK_V2_ADDRESS as `0x${string}`, + abi: FLOCK_V2_ABI, functionName: 'transfer', }); @@ -178,8 +180,12 @@ function Wallet() { }); }; - const roundedFLCBalance = flockTokenBalance - ? Math.round(Number(flockTokenBalance.formatted) * 100) / 100 + const roundedFLCBalance = FLCTokenBalance + ? Math.round(Number(FLCTokenBalance.formatted) * 100) / 100 + : 0; + + const roundedFLOBalance = FLOTokenBalance + ? Math.round(Number(FLOTokenBalance.formatted) * 100) / 100 : 0; const roundedMaticBalance = nativeTokenBalance @@ -215,6 +221,10 @@ function Wallet() { Wallet Address: {address} + + FLock(FLO) Balance: + {roundedFLOBalance} $F + FLock(FLC) Balance: {roundedFLCBalance} $F @@ -225,7 +235,7 @@ function Wallet() { - Transfer FLC tokens + Transfer FLO tokens ({}); + const [disabled, setDisabled] = useState(true); + const [isLoading, setIsLoading] = useState(false); + const { FLCTokenBalance } = useContext(WalletContext); + + const { data: dataMigrate, write: writeMigrate } = useContractWrite({ + address: MIGRATE_TOKENS_ADDRESS as `0x${string}`, + abi: MIGRATE_TOKENS_ABI, + functionName: 'migrate', + }); - const { data, write } = useContractWrite({ + const { data: dataApprove, write: writeApprove } = useContractWrite({ address: FLOCK_ADDRESS as `0x${string}`, abi: FLOCK_ABI, - functionName: 'mint', + functionName: 'approve', }); - const { isSuccess, isLoading } = useWaitForTransaction({ - hash: data?.hash, + const { isSuccess: isSuccessMigrate } = useWaitForTransaction({ + hash: dataMigrate?.hash, }); - const handleMint = async () => { - write?.({ args: [address, amount * 10 ** 18] }); + const { isSuccess: isSuccessApprove } = useWaitForTransaction({ + hash: dataApprove?.hash, + }); + + const handleApprove = async () => { + setIsLoading(true); + writeApprove?.({ + args: [MIGRATE_TOKENS_ADDRESS as `0x${string}`, FLCTokenBalance.value], + }); }; useEffect(() => { - if (isSuccess) { - toast.success(`Minted ${amount} FLC successfully`); + if (isSuccessApprove) { + writeMigrate?.(); } - setAmount(0); - }, [isSuccess]); + if (isSuccessMigrate) { + setIsLoading(false); + } + }, [isSuccessApprove, isSuccessMigrate]); const hasErrors = Object.keys(errors).length > 0; + useEffect(() => { + setDisabled(!address || hasErrors || isLoading); + }, [address, isLoading]); + + const roundedFLCBalance = FLCTokenBalance + ? Math.round(Number(FLCTokenBalance.formatted) * 100) / 100 + : 0; + return ( - + - - FLock (FLC) tokens faucet + + FLock (FLO) tokens faucet - Mint your FLC tokens for participating in the FLock network. + Migrate your FLC to FLO tokens for participating in the FLock network. - Contract Address: {FLOCK_ADDRESS} - - - {`To get testnet MATIC on Polygon Mumbai network visit this `} - - link - + {roundedFLCBalance} FLC tokens available to migrate. @@ -84,49 +93,16 @@ export default function Faucet() { justify="center" round="small" > -
{ - setErrors(validationResults.errors); - }} - > - - setAmount(e.target.value)} - /> - - -