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