@exodus/solana-api 3.1.0 → 3.3.0
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 +3 -3
- package/src/api.js +6 -0
- package/src/get-balances.js +22 -3
- package/src/tx-send.js +16 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/solana-api",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "Exodus internal Solana asset API wrapper",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"@exodus/models": "^10.1.0",
|
|
30
30
|
"@exodus/nfts-core": "^0.5.0",
|
|
31
31
|
"@exodus/simple-retry": "^0.0.6",
|
|
32
|
-
"@exodus/solana-lib": "^2.
|
|
32
|
+
"@exodus/solana-lib": "^2.3.0",
|
|
33
33
|
"@exodus/solana-meta": "^1.0.7",
|
|
34
34
|
"bn.js": "^4.11.0",
|
|
35
35
|
"debug": "^4.1.1",
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@exodus/assets-testing": "^1.0.0"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "5be11b271fd14c54f4fe8dd04b146361100e2a4d"
|
|
48
48
|
}
|
package/src/api.js
CHANGED
|
@@ -148,6 +148,12 @@ export class Api {
|
|
|
148
148
|
return lodash.get(result, 'value.feeCalculator.lamportsPerSignature')
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
+
async getPriorityFee(transaction) {
|
|
152
|
+
// https://docs.helius.dev/solana-rpc-nodes/alpha-priority-fee-api
|
|
153
|
+
const result = await this.rpcCall('getPriorityFeeEstimate', [{ transaction }])
|
|
154
|
+
return result.priorityFeeEstimate
|
|
155
|
+
}
|
|
156
|
+
|
|
151
157
|
async getBalance(address) {
|
|
152
158
|
const result = await this.rpcCall('getBalance', [address, { encoding: 'jsonParsed' }], {
|
|
153
159
|
address,
|
package/src/get-balances.js
CHANGED
|
@@ -16,7 +16,14 @@ export const getBalancesFactory =
|
|
|
16
16
|
asset,
|
|
17
17
|
})
|
|
18
18
|
if (asset.baseAsset.name !== asset.name) {
|
|
19
|
-
return {
|
|
19
|
+
return {
|
|
20
|
+
// legacy
|
|
21
|
+
balance,
|
|
22
|
+
spendableBalance: balance,
|
|
23
|
+
// new
|
|
24
|
+
total: balance,
|
|
25
|
+
spendable: balance,
|
|
26
|
+
}
|
|
20
27
|
}
|
|
21
28
|
|
|
22
29
|
const balanceWithoutStaking = balance
|
|
@@ -25,9 +32,21 @@ export const getBalancesFactory =
|
|
|
25
32
|
.sub(pending)
|
|
26
33
|
.clampLowerZero()
|
|
27
34
|
|
|
35
|
+
const total = stakingFeatureAvailable ? balance : balanceWithoutStaking
|
|
36
|
+
const spendable = balanceWithoutStaking.sub(asset.accountReserve || zero).clampLowerZero()
|
|
37
|
+
|
|
38
|
+
const staked = locked
|
|
39
|
+
const unstaking = pending
|
|
40
|
+
|
|
28
41
|
return {
|
|
29
|
-
|
|
30
|
-
|
|
42
|
+
// legacy
|
|
43
|
+
balance: total,
|
|
44
|
+
spendableBalance: spendable,
|
|
45
|
+
// new
|
|
46
|
+
total,
|
|
47
|
+
spendable,
|
|
48
|
+
staked,
|
|
49
|
+
unstaking,
|
|
31
50
|
}
|
|
32
51
|
}
|
|
33
52
|
|
package/src/tx-send.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createUnsignedTx,
|
|
3
3
|
findAssociatedTokenAddress,
|
|
4
|
+
prepareForSigning,
|
|
4
5
|
TOKEN_PROGRAM_ID,
|
|
5
6
|
TOKEN_2022_PROGRAM_ID,
|
|
6
7
|
} from '@exodus/solana-lib'
|
|
8
|
+
import { transactionToBase58 } from '@exodus/solana-lib/src/tx/common'
|
|
7
9
|
import assert from 'minimalistic-assert'
|
|
8
10
|
|
|
9
11
|
export const createAndBroadcastTXFactory =
|
|
@@ -137,6 +139,20 @@ export const createAndBroadcastTXFactory =
|
|
|
137
139
|
...magicEdenParams,
|
|
138
140
|
})
|
|
139
141
|
|
|
142
|
+
let { priorityFee } = feeData
|
|
143
|
+
|
|
144
|
+
if (!priorityFee) {
|
|
145
|
+
try {
|
|
146
|
+
const transactionForFeeEstimation = prepareForSigning(unsignedTransaction)
|
|
147
|
+
priorityFee = await api.getPriorityFee(transactionToBase58(transactionForFeeEstimation))
|
|
148
|
+
} catch (e) {
|
|
149
|
+
console.warn(`Failed to fetch priority fee: ${e.message}`)
|
|
150
|
+
priorityFee = feeData.fallbackPriorityFee
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
unsignedTransaction.txData.priorityFee = priorityFee
|
|
155
|
+
|
|
140
156
|
const { txId, rawTx } = await assetClientInterface.signTransaction({
|
|
141
157
|
assetName: baseAsset.name,
|
|
142
158
|
unsignedTx: unsignedTransaction,
|