@actalink/commonlib 0.0.42 → 0.1.0-dev

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -680,6 +680,7 @@ var import_account_abstraction = require("viem/account-abstraction");
680
680
  var import_sdk = require("@zerodev/sdk");
681
681
  var import_constants = require("@zerodev/sdk/constants");
682
682
  var import_ecdsa_validator = require("@zerodev/ecdsa-validator");
683
+ var import_smart_account_validator = require("@zerodev/smart-account-validator");
683
684
  var import_permissionless = require("permissionless");
684
685
  var import_pimlico = require("permissionless/clients/pimlico");
685
686
 
@@ -789,8 +790,9 @@ var ActaAccount = class {
789
790
  this.signer = signer;
790
791
  this.publicClient = publicClient;
791
792
  }
792
- createAccount() {
793
+ createAccountFromEOA() {
793
794
  return __async(this, null, function* () {
795
+ console.log("EOA connected");
794
796
  const kernelVersion = import_constants.KERNEL_V3_1;
795
797
  const entryPoint = (0, import_constants.getEntryPoint)("0.7");
796
798
  const ecdsaValidator = yield (0, import_ecdsa_validator.signerToEcdsaValidator)(this.publicClient, {
@@ -808,6 +810,45 @@ var ActaAccount = class {
808
810
  return account;
809
811
  });
810
812
  }
813
+ createAccountFromSmartWallet() {
814
+ return __async(this, null, function* () {
815
+ console.log("Smart account Connected");
816
+ const kernelVersion = import_constants.KERNEL_V3_1;
817
+ const entryPoint = (0, import_constants.getEntryPoint)("0.7");
818
+ const validator = yield (0, import_smart_account_validator.signerToSmartAccountValidator)(this.publicClient, {
819
+ entryPoint: (0, import_constants.getEntryPoint)("0.7"),
820
+ kernelVersion,
821
+ signer: this.signer,
822
+ smartAccountType: "SAFE"
823
+ });
824
+ const account = yield (0, import_sdk.createKernelAccount)(this.publicClient, {
825
+ plugins: {
826
+ sudo: validator
827
+ },
828
+ entryPoint,
829
+ kernelVersion
830
+ });
831
+ return account;
832
+ });
833
+ }
834
+ createAccount() {
835
+ return __async(this, null, function* () {
836
+ const signerAccount = this.signer.account;
837
+ if (!signerAccount) {
838
+ throw new Error("Signer account not provided");
839
+ }
840
+ const code = yield this.publicClient.getCode({
841
+ address: signerAccount.address
842
+ });
843
+ let account;
844
+ if (code && code.length > 0) {
845
+ account = yield this.createAccountFromSmartWallet();
846
+ } else {
847
+ account = yield this.createAccountFromEOA();
848
+ }
849
+ return account;
850
+ });
851
+ }
811
852
  createAccountHelpers() {
812
853
  return __async(this, null, function* () {
813
854
  const account = yield this.createAccount();
@@ -908,10 +949,8 @@ var ActaAccount = class {
908
949
  if (receiver === signerAddress) {
909
950
  throw new Error("Receiver cannot be the same as the signer.");
910
951
  }
911
- const account = yield this.createAccount();
912
952
  const { accountClient, pimlicoClient } = yield this.createAccountHelpers();
913
953
  const fromAddress = signerAddress;
914
- const smartAccountAddress = account.address;
915
954
  const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
916
955
  if (!token2) {
917
956
  throw new Error("Token not found.");
@@ -983,10 +1022,8 @@ var ActaAccount = class {
983
1022
  if (receivers.length === 0) {
984
1023
  throw new Error("Receivers not found for batch payment");
985
1024
  }
986
- const account = yield this.createAccount();
987
1025
  const { accountClient, pimlicoClient } = yield this.createAccountHelperBatch();
988
1026
  const fromAddress = signerAddress;
989
- const smartAccountAddress = account.address;
990
1027
  const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
991
1028
  if (!token2) {
992
1029
  throw new Error("Token not found.");