@exodus/solana-lib 1.4.3 → 1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/solana-lib",
3
- "version": "1.4.3",
3
+ "version": "1.5.0",
4
4
  "description": "Exodus internal Solana low-level library",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -13,13 +13,11 @@
13
13
  "access": "restricted"
14
14
  },
15
15
  "dependencies": {
16
- "@exodus/asset-lib": "^3.6.2",
17
- "@exodus/assets": "^8.0.68",
18
- "@exodus/assets-base": "^8.0.139",
16
+ "@exodus/asset-lib": "^3.7.1",
17
+ "@exodus/assets": "^8.0.74",
19
18
  "@exodus/buffer-layout": "^1.2.0-exodus1",
20
- "@exodus/models": "^8.7.2",
19
+ "@exodus/models": "^8.10.4",
21
20
  "@exodus/solana-spl-token": "0.1.8-exodus.1",
22
- "@exodus/web3-solana-utils": "^0.14.0",
23
21
  "@project-serum/serum": "0.13.64",
24
22
  "@solana/web3.js": "1.31.0",
25
23
  "bn.js": "^4.11.0",
@@ -29,5 +27,5 @@
29
27
  "lodash": "^4.17.11",
30
28
  "tweetnacl": "^1.0.3"
31
29
  },
32
- "gitHead": "78b7f5c6d314b393f038848ef5b5815d46b8dd35"
30
+ "gitHead": "fe989a47ba9278f5fe797f9b01d8bc93fb53467a"
33
31
  }
@@ -1,10 +1,11 @@
1
1
  import { FeeData } from '@exodus/asset-lib'
2
+ import assets from '@exodus/assets'
2
3
 
3
- export default new FeeData(
4
- {
4
+ export default new FeeData({
5
+ config: {
5
6
  fee: '0.000005 SOL',
6
7
  fuelThreshold: '0.000015 SOL',
7
8
  },
8
- 'fee',
9
- 'solana'
10
- )
9
+ mainKey: 'fee',
10
+ currency: assets.solana.currency,
11
+ })
package/src/index.js CHANGED
@@ -1,6 +1,5 @@
1
1
  // @flow
2
2
 
3
- export { buildRawTransaction } from '@exodus/web3-solana-utils'
4
3
  export * from './constants'
5
4
  export * from './encode'
6
5
  export * from './keypair'
@@ -0,0 +1,62 @@
1
+ import * as nacl from 'tweetnacl'
2
+ import { PACKET_DATA_SIZE } from '@solana/web3.js'
3
+
4
+ // Copied from:
5
+ // https://github.com/solana-labs/solana-web3.js/blob/42612c936d8d4ddbcb09dbb73db9e1aeaf6d8764/src/util/shortvec-encoding.ts#L15-L28.
6
+ function encodeLength(bytes: number[], length: number) {
7
+ let remainingLength = length
8
+
9
+ for (;;) {
10
+ let element = remainingLength & 0x7f
11
+
12
+ remainingLength >>= 7
13
+ if (remainingLength === 0) {
14
+ bytes.push(element)
15
+ break
16
+ }
17
+
18
+ element |= 0x80
19
+ bytes.push(element)
20
+ }
21
+ }
22
+
23
+ // As per:
24
+ // https://github.com/solana-labs/solana-web3.js/blob/61433de0d39686c6ad4f0b3cb5b95a68a058aa04/src/transaction.ts#L682
25
+ const MAX_SIGNATURES = 255
26
+
27
+ export const SIGNATURE_LENGTH = nacl.sign.signatureLength
28
+
29
+ export function buildRawTransaction(signData: Buffer, signatures: (Uint8Array | null)[]) {
30
+ const signatureCount: number[] = []
31
+ encodeLength(signatureCount, signatures.length)
32
+
33
+ const signaturesLength = signatureCount.length + signatures.length * SIGNATURE_LENGTH
34
+ const rawTransactionLength = signData.length + signaturesLength
35
+
36
+ if (signatures.length > MAX_SIGNATURES) {
37
+ throw Error(`Too many signatures: ${signatures.length} > ${MAX_SIGNATURES}`)
38
+ }
39
+
40
+ if (rawTransactionLength > PACKET_DATA_SIZE) {
41
+ throw Error(`Transaction too large: ${rawTransactionLength} > ${PACKET_DATA_SIZE}`)
42
+ }
43
+
44
+ const rawTransaction = Buffer.alloc(rawTransactionLength)
45
+ Buffer.from(signatureCount).copy(rawTransaction)
46
+
47
+ signatures.forEach((signature, index) => {
48
+ if (signature === null) {
49
+ return
50
+ }
51
+
52
+ if (signature.length !== SIGNATURE_LENGTH) {
53
+ throw Error('Invalid signature length')
54
+ }
55
+
56
+ Buffer.from(signature).copy(rawTransaction, signatureCount.length + index * SIGNATURE_LENGTH)
57
+ })
58
+
59
+ signData.copy(rawTransaction, signaturesLength)
60
+
61
+ return rawTransaction
62
+ }
package/src/tx/index.js CHANGED
@@ -4,4 +4,5 @@ export * from './create-unsigned-tx'
4
4
  export * from './create-and-sign-tx'
5
5
  export * from './simulate-and-sign-tx'
6
6
  export * from './decode-tx-instructions'
7
+ export * from './build-raw-transaction'
7
8
  export { default as signMessage } from './sign-message'