@pioneer-platform/pioneer-sdk 4.20.13 → 4.20.15

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
@@ -2035,11 +2035,20 @@ async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, pub
2035
2035
  }
2036
2036
  case "erc20": {
2037
2037
  const contractAddress = extractContractAddressFromCaip(caip);
2038
- let tokenDecimals = 18;
2039
- const contractLower = contractAddress.toLowerCase();
2040
- if (contractLower === "0xdac17f958d2ee523a2206206994597c13d831ec7" || contractLower === "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48" || contractLower === "0x4fabb145d64652a948d72533023f6e7a623c7c53" || contractLower === "0x8e870d67f660d95d5be530380d0ec0bd388289e1") {
2041
- tokenDecimals = 6;
2042
- console.log(tag5, "Using 6 decimals for stablecoin:", contractAddress);
2038
+ console.log(tag5, "Fetching token decimals from contract:", contractAddress, "on network:", networkId);
2039
+ let tokenDecimals;
2040
+ try {
2041
+ console.log(tag5, "Fetching token decimals via pioneer-server API for", contractAddress, "on", networkId);
2042
+ const decimalsResponse = await pioneer.GetTokenDecimals({
2043
+ networkId,
2044
+ contractAddress
2045
+ });
2046
+ tokenDecimals = Number(decimalsResponse.data.decimals);
2047
+ console.log(tag5, "✅ Fetched decimals from pioneer-server:", tokenDecimals);
2048
+ } catch (error) {
2049
+ console.error(tag5, "Failed to fetch token decimals from pioneer-server:", error);
2050
+ console.warn(tag5, "⚠️ FALLBACK: Using default 18 decimals - THIS MAY BE INCORRECT!");
2051
+ tokenDecimals = 18;
2043
2052
  }
2044
2053
  const tokenMultiplier = 10n ** BigInt(tokenDecimals);
2045
2054
  let gasLimit = BigInt(1e5);
@@ -2377,12 +2386,14 @@ async function createUnsignedTendermintTx(caip, type, amount, memo, pubkeys, pio
2377
2386
  let balanceInfo = await pioneer.GetPubkeyBalance({ asset: chain, pubkey: fromAddress });
2378
2387
  console.log(tag5, `\uD83D\uDCB0 balanceInfo:`, balanceInfo);
2379
2388
  let account_number, sequence;
2380
- if (networkId === "cosmos:cosmoshub-4" || networkId === "cosmos:osmosis-1") {
2389
+ if (accountInfo.account) {
2381
2390
  account_number = accountInfo.account.account_number || "0";
2382
2391
  sequence = accountInfo.account.sequence || "0";
2383
- } else if (networkId === "cosmos:thorchain-mainnet-v1" || networkId === "cosmos:mayachain-mainnet-v1") {
2392
+ } else if (accountInfo.result?.value) {
2384
2393
  account_number = accountInfo.result.value.account_number || "0";
2385
2394
  sequence = accountInfo.result.value.sequence || "0";
2395
+ } else {
2396
+ throw new Error(`Unexpected account info format for ${networkId}: ${JSON.stringify(accountInfo)}`);
2386
2397
  }
2387
2398
  console.log(tag5, `\uD83D\uDCCA Extracted account_number: ${account_number}, sequence: ${sequence}`);
2388
2399
  if (account_number === "0" || account_number === 0) {
@@ -4131,7 +4142,7 @@ class SDK {
4131
4142
  this.status = "preInit";
4132
4143
  this.appName = config.appName || "unknown app";
4133
4144
  this.appIcon = config.appIcon || "https://pioneers.dev/coins/keepkey.png";
4134
- this.spec = spec || config.spec || "https://pioneers.dev/spec/swagger";
4145
+ this.spec = spec || config.spec || "https://api.keepkey.info/spec/swagger";
4135
4146
  this.wss = config.wss || "wss://pioneers.dev";
4136
4147
  this.assets = import_pioneer_discovery2.assetData;
4137
4148
  this.assetsMap = new Map;
package/dist/index.es.js CHANGED
@@ -2211,11 +2211,20 @@ async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, pub
2211
2211
  }
2212
2212
  case "erc20": {
2213
2213
  const contractAddress = extractContractAddressFromCaip(caip);
2214
- let tokenDecimals = 18;
2215
- const contractLower = contractAddress.toLowerCase();
2216
- if (contractLower === "0xdac17f958d2ee523a2206206994597c13d831ec7" || contractLower === "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48" || contractLower === "0x4fabb145d64652a948d72533023f6e7a623c7c53" || contractLower === "0x8e870d67f660d95d5be530380d0ec0bd388289e1") {
2217
- tokenDecimals = 6;
2218
- console.log(tag5, "Using 6 decimals for stablecoin:", contractAddress);
2214
+ console.log(tag5, "Fetching token decimals from contract:", contractAddress, "on network:", networkId);
2215
+ let tokenDecimals;
2216
+ try {
2217
+ console.log(tag5, "Fetching token decimals via pioneer-server API for", contractAddress, "on", networkId);
2218
+ const decimalsResponse = await pioneer.GetTokenDecimals({
2219
+ networkId,
2220
+ contractAddress
2221
+ });
2222
+ tokenDecimals = Number(decimalsResponse.data.decimals);
2223
+ console.log(tag5, "✅ Fetched decimals from pioneer-server:", tokenDecimals);
2224
+ } catch (error) {
2225
+ console.error(tag5, "Failed to fetch token decimals from pioneer-server:", error);
2226
+ console.warn(tag5, "⚠️ FALLBACK: Using default 18 decimals - THIS MAY BE INCORRECT!");
2227
+ tokenDecimals = 18;
2219
2228
  }
2220
2229
  const tokenMultiplier = 10n ** BigInt(tokenDecimals);
2221
2230
  let gasLimit = BigInt(1e5);
@@ -2553,12 +2562,14 @@ async function createUnsignedTendermintTx(caip, type, amount, memo, pubkeys, pio
2553
2562
  let balanceInfo = await pioneer.GetPubkeyBalance({ asset: chain, pubkey: fromAddress });
2554
2563
  console.log(tag5, `\uD83D\uDCB0 balanceInfo:`, balanceInfo);
2555
2564
  let account_number, sequence;
2556
- if (networkId === "cosmos:cosmoshub-4" || networkId === "cosmos:osmosis-1") {
2565
+ if (accountInfo.account) {
2557
2566
  account_number = accountInfo.account.account_number || "0";
2558
2567
  sequence = accountInfo.account.sequence || "0";
2559
- } else if (networkId === "cosmos:thorchain-mainnet-v1" || networkId === "cosmos:mayachain-mainnet-v1") {
2568
+ } else if (accountInfo.result?.value) {
2560
2569
  account_number = accountInfo.result.value.account_number || "0";
2561
2570
  sequence = accountInfo.result.value.sequence || "0";
2571
+ } else {
2572
+ throw new Error(`Unexpected account info format for ${networkId}: ${JSON.stringify(accountInfo)}`);
2562
2573
  }
2563
2574
  console.log(tag5, `\uD83D\uDCCA Extracted account_number: ${account_number}, sequence: ${sequence}`);
2564
2575
  if (account_number === "0" || account_number === 0) {
@@ -4307,7 +4318,7 @@ class SDK {
4307
4318
  this.status = "preInit";
4308
4319
  this.appName = config.appName || "unknown app";
4309
4320
  this.appIcon = config.appIcon || "https://pioneers.dev/coins/keepkey.png";
4310
- this.spec = spec || config.spec || "https://pioneers.dev/spec/swagger";
4321
+ this.spec = spec || config.spec || "https://api.keepkey.info/spec/swagger";
4311
4322
  this.wss = config.wss || "wss://pioneers.dev";
4312
4323
  this.assets = assetData2;
4313
4324
  this.assetsMap = new Map;
package/dist/index.js CHANGED
@@ -2211,11 +2211,20 @@ async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, pub
2211
2211
  }
2212
2212
  case "erc20": {
2213
2213
  const contractAddress = extractContractAddressFromCaip(caip);
2214
- let tokenDecimals = 18;
2215
- const contractLower = contractAddress.toLowerCase();
2216
- if (contractLower === "0xdac17f958d2ee523a2206206994597c13d831ec7" || contractLower === "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48" || contractLower === "0x4fabb145d64652a948d72533023f6e7a623c7c53" || contractLower === "0x8e870d67f660d95d5be530380d0ec0bd388289e1") {
2217
- tokenDecimals = 6;
2218
- console.log(tag5, "Using 6 decimals for stablecoin:", contractAddress);
2214
+ console.log(tag5, "Fetching token decimals from contract:", contractAddress, "on network:", networkId);
2215
+ let tokenDecimals;
2216
+ try {
2217
+ console.log(tag5, "Fetching token decimals via pioneer-server API for", contractAddress, "on", networkId);
2218
+ const decimalsResponse = await pioneer.GetTokenDecimals({
2219
+ networkId,
2220
+ contractAddress
2221
+ });
2222
+ tokenDecimals = Number(decimalsResponse.data.decimals);
2223
+ console.log(tag5, "✅ Fetched decimals from pioneer-server:", tokenDecimals);
2224
+ } catch (error) {
2225
+ console.error(tag5, "Failed to fetch token decimals from pioneer-server:", error);
2226
+ console.warn(tag5, "⚠️ FALLBACK: Using default 18 decimals - THIS MAY BE INCORRECT!");
2227
+ tokenDecimals = 18;
2219
2228
  }
2220
2229
  const tokenMultiplier = 10n ** BigInt(tokenDecimals);
2221
2230
  let gasLimit = BigInt(1e5);
@@ -2553,12 +2562,14 @@ async function createUnsignedTendermintTx(caip, type, amount, memo, pubkeys, pio
2553
2562
  let balanceInfo = await pioneer.GetPubkeyBalance({ asset: chain, pubkey: fromAddress });
2554
2563
  console.log(tag5, `\uD83D\uDCB0 balanceInfo:`, balanceInfo);
2555
2564
  let account_number, sequence;
2556
- if (networkId === "cosmos:cosmoshub-4" || networkId === "cosmos:osmosis-1") {
2565
+ if (accountInfo.account) {
2557
2566
  account_number = accountInfo.account.account_number || "0";
2558
2567
  sequence = accountInfo.account.sequence || "0";
2559
- } else if (networkId === "cosmos:thorchain-mainnet-v1" || networkId === "cosmos:mayachain-mainnet-v1") {
2568
+ } else if (accountInfo.result?.value) {
2560
2569
  account_number = accountInfo.result.value.account_number || "0";
2561
2570
  sequence = accountInfo.result.value.sequence || "0";
2571
+ } else {
2572
+ throw new Error(`Unexpected account info format for ${networkId}: ${JSON.stringify(accountInfo)}`);
2562
2573
  }
2563
2574
  console.log(tag5, `\uD83D\uDCCA Extracted account_number: ${account_number}, sequence: ${sequence}`);
2564
2575
  if (account_number === "0" || account_number === 0) {
@@ -4307,7 +4318,7 @@ class SDK {
4307
4318
  this.status = "preInit";
4308
4319
  this.appName = config.appName || "unknown app";
4309
4320
  this.appIcon = config.appIcon || "https://pioneers.dev/coins/keepkey.png";
4310
- this.spec = spec || config.spec || "https://pioneers.dev/spec/swagger";
4321
+ this.spec = spec || config.spec || "https://api.keepkey.info/spec/swagger";
4311
4322
  this.wss = config.wss || "wss://pioneers.dev";
4312
4323
  this.assets = assetData2;
4313
4324
  this.assetsMap = new Map;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "highlander",
3
3
  "name": "@pioneer-platform/pioneer-sdk",
4
- "version": "4.20.13",
4
+ "version": "4.20.15",
5
5
  "dependencies": {
6
6
  "@keepkey/keepkey-sdk": "^0.2.62",
7
7
  "@pioneer-platform/loggerdog": "^8.11.0",
package/src/index.ts CHANGED
@@ -172,7 +172,7 @@ export class SDK {
172
172
  this.status = 'preInit';
173
173
  this.appName = config.appName || 'unknown app';
174
174
  this.appIcon = config.appIcon || 'https://pioneers.dev/coins/keepkey.png';
175
- this.spec = spec || config.spec || 'https://pioneers.dev/spec/swagger';
175
+ this.spec = spec || config.spec || 'https://api.keepkey.info/spec/swagger';
176
176
  this.wss = config.wss || 'wss://pioneers.dev';
177
177
  this.assets = assetData;
178
178
  this.assetsMap = new Map();
@@ -468,26 +468,27 @@ export async function createUnsignedEvmTx(
468
468
  case 'erc20': {
469
469
  const contractAddress = extractContractAddressFromCaip(caip);
470
470
 
471
- // Get token decimals - CRITICAL for correct amount calculation
472
- // Common token decimals:
473
- // USDT: 6, USDC: 6, DAI: 18, WETH: 18, most others: 18
474
- let tokenDecimals = 18; // Default to 18 if not specified
475
-
476
- // Check for known stablecoins with 6 decimals
477
- const contractLower = contractAddress.toLowerCase();
478
- if (
479
- contractLower === '0xdac17f958d2ee523a2206206994597c13d831ec7' || // USDT on Ethereum
480
- contractLower === '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48' || // USDC on Ethereum
481
- contractLower === '0x4fabb145d64652a948d72533023f6e7a623c7c53' || // BUSD on Ethereum
482
- contractLower === '0x8e870d67f660d95d5be530380d0ec0bd388289e1'
483
- ) {
484
- // USDP on Ethereum
485
- tokenDecimals = 6;
486
- console.log(tag, 'Using 6 decimals for stablecoin:', contractAddress);
487
- }
471
+ // Get token decimals from contract - CRITICAL for correct amount calculation
472
+ // Fetch decimals from contract directly (handles all tokens on all chains)
473
+ console.log(tag, 'Fetching token decimals from contract:', contractAddress, 'on network:', networkId);
474
+
475
+ let tokenDecimals: number;
476
+ try {
477
+ // Call pioneer-server API to get token decimals (server handles RPC calls)
478
+ console.log(tag, 'Fetching token decimals via pioneer-server API for', contractAddress, 'on', networkId);
479
+ const decimalsResponse = await pioneer.GetTokenDecimals({
480
+ networkId,
481
+ contractAddress,
482
+ });
488
483
 
489
- // TODO: Fetch decimals from contract in the future:
490
- // const decimals = await getTokenDecimals(contractAddress, networkId);
484
+ tokenDecimals = Number(decimalsResponse.data.decimals);
485
+ console.log(tag, '✅ Fetched decimals from pioneer-server:', tokenDecimals);
486
+ } catch (error: any) {
487
+ console.error(tag, 'Failed to fetch token decimals from pioneer-server:', error);
488
+ // Fallback to 18 decimals as last resort (but log warning)
489
+ console.warn(tag, '⚠️ FALLBACK: Using default 18 decimals - THIS MAY BE INCORRECT!');
490
+ tokenDecimals = 18;
491
+ }
491
492
 
492
493
  // Use BigInt for precise decimal math (no float drift)
493
494
  const tokenMultiplier = 10n ** BigInt(tokenDecimals);
@@ -73,15 +73,19 @@ export async function createUnsignedTendermintTx(
73
73
  console.log(tag, `💰 balanceInfo:`, balanceInfo);
74
74
 
75
75
  let account_number, sequence;
76
- if (networkId === 'cosmos:cosmoshub-4' || networkId === 'cosmos:osmosis-1') {
76
+
77
+ // Handle both old (result.value) and new (account) API formats
78
+ // Thorchain upgraded to Cosmos SDK v0.47+ format, similar to Cosmoshub/Osmosis
79
+ if (accountInfo.account) {
80
+ // New format (Cosmos SDK v0.47+): used by all chains now
77
81
  account_number = accountInfo.account.account_number || '0';
78
82
  sequence = accountInfo.account.sequence || '0';
79
- } else if (
80
- networkId === 'cosmos:thorchain-mainnet-v1' ||
81
- networkId === 'cosmos:mayachain-mainnet-v1'
82
- ) {
83
+ } else if (accountInfo.result?.value) {
84
+ // Old format (Cosmos SDK v0.45): legacy fallback
83
85
  account_number = accountInfo.result.value.account_number || '0';
84
86
  sequence = accountInfo.result.value.sequence || '0';
87
+ } else {
88
+ throw new Error(`Unexpected account info format for ${networkId}: ${JSON.stringify(accountInfo)}`);
85
89
  }
86
90
 
87
91
  console.log(tag, `📊 Extracted account_number: ${account_number}, sequence: ${sequence}`);