From 68399bbdde8ba8deb7310cd31dde9c422e96f65b Mon Sep 17 00:00:00 2001 From: andrea Date: Sat, 18 Nov 2023 23:50:28 +0300 Subject: [PATCH 1/4] ccip integration --- .../nextjs/components/record/Recorder.tsx | 25 +++++++++++++------ packages/nextjs/hooks/dub3/utils.ts | 13 ++++++---- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/packages/nextjs/components/record/Recorder.tsx b/packages/nextjs/components/record/Recorder.tsx index 4a5246a..48df35c 100644 --- a/packages/nextjs/components/record/Recorder.tsx +++ b/packages/nextjs/components/record/Recorder.tsx @@ -1,7 +1,8 @@ import React, { useEffect, useState } from "react"; import lighthouse from "@lighthouse-web3/sdk"; +import { polygonMumbai } from "@wagmi/core/chains"; import { LoaderIcon } from "react-hot-toast"; -import { useAccount, useContractWrite } from "wagmi"; +import { useAccount, useContractWrite, useNetwork } from "wagmi"; import { ContractsAndAbis } from "~~/hooks/dub3/utils"; import { notification } from "~~/utils/scaffold-eth"; @@ -12,14 +13,19 @@ export const Recorder = () => { const [price, setPrice] = useState(""); const [cid, setCid] = useState(""); const { address: to, isDisconnected } = useAccount(); - + const { chain } = useNetwork(); + const destinationChainSelector = "12532609583862916517"; + const receiver = "0xF0228036FC21aD442250d4c887F492c50b5A3A37"; + const payFeesIn = 1; const SAMPLE_TEXT = - " Unlock new possibilities with cutting-edge technology. Experience innovation at your fingertips. Embrace the future today."; - - // const { ...writeHook } = useDub3Contract({ contractName: "SpeakerNFT", functionName: "mint" }); + "Unlock new possibilities with cutting-edge technology. Experience innovation at your fingertips. Embrace the future today."; + console.log(chain); const { data, isSuccess, write } = useContractWrite({ - address: ContractsAndAbis.SpeakerNFT.address, - abi: ContractsAndAbis.SpeakerNFT.abi, + address: + chain?.id == polygonMumbai.id ? ContractsAndAbis.SpeakerNFT.address : ContractsAndAbis.SourceMinter.address, + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + abi: chain?.id == polygonMumbai.id ? ContractsAndAbis.SpeakerNFT.abi : ContractsAndAbis.SourceMinter.abi, functionName: "mint", }); @@ -65,7 +71,10 @@ export const Recorder = () => { } console.log(ContractsAndAbis.SpeakerNFT.abi); write({ - args: [to, cid, SAMPLE_TEXT, 0], // to, cid,audioscript,audioprice + args: + chain?.id == polygonMumbai.id + ? [to, cid, SAMPLE_TEXT, 0] + : [destinationChainSelector, receiver, payFeesIn, cid, SAMPLE_TEXT, 0], // to, cid,audioscript,audioprice }); }; return ( diff --git a/packages/nextjs/hooks/dub3/utils.ts b/packages/nextjs/hooks/dub3/utils.ts index f504176..d43505f 100644 --- a/packages/nextjs/hooks/dub3/utils.ts +++ b/packages/nextjs/hooks/dub3/utils.ts @@ -1,21 +1,24 @@ -import { abi } from "./SpeakerNFTAbi"; +import { abi as buyerAbi } from "./BuyerNFTABI"; +import { abi as speakerAbi } from "./SpeakerNFTAbi"; +import { abi as destinationMinterABI } from "./destinationMinterABI"; +import { abi as sourceMinterAbi } from "./sourceMinterABI"; export const ContractsAndAbis = { SpeakerNFT: { address: "0xB31B82CDF32ce766E7acB943565347383Ac9ec26", - abi: abi, + abi: speakerAbi, }, BuyerNFT: { address: "0x59087174Dd6F511C73e62618DaeE710F2db0819F", - abi: abi, + abi: buyerAbi, }, SourceMinter: { address: "0x7e28Bca799F90AB6e8264E93B123cE9990987567", - abi: abi, + abi: sourceMinterAbi, }, DestinationMinter: { address: "0xF0228036FC21aD442250d4c887F492c50b5A3A37", - abi: abi, + abi: destinationMinterABI, }, }; From da150bdedcb2b3ece0a7b8405e7096060f32f154 Mon Sep 17 00:00:00 2001 From: andrea Date: Sun, 19 Nov 2023 01:04:17 +0300 Subject: [PATCH 2/4] ccip integration e2e fixed --- packages/hardhat/contracts/BuyerNFT.sol | 4 ++-- packages/hardhat/contracts/ccip_buyer/sourceMinter.sol | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/hardhat/contracts/BuyerNFT.sol b/packages/hardhat/contracts/BuyerNFT.sol index 743bced..0e73d47 100644 --- a/packages/hardhat/contracts/BuyerNFT.sol +++ b/packages/hardhat/contracts/BuyerNFT.sol @@ -56,7 +56,7 @@ contract BuyerNFT is ERC721URIStorage, Ownable { function tokenIDs(address speaker) external view returns (uint256[] memory) { return _tokenIDs[speaker]; } - function getNFTMetadata(uint256 tokenId) + function getNFTMetadata(uint256 tknId) public view returns ( @@ -66,7 +66,7 @@ contract BuyerNFT is ERC721URIStorage, Ownable { string memory script ) { - NFTMetadata storage metadata = nftMetadata[tokenId]; + NFTMetadata storage metadata = nftMetadata[tknId]; return ( metadata.cid, metadata.speakerAddress, diff --git a/packages/hardhat/contracts/ccip_buyer/sourceMinter.sol b/packages/hardhat/contracts/ccip_buyer/sourceMinter.sol index b9c84e3..54538c5 100644 --- a/packages/hardhat/contracts/ccip_buyer/sourceMinter.sol +++ b/packages/hardhat/contracts/ccip_buyer/sourceMinter.sol @@ -33,14 +33,14 @@ contract SourceMinter is Withdraw { function mint ( uint64 destinationChainSelector, address receiver, - PayFeesIn payFeesIn, + PayFeesIn payFeesIn, string memory cID, - string memory name, - string memory script + string memory _audioScript, + uint256 _audioPrice ) external { Client.EVM2AnyMessage memory message = Client.EVM2AnyMessage({ receiver: abi.encode(receiver), - data: abi.encodeWithSignature("mint(address,string,string,string)",msg.sender,cID,name,script), + data: abi.encodeWithSignature("mint(address,string,string,uint256)",msg.sender,cID,_audioScript,_audioPrice), tokenAmounts: new Client.EVMTokenAmount[](0), extraArgs: Client._argsToBytes( Client.EVMExtraArgsV1({gasLimit: 1000000, strict: false}) From b8df5168248261155b851c0388949d87b2eb6945 Mon Sep 17 00:00:00 2001 From: andrea Date: Sat, 18 Nov 2023 23:50:28 +0300 Subject: [PATCH 3/4] ccip integration --- .../nextjs/components/record/Recorder.tsx | 25 +++++++++++++------ packages/nextjs/hooks/dub3/utils.ts | 13 ++++++---- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/packages/nextjs/components/record/Recorder.tsx b/packages/nextjs/components/record/Recorder.tsx index 4a5246a..48df35c 100644 --- a/packages/nextjs/components/record/Recorder.tsx +++ b/packages/nextjs/components/record/Recorder.tsx @@ -1,7 +1,8 @@ import React, { useEffect, useState } from "react"; import lighthouse from "@lighthouse-web3/sdk"; +import { polygonMumbai } from "@wagmi/core/chains"; import { LoaderIcon } from "react-hot-toast"; -import { useAccount, useContractWrite } from "wagmi"; +import { useAccount, useContractWrite, useNetwork } from "wagmi"; import { ContractsAndAbis } from "~~/hooks/dub3/utils"; import { notification } from "~~/utils/scaffold-eth"; @@ -12,14 +13,19 @@ export const Recorder = () => { const [price, setPrice] = useState(""); const [cid, setCid] = useState(""); const { address: to, isDisconnected } = useAccount(); - + const { chain } = useNetwork(); + const destinationChainSelector = "12532609583862916517"; + const receiver = "0xF0228036FC21aD442250d4c887F492c50b5A3A37"; + const payFeesIn = 1; const SAMPLE_TEXT = - " Unlock new possibilities with cutting-edge technology. Experience innovation at your fingertips. Embrace the future today."; - - // const { ...writeHook } = useDub3Contract({ contractName: "SpeakerNFT", functionName: "mint" }); + "Unlock new possibilities with cutting-edge technology. Experience innovation at your fingertips. Embrace the future today."; + console.log(chain); const { data, isSuccess, write } = useContractWrite({ - address: ContractsAndAbis.SpeakerNFT.address, - abi: ContractsAndAbis.SpeakerNFT.abi, + address: + chain?.id == polygonMumbai.id ? ContractsAndAbis.SpeakerNFT.address : ContractsAndAbis.SourceMinter.address, + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + abi: chain?.id == polygonMumbai.id ? ContractsAndAbis.SpeakerNFT.abi : ContractsAndAbis.SourceMinter.abi, functionName: "mint", }); @@ -65,7 +71,10 @@ export const Recorder = () => { } console.log(ContractsAndAbis.SpeakerNFT.abi); write({ - args: [to, cid, SAMPLE_TEXT, 0], // to, cid,audioscript,audioprice + args: + chain?.id == polygonMumbai.id + ? [to, cid, SAMPLE_TEXT, 0] + : [destinationChainSelector, receiver, payFeesIn, cid, SAMPLE_TEXT, 0], // to, cid,audioscript,audioprice }); }; return ( diff --git a/packages/nextjs/hooks/dub3/utils.ts b/packages/nextjs/hooks/dub3/utils.ts index f504176..d43505f 100644 --- a/packages/nextjs/hooks/dub3/utils.ts +++ b/packages/nextjs/hooks/dub3/utils.ts @@ -1,21 +1,24 @@ -import { abi } from "./SpeakerNFTAbi"; +import { abi as buyerAbi } from "./BuyerNFTABI"; +import { abi as speakerAbi } from "./SpeakerNFTAbi"; +import { abi as destinationMinterABI } from "./destinationMinterABI"; +import { abi as sourceMinterAbi } from "./sourceMinterABI"; export const ContractsAndAbis = { SpeakerNFT: { address: "0xB31B82CDF32ce766E7acB943565347383Ac9ec26", - abi: abi, + abi: speakerAbi, }, BuyerNFT: { address: "0x59087174Dd6F511C73e62618DaeE710F2db0819F", - abi: abi, + abi: buyerAbi, }, SourceMinter: { address: "0x7e28Bca799F90AB6e8264E93B123cE9990987567", - abi: abi, + abi: sourceMinterAbi, }, DestinationMinter: { address: "0xF0228036FC21aD442250d4c887F492c50b5A3A37", - abi: abi, + abi: destinationMinterABI, }, }; From f7f61c30d2a34d33a0c426b522c20e84b719d547 Mon Sep 17 00:00:00 2001 From: andrea Date: Sun, 19 Nov 2023 01:04:17 +0300 Subject: [PATCH 4/4] ccip integration e2e fixed --- packages/hardhat/contracts/BuyerNFT.sol | 4 ++-- packages/hardhat/contracts/ccip_buyer/sourceMinter.sol | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/hardhat/contracts/BuyerNFT.sol b/packages/hardhat/contracts/BuyerNFT.sol index 743bced..0e73d47 100644 --- a/packages/hardhat/contracts/BuyerNFT.sol +++ b/packages/hardhat/contracts/BuyerNFT.sol @@ -56,7 +56,7 @@ contract BuyerNFT is ERC721URIStorage, Ownable { function tokenIDs(address speaker) external view returns (uint256[] memory) { return _tokenIDs[speaker]; } - function getNFTMetadata(uint256 tokenId) + function getNFTMetadata(uint256 tknId) public view returns ( @@ -66,7 +66,7 @@ contract BuyerNFT is ERC721URIStorage, Ownable { string memory script ) { - NFTMetadata storage metadata = nftMetadata[tokenId]; + NFTMetadata storage metadata = nftMetadata[tknId]; return ( metadata.cid, metadata.speakerAddress, diff --git a/packages/hardhat/contracts/ccip_buyer/sourceMinter.sol b/packages/hardhat/contracts/ccip_buyer/sourceMinter.sol index b9c84e3..54538c5 100644 --- a/packages/hardhat/contracts/ccip_buyer/sourceMinter.sol +++ b/packages/hardhat/contracts/ccip_buyer/sourceMinter.sol @@ -33,14 +33,14 @@ contract SourceMinter is Withdraw { function mint ( uint64 destinationChainSelector, address receiver, - PayFeesIn payFeesIn, + PayFeesIn payFeesIn, string memory cID, - string memory name, - string memory script + string memory _audioScript, + uint256 _audioPrice ) external { Client.EVM2AnyMessage memory message = Client.EVM2AnyMessage({ receiver: abi.encode(receiver), - data: abi.encodeWithSignature("mint(address,string,string,string)",msg.sender,cID,name,script), + data: abi.encodeWithSignature("mint(address,string,string,uint256)",msg.sender,cID,_audioScript,_audioPrice), tokenAmounts: new Client.EVMTokenAmount[](0), extraArgs: Client._argsToBytes( Client.EVMExtraArgsV1({gasLimit: 1000000, strict: false})