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/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 new file mode 100644 index 00000000..bedf4e35 --- /dev/null +++ b/scripts/certify.ts @@ -0,0 +1,71 @@ +import { artifacts, ethers } from "hardhat"; +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, CONTRACT_FACTORY_ADDRESS } = process.env; + + 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); + const wallet = new ethers.Wallet(PRIVATE_KEY, ethers.provider); + + const contractFactoryAbi = ( await artifacts.readArtifact("OffchainAssetReceiptVaultFactory") ).abi; + + const contractFactory = new ethers.Contract(CONTRACT_FACTORY_ADDRESS, 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(); + const block = await ethers.provider.getBlock(blockNum); + const _certifiedUntil = block.timestamp + 100; + + // 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 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 certifyTx.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