ufomarketplace-sdk
Version:
SDK to interact with set ufo marketplace contracts
101 lines • 5.22 kB
JavaScript
;
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 ufoAbi = JSON.stringify(ufoABI_json_1.default);
const ufoLPAbi = JSON.stringify(ufoLPABI_json_1.default);
const plasmaAbi = JSON.stringify(ufoLPABI_json_2.default);
class ufoProviderSDK {
constructor(provider, ufoConfig, netID) {
this.ufo = null;
this.ufoLP = null;
this.plasma = null;
this.provider = null;
this.provider = provider;
switch (netID) {
case constants_1.NETWORK_ID.ETHEREUM:
case constants_1.NETWORK_ID.GOERLI:
default:
this.ufo = new ethers_1.ethers.Contract(ufoConfig.ufoTokenOnEth, ufoAbi, provider);
this.ufoLP = new ethers_1.ethers.Contract(ufoConfig.ufoLPTokenOnEth, ufoLPAbi, provider);
if (ufoConfig.plasmaTokenOnEth != undefined) {
this.plasma = new ethers_1.ethers.Contract(ufoConfig.plasmaTokenOnEth, plasmaAbi, provider);
}
break;
case constants_1.NETWORK_ID.POLYGON:
case constants_1.NETWORK_ID.MUMBAI:
this.ufo = new ethers_1.ethers.Contract(ufoConfig.ufoTokenOnMatic, ufoAbi, provider);
this.ufoLP = new ethers_1.ethers.Contract(ufoConfig.ufoLPTokenOnMatic, ufoLPAbi, provider);
this.plasma = new ethers_1.ethers.Contract(ufoConfig.plasmaTokenOnMatic, plasmaAbi, 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();
});
}
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();
});
}
}
exports.ufoProviderSDK = ufoProviderSDK;
//# sourceMappingURL=ufoProviderSDK.js.map