@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": "1.8.1",
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": "4a4e5e5ea8765b595cb83acd293305bb28b2a103"
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,14 +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
- if (feeAmount > feeData.fee.toBaseNumber()) {
11
- const ratio = feeAmount - feeData.fee.toBaseNumber()
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 { 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
28
35
 
29
36
  if (!transaction) {
30
37
  // Create a transaction in web3.js format
31
38
  const address = from
32
- const amount = unitAmount ? asset.currency.baseUnit(unitAmount).toNumber() : unitAmount
33
- 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
34
47
 
35
48
  const txData = { ...unsignedTx.txData, address, amount, fee }
36
49
 
37
50
  const transaction = createTx({ txData, method })
38
- addPriorityFeeToTransaction({ transaction, feeAmount })
51
+
52
+ addPriorityFeeToTransaction({ transaction, feeAmount, fixedFee })
53
+
39
54
  if (!transaction.feePayer) {
40
55
  transaction.feePayer = new PublicKey(from)
41
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
- })