@agglayer/sdk 1.0.0-beta.27 → 1.0.0-beta.29
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/README.md +2 -0
- package/dist/index.d.mts +16 -7
- package/dist/index.d.ts +16 -7
- package/dist/index.js +78 -46
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +76 -45
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -21,7 +21,7 @@ var ChainRegistry = class _ChainRegistry {
|
|
|
21
21
|
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
22
22
|
blockExplorer: { name: "Etherscan", url: "https://etherscan.io" },
|
|
23
23
|
bridgeAddress: "",
|
|
24
|
-
proofApiUrl: "https://api
|
|
24
|
+
proofApiUrl: "https://bridge-hub-api.polygon.technology/mainnet/",
|
|
25
25
|
isTestnet: false
|
|
26
26
|
});
|
|
27
27
|
this.registerChain({
|
|
@@ -35,7 +35,7 @@ var ChainRegistry = class _ChainRegistry {
|
|
|
35
35
|
url: "https://katanascan.com"
|
|
36
36
|
},
|
|
37
37
|
bridgeAddress: "",
|
|
38
|
-
proofApiUrl: "https://api
|
|
38
|
+
proofApiUrl: "https://bridge-hub-api.polygon.technology/mainnet/",
|
|
39
39
|
isTestnet: false
|
|
40
40
|
});
|
|
41
41
|
this.registerChain({
|
|
@@ -49,7 +49,7 @@ var ChainRegistry = class _ChainRegistry {
|
|
|
49
49
|
url: "https://sepolia.etherscan.io"
|
|
50
50
|
},
|
|
51
51
|
bridgeAddress: "0x528e26b25a34a4A5d0dbDa1d57D318153d2ED582",
|
|
52
|
-
proofApiUrl: "https://api
|
|
52
|
+
proofApiUrl: "https://bridge-hub-api.polygon.technology/testnet/",
|
|
53
53
|
isTestnet: true
|
|
54
54
|
});
|
|
55
55
|
}
|
|
@@ -251,11 +251,12 @@ var BaseContract = class {
|
|
|
251
251
|
/**
|
|
252
252
|
* Estimate gas for transaction
|
|
253
253
|
*/
|
|
254
|
-
async estimateGas(data, to, from) {
|
|
254
|
+
async estimateGas(data, to, from, value) {
|
|
255
255
|
const gasEstimate = await this.client.estimateGas({
|
|
256
256
|
account: from,
|
|
257
257
|
to,
|
|
258
|
-
data
|
|
258
|
+
data,
|
|
259
|
+
value
|
|
259
260
|
});
|
|
260
261
|
return gasEstimate.toString();
|
|
261
262
|
}
|
|
@@ -612,6 +613,21 @@ var bridgeAbi = [
|
|
|
612
613
|
}
|
|
613
614
|
];
|
|
614
615
|
|
|
616
|
+
// src/constants.ts
|
|
617
|
+
var ARC_API_BASE_URL = "https://arc-api.polygon.technology";
|
|
618
|
+
var ARC_API_DEFAULT_TIMEOUT = 3e4;
|
|
619
|
+
var LIFI_API_BASE_URL = "https://li.quest";
|
|
620
|
+
var LIFI_API_DEFAULT_TIMEOUT = 5e3;
|
|
621
|
+
var DEFAULT_CHAINS_PER_PAGE = 100;
|
|
622
|
+
var DEFAULT_CHAINS_WITH_TOKENS_PER_PAGE = 1;
|
|
623
|
+
var MAX_TRANSACTIONS_PER_PAGE = 100;
|
|
624
|
+
var NETWORKS = {
|
|
625
|
+
ETHEREUM: 1,
|
|
626
|
+
KATANA: 747474
|
|
627
|
+
};
|
|
628
|
+
var DEFAULT_NETWORK = NETWORKS.ETHEREUM;
|
|
629
|
+
var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
630
|
+
|
|
615
631
|
// src/native/bridge/build.ts
|
|
616
632
|
async function buildBridgeAsset(ctx, destinationNetwork, destinationAddress, amount, token, forceUpdateGlobalExitRoot, permitData = "0x", from) {
|
|
617
633
|
const data = encodeFunctionData2({
|
|
@@ -626,17 +642,23 @@ async function buildBridgeAsset(ctx, destinationNetwork, destinationAddress, amo
|
|
|
626
642
|
permitData
|
|
627
643
|
]
|
|
628
644
|
});
|
|
645
|
+
const isNativeETH = token.toLowerCase() === ZERO_ADDRESS;
|
|
646
|
+
const value = isNativeETH ? amount : void 0;
|
|
629
647
|
const [nonce, gas] = await Promise.all([
|
|
630
648
|
ctx.getNonce(from),
|
|
631
|
-
ctx.estimateGas(data, ctx.bridgeAddress, from)
|
|
649
|
+
ctx.estimateGas(data, ctx.bridgeAddress, from, value)
|
|
632
650
|
]);
|
|
633
|
-
|
|
651
|
+
const result = {
|
|
634
652
|
from,
|
|
635
653
|
to: ctx.bridgeAddress,
|
|
636
654
|
data,
|
|
637
655
|
gas,
|
|
638
656
|
nonce
|
|
639
657
|
};
|
|
658
|
+
if (isNativeETH) {
|
|
659
|
+
result.value = amount.toString();
|
|
660
|
+
}
|
|
661
|
+
return result;
|
|
640
662
|
}
|
|
641
663
|
async function buildClaimAsset(ctx, smtProofLocalExitRoot, smtProofRollupExitRoot, globalIndex, mainnetExitRoot, rollupExitRoot, originNetwork, originTokenAddress, destinationNetwork, destinationAddress, amount, metadata, from) {
|
|
642
664
|
const data = encodeFunctionData2({
|
|
@@ -835,12 +857,12 @@ var BridgeUtil = class _BridgeUtil {
|
|
|
835
857
|
}
|
|
836
858
|
}
|
|
837
859
|
/**
|
|
838
|
-
* Fetch merkle proof from Polygon's
|
|
860
|
+
* Fetch merkle proof from Polygon's hub API
|
|
839
861
|
*/
|
|
840
|
-
async fetchMerkleProof(networkId, depositCount) {
|
|
862
|
+
async fetchMerkleProof(networkId, depositCount, leafIndex) {
|
|
841
863
|
try {
|
|
842
864
|
const baseUrl = this.proofApiUrl.endsWith("/") ? this.proofApiUrl : `${this.proofApiUrl}/`;
|
|
843
|
-
const url = `${baseUrl}
|
|
865
|
+
const url = `${baseUrl}claim-proof?sourceNetworkId=${networkId}&depositCount=${depositCount}&leafIndex=${leafIndex}`;
|
|
844
866
|
const response = await fetch(url);
|
|
845
867
|
if (!response.ok) {
|
|
846
868
|
throw new Error(
|
|
@@ -848,10 +870,10 @@ var BridgeUtil = class _BridgeUtil {
|
|
|
848
870
|
);
|
|
849
871
|
}
|
|
850
872
|
const data = await response.json();
|
|
851
|
-
if (!data.
|
|
873
|
+
if (data.status !== "success" || !data.data) {
|
|
852
874
|
throw new Error("Invalid response format: missing proof data");
|
|
853
875
|
}
|
|
854
|
-
return data.
|
|
876
|
+
return data.data;
|
|
855
877
|
} catch (error) {
|
|
856
878
|
if (error instanceof Error) {
|
|
857
879
|
throw new Error(`Failed to fetch merkle proof: ${error.message}`);
|
|
@@ -873,7 +895,7 @@ var BridgeUtil = class _BridgeUtil {
|
|
|
873
895
|
/**
|
|
874
896
|
* Build claim payload from transaction hash (user-friendly method)
|
|
875
897
|
*/
|
|
876
|
-
async buildPayloadForClaim(transactionHash, sourceNetworkId, bridgeIndex = 0) {
|
|
898
|
+
async buildPayloadForClaim(transactionHash, sourceNetworkId, leafIndex, bridgeIndex = 0) {
|
|
877
899
|
const bridgeEvent = await this.extractBridgeEvent(
|
|
878
900
|
transactionHash,
|
|
879
901
|
sourceNetworkId,
|
|
@@ -881,18 +903,19 @@ var BridgeUtil = class _BridgeUtil {
|
|
|
881
903
|
);
|
|
882
904
|
const proof = await this.fetchMerkleProof(
|
|
883
905
|
sourceNetworkId,
|
|
884
|
-
bridgeEvent.depositCount
|
|
906
|
+
bridgeEvent.depositCount,
|
|
907
|
+
leafIndex
|
|
885
908
|
);
|
|
886
909
|
const globalIndex = this.computeGlobalIndex(
|
|
887
910
|
bridgeEvent.depositCount,
|
|
888
911
|
sourceNetworkId
|
|
889
912
|
);
|
|
890
913
|
return {
|
|
891
|
-
smtProof: proof.
|
|
892
|
-
smtProofRollup: proof.
|
|
914
|
+
smtProof: proof.proof_local_exit_root,
|
|
915
|
+
smtProofRollup: proof.proof_rollup_exit_root,
|
|
893
916
|
globalIndex: globalIndex.toString(),
|
|
894
|
-
mainnetExitRoot: proof.
|
|
895
|
-
rollupExitRoot: proof.rollup_exit_root,
|
|
917
|
+
mainnetExitRoot: proof.l1_info_tree_leaf.mainnet_exit_root,
|
|
918
|
+
rollupExitRoot: proof.l1_info_tree_leaf.rollup_exit_root,
|
|
896
919
|
originNetwork: bridgeEvent.originNetwork,
|
|
897
920
|
originTokenAddress: bridgeEvent.originTokenAddress,
|
|
898
921
|
destinationNetwork: bridgeEvent.destinationNetwork,
|
|
@@ -904,10 +927,11 @@ var BridgeUtil = class _BridgeUtil {
|
|
|
904
927
|
/**
|
|
905
928
|
* Build claim asset parameters from transaction hash
|
|
906
929
|
*/
|
|
907
|
-
async buildClaimAssetParams(transactionHash, sourceNetworkId, bridgeIndex = 0) {
|
|
930
|
+
async buildClaimAssetParams(transactionHash, sourceNetworkId, leafIndex, bridgeIndex = 0) {
|
|
908
931
|
const payload = await this.buildPayloadForClaim(
|
|
909
932
|
transactionHash,
|
|
910
933
|
sourceNetworkId,
|
|
934
|
+
leafIndex,
|
|
911
935
|
bridgeIndex
|
|
912
936
|
);
|
|
913
937
|
return {
|
|
@@ -927,10 +951,11 @@ var BridgeUtil = class _BridgeUtil {
|
|
|
927
951
|
/**
|
|
928
952
|
* Build claim message parameters from transaction hash
|
|
929
953
|
*/
|
|
930
|
-
async buildClaimMessageParams(transactionHash, sourceNetworkId, bridgeIndex = 0) {
|
|
954
|
+
async buildClaimMessageParams(transactionHash, sourceNetworkId, leafIndex, bridgeIndex = 0) {
|
|
931
955
|
const payload = await this.buildPayloadForClaim(
|
|
932
956
|
transactionHash,
|
|
933
957
|
sourceNetworkId,
|
|
958
|
+
leafIndex,
|
|
934
959
|
bridgeIndex
|
|
935
960
|
);
|
|
936
961
|
return {
|
|
@@ -977,7 +1002,7 @@ var Bridge = class extends BaseContract {
|
|
|
977
1002
|
return buildBridgeAsset(
|
|
978
1003
|
{
|
|
979
1004
|
bridgeAddress: this.bridgeAddress,
|
|
980
|
-
estimateGas: (data, to, from2) => this.estimateGas(data, to, from2),
|
|
1005
|
+
estimateGas: (data, to, from2, value) => this.estimateGas(data, to, from2, value),
|
|
981
1006
|
getNonce: (address) => this.getNonce(address)
|
|
982
1007
|
},
|
|
983
1008
|
params.destinationNetwork,
|
|
@@ -1004,7 +1029,7 @@ var Bridge = class extends BaseContract {
|
|
|
1004
1029
|
return buildClaimAsset(
|
|
1005
1030
|
{
|
|
1006
1031
|
bridgeAddress: this.bridgeAddress,
|
|
1007
|
-
estimateGas: (data, to, from2) => this.estimateGas(data, to, from2),
|
|
1032
|
+
estimateGas: (data, to, from2, value) => this.estimateGas(data, to, from2, value),
|
|
1008
1033
|
getNonce: (address) => this.getNonce(address)
|
|
1009
1034
|
},
|
|
1010
1035
|
params.smtProofLocalExitRoot,
|
|
@@ -1078,7 +1103,7 @@ var Bridge = class extends BaseContract {
|
|
|
1078
1103
|
return buildBridgeMessage(
|
|
1079
1104
|
{
|
|
1080
1105
|
bridgeAddress: this.bridgeAddress,
|
|
1081
|
-
estimateGas: (data, to, from2) => this.estimateGas(data, to, from2),
|
|
1106
|
+
estimateGas: (data, to, from2, value) => this.estimateGas(data, to, from2, value),
|
|
1082
1107
|
getNonce: (address) => this.getNonce(address)
|
|
1083
1108
|
},
|
|
1084
1109
|
params.destinationNetwork,
|
|
@@ -1103,7 +1128,7 @@ var Bridge = class extends BaseContract {
|
|
|
1103
1128
|
return buildClaimMessage(
|
|
1104
1129
|
{
|
|
1105
1130
|
bridgeAddress: this.bridgeAddress,
|
|
1106
|
-
estimateGas: (data, to, from2) => this.estimateGas(data, to, from2),
|
|
1131
|
+
estimateGas: (data, to, from2, value) => this.estimateGas(data, to, from2, value),
|
|
1107
1132
|
getNonce: (address) => this.getNonce(address)
|
|
1108
1133
|
},
|
|
1109
1134
|
params.smtProofLocalExitRoot,
|
|
@@ -1157,14 +1182,16 @@ var Bridge = class extends BaseContract {
|
|
|
1157
1182
|
*
|
|
1158
1183
|
* @param transactionHash - Hash of the bridge transaction on the source network
|
|
1159
1184
|
* @param sourceNetworkId - Network ID of the source network (where bridge tx happened)
|
|
1185
|
+
* @param leafIndex - Leaf index for the claim proof
|
|
1160
1186
|
* @param bridgeIndex - Index of bridge event in transaction (default: 0)
|
|
1161
1187
|
* @param from - From address for the claim transaction
|
|
1162
1188
|
*/
|
|
1163
|
-
async buildClaimAssetFromHash(transactionHash, sourceNetworkId, bridgeIndex = 0, from) {
|
|
1189
|
+
async buildClaimAssetFromHash(transactionHash, sourceNetworkId, leafIndex, bridgeIndex = 0, from) {
|
|
1164
1190
|
const bridgeUtil = await BridgeUtil.fromNetworkId(sourceNetworkId);
|
|
1165
1191
|
const params = await bridgeUtil.buildClaimAssetParams(
|
|
1166
1192
|
transactionHash,
|
|
1167
1193
|
sourceNetworkId,
|
|
1194
|
+
leafIndex,
|
|
1168
1195
|
bridgeIndex
|
|
1169
1196
|
);
|
|
1170
1197
|
return this.buildClaimAsset(params, from);
|
|
@@ -1174,14 +1201,16 @@ var Bridge = class extends BaseContract {
|
|
|
1174
1201
|
*
|
|
1175
1202
|
* @param transactionHash - Hash of the bridge transaction on the source network
|
|
1176
1203
|
* @param sourceNetworkId - Network ID of the source network (where bridge tx happened)
|
|
1204
|
+
* @param leafIndex - Leaf index for the claim proof
|
|
1177
1205
|
* @param bridgeIndex - Index of bridge event in transaction (default: 0)
|
|
1178
1206
|
* @param from - From address for the claim transaction
|
|
1179
1207
|
*/
|
|
1180
|
-
async buildClaimMessageFromHash(transactionHash, sourceNetworkId, bridgeIndex = 0, from) {
|
|
1208
|
+
async buildClaimMessageFromHash(transactionHash, sourceNetworkId, leafIndex, bridgeIndex = 0, from) {
|
|
1181
1209
|
const bridgeUtil = await BridgeUtil.fromNetworkId(sourceNetworkId);
|
|
1182
1210
|
const params = await bridgeUtil.buildClaimMessageParams(
|
|
1183
1211
|
transactionHash,
|
|
1184
1212
|
sourceNetworkId,
|
|
1213
|
+
leafIndex,
|
|
1185
1214
|
bridgeIndex
|
|
1186
1215
|
);
|
|
1187
1216
|
return this.buildClaimMessage(params, from);
|
|
@@ -1339,14 +1368,16 @@ var ERC20 = class extends BaseContract {
|
|
|
1339
1368
|
*
|
|
1340
1369
|
* @param transactionHash - Hash of the bridge transaction on the source network
|
|
1341
1370
|
* @param sourceNetworkId - Network ID of the source network (where bridge tx happened)
|
|
1371
|
+
* @param leafIndex - Leaf index for the claim proof
|
|
1342
1372
|
* @param bridgeIndex - Index of bridge event in transaction (default: 0)
|
|
1343
1373
|
* @param from - From address for the claim transaction
|
|
1344
1374
|
*/
|
|
1345
|
-
async claimAsset(transactionHash, sourceNetworkId, bridgeIndex = 0, from) {
|
|
1375
|
+
async claimAsset(transactionHash, sourceNetworkId, leafIndex, bridgeIndex = 0, from) {
|
|
1346
1376
|
const bridge = this.getBridge();
|
|
1347
1377
|
return bridge.buildClaimAssetFromHash(
|
|
1348
1378
|
transactionHash,
|
|
1349
1379
|
sourceNetworkId,
|
|
1380
|
+
leafIndex,
|
|
1350
1381
|
bridgeIndex,
|
|
1351
1382
|
from
|
|
1352
1383
|
);
|
|
@@ -1356,14 +1387,16 @@ var ERC20 = class extends BaseContract {
|
|
|
1356
1387
|
*
|
|
1357
1388
|
* @param transactionHash - Hash of the bridge transaction on the source network
|
|
1358
1389
|
* @param sourceNetworkId - Network ID of the source network (where bridge tx happened)
|
|
1390
|
+
* @param leafIndex - Leaf index for the claim proof
|
|
1359
1391
|
* @param bridgeIndex - Index of bridge event in transaction (default: 0)
|
|
1360
1392
|
* @param from - From address for the claim transaction
|
|
1361
1393
|
*/
|
|
1362
|
-
async claimMessage(transactionHash, sourceNetworkId, bridgeIndex = 0, from) {
|
|
1394
|
+
async claimMessage(transactionHash, sourceNetworkId, leafIndex, bridgeIndex = 0, from) {
|
|
1363
1395
|
const bridge = this.getBridge();
|
|
1364
1396
|
return bridge.buildClaimMessageFromHash(
|
|
1365
1397
|
transactionHash,
|
|
1366
1398
|
sourceNetworkId,
|
|
1399
|
+
leafIndex,
|
|
1367
1400
|
bridgeIndex,
|
|
1368
1401
|
from
|
|
1369
1402
|
);
|
|
@@ -1400,22 +1433,6 @@ var ERC20 = class extends BaseContract {
|
|
|
1400
1433
|
|
|
1401
1434
|
// src/native/index.ts
|
|
1402
1435
|
import { createPublicClient as createPublicClient3, http as http3 } from "viem";
|
|
1403
|
-
|
|
1404
|
-
// src/constants.ts
|
|
1405
|
-
var ARC_API_BASE_URL = "https://arc-api.polygon.technology";
|
|
1406
|
-
var ARC_API_DEFAULT_TIMEOUT = 3e4;
|
|
1407
|
-
var LIFI_API_BASE_URL = "https://li.quest";
|
|
1408
|
-
var LIFI_API_DEFAULT_TIMEOUT = 5e3;
|
|
1409
|
-
var DEFAULT_CHAINS_PER_PAGE = 100;
|
|
1410
|
-
var DEFAULT_CHAINS_WITH_TOKENS_PER_PAGE = 1;
|
|
1411
|
-
var MAX_TRANSACTIONS_PER_PAGE = 100;
|
|
1412
|
-
var NETWORKS = {
|
|
1413
|
-
ETHEREUM: 1,
|
|
1414
|
-
KATANA: 747474
|
|
1415
|
-
};
|
|
1416
|
-
var DEFAULT_NETWORK = NETWORKS.ETHEREUM;
|
|
1417
|
-
|
|
1418
|
-
// src/native/index.ts
|
|
1419
1436
|
var NativeClient = class {
|
|
1420
1437
|
constructor(config) {
|
|
1421
1438
|
this.config = config;
|
|
@@ -1519,6 +1536,19 @@ var SDK_MODES = {
|
|
|
1519
1536
|
NATIVE: "NATIVE"
|
|
1520
1537
|
};
|
|
1521
1538
|
|
|
1539
|
+
// src/types/core/arcApi/arcApiTransactions.ts
|
|
1540
|
+
var TransactionStatus = /* @__PURE__ */ ((TransactionStatus2) => {
|
|
1541
|
+
TransactionStatus2["BRIDGED"] = "BRIDGED";
|
|
1542
|
+
TransactionStatus2["LEAF_INCLUDED"] = "LEAF_INCLUDED";
|
|
1543
|
+
TransactionStatus2["READY_TO_CLAIM"] = "READY_TO_CLAIM";
|
|
1544
|
+
TransactionStatus2["CLAIMED"] = "CLAIMED";
|
|
1545
|
+
TransactionStatus2["REFUND_IN_PROGRESS"] = "REFUND_IN_PROGRESS";
|
|
1546
|
+
TransactionStatus2["REFUNDED"] = "REFUNDED";
|
|
1547
|
+
TransactionStatus2["FAILED"] = "FAILED";
|
|
1548
|
+
TransactionStatus2["PARTIAL"] = "PARTIAL";
|
|
1549
|
+
return TransactionStatus2;
|
|
1550
|
+
})(TransactionStatus || {});
|
|
1551
|
+
|
|
1522
1552
|
// src/core/utils/httpClient.ts
|
|
1523
1553
|
var HttpClient = class {
|
|
1524
1554
|
constructor(config) {
|
|
@@ -2158,6 +2188,7 @@ var AggLayerSDK = class {
|
|
|
2158
2188
|
export {
|
|
2159
2189
|
AggLayerSDK,
|
|
2160
2190
|
ApiError,
|
|
2161
|
-
SDK_MODES
|
|
2191
|
+
SDK_MODES,
|
|
2192
|
+
TransactionStatus
|
|
2162
2193
|
};
|
|
2163
2194
|
//# sourceMappingURL=index.mjs.map
|