@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 +24 -12
- package/dist/index.es.js +24 -12
- package/dist/index.js +24 -12
- package/package.json +1 -1
- package/src/TransactionManager.ts +4 -3
- package/src/index.ts +1 -1
- package/src/txbuilder/createUnsignedEvmTx.ts +20 -19
- package/src/txbuilder/createUnsignedTendermintTx.ts +9 -5
- package/src/txbuilder/templates/thorchain.ts +1 -1
- 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);
|
|
@@ -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: "
|
|
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 (
|
|
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) {
|
|
@@ -3043,14 +3054,15 @@ class TransactionManager {
|
|
|
3043
3054
|
break;
|
|
3044
3055
|
}
|
|
3045
3056
|
case "cosmos:thorchain-mainnet-v1/slip44:931": {
|
|
3046
|
-
|
|
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 (
|
|
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: ${
|
|
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://
|
|
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
|
-
|
|
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);
|
|
@@ -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: "
|
|
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 (
|
|
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) {
|
|
@@ -3219,14 +3230,15 @@ class TransactionManager {
|
|
|
3219
3230
|
break;
|
|
3220
3231
|
}
|
|
3221
3232
|
case "cosmos:thorchain-mainnet-v1/slip44:931": {
|
|
3222
|
-
|
|
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 (
|
|
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: ${
|
|
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://
|
|
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
|
-
|
|
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);
|
|
@@ -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: "
|
|
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 (
|
|
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) {
|
|
@@ -3219,14 +3230,15 @@ class TransactionManager {
|
|
|
3219
3230
|
break;
|
|
3220
3231
|
}
|
|
3221
3232
|
case "cosmos:thorchain-mainnet-v1/slip44:931": {
|
|
3222
|
-
|
|
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 (
|
|
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: ${
|
|
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://
|
|
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
|
@@ -223,17 +223,18 @@ export class TransactionManager {
|
|
|
223
223
|
break;
|
|
224
224
|
}
|
|
225
225
|
case 'cosmos:thorchain-mainnet-v1/slip44:931': {
|
|
226
|
-
|
|
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 (
|
|
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: ${
|
|
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://
|
|
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}`);
|