@exodus/solana-lib 1.2.24 → 1.2.25

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.2.24",
3
+ "version": "1.2.25",
4
4
  "description": "Exodus internal Solana low-level library",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -24,5 +24,5 @@
24
24
  "lodash": "^4.17.11",
25
25
  "tweetnacl": "^1.0.3"
26
26
  },
27
- "gitHead": "131c0987f26bbef2c42e9bcf54b799c63a0dea7b"
27
+ "gitHead": "2703cd0c4f81f6b99570579e3b3ae3bfb1585f0a"
28
28
  }
package/src/constants.js CHANGED
@@ -9,4 +9,8 @@ export const STAKE_PROGRAM_ID = StakeProgram.programId
9
9
 
10
10
  export const TOKEN_PROGRAM_ID = new PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA')
11
11
 
12
+ export const MAGIC_EDEN_ESCROW_PROGRAM_ID = new PublicKey(
13
+ 'MEisE1HzehtrDpAAT8PnLHjpSSkRYakotTuJRPjTpo8'
14
+ )
15
+
12
16
  export const SEED = 'stake:0'
package/src/index.js CHANGED
@@ -4,6 +4,6 @@ export * from './constants'
4
4
  export * from './encode'
5
5
  export * from './keypair'
6
6
  export * from './tx'
7
- export { StakeInstruction } from './vendor'
7
+ export { StakeInstruction, PublicKey } from './vendor'
8
8
  export { default as tokens } from './tokens'
9
9
  export { default as Transaction } from './transaction'
@@ -1,28 +1,25 @@
1
1
  import * as BufferLayout from '@exodus/buffer-layout'
2
-
3
- import { snakeCase } from 'lodash'
4
2
  import createHash from 'create-hash'
5
3
 
6
- import { bnAmountU64 } from '../vendor/utils/layout'
4
+ import { bnAmountU64, publicKey } from '../vendor/utils/layout'
7
5
 
8
6
  const idl = {
9
7
  initializeEscrow: {
10
- name: 'initializeEscrow',
11
- layout: BufferLayout.struct([bnAmountU64('takerAmount')]),
8
+ name: 'initialize_escrow2',
9
+ layout: BufferLayout.struct([bnAmountU64('takerAmount'), BufferLayout.u8('escrowBump')]),
12
10
  },
13
11
  cancelEscrow: {
14
- name: 'cancelEscrow',
12
+ name: 'cancel_escrow',
15
13
  layout: BufferLayout.struct([]),
16
14
  },
17
15
  exchange: {
18
- name: 'exchange',
19
- layout: BufferLayout.struct([]),
16
+ name: 'exchange2',
17
+ layout: BufferLayout.struct([bnAmountU64('expectedTakerAmount'), publicKey('expectedMint')]),
20
18
  },
21
19
  }
22
20
 
23
21
  export function sighash(nameSpace, ixName) {
24
- let name = snakeCase(ixName)
25
- let preimage = `${nameSpace}:${name}`
22
+ let preimage = `${nameSpace}:${ixName}`
26
23
 
27
24
  return Buffer.from(
28
25
  createHash('sha256')
@@ -1,12 +1,12 @@
1
- import { PublicKey, Transaction, SystemProgram } from '../vendor'
2
- import { SYSTEM_PROGRAM_ID, TOKEN_PROGRAM_ID } from '../constants'
1
+ import { PublicKey, Transaction } from '../vendor'
2
+ import { SYSTEM_PROGRAM_ID, TOKEN_PROGRAM_ID, MAGIC_EDEN_ESCROW_PROGRAM_ID } from '../constants'
3
3
  import { encodeData } from './coders'
4
4
 
5
5
  const PLATFORM_FEES_PROGRAM_ID = new PublicKey('2NZukH2TXpcuZP4htiuT8CFxcaQSWzkkR6kepSWnZ24Q')
6
6
 
7
7
  export class MagicEdenEscrowProgram {
8
8
  static get programId() {
9
- return new PublicKey('MEisE1HzehtrDpAAT8PnLHjpSSkRYakotTuJRPjTpo8')
9
+ return MAGIC_EDEN_ESCROW_PROGRAM_ID
10
10
  }
11
11
 
12
12
  static get space() {
@@ -18,22 +18,12 @@ export class MagicEdenEscrowProgram {
18
18
  initializerPubkey,
19
19
  initializerDepositTokenPubkey,
20
20
  escrowPubkey,
21
- lamports,
21
+ escrowBump,
22
22
  takerAmount,
23
23
  } = params
24
24
 
25
25
  const transaction = new Transaction()
26
26
 
27
- transaction.add(
28
- SystemProgram.createAccount({
29
- fromPubkey: initializerPubkey,
30
- newAccountPubkey: escrowPubkey,
31
- lamports: lamports,
32
- space: this.space,
33
- programId: this.programId,
34
- })
35
- )
36
-
37
27
  return transaction.add({
38
28
  keys: [
39
29
  {
@@ -56,9 +46,14 @@ export class MagicEdenEscrowProgram {
56
46
  isSigner: false,
57
47
  isWritable: false,
58
48
  },
49
+ {
50
+ pubkey: SYSTEM_PROGRAM_ID,
51
+ isSigner: false,
52
+ isWritable: false,
53
+ },
59
54
  ],
60
55
  programId: this.programId,
61
- data: encodeData('initializeEscrow', { takerAmount }),
56
+ data: encodeData('initializeEscrow', { takerAmount, escrowBump }),
62
57
  })
63
58
  }
64
59
 
@@ -100,6 +95,8 @@ export class MagicEdenEscrowProgram {
100
95
 
101
96
  static exchange(params) {
102
97
  const {
98
+ expectedTakerAmount,
99
+ expectedMintPubkey,
103
100
  takerPubkey,
104
101
  initializerDepositTokenPubkey,
105
102
  initializerPubkey,
@@ -165,7 +162,10 @@ export class MagicEdenEscrowProgram {
165
162
  ...remainingAccounts,
166
163
  ],
167
164
  programId: this.programId,
168
- data: encodeData('exchange'),
165
+ data: encodeData('exchange', {
166
+ expectedTakerAmount,
167
+ expectedMint: expectedMintPubkey.toBuffer(),
168
+ }),
169
169
  })
170
170
  }
171
171
  }
@@ -209,19 +209,20 @@ class Tx {
209
209
  static magicEdenInitializeEscrow({
210
210
  initializerAddress,
211
211
  initializerDepositTokenAddress,
212
- lamports,
213
212
  takerAmount,
214
- escrowAccount,
213
+ escrowAddress,
214
+ escrowBump,
215
215
  recentBlockhash,
216
216
  }) {
217
217
  const initializerPubkey = new PublicKey(initializerAddress)
218
218
  const initializerDepositTokenPubkey = new PublicKey(initializerDepositTokenAddress)
219
+ const escrowPubkey = new PublicKey(escrowAddress)
219
220
 
220
221
  const transaction = MagicEdenEscrowProgram.initializeEscrow({
221
222
  initializerPubkey,
222
223
  initializerDepositTokenPubkey,
223
- escrowPubkey: escrowAccount.publicKey,
224
- lamports,
224
+ escrowPubkey,
225
+ escrowBump,
225
226
  takerAmount: assets.solana.currency.baseUnit(takerAmount)._number,
226
227
  })
227
228
 
@@ -255,6 +256,8 @@ class Tx {
255
256
  }
256
257
 
257
258
  static magicEdenExchange({
259
+ expectedTakerAmount,
260
+ expectedMintAddress,
258
261
  takerAddress,
259
262
  initializerAddress,
260
263
  initializerDepositTokenAddress,
@@ -264,6 +267,7 @@ class Tx {
264
267
  creators,
265
268
  recentBlockhash,
266
269
  }) {
270
+ const expectedMintPubkey = new PublicKey(expectedMintAddress)
267
271
  const takerPubkey = new PublicKey(takerAddress)
268
272
  const initializerPubkey = new PublicKey(initializerAddress)
269
273
  const initializerDepositTokenPubkey = new PublicKey(initializerDepositTokenAddress)
@@ -272,6 +276,8 @@ class Tx {
272
276
  const metadataPubkey = new PublicKey(metadataAddress)
273
277
 
274
278
  const transaction = MagicEdenEscrowProgram.exchange({
279
+ expectedTakerAmount,
280
+ expectedMintPubkey,
275
281
  takerPubkey,
276
282
  initializerPubkey,
277
283
  initializerDepositTokenPubkey,
@@ -22,11 +22,13 @@ export function createUnsignedTx({
22
22
  // MagicEden escrow/related:
23
23
  initializerAddress,
24
24
  initializerDepositTokenAddress,
25
- lamports,
26
25
  takerAmount,
27
26
  escrowAddress,
27
+ escrowBump,
28
28
  pdaAddress,
29
29
  takerAddress,
30
+ expectedTakerAmount,
31
+ expectedMintAddress,
30
32
  metadataAddress,
31
33
  creators,
32
34
  }: ParsedTransaction): UnsignedTransaction {
@@ -51,10 +53,12 @@ export function createUnsignedTx({
51
53
  // MagicEden escrow/related:
52
54
  initializerAddress,
53
55
  initializerDepositTokenAddress,
54
- lamports,
55
56
  takerAmount: takerAmount ? takerAmount.toBaseString() : null,
56
57
  escrowAddress,
58
+ escrowBump,
57
59
  pdaAddress,
60
+ expectedTakerAmount: expectedTakerAmount ? expectedTakerAmount.toBaseString() : null,
61
+ expectedMintAddress,
58
62
  takerAddress,
59
63
  metadataAddress,
60
64
  creators,
@@ -18,11 +18,13 @@ export function parseUnsignedTx(unsignedTx: UnsignedTransaction): ParsedTransact
18
18
  pool,
19
19
  initializerAddress,
20
20
  initializerDepositTokenAddress,
21
- lamports,
22
21
  takerAmount,
23
22
  escrowAddress,
23
+ escrowBump,
24
24
  pdaAddress,
25
25
  takerAddress,
26
+ expectedTakerAmount,
27
+ expectedMintAddress,
26
28
  metadataAddress,
27
29
  creators,
28
30
  ...txData
@@ -51,11 +53,13 @@ export function parseUnsignedTx(unsignedTx: UnsignedTransaction): ParsedTransact
51
53
  // MagicEden escrow/related:
52
54
  initializerAddress,
53
55
  initializerDepositTokenAddress,
54
- lamports,
55
- takerAmount: asset.currency.baseUnit(txData.takerAmount),
56
+ takerAmount: takerAmount ? asset.currency.baseUnit(takerAmount) : null,
56
57
  escrowAddress,
58
+ escrowBump,
57
59
  pdaAddress,
58
60
  takerAddress,
61
+ expectedTakerAmount: expectedTakerAmount ? asset.currency.baseUnit(expectedTakerAmount) : null,
62
+ expectedMintAddress,
59
63
  metadataAddress,
60
64
  creators,
61
65
  }
@@ -1,7 +1,6 @@
1
1
  import assets from '@exodus/assets'
2
2
  import type { UnsignedTransaction, SignedTransaction } from '@exodus/models/lib/types'
3
- import { Account } from '../vendor'
4
- import { Transaction, generateKeyPair } from '../'
3
+ import { Transaction } from '../'
5
4
 
6
5
  export function signUnsignedTx(
7
6
  unsignedTx: UnsignedTransaction,
@@ -26,11 +25,13 @@ export function signUnsignedTx(
26
25
  // MagicEden escrow/related:
27
26
  initializerAddress,
28
27
  initializerDepositTokenAddress,
29
- lamports,
30
28
  takerAmount,
31
29
  escrowAddress,
30
+ escrowBump,
32
31
  pdaAddress,
33
32
  takerAddress,
33
+ expectedTakerAmount,
34
+ expectedMintAddress,
34
35
  metadataAddress,
35
36
  creators,
36
37
  } = unsignedTx.txData
@@ -41,7 +42,6 @@ export function signUnsignedTx(
41
42
  const amount = unitAmount ? asset.currency.baseUnit(unitAmount).toNumber() : unitAmount
42
43
 
43
44
  let tx
44
- const extraSigners = []
45
45
  switch (method) {
46
46
  case 'delegate':
47
47
  tx = Transaction.createStakeAccountTransaction({
@@ -68,18 +68,15 @@ export function signUnsignedTx(
68
68
  })
69
69
  break
70
70
  case 'initializeEscrow': {
71
- const escrowAccount = new Account(generateKeyPair().secretKey)
72
-
73
71
  tx = Transaction.magicEdenInitializeEscrow({
74
72
  initializerAddress,
75
73
  initializerDepositTokenAddress,
76
- lamports,
74
+ escrowBump,
75
+ escrowAddress,
77
76
  takerAmount,
78
- escrowAccount,
79
77
  recentBlockhash,
80
78
  })
81
79
 
82
- extraSigners.push(escrowAccount)
83
80
  break
84
81
  }
85
82
  case 'cancelEscrow':
@@ -93,6 +90,8 @@ export function signUnsignedTx(
93
90
  break
94
91
  case 'exchange':
95
92
  tx = Transaction.magicEdenExchange({
93
+ expectedTakerAmount,
94
+ expectedMintAddress,
96
95
  takerAddress,
97
96
  initializerAddress,
98
97
  initializerDepositTokenAddress,
@@ -120,7 +119,7 @@ export function signUnsignedTx(
120
119
  }
121
120
 
122
121
  // sign plain tx
123
- Transaction.sign(tx, privateKey, extraSigners)
122
+ Transaction.sign(tx, privateKey)
124
123
  const rawTx = Transaction.serialize(tx)
125
124
  const txId = Transaction.getTxId(tx)
126
125