@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 +19 -8
- package/dist/index.es.js +19 -8
- package/dist/index.js +19 -8
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/txbuilder/createUnsignedEvmTx.ts +20 -19
- package/src/txbuilder/createUnsignedTendermintTx.ts +9 -5
- package/src/index.ts.backup +0 -2584
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
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
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 (
|
|
2389
|
+
if (accountInfo.account) {
|
|
2381
2390
|
account_number = accountInfo.account.account_number || "0";
|
|
2382
2391
|
sequence = accountInfo.account.sequence || "0";
|
|
2383
|
-
} else if (
|
|
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://
|
|
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
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
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 (
|
|
2565
|
+
if (accountInfo.account) {
|
|
2557
2566
|
account_number = accountInfo.account.account_number || "0";
|
|
2558
2567
|
sequence = accountInfo.account.sequence || "0";
|
|
2559
|
-
} else if (
|
|
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://
|
|
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
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
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 (
|
|
2565
|
+
if (accountInfo.account) {
|
|
2557
2566
|
account_number = accountInfo.account.account_number || "0";
|
|
2558
2567
|
sequence = accountInfo.account.sequence || "0";
|
|
2559
|
-
} else if (
|
|
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://
|
|
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
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://
|
|
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
|
-
//
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
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
|
-
|
|
490
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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}`);
|