@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 +2 -2
- package/src/constants.js +4 -0
- package/src/index.js +1 -1
- package/src/magiceden/coders.js +7 -10
- package/src/magiceden/escrow-program.js +16 -16
- package/src/transaction.js +10 -4
- package/src/tx/create-unsigned-tx.js +6 -2
- package/src/tx/parse-unsigned-tx.js +7 -3
- package/src/tx/sign-unsigned-tx.js +9 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/solana-lib",
|
|
3
|
-
"version": "1.2.
|
|
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": "
|
|
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'
|
package/src/magiceden/coders.js
CHANGED
|
@@ -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: '
|
|
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: '
|
|
12
|
+
name: 'cancel_escrow',
|
|
15
13
|
layout: BufferLayout.struct([]),
|
|
16
14
|
},
|
|
17
15
|
exchange: {
|
|
18
|
-
name: '
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
}
|
package/src/transaction.js
CHANGED
|
@@ -209,19 +209,20 @@ class Tx {
|
|
|
209
209
|
static magicEdenInitializeEscrow({
|
|
210
210
|
initializerAddress,
|
|
211
211
|
initializerDepositTokenAddress,
|
|
212
|
-
lamports,
|
|
213
212
|
takerAmount,
|
|
214
|
-
|
|
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
|
|
224
|
-
|
|
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
|
-
|
|
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 {
|
|
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
|
-
|
|
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
|
|
122
|
+
Transaction.sign(tx, privateKey)
|
|
124
123
|
const rawTx = Transaction.serialize(tx)
|
|
125
124
|
const txId = Transaction.getTxId(tx)
|
|
126
125
|
|