@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.cjs +389 -153
- package/dist/index.d.cts +430 -381
- package/dist/index.d.ts +430 -381
- package/dist/index.js +398 -162
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -777,6 +777,43 @@ var ViemClient = class {
|
|
|
777
777
|
return allowance;
|
|
778
778
|
});
|
|
779
779
|
}
|
|
780
|
+
approveToken(token2, spender, amount, allowMaxTokenApproval) {
|
|
781
|
+
return __async(this, null, function* () {
|
|
782
|
+
var _a;
|
|
783
|
+
if (this.walletClient === void 0) {
|
|
784
|
+
throw new Error("Wallet client is required");
|
|
785
|
+
}
|
|
786
|
+
const signerAddress = (_a = this.walletClient.account) == null ? void 0 : _a.address;
|
|
787
|
+
console.log("signerAddress", signerAddress);
|
|
788
|
+
if (signerAddress === void 0) {
|
|
789
|
+
throw new Error("Signer address is required");
|
|
790
|
+
}
|
|
791
|
+
const txn = yield this.walletClient.sendTransaction({
|
|
792
|
+
to: token2.address,
|
|
793
|
+
account: signerAddress,
|
|
794
|
+
chain: getChainById(token2.chainId),
|
|
795
|
+
value: BigInt(0),
|
|
796
|
+
data: (0, import_viem2.encodeFunctionData)({
|
|
797
|
+
abi: (0, import_viem2.parseAbi)(["function approve(address,uint)"]),
|
|
798
|
+
functionName: "approve",
|
|
799
|
+
args: [spender, allowMaxTokenApproval ? import_viem2.maxUint256 : amount]
|
|
800
|
+
})
|
|
801
|
+
});
|
|
802
|
+
return txn;
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
waitForTransactionReceipt(hash, blocks = 1) {
|
|
806
|
+
return __async(this, null, function* () {
|
|
807
|
+
if (this.walletClient === void 0) {
|
|
808
|
+
throw new Error("Wallet client is required");
|
|
809
|
+
}
|
|
810
|
+
const receipt = yield this.publicClient().waitForTransactionReceipt({
|
|
811
|
+
hash,
|
|
812
|
+
confirmations: blocks
|
|
813
|
+
});
|
|
814
|
+
return receipt;
|
|
815
|
+
});
|
|
816
|
+
}
|
|
780
817
|
};
|
|
781
818
|
|
|
782
819
|
// src/account.ts
|
|
@@ -854,7 +891,7 @@ var ActaAccount = class {
|
|
|
854
891
|
const account = yield this.createAccount();
|
|
855
892
|
const entryPoint = (0, import_constants.getEntryPoint)("0.7");
|
|
856
893
|
const paymasterClient = (0, import_account_abstraction.createPaymasterClient)({
|
|
857
|
-
transport: (0, import_viem3.http)(
|
|
894
|
+
transport: (0, import_viem3.http)(`https://api.acta.link/paymaster/v1/rpc`)
|
|
858
895
|
});
|
|
859
896
|
const pimlicoClient = (0, import_pimlico.createPimlicoClient)({
|
|
860
897
|
chain: getChainById(this.chainId),
|
|
@@ -975,17 +1012,42 @@ var ActaAccount = class {
|
|
|
975
1012
|
}
|
|
976
1013
|
]
|
|
977
1014
|
});
|
|
978
|
-
const
|
|
979
|
-
|
|
980
|
-
|
|
1015
|
+
const data = {
|
|
1016
|
+
jsonrpc: "2.0",
|
|
1017
|
+
id: 1,
|
|
1018
|
+
method: "pm_getTokenQuotes",
|
|
1019
|
+
params: [
|
|
1020
|
+
{
|
|
1021
|
+
tokens: [token2.address]
|
|
1022
|
+
},
|
|
1023
|
+
import_account_abstraction.entryPoint07Address,
|
|
1024
|
+
(0, import_viem3.toHex)(chainId)
|
|
1025
|
+
]
|
|
1026
|
+
};
|
|
1027
|
+
const res = yield fetch("https://api.acta.link/paymaster/v1/rpc", {
|
|
1028
|
+
method: "POST",
|
|
1029
|
+
headers: {
|
|
1030
|
+
"Content-Type": "application/json"
|
|
1031
|
+
},
|
|
1032
|
+
body: JSON.stringify(data)
|
|
1033
|
+
}).then((response) => {
|
|
1034
|
+
if (!response.ok) {
|
|
1035
|
+
throw new Error("HTTP error " + response.status);
|
|
1036
|
+
}
|
|
1037
|
+
return response.json();
|
|
981
1038
|
});
|
|
982
1039
|
const userOperationMaxCost = (0, import_permissionless.getRequiredPrefund)({
|
|
983
1040
|
userOperation,
|
|
984
1041
|
entryPointVersion: "0.7"
|
|
985
1042
|
});
|
|
986
|
-
const
|
|
987
|
-
|
|
988
|
-
|
|
1043
|
+
const quotes = res.result;
|
|
1044
|
+
if (!quotes.paymaster) {
|
|
1045
|
+
throw new Error("Error fetching quotes");
|
|
1046
|
+
}
|
|
1047
|
+
const postOpGas = (0, import_viem3.hexToBigInt)(quotes.postOpGas);
|
|
1048
|
+
const exchangeRate = (0, import_viem3.hexToBigInt)(quotes.exchangeRate);
|
|
1049
|
+
const exchangeRateNativeToUsd = (0, import_viem3.hexToBigInt)(quotes.exchangeRateNativeToUsd);
|
|
1050
|
+
const paymaster = quotes.paymaster;
|
|
989
1051
|
const maxCostInWei = userOperationMaxCost + postOpGas * userOperation.maxFeePerGas;
|
|
990
1052
|
const costInToken = maxCostInWei * exchangeRate / BigInt(1e18);
|
|
991
1053
|
const costInUsd = maxCostInWei * exchangeRateNativeToUsd / BigInt(1e18);
|
|
@@ -999,7 +1061,7 @@ var ActaAccount = class {
|
|
|
999
1061
|
estimatedTotalFeesInToken,
|
|
1000
1062
|
feeInclusiveAmountInToken,
|
|
1001
1063
|
feeExclusiveAmountInToken,
|
|
1002
|
-
paymaster
|
|
1064
|
+
paymaster,
|
|
1003
1065
|
userOperation
|
|
1004
1066
|
};
|
|
1005
1067
|
});
|
|
@@ -1106,7 +1168,7 @@ var ActaAccount = class {
|
|
|
1106
1168
|
};
|
|
1107
1169
|
});
|
|
1108
1170
|
}
|
|
1109
|
-
|
|
1171
|
+
estimatePaymentAmount(singlePaymentParams) {
|
|
1110
1172
|
return __async(this, null, function* () {
|
|
1111
1173
|
try {
|
|
1112
1174
|
if (!this.signer) {
|
|
@@ -1119,7 +1181,6 @@ var ActaAccount = class {
|
|
|
1119
1181
|
amount,
|
|
1120
1182
|
receiver,
|
|
1121
1183
|
feeInclusive,
|
|
1122
|
-
allowMaxTokenApproval,
|
|
1123
1184
|
feebps
|
|
1124
1185
|
} = singlePaymentParams;
|
|
1125
1186
|
if (amount <= BigInt(0)) {
|
|
@@ -1132,14 +1193,10 @@ var ActaAccount = class {
|
|
|
1132
1193
|
if (!token2) {
|
|
1133
1194
|
throw new Error("Token not found.");
|
|
1134
1195
|
}
|
|
1135
|
-
const viemClient = new ViemClient(this.chainId, this.signer);
|
|
1136
1196
|
const {
|
|
1137
|
-
estimatedGasCostInToken,
|
|
1138
|
-
ActalinkFeesInToken,
|
|
1139
1197
|
feeInclusiveAmountInToken,
|
|
1140
1198
|
feeExclusiveAmountInToken,
|
|
1141
|
-
estimatedTotalFeesInToken
|
|
1142
|
-
paymaster
|
|
1199
|
+
estimatedTotalFeesInToken
|
|
1143
1200
|
} = yield this.estimateSinglePaymentGas({
|
|
1144
1201
|
signerAddress,
|
|
1145
1202
|
chainId,
|
|
@@ -1149,18 +1206,141 @@ var ActaAccount = class {
|
|
|
1149
1206
|
feeInclusive,
|
|
1150
1207
|
feebps
|
|
1151
1208
|
});
|
|
1152
|
-
const
|
|
1153
|
-
const
|
|
1154
|
-
const fromAddress = signerAddress;
|
|
1155
|
-
const smartAccountAddress = account.address;
|
|
1156
|
-
const amountToTransfer = feeInclusive ? amount : feeExclusiveAmountInToken;
|
|
1209
|
+
const totalAmount = feeInclusive ? amount : feeExclusiveAmountInToken;
|
|
1210
|
+
const actalinkFees = estimatedTotalFeesInToken;
|
|
1157
1211
|
const receiverAmount = feeInclusive ? feeInclusiveAmountInToken : amount;
|
|
1158
|
-
|
|
1212
|
+
return {
|
|
1213
|
+
totalAmount,
|
|
1214
|
+
actalinkFees,
|
|
1215
|
+
receiverAmount
|
|
1216
|
+
};
|
|
1217
|
+
} catch (error) {
|
|
1218
|
+
if (error instanceof Error) {
|
|
1219
|
+
throw new Error(error.message);
|
|
1220
|
+
}
|
|
1221
|
+
throw new Error("Failed to estimate payment amount.");
|
|
1222
|
+
}
|
|
1223
|
+
});
|
|
1224
|
+
}
|
|
1225
|
+
checkAllowance(params) {
|
|
1226
|
+
return __async(this, null, function* () {
|
|
1227
|
+
var _a;
|
|
1228
|
+
try {
|
|
1229
|
+
if (!this.signer) {
|
|
1230
|
+
throw new Error("Signer is required for self custody payments.");
|
|
1231
|
+
}
|
|
1232
|
+
const { chainId, token: tokenSymbol } = params;
|
|
1233
|
+
const account = yield this.createAccount();
|
|
1234
|
+
const smartAccountAddress = yield account.getAddress();
|
|
1235
|
+
const owner = (_a = this.signer.account) == null ? void 0 : _a.address;
|
|
1236
|
+
console.log("signerAddress", owner);
|
|
1237
|
+
if (owner === void 0) {
|
|
1238
|
+
throw new Error("Signer address is required");
|
|
1239
|
+
}
|
|
1240
|
+
const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
|
|
1241
|
+
if (!token2) {
|
|
1242
|
+
throw new Error("Token not found.");
|
|
1243
|
+
}
|
|
1244
|
+
const viemClient = new ViemClient(this.chainId, this.signer);
|
|
1245
|
+
const allowance = yield viemClient.checkTokenAllowance(
|
|
1246
|
+
token2,
|
|
1247
|
+
owner,
|
|
1248
|
+
smartAccountAddress
|
|
1249
|
+
);
|
|
1250
|
+
return allowance;
|
|
1251
|
+
} catch (error) {
|
|
1252
|
+
if (error instanceof Error) {
|
|
1253
|
+
throw new Error(error.message);
|
|
1254
|
+
}
|
|
1255
|
+
throw new Error("Failed to check token allownace.");
|
|
1256
|
+
}
|
|
1257
|
+
});
|
|
1258
|
+
}
|
|
1259
|
+
approveToken(params) {
|
|
1260
|
+
return __async(this, null, function* () {
|
|
1261
|
+
try {
|
|
1262
|
+
if (!this.signer) {
|
|
1263
|
+
throw new Error("Signer is required for self custody payments.");
|
|
1264
|
+
}
|
|
1265
|
+
const {
|
|
1266
|
+
chainId,
|
|
1267
|
+
token: tokenSymbol,
|
|
1268
|
+
amount,
|
|
1269
|
+
allowMaxTokenApproval
|
|
1270
|
+
} = params;
|
|
1271
|
+
const account = yield this.createAccount();
|
|
1272
|
+
const smartAccountAddress = yield account.getAddress();
|
|
1273
|
+
const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
|
|
1274
|
+
if (!token2) {
|
|
1275
|
+
throw new Error("Token not found.");
|
|
1276
|
+
}
|
|
1277
|
+
const viemClient = new ViemClient(this.chainId, this.signer);
|
|
1278
|
+
const allowance = yield viemClient.approveToken(
|
|
1159
1279
|
token2,
|
|
1160
1280
|
smartAccountAddress,
|
|
1161
|
-
|
|
1162
|
-
allowMaxTokenApproval
|
|
1281
|
+
amount,
|
|
1282
|
+
allowMaxTokenApproval
|
|
1163
1283
|
);
|
|
1284
|
+
return allowance;
|
|
1285
|
+
} catch (error) {
|
|
1286
|
+
if (error instanceof Error) {
|
|
1287
|
+
throw new Error(error.message);
|
|
1288
|
+
}
|
|
1289
|
+
throw new Error("Failed to approve token.");
|
|
1290
|
+
}
|
|
1291
|
+
});
|
|
1292
|
+
}
|
|
1293
|
+
waitForTransactionReceipt(params) {
|
|
1294
|
+
return __async(this, null, function* () {
|
|
1295
|
+
try {
|
|
1296
|
+
if (!this.signer) {
|
|
1297
|
+
throw new Error("Signer is required for self custody payments.");
|
|
1298
|
+
}
|
|
1299
|
+
const { chainId, hash } = params;
|
|
1300
|
+
if (!hash) {
|
|
1301
|
+
throw new Error("Hash is not provided.");
|
|
1302
|
+
}
|
|
1303
|
+
const viemClient = new ViemClient(this.chainId, this.signer);
|
|
1304
|
+
const receipt = yield viemClient.waitForTransactionReceipt(hash);
|
|
1305
|
+
return receipt;
|
|
1306
|
+
} catch (error) {
|
|
1307
|
+
if (error instanceof Error) {
|
|
1308
|
+
throw new Error(error.message);
|
|
1309
|
+
}
|
|
1310
|
+
throw new Error("Failed to check token allownace.");
|
|
1311
|
+
}
|
|
1312
|
+
});
|
|
1313
|
+
}
|
|
1314
|
+
signSinglePaymentOperation(singlePaymentParams) {
|
|
1315
|
+
return __async(this, null, function* () {
|
|
1316
|
+
try {
|
|
1317
|
+
if (!this.signer) {
|
|
1318
|
+
throw new Error("Signer is required for self custody payments.");
|
|
1319
|
+
}
|
|
1320
|
+
const {
|
|
1321
|
+
signerAddress,
|
|
1322
|
+
chainId,
|
|
1323
|
+
token: tokenSymbol,
|
|
1324
|
+
actalinkFees,
|
|
1325
|
+
receiverAmount,
|
|
1326
|
+
receiver
|
|
1327
|
+
} = singlePaymentParams;
|
|
1328
|
+
if (receiverAmount <= BigInt(0)) {
|
|
1329
|
+
throw new Error("Amount must be greater than 0.");
|
|
1330
|
+
}
|
|
1331
|
+
if (actalinkFees <= BigInt(0)) {
|
|
1332
|
+
throw new Error("Fees must be greater than 0.");
|
|
1333
|
+
}
|
|
1334
|
+
if (receiver === signerAddress) {
|
|
1335
|
+
throw new Error("Receiver cannot be the same as the signer.");
|
|
1336
|
+
}
|
|
1337
|
+
const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
|
|
1338
|
+
if (!token2) {
|
|
1339
|
+
throw new Error("Token not found.");
|
|
1340
|
+
}
|
|
1341
|
+
const account = yield this.createAccount();
|
|
1342
|
+
const { accountClient } = yield this.createAccountHelpers();
|
|
1343
|
+
const fromAddress = signerAddress;
|
|
1164
1344
|
const userOperation = yield accountClient.prepareUserOperation({
|
|
1165
1345
|
calls: [
|
|
1166
1346
|
{
|
|
@@ -1170,7 +1350,7 @@ var ActaAccount = class {
|
|
|
1170
1350
|
args: [
|
|
1171
1351
|
fromAddress,
|
|
1172
1352
|
"0x26eeCa5956Bf8C01040BAC9e6D7982a0e87F31B4",
|
|
1173
|
-
|
|
1353
|
+
actalinkFees
|
|
1174
1354
|
]
|
|
1175
1355
|
},
|
|
1176
1356
|
{
|
|
@@ -1303,14 +1483,7 @@ var ActaAccount = class {
|
|
|
1303
1483
|
chainId,
|
|
1304
1484
|
token: tokenSymbol,
|
|
1305
1485
|
amount,
|
|
1306
|
-
receiver
|
|
1307
|
-
feeInclusive,
|
|
1308
|
-
count,
|
|
1309
|
-
intervalUnit,
|
|
1310
|
-
startDate,
|
|
1311
|
-
endDate,
|
|
1312
|
-
allowMaxTokenApproval,
|
|
1313
|
-
feebps
|
|
1486
|
+
receiver
|
|
1314
1487
|
} = recurringPaymentParams;
|
|
1315
1488
|
if (amount <= BigInt(0)) {
|
|
1316
1489
|
throw new Error("Amount must be greater than 0.");
|
|
@@ -1321,20 +1494,14 @@ var ActaAccount = class {
|
|
|
1321
1494
|
if (receiver === signerAddress) {
|
|
1322
1495
|
throw new Error("Receiver cannot be the same as the signer.");
|
|
1323
1496
|
}
|
|
1324
|
-
if (!intervalUnit) {
|
|
1325
|
-
throw new Error("Interval unit is required.");
|
|
1326
|
-
}
|
|
1327
1497
|
const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
|
|
1328
1498
|
if (!token2) {
|
|
1329
1499
|
throw new Error("Token not found.");
|
|
1330
1500
|
}
|
|
1331
1501
|
const kernelVersion = import_constants.KERNEL_V3_1;
|
|
1332
1502
|
const entryPoint = (0, import_constants.getEntryPoint)("0.7");
|
|
1333
|
-
const paymentCount = count != null ? count : 24;
|
|
1334
1503
|
const account = yield this.createAccount();
|
|
1335
|
-
const smartAccountAddress = account.address;
|
|
1336
1504
|
const viemClient = new ViemClient(this.chainId, this.signer);
|
|
1337
|
-
const { paymasterClient, pimlicoClient } = yield this.createAccountHelpers();
|
|
1338
1505
|
const ecdsaValidator = yield (0, import_ecdsa_validator.signerToEcdsaValidator)(
|
|
1339
1506
|
viemClient.publicClient(),
|
|
1340
1507
|
{
|
|
@@ -1346,32 +1513,7 @@ var ActaAccount = class {
|
|
|
1346
1513
|
const sessionKeyAddress = "0xFDEed8e268D74DF71f3Db7409F8A8290FF1263ED";
|
|
1347
1514
|
const emptyAccount = (0, import_sdk.addressToEmptyAccount)(sessionKeyAddress);
|
|
1348
1515
|
const emptySessionKeySigner = yield (0, import_signers.toECDSASigner)({ signer: emptyAccount });
|
|
1349
|
-
const
|
|
1350
|
-
paymaster,
|
|
1351
|
-
ActalinkFeesInToken,
|
|
1352
|
-
feeInclusiveAmountInToken,
|
|
1353
|
-
feeExclusiveAmountInToken,
|
|
1354
|
-
estimatedTotalFeesInToken,
|
|
1355
|
-
userOperation,
|
|
1356
|
-
estimatedGasCostInToken
|
|
1357
|
-
} = yield this.estimateSinglePaymentGas({
|
|
1358
|
-
signerAddress,
|
|
1359
|
-
chainId,
|
|
1360
|
-
token: tokenSymbol,
|
|
1361
|
-
amount,
|
|
1362
|
-
receiver,
|
|
1363
|
-
feeInclusive,
|
|
1364
|
-
feebps
|
|
1365
|
-
});
|
|
1366
|
-
const amountToTransfer = feeInclusive ? amount : feeExclusiveAmountInToken;
|
|
1367
|
-
const receiverAmount = feeInclusive ? feeInclusiveAmountInToken : amount;
|
|
1368
|
-
yield viemClient.checkAndApproveToken(
|
|
1369
|
-
token2,
|
|
1370
|
-
smartAccountAddress,
|
|
1371
|
-
amountToTransfer * BigInt(paymentCount) + estimatedGasCostInToken * BigInt(2) * BigInt(paymentCount),
|
|
1372
|
-
allowMaxTokenApproval != null ? allowMaxTokenApproval : false
|
|
1373
|
-
);
|
|
1374
|
-
const amountExclusive = amountToTransfer + amountToTransfer / BigInt(2);
|
|
1516
|
+
const amountExclusive = amount + amount / BigInt(2);
|
|
1375
1517
|
const callPolicy = (0, import_policies.toCallPolicy)({
|
|
1376
1518
|
policyVersion: import_policies.CallPolicyVersion.V0_0_4,
|
|
1377
1519
|
permissions: [
|
|
@@ -1918,6 +2060,7 @@ var ActaFlexDeposit = class {
|
|
|
1918
2060
|
this.status = "not_started";
|
|
1919
2061
|
this.serviceType = "deposit";
|
|
1920
2062
|
this.allowMaxTokenApproval = false;
|
|
2063
|
+
this.feebps = 10;
|
|
1921
2064
|
var _a, _b, _c;
|
|
1922
2065
|
this.connectorType = parameters.connectorType;
|
|
1923
2066
|
this.walletClient = parameters.walletClient;
|
|
@@ -2037,35 +2180,95 @@ var ActaFlexDeposit = class {
|
|
|
2037
2180
|
}
|
|
2038
2181
|
});
|
|
2039
2182
|
}
|
|
2040
|
-
|
|
2183
|
+
estimatePaymentAmount() {
|
|
2041
2184
|
return __async(this, null, function* () {
|
|
2042
2185
|
try {
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2186
|
+
const signerAddress = this.signerAddress;
|
|
2187
|
+
const chainId = this.chainId;
|
|
2188
|
+
const tokenSymbol = this.token;
|
|
2189
|
+
const amount = this.amount;
|
|
2190
|
+
const receiver = this.receiver;
|
|
2191
|
+
const feeInclusive = this.feeInclusive;
|
|
2192
|
+
const feebps = this.feebps;
|
|
2193
|
+
const { totalAmount, actalinkFees, receiverAmount } = yield this.account.estimatePaymentAmount({
|
|
2194
|
+
signerAddress,
|
|
2195
|
+
chainId,
|
|
2196
|
+
token: tokenSymbol,
|
|
2197
|
+
amount,
|
|
2198
|
+
receiver,
|
|
2199
|
+
feeInclusive,
|
|
2200
|
+
feebps
|
|
2201
|
+
});
|
|
2202
|
+
return {
|
|
2203
|
+
totalAmount,
|
|
2204
|
+
actalinkFees,
|
|
2205
|
+
receiverAmount
|
|
2206
|
+
};
|
|
2207
|
+
} catch (error) {
|
|
2208
|
+
if (error instanceof Error) {
|
|
2209
|
+
throw new Error(error.message);
|
|
2058
2210
|
}
|
|
2211
|
+
throw new Error("Failed to estimate payment amount.");
|
|
2212
|
+
}
|
|
2213
|
+
});
|
|
2214
|
+
}
|
|
2215
|
+
checkAllowance() {
|
|
2216
|
+
return __async(this, null, function* () {
|
|
2217
|
+
try {
|
|
2218
|
+
const chainId = this.chainId;
|
|
2219
|
+
const tokenSymbol = this.token;
|
|
2220
|
+
const allowance = yield this.account.checkAllowance({
|
|
2221
|
+
chainId,
|
|
2222
|
+
token: tokenSymbol
|
|
2223
|
+
});
|
|
2224
|
+
return allowance;
|
|
2059
2225
|
} catch (error) {
|
|
2060
|
-
this.status = "payment_failed";
|
|
2061
2226
|
if (error instanceof Error) {
|
|
2062
2227
|
throw new Error(error.message);
|
|
2063
2228
|
}
|
|
2064
|
-
throw new Error("Failed to
|
|
2229
|
+
throw new Error("Failed to check token allowance.");
|
|
2065
2230
|
}
|
|
2066
2231
|
});
|
|
2067
2232
|
}
|
|
2068
|
-
|
|
2233
|
+
approveToken(parameters) {
|
|
2234
|
+
return __async(this, null, function* () {
|
|
2235
|
+
try {
|
|
2236
|
+
const chainId = this.chainId;
|
|
2237
|
+
const tokenSymbol = this.token;
|
|
2238
|
+
const { totalAmount, allowMaxTokenApproval } = parameters;
|
|
2239
|
+
const hash = yield this.account.approveToken({
|
|
2240
|
+
chainId,
|
|
2241
|
+
token: tokenSymbol,
|
|
2242
|
+
amount: totalAmount,
|
|
2243
|
+
allowMaxTokenApproval
|
|
2244
|
+
});
|
|
2245
|
+
return hash;
|
|
2246
|
+
} catch (error) {
|
|
2247
|
+
if (error instanceof Error) {
|
|
2248
|
+
throw new Error(error.message);
|
|
2249
|
+
}
|
|
2250
|
+
throw new Error("Failed to approve token.");
|
|
2251
|
+
}
|
|
2252
|
+
});
|
|
2253
|
+
}
|
|
2254
|
+
waitForTransactionReceipt(hash) {
|
|
2255
|
+
return __async(this, null, function* () {
|
|
2256
|
+
try {
|
|
2257
|
+
const chainId = this.chainId;
|
|
2258
|
+
const receipt = yield this.account.waitForTransactionReceipt({
|
|
2259
|
+
chainId,
|
|
2260
|
+
hash
|
|
2261
|
+
});
|
|
2262
|
+
return receipt;
|
|
2263
|
+
} catch (error) {
|
|
2264
|
+
if (error instanceof Error) {
|
|
2265
|
+
throw new Error(error.message);
|
|
2266
|
+
}
|
|
2267
|
+
throw new Error("Failed to fetch transaction receipt.");
|
|
2268
|
+
}
|
|
2269
|
+
});
|
|
2270
|
+
}
|
|
2271
|
+
createSinglePayment(parameters, servicePaymentParams) {
|
|
2069
2272
|
return __async(this, null, function* () {
|
|
2070
2273
|
try {
|
|
2071
2274
|
if (this.connectorType !== "Self-Custody" /* SELF_CUSTODY */) {
|
|
@@ -2077,18 +2280,12 @@ var ActaFlexDeposit = class {
|
|
|
2077
2280
|
const signerAddress = this.signerAddress;
|
|
2078
2281
|
const chainId = this.chainId;
|
|
2079
2282
|
const tokenSymbol = this.token;
|
|
2080
|
-
const amount = this.amount;
|
|
2081
2283
|
const receiver = this.receiver;
|
|
2284
|
+
const amount = this.amount;
|
|
2082
2285
|
const feeInclusive = this.feeInclusive;
|
|
2083
2286
|
const serviceType = this.serviceType;
|
|
2287
|
+
const { actalinkFees, receiverAmount } = parameters;
|
|
2084
2288
|
const { envTransactionServiceUrl, envDepositServiceUrl } = returnEnvUrl(chainId);
|
|
2085
|
-
if (this.depositSessionId !== "") {
|
|
2086
|
-
const session = yield verifySessionAPICall(
|
|
2087
|
-
`${envDepositServiceUrl}verify-session?sessionId=${this.depositSessionId}`,
|
|
2088
|
-
this.depositSessionId
|
|
2089
|
-
);
|
|
2090
|
-
this.depositSessionId = session.sessionId;
|
|
2091
|
-
}
|
|
2092
2289
|
const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
|
|
2093
2290
|
if (!token2) {
|
|
2094
2291
|
throw new Error("Token not supported.");
|
|
@@ -2097,11 +2294,9 @@ var ActaFlexDeposit = class {
|
|
|
2097
2294
|
signerAddress,
|
|
2098
2295
|
chainId,
|
|
2099
2296
|
token: tokenSymbol,
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
allowMaxTokenApproval: this.allowMaxTokenApproval,
|
|
2104
|
-
feebps: 10
|
|
2297
|
+
actalinkFees,
|
|
2298
|
+
receiverAmount,
|
|
2299
|
+
receiver
|
|
2105
2300
|
});
|
|
2106
2301
|
const txn = yield executeSinglePaymentAPICall(
|
|
2107
2302
|
`${envTransactionServiceUrl}execute/single`,
|
|
@@ -2189,14 +2384,7 @@ var ActaFlexDeposit = class {
|
|
|
2189
2384
|
chainId,
|
|
2190
2385
|
token: tokenSymbol,
|
|
2191
2386
|
amount,
|
|
2192
|
-
|
|
2193
|
-
count,
|
|
2194
|
-
intervalUnit,
|
|
2195
|
-
startDate,
|
|
2196
|
-
endDate,
|
|
2197
|
-
receiver,
|
|
2198
|
-
allowMaxTokenApproval: this.allowMaxTokenApproval,
|
|
2199
|
-
feebps: 20
|
|
2387
|
+
receiver
|
|
2200
2388
|
});
|
|
2201
2389
|
const txn = yield scheduleRecurringPaymentsAPICall(
|
|
2202
2390
|
`${envTransactionServiceUrl}schedule/recurring`,
|
|
@@ -2220,39 +2408,6 @@ var ActaFlexDeposit = class {
|
|
|
2220
2408
|
return txn.recurringTransaction.id;
|
|
2221
2409
|
});
|
|
2222
2410
|
}
|
|
2223
|
-
getPaymentSteps() {
|
|
2224
|
-
return __async(this, null, function* () {
|
|
2225
|
-
const signerAddress = this.signerAddress;
|
|
2226
|
-
const chainId = this.chainId;
|
|
2227
|
-
const tokenSymbol = this.token;
|
|
2228
|
-
const amount = this.amount;
|
|
2229
|
-
const receiver = this.receiver;
|
|
2230
|
-
const feeInclusive = this.feeInclusive;
|
|
2231
|
-
const count = this.count;
|
|
2232
|
-
if (!signerAddress) return ["allowance", "confirm"];
|
|
2233
|
-
const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
|
|
2234
|
-
if (!token2) return ["allowance", "confirm"];
|
|
2235
|
-
const smartAccount = yield this.account.createAccount();
|
|
2236
|
-
const { estimatedGasCostInToken, feeExclusiveAmountInToken } = yield this.account.estimateSinglePaymentGas({
|
|
2237
|
-
chainId,
|
|
2238
|
-
amount,
|
|
2239
|
-
feeInclusive,
|
|
2240
|
-
receiver,
|
|
2241
|
-
signerAddress,
|
|
2242
|
-
token: tokenSymbol,
|
|
2243
|
-
feebps: 10
|
|
2244
|
-
});
|
|
2245
|
-
const amountToTransfer = feeInclusive ? amount : feeExclusiveAmountInToken;
|
|
2246
|
-
let paymentAmount = (amountToTransfer + estimatedGasCostInToken * BigInt(2)) * BigInt(count != null ? count : 1);
|
|
2247
|
-
const allowance = yield this.viemClient.checkTokenAllowance(
|
|
2248
|
-
token2,
|
|
2249
|
-
signerAddress,
|
|
2250
|
-
smartAccount.address
|
|
2251
|
-
);
|
|
2252
|
-
if (paymentAmount <= allowance) return ["confirm"];
|
|
2253
|
-
return ["allowance", "confirm"];
|
|
2254
|
-
});
|
|
2255
|
-
}
|
|
2256
2411
|
};
|
|
2257
2412
|
|
|
2258
2413
|
// src/flexbatch.ts
|
|
@@ -2717,8 +2872,8 @@ var ActaFlexBatch = class {
|
|
|
2717
2872
|
|
|
2718
2873
|
// src/billing.ts
|
|
2719
2874
|
var import_viem7 = require("viem");
|
|
2720
|
-
var billingServiceUrl = "https://api.
|
|
2721
|
-
var billingServiceTestUrl = "https://api.
|
|
2875
|
+
var billingServiceUrl = "https://pay-api.fhoton.xyz/pay/api/v1/";
|
|
2876
|
+
var billingServiceTestUrl = "https://pay-api.fhoton.xyz/pay/test/api/v1/";
|
|
2722
2877
|
var returnEnvUrl3 = (chainId) => {
|
|
2723
2878
|
const mainnetChain = mainnetChains.find((c) => c.id === chainId);
|
|
2724
2879
|
const testnetChain = testnetChains.find((c) => c.id === chainId);
|
|
@@ -2746,6 +2901,7 @@ var ActaBilling = class {
|
|
|
2746
2901
|
this.status = "not_started";
|
|
2747
2902
|
this.serviceType = "deposit";
|
|
2748
2903
|
this.allowMaxTokenApproval = false;
|
|
2904
|
+
this.feebps = 20;
|
|
2749
2905
|
var _a, _b;
|
|
2750
2906
|
this.connectorType = parameters.connectorType;
|
|
2751
2907
|
this.walletClient = parameters.walletClient;
|
|
@@ -2801,7 +2957,95 @@ var ActaBilling = class {
|
|
|
2801
2957
|
}
|
|
2802
2958
|
});
|
|
2803
2959
|
}
|
|
2804
|
-
|
|
2960
|
+
estimatePaymentAmount() {
|
|
2961
|
+
return __async(this, null, function* () {
|
|
2962
|
+
try {
|
|
2963
|
+
const signerAddress = this.signerAddress;
|
|
2964
|
+
const chainId = this.chainId;
|
|
2965
|
+
const tokenSymbol = this.token;
|
|
2966
|
+
const amount = this.amount;
|
|
2967
|
+
const receiver = this.receiver;
|
|
2968
|
+
const feeInclusive = this.feeInclusive;
|
|
2969
|
+
const feebps = this.feebps;
|
|
2970
|
+
const { totalAmount, actalinkFees, receiverAmount } = yield this.account.estimatePaymentAmount({
|
|
2971
|
+
signerAddress,
|
|
2972
|
+
chainId,
|
|
2973
|
+
token: tokenSymbol,
|
|
2974
|
+
amount,
|
|
2975
|
+
receiver,
|
|
2976
|
+
feeInclusive,
|
|
2977
|
+
feebps
|
|
2978
|
+
});
|
|
2979
|
+
return {
|
|
2980
|
+
totalAmount,
|
|
2981
|
+
actalinkFees,
|
|
2982
|
+
receiverAmount
|
|
2983
|
+
};
|
|
2984
|
+
} catch (error) {
|
|
2985
|
+
if (error instanceof Error) {
|
|
2986
|
+
throw new Error(error.message);
|
|
2987
|
+
}
|
|
2988
|
+
throw new Error("Failed to estimate payment amount.");
|
|
2989
|
+
}
|
|
2990
|
+
});
|
|
2991
|
+
}
|
|
2992
|
+
checkAllowance() {
|
|
2993
|
+
return __async(this, null, function* () {
|
|
2994
|
+
try {
|
|
2995
|
+
const chainId = this.chainId;
|
|
2996
|
+
const tokenSymbol = this.token;
|
|
2997
|
+
const allowance = yield this.account.checkAllowance({
|
|
2998
|
+
chainId,
|
|
2999
|
+
token: tokenSymbol
|
|
3000
|
+
});
|
|
3001
|
+
return allowance;
|
|
3002
|
+
} catch (error) {
|
|
3003
|
+
if (error instanceof Error) {
|
|
3004
|
+
throw new Error(error.message);
|
|
3005
|
+
}
|
|
3006
|
+
throw new Error("Failed to check token allowance.");
|
|
3007
|
+
}
|
|
3008
|
+
});
|
|
3009
|
+
}
|
|
3010
|
+
approveToken(parameters) {
|
|
3011
|
+
return __async(this, null, function* () {
|
|
3012
|
+
try {
|
|
3013
|
+
const chainId = this.chainId;
|
|
3014
|
+
const tokenSymbol = this.token;
|
|
3015
|
+
const { totalAmount, allowMaxTokenApproval } = parameters;
|
|
3016
|
+
const hash = yield this.account.approveToken({
|
|
3017
|
+
chainId,
|
|
3018
|
+
token: tokenSymbol,
|
|
3019
|
+
amount: totalAmount,
|
|
3020
|
+
allowMaxTokenApproval
|
|
3021
|
+
});
|
|
3022
|
+
return hash;
|
|
3023
|
+
} catch (error) {
|
|
3024
|
+
if (error instanceof Error) {
|
|
3025
|
+
throw new Error(error.message);
|
|
3026
|
+
}
|
|
3027
|
+
throw new Error("Failed to approve token.");
|
|
3028
|
+
}
|
|
3029
|
+
});
|
|
3030
|
+
}
|
|
3031
|
+
waitForTransactionReceipt(hash) {
|
|
3032
|
+
return __async(this, null, function* () {
|
|
3033
|
+
try {
|
|
3034
|
+
const chainId = this.chainId;
|
|
3035
|
+
const receipt = yield this.account.waitForTransactionReceipt({
|
|
3036
|
+
chainId,
|
|
3037
|
+
hash
|
|
3038
|
+
});
|
|
3039
|
+
return receipt;
|
|
3040
|
+
} catch (error) {
|
|
3041
|
+
if (error instanceof Error) {
|
|
3042
|
+
throw new Error(error.message);
|
|
3043
|
+
}
|
|
3044
|
+
throw new Error("Failed to fetch transaction receipt.");
|
|
3045
|
+
}
|
|
3046
|
+
});
|
|
3047
|
+
}
|
|
3048
|
+
createSinglePayment(parameters, servicePaymentParams) {
|
|
2805
3049
|
return __async(this, null, function* () {
|
|
2806
3050
|
try {
|
|
2807
3051
|
if (this.connectorType !== "Self-Custody" /* SELF_CUSTODY */) {
|
|
@@ -2810,6 +3054,7 @@ var ActaBilling = class {
|
|
|
2810
3054
|
if (!servicePaymentParams.checkoutSessionId || servicePaymentParams.checkoutSessionId === "") {
|
|
2811
3055
|
throw new Error("checkout session ID is required.");
|
|
2812
3056
|
}
|
|
3057
|
+
const { actalinkFees, receiverAmount } = parameters;
|
|
2813
3058
|
const signerAddress = this.signerAddress;
|
|
2814
3059
|
const chainId = this.chainId;
|
|
2815
3060
|
const tokenSymbol = this.token;
|
|
@@ -2826,11 +3071,9 @@ var ActaBilling = class {
|
|
|
2826
3071
|
signerAddress,
|
|
2827
3072
|
chainId,
|
|
2828
3073
|
token: tokenSymbol,
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
allowMaxTokenApproval: this.allowMaxTokenApproval,
|
|
2833
|
-
feebps: 20
|
|
3074
|
+
actalinkFees,
|
|
3075
|
+
receiverAmount,
|
|
3076
|
+
receiver
|
|
2834
3077
|
});
|
|
2835
3078
|
const txn = yield executeSinglePaymentAPICall(
|
|
2836
3079
|
`${envBillingServiceUrl}execute/single`,
|
|
@@ -2890,14 +3133,7 @@ var ActaBilling = class {
|
|
|
2890
3133
|
chainId,
|
|
2891
3134
|
token: tokenSymbol,
|
|
2892
3135
|
amount,
|
|
2893
|
-
|
|
2894
|
-
count,
|
|
2895
|
-
intervalUnit,
|
|
2896
|
-
startDate,
|
|
2897
|
-
endDate,
|
|
2898
|
-
receiver,
|
|
2899
|
-
allowMaxTokenApproval: this.allowMaxTokenApproval,
|
|
2900
|
-
feebps: 20
|
|
3136
|
+
receiver
|
|
2901
3137
|
});
|
|
2902
3138
|
const txn = yield scheduleSubscriptionPaymentsAPICall(
|
|
2903
3139
|
`${envBillingServiceUrl}schedule/subscription`,
|