@pioneer-platform/pioneer-sdk 4.20.11 → 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 +28 -15
- package/dist/index.es.js +28 -15
- package/dist/index.js +28 -15
- package/package.json +2 -2
- package/src/txbuilder/createUnsignedEvmTx.ts +38 -25
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
|
|
1759
|
-
|
|
1760
|
-
|
|
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(
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
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 | ";
|
|
@@ -1891,7 +1904,7 @@ async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, pub
|
|
|
1891
1904
|
let nonce;
|
|
1892
1905
|
try {
|
|
1893
1906
|
const nonceData = await pioneer.GetNonceByNetwork({ networkId, address });
|
|
1894
|
-
nonce = nonceData.data;
|
|
1907
|
+
nonce = nonceData.data.nonce;
|
|
1895
1908
|
if (nonce === undefined || nonce === null) {
|
|
1896
1909
|
console.log(tag5, "No nonce found for address (likely fresh address), defaulting to 0");
|
|
1897
1910
|
nonce = 0;
|
|
@@ -1901,7 +1914,7 @@ async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, pub
|
|
|
1901
1914
|
nonce = 0;
|
|
1902
1915
|
}
|
|
1903
1916
|
const balanceData = await pioneer.GetBalanceAddressByNetwork({ networkId, address });
|
|
1904
|
-
const balanceEth = balanceData.data;
|
|
1917
|
+
const balanceEth = parseFloat(balanceData.data.balance);
|
|
1905
1918
|
const balance = BigInt(Math.round(balanceEth * 1000000000000000000));
|
|
1906
1919
|
if (balance <= 0n)
|
|
1907
1920
|
throw new Error("Wallet balance is zero");
|
|
@@ -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(
|
|
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
|
|
1935
|
-
|
|
1936
|
-
|
|
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(
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
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 | ";
|
|
@@ -2067,7 +2080,7 @@ async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, pub
|
|
|
2067
2080
|
let nonce;
|
|
2068
2081
|
try {
|
|
2069
2082
|
const nonceData = await pioneer.GetNonceByNetwork({ networkId, address });
|
|
2070
|
-
nonce = nonceData.data;
|
|
2083
|
+
nonce = nonceData.data.nonce;
|
|
2071
2084
|
if (nonce === undefined || nonce === null) {
|
|
2072
2085
|
console.log(tag5, "No nonce found for address (likely fresh address), defaulting to 0");
|
|
2073
2086
|
nonce = 0;
|
|
@@ -2077,7 +2090,7 @@ async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, pub
|
|
|
2077
2090
|
nonce = 0;
|
|
2078
2091
|
}
|
|
2079
2092
|
const balanceData = await pioneer.GetBalanceAddressByNetwork({ networkId, address });
|
|
2080
|
-
const balanceEth = balanceData.data;
|
|
2093
|
+
const balanceEth = parseFloat(balanceData.data.balance);
|
|
2081
2094
|
const balance = BigInt(Math.round(balanceEth * 1000000000000000000));
|
|
2082
2095
|
if (balance <= 0n)
|
|
2083
2096
|
throw new Error("Wallet balance is zero");
|
|
@@ -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(
|
|
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
|
|
1935
|
-
|
|
1936
|
-
|
|
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(
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
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 | ";
|
|
@@ -2067,7 +2080,7 @@ async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, pub
|
|
|
2067
2080
|
let nonce;
|
|
2068
2081
|
try {
|
|
2069
2082
|
const nonceData = await pioneer.GetNonceByNetwork({ networkId, address });
|
|
2070
|
-
nonce = nonceData.data;
|
|
2083
|
+
nonce = nonceData.data.nonce;
|
|
2071
2084
|
if (nonce === undefined || nonce === null) {
|
|
2072
2085
|
console.log(tag5, "No nonce found for address (likely fresh address), defaulting to 0");
|
|
2073
2086
|
nonce = 0;
|
|
@@ -2077,7 +2090,7 @@ async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, pub
|
|
|
2077
2090
|
nonce = 0;
|
|
2078
2091
|
}
|
|
2079
2092
|
const balanceData = await pioneer.GetBalanceAddressByNetwork({ networkId, address });
|
|
2080
|
-
const balanceEth = balanceData.data;
|
|
2093
|
+
const balanceEth = parseFloat(balanceData.data.balance);
|
|
2081
2094
|
const balance = BigInt(Math.round(balanceEth * 1000000000000000000));
|
|
2082
2095
|
if (balance <= 0n)
|
|
2083
2096
|
throw new Error("Wallet balance is zero");
|
|
@@ -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(
|
|
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.
|
|
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.
|
|
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
|
|
36
|
-
async function fetchEthPriceInUsd() {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
//
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
|
@@ -241,8 +254,8 @@ export async function createUnsignedEvmTx(
|
|
|
241
254
|
let nonce;
|
|
242
255
|
try {
|
|
243
256
|
const nonceData = await pioneer.GetNonceByNetwork({ networkId, address });
|
|
244
|
-
nonce = nonceData.data;
|
|
245
|
-
|
|
257
|
+
nonce = nonceData.data.nonce;
|
|
258
|
+
|
|
246
259
|
// Handle fresh addresses that have never sent a transaction
|
|
247
260
|
if (nonce === undefined || nonce === null) {
|
|
248
261
|
console.log(tag, 'No nonce found for address (likely fresh address), defaulting to 0');
|
|
@@ -256,7 +269,7 @@ export async function createUnsignedEvmTx(
|
|
|
256
269
|
//console.log(tag, 'nonce:', nonce);
|
|
257
270
|
|
|
258
271
|
const balanceData = await pioneer.GetBalanceAddressByNetwork({ networkId, address });
|
|
259
|
-
const balanceEth = balanceData.data; // Assuming this is in ETH
|
|
272
|
+
const balanceEth = parseFloat(balanceData.data.balance); // Assuming this is in ETH
|
|
260
273
|
const balance = BigInt(Math.round(balanceEth * 1e18)); // Convert to wei
|
|
261
274
|
//console.log(tag, 'balance (wei):', balance.toString());
|
|
262
275
|
if (balance <= 0n) throw new Error('Wallet balance is zero');
|
|
@@ -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,
|
|
533
|
-
const tokenPriceInUsd = await fetchTokenPriceInUsd(
|
|
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
|
|