ufomarketplace-sdk-new
Version:
SDK to interact with set ufo marketplace contracts
137 lines • 7.39 kB
JavaScript
"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.ufoProviderSDK = 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 uapABI_json_1 = __importDefault(require("./abis/uapABI.json"));
const ERC20_json_1 = __importDefault(require("./abis/ERC20.json"));
const ufoAbi = JSON.stringify(ufoABI_json_1.default);
const ufoLPAbi = JSON.stringify(ufoLPABI_json_1.default);
const plasmaAbi = JSON.stringify(ufoLPABI_json_2.default);
const uapAbi = JSON.stringify(uapABI_json_1.default);
const usdtAbi = JSON.stringify(ERC20_json_1.default.abi);
class ufoProviderSDK {
constructor(provider, ufoConfig, netID) {
this.ufo = null;
this.ufoLP = null;
this.plasma = null;
this.uap = null;
this.weth = null;
this.usdt = null;
this.provider = null;
this.provider = provider;
switch (netID) {
case constants_1.NETWORK_ID.ETHEREUM:
case constants_1.NETWORK_ID.SEPOLIA:
default:
this.ufo = new ethers_1.ethers.Contract(ufoConfig.ufoTokenOnEth, ufoAbi, provider);
this.ufoLP = new ethers_1.ethers.Contract(ufoConfig.ufoLPTokenOnEth, ufoLPAbi, provider);
this.weth = new ethers_1.ethers.Contract(ufoConfig.WETHOnEth, uapAbi, this.provider);
if (ufoConfig.plasmaTokenOnEth != undefined) {
this.plasma = new ethers_1.ethers.Contract(ufoConfig.plasmaTokenOnEth, plasmaAbi, provider);
}
break;
case constants_1.NETWORK_ID.BEAM_TESTNET:
case constants_1.NETWORK_ID.BEAM:
this.ufo = new ethers_1.ethers.Contract(ufoConfig.ufoTokenOnBeamTestNet, ufoAbi, provider);
this.ufoLP = new ethers_1.ethers.Contract(ufoConfig.ufoLPTokenOnBeamTestNet, ufoLPAbi, provider);
this.plasma = new ethers_1.ethers.Contract(ufoConfig.plasmaTokenOnBeamTestNet, plasmaAbi, provider);
this.uap = new ethers_1.ethers.Contract(ufoConfig.uapOnBeamTestNet, uapAbi, this.provider);
this.weth = new ethers_1.ethers.Contract(ufoConfig.WETHOnBeamTestNet, uapAbi, this.provider);
this.usdt = new ethers_1.ethers.Contract(ufoConfig.usdtTokenOnBeamTestNet, usdtAbi, this.provider);
break;
}
}
getUFOTotalSupply() {
return __awaiter(this, void 0, void 0, function* () {
let totalSupply = yield this.ufo.functions.totalSupply();
let decimals = yield this.ufo.functions.decimals();
let count = ethers_1.BigNumber.from(totalSupply.toString()).div(ethers_1.BigNumber.from('10').pow(decimals));
return count.toString();
});
}
getUFOLPTotalSupply() {
return __awaiter(this, void 0, void 0, function* () {
let totalSupply = yield this.ufoLP.functions.totalSupply();
let decimals = yield this.ufoLP.functions.decimals();
let count = ethers_1.BigNumber.from(totalSupply.toString()).div(ethers_1.BigNumber.from('10').pow(decimals));
return count.toString();
});
}
getUFOCount(address) {
return __awaiter(this, void 0, void 0, function* () {
let balance = yield this.ufo.functions.balanceOf(address);
let decimals = yield this.ufo.functions.decimals();
let count = ethers_1.BigNumber.from(balance.toString()).div(ethers_1.BigNumber.from('10').pow(decimals));
return count.toString();
});
}
getUAPBalance(address) {
return __awaiter(this, void 0, void 0, function* () {
let balance = yield this.uap.functions.balanceOf(address);
let decimals = yield this.uap.functions.decimals();
let count = ethers_1.BigNumber.from(balance.toString()).div(ethers_1.BigNumber.from('10').pow(decimals));
return count.toString();
});
}
getUFOLPCount(address) {
return __awaiter(this, void 0, void 0, function* () {
let balance = yield this.ufoLP.functions.balanceOf(address);
let decimals = yield this.ufoLP.functions.decimals();
let count = ethers_1.BigNumber.from(balance.toString()).div(ethers_1.BigNumber.from('10').pow(decimals));
return count.toString();
});
}
getPlasmaCount(address) {
return __awaiter(this, void 0, void 0, function* () {
if (this.plasma == null) {
return '0';
}
let balance = yield this.plasma.functions.balanceOf(address);
let decimals = yield this.plasma.functions.decimals();
let count = ethers_1.BigNumber.from(balance.toString()).div(ethers_1.BigNumber.from('10').pow(decimals));
return count.toString();
});
}
getNativeTokenBalance(address) {
return __awaiter(this, void 0, void 0, function* () {
let balance = yield this.provider.getBalance(address);
let actual = ethers_1.ethers.utils.formatEther(balance.toString());
return actual.toString();
});
}
getInfoOfMaticByPromise(address) {
return __awaiter(this, void 0, void 0, function* () {
let contractCalls = [this.ufo, this.ufoLP, this.plasma, this.uap, this.weth, this.usdt];
const res = yield Promise.all(contractCalls.map((item) => item.functions.balanceOf(address)));
const nativeBalance = yield this.provider.getBalance(address);
const usdtDecimal = yield this.usdt.functions.decimals();
return {
ufo: ethers_1.ethers.utils.formatEther(res[0][0].toString()),
ufoLP: ethers_1.ethers.utils.formatEther(res[1][0].toString()),
plasma: ethers_1.ethers.utils.formatEther(res[2][0].toString()),
uap: ethers_1.ethers.utils.formatEther(res[3][0].toString()),
nativeCrypto: ethers_1.ethers.utils.formatEther(nativeBalance.toString()),
wEth: ethers_1.ethers.utils.formatEther(res[4][0].toString()),
usdt: ethers_1.ethers.utils.formatUnits(res[5][0].toString(), usdtDecimal),
};
});
}
}
exports.ufoProviderSDK = ufoProviderSDK;
//# sourceMappingURL=ufoProviderSDK.js.map