@exodus/solana-lib 3.20.1 → 3.21.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/CHANGELOG.md +18 -0
- package/package.json +2 -2
- package/src/tx/index.js +1 -0
- package/src/tx/instruction-utils.js +66 -0
- package/src/tx/parse-tx-buffer.js +12 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,24 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [3.21.1](https://github.com/ExodusMovement/assets/compare/@exodus/solana-lib@3.21.0...@exodus/solana-lib@3.21.1) (2026-03-12)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @exodus/solana-lib
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [3.21.0](https://github.com/ExodusMovement/assets/compare/@exodus/solana-lib@3.20.1...@exodus/solana-lib@3.21.0) (2026-03-10)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
* feat: Solana add sponsored fee-payer tagging and instruction helpers (#7522)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
6
24
|
## [3.20.1](https://github.com/ExodusMovement/assets/compare/@exodus/solana-lib@3.20.0...@exodus/solana-lib@3.20.1) (2026-02-03)
|
|
7
25
|
|
|
8
26
|
**Note:** Version bump only for package @exodus/solana-lib
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/solana-lib",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.21.1",
|
|
4
4
|
"description": "Solana utils, such as for cryptography, address encoding/decoding, transaction building, etc.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"type": "git",
|
|
49
49
|
"url": "git+https://github.com/ExodusMovement/assets.git"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "1c57290eed9f84bfd28f25948796f52f94e8a52f"
|
|
52
52
|
}
|
package/src/tx/index.js
CHANGED
|
@@ -9,4 +9,5 @@ export * from './sign-hardware.js'
|
|
|
9
9
|
export * from './prepare-for-signing.js'
|
|
10
10
|
export * from './verify-only-fee-payer-changed.js'
|
|
11
11
|
export * from './parse-tx-buffer.js'
|
|
12
|
+
export * from './instruction-utils.js'
|
|
12
13
|
export { transactionToBase58, deserializeTransaction } from './common.js'
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {
|
|
2
|
+
COMPUTE_BUDGET_PROGRAM_ID,
|
|
3
|
+
SYSTEM_PROGRAM_ID,
|
|
4
|
+
TOKEN_2022_PROGRAM_ID,
|
|
5
|
+
TOKEN_PROGRAM_ID,
|
|
6
|
+
} from '../constants.js'
|
|
7
|
+
import { TOKEN_INSTRUCTION_LAYOUTS, TRANSFER_FEE_SUB_INSTRUCTIONS } from '../vendor/index.js'
|
|
8
|
+
import { toBuffer } from '../vendor/utils/to-buffer.js'
|
|
9
|
+
|
|
10
|
+
export function isTokenProgramInstruction(instruction) {
|
|
11
|
+
const programId = instruction?.programId
|
|
12
|
+
if (!programId) return false
|
|
13
|
+
return programId.equals(TOKEN_PROGRAM_ID) || programId.equals(TOKEN_2022_PROGRAM_ID)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function isSystemTransferInstruction(instruction) {
|
|
17
|
+
const programId = instruction?.programId
|
|
18
|
+
if (!programId || !programId.equals(SYSTEM_PROGRAM_ID)) return false
|
|
19
|
+
if (!Array.isArray(instruction.keys) || instruction.keys.length !== 2) return false
|
|
20
|
+
if (!instruction.data) return false
|
|
21
|
+
try {
|
|
22
|
+
const buffer = toBuffer(instruction.data)
|
|
23
|
+
if (buffer.length < 12) return false
|
|
24
|
+
return buffer.readUInt32LE(0) === 2
|
|
25
|
+
} catch {
|
|
26
|
+
return false
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function isComputeBudgetInstruction(instruction) {
|
|
31
|
+
const programId = instruction?.programId
|
|
32
|
+
if (!programId) return false
|
|
33
|
+
return programId.equals(COMPUTE_BUDGET_PROGRAM_ID)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function isSetAuthorityInstruction(instruction) {
|
|
37
|
+
if (!isTokenProgramInstruction(instruction)) return false
|
|
38
|
+
if (!instruction.data) return false
|
|
39
|
+
const buffer = toBuffer(instruction.data)
|
|
40
|
+
return buffer.length > 0 && buffer[0] === TOKEN_INSTRUCTION_LAYOUTS.SetAuthority.index
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function isTransferInstruction(instruction) {
|
|
44
|
+
if (!isTokenProgramInstruction(instruction)) return false
|
|
45
|
+
if (!instruction.data) return false
|
|
46
|
+
const buffer = toBuffer(instruction.data)
|
|
47
|
+
return buffer.length > 0 && buffer[0] === TOKEN_INSTRUCTION_LAYOUTS.Transfer.index
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function isTransferCheckedInstruction(instruction) {
|
|
51
|
+
if (!isTokenProgramInstruction(instruction)) return false
|
|
52
|
+
if (!instruction.data) return false
|
|
53
|
+
const buffer = toBuffer(instruction.data)
|
|
54
|
+
return buffer.length > 0 && buffer[0] === TOKEN_INSTRUCTION_LAYOUTS.TransferChecked.index
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function isTransferCheckedWithFeeInstruction(instruction) {
|
|
58
|
+
if (!isTokenProgramInstruction(instruction)) return false
|
|
59
|
+
if (!instruction.data) return false
|
|
60
|
+
const buffer = toBuffer(instruction.data)
|
|
61
|
+
return (
|
|
62
|
+
buffer.length >= 2 &&
|
|
63
|
+
buffer[0] === TOKEN_INSTRUCTION_LAYOUTS.TransferFeeExtension.index &&
|
|
64
|
+
buffer[1] === TRANSFER_FEE_SUB_INSTRUCTIONS.TransferCheckedWithFee
|
|
65
|
+
)
|
|
66
|
+
}
|
|
@@ -40,7 +40,7 @@ function getStakedAmountFromCreateWithSeed(stakeAddress, instructions, accountKe
|
|
|
40
40
|
|
|
41
41
|
// TODO: Unify with parseTransaction in solana-api and use there as well?
|
|
42
42
|
// TODO: add support for swap instructions
|
|
43
|
-
export async function parseTxBuffer(buffer, api) {
|
|
43
|
+
export async function parseTxBuffer(buffer, api, options = Object.create(null)) {
|
|
44
44
|
const transaction = deserializeTransaction(buffer)
|
|
45
45
|
const { message } = transaction
|
|
46
46
|
|
|
@@ -51,6 +51,10 @@ export async function parseTxBuffer(buffer, api) {
|
|
|
51
51
|
throw new TypeError('Invalid transaction structure')
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
const feePayerAddress = accountKeys[0]?.toBase58()
|
|
55
|
+
const { sponsors } = options
|
|
56
|
+
const isSponsoredBy = sponsors?.[feePayerAddress]
|
|
57
|
+
|
|
54
58
|
const decodedEntries = []
|
|
55
59
|
|
|
56
60
|
for (const [index, instruction] of instructions.entries()) {
|
|
@@ -75,7 +79,13 @@ export async function parseTxBuffer(buffer, api) {
|
|
|
75
79
|
api,
|
|
76
80
|
instructions,
|
|
77
81
|
})
|
|
78
|
-
if (parsed)
|
|
82
|
+
if (parsed) {
|
|
83
|
+
parsedInstructions.push({
|
|
84
|
+
...parsed,
|
|
85
|
+
feePayerAddress,
|
|
86
|
+
...(isSponsoredBy && { isSponsoredBy }),
|
|
87
|
+
})
|
|
88
|
+
}
|
|
79
89
|
}
|
|
80
90
|
|
|
81
91
|
if (parsedInstructions.length === 0) {
|