Skip to content

Commit

Permalink
update script
Browse files Browse the repository at this point in the history
  • Loading branch information
YouStillAlive committed Dec 13, 2023
1 parent 93a794f commit 3d7a539
Showing 1 changed file with 30 additions and 15 deletions.
45 changes: 30 additions & 15 deletions scripts/testnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand All @@ -42,11 +43,6 @@ async function main() {
}
}

async function connectToBlockchain(): Promise<Wallet> {
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, "")
Expand All @@ -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")
}

Expand All @@ -94,4 +101,12 @@ async function deployFrom<T>(contractName: string, user: Wallet, ...args: string
return contract.deployed() as Promise<T>
}

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()

0 comments on commit 3d7a539

Please sign in to comment.