@kanalabs/mirai
Version:
Mirai - Account Abstraction SDK (EVM + non-EVM)
90 lines (89 loc) • 4.07 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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ERC20Helper = void 0;
const ethers_1 = require("ethers");
const erc20_ABI_1 = require("./erc20-ABI");
class ERC20Helper {
constructor(sdk, tokenAddress, walletProvider) {
this.sdk = sdk;
this.tokenAddress = tokenAddress;
this.walletProvider = walletProvider;
this.token = new ethers_1.Contract(this.tokenAddress, erc20_ABI_1.ERC20_ABI, this.walletProvider);
}
name() {
return __awaiter(this, void 0, void 0, function* () {
const name = yield this.token.functions.name();
return name[0];
});
}
symbol() {
return __awaiter(this, void 0, void 0, function* () {
const symbol = yield this.token.functions.symbol();
return symbol[0];
});
}
decimals() {
return __awaiter(this, void 0, void 0, function* () {
const decimal = yield this.token.functions.decimals();
return decimal[0];
});
}
totalSupply() {
return __awaiter(this, void 0, void 0, function* () {
const supply = yield this.token.functions.totalSupply();
return supply[0];
});
}
balanceOf(address) {
return __awaiter(this, void 0, void 0, function* () {
const bal = yield this.token.functions.balanceOf(address);
return bal[0];
});
}
allowance(owner, spender) {
return __awaiter(this, void 0, void 0, function* () {
const allowance = yield this.token.functions.allowance(owner, spender);
return allowance[0];
});
}
approve(spender, amount) {
return __awaiter(this, void 0, void 0, function* () {
const transactionData = this.token.interface.encodeFunctionData('approve', [spender, amount]);
yield this.sdk.addUserOpsToBatch({ to: this.tokenAddress, data: transactionData });
});
}
decreaseAllowance(spender, subtractedValue) {
return __awaiter(this, void 0, void 0, function* () {
const transactionData = this.token.interface.encodeFunctionData('decreaseAllowance', [spender, subtractedValue]);
yield this.sdk.addUserOpsToBatch({ to: this.tokenAddress, data: transactionData });
});
}
increaseAllowance(spender, addedValue) {
return __awaiter(this, void 0, void 0, function* () {
const transactionData = this.token.interface.encodeFunctionData('increaseAllowance', [spender, addedValue]);
yield this.sdk.addUserOpsToBatch({ to: this.tokenAddress, data: transactionData });
});
}
transfer(recipient, amount) {
return __awaiter(this, void 0, void 0, function* () {
const transactionData = this.token.interface.encodeFunctionData('transfer', [recipient, amount]);
yield this.sdk.addUserOpsToBatch({ to: this.tokenAddress, data: transactionData });
});
}
transferFrom(sender, recipient, amount) {
return __awaiter(this, void 0, void 0, function* () {
const transactionData = this.token.interface.encodeFunctionData('transferFrom', [sender, recipient, amount]);
yield this.sdk.addUserOpsToBatch({ to: this.tokenAddress, data: transactionData });
});
}
}
exports.ERC20Helper = ERC20Helper;