@exodus/solana-lib 1.8.1 → 2.0.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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/solana-lib",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Exodus internal Solana low-level library",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@exodus/asset-lib": "^4.1.0",
|
|
22
22
|
"@exodus/buffer-layout": "^1.2.0-exodus1",
|
|
23
|
+
"@exodus/currency": "^2.3.2",
|
|
23
24
|
"@exodus/key-utils": "^3.1.0",
|
|
24
25
|
"@exodus/models": "^10.1.0",
|
|
25
|
-
"@exodus/solana-meta": "^1.0.7",
|
|
26
26
|
"@project-serum/serum": "0.13.64",
|
|
27
27
|
"bn.js": "^4.11.0",
|
|
28
28
|
"borsh": "^0.7.0",
|
|
@@ -33,7 +33,8 @@
|
|
|
33
33
|
"tweetnacl": "^1.0.3"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
+
"@exodus/solana-meta": "^1.0.7",
|
|
36
37
|
"@solana/web3.js": "^1.90.0"
|
|
37
38
|
},
|
|
38
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "1f9f097ac7c8d4c657ef1a4786af7781bcfd7660"
|
|
39
40
|
}
|
package/src/fee-data/index.js
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import { FeeData } from '@exodus/asset-lib'
|
|
2
|
+
|
|
3
|
+
export const createFeeData = ({ asset }) =>
|
|
4
|
+
new FeeData({
|
|
5
|
+
config: {
|
|
6
|
+
fee: `0.000005 ${asset.ticker}`,
|
|
7
|
+
fuelThreshold: `0.000015 ${asset.ticker}`,
|
|
8
|
+
},
|
|
9
|
+
mainKey: 'fee',
|
|
10
|
+
currency: asset.currency,
|
|
11
|
+
})
|
package/src/index.js
CHANGED
|
@@ -4,6 +4,7 @@ export function createUnsignedTx({
|
|
|
4
4
|
to,
|
|
5
5
|
amount,
|
|
6
6
|
fee,
|
|
7
|
+
feeData,
|
|
7
8
|
recentBlockhash,
|
|
8
9
|
// Tokens related:
|
|
9
10
|
tokenMintAddress,
|
|
@@ -39,6 +40,7 @@ export function createUnsignedTx({
|
|
|
39
40
|
to,
|
|
40
41
|
amount: amount ? amount.toBaseNumber() : null,
|
|
41
42
|
fee: fee ? fee.toBaseNumber() : null,
|
|
43
|
+
fixedFee: feeData ? feeData.fee.toBaseNumber() : null,
|
|
42
44
|
recentBlockhash,
|
|
43
45
|
// Tokens related:
|
|
44
46
|
tokenMintAddress,
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isNumberUnit } from '@exodus/currency'
|
|
2
|
+
import BN from 'bn.js'
|
|
2
3
|
|
|
3
4
|
import { ComputeBudgetProgram, PublicKey } from '../vendor'
|
|
4
5
|
import Transaction from '../transaction'
|
|
5
6
|
import { createMetaplexTransferTransaction } from '../helpers/metaplex-transfer'
|
|
6
|
-
import feeData from '../fee-data/solana'
|
|
7
7
|
|
|
8
|
-
const addPriorityFeeToTransaction = ({ transaction, feeAmount }) => {
|
|
8
|
+
const addPriorityFeeToTransaction = ({ transaction, feeAmount = 0, fixedFee = 0 }) => {
|
|
9
9
|
// if fee greater than base fee. Add prioritization fee:
|
|
10
|
-
if (feeAmount >
|
|
11
|
-
const ratio = feeAmount -
|
|
10
|
+
if (feeAmount > fixedFee) {
|
|
11
|
+
const ratio = feeAmount - fixedFee
|
|
12
12
|
if (ratio > 1_000_000) throw new Error('Prioritization fee is too high')
|
|
13
13
|
|
|
14
14
|
const priorityFeeInstruction = ComputeBudgetProgram.setComputeUnitPrice({
|
|
@@ -24,18 +24,33 @@ const addPriorityFeeToTransaction = ({ transaction, feeAmount }) => {
|
|
|
24
24
|
* @returns a Solana Web3.js Transaction object
|
|
25
25
|
*/
|
|
26
26
|
export function prepareForSigning(unsignedTx) {
|
|
27
|
-
const {
|
|
27
|
+
const {
|
|
28
|
+
amount: unitAmount,
|
|
29
|
+
fee: feeAmount,
|
|
30
|
+
fixedFee,
|
|
31
|
+
from,
|
|
32
|
+
method,
|
|
33
|
+
transaction,
|
|
34
|
+
} = unsignedTx.txData
|
|
28
35
|
|
|
29
36
|
if (!transaction) {
|
|
30
37
|
// Create a transaction in web3.js format
|
|
31
38
|
const address = from
|
|
32
|
-
|
|
33
|
-
const
|
|
39
|
+
|
|
40
|
+
const amount = unitAmount
|
|
41
|
+
? new BN(isNumberUnit(unitAmount) ? unitAmount.toBaseString() : unitAmount).toNumber()
|
|
42
|
+
: unitAmount
|
|
43
|
+
|
|
44
|
+
const fee = feeAmount
|
|
45
|
+
? new BN(isNumberUnit(feeAmount) ? feeAmount.toBaseString() : feeAmount).toNumber()
|
|
46
|
+
: feeAmount
|
|
34
47
|
|
|
35
48
|
const txData = { ...unsignedTx.txData, address, amount, fee }
|
|
36
49
|
|
|
37
50
|
const transaction = createTx({ txData, method })
|
|
38
|
-
|
|
51
|
+
|
|
52
|
+
addPriorityFeeToTransaction({ transaction, feeAmount, fixedFee })
|
|
53
|
+
|
|
39
54
|
if (!transaction.feePayer) {
|
|
40
55
|
transaction.feePayer = new PublicKey(from)
|
|
41
56
|
}
|
package/src/fee-data/solana.js
DELETED