From 3d7a539cb720014073e25da13b86b082c8ee4cfe Mon Sep 17 00:00:00 2001 From: Andrew Dmytrenko Date: Wed, 13 Dec 2023 14:23:28 +0200 Subject: [PATCH] update script --- scripts/testnet.ts | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/scripts/testnet.ts b/scripts/testnet.ts index 5fee3a5..5985f5e 100644 --- a/scripts/testnet.ts +++ b/scripts/testnet.ts @@ -17,6 +17,7 @@ import { ethers } from "hardhat" const password = process.env.PASSWORD ?? "" const networkRPC = "https://bsc-testnet.publicnode.com" const gasLimit = 35_000_000 +const provider = new ethers.providers.JsonRpcProvider(networkRPC) const gasPrice = ethers.utils.parseUnits("5", "gwei") let vaultManager: VaultManager, lockDealNFT: LockDealNFT, @@ -31,7 +32,7 @@ let vaultManager: VaultManager, async function main() { try { - const user = await connectToBlockchain() + const user = new Wallet(password.toString(), provider) await deploy(user) await setup(user) const ids = await createPools(user) @@ -42,11 +43,6 @@ async function main() { } } -async function connectToBlockchain(): Promise { - const provider = new ethers.providers.JsonRpcProvider(networkRPC) - return new Wallet(password.toString(), provider) -} - async function deploy(user: Wallet) { vaultManager = await deployFrom("VaultManager", user) lockDealNFT = await deployFrom("LockDealNFT", user, vaultManager.address, "") @@ -67,15 +63,26 @@ async function deploy(user: Wallet) { } async function setup(user: Wallet) { - //const contract = new ethers.Contract(contractAddress, contractABI, provider) - await lockDealNFT.connect(user).setApprovedContract(dealProvider.address, true, { gasLimit: gasLimit }) - await lockDealNFT.connect(user).setApprovedContract(lockProvider.address, true, { gasLimit: gasLimit }) - await lockDealNFT.connect(user).setApprovedContract(timedProvider.address, true, { gasLimit: gasLimit }) - await lockDealNFT.connect(user).setApprovedContract(collateralProvider.address, true, { gasLimit: gasLimit }) - await lockDealNFT.connect(user).setApprovedContract(refundProvider.address, true, { gasLimit: gasLimit }) - await lockDealNFT.connect(user).setApprovedContract(simpleBuilder.address, true, { gasLimit: gasLimit }) - await lockDealNFT.connect(user).setApprovedContract(simpleRefundBuilder.address, true, { gasLimit: gasLimit }) - await token.connect(user).approve(vaultManager.address, ethers.constants.MaxUint256, { gasLimit: gasLimit }) + let tx = await vaultManager + .connect(user) + .setTrustee(lockDealNFT.address, { gasLimit: gasLimit, gasPrice: gasPrice }) + await tx.wait() + const contractsToApprove = [ + dealProvider, + lockProvider, + timedProvider, + collateralProvider, + refundProvider, + simpleBuilder, + simpleRefundBuilder, + ] + for (const contract of contractsToApprove) { + await approveContract(user, lockDealNFT, contract) + } + tx = await token + .connect(user) + .approve(vaultManager.address, ethers.constants.MaxUint256, { gasLimit: gasLimit, gasPrice: gasPrice }) + await tx.wait() console.log("Setup done") } @@ -94,4 +101,12 @@ async function deployFrom(contractName: string, user: Wallet, ...args: string return contract.deployed() as Promise } +async function approveContract(user: Wallet, lockDealNFT: LockDealNFT, contract: any) { + const tx = await lockDealNFT.connect(user).setApprovedContract(contract.address, true, { + gasLimit: gasLimit, + gasPrice: gasPrice, + }) + await tx.wait() +} + main()