UNPKG

@volare.finance/utils.js

Version:
173 lines 7.7 kB
"use strict"; /** * @file erc721.ts * @author astra <astra@volare.finance> * @date 2022 */ Object.defineProperty(exports, "__esModule", { value: true }); exports.ERC721 = void 0; const tslib_1 = require("tslib"); const ethers_1 = require("ethers"); const ERC721_json_1 = require("../artifacts/token/ERC721.json"); const provider_1 = require("../provider"); const type_1 = require("../type"); class ERC721 extends provider_1.Provider { static ABI() { return ERC721_json_1.abi; } // https://eips.ethereum.org/EIPS/eip-721#ERC721 static BalanceOf(contract, owner) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const erc721 = new ethers_1.Contract(contract, ERC721.ABI(), ERC721.provider); return new type_1.BigNumber((yield erc721.balanceOf(owner)).toString()); }); } static OwnerOf(contract, tokenId) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const erc721 = new ethers_1.Contract(contract, ERC721.ABI(), ERC721.provider); return erc721.ownerOf(tokenId); }); } static SafeTransferFrom(contract, owner, from, to, tokenId, data) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const erc721 = new ethers_1.Contract(contract, ERC721.ABI(), ERC721.provider); if (data === null || data === void 0 ? void 0 : data.length) { return erc721.connect(owner)['safeTransferFrom(address,address,uint256,bytes)'](from, to, tokenId, data); } else { return erc721.connect(owner)['safeTransferFrom(address,address,uint256)'](from, to, tokenId); } }); } static TransferFrom(contract, owner, from, to, tokenId) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const erc721 = new ethers_1.Contract(contract, ERC721.ABI(), ERC721.provider); return erc721.connect(owner).transferFrom(from, to, tokenId); }); } static Approve(contract, owner, approved, tokenId) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const erc721 = new ethers_1.Contract(contract, ERC721.ABI(), ERC721.provider); return erc721.connect(owner).approve(approved, tokenId); }); } static SetApprovalForAll(contract, owner, operator, approved) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const erc721 = new ethers_1.Contract(contract, ERC721.ABI(), ERC721.provider); return erc721.connect(owner).setApprovalForAll(operator, approved); }); } static GetApproved(contract, tokenId) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const erc721 = new ethers_1.Contract(contract, ERC721.ABI(), ERC721.provider); return erc721.getApproved(tokenId); }); } static IsApprovedForAll(contract, owner, operator) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const erc721 = new ethers_1.Contract(contract, ERC721.ABI(), ERC721.provider); return erc721.isApprovedForAll(owner, operator); }); } // https://eips.ethereum.org/EIPS/eip-721#ERC721Metadata static Name(contract) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const erc721 = new ethers_1.Contract(contract, ERC721.ABI(), ERC721.provider); return erc721.name(); }); } static Symbol(contract) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const erc721 = new ethers_1.Contract(contract, ERC721.ABI(), ERC721.provider); return erc721.symbol(); }); } static TokenURI(contract, tokenId) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const erc721 = new ethers_1.Contract(contract, ERC721.ABI(), ERC721.provider); return erc721.tokenURI(tokenId); }); } constructor(contract, endpoint) { super(endpoint); this.contract = new ethers_1.Contract(contract, ERC721.ABI(), this.provider); } // https://eips.ethereum.org/EIPS/eip-721#ERC721 balanceOf(owner) { var _a; return tslib_1.__awaiter(this, void 0, void 0, function* () { return new type_1.BigNumber((yield ((_a = this.contract) === null || _a === void 0 ? void 0 : _a.balanceOf(owner))).toString()); }); } ownerOf(tokenId) { var _a; return tslib_1.__awaiter(this, void 0, void 0, function* () { return (_a = this.contract) === null || _a === void 0 ? void 0 : _a.ownerOf(tokenId); }); } safeTransferFrom(owner, from, to, tokenId, data) { var _a, _b; return tslib_1.__awaiter(this, void 0, void 0, function* () { if (data === null || data === void 0 ? void 0 : data.length) { return (_a = this.contract) === null || _a === void 0 ? void 0 : _a.connect(owner)['safeTransferFrom(address,address,uint256,bytes)'](from, to, tokenId, data); } else { return (_b = this.contract) === null || _b === void 0 ? void 0 : _b.connect(owner)['safeTransferFrom(address,address,uint256)'](from, to, tokenId); } }); } transferFrom(owner, from, to, tokenId) { var _a; return tslib_1.__awaiter(this, void 0, void 0, function* () { return (_a = this.contract) === null || _a === void 0 ? void 0 : _a.connect(owner).transferFrom(from, to, tokenId); }); } approve(owner, approved, tokenId) { var _a; return tslib_1.__awaiter(this, void 0, void 0, function* () { return (_a = this.contract) === null || _a === void 0 ? void 0 : _a.connect(owner).approve(approved, tokenId); }); } setApprovalForAll(owner, operator, approved) { var _a; return tslib_1.__awaiter(this, void 0, void 0, function* () { return (_a = this.contract) === null || _a === void 0 ? void 0 : _a.connect(owner).setApprovalForAll(operator, approved); }); } getApproved(tokenId) { var _a; return tslib_1.__awaiter(this, void 0, void 0, function* () { return (_a = this.contract) === null || _a === void 0 ? void 0 : _a.getApproved(tokenId); }); } isApprovedForAll(owner, operator) { var _a; return tslib_1.__awaiter(this, void 0, void 0, function* () { return (_a = this.contract) === null || _a === void 0 ? void 0 : _a.isApprovedForAll(owner, operator); }); } // https://eips.ethereum.org/EIPS/eip-721#ERC721Metadata name() { var _a; return tslib_1.__awaiter(this, void 0, void 0, function* () { return (_a = this.contract) === null || _a === void 0 ? void 0 : _a.name(); }); } symbol() { var _a; return tslib_1.__awaiter(this, void 0, void 0, function* () { return (_a = this.contract) === null || _a === void 0 ? void 0 : _a.symbol(); }); } tokenURI(tokenId) { var _a; return tslib_1.__awaiter(this, void 0, void 0, function* () { return (_a = this.contract) === null || _a === void 0 ? void 0 : _a.tokenURI(tokenId); }); } } exports.ERC721 = ERC721; ERC721.Transfer_t0 = ethers_1.utils.id('Transfer(address,address,uint256)'); ERC721.Approval_t0 = ethers_1.utils.id('Approval(address,address,uint256)'); ERC721.ApprovalForAll_t0 = ethers_1.utils.id('ApprovalForAll(address,address,bool)'); //# sourceMappingURL=erc721.js.map