diff --git a/src/components/ui/dialog.tsx b/src/components/ui/dialog.tsx index a155911..d9fbe9b 100644 --- a/src/components/ui/dialog.tsx +++ b/src/components/ui/dialog.tsx @@ -13,14 +13,13 @@ import toast from 'react-hot-toast'; import useWeb3auth, { chainConfig } from '@/hooks/useWeb3auth'; import { PurchaseSubsAvaGasslessBundle, - PurchaseSubsPolygon, + PurchaseSubsAmoyGasslessBundle, approveNSubscribe, batchSubscribeFor, chainLinkAutomationSubscription, checkUserBalanceAvaWeb3Auth, - checkUserBalancePolygonWeb3Auth, + checkUserBalanceAmoyWeb3Auth, checkUserBalanceWeb3Auth, - getPolygonFundsWeb3Auth, getTestFundsWeb3Auth, mintingNft, } from '@/lib/func'; @@ -214,7 +213,7 @@ export default function MyModal({ } } else if (walletChosen === 'Polygon') { setProgress(10); - const resp = await PurchaseSubsPolygon( + const resp = await PurchaseSubsAmoyGasslessBundle( smartAccount, modelId, subscriptionId, @@ -253,8 +252,8 @@ export default function MyModal({ } }; - const insufficiantPolygonBalance = async () => { - const amount = await checkUserBalancePolygonWeb3Auth(smartAccount); + const insufficiantAmoyBalance = async () => { + const amount = await checkUserBalanceAmoyWeb3Auth(smartAccount); if (parseInt(amount.signerBalance) < value) { setLoadingState( `Insufficient Funds need ${ @@ -270,7 +269,8 @@ export default function MyModal({ } else if (walletChosen === 'avalanche') { insufficiantAvaBalance(); } else if (walletChosen === 'Polygon') { - insufficiantPolygonBalance(); + console.log('there?'); + insufficiantAmoyBalance(); } }, [walletChosen]); return ( @@ -509,6 +509,7 @@ export default function MyModal({ } else if (coin.name === 'Ethereum') { login(1); } else if (coin.name === 'Polygon') { + console.log('there?'); login(2); } setWalletChosen(coin.name); @@ -583,24 +584,6 @@ export default function MyModal({ ); setTestTokensHash(''); } - } else if (walletChosen === 'Polygon') { - const resp = await getPolygonFundsWeb3Auth( - smartAccount - ); - if (resp.trxhash) { - toast.success( - 'Wooho your funds have arrived 🚀🎉💸', - toastStyles - ); - setPolygonTokensHash(resp.trxhash); - setLoadingState('Confirm Payment'); - } else { - toast.error( - 'Something went wrong', - toastStyles - ); - setPolygonTokensHash(''); - } } else { window.open( 'https://faucet.circle.com/', diff --git a/src/constant/PurchaseSubscriptionAmoy.json b/src/constant/PurchaseSubscriptionAmoy.json new file mode 100644 index 0000000..a3e4f6a --- /dev/null +++ b/src/constant/PurchaseSubscriptionAmoy.json @@ -0,0 +1,329 @@ +[ + { + "inputs": [ + { + "internalType": "address", + "name": "_router", + "type": "address" + }, + { + "internalType": "address", + "name": "_link", + "type": "address" + }, + { + "internalType": "address", + "name": "_stablecoinAddress", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [ + { + "internalType": "uint64", + "name": "destinationChainSelector", + "type": "uint64" + } + ], + "name": "DestinationChainNotAllowed", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "internalType": "address", + "name": "target", + "type": "address" + }, + { + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "FailedToWithdrawEth", + "type": "error" + }, + { + "inputs": [], + "name": "InvalidReceiverAddress", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "currentBalance", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "calculatedFees", + "type": "uint256" + } + ], + "name": "NotEnoughBalance", + "type": "error" + }, + { + "inputs": [], + "name": "NothingToWithdraw", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "SenderNotAllowed", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "uint64", + "name": "sourceChainSelector", + "type": "uint64" + } + ], + "name": "SourceChainNotAllowed", + "type": "error" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "messageId", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "uint64", + "name": "destinationChainSelector", + "type": "uint64" + }, + { + "indexed": false, + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "indexed": false, + "internalType": "string", + "name": "text", + "type": "string" + }, + { + "indexed": false, + "internalType": "address", + "name": "token", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "tokenAmount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "address", + "name": "feeToken", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "fees", + "type": "uint256" + } + ], + "name": "MessageSent", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "uint64", + "name": "_destinationChainSelector", + "type": "uint64" + }, + { + "internalType": "address", + "name": "_receiver", + "type": "address" + }, + { + "internalType": "uint256", + "name": "modelId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "subscriptionId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "duration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + } + ], + "name": "sendUsdcCrossChainNFTMint", + "outputs": [ + { + "internalType": "bytes32", + "name": "messageId", + "type": "bytes32" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "subscriber", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "modelId", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "subscriptionId", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "priceInUsd", + "type": "uint256" + } + ], + "name": "SubscribedWithToken", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "modelId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "subscriptionId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "priceInUsd", + "type": "uint256" + } + ], + "name": "subscribeWithToken", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "s_lastRequestId", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "stablecoin", + "outputs": [ + { + "internalType": "contract IERC20", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + }, + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "subscriptions", + "outputs": [ + { + "internalType": "uint256", + "name": "modelId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "subscriptionId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "priceInUsd", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + } +] diff --git a/src/lib/func.tsx b/src/lib/func.tsx index 3f1ca30..a5a9920 100644 --- a/src/lib/func.tsx +++ b/src/lib/func.tsx @@ -6,6 +6,7 @@ import userOnBoardingAbi from '../constant/userOnBoarding.json'; import batchAbi from '../constant/Batch.json'; import mockUsdAbi from '../constant/MockUSD.json'; import purchaseSubsAvaAbi from '../constant/purchaseSubsAva.json'; +import purchaseSubsAmoyAbi from '../constant/PurchaseSubscriptionAmoy.json'; import nftAbi from '../constant/nft.json'; import nftMarketPlaceSepoliaAbi from '../constant/NftMarketPlaceSepolia.json'; import NftsMarketPlaceMoonAbi from '../constant/nftsMarketPlaceAbi.json'; @@ -24,8 +25,10 @@ const purchaseSubscriptionAddress = const purchaseSubscriptionAddressMorph = '0xF99b791257ab50be7F235BC825E7d4B83942cf38'; const purchaseSubsAva = '0xf6b6A9EFAFd008b1170D703C32Fe32C0dA92fc2F'; +const purhcaseSubsAmoy = '0xa52309ed1de8781cbeecef9d05b4b09b209b2493'; // const usdcAvaAddr = '0x6F3c4787bAB4EeEbf62eFB8C35Dc9259FDc9D9f4'; const usdcAvaAddr = '0x5425890298aed601595a70AB815c96711a31Bc65'; +const usdcAmoyAddr = '0x41E94Eb019C0762f9Bfcf9Fb1E58725BfB0e7582'; const mockUsdAddress = '0xf7409b94F7285d27Ab1A456638A1110A4E55bFEC'; const userOnboardingAddress = '0x82376dA85a76360BC9FfC9a542961429A2A653ff'; const batchAddress = '0x0000000000000000000000000000000000000808'; @@ -410,13 +413,13 @@ export async function checkUserBalanceAvaWeb3Auth(smartAccount: any) { return { signerBalance }; } -//check user balance with polygon -export async function checkUserBalancePolygonWeb3Auth(smartAccount: any) { +//check user balance with amoy +export async function checkUserBalanceAmoyWeb3Auth(smartAccount: any) { const provider = new ethers.providers.JsonRpcProvider( - 'https://rpc.ankr.com/avalanche_fuji' + 'https://rpc-amoy.polygon.technology' ); const signerAddress = await smartAccount.getAddress(); - const usdc = new ethers.Contract(usdcAvaAddr, UsdcAvaAbi, provider); + const usdc = new ethers.Contract(usdcAmoyAddr, UsdcAvaAbi, provider); const signerBalance = ethers.utils.formatUnits( await usdc.balanceOf(signerAddress), 8 @@ -458,25 +461,7 @@ export async function getTestFundsWeb3Auth(smartAccount: any) { const trx = await usdc.transfer(signerAddress, 100e8); return { trxhash: trx.hash }; } -//get test polygon funds -export async function getPolygonFundsWeb3Auth(smartAccount: any) { - const provider = new ethers.providers.JsonRpcProvider( - 'https://eth-sepolia.public.blastapi.io' - ); - const signerAddress = await smartAccount.getAddress(); - const thirdPartyProvider = new ethers.Wallet( - process.env.NEXT_PUBLIC_THIRD_PARTY_SIGNER || '', - provider - ); - console.log(thirdPartyProvider); - const usdc = new ethers.Contract( - usdcSepoliaEthAddr, - UsdcEthSepoliaAbi, - thirdPartyProvider - ); - const trx = await usdc.transfer(signerAddress, 100e8); - return { trxhash: trx.hash }; -} + export async function balanceOffModel(provider: any, modelId: string) { const signer = provider.getSigner(); const signerAddress = await signer.getAddress(); @@ -902,20 +887,20 @@ export async function PurchaseSubsAvaGasslessBundle( console.error('Error in PurchaseSubsAvaGasslessBundle', error); } } -//this is contract call one when user presses confirm with polygon -export async function PurchaseSubsPolygon( +//this is contract call one when user presses confirm with Amoy +export async function PurchaseSubsAmoyGasslessBundle( smartAccount: any, modelId: number, subscriptionId: number, priceInUsd: number ) { - console.log('Starting PurchaseSubsAvaGasslessBundle'); + console.log('Starting PurchaseSubsAmoyGasslessBundle'); console.log(`SmartAccount provided: ${smartAccount}`); try { - const usdcContractAddress = usdcAvaAddr; - const purchaseSubAddress = purchaseSubsAva; + const usdcContractAddress = usdcAmoyAddr; + const purchaseSubAddress = purhcaseSubsAmoy; const provider = new ethers.providers.JsonRpcProvider( - 'https://api.avax-test.network/ext/bc/C/rpc' + 'https://rpc-amoy.polygon.technology' ); console.log('Provider initialized'); @@ -926,7 +911,7 @@ export async function PurchaseSubsPolygon( ); console.log('USDC Contract instance created'); - const approvalUsdcAmount = priceInUsd * 3; + const approvalUsdcAmount = priceInUsd; const approvePriceInUsdc = ethers.utils.parseUnits( approvalUsdcAmount.toString(), 6 @@ -949,7 +934,7 @@ export async function PurchaseSubsPolygon( // Step 2: Create and call sendUsdcCrossChainNFTMint on the purchaseSub contract const purchaseSubInstance = new ethers.Contract( purchaseSubAddress, - purchaseSubsAvaAbi, + purchaseSubsAmoyAbi, provider ); console.log('Purchase Subscription Contract instance created');