@agglayer/sdk 1.0.0-beta.15 → 1.0.0-beta.17
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.d.mts +76 -19
- package/dist/index.d.ts +76 -19
- package/dist/index.js +127 -35
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +127 -35
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1395,6 +1395,9 @@ var NETWORKS = {
|
|
|
1395
1395
|
CARDONA: 2442
|
|
1396
1396
|
};
|
|
1397
1397
|
var DEFAULT_NETWORK = NETWORKS.SEPOLIA;
|
|
1398
|
+
var DEFAULT_CHAINS_PER_PAGE = 100;
|
|
1399
|
+
var DEFAULT_CHAINS_WITH_TOKENS_PER_PAGE = 1;
|
|
1400
|
+
var MAX_TRANSACTIONS_PER_PAGE = 100;
|
|
1398
1401
|
|
|
1399
1402
|
// src/native/index.ts
|
|
1400
1403
|
var NativeClient = class {
|
|
@@ -1623,11 +1626,12 @@ var HttpClient = class {
|
|
|
1623
1626
|
continue;
|
|
1624
1627
|
}
|
|
1625
1628
|
if (Array.isArray(value)) {
|
|
1626
|
-
value.
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1629
|
+
const filteredValues = value.filter(
|
|
1630
|
+
(item) => item !== void 0 && item !== null
|
|
1631
|
+
);
|
|
1632
|
+
if (filteredValues.length > 0) {
|
|
1633
|
+
result[fullKey] = filteredValues.join(",");
|
|
1634
|
+
}
|
|
1631
1635
|
} else if (typeof value === "object") {
|
|
1632
1636
|
Object.assign(
|
|
1633
1637
|
result,
|
|
@@ -1657,16 +1661,17 @@ var ArcApiService = class {
|
|
|
1657
1661
|
this.httpClient = new HttpClient({ baseUrl, timeout });
|
|
1658
1662
|
}
|
|
1659
1663
|
// responsible for both chains metadata and tokens
|
|
1664
|
+
// supports limit/offset based pagination
|
|
1660
1665
|
async chains({
|
|
1661
1666
|
withSupportedTokens = false,
|
|
1662
|
-
limit =
|
|
1663
|
-
|
|
1667
|
+
limit = 10,
|
|
1668
|
+
offset,
|
|
1664
1669
|
chainIds
|
|
1665
1670
|
} = {}) {
|
|
1666
1671
|
return this.httpClient.get("/metadata/chains", {
|
|
1667
1672
|
withSupportedTokens,
|
|
1668
1673
|
limit,
|
|
1669
|
-
|
|
1674
|
+
offset,
|
|
1670
1675
|
chainIds
|
|
1671
1676
|
});
|
|
1672
1677
|
}
|
|
@@ -1679,6 +1684,13 @@ var ArcApiService = class {
|
|
|
1679
1684
|
builtTransactionRequestBody
|
|
1680
1685
|
);
|
|
1681
1686
|
}
|
|
1687
|
+
async buildClaimTransaction(sourceNetworkId, depositCount) {
|
|
1688
|
+
return this.httpClient.get("/routes/build-transaction-for-claim", {
|
|
1689
|
+
sourceNetworkId,
|
|
1690
|
+
depositCount
|
|
1691
|
+
});
|
|
1692
|
+
}
|
|
1693
|
+
// supports cursor based pagination only
|
|
1682
1694
|
async transactions(transactionsRequestQueryParams) {
|
|
1683
1695
|
return this.httpClient.get("/transactions", {
|
|
1684
1696
|
transactionsRequestQueryParams
|
|
@@ -1702,69 +1714,144 @@ var CoreClient = class {
|
|
|
1702
1714
|
timeout: apiTimeout ?? 3e4
|
|
1703
1715
|
});
|
|
1704
1716
|
}
|
|
1717
|
+
/**
|
|
1718
|
+
* Generic pagination helper for chains API calls (limit and offset based pagination)
|
|
1719
|
+
* Handles automatic pagination to fetch all available data
|
|
1720
|
+
* @param params - Parameters for the chains API call
|
|
1721
|
+
* @param pageSize - Number of items per page (defaults to DEFAULT_CHAINS_PER_PAGE)
|
|
1722
|
+
*/
|
|
1723
|
+
async getAllChainsPaginated(params, pageSize = DEFAULT_CHAINS_PER_PAGE) {
|
|
1724
|
+
const firstResponse = await this.arcApiService.chains({
|
|
1725
|
+
...params,
|
|
1726
|
+
limit: pageSize
|
|
1727
|
+
});
|
|
1728
|
+
if (firstResponse.data.status !== "success") {
|
|
1729
|
+
throw new Error(firstResponse.data.message);
|
|
1730
|
+
}
|
|
1731
|
+
const firstPageData = firstResponse.data.data;
|
|
1732
|
+
const pagination = firstResponse.data.pagination;
|
|
1733
|
+
const firstPageChains = Array.isArray(firstPageData) ? firstPageData : [];
|
|
1734
|
+
if (!pagination?.total || pagination.total <= pageSize) {
|
|
1735
|
+
return {
|
|
1736
|
+
chains: firstPageChains
|
|
1737
|
+
};
|
|
1738
|
+
}
|
|
1739
|
+
const totalPages = Math.ceil(pagination.total / pageSize);
|
|
1740
|
+
const remainingPages = totalPages - 1;
|
|
1741
|
+
if (remainingPages === 0) {
|
|
1742
|
+
return {
|
|
1743
|
+
chains: firstPageChains
|
|
1744
|
+
};
|
|
1745
|
+
}
|
|
1746
|
+
const remainingPagePromises = Array.from(
|
|
1747
|
+
{ length: remainingPages },
|
|
1748
|
+
(_, index) => {
|
|
1749
|
+
const offset = (index + 1) * pageSize;
|
|
1750
|
+
return this.arcApiService.chains({
|
|
1751
|
+
...params,
|
|
1752
|
+
limit: pageSize,
|
|
1753
|
+
offset
|
|
1754
|
+
});
|
|
1755
|
+
}
|
|
1756
|
+
);
|
|
1757
|
+
const remainingResponses = await Promise.all(remainingPagePromises);
|
|
1758
|
+
for (const response of remainingResponses) {
|
|
1759
|
+
if (response.data.status !== "success") {
|
|
1760
|
+
throw new Error(response.data.message);
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1763
|
+
const allChains = [
|
|
1764
|
+
...firstPageChains,
|
|
1765
|
+
...remainingResponses.flatMap((response) => {
|
|
1766
|
+
if (response.data.status === "success") {
|
|
1767
|
+
return Array.isArray(response.data.data) ? response.data.data : [];
|
|
1768
|
+
}
|
|
1769
|
+
return [];
|
|
1770
|
+
})
|
|
1771
|
+
];
|
|
1772
|
+
return {
|
|
1773
|
+
chains: allChains
|
|
1774
|
+
};
|
|
1775
|
+
}
|
|
1705
1776
|
/**
|
|
1706
1777
|
* Get all chains metadata from AggLayer API
|
|
1778
|
+
* Handles pagination automatically to fetch all available chains
|
|
1707
1779
|
*/
|
|
1708
1780
|
async getAllChains() {
|
|
1709
|
-
|
|
1710
|
-
if (response.data.status === "success") {
|
|
1711
|
-
return response.data.data;
|
|
1712
|
-
}
|
|
1713
|
-
throw new Error(response.data.message);
|
|
1781
|
+
return this.getAllChainsPaginated({});
|
|
1714
1782
|
}
|
|
1715
1783
|
/**
|
|
1716
1784
|
* Get chain metadata by id from AggLayer API
|
|
1785
|
+
* Handles pagination automatically to fetch all available chain metadata
|
|
1717
1786
|
* @param ids - the ids of the chains to get metadata for
|
|
1718
1787
|
*/
|
|
1719
1788
|
async getChainMetadataByChainIds(ids) {
|
|
1720
|
-
|
|
1721
|
-
if (response.data.status === "success") {
|
|
1722
|
-
return response.data.data;
|
|
1723
|
-
}
|
|
1724
|
-
throw new Error(response.data.message);
|
|
1789
|
+
return this.getAllChainsPaginated({ chainIds: ids });
|
|
1725
1790
|
}
|
|
1726
1791
|
/**
|
|
1727
1792
|
* Get all tokens from AggLayer API
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1793
|
+
*
|
|
1794
|
+
* Developer Note: This method is not recommended to use frequently or from frontend.
|
|
1795
|
+
* As it can be very slow and resource intensive.
|
|
1796
|
+
* It is recommended to use getChainDataAndTokensByChainIds instead.
|
|
1797
|
+
*/
|
|
1798
|
+
async getAllTokens() {
|
|
1799
|
+
return this.getAllChainsPaginated(
|
|
1800
|
+
{ withSupportedTokens: true },
|
|
1801
|
+
DEFAULT_CHAINS_WITH_TOKENS_PER_PAGE
|
|
1802
|
+
);
|
|
1737
1803
|
}
|
|
1738
1804
|
/**
|
|
1739
1805
|
* Get chain data and tokens by AggLayer API
|
|
1740
1806
|
* @param ids - the ids of the chains to get data and tokens for
|
|
1741
1807
|
*/
|
|
1742
1808
|
async getChainDataAndTokensByChainIds(ids) {
|
|
1743
|
-
|
|
1809
|
+
return this.getAllChainsPaginated({
|
|
1744
1810
|
chainIds: ids,
|
|
1745
1811
|
withSupportedTokens: true
|
|
1746
1812
|
});
|
|
1813
|
+
}
|
|
1814
|
+
/**
|
|
1815
|
+
* Get all routes from AggLayer API
|
|
1816
|
+
*/
|
|
1817
|
+
async getRoutes(routesRequestParams) {
|
|
1818
|
+
const response = await this.arcApiService.routes(routesRequestParams);
|
|
1747
1819
|
if (response.data.status === "success") {
|
|
1748
1820
|
return response.data.data;
|
|
1749
1821
|
}
|
|
1750
1822
|
throw new Error(response.data.message);
|
|
1751
1823
|
}
|
|
1752
1824
|
/**
|
|
1753
|
-
* Get
|
|
1825
|
+
* Get calldata from a route
|
|
1826
|
+
* If route has transactionRequest field, return it directly as calldata
|
|
1827
|
+
* Otherwise, call buildTransaction on route.steps[0] and return that as calldata
|
|
1754
1828
|
*/
|
|
1755
|
-
async
|
|
1756
|
-
|
|
1829
|
+
async getUnsignedTransaction(route) {
|
|
1830
|
+
if (route.transactionRequest) {
|
|
1831
|
+
return route.transactionRequest;
|
|
1832
|
+
}
|
|
1833
|
+
if (route.steps.length === 0 || !route.steps[0]) {
|
|
1834
|
+
throw new Error("Route has no steps to build transaction from");
|
|
1835
|
+
}
|
|
1836
|
+
const response = await this.arcApiService.buildTransaction(route.steps[0]);
|
|
1757
1837
|
if (response.data.status === "success") {
|
|
1758
1838
|
return response.data.data;
|
|
1759
1839
|
}
|
|
1760
1840
|
throw new Error(response.data.message);
|
|
1761
1841
|
}
|
|
1762
1842
|
/**
|
|
1763
|
-
*
|
|
1843
|
+
* Get calldata for claim step
|
|
1844
|
+
* Needs to be called separately as claim step is not part of route.
|
|
1845
|
+
*
|
|
1846
|
+
* @developer Note: Do not misinterpret network ID as chain ID.
|
|
1847
|
+
*
|
|
1848
|
+
* @param sourceNetworkId - The source network ID where the transfer was initiated.
|
|
1849
|
+
* @param depositCount - The deposit count associated with the transfer.
|
|
1764
1850
|
*/
|
|
1765
|
-
async
|
|
1766
|
-
const response = await this.arcApiService.
|
|
1767
|
-
|
|
1851
|
+
async getClaimUnsignedTransaction(buildClaimTxParams) {
|
|
1852
|
+
const response = await this.arcApiService.buildClaimTransaction(
|
|
1853
|
+
buildClaimTxParams.sourceNetworkId,
|
|
1854
|
+
buildClaimTxParams.depositCount
|
|
1768
1855
|
);
|
|
1769
1856
|
if (response.data.status === "success") {
|
|
1770
1857
|
return response.data.data;
|
|
@@ -1775,6 +1862,11 @@ var CoreClient = class {
|
|
|
1775
1862
|
* Get all transactions via web sockets
|
|
1776
1863
|
*/
|
|
1777
1864
|
async getTransactions(transactionsRequestQueryParams) {
|
|
1865
|
+
if (transactionsRequestQueryParams.limit && transactionsRequestQueryParams.limit > MAX_TRANSACTIONS_PER_PAGE) {
|
|
1866
|
+
throw new Error(
|
|
1867
|
+
`Limit cannot be greater than ${MAX_TRANSACTIONS_PER_PAGE}`
|
|
1868
|
+
);
|
|
1869
|
+
}
|
|
1778
1870
|
const response = await this.arcApiService.transactions(
|
|
1779
1871
|
transactionsRequestQueryParams
|
|
1780
1872
|
);
|