@exodus/solana-api 1.2.15 → 1.2.16

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.
Files changed (2) hide show
  1. package/package.json +4 -3
  2. package/src/index.js +37 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/solana-api",
3
- "version": "1.2.15",
3
+ "version": "1.2.16",
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.13",
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": "6aa4ea58a169758d9c9471bf55ce060e113dd88c"
25
+ "gitHead": "882b8a97ef05cbd0fbd7da0b2ce457e0a0ae7e35"
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
- async getCurrentEpoch(): number {
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
  })
@@ -287,14 +295,14 @@ class Api {
287
295
  const mint = lodash.get(account, 'data.parsed.info.mint')
288
296
  const token = tokens.find(({ mintAddress }) => mintAddress === mint) || {
289
297
  tokenName: 'unknown',
290
- tokenSymbol: 'UNKNOWN',
298
+ ticker: 'UNKNOWN',
291
299
  }
292
300
  const balance = lodash.get(account, 'data.parsed.info.tokenAmount.amount', '0')
293
301
  tokenAccounts.push({
294
302
  tokenAccountAddress: pubkey,
295
303
  owner: address,
296
304
  tokenName: token.tokenName,
297
- ticker: token.tokenSymbol,
305
+ ticker: token.ticker,
298
306
  balance,
299
307
  })
300
308
  }
@@ -412,6 +420,32 @@ class Api {
412
420
  return { accounts, totalStake, locked, withdrawable, pending }
413
421
  }
414
422
 
423
+ async getInflationReward(stakingAddresses: Array, epoch: number) {
424
+ const rewards = await this.api.post({
425
+ method: 'getInflationReward',
426
+ params: [stakingAddresses, { epoch }],
427
+ })
428
+
429
+ return rewards
430
+ }
431
+
432
+ async getRewards(stakingAddresses = []) {
433
+ if (!stakingAddresses.length) return 0
434
+
435
+ const rewards = await this.request(`rewards?addresses=${stakingAddresses.join(',')}`)
436
+ .get()
437
+ .error(500, () => ({})) // addresses not found
438
+ .error(400, () => ({}))
439
+ .json()
440
+
441
+ // sum rewards for all addresses
442
+ const earnings = Object.values(rewards).reduce((total, x) => {
443
+ return total + x
444
+ }, 0)
445
+
446
+ return earnings
447
+ }
448
+
415
449
  /**
416
450
  * Broadcast a signed transaction
417
451
  */