@sentio/sdk 2.25.0-rc.1 → 2.25.0-rc.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.
Files changed (30) hide show
  1. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js +23 -23
  2. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js.map +1 -1
  3. package/lib/eth/builtin/internal/erc1155-processor.js +8 -8
  4. package/lib/eth/builtin/internal/erc1155-processor.js.map +1 -1
  5. package/lib/eth/builtin/internal/erc20-processor.js +18 -18
  6. package/lib/eth/builtin/internal/erc20-processor.js.map +1 -1
  7. package/lib/eth/builtin/internal/erc20bytes-processor.js +9 -9
  8. package/lib/eth/builtin/internal/erc20bytes-processor.js.map +1 -1
  9. package/lib/eth/builtin/internal/erc721-processor.js +14 -14
  10. package/lib/eth/builtin/internal/erc721-processor.js.map +1 -1
  11. package/lib/eth/builtin/internal/weth9-processor.js +11 -11
  12. package/lib/eth/builtin/internal/weth9-processor.js.map +1 -1
  13. package/lib/eth/codegen/function-calls.js +5 -5
  14. package/lib/eth/codegen/function-calls.js.map +1 -1
  15. package/lib/eth/provider.d.ts.map +1 -1
  16. package/lib/eth/provider.js +4 -1
  17. package/lib/eth/provider.js.map +1 -1
  18. package/lib/utils/price.d.ts.map +1 -1
  19. package/lib/utils/price.js +8 -5
  20. package/lib/utils/price.js.map +1 -1
  21. package/package.json +4 -3
  22. package/src/eth/builtin/internal/eacaggregatorproxy-processor.ts +23 -23
  23. package/src/eth/builtin/internal/erc1155-processor.ts +8 -8
  24. package/src/eth/builtin/internal/erc20-processor.ts +18 -18
  25. package/src/eth/builtin/internal/erc20bytes-processor.ts +9 -9
  26. package/src/eth/builtin/internal/erc721-processor.ts +14 -14
  27. package/src/eth/builtin/internal/weth9-processor.ts +11 -11
  28. package/src/eth/codegen/function-calls.ts +9 -9
  29. package/src/eth/provider.ts +6 -3
  30. package/src/utils/price.ts +13 -10
@@ -112,49 +112,49 @@ export class WETH9ContractView extends ContractView<WETH9> {
112
112
  }
113
113
 
114
114
  async name(overrides?: Overrides): Promise<string> {
115
- const stack = new Error().stack;
116
115
  try {
117
116
  return await this.contract.getFunction("name()")(overrides || {});
118
117
  } catch (e) {
118
+ const stack = new Error().stack;
119
119
  throw transformEtherError(e, undefined, stack);
120
120
  }
121
121
  }
122
122
 
123
123
  async totalSupply(overrides?: Overrides): Promise<bigint> {
124
- const stack = new Error().stack;
125
124
  try {
126
125
  return await this.contract.getFunction("totalSupply()")(overrides || {});
127
126
  } catch (e) {
127
+ const stack = new Error().stack;
128
128
  throw transformEtherError(e, undefined, stack);
129
129
  }
130
130
  }
131
131
 
132
132
  async decimals(overrides?: Overrides): Promise<bigint> {
133
- const stack = new Error().stack;
134
133
  try {
135
134
  return await this.contract.getFunction("decimals()")(overrides || {});
136
135
  } catch (e) {
136
+ const stack = new Error().stack;
137
137
  throw transformEtherError(e, undefined, stack);
138
138
  }
139
139
  }
140
140
 
141
141
  async balanceOf(arg0: string, overrides?: Overrides): Promise<bigint> {
142
- const stack = new Error().stack;
143
142
  try {
144
143
  return await this.contract.getFunction("balanceOf(address)")(
145
144
  arg0,
146
145
  overrides || {}
147
146
  );
148
147
  } catch (e) {
148
+ const stack = new Error().stack;
149
149
  throw transformEtherError(e, undefined, stack);
150
150
  }
151
151
  }
152
152
 
153
153
  async symbol(overrides?: Overrides): Promise<string> {
154
- const stack = new Error().stack;
155
154
  try {
156
155
  return await this.contract.getFunction("symbol()")(overrides || {});
157
156
  } catch (e) {
157
+ const stack = new Error().stack;
158
158
  throw transformEtherError(e, undefined, stack);
159
159
  }
160
160
  }
@@ -164,7 +164,6 @@ export class WETH9ContractView extends ContractView<WETH9> {
164
164
  arg1: string,
165
165
  overrides?: Overrides
166
166
  ): Promise<bigint> {
167
- const stack = new Error().stack;
168
167
  try {
169
168
  return await this.contract.getFunction("allowance(address,address)")(
170
169
  arg0,
@@ -172,6 +171,7 @@ export class WETH9ContractView extends ContractView<WETH9> {
172
171
  overrides || {}
173
172
  );
174
173
  } catch (e) {
174
+ const stack = new Error().stack;
175
175
  throw transformEtherError(e, undefined, stack);
176
176
  }
177
177
  }
@@ -184,12 +184,12 @@ export class WETH9ContractView extends ContractView<WETH9> {
184
184
  wad: BigNumberish,
185
185
  overrides?: Overrides
186
186
  ): Promise<boolean> {
187
- const stack = new Error().stack;
188
187
  try {
189
188
  return await this.contract
190
189
  .getFunction("approve(address,uint256)")
191
190
  .staticCall(guy, wad, overrides || {});
192
191
  } catch (e) {
192
+ const stack = new Error().stack;
193
193
  throw transformEtherError(e, undefined, stack);
194
194
  }
195
195
  },
@@ -199,22 +199,22 @@ export class WETH9ContractView extends ContractView<WETH9> {
199
199
  wad: BigNumberish,
200
200
  overrides?: Overrides
201
201
  ): Promise<boolean> {
202
- const stack = new Error().stack;
203
202
  try {
204
203
  return await this.contract
205
204
  .getFunction("transferFrom(address,address,uint256)")
206
205
  .staticCall(src, dst, wad, overrides || {});
207
206
  } catch (e) {
207
+ const stack = new Error().stack;
208
208
  throw transformEtherError(e, undefined, stack);
209
209
  }
210
210
  },
211
211
  async withdraw(wad: BigNumberish, overrides?: Overrides): Promise<void> {
212
- const stack = new Error().stack;
213
212
  try {
214
213
  return await this.contract
215
214
  .getFunction("withdraw(uint256)")
216
215
  .staticCall(wad, overrides || {});
217
216
  } catch (e) {
217
+ const stack = new Error().stack;
218
218
  throw transformEtherError(e, undefined, stack);
219
219
  }
220
220
  },
@@ -223,22 +223,22 @@ export class WETH9ContractView extends ContractView<WETH9> {
223
223
  wad: BigNumberish,
224
224
  overrides?: Overrides
225
225
  ): Promise<boolean> {
226
- const stack = new Error().stack;
227
226
  try {
228
227
  return await this.contract
229
228
  .getFunction("transfer(address,uint256)")
230
229
  .staticCall(dst, wad, overrides || {});
231
230
  } catch (e) {
231
+ const stack = new Error().stack;
232
232
  throw transformEtherError(e, undefined, stack);
233
233
  }
234
234
  },
235
235
  async deposit(overrides?: Overrides): Promise<void> {
236
- const stack = new Error().stack;
237
236
  try {
238
237
  return await this.contract
239
238
  .getFunction("deposit()")
240
239
  .staticCall(overrides || {});
241
240
  } catch (e) {
241
+ const stack = new Error().stack;
242
242
  throw transformEtherError(e, undefined, stack);
243
243
  }
244
244
  },
@@ -33,18 +33,18 @@ export function generateViewFunction(view: boolean, fn: FunctionDeclaration, inc
33
33
  return [
34
34
  `
35
35
  async ${declName}(${generateInputTypes(fn.inputs, {
36
- useStructs: true,
37
- })}overrides?: Overrides): ${generateReturnTypes(fn)} {
38
- const stack = new Error().stack
36
+ useStructs: true
37
+ })}overrides?: Overrides): ${generateReturnTypes(fn)} {
39
38
  try {
40
39
  return await ${func}${call}(${
41
- fn.inputs.length > 0 ? fn.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''
42
- } overrides || {})
40
+ fn.inputs.length > 0 ? fn.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''
41
+ } overrides || {})
43
42
  } catch (e) {
43
+ const stack = new Error().stack
44
44
  throw transformEtherError(e, undefined, stack)
45
45
  }
46
46
  }
47
- `,
47
+ `
48
48
  ]
49
49
  }
50
50
 
@@ -65,8 +65,8 @@ export function generateBoundViewFunction(view: boolean, fn: FunctionDeclaration
65
65
  return [
66
66
  `
67
67
  async ${declName ?? fn.name}(${generateInputTypes(fn.inputs, {
68
- useStructs: true,
69
- })}overrides?: Overrides): ${generateReturnTypes(fn)} {
68
+ useStructs: true
69
+ })}overrides?: Overrides): ${generateReturnTypes(fn)} {
70
70
  return await this.${qualifier}.${declName}(${
71
71
  fn.inputs.length > 0 ? fn.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''
72
72
  } {
@@ -74,6 +74,6 @@ export function generateBoundViewFunction(view: boolean, fn: FunctionDeclaration
74
74
  ...overrides
75
75
  })
76
76
  }
77
- `,
77
+ `
78
78
  ]
79
79
  }
@@ -3,6 +3,7 @@ import { JsonRpcProvider, Network, Provider } from 'ethers'
3
3
  import PQueue from 'p-queue'
4
4
  import { Endpoints } from '@sentio/runtime'
5
5
  import { EthChainId } from '@sentio/chain'
6
+ import { LRUCache } from 'lru-cache'
6
7
 
7
8
  export const DummyProvider = new JsonRpcProvider('', Network.from(1))
8
9
 
@@ -39,7 +40,7 @@ export function getProvider(chainId?: EthChainId): Provider {
39
40
  'Provider not found for chain ' +
40
41
  network.chainId +
41
42
  ', configured chains: ' +
42
- [...Endpoints.INSTANCE.chainServer.keys()].join(' '),
43
+ [...Endpoints.INSTANCE.chainServer.keys()].join(' ')
43
44
  )
44
45
  }
45
46
  provider = new QueuedStaticJsonRpcProvider(address, network, Endpoints.INSTANCE.concurrency)
@@ -71,7 +72,7 @@ function getTag(prefix: string, value: any): string {
71
72
  accum[key] = v[key]
72
73
  return accum
73
74
  },
74
- <any>{},
75
+ <any>{}
75
76
  )
76
77
  }
77
78
 
@@ -82,7 +83,9 @@ function getTag(prefix: string, value: any): string {
82
83
 
83
84
  class QueuedStaticJsonRpcProvider extends JsonRpcProvider {
84
85
  executor: PQueue
85
- #performCache = new Map<string, Promise<any>>()
86
+ #performCache = new LRUCache<string, Promise<any>>({
87
+ max: 10000
88
+ })
86
89
 
87
90
  constructor(url: string, network: Network, concurrency: number) {
88
91
  // TODO re-enable match when possible
@@ -4,6 +4,7 @@ import { prometheusClientMiddleware } from 'nice-grpc-prometheus'
4
4
  import { retryMiddleware, RetryOptions } from 'nice-grpc-client-middleware-retry'
5
5
  import { Endpoints } from '@sentio/runtime'
6
6
  import { ChainId } from '@sentio/chain'
7
+ import { LRUCache } from 'lru-cache'
7
8
 
8
9
  export function getPriceClient(address?: string) {
9
10
  if (!address) {
@@ -17,7 +18,9 @@ export function getPriceClient(address?: string) {
17
18
  .create(PriceServiceDefinition, channel)
18
19
  }
19
20
 
20
- const priceMap = new Map<string, Promise<number | undefined>>()
21
+ const priceMap = new LRUCache<string, Promise<number | undefined>>({
22
+ max: 100000
23
+ })
21
24
  let priceClient: PriceServiceClient<RetryOptions>
22
25
 
23
26
  interface PriceOptions {
@@ -34,7 +37,7 @@ export async function getPriceByTypeOrSymbolInternal(
34
37
  priceClient: PriceServiceClient<RetryOptions>,
35
38
  date: Date,
36
39
  coinId: CoinID,
37
- options?: PriceOptions,
40
+ options?: PriceOptions
38
41
  ): Promise<number | undefined> {
39
42
  const dateStr = dateString(date)
40
43
  const todayDateString = dateString(new Date())
@@ -53,12 +56,12 @@ export async function getPriceByTypeOrSymbolInternal(
53
56
  const response = priceClient.getPrice(
54
57
  {
55
58
  timestamp: date,
56
- coinId,
59
+ coinId
57
60
  },
58
61
  {
59
62
  retry: true,
60
- retryMaxAttempts: 5,
61
- },
63
+ retryMaxAttempts: 5
64
+ }
62
65
  )
63
66
  price = response
64
67
  .then((res) => {
@@ -107,17 +110,17 @@ export async function getPriceByType(
107
110
  chainId: ChainId,
108
111
  coinType: string,
109
112
  date: Date,
110
- options?: PriceOptions,
113
+ options?: PriceOptions
111
114
  ): Promise<number | undefined> {
112
115
  return getPriceByTypeOrSymbol(
113
116
  date,
114
117
  {
115
118
  address: {
116
119
  chain: chainId,
117
- address: coinType,
118
- },
120
+ address: coinType
121
+ }
119
122
  },
120
- options,
123
+ options
121
124
  )
122
125
  }
123
126
 
@@ -129,7 +132,7 @@ export async function getPriceByType(
129
132
  export async function getPriceBySymbol(
130
133
  symbol: string,
131
134
  date: Date,
132
- options?: PriceOptions,
135
+ options?: PriceOptions
133
136
  ): Promise<number | undefined> {
134
137
  return getPriceByTypeOrSymbol(date, { symbol }, options)
135
138
  }