@pioneer-platform/pioneer-sdk 4.20.13 → 4.21.0

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);
@@ -2306,7 +2315,7 @@ var thorchainTransferTemplate = (params) => ({
2306
2315
  to_address: params.to_address,
2307
2316
  from_address: params.from_address
2308
2317
  },
2309
- type: "cosmos-sdk/MsgSend"
2318
+ type: "thorchain/MsgSend"
2310
2319
  }
2311
2320
  ],
2312
2321
  memo: params.memo,
@@ -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) {
@@ -3043,14 +3054,15 @@ class TransactionManager {
3043
3054
  break;
3044
3055
  }
3045
3056
  case "cosmos:thorchain-mainnet-v1/slip44:931": {
3046
- if (unsignedTx.signDoc.msgs[0].type === "thorchain/MsgSend") {
3057
+ const msgType = unsignedTx.signDoc.msgs[0].type;
3058
+ if (msgType === "thorchain/MsgSend" || msgType === "cosmos-sdk/MsgSend") {
3047
3059
  const responseSign = await this.keepKeySdk.thorchain.thorchainSignAminoTransfer(unsignedTx);
3048
3060
  signedTx = responseSign.serialized;
3049
- } else if (unsignedTx.signDoc.msgs[0].type === "thorchain/MsgDeposit") {
3061
+ } else if (msgType === "thorchain/MsgDeposit") {
3050
3062
  const responseSign = await this.keepKeySdk.thorchain.thorchainSignAminoDeposit(unsignedTx);
3051
3063
  signedTx = responseSign.serialized;
3052
3064
  } else {
3053
- throw new Error(`Unsupported Thorchain message type: ${unsignedTx.signDoc.msgs[0].type}`);
3065
+ throw new Error(`Unsupported Thorchain message type: ${msgType}`);
3054
3066
  }
3055
3067
  break;
3056
3068
  }
@@ -4131,7 +4143,7 @@ class SDK {
4131
4143
  this.status = "preInit";
4132
4144
  this.appName = config.appName || "unknown app";
4133
4145
  this.appIcon = config.appIcon || "https://pioneers.dev/coins/keepkey.png";
4134
- this.spec = spec || config.spec || "https://pioneers.dev/spec/swagger";
4146
+ this.spec = spec || config.spec || "https://api.keepkey.info/spec/swagger";
4135
4147
  this.wss = config.wss || "wss://pioneers.dev";
4136
4148
  this.assets = import_pioneer_discovery2.assetData;
4137
4149
  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);
@@ -2482,7 +2491,7 @@ var thorchainTransferTemplate = (params) => ({
2482
2491
  to_address: params.to_address,
2483
2492
  from_address: params.from_address
2484
2493
  },
2485
- type: "cosmos-sdk/MsgSend"
2494
+ type: "thorchain/MsgSend"
2486
2495
  }
2487
2496
  ],
2488
2497
  memo: params.memo,
@@ -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) {
@@ -3219,14 +3230,15 @@ class TransactionManager {
3219
3230
  break;
3220
3231
  }
3221
3232
  case "cosmos:thorchain-mainnet-v1/slip44:931": {
3222
- if (unsignedTx.signDoc.msgs[0].type === "thorchain/MsgSend") {
3233
+ const msgType = unsignedTx.signDoc.msgs[0].type;
3234
+ if (msgType === "thorchain/MsgSend" || msgType === "cosmos-sdk/MsgSend") {
3223
3235
  const responseSign = await this.keepKeySdk.thorchain.thorchainSignAminoTransfer(unsignedTx);
3224
3236
  signedTx = responseSign.serialized;
3225
- } else if (unsignedTx.signDoc.msgs[0].type === "thorchain/MsgDeposit") {
3237
+ } else if (msgType === "thorchain/MsgDeposit") {
3226
3238
  const responseSign = await this.keepKeySdk.thorchain.thorchainSignAminoDeposit(unsignedTx);
3227
3239
  signedTx = responseSign.serialized;
3228
3240
  } else {
3229
- throw new Error(`Unsupported Thorchain message type: ${unsignedTx.signDoc.msgs[0].type}`);
3241
+ throw new Error(`Unsupported Thorchain message type: ${msgType}`);
3230
3242
  }
3231
3243
  break;
3232
3244
  }
@@ -4307,7 +4319,7 @@ class SDK {
4307
4319
  this.status = "preInit";
4308
4320
  this.appName = config.appName || "unknown app";
4309
4321
  this.appIcon = config.appIcon || "https://pioneers.dev/coins/keepkey.png";
4310
- this.spec = spec || config.spec || "https://pioneers.dev/spec/swagger";
4322
+ this.spec = spec || config.spec || "https://api.keepkey.info/spec/swagger";
4311
4323
  this.wss = config.wss || "wss://pioneers.dev";
4312
4324
  this.assets = assetData2;
4313
4325
  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);
@@ -2482,7 +2491,7 @@ var thorchainTransferTemplate = (params) => ({
2482
2491
  to_address: params.to_address,
2483
2492
  from_address: params.from_address
2484
2493
  },
2485
- type: "cosmos-sdk/MsgSend"
2494
+ type: "thorchain/MsgSend"
2486
2495
  }
2487
2496
  ],
2488
2497
  memo: params.memo,
@@ -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) {
@@ -3219,14 +3230,15 @@ class TransactionManager {
3219
3230
  break;
3220
3231
  }
3221
3232
  case "cosmos:thorchain-mainnet-v1/slip44:931": {
3222
- if (unsignedTx.signDoc.msgs[0].type === "thorchain/MsgSend") {
3233
+ const msgType = unsignedTx.signDoc.msgs[0].type;
3234
+ if (msgType === "thorchain/MsgSend" || msgType === "cosmos-sdk/MsgSend") {
3223
3235
  const responseSign = await this.keepKeySdk.thorchain.thorchainSignAminoTransfer(unsignedTx);
3224
3236
  signedTx = responseSign.serialized;
3225
- } else if (unsignedTx.signDoc.msgs[0].type === "thorchain/MsgDeposit") {
3237
+ } else if (msgType === "thorchain/MsgDeposit") {
3226
3238
  const responseSign = await this.keepKeySdk.thorchain.thorchainSignAminoDeposit(unsignedTx);
3227
3239
  signedTx = responseSign.serialized;
3228
3240
  } else {
3229
- throw new Error(`Unsupported Thorchain message type: ${unsignedTx.signDoc.msgs[0].type}`);
3241
+ throw new Error(`Unsupported Thorchain message type: ${msgType}`);
3230
3242
  }
3231
3243
  break;
3232
3244
  }
@@ -4307,7 +4319,7 @@ class SDK {
4307
4319
  this.status = "preInit";
4308
4320
  this.appName = config.appName || "unknown app";
4309
4321
  this.appIcon = config.appIcon || "https://pioneers.dev/coins/keepkey.png";
4310
- this.spec = spec || config.spec || "https://pioneers.dev/spec/swagger";
4322
+ this.spec = spec || config.spec || "https://api.keepkey.info/spec/swagger";
4311
4323
  this.wss = config.wss || "wss://pioneers.dev";
4312
4324
  this.assets = assetData2;
4313
4325
  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.21.0",
5
5
  "dependencies": {
6
6
  "@keepkey/keepkey-sdk": "^0.2.62",
7
7
  "@pioneer-platform/loggerdog": "^8.11.0",
@@ -223,17 +223,18 @@ export class TransactionManager {
223
223
  break;
224
224
  }
225
225
  case 'cosmos:thorchain-mainnet-v1/slip44:931': {
226
- if (unsignedTx.signDoc.msgs[0].type === 'thorchain/MsgSend') {
226
+ const msgType = unsignedTx.signDoc.msgs[0].type;
227
+ if (msgType === 'thorchain/MsgSend' || msgType === 'cosmos-sdk/MsgSend') {
227
228
  const responseSign =
228
229
  await this.keepKeySdk.thorchain.thorchainSignAminoTransfer(unsignedTx);
229
230
  signedTx = responseSign.serialized;
230
- } else if (unsignedTx.signDoc.msgs[0].type === 'thorchain/MsgDeposit') {
231
+ } else if (msgType === 'thorchain/MsgDeposit') {
231
232
  const responseSign =
232
233
  await this.keepKeySdk.thorchain.thorchainSignAminoDeposit(unsignedTx);
233
234
  signedTx = responseSign.serialized;
234
235
  } else {
235
236
  throw new Error(
236
- `Unsupported Thorchain message type: ${unsignedTx.signDoc.msgs[0].type}`,
237
+ `Unsupported Thorchain message type: ${msgType}`,
237
238
  );
238
239
  }
239
240
  break;
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}`);
@@ -21,7 +21,7 @@ export const thorchainTransferTemplate = (params: {
21
21
  to_address: params.to_address,
22
22
  from_address: params.from_address,
23
23
  },
24
- type: 'cosmos-sdk/MsgSend' as const,
24
+ type: 'thorchain/MsgSend' as const,
25
25
  },
26
26
  ],
27
27
  memo: params.memo,