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