locklift
Version:
Node JS framework for working with Ever contracts. Inspired by Truffle and Hardhat. Helps you to build, test, run and maintain your smart contracts.
109 lines (108 loc) • 4.83 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AccountFactory2 = void 0;
const types_1 = require("../../types");
const everscale_standalone_client_1 = require("everscale-standalone-client");
/*
AccountFactory2 is service based on everscale-standalone-client SimpleAccountsStorage
*/
class AccountFactory2 {
sourceFactory;
sender;
accountsStorage;
constructor(sourceFactory, sender, accountsStorage) {
this.sourceFactory = sourceFactory;
this.sender = sender;
this.accountsStorage = accountsStorage;
}
/*
* Deploy and add the account to the account storage
*/
addNewAccount = async (params) => {
const { account, tx } = await this.createAccount(params);
this.accountsStorage.addAccount(account);
return { account, tx };
};
createAccount = async (params) => {
switch (params.type) {
case types_1.WalletTypes.WalletV3: {
const account = await everscale_standalone_client_1.WalletV3Account.fromPubkey({ publicKey: params.publicKey });
const depositTransaction = await this.sender(account.address, params.value);
return {
account,
tx: depositTransaction,
};
}
case types_1.WalletTypes.HighLoadWalletV2: {
const account = await everscale_standalone_client_1.HighloadWalletV2.fromPubkey({ publicKey: params.publicKey });
const depositTransaction = await this.sender(account.address, params.value);
return {
account,
tx: depositTransaction,
};
}
case types_1.WalletTypes.MsigAccount: {
const contractWithTx = await this.sourceFactory.deployContract(params);
const account = new everscale_standalone_client_1.MsigAccount({
publicKey: params.publicKey,
address: contractWithTx.contract.address,
type: params.mSigType,
});
return { tx: contractWithTx.tx, account };
}
case types_1.WalletTypes.EverWallet: {
const account = await everscale_standalone_client_1.EverWalletAccount.fromPubkey({ publicKey: params.publicKey, nonce: params.nonce });
const depositTransaction = await this.sender(account.address, params.value);
return {
account,
tx: depositTransaction,
};
}
case types_1.WalletTypes.WalletV5R1: {
const account = await everscale_standalone_client_1.WalletV5R1Account.fromPubkey({ publicKey: params.publicKey, nonce: params.nonce });
const depositTransaction = await this.sender(account.address, params.value);
return {
account,
tx: depositTransaction,
};
}
}
};
/*
* Add an existing account to the account storage
*/
addExistingAccount = async (params) => {
const account = await this.getExistingAccount(params);
this.accountsStorage.addAccount(account);
return account;
};
getExistingAccount = async (params) => {
switch (params.type) {
case types_1.WalletTypes.HighLoadWalletV2:
return everscale_standalone_client_1.HighloadWalletV2.fromPubkey({ publicKey: params.publicKey });
case types_1.WalletTypes.WalletV3:
return everscale_standalone_client_1.WalletV3Account.fromPubkey({ publicKey: params.publicKey });
case types_1.WalletTypes.MsigAccount:
return new everscale_standalone_client_1.MsigAccount({ publicKey: params.publicKey, address: params.address, type: params.mSigType });
case types_1.WalletTypes.EverWallet: {
if ("publicKey" in params) {
return everscale_standalone_client_1.EverWalletAccount.fromPubkey({ publicKey: params.publicKey, nonce: params.nonce });
}
return new everscale_standalone_client_1.EverWalletAccount(params.address);
}
case types_1.WalletTypes.WalletV5R1: {
if ("publicKey" in params) {
return everscale_standalone_client_1.WalletV5R1Account.fromPubkey({ publicKey: params.publicKey, nonce: params.nonce });
}
return new everscale_standalone_client_1.WalletV5R1Account(params.address);
}
}
};
/*
Access to the account storage
*/
get storage() {
return this.accountsStorage;
}
}
exports.AccountFactory2 = AccountFactory2;