@exodus/solana-lib 1.3.13 → 1.3.15

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.3.13",
3
+ "version": "1.3.15",
4
4
  "description": "Exodus internal Solana low-level library",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -13,7 +13,7 @@
13
13
  "access": "restricted"
14
14
  },
15
15
  "dependencies": {
16
- "@exodus/asset-lib": "^3.6.0",
16
+ "@exodus/asset-lib": "^3.6.2",
17
17
  "@exodus/assets": "^8.0.68",
18
18
  "@exodus/assets-base": "^8.0.139",
19
19
  "@exodus/buffer-layout": "^1.2.0-exodus1",
@@ -29,5 +29,5 @@
29
29
  "lodash": "^4.17.11",
30
30
  "tweetnacl": "^1.0.3"
31
31
  },
32
- "gitHead": "12104775b7a98f110b78e928321ca0d530757d88"
32
+ "gitHead": "3c0551a25d29f31be43d522e742d5754cd7deb5f"
33
33
  }
@@ -1,3 +1,4 @@
1
+ import { merge } from 'lodash'
1
2
  import assets from '@exodus/assets'
2
3
  import type { UnsignedTransaction, SignedTransaction } from '@exodus/models/lib/types'
3
4
  import { Transaction } from '../'
@@ -6,118 +7,42 @@ export function signUnsignedTx(
6
7
  unsignedTx: UnsignedTransaction,
7
8
  privateKey: Buffer
8
9
  ): SignedTransaction {
9
- const {
10
- from,
11
- to,
12
- amount: unitAmount,
13
- recentBlockhash,
14
- // tokens related
15
- tokenMintAddress,
16
- destinationAddressType,
17
- isAssociatedTokenAccountActive,
18
- fromTokenAddresses,
19
- // staking related
20
- stakeAddresses,
21
- method,
22
- seed,
23
- pool,
24
- // MagicEden escrow/related:
25
- initializerAddress,
26
- initializerDepositTokenAddress,
27
- takerAmount,
28
- escrowAddress,
29
- escrowBump,
30
- pdaAddress,
31
- takerAddress,
32
- expectedTakerAmount,
33
- expectedMintAddress,
34
- metadataAddress,
35
- creators,
36
- // Wallet Connect
37
- instructions,
38
- feePayer,
39
- } = unsignedTx.txData
10
+ const { amount: unitAmount, from, method } = unsignedTx.txData
40
11
 
41
12
  const asset = assets.solana
42
13
 
43
14
  const address = from
44
15
  const amount = unitAmount ? asset.currency.baseUnit(unitAmount).toNumber() : unitAmount
45
16
 
17
+ const args = merge(unsignedTx.txData, {
18
+ asset,
19
+ address,
20
+ amount,
21
+ })
46
22
  let tx
47
23
  switch (method) {
48
24
  case 'delegate':
49
- tx = Transaction.createStakeAccountTransaction({
50
- address,
51
- amount,
52
- recentBlockhash,
53
- seed,
54
- pool,
55
- })
25
+ tx = createDelegateTransaction(args)
56
26
  break
57
27
  case 'undelegate':
58
- tx = Transaction.undelegate({
59
- address,
60
- stakeAddresses,
61
- recentBlockhash,
62
- })
28
+ tx = createUndelegateTransaction(args)
63
29
  break
64
30
  case 'withdraw':
65
- tx = Transaction.withdraw({
66
- address,
67
- stakeAddresses,
68
- amount,
69
- recentBlockhash,
70
- })
31
+ tx = createWithdrawTransaction(args)
71
32
  break
72
33
  case 'initializeEscrow': {
73
- tx = Transaction.magicEdenInitializeEscrow({
74
- initializerAddress,
75
- initializerDepositTokenAddress,
76
- escrowBump,
77
- escrowAddress,
78
- takerAmount,
79
- recentBlockhash,
80
- })
81
-
34
+ tx = createMagicEdenInitializeEscrowTransaction(args)
82
35
  break
83
36
  }
84
37
  case 'cancelEscrow':
85
- tx = Transaction.magicEdenCancelEscrow({
86
- initializerAddress,
87
- initializerDepositTokenAddress,
88
- escrowAddress,
89
- pdaAddress,
90
- recentBlockhash,
91
- })
38
+ tx = createMagicEdenCancelEscrowTransaction(args)
92
39
  break
93
40
  case 'exchange':
94
- tx = Transaction.magicEdenExchange({
95
- expectedTakerAmount,
96
- expectedMintAddress,
97
- takerAddress,
98
- initializerAddress,
99
- initializerDepositTokenAddress,
100
- escrowAddress,
101
- pdaAddress,
102
- metadataAddress,
103
- creators,
104
- recentBlockhash,
105
- })
41
+ tx = createMagicEdenExchangeTransaction(args)
106
42
  break
107
43
  default:
108
44
  // SOL and Token tx
109
- tx = new Transaction({
110
- from,
111
- to,
112
- amount,
113
- recentBlockhash,
114
- tokenMintAddress,
115
- destinationAddressType,
116
- isAssociatedTokenAccountActive,
117
- fromTokenAddresses,
118
- instructions,
119
- feePayer,
120
- })
45
+ tx = createTokenTransaction(args)
121
46
  break
122
47
  }
123
48
 
@@ -128,3 +53,109 @@ export function signUnsignedTx(
128
53
 
129
54
  return { txId, rawTx }
130
55
  }
56
+
57
+ const createDelegateTransaction = ({ address, amount, pool, recentBlockhash, seed }) =>
58
+ Transaction.createStakeAccountTransaction({
59
+ address,
60
+ amount,
61
+ recentBlockhash,
62
+ seed,
63
+ pool,
64
+ })
65
+
66
+ const createUndelegateTransaction = ({ address, recentBlockhash, stakeAddresses }) =>
67
+ Transaction.undelegate({
68
+ address,
69
+ recentBlockhash,
70
+ stakeAddresses,
71
+ })
72
+
73
+ const createWithdrawTransaction = ({ address, amount, recentBlockhash, stakeAddresses }) =>
74
+ Transaction.withdraw({
75
+ address,
76
+ amount,
77
+ recentBlockhash,
78
+ stakeAddresses,
79
+ })
80
+
81
+ const createMagicEdenInitializeEscrowTransaction = ({
82
+ escrowAddress,
83
+ escrowBump,
84
+ initializerDepositTokenAddress,
85
+ recentBlockhash,
86
+ takerAmount,
87
+ initializerAddress,
88
+ }) =>
89
+ Transaction.magicEdenInitializeEscrow({
90
+ escrowAddress,
91
+ escrowBump,
92
+ initializerAddress,
93
+ initializerDepositTokenAddress,
94
+ recentBlockhash,
95
+ takerAmount,
96
+ })
97
+
98
+ const createMagicEdenCancelEscrowTransaction = ({
99
+ escrowAddress,
100
+ initializerAddress,
101
+ initializerDepositTokenAddress,
102
+ pdaAddress,
103
+ recentBlockhash,
104
+ }) =>
105
+ Transaction.magicEdenCancelEscrow({
106
+ escrowAddress,
107
+ initializerAddress,
108
+ initializerDepositTokenAddress,
109
+ pdaAddress,
110
+ recentBlockhash,
111
+ })
112
+
113
+ const createMagicEdenExchangeTransaction = ({
114
+ creators,
115
+ escrowAddress,
116
+ expectedMintAddress,
117
+ expectedTakerAmount,
118
+ initializerAddress,
119
+ initializerDepositTokenAddress,
120
+ metadataAddress,
121
+ pdaAddress,
122
+ recentBlockhash,
123
+ takerAddress,
124
+ }) =>
125
+ Transaction.magicEdenExchange({
126
+ creators,
127
+ escrowAddress,
128
+ expectedMintAddress,
129
+ expectedTakerAmount,
130
+ initializerAddress,
131
+ initializerDepositTokenAddress,
132
+ metadataAddress,
133
+ pdaAddress,
134
+ recentBlockhash,
135
+ takerAddress,
136
+ })
137
+
138
+ const createTokenTransaction = ({
139
+ amount,
140
+ destinationAddressType,
141
+ feePayer,
142
+ from,
143
+ fromTokenAddresses,
144
+ instructions,
145
+ isAssociatedTokenAccountActive,
146
+ recentBlockhash,
147
+ to,
148
+ tokenMintAddress,
149
+ }) =>
150
+ new Transaction({
151
+ amount,
152
+ destinationAddressType,
153
+ feePayer,
154
+ from,
155
+ fromTokenAddresses,
156
+ instructions,
157
+ isAssociatedTokenAccountActive,
158
+ recentBlockhash,
159
+ to,
160
+ tokenMintAddress,
161
+ })
@@ -262,10 +262,19 @@ export class Transaction {
262
262
 
263
263
  // Sort. Prioritizing first by signer, then by writable
264
264
  accountMetas.sort(function(x, y) {
265
- const pubkeySorting = x.pubkey.toBase58().localeCompare(y.pubkey.toBase58())
266
- const checkSigner = x.isSigner === y.isSigner ? 0 : x.isSigner ? -1 : 1
267
- const checkWritable = x.isWritable === y.isWritable ? pubkeySorting : x.isWritable ? -1 : 1
268
- return checkSigner || checkWritable
265
+ if (x.isSigner !== y.isSigner) {
266
+ // Signers always come before non-signers
267
+ return x.isSigner ? -1 : 1
268
+ }
269
+ if (x.isWritable !== y.isWritable) {
270
+ // Writable accounts always come before read-only accounts
271
+ return x.isWritable ? -1 : 1
272
+ }
273
+
274
+ const xPubKey = x.pubkey.toBase58().toLowerCase()
275
+ const yPubKey = y.pubkey.toBase58().toLowerCase()
276
+
277
+ return xPubKey < yPubKey ? -1 : xPubKey > yPubKey ? 1 : 0
269
278
  })
270
279
 
271
280
  // Cull duplicate account metas