@sentio/sdk 1.7.21 → 1.8.0

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 (41) hide show
  1. package/lib/gen/processor/protos/processor.d.ts +80 -16
  2. package/lib/gen/processor/protos/processor.js +236 -19
  3. package/lib/gen/processor/protos/processor.js.map +1 -1
  4. package/lib/meter.js +1 -1
  5. package/lib/meter.js.map +1 -1
  6. package/lib/processor-runner.js +0 -2
  7. package/lib/processor-runner.js.map +1 -1
  8. package/lib/service.d.ts +2 -1
  9. package/lib/service.js +6 -1
  10. package/lib/service.js.map +1 -1
  11. package/lib/test/index.d.ts +1 -0
  12. package/lib/test/index.js +3 -1
  13. package/lib/test/index.js.map +1 -1
  14. package/lib/test/test-processor-server.d.ts +2 -1
  15. package/lib/test/test-processor-server.js +3 -0
  16. package/lib/test/test-processor-server.js.map +1 -1
  17. package/lib/test/test-provider.d.ts +1 -0
  18. package/lib/test/test-provider.js +25 -0
  19. package/lib/test/test-provider.js.map +1 -0
  20. package/lib/utils/chainmap.js +3 -3
  21. package/lib/utils/chainmap.js.map +1 -1
  22. package/lib/utils/erc20.d.ts +6 -1
  23. package/lib/utils/erc20.js +12 -1
  24. package/lib/utils/erc20.js.map +1 -1
  25. package/lib/utils/erc20.test.js +6 -11
  26. package/lib/utils/erc20.test.js.map +1 -1
  27. package/lib/utils/index.d.ts +1 -1
  28. package/lib/utils/index.js +3 -1
  29. package/lib/utils/index.js.map +1 -1
  30. package/package.json +1 -1
  31. package/src/gen/processor/protos/processor.ts +327 -32
  32. package/src/meter.ts +1 -1
  33. package/src/processor-runner.ts +0 -3
  34. package/src/service.ts +9 -1
  35. package/src/test/index.ts +1 -0
  36. package/src/test/test-processor-server.ts +6 -0
  37. package/src/test/test-provider.ts +25 -0
  38. package/src/utils/chainmap.ts +3 -3
  39. package/src/utils/erc20.test.ts +7 -12
  40. package/src/utils/erc20.ts +8 -2
  41. package/src/utils/index.ts +1 -1
@@ -1,19 +1,14 @@
1
- import { ProcessorState, setProvider } from '@sentio/sdk'
1
+ import { ProcessorState } from '@sentio/sdk'
2
2
  import { getERC20TokenInfo } from './erc20'
3
+ import { loadTestProvidersFromEnv } from '../test'
3
4
 
4
5
  describe('erc20 tests', () => {
5
- beforeAll(async () => {
6
- global.PROCESSOR_STATE = new ProcessorState()
6
+ global.PROCESSOR_STATE = new ProcessorState()
7
+ const haveProviders = loadTestProvidersFromEnv('1')
7
8
 
8
- setProvider({
9
- '1': {
10
- ChainID: '1',
11
- Https: ['https://eth-mainnet.alchemyapi.io/v2/Gk024pFA-64RaEPIawL40n__1esXJFb2'], // Use env
12
- },
13
- })
14
- })
9
+ const testIf = haveProviders ? test : test.skip
15
10
 
16
- test('test bytes32', async () => {
11
+ testIf('test bytes32', async () => {
17
12
  const info = await getERC20TokenInfo('0x9f8F72aA9304c8B593d555F12eF6589cC3A579A2')
18
13
 
19
14
  expect(info.decimal).toEqual(18)
@@ -21,7 +16,7 @@ describe('erc20 tests', () => {
21
16
  expect(info.name).toEqual('Maker')
22
17
  })
23
18
 
24
- test('test normal', async () => {
19
+ testIf('test normal', async () => {
25
20
  const info = await getERC20TokenInfo('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48')
26
21
 
27
22
  expect(info.decimal).toEqual(6)
@@ -7,12 +7,18 @@ import { BigDecimal } from '@sentio/sdk'
7
7
  import { toBigDecimal } from './convert'
8
8
  import { utils } from 'ethers'
9
9
 
10
- export interface TokenInfo {
10
+ export class TokenInfo {
11
11
  symbol: string
12
12
  name: string
13
13
  decimal: number
14
14
  }
15
15
 
16
+ export const NATIVE_ETH = {
17
+ symbol: 'ETH',
18
+ decimal: 18,
19
+ name: 'Native ETH',
20
+ }
21
+
16
22
  const TOKEN_INFOS = new Map<string, TokenInfo>()
17
23
 
18
24
  export async function getERC20TokenInfo(tokenAddress: string, chainId = 1): Promise<TokenInfo> {
@@ -41,7 +47,7 @@ export async function getERC20TokenInfo(tokenAddress: string, chainId = 1): Prom
41
47
  }
42
48
 
43
49
  const decimal = await contract.decimals()
44
- const info = { name, symbol, decimal }
50
+ const info: TokenInfo = { name, symbol, decimal }
45
51
  TOKEN_INFOS.set(key, info)
46
52
  return info
47
53
  } catch (e) {
@@ -1,3 +1,3 @@
1
1
  export { getChainName } from './chainmap'
2
2
  export { toBigDecimal, metricValueToNumberish } from './convert'
3
- export { getERC20TokenInfo, getER20NormalizedAmount } from './erc20'
3
+ export { getERC20TokenInfo, getER20NormalizedAmount, TokenInfo, NATIVE_ETH } from './erc20'