UNPKG

@tatumio/tatum-v1

Version:

Tatum API client allows browsers and Node.js clients to interact with Tatum API.

686 lines 120 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.sendPolygonBurnMultiTokenBatchSignedTransaction = exports.sendPolygonBurnMultiTokenSignedTransaction = exports.sendPolygonDeployErc721SignedTransaction = exports.sendPolygonUpdateCashbackForAuthorErc721SignedTransaction = exports.sendPolygonTransferErc721SignedTransaction = exports.sendPolygonBurnErc721SignedTransaction = exports.sendPolygonMintMultipleErc721SignedTransaction = exports.sendPolygonMintMultipleErc721ProvenanceSignedTransaction = exports.sendPolygonMintMultipleCashbackErc721SignedTransaction = exports.sendPolygonMintErc721ProvenanceSignedTransaction = exports.sendPolygonMintCashbackErc721SignedTransaction = exports.sendPolygonMintErc721SignedTransaction = exports.sendPolygonDeployErc20SignedTransaction = exports.sendPolygonTransferErc20SignedTransaction = exports.sendPolygonBurnErc20SignedTransaction = exports.sendPolygonMintErc20SignedTransaction = exports.sendPolygonStoreDataTransaction = exports.sendPolygonSmartContractReadMethodInvocationTransaction = exports.preparePolygonSmartContractWriteMethodInvocation = exports.preparePolygonDeployMultiTokenSignedTransaction = exports.preparePolygonMintMultiTokenBatchSignedTransaction = exports.preparePolygonMintMultiTokenSignedTransaction = exports.preparePolygonBatchTransferMultiTokenSignedTransaction = exports.preparePolygonTransferMultiTokenSignedTransaction = exports.preparePolygonBurnMultiTokenBatchSignedTransaction = exports.preparePolygonBurnMultiTokenSignedTransaction = exports.preparePolygonDeployAuctionSignedTransaction = exports.preparePolygonDeployMarketplaceListingSignedTransaction = exports.preparePolygonDeployErc721SignedTransaction = exports.preparePolygonUpdateCashbackForAuthorErc721SignedTransaction = exports.preparePolygonTransferErc721SignedTransaction = exports.preparePolygonBurnErc721SignedTransaction = exports.preparePolygonMintMultipleErc721SignedTransaction = exports.preparePolygonMintMultipleCashbackErc721SignedTransaction = exports.preparePolygonMintMultipleErc721ProvenanceSignedTransaction = exports.preparePolygonMintCashbackErc721SignedTransaction = exports.preparePolygonMintErc721ProvenanceSignedTransaction = exports.preparePolygonMintErc721SignedTransaction = exports.preparePolygonDeployErc20SignedTransaction = exports.preparePolygonTransferErc20SignedTransaction = exports.preparePolygonBurnErc20SignedTransaction = exports.preparePolygonMintErc20SignedTransaction = exports.preparePolygonStoreDataTransaction = exports.preparePolygonSignedTransaction = exports.preparePolygonGenerateCustodialWalletSignedTransaction = exports.getPolygonErc20ContractDecimals = exports.signPolygonKMSTransaction = exports.preparePolygonClient = exports.sendPolygonTransaction = exports.polygonGetGasPriceInWei = void 0; exports.sendPolygonDeployMarketplaceListingSignedTransaction = exports.sendPolygonSmartContractMethodInvocationTransaction = exports.sendPolygonGenerateCustodialWalletSignedTransaction = exports.sendPolygonDeployMultiTokenSignedTransaction = exports.sendPolygonMintMultiTokenBatchSignedTransaction = exports.sendPolygonMintMultiTokenSignedTransaction = exports.sendPolygonBatchTransferMultiTokenSignedTransaction = exports.sendPolygonTransferMultiTokenSignedTransaction = void 0; const bignumber_js_1 = require("bignumber.js"); const web3_1 = __importDefault(require("web3")); const web3_utils_1 = require("web3-utils"); const blockchain_1 = require("../blockchain"); const tatum_1 = require("../connector/tatum"); const constants_1 = require("../constants"); const erc1155_abi_1 = __importDefault(require("../contracts/erc1155/erc1155_abi")); const erc1155_bytecode_1 = __importDefault(require("../contracts/erc1155/erc1155_bytecode")); const token_abi_1 = __importDefault(require("../contracts/erc20/token_abi")); const token_abi_2 = __importDefault(require("../contracts/erc20/token_abi")); const token_bytecode_1 = __importDefault(require("../contracts/erc20/token_bytecode")); const erc721_abi_1 = __importDefault(require("../contracts/erc721Cashback/erc721_abi")); const erc721_bytecode_1 = __importDefault(require("../contracts/erc721Cashback/erc721_bytecode")); const erc721Provenance_abi_1 = __importDefault(require("../contracts/erc721Provenance/erc721Provenance_abi")); const erc721Provenance_bytecode_1 = __importDefault(require("../contracts/erc721Provenance/erc721Provenance_bytecode")); const marketplace_1 = require("../contracts/marketplace"); const model_1 = require("../model"); const nft_1 = require("../nft"); const wallet_1 = require("../wallet"); const erc721_abi_2 = __importDefault(require("../contracts/erc721General/erc721_abi")); const erc721_bytecode_2 = __importDefault(require("../contracts/erc721General/erc721_bytecode")); /** * Estimate Gas price for the transaction. */ const polygonGetGasPriceInWei = async () => { var _a, _b; const { data } = await tatum_1.axios.get('https://gasstation.polygon.technology/v2'); const gasPrice = new bignumber_js_1.BigNumber((_b = (_a = data === null || data === void 0 ? void 0 : data.fast) === null || _a === void 0 ? void 0 : _a.maxFee) !== null && _b !== void 0 ? _b : 30).toNumber(); return web3_1.default.utils.toWei(`${Math.max(30, Math.ceil(gasPrice))}`, 'gwei'); }; exports.polygonGetGasPriceInWei = polygonGetGasPriceInWei; const prepareGeneralTx = async (client, testnet, fromPrivateKey, signatureId, to, amount, nonce, data, gasLimit, gasPrice) => { const tx = { from: 0, to, value: amount ? `0x${new bignumber_js_1.BigNumber(web3_utils_1.toWei(amount, 'ether')).toString(16)}` : undefined, data, gas: gasLimit, nonce, gasPrice: gasPrice ? `0x${new bignumber_js_1.BigNumber(web3_utils_1.toWei(gasPrice, 'gwei')).toString(16)}` : await exports.polygonGetGasPriceInWei(), }; if (signatureId) { return JSON.stringify(tx); } const estimatedGas = await client.eth.estimateGas({ to, data: data || '', value: tx.value }); tx.gas = gasLimit || estimatedGas; return (await client.eth.accounts.signTransaction(tx, fromPrivateKey)).rawTransaction; }; /** * Send Polygon transaction to the blockchain. This method broadcasts signed transaction to the blockchain. * This operation is irreversible. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Polygon Server to connect to. If not set, default public server will be used. * @returns transaction id of the transaction in the blockchain */ const sendPolygonTransaction = async (testnet, body, provider) => { return blockchain_1.polygonBroadcast(await exports.preparePolygonSignedTransaction(testnet, body, provider)); }; exports.sendPolygonTransaction = sendPolygonTransaction; const preparePolygonClient = (testnet, provider, fromPrivateKey) => { const client = new web3_1.default(provider || `${process.env.TATUM_API_URL || constants_1.TATUM_API_URL}/v3/polygon/web3/${process.env.TATUM_API_KEY}`); if (fromPrivateKey) { client.eth.accounts.wallet.clear(); client.eth.accounts.wallet.add(fromPrivateKey); client.eth.defaultAccount = client.eth.accounts.wallet[0].address; } return client; }; exports.preparePolygonClient = preparePolygonClient; /** * Sign Polygon pending transaction from Tatum KMS * @param tx pending transaction from KMS * @param fromPrivateKey private key to sign transaction with. * @param testnet mainnet or testnet version * @param provider url of the Polygon Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const signPolygonKMSTransaction = async (tx, fromPrivateKey, testnet, provider) => { if (tx.chain !== model_1.Currency.MATIC) { throw Error('Unsupported chain.'); } const client = exports.preparePolygonClient(testnet, provider, fromPrivateKey); const transactionConfig = JSON.parse(tx.serializedTransaction); if (!transactionConfig.gas) { transactionConfig.gas = await client.eth.estimateGas({ to: transactionConfig.to, data: transactionConfig.data }); } if (!transactionConfig.gasPrice || transactionConfig.gasPrice === '0' || transactionConfig.gasPrice === 0 || transactionConfig.gasPrice === '0x0') { transactionConfig.gasPrice = await exports.polygonGetGasPriceInWei(); } return (await client.eth.accounts.signTransaction(transactionConfig, fromPrivateKey)).rawTransaction; }; exports.signPolygonKMSTransaction = signPolygonKMSTransaction; const getPolygonErc20ContractDecimals = async (testnet, contractAddress, provider) => { if (!contractAddress) { throw new Error('Contract address not set.'); } const client = await exports.preparePolygonClient(testnet, provider); // @ts-ignore const contract = new client.eth.Contract(token_abi_1.default, contractAddress.trim()); return await contract.methods.decimals().call(); }; exports.getPolygonErc20ContractDecimals = getPolygonErc20ContractDecimals; /** * Sign Polygon generate custodial wallet transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Polygon Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const preparePolygonGenerateCustodialWalletSignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.GenerateCustodialAddress); const client = await exports.preparePolygonClient(testnet, provider, body.fromPrivateKey); const { abi, code } = wallet_1.obtainCustodialAddressType(body); // @ts-ignore const contract = new client.eth.Contract(abi); const data = contract.deploy({ data: code, }).encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, undefined, undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.preparePolygonGenerateCustodialWalletSignedTransaction = preparePolygonGenerateCustodialWalletSignedTransaction; /** * Sign Polygon transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Polygon Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const preparePolygonSignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.TransferErc20); const client = await exports.preparePolygonClient(testnet, provider, body.fromPrivateKey); let data; let to = body.to; if (body.currency === model_1.Currency.MATIC) { data = body.data ? (client.utils.isHex(body.data) ? client.utils.stringToHex(body.data) : client.utils.toHex(body.data)) : undefined; } else { to = constants_1.CONTRACT_ADDRESSES[body.currency]; // @ts-ignore const contract = new client.eth.Contract([constants_1.TRANSFER_METHOD_ABI], to); const digits = new bignumber_js_1.BigNumber(10).pow(constants_1.CONTRACT_DECIMALS[body.currency]); data = contract.methods.transfer(body.to.trim(), `0x${new bignumber_js_1.BigNumber(body.amount).multipliedBy(digits).toString(16)}`).encodeABI(); } return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, body.to, body.amount, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.preparePolygonSignedTransaction = preparePolygonSignedTransaction; /** * Sign Polygon store data transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Polygon Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const preparePolygonStoreDataTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.CreateRecord); const client = await exports.preparePolygonClient(testnet, provider, body.fromPrivateKey); const hexData = web3_utils_1.isHex(body.data) ? web3_utils_1.stringToHex(body.data) : web3_utils_1.toHex(body.data); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, body.to || client.eth.accounts.wallet[0].address, undefined, body.nonce, hexData, (_a = body.ethFee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.ethFee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.preparePolygonStoreDataTransaction = preparePolygonStoreDataTransaction; /** * Sign Polygon mint erc20 transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Polygon Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const preparePolygonMintErc20SignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.MintErc20); const client = await exports.preparePolygonClient(testnet, provider, body.fromPrivateKey); // @ts-ignore const contract = new client.eth.Contract(token_abi_2.default, body.contractAddress.trim().trim()); const digits = new bignumber_js_1.BigNumber(10).pow(await contract.methods.decimals().call()); const data = contract.methods .mint(body.to.trim(), `0x${new bignumber_js_1.BigNumber(body.amount).multipliedBy(digits).toString(16)}`).encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, body.contractAddress.trim(), undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.preparePolygonMintErc20SignedTransaction = preparePolygonMintErc20SignedTransaction; /** * Sign Polygon burn erc20 transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Polygon Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const preparePolygonBurnErc20SignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.BurnErc20); const client = await exports.preparePolygonClient(testnet, provider, body.fromPrivateKey); // @ts-ignore const contract = new client.eth.Contract(token_abi_2.default, body.contractAddress.trim().trim()); const digits = new bignumber_js_1.BigNumber(10).pow(await contract.methods.decimals().call()); const data = contract.methods .burn(`0x${new bignumber_js_1.BigNumber(body.amount).multipliedBy(digits).toString(16)}`).encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, body.contractAddress.trim(), undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.preparePolygonBurnErc20SignedTransaction = preparePolygonBurnErc20SignedTransaction; /** * Sign Polygon transfer erc20 transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Polygon Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const preparePolygonTransferErc20SignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.TransferErc20); const client = await exports.preparePolygonClient(testnet, provider, body.fromPrivateKey); const decimals = new bignumber_js_1.BigNumber(10).pow(body.digits); // @ts-ignore const data = new client.eth.Contract(token_abi_2.default, body.contractAddress.trim().trim()).methods .transfer(body.to.trim(), `0x${new bignumber_js_1.BigNumber(body.amount).multipliedBy(decimals).toString(16)}`).encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, body.contractAddress.trim(), undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.preparePolygonTransferErc20SignedTransaction = preparePolygonTransferErc20SignedTransaction; /** * Sign Polygon deploy erc20 transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Polygon Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const preparePolygonDeployErc20SignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.DeployErc20); const client = await exports.preparePolygonClient(testnet, provider, body.fromPrivateKey); // @ts-ignore const contract = new client.eth.Contract(token_abi_2.default); const data = contract.deploy({ data: token_bytecode_1.default, arguments: [ body.name, body.symbol, body.address.trim(), body.digits, `0x${new bignumber_js_1.BigNumber(body.totalCap || body.supply).multipliedBy(new bignumber_js_1.BigNumber(10).pow(body.digits)).toString(16)}`, `0x${new bignumber_js_1.BigNumber(body.supply).multipliedBy(new bignumber_js_1.BigNumber(10).pow(body.digits)).toString(16)}`, ], }).encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, undefined, undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.preparePolygonDeployErc20SignedTransaction = preparePolygonDeployErc20SignedTransaction; /** * Sign Polygon mint erc721 transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Polygon Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const preparePolygonMintErc721SignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.EthMintErc721); const client = await exports.preparePolygonClient(testnet, provider, body.fromPrivateKey); // @ts-ignore const data = new (client).eth.Contract(erc721_abi_1.default, body.contractAddress.trim()).methods .mintWithTokenURI(body.to.trim(), body.tokenId, body.url).encodeABI(); if (body.contractAddress) { return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, body.contractAddress.trim(), undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); } throw new Error('Contract address should not be empty!'); }; exports.preparePolygonMintErc721SignedTransaction = preparePolygonMintErc721SignedTransaction; /** * Sign Polygon mint cashback erc721 provenance transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Polygon Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const preparePolygonMintErc721ProvenanceSignedTransaction = async (testnet, body, provider) => { var _a, _b, _c, _d; await tatum_1.validateBody(body, model_1.EthMintErc721); const client = await exports.preparePolygonClient(testnet, provider, body.fromPrivateKey); const cb = []; const fv = []; if (body.cashbackValues && body.fixedValues && body.authorAddresses) { body.cashbackValues.map(c => cb.push(`0x${new bignumber_js_1.BigNumber(c).multipliedBy(100).toString(16)}`)); body.fixedValues.map(c => fv.push(`0x${new bignumber_js_1.BigNumber(client.utils.toWei(c, 'ether')).toString(16)}`)); } if (body.erc20) { // @ts-ignore const data = new (client).eth.Contract(erc721Provenance_abi_1.default, body.contractAddress.trim()).methods .mintWithTokenURI(body.to.trim(), body.tokenId, body.url, body.authorAddresses ? body.authorAddresses : [], cb, fv, body.erc20).encodeABI(); if (body.contractAddress) { return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, body.contractAddress.trim(), undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); } throw new Error('Contract address should not be empty!'); } else { // @ts-ignore const data = new (client).eth.Contract(erc721Provenance_abi_1.default, body.contractAddress.trim()).methods .mintWithTokenURI(body.to.trim(), body.tokenId, body.url, body.authorAddresses ? body.authorAddresses : [], cb, fv).encodeABI(); if (body.contractAddress) { return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, body.contractAddress.trim(), undefined, body.nonce, data, (_c = body.fee) === null || _c === void 0 ? void 0 : _c.gasLimit, (_d = body.fee) === null || _d === void 0 ? void 0 : _d.gasPrice); } throw new Error('Contract address should not be empty!'); } }; exports.preparePolygonMintErc721ProvenanceSignedTransaction = preparePolygonMintErc721ProvenanceSignedTransaction; /** * Sign Polygon mint cashback erc721 transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Polygon Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const preparePolygonMintCashbackErc721SignedTransaction = async (testnet, body, provider) => { var _a, _b, _c, _d; await tatum_1.validateBody(body, model_1.EthMintErc721); const client = await exports.preparePolygonClient(testnet, provider, body.fromPrivateKey); const cashbacks = body.cashbackValues; const cb = cashbacks.map(c => `0x${new bignumber_js_1.BigNumber(client.utils.toWei(c, 'ether')).toString(16)}`); if (body.erc20) { // @ts-ignore const data = new (client).eth.Contract(erc721_abi_1.default, body.contractAddress.trim()).methods .mintWithCashback(body.to.trim(), body.tokenId, body.url, body.authorAddresses, cb, body.erc20).encodeABI(); if (body.contractAddress) { return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, body.contractAddress.trim(), undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); } throw new Error('Contract address should not be empty!'); } else { // @ts-ignore const data = new (client).eth.Contract(erc721_abi_1.default, body.contractAddress.trim()).methods .mintWithCashback(body.to.trim(), body.tokenId, body.url, body.authorAddresses, cb).encodeABI(); if (body.contractAddress) { return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, body.contractAddress.trim(), undefined, body.nonce, data, (_c = body.fee) === null || _c === void 0 ? void 0 : _c.gasLimit, (_d = body.fee) === null || _d === void 0 ? void 0 : _d.gasPrice); } throw new Error('Contract address should not be empty!'); } }; exports.preparePolygonMintCashbackErc721SignedTransaction = preparePolygonMintCashbackErc721SignedTransaction; /** * Sign Polygon mint multiple cashback erc721 provenance transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Polygon Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const preparePolygonMintMultipleErc721ProvenanceSignedTransaction = async (testnet, body, provider) => { var _a, _b, _c, _d; await tatum_1.validateBody(body, model_1.EthMintMultipleErc721); const client = await exports.preparePolygonClient(testnet, provider, body.fromPrivateKey); const cb = []; const fv = []; if (body.cashbackValues && body.fixedValues && body.authorAddresses) { for (let i = 0; i < body.cashbackValues.length; i++) { const cb2 = []; const fv2 = []; for (let j = 0; j < body.cashbackValues[i].length; j++) { cb2.push(`0x${new bignumber_js_1.BigNumber(body.cashbackValues[i][j]).multipliedBy(100).toString(16)}`); fv2.push(`0x${new bignumber_js_1.BigNumber(web3_utils_1.toWei(body.fixedValues[i][j], 'ether')).toString(16)}`); } cb.push(cb2); fv.push(fv2); } } if (body.erc20) { // @ts-ignore const data = new (client).eth.Contract(erc721Provenance_abi_1.default, body.contractAddress.trim()).methods .mintMultiple(body.to.map(t => t.trim()), body.tokenId, body.url, body.authorAddresses ? body.authorAddresses : [], cb, fv, body.erc20).encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, body.contractAddress.trim(), undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); } else { // @ts-ignore const data = new (client).eth.Contract(erc721Provenance_abi_1.default, body.contractAddress.trim()).methods .mintMultiple(body.to.map(t => t.trim()), body.tokenId, body.url, body.authorAddresses ? body.authorAddresses : [], cb, fv).encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, body.contractAddress.trim(), undefined, body.nonce, data, (_c = body.fee) === null || _c === void 0 ? void 0 : _c.gasLimit, (_d = body.fee) === null || _d === void 0 ? void 0 : _d.gasPrice); } }; exports.preparePolygonMintMultipleErc721ProvenanceSignedTransaction = preparePolygonMintMultipleErc721ProvenanceSignedTransaction; /** * Sign Polygon mint multiple cashback erc721 transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Polygon Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const preparePolygonMintMultipleCashbackErc721SignedTransaction = async (testnet, body, provider) => { var _a, _b, _c, _d; await tatum_1.validateBody(body, model_1.EthMintMultipleErc721); const client = await exports.preparePolygonClient(testnet, provider, body.fromPrivateKey); const cashbacks = body.cashbackValues; const cb = cashbacks.map(cashback => cashback.map(c => `0x${new bignumber_js_1.BigNumber(client.utils.toWei(c, 'ether')).toString(16)}`)); if (body.erc20) { // @ts-ignore const data = new (client).eth.Contract(erc721_abi_1.default, body.contractAddress.trim()).methods .mintMultipleCashback(body.to.map(t => t.trim()), body.tokenId, body.url, body.authorAddresses, cb, body.erc20).encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, body.contractAddress.trim(), undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); } else { // @ts-ignore const data = new (client).eth.Contract(erc721_abi_1.default, body.contractAddress.trim()).methods .mintMultipleCashback(body.to.map(t => t.trim()), body.tokenId, body.url, body.authorAddresses, cb).encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, body.contractAddress.trim(), undefined, body.nonce, data, (_c = body.fee) === null || _c === void 0 ? void 0 : _c.gasLimit, (_d = body.fee) === null || _d === void 0 ? void 0 : _d.gasPrice); } }; exports.preparePolygonMintMultipleCashbackErc721SignedTransaction = preparePolygonMintMultipleCashbackErc721SignedTransaction; /** * Sign Polygon mint multiple erc721 transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Polygon Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const preparePolygonMintMultipleErc721SignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.EthMintMultipleErc721); const client = await exports.preparePolygonClient(testnet, provider, body.fromPrivateKey); // @ts-ignore const data = new (client).eth.Contract(erc721_abi_1.default, body.contractAddress.trim()) .methods.mintMultiple(body.to.map(t => t.trim()), body.tokenId, body.url).encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, body.contractAddress.trim(), undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.preparePolygonMintMultipleErc721SignedTransaction = preparePolygonMintMultipleErc721SignedTransaction; /** * Sign Polygon burn erc721 transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Polygon Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const preparePolygonBurnErc721SignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.EthBurnErc721); const client = await exports.preparePolygonClient(testnet, provider, body.fromPrivateKey); // @ts-ignore const data = new (client).eth.Contract(erc721_abi_1.default, body.contractAddress.trim()).methods.burn(body.tokenId).encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, body.contractAddress.trim(), undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.preparePolygonBurnErc721SignedTransaction = preparePolygonBurnErc721SignedTransaction; /** * Sign Polygon transfer erc721 transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Polygon Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const preparePolygonTransferErc721SignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.EthTransferErc721); const client = await exports.preparePolygonClient(testnet, provider, body.fromPrivateKey); // @ts-ignore const contract = new (client).eth.Contract(body.provenance ? erc721Provenance_abi_1.default : erc721_abi_1.default, body.contractAddress.trim()); const dataBytes = body.provenance ? Buffer.from(body.provenanceData + '\'\'\'###\'\'\'' + web3_utils_1.toWei(body.tokenPrice, 'ether'), 'utf8') : ''; const data = body.provenance ? contract.methods.safeTransfer(body.to.trim(), body.tokenId, `0x${dataBytes.toString('hex')}`).encodeABI() : contract.methods.safeTransfer(body.to.trim(), body.tokenId).encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, body.contractAddress.trim(), body.value, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.preparePolygonTransferErc721SignedTransaction = preparePolygonTransferErc721SignedTransaction; /** * Sign Polygon update cashback for author erc721 transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Polygon Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const preparePolygonUpdateCashbackForAuthorErc721SignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.UpdateCashbackErc721); const client = await exports.preparePolygonClient(testnet, provider, body.fromPrivateKey); // @ts-ignore const data = new (client).eth.Contract(erc721_abi_1.default, body.contractAddress.trim()).methods .updateCashbackForAuthor(body.tokenId, `0x${new bignumber_js_1.BigNumber(web3_utils_1.toWei(body.cashbackValue, 'ether')).toString(16)}`).encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, body.contractAddress.trim(), undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.preparePolygonUpdateCashbackForAuthorErc721SignedTransaction = preparePolygonUpdateCashbackForAuthorErc721SignedTransaction; /** * Sign Polygon deploy erc721 transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Polygon Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const preparePolygonDeployErc721SignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.EthDeployErc721); const client = await exports.preparePolygonClient(testnet, provider, body.fromPrivateKey); if (body.provenance && body.cashback) { throw new Error('Only one of provenance or cashback must be present and true.'); } let abi = erc721_abi_2.default; let deployData = erc721_bytecode_2.default; if (body.provenance) { abi = erc721Provenance_abi_1.default; deployData = erc721Provenance_bytecode_1.default; } else if (body.cashback) { abi = erc721_abi_1.default; deployData = erc721_bytecode_1.default; } // @ts-ignore const data = new client.eth.Contract(abi).deploy({ arguments: [body.name, body.symbol, body.publicMint ? body.publicMint : false], data: deployData, }).encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, undefined, undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.preparePolygonDeployErc721SignedTransaction = preparePolygonDeployErc721SignedTransaction; /** * Sign Polygon generate custodial wallet address transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet * @param body content of the transaction to broadcast * @param provider url of the Polygon Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain, or signatureId in case of Tatum KMS */ const preparePolygonDeployMarketplaceListingSignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.DeployMarketplaceListing); const client = await exports.preparePolygonClient(testnet, provider, body.fromPrivateKey); // @ts-ignore const data = new client.eth.Contract(marketplace_1.listing.abi).deploy({ arguments: [body.marketplaceFee, body.feeRecipient], data: marketplace_1.listing.data, }).encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, undefined, undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.preparePolygonDeployMarketplaceListingSignedTransaction = preparePolygonDeployMarketplaceListingSignedTransaction; /** * Sign Polygon deploy NFT Auction contract transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet * @param body content of the transaction to broadcast * @param provider url of the Polygon Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain, or signatureId in case of Tatum KMS */ const preparePolygonDeployAuctionSignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.DeployNftAuction); const client = await exports.preparePolygonClient(testnet, provider, body.fromPrivateKey); // @ts-ignore const data = new client.eth.Contract(marketplace_1.auction.abi).deploy({ arguments: [body.auctionFee, body.feeRecipient], data: marketplace_1.auction.data, }).encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, undefined, undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.preparePolygonDeployAuctionSignedTransaction = preparePolygonDeployAuctionSignedTransaction; /** * Sign Polygon burn multiple tokens transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Polygon Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const preparePolygonBurnMultiTokenSignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.EthBurnMultiToken); const client = await exports.preparePolygonClient(testnet, provider, body.fromPrivateKey); // @ts-ignore const data = new (client).eth.Contract(erc1155_abi_1.default, body.contractAddress.trim()).methods .burn(body.account.trim(), body.tokenId, body.amount).encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, body.contractAddress.trim(), undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.preparePolygonBurnMultiTokenSignedTransaction = preparePolygonBurnMultiTokenSignedTransaction; /** * Sign Polygon burn multiple tokens batch transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Polygon Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const preparePolygonBurnMultiTokenBatchSignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.EthBurnMultiTokenBatch); const client = await exports.preparePolygonClient(testnet, provider, body.fromPrivateKey); // @ts-ignore const data = new (client).eth.Contract(erc1155_abi_1.default, body.contractAddress.trim()).methods .burnBatch(body.account.trim(), body.tokenId, body.amounts).encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, body.contractAddress.trim(), undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.preparePolygonBurnMultiTokenBatchSignedTransaction = preparePolygonBurnMultiTokenBatchSignedTransaction; /** * Sign Polygon transfer multiple tokens transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Polygon Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const preparePolygonTransferMultiTokenSignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.TransferMultiToken); const client = await exports.preparePolygonClient(testnet, provider, body.fromPrivateKey); // @ts-ignore const data = new (client).eth.Contract(erc1155_abi_1.default, body.contractAddress.trim()).methods .safeTransfer(body.to.trim(), body.tokenId, `0x${new bignumber_js_1.BigNumber(body.amount).toString(16)}`, body.data ? body.data : '0x0').encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, body.contractAddress.trim(), undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.preparePolygonTransferMultiTokenSignedTransaction = preparePolygonTransferMultiTokenSignedTransaction; /** * Sign Polygon batch transfer multiple tokens transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Polygon Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const preparePolygonBatchTransferMultiTokenSignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.TransferMultiTokenBatch); const client = await exports.preparePolygonClient(testnet, provider, body.fromPrivateKey); const amts = body.amounts.map(amt => `0x${new bignumber_js_1.BigNumber(amt).toString(16)}`); // @ts-ignore const data = new (client).eth.Contract(erc1155_abi_1.default, body.contractAddress.trim()).methods .safeBatchTransfer(body.to.trim(), body.tokenId.map(token => token.trim()), amts, body.data ? body.data : '0x0').encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, body.contractAddress.trim(), undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.preparePolygonBatchTransferMultiTokenSignedTransaction = preparePolygonBatchTransferMultiTokenSignedTransaction; /** * Sign Polygon mint multiple tokens transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Polygon Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const preparePolygonMintMultiTokenSignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.MintMultiToken); const client = await exports.preparePolygonClient(testnet, provider, body.fromPrivateKey); // @ts-ignore const data = new (client).eth.Contract(erc1155_abi_1.default, body.contractAddress.trim()).methods .mint(body.to.trim(), body.tokenId, `0x${new bignumber_js_1.BigNumber(body.amount).toString(16)}`, body.data ? body.data : '0x0').encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, body.contractAddress.trim(), undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.preparePolygonMintMultiTokenSignedTransaction = preparePolygonMintMultiTokenSignedTransaction; /** * Sign Polygon mint multiple tokens batch transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Polygon Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const preparePolygonMintMultiTokenBatchSignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.MintMultiTokenBatch); const client = await exports.preparePolygonClient(testnet, provider, body.fromPrivateKey); const batchAmounts = body.amounts.map(amts => amts.map(amt => `0x${new bignumber_js_1.BigNumber(amt).toString(16)}`)); // @ts-ignore const data = new (client).eth.Contract(erc1155_abi_1.default, body.contractAddress.trim()).methods .mintBatch(body.to, body.tokenId, batchAmounts, body.data ? body.data : '0x0').encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, body.contractAddress.trim(), undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.preparePolygonMintMultiTokenBatchSignedTransaction = preparePolygonMintMultiTokenBatchSignedTransaction; /** * Sign Polygon deploy multiple tokens transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Polygon Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const preparePolygonDeployMultiTokenSignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.EthDeployMultiToken); const client = await exports.preparePolygonClient(testnet, provider, body.fromPrivateKey); // @ts-ignore const data = new client.eth.Contract(erc1155_abi_1.default).deploy({ arguments: [body.uri, body.publicMint ? body.publicMint : false], data: erc1155_bytecode_1.default, }).encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, undefined, undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.preparePolygonDeployMultiTokenSignedTransaction = preparePolygonDeployMultiTokenSignedTransaction; /** * Sign Polygon smart contract write method invocation transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Polygon Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const preparePolygonSmartContractWriteMethodInvocation = async (testnet, body, provider) => { await tatum_1.validateBody(body, model_1.SmartContractMethodInvocation); const { fromPrivateKey, fee, params, methodName, methodABI, contractAddress, nonce, amount, signatureId, } = body; const client = await exports.preparePolygonClient(testnet, provider, fromPrivateKey); const data = new client.eth.Contract([methodABI]).methods[methodName](...params).encodeABI(); return prepareGeneralTx(client, testnet, fromPrivateKey, signatureId, contractAddress.trim(), amount, nonce, data, fee === null || fee === void 0 ? void 0 : fee.gasLimit, fee === null || fee === void 0 ? void 0 : fee.gasPrice); }; exports.preparePolygonSmartContractWriteMethod