@exodus/solana-lib 1.4.0 → 1.4.1
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/solana-lib",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "Exodus internal Solana low-level library",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"lodash": "^4.17.11",
|
|
30
30
|
"tweetnacl": "^1.0.3"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "cafda9efb741487bae7db4c3187c8b69d3553151"
|
|
33
33
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@exodus/solana-spl-token'
|
|
2
2
|
import { MARKETS, TokenInstructions } from '@project-serum/serum'
|
|
3
|
+
import * as BufferLayout from '@exodus/buffer-layout'
|
|
4
|
+
|
|
3
5
|
import {
|
|
4
6
|
Message,
|
|
5
7
|
SystemInstruction,
|
|
@@ -18,6 +20,13 @@ type DecodedInstruction = {
|
|
|
18
20
|
},
|
|
19
21
|
}
|
|
20
22
|
|
|
23
|
+
const INSTRUCTION_LAYOUT = BufferLayout.union(BufferLayout.u8('instruction'))
|
|
24
|
+
INSTRUCTION_LAYOUT.addVariant(
|
|
25
|
+
12,
|
|
26
|
+
BufferLayout.struct([BufferLayout.nu64('amount'), BufferLayout.u8('decimals')]),
|
|
27
|
+
'transferChecked'
|
|
28
|
+
)
|
|
29
|
+
|
|
21
30
|
export const INSTRUCTION_TITLE_BY_TYPE = {
|
|
22
31
|
approve: 'Approve',
|
|
23
32
|
cancelOrder: 'Cancel Order',
|
|
@@ -43,6 +52,7 @@ export const INSTRUCTION_TITLE_BY_TYPE = {
|
|
|
43
52
|
systemAuthorizeNonceAccount: 'Authorize Nonce Account',
|
|
44
53
|
systemWithdrawNonceAccount: 'Withdraw Nonce Account',
|
|
45
54
|
transfer: 'Transfer Token',
|
|
55
|
+
transferChecked: 'Transfer Token Checked',
|
|
46
56
|
unknown: 'Unknown',
|
|
47
57
|
}
|
|
48
58
|
|
|
@@ -56,7 +66,7 @@ class InstructionKeys {
|
|
|
56
66
|
}
|
|
57
67
|
}
|
|
58
68
|
|
|
59
|
-
function getTransactionInstructionsFromMessage(message: Message): TransactionInstruction[] {
|
|
69
|
+
export function getTransactionInstructionsFromMessage(message: Message): TransactionInstruction[] {
|
|
60
70
|
const { accountKeys, instructions } = message
|
|
61
71
|
return instructions.map((instruction) => {
|
|
62
72
|
const { accounts, data, programIdIndex } = instruction
|
|
@@ -110,10 +120,17 @@ function decodeTokenInstructionData(data: Buffer) {
|
|
|
110
120
|
}
|
|
111
121
|
}
|
|
112
122
|
|
|
123
|
+
// Type TransferChecked
|
|
124
|
+
if (data.length > 1 && data[0] === 12) {
|
|
125
|
+
return INSTRUCTION_LAYOUT.decode(data)
|
|
126
|
+
}
|
|
127
|
+
|
|
113
128
|
return TokenInstructions.decodeTokenInstructionData(data)
|
|
114
129
|
}
|
|
115
130
|
|
|
116
|
-
function decodeTokenProgramInstruction(
|
|
131
|
+
export function decodeTokenProgramInstruction(
|
|
132
|
+
instruction: TransactionInstruction
|
|
133
|
+
): DecodedInstruction {
|
|
117
134
|
const decodedInstructionData = decodeTokenInstructionData(instruction.data)
|
|
118
135
|
|
|
119
136
|
if (!decodedInstructionData || Object.keys(decodedInstructionData).length > 1) {
|
|
@@ -202,10 +219,18 @@ export function decodeTransactionInstructions(
|
|
|
202
219
|
transactionMessages: Message[]
|
|
203
220
|
): DecodedInstruction[] {
|
|
204
221
|
const transactionInstructions = transactionMessages.reduce(
|
|
205
|
-
(prevInstructions: TransactionInstruction[], message: Message) =>
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
222
|
+
(prevInstructions: TransactionInstruction[], message: Message) => {
|
|
223
|
+
let instructions
|
|
224
|
+
const isTransactionMessage =
|
|
225
|
+
message.instructions.length > 0 && message.instructions[0].programId !== undefined
|
|
226
|
+
if (isTransactionMessage) {
|
|
227
|
+
instructions = message.instructions
|
|
228
|
+
} else {
|
|
229
|
+
instructions = getTransactionInstructionsFromMessage(message)
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return [...prevInstructions, ...instructions]
|
|
233
|
+
},
|
|
209
234
|
[]
|
|
210
235
|
)
|
|
211
236
|
return transactionInstructions.map((instruction) => {
|