@exodus/solana-lib 3.4.2 → 3.5.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/CHANGELOG.md ADDED
@@ -0,0 +1,210 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ ## [3.5.0](https://github.com/ExodusMovement/assets/compare/@exodus/solana-lib@3.4.2...@exodus/solana-lib@3.5.0) (2024-06-19)
7
+
8
+
9
+ ### Features
10
+
11
+ * **solana-lib:** support signing legacy transaction from buffer ([#2604](https://github.com/ExodusMovement/assets/issues/2604)) ([b08a818](https://github.com/ExodusMovement/assets/commit/b08a8187916dc4a874eabb6b29e79014c63f835b))
12
+
13
+
14
+
15
+ ## [3.4.2](https://github.com/ExodusMovement/assets/compare/@exodus/solana-lib@3.4.1...@exodus/solana-lib@3.4.2) (2024-06-06)
16
+
17
+ **Note:** Version bump only for package @exodus/solana-lib
18
+
19
+
20
+
21
+
22
+
23
+ ## [3.4.1](https://github.com/ExodusMovement/assets/compare/@exodus/solana-lib@3.4.0...@exodus/solana-lib@3.4.1) (2024-05-28)
24
+
25
+
26
+ ### Bug Fixes
27
+
28
+ * support using keychain private keys ([#2399](https://github.com/ExodusMovement/assets/issues/2399)) ([b900ad3](https://github.com/ExodusMovement/assets/commit/b900ad3b5bdf363f8c83175a5297333375a27529))
29
+
30
+
31
+
32
+ ## [3.4.0](https://github.com/ExodusMovement/assets/compare/@exodus/solana-lib@3.3.1...@exodus/solana-lib@3.4.0) (2024-05-23)
33
+
34
+
35
+ ### Features
36
+
37
+ * **solana-lib:** recreate a Web3.js transaction if `transactionBuffer` supplied ([#2351](https://github.com/ExodusMovement/assets/issues/2351)) ([8ab56db](https://github.com/ExodusMovement/assets/commit/8ab56dbd120380cd7f89a4954c5d0f765156dbe3))
38
+
39
+
40
+
41
+ ## [3.3.1](https://github.com/ExodusMovement/assets/compare/@exodus/solana-lib@3.3.0...@exodus/solana-lib@3.3.1) (2024-05-15)
42
+
43
+
44
+ ### Bug Fixes
45
+
46
+ * **solana-plugin:** supply a proper Web3 Transaction instance to simulation ([#2288](https://github.com/ExodusMovement/assets/issues/2288)) ([5316cc0](https://github.com/ExodusMovement/assets/commit/5316cc0ce23643da8e9926adfd8e0db904b704e4))
47
+
48
+
49
+
50
+ ## [3.3.0](https://github.com/ExodusMovement/assets/compare/@exodus/solana-lib@3.2.2...@exodus/solana-lib@3.3.0) (2024-05-10)
51
+
52
+
53
+ ### Features
54
+
55
+ * `signatureType` to external signer ([#2244](https://github.com/ExodusMovement/assets/issues/2244)) ([ba0f522](https://github.com/ExodusMovement/assets/commit/ba0f522acd0b0ef744c82405ba9e67d5f90ac9c3))
56
+
57
+
58
+
59
+ ## [3.2.2](https://github.com/ExodusMovement/assets/compare/@exodus/solana-lib@3.2.1...@exodus/solana-lib@3.2.2) (2024-05-08)
60
+
61
+
62
+ ### Bug Fixes
63
+
64
+ * provide `assetName` to createGetKeyIdentifier ([#2191](https://github.com/ExodusMovement/assets/issues/2191)) ([55e5171](https://github.com/ExodusMovement/assets/commit/55e5171b142fd72ff88b645f02f0ad358b93ccf8))
65
+
66
+
67
+
68
+ ## [3.2.1](https://github.com/ExodusMovement/assets/compare/@exodus/solana-lib@3.2.0...@exodus/solana-lib@3.2.1) (2024-04-26)
69
+
70
+
71
+ ### Bug Fixes
72
+
73
+ * handle decode staking tx crash ([#2161](https://github.com/ExodusMovement/assets/issues/2161)) ([970ef7c](https://github.com/ExodusMovement/assets/commit/970ef7ca4abc393826716702c4d4e56d13ee7914))
74
+
75
+
76
+
77
+ ## [3.2.0](https://github.com/ExodusMovement/assets/compare/@exodus/solana-lib@3.1.1...@exodus/solana-lib@3.2.0) (2024-04-24)
78
+
79
+
80
+ ### Features
81
+
82
+ * support external signer for solana message signing ([#2151](https://github.com/ExodusMovement/assets/issues/2151)) ([a58921c](https://github.com/ExodusMovement/assets/commit/a58921c6d2020fd67a99dc4c17129c04e346eb8b))
83
+
84
+
85
+
86
+ ## [3.1.1](https://github.com/ExodusMovement/assets/compare/@exodus/solana-lib@3.1.0...@exodus/solana-lib@3.1.1) (2024-04-22)
87
+
88
+ **Note:** Version bump only for package @exodus/solana-lib
89
+
90
+
91
+
92
+
93
+
94
+ ## [3.1.0](https://github.com/ExodusMovement/assets/compare/@exodus/solana-lib@3.0.1...@exodus/solana-lib@3.1.0) (2024-04-20)
95
+
96
+
97
+ ### Features
98
+
99
+ * add compute budget instruction ([#2006](https://github.com/ExodusMovement/assets/issues/2006)) ([f1479ac](https://github.com/ExodusMovement/assets/commit/f1479aca619370da573f442ef4526e6d21db14d2))
100
+
101
+
102
+
103
+ ## [3.0.1](https://github.com/ExodusMovement/assets/compare/@exodus/solana-lib@3.0.0...@exodus/solana-lib@3.0.1) (2024-04-17)
104
+
105
+ **Note:** Version bump only for package @exodus/solana-lib
106
+
107
+
108
+
109
+
110
+
111
+ ## [3.0.0](https://github.com/ExodusMovement/assets/compare/@exodus/solana-lib@2.4.0...@exodus/solana-lib@3.0.0) (2024-04-12)
112
+
113
+
114
+ ### ⚠ BREAKING CHANGES
115
+
116
+ * **solana:** transaction signing (#2017)
117
+
118
+ ### Bug Fixes
119
+
120
+ * replace serum with fork ([#2037](https://github.com/ExodusMovement/assets/issues/2037)) ([d7fdbae](https://github.com/ExodusMovement/assets/commit/d7fdbae87cfa605afeff8f2b836a5a2839105f78))
121
+ * **solana:** transaction signing ([#2017](https://github.com/ExodusMovement/assets/issues/2017)) ([78393f9](https://github.com/ExodusMovement/assets/commit/78393f96c5102636dab62e1cf0b368475c8b038e))
122
+
123
+
124
+
125
+ ## [2.4.0](https://github.com/ExodusMovement/assets/compare/@exodus/solana-lib@2.3.0...@exodus/solana-lib@2.4.0) (2024-04-08)
126
+
127
+
128
+ ### Features
129
+
130
+ * **solana:** add signMessage ([#1980](https://github.com/ExodusMovement/assets/issues/1980)) ([fd0b28c](https://github.com/ExodusMovement/assets/commit/fd0b28ce0c86249ec8a5d32ee0a3e542513c6d47))
131
+
132
+
133
+
134
+ ## [2.3.0](https://github.com/ExodusMovement/assets/compare/@exodus/solana-lib@2.2.0...@exodus/solana-lib@2.3.0) (2024-04-04)
135
+
136
+
137
+ ### Features
138
+
139
+ * implement helius priority fee ([#1799](https://github.com/ExodusMovement/assets/issues/1799)) ([e681ee7](https://github.com/ExodusMovement/assets/commit/e681ee7f52526bc8a77ab9917d57fb5c2fca2fd4))
140
+
141
+
142
+
143
+ ## [2.2.0](https://github.com/ExodusMovement/assets/compare/@exodus/solana-lib@2.1.0...@exodus/solana-lib@2.2.0) (2024-04-04)
144
+
145
+
146
+ ### Features
147
+
148
+ * add support for external signer for Solana ([#1952](https://github.com/ExodusMovement/assets/issues/1952)) ([70424fe](https://github.com/ExodusMovement/assets/commit/70424fe54c4bcf6be897a182761746b1e02475f3))
149
+
150
+
151
+
152
+ ## [2.1.0](https://github.com/ExodusMovement/assets/compare/@exodus/solana-lib@2.0.0...@exodus/solana-lib@2.1.0) (2024-03-27)
153
+
154
+
155
+ ### Features
156
+
157
+ * add new Solana token 2022 program ([#1808](https://github.com/ExodusMovement/assets/issues/1808)) ([90747bc](https://github.com/ExodusMovement/assets/commit/90747bc97fba0e629a1eaba5878dd06f834b0d72))
158
+
159
+
160
+ ### Bug Fixes
161
+
162
+ * support token-2022 program for metaplex transfer ([#1894](https://github.com/ExodusMovement/assets/issues/1894)) ([31f712a](https://github.com/ExodusMovement/assets/commit/31f712a8fda681969b1c3dbe6f4c5e3d250f3062))
163
+
164
+
165
+
166
+ ## [2.0.0](https://github.com/ExodusMovement/assets/compare/@exodus/solana-lib@1.8.2...@exodus/solana-lib@2.0.0) (2024-03-21)
167
+
168
+
169
+ ### ⚠ BREAKING CHANGES
170
+
171
+ * decouple solana-lib from solana-meta (#1810)
172
+
173
+ ### Features
174
+
175
+ * decouple solana-lib from solana-meta ([#1810](https://github.com/ExodusMovement/assets/issues/1810)) ([50db597](https://github.com/ExodusMovement/assets/commit/50db59734b1e48f8616f5de1ff61bfac356685a3))
176
+
177
+
178
+
179
+ ## [1.8.2](https://github.com/ExodusMovement/assets/compare/@exodus/solana-lib@1.8.1...@exodus/solana-lib@1.8.2) (2024-03-18)
180
+
181
+
182
+ ### Bug Fixes
183
+
184
+ * accurately calculate solana priority fee ([#1777](https://github.com/ExodusMovement/assets/issues/1777)) ([aa72d65](https://github.com/ExodusMovement/assets/commit/aa72d65d0117e7ff418967c019c1f3cb865961eb))
185
+
186
+
187
+
188
+
189
+
190
+ ## [1.8.1](https://github.com/ExodusMovement/assets/compare/@exodus/solana-lib@1.8.0...@exodus/solana-lib@1.8.1) (2024-03-16)
191
+
192
+ **Note:** Version bump only for package @exodus/solana-lib
193
+
194
+
195
+
196
+
197
+
198
+ # [1.8.0](https://github.com/ExodusMovement/assets/compare/@exodus/solana-lib@1.7.5...@exodus/solana-lib@1.8.0) (2024-03-12)
199
+
200
+
201
+ ### Bug Fixes
202
+
203
+ * increase SOL fee boundary check ([#1717](https://github.com/ExodusMovement/assets/issues/1717)) ([6ae954e](https://github.com/ExodusMovement/assets/commit/6ae954e2314acf0a84ea6dea07b89e5bba96e5b1))
204
+ * solana test case ([#1602](https://github.com/ExodusMovement/assets/issues/1602)) ([00b8ddd](https://github.com/ExodusMovement/assets/commit/00b8ddd7726d50bbfe227ddacced7e388c2af283))
205
+
206
+
207
+ ### Features
208
+
209
+ * add SOL prioritization fee ([#1682](https://github.com/ExodusMovement/assets/issues/1682)) ([f199ef5](https://github.com/ExodusMovement/assets/commit/f199ef52dc9047768c5a8f4ccb75cd5f82a13e2e))
210
+ * **solana:** migrate some implementations and remove `@exodus/solana-spl-tokan` usage. ([#1669](https://github.com/ExodusMovement/assets/issues/1669)) ([ee75e1f](https://github.com/ExodusMovement/assets/commit/ee75e1fbf5c276aafc91260dee9ad6e44e5c8b8b))
package/package.json CHANGED
@@ -1,20 +1,21 @@
1
1
  {
2
2
  "name": "@exodus/solana-lib",
3
- "version": "3.4.2",
3
+ "version": "3.5.0",
4
4
  "description": "Exodus internal Solana low-level library",
5
5
  "main": "src/index.js",
6
6
  "files": [
7
- "src/",
7
+ "src",
8
+ "CHANGELOG.md",
8
9
  "!src/**/__tests__"
9
10
  ],
10
- "author": "Exodus",
11
+ "author": "Exodus Movement, Inc.",
11
12
  "license": "ISC",
12
13
  "publishConfig": {
13
14
  "access": "restricted"
14
15
  },
15
16
  "scripts": {
16
17
  "test": "run -T jest",
17
- "lint": "run -T eslint ./src",
18
+ "lint": "run -T eslint .",
18
19
  "lint:fix": "yarn lint --fix"
19
20
  },
20
21
  "dependencies": {
@@ -23,7 +24,7 @@
23
24
  "@exodus/currency": "^2.3.2",
24
25
  "@exodus/key-utils": "^3.1.0",
25
26
  "@exodus/models": "^10.1.0",
26
- "@exodus/project-serum-serum": "0.13.64-exodus.0",
27
+ "@exodus/project-serum-serum": "^0.13.64-exodus.0",
27
28
  "@exodus/solana-web3.js": "^1.63.1-exodus.3",
28
29
  "bn.js": "^5.2.1",
29
30
  "borsh": "^0.7.0",
@@ -40,5 +41,13 @@
40
41
  "@solana/web3.js": "^1.90.0",
41
42
  "bip39": "^2.6.0"
42
43
  },
43
- "gitHead": "9d24eb58422692fc1acdcb834061d02b2632801d"
44
+ "bugs": {
45
+ "url": "https://github.com/ExodusMovement/assets/issues?q=is%3Aissue+is%3Aopen+label%3Asolana-lib"
46
+ },
47
+ "homepage": "https://github.com/ExodusMovement/assets/tree/master/solana/solana-lib",
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "git+https://github.com/ExodusMovement/assets.git"
51
+ },
52
+ "gitHead": "61b8ec6544e7a62a774f0e74e6a1b623371742fa"
44
53
  }
package/src/tx/common.js CHANGED
@@ -22,16 +22,8 @@ export function getTxId(tx) {
22
22
  }
23
23
 
24
24
  function getFirstSignature(tx) {
25
- if (isVersionedTransaction(tx)) {
26
- // Versioned
27
- if (tx.signatures.length > 0) {
28
- return tx.signatures[0]
29
- }
30
- } else {
31
- // Legacy
32
- if (tx.signatures.length > 0) {
33
- return tx.signatures[0].signature
34
- }
25
+ if (tx.signatures.length > 0) {
26
+ return tx.signatures[0]
35
27
  }
36
28
 
37
29
  return null
@@ -20,10 +20,14 @@ const addComputeBudgetToTransaction = ({ transaction, computeUnits }) => {
20
20
  transaction.add(computeBudgetInstruction)
21
21
  }
22
22
 
23
+ const deserializeTransactionBytes = (wireTransactionBuffer) => {
24
+ return VersionedTransaction.deserialize(Uint8Array.from(wireTransactionBuffer))
25
+ }
26
+
23
27
  /**
24
28
  * Prepares the transaction to be signed (exodus & ledger).
25
29
  * @param {UnsignedTx} unsignedTx
26
- * @returns a Solana Web3.js Transaction object
30
+ * @returns a Solana Web3.js VersionedTransaction object (supports both Legacy & Versioned transactions)
27
31
  */
28
32
  export function prepareForSigning(unsignedTx) {
29
33
  const {
@@ -37,7 +41,7 @@ export function prepareForSigning(unsignedTx) {
37
41
 
38
42
  // Recreate a Web3.js Transaction instance if the buffer provided.
39
43
  if (transactionBuffer) {
40
- return VersionedTransaction.deserialize(transactionBuffer)
44
+ return deserializeTransactionBytes(transactionBuffer)
41
45
  }
42
46
 
43
47
  if (!transaction) {
@@ -54,31 +58,19 @@ export function prepareForSigning(unsignedTx) {
54
58
 
55
59
  const txData = { ...unsignedTx.txData, address, amount, fee }
56
60
 
57
- const transaction = createTx({ txData, method })
58
-
59
- if (txData.priorityFee) {
60
- addPriorityFeeToTransaction({
61
- transaction,
62
- priorityFee: txData.priorityFee,
63
- })
64
- }
65
-
66
- if (txData.computeUnits) {
67
- addComputeBudgetToTransaction({ transaction, computeUnits: txData.computeUnits })
68
- }
69
-
70
- if (!transaction.feePayer) {
71
- transaction.feePayer = new PublicKey(from)
72
- }
73
-
74
- return transaction
61
+ const legacyTransaction = createTx({ txData, method, from })
62
+ return VersionedTransaction.deserialize(
63
+ legacyTransaction.serialize({ requireAllSignatures: false, verifySignatures: false })
64
+ )
75
65
  }
76
66
 
77
67
  // unsignedTx contained a transaction in web3.js format
78
- return transaction
68
+ return VersionedTransaction.deserialize(
69
+ transaction.serialize({ requireAllSignatures: false, verifySignatures: false })
70
+ )
79
71
  }
80
72
 
81
- const createTx = ({ txData, method }) => {
73
+ const createTx = ({ txData, method, from }) => {
82
74
  let tx
83
75
  switch (method) {
84
76
  case 'delegate':
@@ -113,6 +105,31 @@ const createTx = ({ txData, method }) => {
113
105
  break
114
106
  }
115
107
 
108
+ if (txData.priorityFee) {
109
+ addPriorityFeeToTransaction({
110
+ transaction: tx,
111
+ priorityFee: txData.priorityFee,
112
+ })
113
+ }
114
+
115
+ if (txData.computeUnits) {
116
+ addComputeBudgetToTransaction({ transaction: tx, computeUnits: txData.computeUnits })
117
+ }
118
+
119
+ const publicKey = new PublicKey(from)
120
+ if (!tx.feePayer) {
121
+ tx.feePayer = publicKey
122
+ }
123
+
124
+ if (tx.signatures.length !== tx.compileMessage().header.numRequiredSignatures) {
125
+ // Some transactions that we construct internally are technically not complete.
126
+ // They don't contain the empty signature slot for the public key.
127
+ tx.signatures.push({
128
+ publicKey,
129
+ signature: null,
130
+ })
131
+ }
132
+
116
133
  return tx
117
134
  }
118
135
 
@@ -2,7 +2,7 @@ import assert from 'minimalistic-assert'
2
2
 
3
3
  import { prepareForSigning } from './prepare-for-signing'
4
4
  import { PublicKey } from '../vendor'
5
- import { isVersionedTransaction, isLegacyTransaction, extractTransaction } from './common'
5
+ import { extractTransaction } from './common'
6
6
 
7
7
  export async function signHardware({ unsignedTx, hardwareDevice, accountIndex }) {
8
8
  assert(hardwareDevice, 'expected hardwareDevice to be defined')
@@ -19,9 +19,7 @@ const signWithHardwareWallet = async ({ tx, hardwareDevice, accountIndex }) => {
19
19
  assert(hardwareDevice, `hardwareDevice required`)
20
20
  assert(Number.isInteger(accountIndex), `accountIndex required`)
21
21
 
22
- const messageToSign = isVersionedTransaction(tx)
23
- ? tx.message.serialize()
24
- : tx.compileMessage().serialize()
22
+ const messageToSign = tx.message.serialize()
25
23
 
26
24
  return hardwareDevice.signTransaction({
27
25
  assetName: 'solana',
@@ -31,24 +29,6 @@ const signWithHardwareWallet = async ({ tx, hardwareDevice, accountIndex }) => {
31
29
  }
32
30
 
33
31
  const applySignatures = ({ tx, signatures }) => {
34
- if (isLegacyTransaction(tx)) {
35
- signatures.forEach(({ publicKey: publicKeyBuffer }) => {
36
- const publicKey = new PublicKey(publicKeyBuffer)
37
- // Some transactions that we construct internally are technically not complete.
38
- // They don't contain the empty signature slot for the public key.
39
- const foundEmptySignatureSlot = tx.signatures.find(({ publicKey: pubKey }) =>
40
- pubKey.equals(publicKey)
41
- )
42
- if (!foundEmptySignatureSlot) {
43
- // We could use `setSigners` but maybe this is more robust?
44
- tx.signatures.push({
45
- publicKey,
46
- signature: null,
47
- })
48
- }
49
- })
50
- }
51
-
52
32
  signatures.forEach(({ publicKey, signature }) => {
53
33
  tx.addSignature(new PublicKey(publicKey), signature)
54
34
  })
@@ -5,7 +5,7 @@ import bs58 from 'bs58'
5
5
  import { prepareForSigning } from './prepare-for-signing'
6
6
  import { getKeyPairFromPrivateKey } from '../keypair'
7
7
  import { PublicKey } from '../vendor'
8
- import { extractTransaction, isVersionedTransaction } from './common'
8
+ import { extractTransaction } from './common'
9
9
 
10
10
  /**
11
11
  *
@@ -38,44 +38,10 @@ export async function signUnsignedTx(unsignedTx, privateKey) {
38
38
  return extractTransaction({ tx })
39
39
  }
40
40
 
41
- // Some transactions that we construct internally are technically not complete.
42
- // They don't contain the empty signature slot for the public key.
43
- export const fillTransactionWithEmptySignatureSlot = ({ transaction, publicKey }) => {
44
- const foundEmptySignatureSlot = transaction.signatures.find(({ publicKey: _publicKey }) =>
45
- _publicKey.equals(publicKey)
46
- )
47
- if (!foundEmptySignatureSlot) {
48
- // We could use `setSigners` but maybe this is more robust?
49
- transaction.signatures.push({
50
- publicKey,
51
- signature: null,
52
- })
53
- }
54
- }
55
-
56
41
  // Signs plain tx.
57
42
  const _signTx = async ({ tx, signer }) => {
58
43
  const publicKey = new PublicKey(bs58.encode(Buffer.from(await signer.getPublicKey())))
59
-
60
- if (isVersionedTransaction(tx)) {
61
- // VersionedTransaction
62
- return _signVersionedTransaction({ tx, signer, publicKey })
63
- }
64
-
65
- // Legacy Transactions
66
- fillTransactionWithEmptySignatureSlot({ transaction: tx, publicKey })
67
-
68
- return _signLegacyTransaction({ tx, signer, publicKey })
69
- }
70
-
71
- const _signVersionedTransaction = async ({ tx, signer, publicKey }) => {
72
44
  const messageData = tx.message.serialize()
73
45
  const signature = await signer.sign({ data: messageData, signatureType: 'ed25519' })
74
46
  tx.addSignature(publicKey, signature)
75
47
  }
76
-
77
- const _signLegacyTransaction = async ({ tx, signer, publicKey }) => {
78
- const messageData = tx.compileMessage().serialize()
79
- const signature = await signer.sign({ data: messageData, signatureType: 'ed25519' })
80
- tx.addSignature(publicKey, signature)
81
- }