@pioneer-platform/pioneer-sdk 8.15.44 → 8.19.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 +58302 -121
- package/dist/index.es.js +46545 -2192
- package/dist/index.js +46545 -2192
- package/package.json +6 -6
- package/src/TransactionManager.ts +109 -11
- package/src/getPubkey.ts +29 -3
- package/src/index.ts +27 -2
- package/src/kkapi-batch-client.ts +97 -20
- package/src/supportedCaips.ts +6 -1
- package/src/txbuilder/createUnsignedSolanaTx.ts +132 -0
- package/src/txbuilder/createUnsignedTronTx.ts +97 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Create Unsigned TRON Transaction
|
|
3
|
+
*/
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
import { caipToNetworkId } from '@pioneer-platform/pioneer-caip';
|
|
6
|
+
|
|
7
|
+
const TAG = ' | createUnsignedTronTx | ';
|
|
8
|
+
|
|
9
|
+
export async function createUnsignedTronTx(
|
|
10
|
+
caip: string,
|
|
11
|
+
to: string,
|
|
12
|
+
amount: any,
|
|
13
|
+
memo: string,
|
|
14
|
+
pubkeys: any,
|
|
15
|
+
pioneer: any,
|
|
16
|
+
pubkeyContext: any,
|
|
17
|
+
isMax: boolean,
|
|
18
|
+
): Promise<any> {
|
|
19
|
+
let tag = TAG + ' | createUnsignedTronTx | ';
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
if (!pioneer) throw new Error('Failed to init! pioneer');
|
|
23
|
+
|
|
24
|
+
// Determine networkId from caip
|
|
25
|
+
const networkId = caipToNetworkId(caip);
|
|
26
|
+
|
|
27
|
+
// Use the passed pubkeyContext directly - it's already been set by Pioneer SDK
|
|
28
|
+
if (!pubkeyContext) {
|
|
29
|
+
throw new Error(`No pubkey context provided for networkId: ${networkId}`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (!pubkeyContext.networks?.includes(networkId)) {
|
|
33
|
+
throw new Error(
|
|
34
|
+
`Pubkey context is for wrong network. Expected ${networkId}, got ${pubkeyContext.networks}`,
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
console.log(tag, `✅ Using pubkeyContext for network ${networkId}:`, {
|
|
39
|
+
address: pubkeyContext.address,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const fromAddress = pubkeyContext.address || pubkeyContext.pubkey;
|
|
43
|
+
|
|
44
|
+
// Calculate amount in TRX (6 decimals for TRON)
|
|
45
|
+
let amountInTrx: number;
|
|
46
|
+
if (isMax) {
|
|
47
|
+
// For max transfers, get account balance
|
|
48
|
+
try {
|
|
49
|
+
let accountInfo = await pioneer.GetAccountInfo({
|
|
50
|
+
address: fromAddress,
|
|
51
|
+
network: 'tron',
|
|
52
|
+
});
|
|
53
|
+
accountInfo = accountInfo.data;
|
|
54
|
+
|
|
55
|
+
// Reserve fee (approximately 0.1 TRX)
|
|
56
|
+
const feeInTrx = 0.1;
|
|
57
|
+
amountInTrx = parseFloat(accountInfo.balance) - feeInTrx;
|
|
58
|
+
if (amountInTrx <= 0) {
|
|
59
|
+
throw new Error('Insufficient balance to cover fee');
|
|
60
|
+
}
|
|
61
|
+
} catch (e: any) {
|
|
62
|
+
console.warn(tag, 'GetAccountInfo not available for TRON, max transfer not supported:', e.message);
|
|
63
|
+
throw new Error('Max transfer not supported for TRON - Pioneer backend needs TRON account info support');
|
|
64
|
+
}
|
|
65
|
+
} else {
|
|
66
|
+
// For non-max transfers, use the provided amount directly
|
|
67
|
+
amountInTrx = parseFloat(amount);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Convert TRX to sun (1 TRX = 1,000,000 sun)
|
|
71
|
+
const amountInSun = Math.floor(amountInTrx * 1000000);
|
|
72
|
+
|
|
73
|
+
// Build unsigned transaction object for TRON
|
|
74
|
+
const unsignedTx = {
|
|
75
|
+
from: fromAddress,
|
|
76
|
+
to: to,
|
|
77
|
+
amount: amountInTrx,
|
|
78
|
+
amountInSun: amountInSun,
|
|
79
|
+
memo: memo || '',
|
|
80
|
+
addressNList: pubkeyContext.addressNList || pubkeyContext.addressNListMaster,
|
|
81
|
+
caip,
|
|
82
|
+
networkId,
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
console.log(tag, '✅ TRON transaction built successfully');
|
|
86
|
+
console.log(tag, 'Transaction details:', {
|
|
87
|
+
from: fromAddress,
|
|
88
|
+
to: to,
|
|
89
|
+
amount: `${amountInTrx} TRX (${amountInSun} sun)`,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
return unsignedTx;
|
|
93
|
+
} catch (error) {
|
|
94
|
+
console.error(tag, 'Error:', error);
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
97
|
+
}
|