From 92f446fd9514cf8ceab911a0d685bf445d0aba24 Mon Sep 17 00:00:00 2001 From: kkatusic Date: Mon, 11 Nov 2024 16:55:40 +0100 Subject: [PATCH 01/12] Fix/Recurring USDC donation month number and value --- .../views/donate/Recurring/RecurringDonationCard.tsx | 9 +++++++-- .../donate/Recurring/RecurringDonationModal/Item.tsx | 7 ++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/components/views/donate/Recurring/RecurringDonationCard.tsx b/src/components/views/donate/Recurring/RecurringDonationCard.tsx index d40b596581..7e7cfb9873 100644 --- a/src/components/views/donate/Recurring/RecurringDonationCard.tsx +++ b/src/components/views/donate/Recurring/RecurringDonationCard.tsx @@ -146,8 +146,12 @@ export const RecurringDonationCard = () => { const underlyingToken = selectedRecurringToken?.token.underlyingToken; + // Introduce a scaling factor to handle tokens with different decimals + const scaleFactor = + selectedRecurringToken?.token.decimals === 6 ? 10000n : 1n; + // total means project + giveth - const totalPerSec = perMonthAmount / ONE_MONTH_SECONDS; + const totalPerSec = perMonthAmount / (ONE_MONTH_SECONDS / scaleFactor); const projectPerMonth = (perMonthAmount * BigInt(100 - donationToGiveth)) / 100n; const givethPerMonth = perMonthAmount - projectPerMonth; @@ -168,7 +172,8 @@ export const RecurringDonationCard = () => { 0n, ) || 0n; const totalStreamPerSec = totalPerSec + otherStreamsPerSec; - const totalStreamPerMonth = totalStreamPerSec * ONE_MONTH_SECONDS; + const totalStreamPerMonth = + totalStreamPerSec * (ONE_MONTH_SECONDS / scaleFactor); const streamRunOutInMonth = totalStreamPerSec > 0 ? amount / totalStreamPerMonth : 0n; const isTotalStreamExceed = diff --git a/src/components/views/donate/Recurring/RecurringDonationModal/Item.tsx b/src/components/views/donate/Recurring/RecurringDonationModal/Item.tsx index 2366a6de13..44d2ccf395 100644 --- a/src/components/views/donate/Recurring/RecurringDonationModal/Item.tsx +++ b/src/components/views/donate/Recurring/RecurringDonationModal/Item.tsx @@ -29,10 +29,7 @@ export const Item: FC = ({ {limitFraction( - formatUnits( - amount, - token.underlyingToken?.decimals || 18, - ), + formatUnits(amount, token?.decimals || 18), )}  {token.symbol} @@ -47,7 +44,7 @@ export const Item: FC = ({ .multipliedBy(amount.toString()) .toFixed(0), ), - token.underlyingToken?.decimals || 18, + token?.decimals || 18, ), 2, )} From 7e3fbd10fa42f622863048c42d09c954e70da455 Mon Sep 17 00:00:00 2001 From: kkatusic Date: Tue, 12 Nov 2024 09:20:57 +0100 Subject: [PATCH 02/12] Fixing toggle option --- .../donate/Recurring/RecurringDonationCard.tsx | 8 ++++++++ src/config/production.tsx | 17 ++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/components/views/donate/Recurring/RecurringDonationCard.tsx b/src/components/views/donate/Recurring/RecurringDonationCard.tsx index 7e7cfb9873..b669daa804 100644 --- a/src/components/views/donate/Recurring/RecurringDonationCard.tsx +++ b/src/components/views/donate/Recurring/RecurringDonationCard.tsx @@ -243,6 +243,14 @@ export const RecurringDonationCard = () => { ? Number((perMonthAmount * 1000n) / amount) / 10 : 0; + // Reset the input value when the token is changed + useEffect(() => { + if (selectedRecurringToken || anchorContractAddress) { + setAmount(0n); + setPerMonthAmount(0n); + } + }, [anchorContractAddress, selectedRecurringToken]); + return ( <> diff --git a/src/config/production.tsx b/src/config/production.tsx index 27c51ceb91..462abed82b 100644 --- a/src/config/production.tsx +++ b/src/config/production.tsx @@ -526,13 +526,28 @@ const config: EnvConfig = { underlyingToken: { decimals: 6, id: '0x7f5c764cbc14f9669b88837ca1490cca17c31607', - name: 'USD Coin', + name: 'USD Coin E', symbol: 'USDC', coingeckoId: 'usd-coin', }, decimals: 18, id: '0x8430f084b939208e2eded1584889c9a66b90562f', name: 'Super USD Coin', + symbol: 'USDCe', + isSuperToken: true, + coingeckoId: 'usd-coin', + }, + { + underlyingToken: { + decimals: 6, + id: '0x0b2c639c533813f4aa9d7837caf62653d097ff85', + name: 'USD Coin', + symbol: 'USDC', + coingeckoId: 'usd-coin', + }, + decimals: 18, + id: '0x35adeb0638eb192755b6e52544650603fe65a006', + name: 'Super USD Coin', symbol: 'USDCx', isSuperToken: true, coingeckoId: 'usd-coin', From 99fa30a6da8f20690e02783d0e86c60fcb256f90 Mon Sep 17 00:00:00 2001 From: kkatusic <kkatusic@gmail.com> Date: Tue, 12 Nov 2024 13:14:32 +0100 Subject: [PATCH 03/12] symbol corrected --- src/config/production.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/production.tsx b/src/config/production.tsx index 462abed82b..a2f5b040a6 100644 --- a/src/config/production.tsx +++ b/src/config/production.tsx @@ -533,7 +533,7 @@ const config: EnvConfig = { decimals: 18, id: '0x8430f084b939208e2eded1584889c9a66b90562f', name: 'Super USD Coin', - symbol: 'USDCe', + symbol: 'USDC.ex', isSuperToken: true, coingeckoId: 'usd-coin', }, From 986dbdd7498536898f9aa0df4649fca9f8c31be8 Mon Sep 17 00:00:00 2001 From: kkatusic <kkatusic@gmail.com> Date: Tue, 12 Nov 2024 15:31:07 +0100 Subject: [PATCH 04/12] made test file --- pages/test2.tsx | 207 +++++++----------- .../RecurringDonationModal.tsx | 11 + 2 files changed, 91 insertions(+), 127 deletions(-) diff --git a/pages/test2.tsx b/pages/test2.tsx index c9256c9843..b85ee03b87 100644 --- a/pages/test2.tsx +++ b/pages/test2.tsx @@ -1,138 +1,91 @@ -import { useState } from 'react'; -import { useQueries } from '@tanstack/react-query'; -import { useAccount } from 'wagmi'; -import { - PublicKey, - LAMPORTS_PER_SOL, - Transaction, - SystemProgram, -} from '@solana/web3.js'; -import BigNumber from 'bignumber.js'; -import { useConnection, useWallet } from '@solana/wallet-adapter-react'; -import FailedDonation, { - EDonationFailedType, -} from '@/components/modals/FailedDonation'; -import { getTotalGIVpower } from '@/helpers/givpower'; -import { formatWeiHelper } from '@/helpers/number'; +import React from 'react'; +import { ethers } from 'ethers'; +import { Framework } from '@superfluid-finance/sdk-core'; import config from '@/configuration'; -import { fetchSubgraphData } from '@/services/subgraph.service'; const YourApp = () => { - const [failedModalType, setFailedModalType] = - useState<EDonationFailedType>(); - const { address } = useAccount(); - const subgraphValues = useQueries({ - queries: config.CHAINS_WITH_SUBGRAPH.map(chain => ({ - queryKey: ['subgraph', chain.id, address], - queryFn: async () => { - return await fetchSubgraphData(chain.id, address); - }, - staleTime: config.SUBGRAPH_POLLING_INTERVAL, - })), - }); - - // Solana wallet hooks - const { - publicKey, - disconnect: solanaWalletDisconnect, - signMessage: solanaSignMessage, - sendTransaction: solanaSendTransaction, - connecting: solanaIsConnecting, - connected: solanaIsConnected, - } = useWallet(); - - const { connection: solanaConnection } = useConnection(); - - const donateToSolana = async () => { - if (!publicKey) { - console.error('Wallet is not connected'); - return; - } - - console.log('Connection endpoint:', solanaConnection.rpcEndpoint); - - const to = 'B6bfJUMPnpL2ddngPPe3M7QNpvrv7hiYYiGtg9iCJDMS'; - const donationValue = 0.001; - - console.log('publicKey', publicKey); - console.log('Public Key string:', publicKey.toString()); - - // Ensure the wallet has enough funds by requesting an airdrop if necessary - let balance = await solanaConnection.getBalance(publicKey); - console.log('Initial balance:', balance); - if (balance < LAMPORTS_PER_SOL) { - console.log('Airdropping 1 SOL for testing...'); - const airdropSignature = await solanaConnection.requestAirdrop( - publicKey, - LAMPORTS_PER_SOL, + const handleApproveAndExecute = async () => { + try { + // Connect to MetaMask + if (!window.ethereum) { + alert('MetaMask not detected'); + return; + } + + const provider = new ethers.providers.Web3Provider(window.ethereum); + await provider.send('eth_requestAccounts', []); + const signer = provider.getSigner(); + const sf = await Framework.create({ + chainId: config.OPTIMISM_CONFIG.id, + provider, + }); + + // WORK 0x35adeb0638eb192755b6e52544650603fe65a006 USDCx + // NOT WORK 0x8430f084b939208e2eded1584889c9a66b90562f USDC.ex + + const address = await signer.getAddress(); + const usdcx = await sf.loadWrapperSuperToken( + '0x8430f084b939208e2eded1584889c9a66b90562f', ); - await solanaConnection.confirmTransaction(airdropSignature); - balance = await solanaConnection.getBalance(publicKey); - console.log('New balance:', balance); - } - - const lamports = new BigNumber(donationValue) - .times(LAMPORTS_PER_SOL) - .toFixed(); - - const transaction = new Transaction().add( - SystemProgram.transfer({ - fromPubkey: publicKey!, - toPubkey: new PublicKey(to), - lamports: BigInt(lamports), - }), - ); - - console.log('Transaction', transaction); - - console.log( - 'Fee Payer:', - transaction.feePayer ? transaction.feePayer.toBase58() : 'None', - ); - - transaction.feePayer = publicKey; - - const simulationResult = - await solanaConnection.simulateTransaction(transaction); - console.log('Simulation Result:', simulationResult); - - if (simulationResult.value.err) { - console.error('Simulation error:', simulationResult.value.err); - return; + const spenderAddress = '0x567c4B141ED61923967cA25Ef4906C8781069a10'; + + // Define the amount to approve (0.1 USDCx) + const amountToApprove = ethers.utils.parseUnits('0.01', 18); + + // Check current allowance + const allowance = await usdcx.allowance({ + owner: address, + spender: spenderAddress, + providerOrSigner: signer, + }); + + // If allowance is insufficient, approve the required amount + if (ethers.BigNumber.from(allowance).lt(amountToApprove)) { + const approveOperation = usdcx.approve({ + receiver: spenderAddress, + amount: amountToApprove.toString(), + }); + + // Get the populated transaction and send it with gasLimit + const populatedApproveTx = + await approveOperation.getPopulatedTransactionRequest( + signer, + ); + const approveTxResponse = await signer.sendTransaction({ + ...populatedApproveTx, + gasLimit: ethers.utils.hexlify(200000), + }); + await approveTxResponse.wait(); + console.log('Approved 0.01 USDCx for spending.'); + } else { + console.log('Already approved for 0.01 USDCx.'); + } + + // Now execute the main transaction (transfer) + const mainTransaction = await usdcx.transfer({ + receiver: spenderAddress, + amount: amountToApprove.toString(), + }); + + // Get the populated transaction and send it with gasLimit + const populatedTransferTx = + await mainTransaction.getPopulatedTransactionRequest(signer); + const transferTxResponse = await signer.sendTransaction({ + ...populatedTransferTx, + gasLimit: ethers.utils.hexlify(200000), + }); + await transferTxResponse.wait(); + console.log('Transaction executed successfully.'); + } catch (error) { + console.error('Error during approval or execution:', error); + alert('An error occurred. Check console for details.'); } - - const hash = await solanaSendTransaction(transaction, solanaConnection); - - console.log('hash', hash); }; return ( - <div> - <button onClick={donateToSolana}>DONATE ON SOLANA</button> - <w3m-button /> - <div> - <button - onClick={() => { - const totalgivpower = getTotalGIVpower( - subgraphValues, - address, - ); - console.log( - 'totalgivpower', - formatWeiHelper(totalgivpower.total), - ); - }} - > - Test Button - </button> - </div> - {failedModalType && ( - <FailedDonation - txUrl={'0x01121212'} - setShowModal={() => setFailedModalType(undefined)} - type={failedModalType} - /> - )} + <div style={{ textAlign: 'center', marginTop: '50px' }}> + <h1>Approve and Execute 0.1 USDC.ex</h1> + <button onClick={handleApproveAndExecute}>Approve & Execute</button> </div> ); }; diff --git a/src/components/views/donate/Recurring/RecurringDonationModal/RecurringDonationModal.tsx b/src/components/views/donate/Recurring/RecurringDonationModal/RecurringDonationModal.tsx index 76021e47e1..2bd6353364 100644 --- a/src/components/views/donate/Recurring/RecurringDonationModal/RecurringDonationModal.tsx +++ b/src/components/views/donate/Recurring/RecurringDonationModal/RecurringDonationModal.tsx @@ -217,6 +217,17 @@ const RecurringDonationInnerModal: FC<IRecurringDonationInnerModalProps> = ({ }; const sf = await Framework.create(_options); + const usdce = await sf.loadWrapperSuperToken( + '0x8430f084b939208e2eded1584889c9a66b90562f', + ); + console.log('USDC.ex SuperToken loaded:', usdce.address); + + const balance = await usdce.balanceOf({ + account: address, + providerOrSigner: signer, // Use the signer to ensure correct network + }); + console.log('USDC.ex SuperToken Balance:', balance.toString()); + // EThx is not a Wrapper Super Token and should load separately let superToken; if (_superToken.symbol === 'ETHx') { From ee193fabd95c8a3649eb139bd30135ba27b27c94 Mon Sep 17 00:00:00 2001 From: kkatusic <kkatusic@gmail.com> Date: Tue, 12 Nov 2024 21:15:21 +0100 Subject: [PATCH 05/12] refactoring isolated example --- pages/test2.tsx | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/pages/test2.tsx b/pages/test2.tsx index b85ee03b87..c647c9a7cb 100644 --- a/pages/test2.tsx +++ b/pages/test2.tsx @@ -1,7 +1,14 @@ import React from 'react'; import { ethers } from 'ethers'; import { Framework } from '@superfluid-finance/sdk-core'; -import config from '@/configuration'; + +const USDCx_TOKEN_ADDRESS = '0x35adeb0638eb192755b6e52544650603fe65a006'; +const USDCex_TOKEN_ADDRESS = '0x8430f084b939208e2eded1584889c9a66b90562f'; // NOT WORKING +const GIVETH_HOUSE_ADDRESS = '0x567c4B141ED61923967cA25Ef4906C8781069a10'; + +const OPTIMISM_CHAIN_ID = 10; + +const STREAM_VALUE = '0.01'; const YourApp = () => { const handleApproveAndExecute = async () => { @@ -16,21 +23,16 @@ const YourApp = () => { await provider.send('eth_requestAccounts', []); const signer = provider.getSigner(); const sf = await Framework.create({ - chainId: config.OPTIMISM_CONFIG.id, + chainId: OPTIMISM_CHAIN_ID, provider, }); - // WORK 0x35adeb0638eb192755b6e52544650603fe65a006 USDCx - // NOT WORK 0x8430f084b939208e2eded1584889c9a66b90562f USDC.ex - const address = await signer.getAddress(); - const usdcx = await sf.loadWrapperSuperToken( - '0x8430f084b939208e2eded1584889c9a66b90562f', - ); - const spenderAddress = '0x567c4B141ED61923967cA25Ef4906C8781069a10'; + const usdcx = await sf.loadWrapperSuperToken(USDCex_TOKEN_ADDRESS); + const spenderAddress = GIVETH_HOUSE_ADDRESS; - // Define the amount to approve (0.1 USDCx) - const amountToApprove = ethers.utils.parseUnits('0.01', 18); + // Define the amount to approve (X.XX USDCx) + const amountToApprove = ethers.utils.parseUnits(STREAM_VALUE, 18); // Check current allowance const allowance = await usdcx.allowance({ @@ -56,9 +58,9 @@ const YourApp = () => { gasLimit: ethers.utils.hexlify(200000), }); await approveTxResponse.wait(); - console.log('Approved 0.01 USDCx for spending.'); + console.log(`Approved ${STREAM_VALUE} USDC for spending.`); } else { - console.log('Already approved for 0.01 USDCx.'); + console.log(`Already approved for ${STREAM_VALUE} USDC.`); } // Now execute the main transaction (transfer) @@ -84,7 +86,7 @@ const YourApp = () => { return ( <div style={{ textAlign: 'center', marginTop: '50px' }}> - <h1>Approve and Execute 0.1 USDC.ex</h1> + <h1>Approve and Execute {STREAM_VALUE} USDC</h1> <button onClick={handleApproveAndExecute}>Approve & Execute</button> </div> ); From f6599bfa36163b956c2e82ef19c866c114972022 Mon Sep 17 00:00:00 2001 From: kkatusic <kkatusic@gmail.com> Date: Wed, 20 Nov 2024 19:39:48 +0100 Subject: [PATCH 06/12] update test2 example --- pages/test2.tsx | 161 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 151 insertions(+), 10 deletions(-) diff --git a/pages/test2.tsx b/pages/test2.tsx index c647c9a7cb..1633336da9 100644 --- a/pages/test2.tsx +++ b/pages/test2.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useEffect, useState } from 'react'; import { ethers } from 'ethers'; import { Framework } from '@superfluid-finance/sdk-core'; @@ -6,11 +6,26 @@ const USDCx_TOKEN_ADDRESS = '0x35adeb0638eb192755b6e52544650603fe65a006'; const USDCex_TOKEN_ADDRESS = '0x8430f084b939208e2eded1584889c9a66b90562f'; // NOT WORKING const GIVETH_HOUSE_ADDRESS = '0x567c4B141ED61923967cA25Ef4906C8781069a10'; -const OPTIMISM_CHAIN_ID = 10; +const TOKEN_ADDRESSES = [ + { name: 'USDCx', address: '0x35adeb0638eb192755b6e52544650603fe65a006' }, + { name: 'USDCex', address: '0x8430f084b939208e2eded1584889c9a66b90562f' }, + { name: 'USDC', address: '0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85' }, +]; -const STREAM_VALUE = '0.01'; +const OPTIMISM_CHAIN_ID = 10; const YourApp = () => { + const [tokens, setTokens] = useState< + { name: string; address: string; balance: string }[] + >([]); + const [selectedToken, setSelectedToken] = useState(''); + const [destinationAddress, setDestinationAddress] = useState( + '0x567c4B141ED61923967cA25Ef4906C8781069a10', + ); + const [loading, setLoading] = useState(true); + const [amount, setAmount] = useState('0.001'); // Initial amount + const [notification, setNotification] = useState(''); + const handleApproveAndExecute = async () => { try { // Connect to MetaMask @@ -28,11 +43,11 @@ const YourApp = () => { }); const address = await signer.getAddress(); - const usdcx = await sf.loadWrapperSuperToken(USDCex_TOKEN_ADDRESS); + const usdcx = await sf.loadWrapperSuperToken(selectedToken); const spenderAddress = GIVETH_HOUSE_ADDRESS; // Define the amount to approve (X.XX USDCx) - const amountToApprove = ethers.utils.parseUnits(STREAM_VALUE, 18); + const amountToApprove = ethers.utils.parseUnits(amount, 18); // Check current allowance const allowance = await usdcx.allowance({ @@ -58,9 +73,9 @@ const YourApp = () => { gasLimit: ethers.utils.hexlify(200000), }); await approveTxResponse.wait(); - console.log(`Approved ${STREAM_VALUE} USDC for spending.`); + console.log(`Approved ${amount} USDC for spending.`); } else { - console.log(`Already approved for ${STREAM_VALUE} USDC.`); + console.log(`Already approved for ${amount} USDC.`); } // Now execute the main transaction (transfer) @@ -78,16 +93,142 @@ const YourApp = () => { }); await transferTxResponse.wait(); console.log('Transaction executed successfully.'); + setNotification('Transaction executed successfully!'); + setTimeout(() => setNotification(''), 5000); // Clear notification after 5 seconds } catch (error) { console.error('Error during approval or execution:', error); - alert('An error occurred. Check console for details.'); + setNotification( + 'Transaction failed! Please check the console for details.', + ); + setTimeout(() => setNotification(''), 5000); } }; + useEffect(() => { + const fetchTokens = async () => { + try { + if (!window.ethereum) { + alert('MetaMask not detected'); + return; + } + + const provider = new ethers.providers.Web3Provider( + window.ethereum, + ); + await provider.send('eth_requestAccounts', []); + const signer = provider.getSigner(); + const address = await signer.getAddress(); + + const balances = await Promise.all( + TOKEN_ADDRESSES.map(async token => { + const contract = new ethers.Contract( + token.address, + [ + // ERC20 ABI for balanceOf and decimals + 'function balanceOf(address owner) view returns (uint256)', + 'function decimals() view returns (uint8)', + ], + provider, + ); + + const balance = await contract.balanceOf(address); + const decimals = await contract.decimals(); + + return { + name: token.name, + address: token.address, + balance: ethers.utils.formatUnits( + balance, + decimals, + ), + }; + }), + ); + + setTokens(balances); + setSelectedToken(balances[0]?.address || ''); + setLoading(false); + } catch (error) { + console.error('Error fetching tokens:', error); + alert('An error occurred while fetching tokens.'); + } + }; + + fetchTokens(); + }, []); + return ( <div style={{ textAlign: 'center', marginTop: '50px' }}> - <h1>Approve and Execute {STREAM_VALUE} USDC</h1> - <button onClick={handleApproveAndExecute}>Approve & Execute</button> + <h1>Approve and Execute {amount} USDC</h1> + <h3> + Network ID: {OPTIMISM_CHAIN_ID} <em>Optimism Network</em> + </h3> + <h3> + Transaction to wallet: {GIVETH_HOUSE_ADDRESS} + <em>Giveth House</em> + </h3> + <div> + <h3>Select a Token</h3> + {loading ? ( + <p>Loading tokens...</p> + ) : ( + <select + value={selectedToken} + onChange={e => setSelectedToken(e.target.value)} + style={{ padding: '10px 20px' }} + > + {tokens.map(token => ( + <option key={token.address} value={token.address}> + {token.name} - ${token.balance} -{' '} + {token.address} + </option> + ))} + </select> + )} + </div> + <br /> + <div> + <h3>Enter Amount</h3> + <input + type='text' + value={amount} + onChange={e => setAmount(e.target.value)} + style={{ padding: '10px', width: '200px' }} + /> + </div> + <br /> + <div> + <h3>Destination Address</h3> + <input + type='text' + value={destinationAddress} + onChange={e => setDestinationAddress(e.target.value)} + style={{ padding: '10px', width: '500px' }} + /> + </div> + <br /> + <button + onClick={handleApproveAndExecute} + style={{ padding: '10px 20px' }} + > + Approve & Execute + </button> + {notification && ( + <div + style={{ + position: 'fixed', + bottom: '10px', + right: '10px', + backgroundColor: '#4caf50', + color: 'white', + padding: '15px', + borderRadius: '5px', + boxShadow: '0 0 10px rgba(0,0,0,0.2)', + }} + > + {notification} + </div> + )} </div> ); }; From 7ab265c50248065ce2d6117ce36e8261a899a152 Mon Sep 17 00:00:00 2001 From: kkatusic <kkatusic@gmail.com> Date: Wed, 20 Nov 2024 19:48:30 +0100 Subject: [PATCH 07/12] added optimism for testing purpose --- src/config/development.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/config/development.tsx b/src/config/development.tsx index 11f737c951..228b678061 100644 --- a/src/config/development.tsx +++ b/src/config/development.tsx @@ -4,6 +4,7 @@ import { gnosis, sepolia, optimismSepolia, + optimism, polygon, arbitrumSepolia, baseSepolia, @@ -121,6 +122,7 @@ const EVM_CHAINS = [ sepolia, gnosis, optimismSepolia, + optimism, celoAlfajores, arbitrumSepolia, baseSepolia, From 932e2d7ab6204fd4c830ee244ff79c41b3bee5ad Mon Sep 17 00:00:00 2001 From: kkatusic <kkatusic@gmail.com> Date: Wed, 20 Nov 2024 20:31:02 +0100 Subject: [PATCH 08/12] added one more token to test --- pages/test2.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pages/test2.tsx b/pages/test2.tsx index 1633336da9..7c6c62e4e7 100644 --- a/pages/test2.tsx +++ b/pages/test2.tsx @@ -7,9 +7,16 @@ const USDCex_TOKEN_ADDRESS = '0x8430f084b939208e2eded1584889c9a66b90562f'; // NO const GIVETH_HOUSE_ADDRESS = '0x567c4B141ED61923967cA25Ef4906C8781069a10'; const TOKEN_ADDRESSES = [ - { name: 'USDCx', address: '0x35adeb0638eb192755b6e52544650603fe65a006' }, { name: 'USDCex', address: '0x8430f084b939208e2eded1584889c9a66b90562f' }, - { name: 'USDC', address: '0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85' }, + { + name: 'USDC bridge', + address: '0x7f5c764cbc14f9669b88837ca1490cca17c31607', + }, + { name: 'USDCx', address: '0x35adeb0638eb192755b6e52544650603fe65a006' }, + { + name: 'USDC native', + address: '0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85', + }, ]; const OPTIMISM_CHAIN_ID = 10; From eed623722a4167bb3733296e14c07d06340dd45c Mon Sep 17 00:00:00 2001 From: kkatusic <kkatusic@gmail.com> Date: Wed, 20 Nov 2024 21:26:13 +0100 Subject: [PATCH 09/12] test example with all tokens --- pages/test2.tsx | 198 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 146 insertions(+), 52 deletions(-) diff --git a/pages/test2.tsx b/pages/test2.tsx index 7c6c62e4e7..d3bc0de8c3 100644 --- a/pages/test2.tsx +++ b/pages/test2.tsx @@ -2,20 +2,28 @@ import React, { useEffect, useState } from 'react'; import { ethers } from 'ethers'; import { Framework } from '@superfluid-finance/sdk-core'; -const USDCx_TOKEN_ADDRESS = '0x35adeb0638eb192755b6e52544650603fe65a006'; -const USDCex_TOKEN_ADDRESS = '0x8430f084b939208e2eded1584889c9a66b90562f'; // NOT WORKING const GIVETH_HOUSE_ADDRESS = '0x567c4B141ED61923967cA25Ef4906C8781069a10'; const TOKEN_ADDRESSES = [ - { name: 'USDCex', address: '0x8430f084b939208e2eded1584889c9a66b90562f' }, { - name: 'USDC bridge', + name: 'USDCex', + address: '0x8430f084b939208e2eded1584889c9a66b90562f', + decimals: 18, + }, + { + name: 'USDC bridged', address: '0x7f5c764cbc14f9669b88837ca1490cca17c31607', + decimals: 6, + }, + { + name: 'USDCx', + address: '0x35adeb0638eb192755b6e52544650603fe65a006', + decimals: 18, }, - { name: 'USDCx', address: '0x35adeb0638eb192755b6e52544650603fe65a006' }, { name: 'USDC native', address: '0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85', + decimals: 6, }, ]; @@ -26,13 +34,44 @@ const YourApp = () => { { name: string; address: string; balance: string }[] >([]); const [selectedToken, setSelectedToken] = useState(''); - const [destinationAddress, setDestinationAddress] = useState( - '0x567c4B141ED61923967cA25Ef4906C8781069a10', - ); + const [destinationAddress, setDestinationAddress] = + useState(GIVETH_HOUSE_ADDRESS); const [loading, setLoading] = useState(true); const [amount, setAmount] = useState('0.001'); // Initial amount const [notification, setNotification] = useState(''); + const determineTokenType = async ( + sf: { + loadNativeAssetSuperToken: (arg0: any) => any; + loadWrapperSuperToken: (arg0: any) => any; + }, + tokenAddress: any, + ) => { + let superToken; + + // Check if it's a native super token + try { + superToken = await sf.loadNativeAssetSuperToken(tokenAddress); + console.log('Native Super Token detected.'); + return { type: 'native', superToken }; + } catch (error) { + console.log('Not a Native Super Token.'); + } + + // Check if it's a wrapper super token + try { + superToken = await sf.loadWrapperSuperToken(tokenAddress); + console.log('Wrapper Super Token detected.'); + return { type: 'wrapper', superToken }; + } catch (error) { + console.log('Not a Wrapper Super Token.'); + } + + // If both checks fail, it's a regular ERC-20 token + console.log('Regular ERC-20 token detected.'); + return { type: 'erc20', superToken: null }; + }; + const handleApproveAndExecute = async () => { try { // Connect to MetaMask @@ -50,64 +89,119 @@ const YourApp = () => { }); const address = await signer.getAddress(); - const usdcx = await sf.loadWrapperSuperToken(selectedToken); - const spenderAddress = GIVETH_HOUSE_ADDRESS; + + // Get token details (decimals, etc.) + const token = TOKEN_ADDRESSES.find( + t => t.address === selectedToken, + ); + if (!token) { + alert('Invalid token selected.'); + return; + } + const tokenDecimals = token.decimals; // Define the amount to approve (X.XX USDCx) - const amountToApprove = ethers.utils.parseUnits(amount, 18); + const amountToApprove = ethers.utils.parseUnits( + amount, + tokenDecimals, + ); - // Check current allowance - const allowance = await usdcx.allowance({ - owner: address, - spender: spenderAddress, - providerOrSigner: signer, - }); + // Determine the token type + const { type, superToken } = await determineTokenType( + sf, + selectedToken, + ); - // If allowance is insufficient, approve the required amount - if (ethers.BigNumber.from(allowance).lt(amountToApprove)) { - const approveOperation = usdcx.approve({ - receiver: spenderAddress, + console.log('Super type:', type); + console.log('Super Token:', superToken); + + if (type === 'native' || type === 'wrapper') { + console.log( + `${type.charAt(0).toUpperCase() + type.slice(1)} Super Token detected`, + ); + + // Attempt to check allowance (skip if it fails) + let allowance; + try { + allowance = await superToken.allowance({ + owner: await signer.getAddress(), + spender: destinationAddress, + providerOrSigner: signer, + }); + console.log(`Current allowance: ${allowance.toString()}`); + } catch (error) { + console.log( + 'Allowance does not exist or cannot be fetched. Proceeding to approve...', + ); + } + + // Approve if needed + if (ethers.BigNumber.from(allowance).lt(amountToApprove)) { + const approveOperation = superToken.approve({ + receiver: destinationAddress, + amount: amountToApprove.toString(), + }); + + const approveTxResponse = await signer.sendTransaction( + await approveOperation.getPopulatedTransactionRequest( + signer, + ), + ); + await approveTxResponse.wait(); + console.log(`Approved ${amount} ${type} super tokens.`); + } + + // Transfer or execute the operation + const transferOperation = superToken.transfer({ + receiver: destinationAddress, amount: amountToApprove.toString(), }); - // Get the populated transaction and send it with gasLimit - const populatedApproveTx = - await approveOperation.getPopulatedTransactionRequest( + const transferTxResponse = await signer.sendTransaction( + await transferOperation.getPopulatedTransactionRequest( signer, - ); - const approveTxResponse = await signer.sendTransaction({ - ...populatedApproveTx, - gasLimit: ethers.utils.hexlify(200000), - }); - await approveTxResponse.wait(); - console.log(`Approved ${amount} USDC for spending.`); - } else { - console.log(`Already approved for ${amount} USDC.`); - } + ), + ); + await transferTxResponse.wait(); + console.log('Super token transaction executed.'); + setNotification( + 'Super Token transaction executed successfully!', + ); + } else if (type === 'erc20') { + console.log('Regular ERC-20 token detected'); + const erc20Contract = new ethers.Contract( + selectedToken, + [ + 'function approve(address spender, uint256 amount) public returns (bool)', + 'function transfer(address recipient, uint256 amount) public returns (bool)', + ], + signer, + ); - // Now execute the main transaction (transfer) - const mainTransaction = await usdcx.transfer({ - receiver: spenderAddress, - amount: amountToApprove.toString(), - }); + // Approve the transfer + const approveTx = await erc20Contract.approve( + destinationAddress, + amountToApprove, + ); + await approveTx.wait(); + console.log(`Approved ${amount} regular ERC-20 tokens.`); - // Get the populated transaction and send it with gasLimit - const populatedTransferTx = - await mainTransaction.getPopulatedTransactionRequest(signer); - const transferTxResponse = await signer.sendTransaction({ - ...populatedTransferTx, - gasLimit: ethers.utils.hexlify(200000), - }); - await transferTxResponse.wait(); - console.log('Transaction executed successfully.'); - setNotification('Transaction executed successfully!'); - setTimeout(() => setNotification(''), 5000); // Clear notification after 5 seconds + // Execute the transfer + const transferTx = await erc20Contract.transfer( + destinationAddress, + amountToApprove, + ); + await transferTx.wait(); + console.log('Regular token transaction executed.'); + setNotification( + 'Regular ERC-20 transaction executed successfully!', + ); + } } catch (error) { console.error('Error during approval or execution:', error); setNotification( 'Transaction failed! Please check the console for details.', ); - setTimeout(() => setNotification(''), 5000); } }; @@ -171,7 +265,7 @@ const YourApp = () => { Network ID: {OPTIMISM_CHAIN_ID} <em>Optimism Network</em> </h3> <h3> - Transaction to wallet: {GIVETH_HOUSE_ADDRESS} + Transaction to wallet: {destinationAddress} <em>Giveth House</em> </h3> <div> From 38ca0ce916616457b241189160730158cc1ab3a9 Mon Sep 17 00:00:00 2001 From: kkatusic <kkatusic@gmail.com> Date: Thu, 21 Nov 2024 00:41:06 +0100 Subject: [PATCH 10/12] added stream --- pages/test2.tsx | 75 +++++++++++++++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 27 deletions(-) diff --git a/pages/test2.tsx b/pages/test2.tsx index d3bc0de8c3..d417b23647 100644 --- a/pages/test2.tsx +++ b/pages/test2.tsx @@ -88,6 +88,8 @@ const YourApp = () => { provider, }); + console.log({ sf }); + const address = await signer.getAddress(); // Get token details (decimals, etc.) @@ -106,12 +108,15 @@ const YourApp = () => { tokenDecimals, ); + const flowRatePerSecond = amountToApprove.div(30 * 24 * 60 * 60); // Convert monthly to per-second rate + // Determine the token type const { type, superToken } = await determineTokenType( sf, selectedToken, ); + console.log('Selected token:', selectedToken); console.log('Super type:', type); console.log('Super Token:', superToken); @@ -151,51 +156,67 @@ const YourApp = () => { console.log(`Approved ${amount} ${type} super tokens.`); } - // Transfer or execute the operation - const transferOperation = superToken.transfer({ + // Create the stream + const createFlowOperation = superToken.createFlow({ + sender: address, receiver: destinationAddress, - amount: amountToApprove.toString(), + flowRate: flowRatePerSecond.toString(), }); - const transferTxResponse = await signer.sendTransaction( - await transferOperation.getPopulatedTransactionRequest( - signer, - ), - ); - await transferTxResponse.wait(); - console.log('Super token transaction executed.'); - setNotification( - 'Super Token transaction executed successfully!', + console.log({ createFlowOperation }); + + const flowTxResponse = await createFlowOperation.exec( + signer, + 50, ); + await flowTxResponse.wait(); + console.log('Stream created successfully.'); + setNotification('Stream created successfully!'); } else if (type === 'erc20') { - console.log('Regular ERC-20 token detected'); + console.log( + 'Regular ERC-20 token detected. Upgrading to Super Token...', + ); + const wrapperSuperToken = + await sf.loadSuperToken(selectedToken); + + console.log({ wrapperSuperToken }); + + // Approve upgrade if needed const erc20Contract = new ethers.Contract( selectedToken, [ 'function approve(address spender, uint256 amount) public returns (bool)', - 'function transfer(address recipient, uint256 amount) public returns (bool)', ], signer, ); - - // Approve the transfer const approveTx = await erc20Contract.approve( - destinationAddress, + wrapperSuperToken.address, amountToApprove, ); await approveTx.wait(); - console.log(`Approved ${amount} regular ERC-20 tokens.`); + console.log('ERC-20 token approved for upgrade.'); + + // Upgrade ERC20 to Super Token + // const upgradeOp = wrapperSuperToken.upgrade({ + // amount: amountToApprove.toString(), + // }); + // await upgradeOp.exec(signer); + // console.log('Upgrade complete.'); + + // Create the stream + const createFlowOperation = wrapperSuperToken.createFlow({ + sender: address, + receiver: destinationAddress, + flowRate: flowRatePerSecond.toString(), + }); - // Execute the transfer - const transferTx = await erc20Contract.transfer( - destinationAddress, - amountToApprove, - ); - await transferTx.wait(); - console.log('Regular token transaction executed.'); - setNotification( - 'Regular ERC-20 transaction executed successfully!', + const flowTxResponse = await createFlowOperation.exec( + signer, + 50, ); + await flowTxResponse.wait(); + console.log('Stream created successfully.'); + setNotification('Stream created successfully!'); } } catch (error) { console.error('Error during approval or execution:', error); From 3c8fbd99d3803e18f8c15adc287fa0a31c03c0e5 Mon Sep 17 00:00:00 2001 From: kkatusic <kkatusic@gmail.com> Date: Fri, 22 Nov 2024 14:45:12 +0100 Subject: [PATCH 11/12] wrapped logic is working --- pages/test2.tsx | 281 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 240 insertions(+), 41 deletions(-) diff --git a/pages/test2.tsx b/pages/test2.tsx index d417b23647..4fade28052 100644 --- a/pages/test2.tsx +++ b/pages/test2.tsx @@ -1,6 +1,6 @@ import React, { useEffect, useState } from 'react'; import { ethers } from 'ethers'; -import { Framework } from '@superfluid-finance/sdk-core'; +import { Framework, Operation } from '@superfluid-finance/sdk-core'; const GIVETH_HOUSE_ADDRESS = '0x567c4B141ED61923967cA25Ef4906C8781069a10'; @@ -72,6 +72,40 @@ const YourApp = () => { return { type: 'erc20', superToken: null }; }; + // Function to check if a flow exists + const checkIfFlowExists = async ( + sf: { + cfaV1: { + getFlow: (arg0: { + superToken: any; + sender: any; + receiver: any; + providerOrSigner: any; + }) => any; + }; + }, + superTokenAddress: any, + senderAddress: any, + receiverAddress: any, + signer: any, + ) => { + try { + const flowInfo = await sf.cfaV1.getFlow({ + superToken: superTokenAddress, + sender: senderAddress, + receiver: receiverAddress, + providerOrSigner: signer, + }); + console.log( + `Existing flow found. Current flow rate: ${flowInfo.flowRate}`, + ); + return { exists: true, flowRate: flowInfo.flowRate }; + } catch (error) { + console.log('No existing flow found.'); + return { exists: false, flowRate: '0' }; + } + }; + const handleApproveAndExecute = async () => { try { // Connect to MetaMask @@ -156,67 +190,232 @@ const YourApp = () => { console.log(`Approved ${amount} ${type} super tokens.`); } - // Create the stream - const createFlowOperation = superToken.createFlow({ - sender: address, - receiver: destinationAddress, - flowRate: flowRatePerSecond.toString(), - }); - - console.log({ createFlowOperation }); + // // Create the stream + // const createFlowOperation = superToken.createFlow({ + // sender: address, + // receiver: destinationAddress, + // flowRate: flowRatePerSecond.toString(), + // }); - const flowTxResponse = await createFlowOperation.exec( + // console.log({ createFlowOperation }); + + // const flowTxResponse = await createFlowOperation.exec(signer); + // await flowTxResponse.wait(); + // console.log('Stream created successfully.'); + // setNotification('Stream created successfully!'); + // Check for existing flow + const flowStatus = await checkIfFlowExists( + sf, + superToken.address, + address, + destinationAddress, signer, - 50, ); - await flowTxResponse.wait(); - console.log('Stream created successfully.'); - setNotification('Stream created successfully!'); + + if (flowStatus.exists && flowStatus.flowRate !== '0') { + // Add new flow rate to existing flow rate + const newFlowRate = ethers.BigNumber.from( + flowStatus.flowRate, + ).add(flowRatePerSecond); + + // Update the flow + const updateFlowOperation = superToken.updateFlow({ + sender: address, + receiver: destinationAddress, + flowRate: newFlowRate.toString(), // New total flow rate + }); + + console.log('Updating existing flow...'); + const updateFlowTxResponse = await updateFlowOperation.exec( + signer, + 70, + ); + await updateFlowTxResponse.wait(); + console.log('Flow updated successfully.'); + setNotification('Flow updated successfully!'); + } else { + // Create a new flow if none exists + const createFlowOperation = superToken.createFlow({ + sender: address, + receiver: destinationAddress, + flowRate: flowRatePerSecond.toString(), // New flow rate + }); + + console.log('Creating new flow...'); + const createFlowTxResponse = await createFlowOperation.exec( + signer, + 2, + ); + await createFlowTxResponse.wait(); + console.log('Flow created successfully.'); + setNotification('Flow created successfully!'); + } } else if (type === 'erc20') { - console.log( - 'Regular ERC-20 token detected. Upgrading to Super Token...', - ); + // console.log( + // 'Regular ERC-20 token detected. Upgrading to Super Token...', + // ); + // const wrapperSuperToken = + // await sf.loadSuperToken(selectedToken); + // console.log({ wrapperSuperToken }); + // // Approve upgrade if needed + // const erc20Contract = new ethers.Contract( + // selectedToken, + // [ + // 'function approve(address spender, uint256 amount) public returns (bool)', + // ], + // signer, + // ); + // const approveTx = await erc20Contract.approve( + // wrapperSuperToken.address, + // amountToApprove, + // ); + // await approveTx.wait(); + // console.log('ERC-20 token approved for upgrade.'); + // // Upgrade ERC20 to Super Token + // // const upgradeOp = wrapperSuperToken.upgrade({ + // // amount: amountToApprove.toString(), + // // }); + // // await upgradeOp.exec(signer); + // // console.log('Upgrade complete.'); + // // Create the stream + // const createFlowOperation = wrapperSuperToken.createFlow({ + // sender: address, + // receiver: destinationAddress, + // flowRate: flowRatePerSecond.toString(), + // }); + // const flowTxResponse = await createFlowOperation.exec( + // signer, + // 50, + // ); + // await flowTxResponse.wait(); + // console.log('Stream created successfully.'); + // setNotification('Stream created successfully!'); + console.log('Approving underlying ERC-20 token for upgrade...'); + + const operations: Operation[] = []; + const wrapperSuperToken = await sf.loadSuperToken(selectedToken); - console.log({ wrapperSuperToken }); - - // Approve upgrade if needed const erc20Contract = new ethers.Contract( - selectedToken, + selectedToken, // Underlying ERC-20 token address [ 'function approve(address spender, uint256 amount) public returns (bool)', ], signer, ); + + // Approve the Super Token contract to spend the ERC-20 token const approveTx = await erc20Contract.approve( - wrapperSuperToken.address, - amountToApprove, + wrapperSuperToken.address, // Address of the Super Token + amountToApprove.toString(), ); await approveTx.wait(); - console.log('ERC-20 token approved for upgrade.'); + console.log('Underlying ERC-20 token approved for upgrade.'); + + // Interact with the Super Token contract to perform the upgrade + const superTokenAbi = [ + 'function upgrade(uint256 amount) external', + ]; + // const superTokenContract = new ethers.Contract( + // wrapperSuperToken.address, + // superTokenAbi, + // signer, + // ); + + console.log('Upgrading ERC-20 token to Super Token...'); + const newSuperToken = await sf.loadWrapperSuperToken( + '0x35adeb0638eb192755b6e52544650603fe65a006', + ); - // Upgrade ERC20 to Super Token - // const upgradeOp = wrapperSuperToken.upgrade({ - // amount: amountToApprove.toString(), - // }); - // await upgradeOp.exec(signer); - // console.log('Upgrade complete.'); - - // Create the stream - const createFlowOperation = wrapperSuperToken.createFlow({ - sender: address, - receiver: destinationAddress, - flowRate: flowRatePerSecond.toString(), + console.log({ newSuperToken }); + + const upgradeTx = await newSuperToken.upgrade({ + amount: amountToApprove.toString(), }); + // await upgradeTx.wait(); + // await upgradeTx.exec(signer); + operations.push(upgradeTx); + console.log('Upgrade to Super Token complete.', upgradeTx); + + // Attempt to check allowance (skip if it fails) + let allowance; + try { + allowance = await newSuperToken.allowance({ + owner: await signer.getAddress(), + spender: destinationAddress, + providerOrSigner: signer, + }); + console.log(`Current allowance: ${allowance.toString()}`); + } catch (error) { + console.log( + 'Allowance does not exist or cannot be fetched. Proceeding to approve...', + ); + } + + // Approve if needed + if (ethers.BigNumber.from(allowance).lt(amountToApprove)) { + const approveOperation = newSuperToken.approve({ + receiver: destinationAddress, + amount: amountToApprove.toString(), + }); - const flowTxResponse = await createFlowOperation.exec( + const approveTxResponse = await signer.sendTransaction( + await approveOperation.getPopulatedTransactionRequest( + signer, + ), + ); + await approveTxResponse.wait(); + console.log(`Approved ${amount} ${type} super tokens.`); + } + + // Create or update the stream + const flowStatus = await checkIfFlowExists( + sf, + newSuperToken.address, + address, + destinationAddress, signer, - 50, ); - await flowTxResponse.wait(); - console.log('Stream created successfully.'); - setNotification('Stream created successfully!'); + + if (flowStatus.exists && flowStatus.flowRate !== '0') { + console.log('Updating existing flow...'); + const updateFlowOperation = newSuperToken.updateFlow({ + sender: address, + receiver: destinationAddress, + flowRate: flowRatePerSecond.toString(), // New flow rate + }); + // const flowTxResponse = + // await updateFlowOperation.exec(signer); + // await flowTxResponse.wait(); + + operations.push(updateFlowOperation); + + const batchOp = sf.batchCall(operations); + const txUpdate = await batchOp.exec(signer, 70); + + console.log('Flow updated successfully.', txUpdate); + setNotification('Flow updated successfully!'); + } else { + console.log('Creating new flow...'); + const createFlowOperation = newSuperToken.createFlow({ + sender: address, + receiver: destinationAddress, + flowRate: flowRatePerSecond.toString(), // New flow rate + }); + // const flowTxResponse = await createFlowOperation.exec( + // signer, + // 2, + // ); + // await flowTxResponse.wait(); + operations.push(createFlowOperation); + + const batchOp = sf.batchCall(operations); + const txCreate = await batchOp.exec(signer, 70); + + console.log('Flow created successfully.', txCreate); + setNotification('Flow created successfully!'); + } } } catch (error) { console.error('Error during approval or execution:', error); From fe70e6c4e76ebe5715d90da1d56cbac6ad028796 Mon Sep 17 00:00:00 2001 From: kkatusic <kkatusic@gmail.com> Date: Fri, 22 Nov 2024 21:09:50 +0100 Subject: [PATCH 12/12] removed unused code --- pages/test2.tsx | 58 +++---------------------------------------------- 1 file changed, 3 insertions(+), 55 deletions(-) diff --git a/pages/test2.tsx b/pages/test2.tsx index 4fade28052..2ada14f76b 100644 --- a/pages/test2.tsx +++ b/pages/test2.tsx @@ -190,19 +190,6 @@ const YourApp = () => { console.log(`Approved ${amount} ${type} super tokens.`); } - // // Create the stream - // const createFlowOperation = superToken.createFlow({ - // sender: address, - // receiver: destinationAddress, - // flowRate: flowRatePerSecond.toString(), - // }); - - // console.log({ createFlowOperation }); - - // const flowTxResponse = await createFlowOperation.exec(signer); - // await flowTxResponse.wait(); - // console.log('Stream created successfully.'); - // setNotification('Stream created successfully!'); // Check for existing flow const flowStatus = await checkIfFlowExists( sf, @@ -251,45 +238,6 @@ const YourApp = () => { setNotification('Flow created successfully!'); } } else if (type === 'erc20') { - // console.log( - // 'Regular ERC-20 token detected. Upgrading to Super Token...', - // ); - // const wrapperSuperToken = - // await sf.loadSuperToken(selectedToken); - // console.log({ wrapperSuperToken }); - // // Approve upgrade if needed - // const erc20Contract = new ethers.Contract( - // selectedToken, - // [ - // 'function approve(address spender, uint256 amount) public returns (bool)', - // ], - // signer, - // ); - // const approveTx = await erc20Contract.approve( - // wrapperSuperToken.address, - // amountToApprove, - // ); - // await approveTx.wait(); - // console.log('ERC-20 token approved for upgrade.'); - // // Upgrade ERC20 to Super Token - // // const upgradeOp = wrapperSuperToken.upgrade({ - // // amount: amountToApprove.toString(), - // // }); - // // await upgradeOp.exec(signer); - // // console.log('Upgrade complete.'); - // // Create the stream - // const createFlowOperation = wrapperSuperToken.createFlow({ - // sender: address, - // receiver: destinationAddress, - // flowRate: flowRatePerSecond.toString(), - // }); - // const flowTxResponse = await createFlowOperation.exec( - // signer, - // 50, - // ); - // await flowTxResponse.wait(); - // console.log('Stream created successfully.'); - // setNotification('Stream created successfully!'); console.log('Approving underlying ERC-20 token for upgrade...'); const operations: Operation[] = []; @@ -314,9 +262,9 @@ const YourApp = () => { console.log('Underlying ERC-20 token approved for upgrade.'); // Interact with the Super Token contract to perform the upgrade - const superTokenAbi = [ - 'function upgrade(uint256 amount) external', - ]; + // const superTokenAbi = [ + // 'function upgrade(uint256 amount) external', + // ]; // const superTokenContract = new ethers.Contract( // wrapperSuperToken.address, // superTokenAbi,