@exodus/solana-lib 1.8.2 → 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": "1.8.2",
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": "4c01d2640992ed8487c6a018844a96ba1990095e"
39
+ "gitHead": "1f9f097ac7c8d4c657ef1a4786af7781bcfd7660"
39
40
  }
@@ -1 +1,11 @@
1
- export { default as solana } from './solana'
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
@@ -2,6 +2,7 @@ export * from './constants'
2
2
  export * from './encode'
3
3
  export * from './keypair'
4
4
  export * from './tx'
5
+ export * from './fee-data'
5
6
  export {
6
7
  TransactionInstruction,
7
8
  StakeInstruction,
@@ -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,6 +1,4 @@
1
- import { asset } from '@exodus/solana-meta'
2
-
3
- export function parseUnsignedTx(unsignedTx) {
1
+ export function parseUnsignedTx({ asset, unsignedTx }) {
4
2
  const {
5
3
  from,
6
4
  to,
@@ -1,15 +1,14 @@
1
- import { asset } from '@exodus/solana-meta'
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
- const feeAmountNU = asset.currency.baseUnit(feeAmount || 0)
11
- if (feeAmountNU.gt(feeData.fee)) {
12
- const ratio = feeAmountNU.sub(feeData.fee).toBaseNumber()
10
+ if (feeAmount > fixedFee) {
11
+ const ratio = feeAmount - fixedFee
13
12
  if (ratio > 1_000_000) throw new Error('Prioritization fee is too high')
14
13
 
15
14
  const priorityFeeInstruction = ComputeBudgetProgram.setComputeUnitPrice({
@@ -25,18 +24,33 @@ const addPriorityFeeToTransaction = ({ transaction, feeAmount }) => {
25
24
  * @returns a Solana Web3.js Transaction object
26
25
  */
27
26
  export function prepareForSigning(unsignedTx) {
28
- const { amount: unitAmount, fee: feeAmount, from, method, transaction } = unsignedTx.txData
27
+ const {
28
+ amount: unitAmount,
29
+ fee: feeAmount,
30
+ fixedFee,
31
+ from,
32
+ method,
33
+ transaction,
34
+ } = unsignedTx.txData
29
35
 
30
36
  if (!transaction) {
31
37
  // Create a transaction in web3.js format
32
38
  const address = from
33
- const amount = unitAmount ? asset.currency.baseUnit(unitAmount).toNumber() : unitAmount
34
- const fee = feeAmount ? asset.currency.baseUnit(feeAmount).toNumber() : feeAmount
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
35
47
 
36
48
  const txData = { ...unsignedTx.txData, address, amount, fee }
37
49
 
38
50
  const transaction = createTx({ txData, method })
39
- addPriorityFeeToTransaction({ transaction, feeAmount })
51
+
52
+ addPriorityFeeToTransaction({ transaction, feeAmount, fixedFee })
53
+
40
54
  if (!transaction.feePayer) {
41
55
  transaction.feePayer = new PublicKey(from)
42
56
  }
@@ -1,11 +0,0 @@
1
- import { FeeData } from '@exodus/asset-lib'
2
- import { asset } from '@exodus/solana-meta'
3
-
4
- export default new FeeData({
5
- config: {
6
- fee: '0.000005 SOL',
7
- fuelThreshold: '0.000015 SOL',
8
- },
9
- mainKey: 'fee',
10
- currency: asset.currency,
11
- })