@actalink/commonlib 0.1.0-dev → 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
@@ -783,7 +820,7 @@ var ActaAccount = class {
783
820
  const account = yield this.createAccount();
784
821
  const entryPoint = getEntryPoint("0.7");
785
822
  const paymasterClient = createPaymasterClient({
786
- transport: http2(`${proxyUrl}/rpc?chainId=${this.chainId}`)
823
+ transport: http2(`https://api.acta.link/paymaster/v1/rpc`)
787
824
  });
788
825
  const pimlicoClient = createPimlicoClient({
789
826
  chain: getChainById(this.chainId),
@@ -904,17 +941,42 @@ var ActaAccount = class {
904
941
  }
905
942
  ]
906
943
  });
907
- const quotes = yield pimlicoClient.getTokenQuotes({
908
- tokens: [token2.address],
909
- chain: getChainById(chainId)
944
+ const data = {
945
+ jsonrpc: "2.0",
946
+ id: 1,
947
+ method: "pm_getTokenQuotes",
948
+ params: [
949
+ {
950
+ tokens: [token2.address]
951
+ },
952
+ entryPoint07Address,
953
+ toHex(chainId)
954
+ ]
955
+ };
956
+ const res = yield fetch("https://api.acta.link/paymaster/v1/rpc", {
957
+ method: "POST",
958
+ headers: {
959
+ "Content-Type": "application/json"
960
+ },
961
+ body: JSON.stringify(data)
962
+ }).then((response) => {
963
+ if (!response.ok) {
964
+ throw new Error("HTTP error " + response.status);
965
+ }
966
+ return response.json();
910
967
  });
911
968
  const userOperationMaxCost = getRequiredPrefund({
912
969
  userOperation,
913
970
  entryPointVersion: "0.7"
914
971
  });
915
- const postOpGas = quotes[0].postOpGas;
916
- const exchangeRate = quotes[0].exchangeRate;
917
- const exchangeRateNativeToUsd = quotes[0].exchangeRateNativeToUsd;
972
+ const quotes = res.result;
973
+ if (!quotes.paymaster) {
974
+ throw new Error("Error fetching quotes");
975
+ }
976
+ const postOpGas = hexToBigInt(quotes.postOpGas);
977
+ const exchangeRate = hexToBigInt(quotes.exchangeRate);
978
+ const exchangeRateNativeToUsd = hexToBigInt(quotes.exchangeRateNativeToUsd);
979
+ const paymaster = quotes.paymaster;
918
980
  const maxCostInWei = userOperationMaxCost + postOpGas * userOperation.maxFeePerGas;
919
981
  const costInToken = maxCostInWei * exchangeRate / BigInt(1e18);
920
982
  const costInUsd = maxCostInWei * exchangeRateNativeToUsd / BigInt(1e18);
@@ -928,7 +990,7 @@ var ActaAccount = class {
928
990
  estimatedTotalFeesInToken,
929
991
  feeInclusiveAmountInToken,
930
992
  feeExclusiveAmountInToken,
931
- paymaster: quotes[0].paymaster,
993
+ paymaster,
932
994
  userOperation
933
995
  };
934
996
  });
@@ -1035,7 +1097,7 @@ var ActaAccount = class {
1035
1097
  };
1036
1098
  });
1037
1099
  }
1038
- signSinglePaymentOperation(singlePaymentParams) {
1100
+ estimatePaymentAmount(singlePaymentParams) {
1039
1101
  return __async(this, null, function* () {
1040
1102
  try {
1041
1103
  if (!this.signer) {
@@ -1048,7 +1110,6 @@ var ActaAccount = class {
1048
1110
  amount,
1049
1111
  receiver,
1050
1112
  feeInclusive,
1051
- allowMaxTokenApproval,
1052
1113
  feebps
1053
1114
  } = singlePaymentParams;
1054
1115
  if (amount <= BigInt(0)) {
@@ -1061,14 +1122,10 @@ var ActaAccount = class {
1061
1122
  if (!token2) {
1062
1123
  throw new Error("Token not found.");
1063
1124
  }
1064
- const viemClient = new ViemClient(this.chainId, this.signer);
1065
1125
  const {
1066
- estimatedGasCostInToken,
1067
- ActalinkFeesInToken,
1068
1126
  feeInclusiveAmountInToken,
1069
1127
  feeExclusiveAmountInToken,
1070
- estimatedTotalFeesInToken,
1071
- paymaster
1128
+ estimatedTotalFeesInToken
1072
1129
  } = yield this.estimateSinglePaymentGas({
1073
1130
  signerAddress,
1074
1131
  chainId,
@@ -1078,18 +1135,141 @@ var ActaAccount = class {
1078
1135
  feeInclusive,
1079
1136
  feebps
1080
1137
  });
1081
- const account = yield this.createAccount();
1082
- const { accountClient } = yield this.createAccountHelpers();
1083
- const fromAddress = signerAddress;
1084
- const smartAccountAddress = account.address;
1085
- const amountToTransfer = feeInclusive ? amount : feeExclusiveAmountInToken;
1138
+ const totalAmount = feeInclusive ? amount : feeExclusiveAmountInToken;
1139
+ const actalinkFees = estimatedTotalFeesInToken;
1086
1140
  const receiverAmount = feeInclusive ? feeInclusiveAmountInToken : amount;
1087
- 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(
1088
1208
  token2,
1089
1209
  smartAccountAddress,
1090
- amountToTransfer,
1091
- allowMaxTokenApproval != null ? allowMaxTokenApproval : false
1210
+ amount,
1211
+ allowMaxTokenApproval
1092
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;
1093
1273
  const userOperation = yield accountClient.prepareUserOperation({
1094
1274
  calls: [
1095
1275
  {
@@ -1099,7 +1279,7 @@ var ActaAccount = class {
1099
1279
  args: [
1100
1280
  fromAddress,
1101
1281
  "0x26eeCa5956Bf8C01040BAC9e6D7982a0e87F31B4",
1102
- estimatedTotalFeesInToken
1282
+ actalinkFees
1103
1283
  ]
1104
1284
  },
1105
1285
  {
@@ -1232,14 +1412,7 @@ var ActaAccount = class {
1232
1412
  chainId,
1233
1413
  token: tokenSymbol,
1234
1414
  amount,
1235
- receiver,
1236
- feeInclusive,
1237
- count,
1238
- intervalUnit,
1239
- startDate,
1240
- endDate,
1241
- allowMaxTokenApproval,
1242
- feebps
1415
+ receiver
1243
1416
  } = recurringPaymentParams;
1244
1417
  if (amount <= BigInt(0)) {
1245
1418
  throw new Error("Amount must be greater than 0.");
@@ -1250,20 +1423,14 @@ var ActaAccount = class {
1250
1423
  if (receiver === signerAddress) {
1251
1424
  throw new Error("Receiver cannot be the same as the signer.");
1252
1425
  }
1253
- if (!intervalUnit) {
1254
- throw new Error("Interval unit is required.");
1255
- }
1256
1426
  const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
1257
1427
  if (!token2) {
1258
1428
  throw new Error("Token not found.");
1259
1429
  }
1260
1430
  const kernelVersion = KERNEL_V3_1;
1261
1431
  const entryPoint = getEntryPoint("0.7");
1262
- const paymentCount = count != null ? count : 24;
1263
1432
  const account = yield this.createAccount();
1264
- const smartAccountAddress = account.address;
1265
1433
  const viemClient = new ViemClient(this.chainId, this.signer);
1266
- const { paymasterClient, pimlicoClient } = yield this.createAccountHelpers();
1267
1434
  const ecdsaValidator = yield signerToEcdsaValidator(
1268
1435
  viemClient.publicClient(),
1269
1436
  {
@@ -1275,32 +1442,7 @@ var ActaAccount = class {
1275
1442
  const sessionKeyAddress = "0xFDEed8e268D74DF71f3Db7409F8A8290FF1263ED";
1276
1443
  const emptyAccount = addressToEmptyAccount(sessionKeyAddress);
1277
1444
  const emptySessionKeySigner = yield toECDSASigner({ signer: emptyAccount });
1278
- const {
1279
- paymaster,
1280
- ActalinkFeesInToken,
1281
- feeInclusiveAmountInToken,
1282
- feeExclusiveAmountInToken,
1283
- estimatedTotalFeesInToken,
1284
- userOperation,
1285
- estimatedGasCostInToken
1286
- } = yield this.estimateSinglePaymentGas({
1287
- signerAddress,
1288
- chainId,
1289
- token: tokenSymbol,
1290
- amount,
1291
- receiver,
1292
- feeInclusive,
1293
- feebps
1294
- });
1295
- const amountToTransfer = feeInclusive ? amount : feeExclusiveAmountInToken;
1296
- const receiverAmount = feeInclusive ? feeInclusiveAmountInToken : amount;
1297
- yield viemClient.checkAndApproveToken(
1298
- token2,
1299
- smartAccountAddress,
1300
- amountToTransfer * BigInt(paymentCount) + estimatedGasCostInToken * BigInt(2) * BigInt(paymentCount),
1301
- allowMaxTokenApproval != null ? allowMaxTokenApproval : false
1302
- );
1303
- const amountExclusive = amountToTransfer + amountToTransfer / BigInt(2);
1445
+ const amountExclusive = amount + amount / BigInt(2);
1304
1446
  const callPolicy = toCallPolicy({
1305
1447
  policyVersion: CallPolicyVersion.V0_0_4,
1306
1448
  permissions: [
@@ -1847,6 +1989,7 @@ var ActaFlexDeposit = class {
1847
1989
  this.status = "not_started";
1848
1990
  this.serviceType = "deposit";
1849
1991
  this.allowMaxTokenApproval = false;
1992
+ this.feebps = 10;
1850
1993
  var _a, _b, _c;
1851
1994
  this.connectorType = parameters.connectorType;
1852
1995
  this.walletClient = parameters.walletClient;
@@ -1873,13 +2016,13 @@ var ActaFlexDeposit = class {
1873
2016
  createSession(serviceSessionparams) {
1874
2017
  return __async(this, null, function* () {
1875
2018
  try {
1876
- if (!this.signerAddress || this.signerAddress === zeroAddress2) {
2019
+ if (!this.signerAddress || this.signerAddress === zeroAddress3) {
1877
2020
  throw new Error("Signer address is required.");
1878
2021
  }
1879
2022
  if (this.paymentType !== "single" && this.paymentType !== "choose" && this.paymentType !== "recurring") {
1880
2023
  throw new Error("Invalid payment type.");
1881
2024
  }
1882
- if (!this.receiver || this.receiver === zeroAddress2) {
2025
+ if (!this.receiver || this.receiver === zeroAddress3) {
1883
2026
  throw new Error("Receiver is required.");
1884
2027
  }
1885
2028
  if (this.paymentType === "recurring" && (this.count === void 0 || this.count === 0)) {
@@ -1966,35 +2109,95 @@ var ActaFlexDeposit = class {
1966
2109
  }
1967
2110
  });
1968
2111
  }
1969
- createPayment(servicePaymentParams) {
2112
+ estimatePaymentAmount() {
1970
2113
  return __async(this, null, function* () {
1971
2114
  try {
1972
- if (this.paymentType === "single") {
1973
- const paymentParams = this.serviceType === "deposit" ? __spreadProps(__spreadValues({}, servicePaymentParams), {
1974
- depositSessionId: this.depositSessionId
1975
- }) : servicePaymentParams;
1976
- const id = yield this.createSinglePayment(paymentParams);
1977
- return id;
1978
- }
1979
- if (this.paymentType === "choose") {
1980
- }
1981
- if (this.paymentType === "recurring") {
1982
- const paymentParams = this.serviceType === "deposit" ? __spreadProps(__spreadValues({}, servicePaymentParams), {
1983
- depositSessionId: this.depositSessionId
1984
- }) : servicePaymentParams;
1985
- const id = yield this.createRecurringPayments(paymentParams);
1986
- return id;
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);
1987
2139
  }
2140
+ throw new Error("Failed to estimate payment amount.");
2141
+ }
2142
+ });
2143
+ }
2144
+ checkAllowance() {
2145
+ return __async(this, null, function* () {
2146
+ try {
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;
1988
2154
  } catch (error) {
1989
- this.status = "payment_failed";
1990
2155
  if (error instanceof Error) {
1991
2156
  throw new Error(error.message);
1992
2157
  }
1993
- throw new Error("Failed to create payment.");
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;
2175
+ } catch (error) {
2176
+ if (error instanceof Error) {
2177
+ throw new Error(error.message);
2178
+ }
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.");
1994
2197
  }
1995
2198
  });
1996
2199
  }
1997
- createSinglePayment(servicePaymentParams) {
2200
+ createSinglePayment(parameters, servicePaymentParams) {
1998
2201
  return __async(this, null, function* () {
1999
2202
  try {
2000
2203
  if (this.connectorType !== "Self-Custody" /* SELF_CUSTODY */) {
@@ -2006,18 +2209,12 @@ var ActaFlexDeposit = class {
2006
2209
  const signerAddress = this.signerAddress;
2007
2210
  const chainId = this.chainId;
2008
2211
  const tokenSymbol = this.token;
2009
- const amount = this.amount;
2010
2212
  const receiver = this.receiver;
2213
+ const amount = this.amount;
2011
2214
  const feeInclusive = this.feeInclusive;
2012
2215
  const serviceType = this.serviceType;
2216
+ const { actalinkFees, receiverAmount } = parameters;
2013
2217
  const { envTransactionServiceUrl, envDepositServiceUrl } = returnEnvUrl(chainId);
2014
- if (this.depositSessionId !== "") {
2015
- const session = yield verifySessionAPICall(
2016
- `${envDepositServiceUrl}verify-session?sessionId=${this.depositSessionId}`,
2017
- this.depositSessionId
2018
- );
2019
- this.depositSessionId = session.sessionId;
2020
- }
2021
2218
  const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
2022
2219
  if (!token2) {
2023
2220
  throw new Error("Token not supported.");
@@ -2026,11 +2223,9 @@ var ActaFlexDeposit = class {
2026
2223
  signerAddress,
2027
2224
  chainId,
2028
2225
  token: tokenSymbol,
2029
- amount,
2030
- receiver,
2031
- feeInclusive,
2032
- allowMaxTokenApproval: this.allowMaxTokenApproval,
2033
- feebps: 10
2226
+ actalinkFees,
2227
+ receiverAmount,
2228
+ receiver
2034
2229
  });
2035
2230
  const txn = yield executeSinglePaymentAPICall(
2036
2231
  `${envTransactionServiceUrl}execute/single`,
@@ -2118,14 +2313,7 @@ var ActaFlexDeposit = class {
2118
2313
  chainId,
2119
2314
  token: tokenSymbol,
2120
2315
  amount,
2121
- feeInclusive,
2122
- count,
2123
- intervalUnit,
2124
- startDate,
2125
- endDate,
2126
- receiver,
2127
- allowMaxTokenApproval: this.allowMaxTokenApproval,
2128
- feebps: 20
2316
+ receiver
2129
2317
  });
2130
2318
  const txn = yield scheduleRecurringPaymentsAPICall(
2131
2319
  `${envTransactionServiceUrl}schedule/recurring`,
@@ -2149,39 +2337,6 @@ var ActaFlexDeposit = class {
2149
2337
  return txn.recurringTransaction.id;
2150
2338
  });
2151
2339
  }
2152
- getPaymentSteps() {
2153
- return __async(this, null, function* () {
2154
- const signerAddress = this.signerAddress;
2155
- const chainId = this.chainId;
2156
- const tokenSymbol = this.token;
2157
- const amount = this.amount;
2158
- const receiver = this.receiver;
2159
- const feeInclusive = this.feeInclusive;
2160
- const count = this.count;
2161
- if (!signerAddress) return ["allowance", "confirm"];
2162
- const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
2163
- if (!token2) return ["allowance", "confirm"];
2164
- const smartAccount = yield this.account.createAccount();
2165
- const { estimatedGasCostInToken, feeExclusiveAmountInToken } = yield this.account.estimateSinglePaymentGas({
2166
- chainId,
2167
- amount,
2168
- feeInclusive,
2169
- receiver,
2170
- signerAddress,
2171
- token: tokenSymbol,
2172
- feebps: 10
2173
- });
2174
- const amountToTransfer = feeInclusive ? amount : feeExclusiveAmountInToken;
2175
- let paymentAmount = (amountToTransfer + estimatedGasCostInToken * BigInt(2)) * BigInt(count != null ? count : 1);
2176
- const allowance = yield this.viemClient.checkTokenAllowance(
2177
- token2,
2178
- signerAddress,
2179
- smartAccount.address
2180
- );
2181
- if (paymentAmount <= allowance) return ["confirm"];
2182
- return ["allowance", "confirm"];
2183
- });
2184
- }
2185
2340
  };
2186
2341
 
2187
2342
  // src/flexbatch.ts
@@ -2189,7 +2344,7 @@ import {
2189
2344
  getAddress as getAddress3,
2190
2345
  parseUnits,
2191
2346
  toHex as toHex4,
2192
- zeroAddress as zeroAddress3
2347
+ zeroAddress as zeroAddress4
2193
2348
  } from "viem";
2194
2349
  var batchServiceUrl = "https://flex-api.acta.link/flex/batch/api/v1/";
2195
2350
  var batchServiceTestUrl = "https://flex-api.acta.link/flex/batch/test/api/v1/";
@@ -2221,7 +2376,7 @@ var ActaFlexBatch = class {
2221
2376
  if (!this.APIkey) {
2222
2377
  throw new Error("No API key provided.");
2223
2378
  }
2224
- if (!signerAddress || signerAddress === zeroAddress3) {
2379
+ if (!signerAddress || signerAddress === zeroAddress4) {
2225
2380
  throw new Error("Signer address is required.");
2226
2381
  }
2227
2382
  if (!name || name === "") {
@@ -2651,8 +2806,8 @@ var ActaFlexBatch = class {
2651
2806
 
2652
2807
  // src/billing.ts
2653
2808
  import { toHex as toHex5 } from "viem";
2654
- var billingServiceUrl = "https://api.acta.link/pay/api/v1/";
2655
- 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/";
2656
2811
  var returnEnvUrl3 = (chainId) => {
2657
2812
  const mainnetChain = mainnetChains.find((c) => c.id === chainId);
2658
2813
  const testnetChain = testnetChains.find((c) => c.id === chainId);
@@ -2680,6 +2835,7 @@ var ActaBilling = class {
2680
2835
  this.status = "not_started";
2681
2836
  this.serviceType = "deposit";
2682
2837
  this.allowMaxTokenApproval = false;
2838
+ this.feebps = 20;
2683
2839
  var _a, _b;
2684
2840
  this.connectorType = parameters.connectorType;
2685
2841
  this.walletClient = parameters.walletClient;
@@ -2735,7 +2891,95 @@ var ActaBilling = class {
2735
2891
  }
2736
2892
  });
2737
2893
  }
2738
- 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) {
2739
2983
  return __async(this, null, function* () {
2740
2984
  try {
2741
2985
  if (this.connectorType !== "Self-Custody" /* SELF_CUSTODY */) {
@@ -2744,6 +2988,7 @@ var ActaBilling = class {
2744
2988
  if (!servicePaymentParams.checkoutSessionId || servicePaymentParams.checkoutSessionId === "") {
2745
2989
  throw new Error("checkout session ID is required.");
2746
2990
  }
2991
+ const { actalinkFees, receiverAmount } = parameters;
2747
2992
  const signerAddress = this.signerAddress;
2748
2993
  const chainId = this.chainId;
2749
2994
  const tokenSymbol = this.token;
@@ -2760,11 +3005,9 @@ var ActaBilling = class {
2760
3005
  signerAddress,
2761
3006
  chainId,
2762
3007
  token: tokenSymbol,
2763
- amount,
2764
- receiver,
2765
- feeInclusive,
2766
- allowMaxTokenApproval: this.allowMaxTokenApproval,
2767
- feebps: 20
3008
+ actalinkFees,
3009
+ receiverAmount,
3010
+ receiver
2768
3011
  });
2769
3012
  const txn = yield executeSinglePaymentAPICall(
2770
3013
  `${envBillingServiceUrl}execute/single`,
@@ -2824,14 +3067,7 @@ var ActaBilling = class {
2824
3067
  chainId,
2825
3068
  token: tokenSymbol,
2826
3069
  amount,
2827
- feeInclusive,
2828
- count,
2829
- intervalUnit,
2830
- startDate,
2831
- endDate,
2832
- receiver,
2833
- allowMaxTokenApproval: this.allowMaxTokenApproval,
2834
- feebps: 20
3070
+ receiver
2835
3071
  });
2836
3072
  const txn = yield scheduleSubscriptionPaymentsAPICall(
2837
3073
  `${envBillingServiceUrl}schedule/subscription`,
@@ -2895,7 +3131,7 @@ import {
2895
3131
  getAddress as getAddress4,
2896
3132
  parseUnits as parseUnits2,
2897
3133
  toHex as toHex6,
2898
- zeroAddress as zeroAddress4
3134
+ zeroAddress as zeroAddress5
2899
3135
  } from "viem";
2900
3136
  var batchServiceUrl2 = "https://api.acta.link/bexo/api/v1/";
2901
3137
  var batchServiceTestUrl2 = "https://api.acta.link/bexo/test/api/v1/";
@@ -2927,7 +3163,7 @@ var ActaBatch = class {
2927
3163
  if (!this.APIkey) {
2928
3164
  throw new Error("No API key provided.");
2929
3165
  }
2930
- if (!signerAddress || signerAddress === zeroAddress4) {
3166
+ if (!signerAddress || signerAddress === zeroAddress5) {
2931
3167
  throw new Error("Signer address is required.");
2932
3168
  }
2933
3169
  if (!name || name === "") {
@@ -3374,7 +3610,7 @@ import {
3374
3610
  encodeAbiParameters,
3375
3611
  keccak256,
3376
3612
  slice,
3377
- zeroAddress as zeroAddress5,
3613
+ zeroAddress as zeroAddress6,
3378
3614
  decodeFunctionData,
3379
3615
  hexToBigInt as hexToBigInt2
3380
3616
  } from "viem";
@@ -3486,7 +3722,7 @@ function toPermissionValidator2(_0, _1) {
3486
3722
  return __spreadProps(__spreadValues({}, signer.account), {
3487
3723
  supportedKernelVersions: ">=0.3.0",
3488
3724
  validatorType: "PERMISSION",
3489
- address: zeroAddress5,
3725
+ address: zeroAddress6,
3490
3726
  source: "PermissionValidator",
3491
3727
  getEnableData,
3492
3728
  getIdentifier: getPermissionId,