@exodus/solana-api 3.8.1 → 3.8.3
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
CHANGED
|
@@ -3,6 +3,22 @@
|
|
|
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.8.3](https://github.com/ExodusMovement/assets/compare/@exodus/solana-api@3.8.2...@exodus/solana-api@3.8.3) (2024-06-27)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @exodus/solana-api
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [3.8.2](https://github.com/ExodusMovement/assets/compare/@exodus/solana-api@3.8.1...@exodus/solana-api@3.8.2) (2024-06-27)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @exodus/solana-api
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
6
22
|
## [3.8.1](https://github.com/ExodusMovement/assets/compare/@exodus/solana-api@3.8.0...@exodus/solana-api@3.8.1) (2024-06-24)
|
|
7
23
|
|
|
8
24
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/solana-api",
|
|
3
|
-
"version": "3.8.
|
|
3
|
+
"version": "3.8.3",
|
|
4
4
|
"description": "Exodus internal Solana asset API wrapper",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"@exodus/simple-retry": "^0.0.6",
|
|
33
33
|
"@exodus/solana-lib": "^3.4.2",
|
|
34
34
|
"@exodus/solana-meta": "^1.0.7",
|
|
35
|
+
"@exodus/timer": "^1.0.0",
|
|
35
36
|
"bn.js": "^4.11.0",
|
|
36
37
|
"debug": "^4.1.1",
|
|
37
38
|
"delay": "^4.0.1",
|
|
@@ -46,7 +47,7 @@
|
|
|
46
47
|
"@exodus/assets-testing": "^1.0.0",
|
|
47
48
|
"@solana/web3.js": "^1.91.8"
|
|
48
49
|
},
|
|
49
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "8a78b9595437fd8fecc5b08916a98584eabde577",
|
|
50
51
|
"bugs": {
|
|
51
52
|
"url": "https://github.com/ExodusMovement/assets/issues?q=is%3Aissue+is%3Aopen+label%3Asolana-api"
|
|
52
53
|
},
|
package/src/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import assetsList from '@exodus/solana-meta'
|
|
|
5
5
|
import { Api } from './api'
|
|
6
6
|
|
|
7
7
|
export { default as SolanaFeeMonitor } from './fee-monitor'
|
|
8
|
-
export { SolanaMonitor } from './tx-log'
|
|
8
|
+
export { SolanaMonitor, SolanaAutoWithdrawMonitor } from './tx-log'
|
|
9
9
|
export { createAccountState } from './account-state'
|
|
10
10
|
export { getSolStakedFee, getStakingInfo, getUnstakingFee } from './staking-utils'
|
|
11
11
|
export {
|
package/src/tx-log/index.js
CHANGED
|
@@ -67,6 +67,13 @@ export class MeSolanaMonitor extends SolanaMonitor {
|
|
|
67
67
|
]
|
|
68
68
|
|
|
69
69
|
const { balances } = await this.request('v1/wallet/balances/fungible').post(body).json()
|
|
70
|
+
const metadata = new Map()
|
|
71
|
+
balances.forEach((balance) => {
|
|
72
|
+
if (balance.asset?.id) {
|
|
73
|
+
metadata.set(balance.asset.id, { imageURL: balance.image })
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
this.emit('token-metadata', { source: 'solana', metadata })
|
|
70
77
|
|
|
71
78
|
return balances
|
|
72
79
|
.filter((balance) => balance.asset.mintAddress !== SOL_NATIVE)
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Timer } from '@exodus/timer'
|
|
2
|
+
import { get } from 'lodash'
|
|
3
|
+
import ms from 'ms'
|
|
4
|
+
import assert from 'assert'
|
|
5
|
+
|
|
6
|
+
const INTERVAL = ms('30s')
|
|
7
|
+
|
|
8
|
+
export class SolanaAutoWithdrawMonitor {
|
|
9
|
+
constructor({ interval = INTERVAL, assetClientInterface, createAndSendStake }) {
|
|
10
|
+
this.assetName = 'solana'
|
|
11
|
+
this.timer = new Timer(interval)
|
|
12
|
+
this.aci = assetClientInterface
|
|
13
|
+
this.createAndSendStake = createAndSendStake
|
|
14
|
+
assert(typeof createAndSendStake === 'function', 'createAndSendStake is required')
|
|
15
|
+
this.cursors = {}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
start = async () => {
|
|
19
|
+
const assets = await this.aci.getAssetsForNetwork({ baseAssetName: this.assetName })
|
|
20
|
+
this.asset = assets[this.assetName]
|
|
21
|
+
await this.timer.start(() => this.tick())
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async tick() {
|
|
25
|
+
const walletAccounts = await this.aci.getWalletAccounts({ assetName: this.assetName })
|
|
26
|
+
await Promise.all(walletAccounts.map((walletAccount) => this._tick({ walletAccount })))
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async _tick({ walletAccount }) {
|
|
30
|
+
const accountState = await this.aci.getAccountState({
|
|
31
|
+
assetName: this.assetName,
|
|
32
|
+
walletAccount,
|
|
33
|
+
})
|
|
34
|
+
const { cursor, mem } = accountState
|
|
35
|
+
const { loaded, withdrawable } = mem
|
|
36
|
+
|
|
37
|
+
if (!Array.isArray(this.cursors[walletAccount])) this.cursors[walletAccount] = []
|
|
38
|
+
const cursorChanged = !this.cursors[walletAccount].includes(cursor)
|
|
39
|
+
|
|
40
|
+
if (loaded && cursorChanged && withdrawable.isPositive) {
|
|
41
|
+
this.cursors[walletAccount].push(cursor)
|
|
42
|
+
try {
|
|
43
|
+
const txIds = await this.tryWithdraw({ accountState, walletAccount })
|
|
44
|
+
this.cursors[walletAccount].push(...txIds)
|
|
45
|
+
} catch (e) {
|
|
46
|
+
console.log('solana auto withdraw error:', e)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async tryWithdraw({ accountState, walletAccount }) {
|
|
52
|
+
const stakingInfo = accountState.mem
|
|
53
|
+
const feeData = await this.aci.getFeeData({ assetName: this.assetName })
|
|
54
|
+
const fee = get(feeData, 'fee', this.asset.currency.ZERO)
|
|
55
|
+
|
|
56
|
+
const solBalance = get(accountState, 'balance', this.asset.currency.ZERO)
|
|
57
|
+
if (solBalance.lt(fee) || stakingInfo.withdrawable.isZero) return []
|
|
58
|
+
|
|
59
|
+
const promises = await this.createAndSendStake(
|
|
60
|
+
{
|
|
61
|
+
method: 'withdraw',
|
|
62
|
+
walletAccount,
|
|
63
|
+
amount: stakingInfo.withdrawable,
|
|
64
|
+
},
|
|
65
|
+
{ watchForTxConfirmation: false }
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
return Promise.all(promises)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/*
|
|
73
|
+
const _solanaAutoWithdrawMonitor = new SolanaAutoWithdrawMonitor({ interval: INTERVAL })
|
|
74
|
+
|
|
75
|
+
export const solanaAutoWithdrawMonitor = {
|
|
76
|
+
start:
|
|
77
|
+
({ assetClientInterface, createAndSendStake }) =>
|
|
78
|
+
async () =>
|
|
79
|
+
_solanaAutoWithdrawMonitor.start({ assetClientInterface, createAndSendStake }),
|
|
80
|
+
}
|
|
81
|
+
*/
|