@actalink/commonlib 0.1.0 → 0.1.1-dev

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -565,7 +565,7 @@ function getTokenByChainIdAndAddress(chainId, address) {
565
565
  }
566
566
 
567
567
  // src/flexdeposit.ts
568
- import { toHex as toHex3, zeroAddress as zeroAddress2 } from "viem";
568
+ import { toHex as toHex3, zeroAddress as zeroAddress3 } from "viem";
569
569
 
570
570
  // src/account.ts
571
571
  import {
@@ -699,6 +699,43 @@ var ViemClient = class {
699
699
  return allowance;
700
700
  });
701
701
  }
702
+ approveToken(token2, spender, amount, allowMaxTokenApproval) {
703
+ return __async(this, null, function* () {
704
+ var _a;
705
+ if (this.walletClient === void 0) {
706
+ throw new Error("Wallet client is required");
707
+ }
708
+ const signerAddress = (_a = this.walletClient.account) == null ? void 0 : _a.address;
709
+ console.log("signerAddress", signerAddress);
710
+ if (signerAddress === void 0) {
711
+ throw new Error("Signer address is required");
712
+ }
713
+ const txn = yield this.walletClient.sendTransaction({
714
+ to: token2.address,
715
+ account: signerAddress,
716
+ chain: getChainById(token2.chainId),
717
+ value: BigInt(0),
718
+ data: encodeFunctionData({
719
+ abi: parseAbi(["function approve(address,uint)"]),
720
+ functionName: "approve",
721
+ args: [spender, allowMaxTokenApproval ? maxUint256 : amount]
722
+ })
723
+ });
724
+ return txn;
725
+ });
726
+ }
727
+ waitForTransactionReceipt(hash, blocks = 1) {
728
+ return __async(this, null, function* () {
729
+ if (this.walletClient === void 0) {
730
+ throw new Error("Wallet client is required");
731
+ }
732
+ const receipt = yield this.publicClient().waitForTransactionReceipt({
733
+ hash,
734
+ confirmations: blocks
735
+ });
736
+ return receipt;
737
+ });
738
+ }
702
739
  };
703
740
 
704
741
  // src/account.ts
@@ -1060,7 +1097,7 @@ var ActaAccount = class {
1060
1097
  };
1061
1098
  });
1062
1099
  }
1063
- signSinglePaymentOperation(singlePaymentParams) {
1100
+ estimatePaymentAmount(singlePaymentParams) {
1064
1101
  return __async(this, null, function* () {
1065
1102
  try {
1066
1103
  if (!this.signer) {
@@ -1073,7 +1110,6 @@ var ActaAccount = class {
1073
1110
  amount,
1074
1111
  receiver,
1075
1112
  feeInclusive,
1076
- allowMaxTokenApproval,
1077
1113
  feebps
1078
1114
  } = singlePaymentParams;
1079
1115
  if (amount <= BigInt(0)) {
@@ -1086,14 +1122,10 @@ var ActaAccount = class {
1086
1122
  if (!token2) {
1087
1123
  throw new Error("Token not found.");
1088
1124
  }
1089
- const viemClient = new ViemClient(this.chainId, this.signer);
1090
1125
  const {
1091
- estimatedGasCostInToken,
1092
- ActalinkFeesInToken,
1093
1126
  feeInclusiveAmountInToken,
1094
1127
  feeExclusiveAmountInToken,
1095
- estimatedTotalFeesInToken,
1096
- paymaster
1128
+ estimatedTotalFeesInToken
1097
1129
  } = yield this.estimateSinglePaymentGas({
1098
1130
  signerAddress,
1099
1131
  chainId,
@@ -1103,18 +1135,141 @@ var ActaAccount = class {
1103
1135
  feeInclusive,
1104
1136
  feebps
1105
1137
  });
1106
- const account = yield this.createAccount();
1107
- const { accountClient } = yield this.createAccountHelpers();
1108
- const fromAddress = signerAddress;
1109
- const smartAccountAddress = account.address;
1110
- const amountToTransfer = feeInclusive ? amount : feeExclusiveAmountInToken;
1138
+ const totalAmount = feeInclusive ? amount : feeExclusiveAmountInToken;
1139
+ const actalinkFees = estimatedTotalFeesInToken;
1111
1140
  const receiverAmount = feeInclusive ? feeInclusiveAmountInToken : amount;
1112
- yield viemClient.checkAndApproveToken(
1141
+ return {
1142
+ totalAmount,
1143
+ actalinkFees,
1144
+ receiverAmount
1145
+ };
1146
+ } catch (error) {
1147
+ if (error instanceof Error) {
1148
+ throw new Error(error.message);
1149
+ }
1150
+ throw new Error("Failed to estimate payment amount.");
1151
+ }
1152
+ });
1153
+ }
1154
+ checkAllowance(params) {
1155
+ return __async(this, null, function* () {
1156
+ var _a;
1157
+ try {
1158
+ if (!this.signer) {
1159
+ throw new Error("Signer is required for self custody payments.");
1160
+ }
1161
+ const { chainId, token: tokenSymbol } = params;
1162
+ const account = yield this.createAccount();
1163
+ const smartAccountAddress = yield account.getAddress();
1164
+ const owner = (_a = this.signer.account) == null ? void 0 : _a.address;
1165
+ console.log("signerAddress", owner);
1166
+ if (owner === void 0) {
1167
+ throw new Error("Signer address is required");
1168
+ }
1169
+ const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
1170
+ if (!token2) {
1171
+ throw new Error("Token not found.");
1172
+ }
1173
+ const viemClient = new ViemClient(this.chainId, this.signer);
1174
+ const allowance = yield viemClient.checkTokenAllowance(
1175
+ token2,
1176
+ owner,
1177
+ smartAccountAddress
1178
+ );
1179
+ return allowance;
1180
+ } catch (error) {
1181
+ if (error instanceof Error) {
1182
+ throw new Error(error.message);
1183
+ }
1184
+ throw new Error("Failed to check token allownace.");
1185
+ }
1186
+ });
1187
+ }
1188
+ approveToken(params) {
1189
+ return __async(this, null, function* () {
1190
+ try {
1191
+ if (!this.signer) {
1192
+ throw new Error("Signer is required for self custody payments.");
1193
+ }
1194
+ const {
1195
+ chainId,
1196
+ token: tokenSymbol,
1197
+ amount,
1198
+ allowMaxTokenApproval
1199
+ } = params;
1200
+ const account = yield this.createAccount();
1201
+ const smartAccountAddress = yield account.getAddress();
1202
+ const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
1203
+ if (!token2) {
1204
+ throw new Error("Token not found.");
1205
+ }
1206
+ const viemClient = new ViemClient(this.chainId, this.signer);
1207
+ const allowance = yield viemClient.approveToken(
1113
1208
  token2,
1114
1209
  smartAccountAddress,
1115
- amountToTransfer,
1116
- allowMaxTokenApproval != null ? allowMaxTokenApproval : false
1210
+ amount,
1211
+ allowMaxTokenApproval
1117
1212
  );
1213
+ return allowance;
1214
+ } catch (error) {
1215
+ if (error instanceof Error) {
1216
+ throw new Error(error.message);
1217
+ }
1218
+ throw new Error("Failed to approve token.");
1219
+ }
1220
+ });
1221
+ }
1222
+ waitForTransactionReceipt(params) {
1223
+ return __async(this, null, function* () {
1224
+ try {
1225
+ if (!this.signer) {
1226
+ throw new Error("Signer is required for self custody payments.");
1227
+ }
1228
+ const { chainId, hash } = params;
1229
+ if (!hash) {
1230
+ throw new Error("Hash is not provided.");
1231
+ }
1232
+ const viemClient = new ViemClient(this.chainId, this.signer);
1233
+ const receipt = yield viemClient.waitForTransactionReceipt(hash);
1234
+ return receipt;
1235
+ } catch (error) {
1236
+ if (error instanceof Error) {
1237
+ throw new Error(error.message);
1238
+ }
1239
+ throw new Error("Failed to check token allownace.");
1240
+ }
1241
+ });
1242
+ }
1243
+ signSinglePaymentOperation(singlePaymentParams) {
1244
+ return __async(this, null, function* () {
1245
+ try {
1246
+ if (!this.signer) {
1247
+ throw new Error("Signer is required for self custody payments.");
1248
+ }
1249
+ const {
1250
+ signerAddress,
1251
+ chainId,
1252
+ token: tokenSymbol,
1253
+ actalinkFees,
1254
+ receiverAmount,
1255
+ receiver
1256
+ } = singlePaymentParams;
1257
+ if (receiverAmount <= BigInt(0)) {
1258
+ throw new Error("Amount must be greater than 0.");
1259
+ }
1260
+ if (actalinkFees <= BigInt(0)) {
1261
+ throw new Error("Fees must be greater than 0.");
1262
+ }
1263
+ if (receiver === signerAddress) {
1264
+ throw new Error("Receiver cannot be the same as the signer.");
1265
+ }
1266
+ const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
1267
+ if (!token2) {
1268
+ throw new Error("Token not found.");
1269
+ }
1270
+ const account = yield this.createAccount();
1271
+ const { accountClient } = yield this.createAccountHelpers();
1272
+ const fromAddress = signerAddress;
1118
1273
  const userOperation = yield accountClient.prepareUserOperation({
1119
1274
  calls: [
1120
1275
  {
@@ -1124,7 +1279,7 @@ var ActaAccount = class {
1124
1279
  args: [
1125
1280
  fromAddress,
1126
1281
  "0x26eeCa5956Bf8C01040BAC9e6D7982a0e87F31B4",
1127
- estimatedTotalFeesInToken
1282
+ actalinkFees
1128
1283
  ]
1129
1284
  },
1130
1285
  {
@@ -1257,14 +1412,7 @@ var ActaAccount = class {
1257
1412
  chainId,
1258
1413
  token: tokenSymbol,
1259
1414
  amount,
1260
- receiver,
1261
- feeInclusive,
1262
- count,
1263
- intervalUnit,
1264
- startDate,
1265
- endDate,
1266
- allowMaxTokenApproval,
1267
- feebps
1415
+ receiver
1268
1416
  } = recurringPaymentParams;
1269
1417
  if (amount <= BigInt(0)) {
1270
1418
  throw new Error("Amount must be greater than 0.");
@@ -1275,20 +1423,14 @@ var ActaAccount = class {
1275
1423
  if (receiver === signerAddress) {
1276
1424
  throw new Error("Receiver cannot be the same as the signer.");
1277
1425
  }
1278
- if (!intervalUnit) {
1279
- throw new Error("Interval unit is required.");
1280
- }
1281
1426
  const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
1282
1427
  if (!token2) {
1283
1428
  throw new Error("Token not found.");
1284
1429
  }
1285
1430
  const kernelVersion = KERNEL_V3_1;
1286
1431
  const entryPoint = getEntryPoint("0.7");
1287
- const paymentCount = count != null ? count : 24;
1288
1432
  const account = yield this.createAccount();
1289
- const smartAccountAddress = account.address;
1290
1433
  const viemClient = new ViemClient(this.chainId, this.signer);
1291
- const { paymasterClient, pimlicoClient } = yield this.createAccountHelpers();
1292
1434
  const ecdsaValidator = yield signerToEcdsaValidator(
1293
1435
  viemClient.publicClient(),
1294
1436
  {
@@ -1300,32 +1442,7 @@ var ActaAccount = class {
1300
1442
  const sessionKeyAddress = "0xFDEed8e268D74DF71f3Db7409F8A8290FF1263ED";
1301
1443
  const emptyAccount = addressToEmptyAccount(sessionKeyAddress);
1302
1444
  const emptySessionKeySigner = yield toECDSASigner({ signer: emptyAccount });
1303
- const {
1304
- paymaster,
1305
- ActalinkFeesInToken,
1306
- feeInclusiveAmountInToken,
1307
- feeExclusiveAmountInToken,
1308
- estimatedTotalFeesInToken,
1309
- userOperation,
1310
- estimatedGasCostInToken
1311
- } = yield this.estimateSinglePaymentGas({
1312
- signerAddress,
1313
- chainId,
1314
- token: tokenSymbol,
1315
- amount,
1316
- receiver,
1317
- feeInclusive,
1318
- feebps
1319
- });
1320
- const amountToTransfer = feeInclusive ? amount : feeExclusiveAmountInToken;
1321
- const receiverAmount = feeInclusive ? feeInclusiveAmountInToken : amount;
1322
- yield viemClient.checkAndApproveToken(
1323
- token2,
1324
- smartAccountAddress,
1325
- amountToTransfer * BigInt(paymentCount) + estimatedGasCostInToken * BigInt(2) * BigInt(paymentCount),
1326
- allowMaxTokenApproval != null ? allowMaxTokenApproval : false
1327
- );
1328
- const amountExclusive = amountToTransfer + amountToTransfer / BigInt(2);
1445
+ const amountExclusive = amount + amount / BigInt(2);
1329
1446
  const callPolicy = toCallPolicy({
1330
1447
  policyVersion: CallPolicyVersion.V0_0_4,
1331
1448
  permissions: [
@@ -1872,6 +1989,7 @@ var ActaFlexDeposit = class {
1872
1989
  this.status = "not_started";
1873
1990
  this.serviceType = "deposit";
1874
1991
  this.allowMaxTokenApproval = false;
1992
+ this.feebps = 10;
1875
1993
  var _a, _b, _c;
1876
1994
  this.connectorType = parameters.connectorType;
1877
1995
  this.walletClient = parameters.walletClient;
@@ -1898,13 +2016,13 @@ var ActaFlexDeposit = class {
1898
2016
  createSession(serviceSessionparams) {
1899
2017
  return __async(this, null, function* () {
1900
2018
  try {
1901
- if (!this.signerAddress || this.signerAddress === zeroAddress2) {
2019
+ if (!this.signerAddress || this.signerAddress === zeroAddress3) {
1902
2020
  throw new Error("Signer address is required.");
1903
2021
  }
1904
2022
  if (this.paymentType !== "single" && this.paymentType !== "choose" && this.paymentType !== "recurring") {
1905
2023
  throw new Error("Invalid payment type.");
1906
2024
  }
1907
- if (!this.receiver || this.receiver === zeroAddress2) {
2025
+ if (!this.receiver || this.receiver === zeroAddress3) {
1908
2026
  throw new Error("Receiver is required.");
1909
2027
  }
1910
2028
  if (this.paymentType === "recurring" && (this.count === void 0 || this.count === 0)) {
@@ -1991,35 +2109,95 @@ var ActaFlexDeposit = class {
1991
2109
  }
1992
2110
  });
1993
2111
  }
1994
- createPayment(servicePaymentParams) {
2112
+ estimatePaymentAmount() {
2113
+ return __async(this, null, function* () {
2114
+ try {
2115
+ const signerAddress = this.signerAddress;
2116
+ const chainId = this.chainId;
2117
+ const tokenSymbol = this.token;
2118
+ const amount = this.amount;
2119
+ const receiver = this.receiver;
2120
+ const feeInclusive = this.feeInclusive;
2121
+ const feebps = this.feebps;
2122
+ const { totalAmount, actalinkFees, receiverAmount } = yield this.account.estimatePaymentAmount({
2123
+ signerAddress,
2124
+ chainId,
2125
+ token: tokenSymbol,
2126
+ amount,
2127
+ receiver,
2128
+ feeInclusive,
2129
+ feebps
2130
+ });
2131
+ return {
2132
+ totalAmount,
2133
+ actalinkFees,
2134
+ receiverAmount
2135
+ };
2136
+ } catch (error) {
2137
+ if (error instanceof Error) {
2138
+ throw new Error(error.message);
2139
+ }
2140
+ throw new Error("Failed to estimate payment amount.");
2141
+ }
2142
+ });
2143
+ }
2144
+ checkAllowance() {
1995
2145
  return __async(this, null, function* () {
1996
2146
  try {
1997
- if (this.paymentType === "single") {
1998
- const paymentParams = this.serviceType === "deposit" ? __spreadProps(__spreadValues({}, servicePaymentParams), {
1999
- depositSessionId: this.depositSessionId
2000
- }) : servicePaymentParams;
2001
- const id = yield this.createSinglePayment(paymentParams);
2002
- return id;
2003
- }
2004
- if (this.paymentType === "choose") {
2005
- }
2006
- if (this.paymentType === "recurring") {
2007
- const paymentParams = this.serviceType === "deposit" ? __spreadProps(__spreadValues({}, servicePaymentParams), {
2008
- depositSessionId: this.depositSessionId
2009
- }) : servicePaymentParams;
2010
- const id = yield this.createRecurringPayments(paymentParams);
2011
- return id;
2147
+ const chainId = this.chainId;
2148
+ const tokenSymbol = this.token;
2149
+ const allowance = yield this.account.checkAllowance({
2150
+ chainId,
2151
+ token: tokenSymbol
2152
+ });
2153
+ return allowance;
2154
+ } catch (error) {
2155
+ if (error instanceof Error) {
2156
+ throw new Error(error.message);
2012
2157
  }
2158
+ throw new Error("Failed to check token allowance.");
2159
+ }
2160
+ });
2161
+ }
2162
+ approveToken(parameters) {
2163
+ return __async(this, null, function* () {
2164
+ try {
2165
+ const chainId = this.chainId;
2166
+ const tokenSymbol = this.token;
2167
+ const { totalAmount, allowMaxTokenApproval } = parameters;
2168
+ const hash = yield this.account.approveToken({
2169
+ chainId,
2170
+ token: tokenSymbol,
2171
+ amount: totalAmount,
2172
+ allowMaxTokenApproval
2173
+ });
2174
+ return hash;
2013
2175
  } catch (error) {
2014
- this.status = "payment_failed";
2015
2176
  if (error instanceof Error) {
2016
2177
  throw new Error(error.message);
2017
2178
  }
2018
- throw new Error("Failed to create payment.");
2179
+ throw new Error("Failed to approve token.");
2180
+ }
2181
+ });
2182
+ }
2183
+ waitForTransactionReceipt(hash) {
2184
+ return __async(this, null, function* () {
2185
+ try {
2186
+ const chainId = this.chainId;
2187
+ const receipt = yield this.account.waitForTransactionReceipt({
2188
+ chainId,
2189
+ hash
2190
+ });
2191
+ return receipt;
2192
+ } catch (error) {
2193
+ if (error instanceof Error) {
2194
+ throw new Error(error.message);
2195
+ }
2196
+ throw new Error("Failed to fetch transaction receipt.");
2019
2197
  }
2020
2198
  });
2021
2199
  }
2022
- createSinglePayment(servicePaymentParams) {
2200
+ createSinglePayment(parameters, servicePaymentParams) {
2023
2201
  return __async(this, null, function* () {
2024
2202
  try {
2025
2203
  if (this.connectorType !== "Self-Custody" /* SELF_CUSTODY */) {
@@ -2031,18 +2209,12 @@ var ActaFlexDeposit = class {
2031
2209
  const signerAddress = this.signerAddress;
2032
2210
  const chainId = this.chainId;
2033
2211
  const tokenSymbol = this.token;
2034
- const amount = this.amount;
2035
2212
  const receiver = this.receiver;
2213
+ const amount = this.amount;
2036
2214
  const feeInclusive = this.feeInclusive;
2037
2215
  const serviceType = this.serviceType;
2216
+ const { actalinkFees, receiverAmount } = parameters;
2038
2217
  const { envTransactionServiceUrl, envDepositServiceUrl } = returnEnvUrl(chainId);
2039
- if (this.depositSessionId !== "") {
2040
- const session = yield verifySessionAPICall(
2041
- `${envDepositServiceUrl}verify-session?sessionId=${this.depositSessionId}`,
2042
- this.depositSessionId
2043
- );
2044
- this.depositSessionId = session.sessionId;
2045
- }
2046
2218
  const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
2047
2219
  if (!token2) {
2048
2220
  throw new Error("Token not supported.");
@@ -2051,11 +2223,9 @@ var ActaFlexDeposit = class {
2051
2223
  signerAddress,
2052
2224
  chainId,
2053
2225
  token: tokenSymbol,
2054
- amount,
2055
- receiver,
2056
- feeInclusive,
2057
- allowMaxTokenApproval: this.allowMaxTokenApproval,
2058
- feebps: 10
2226
+ actalinkFees,
2227
+ receiverAmount,
2228
+ receiver
2059
2229
  });
2060
2230
  const txn = yield executeSinglePaymentAPICall(
2061
2231
  `${envTransactionServiceUrl}execute/single`,
@@ -2143,14 +2313,7 @@ var ActaFlexDeposit = class {
2143
2313
  chainId,
2144
2314
  token: tokenSymbol,
2145
2315
  amount,
2146
- feeInclusive,
2147
- count,
2148
- intervalUnit,
2149
- startDate,
2150
- endDate,
2151
- receiver,
2152
- allowMaxTokenApproval: this.allowMaxTokenApproval,
2153
- feebps: 20
2316
+ receiver
2154
2317
  });
2155
2318
  const txn = yield scheduleRecurringPaymentsAPICall(
2156
2319
  `${envTransactionServiceUrl}schedule/recurring`,
@@ -2174,39 +2337,6 @@ var ActaFlexDeposit = class {
2174
2337
  return txn.recurringTransaction.id;
2175
2338
  });
2176
2339
  }
2177
- getPaymentSteps() {
2178
- return __async(this, null, function* () {
2179
- const signerAddress = this.signerAddress;
2180
- const chainId = this.chainId;
2181
- const tokenSymbol = this.token;
2182
- const amount = this.amount;
2183
- const receiver = this.receiver;
2184
- const feeInclusive = this.feeInclusive;
2185
- const count = this.count;
2186
- if (!signerAddress) return ["allowance", "confirm"];
2187
- const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
2188
- if (!token2) return ["allowance", "confirm"];
2189
- const smartAccount = yield this.account.createAccount();
2190
- const { estimatedGasCostInToken, feeExclusiveAmountInToken } = yield this.account.estimateSinglePaymentGas({
2191
- chainId,
2192
- amount,
2193
- feeInclusive,
2194
- receiver,
2195
- signerAddress,
2196
- token: tokenSymbol,
2197
- feebps: 10
2198
- });
2199
- const amountToTransfer = feeInclusive ? amount : feeExclusiveAmountInToken;
2200
- let paymentAmount = (amountToTransfer + estimatedGasCostInToken * BigInt(2)) * BigInt(count != null ? count : 1);
2201
- const allowance = yield this.viemClient.checkTokenAllowance(
2202
- token2,
2203
- signerAddress,
2204
- smartAccount.address
2205
- );
2206
- if (paymentAmount <= allowance) return ["confirm"];
2207
- return ["allowance", "confirm"];
2208
- });
2209
- }
2210
2340
  };
2211
2341
 
2212
2342
  // src/flexbatch.ts
@@ -2214,7 +2344,7 @@ import {
2214
2344
  getAddress as getAddress3,
2215
2345
  parseUnits,
2216
2346
  toHex as toHex4,
2217
- zeroAddress as zeroAddress3
2347
+ zeroAddress as zeroAddress4
2218
2348
  } from "viem";
2219
2349
  var batchServiceUrl = "https://flex-api.acta.link/flex/batch/api/v1/";
2220
2350
  var batchServiceTestUrl = "https://flex-api.acta.link/flex/batch/test/api/v1/";
@@ -2246,7 +2376,7 @@ var ActaFlexBatch = class {
2246
2376
  if (!this.APIkey) {
2247
2377
  throw new Error("No API key provided.");
2248
2378
  }
2249
- if (!signerAddress || signerAddress === zeroAddress3) {
2379
+ if (!signerAddress || signerAddress === zeroAddress4) {
2250
2380
  throw new Error("Signer address is required.");
2251
2381
  }
2252
2382
  if (!name || name === "") {
@@ -2676,8 +2806,8 @@ var ActaFlexBatch = class {
2676
2806
 
2677
2807
  // src/billing.ts
2678
2808
  import { toHex as toHex5 } from "viem";
2679
- var billingServiceUrl = "https://api.acta.link/pay/api/v1/";
2680
- var billingServiceTestUrl = "https://api.acta.link/pay/test/api/v1/";
2809
+ var billingServiceUrl = "https://pay-api.fhoton.xyz/pay/api/v1/";
2810
+ var billingServiceTestUrl = "https://pay-api.fhoton.xyz/pay/test/api/v1/";
2681
2811
  var returnEnvUrl3 = (chainId) => {
2682
2812
  const mainnetChain = mainnetChains.find((c) => c.id === chainId);
2683
2813
  const testnetChain = testnetChains.find((c) => c.id === chainId);
@@ -2705,6 +2835,7 @@ var ActaBilling = class {
2705
2835
  this.status = "not_started";
2706
2836
  this.serviceType = "deposit";
2707
2837
  this.allowMaxTokenApproval = false;
2838
+ this.feebps = 20;
2708
2839
  var _a, _b;
2709
2840
  this.connectorType = parameters.connectorType;
2710
2841
  this.walletClient = parameters.walletClient;
@@ -2760,7 +2891,95 @@ var ActaBilling = class {
2760
2891
  }
2761
2892
  });
2762
2893
  }
2763
- createSinglePayment(servicePaymentParams) {
2894
+ estimatePaymentAmount() {
2895
+ return __async(this, null, function* () {
2896
+ try {
2897
+ const signerAddress = this.signerAddress;
2898
+ const chainId = this.chainId;
2899
+ const tokenSymbol = this.token;
2900
+ const amount = this.amount;
2901
+ const receiver = this.receiver;
2902
+ const feeInclusive = this.feeInclusive;
2903
+ const feebps = this.feebps;
2904
+ const { totalAmount, actalinkFees, receiverAmount } = yield this.account.estimatePaymentAmount({
2905
+ signerAddress,
2906
+ chainId,
2907
+ token: tokenSymbol,
2908
+ amount,
2909
+ receiver,
2910
+ feeInclusive,
2911
+ feebps
2912
+ });
2913
+ return {
2914
+ totalAmount,
2915
+ actalinkFees,
2916
+ receiverAmount
2917
+ };
2918
+ } catch (error) {
2919
+ if (error instanceof Error) {
2920
+ throw new Error(error.message);
2921
+ }
2922
+ throw new Error("Failed to estimate payment amount.");
2923
+ }
2924
+ });
2925
+ }
2926
+ checkAllowance() {
2927
+ return __async(this, null, function* () {
2928
+ try {
2929
+ const chainId = this.chainId;
2930
+ const tokenSymbol = this.token;
2931
+ const allowance = yield this.account.checkAllowance({
2932
+ chainId,
2933
+ token: tokenSymbol
2934
+ });
2935
+ return allowance;
2936
+ } catch (error) {
2937
+ if (error instanceof Error) {
2938
+ throw new Error(error.message);
2939
+ }
2940
+ throw new Error("Failed to check token allowance.");
2941
+ }
2942
+ });
2943
+ }
2944
+ approveToken(parameters) {
2945
+ return __async(this, null, function* () {
2946
+ try {
2947
+ const chainId = this.chainId;
2948
+ const tokenSymbol = this.token;
2949
+ const { totalAmount, allowMaxTokenApproval } = parameters;
2950
+ const hash = yield this.account.approveToken({
2951
+ chainId,
2952
+ token: tokenSymbol,
2953
+ amount: totalAmount,
2954
+ allowMaxTokenApproval
2955
+ });
2956
+ return hash;
2957
+ } catch (error) {
2958
+ if (error instanceof Error) {
2959
+ throw new Error(error.message);
2960
+ }
2961
+ throw new Error("Failed to approve token.");
2962
+ }
2963
+ });
2964
+ }
2965
+ waitForTransactionReceipt(hash) {
2966
+ return __async(this, null, function* () {
2967
+ try {
2968
+ const chainId = this.chainId;
2969
+ const receipt = yield this.account.waitForTransactionReceipt({
2970
+ chainId,
2971
+ hash
2972
+ });
2973
+ return receipt;
2974
+ } catch (error) {
2975
+ if (error instanceof Error) {
2976
+ throw new Error(error.message);
2977
+ }
2978
+ throw new Error("Failed to fetch transaction receipt.");
2979
+ }
2980
+ });
2981
+ }
2982
+ createSinglePayment(parameters, servicePaymentParams) {
2764
2983
  return __async(this, null, function* () {
2765
2984
  try {
2766
2985
  if (this.connectorType !== "Self-Custody" /* SELF_CUSTODY */) {
@@ -2769,6 +2988,7 @@ var ActaBilling = class {
2769
2988
  if (!servicePaymentParams.checkoutSessionId || servicePaymentParams.checkoutSessionId === "") {
2770
2989
  throw new Error("checkout session ID is required.");
2771
2990
  }
2991
+ const { actalinkFees, receiverAmount } = parameters;
2772
2992
  const signerAddress = this.signerAddress;
2773
2993
  const chainId = this.chainId;
2774
2994
  const tokenSymbol = this.token;
@@ -2785,11 +3005,9 @@ var ActaBilling = class {
2785
3005
  signerAddress,
2786
3006
  chainId,
2787
3007
  token: tokenSymbol,
2788
- amount,
2789
- receiver,
2790
- feeInclusive,
2791
- allowMaxTokenApproval: this.allowMaxTokenApproval,
2792
- feebps: 20
3008
+ actalinkFees,
3009
+ receiverAmount,
3010
+ receiver
2793
3011
  });
2794
3012
  const txn = yield executeSinglePaymentAPICall(
2795
3013
  `${envBillingServiceUrl}execute/single`,
@@ -2849,14 +3067,7 @@ var ActaBilling = class {
2849
3067
  chainId,
2850
3068
  token: tokenSymbol,
2851
3069
  amount,
2852
- feeInclusive,
2853
- count,
2854
- intervalUnit,
2855
- startDate,
2856
- endDate,
2857
- receiver,
2858
- allowMaxTokenApproval: this.allowMaxTokenApproval,
2859
- feebps: 20
3070
+ receiver
2860
3071
  });
2861
3072
  const txn = yield scheduleSubscriptionPaymentsAPICall(
2862
3073
  `${envBillingServiceUrl}schedule/subscription`,
@@ -2920,7 +3131,7 @@ import {
2920
3131
  getAddress as getAddress4,
2921
3132
  parseUnits as parseUnits2,
2922
3133
  toHex as toHex6,
2923
- zeroAddress as zeroAddress4
3134
+ zeroAddress as zeroAddress5
2924
3135
  } from "viem";
2925
3136
  var batchServiceUrl2 = "https://api.acta.link/bexo/api/v1/";
2926
3137
  var batchServiceTestUrl2 = "https://api.acta.link/bexo/test/api/v1/";
@@ -2952,7 +3163,7 @@ var ActaBatch = class {
2952
3163
  if (!this.APIkey) {
2953
3164
  throw new Error("No API key provided.");
2954
3165
  }
2955
- if (!signerAddress || signerAddress === zeroAddress4) {
3166
+ if (!signerAddress || signerAddress === zeroAddress5) {
2956
3167
  throw new Error("Signer address is required.");
2957
3168
  }
2958
3169
  if (!name || name === "") {
@@ -3399,7 +3610,7 @@ import {
3399
3610
  encodeAbiParameters,
3400
3611
  keccak256,
3401
3612
  slice,
3402
- zeroAddress as zeroAddress5,
3613
+ zeroAddress as zeroAddress6,
3403
3614
  decodeFunctionData,
3404
3615
  hexToBigInt as hexToBigInt2
3405
3616
  } from "viem";
@@ -3511,7 +3722,7 @@ function toPermissionValidator2(_0, _1) {
3511
3722
  return __spreadProps(__spreadValues({}, signer.account), {
3512
3723
  supportedKernelVersions: ">=0.3.0",
3513
3724
  validatorType: "PERMISSION",
3514
- address: zeroAddress5,
3725
+ address: zeroAddress6,
3515
3726
  source: "PermissionValidator",
3516
3727
  getEnableData,
3517
3728
  getIdentifier: getPermissionId,