UNPKG

ufomarketplace-sdk-new

Version:

SDK to interact with set ufo marketplace contracts

253 lines 10.9 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()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ufoInfoSDK = void 0; const ethers_1 = require("ethers"); const constants_1 = require("./constants/constants"); const ufoABI_json_1 = __importDefault(require("./abis/ufoABI.json")); const ufoLPABI_json_1 = __importDefault(require("./abis/ufoLPABI.json")); const ufoLPABI_json_2 = __importDefault(require("./abis/ufoLPABI.json")); const SuperGalaticFactory_json_1 = __importDefault(require("./abis/SuperGalaticFactory.json")); const ethereum_multicall_1 = require("ethereum-multicall"); const abis_1 = require("./abis"); const bignumber_js_1 = require("bignumber.js"); const ufoAbi = JSON.stringify(ufoABI_json_1.default); const ufoLPAbi = JSON.stringify(ufoLPABI_json_1.default); const plasmaAbi = JSON.stringify(ufoLPABI_json_2.default); class ufoInfoSDK { constructor(ufoConfig, netType) { this.ethProvider = null; this.beamProvider = null; this.ufoConfig = null; this.netType = 'mainnet'; this.ufoConfig = ufoConfig; this.netType = netType; if (netType == 'mainnet') { this.beamProvider = ethers_1.ethers.providers.getDefaultProvider(constants_1.RPCS[constants_1.NETWORK_ID.BEAM]); this.ethProvider = ethers_1.ethers.providers.getDefaultProvider(constants_1.RPCS[constants_1.NETWORK_ID.ETHEREUM]); } else if (netType == 'testnet') { this.beamProvider = ethers_1.ethers.providers.getDefaultProvider(constants_1.RPCS[constants_1.NETWORK_ID.BEAM_TESTNET]); this.ethProvider = ethers_1.ethers.providers.getDefaultProvider(constants_1.RPCS[constants_1.NETWORK_ID.SEPOLIA]); } else { console.error('UFO INFO SDK', 'provided wrong netType, netType will be "mainnet" or "testnet"'); } } getMultiCallParams(netType, userAddr) { let ufoAddr = null; let ufoLpAddr = null; let plasmaAddr = null; let uapAddr = null; let wEthAddr = null; if (netType == 'eth') { ufoAddr = this.ufoConfig.ufoTokenOnEth; ufoLpAddr = this.ufoConfig.ufoLPTokenOnEth; plasmaAddr = this.ufoConfig.plasmaTokenOnEth; uapAddr = this.ufoConfig.uapOnEth; wEthAddr = this.ufoConfig.WETHOnEth; } else if (netType == 'polygon') { ufoAddr = this.ufoConfig.ufoTokenOnMatic; ufoLpAddr = this.ufoConfig.ufoLPTokenOnMatic; plasmaAddr = this.ufoConfig.plasmaTokenOnMatic; uapAddr = this.ufoConfig.uapOnMatic; wEthAddr = this.ufoConfig.WETHOnMatic; } let contractsCall = [ { reference: 'ufo', contractAddress: ufoAddr, abi: abis_1.BALANCE_ABI, calls: [ { reference: 'balance', methodName: 'balanceOf', methodParameters: [userAddr], }, ], }, { reference: 'ufo_lp', contractAddress: ufoLpAddr, abi: abis_1.BALANCE_ABI, calls: [ { reference: 'balance', methodName: 'balanceOf', methodParameters: [userAddr], }, ], }, ]; if (plasmaAddr != undefined) { contractsCall.push({ reference: 'plasma', contractAddress: plasmaAddr, abi: abis_1.BALANCE_ABI, calls: [ { reference: 'balance', methodName: 'balanceOf', methodParameters: [userAddr], }, ], }); } if (uapAddr != undefined) { contractsCall.push({ reference: 'uap', contractAddress: uapAddr, abi: abis_1.BALANCE_ABI, calls: [ { reference: 'balance', methodName: 'balanceOf', methodParameters: [userAddr], }, ], }); } if (wEthAddr != undefined) { contractsCall.push({ reference: 'wEth', contractAddress: wEthAddr, abi: abis_1.BALANCE_ABI, calls: [ { reference: 'balance', methodName: 'balanceOf', methodParameters: [userAddr], }, ], }); } return contractsCall; } getInfoOfEth(address) { return __awaiter(this, void 0, void 0, function* () { return yield this.getBalanceInfo(address, 'eth'); }); } getInfoOfMatic(address) { return __awaiter(this, void 0, void 0, function* () { return yield this.getBalanceInfo(address, 'polygon'); }); } getBalanceInfo(address, blockchainType) { return __awaiter(this, void 0, void 0, function* () { let provider = blockchainType == 'eth' ? this.ethProvider : this.beamProvider; const multicall = new ethereum_multicall_1.Multicall({ ethersProvider: provider, tryAggregate: true, }); const multiParam = this.getMultiCallParams(blockchainType, address); let res = yield multicall.call(multiParam); let ufoBalance, ufoLpBalance, plasma, uap, wEth; try { ufoBalance = new bignumber_js_1.BigNumber(res.results.ufo.callsReturnContext[0].returnValues[0].hex.toString()).div(new bignumber_js_1.BigNumber('10').pow(18)); ufoLpBalance = new bignumber_js_1.BigNumber(res.results.ufo_lp.callsReturnContext[0].returnValues[0].hex.toString()).div(new bignumber_js_1.BigNumber('10').pow(18)); plasma = res.results.plasma != undefined ? new bignumber_js_1.BigNumber(res.results.plasma.callsReturnContext[0].returnValues[0].hex.toString()).div(new bignumber_js_1.BigNumber('10').pow(18)) : 0; uap = res.results.uap != undefined ? new bignumber_js_1.BigNumber(res.results.uap.callsReturnContext[0].returnValues[0].hex.toString()).div(new bignumber_js_1.BigNumber('10').pow(18)) : 0; wEth = res.results.wEth != undefined ? new bignumber_js_1.BigNumber(res.results.wEth.callsReturnContext[0].returnValues[0].hex.toString()).div(new bignumber_js_1.BigNumber('10').pow(18)) : 0; } catch (e) { console.log(e); } let balance = yield provider.getBalance(address); let actual = ethers_1.ethers.utils.formatEther(balance.toString()); return { ufo: ufoBalance.toString(), ufoLP: ufoLpBalance.toString(), plasma: plasma.toString(), uap: uap.toString(), nativeCrypto: actual.toString(), wEth: wEth.toString(), }; }); } getNFTContractInfo(nftAddr_1) { return __awaiter(this, arguments, void 0, function* (nftAddr, nftType = 'polygon') { let nftContract = null; if (nftType == 'polygon') { nftContract = new ethers_1.ethers.Contract(nftAddr, abis_1.TOTAL_SUPPLY_ABI, this.beamProvider); } else { nftContract = new ethers_1.ethers.Contract(nftAddr, abis_1.TOTAL_SUPPLY_ABI, this.ethProvider); } let totalSupply = 0; try { totalSupply = yield nftContract.totalSupply(); } catch (e) { if (e.reason == null) { console.log('Error : network or smart contract address is not correct'); } else { console.log(e); } } return { totalSupply, }; }); } getWeaponPrice(tokenType, factoryAddr) { return __awaiter(this, void 0, void 0, function* () { let price = ethers_1.BigNumber.from('0'); let factory = null; factory = new ethers_1.ethers.Contract(factoryAddr, SuperGalaticFactory_json_1.default, this.beamProvider); if (tokenType == 0) { price = yield factory.weaponPrice(); } else if (tokenType == 1) { price = yield factory.weaponUfoPrice(); } else if (tokenType == 2) { price = yield factory.getWeaponUsdtPrice(); } return price; }); } getGenesisNftBeamPrice(factoryAddr) { return __awaiter(this, void 0, void 0, function* () { let factory = new ethers_1.ethers.Contract(factoryAddr, SuperGalaticFactory_json_1.default, this.beamProvider); let beamPriceInUSDT = yield factory.beamAmountPerNft(); return ethers_1.ethers.utils.formatEther(beamPriceInUSDT.toString()); }); } /** * already minted nft count for checking price in 3000 and 7000 * @param factoryAddr : supergalatic factory address * @returns */ getAlreadyMintedNftCount(factoryAddr) { return __awaiter(this, void 0, void 0, function* () { let factory = new ethers_1.ethers.Contract(factoryAddr, SuperGalaticFactory_json_1.default, this.beamProvider); let mintCount = yield factory.alreadyMintedGenesisNFT(); return mintCount; }); } } exports.ufoInfoSDK = ufoInfoSDK; //# sourceMappingURL=ufoInfoSDK.js.map