@actalink/commonlib 0.0.42 → 0.1.0
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 +75 -13
- package/dist/index.d.cts +1806 -4998
- package/dist/index.d.ts +1806 -4998
- package/dist/index.js +84 -22
- package/package.json +3 -2
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
|
-
|
|
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,12 +810,51 @@ 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();
|
|
814
855
|
const entryPoint = (0, import_constants.getEntryPoint)("0.7");
|
|
815
856
|
const paymasterClient = (0, import_account_abstraction.createPaymasterClient)({
|
|
816
|
-
transport: (0, import_viem3.http)(
|
|
857
|
+
transport: (0, import_viem3.http)(`https://api.acta.link/paymaster/v1/rpc`)
|
|
817
858
|
});
|
|
818
859
|
const pimlicoClient = (0, import_pimlico.createPimlicoClient)({
|
|
819
860
|
chain: getChainById(this.chainId),
|
|
@@ -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.");
|
|
@@ -936,17 +975,42 @@ var ActaAccount = class {
|
|
|
936
975
|
}
|
|
937
976
|
]
|
|
938
977
|
});
|
|
939
|
-
const
|
|
940
|
-
|
|
941
|
-
|
|
978
|
+
const data = {
|
|
979
|
+
jsonrpc: "2.0",
|
|
980
|
+
id: 1,
|
|
981
|
+
method: "pm_getTokenQuotes",
|
|
982
|
+
params: [
|
|
983
|
+
{
|
|
984
|
+
tokens: [token2.address]
|
|
985
|
+
},
|
|
986
|
+
import_account_abstraction.entryPoint07Address,
|
|
987
|
+
(0, import_viem3.toHex)(chainId)
|
|
988
|
+
]
|
|
989
|
+
};
|
|
990
|
+
const res = yield fetch("https://api.acta.link/paymaster/v1/rpc", {
|
|
991
|
+
method: "POST",
|
|
992
|
+
headers: {
|
|
993
|
+
"Content-Type": "application/json"
|
|
994
|
+
},
|
|
995
|
+
body: JSON.stringify(data)
|
|
996
|
+
}).then((response) => {
|
|
997
|
+
if (!response.ok) {
|
|
998
|
+
throw new Error("HTTP error " + response.status);
|
|
999
|
+
}
|
|
1000
|
+
return response.json();
|
|
942
1001
|
});
|
|
943
1002
|
const userOperationMaxCost = (0, import_permissionless.getRequiredPrefund)({
|
|
944
1003
|
userOperation,
|
|
945
1004
|
entryPointVersion: "0.7"
|
|
946
1005
|
});
|
|
947
|
-
const
|
|
948
|
-
|
|
949
|
-
|
|
1006
|
+
const quotes = res.result;
|
|
1007
|
+
if (!quotes.paymaster) {
|
|
1008
|
+
throw new Error("Error fetching quotes");
|
|
1009
|
+
}
|
|
1010
|
+
const postOpGas = (0, import_viem3.hexToBigInt)(quotes.postOpGas);
|
|
1011
|
+
const exchangeRate = (0, import_viem3.hexToBigInt)(quotes.exchangeRate);
|
|
1012
|
+
const exchangeRateNativeToUsd = (0, import_viem3.hexToBigInt)(quotes.exchangeRateNativeToUsd);
|
|
1013
|
+
const paymaster = quotes.paymaster;
|
|
950
1014
|
const maxCostInWei = userOperationMaxCost + postOpGas * userOperation.maxFeePerGas;
|
|
951
1015
|
const costInToken = maxCostInWei * exchangeRate / BigInt(1e18);
|
|
952
1016
|
const costInUsd = maxCostInWei * exchangeRateNativeToUsd / BigInt(1e18);
|
|
@@ -960,7 +1024,7 @@ var ActaAccount = class {
|
|
|
960
1024
|
estimatedTotalFeesInToken,
|
|
961
1025
|
feeInclusiveAmountInToken,
|
|
962
1026
|
feeExclusiveAmountInToken,
|
|
963
|
-
paymaster
|
|
1027
|
+
paymaster,
|
|
964
1028
|
userOperation
|
|
965
1029
|
};
|
|
966
1030
|
});
|
|
@@ -983,10 +1047,8 @@ var ActaAccount = class {
|
|
|
983
1047
|
if (receivers.length === 0) {
|
|
984
1048
|
throw new Error("Receivers not found for batch payment");
|
|
985
1049
|
}
|
|
986
|
-
const account = yield this.createAccount();
|
|
987
1050
|
const { accountClient, pimlicoClient } = yield this.createAccountHelperBatch();
|
|
988
1051
|
const fromAddress = signerAddress;
|
|
989
|
-
const smartAccountAddress = account.address;
|
|
990
1052
|
const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
|
|
991
1053
|
if (!token2) {
|
|
992
1054
|
throw new Error("Token not found.");
|