@pioneer-platform/pioneer-sdk 4.20.12 → 4.20.13

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 CHANGED
@@ -1754,10 +1754,19 @@ var extractChainIdFromNetworkId = (networkId) => {
1754
1754
  }
1755
1755
  return parseInt(id);
1756
1756
  };
1757
- async function fetchEthPriceInUsd() {
1758
- const response = await fetch("https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=usd");
1759
- const data = await response.json();
1760
- return data.ethereum.usd;
1757
+ async function fetchEthPriceInUsd(pioneer, networkId) {
1758
+ const gasCaip = `${networkId}/slip44:60`;
1759
+ try {
1760
+ const marketInfo = await pioneer.GetMarketInfo([gasCaip]);
1761
+ if (marketInfo?.data && marketInfo.data.length > 0 && marketInfo.data[0] > 0) {
1762
+ return marketInfo.data[0];
1763
+ }
1764
+ console.warn("ETH price not available from Pioneer API, using fallback");
1765
+ return 0;
1766
+ } catch (error) {
1767
+ console.error("Error fetching ETH price from Pioneer API:", error);
1768
+ return 0;
1769
+ }
1761
1770
  }
1762
1771
  var extractContractAddressFromCaip = (caip) => {
1763
1772
  const parts = caip.split("/");
@@ -1784,14 +1793,18 @@ var encodeTransferData = (toAddress, amountWei) => {
1784
1793
  const data = "0x" + functionSignature + toAddressPadded + amountPadded;
1785
1794
  return data;
1786
1795
  };
1787
- async function fetchTokenPriceInUsd(contractAddress) {
1788
- const response = await fetch(`https://api.coingecko.com/api/v3/simple/token_price/ethereum?contract_addresses=${contractAddress}&vs_currencies=usd`);
1789
- const data = await response.json();
1790
- const price = data[contractAddress.toLowerCase()]?.usd;
1791
- if (!price) {
1792
- throw new Error("Failed to fetch token price");
1796
+ async function fetchTokenPriceInUsd(pioneer, caip) {
1797
+ try {
1798
+ const marketInfo = await pioneer.GetMarketInfo([caip]);
1799
+ if (marketInfo?.data && marketInfo.data.length > 0 && marketInfo.data[0] > 0) {
1800
+ return marketInfo.data[0];
1801
+ }
1802
+ console.warn(`Token price not available from Pioneer API for ${caip}, using 0`);
1803
+ return 0;
1804
+ } catch (error) {
1805
+ console.error(`Error fetching token price from Pioneer API for ${caip}:`, error);
1806
+ return 0;
1793
1807
  }
1794
- return price;
1795
1808
  }
1796
1809
  async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, pubkeyContext, isMax, feeLevel = 5) {
1797
1810
  const tag5 = TAG + " | createUnsignedEvmTx | ";
@@ -2057,9 +2070,9 @@ async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, pub
2057
2070
  throw new Error("Insufficient ETH balance to cover gas fees");
2058
2071
  }
2059
2072
  const data = encodeTransferData(to, amountWei);
2060
- const ethPriceInUsd = await fetchEthPriceInUsd();
2073
+ const ethPriceInUsd = await fetchEthPriceInUsd(pioneer, networkId);
2061
2074
  const gasFeeUsd = Number(gasFee) / 1000000000000000000 * ethPriceInUsd;
2062
- const tokenPriceInUsd = await fetchTokenPriceInUsd(contractAddress);
2075
+ const tokenPriceInUsd = await fetchTokenPriceInUsd(pioneer, caip);
2063
2076
  const amountUsd = Number(amountWei) / Number(tokenMultiplier) * tokenPriceInUsd;
2064
2077
  unsignedTx = {
2065
2078
  chainId,
package/dist/index.es.js CHANGED
@@ -1930,10 +1930,19 @@ var extractChainIdFromNetworkId = (networkId) => {
1930
1930
  }
1931
1931
  return parseInt(id);
1932
1932
  };
1933
- async function fetchEthPriceInUsd() {
1934
- const response = await fetch("https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=usd");
1935
- const data = await response.json();
1936
- return data.ethereum.usd;
1933
+ async function fetchEthPriceInUsd(pioneer, networkId) {
1934
+ const gasCaip = `${networkId}/slip44:60`;
1935
+ try {
1936
+ const marketInfo = await pioneer.GetMarketInfo([gasCaip]);
1937
+ if (marketInfo?.data && marketInfo.data.length > 0 && marketInfo.data[0] > 0) {
1938
+ return marketInfo.data[0];
1939
+ }
1940
+ console.warn("ETH price not available from Pioneer API, using fallback");
1941
+ return 0;
1942
+ } catch (error) {
1943
+ console.error("Error fetching ETH price from Pioneer API:", error);
1944
+ return 0;
1945
+ }
1937
1946
  }
1938
1947
  var extractContractAddressFromCaip = (caip) => {
1939
1948
  const parts = caip.split("/");
@@ -1960,14 +1969,18 @@ var encodeTransferData = (toAddress, amountWei) => {
1960
1969
  const data = "0x" + functionSignature + toAddressPadded + amountPadded;
1961
1970
  return data;
1962
1971
  };
1963
- async function fetchTokenPriceInUsd(contractAddress) {
1964
- const response = await fetch(`https://api.coingecko.com/api/v3/simple/token_price/ethereum?contract_addresses=${contractAddress}&vs_currencies=usd`);
1965
- const data = await response.json();
1966
- const price = data[contractAddress.toLowerCase()]?.usd;
1967
- if (!price) {
1968
- throw new Error("Failed to fetch token price");
1972
+ async function fetchTokenPriceInUsd(pioneer, caip) {
1973
+ try {
1974
+ const marketInfo = await pioneer.GetMarketInfo([caip]);
1975
+ if (marketInfo?.data && marketInfo.data.length > 0 && marketInfo.data[0] > 0) {
1976
+ return marketInfo.data[0];
1977
+ }
1978
+ console.warn(`Token price not available from Pioneer API for ${caip}, using 0`);
1979
+ return 0;
1980
+ } catch (error) {
1981
+ console.error(`Error fetching token price from Pioneer API for ${caip}:`, error);
1982
+ return 0;
1969
1983
  }
1970
- return price;
1971
1984
  }
1972
1985
  async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, pubkeyContext, isMax, feeLevel = 5) {
1973
1986
  const tag5 = TAG + " | createUnsignedEvmTx | ";
@@ -2233,9 +2246,9 @@ async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, pub
2233
2246
  throw new Error("Insufficient ETH balance to cover gas fees");
2234
2247
  }
2235
2248
  const data = encodeTransferData(to, amountWei);
2236
- const ethPriceInUsd = await fetchEthPriceInUsd();
2249
+ const ethPriceInUsd = await fetchEthPriceInUsd(pioneer, networkId);
2237
2250
  const gasFeeUsd = Number(gasFee) / 1000000000000000000 * ethPriceInUsd;
2238
- const tokenPriceInUsd = await fetchTokenPriceInUsd(contractAddress);
2251
+ const tokenPriceInUsd = await fetchTokenPriceInUsd(pioneer, caip);
2239
2252
  const amountUsd = Number(amountWei) / Number(tokenMultiplier) * tokenPriceInUsd;
2240
2253
  unsignedTx = {
2241
2254
  chainId,
package/dist/index.js CHANGED
@@ -1930,10 +1930,19 @@ var extractChainIdFromNetworkId = (networkId) => {
1930
1930
  }
1931
1931
  return parseInt(id);
1932
1932
  };
1933
- async function fetchEthPriceInUsd() {
1934
- const response = await fetch("https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=usd");
1935
- const data = await response.json();
1936
- return data.ethereum.usd;
1933
+ async function fetchEthPriceInUsd(pioneer, networkId) {
1934
+ const gasCaip = `${networkId}/slip44:60`;
1935
+ try {
1936
+ const marketInfo = await pioneer.GetMarketInfo([gasCaip]);
1937
+ if (marketInfo?.data && marketInfo.data.length > 0 && marketInfo.data[0] > 0) {
1938
+ return marketInfo.data[0];
1939
+ }
1940
+ console.warn("ETH price not available from Pioneer API, using fallback");
1941
+ return 0;
1942
+ } catch (error) {
1943
+ console.error("Error fetching ETH price from Pioneer API:", error);
1944
+ return 0;
1945
+ }
1937
1946
  }
1938
1947
  var extractContractAddressFromCaip = (caip) => {
1939
1948
  const parts = caip.split("/");
@@ -1960,14 +1969,18 @@ var encodeTransferData = (toAddress, amountWei) => {
1960
1969
  const data = "0x" + functionSignature + toAddressPadded + amountPadded;
1961
1970
  return data;
1962
1971
  };
1963
- async function fetchTokenPriceInUsd(contractAddress) {
1964
- const response = await fetch(`https://api.coingecko.com/api/v3/simple/token_price/ethereum?contract_addresses=${contractAddress}&vs_currencies=usd`);
1965
- const data = await response.json();
1966
- const price = data[contractAddress.toLowerCase()]?.usd;
1967
- if (!price) {
1968
- throw new Error("Failed to fetch token price");
1972
+ async function fetchTokenPriceInUsd(pioneer, caip) {
1973
+ try {
1974
+ const marketInfo = await pioneer.GetMarketInfo([caip]);
1975
+ if (marketInfo?.data && marketInfo.data.length > 0 && marketInfo.data[0] > 0) {
1976
+ return marketInfo.data[0];
1977
+ }
1978
+ console.warn(`Token price not available from Pioneer API for ${caip}, using 0`);
1979
+ return 0;
1980
+ } catch (error) {
1981
+ console.error(`Error fetching token price from Pioneer API for ${caip}:`, error);
1982
+ return 0;
1969
1983
  }
1970
- return price;
1971
1984
  }
1972
1985
  async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, pubkeyContext, isMax, feeLevel = 5) {
1973
1986
  const tag5 = TAG + " | createUnsignedEvmTx | ";
@@ -2233,9 +2246,9 @@ async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, pub
2233
2246
  throw new Error("Insufficient ETH balance to cover gas fees");
2234
2247
  }
2235
2248
  const data = encodeTransferData(to, amountWei);
2236
- const ethPriceInUsd = await fetchEthPriceInUsd();
2249
+ const ethPriceInUsd = await fetchEthPriceInUsd(pioneer, networkId);
2237
2250
  const gasFeeUsd = Number(gasFee) / 1000000000000000000 * ethPriceInUsd;
2238
- const tokenPriceInUsd = await fetchTokenPriceInUsd(contractAddress);
2251
+ const tokenPriceInUsd = await fetchTokenPriceInUsd(pioneer, caip);
2239
2252
  const amountUsd = Number(amountWei) / Number(tokenMultiplier) * tokenPriceInUsd;
2240
2253
  unsignedTx = {
2241
2254
  chainId,
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "author": "highlander",
3
3
  "name": "@pioneer-platform/pioneer-sdk",
4
- "version": "4.20.12",
4
+ "version": "4.20.13",
5
5
  "dependencies": {
6
6
  "@keepkey/keepkey-sdk": "^0.2.62",
7
7
  "@pioneer-platform/loggerdog": "^8.11.0",
8
8
  "@pioneer-platform/pioneer-caip": "^9.10.0",
9
- "@pioneer-platform/pioneer-client": "^9.10.4",
9
+ "@pioneer-platform/pioneer-client": "^9.10.5",
10
10
  "@pioneer-platform/pioneer-coins": "^9.11.0",
11
11
  "@pioneer-platform/pioneer-discovery": "^0.8.0",
12
12
  "@pioneer-platform/pioneer-events": "^8.11.0",
@@ -32,13 +32,24 @@ const extractChainIdFromNetworkId = (networkId) => {
32
32
  return parseInt(id);
33
33
  };
34
34
 
35
- // Fetch the current ETH price in USD from CoinGecko
36
- async function fetchEthPriceInUsd() {
37
- const response = await fetch(
38
- 'https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=usd',
39
- );
40
- const data = await response.json();
41
- return data.ethereum.usd;
35
+ // Fetch the current ETH price in USD from Pioneer API
36
+ async function fetchEthPriceInUsd(pioneer: any, networkId: string) {
37
+ // Build CAIP for the native gas token based on networkId
38
+ // For EVM chains, the native gas asset uses slip44 format
39
+ const gasCaip = `${networkId}/slip44:60`; // ETH slip44 code
40
+
41
+ try {
42
+ const marketInfo = await pioneer.GetMarketInfo([gasCaip]);
43
+ if (marketInfo?.data && marketInfo.data.length > 0 && marketInfo.data[0] > 0) {
44
+ return marketInfo.data[0];
45
+ }
46
+ // Fallback if price not available
47
+ console.warn('ETH price not available from Pioneer API, using fallback');
48
+ return 0;
49
+ } catch (error) {
50
+ console.error('Error fetching ETH price from Pioneer API:', error);
51
+ return 0;
52
+ }
42
53
  }
43
54
 
44
55
  // Extract contract address from CAIP
@@ -75,19 +86,21 @@ const encodeTransferData = (toAddress, amountWei) => {
75
86
  return data;
76
87
  };
77
88
 
78
- //TODO use assetData here, this is horrible
79
- // Helper function to fetch token price in USD
80
- async function fetchTokenPriceInUsd(contractAddress) {
81
- // Use CoinGecko API to get token price by contract address
82
- const response = await fetch(
83
- `https://api.coingecko.com/api/v3/simple/token_price/ethereum?contract_addresses=${contractAddress}&vs_currencies=usd`,
84
- );
85
- const data = await response.json();
86
- const price = data[contractAddress.toLowerCase()]?.usd;
87
- if (!price) {
88
- throw new Error('Failed to fetch token price');
89
+ // Helper function to fetch token price in USD from Pioneer API
90
+ async function fetchTokenPriceInUsd(pioneer: any, caip: string) {
91
+ // Use the full CAIP string to get price from Pioneer API
92
+ try {
93
+ const marketInfo = await pioneer.GetMarketInfo([caip]);
94
+ if (marketInfo?.data && marketInfo.data.length > 0 && marketInfo.data[0] > 0) {
95
+ return marketInfo.data[0];
96
+ }
97
+ // Fallback if price not available
98
+ console.warn(`Token price not available from Pioneer API for ${caip}, using 0`);
99
+ return 0;
100
+ } catch (error) {
101
+ console.error(`Error fetching token price from Pioneer API for ${caip}:`, error);
102
+ return 0;
89
103
  }
90
- return price;
91
104
  }
92
105
 
93
106
  // Create an unsigned EVM transaction
@@ -526,11 +539,11 @@ export async function createUnsignedEvmTx(
526
539
 
527
540
  const data = encodeTransferData(to, amountWei);
528
541
 
529
- const ethPriceInUsd = await fetchEthPriceInUsd();
542
+ const ethPriceInUsd = await fetchEthPriceInUsd(pioneer, networkId);
530
543
  const gasFeeUsd = (Number(gasFee) / 1e18) * ethPriceInUsd;
531
544
 
532
- // For token price, need to fetch from API
533
- const tokenPriceInUsd = await fetchTokenPriceInUsd(contractAddress);
545
+ // For token price, fetch from Pioneer API using the full CAIP
546
+ const tokenPriceInUsd = await fetchTokenPriceInUsd(pioneer, caip);
534
547
  // Use the correct decimals for USD calculation
535
548
  const amountUsd = (Number(amountWei) / Number(tokenMultiplier)) * tokenPriceInUsd;
536
549