@exodus/solana-lib 1.2.20 → 1.2.22
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.22",
|
|
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": "b0b12a6e226a8b1780cc6191f75b50822af3b71d"
|
|
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,24 @@ 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
|
+
assert(token, `token with tokenName ${tokenName} not found in tokens list`)
|
|
60
|
+
tokenMintAddress = token.mintAddress
|
|
61
|
+
}
|
|
62
|
+
|
|
56
63
|
this.txObj = {
|
|
57
64
|
from,
|
|
58
65
|
to,
|
|
59
66
|
amount,
|
|
60
67
|
recentBlockhash,
|
|
61
|
-
|
|
68
|
+
tokenMintAddress,
|
|
62
69
|
destinationAddressType,
|
|
63
70
|
isAssociatedTokenAccountActive,
|
|
64
71
|
fromTokenAddresses,
|
|
65
72
|
}
|
|
66
73
|
|
|
67
|
-
if (
|
|
74
|
+
if (tokenMintAddress) {
|
|
68
75
|
// TOKEN transfer tx
|
|
69
76
|
this.buildTokenTransaction(this.txObj)
|
|
70
77
|
} else {
|
|
@@ -91,7 +98,7 @@ class Tx {
|
|
|
91
98
|
to,
|
|
92
99
|
amount,
|
|
93
100
|
recentBlockhash,
|
|
94
|
-
|
|
101
|
+
tokenMintAddress,
|
|
95
102
|
destinationAddressType,
|
|
96
103
|
isAssociatedTokenAccountActive,
|
|
97
104
|
fromTokenAddresses,
|
|
@@ -99,18 +106,18 @@ class Tx {
|
|
|
99
106
|
this.transaction = new Transaction({
|
|
100
107
|
recentBlockhash,
|
|
101
108
|
})
|
|
102
|
-
const isUnknown = destinationAddressType === null
|
|
103
|
-
|
|
109
|
+
// const isUnknown = destinationAddressType === null
|
|
110
|
+
// if (isUnknown) throw new Error('Destination SOL balance cannot be zero (address not active)') // cannot initialize without knowing the owner
|
|
111
|
+
const isSOLaddress = ['solana', null].includes(destinationAddressType)
|
|
104
112
|
// 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
113
|
if (isSOLaddress && !isAssociatedTokenAccountActive)
|
|
107
|
-
this.transaction.add(createAssociatedTokenAccount(from,
|
|
114
|
+
this.transaction.add(createAssociatedTokenAccount(from, tokenMintAddress, to))
|
|
108
115
|
|
|
109
116
|
let amountLeft = amount
|
|
110
117
|
let amountToSend
|
|
111
|
-
for (let {
|
|
118
|
+
for (let { mintAddress, tokenAccountAddress, balance } of fromTokenAddresses) {
|
|
112
119
|
// need to add more of this instruction until we reach the desired balance (amount) to send
|
|
113
|
-
assert(
|
|
120
|
+
assert(mintAddress === tokenMintAddress, `Got unexpected mintAddress ${mintAddress}`)
|
|
114
121
|
if (amountLeft === 0) break
|
|
115
122
|
|
|
116
123
|
balance = Number(balance)
|
|
@@ -122,14 +129,14 @@ class Tx {
|
|
|
122
129
|
amountLeft -= amountToSend
|
|
123
130
|
}
|
|
124
131
|
|
|
125
|
-
const dest = isSOLaddress ? findAssociatedTokenAddress(to,
|
|
132
|
+
const dest = isSOLaddress ? findAssociatedTokenAddress(to, tokenMintAddress) : to
|
|
126
133
|
// add transfer token instruction
|
|
127
134
|
this.transaction.add(
|
|
128
135
|
createTokenTransferInstruction(from, tokenAccountAddress, dest, amountToSend)
|
|
129
136
|
)
|
|
130
137
|
}
|
|
131
138
|
|
|
132
|
-
assert(amountLeft === 0, `Not enough balance to send ${amount} ${
|
|
139
|
+
assert(amountLeft === 0, `Not enough balance to send ${amount} ${tokenMintAddress}`)
|
|
133
140
|
}
|
|
134
141
|
|
|
135
142
|
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,
|