UNPKG

axie-tools

Version:

TypeScript library and CLI tool for interacting with Axie Infinity marketplace and NFTs on Ronin network. Features marketplace operations (buy/sell/delist), batch transfers, and wallet information.

54 lines (53 loc) 3.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.approveMarketplaceContract = approveMarketplaceContract; exports.approveWETH = approveWETH; exports.approveBatchTransfer = approveBatchTransfer; const ethers_1 = require("ethers"); const contracts_1 = require("@roninbuilders/contracts"); const contracts_2 = require("../contracts"); // check and approve the axie contract to transfer axies from address to the marketplace contract async function approveMarketplaceContract(signer) { const axieContract = (0, contracts_2.getAxieContract)(signer); const address = await signer.getAddress(); let isApproved = await axieContract.isApprovedForAll(address, contracts_1.MARKETPLACE_GATEWAY_V_2.address); if (!isApproved) { const axieContract = (0, contracts_2.getAxieContract)(signer); console.log(`Approving Marketplace (${contracts_1.MARKETPLACE_GATEWAY_V_2.address}) to handle Axies for ${address}`); const tx = await axieContract.setApprovalForAll(contracts_1.MARKETPLACE_GATEWAY_V_2.address, true, { gasPrice: (0, ethers_1.parseUnits)("20", "gwei"), }); const receipt = await tx.wait(); console.log("✅ Marketplace approved! Transaction hash:", receipt.hash); console.log("🔗 View on Ronin Explorer:", `https://explorer.roninchain.com/tx/${receipt.hash}`); } return isApproved; } async function approveWETH(signer) { const address = await signer.getAddress(); const wethContract = (0, contracts_2.getWETHContract)(signer); const currentAllowance = await wethContract.allowance(address, contracts_1.MARKETPLACE_GATEWAY_V_2.address); if (currentAllowance === 0n) { const amountToApprove = "115792089237316195423570985008687907853269984665640564039457584007913129639935"; console.log(`Approving Marketplace (${contracts_1.MARKETPLACE_GATEWAY_V_2.address}) to spend ${amountToApprove} WETH for the address ${address}`); const txApproveWETH = await wethContract.approve(contracts_1.MARKETPLACE_GATEWAY_V_2.address, amountToApprove, { gasPrice: (0, ethers_1.parseUnits)("20", "gwei"), }); const txApproveReceipt = await txApproveWETH.wait(); console.log("✅ WETH approved! Transaction hash:", txApproveReceipt.hash); } return currentAllowance; } async function approveBatchTransfer(signer, batchTransferAddress) { const address = await signer.getAddress(); const axieContract = (0, contracts_2.getAxieContract)(signer); const isApproved = await axieContract.isApprovedForAll(address, batchTransferAddress); if (!isApproved) { console.info("🛠️ Approving batch transfer contract..."); const approveTx = await axieContract.setApprovalForAll(batchTransferAddress, true, { gasPrice: (0, ethers_1.parseUnits)("20", "gwei"), }); await approveTx.wait(); console.log("✅ Batch transfer contract approved, hash:", approveTx.hash); } }