working wrap and uwrap scripts
This commit is contained in:
parent
691c0c4279
commit
01c8e2aefc
|
@ -0,0 +1,35 @@
|
|||
const Wrapper = artifacts.require("CurioERC1155Wrapper");
|
||||
const IMastersFedi = artifacts.require("IMastersFedi");
|
||||
|
||||
module.exports = async (callback) => {
|
||||
const nftId = parseInt(process.argv[6]);
|
||||
const quantity = parseInt(process.argv[7]);
|
||||
console.log(`Quantity to unwrap: ${quantity}`);
|
||||
|
||||
const wrapper = await Wrapper.deployed();
|
||||
const tokenContractAddress = await wrapper.contracts(nftId);
|
||||
const tokenContract = await IMastersFedi.at(tokenContractAddress);
|
||||
const tokenName = await tokenContract.name();
|
||||
console.log(`Token contract address: ${tokenContractAddress}, name: "${tokenName}"`);
|
||||
|
||||
const [account,] = await web3.eth.getAccounts();
|
||||
let wrappedQuantity = await wrapper.balanceOf(account, nftId);
|
||||
console.log(`Wrapped quantity: ${wrappedQuantity}`);
|
||||
|
||||
let result1;
|
||||
try {
|
||||
console.log("Sending unwrap transaction...");
|
||||
result1 = await wrapper.unwrap(nftId, quantity, { from: account });
|
||||
|
||||
wrappedQuantity = await wrapper.balanceOf(account, nftId);
|
||||
console.log(`New wrapped balance: ${wrappedQuantity}`);
|
||||
|
||||
const unwrappedBalance = await tokenContract.balanceOf(account);
|
||||
console.log(`New unwrapped balance: ${unwrappedBalance}`);
|
||||
}
|
||||
catch (e) {
|
||||
console.error(`FAILED: ${e}`);
|
||||
}
|
||||
|
||||
callback();
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
const Wrapper = artifacts.require("CurioERC1155Wrapper");
|
||||
const IMastersFedi = artifacts.require("IMastersFedi");
|
||||
|
||||
module.exports = async (callback) => {
|
||||
const nftId = parseInt(process.argv[6]);
|
||||
const quantity = parseInt(process.argv[7]);
|
||||
console.log(`Quantity to wrap: ${quantity}`);
|
||||
|
||||
const wrapper = await Wrapper.deployed();
|
||||
const tokenContractAddress = await wrapper.contracts(nftId);
|
||||
const tokenContract = await IMastersFedi.at(tokenContractAddress);
|
||||
const tokenName = await tokenContract.name();
|
||||
console.log(`Token contract address: ${tokenContractAddress}, name: "${tokenName}"`);
|
||||
|
||||
const [account,] = await web3.eth.getAccounts();
|
||||
const tokenQuantity = await tokenContract.balanceOf(account);
|
||||
console.log(`Unwrapped balance: ${tokenQuantity}`);
|
||||
|
||||
if (tokenQuantity >= quantity) {
|
||||
console.log("First approving contract to withdraw token quantity...");
|
||||
let result1;
|
||||
try {
|
||||
result1 = await tokenContract.approve(wrapper.address, quantity, { from: account });
|
||||
}
|
||||
catch (e) {
|
||||
console.error(`FAILED: ${e}`);
|
||||
}
|
||||
|
||||
if (result1) {
|
||||
console.log("Now submitting wrap transaction...");
|
||||
let result;
|
||||
|
||||
try {
|
||||
result = await wrapper.wrap(nftId, quantity, { from: account });
|
||||
console.log(`Transaction: ${result.tx}`);
|
||||
|
||||
const wrappedQuantity = await wrapper.balanceOf(account, nftId);
|
||||
console.log(`New wrapped quantity: ${wrappedQuantity}`);
|
||||
}
|
||||
catch (e) {
|
||||
console.error(`FAILED: ${e}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
console.error("Insufficient balance");
|
||||
}
|
||||
|
||||
console.log("Done.");
|
||||
callback();
|
||||
}
|
Loading…
Reference in New Issue