From 447c13cf85769c44b86266bd4729e71718a83a95 Mon Sep 17 00:00:00 2001 From: ninokeldishvili Date: Tue, 21 May 2024 16:28:30 +0400 Subject: [PATCH 1/5] Create certify script --- hardhat.config.ts | 18 +++++++++++------ scripts/certify.ts | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 scripts/certify.ts diff --git a/hardhat.config.ts b/hardhat.config.ts index f0cecf1f..0fc2d8cc 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -14,6 +14,8 @@ const { ETHERSCAN_API_KEY, SEPOLIA_URL, POLYGON_AMOY_URL, + ARBITRUM_SEPOLIA_URL, + ETHEREUM_SEPOLIA_URL } = process.env; export const config = { @@ -46,12 +48,16 @@ export const config = { accounts: PRIVATE_KEY ? [`0x${PRIVATE_KEY}`] : [], gasPrice: 22000000000, }, - - // arbitrumSepolia: { - // url: ARBITRUM_SEPOLIA_URL || "", - // accounts: PRIVATE_KEY ? [`0x${PRIVATE_KEY}`] : [], - // gasPrice: 22000000000, - // }, + "arbitrum-sepolia": { + url: ARBITRUM_SEPOLIA_URL || "", + accounts: PRIVATE_KEY ? [`0x${PRIVATE_KEY}`] : [], + gasPrice: 22000000000, + }, + "ethereum-sepolia": { + url: ETHEREUM_SEPOLIA_URL || "", + accounts: PRIVATE_KEY ? [`0x${PRIVATE_KEY}`] : [], + gasPrice: 22000000000, + }, }, solidity: { compilers: [ diff --git a/scripts/certify.ts b/scripts/certify.ts new file mode 100644 index 00000000..e5986109 --- /dev/null +++ b/scripts/certify.ts @@ -0,0 +1,49 @@ +import { artifacts, ethers } from "hardhat"; +import * as dotenv from 'dotenv'; + +dotenv.config(); + +async function main() { + const { PRIVATE_KEY, ARBITRUM_SEPOLIA_RPC_URL } = process.env; + // const { PRIVATE_KEY, ETHEREUM_SEPOLIA_URL } = process.env; + + if (!PRIVATE_KEY || !ARBITRUM_SEPOLIA_RPC_URL) { + // if (!PRIVATE_KEY || !ETHEREUM_SEPOLIA_URL) { + throw new Error("Please set PRIVATE_KEY and ARBITRUM_RPC_URL in your .env file"); + } + + const provider = new ethers.providers.JsonRpcProvider(ARBITRUM_SEPOLIA_RPC_URL); + // const provider = new ethers.providers.JsonRpcProvider(ETHEREUM_SEPOLIA_URL); + // const wallet = new ethers.Wallet(PRIVATE_KEY, provider); + const wallet = new ethers.Wallet(PRIVATE_KEY, provider); + + const contractAbi = (await artifacts.readArtifact("OffchainAssetReceiptVault")).abi + const contractAddress = '0xfc34d331cc7a4b461b7ded2f6835a837411d8684'; // arbitrum sepolia + // const contractAddress = '0xAFD4239F28297F61AB8f6bE03CeD343E2389739F'; //ethereum-sepolia + + const contract = new ethers.Contract(contractAddress, contractAbi, wallet); + + try { + const blockNum = await ethers.provider.getBlockNumber(); + const block = await ethers.provider.getBlock(blockNum); + const _certifiedUntil = block.timestamp + 100; + + //Grant role + // contract.grantRole(await contract.CERTIFIER(), alice.address); + + // Replace with the function you want to test and its parameters + const tx = await contract.certify(_certifiedUntil, blockNum, false, []); + console.log('Transaction sent:', tx.hash); + + // Wait for the transaction to be mined + const receipt = await tx.wait(); + console.log('Transaction mined:', receipt); + } catch (error) { + console.error('Error occurred:', error); + } +} + +main().catch((error) => { + console.error(error); + process.exitCode = 1; +}); \ No newline at end of file From e473c87092688bdc0e61f3b88e68c79cf05e3732 Mon Sep 17 00:00:00 2001 From: ninokeldishvili Date: Tue, 21 May 2024 17:13:12 +0400 Subject: [PATCH 2/5] Deploy new contract in script. add script in package.json --- package.json | 3 +++ scripts/certify.ts | 57 ++++++++++++++++++++++++++++++++-------------- 2 files changed, 43 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 452ce969..9c2cffef 100644 --- a/package.json +++ b/package.json @@ -24,5 +24,8 @@ "dependencies": { "@rainprotocol/rain-protocol": "git://github.com/rainprotocol/rain-protocol.git#33275a8c9ef751c3d1187dc9a66b37d77aca6848", "solc": "=0.8.17" + }, + "scripts": { + "certify-arb-sepolia": "npx hardhat run scripts/certify.ts --network arbitrum-sepolia" } } diff --git a/scripts/certify.ts b/scripts/certify.ts index e5986109..78bd5d03 100644 --- a/scripts/certify.ts +++ b/scripts/certify.ts @@ -1,27 +1,50 @@ import { artifacts, ethers } from "hardhat"; -import * as dotenv from 'dotenv'; +import * as dotenv from "dotenv"; +import { getEventArgs } from "../test/util"; +import { Contract } from "ethers"; +import type { OffchainAssetReceiptVault } from "../typechain-types"; dotenv.config(); async function main() { const { PRIVATE_KEY, ARBITRUM_SEPOLIA_RPC_URL } = process.env; - // const { PRIVATE_KEY, ETHEREUM_SEPOLIA_URL } = process.env; - if (!PRIVATE_KEY || !ARBITRUM_SEPOLIA_RPC_URL) { - // if (!PRIVATE_KEY || !ETHEREUM_SEPOLIA_URL) { + if ( !PRIVATE_KEY || !ARBITRUM_SEPOLIA_RPC_URL ) { throw new Error("Please set PRIVATE_KEY and ARBITRUM_RPC_URL in your .env file"); } const provider = new ethers.providers.JsonRpcProvider(ARBITRUM_SEPOLIA_RPC_URL); - // const provider = new ethers.providers.JsonRpcProvider(ETHEREUM_SEPOLIA_URL); - // const wallet = new ethers.Wallet(PRIVATE_KEY, provider); const wallet = new ethers.Wallet(PRIVATE_KEY, provider); - const contractAbi = (await artifacts.readArtifact("OffchainAssetReceiptVault")).abi - const contractAddress = '0xfc34d331cc7a4b461b7ded2f6835a837411d8684'; // arbitrum sepolia - // const contractAddress = '0xAFD4239F28297F61AB8f6bE03CeD343E2389739F'; //ethereum-sepolia + const contractFactoryAbi = ( await artifacts.readArtifact("OffchainAssetReceiptVaultFactory") ).abi; + //factory contract address on arbitrum sepolia + const contractFactoryAddress = "0xf1A14e96977E8dE295Ba9612691D127B157d1371"; - const contract = new ethers.Contract(contractAddress, contractAbi, wallet); + const contractFactory = new ethers.Contract(contractFactoryAddress, contractFactoryAbi, wallet); + + const constructionConfig = { + admin: wallet.address, + vaultConfig: { + asset: ethers.constants.AddressZero, + name: `OffchainAssetVaul-${ new Date().getTime() }`, + symbol: "OAV" + } + }; + + let tx = await contractFactory.connect(wallet).createChildTyped( + constructionConfig + ); + + const { child } = await getEventArgs( + tx, + "NewChild", + contractFactory + ); + + let contract = new Contract( + child, + ( await artifacts.readArtifact("OffchainAssetReceiptVault") ).abi + ) as OffchainAssetReceiptVault; try { const blockNum = await ethers.provider.getBlockNumber(); @@ -29,17 +52,17 @@ async function main() { const _certifiedUntil = block.timestamp + 100; //Grant role - // contract.grantRole(await contract.CERTIFIER(), alice.address); + await contract.connect(wallet).grantRole(await contract.connect(wallet).CERTIFIER(), wallet.address); - // Replace with the function you want to test and its parameters - const tx = await contract.certify(_certifiedUntil, blockNum, false, []); - console.log('Transaction sent:', tx.hash); + //Call certify function + const tx = await contract.connect(wallet).certify(_certifiedUntil, blockNum, false, []); + console.log("Transaction sent:", tx.hash); // Wait for the transaction to be mined const receipt = await tx.wait(); - console.log('Transaction mined:', receipt); - } catch (error) { - console.error('Error occurred:', error); + console.log("Transaction mined:", receipt); + } catch ( error ) { + console.error("Error occurred:", error); } } From b5cc482abe760eef59513cb0861985bcbee6c4b3 Mon Sep 17 00:00:00 2001 From: ninokeldishvili Date: Tue, 21 May 2024 17:52:12 +0400 Subject: [PATCH 3/5] Remove RPC url -s and wait for role grant --- scripts/certify.ts | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/scripts/certify.ts b/scripts/certify.ts index 78bd5d03..13cc1bfa 100644 --- a/scripts/certify.ts +++ b/scripts/certify.ts @@ -7,20 +7,18 @@ import type { OffchainAssetReceiptVault } from "../typechain-types"; dotenv.config(); async function main() { - const { PRIVATE_KEY, ARBITRUM_SEPOLIA_RPC_URL } = process.env; + const { PRIVATE_KEY, CONTRACT_FACTORY_ADDRESS } = process.env; - if ( !PRIVATE_KEY || !ARBITRUM_SEPOLIA_RPC_URL ) { + if ( !PRIVATE_KEY ) { throw new Error("Please set PRIVATE_KEY and ARBITRUM_RPC_URL in your .env file"); } - const provider = new ethers.providers.JsonRpcProvider(ARBITRUM_SEPOLIA_RPC_URL); - const wallet = new ethers.Wallet(PRIVATE_KEY, provider); + // const provider = new ethers.providers.JsonRpcProvider(ETHEREUM_SEPOLIA_URL); + const wallet = new ethers.Wallet(PRIVATE_KEY, ethers.provider); const contractFactoryAbi = ( await artifacts.readArtifact("OffchainAssetReceiptVaultFactory") ).abi; - //factory contract address on arbitrum sepolia - const contractFactoryAddress = "0xf1A14e96977E8dE295Ba9612691D127B157d1371"; - const contractFactory = new ethers.Contract(contractFactoryAddress, contractFactoryAbi, wallet); + const contractFactory = new ethers.Contract(CONTRACT_FACTORY_ADDRESS, contractFactoryAbi, wallet); const constructionConfig = { admin: wallet.address, @@ -51,17 +49,18 @@ async function main() { const block = await ethers.provider.getBlock(blockNum); const _certifiedUntil = block.timestamp + 100; - //Grant role - await contract.connect(wallet).grantRole(await contract.connect(wallet).CERTIFIER(), wallet.address); + // Grant role and wait for the transaction to be mined + const grantRoleTx = await contract.connect(wallet).grantRole(await contract.connect(wallet).CERTIFIER(), wallet.address); + await grantRoleTx.wait(); - //Call certify function - const tx = await contract.connect(wallet).certify(_certifiedUntil, blockNum, false, []); - console.log("Transaction sent:", tx.hash); + // Call certify function + const certifyTx = await contract.connect(wallet).certify(_certifiedUntil, blockNum, false, []); + console.log("Transaction sent:", certifyTx.hash); // Wait for the transaction to be mined - const receipt = await tx.wait(); + const receipt = await certifyTx.wait(); console.log("Transaction mined:", receipt); - } catch ( error ) { + } catch (error) { console.error("Error occurred:", error); } } From 4e3ba9c8158fc1439ec66662a7bfdbc1e198fedb Mon Sep 17 00:00:00 2001 From: ninokeldishvili Date: Tue, 21 May 2024 17:55:07 +0400 Subject: [PATCH 4/5] Add minor env check --- scripts/certify.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/certify.ts b/scripts/certify.ts index 13cc1bfa..92bce360 100644 --- a/scripts/certify.ts +++ b/scripts/certify.ts @@ -9,8 +9,8 @@ dotenv.config(); async function main() { const { PRIVATE_KEY, CONTRACT_FACTORY_ADDRESS } = process.env; - if ( !PRIVATE_KEY ) { - throw new Error("Please set PRIVATE_KEY and ARBITRUM_RPC_URL in your .env file"); + if ( !PRIVATE_KEY || CONTRACT_FACTORY_ADDRESS) { + throw new Error("Please set PRIVATE_KEY and CONTRACT_FACTORY_ADDRESS in your .env file"); } // const provider = new ethers.providers.JsonRpcProvider(ETHEREUM_SEPOLIA_URL); From d5c14917c0438d39a91cd5a119c15a091b51a9fe Mon Sep 17 00:00:00 2001 From: ninokeldishvili Date: Tue, 21 May 2024 17:59:27 +0400 Subject: [PATCH 5/5] Missing ! in check --- scripts/certify.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/certify.ts b/scripts/certify.ts index 92bce360..bedf4e35 100644 --- a/scripts/certify.ts +++ b/scripts/certify.ts @@ -9,7 +9,7 @@ dotenv.config(); async function main() { const { PRIVATE_KEY, CONTRACT_FACTORY_ADDRESS } = process.env; - if ( !PRIVATE_KEY || CONTRACT_FACTORY_ADDRESS) { + if ( !PRIVATE_KEY || !CONTRACT_FACTORY_ADDRESS) { throw new Error("Please set PRIVATE_KEY and CONTRACT_FACTORY_ADDRESS in your .env file"); }