@exodus/solana-lib 1.2.20 → 1.2.21
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.
|
|
3
|
+
"version": "1.2.21",
|
|
4
4
|
"description": "Exodus internal Solana low-level library",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -23,5 +23,5 @@
|
|
|
23
23
|
"lodash": "^4.17.11",
|
|
24
24
|
"tweetnacl": "^1.0.3"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "dac1d4d133b92c18334de5a37332cfad769e1459"
|
|
27
27
|
}
|
package/src/transaction.js
CHANGED
|
@@ -30,7 +30,9 @@ class Tx {
|
|
|
30
30
|
recentBlockhash,
|
|
31
31
|
// fee, // (Fee per Signature: 5000 lamports)
|
|
32
32
|
// Tokens related:
|
|
33
|
+
// pass either name or mintAddress, if both, mintAddress has priority
|
|
33
34
|
tokenName,
|
|
35
|
+
tokenMintAddress,
|
|
34
36
|
destinationAddressType,
|
|
35
37
|
isAssociatedTokenAccountActive, // true when recipient balance !== 0
|
|
36
38
|
fromTokenAddresses, // sender token addresses
|
|
@@ -40,7 +42,7 @@ class Tx {
|
|
|
40
42
|
assert(amount, 'amount is required')
|
|
41
43
|
assert(typeof amount === 'number', 'amount must be a number')
|
|
42
44
|
assert(recentBlockhash, 'recentBlockhash is required')
|
|
43
|
-
if (tokenName) {
|
|
45
|
+
if (tokenName || tokenMintAddress) {
|
|
44
46
|
assert(
|
|
45
47
|
typeof destinationAddressType !== 'undefined',
|
|
46
48
|
'destinationAddressType is required when sending tokens'
|
|
@@ -52,19 +54,23 @@ class Tx {
|
|
|
52
54
|
assert(Array.isArray(fromTokenAddresses), 'fromTokenAddresses Array is required')
|
|
53
55
|
}
|
|
54
56
|
|
|
55
|
-
|
|
57
|
+
if (tokenName && !tokenMintAddress) {
|
|
58
|
+
const token = TOKENS.find(({ name }) => name === tokenName)
|
|
59
|
+
tokenMintAddress = token && token.mintAddress
|
|
60
|
+
}
|
|
61
|
+
|
|
56
62
|
this.txObj = {
|
|
57
63
|
from,
|
|
58
64
|
to,
|
|
59
65
|
amount,
|
|
60
66
|
recentBlockhash,
|
|
61
|
-
|
|
67
|
+
tokenMintAddress,
|
|
62
68
|
destinationAddressType,
|
|
63
69
|
isAssociatedTokenAccountActive,
|
|
64
70
|
fromTokenAddresses,
|
|
65
71
|
}
|
|
66
72
|
|
|
67
|
-
if (
|
|
73
|
+
if (tokenMintAddress) {
|
|
68
74
|
// TOKEN transfer tx
|
|
69
75
|
this.buildTokenTransaction(this.txObj)
|
|
70
76
|
} else {
|
|
@@ -91,7 +97,7 @@ class Tx {
|
|
|
91
97
|
to,
|
|
92
98
|
amount,
|
|
93
99
|
recentBlockhash,
|
|
94
|
-
|
|
100
|
+
tokenMintAddress,
|
|
95
101
|
destinationAddressType,
|
|
96
102
|
isAssociatedTokenAccountActive,
|
|
97
103
|
fromTokenAddresses,
|
|
@@ -99,18 +105,18 @@ class Tx {
|
|
|
99
105
|
this.transaction = new Transaction({
|
|
100
106
|
recentBlockhash,
|
|
101
107
|
})
|
|
102
|
-
const isUnknown = destinationAddressType === null
|
|
108
|
+
// const isUnknown = destinationAddressType === null
|
|
109
|
+
// if (isUnknown) throw new Error('Destination SOL balance cannot be zero (address not active)') // cannot initialize without knowing the owner
|
|
103
110
|
const isSOLaddress = destinationAddressType === 'solana'
|
|
104
111
|
// crete account instruction
|
|
105
|
-
if (isUnknown) throw new Error('Destination SOL balance cannot be zero (address not active)') // cannot initialize without knowing the owner
|
|
106
112
|
if (isSOLaddress && !isAssociatedTokenAccountActive)
|
|
107
|
-
this.transaction.add(createAssociatedTokenAccount(from,
|
|
113
|
+
this.transaction.add(createAssociatedTokenAccount(from, tokenMintAddress, to))
|
|
108
114
|
|
|
109
115
|
let amountLeft = amount
|
|
110
116
|
let amountToSend
|
|
111
|
-
for (let {
|
|
117
|
+
for (let { mintAddress, tokenAccountAddress, balance } of fromTokenAddresses) {
|
|
112
118
|
// need to add more of this instruction until we reach the desired balance (amount) to send
|
|
113
|
-
assert(
|
|
119
|
+
assert(mintAddress === tokenMintAddress, `Got unexpected mintAddress ${mintAddress}`)
|
|
114
120
|
if (amountLeft === 0) break
|
|
115
121
|
|
|
116
122
|
balance = Number(balance)
|
|
@@ -122,14 +128,14 @@ class Tx {
|
|
|
122
128
|
amountLeft -= amountToSend
|
|
123
129
|
}
|
|
124
130
|
|
|
125
|
-
const dest = isSOLaddress ? findAssociatedTokenAddress(to,
|
|
131
|
+
const dest = isSOLaddress ? findAssociatedTokenAddress(to, tokenMintAddress) : to
|
|
126
132
|
// add transfer token instruction
|
|
127
133
|
this.transaction.add(
|
|
128
134
|
createTokenTransferInstruction(from, tokenAccountAddress, dest, amountToSend)
|
|
129
135
|
)
|
|
130
136
|
}
|
|
131
137
|
|
|
132
|
-
assert(amountLeft === 0, `Not enough balance to send ${amount} ${
|
|
138
|
+
assert(amountLeft === 0, `Not enough balance to send ${amount} ${tokenMintAddress}`)
|
|
133
139
|
}
|
|
134
140
|
|
|
135
141
|
static createStakeAccountTransaction({ address, amount, seed = SEED, pool, recentBlockhash }) {
|
|
@@ -9,6 +9,7 @@ export function createUnsignedTx({
|
|
|
9
9
|
recentBlockhash,
|
|
10
10
|
// Tokens related:
|
|
11
11
|
tokenName,
|
|
12
|
+
tokenMintAddress,
|
|
12
13
|
destinationAddressType,
|
|
13
14
|
isAssociatedTokenAccountActive, // true when recipient balance !== 0
|
|
14
15
|
fromTokenAddresses, // sender token addresses
|
|
@@ -27,6 +28,7 @@ export function createUnsignedTx({
|
|
|
27
28
|
recentBlockhash,
|
|
28
29
|
// Tokens related:
|
|
29
30
|
tokenName,
|
|
31
|
+
tokenMintAddress,
|
|
30
32
|
destinationAddressType,
|
|
31
33
|
isAssociatedTokenAccountActive,
|
|
32
34
|
fromTokenAddresses,
|
|
@@ -8,6 +8,7 @@ export function parseUnsignedTx(unsignedTx: UnsignedTransaction): ParsedTransact
|
|
|
8
8
|
to,
|
|
9
9
|
recentBlockhash,
|
|
10
10
|
tokenName,
|
|
11
|
+
tokenMintAddress,
|
|
11
12
|
destinationAddressType,
|
|
12
13
|
isAssociatedTokenAccountActive,
|
|
13
14
|
fromTokenAddresses,
|
|
@@ -29,6 +30,7 @@ export function parseUnsignedTx(unsignedTx: UnsignedTransaction): ParsedTransact
|
|
|
29
30
|
recentBlockhash,
|
|
30
31
|
// token related
|
|
31
32
|
tokenName,
|
|
33
|
+
tokenMintAddress,
|
|
32
34
|
destinationAddressType,
|
|
33
35
|
isAssociatedTokenAccountActive,
|
|
34
36
|
fromTokenAddresses,
|
|
@@ -13,6 +13,7 @@ export function signUnsignedTx(
|
|
|
13
13
|
recentBlockhash,
|
|
14
14
|
// tokens related
|
|
15
15
|
tokenName,
|
|
16
|
+
tokenMintAddress,
|
|
16
17
|
destinationAddressType,
|
|
17
18
|
isAssociatedTokenAccountActive,
|
|
18
19
|
fromTokenAddresses,
|
|
@@ -62,6 +63,7 @@ export function signUnsignedTx(
|
|
|
62
63
|
amount,
|
|
63
64
|
recentBlockhash,
|
|
64
65
|
tokenName,
|
|
66
|
+
tokenMintAddress,
|
|
65
67
|
destinationAddressType,
|
|
66
68
|
isAssociatedTokenAccountActive,
|
|
67
69
|
fromTokenAddresses,
|