@exodus/solana-lib 1.3.3 → 1.3.4
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/package.json +2 -2
- package/src/transaction.js +5 -5
- package/src/tx/simulate-and-sign-tx.js +31 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/solana-lib",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.4",
|
|
4
4
|
"description": "Exodus internal Solana low-level library",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -25,5 +25,5 @@
|
|
|
25
25
|
"lodash": "^4.17.11",
|
|
26
26
|
"tweetnacl": "^1.0.3"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "bb5c9d32448313fc724739be2e3583926946c42e"
|
|
29
29
|
}
|
package/src/transaction.js
CHANGED
|
@@ -98,13 +98,13 @@ class Tx {
|
|
|
98
98
|
buildInstructionsTransaction({ feePayer, recentBlockhash, instructions }) {
|
|
99
99
|
this.transaction = new Transaction({
|
|
100
100
|
feePayer: new PublicKey(feePayer),
|
|
101
|
-
instructions: instructions.map(i => ({
|
|
101
|
+
instructions: instructions.map((i) => ({
|
|
102
102
|
programId: new PublicKey(i.programId),
|
|
103
|
-
data: i.data ? Buffer.from(i.data) : Buffer.from([]),
|
|
104
|
-
keys: i.keys.map(k => ({
|
|
103
|
+
data: i.data ? Buffer.from(bs58.decode(i.data)) : Buffer.from([]),
|
|
104
|
+
keys: i.keys.map((k) => ({
|
|
105
105
|
...k,
|
|
106
|
-
pubkey: new PublicKey(k.pubkey)
|
|
107
|
-
}))
|
|
106
|
+
pubkey: new PublicKey(k.pubkey),
|
|
107
|
+
})),
|
|
108
108
|
})),
|
|
109
109
|
recentBlockhash,
|
|
110
110
|
})
|
|
@@ -1,18 +1,27 @@
|
|
|
1
1
|
import { Token, U64 } from '../helpers/spl-token'
|
|
2
2
|
import { PublicKey } from '../vendor/'
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Maximum over-the-wire size of a Transaction
|
|
6
|
+
*
|
|
7
|
+
* 1280 is IPv6 minimum MTU
|
|
8
|
+
* 40 bytes is the size of the IPv6 header
|
|
9
|
+
* 8 bytes is the size of the fragment header
|
|
10
|
+
*/
|
|
11
|
+
const PACKET_DATA_SIZE = 1280 - 40 - 8;
|
|
12
|
+
const SIGNATURE_LENGTH = 64;
|
|
13
|
+
|
|
4
14
|
export function computeBalance(futureAccountBalance: string, currentAccountBalance: string) {
|
|
5
15
|
return new U64(futureAccountBalance).sub(new U64(currentAccountBalance))
|
|
6
16
|
}
|
|
7
17
|
|
|
8
|
-
export function getTransactionSimulationParams(
|
|
18
|
+
export function getTransactionSimulationParams(transactionMessage) {
|
|
9
19
|
const config = {
|
|
10
20
|
encoding: 'base64',
|
|
11
21
|
commitment: 'confirmed',
|
|
12
22
|
}
|
|
13
23
|
|
|
14
|
-
const accountAddresses =
|
|
15
|
-
.compileMessage()
|
|
24
|
+
const accountAddresses = transactionMessage
|
|
16
25
|
.accountKeys.map((account) => account.toString())
|
|
17
26
|
config['accounts'] = {
|
|
18
27
|
encoding: 'base64',
|
|
@@ -75,3 +84,22 @@ export function filterAccountsByOwner(futureAccountsState, accountAddresses, pub
|
|
|
75
84
|
tokenAccounts,
|
|
76
85
|
}
|
|
77
86
|
}
|
|
87
|
+
|
|
88
|
+
export function buildRawTransaction(signData) {
|
|
89
|
+
// One signature count. This needs to be allocated even though no signature is attached
|
|
90
|
+
const signatureCount = [1]
|
|
91
|
+
const signaturesLength = signatureCount.length + SIGNATURE_LENGTH
|
|
92
|
+
const rawTransactionLength = signData.length + signaturesLength
|
|
93
|
+
|
|
94
|
+
if (rawTransactionLength > PACKET_DATA_SIZE) {
|
|
95
|
+
throw Error(
|
|
96
|
+
`Transaction too large: ${rawTransactionLength} > ${PACKET_DATA_SIZE}`,
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const rawTransaction = Buffer.alloc(rawTransactionLength)
|
|
101
|
+
Buffer.from(signatureCount).copy(rawTransaction)
|
|
102
|
+
signData.copy(rawTransaction, signaturesLength)
|
|
103
|
+
|
|
104
|
+
return rawTransaction
|
|
105
|
+
}
|