UNPKG

@kanalabs/mirai

Version:

Mirai - Account Abstraction SDK (EVM + non-EVM)

72 lines (71 loc) 3.31 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ERC1155Helper = void 0; const ethers_1 = require("ethers"); const erc1155_ABI_1 = require("./erc1155-ABI"); class ERC1155Helper { constructor(sdk, collectionAddress, walletProvider) { this.sdk = sdk; this.collectionAddress = collectionAddress; this.walletProvider = walletProvider; this.collection = new ethers_1.Contract(this.collectionAddress, erc1155_ABI_1.ERC1155_ABI, this.walletProvider); } uri(_id) { return __awaiter(this, void 0, void 0, function* () { const URI = yield this.collection.functions.uri(_id); return URI[0]; }); } balanceOf(address, id) { return __awaiter(this, void 0, void 0, function* () { const bal = yield this.collection.functions.balanceOf(address, id); return bal[0]; }); } balanceOfBatch(addresses, ids) { return __awaiter(this, void 0, void 0, function* () { const balances = yield this.collection.functions.balanceOfBatch(addresses, ids); return balances[0]; }); } setApprovalForAll(operator, approved) { return __awaiter(this, void 0, void 0, function* () { const transactionData = this.collection.interface.encodeFunctionData('setApprovalForAll', [operator, approved]); yield this.sdk.addUserOpsToBatch({ to: this.collectionAddress, data: transactionData }); }); } isApprovedForAll(account, operator) { return __awaiter(this, void 0, void 0, function* () { const isApproved = yield this.collection.functions.isApprovedForAll(account, operator); return isApproved[0]; }); } safeTransferFrom(from, to, id, amount, data) { return __awaiter(this, void 0, void 0, function* () { const txData = this.collection.interface.encodeFunctionData('safeTransferFrom', [from, to, id, amount, data]); yield this.sdk.addUserOpsToBatch({ to: this.collectionAddress, data: txData }); }); } safeBatchTransferFrom(from, to, id, amount, data) { return __awaiter(this, void 0, void 0, function* () { const transactionData = this.collection.interface.encodeFunctionData('safeBatchTransferFrom', [ from, to, id, amount, data, ]); yield this.sdk.addUserOpsToBatch({ to: this.collectionAddress, data: transactionData }); }); } } exports.ERC1155Helper = ERC1155Helper;