Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refund scripts #247

Merged
merged 4 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion example.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
ALPHANET_RPC_URL=http://127.0.0.1:4444
MAINNET_RPC_URL=https://public-node.rsk.co
TESTNET_RPC_URL=https://public-node.testnet.rsk.co
TESTNET_RPC_URL=https://public-node.testnet.rsk.co
MAINNET_SIGNER_PRIVATE_KEY=<private_key>
TESTNET_SIGNER_PRIVATE_KEY=<private_key>
DEV_SIGNER_PRIVATE_KEY=<private_key>
214 changes: 214 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
},
"homepage": "https://github.com/rsksmart/liquidity-bridge-contract#readme",
"devDependencies": {
"@mempool/mempool.js": "^2.3.0",
"@openzeppelin/truffle-upgrades": "^1.17.1",
"@rsksmart/pmt-builder": "^3.0.0",
"bitcoinjs-lib": "^6.0.1",
"bs58check": "^3.0.1",
"dotenv": "^16.3.1",
"prettier": "^2.4.1",
Expand Down
59 changes: 59 additions & 0 deletions scripts/refundUserPegout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
require('dotenv').config();
const Web3 = require("web3");
const web3Provider = new Web3.providers.HttpProvider(
config.config.network === 'rskMainnet' ? process.env.MAINNET_RPC_URL : process.env.TESTNET_RPC_URL
);
const web3 = new Web3(web3Provider);

// ------ REPLACE THE FOLLOWING DATA WITH THE DATA OF THE PEGOUT YOU WANT TO REFUND ------

const quoteHash = "2a64325b9f587fe206f46c92b2a12568815ad76427ad56e02e0946f08d12d7d2";

// ------ END OF THE DATA TO BE REPLACED ------

const networksInfo = {
'rskDevelopment': {
privateKeyEnv: 'DEV_SIGNER_PRIVATE_KEY',
lbcAddress: '0x18D8212bC00106b93070123f325021C723D503a3',
},
'rskTestnet': {
privateKeyEnv: 'TESTNET_SIGNER_PRIVATE_KEY',
lbcAddress: '0xc2A630c053D12D63d32b025082f6Ba268db18300',
},
'rskMainnet': {
privateKeyEnv: 'MAINNET_SIGNER_PRIVATE_KEY',
lbcAddress: '0xAA9cAf1e3967600578727F975F283446A3Da6612',
}
}

module.exports = async function (callback) {
try {
const networkInfo = networksInfo[config.config.network];
web3.eth.accounts.wallet.add("0x"+process.env[networkInfo.privateKeyEnv]);
const signer = web3.eth.accounts.wallet[0];
const refundPegoutCaller = signer.address;
console.log('Executing refundUserPegOut from ' + refundPegoutCaller);

const json = require("../build/contracts/LiquidityBridgeContractV2.json");
const contract = new web3.eth.Contract(json.abi, networkInfo.lbcAddress);


const gasEstimation = await contract.methods.refundUserPegOut('0x' + quoteHash).estimateGas();

console.log("Gas estimation: ", gasEstimation);

const refundPegoutResult = await contract.methods.refundUserPegOut('0x' + quoteHash)
.call({ to: networkInfo.lbcAddress, from: refundPegoutCaller, gasLimit: gasEstimation });

console.log("Expected result: ", refundPegoutResult);
const receipt = await contract.methods.refundUserPegOut('0x' + quoteHash)
.send({ to: networkInfo.lbcAddress, from: refundPegoutCaller, gasLimit: gasEstimation + 200 });
console.log("Receipt: ");
console.log(receipt);

} catch (error) {
console.error("Error running refund pegout script: ");
console.error(error);
}
callback();
};
Loading
Loading