@volare.finance/utils.js
Version:
The Blockchain Utils
136 lines • 5.78 kB
JavaScript
"use strict";
/**
* @file erc20.ts
* @author astra <astra@volare.finance>
* @date 2022
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.ERC20 = void 0;
const tslib_1 = require("tslib");
const ethers_1 = require("ethers");
const ERC20_json_1 = require("../artifacts/token/ERC20.json");
const provider_1 = require("../provider");
const type_1 = require("../type");
class ERC20 extends provider_1.Provider {
static ABI() {
return ERC20_json_1.abi;
}
// https://eips.ethereum.org/EIPS/eip-20
static Name(contract) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const erc20 = new ethers_1.Contract(contract, ERC20.ABI(), ERC20.provider);
return erc20.name();
});
}
static Symbol(contract) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const erc20 = new ethers_1.Contract(contract, ERC20.ABI(), ERC20.provider);
return erc20.symbol();
});
}
static Decimals(contract) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const erc20 = new ethers_1.Contract(contract, ERC20.ABI(), ERC20.provider);
return erc20.decimals();
});
}
static TotalSupply(contract) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const erc20 = new ethers_1.Contract(contract, ERC20.ABI(), ERC20.provider);
return new type_1.BigNumber((yield erc20.totalSupply()).toString());
});
}
static BalanceOf(contract, owner) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const erc20 = new ethers_1.Contract(contract, ERC20.ABI(), ERC20.provider);
return new type_1.BigNumber((yield erc20.balanceOf(owner)).toString());
});
}
static Transfer(contract, owner, to, value) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const erc20 = new ethers_1.Contract(contract, ERC20.ABI(), ERC20.provider);
return erc20.connect(owner).transfer(to, value.toString(10));
});
}
static TransferFrom(contract, owner, from, to, value) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const erc20 = new ethers_1.Contract(contract, ERC20.ABI(), ERC20.provider);
return erc20.connect(owner).transferFrom(from, to, value.toString(10));
});
}
static Approve(contract, owner, spender, value) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const erc20 = new ethers_1.Contract(contract, ERC20.ABI(), ERC20.provider);
return erc20.connect(owner).approve(spender, value.toString(10));
});
}
static Allowance(contract, owner, spender) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const erc20 = new ethers_1.Contract(contract, ERC20.ABI(), ERC20.provider);
return new type_1.BigNumber((yield erc20.allowance(owner, spender)).toString());
});
}
constructor(contract, endpoint) {
super(endpoint);
this.contract = new ethers_1.Contract(contract, ERC20.ABI(), this.provider);
}
// https://eips.ethereum.org/EIPS/eip-20
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();
});
}
decimals() {
var _a;
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return (_a = this.contract) === null || _a === void 0 ? void 0 : _a.decimals();
});
}
totalSupply() {
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.totalSupply())).toString());
});
}
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());
});
}
transfer(owner, to, value) {
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).transfer(to, value.toString(10));
});
}
transferFrom(owner, from, to, value) {
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, value.toString(10));
});
}
approve(owner, spender, value) {
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(spender, value.toString(10));
});
}
allowance(owner, spender) {
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.allowance(owner, spender))).toString());
});
}
}
exports.ERC20 = ERC20;
ERC20.Transfer_t0 = ethers_1.utils.id('Transfer(address,address,uint256)');
ERC20.Approval_t0 = ethers_1.utils.id('Approval(address,address,uint256)');
//# sourceMappingURL=erc20.js.map