@actalink/commonlib 0.0.11 → 0.0.12
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 +449 -23
- package/dist/index.d.cts +4925 -1541
- package/dist/index.d.ts +4925 -1541
- package/dist/index.js +429 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -58,6 +58,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
58
58
|
var index_exports = {};
|
|
59
59
|
__export(index_exports, {
|
|
60
60
|
ActaAccount: () => ActaAccount,
|
|
61
|
+
ActaBatch: () => ActaBatch,
|
|
61
62
|
ActaBilling: () => ActaBilling,
|
|
62
63
|
ActaDeposit: () => ActaDeposit,
|
|
63
64
|
ConnectorType: () => ConnectorType,
|
|
@@ -86,6 +87,7 @@ __export(index_exports, {
|
|
|
86
87
|
bytesToBase64: () => bytesToBase64,
|
|
87
88
|
cancelRecurringPaymentAPICall: () => cancelRecurringPaymentAPICall,
|
|
88
89
|
cancelRecurringTransaction: () => cancelRecurringTransaction,
|
|
90
|
+
createBatchSessionAPICall: () => createBatchSessionAPICall,
|
|
89
91
|
createBillingCheckoutSession: () => createBillingCheckoutSession,
|
|
90
92
|
createBillingSessionAPICall: () => createBillingSessionAPICall,
|
|
91
93
|
createPolicyFromParams: () => createPolicyFromParams,
|
|
@@ -99,7 +101,9 @@ __export(index_exports, {
|
|
|
99
101
|
ethereumUSDC: () => ethereumUSDC,
|
|
100
102
|
ethereumUSDT: () => ethereumUSDT,
|
|
101
103
|
ethereumWETH: () => ethereumWETH,
|
|
104
|
+
executeSingleBatchPaymentAPICall: () => executeSingleBatchPaymentAPICall,
|
|
102
105
|
executeSinglePaymentAPICall: () => executeSinglePaymentAPICall,
|
|
106
|
+
fetchBatchInstructionDetails: () => fetchBatchInstructionDetails,
|
|
103
107
|
fetchBillingSessionDetails: () => fetchBillingSessionDetails,
|
|
104
108
|
fetchRecurringTransactionWithId: () => fetchRecurringTransactionWithId,
|
|
105
109
|
getBillingPaymentSessionDetails: () => getBillingPaymentSessionDetails,
|
|
@@ -873,6 +877,83 @@ var ActaAccount = class {
|
|
|
873
877
|
};
|
|
874
878
|
});
|
|
875
879
|
}
|
|
880
|
+
estimateSingleBatchPaymentGas(parameters) {
|
|
881
|
+
return __async(this, null, function* () {
|
|
882
|
+
const {
|
|
883
|
+
signerAddress,
|
|
884
|
+
chainId,
|
|
885
|
+
token: tokenSymbol,
|
|
886
|
+
receivers,
|
|
887
|
+
feeInclusive,
|
|
888
|
+
walletClient,
|
|
889
|
+
totalAmount
|
|
890
|
+
} = parameters;
|
|
891
|
+
if (totalAmount <= BigInt(0)) {
|
|
892
|
+
throw new Error("Amount must be greater than 0.");
|
|
893
|
+
}
|
|
894
|
+
if (receivers.length === 0) {
|
|
895
|
+
throw new Error("Receivers not found for batch payment");
|
|
896
|
+
}
|
|
897
|
+
const account = yield this.createAccount();
|
|
898
|
+
const { accountClient, pimlicoClient } = yield this.createAccountHelpers();
|
|
899
|
+
const fromAddress = signerAddress;
|
|
900
|
+
const smartAccountAddress = account.address;
|
|
901
|
+
const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
|
|
902
|
+
if (!token2) {
|
|
903
|
+
throw new Error("Token not found.");
|
|
904
|
+
}
|
|
905
|
+
console.log(`fromAddress: ${fromAddress}`);
|
|
906
|
+
const quotes = yield pimlicoClient.getTokenQuotes({
|
|
907
|
+
tokens: [token2.address],
|
|
908
|
+
chain: getChainById(chainId)
|
|
909
|
+
});
|
|
910
|
+
const { postOpGas, exchangeRate, paymaster } = quotes[0];
|
|
911
|
+
console.log("preparing");
|
|
912
|
+
console.log(token2.address);
|
|
913
|
+
const receiversData = receivers.map((r) => {
|
|
914
|
+
return {
|
|
915
|
+
to: (0, import_viem3.getAddress)(token2.address),
|
|
916
|
+
abi: (0, import_viem3.parseAbi)(["function transferFrom(address,address,uint)"]),
|
|
917
|
+
functionName: "transferFrom",
|
|
918
|
+
args: [fromAddress, r.address, BigInt(0)]
|
|
919
|
+
};
|
|
920
|
+
});
|
|
921
|
+
console.log(receiversData);
|
|
922
|
+
const userOperation = yield accountClient.prepareUserOperation({
|
|
923
|
+
calls: [
|
|
924
|
+
...receiversData,
|
|
925
|
+
{
|
|
926
|
+
to: (0, import_viem3.getAddress)(token2.address),
|
|
927
|
+
abi: (0, import_viem3.parseAbi)(["function transferFrom(address,address,uint)"]),
|
|
928
|
+
functionName: "transferFrom",
|
|
929
|
+
args: [
|
|
930
|
+
fromAddress,
|
|
931
|
+
"0xC4910E5ec82Da0A41aF9C6360b7A1f531e1e37B0",
|
|
932
|
+
BigInt(0)
|
|
933
|
+
]
|
|
934
|
+
}
|
|
935
|
+
]
|
|
936
|
+
});
|
|
937
|
+
const userOperationMaxGas = userOperation.preVerificationGas + userOperation.callGasLimit + userOperation.verificationGasLimit + (userOperation.paymasterPostOpGasLimit || BigInt(0)) + (userOperation.paymasterVerificationGasLimit || BigInt(0));
|
|
938
|
+
const userOperationMaxCost = BigInt(
|
|
939
|
+
userOperationMaxGas * userOperation.maxFeePerGas
|
|
940
|
+
);
|
|
941
|
+
const estimatedGasCostInToken = (userOperationMaxCost + postOpGas * userOperation.maxFeePerGas) * exchangeRate / BigInt(1e18);
|
|
942
|
+
const ActalinkFeesInToken = totalAmount * BigInt(20) / BigInt(1e4);
|
|
943
|
+
const estimatedTotalFeesInToken = estimatedGasCostInToken + ActalinkFeesInToken;
|
|
944
|
+
const feeInclusiveAmountInToken = totalAmount - estimatedTotalFeesInToken;
|
|
945
|
+
const feeExclusiveAmountInToken = totalAmount + estimatedTotalFeesInToken;
|
|
946
|
+
return {
|
|
947
|
+
estimatedGasCostInToken,
|
|
948
|
+
ActalinkFeesInToken,
|
|
949
|
+
estimatedTotalFeesInToken,
|
|
950
|
+
feeInclusiveAmountInToken,
|
|
951
|
+
feeExclusiveAmountInToken,
|
|
952
|
+
paymaster,
|
|
953
|
+
userOperation
|
|
954
|
+
};
|
|
955
|
+
});
|
|
956
|
+
}
|
|
876
957
|
signSinglePaymentOperation(singlePaymentParams) {
|
|
877
958
|
return __async(this, null, function* () {
|
|
878
959
|
try {
|
|
@@ -961,6 +1042,102 @@ var ActaAccount = class {
|
|
|
961
1042
|
}
|
|
962
1043
|
});
|
|
963
1044
|
}
|
|
1045
|
+
signSingleBatchOperation(singlePaymentParams) {
|
|
1046
|
+
return __async(this, null, function* () {
|
|
1047
|
+
try {
|
|
1048
|
+
if (!this.signer) {
|
|
1049
|
+
throw new Error("Signer is required for self custody payments.");
|
|
1050
|
+
}
|
|
1051
|
+
const {
|
|
1052
|
+
signerAddress,
|
|
1053
|
+
chainId,
|
|
1054
|
+
token: tokenSymbol,
|
|
1055
|
+
receivers,
|
|
1056
|
+
feeInclusive,
|
|
1057
|
+
allowMaxTokenApproval,
|
|
1058
|
+
totalAmount,
|
|
1059
|
+
walletClient
|
|
1060
|
+
} = singlePaymentParams;
|
|
1061
|
+
if (totalAmount <= BigInt(0)) {
|
|
1062
|
+
throw new Error("Amount must be greater than 0.");
|
|
1063
|
+
}
|
|
1064
|
+
if (receivers.length === 0) {
|
|
1065
|
+
throw new Error("Receivers not found for batch payment");
|
|
1066
|
+
}
|
|
1067
|
+
const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
|
|
1068
|
+
if (!token2) {
|
|
1069
|
+
throw new Error("Token not found.");
|
|
1070
|
+
}
|
|
1071
|
+
const viemClient = new ViemClient(this.chainId, this.signer);
|
|
1072
|
+
console.log("validating gas");
|
|
1073
|
+
console.log(receivers);
|
|
1074
|
+
const {
|
|
1075
|
+
estimatedGasCostInToken,
|
|
1076
|
+
ActalinkFeesInToken,
|
|
1077
|
+
feeInclusiveAmountInToken,
|
|
1078
|
+
feeExclusiveAmountInToken,
|
|
1079
|
+
estimatedTotalFeesInToken,
|
|
1080
|
+
paymaster
|
|
1081
|
+
} = yield this.estimateSingleBatchPaymentGas({
|
|
1082
|
+
signerAddress,
|
|
1083
|
+
chainId,
|
|
1084
|
+
token: tokenSymbol,
|
|
1085
|
+
receivers,
|
|
1086
|
+
feeInclusive,
|
|
1087
|
+
totalAmount,
|
|
1088
|
+
walletClient
|
|
1089
|
+
});
|
|
1090
|
+
const account = yield this.createAccount();
|
|
1091
|
+
const { accountClient } = yield this.createAccountHelpers();
|
|
1092
|
+
const fromAddress = signerAddress;
|
|
1093
|
+
const smartAccountAddress = account.address;
|
|
1094
|
+
const amountToTransfer = feeInclusive ? totalAmount : feeExclusiveAmountInToken;
|
|
1095
|
+
const receiverAmount = feeInclusive ? feeInclusiveAmountInToken : totalAmount;
|
|
1096
|
+
console.log("checking approval");
|
|
1097
|
+
yield viemClient.checkAndApproveToken(
|
|
1098
|
+
token2,
|
|
1099
|
+
smartAccountAddress,
|
|
1100
|
+
amountToTransfer,
|
|
1101
|
+
allowMaxTokenApproval != null ? allowMaxTokenApproval : false
|
|
1102
|
+
);
|
|
1103
|
+
const receiversData = receivers.map((r) => {
|
|
1104
|
+
return {
|
|
1105
|
+
to: (0, import_viem3.getAddress)(token2.address),
|
|
1106
|
+
abi: (0, import_viem3.parseAbi)(["function transferFrom(address,address,uint)"]),
|
|
1107
|
+
functionName: "transferFrom",
|
|
1108
|
+
args: [fromAddress, r.address, r.amount]
|
|
1109
|
+
};
|
|
1110
|
+
});
|
|
1111
|
+
const userOperation = yield accountClient.prepareUserOperation({
|
|
1112
|
+
calls: [
|
|
1113
|
+
...receiversData,
|
|
1114
|
+
{
|
|
1115
|
+
to: (0, import_viem3.getAddress)(token2.address),
|
|
1116
|
+
abi: (0, import_viem3.parseAbi)(["function transferFrom(address,address,uint)"]),
|
|
1117
|
+
functionName: "transferFrom",
|
|
1118
|
+
args: [
|
|
1119
|
+
fromAddress,
|
|
1120
|
+
"0xC4910E5ec82Da0A41aF9C6360b7A1f531e1e37B0",
|
|
1121
|
+
estimatedGasCostInToken
|
|
1122
|
+
]
|
|
1123
|
+
}
|
|
1124
|
+
]
|
|
1125
|
+
});
|
|
1126
|
+
const signature = yield account.signUserOperation(__spreadProps(__spreadValues({}, userOperation), {
|
|
1127
|
+
chainId: this.chainId
|
|
1128
|
+
}));
|
|
1129
|
+
const rpcParameters = (0, import_account_abstraction.formatUserOperationRequest)(__spreadProps(__spreadValues({}, userOperation), {
|
|
1130
|
+
signature
|
|
1131
|
+
}));
|
|
1132
|
+
return rpcParameters;
|
|
1133
|
+
} catch (error) {
|
|
1134
|
+
if (error instanceof Error) {
|
|
1135
|
+
throw new Error(error.message);
|
|
1136
|
+
}
|
|
1137
|
+
throw new Error("Failed to sign single payment operation.");
|
|
1138
|
+
}
|
|
1139
|
+
});
|
|
1140
|
+
}
|
|
964
1141
|
signRecurringPayments(recurringPaymentParams) {
|
|
965
1142
|
return __async(this, null, function* () {
|
|
966
1143
|
if (!this.signer) {
|
|
@@ -1321,6 +1498,24 @@ function executeSinglePaymentAPICall(url, userOperation, paymentParams, serviceP
|
|
|
1321
1498
|
return response.data;
|
|
1322
1499
|
});
|
|
1323
1500
|
}
|
|
1501
|
+
function executeSingleBatchPaymentAPICall(url, APIKey, userOperation, paymentParams, serviceParams) {
|
|
1502
|
+
return __async(this, null, function* () {
|
|
1503
|
+
const params = {
|
|
1504
|
+
userOperation,
|
|
1505
|
+
paymentParams,
|
|
1506
|
+
serviceParams
|
|
1507
|
+
};
|
|
1508
|
+
const response = yield sendRequest({
|
|
1509
|
+
url,
|
|
1510
|
+
method: "post" /* Post */,
|
|
1511
|
+
body: params,
|
|
1512
|
+
headers: {
|
|
1513
|
+
"x-api-key": APIKey
|
|
1514
|
+
}
|
|
1515
|
+
});
|
|
1516
|
+
return response.data;
|
|
1517
|
+
});
|
|
1518
|
+
}
|
|
1324
1519
|
function fetchRecurringTransactionWithId(url) {
|
|
1325
1520
|
return __async(this, null, function* () {
|
|
1326
1521
|
const response = yield sendRequest({ url, method: "get" /* Get */ });
|
|
@@ -1342,6 +1537,31 @@ function cancelRecurringPaymentAPICall(url, userOperation, paymentParams, servic
|
|
|
1342
1537
|
return response.data;
|
|
1343
1538
|
});
|
|
1344
1539
|
}
|
|
1540
|
+
function createBatchSessionAPICall(url, APIKey, params) {
|
|
1541
|
+
return __async(this, null, function* () {
|
|
1542
|
+
const response = yield sendRequest({
|
|
1543
|
+
url,
|
|
1544
|
+
method: "post" /* Post */,
|
|
1545
|
+
body: params,
|
|
1546
|
+
headers: {
|
|
1547
|
+
"x-api-key": APIKey
|
|
1548
|
+
}
|
|
1549
|
+
});
|
|
1550
|
+
return response.data;
|
|
1551
|
+
});
|
|
1552
|
+
}
|
|
1553
|
+
function fetchBatchInstructionDetails(url, APIKey) {
|
|
1554
|
+
return __async(this, null, function* () {
|
|
1555
|
+
const response = yield sendRequest({
|
|
1556
|
+
url,
|
|
1557
|
+
method: "get" /* Get */,
|
|
1558
|
+
headers: {
|
|
1559
|
+
"x-api-key": APIKey
|
|
1560
|
+
}
|
|
1561
|
+
});
|
|
1562
|
+
return response.data;
|
|
1563
|
+
});
|
|
1564
|
+
}
|
|
1345
1565
|
|
|
1346
1566
|
// src/deposit.ts
|
|
1347
1567
|
var transactionServiceUrl = "https://api.acta.link/transaction/v1/";
|
|
@@ -1906,10 +2126,212 @@ var ActaBilling = class {
|
|
|
1906
2126
|
}
|
|
1907
2127
|
};
|
|
1908
2128
|
|
|
2129
|
+
// src/batch.ts
|
|
2130
|
+
var import_viem7 = require("viem");
|
|
2131
|
+
var batchServiceUrl = "http://localhost:4000/batch/api/v1/";
|
|
2132
|
+
var ActaBatch = class {
|
|
2133
|
+
constructor(parameters) {
|
|
2134
|
+
this.APIkey = parameters.APIKey;
|
|
2135
|
+
}
|
|
2136
|
+
createSession(params) {
|
|
2137
|
+
return __async(this, null, function* () {
|
|
2138
|
+
try {
|
|
2139
|
+
const { instructionId, name, signerAddress, token: token2, chainId } = params;
|
|
2140
|
+
if (!signerAddress || signerAddress === import_viem7.zeroAddress) {
|
|
2141
|
+
throw new Error("Signer address is required.");
|
|
2142
|
+
}
|
|
2143
|
+
if (!name || name === "") {
|
|
2144
|
+
throw new Error("Name of Batch payment is required");
|
|
2145
|
+
}
|
|
2146
|
+
if (!token2) {
|
|
2147
|
+
throw new Error("Token symbol is required");
|
|
2148
|
+
}
|
|
2149
|
+
if (!instructionId || instructionId === "") {
|
|
2150
|
+
throw new Error("Instruction id is required");
|
|
2151
|
+
}
|
|
2152
|
+
const session = yield createBatchSessionAPICall(
|
|
2153
|
+
`${batchServiceUrl}create/session`,
|
|
2154
|
+
this.APIkey,
|
|
2155
|
+
{
|
|
2156
|
+
name,
|
|
2157
|
+
chainId,
|
|
2158
|
+
instructionId,
|
|
2159
|
+
signerAddress,
|
|
2160
|
+
token: token2
|
|
2161
|
+
}
|
|
2162
|
+
);
|
|
2163
|
+
console.log(session);
|
|
2164
|
+
const sessionId = session.id;
|
|
2165
|
+
return sessionId;
|
|
2166
|
+
} catch (error) {
|
|
2167
|
+
if (error instanceof Error) {
|
|
2168
|
+
throw new Error(error.message);
|
|
2169
|
+
}
|
|
2170
|
+
throw new Error("Failed to create session.");
|
|
2171
|
+
}
|
|
2172
|
+
});
|
|
2173
|
+
}
|
|
2174
|
+
estimateSinglePaymentGas(parameters) {
|
|
2175
|
+
return __async(this, null, function* () {
|
|
2176
|
+
try {
|
|
2177
|
+
const {
|
|
2178
|
+
chainId,
|
|
2179
|
+
feeInclusive,
|
|
2180
|
+
signerAddress,
|
|
2181
|
+
token: token2,
|
|
2182
|
+
walletClient,
|
|
2183
|
+
instructionId
|
|
2184
|
+
} = parameters;
|
|
2185
|
+
const instuctionData = yield fetchBatchInstructionDetails(
|
|
2186
|
+
`${batchServiceUrl}instruction/${instructionId}`,
|
|
2187
|
+
this.APIkey
|
|
2188
|
+
);
|
|
2189
|
+
if (instuctionData.receivers.length === 0 || instuctionData.receivers.length === void 0) {
|
|
2190
|
+
throw new Error("Instruction not found");
|
|
2191
|
+
}
|
|
2192
|
+
const tokenData = getTokenByChainIdAndSymbol(chainId, token2);
|
|
2193
|
+
if (!tokenData) {
|
|
2194
|
+
throw new Error("Token not supported");
|
|
2195
|
+
}
|
|
2196
|
+
const totalAmount = instuctionData.totalAmount;
|
|
2197
|
+
const totalAmountParsed = BigInt(
|
|
2198
|
+
(0, import_viem7.parseUnits)(totalAmount, tokenData.decimals)
|
|
2199
|
+
);
|
|
2200
|
+
const receivers = instuctionData.receivers.map(
|
|
2201
|
+
(i) => {
|
|
2202
|
+
const receiver = (0, import_viem7.getAddress)(i.address);
|
|
2203
|
+
const tokenAmount = BigInt((0, import_viem7.parseUnits)(i.amount, tokenData.decimals));
|
|
2204
|
+
return {
|
|
2205
|
+
address: receiver,
|
|
2206
|
+
amount: tokenAmount
|
|
2207
|
+
};
|
|
2208
|
+
}
|
|
2209
|
+
);
|
|
2210
|
+
const viemClient = new ViemClient(chainId, walletClient);
|
|
2211
|
+
const account = new ActaAccount(
|
|
2212
|
+
chainId,
|
|
2213
|
+
viemClient.publicClient(),
|
|
2214
|
+
walletClient
|
|
2215
|
+
);
|
|
2216
|
+
const {
|
|
2217
|
+
estimatedGasCostInToken,
|
|
2218
|
+
ActalinkFeesInToken,
|
|
2219
|
+
feeInclusiveAmountInToken,
|
|
2220
|
+
feeExclusiveAmountInToken,
|
|
2221
|
+
estimatedTotalFeesInToken,
|
|
2222
|
+
paymaster,
|
|
2223
|
+
userOperation
|
|
2224
|
+
} = yield account.estimateSingleBatchPaymentGas({
|
|
2225
|
+
chainId,
|
|
2226
|
+
feeInclusive,
|
|
2227
|
+
signerAddress,
|
|
2228
|
+
token: token2,
|
|
2229
|
+
walletClient,
|
|
2230
|
+
receivers,
|
|
2231
|
+
totalAmount: totalAmountParsed
|
|
2232
|
+
});
|
|
2233
|
+
return {
|
|
2234
|
+
estimatedGasCostInToken,
|
|
2235
|
+
ActalinkFeesInToken,
|
|
2236
|
+
feeInclusiveAmountInToken,
|
|
2237
|
+
feeExclusiveAmountInToken,
|
|
2238
|
+
estimatedTotalFeesInToken,
|
|
2239
|
+
paymaster,
|
|
2240
|
+
userOperation
|
|
2241
|
+
};
|
|
2242
|
+
} catch (error) {
|
|
2243
|
+
if (error instanceof Error) {
|
|
2244
|
+
throw new Error(error.message);
|
|
2245
|
+
}
|
|
2246
|
+
throw new Error("Failed to estimate single payment gas.");
|
|
2247
|
+
}
|
|
2248
|
+
});
|
|
2249
|
+
}
|
|
2250
|
+
createSingleBatchPayment(params, serviceParams) {
|
|
2251
|
+
return __async(this, null, function* () {
|
|
2252
|
+
try {
|
|
2253
|
+
const {
|
|
2254
|
+
chainId,
|
|
2255
|
+
feeInclusive,
|
|
2256
|
+
signerAddress,
|
|
2257
|
+
token: tokenSymbol,
|
|
2258
|
+
walletClient,
|
|
2259
|
+
allowMaxTokenApproval,
|
|
2260
|
+
instructionId
|
|
2261
|
+
} = params;
|
|
2262
|
+
const instuctionData = yield fetchBatchInstructionDetails(
|
|
2263
|
+
`${batchServiceUrl}instruction/${instructionId}`,
|
|
2264
|
+
this.APIkey
|
|
2265
|
+
);
|
|
2266
|
+
if (instuctionData.receivers.length === 0 || instuctionData.receivers.length === void 0) {
|
|
2267
|
+
throw new Error("Instruction not found");
|
|
2268
|
+
}
|
|
2269
|
+
console.log(instuctionData);
|
|
2270
|
+
const tokenData = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
|
|
2271
|
+
if (!tokenData) {
|
|
2272
|
+
throw new Error("Token not supported");
|
|
2273
|
+
}
|
|
2274
|
+
const totalAmount = instuctionData.totalAmount;
|
|
2275
|
+
const totalAmountParsed = BigInt(
|
|
2276
|
+
(0, import_viem7.parseUnits)(totalAmount, tokenData.decimals)
|
|
2277
|
+
);
|
|
2278
|
+
const receivers = instuctionData.receivers.map(
|
|
2279
|
+
(i) => {
|
|
2280
|
+
const receiver = (0, import_viem7.getAddress)(i.address);
|
|
2281
|
+
const tokenAmount = BigInt((0, import_viem7.parseUnits)(i.amount, tokenData.decimals));
|
|
2282
|
+
return {
|
|
2283
|
+
address: receiver,
|
|
2284
|
+
amount: tokenAmount
|
|
2285
|
+
};
|
|
2286
|
+
}
|
|
2287
|
+
);
|
|
2288
|
+
const viemClient = new ViemClient(chainId, walletClient);
|
|
2289
|
+
const account = new ActaAccount(
|
|
2290
|
+
chainId,
|
|
2291
|
+
viemClient.publicClient(),
|
|
2292
|
+
walletClient
|
|
2293
|
+
);
|
|
2294
|
+
console.log("signing");
|
|
2295
|
+
const rpcParameters = yield account.signSingleBatchOperation({
|
|
2296
|
+
signerAddress,
|
|
2297
|
+
chainId,
|
|
2298
|
+
token: tokenSymbol,
|
|
2299
|
+
feeInclusive,
|
|
2300
|
+
receivers,
|
|
2301
|
+
totalAmount: totalAmountParsed,
|
|
2302
|
+
walletClient,
|
|
2303
|
+
allowMaxTokenApproval
|
|
2304
|
+
});
|
|
2305
|
+
const txn = yield executeSingleBatchPaymentAPICall(
|
|
2306
|
+
`${batchServiceUrl}execute/single/batch`,
|
|
2307
|
+
this.APIkey,
|
|
2308
|
+
rpcParameters,
|
|
2309
|
+
{
|
|
2310
|
+
senderAddress: signerAddress,
|
|
2311
|
+
chainId,
|
|
2312
|
+
tokenAddress: tokenData.address,
|
|
2313
|
+
amount: (0, import_viem7.toHex)(totalAmountParsed),
|
|
2314
|
+
feeInclusive,
|
|
2315
|
+
serviceType: "batch"
|
|
2316
|
+
},
|
|
2317
|
+
serviceParams
|
|
2318
|
+
);
|
|
2319
|
+
console.log(txn);
|
|
2320
|
+
return txn.transaction.id;
|
|
2321
|
+
} catch (error) {
|
|
2322
|
+
if (error instanceof Error) {
|
|
2323
|
+
throw new Error(error.message);
|
|
2324
|
+
}
|
|
2325
|
+
throw new Error("Failed to create payment.");
|
|
2326
|
+
}
|
|
2327
|
+
});
|
|
2328
|
+
}
|
|
2329
|
+
};
|
|
2330
|
+
|
|
1909
2331
|
// src/utils.ts
|
|
1910
2332
|
var import_sdk2 = require("@zerodev/sdk");
|
|
1911
2333
|
var import_accounts = require("@zerodev/sdk/accounts");
|
|
1912
|
-
var
|
|
2334
|
+
var import_viem8 = require("viem");
|
|
1913
2335
|
var import_accounts2 = require("viem/accounts");
|
|
1914
2336
|
var import_actions = require("viem/actions");
|
|
1915
2337
|
var import_utils2 = require("viem/utils");
|
|
@@ -1921,9 +2343,9 @@ var billingServiceUrl = "https://api.acta.link/billing/v1/";
|
|
|
1921
2343
|
var depositServiceUrl2 = "https://api.acta.link/deposit/v1/";
|
|
1922
2344
|
var transactionServiceUrl3 = "https://api.acta.link/transaction/v1/";
|
|
1923
2345
|
var toSignerId = (signer) => {
|
|
1924
|
-
return (0,
|
|
2346
|
+
return (0, import_viem8.encodeAbiParameters)(
|
|
1925
2347
|
[{ name: "signerData", type: "bytes" }],
|
|
1926
|
-
[(0,
|
|
2348
|
+
[(0, import_viem8.concat)([signer.signerContractAddress, signer.getSignerData()])]
|
|
1927
2349
|
);
|
|
1928
2350
|
};
|
|
1929
2351
|
function toECDSASigner2(_0) {
|
|
@@ -1960,11 +2382,11 @@ function toECDSASigner2(_0) {
|
|
|
1960
2382
|
});
|
|
1961
2383
|
}
|
|
1962
2384
|
var toPolicyId = (policies) => {
|
|
1963
|
-
return (0,
|
|
2385
|
+
return (0, import_viem8.encodeAbiParameters)(
|
|
1964
2386
|
[{ name: "policiesData", type: "bytes[]" }],
|
|
1965
2387
|
[
|
|
1966
2388
|
policies.map(
|
|
1967
|
-
(policy) => (0,
|
|
2389
|
+
(policy) => (0, import_viem8.concat)([policy.getPolicyInfoInBytes(), policy.getPolicyData()])
|
|
1968
2390
|
)
|
|
1969
2391
|
]
|
|
1970
2392
|
);
|
|
@@ -1982,38 +2404,38 @@ function toPermissionValidator2(_0, _1) {
|
|
|
1982
2404
|
throw new Error("Only EntryPoint 0.7 is supported");
|
|
1983
2405
|
}
|
|
1984
2406
|
const getEnableData = (_kernelAccountAddress) => __async(null, null, function* () {
|
|
1985
|
-
const enableData = (0,
|
|
2407
|
+
const enableData = (0, import_viem8.encodeAbiParameters)(
|
|
1986
2408
|
[{ name: "policyAndSignerData", type: "bytes[]" }],
|
|
1987
2409
|
[
|
|
1988
2410
|
[
|
|
1989
2411
|
...policies.map(
|
|
1990
|
-
(policy) => (0,
|
|
2412
|
+
(policy) => (0, import_viem8.concat)([policy.getPolicyInfoInBytes(), policy.getPolicyData()])
|
|
1991
2413
|
),
|
|
1992
|
-
(0,
|
|
2414
|
+
(0, import_viem8.concat)([flag, signer.signerContractAddress, signer.getSignerData()])
|
|
1993
2415
|
]
|
|
1994
2416
|
]
|
|
1995
2417
|
);
|
|
1996
2418
|
return enableData;
|
|
1997
2419
|
});
|
|
1998
2420
|
const getPermissionId = () => {
|
|
1999
|
-
const pIdData = (0,
|
|
2421
|
+
const pIdData = (0, import_viem8.encodeAbiParameters)(
|
|
2000
2422
|
[{ name: "policyAndSignerData", type: "bytes[]" }],
|
|
2001
2423
|
[[toPolicyId(policies), flag, toSignerId(signer)]]
|
|
2002
2424
|
);
|
|
2003
|
-
return (0,
|
|
2425
|
+
return (0, import_viem8.slice)((0, import_viem8.keccak256)(pIdData), 0, 4);
|
|
2004
2426
|
};
|
|
2005
2427
|
return __spreadProps(__spreadValues({}, signer.account), {
|
|
2006
2428
|
supportedKernelVersions: ">=0.3.0",
|
|
2007
2429
|
validatorType: "PERMISSION",
|
|
2008
|
-
address:
|
|
2430
|
+
address: import_viem8.zeroAddress,
|
|
2009
2431
|
source: "PermissionValidator",
|
|
2010
2432
|
getEnableData,
|
|
2011
2433
|
getIdentifier: getPermissionId,
|
|
2012
2434
|
signMessage: (_02) => __async(null, [_02], function* ({ message }) {
|
|
2013
|
-
return (0,
|
|
2435
|
+
return (0, import_viem8.concat)(["0xff", yield signer.account.signMessage({ message })]);
|
|
2014
2436
|
}),
|
|
2015
2437
|
signTypedData: (typedData) => __async(null, null, function* () {
|
|
2016
|
-
return (0,
|
|
2438
|
+
return (0, import_viem8.concat)(["0xff", yield signer.account.signTypedData(typedData)]);
|
|
2017
2439
|
}),
|
|
2018
2440
|
signUserOperation: (userOperation) => __async(null, null, function* () {
|
|
2019
2441
|
const userOpHash = (0, import_account_abstraction2.getUserOperationHash)({
|
|
@@ -2027,7 +2449,7 @@ function toPermissionValidator2(_0, _1) {
|
|
|
2027
2449
|
const signature = yield signer.account.signMessage({
|
|
2028
2450
|
message: { raw: userOpHash }
|
|
2029
2451
|
});
|
|
2030
|
-
return (0,
|
|
2452
|
+
return (0, import_viem8.concat)(["0xff", signature]);
|
|
2031
2453
|
}),
|
|
2032
2454
|
getNonceKey(_accountAddress, customNonceKey) {
|
|
2033
2455
|
return __async(this, null, function* () {
|
|
@@ -2039,7 +2461,7 @@ function toPermissionValidator2(_0, _1) {
|
|
|
2039
2461
|
},
|
|
2040
2462
|
getStubSignature(_userOperation) {
|
|
2041
2463
|
return __async(this, null, function* () {
|
|
2042
|
-
return (0,
|
|
2464
|
+
return (0, import_viem8.concat)(["0xff", signer.getDummySignature()]);
|
|
2043
2465
|
});
|
|
2044
2466
|
},
|
|
2045
2467
|
getPluginSerializationParams: () => {
|
|
@@ -2176,12 +2598,12 @@ var decodeParamsFromInitCode = (initCode, kernelVersion) => {
|
|
|
2176
2598
|
};
|
|
2177
2599
|
}
|
|
2178
2600
|
try {
|
|
2179
|
-
deployWithFactoryFunctionData = (0,
|
|
2601
|
+
deployWithFactoryFunctionData = (0, import_viem8.decodeFunctionData)({
|
|
2180
2602
|
abi: import_sdk2.KernelFactoryStakerAbi,
|
|
2181
2603
|
data: initCode
|
|
2182
2604
|
});
|
|
2183
2605
|
} catch (error) {
|
|
2184
|
-
deployWithFactoryFunctionData = (0,
|
|
2606
|
+
deployWithFactoryFunctionData = (0, import_viem8.decodeFunctionData)({
|
|
2185
2607
|
abi: import_sdk2.KernelV3FactoryAbi,
|
|
2186
2608
|
data: initCode
|
|
2187
2609
|
});
|
|
@@ -2192,12 +2614,12 @@ var decodeParamsFromInitCode = (initCode, kernelVersion) => {
|
|
|
2192
2614
|
index = BigInt(deployWithFactoryFunctionData.args[2]);
|
|
2193
2615
|
let initializeFunctionData;
|
|
2194
2616
|
if (kernelVersion === "0.3.0") {
|
|
2195
|
-
initializeFunctionData = (0,
|
|
2617
|
+
initializeFunctionData = (0, import_viem8.decodeFunctionData)({
|
|
2196
2618
|
abi: import_sdk2.KernelV3AccountAbi,
|
|
2197
2619
|
data: deployWithFactoryFunctionData.args[1]
|
|
2198
2620
|
});
|
|
2199
2621
|
} else {
|
|
2200
|
-
initializeFunctionData = (0,
|
|
2622
|
+
initializeFunctionData = (0, import_viem8.decodeFunctionData)({
|
|
2201
2623
|
abi: import_sdk2.KernelV3_1AccountAbi,
|
|
2202
2624
|
data: deployWithFactoryFunctionData.args[1]
|
|
2203
2625
|
});
|
|
@@ -2215,12 +2637,12 @@ var decodeParamsFromInitCode = (initCode, kernelVersion) => {
|
|
|
2215
2637
|
index = BigInt(deployWithFactoryFunctionData.args[1]);
|
|
2216
2638
|
let initializeFunctionData;
|
|
2217
2639
|
if (kernelVersion === "0.3.0") {
|
|
2218
|
-
initializeFunctionData = (0,
|
|
2640
|
+
initializeFunctionData = (0, import_viem8.decodeFunctionData)({
|
|
2219
2641
|
abi: import_sdk2.KernelV3AccountAbi,
|
|
2220
2642
|
data: deployWithFactoryFunctionData.args[0]
|
|
2221
2643
|
});
|
|
2222
2644
|
} else {
|
|
2223
|
-
initializeFunctionData = (0,
|
|
2645
|
+
initializeFunctionData = (0, import_viem8.decodeFunctionData)({
|
|
2224
2646
|
abi: import_sdk2.KernelV3_1AccountAbi,
|
|
2225
2647
|
data: deployWithFactoryFunctionData.args[0]
|
|
2226
2648
|
});
|
|
@@ -2308,12 +2730,12 @@ var cancelRecurringTransaction = (_0) => __async(null, [_0], function* ({
|
|
|
2308
2730
|
);
|
|
2309
2731
|
console.log(`sender: ${response.senderAddress}`);
|
|
2310
2732
|
console.log(`receiver: ${response.receiverAddress}`);
|
|
2311
|
-
console.log(`amountEx: ${(0,
|
|
2733
|
+
console.log(`amountEx: ${(0, import_viem8.hexToBigInt)(response.amountExclusive)}`);
|
|
2312
2734
|
console.log(`token: ${response.tokenAddress}`);
|
|
2313
2735
|
const rpcParameters = yield account.signRecurringTransactionCancellation({
|
|
2314
2736
|
signerAddress: response.senderAddress,
|
|
2315
2737
|
receiverAddress: response.receiverAddress,
|
|
2316
|
-
amountExclusive: (0,
|
|
2738
|
+
amountExclusive: (0, import_viem8.hexToBigInt)(response.amountExclusive),
|
|
2317
2739
|
token: response.tokenAddress
|
|
2318
2740
|
});
|
|
2319
2741
|
console.log(rpcParameters);
|
|
@@ -2335,6 +2757,7 @@ var cancelRecurringTransaction = (_0) => __async(null, [_0], function* ({
|
|
|
2335
2757
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2336
2758
|
0 && (module.exports = {
|
|
2337
2759
|
ActaAccount,
|
|
2760
|
+
ActaBatch,
|
|
2338
2761
|
ActaBilling,
|
|
2339
2762
|
ActaDeposit,
|
|
2340
2763
|
ConnectorType,
|
|
@@ -2363,6 +2786,7 @@ var cancelRecurringTransaction = (_0) => __async(null, [_0], function* ({
|
|
|
2363
2786
|
bytesToBase64,
|
|
2364
2787
|
cancelRecurringPaymentAPICall,
|
|
2365
2788
|
cancelRecurringTransaction,
|
|
2789
|
+
createBatchSessionAPICall,
|
|
2366
2790
|
createBillingCheckoutSession,
|
|
2367
2791
|
createBillingSessionAPICall,
|
|
2368
2792
|
createPolicyFromParams,
|
|
@@ -2376,7 +2800,9 @@ var cancelRecurringTransaction = (_0) => __async(null, [_0], function* ({
|
|
|
2376
2800
|
ethereumUSDC,
|
|
2377
2801
|
ethereumUSDT,
|
|
2378
2802
|
ethereumWETH,
|
|
2803
|
+
executeSingleBatchPaymentAPICall,
|
|
2379
2804
|
executeSinglePaymentAPICall,
|
|
2805
|
+
fetchBatchInstructionDetails,
|
|
2380
2806
|
fetchBillingSessionDetails,
|
|
2381
2807
|
fetchRecurringTransactionWithId,
|
|
2382
2808
|
getBillingPaymentSessionDetails,
|