@exodus/solana-api 1.2.15 → 1.2.17
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 +4 -3
- package/src/index.js +49 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/solana-api",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.17",
|
|
4
4
|
"description": "Exodus internal Solana asset API wrapper",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -14,12 +14,13 @@
|
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@exodus/asset-json-rpc": "^1.0.0",
|
|
17
|
-
"@exodus/solana-lib": "^1.2.
|
|
17
|
+
"@exodus/solana-lib": "^1.2.16",
|
|
18
18
|
"lodash": "^4.17.11",
|
|
19
|
+
"url-join": "4.0.0",
|
|
19
20
|
"wretch": "^1.5.2"
|
|
20
21
|
},
|
|
21
22
|
"devDependencies": {
|
|
22
23
|
"node-fetch": "~1.6.3"
|
|
23
24
|
},
|
|
24
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "6e6162c94eefd164c7dd63d039be60f790b37ced"
|
|
25
26
|
}
|
package/src/index.js
CHANGED
|
@@ -3,6 +3,8 @@ import createApi from '@exodus/asset-json-rpc'
|
|
|
3
3
|
import { tokens, SYSTEM_PROGRAM_ID, STAKE_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@exodus/solana-lib'
|
|
4
4
|
import assert from 'assert'
|
|
5
5
|
import lodash from 'lodash'
|
|
6
|
+
import urljoin from 'url-join'
|
|
7
|
+
import wretch, { Wretcher } from 'wretch'
|
|
6
8
|
|
|
7
9
|
// Doc: https://docs.solana.com/apps/jsonrpc-api
|
|
8
10
|
|
|
@@ -19,7 +21,13 @@ class Api {
|
|
|
19
21
|
this.api = createApi(this.rpcUrl)
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
|
|
24
|
+
request(path, contentType = 'application/json'): Wretcher {
|
|
25
|
+
return wretch(urljoin(this.rpcUrl, path)).headers({
|
|
26
|
+
'Content-type': contentType,
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async getEpochInfo(): number {
|
|
23
31
|
const { epoch } = await this.api.post({
|
|
24
32
|
method: 'getEpochInfo',
|
|
25
33
|
})
|
|
@@ -190,12 +198,15 @@ class Api {
|
|
|
190
198
|
staking: {
|
|
191
199
|
method: 'createAccountWithSeed',
|
|
192
200
|
seed: stakeTx.seed,
|
|
193
|
-
|
|
201
|
+
stakeAddresses: [stakeTx.newAccount],
|
|
194
202
|
stake: stakeTx.lamports,
|
|
195
203
|
},
|
|
196
204
|
}
|
|
197
205
|
} else if (stakeWithdraw) {
|
|
198
|
-
|
|
206
|
+
const stakeAccounts = lodash.map(
|
|
207
|
+
lodash.filter(instructions, { program: 'stake', type: 'withdraw' }),
|
|
208
|
+
'stakeAccount'
|
|
209
|
+
)
|
|
199
210
|
tx = {
|
|
200
211
|
owner: stakeWithdraw.withdrawAuthority,
|
|
201
212
|
from: stakeWithdraw.stakeAccount,
|
|
@@ -204,20 +215,24 @@ class Api {
|
|
|
204
215
|
fee,
|
|
205
216
|
staking: {
|
|
206
217
|
method: 'withdraw',
|
|
207
|
-
|
|
218
|
+
stakeAddresses: stakeAccounts,
|
|
208
219
|
stake: stakeWithdraw.lamports,
|
|
209
220
|
},
|
|
210
221
|
}
|
|
211
222
|
} else if (stakeUndelegate) {
|
|
223
|
+
const stakeAccounts = lodash.map(
|
|
224
|
+
lodash.filter(instructions, { program: 'stake', type: 'deactivate' }),
|
|
225
|
+
'stakeAccount'
|
|
226
|
+
)
|
|
212
227
|
tx = {
|
|
213
228
|
owner: stakeUndelegate.stakeAuthority,
|
|
214
229
|
from: stakeUndelegate.stakeAuthority,
|
|
215
|
-
to: stakeUndelegate.stakeAccount,
|
|
230
|
+
to: stakeUndelegate.stakeAccount, // obsolete
|
|
216
231
|
amount: 0,
|
|
217
232
|
fee,
|
|
218
233
|
staking: {
|
|
219
234
|
method: 'undelegate',
|
|
220
|
-
|
|
235
|
+
stakeAddresses: stakeAccounts,
|
|
221
236
|
},
|
|
222
237
|
}
|
|
223
238
|
} else {
|
|
@@ -287,14 +302,14 @@ class Api {
|
|
|
287
302
|
const mint = lodash.get(account, 'data.parsed.info.mint')
|
|
288
303
|
const token = tokens.find(({ mintAddress }) => mintAddress === mint) || {
|
|
289
304
|
tokenName: 'unknown',
|
|
290
|
-
|
|
305
|
+
ticker: 'UNKNOWN',
|
|
291
306
|
}
|
|
292
307
|
const balance = lodash.get(account, 'data.parsed.info.tokenAmount.amount', '0')
|
|
293
308
|
tokenAccounts.push({
|
|
294
309
|
tokenAccountAddress: pubkey,
|
|
295
310
|
owner: address,
|
|
296
311
|
tokenName: token.tokenName,
|
|
297
|
-
ticker: token.
|
|
312
|
+
ticker: token.ticker,
|
|
298
313
|
balance,
|
|
299
314
|
})
|
|
300
315
|
}
|
|
@@ -412,6 +427,32 @@ class Api {
|
|
|
412
427
|
return { accounts, totalStake, locked, withdrawable, pending }
|
|
413
428
|
}
|
|
414
429
|
|
|
430
|
+
async getInflationReward(stakingAddresses: Array, epoch: number) {
|
|
431
|
+
const rewards = await this.api.post({
|
|
432
|
+
method: 'getInflationReward',
|
|
433
|
+
params: [stakingAddresses, { epoch }],
|
|
434
|
+
})
|
|
435
|
+
|
|
436
|
+
return rewards
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
async getRewards(stakingAddresses = []) {
|
|
440
|
+
if (!stakingAddresses.length) return 0
|
|
441
|
+
|
|
442
|
+
const rewards = await this.request(`rewards?addresses=${stakingAddresses.join(',')}`)
|
|
443
|
+
.get()
|
|
444
|
+
.error(500, () => ({})) // addresses not found
|
|
445
|
+
.error(400, () => ({}))
|
|
446
|
+
.json()
|
|
447
|
+
|
|
448
|
+
// sum rewards for all addresses
|
|
449
|
+
const earnings = Object.values(rewards).reduce((total, x) => {
|
|
450
|
+
return total + x
|
|
451
|
+
}, 0)
|
|
452
|
+
|
|
453
|
+
return earnings
|
|
454
|
+
}
|
|
455
|
+
|
|
415
456
|
/**
|
|
416
457
|
* Broadcast a signed transaction
|
|
417
458
|
*/
|