-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: migrate truffle scripts to hardhat tasks
- Loading branch information
Showing
11 changed files
with
553 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const BRIDGE_ADDRESS = "0x0000000000000000000000000000000001000006"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { task } from "hardhat/config"; | ||
import { BRIDGE_ADDRESS } from "../scripts/deployment-utils/constants"; | ||
|
||
task("btc-best-height") | ||
.setDescription( | ||
"Prints the best height of the Bitcoin network seen by the Rootstock Bridge" | ||
) | ||
.setAction(async (_, hre) => { | ||
const { ethers } = hre; | ||
const bridge = await ethers.getContractAt("Bridge", BRIDGE_ADDRESS); | ||
const bestHeight = await bridge.getBtcBlockchainBestChainHeight(); | ||
console.info( | ||
`Best BTC blockchain height: \x1b[32m${bestHeight.toString()}\x1b[0m` | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { task } from "hardhat/config"; | ||
import { DeploymentConfig, read } from "../scripts/deployment-utils/deploy"; | ||
|
||
task("get-versions") | ||
.setDescription( | ||
"Prints the versions of the LiquidityBridgeContract and its libraries where applicable" | ||
) | ||
.setAction(async (_, hre) => { | ||
const { ethers, network } = hre; | ||
const addresses: Partial<DeploymentConfig> = read(); | ||
const networkDeployments: Partial<DeploymentConfig[string]> | undefined = | ||
addresses[network.name]; | ||
|
||
if (!networkDeployments?.LiquidityBridgeContract?.address) { | ||
throw new Error( | ||
"LiquidityBridgeContract proxy deployment info not found" | ||
); | ||
} | ||
const lbcAddress = networkDeployments.LiquidityBridgeContract.address; | ||
|
||
if (!networkDeployments.BtcUtils?.address) { | ||
throw new Error( | ||
"LiquidityBridgeContract proxy deployment info not found" | ||
); | ||
} | ||
const btcUtilsAddress = networkDeployments.BtcUtils.address; | ||
|
||
const lbc = await ethers.getContractAt( | ||
"LiquidityBridgeContractV2", | ||
lbcAddress | ||
); | ||
const lbcVersion = await lbc.version().catch(() => "Not found"); | ||
|
||
const btcUtils = await ethers.getContractAt("BtcUtils", btcUtilsAddress); | ||
const btcUtilsVersion = await btcUtils.version().catch(() => "Not found"); | ||
|
||
console.info("======================================="); | ||
console.info( | ||
`LiquidityBridgeContract version: \x1b[32m${lbcVersion}\x1b[0m` | ||
); | ||
console.info(`BtcUtils version: \x1b[32m${btcUtilsVersion}\x1b[0m`); | ||
console.info("======================================="); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"fedBTCAddr": "2N9uY615Mxk6KSSjv6F3FnvSPgZMer7FF39", | ||
"lbcAddr": "0x18D8212bC00106b93070123f325021C723D503a3", | ||
"lpRSKAddr": "0xdfcf32644e6cc5badd1188cddf66f66e21b24375", | ||
"btcRefundAddr": "mfWxJ45yp2SFn7UciZyNpvDKrzbhyfKrY8", | ||
"rskRefundAddr": "0x8dcCD82443B80DDdE3690aF86746BfD9D766f8d2", | ||
"lpBTCAddr": "mwEceC31MwWmF6hc5SSQ8FmbgdsSoBSnbm", | ||
"callFee": 150000000000000, | ||
"penaltyFee": 10000000000000, | ||
"contractAddr": "0x8dcCD82443B80DDdE3690aF86746BfD9D766f8d2", | ||
"data": "0x", | ||
"gasLimit": 21000, | ||
"nonce": "3307065858190946360", | ||
"value": "5000000000000000", | ||
"agreementTimestamp": 1735243258, | ||
"timeForDeposit": 9800, | ||
"lpCallTime": 10800, | ||
"confirmations": 2, | ||
"callOnRegister": false, | ||
"gasFee": 114524739000, | ||
"productFeeAmount": 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { task, types } from "hardhat/config"; | ||
import { readFileSync } from "fs"; | ||
import { DeploymentConfig, read } from "../scripts/deployment-utils/deploy"; | ||
import { | ||
ApiPeginQuote, | ||
ApiPegoutQuote, | ||
parsePeginQuote, | ||
parsePegoutQuote, | ||
} from "./utils/quote"; | ||
|
||
task("hash-quote") | ||
.setDescription("Prints the hash of the quote provided in the input file") | ||
.addParam( | ||
"file", | ||
"The file containing the quote to hash", | ||
undefined, | ||
types.inputFile | ||
) | ||
.addParam( | ||
"type", | ||
"Wether the quote is a PegIn or PegOut quote", | ||
undefined, | ||
types.string | ||
) | ||
.setAction(async (args, hre) => { | ||
const { network, ethers } = hre; | ||
const typedArgs = args as { file: string; type: string }; | ||
const type: string = typedArgs.type.toLowerCase(); | ||
const inputFile: string = typedArgs.file; | ||
|
||
if (!["pegin", "pegout"].includes(type)) { | ||
throw new Error("Invalid type. Must be 'pegin' or 'pegout'"); | ||
} | ||
const fileContent = readFileSync(inputFile); | ||
const quote: unknown = JSON.parse(fileContent.toString()); | ||
|
||
const addresses: Partial<DeploymentConfig> = read(); | ||
const networkDeployments: Partial<DeploymentConfig[string]> | undefined = | ||
addresses[network.name]; | ||
const lbcAddress = networkDeployments?.LiquidityBridgeContract?.address; | ||
if (!lbcAddress) { | ||
throw new Error( | ||
"LiquidityBridgeContract proxy deployment info not found" | ||
); | ||
} | ||
const lbc = await ethers.getContractAt( | ||
"LiquidityBridgeContractV2", | ||
lbcAddress | ||
); | ||
|
||
if (type === "pegin") { | ||
const hash = await lbc.hashQuote(parsePeginQuote(quote as ApiPeginQuote)); | ||
console.info( | ||
`Hash of the provided PegIn quote: \x1b[32m${hash.slice(2)}\x1b[0m` | ||
); | ||
} else { | ||
const hash = await lbc.hashPegoutQuote( | ||
parsePegoutQuote(quote as ApiPegoutQuote) | ||
); | ||
console.info( | ||
`Hash of the provided PegOut quote: \x1b[32m${hash.slice(2)}\x1b[0m` | ||
); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { task, types } from "hardhat/config"; | ||
import { DeploymentConfig, read } from "../scripts/deployment-utils/deploy"; | ||
|
||
task("refund-user-pegout") | ||
.setDescription( | ||
"Refund a user that didn't receive their PegOut in the agreed time" | ||
) | ||
.addParam( | ||
"quotehash", | ||
"The hash of the accepted PegOut quote", | ||
undefined, | ||
types.string | ||
) | ||
.setAction(async (args, hre) => { | ||
const { ethers, network } = hre; | ||
const typedArgs = args as { quotehash: string }; | ||
const quoteHash: string = "0x" + typedArgs.quotehash; | ||
|
||
const addresses: Partial<DeploymentConfig> = read(); | ||
const networkDeployments: Partial<DeploymentConfig[string]> | undefined = | ||
addresses[network.name]; | ||
|
||
const lbcAddress = networkDeployments?.LiquidityBridgeContract?.address; | ||
if (!lbcAddress) { | ||
throw new Error( | ||
"LiquidityBridgeContract proxy deployment info not found" | ||
); | ||
} | ||
const lbc = await ethers.getContractAt( | ||
"LiquidityBridgeContractV2", | ||
lbcAddress | ||
); | ||
|
||
const gasEstimation = await lbc.refundUserPegOut.estimateGas(quoteHash); | ||
console.info("Gas estimation for refundUserPegOut:", gasEstimation); | ||
|
||
const tx = await lbc.refundUserPegOut(quoteHash); | ||
const receipt = await tx.wait(); | ||
console.info(`Transaction hash: ${receipt!.hash}`); | ||
console.info("Transaction receipt: "); | ||
console.info(receipt); | ||
}); |
Oops, something went wrong.