@exodus/solana-api 3.29.2 → 3.29.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,14 @@
|
|
|
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.29.3](https://github.com/ExodusMovement/assets/compare/@exodus/solana-api@3.29.2...@exodus/solana-api@3.29.3) (2026-02-12)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @exodus/solana-api
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
## [3.29.2](https://github.com/ExodusMovement/assets/compare/@exodus/solana-api@3.29.1...@exodus/solana-api@3.29.2) (2026-02-11)
|
|
7
15
|
|
|
8
16
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/solana-api",
|
|
3
|
-
"version": "3.29.
|
|
3
|
+
"version": "3.29.3",
|
|
4
4
|
"description": "Transaction monitors, fee monitors, RPC with the blockchain node, and other networking code for Solana",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"@exodus/assets-testing": "^1.0.0",
|
|
50
50
|
"@exodus/solana-web3.js": "^1.63.1-exodus.9-rc3"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "970efdfe3384d11099816eb037bb46a77575dce4",
|
|
53
53
|
"bugs": {
|
|
54
54
|
"url": "https://github.com/ExodusMovement/assets/issues?q=is%3Aissue+is%3Aopen+label%3Asolana-api"
|
|
55
55
|
},
|
package/src/index.js
CHANGED
|
@@ -8,7 +8,6 @@ export { SolanaMonitor } from './tx-log/index.js'
|
|
|
8
8
|
export { SolanaClarityMonitor } from './tx-log/index.js'
|
|
9
9
|
export { SolanaWebsocketMonitor } from './tx-log/index.js'
|
|
10
10
|
export { createAccountState } from './account-state.js'
|
|
11
|
-
export { getStakingInfo } from './staking-utils.js'
|
|
12
11
|
export {
|
|
13
12
|
isSolanaStaking,
|
|
14
13
|
isSolanaUnstaking,
|
|
@@ -18,7 +17,7 @@ export {
|
|
|
18
17
|
export { createAndBroadcastTXFactory } from './tx-send.js'
|
|
19
18
|
export { getBalancesFactory } from './get-balances.js'
|
|
20
19
|
export { getFeeAsyncFactory } from './get-fees.js'
|
|
21
|
-
export {
|
|
20
|
+
export { stakingApiFactory, getStakingInfo } from './staking/index.js'
|
|
22
21
|
export { createTxFactory } from './create-unsigned-tx-for-send.js'
|
|
23
22
|
export { feePayerClientFactory } from './fee-payer.js'
|
|
24
23
|
export { createInitAgentWalletFactory } from './init-agent-wallet.js'
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import chunk from 'lodash/chunk.js'
|
|
2
|
+
|
|
3
|
+
import { getStakingInfo } from '../staking-utils.js'
|
|
4
|
+
import { stakingProviderClientFactory } from './staking-provider-client.js'
|
|
5
|
+
|
|
6
|
+
export { getStakingInfo } from '../staking-utils.js'
|
|
7
|
+
|
|
8
|
+
export const stakingApiFactory = ({ asset, createTx, sendTx, stakingProviderClient }) => {
|
|
9
|
+
const stakingProvider = stakingProviderClient ?? stakingProviderClientFactory()
|
|
10
|
+
|
|
11
|
+
async function sendStake({
|
|
12
|
+
address,
|
|
13
|
+
walletAccount,
|
|
14
|
+
method,
|
|
15
|
+
amount,
|
|
16
|
+
stakeAddresses,
|
|
17
|
+
accounts,
|
|
18
|
+
seed,
|
|
19
|
+
pool,
|
|
20
|
+
}) {
|
|
21
|
+
let error
|
|
22
|
+
let result
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
const { unsignedTx } = await createTx({
|
|
26
|
+
asset,
|
|
27
|
+
walletAccount,
|
|
28
|
+
fromAddress: address,
|
|
29
|
+
address,
|
|
30
|
+
amount: amount ?? asset.currency.ZERO,
|
|
31
|
+
method,
|
|
32
|
+
stakeAddresses,
|
|
33
|
+
accounts,
|
|
34
|
+
seed,
|
|
35
|
+
pool,
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
const sendResult = await sendTx({
|
|
39
|
+
asset,
|
|
40
|
+
walletAccount,
|
|
41
|
+
unsignedTx,
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
result = { txId: sendResult.txId }
|
|
45
|
+
} catch (err) {
|
|
46
|
+
error = err
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
const notifyMethod = {
|
|
51
|
+
delegate: 'notifyStaking',
|
|
52
|
+
withdraw: 'notifyWithdraw',
|
|
53
|
+
}
|
|
54
|
+
if (notifyMethod[method] && (error || result?.txId)) {
|
|
55
|
+
await stakingProvider[notifyMethod[method]]({
|
|
56
|
+
asset: asset.name,
|
|
57
|
+
txId: result?.txId ?? null,
|
|
58
|
+
delegator: address,
|
|
59
|
+
amount: amount?.toBaseString?.({ unit: false }) ?? '0',
|
|
60
|
+
error,
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
} catch (e) {
|
|
64
|
+
console.error('Failed to notify staking service:', e)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return { error, result }
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function createAndSendStake({ method, address, amount, stakingInfo, walletAccount }) {
|
|
71
|
+
const txs = []
|
|
72
|
+
switch (method) {
|
|
73
|
+
case 'delegate': {
|
|
74
|
+
const seed = `exodus:${Date.now()}`
|
|
75
|
+
txs.push({
|
|
76
|
+
method: 'delegate',
|
|
77
|
+
address,
|
|
78
|
+
amount,
|
|
79
|
+
seed,
|
|
80
|
+
pool: stakingInfo.staking.pool,
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
break
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
case 'undelegate': {
|
|
87
|
+
const addresses = []
|
|
88
|
+
for (const [addr, info] of Object.entries(stakingInfo.accounts)) {
|
|
89
|
+
if (info.state === 'active' || info.state === 'activating') addresses.push(addr)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const N_UNDELEGATE_ADDR = 10
|
|
93
|
+
chunk(addresses, N_UNDELEGATE_ADDR).forEach((stakeAddresses) => {
|
|
94
|
+
txs.push({
|
|
95
|
+
method,
|
|
96
|
+
address,
|
|
97
|
+
amount: asset.currency.ZERO,
|
|
98
|
+
stakeAddresses,
|
|
99
|
+
})
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
break
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
case 'withdraw': {
|
|
106
|
+
const accounts = {}
|
|
107
|
+
for (const [addr, info] of Object.entries(stakingInfo.accounts)) {
|
|
108
|
+
if (info.state === 'inactive') accounts[addr] = info
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const N_WITHDRAW_ACCOUNTS = 10
|
|
112
|
+
chunk(Object.entries(accounts), N_WITHDRAW_ACCOUNTS).forEach((entries) => {
|
|
113
|
+
txs.push({
|
|
114
|
+
method,
|
|
115
|
+
address,
|
|
116
|
+
amount: asset.currency.ZERO,
|
|
117
|
+
accounts: Object.fromEntries(entries),
|
|
118
|
+
})
|
|
119
|
+
})
|
|
120
|
+
if (txs.length === 0) throw new Error('no funds to withdraw')
|
|
121
|
+
break
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
default: {
|
|
125
|
+
throw new Error('Unknown method')
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const txIds = []
|
|
130
|
+
for (const tx of txs) {
|
|
131
|
+
const { error, result } = await sendStake({
|
|
132
|
+
address,
|
|
133
|
+
walletAccount,
|
|
134
|
+
...tx,
|
|
135
|
+
})
|
|
136
|
+
if (error) throw error
|
|
137
|
+
|
|
138
|
+
txIds.push(result.txId)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return txIds
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async function delegate({ address, amount, stakingInfo, walletAccount }) {
|
|
145
|
+
return createAndSendStake({ method: 'delegate', address, amount, stakingInfo, walletAccount })
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
async function undelegate({ address, amount, stakingInfo, walletAccount }) {
|
|
149
|
+
return createAndSendStake({ method: 'undelegate', address, amount, stakingInfo, walletAccount })
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async function withdraw({ address, amount, stakingInfo, walletAccount }) {
|
|
153
|
+
return createAndSendStake({ method: 'withdraw', address, amount, stakingInfo, walletAccount })
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return {
|
|
157
|
+
stake: delegate,
|
|
158
|
+
unstake: undelegate,
|
|
159
|
+
claimUnstaked: withdraw,
|
|
160
|
+
getStakingInfo,
|
|
161
|
+
// Legacy names
|
|
162
|
+
createAndSendStake,
|
|
163
|
+
delegate,
|
|
164
|
+
undelegate,
|
|
165
|
+
withdraw,
|
|
166
|
+
}
|
|
167
|
+
}
|
|
File without changes
|