@exodus/solana-api 3.9.3 → 3.10.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/CHANGELOG.md +24 -0
- package/package.json +2 -2
- package/src/account-state.js +2 -2
- package/src/connection.js +3 -3
- package/src/index.js +1 -1
- package/src/staking-provider-client.js +1 -1
- package/src/tx-log/solana-auto-withdraw-monitor.js +1 -1
- package/src/tx-send.js +1 -1
- package/src/tx-log/me-flagr.js +0 -18
- package/src/tx-log/me-solana-monitor.js +0 -132
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,30 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [3.10.0](https://github.com/ExodusMovement/assets/compare/@exodus/solana-api@3.9.4...@exodus/solana-api@3.10.0) (2024-08-08)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* move ME solana monitor to the ME codebase ([#3117](https://github.com/ExodusMovement/assets/issues/3117)) ([6e2b25c](https://github.com/ExodusMovement/assets/commit/6e2b25c15d5c43a775b0ab53792882f69aa5c30d))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Reverts
|
|
15
|
+
|
|
16
|
+
* Revert "chore: skip ws test" (#3078) ([072f542](https://github.com/ExodusMovement/assets/commit/072f542dbe1adca57703da680508bbf21b412e3a)), closes [#3078](https://github.com/ExodusMovement/assets/issues/3078)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
## [3.9.4](https://github.com/ExodusMovement/assets/compare/@exodus/solana-api@3.9.3...@exodus/solana-api@3.9.4) (2024-08-01)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Bug Fixes
|
|
24
|
+
|
|
25
|
+
* revert object.defineProperty usage ([#3056](https://github.com/ExodusMovement/assets/issues/3056)) ([493a486](https://github.com/ExodusMovement/assets/commit/493a4865ed07c816167b96a5d01ba0f154b077c8))
|
|
26
|
+
* SOL lint ([#2953](https://github.com/ExodusMovement/assets/issues/2953)) ([3f1b3b8](https://github.com/ExodusMovement/assets/commit/3f1b3b8c9a1544ca7d41ac883c06e465d6928b32))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
6
30
|
## [3.9.3](https://github.com/ExodusMovement/assets/compare/@exodus/solana-api@3.9.2...@exodus/solana-api@3.9.3) (2024-07-23)
|
|
7
31
|
|
|
8
32
|
**Note:** Version bump only for package @exodus/solana-api
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/solana-api",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.10.0",
|
|
4
4
|
"description": "Exodus internal Solana asset API wrapper",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@exodus/assets-testing": "^1.0.0",
|
|
48
48
|
"@solana/web3.js": "^1.91.8"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "101deb0e348677bb19d301df54c53557a64f80fe",
|
|
51
51
|
"bugs": {
|
|
52
52
|
"url": "https://github.com/ExodusMovement/assets/issues?q=is%3Aissue+is%3Aopen+label%3Asolana-api"
|
|
53
53
|
},
|
package/src/account-state.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { AccountState } from '@exodus/models'
|
|
2
1
|
import { assetsListToObject } from '@exodus/assets'
|
|
3
|
-
import { isString, reduce } from 'lodash'
|
|
4
2
|
import { isNumberUnit } from '@exodus/currency'
|
|
3
|
+
import { AccountState } from '@exodus/models'
|
|
4
|
+
import { isString, reduce } from 'lodash'
|
|
5
5
|
|
|
6
6
|
const parseBalance = (balance, asset) =>
|
|
7
7
|
!isNumberUnit(balance) && isString(balance) ? asset.currency.parse(balance) : balance
|
package/src/connection.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { WebSocket } from '@exodus/fetch'
|
|
2
|
+
import debugLogger from 'debug'
|
|
2
3
|
import delay from 'delay'
|
|
3
4
|
import lodash from 'lodash'
|
|
4
|
-
import debugLogger from 'debug'
|
|
5
|
-
import { WebSocket } from '@exodus/fetch'
|
|
6
5
|
import makeConcurrent from 'make-concurrent'
|
|
6
|
+
import ms from 'ms'
|
|
7
7
|
|
|
8
8
|
// WS subscriptions: https://docs.solana.com/developing/clients/jsonrpc-api#subscription-websocket
|
|
9
9
|
|
package/src/index.js
CHANGED
package/src/tx-send.js
CHANGED
|
@@ -2,8 +2,8 @@ import {
|
|
|
2
2
|
createUnsignedTx,
|
|
3
3
|
findAssociatedTokenAddress,
|
|
4
4
|
prepareForSigning,
|
|
5
|
-
TOKEN_PROGRAM_ID,
|
|
6
5
|
TOKEN_2022_PROGRAM_ID,
|
|
6
|
+
TOKEN_PROGRAM_ID,
|
|
7
7
|
} from '@exodus/solana-lib'
|
|
8
8
|
import { transactionToBase58 } from '@exodus/solana-lib/src/tx/common'
|
|
9
9
|
import assert from 'minimalistic-assert'
|
package/src/tx-log/me-flagr.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import wretch from 'wretch'
|
|
2
|
-
import urljoin from 'url-join'
|
|
3
|
-
|
|
4
|
-
const FLAGR_URL = 'https://flagr-w.magiceden.io/api/v1/evaluation'
|
|
5
|
-
|
|
6
|
-
const fetchFlagrEvaluation = async (wallet, flagKey) => {
|
|
7
|
-
const url = urljoin(FLAGR_URL)
|
|
8
|
-
const entityContext = { wallet }
|
|
9
|
-
|
|
10
|
-
try {
|
|
11
|
-
return await wretch(url).post({ entityContext, flagKey }).json()
|
|
12
|
-
} catch (error) {
|
|
13
|
-
console.error('Error fetching flagr:', error)
|
|
14
|
-
throw error
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export default fetchFlagrEvaluation
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import urljoin from 'url-join'
|
|
2
|
-
import wretch from 'wretch'
|
|
3
|
-
|
|
4
|
-
import fetchFlagrEvaluation from './me-flagr'
|
|
5
|
-
import { SolanaMonitor } from './solana-monitor'
|
|
6
|
-
|
|
7
|
-
const FLAGR_KEY = 'sol-balance-api'
|
|
8
|
-
const SOL_NATIVE = '11111111111111111111111111111111'
|
|
9
|
-
|
|
10
|
-
export class MeSolanaMonitor extends SolanaMonitor {
|
|
11
|
-
#extraHeaders
|
|
12
|
-
|
|
13
|
-
constructor(args) {
|
|
14
|
-
super(args)
|
|
15
|
-
this.useMeMonitor = false
|
|
16
|
-
this.#extraHeaders = args.extraHeaders
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
async startListener({ walletAccount }) {
|
|
20
|
-
const address = await this.aci.getReceiveAddress({
|
|
21
|
-
assetName: this.asset.name,
|
|
22
|
-
walletAccount,
|
|
23
|
-
useCache: true,
|
|
24
|
-
})
|
|
25
|
-
await this.initFlagr(address)
|
|
26
|
-
return super.startListener({ walletAccount })
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
request(path, contentType = 'application/json') {
|
|
30
|
-
return wretch(urljoin('https://api-mainnet.magiceden.io', path)).headers({
|
|
31
|
-
'Content-Type': contentType,
|
|
32
|
-
...this.#extraHeaders,
|
|
33
|
-
})
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async initFlagr(address) {
|
|
37
|
-
// If one of the user's SOL addresses is whitelisted, use the ME API
|
|
38
|
-
if (this.useMeMonitor) return
|
|
39
|
-
try {
|
|
40
|
-
const response = await fetchFlagrEvaluation(address, FLAGR_KEY)
|
|
41
|
-
if (response.variantKey === 'on') {
|
|
42
|
-
this.useMeMonitor = true
|
|
43
|
-
}
|
|
44
|
-
} catch (error) {
|
|
45
|
-
console.error('Failed to fetch useMeMonitor config:', error)
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
getTokens() {
|
|
50
|
-
return this.api.tokens
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
isStakingEnabled() {
|
|
54
|
-
return !this.useMeMonitor
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async getAccountsAndBalances({ refresh, address, accountState, walletAccount }) {
|
|
58
|
-
if (!this.useMeMonitor) {
|
|
59
|
-
return super.getAccountsAndBalances({ refresh, address, accountState, walletAccount })
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const tokens = this.getTokens()
|
|
63
|
-
const body = [
|
|
64
|
-
{
|
|
65
|
-
address,
|
|
66
|
-
chain: 'solana',
|
|
67
|
-
},
|
|
68
|
-
]
|
|
69
|
-
|
|
70
|
-
const { balances } = await this.request('v1/wallet/balances/fungible').post(body).json()
|
|
71
|
-
const metadata = new Map()
|
|
72
|
-
|
|
73
|
-
const account = {
|
|
74
|
-
balance: this.asset.currency.ZERO,
|
|
75
|
-
tokenBalances: Object.create(null),
|
|
76
|
-
}
|
|
77
|
-
const tokenAccounts = []
|
|
78
|
-
|
|
79
|
-
balances.forEach((assetBalance) => {
|
|
80
|
-
const { asset: assetData, balance } = assetBalance
|
|
81
|
-
const mintAddress = assetData.mintAddress
|
|
82
|
-
|
|
83
|
-
if (assetBalance.asset?.id) {
|
|
84
|
-
metadata.set(assetBalance.asset.id, { imageURL: assetBalance.image })
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (mintAddress === SOL_NATIVE) {
|
|
88
|
-
// SOL balance
|
|
89
|
-
account.balance = this.asset.currency.baseUnit(balance.rawBalance)
|
|
90
|
-
} else {
|
|
91
|
-
// Fungible token balances
|
|
92
|
-
const token = tokens.get(mintAddress) || {
|
|
93
|
-
// name here is the exodus unique identifier not the display name
|
|
94
|
-
name: 'unknown',
|
|
95
|
-
ticker: assetData.symbol,
|
|
96
|
-
decimals: balance.decimals,
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (tokens.get(mintAddress)) {
|
|
100
|
-
const tokenKey = token.name
|
|
101
|
-
Object.defineProperty(account.tokenBalances, tokenKey, {
|
|
102
|
-
value: token.currency.baseUnit(balance.rawBalance),
|
|
103
|
-
})
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const tokenAccount = {
|
|
107
|
-
tokenAccountAddress: assetData.tokenAccount,
|
|
108
|
-
owner: assetBalance.owner,
|
|
109
|
-
tokenName: token.name,
|
|
110
|
-
ticker: token.ticker,
|
|
111
|
-
balance: assetBalance.balance.rawBalance,
|
|
112
|
-
mintAddress,
|
|
113
|
-
tokenProgram: assetData.tokenProgram,
|
|
114
|
-
decimals: token.decimals,
|
|
115
|
-
feeBasisPoints: assetData.feeBasisPoints ?? 0,
|
|
116
|
-
maximumFee: assetData.maximumFee ?? 0,
|
|
117
|
-
}
|
|
118
|
-
tokenAccounts.push(tokenAccount)
|
|
119
|
-
}
|
|
120
|
-
})
|
|
121
|
-
this.emit('token-metadata', { source: 'solana', metadata })
|
|
122
|
-
|
|
123
|
-
const fetchStakingInfo =
|
|
124
|
-
refresh || this.tickCount[walletAccount] % this.ticksBetweenStakeFetches === 0
|
|
125
|
-
const staking =
|
|
126
|
-
this.isStakingEnabled() && fetchStakingInfo
|
|
127
|
-
? await this.getStakingInfo({ address, walletAccount })
|
|
128
|
-
: { ...accountState.stakingInfo, staking: this.staking }
|
|
129
|
-
|
|
130
|
-
return { account, tokenAccounts, staking }
|
|
131
|
-
}
|
|
132
|
-
}
|