@exodus/ethereum-api 2.6.15 → 2.6.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.
package/LICENSE.md ADDED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/ethereum-api",
3
- "version": "2.6.15",
3
+ "version": "2.6.16",
4
4
  "description": "Ethereum Api",
5
5
  "main": "src/index.js",
6
6
  "author": "Exodus Movement, Inc.",
@@ -10,7 +10,7 @@
10
10
  "access": "restricted"
11
11
  },
12
12
  "dependencies": {
13
- "@exodus/ethereum-lib": "^2.10.8",
13
+ "@exodus/ethereum-lib": "^2.11.0",
14
14
  "@exodus/ethereumjs-util": "^7.1.0-exodus.6",
15
15
  "@exodus/simple-retry": "^0.0.6",
16
16
  "fetchival": "0.3.3",
@@ -19,5 +19,6 @@
19
19
  "url": "0.10.3",
20
20
  "url-join": "4.0.0",
21
21
  "ws": "6.1.0"
22
- }
22
+ },
23
+ "gitHead": "84627634686049aa4d88d8b631af006dba571bb9"
23
24
  }
@@ -48,6 +48,14 @@ export async function getTokenBalance({ asset, address }) {
48
48
  return balances?.confirmed?.[contractAddress] || '0'
49
49
  }
50
50
 
51
+ export async function getTokenBalanceFromNode({ asset, address }) {
52
+ if (!isEthereumLikeToken(asset)) throw new Error(`unsupported ETH-like token ${asset.name}`)
53
+ const server = getServer(asset)
54
+ const contractAddress = asset.contract.address.toLowerCase()
55
+ const balances = await server.balanceOf(address, contractAddress)
56
+ return balances?.confirmed?.[contractAddress] || '0'
57
+ }
58
+
51
59
  // Returns function for supplied asset
52
60
  export function sendRawTransaction(asset) {
53
61
  return getServer(asset).sendRawTransaction
@@ -4,6 +4,8 @@ import fetchival from 'fetchival'
4
4
  import ms from 'ms'
5
5
  import createWebSocket from './ws'
6
6
  import { retry } from '@exodus/simple-retry'
7
+ import { simpleErc20 } from '@exodus/solidity-contract'
8
+ import { bufferToHex } from '@exodus/ethereumjs-util'
7
9
 
8
10
  const RETRY_DELAYS = ['10s']
9
11
 
@@ -61,6 +63,22 @@ export function create(defaultURL) {
61
63
  return requestWithRetry('balance', { address, from: opts.startblock, to: opts.endblock })
62
64
  },
63
65
 
66
+ async balanceOf(address, tokenAddress, tag = 'latest') {
67
+ const contract = simpleErc20(tokenAddress)
68
+ const callData = contract.balanceOf.build(address)
69
+ const data = {
70
+ data: bufferToHex(callData),
71
+ to: tokenAddress,
72
+ tag,
73
+ }
74
+ const result = await retry(this.ethCall, { delayTimesMs: RETRY_DELAYS })(data)
75
+ return {
76
+ confirmed: {
77
+ [tokenAddress]: parseInt(result, 16),
78
+ },
79
+ }
80
+ },
81
+
64
82
  async getHistory(address, opts) {
65
83
  opts = { startblock: 'earliest', endblock: 'pending', limit: 1000, ...opts }
66
84
  return requestWithRetry('history', {