@actalink/commonlib 0.1.0 → 0.1.2-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 +358 -147
- package/dist/index.d.cts +430 -381
- package/dist/index.d.ts +430 -381
- package/dist/index.js +367 -156
- 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
|
|
@@ -1131,7 +1168,7 @@ var ActaAccount = class {
|
|
|
1131
1168
|
};
|
|
1132
1169
|
});
|
|
1133
1170
|
}
|
|
1134
|
-
|
|
1171
|
+
estimatePaymentAmount(singlePaymentParams) {
|
|
1135
1172
|
return __async(this, null, function* () {
|
|
1136
1173
|
try {
|
|
1137
1174
|
if (!this.signer) {
|
|
@@ -1144,7 +1181,6 @@ var ActaAccount = class {
|
|
|
1144
1181
|
amount,
|
|
1145
1182
|
receiver,
|
|
1146
1183
|
feeInclusive,
|
|
1147
|
-
allowMaxTokenApproval,
|
|
1148
1184
|
feebps
|
|
1149
1185
|
} = singlePaymentParams;
|
|
1150
1186
|
if (amount <= BigInt(0)) {
|
|
@@ -1157,14 +1193,10 @@ var ActaAccount = class {
|
|
|
1157
1193
|
if (!token2) {
|
|
1158
1194
|
throw new Error("Token not found.");
|
|
1159
1195
|
}
|
|
1160
|
-
const viemClient = new ViemClient(this.chainId, this.signer);
|
|
1161
1196
|
const {
|
|
1162
|
-
estimatedGasCostInToken,
|
|
1163
|
-
ActalinkFeesInToken,
|
|
1164
1197
|
feeInclusiveAmountInToken,
|
|
1165
1198
|
feeExclusiveAmountInToken,
|
|
1166
|
-
estimatedTotalFeesInToken
|
|
1167
|
-
paymaster
|
|
1199
|
+
estimatedTotalFeesInToken
|
|
1168
1200
|
} = yield this.estimateSinglePaymentGas({
|
|
1169
1201
|
signerAddress,
|
|
1170
1202
|
chainId,
|
|
@@ -1174,18 +1206,141 @@ var ActaAccount = class {
|
|
|
1174
1206
|
feeInclusive,
|
|
1175
1207
|
feebps
|
|
1176
1208
|
});
|
|
1177
|
-
const
|
|
1178
|
-
const
|
|
1179
|
-
const fromAddress = signerAddress;
|
|
1180
|
-
const smartAccountAddress = account.address;
|
|
1181
|
-
const amountToTransfer = feeInclusive ? amount : feeExclusiveAmountInToken;
|
|
1209
|
+
const totalAmount = feeInclusive ? amount : feeExclusiveAmountInToken;
|
|
1210
|
+
const actalinkFees = estimatedTotalFeesInToken;
|
|
1182
1211
|
const receiverAmount = feeInclusive ? feeInclusiveAmountInToken : amount;
|
|
1183
|
-
|
|
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(
|
|
1184
1279
|
token2,
|
|
1185
1280
|
smartAccountAddress,
|
|
1186
|
-
|
|
1187
|
-
allowMaxTokenApproval
|
|
1281
|
+
amount,
|
|
1282
|
+
allowMaxTokenApproval
|
|
1188
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;
|
|
1189
1344
|
const userOperation = yield accountClient.prepareUserOperation({
|
|
1190
1345
|
calls: [
|
|
1191
1346
|
{
|
|
@@ -1195,7 +1350,7 @@ var ActaAccount = class {
|
|
|
1195
1350
|
args: [
|
|
1196
1351
|
fromAddress,
|
|
1197
1352
|
"0x26eeCa5956Bf8C01040BAC9e6D7982a0e87F31B4",
|
|
1198
|
-
|
|
1353
|
+
actalinkFees
|
|
1199
1354
|
]
|
|
1200
1355
|
},
|
|
1201
1356
|
{
|
|
@@ -1328,14 +1483,7 @@ var ActaAccount = class {
|
|
|
1328
1483
|
chainId,
|
|
1329
1484
|
token: tokenSymbol,
|
|
1330
1485
|
amount,
|
|
1331
|
-
receiver
|
|
1332
|
-
feeInclusive,
|
|
1333
|
-
count,
|
|
1334
|
-
intervalUnit,
|
|
1335
|
-
startDate,
|
|
1336
|
-
endDate,
|
|
1337
|
-
allowMaxTokenApproval,
|
|
1338
|
-
feebps
|
|
1486
|
+
receiver
|
|
1339
1487
|
} = recurringPaymentParams;
|
|
1340
1488
|
if (amount <= BigInt(0)) {
|
|
1341
1489
|
throw new Error("Amount must be greater than 0.");
|
|
@@ -1346,20 +1494,14 @@ var ActaAccount = class {
|
|
|
1346
1494
|
if (receiver === signerAddress) {
|
|
1347
1495
|
throw new Error("Receiver cannot be the same as the signer.");
|
|
1348
1496
|
}
|
|
1349
|
-
if (!intervalUnit) {
|
|
1350
|
-
throw new Error("Interval unit is required.");
|
|
1351
|
-
}
|
|
1352
1497
|
const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
|
|
1353
1498
|
if (!token2) {
|
|
1354
1499
|
throw new Error("Token not found.");
|
|
1355
1500
|
}
|
|
1356
1501
|
const kernelVersion = import_constants.KERNEL_V3_1;
|
|
1357
1502
|
const entryPoint = (0, import_constants.getEntryPoint)("0.7");
|
|
1358
|
-
const paymentCount = count != null ? count : 24;
|
|
1359
1503
|
const account = yield this.createAccount();
|
|
1360
|
-
const smartAccountAddress = account.address;
|
|
1361
1504
|
const viemClient = new ViemClient(this.chainId, this.signer);
|
|
1362
|
-
const { paymasterClient, pimlicoClient } = yield this.createAccountHelpers();
|
|
1363
1505
|
const ecdsaValidator = yield (0, import_ecdsa_validator.signerToEcdsaValidator)(
|
|
1364
1506
|
viemClient.publicClient(),
|
|
1365
1507
|
{
|
|
@@ -1371,32 +1513,7 @@ var ActaAccount = class {
|
|
|
1371
1513
|
const sessionKeyAddress = "0xFDEed8e268D74DF71f3Db7409F8A8290FF1263ED";
|
|
1372
1514
|
const emptyAccount = (0, import_sdk.addressToEmptyAccount)(sessionKeyAddress);
|
|
1373
1515
|
const emptySessionKeySigner = yield (0, import_signers.toECDSASigner)({ signer: emptyAccount });
|
|
1374
|
-
const
|
|
1375
|
-
paymaster,
|
|
1376
|
-
ActalinkFeesInToken,
|
|
1377
|
-
feeInclusiveAmountInToken,
|
|
1378
|
-
feeExclusiveAmountInToken,
|
|
1379
|
-
estimatedTotalFeesInToken,
|
|
1380
|
-
userOperation,
|
|
1381
|
-
estimatedGasCostInToken
|
|
1382
|
-
} = yield this.estimateSinglePaymentGas({
|
|
1383
|
-
signerAddress,
|
|
1384
|
-
chainId,
|
|
1385
|
-
token: tokenSymbol,
|
|
1386
|
-
amount,
|
|
1387
|
-
receiver,
|
|
1388
|
-
feeInclusive,
|
|
1389
|
-
feebps
|
|
1390
|
-
});
|
|
1391
|
-
const amountToTransfer = feeInclusive ? amount : feeExclusiveAmountInToken;
|
|
1392
|
-
const receiverAmount = feeInclusive ? feeInclusiveAmountInToken : amount;
|
|
1393
|
-
yield viemClient.checkAndApproveToken(
|
|
1394
|
-
token2,
|
|
1395
|
-
smartAccountAddress,
|
|
1396
|
-
amountToTransfer * BigInt(paymentCount) + estimatedGasCostInToken * BigInt(2) * BigInt(paymentCount),
|
|
1397
|
-
allowMaxTokenApproval != null ? allowMaxTokenApproval : false
|
|
1398
|
-
);
|
|
1399
|
-
const amountExclusive = amountToTransfer + amountToTransfer / BigInt(2);
|
|
1516
|
+
const amountExclusive = amount + amount / BigInt(2);
|
|
1400
1517
|
const callPolicy = (0, import_policies.toCallPolicy)({
|
|
1401
1518
|
policyVersion: import_policies.CallPolicyVersion.V0_0_4,
|
|
1402
1519
|
permissions: [
|
|
@@ -1943,6 +2060,7 @@ var ActaFlexDeposit = class {
|
|
|
1943
2060
|
this.status = "not_started";
|
|
1944
2061
|
this.serviceType = "deposit";
|
|
1945
2062
|
this.allowMaxTokenApproval = false;
|
|
2063
|
+
this.feebps = 10;
|
|
1946
2064
|
var _a, _b, _c;
|
|
1947
2065
|
this.connectorType = parameters.connectorType;
|
|
1948
2066
|
this.walletClient = parameters.walletClient;
|
|
@@ -2062,35 +2180,95 @@ var ActaFlexDeposit = class {
|
|
|
2062
2180
|
}
|
|
2063
2181
|
});
|
|
2064
2182
|
}
|
|
2065
|
-
|
|
2183
|
+
estimatePaymentAmount() {
|
|
2184
|
+
return __async(this, null, function* () {
|
|
2185
|
+
try {
|
|
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);
|
|
2210
|
+
}
|
|
2211
|
+
throw new Error("Failed to estimate payment amount.");
|
|
2212
|
+
}
|
|
2213
|
+
});
|
|
2214
|
+
}
|
|
2215
|
+
checkAllowance() {
|
|
2066
2216
|
return __async(this, null, function* () {
|
|
2067
2217
|
try {
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
const paymentParams = this.serviceType === "deposit" ? __spreadProps(__spreadValues({}, servicePaymentParams), {
|
|
2079
|
-
depositSessionId: this.depositSessionId
|
|
2080
|
-
}) : servicePaymentParams;
|
|
2081
|
-
const id = yield this.createRecurringPayments(paymentParams);
|
|
2082
|
-
return id;
|
|
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;
|
|
2225
|
+
} catch (error) {
|
|
2226
|
+
if (error instanceof Error) {
|
|
2227
|
+
throw new Error(error.message);
|
|
2083
2228
|
}
|
|
2229
|
+
throw new Error("Failed to check token allowance.");
|
|
2230
|
+
}
|
|
2231
|
+
});
|
|
2232
|
+
}
|
|
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;
|
|
2084
2246
|
} catch (error) {
|
|
2085
|
-
this.status = "payment_failed";
|
|
2086
2247
|
if (error instanceof Error) {
|
|
2087
2248
|
throw new Error(error.message);
|
|
2088
2249
|
}
|
|
2089
|
-
throw new Error("Failed to
|
|
2250
|
+
throw new Error("Failed to approve token.");
|
|
2090
2251
|
}
|
|
2091
2252
|
});
|
|
2092
2253
|
}
|
|
2093
|
-
|
|
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) {
|
|
2094
2272
|
return __async(this, null, function* () {
|
|
2095
2273
|
try {
|
|
2096
2274
|
if (this.connectorType !== "Self-Custody" /* SELF_CUSTODY */) {
|
|
@@ -2102,18 +2280,12 @@ var ActaFlexDeposit = class {
|
|
|
2102
2280
|
const signerAddress = this.signerAddress;
|
|
2103
2281
|
const chainId = this.chainId;
|
|
2104
2282
|
const tokenSymbol = this.token;
|
|
2105
|
-
const amount = this.amount;
|
|
2106
2283
|
const receiver = this.receiver;
|
|
2284
|
+
const amount = this.amount;
|
|
2107
2285
|
const feeInclusive = this.feeInclusive;
|
|
2108
2286
|
const serviceType = this.serviceType;
|
|
2287
|
+
const { actalinkFees, receiverAmount } = parameters;
|
|
2109
2288
|
const { envTransactionServiceUrl, envDepositServiceUrl } = returnEnvUrl(chainId);
|
|
2110
|
-
if (this.depositSessionId !== "") {
|
|
2111
|
-
const session = yield verifySessionAPICall(
|
|
2112
|
-
`${envDepositServiceUrl}verify-session?sessionId=${this.depositSessionId}`,
|
|
2113
|
-
this.depositSessionId
|
|
2114
|
-
);
|
|
2115
|
-
this.depositSessionId = session.sessionId;
|
|
2116
|
-
}
|
|
2117
2289
|
const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
|
|
2118
2290
|
if (!token2) {
|
|
2119
2291
|
throw new Error("Token not supported.");
|
|
@@ -2122,11 +2294,9 @@ var ActaFlexDeposit = class {
|
|
|
2122
2294
|
signerAddress,
|
|
2123
2295
|
chainId,
|
|
2124
2296
|
token: tokenSymbol,
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
allowMaxTokenApproval: this.allowMaxTokenApproval,
|
|
2129
|
-
feebps: 10
|
|
2297
|
+
actalinkFees,
|
|
2298
|
+
receiverAmount,
|
|
2299
|
+
receiver
|
|
2130
2300
|
});
|
|
2131
2301
|
const txn = yield executeSinglePaymentAPICall(
|
|
2132
2302
|
`${envTransactionServiceUrl}execute/single`,
|
|
@@ -2214,14 +2384,7 @@ var ActaFlexDeposit = class {
|
|
|
2214
2384
|
chainId,
|
|
2215
2385
|
token: tokenSymbol,
|
|
2216
2386
|
amount,
|
|
2217
|
-
|
|
2218
|
-
count,
|
|
2219
|
-
intervalUnit,
|
|
2220
|
-
startDate,
|
|
2221
|
-
endDate,
|
|
2222
|
-
receiver,
|
|
2223
|
-
allowMaxTokenApproval: this.allowMaxTokenApproval,
|
|
2224
|
-
feebps: 20
|
|
2387
|
+
receiver
|
|
2225
2388
|
});
|
|
2226
2389
|
const txn = yield scheduleRecurringPaymentsAPICall(
|
|
2227
2390
|
`${envTransactionServiceUrl}schedule/recurring`,
|
|
@@ -2245,39 +2408,6 @@ var ActaFlexDeposit = class {
|
|
|
2245
2408
|
return txn.recurringTransaction.id;
|
|
2246
2409
|
});
|
|
2247
2410
|
}
|
|
2248
|
-
getPaymentSteps() {
|
|
2249
|
-
return __async(this, null, function* () {
|
|
2250
|
-
const signerAddress = this.signerAddress;
|
|
2251
|
-
const chainId = this.chainId;
|
|
2252
|
-
const tokenSymbol = this.token;
|
|
2253
|
-
const amount = this.amount;
|
|
2254
|
-
const receiver = this.receiver;
|
|
2255
|
-
const feeInclusive = this.feeInclusive;
|
|
2256
|
-
const count = this.count;
|
|
2257
|
-
if (!signerAddress) return ["allowance", "confirm"];
|
|
2258
|
-
const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
|
|
2259
|
-
if (!token2) return ["allowance", "confirm"];
|
|
2260
|
-
const smartAccount = yield this.account.createAccount();
|
|
2261
|
-
const { estimatedGasCostInToken, feeExclusiveAmountInToken } = yield this.account.estimateSinglePaymentGas({
|
|
2262
|
-
chainId,
|
|
2263
|
-
amount,
|
|
2264
|
-
feeInclusive,
|
|
2265
|
-
receiver,
|
|
2266
|
-
signerAddress,
|
|
2267
|
-
token: tokenSymbol,
|
|
2268
|
-
feebps: 10
|
|
2269
|
-
});
|
|
2270
|
-
const amountToTransfer = feeInclusive ? amount : feeExclusiveAmountInToken;
|
|
2271
|
-
let paymentAmount = (amountToTransfer + estimatedGasCostInToken * BigInt(2)) * BigInt(count != null ? count : 1);
|
|
2272
|
-
const allowance = yield this.viemClient.checkTokenAllowance(
|
|
2273
|
-
token2,
|
|
2274
|
-
signerAddress,
|
|
2275
|
-
smartAccount.address
|
|
2276
|
-
);
|
|
2277
|
-
if (paymentAmount <= allowance) return ["confirm"];
|
|
2278
|
-
return ["allowance", "confirm"];
|
|
2279
|
-
});
|
|
2280
|
-
}
|
|
2281
2411
|
};
|
|
2282
2412
|
|
|
2283
2413
|
// src/flexbatch.ts
|
|
@@ -2742,8 +2872,8 @@ var ActaFlexBatch = class {
|
|
|
2742
2872
|
|
|
2743
2873
|
// src/billing.ts
|
|
2744
2874
|
var import_viem7 = require("viem");
|
|
2745
|
-
var billingServiceUrl = "https://api.
|
|
2746
|
-
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/";
|
|
2747
2877
|
var returnEnvUrl3 = (chainId) => {
|
|
2748
2878
|
const mainnetChain = mainnetChains.find((c) => c.id === chainId);
|
|
2749
2879
|
const testnetChain = testnetChains.find((c) => c.id === chainId);
|
|
@@ -2771,6 +2901,7 @@ var ActaBilling = class {
|
|
|
2771
2901
|
this.status = "not_started";
|
|
2772
2902
|
this.serviceType = "deposit";
|
|
2773
2903
|
this.allowMaxTokenApproval = false;
|
|
2904
|
+
this.feebps = 20;
|
|
2774
2905
|
var _a, _b;
|
|
2775
2906
|
this.connectorType = parameters.connectorType;
|
|
2776
2907
|
this.walletClient = parameters.walletClient;
|
|
@@ -2826,7 +2957,95 @@ var ActaBilling = class {
|
|
|
2826
2957
|
}
|
|
2827
2958
|
});
|
|
2828
2959
|
}
|
|
2829
|
-
|
|
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) {
|
|
2830
3049
|
return __async(this, null, function* () {
|
|
2831
3050
|
try {
|
|
2832
3051
|
if (this.connectorType !== "Self-Custody" /* SELF_CUSTODY */) {
|
|
@@ -2835,6 +3054,7 @@ var ActaBilling = class {
|
|
|
2835
3054
|
if (!servicePaymentParams.checkoutSessionId || servicePaymentParams.checkoutSessionId === "") {
|
|
2836
3055
|
throw new Error("checkout session ID is required.");
|
|
2837
3056
|
}
|
|
3057
|
+
const { actalinkFees, receiverAmount } = parameters;
|
|
2838
3058
|
const signerAddress = this.signerAddress;
|
|
2839
3059
|
const chainId = this.chainId;
|
|
2840
3060
|
const tokenSymbol = this.token;
|
|
@@ -2851,11 +3071,9 @@ var ActaBilling = class {
|
|
|
2851
3071
|
signerAddress,
|
|
2852
3072
|
chainId,
|
|
2853
3073
|
token: tokenSymbol,
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
allowMaxTokenApproval: this.allowMaxTokenApproval,
|
|
2858
|
-
feebps: 20
|
|
3074
|
+
actalinkFees,
|
|
3075
|
+
receiverAmount,
|
|
3076
|
+
receiver
|
|
2859
3077
|
});
|
|
2860
3078
|
const txn = yield executeSinglePaymentAPICall(
|
|
2861
3079
|
`${envBillingServiceUrl}execute/single`,
|
|
@@ -2915,14 +3133,7 @@ var ActaBilling = class {
|
|
|
2915
3133
|
chainId,
|
|
2916
3134
|
token: tokenSymbol,
|
|
2917
3135
|
amount,
|
|
2918
|
-
|
|
2919
|
-
count,
|
|
2920
|
-
intervalUnit,
|
|
2921
|
-
startDate,
|
|
2922
|
-
endDate,
|
|
2923
|
-
receiver,
|
|
2924
|
-
allowMaxTokenApproval: this.allowMaxTokenApproval,
|
|
2925
|
-
feebps: 20
|
|
3136
|
+
receiver
|
|
2926
3137
|
});
|
|
2927
3138
|
const txn = yield scheduleSubscriptionPaymentsAPICall(
|
|
2928
3139
|
`${envBillingServiceUrl}schedule/subscription`,
|
|
@@ -3452,10 +3663,10 @@ var import_account_abstraction2 = require("viem/account-abstraction");
|
|
|
3452
3663
|
var import_policies2 = require("@zerodev/permissions/policies");
|
|
3453
3664
|
var import_semver = require("semver");
|
|
3454
3665
|
var ECDSA_SIGNER_CONTRACT = "0x6A6F069E2a08c2468e7724Ab3250CdBFBA14D4FF";
|
|
3455
|
-
var billingServiceUrl2 = "https://api.acta.link/pay/v1/";
|
|
3456
3666
|
var depositServiceUrl2 = "https://api.acta.link/bexo/v1/";
|
|
3457
3667
|
var transactionServiceUrl2 = "https://api.acta.link/transaction/v1/";
|
|
3458
|
-
var
|
|
3668
|
+
var billingServiceUrl2 = "https://pay-api.fhoton.xyz/pay/api/v1/";
|
|
3669
|
+
var billingServiceTestUrl2 = "https://pay-api.fhoton.xyz/pay/test/api/v1/";
|
|
3459
3670
|
var toSignerId = (signer) => {
|
|
3460
3671
|
return (0, import_viem9.encodeAbiParameters)(
|
|
3461
3672
|
[{ name: "signerData", type: "bytes" }],
|