@dgpub/prime-sdk
Version:
Etherspot Prime (Account Abstraction) SDK
53 lines (52 loc) • 2.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BiconomyV1WalletAPI = void 0;
const ethers_1 = require("ethers");
const utils_1 = require("ethers/lib/utils");
const BaseAccountAPI_1 = require("./BaseAccountAPI");
const BiconomyV1Abi_1 = require("../contracts/BiconomyV1/BiconomyV1Abi");
const BiconomyV1FactoryAbi_1 = require("../contracts/BiconomyV1/BiconomyV1FactoryAbi");
class BiconomyV1WalletAPI extends BaseAccountAPI_1.BaseAccountAPI {
constructor(params) {
var _a;
super(params);
this.factoryAddress = params.factoryAddress;
this.index = (_a = params.index) !== null && _a !== void 0 ? _a : 0;
}
async _getAccountContract() {
this.accountContract = new ethers_1.ethers.Contract(this.accountAddress, BiconomyV1Abi_1.BiconomyV1Abi, this.provider);
return this.accountContract;
}
async getAccountInitCode() {
this.factory = new ethers_1.ethers.Contract(this.factoryAddress, BiconomyV1FactoryAbi_1.BiconomyV1FactoryAbi, this.provider);
return (0, utils_1.hexConcat)([
this.factoryAddress,
this.factory.interface.encodeFunctionData('deployCounterFactualAccount', [
this.services.walletService.EOAAddress,
this.index,
]),
]);
}
async getNonce(key = 0) {
if (await this.checkAccountPhantom()) {
return ethers_1.BigNumber.from(0);
}
return await this.nonceManager.getNonce(await this.getAccountAddress(), key);
}
async encodeExecute(target, value, data) {
const accountContract = await this._getAccountContract();
return accountContract.interface.encodeFunctionData('executeCall', [target, value, data]);
}
async signUserOpHash(userOpHash) {
const signature = await this.services.walletService.signMessage((0, utils_1.arrayify)(userOpHash));
return signature;
}
get epView() {
return this.entryPointView;
}
async encodeBatch(targets, values, datas) {
const accountContract = await this._getAccountContract();
return accountContract.interface.encodeFunctionData('executeBatchCall', [targets, values, datas]);
}
}
exports.BiconomyV1WalletAPI = BiconomyV1WalletAPI;