@actalink/commonlib 0.0.8 → 0.0.10

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.
Files changed (5) hide show
  1. package/dist/index.cjs +1306 -1138
  2. package/dist/index.d.cts +1888 -3741
  3. package/dist/index.d.ts +1888 -3741
  4. package/dist/index.js +1507 -1325
  5. package/package.json +8 -15
package/dist/index.cjs CHANGED
@@ -84,6 +84,8 @@ __export(index_exports, {
84
84
  bscUSDT: () => bscUSDT,
85
85
  bscWBNB: () => bscWBNB,
86
86
  bytesToBase64: () => bytesToBase64,
87
+ cancelRecurringPaymentAPICall: () => cancelRecurringPaymentAPICall,
88
+ cancelRecurringTransaction: () => cancelRecurringTransaction,
87
89
  createBillingCheckoutSession: () => createBillingCheckoutSession,
88
90
  createBillingSessionAPICall: () => createBillingSessionAPICall,
89
91
  createPolicyFromParams: () => createPolicyFromParams,
@@ -99,6 +101,7 @@ __export(index_exports, {
99
101
  ethereumWETH: () => ethereumWETH,
100
102
  executeSinglePaymentAPICall: () => executeSinglePaymentAPICall,
101
103
  fetchBillingSessionDetails: () => fetchBillingSessionDetails,
104
+ fetchRecurringTransactionWithId: () => fetchRecurringTransactionWithId,
102
105
  getBillingPaymentSessionDetails: () => getBillingPaymentSessionDetails,
103
106
  getChainById: () => getChainById,
104
107
  getChainExplorerByChainId: () => getChainExplorerByChainId,
@@ -128,12 +131,11 @@ __export(index_exports, {
128
131
  polygonWPOL: () => polygonWPOL,
129
132
  scheduleRecurringPaymentsAPICall: () => scheduleRecurringPaymentsAPICall,
130
133
  sendRequest: () => sendRequest,
131
- serializePermissionAccount: () => serializePermissionAccount,
132
134
  serializePermissionAccountParams: () => serializePermissionAccountParams,
133
135
  supportedChains: () => supportedChains,
134
136
  supportedTokensByChain: () => supportedTokensByChain,
135
- toECDSASigner: () => toECDSASigner,
136
- toPermissionValidator: () => toPermissionValidator,
137
+ toECDSASigner: () => toECDSASigner2,
138
+ toPermissionValidator: () => toPermissionValidator2,
137
139
  toPolicyId: () => toPolicyId,
138
140
  toSignerId: () => toSignerId,
139
141
  token: () => token,
@@ -613,12 +615,13 @@ function getTokenByChainIdAndAddress(chainId, address) {
613
615
  }
614
616
 
615
617
  // src/deposit.ts
616
- var import_viem6 = require("viem");
618
+ var import_viem5 = require("viem");
617
619
 
618
620
  // src/account.ts
619
- var import_viem5 = require("viem");
620
- var import_account_abstraction2 = require("viem/account-abstraction");
621
- var import_sdk2 = require("@zerodev/sdk");
621
+ var import_viem3 = require("viem");
622
+ var import_utils = require("viem/utils");
623
+ var import_account_abstraction = require("viem/account-abstraction");
624
+ var import_sdk = require("@zerodev/sdk");
622
625
  var import_constants = require("@zerodev/sdk/constants");
623
626
  var import_ecdsa_validator = require("@zerodev/ecdsa-validator");
624
627
  var import_permissionless = require("permissionless");
@@ -731,798 +734,285 @@ var ViemClient = class {
731
734
  }
732
735
  };
733
736
 
734
- // src/utils.ts
735
- var import_sdk = require("@zerodev/sdk");
736
- var import_accounts = require("@zerodev/sdk/accounts");
737
- var import_viem4 = require("viem");
738
- var import_accounts2 = require("viem/accounts");
739
- var import_actions = require("viem/actions");
740
- var import_utils = require("viem/utils");
741
- var import_account_abstraction = require("viem/account-abstraction");
737
+ // src/account.ts
738
+ var import_signers = require("@zerodev/permissions/signers");
739
+ var import_permissions = require("@zerodev/permissions");
742
740
  var import_policies = require("@zerodev/permissions/policies");
743
- var import_semver = require("semver");
744
-
745
- // src/api.ts
746
- var import_viem3 = require("viem");
747
- var HttpMethod = /* @__PURE__ */ ((HttpMethod2) => {
748
- HttpMethod2["Get"] = "get";
749
- HttpMethod2["Post"] = "post";
750
- HttpMethod2["Delete"] = "delete";
751
- HttpMethod2["Update"] = "update";
752
- return HttpMethod2;
753
- })(HttpMethod || {});
754
- function sendRequest(_0) {
755
- return __async(this, arguments, function* ({
756
- url,
757
- method,
758
- body,
759
- headers = {}
760
- }) {
761
- var _a;
762
- const response = yield fetch(url, {
763
- method,
764
- headers: __spreadProps(__spreadValues({}, headers), {
765
- Accept: "application/json",
766
- "Content-Type": "application/json"
767
- }),
768
- body: JSON.stringify(body)
769
- });
770
- let jsonResponse;
771
- const res = yield response.json();
772
- if (!response.ok) {
773
- jsonResponse = {
774
- error: {
775
- code: response.status,
776
- message: response.statusText
777
- },
778
- data: void 0
779
- };
780
- return jsonResponse;
781
- }
782
- if (!res) {
783
- jsonResponse = {
784
- error: {
785
- code: 400,
786
- message: "No response received."
787
- },
788
- data: void 0
789
- };
790
- return jsonResponse;
791
- }
792
- if (res == null ? void 0 : res.error) {
793
- jsonResponse = {
794
- error: {
795
- code: response.status,
796
- message: res.error
741
+ var ActaAccount = class {
742
+ constructor(chainId, publicClient, signer) {
743
+ this.chainId = chainId;
744
+ this.signer = signer;
745
+ this.publicClient = publicClient;
746
+ }
747
+ createAccount() {
748
+ return __async(this, null, function* () {
749
+ const kernelVersion = import_constants.KERNEL_V3_1;
750
+ const entryPoint = (0, import_constants.getEntryPoint)("0.7");
751
+ const ecdsaValidator = yield (0, import_ecdsa_validator.signerToEcdsaValidator)(this.publicClient, {
752
+ signer: this.signer,
753
+ entryPoint,
754
+ kernelVersion
755
+ });
756
+ const account = yield (0, import_sdk.createKernelAccount)(this.publicClient, {
757
+ plugins: {
758
+ sudo: ecdsaValidator
797
759
  },
798
- data: void 0
799
- };
800
- return jsonResponse;
801
- }
802
- jsonResponse = {
803
- data: res.data,
804
- message: (_a = res.message) != null ? _a : "Success",
805
- error: void 0
806
- };
807
- return jsonResponse;
808
- });
809
- }
810
- function createSessionAPICall(url, sessionBodyParams) {
811
- return __async(this, null, function* () {
812
- const response = yield sendRequest({
813
- url,
814
- method: "post" /* Post */,
815
- body: sessionBodyParams
816
- });
817
- return response.data;
818
- });
819
- }
820
- function verifySessionAPICall(url, sessionId) {
821
- return __async(this, null, function* () {
822
- const response = yield sendRequest({
823
- url,
824
- method: "get" /* Get */
825
- });
826
- return response.data;
827
- });
828
- }
829
- function scheduleRecurringPaymentsAPICall(url, params) {
830
- return __async(this, null, function* () {
831
- const parsedParams = __spreadProps(__spreadValues({}, params), {
832
- amount: (0, import_viem3.toHex)(params.amount)
833
- });
834
- const response = yield sendRequest({
835
- url,
836
- method: "post" /* Post */,
837
- body: parsedParams
838
- });
839
- return response.data;
840
- });
841
- }
842
- function createBillingSessionAPICall(url, sessionBodyParams) {
843
- return __async(this, null, function* () {
844
- const response = yield sendRequest({
845
- url,
846
- method: "post" /* Post */,
847
- body: sessionBodyParams
848
- });
849
- return response.data;
850
- });
851
- }
852
- function fetchBillingSessionDetails(url) {
853
- return __async(this, null, function* () {
854
- const response = yield sendRequest({
855
- url,
856
- method: "get" /* Get */
760
+ entryPoint,
761
+ kernelVersion
762
+ });
763
+ return account;
857
764
  });
858
- return response.data;
859
- });
860
- }
861
- function executeSinglePaymentAPICall(url, userOperation, paymentParams, serviceParams) {
862
- return __async(this, null, function* () {
863
- const params = {
864
- userOperation,
865
- paymentParams,
866
- serviceParams
867
- };
868
- const response = yield sendRequest({
869
- url,
870
- method: "post" /* Post */,
871
- body: params
765
+ }
766
+ createAccountHelpers() {
767
+ return __async(this, null, function* () {
768
+ const account = yield this.createAccount();
769
+ const entryPoint = (0, import_constants.getEntryPoint)("0.7");
770
+ const paymasterClient = (0, import_account_abstraction.createPaymasterClient)({
771
+ transport: (0, import_viem3.http)(getPimlicoRpcByChainId(this.chainId))
772
+ });
773
+ const pimlicoClient = (0, import_pimlico.createPimlicoClient)({
774
+ chain: getChainById(this.chainId),
775
+ transport: (0, import_viem3.http)(getPimlicoRpcByChainId(this.chainId)),
776
+ entryPoint
777
+ });
778
+ const accountClient = (0, import_permissionless.createSmartAccountClient)({
779
+ account,
780
+ chain: getChainById(this.chainId),
781
+ paymaster: paymasterClient,
782
+ bundlerTransport: (0, import_viem3.http)(getPimlicoRpcByChainId(this.chainId)),
783
+ userOperation: {
784
+ estimateFeesPerGas: () => __async(this, null, function* () {
785
+ return (yield pimlicoClient.getUserOperationGasPrice()).fast;
786
+ })
787
+ }
788
+ });
789
+ const kernelAccountClient = (0, import_sdk.createKernelAccountClient)({
790
+ account,
791
+ chain: getChainById(this.chainId),
792
+ paymaster: paymasterClient,
793
+ bundlerTransport: (0, import_viem3.http)(getPimlicoRpcByChainId(this.chainId)),
794
+ userOperation: {
795
+ estimateFeesPerGas: () => __async(this, null, function* () {
796
+ return (yield pimlicoClient.getUserOperationGasPrice()).fast;
797
+ })
798
+ }
799
+ });
800
+ return {
801
+ paymasterClient,
802
+ pimlicoClient,
803
+ accountClient,
804
+ kernelAccountClient
805
+ };
872
806
  });
873
- return response.data;
874
- });
875
- }
876
-
877
- // src/utils.ts
878
- var ECDSA_SIGNER_CONTRACT = "0x6A6F069E2a08c2468e7724Ab3250CdBFBA14D4FF";
879
- var billingServiceUrl = "https://api.acta.link/billing/v1/";
880
- var toSignerId = (signer) => {
881
- return (0, import_viem4.encodeAbiParameters)(
882
- [{ name: "signerData", type: "bytes" }],
883
- [(0, import_viem4.concat)([signer.signerContractAddress, signer.getSignerData()])]
884
- );
885
- };
886
- function toECDSASigner(_0) {
887
- return __async(this, arguments, function* (signer, signerContractAddress = ECDSA_SIGNER_CONTRACT) {
888
- const viemSigner = yield (0, import_sdk.toSigner)({ signer });
889
- const account = (0, import_accounts2.toAccount)({
890
- address: viemSigner.address,
891
- signMessage(_02) {
892
- return __async(this, arguments, function* ({ message }) {
893
- return (0, import_sdk.fixSignedData)(yield viemSigner.signMessage({ message }));
894
- });
895
- },
896
- signTransaction(_, __) {
897
- return __async(this, null, function* () {
898
- throw new Error("Smart account signer doesn't need to sign transactions");
899
- });
900
- },
901
- signTypedData(typedData) {
902
- return __async(this, null, function* () {
903
- return (0, import_sdk.fixSignedData)(
904
- yield viemSigner.signTypedData(__spreadValues({}, typedData))
905
- );
906
- });
807
+ }
808
+ estimateSinglePaymentGas(parameters) {
809
+ return __async(this, null, function* () {
810
+ const {
811
+ signerAddress,
812
+ chainId,
813
+ token: tokenSymbol,
814
+ amount,
815
+ receiver
816
+ } = parameters;
817
+ if (amount <= BigInt(0)) {
818
+ throw new Error("Amount must be greater than 0.");
907
819
  }
908
- });
909
- return {
910
- account,
911
- signerContractAddress,
912
- getSignerData: () => {
913
- return viemSigner.address;
914
- },
915
- getDummySignature: () => import_sdk.constants.DUMMY_ECDSA_SIG
916
- };
917
- });
918
- }
919
- var toPolicyId = (policies) => {
920
- return (0, import_viem4.encodeAbiParameters)(
921
- [{ name: "policiesData", type: "bytes[]" }],
922
- [
923
- policies.map(
924
- (policy) => (0, import_viem4.concat)([policy.getPolicyInfoInBytes(), policy.getPolicyData()])
925
- )
926
- ]
927
- );
928
- };
929
- function toPermissionValidator(_0, _1) {
930
- return __async(this, arguments, function* (client, {
931
- signer,
932
- policies,
933
- entryPoint,
934
- kernelVersion: _,
935
- flag = "0x0000" /* FOR_ALL_VALIDATION */
936
- }) {
937
- const chainId = client.chain ? client.chain.id : yield (0, import_actions.getChainId)(client);
938
- if (entryPoint.version !== "0.7") {
939
- throw new Error("Only EntryPoint 0.7 is supported");
940
- }
941
- const getEnableData = (_kernelAccountAddress) => __async(null, null, function* () {
942
- const enableData = (0, import_viem4.encodeAbiParameters)(
943
- [{ name: "policyAndSignerData", type: "bytes[]" }],
944
- [
945
- [
946
- ...policies.map(
947
- (policy) => (0, import_viem4.concat)([policy.getPolicyInfoInBytes(), policy.getPolicyData()])
948
- ),
949
- (0, import_viem4.concat)([flag, signer.signerContractAddress, signer.getSignerData()])
950
- ]
820
+ if (receiver === signerAddress) {
821
+ throw new Error("Receiver cannot be the same as the signer.");
822
+ }
823
+ const account = yield this.createAccount();
824
+ const { accountClient, pimlicoClient } = yield this.createAccountHelpers();
825
+ const fromAddress = signerAddress;
826
+ const smartAccountAddress = account.address;
827
+ const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
828
+ if (!token2) {
829
+ throw new Error("Token not found.");
830
+ }
831
+ const quotes = yield pimlicoClient.getTokenQuotes({
832
+ tokens: [token2.address],
833
+ chain: getChainById(chainId)
834
+ });
835
+ const { postOpGas, exchangeRate, paymaster } = quotes[0];
836
+ const userOperation = yield accountClient.prepareUserOperation({
837
+ calls: [
838
+ {
839
+ to: (0, import_viem3.getAddress)(token2.address),
840
+ abi: (0, import_viem3.parseAbi)(["function transferFrom(address,address,uint)"]),
841
+ functionName: "transferFrom",
842
+ args: [
843
+ fromAddress,
844
+ "0xC4910E5ec82Da0A41aF9C6360b7A1f531e1e37B0",
845
+ BigInt(0)
846
+ ]
847
+ },
848
+ {
849
+ to: (0, import_viem3.getAddress)(token2.address),
850
+ abi: (0, import_viem3.parseAbi)(["function transferFrom(address,address,uint)"]),
851
+ functionName: "transferFrom",
852
+ args: [fromAddress, receiver, BigInt(0)]
853
+ }
951
854
  ]
855
+ });
856
+ const userOperationMaxGas = userOperation.preVerificationGas + userOperation.callGasLimit + userOperation.verificationGasLimit + (userOperation.paymasterPostOpGasLimit || BigInt(0)) + (userOperation.paymasterVerificationGasLimit || BigInt(0));
857
+ const userOperationMaxCost = BigInt(
858
+ userOperationMaxGas * userOperation.maxFeePerGas
952
859
  );
953
- return enableData;
860
+ const estimatedGasCostInToken = (userOperationMaxCost + postOpGas * userOperation.maxFeePerGas) * exchangeRate / BigInt(1e18);
861
+ const ActalinkFeesInToken = amount * BigInt(20) / BigInt(1e4);
862
+ const estimatedTotalFeesInToken = estimatedGasCostInToken + ActalinkFeesInToken;
863
+ const feeInclusiveAmountInToken = amount - estimatedTotalFeesInToken;
864
+ const feeExclusiveAmountInToken = amount + estimatedTotalFeesInToken;
865
+ return {
866
+ estimatedGasCostInToken,
867
+ ActalinkFeesInToken,
868
+ estimatedTotalFeesInToken,
869
+ feeInclusiveAmountInToken,
870
+ feeExclusiveAmountInToken,
871
+ paymaster,
872
+ userOperation
873
+ };
954
874
  });
955
- const getPermissionId = () => {
956
- const pIdData = (0, import_viem4.encodeAbiParameters)(
957
- [{ name: "policyAndSignerData", type: "bytes[]" }],
958
- [[toPolicyId(policies), flag, toSignerId(signer)]]
959
- );
960
- return (0, import_viem4.slice)((0, import_viem4.keccak256)(pIdData), 0, 4);
961
- };
962
- return __spreadProps(__spreadValues({}, signer.account), {
963
- supportedKernelVersions: ">=0.3.0",
964
- validatorType: "PERMISSION",
965
- address: import_viem4.zeroAddress,
966
- source: "PermissionValidator",
967
- getEnableData,
968
- getIdentifier: getPermissionId,
969
- signMessage: (_02) => __async(null, [_02], function* ({ message }) {
970
- return (0, import_viem4.concat)(["0xff", yield signer.account.signMessage({ message })]);
971
- }),
972
- signTypedData: (typedData) => __async(null, null, function* () {
973
- return (0, import_viem4.concat)(["0xff", yield signer.account.signTypedData(typedData)]);
974
- }),
975
- signUserOperation: (userOperation) => __async(null, null, function* () {
976
- const userOpHash = (0, import_account_abstraction.getUserOperationHash)({
977
- userOperation: __spreadProps(__spreadValues({}, userOperation), {
978
- signature: "0x"
979
- }),
980
- entryPointAddress: entryPoint.address,
981
- entryPointVersion: entryPoint.version,
982
- chainId
983
- });
984
- const signature = yield signer.account.signMessage({
985
- message: { raw: userOpHash }
986
- });
987
- return (0, import_viem4.concat)(["0xff", signature]);
988
- }),
989
- getNonceKey(_accountAddress, customNonceKey) {
990
- return __async(this, null, function* () {
991
- if (customNonceKey) {
992
- return customNonceKey;
993
- }
994
- return BigInt(0);
875
+ }
876
+ signSinglePaymentOperation(singlePaymentParams) {
877
+ return __async(this, null, function* () {
878
+ try {
879
+ if (!this.signer) {
880
+ throw new Error("Signer is required for self custody payments.");
881
+ }
882
+ const {
883
+ signerAddress,
884
+ chainId,
885
+ token: tokenSymbol,
886
+ amount,
887
+ receiver,
888
+ feeInclusive,
889
+ allowMaxTokenApproval
890
+ } = singlePaymentParams;
891
+ if (amount <= BigInt(0)) {
892
+ throw new Error("Amount must be greater than 0.");
893
+ }
894
+ if (receiver === signerAddress) {
895
+ throw new Error("Receiver cannot be the same as the signer.");
896
+ }
897
+ const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
898
+ if (!token2) {
899
+ throw new Error("Token not found.");
900
+ }
901
+ const viemClient = new ViemClient(this.chainId, this.signer);
902
+ const {
903
+ estimatedGasCostInToken,
904
+ ActalinkFeesInToken,
905
+ feeInclusiveAmountInToken,
906
+ feeExclusiveAmountInToken,
907
+ estimatedTotalFeesInToken,
908
+ paymaster
909
+ } = yield this.estimateSinglePaymentGas({
910
+ signerAddress,
911
+ chainId,
912
+ token: tokenSymbol,
913
+ amount,
914
+ receiver,
915
+ feeInclusive
995
916
  });
996
- },
997
- getStubSignature(_userOperation) {
998
- return __async(this, null, function* () {
999
- return (0, import_viem4.concat)(["0xff", signer.getDummySignature()]);
917
+ const account = yield this.createAccount();
918
+ const { accountClient } = yield this.createAccountHelpers();
919
+ const fromAddress = signerAddress;
920
+ const smartAccountAddress = account.address;
921
+ const amountToTransfer = feeInclusive ? amount : feeExclusiveAmountInToken;
922
+ const receiverAmount = feeInclusive ? feeInclusiveAmountInToken : amount;
923
+ yield viemClient.checkAndApproveToken(
924
+ token2,
925
+ smartAccountAddress,
926
+ amountToTransfer,
927
+ allowMaxTokenApproval != null ? allowMaxTokenApproval : false
928
+ );
929
+ const userOperation = yield accountClient.prepareUserOperation({
930
+ calls: [
931
+ {
932
+ to: (0, import_viem3.getAddress)(token2.address),
933
+ abi: (0, import_viem3.parseAbi)(["function transferFrom(address,address,uint)"]),
934
+ functionName: "transferFrom",
935
+ args: [
936
+ fromAddress,
937
+ "0xC4910E5ec82Da0A41aF9C6360b7A1f531e1e37B0",
938
+ estimatedGasCostInToken
939
+ ]
940
+ },
941
+ {
942
+ to: (0, import_viem3.getAddress)(token2.address),
943
+ abi: (0, import_viem3.parseAbi)(["function transferFrom(address,address,uint)"]),
944
+ functionName: "transferFrom",
945
+ args: [fromAddress, receiver, receiverAmount]
946
+ }
947
+ ]
1000
948
  });
1001
- },
1002
- getPluginSerializationParams: () => {
1003
- return {
1004
- policies
1005
- };
1006
- },
1007
- isEnabled: (kernelAccountAddress, _selector) => __async(null, null, function* () {
1008
- try {
1009
- const permissionConfig = yield (0, import_utils.getAction)(
1010
- client,
1011
- import_actions.readContract,
1012
- "readContract"
1013
- )({
1014
- abi: import_sdk.KernelV3AccountAbi,
1015
- address: kernelAccountAddress,
1016
- functionName: "permissionConfig",
1017
- args: [getPermissionId()]
1018
- });
1019
- return permissionConfig.signer === signer.signerContractAddress;
1020
- } catch (error) {
1021
- return false;
949
+ const signature = yield account.signUserOperation(__spreadProps(__spreadValues({}, userOperation), {
950
+ chainId: this.chainId
951
+ }));
952
+ const rpcParameters = (0, import_account_abstraction.formatUserOperationRequest)(__spreadProps(__spreadValues({}, userOperation), {
953
+ signature
954
+ }));
955
+ return rpcParameters;
956
+ } catch (error) {
957
+ if (error instanceof Error) {
958
+ throw new Error(error.message);
1022
959
  }
1023
- })
960
+ throw new Error("Failed to sign single payment operation.");
961
+ }
1024
962
  });
1025
- });
1026
- }
1027
- function bytesToBase64(bytes) {
1028
- const binString = Array.from(bytes, (x) => String.fromCodePoint(x)).join("");
1029
- return btoa(binString);
1030
- }
1031
- function isPermissionValidatorPlugin(plugin) {
1032
- return (plugin == null ? void 0 : plugin.getPluginSerializationParams) !== void 0;
1033
- }
1034
- var serializePermissionAccountParams = (params) => {
1035
- const replacer = (_, value) => {
1036
- if (typeof value === "bigint") {
1037
- return value.toString();
1038
- }
1039
- return value;
1040
- };
1041
- const jsonString = JSON.stringify(params, replacer);
1042
- const uint8Array = new TextEncoder().encode(jsonString);
1043
- const base64String = bytesToBase64(uint8Array);
1044
- return base64String;
1045
- };
1046
- var serializePermissionAccount = (account, privateKey, enableSignature, eip7702Auth) => __async(null, null, function* () {
1047
- if (!isPermissionValidatorPlugin(account.kernelPluginManager))
1048
- throw new Error("Account plugin is not a permission validator");
1049
- const permissionParams = account.kernelPluginManager.getPluginSerializationParams();
1050
- const action = account.kernelPluginManager.getAction();
1051
- const validityData = account.kernelPluginManager.getValidityData();
1052
- const _enableSignature = enableSignature != null ? enableSignature : yield account.kernelPluginManager.getPluginEnableSignature(
1053
- account.address
1054
- );
1055
- const _eip7702Auth = account.authorization ? eip7702Auth != null ? eip7702Auth : yield account == null ? void 0 : account.eip7702Auth : void 0;
1056
- const accountParams = {
1057
- initCode: yield account.generateInitCode(),
1058
- accountAddress: account.address
1059
- };
1060
- const paramsToBeSerialized = {
1061
- permissionParams,
1062
- action,
1063
- validityData,
1064
- accountParams,
1065
- enableSignature: _enableSignature,
1066
- privateKey,
1067
- eip7702Auth: _eip7702Auth
1068
- };
1069
- return serializePermissionAccountParams(paramsToBeSerialized);
1070
- });
1071
- var isKernelVersionAfter = (kernelVersion, version) => {
1072
- const coercedKernelVersion = (0, import_semver.coerce)(kernelVersion);
1073
- if (!coercedKernelVersion) return false;
1074
- return (0, import_semver.gt)(coercedKernelVersion, version);
1075
- };
1076
- function base64ToBytes(base64) {
1077
- const binString = atob(base64);
1078
- return Uint8Array.from(binString, (m) => m.codePointAt(0));
1079
- }
1080
- var deserializePermissionAccountParams = (params) => {
1081
- const uint8Array = base64ToBytes(params);
1082
- const jsonString = new TextDecoder().decode(uint8Array);
1083
- return JSON.parse(jsonString);
1084
- };
1085
- var deserializePermissionAccount = (client, entryPoint, kernelVersion, modularPermissionAccountParams, modularSigner) => __async(null, null, function* () {
1086
- var _a;
1087
- if (entryPoint.version !== "0.7") {
1088
- throw new Error("Only EntryPoint 0.7 is supported");
1089
963
  }
1090
- const params = deserializePermissionAccountParams(
1091
- modularPermissionAccountParams
1092
- );
1093
- let signer;
1094
- if (params.privateKey)
1095
- signer = yield toECDSASigner((0, import_accounts2.privateKeyToAccount)(params.privateKey));
1096
- else if (modularSigner) signer = modularSigner;
1097
- else throw new Error("No signer or serialized sessionKey provided");
1098
- const modularPermissionPlugin = yield toPermissionValidator(client, {
1099
- signer,
1100
- policies: yield Promise.all(
1101
- ((_a = params.permissionParams.policies) == null ? void 0 : _a.map(
1102
- (policy) => createPolicyFromParams(policy)
1103
- )) || []
1104
- ),
1105
- entryPoint,
1106
- kernelVersion
1107
- });
1108
- const { index, validatorInitData, useMetaFactory } = decodeParamsFromInitCode(
1109
- params.accountParams.initCode,
1110
- kernelVersion
1111
- );
1112
- const kernelPluginManager = yield (0, import_accounts.toKernelPluginManager)(client, __spreadValues({
1113
- regular: modularPermissionPlugin,
1114
- pluginEnableSignature: params.enableSignature,
1115
- validatorInitData,
1116
- action: params.action,
1117
- entryPoint,
1118
- kernelVersion
1119
- }, params.validityData));
1120
- return (0, import_sdk.createKernelAccount)(client, {
1121
- entryPoint,
1122
- kernelVersion,
1123
- plugins: kernelPluginManager,
1124
- index,
1125
- address: params.accountParams.accountAddress,
1126
- useMetaFactory,
1127
- eip7702Auth: params.eip7702Auth
1128
- });
1129
- });
1130
- var createPolicyFromParams = (policy) => __async(null, null, function* () {
1131
- switch (policy.policyParams.type) {
1132
- case "call":
1133
- return yield (0, import_policies.toCallPolicy)(policy.policyParams);
1134
- case "gas":
1135
- return yield (0, import_policies.toGasPolicy)(policy.policyParams);
1136
- case "rate-limit":
1137
- return yield (0, import_policies.toRateLimitPolicy)(policy.policyParams);
1138
- case "signature-caller":
1139
- return yield (0, import_policies.toSignatureCallerPolicy)(policy.policyParams);
1140
- case "sudo":
1141
- return yield (0, import_policies.toSudoPolicy)(policy.policyParams);
1142
- case "timestamp":
1143
- return yield (0, import_policies.toTimestampPolicy)(policy.policyParams);
1144
- default:
1145
- throw new Error("Unsupported policy type");
1146
- }
1147
- });
1148
- var decodeParamsFromInitCode = (initCode, kernelVersion) => {
1149
- let index;
1150
- let validatorInitData;
1151
- let deployWithFactoryFunctionData;
1152
- let useMetaFactory = true;
1153
- if (initCode === "0x") {
1154
- return {
1155
- index: void 0,
1156
- validatorInitData: void 0,
1157
- useMetaFactory: true
1158
- };
1159
- }
1160
- try {
1161
- deployWithFactoryFunctionData = (0, import_viem4.decodeFunctionData)({
1162
- abi: import_sdk.KernelFactoryStakerAbi,
1163
- data: initCode
1164
- });
1165
- } catch (error) {
1166
- deployWithFactoryFunctionData = (0, import_viem4.decodeFunctionData)({
1167
- abi: import_sdk.KernelV3FactoryAbi,
1168
- data: initCode
1169
- });
1170
- useMetaFactory = false;
1171
- }
1172
- if (!deployWithFactoryFunctionData) throw new Error("Invalid initCode");
1173
- if (deployWithFactoryFunctionData.functionName === "deployWithFactory") {
1174
- index = BigInt(deployWithFactoryFunctionData.args[2]);
1175
- let initializeFunctionData;
1176
- if (kernelVersion === "0.3.0") {
1177
- initializeFunctionData = (0, import_viem4.decodeFunctionData)({
1178
- abi: import_sdk.KernelV3AccountAbi,
1179
- data: deployWithFactoryFunctionData.args[1]
1180
- });
1181
- } else {
1182
- initializeFunctionData = (0, import_viem4.decodeFunctionData)({
1183
- abi: import_sdk.KernelV3_1AccountAbi,
1184
- data: deployWithFactoryFunctionData.args[1]
1185
- });
1186
- }
1187
- if (!initializeFunctionData) throw new Error("Invalid initCode");
1188
- if (initializeFunctionData.functionName === "initialize") {
1189
- validatorInitData = {
1190
- validatorAddress: initializeFunctionData.args[0],
1191
- identifier: initializeFunctionData.args[0],
1192
- enableData: initializeFunctionData.args[2],
1193
- initConfig: isKernelVersionAfter(kernelVersion, "0.3.1") && Array.isArray(initializeFunctionData.args[4]) ? [...initializeFunctionData.args[4]] : void 0
1194
- };
1195
- }
1196
- } else if (deployWithFactoryFunctionData.functionName === "createAccount") {
1197
- index = BigInt(deployWithFactoryFunctionData.args[1]);
1198
- let initializeFunctionData;
1199
- if (kernelVersion === "0.3.0") {
1200
- initializeFunctionData = (0, import_viem4.decodeFunctionData)({
1201
- abi: import_sdk.KernelV3AccountAbi,
1202
- data: deployWithFactoryFunctionData.args[0]
1203
- });
1204
- } else {
1205
- initializeFunctionData = (0, import_viem4.decodeFunctionData)({
1206
- abi: import_sdk.KernelV3_1AccountAbi,
1207
- data: deployWithFactoryFunctionData.args[0]
1208
- });
1209
- }
1210
- if (!initializeFunctionData) throw new Error("Invalid initCode");
1211
- if (initializeFunctionData.functionName === "initialize") {
1212
- validatorInitData = {
1213
- validatorAddress: initializeFunctionData.args[0],
1214
- identifier: initializeFunctionData.args[0],
1215
- enableData: initializeFunctionData.args[2],
1216
- initConfig: isKernelVersionAfter(kernelVersion, "0.3.1") && Array.isArray(initializeFunctionData.args[4]) ? [...initializeFunctionData.args[4]] : void 0
1217
- };
1218
- }
1219
- }
1220
- if (index === void 0 || validatorInitData === void 0)
1221
- throw new Error("Invalid initCode");
1222
- return { index, validatorInitData, useMetaFactory };
1223
- };
1224
- var getPeriodInterval = (periodUnit) => {
1225
- switch (periodUnit) {
1226
- case "5mins":
1227
- return 5 * 60;
1228
- case "day":
1229
- return 24 * 60 * 60;
1230
- case "week":
1231
- return 7 * 24 * 60 * 60;
1232
- case "month":
1233
- return 28 * 24 * 60 * 60;
1234
- case "year":
1235
- return 365 * 24 * 60 * 60;
1236
- default:
1237
- throw new Error("Invalid period unit");
1238
- }
1239
- };
1240
- var createBillingCheckoutSession = (serviceSessionparams) => __async(null, null, function* () {
1241
- try {
1242
- const sessionData = yield createBillingSessionAPICall(
1243
- `${billingServiceUrl}paysession/create`,
1244
- {
1245
- paylinkId: serviceSessionparams.paylinkId
1246
- }
1247
- );
1248
- if (sessionData) {
1249
- return sessionData.checkoutSessionId;
1250
- }
1251
- } catch (error) {
1252
- if (error instanceof Error) {
1253
- throw new Error(error.message);
1254
- }
1255
- throw new Error("Failed to create deposit session.");
1256
- }
1257
- });
1258
- var getBillingPaymentSessionDetails = (serviceSessionparams) => __async(null, null, function* () {
1259
- if (!serviceSessionparams.checkoutSessionId || serviceSessionparams.checkoutSessionId === "") {
1260
- throw new Error("checkout session ID is required.");
1261
- }
1262
- const sessionData = yield fetchBillingSessionDetails(
1263
- `${billingServiceUrl}paysession?checkoutSessionId=${serviceSessionparams.checkoutSessionId}`
1264
- );
1265
- return sessionData;
1266
- });
1267
-
1268
- // src/account.ts
1269
- var import_policies2 = require("@zerodev/permissions/policies");
1270
- var ActaAccount = class {
1271
- constructor(chainId, publicClient, signer) {
1272
- this.chainId = chainId;
1273
- this.signer = signer;
1274
- this.publicClient = publicClient;
1275
- }
1276
- createAccount() {
1277
- return __async(this, null, function* () {
1278
- const kernelVersion = import_constants.KERNEL_V3_1;
1279
- const entryPoint = (0, import_constants.getEntryPoint)("0.7");
1280
- const ecdsaValidator = yield (0, import_ecdsa_validator.signerToEcdsaValidator)(this.publicClient, {
1281
- signer: this.signer,
1282
- entryPoint,
1283
- kernelVersion
1284
- });
1285
- const account = yield (0, import_sdk2.createKernelAccount)(this.publicClient, {
1286
- plugins: {
1287
- sudo: ecdsaValidator
1288
- },
1289
- entryPoint,
1290
- kernelVersion
1291
- });
1292
- return account;
1293
- });
1294
- }
1295
- createAccountHelpers() {
1296
- return __async(this, null, function* () {
1297
- const account = yield this.createAccount();
1298
- const entryPoint = (0, import_constants.getEntryPoint)("0.7");
1299
- const paymasterClient = (0, import_account_abstraction2.createPaymasterClient)({
1300
- transport: (0, import_viem5.http)(getPimlicoRpcByChainId(this.chainId))
1301
- });
1302
- const pimlicoClient = (0, import_pimlico.createPimlicoClient)({
1303
- chain: getChainById(this.chainId),
1304
- transport: (0, import_viem5.http)(getPimlicoRpcByChainId(this.chainId)),
1305
- entryPoint
1306
- });
1307
- const accountClient = (0, import_permissionless.createSmartAccountClient)({
1308
- account,
1309
- chain: getChainById(this.chainId),
1310
- paymaster: paymasterClient,
1311
- bundlerTransport: (0, import_viem5.http)(getPimlicoRpcByChainId(this.chainId)),
1312
- userOperation: {
1313
- estimateFeesPerGas: () => __async(this, null, function* () {
1314
- return (yield pimlicoClient.getUserOperationGasPrice()).fast;
1315
- })
1316
- }
1317
- });
1318
- return { paymasterClient, pimlicoClient, accountClient };
1319
- });
1320
- }
1321
- estimateSinglePaymentGas(parameters) {
964
+ signRecurringPayments(recurringPaymentParams) {
1322
965
  return __async(this, null, function* () {
966
+ if (!this.signer) {
967
+ throw new Error("Signer is required for self custody payments.");
968
+ }
1323
969
  const {
1324
970
  signerAddress,
1325
971
  chainId,
1326
972
  token: tokenSymbol,
1327
973
  amount,
1328
- receiver
1329
- } = parameters;
974
+ receiver,
975
+ feeInclusive,
976
+ count,
977
+ intervalUnit,
978
+ startDate,
979
+ endDate,
980
+ allowMaxTokenApproval
981
+ } = recurringPaymentParams;
1330
982
  if (amount <= BigInt(0)) {
1331
983
  throw new Error("Amount must be greater than 0.");
1332
984
  }
985
+ if (!signerAddress) {
986
+ throw new Error("Signer Connot be empty");
987
+ }
1333
988
  if (receiver === signerAddress) {
1334
989
  throw new Error("Receiver cannot be the same as the signer.");
1335
990
  }
1336
- const account = yield this.createAccount();
1337
- const { accountClient, pimlicoClient } = yield this.createAccountHelpers();
1338
- const fromAddress = signerAddress;
1339
- const smartAccountAddress = account.address;
991
+ if (!intervalUnit) {
992
+ throw new Error("Interval unit is required.");
993
+ }
1340
994
  const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
1341
995
  if (!token2) {
1342
996
  throw new Error("Token not found.");
1343
997
  }
1344
- const quotes = yield pimlicoClient.getTokenQuotes({
1345
- tokens: [token2.address],
1346
- chain: getChainById(chainId)
1347
- });
1348
- const { postOpGas, exchangeRate, paymaster } = quotes[0];
1349
- const userOperation = yield accountClient.prepareUserOperation({
1350
- calls: [
1351
- {
1352
- to: (0, import_viem5.getAddress)(token2.address),
1353
- abi: (0, import_viem5.parseAbi)(["function transferFrom(address,address,uint)"]),
1354
- functionName: "transferFrom",
1355
- args: [
1356
- fromAddress,
1357
- "0xC4910E5ec82Da0A41aF9C6360b7A1f531e1e37B0",
1358
- BigInt(0)
1359
- ]
1360
- },
1361
- {
1362
- to: (0, import_viem5.getAddress)(token2.address),
1363
- abi: (0, import_viem5.parseAbi)(["function transferFrom(address,address,uint)"]),
1364
- functionName: "transferFrom",
1365
- args: [fromAddress, receiver, BigInt(0)]
1366
- }
1367
- ]
1368
- });
1369
- const userOperationMaxGas = userOperation.preVerificationGas + userOperation.callGasLimit + userOperation.verificationGasLimit + (userOperation.paymasterPostOpGasLimit || BigInt(0)) + (userOperation.paymasterVerificationGasLimit || BigInt(0));
1370
- const userOperationMaxCost = BigInt(
1371
- userOperationMaxGas * userOperation.maxFeePerGas
1372
- );
1373
- const estimatedGasCostInToken = (userOperationMaxCost + postOpGas * userOperation.maxFeePerGas) * exchangeRate / BigInt(1e18);
1374
- const ActalinkFeesInToken = amount * BigInt(20) / BigInt(1e4);
1375
- const estimatedTotalFeesInToken = estimatedGasCostInToken + ActalinkFeesInToken;
1376
- const feeInclusiveAmountInToken = amount - estimatedTotalFeesInToken;
1377
- const feeExclusiveAmountInToken = amount + estimatedTotalFeesInToken;
1378
- return {
1379
- estimatedGasCostInToken,
1380
- ActalinkFeesInToken,
1381
- estimatedTotalFeesInToken,
1382
- feeInclusiveAmountInToken,
1383
- feeExclusiveAmountInToken,
1384
- paymaster,
1385
- userOperation
1386
- };
1387
- });
1388
- }
1389
- signSinglePaymentOperation(singlePaymentParams) {
1390
- return __async(this, null, function* () {
1391
- try {
1392
- if (!this.signer) {
1393
- throw new Error("Signer is required for self custody payments.");
1394
- }
1395
- const {
1396
- signerAddress,
1397
- chainId,
1398
- token: tokenSymbol,
1399
- amount,
1400
- receiver,
1401
- feeInclusive,
1402
- allowMaxTokenApproval
1403
- } = singlePaymentParams;
1404
- if (amount <= BigInt(0)) {
1405
- throw new Error("Amount must be greater than 0.");
1406
- }
1407
- if (receiver === signerAddress) {
1408
- throw new Error("Receiver cannot be the same as the signer.");
1409
- }
1410
- const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
1411
- if (!token2) {
1412
- throw new Error("Token not found.");
1413
- }
1414
- const viemClient = new ViemClient(this.chainId, this.signer);
1415
- const {
1416
- estimatedGasCostInToken,
1417
- ActalinkFeesInToken,
1418
- feeInclusiveAmountInToken,
1419
- feeExclusiveAmountInToken,
1420
- estimatedTotalFeesInToken,
1421
- paymaster
1422
- } = yield this.estimateSinglePaymentGas({
1423
- signerAddress,
1424
- chainId,
1425
- token: tokenSymbol,
1426
- amount,
1427
- receiver,
1428
- feeInclusive
1429
- });
1430
- const account = yield this.createAccount();
1431
- const { accountClient } = yield this.createAccountHelpers();
1432
- const fromAddress = signerAddress;
1433
- const smartAccountAddress = account.address;
1434
- const amountToTransfer = feeInclusive ? amount : feeExclusiveAmountInToken;
1435
- const receiverAmount = feeInclusive ? feeInclusiveAmountInToken : amount;
1436
- yield viemClient.checkAndApproveToken(
1437
- token2,
1438
- smartAccountAddress,
1439
- amountToTransfer,
1440
- allowMaxTokenApproval != null ? allowMaxTokenApproval : false
1441
- );
1442
- const userOperation = yield accountClient.prepareUserOperation({
1443
- calls: [
1444
- {
1445
- to: (0, import_viem5.getAddress)(token2.address),
1446
- abi: (0, import_viem5.parseAbi)(["function transferFrom(address,address,uint)"]),
1447
- functionName: "transferFrom",
1448
- args: [
1449
- fromAddress,
1450
- "0xC4910E5ec82Da0A41aF9C6360b7A1f531e1e37B0",
1451
- estimatedGasCostInToken
1452
- ]
1453
- },
1454
- {
1455
- to: (0, import_viem5.getAddress)(token2.address),
1456
- abi: (0, import_viem5.parseAbi)(["function transferFrom(address,address,uint)"]),
1457
- functionName: "transferFrom",
1458
- args: [fromAddress, receiver, receiverAmount]
1459
- }
1460
- ]
1461
- });
1462
- const signature = yield account.signUserOperation(__spreadProps(__spreadValues({}, userOperation), {
1463
- chainId: this.chainId
1464
- }));
1465
- const rpcParameters = (0, import_account_abstraction2.formatUserOperationRequest)(__spreadProps(__spreadValues({}, userOperation), {
1466
- signature
1467
- }));
1468
- return rpcParameters;
1469
- } catch (error) {
1470
- if (error instanceof Error) {
1471
- throw new Error(error.message);
1472
- }
1473
- throw new Error("Failed to sign single payment operation.");
1474
- }
1475
- });
1476
- }
1477
- signRecurringPayments(recurringPaymentParams) {
1478
- return __async(this, null, function* () {
1479
- if (!this.signer) {
1480
- throw new Error("Signer is required for self custody payments.");
1481
- }
1482
- const {
1483
- signerAddress,
1484
- chainId,
1485
- token: tokenSymbol,
1486
- amount,
1487
- receiver,
1488
- feeInclusive,
1489
- count,
1490
- intervalUnit,
1491
- startDate,
1492
- endDate,
1493
- allowMaxTokenApproval
1494
- } = recurringPaymentParams;
1495
- if (amount <= BigInt(0)) {
1496
- throw new Error("Amount must be greater than 0.");
1497
- }
1498
- if (receiver === signerAddress) {
1499
- throw new Error("Receiver cannot be the same as the signer.");
1500
- }
1501
- if (!intervalUnit) {
1502
- throw new Error("Interval unit is required.");
1503
- }
1504
- const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
1505
- if (!token2) {
1506
- throw new Error("Token not found.");
1507
- }
1508
- const kernelVersion = import_constants.KERNEL_V3_1;
1509
- const entryPoint = (0, import_constants.getEntryPoint)("0.7");
1510
- const paymentCount = count != null ? count : 24;
1511
- const account = yield this.createAccount();
1512
- const smartAccountAddress = account.address;
1513
- const viemClient = new ViemClient(this.chainId, this.signer);
1514
- const { paymasterClient, pimlicoClient } = yield this.createAccountHelpers();
1515
- const ecdsaValidator = yield (0, import_ecdsa_validator.signerToEcdsaValidator)(
1516
- viemClient.publicClient(),
1517
- {
1518
- entryPoint,
1519
- kernelVersion,
1520
- signer: this.signer
1521
- }
998
+ const kernelVersion = import_constants.KERNEL_V3_1;
999
+ const entryPoint = (0, import_constants.getEntryPoint)("0.7");
1000
+ const paymentCount = count != null ? count : 24;
1001
+ const account = yield this.createAccount();
1002
+ const smartAccountAddress = account.address;
1003
+ const viemClient = new ViemClient(this.chainId, this.signer);
1004
+ const { paymasterClient, pimlicoClient } = yield this.createAccountHelpers();
1005
+ const ecdsaValidator = yield (0, import_ecdsa_validator.signerToEcdsaValidator)(
1006
+ viemClient.publicClient(),
1007
+ {
1008
+ entryPoint,
1009
+ kernelVersion,
1010
+ signer: this.signer
1011
+ }
1522
1012
  );
1523
1013
  const sessionKeyAddress = "0xFDEed8e268D74DF71f3Db7409F8A8290FF1263ED";
1524
- const emptyAccount = (0, import_sdk2.addressToEmptyAccount)(sessionKeyAddress);
1525
- const emptySessionKeySigner = yield toECDSASigner(emptyAccount);
1014
+ const emptyAccount = (0, import_sdk.addressToEmptyAccount)(sessionKeyAddress);
1015
+ const emptySessionKeySigner = yield (0, import_signers.toECDSASigner)({ signer: emptyAccount });
1526
1016
  const {
1527
1017
  paymaster,
1528
1018
  ActalinkFeesInToken,
@@ -1547,32 +1037,36 @@ var ActaAccount = class {
1547
1037
  amountToTransfer * BigInt(paymentCount) + estimatedGasCostInToken * BigInt(2) * BigInt(paymentCount),
1548
1038
  allowMaxTokenApproval != null ? allowMaxTokenApproval : false
1549
1039
  );
1550
- const callPolicy = (0, import_policies2.toCallPolicy)({
1551
- policyVersion: import_policies2.CallPolicyVersion.V0_0_4,
1040
+ const amountExclusive = amountToTransfer + amountToTransfer / BigInt(2);
1041
+ const callPolicy = (0, import_policies.toCallPolicy)({
1042
+ policyVersion: import_policies.CallPolicyVersion.V0_0_4,
1552
1043
  permissions: [
1553
1044
  {
1554
1045
  target: token2.address,
1555
1046
  valueLimit: BigInt(0),
1556
- abi: (0, import_viem5.parseAbi)(["function transferFrom(address,address,uint)"]),
1047
+ abi: (0, import_viem3.parseAbi)(["function transferFrom(address,address,uint)"]),
1557
1048
  functionName: "transferFrom",
1558
1049
  args: [
1559
1050
  {
1560
- condition: import_policies2.ParamCondition.EQUAL,
1561
- value: signerAddress
1051
+ condition: import_policies.ParamCondition.EQUAL,
1052
+ value: (0, import_viem3.getAddress)(signerAddress)
1562
1053
  },
1563
1054
  {
1564
- condition: import_policies2.ParamCondition.ONE_OF,
1565
- value: ["0xC4910E5ec82Da0A41aF9C6360b7A1f531e1e37B0", receiver]
1055
+ condition: import_policies.ParamCondition.ONE_OF,
1056
+ value: [
1057
+ "0xC4910E5ec82Da0A41aF9C6360b7A1f531e1e37B0",
1058
+ (0, import_viem3.getAddress)(receiver)
1059
+ ]
1566
1060
  },
1567
1061
  {
1568
- condition: import_policies2.ParamCondition.LESS_THAN_OR_EQUAL,
1569
- value: amountToTransfer + amountToTransfer / BigInt(2)
1062
+ condition: import_policies.ParamCondition.LESS_THAN_OR_EQUAL,
1063
+ value: amountExclusive
1570
1064
  }
1571
1065
  ]
1572
1066
  }
1573
1067
  ]
1574
1068
  });
1575
- const permissionPlugin = yield toPermissionValidator(
1069
+ const permissionPlugin = yield (0, import_permissions.toPermissionValidator)(
1576
1070
  viemClient.publicClient(),
1577
1071
  {
1578
1072
  entryPoint,
@@ -1581,7 +1075,7 @@ var ActaAccount = class {
1581
1075
  policies: [callPolicy]
1582
1076
  }
1583
1077
  );
1584
- const serializedSessionKeyAccount = yield (0, import_sdk2.createKernelAccount)(
1078
+ const serializedSessionKeyAccount = yield (0, import_sdk.createKernelAccount)(
1585
1079
  viemClient.publicClient(),
1586
1080
  {
1587
1081
  entryPoint,
@@ -1592,168 +1086,417 @@ var ActaAccount = class {
1592
1086
  }
1593
1087
  }
1594
1088
  );
1595
- const approval = yield serializePermissionAccount(
1089
+ const approval = yield (0, import_permissions.serializePermissionAccount)(
1596
1090
  serializedSessionKeyAccount
1597
1091
  );
1598
- return approval;
1092
+ return { approval, amountExclusive };
1599
1093
  });
1600
1094
  }
1601
- };
1602
-
1603
- // src/deposit.ts
1604
- var transactionServiceUrl = "https://api.acta.link/transaction/v1/";
1605
- var depositServiceUrl = "https://api.acta.link/deposit/v1/";
1606
- var ActaDeposit = class {
1607
- constructor(parameters) {
1608
- this.count = 0;
1609
- this.intervalUnit = void 0;
1610
- this.startDate = void 0;
1611
- this.endDate = void 0;
1612
- this.serviceSessionParams = void 0;
1613
- this.depositSessionId = "";
1614
- this.status = "not_started";
1615
- this.serviceType = "deposit";
1616
- this.allowMaxTokenApproval = false;
1617
- var _a, _b;
1618
- this.connectorType = parameters.connectorType;
1619
- this.walletClient = parameters.walletClient;
1620
- this.signerAddress = parameters.signerAddress;
1621
- this.chainId = parameters.chainId;
1622
- this.token = parameters.token;
1623
- this.amount = parameters.amount;
1624
- this.receiver = parameters.receiver;
1625
- this.feeInclusive = parameters.feeInclusive;
1626
- this.paymentType = parameters.paymentType;
1627
- this.count = parameters.count;
1628
- this.intervalUnit = parameters.intervalUnit;
1629
- this.startDate = parameters.startDate;
1630
- this.endDate = parameters.endDate;
1631
- this.depositSessionId = (_a = parameters.depositSessionId) != null ? _a : "";
1632
- this.allowMaxTokenApproval = (_b = parameters.allowMaxTokenApproval) != null ? _b : false;
1633
- this.viemClient = new ViemClient(this.chainId, this.walletClient);
1634
- this.account = new ActaAccount(
1635
- this.chainId,
1636
- this.viemClient.publicClient(),
1637
- this.walletClient
1638
- );
1639
- }
1640
- createSession(serviceSessionparams) {
1095
+ signRecurringTransactionCancellation(paymentCancellationParams) {
1641
1096
  return __async(this, null, function* () {
1642
- try {
1643
- if (!this.signerAddress || this.signerAddress === import_viem6.zeroAddress) {
1644
- throw new Error("Signer address is required.");
1645
- }
1646
- if (this.paymentType !== "single" && this.paymentType !== "choose" && this.paymentType !== "recurring") {
1647
- throw new Error("Invalid payment type.");
1648
- }
1649
- if (!this.receiver || this.receiver === import_viem6.zeroAddress) {
1650
- throw new Error("Receiver is required.");
1651
- }
1652
- if (this.paymentType === "recurring" && (this.count === void 0 || this.count === 0)) {
1653
- throw new Error("Count is required for recurring payments.");
1654
- }
1655
- if (this.paymentType === "recurring" && this.intervalUnit === void 0) {
1656
- throw new Error("Interval unit is required for recurring payments.");
1657
- }
1658
- if (this.depositSessionId !== "") {
1659
- const session2 = yield verifySessionAPICall(
1660
- `${depositServiceUrl}verify-session?sessionId=${this.depositSessionId}`,
1661
- this.depositSessionId
1662
- );
1663
- this.depositSessionId = session2.sessionId;
1664
- return session2.sessionId;
1665
- }
1666
- const token2 = getTokenByChainIdAndSymbol(this.chainId, this.token);
1667
- if (!token2) {
1668
- throw new Error("Token not supported.");
1669
- }
1670
- const session = yield createSessionAPICall(
1671
- `${depositServiceUrl}session`,
1097
+ var _a;
1098
+ if (!this.signer) {
1099
+ throw new Error("Signer is required for self custody payments.");
1100
+ }
1101
+ const { signerAddress, token: token2, amountExclusive, receiverAddress } = paymentCancellationParams;
1102
+ const address = yield (_a = this.signer.account) == null ? void 0 : _a.address;
1103
+ if (!address) {
1104
+ throw new Error("Signer is required for self custody payments.");
1105
+ }
1106
+ if (address !== (0, import_viem3.getAddress)(signerAddress)) {
1107
+ throw new Error("Connected Wallet is not the owner of transaction.");
1108
+ }
1109
+ if (amountExclusive <= BigInt(0)) {
1110
+ throw new Error("Amount Exclusive must be greater than 0.");
1111
+ }
1112
+ const kernelVersion = import_constants.KERNEL_V3_1;
1113
+ const entryPoint = (0, import_constants.getEntryPoint)("0.7");
1114
+ const viemClient = new ViemClient(this.chainId, this.signer);
1115
+ const account = yield this.createAccount();
1116
+ const { kernelAccountClient, accountClient } = yield this.createAccountHelpers();
1117
+ const sessionKeyAddress = "0xFDEed8e268D74DF71f3Db7409F8A8290FF1263ED";
1118
+ const emptyAccount = (0, import_sdk.addressToEmptyAccount)(sessionKeyAddress);
1119
+ const emptySessionKeySigner = yield (0, import_signers.toECDSASigner)({ signer: emptyAccount });
1120
+ const callPolicy = (0, import_policies.toCallPolicy)({
1121
+ policyVersion: import_policies.CallPolicyVersion.V0_0_4,
1122
+ permissions: [
1672
1123
  {
1673
- paymentParams: {
1674
- signerAddress: this.signerAddress,
1675
- chainId: this.chainId,
1676
- token: token2.address,
1677
- amount: (0, import_viem6.toHex)(this.amount),
1678
- receiver: this.receiver,
1679
- feeInclusive: this.feeInclusive,
1680
- serviceType: "deposit",
1681
- paymentType: this.paymentType,
1682
- count: this.count,
1683
- intervalUnit: this.intervalUnit,
1684
- startDate: this.startDate,
1685
- endDate: this.endDate
1686
- },
1687
- serviceSessionParams: serviceSessionparams
1124
+ target: (0, import_viem3.getAddress)(token2),
1125
+ valueLimit: BigInt(0),
1126
+ abi: (0, import_viem3.parseAbi)(["function transferFrom(address,address,uint)"]),
1127
+ functionName: "transferFrom",
1128
+ args: [
1129
+ {
1130
+ condition: import_policies.ParamCondition.EQUAL,
1131
+ value: (0, import_viem3.getAddress)(signerAddress)
1132
+ },
1133
+ {
1134
+ condition: import_policies.ParamCondition.ONE_OF,
1135
+ value: [
1136
+ "0xC4910E5ec82Da0A41aF9C6360b7A1f531e1e37B0",
1137
+ (0, import_viem3.getAddress)(receiverAddress)
1138
+ ]
1139
+ },
1140
+ {
1141
+ condition: import_policies.ParamCondition.LESS_THAN_OR_EQUAL,
1142
+ value: amountExclusive
1143
+ }
1144
+ ]
1688
1145
  }
1689
- );
1690
- this.depositSessionId = session.sessionId;
1691
- this.status = "session_created";
1692
- const sessionId = session.sessionId;
1693
- return sessionId;
1694
- } catch (error) {
1695
- this.status = "session_fetch_failed";
1696
- if (error instanceof Error) {
1697
- throw new Error(error.message);
1146
+ ]
1147
+ });
1148
+ const permissionPlugin = yield (0, import_permissions.toPermissionValidator)(
1149
+ viemClient.publicClient(),
1150
+ {
1151
+ entryPoint,
1152
+ kernelVersion,
1153
+ signer: emptySessionKeySigner,
1154
+ policies: [callPolicy]
1698
1155
  }
1699
- throw new Error("Failed to create deposit session.");
1700
- }
1156
+ );
1157
+ const validatorId = (0, import_viem3.concatHex)([
1158
+ import_constants.VALIDATOR_TYPE[permissionPlugin.validatorType],
1159
+ (0, import_viem3.pad)(permissionPlugin.getIdentifier(), {
1160
+ size: 20,
1161
+ dir: "right"
1162
+ })
1163
+ ]);
1164
+ const parsedAccount = (0, import_utils.parseAccount)(account);
1165
+ const validatorData = yield permissionPlugin.getEnableData(
1166
+ parsedAccount.address
1167
+ );
1168
+ const userOperation = yield accountClient.prepareUserOperation({
1169
+ calls: [
1170
+ {
1171
+ to: parsedAccount.address,
1172
+ data: (0, import_viem3.encodeFunctionData)({
1173
+ abi: import_sdk.KernelV3AccountAbi,
1174
+ functionName: "uninstallValidation",
1175
+ args: [validatorId, validatorData, "0x"]
1176
+ }),
1177
+ value: BigInt(0)
1178
+ }
1179
+ ]
1180
+ });
1181
+ const signature = yield account.signUserOperation(__spreadProps(__spreadValues({}, userOperation), {
1182
+ chainId: this.chainId
1183
+ }));
1184
+ const rpcParameters = (0, import_account_abstraction.formatUserOperationRequest)(__spreadProps(__spreadValues({}, userOperation), {
1185
+ signature
1186
+ }));
1187
+ return rpcParameters;
1701
1188
  });
1702
1189
  }
1703
- estimateSinglePaymentGas(parameters) {
1704
- return __async(this, null, function* () {
1705
- try {
1706
- if (this.connectorType !== "Self-Custody" /* SELF_CUSTODY */) {
1707
- throw new Error("Only self custody payments are supported.");
1708
- }
1709
- const {
1710
- estimatedGasCostInToken,
1711
- ActalinkFeesInToken,
1712
- feeInclusiveAmountInToken,
1713
- feeExclusiveAmountInToken,
1714
- estimatedTotalFeesInToken,
1715
- paymaster,
1716
- userOperation
1717
- } = yield this.account.estimateSinglePaymentGas(parameters);
1718
- return {
1719
- estimatedGasCostInToken,
1720
- ActalinkFeesInToken,
1721
- feeInclusiveAmountInToken,
1722
- feeExclusiveAmountInToken,
1723
- estimatedTotalFeesInToken,
1724
- paymaster,
1725
- userOperation
1726
- };
1727
- } catch (error) {
1728
- if (error instanceof Error) {
1729
- throw new Error(error.message);
1730
- }
1731
- throw new Error("Failed to estimate single payment gas.");
1732
- }
1190
+ };
1191
+
1192
+ // src/api.ts
1193
+ var import_viem4 = require("viem");
1194
+ var HttpMethod = /* @__PURE__ */ ((HttpMethod2) => {
1195
+ HttpMethod2["Get"] = "get";
1196
+ HttpMethod2["Post"] = "post";
1197
+ HttpMethod2["Delete"] = "delete";
1198
+ HttpMethod2["Update"] = "update";
1199
+ return HttpMethod2;
1200
+ })(HttpMethod || {});
1201
+ function sendRequest(_0) {
1202
+ return __async(this, arguments, function* ({
1203
+ url,
1204
+ method,
1205
+ body,
1206
+ headers = {}
1207
+ }) {
1208
+ var _a;
1209
+ const response = yield fetch(url, {
1210
+ method,
1211
+ headers: __spreadProps(__spreadValues({}, headers), {
1212
+ Accept: "application/json",
1213
+ "Content-Type": "application/json"
1214
+ }),
1215
+ body: JSON.stringify(body)
1216
+ });
1217
+ let jsonResponse;
1218
+ const res = yield response.json();
1219
+ if (!response.ok) {
1220
+ jsonResponse = {
1221
+ error: {
1222
+ code: response.status,
1223
+ message: response.statusText
1224
+ },
1225
+ data: void 0
1226
+ };
1227
+ return jsonResponse;
1228
+ }
1229
+ if (!res) {
1230
+ jsonResponse = {
1231
+ error: {
1232
+ code: 400,
1233
+ message: "No response received."
1234
+ },
1235
+ data: void 0
1236
+ };
1237
+ return jsonResponse;
1238
+ }
1239
+ if (res == null ? void 0 : res.error) {
1240
+ jsonResponse = {
1241
+ error: {
1242
+ code: response.status,
1243
+ message: res.error
1244
+ },
1245
+ data: void 0
1246
+ };
1247
+ return jsonResponse;
1248
+ }
1249
+ jsonResponse = {
1250
+ data: res.data,
1251
+ message: (_a = res.message) != null ? _a : "Success",
1252
+ error: void 0
1253
+ };
1254
+ return jsonResponse;
1255
+ });
1256
+ }
1257
+ function createSessionAPICall(url, sessionBodyParams) {
1258
+ return __async(this, null, function* () {
1259
+ const response = yield sendRequest({
1260
+ url,
1261
+ method: "post" /* Post */,
1262
+ body: sessionBodyParams
1263
+ });
1264
+ return response.data;
1265
+ });
1266
+ }
1267
+ function verifySessionAPICall(url, sessionId) {
1268
+ return __async(this, null, function* () {
1269
+ const response = yield sendRequest({
1270
+ url,
1271
+ method: "get" /* Get */
1272
+ });
1273
+ return response.data;
1274
+ });
1275
+ }
1276
+ function scheduleRecurringPaymentsAPICall(url, params) {
1277
+ return __async(this, null, function* () {
1278
+ const parsedParams = __spreadProps(__spreadValues({}, params), {
1279
+ amount: (0, import_viem4.toHex)(params.amount),
1280
+ amountExclusive: (0, import_viem4.toHex)(params.amountExclusive)
1281
+ });
1282
+ const response = yield sendRequest({
1283
+ url,
1284
+ method: "post" /* Post */,
1285
+ body: parsedParams
1286
+ });
1287
+ return response.data;
1288
+ });
1289
+ }
1290
+ function createBillingSessionAPICall(url, sessionBodyParams) {
1291
+ return __async(this, null, function* () {
1292
+ const response = yield sendRequest({
1293
+ url,
1294
+ method: "post" /* Post */,
1295
+ body: sessionBodyParams
1296
+ });
1297
+ return response.data;
1298
+ });
1299
+ }
1300
+ function fetchBillingSessionDetails(url) {
1301
+ return __async(this, null, function* () {
1302
+ const response = yield sendRequest({
1303
+ url,
1304
+ method: "get" /* Get */
1305
+ });
1306
+ return response.data;
1307
+ });
1308
+ }
1309
+ function executeSinglePaymentAPICall(url, userOperation, paymentParams, serviceParams) {
1310
+ return __async(this, null, function* () {
1311
+ const params = {
1312
+ userOperation,
1313
+ paymentParams,
1314
+ serviceParams
1315
+ };
1316
+ const response = yield sendRequest({
1317
+ url,
1318
+ method: "post" /* Post */,
1319
+ body: params
1320
+ });
1321
+ return response.data;
1322
+ });
1323
+ }
1324
+ function fetchRecurringTransactionWithId(url) {
1325
+ return __async(this, null, function* () {
1326
+ const response = yield sendRequest({ url, method: "get" /* Get */ });
1327
+ return response.data;
1328
+ });
1329
+ }
1330
+ function cancelRecurringPaymentAPICall(url, userOperation, paymentParams, serviceParams) {
1331
+ return __async(this, null, function* () {
1332
+ const params = {
1333
+ userOperation,
1334
+ paymentParams,
1335
+ serviceParams
1336
+ };
1337
+ const response = yield sendRequest({
1338
+ url,
1339
+ method: "post" /* Post */,
1340
+ body: params
1733
1341
  });
1342
+ return response.data;
1343
+ });
1344
+ }
1345
+
1346
+ // src/deposit.ts
1347
+ var transactionServiceUrl = "https://api.acta.link/transaction/v1/";
1348
+ var depositServiceUrl = "https://api.acta.link/deposit/v1/";
1349
+ var ActaDeposit = class {
1350
+ constructor(parameters) {
1351
+ this.count = 0;
1352
+ this.intervalUnit = void 0;
1353
+ this.startDate = void 0;
1354
+ this.endDate = void 0;
1355
+ this.serviceSessionParams = void 0;
1356
+ this.depositSessionId = "";
1357
+ this.status = "not_started";
1358
+ this.serviceType = "deposit";
1359
+ this.allowMaxTokenApproval = false;
1360
+ var _a, _b;
1361
+ this.connectorType = parameters.connectorType;
1362
+ this.walletClient = parameters.walletClient;
1363
+ this.signerAddress = parameters.signerAddress;
1364
+ this.chainId = parameters.chainId;
1365
+ this.token = parameters.token;
1366
+ this.amount = parameters.amount;
1367
+ this.receiver = parameters.receiver;
1368
+ this.feeInclusive = parameters.feeInclusive;
1369
+ this.paymentType = parameters.paymentType;
1370
+ this.count = parameters.count;
1371
+ this.intervalUnit = parameters.intervalUnit;
1372
+ this.startDate = parameters.startDate;
1373
+ this.endDate = parameters.endDate;
1374
+ this.depositSessionId = (_a = parameters.depositSessionId) != null ? _a : "";
1375
+ this.allowMaxTokenApproval = (_b = parameters.allowMaxTokenApproval) != null ? _b : false;
1376
+ this.viemClient = new ViemClient(this.chainId, this.walletClient);
1377
+ this.account = new ActaAccount(
1378
+ this.chainId,
1379
+ this.viemClient.publicClient(),
1380
+ this.walletClient
1381
+ );
1734
1382
  }
1735
- createPayment(servicePaymentParams) {
1383
+ createSession(serviceSessionparams) {
1736
1384
  return __async(this, null, function* () {
1737
1385
  try {
1738
- if (this.paymentType === "single") {
1739
- const paymentParams = this.serviceType === "deposit" ? __spreadProps(__spreadValues({}, servicePaymentParams), {
1740
- depositSessionId: this.depositSessionId
1741
- }) : servicePaymentParams;
1742
- const id = yield this.createSinglePayment(paymentParams);
1743
- return id;
1386
+ if (!this.signerAddress || this.signerAddress === import_viem5.zeroAddress) {
1387
+ throw new Error("Signer address is required.");
1744
1388
  }
1745
- if (this.paymentType === "choose") {
1389
+ if (this.paymentType !== "single" && this.paymentType !== "choose" && this.paymentType !== "recurring") {
1390
+ throw new Error("Invalid payment type.");
1746
1391
  }
1747
- if (this.paymentType === "recurring") {
1748
- const paymentParams = this.serviceType === "deposit" ? __spreadProps(__spreadValues({}, servicePaymentParams), {
1749
- depositSessionId: this.depositSessionId
1750
- }) : servicePaymentParams;
1751
- const id = yield this.createRecurringPayments(paymentParams);
1752
- return id;
1392
+ if (!this.receiver || this.receiver === import_viem5.zeroAddress) {
1393
+ throw new Error("Receiver is required.");
1753
1394
  }
1754
- } catch (error) {
1755
- this.status = "payment_failed";
1756
- if (error instanceof Error) {
1395
+ if (this.paymentType === "recurring" && (this.count === void 0 || this.count === 0)) {
1396
+ throw new Error("Count is required for recurring payments.");
1397
+ }
1398
+ if (this.paymentType === "recurring" && this.intervalUnit === void 0) {
1399
+ throw new Error("Interval unit is required for recurring payments.");
1400
+ }
1401
+ if (this.depositSessionId !== "") {
1402
+ const session2 = yield verifySessionAPICall(
1403
+ `${depositServiceUrl}verify-session?sessionId=${this.depositSessionId}`,
1404
+ this.depositSessionId
1405
+ );
1406
+ this.depositSessionId = session2.sessionId;
1407
+ return session2.sessionId;
1408
+ }
1409
+ const token2 = getTokenByChainIdAndSymbol(this.chainId, this.token);
1410
+ if (!token2) {
1411
+ throw new Error("Token not supported.");
1412
+ }
1413
+ const session = yield createSessionAPICall(
1414
+ `${depositServiceUrl}session`,
1415
+ {
1416
+ paymentParams: {
1417
+ signerAddress: this.signerAddress,
1418
+ chainId: this.chainId,
1419
+ token: token2.address,
1420
+ amount: (0, import_viem5.toHex)(this.amount),
1421
+ receiver: this.receiver,
1422
+ feeInclusive: this.feeInclusive,
1423
+ serviceType: "deposit",
1424
+ paymentType: this.paymentType,
1425
+ count: this.count,
1426
+ intervalUnit: this.intervalUnit,
1427
+ startDate: this.startDate,
1428
+ endDate: this.endDate
1429
+ },
1430
+ serviceSessionParams: serviceSessionparams
1431
+ }
1432
+ );
1433
+ this.depositSessionId = session.sessionId;
1434
+ this.status = "session_created";
1435
+ const sessionId = session.sessionId;
1436
+ return sessionId;
1437
+ } catch (error) {
1438
+ this.status = "session_fetch_failed";
1439
+ if (error instanceof Error) {
1440
+ throw new Error(error.message);
1441
+ }
1442
+ throw new Error("Failed to create deposit session.");
1443
+ }
1444
+ });
1445
+ }
1446
+ estimateSinglePaymentGas(parameters) {
1447
+ return __async(this, null, function* () {
1448
+ try {
1449
+ if (this.connectorType !== "Self-Custody" /* SELF_CUSTODY */) {
1450
+ throw new Error("Only self custody payments are supported.");
1451
+ }
1452
+ const {
1453
+ estimatedGasCostInToken,
1454
+ ActalinkFeesInToken,
1455
+ feeInclusiveAmountInToken,
1456
+ feeExclusiveAmountInToken,
1457
+ estimatedTotalFeesInToken,
1458
+ paymaster,
1459
+ userOperation
1460
+ } = yield this.account.estimateSinglePaymentGas(parameters);
1461
+ return {
1462
+ estimatedGasCostInToken,
1463
+ ActalinkFeesInToken,
1464
+ feeInclusiveAmountInToken,
1465
+ feeExclusiveAmountInToken,
1466
+ estimatedTotalFeesInToken,
1467
+ paymaster,
1468
+ userOperation
1469
+ };
1470
+ } catch (error) {
1471
+ if (error instanceof Error) {
1472
+ throw new Error(error.message);
1473
+ }
1474
+ throw new Error("Failed to estimate single payment gas.");
1475
+ }
1476
+ });
1477
+ }
1478
+ createPayment(servicePaymentParams) {
1479
+ return __async(this, null, function* () {
1480
+ try {
1481
+ if (this.paymentType === "single") {
1482
+ const paymentParams = this.serviceType === "deposit" ? __spreadProps(__spreadValues({}, servicePaymentParams), {
1483
+ depositSessionId: this.depositSessionId
1484
+ }) : servicePaymentParams;
1485
+ const id = yield this.createSinglePayment(paymentParams);
1486
+ return id;
1487
+ }
1488
+ if (this.paymentType === "choose") {
1489
+ }
1490
+ if (this.paymentType === "recurring") {
1491
+ const paymentParams = this.serviceType === "deposit" ? __spreadProps(__spreadValues({}, servicePaymentParams), {
1492
+ depositSessionId: this.depositSessionId
1493
+ }) : servicePaymentParams;
1494
+ const id = yield this.createRecurringPayments(paymentParams);
1495
+ return id;
1496
+ }
1497
+ } catch (error) {
1498
+ this.status = "payment_failed";
1499
+ if (error instanceof Error) {
1757
1500
  throw new Error(error.message);
1758
1501
  }
1759
1502
  throw new Error("Failed to create payment.");
@@ -1804,7 +1547,7 @@ var ActaDeposit = class {
1804
1547
  receiverAddress: receiver,
1805
1548
  chainId,
1806
1549
  tokenAddress: token2.address,
1807
- amount: (0, import_viem6.toHex)(amount),
1550
+ amount: (0, import_viem5.toHex)(amount),
1808
1551
  feeInclusive,
1809
1552
  serviceType
1810
1553
  },
@@ -1876,7 +1619,7 @@ var ActaDeposit = class {
1876
1619
  if (!chainId || !count || !intervalUnit || !startDate || !endDate) {
1877
1620
  throw new Error("Invalid parameters.");
1878
1621
  }
1879
- const approval = yield this.account.signRecurringPayments({
1622
+ const { approval, amountExclusive } = yield this.account.signRecurringPayments({
1880
1623
  signerAddress,
1881
1624
  chainId,
1882
1625
  token: tokenSymbol,
@@ -1893,6 +1636,7 @@ var ActaDeposit = class {
1893
1636
  `${transactionServiceUrl}schedule/recurring`,
1894
1637
  {
1895
1638
  amount,
1639
+ amountExclusive,
1896
1640
  chainId,
1897
1641
  feeInclusive,
1898
1642
  intervalCount: count,
@@ -1943,223 +1687,645 @@ var ActaDeposit = class {
1943
1687
  });
1944
1688
  }
1945
1689
  };
1946
-
1947
- // src/billing.ts
1948
- var import_viem7 = require("viem");
1949
- var transactionServiceUrl2 = "https://api.acta.link/transaction/v1/";
1950
- var ActaBilling = class {
1951
- constructor(parameters) {
1952
- this.count = 0;
1953
- this.intervalUnit = void 0;
1954
- this.startDate = void 0;
1955
- this.endDate = void 0;
1956
- this.serviceSessionParams = void 0;
1957
- this.status = "not_started";
1958
- this.serviceType = "deposit";
1959
- this.allowMaxTokenApproval = false;
1960
- var _a;
1961
- this.connectorType = parameters.connectorType;
1962
- this.walletClient = parameters.walletClient;
1963
- this.signerAddress = parameters.signerAddress;
1964
- this.chainId = parameters.chainId;
1965
- this.token = parameters.token;
1966
- this.amount = parameters.amount;
1967
- this.receiver = parameters.receiver;
1968
- this.feeInclusive = parameters.feeInclusive;
1969
- this.paymentType = parameters.paymentType;
1970
- this.count = parameters.count;
1971
- this.intervalUnit = parameters.intervalUnit;
1972
- this.startDate = parameters.startDate;
1973
- this.endDate = parameters.endDate;
1974
- this.allowMaxTokenApproval = (_a = parameters.allowMaxTokenApproval) != null ? _a : false;
1975
- this.serviceType = parameters.serviceType;
1976
- this.viemClient = new ViemClient(this.chainId, this.walletClient);
1977
- this.account = new ActaAccount(
1978
- this.chainId,
1979
- this.viemClient.publicClient(),
1980
- this.walletClient
1981
- );
1982
- }
1983
- estimateSinglePaymentGas(parameters) {
1984
- return __async(this, null, function* () {
1985
- try {
1986
- if (this.connectorType !== "Self-Custody" /* SELF_CUSTODY */) {
1987
- throw new Error("Only self custody payments are supported.");
1988
- }
1989
- const {
1990
- estimatedGasCostInToken,
1991
- ActalinkFeesInToken,
1992
- feeInclusiveAmountInToken,
1993
- feeExclusiveAmountInToken,
1994
- estimatedTotalFeesInToken,
1995
- paymaster,
1996
- userOperation
1997
- } = yield this.account.estimateSinglePaymentGas(parameters);
1998
- return {
1999
- estimatedGasCostInToken,
2000
- ActalinkFeesInToken,
2001
- feeInclusiveAmountInToken,
2002
- feeExclusiveAmountInToken,
2003
- estimatedTotalFeesInToken,
2004
- paymaster,
2005
- userOperation
2006
- };
2007
- } catch (error) {
2008
- if (error instanceof Error) {
2009
- throw new Error(error.message);
2010
- }
2011
- throw new Error("Failed to estimate single payment gas.");
1690
+
1691
+ // src/billing.ts
1692
+ var import_viem6 = require("viem");
1693
+ var transactionServiceUrl2 = "https://api.acta.link/transaction/v1/";
1694
+ var ActaBilling = class {
1695
+ constructor(parameters) {
1696
+ this.count = 0;
1697
+ this.intervalUnit = void 0;
1698
+ this.startDate = void 0;
1699
+ this.endDate = void 0;
1700
+ this.serviceSessionParams = void 0;
1701
+ this.status = "not_started";
1702
+ this.serviceType = "deposit";
1703
+ this.allowMaxTokenApproval = false;
1704
+ var _a;
1705
+ this.connectorType = parameters.connectorType;
1706
+ this.walletClient = parameters.walletClient;
1707
+ this.signerAddress = parameters.signerAddress;
1708
+ this.chainId = parameters.chainId;
1709
+ this.token = parameters.token;
1710
+ this.amount = parameters.amount;
1711
+ this.receiver = parameters.receiver;
1712
+ this.feeInclusive = parameters.feeInclusive;
1713
+ this.paymentType = parameters.paymentType;
1714
+ this.count = parameters.count;
1715
+ this.intervalUnit = parameters.intervalUnit;
1716
+ this.startDate = parameters.startDate;
1717
+ this.endDate = parameters.endDate;
1718
+ this.allowMaxTokenApproval = (_a = parameters.allowMaxTokenApproval) != null ? _a : false;
1719
+ this.serviceType = parameters.serviceType;
1720
+ this.viemClient = new ViemClient(this.chainId, this.walletClient);
1721
+ this.account = new ActaAccount(
1722
+ this.chainId,
1723
+ this.viemClient.publicClient(),
1724
+ this.walletClient
1725
+ );
1726
+ }
1727
+ estimateSinglePaymentGas(parameters) {
1728
+ return __async(this, null, function* () {
1729
+ try {
1730
+ if (this.connectorType !== "Self-Custody" /* SELF_CUSTODY */) {
1731
+ throw new Error("Only self custody payments are supported.");
1732
+ }
1733
+ const {
1734
+ estimatedGasCostInToken,
1735
+ ActalinkFeesInToken,
1736
+ feeInclusiveAmountInToken,
1737
+ feeExclusiveAmountInToken,
1738
+ estimatedTotalFeesInToken,
1739
+ paymaster,
1740
+ userOperation
1741
+ } = yield this.account.estimateSinglePaymentGas(parameters);
1742
+ return {
1743
+ estimatedGasCostInToken,
1744
+ ActalinkFeesInToken,
1745
+ feeInclusiveAmountInToken,
1746
+ feeExclusiveAmountInToken,
1747
+ estimatedTotalFeesInToken,
1748
+ paymaster,
1749
+ userOperation
1750
+ };
1751
+ } catch (error) {
1752
+ if (error instanceof Error) {
1753
+ throw new Error(error.message);
1754
+ }
1755
+ throw new Error("Failed to estimate single payment gas.");
1756
+ }
1757
+ });
1758
+ }
1759
+ createSinglePayment(servicePaymentParams) {
1760
+ return __async(this, null, function* () {
1761
+ try {
1762
+ if (this.connectorType !== "Self-Custody" /* SELF_CUSTODY */) {
1763
+ throw new Error("Only self custody payments are supported.");
1764
+ }
1765
+ if (!servicePaymentParams.checkoutSessionId || servicePaymentParams.checkoutSessionId === "") {
1766
+ throw new Error("checkout session ID is required.");
1767
+ }
1768
+ const signerAddress = this.signerAddress;
1769
+ const chainId = this.chainId;
1770
+ const tokenSymbol = this.token;
1771
+ const amount = this.amount;
1772
+ const receiver = this.receiver;
1773
+ const feeInclusive = this.feeInclusive;
1774
+ const serviceType = this.serviceType;
1775
+ const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
1776
+ if (!token2) {
1777
+ throw new Error("Token not supported.");
1778
+ }
1779
+ const rpcParameters = yield this.account.signSinglePaymentOperation({
1780
+ signerAddress,
1781
+ chainId,
1782
+ token: tokenSymbol,
1783
+ amount,
1784
+ receiver,
1785
+ feeInclusive,
1786
+ allowMaxTokenApproval: this.allowMaxTokenApproval
1787
+ });
1788
+ const txn = yield executeSinglePaymentAPICall(
1789
+ `${transactionServiceUrl2}execute/single`,
1790
+ rpcParameters,
1791
+ {
1792
+ senderAddress: signerAddress,
1793
+ receiverAddress: receiver,
1794
+ chainId,
1795
+ tokenAddress: token2.address,
1796
+ amount: (0, import_viem6.toHex)(amount),
1797
+ feeInclusive,
1798
+ serviceType
1799
+ },
1800
+ servicePaymentParams
1801
+ );
1802
+ return txn.transaction.id;
1803
+ } catch (error) {
1804
+ if (error instanceof Error) {
1805
+ throw new Error(error.message);
1806
+ }
1807
+ throw new Error("Failed to create payment.");
1808
+ }
1809
+ });
1810
+ }
1811
+ createRecurringPayments(servicePaymentParams) {
1812
+ return __async(this, null, function* () {
1813
+ if (this.connectorType !== "Self-Custody" /* SELF_CUSTODY */) {
1814
+ throw new Error("Only self custody payments are supported.");
1815
+ }
1816
+ if (!servicePaymentParams.checkoutSessionId || servicePaymentParams.checkoutSessionId === "") {
1817
+ throw new Error("checkout session ID is required.");
1818
+ }
1819
+ if (!this.walletClient) {
1820
+ throw new Error("Signer is required for self custody payments.");
1821
+ }
1822
+ const signerAddress = this.signerAddress;
1823
+ const chainId = this.chainId;
1824
+ const tokenSymbol = this.token;
1825
+ const amount = this.amount;
1826
+ const receiver = this.receiver;
1827
+ const feeInclusive = this.feeInclusive;
1828
+ const count = this.count;
1829
+ const intervalUnit = this.intervalUnit;
1830
+ const startDate = this.startDate;
1831
+ const endDate = this.endDate;
1832
+ const serviceType = this.serviceType;
1833
+ const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
1834
+ if (!token2) {
1835
+ throw new Error("Token not supported.");
1836
+ }
1837
+ if (!chainId || !count || !intervalUnit || !startDate || !endDate) {
1838
+ throw new Error("Invalid parameters.");
1839
+ }
1840
+ const { approval, amountExclusive } = yield this.account.signRecurringPayments({
1841
+ signerAddress,
1842
+ chainId,
1843
+ token: tokenSymbol,
1844
+ amount,
1845
+ feeInclusive,
1846
+ count,
1847
+ intervalUnit,
1848
+ startDate,
1849
+ endDate,
1850
+ receiver,
1851
+ allowMaxTokenApproval: this.allowMaxTokenApproval
1852
+ });
1853
+ const txn = yield scheduleRecurringPaymentsAPICall(
1854
+ `${transactionServiceUrl2}schedule/recurring`,
1855
+ {
1856
+ amount,
1857
+ amountExclusive,
1858
+ chainId,
1859
+ feeInclusive,
1860
+ intervalCount: count,
1861
+ intervalUnit,
1862
+ senderAddress: signerAddress,
1863
+ receiverAddress: receiver,
1864
+ tokenAddress: token2.address,
1865
+ startAt: startDate,
1866
+ endAt: endDate,
1867
+ approval,
1868
+ serviceParams: servicePaymentParams,
1869
+ serviceType
1870
+ }
1871
+ );
1872
+ return txn.recurringTransaction.id;
1873
+ });
1874
+ }
1875
+ getPaymentSteps() {
1876
+ return __async(this, null, function* () {
1877
+ const signerAddress = this.signerAddress;
1878
+ const chainId = this.chainId;
1879
+ const tokenSymbol = this.token;
1880
+ const amount = this.amount;
1881
+ const receiver = this.receiver;
1882
+ const feeInclusive = this.feeInclusive;
1883
+ const count = this.count;
1884
+ if (!signerAddress) return ["allowance", "confirm"];
1885
+ const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
1886
+ if (!token2) return ["allowance", "confirm"];
1887
+ const smartAccount = yield this.account.createAccount();
1888
+ const { estimatedGasCostInToken, feeExclusiveAmountInToken } = yield this.account.estimateSinglePaymentGas({
1889
+ chainId,
1890
+ amount,
1891
+ feeInclusive,
1892
+ receiver,
1893
+ signerAddress,
1894
+ token: tokenSymbol
1895
+ });
1896
+ const amountToTransfer = feeInclusive ? amount : feeExclusiveAmountInToken;
1897
+ let paymentAmount = (amountToTransfer + estimatedGasCostInToken * BigInt(2)) * BigInt(count != null ? count : 1);
1898
+ const allowance = yield this.viemClient.checkTokenAllowance(
1899
+ token2,
1900
+ signerAddress,
1901
+ smartAccount.address
1902
+ );
1903
+ if (paymentAmount <= allowance) return ["confirm"];
1904
+ return ["allowance", "confirm"];
1905
+ });
1906
+ }
1907
+ };
1908
+
1909
+ // src/utils.ts
1910
+ var import_sdk2 = require("@zerodev/sdk");
1911
+ var import_accounts = require("@zerodev/sdk/accounts");
1912
+ var import_viem7 = require("viem");
1913
+ var import_accounts2 = require("viem/accounts");
1914
+ var import_actions = require("viem/actions");
1915
+ var import_utils2 = require("viem/utils");
1916
+ var import_account_abstraction2 = require("viem/account-abstraction");
1917
+ var import_policies2 = require("@zerodev/permissions/policies");
1918
+ var import_semver = require("semver");
1919
+ var ECDSA_SIGNER_CONTRACT = "0x6A6F069E2a08c2468e7724Ab3250CdBFBA14D4FF";
1920
+ var billingServiceUrl = "https://api.acta.link/billing/v1/";
1921
+ var depositServiceUrl2 = "https://api.acta.link/deposit/v1/";
1922
+ var transactionServiceUrl3 = "http://localhost:8000/transaction/v1/";
1923
+ var toSignerId = (signer) => {
1924
+ return (0, import_viem7.encodeAbiParameters)(
1925
+ [{ name: "signerData", type: "bytes" }],
1926
+ [(0, import_viem7.concat)([signer.signerContractAddress, signer.getSignerData()])]
1927
+ );
1928
+ };
1929
+ function toECDSASigner2(_0) {
1930
+ return __async(this, arguments, function* (signer, signerContractAddress = ECDSA_SIGNER_CONTRACT) {
1931
+ const viemSigner = yield (0, import_sdk2.toSigner)({ signer });
1932
+ const account = (0, import_accounts2.toAccount)({
1933
+ address: viemSigner.address,
1934
+ signMessage(_02) {
1935
+ return __async(this, arguments, function* ({ message }) {
1936
+ return (0, import_sdk2.fixSignedData)(yield viemSigner.signMessage({ message }));
1937
+ });
1938
+ },
1939
+ signTransaction(_, __) {
1940
+ return __async(this, null, function* () {
1941
+ throw new Error("Smart account signer doesn't need to sign transactions");
1942
+ });
1943
+ },
1944
+ signTypedData(typedData) {
1945
+ return __async(this, null, function* () {
1946
+ return (0, import_sdk2.fixSignedData)(
1947
+ yield viemSigner.signTypedData(__spreadValues({}, typedData))
1948
+ );
1949
+ });
1950
+ }
1951
+ });
1952
+ return {
1953
+ account,
1954
+ signerContractAddress,
1955
+ getSignerData: () => {
1956
+ return viemSigner.address;
1957
+ },
1958
+ getDummySignature: () => import_sdk2.constants.DUMMY_ECDSA_SIG
1959
+ };
1960
+ });
1961
+ }
1962
+ var toPolicyId = (policies) => {
1963
+ return (0, import_viem7.encodeAbiParameters)(
1964
+ [{ name: "policiesData", type: "bytes[]" }],
1965
+ [
1966
+ policies.map(
1967
+ (policy) => (0, import_viem7.concat)([policy.getPolicyInfoInBytes(), policy.getPolicyData()])
1968
+ )
1969
+ ]
1970
+ );
1971
+ };
1972
+ function toPermissionValidator2(_0, _1) {
1973
+ return __async(this, arguments, function* (client, {
1974
+ signer,
1975
+ policies,
1976
+ entryPoint,
1977
+ kernelVersion: _,
1978
+ flag = "0x0000" /* FOR_ALL_VALIDATION */
1979
+ }) {
1980
+ const chainId = client.chain ? client.chain.id : yield (0, import_actions.getChainId)(client);
1981
+ if (entryPoint.version !== "0.7") {
1982
+ throw new Error("Only EntryPoint 0.7 is supported");
1983
+ }
1984
+ const getEnableData = (_kernelAccountAddress) => __async(null, null, function* () {
1985
+ const enableData = (0, import_viem7.encodeAbiParameters)(
1986
+ [{ name: "policyAndSignerData", type: "bytes[]" }],
1987
+ [
1988
+ [
1989
+ ...policies.map(
1990
+ (policy) => (0, import_viem7.concat)([policy.getPolicyInfoInBytes(), policy.getPolicyData()])
1991
+ ),
1992
+ (0, import_viem7.concat)([flag, signer.signerContractAddress, signer.getSignerData()])
1993
+ ]
1994
+ ]
1995
+ );
1996
+ return enableData;
1997
+ });
1998
+ const getPermissionId = () => {
1999
+ const pIdData = (0, import_viem7.encodeAbiParameters)(
2000
+ [{ name: "policyAndSignerData", type: "bytes[]" }],
2001
+ [[toPolicyId(policies), flag, toSignerId(signer)]]
2002
+ );
2003
+ return (0, import_viem7.slice)((0, import_viem7.keccak256)(pIdData), 0, 4);
2004
+ };
2005
+ return __spreadProps(__spreadValues({}, signer.account), {
2006
+ supportedKernelVersions: ">=0.3.0",
2007
+ validatorType: "PERMISSION",
2008
+ address: import_viem7.zeroAddress,
2009
+ source: "PermissionValidator",
2010
+ getEnableData,
2011
+ getIdentifier: getPermissionId,
2012
+ signMessage: (_02) => __async(null, [_02], function* ({ message }) {
2013
+ return (0, import_viem7.concat)(["0xff", yield signer.account.signMessage({ message })]);
2014
+ }),
2015
+ signTypedData: (typedData) => __async(null, null, function* () {
2016
+ return (0, import_viem7.concat)(["0xff", yield signer.account.signTypedData(typedData)]);
2017
+ }),
2018
+ signUserOperation: (userOperation) => __async(null, null, function* () {
2019
+ const userOpHash = (0, import_account_abstraction2.getUserOperationHash)({
2020
+ userOperation: __spreadProps(__spreadValues({}, userOperation), {
2021
+ signature: "0x"
2022
+ }),
2023
+ entryPointAddress: entryPoint.address,
2024
+ entryPointVersion: entryPoint.version,
2025
+ chainId
2026
+ });
2027
+ const signature = yield signer.account.signMessage({
2028
+ message: { raw: userOpHash }
2029
+ });
2030
+ return (0, import_viem7.concat)(["0xff", signature]);
2031
+ }),
2032
+ getNonceKey(_accountAddress, customNonceKey) {
2033
+ return __async(this, null, function* () {
2034
+ if (customNonceKey) {
2035
+ return customNonceKey;
2036
+ }
2037
+ return BigInt(0);
2038
+ });
2039
+ },
2040
+ getStubSignature(_userOperation) {
2041
+ return __async(this, null, function* () {
2042
+ return (0, import_viem7.concat)(["0xff", signer.getDummySignature()]);
2043
+ });
2044
+ },
2045
+ getPluginSerializationParams: () => {
2046
+ return {
2047
+ policies
2048
+ };
2049
+ },
2050
+ isEnabled: (kernelAccountAddress, _selector) => __async(null, null, function* () {
2051
+ try {
2052
+ const permissionConfig = yield (0, import_utils2.getAction)(
2053
+ client,
2054
+ import_actions.readContract,
2055
+ "readContract"
2056
+ )({
2057
+ abi: import_sdk2.KernelV3AccountAbi,
2058
+ address: kernelAccountAddress,
2059
+ functionName: "permissionConfig",
2060
+ args: [getPermissionId()]
2061
+ });
2062
+ return permissionConfig.signer === signer.signerContractAddress;
2063
+ } catch (error) {
2064
+ return false;
2065
+ }
2066
+ })
2067
+ });
2068
+ });
2069
+ }
2070
+ function bytesToBase64(bytes) {
2071
+ const binString = Array.from(bytes, (x) => String.fromCodePoint(x)).join("");
2072
+ return btoa(binString);
2073
+ }
2074
+ function isPermissionValidatorPlugin(plugin) {
2075
+ return (plugin == null ? void 0 : plugin.getPluginSerializationParams) !== void 0;
2076
+ }
2077
+ var serializePermissionAccountParams = (params) => {
2078
+ const replacer = (_, value) => {
2079
+ if (typeof value === "bigint") {
2080
+ return value.toString();
2081
+ }
2082
+ return value;
2083
+ };
2084
+ const jsonString = JSON.stringify(params, replacer);
2085
+ const uint8Array = new TextEncoder().encode(jsonString);
2086
+ const base64String = bytesToBase64(uint8Array);
2087
+ return base64String;
2088
+ };
2089
+ var isKernelVersionAfter = (kernelVersion, version) => {
2090
+ const coercedKernelVersion = (0, import_semver.coerce)(kernelVersion);
2091
+ if (!coercedKernelVersion) return false;
2092
+ return (0, import_semver.gt)(coercedKernelVersion, version);
2093
+ };
2094
+ function base64ToBytes(base64) {
2095
+ const binString = atob(base64);
2096
+ return Uint8Array.from(binString, (m) => m.codePointAt(0));
2097
+ }
2098
+ var deserializePermissionAccountParams = (params) => {
2099
+ const uint8Array = base64ToBytes(params);
2100
+ const jsonString = new TextDecoder().decode(uint8Array);
2101
+ return JSON.parse(jsonString);
2102
+ };
2103
+ var deserializePermissionAccount = (client, entryPoint, kernelVersion, modularPermissionAccountParams, modularSigner) => __async(null, null, function* () {
2104
+ var _a;
2105
+ if (entryPoint.version !== "0.7") {
2106
+ throw new Error("Only EntryPoint 0.7 is supported");
2107
+ }
2108
+ const params = deserializePermissionAccountParams(
2109
+ modularPermissionAccountParams
2110
+ );
2111
+ let signer;
2112
+ if (params.privateKey)
2113
+ signer = yield toECDSASigner2((0, import_accounts2.privateKeyToAccount)(params.privateKey));
2114
+ else if (modularSigner) signer = modularSigner;
2115
+ else throw new Error("No signer or serialized sessionKey provided");
2116
+ const modularPermissionPlugin = yield toPermissionValidator2(client, {
2117
+ signer,
2118
+ policies: yield Promise.all(
2119
+ ((_a = params.permissionParams.policies) == null ? void 0 : _a.map(
2120
+ (policy) => createPolicyFromParams(policy)
2121
+ )) || []
2122
+ ),
2123
+ entryPoint,
2124
+ kernelVersion
2125
+ });
2126
+ const { index, validatorInitData, useMetaFactory } = decodeParamsFromInitCode(
2127
+ params.accountParams.initCode,
2128
+ kernelVersion
2129
+ );
2130
+ const kernelPluginManager = yield (0, import_accounts.toKernelPluginManager)(client, __spreadValues({
2131
+ regular: modularPermissionPlugin,
2132
+ pluginEnableSignature: params.enableSignature,
2133
+ validatorInitData,
2134
+ action: params.action,
2135
+ entryPoint,
2136
+ kernelVersion
2137
+ }, params.validityData));
2138
+ return (0, import_sdk2.createKernelAccount)(client, {
2139
+ entryPoint,
2140
+ kernelVersion,
2141
+ plugins: kernelPluginManager,
2142
+ index,
2143
+ address: params.accountParams.accountAddress,
2144
+ useMetaFactory,
2145
+ eip7702Auth: params.eip7702Auth
2146
+ });
2147
+ });
2148
+ var createPolicyFromParams = (policy) => __async(null, null, function* () {
2149
+ switch (policy.policyParams.type) {
2150
+ case "call":
2151
+ return yield (0, import_policies2.toCallPolicy)(policy.policyParams);
2152
+ case "gas":
2153
+ return yield (0, import_policies2.toGasPolicy)(policy.policyParams);
2154
+ case "rate-limit":
2155
+ return yield (0, import_policies2.toRateLimitPolicy)(policy.policyParams);
2156
+ case "signature-caller":
2157
+ return yield (0, import_policies2.toSignatureCallerPolicy)(policy.policyParams);
2158
+ case "sudo":
2159
+ return yield (0, import_policies2.toSudoPolicy)(policy.policyParams);
2160
+ case "timestamp":
2161
+ return yield (0, import_policies2.toTimestampPolicy)(policy.policyParams);
2162
+ default:
2163
+ throw new Error("Unsupported policy type");
2164
+ }
2165
+ });
2166
+ var decodeParamsFromInitCode = (initCode, kernelVersion) => {
2167
+ let index;
2168
+ let validatorInitData;
2169
+ let deployWithFactoryFunctionData;
2170
+ let useMetaFactory = true;
2171
+ if (initCode === "0x") {
2172
+ return {
2173
+ index: void 0,
2174
+ validatorInitData: void 0,
2175
+ useMetaFactory: true
2176
+ };
2177
+ }
2178
+ try {
2179
+ deployWithFactoryFunctionData = (0, import_viem7.decodeFunctionData)({
2180
+ abi: import_sdk2.KernelFactoryStakerAbi,
2181
+ data: initCode
2182
+ });
2183
+ } catch (error) {
2184
+ deployWithFactoryFunctionData = (0, import_viem7.decodeFunctionData)({
2185
+ abi: import_sdk2.KernelV3FactoryAbi,
2186
+ data: initCode
2187
+ });
2188
+ useMetaFactory = false;
2189
+ }
2190
+ if (!deployWithFactoryFunctionData) throw new Error("Invalid initCode");
2191
+ if (deployWithFactoryFunctionData.functionName === "deployWithFactory") {
2192
+ index = BigInt(deployWithFactoryFunctionData.args[2]);
2193
+ let initializeFunctionData;
2194
+ if (kernelVersion === "0.3.0") {
2195
+ initializeFunctionData = (0, import_viem7.decodeFunctionData)({
2196
+ abi: import_sdk2.KernelV3AccountAbi,
2197
+ data: deployWithFactoryFunctionData.args[1]
2198
+ });
2199
+ } else {
2200
+ initializeFunctionData = (0, import_viem7.decodeFunctionData)({
2201
+ abi: import_sdk2.KernelV3_1AccountAbi,
2202
+ data: deployWithFactoryFunctionData.args[1]
2203
+ });
2204
+ }
2205
+ if (!initializeFunctionData) throw new Error("Invalid initCode");
2206
+ if (initializeFunctionData.functionName === "initialize") {
2207
+ validatorInitData = {
2208
+ validatorAddress: initializeFunctionData.args[0],
2209
+ identifier: initializeFunctionData.args[0],
2210
+ enableData: initializeFunctionData.args[2],
2211
+ initConfig: isKernelVersionAfter(kernelVersion, "0.3.1") && Array.isArray(initializeFunctionData.args[4]) ? [...initializeFunctionData.args[4]] : void 0
2212
+ };
2213
+ }
2214
+ } else if (deployWithFactoryFunctionData.functionName === "createAccount") {
2215
+ index = BigInt(deployWithFactoryFunctionData.args[1]);
2216
+ let initializeFunctionData;
2217
+ if (kernelVersion === "0.3.0") {
2218
+ initializeFunctionData = (0, import_viem7.decodeFunctionData)({
2219
+ abi: import_sdk2.KernelV3AccountAbi,
2220
+ data: deployWithFactoryFunctionData.args[0]
2221
+ });
2222
+ } else {
2223
+ initializeFunctionData = (0, import_viem7.decodeFunctionData)({
2224
+ abi: import_sdk2.KernelV3_1AccountAbi,
2225
+ data: deployWithFactoryFunctionData.args[0]
2226
+ });
2227
+ }
2228
+ if (!initializeFunctionData) throw new Error("Invalid initCode");
2229
+ if (initializeFunctionData.functionName === "initialize") {
2230
+ validatorInitData = {
2231
+ validatorAddress: initializeFunctionData.args[0],
2232
+ identifier: initializeFunctionData.args[0],
2233
+ enableData: initializeFunctionData.args[2],
2234
+ initConfig: isKernelVersionAfter(kernelVersion, "0.3.1") && Array.isArray(initializeFunctionData.args[4]) ? [...initializeFunctionData.args[4]] : void 0
2235
+ };
2236
+ }
2237
+ }
2238
+ if (index === void 0 || validatorInitData === void 0)
2239
+ throw new Error("Invalid initCode");
2240
+ return { index, validatorInitData, useMetaFactory };
2241
+ };
2242
+ var getPeriodInterval = (periodUnit) => {
2243
+ switch (periodUnit) {
2244
+ case "5mins":
2245
+ return 5 * 60;
2246
+ case "day":
2247
+ return 24 * 60 * 60;
2248
+ case "week":
2249
+ return 7 * 24 * 60 * 60;
2250
+ case "month":
2251
+ return 28 * 24 * 60 * 60;
2252
+ case "year":
2253
+ return 365 * 24 * 60 * 60;
2254
+ default:
2255
+ throw new Error("Invalid period unit");
2256
+ }
2257
+ };
2258
+ var createBillingCheckoutSession = (serviceSessionparams) => __async(null, null, function* () {
2259
+ try {
2260
+ const sessionData = yield createBillingSessionAPICall(
2261
+ `${billingServiceUrl}paysession/create`,
2262
+ {
2263
+ paylinkId: serviceSessionparams.paylinkId
2012
2264
  }
2013
- });
2265
+ );
2266
+ if (sessionData) {
2267
+ return sessionData.checkoutSessionId;
2268
+ }
2269
+ } catch (error) {
2270
+ if (error instanceof Error) {
2271
+ throw new Error(error.message);
2272
+ }
2273
+ throw new Error("Failed to create deposit session.");
2014
2274
  }
2015
- createSinglePayment(servicePaymentParams) {
2016
- return __async(this, null, function* () {
2017
- try {
2018
- if (this.connectorType !== "Self-Custody" /* SELF_CUSTODY */) {
2019
- throw new Error("Only self custody payments are supported.");
2020
- }
2021
- if (!servicePaymentParams.checkoutSessionId || servicePaymentParams.checkoutSessionId === "") {
2022
- throw new Error("checkout session ID is required.");
2023
- }
2024
- const signerAddress = this.signerAddress;
2025
- const chainId = this.chainId;
2026
- const tokenSymbol = this.token;
2027
- const amount = this.amount;
2028
- const receiver = this.receiver;
2029
- const feeInclusive = this.feeInclusive;
2030
- const serviceType = this.serviceType;
2031
- const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
2032
- if (!token2) {
2033
- throw new Error("Token not supported.");
2034
- }
2035
- const rpcParameters = yield this.account.signSinglePaymentOperation({
2036
- signerAddress,
2037
- chainId,
2038
- token: tokenSymbol,
2039
- amount,
2040
- receiver,
2041
- feeInclusive,
2042
- allowMaxTokenApproval: this.allowMaxTokenApproval
2043
- });
2044
- const txn = yield executeSinglePaymentAPICall(
2045
- `${transactionServiceUrl2}execute/single`,
2046
- rpcParameters,
2047
- {
2048
- senderAddress: signerAddress,
2049
- receiverAddress: receiver,
2050
- chainId,
2051
- tokenAddress: token2.address,
2052
- amount: (0, import_viem7.toHex)(amount),
2053
- feeInclusive,
2054
- serviceType
2055
- },
2056
- servicePaymentParams
2057
- );
2058
- return txn.transaction.id;
2059
- } catch (error) {
2060
- if (error instanceof Error) {
2061
- throw new Error(error.message);
2062
- }
2063
- throw new Error("Failed to create payment.");
2064
- }
2065
- });
2275
+ });
2276
+ var getBillingPaymentSessionDetails = (serviceSessionparams) => __async(null, null, function* () {
2277
+ if (!serviceSessionparams.checkoutSessionId || serviceSessionparams.checkoutSessionId === "") {
2278
+ throw new Error("checkout session ID is required.");
2066
2279
  }
2067
- createRecurringPayments(servicePaymentParams) {
2068
- return __async(this, null, function* () {
2069
- if (this.connectorType !== "Self-Custody" /* SELF_CUSTODY */) {
2070
- throw new Error("Only self custody payments are supported.");
2071
- }
2072
- if (!servicePaymentParams.checkoutSessionId || servicePaymentParams.checkoutSessionId === "") {
2073
- throw new Error("checkout session ID is required.");
2074
- }
2075
- if (!this.walletClient) {
2076
- throw new Error("Signer is required for self custody payments.");
2077
- }
2078
- const signerAddress = this.signerAddress;
2079
- const chainId = this.chainId;
2080
- const tokenSymbol = this.token;
2081
- const amount = this.amount;
2082
- const receiver = this.receiver;
2083
- const feeInclusive = this.feeInclusive;
2084
- const count = this.count;
2085
- const intervalUnit = this.intervalUnit;
2086
- const startDate = this.startDate;
2087
- const endDate = this.endDate;
2088
- const serviceType = this.serviceType;
2089
- const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
2090
- if (!token2) {
2091
- throw new Error("Token not supported.");
2092
- }
2093
- if (!chainId || !count || !intervalUnit || !startDate || !endDate) {
2094
- throw new Error("Invalid parameters.");
2095
- }
2096
- const approval = yield this.account.signRecurringPayments({
2097
- signerAddress,
2098
- chainId,
2099
- token: tokenSymbol,
2100
- amount,
2101
- feeInclusive,
2102
- count,
2103
- intervalUnit,
2104
- startDate,
2105
- endDate,
2106
- receiver,
2107
- allowMaxTokenApproval: this.allowMaxTokenApproval
2108
- });
2109
- const txn = yield scheduleRecurringPaymentsAPICall(
2110
- `${transactionServiceUrl2}schedule/recurring`,
2111
- {
2112
- amount,
2113
- chainId,
2114
- feeInclusive,
2115
- intervalCount: count,
2116
- intervalUnit,
2117
- senderAddress: signerAddress,
2118
- receiverAddress: receiver,
2119
- tokenAddress: token2.address,
2120
- startAt: startDate,
2121
- endAt: endDate,
2122
- approval,
2123
- serviceParams: servicePaymentParams,
2124
- serviceType
2125
- }
2126
- );
2127
- return txn.recurringTransaction.id;
2280
+ const sessionData = yield fetchBillingSessionDetails(
2281
+ `${billingServiceUrl}paysession?checkoutSessionId=${serviceSessionparams.checkoutSessionId}`
2282
+ );
2283
+ return sessionData;
2284
+ });
2285
+ var cancelRecurringTransaction = (_0) => __async(null, [_0], function* ({
2286
+ serviceType,
2287
+ paymentId,
2288
+ chainId,
2289
+ walletClient
2290
+ }) {
2291
+ if (serviceType !== "billing" && serviceType !== "deposit")
2292
+ throw new Error("service is not compatible");
2293
+ const response = yield fetchRecurringTransactionWithId(
2294
+ `${serviceType === "billing" ? billingServiceUrl : depositServiceUrl2}customer/payment/recurring/info?id=${paymentId}`
2295
+ );
2296
+ if (response) {
2297
+ const viemClient = new ViemClient(chainId, walletClient);
2298
+ const account = new ActaAccount(
2299
+ chainId,
2300
+ viemClient.publicClient(),
2301
+ walletClient
2302
+ );
2303
+ console.log(`sender: ${response.senderAddress}`);
2304
+ console.log(`receiver: ${response.receiverAddress}`);
2305
+ console.log(`amountEx: ${(0, import_viem7.hexToBigInt)(response.amountExclusive)}`);
2306
+ console.log(`token: ${response.tokenAddress}`);
2307
+ const rpcParameters = yield account.signRecurringTransactionCancellation({
2308
+ signerAddress: response.senderAddress,
2309
+ receiverAddress: response.receiverAddress,
2310
+ amountExclusive: (0, import_viem7.hexToBigInt)(response.amountExclusive),
2311
+ token: response.tokenAddress
2128
2312
  });
2129
- }
2130
- getPaymentSteps() {
2131
- return __async(this, null, function* () {
2132
- const signerAddress = this.signerAddress;
2133
- const chainId = this.chainId;
2134
- const tokenSymbol = this.token;
2135
- const amount = this.amount;
2136
- const receiver = this.receiver;
2137
- const feeInclusive = this.feeInclusive;
2138
- const count = this.count;
2139
- if (!signerAddress) return ["allowance", "confirm"];
2140
- const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
2141
- if (!token2) return ["allowance", "confirm"];
2142
- const smartAccount = yield this.account.createAccount();
2143
- const { estimatedGasCostInToken, feeExclusiveAmountInToken } = yield this.account.estimateSinglePaymentGas({
2313
+ console.log(rpcParameters);
2314
+ const txn = yield cancelRecurringPaymentAPICall(
2315
+ `${transactionServiceUrl3}execute/cancel`,
2316
+ rpcParameters,
2317
+ {
2144
2318
  chainId,
2145
- amount,
2146
- feeInclusive,
2147
- receiver,
2148
- signerAddress,
2149
- token: tokenSymbol
2150
- });
2151
- const amountToTransfer = feeInclusive ? amount : feeExclusiveAmountInToken;
2152
- let paymentAmount = (amountToTransfer + estimatedGasCostInToken * BigInt(2)) * BigInt(count != null ? count : 1);
2153
- const allowance = yield this.viemClient.checkTokenAllowance(
2154
- token2,
2155
- signerAddress,
2156
- smartAccount.address
2157
- );
2158
- if (paymentAmount <= allowance) return ["confirm"];
2159
- return ["allowance", "confirm"];
2160
- });
2319
+ serviceType,
2320
+ transactionId: response.transactionServiceId
2321
+ },
2322
+ {
2323
+ servicePaymentId: response.id
2324
+ }
2325
+ );
2326
+ txn;
2161
2327
  }
2162
- };
2328
+ });
2163
2329
  // Annotate the CommonJS export names for ESM import in node:
2164
2330
  0 && (module.exports = {
2165
2331
  ActaAccount,
@@ -2189,6 +2355,8 @@ var ActaBilling = class {
2189
2355
  bscUSDT,
2190
2356
  bscWBNB,
2191
2357
  bytesToBase64,
2358
+ cancelRecurringPaymentAPICall,
2359
+ cancelRecurringTransaction,
2192
2360
  createBillingCheckoutSession,
2193
2361
  createBillingSessionAPICall,
2194
2362
  createPolicyFromParams,
@@ -2204,6 +2372,7 @@ var ActaBilling = class {
2204
2372
  ethereumWETH,
2205
2373
  executeSinglePaymentAPICall,
2206
2374
  fetchBillingSessionDetails,
2375
+ fetchRecurringTransactionWithId,
2207
2376
  getBillingPaymentSessionDetails,
2208
2377
  getChainById,
2209
2378
  getChainExplorerByChainId,
@@ -2233,7 +2402,6 @@ var ActaBilling = class {
2233
2402
  polygonWPOL,
2234
2403
  scheduleRecurringPaymentsAPICall,
2235
2404
  sendRequest,
2236
- serializePermissionAccount,
2237
2405
  serializePermissionAccountParams,
2238
2406
  supportedChains,
2239
2407
  supportedTokensByChain,