@imtbl/sdk 1.78.0 → 1.78.1-alpha.2

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 (59) hide show
  1. package/dist/{blockchain_data-DBsuvv16.js → blockchain_data-CCrmkpmb.js} +2 -2
  2. package/dist/blockchain_data.js +3 -3
  3. package/dist/browser/checkout/{AddTokensWidget-TbB4PmLW.js → AddTokensWidget-CJHVZYKa.js} +237 -555
  4. package/dist/browser/checkout/{BridgeWidget-BhrCocw2.js → BridgeWidget-vrDMhQ7B.js} +6 -7
  5. package/dist/browser/checkout/{CommerceWidget-Be5DHzdC.js → CommerceWidget-BBVjH3re.js} +13 -15
  6. package/dist/browser/checkout/{FeesBreakdown-Ck9YzdSC.js → FeesBreakdown-RbPq4LZ5.js} +1 -1
  7. package/dist/browser/checkout/OnRampWidget-kRHxPV03.js +293 -0
  8. package/dist/browser/checkout/{SaleWidget-BN4NOhbW.js → SaleWidget-BWGmufBb.js} +10 -169
  9. package/dist/browser/checkout/{SpendingCapHero-CPvvFrji.js → SpendingCapHero-BQPyAA3f.js} +1 -1
  10. package/dist/browser/checkout/SwapWidget-BkDWfX2L.js +1850 -0
  11. package/dist/browser/checkout/TokenImage--UlIO1EV.js +17 -0
  12. package/dist/browser/checkout/{TopUpView-B4EZHPvY.js → TopUpView-DfIlK_JP.js} +1 -1
  13. package/dist/browser/checkout/{WalletApproveHero--5umxYJp.js → WalletApproveHero-Dn9hGDpd.js} +3 -3
  14. package/dist/browser/checkout/{WalletWidget-DVqX_Zms.js → WalletWidget-DjloJyln.js} +3 -3
  15. package/dist/browser/checkout/{auto-track-B82Gtc5w.js → auto-track-BZe3xCSS.js} +1 -1
  16. package/dist/browser/checkout/{index-uoFT0va2.js → index-5sdrx8QH.js} +5717 -1990
  17. package/dist/browser/checkout/{index-Bkd29y5M.js → index-BTXdnsnp.js} +2 -2
  18. package/dist/browser/checkout/{index-CE6PQBKk.js → index-BYTs4Dxg.js} +1 -1
  19. package/dist/browser/checkout/{index-BsW6upSH.js → index-B_GTZhrN.js} +1 -1
  20. package/dist/browser/checkout/{index-C0AbsZnL.js → index-CH-rpelg.js} +1 -1
  21. package/dist/browser/checkout/{index-Ba4jcykl.js → index-CbDJaR9u.js} +1 -1
  22. package/dist/browser/checkout/{index-AFLAGIsQ.js → index-DZ8R1kKf.js} +1 -1
  23. package/dist/browser/checkout/{index-CwvzJ6GW.js → index-RqybJAdr.js} +1 -1
  24. package/dist/browser/checkout/{index.umd-DHRFESK1.js → index.umd-3Oyl4YBD.js} +1 -1
  25. package/dist/browser/checkout/sdk.js +4 -4
  26. package/dist/browser/checkout/{useInterval-DoDljSUa.js → useInterval-QM8R1U-I.js} +1 -1
  27. package/dist/browser/checkout/widgets-esm.js +1 -1
  28. package/dist/browser/checkout/widgets.js +8731 -7632
  29. package/dist/{checkout-BX4BMX31.js → checkout-DhYCToL4.js} +6 -6
  30. package/dist/checkout.js +5 -5
  31. package/dist/{config-d4_WLWVX.js → config-CNcw_kd-.js} +1 -1
  32. package/dist/config.js +1 -1
  33. package/dist/{index-BbCunE2k.js → index-9VxXSbmb.js} +3 -3
  34. package/dist/{index-BVC9tGIa.js → index-BPyEbnCx.js} +4 -4
  35. package/dist/{index-BFY7ef9q.js → index-Bcm7x5Hm.js} +1 -1
  36. package/dist/{index-BOa7TPFI.js → index-Cku7hAok.js} +1 -1
  37. package/dist/{index-Bd-KXMjV.js → index-D-n_UnH_.js} +1 -1
  38. package/dist/{index-Dvk4T7xM.js → index-Qorn6iz9.js} +1 -1
  39. package/dist/index.browser.js +4 -4
  40. package/dist/index.browser.js.map +1 -1
  41. package/dist/index.cjs +8 -8
  42. package/dist/index.js +14 -14
  43. package/dist/{minting_backend-DSYjNnIR.js → minting_backend-DYaWr25k.js} +3 -3
  44. package/dist/minting_backend.js +5 -5
  45. package/dist/{orderbook-y-wZqTX7.js → orderbook-Bi4JW2Y0.js} +1 -1
  46. package/dist/orderbook.js +2 -2
  47. package/dist/{passport-Hck6nDL8.js → passport-CoPDh6o5.js} +3 -3
  48. package/dist/passport.js +4 -4
  49. package/dist/version.json +1 -1
  50. package/dist/{webhook-ByqpJy1j.js → webhook-BWsWhUx9.js} +1 -1
  51. package/dist/webhook.js +2 -2
  52. package/dist/{x-U0dfyoEE.js → x-DYxIkc23.js} +3 -3
  53. package/dist/x.js +4 -4
  54. package/package.json +1 -1
  55. package/dist/browser/checkout/HandoverContent-DB23bXer.js +0 -23
  56. package/dist/browser/checkout/OnRampWidget-CqVk3g3X.js +0 -1635
  57. package/dist/browser/checkout/SwapWidget-CwFYyKSt.js +0 -1738
  58. package/dist/browser/checkout/TokenImage-BKsKixKT.js +0 -45
  59. package/dist/browser/checkout/index-Smb16jHM.js +0 -885
@@ -1,885 +0,0 @@
1
- import { cI as defineReadOnly, cJ as getStatic, cK as Signer, cL as Provider, cM as getAddress, cN as Logger, cO as getContractAddress, cP as Interface, cQ as shallowCopy, cR as VoidSigner, cS as Indexed, cT as deepCopy, cU as isHexString, cV as checkResultErrors, cW as resolveProperties, F as BigNumber, cX as accessListify, cY as arrayify } from './index-uoFT0va2.js';
2
-
3
- const version = "contracts/5.7.0";
4
-
5
- var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
6
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7
- return new (P || (P = Promise))(function (resolve, reject) {
8
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11
- step((generator = generator.apply(thisArg, _arguments || [])).next());
12
- });
13
- };
14
- const logger = new Logger(version);
15
- function resolveName(resolver, nameOrPromise) {
16
- return __awaiter(this, void 0, void 0, function* () {
17
- const name = yield nameOrPromise;
18
- if (typeof (name) !== "string") {
19
- logger.throwArgumentError("invalid address or ENS name", "name", name);
20
- }
21
- // If it is already an address, just use it (after adding checksum)
22
- try {
23
- return getAddress(name);
24
- }
25
- catch (error) { }
26
- if (!resolver) {
27
- logger.throwError("a provider or signer is needed to resolve ENS names", Logger.errors.UNSUPPORTED_OPERATION, {
28
- operation: "resolveName"
29
- });
30
- }
31
- const address = yield resolver.resolveName(name);
32
- if (address == null) {
33
- logger.throwArgumentError("resolver or addr is not configured for ENS name", "name", name);
34
- }
35
- return address;
36
- });
37
- }
38
- // Recursively replaces ENS names with promises to resolve the name and resolves all properties
39
- function resolveAddresses(resolver, value, paramType) {
40
- return __awaiter(this, void 0, void 0, function* () {
41
- if (Array.isArray(paramType)) {
42
- return yield Promise.all(paramType.map((paramType, index) => {
43
- return resolveAddresses(resolver, ((Array.isArray(value)) ? value[index] : value[paramType.name]), paramType);
44
- }));
45
- }
46
- if (paramType.type === "address") {
47
- return yield resolveName(resolver, value);
48
- }
49
- if (paramType.type === "tuple") {
50
- return yield resolveAddresses(resolver, value, paramType.components);
51
- }
52
- if (paramType.baseType === "array") {
53
- if (!Array.isArray(value)) {
54
- return Promise.reject(logger.makeError("invalid value for array", Logger.errors.INVALID_ARGUMENT, {
55
- argument: "value",
56
- value
57
- }));
58
- }
59
- return yield Promise.all(value.map((v) => resolveAddresses(resolver, v, paramType.arrayChildren)));
60
- }
61
- return value;
62
- });
63
- }
64
- function populateTransaction(contract, fragment, args) {
65
- return __awaiter(this, void 0, void 0, function* () {
66
- // If an extra argument is given, it is overrides
67
- let overrides = {};
68
- if (args.length === fragment.inputs.length + 1 && typeof (args[args.length - 1]) === "object") {
69
- overrides = shallowCopy(args.pop());
70
- }
71
- // Make sure the parameter count matches
72
- logger.checkArgumentCount(args.length, fragment.inputs.length, "passed to contract");
73
- // Populate "from" override (allow promises)
74
- if (contract.signer) {
75
- if (overrides.from) {
76
- // Contracts with a Signer are from the Signer's frame-of-reference;
77
- // but we allow overriding "from" if it matches the signer
78
- overrides.from = resolveProperties({
79
- override: resolveName(contract.signer, overrides.from),
80
- signer: contract.signer.getAddress()
81
- }).then((check) => __awaiter(this, void 0, void 0, function* () {
82
- if (getAddress(check.signer) !== check.override) {
83
- logger.throwError("Contract with a Signer cannot override from", Logger.errors.UNSUPPORTED_OPERATION, {
84
- operation: "overrides.from"
85
- });
86
- }
87
- return check.override;
88
- }));
89
- }
90
- else {
91
- overrides.from = contract.signer.getAddress();
92
- }
93
- }
94
- else if (overrides.from) {
95
- overrides.from = resolveName(contract.provider, overrides.from);
96
- //} else {
97
- // Contracts without a signer can override "from", and if
98
- // unspecified the zero address is used
99
- //overrides.from = AddressZero;
100
- }
101
- // Wait for all dependencies to be resolved (prefer the signer over the provider)
102
- const resolved = yield resolveProperties({
103
- args: resolveAddresses(contract.signer || contract.provider, args, fragment.inputs),
104
- address: contract.resolvedAddress,
105
- overrides: (resolveProperties(overrides) || {})
106
- });
107
- // The ABI coded transaction
108
- const data = contract.interface.encodeFunctionData(fragment, resolved.args);
109
- const tx = {
110
- data: data,
111
- to: resolved.address
112
- };
113
- // Resolved Overrides
114
- const ro = resolved.overrides;
115
- // Populate simple overrides
116
- if (ro.nonce != null) {
117
- tx.nonce = BigNumber.from(ro.nonce).toNumber();
118
- }
119
- if (ro.gasLimit != null) {
120
- tx.gasLimit = BigNumber.from(ro.gasLimit);
121
- }
122
- if (ro.gasPrice != null) {
123
- tx.gasPrice = BigNumber.from(ro.gasPrice);
124
- }
125
- if (ro.maxFeePerGas != null) {
126
- tx.maxFeePerGas = BigNumber.from(ro.maxFeePerGas);
127
- }
128
- if (ro.maxPriorityFeePerGas != null) {
129
- tx.maxPriorityFeePerGas = BigNumber.from(ro.maxPriorityFeePerGas);
130
- }
131
- if (ro.from != null) {
132
- tx.from = ro.from;
133
- }
134
- if (ro.type != null) {
135
- tx.type = ro.type;
136
- }
137
- if (ro.accessList != null) {
138
- tx.accessList = accessListify(ro.accessList);
139
- }
140
- // If there was no "gasLimit" override, but the ABI specifies a default, use it
141
- if (tx.gasLimit == null && fragment.gas != null) {
142
- // Compute the intrinsic gas cost for this transaction
143
- // @TODO: This is based on the yellow paper as of Petersburg; this is something
144
- // we may wish to parameterize in v6 as part of the Network object. Since this
145
- // is always a non-nil to address, we can ignore G_create, but may wish to add
146
- // similar logic to the ContractFactory.
147
- let intrinsic = 21000;
148
- const bytes = arrayify(data);
149
- for (let i = 0; i < bytes.length; i++) {
150
- intrinsic += 4;
151
- if (bytes[i]) {
152
- intrinsic += 64;
153
- }
154
- }
155
- tx.gasLimit = BigNumber.from(fragment.gas).add(intrinsic);
156
- }
157
- // Populate "value" override
158
- if (ro.value) {
159
- const roValue = BigNumber.from(ro.value);
160
- if (!roValue.isZero() && !fragment.payable) {
161
- logger.throwError("non-payable method cannot override value", Logger.errors.UNSUPPORTED_OPERATION, {
162
- operation: "overrides.value",
163
- value: overrides.value
164
- });
165
- }
166
- tx.value = roValue;
167
- }
168
- if (ro.customData) {
169
- tx.customData = shallowCopy(ro.customData);
170
- }
171
- if (ro.ccipReadEnabled) {
172
- tx.ccipReadEnabled = !!ro.ccipReadEnabled;
173
- }
174
- // Remove the overrides
175
- delete overrides.nonce;
176
- delete overrides.gasLimit;
177
- delete overrides.gasPrice;
178
- delete overrides.from;
179
- delete overrides.value;
180
- delete overrides.type;
181
- delete overrides.accessList;
182
- delete overrides.maxFeePerGas;
183
- delete overrides.maxPriorityFeePerGas;
184
- delete overrides.customData;
185
- delete overrides.ccipReadEnabled;
186
- // Make sure there are no stray overrides, which may indicate a
187
- // typo or using an unsupported key.
188
- const leftovers = Object.keys(overrides).filter((key) => (overrides[key] != null));
189
- if (leftovers.length) {
190
- logger.throwError(`cannot override ${leftovers.map((l) => JSON.stringify(l)).join(",")}`, Logger.errors.UNSUPPORTED_OPERATION, {
191
- operation: "overrides",
192
- overrides: leftovers
193
- });
194
- }
195
- return tx;
196
- });
197
- }
198
- function buildPopulate(contract, fragment) {
199
- return function (...args) {
200
- return populateTransaction(contract, fragment, args);
201
- };
202
- }
203
- function buildEstimate(contract, fragment) {
204
- const signerOrProvider = (contract.signer || contract.provider);
205
- return function (...args) {
206
- return __awaiter(this, void 0, void 0, function* () {
207
- if (!signerOrProvider) {
208
- logger.throwError("estimate require a provider or signer", Logger.errors.UNSUPPORTED_OPERATION, {
209
- operation: "estimateGas"
210
- });
211
- }
212
- const tx = yield populateTransaction(contract, fragment, args);
213
- return yield signerOrProvider.estimateGas(tx);
214
- });
215
- };
216
- }
217
- function addContractWait(contract, tx) {
218
- const wait = tx.wait.bind(tx);
219
- tx.wait = (confirmations) => {
220
- return wait(confirmations).then((receipt) => {
221
- receipt.events = receipt.logs.map((log) => {
222
- let event = deepCopy(log);
223
- let parsed = null;
224
- try {
225
- parsed = contract.interface.parseLog(log);
226
- }
227
- catch (e) { }
228
- // Successfully parsed the event log; include it
229
- if (parsed) {
230
- event.args = parsed.args;
231
- event.decode = (data, topics) => {
232
- return contract.interface.decodeEventLog(parsed.eventFragment, data, topics);
233
- };
234
- event.event = parsed.name;
235
- event.eventSignature = parsed.signature;
236
- }
237
- // Useful operations
238
- event.removeListener = () => { return contract.provider; };
239
- event.getBlock = () => {
240
- return contract.provider.getBlock(receipt.blockHash);
241
- };
242
- event.getTransaction = () => {
243
- return contract.provider.getTransaction(receipt.transactionHash);
244
- };
245
- event.getTransactionReceipt = () => {
246
- return Promise.resolve(receipt);
247
- };
248
- return event;
249
- });
250
- return receipt;
251
- });
252
- };
253
- }
254
- function buildCall(contract, fragment, collapseSimple) {
255
- const signerOrProvider = (contract.signer || contract.provider);
256
- return function (...args) {
257
- return __awaiter(this, void 0, void 0, function* () {
258
- // Extract the "blockTag" override if present
259
- let blockTag = undefined;
260
- if (args.length === fragment.inputs.length + 1 && typeof (args[args.length - 1]) === "object") {
261
- const overrides = shallowCopy(args.pop());
262
- if (overrides.blockTag != null) {
263
- blockTag = yield overrides.blockTag;
264
- }
265
- delete overrides.blockTag;
266
- args.push(overrides);
267
- }
268
- // If the contract was just deployed, wait until it is mined
269
- if (contract.deployTransaction != null) {
270
- yield contract._deployed(blockTag);
271
- }
272
- // Call a node and get the result
273
- const tx = yield populateTransaction(contract, fragment, args);
274
- const result = yield signerOrProvider.call(tx, blockTag);
275
- try {
276
- let value = contract.interface.decodeFunctionResult(fragment, result);
277
- if (collapseSimple && fragment.outputs.length === 1) {
278
- value = value[0];
279
- }
280
- return value;
281
- }
282
- catch (error) {
283
- if (error.code === Logger.errors.CALL_EXCEPTION) {
284
- error.address = contract.address;
285
- error.args = args;
286
- error.transaction = tx;
287
- }
288
- throw error;
289
- }
290
- });
291
- };
292
- }
293
- function buildSend(contract, fragment) {
294
- return function (...args) {
295
- return __awaiter(this, void 0, void 0, function* () {
296
- if (!contract.signer) {
297
- logger.throwError("sending a transaction requires a signer", Logger.errors.UNSUPPORTED_OPERATION, {
298
- operation: "sendTransaction"
299
- });
300
- }
301
- // If the contract was just deployed, wait until it is mined
302
- if (contract.deployTransaction != null) {
303
- yield contract._deployed();
304
- }
305
- const txRequest = yield populateTransaction(contract, fragment, args);
306
- const tx = yield contract.signer.sendTransaction(txRequest);
307
- // Tweak the tx.wait so the receipt has extra properties
308
- addContractWait(contract, tx);
309
- return tx;
310
- });
311
- };
312
- }
313
- function buildDefault(contract, fragment, collapseSimple) {
314
- if (fragment.constant) {
315
- return buildCall(contract, fragment, collapseSimple);
316
- }
317
- return buildSend(contract, fragment);
318
- }
319
- function getEventTag(filter) {
320
- if (filter.address && (filter.topics == null || filter.topics.length === 0)) {
321
- return "*";
322
- }
323
- return (filter.address || "*") + "@" + (filter.topics ? filter.topics.map((topic) => {
324
- if (Array.isArray(topic)) {
325
- return topic.join("|");
326
- }
327
- return topic;
328
- }).join(":") : "");
329
- }
330
- class RunningEvent {
331
- constructor(tag, filter) {
332
- defineReadOnly(this, "tag", tag);
333
- defineReadOnly(this, "filter", filter);
334
- this._listeners = [];
335
- }
336
- addListener(listener, once) {
337
- this._listeners.push({ listener: listener, once: once });
338
- }
339
- removeListener(listener) {
340
- let done = false;
341
- this._listeners = this._listeners.filter((item) => {
342
- if (done || item.listener !== listener) {
343
- return true;
344
- }
345
- done = true;
346
- return false;
347
- });
348
- }
349
- removeAllListeners() {
350
- this._listeners = [];
351
- }
352
- listeners() {
353
- return this._listeners.map((i) => i.listener);
354
- }
355
- listenerCount() {
356
- return this._listeners.length;
357
- }
358
- run(args) {
359
- const listenerCount = this.listenerCount();
360
- this._listeners = this._listeners.filter((item) => {
361
- const argsCopy = args.slice();
362
- // Call the callback in the next event loop
363
- setTimeout(() => {
364
- item.listener.apply(this, argsCopy);
365
- }, 0);
366
- // Reschedule it if it not "once"
367
- return !(item.once);
368
- });
369
- return listenerCount;
370
- }
371
- prepareEvent(event) {
372
- }
373
- // Returns the array that will be applied to an emit
374
- getEmit(event) {
375
- return [event];
376
- }
377
- }
378
- class ErrorRunningEvent extends RunningEvent {
379
- constructor() {
380
- super("error", null);
381
- }
382
- }
383
- // @TODO Fragment should inherit Wildcard? and just override getEmit?
384
- // or have a common abstract super class, with enough constructor
385
- // options to configure both.
386
- // A Fragment Event will populate all the properties that Wildcard
387
- // will, and additionally dereference the arguments when emitting
388
- class FragmentRunningEvent extends RunningEvent {
389
- constructor(address, contractInterface, fragment, topics) {
390
- const filter = {
391
- address: address
392
- };
393
- let topic = contractInterface.getEventTopic(fragment);
394
- if (topics) {
395
- if (topic !== topics[0]) {
396
- logger.throwArgumentError("topic mismatch", "topics", topics);
397
- }
398
- filter.topics = topics.slice();
399
- }
400
- else {
401
- filter.topics = [topic];
402
- }
403
- super(getEventTag(filter), filter);
404
- defineReadOnly(this, "address", address);
405
- defineReadOnly(this, "interface", contractInterface);
406
- defineReadOnly(this, "fragment", fragment);
407
- }
408
- prepareEvent(event) {
409
- super.prepareEvent(event);
410
- event.event = this.fragment.name;
411
- event.eventSignature = this.fragment.format();
412
- event.decode = (data, topics) => {
413
- return this.interface.decodeEventLog(this.fragment, data, topics);
414
- };
415
- try {
416
- event.args = this.interface.decodeEventLog(this.fragment, event.data, event.topics);
417
- }
418
- catch (error) {
419
- event.args = null;
420
- event.decodeError = error;
421
- }
422
- }
423
- getEmit(event) {
424
- const errors = checkResultErrors(event.args);
425
- if (errors.length) {
426
- throw errors[0].error;
427
- }
428
- const args = (event.args || []).slice();
429
- args.push(event);
430
- return args;
431
- }
432
- }
433
- // A Wildcard Event will attempt to populate:
434
- // - event The name of the event name
435
- // - eventSignature The full signature of the event
436
- // - decode A function to decode data and topics
437
- // - args The decoded data and topics
438
- class WildcardRunningEvent extends RunningEvent {
439
- constructor(address, contractInterface) {
440
- super("*", { address: address });
441
- defineReadOnly(this, "address", address);
442
- defineReadOnly(this, "interface", contractInterface);
443
- }
444
- prepareEvent(event) {
445
- super.prepareEvent(event);
446
- try {
447
- const parsed = this.interface.parseLog(event);
448
- event.event = parsed.name;
449
- event.eventSignature = parsed.signature;
450
- event.decode = (data, topics) => {
451
- return this.interface.decodeEventLog(parsed.eventFragment, data, topics);
452
- };
453
- event.args = parsed.args;
454
- }
455
- catch (error) {
456
- // No matching event
457
- }
458
- }
459
- }
460
- class BaseContract {
461
- constructor(addressOrName, contractInterface, signerOrProvider) {
462
- // @TODO: Maybe still check the addressOrName looks like a valid address or name?
463
- //address = getAddress(address);
464
- defineReadOnly(this, "interface", getStatic(new.target, "getInterface")(contractInterface));
465
- if (signerOrProvider == null) {
466
- defineReadOnly(this, "provider", null);
467
- defineReadOnly(this, "signer", null);
468
- }
469
- else if (Signer.isSigner(signerOrProvider)) {
470
- defineReadOnly(this, "provider", signerOrProvider.provider || null);
471
- defineReadOnly(this, "signer", signerOrProvider);
472
- }
473
- else if (Provider.isProvider(signerOrProvider)) {
474
- defineReadOnly(this, "provider", signerOrProvider);
475
- defineReadOnly(this, "signer", null);
476
- }
477
- else {
478
- logger.throwArgumentError("invalid signer or provider", "signerOrProvider", signerOrProvider);
479
- }
480
- defineReadOnly(this, "callStatic", {});
481
- defineReadOnly(this, "estimateGas", {});
482
- defineReadOnly(this, "functions", {});
483
- defineReadOnly(this, "populateTransaction", {});
484
- defineReadOnly(this, "filters", {});
485
- {
486
- const uniqueFilters = {};
487
- Object.keys(this.interface.events).forEach((eventSignature) => {
488
- const event = this.interface.events[eventSignature];
489
- defineReadOnly(this.filters, eventSignature, (...args) => {
490
- return {
491
- address: this.address,
492
- topics: this.interface.encodeFilterTopics(event, args)
493
- };
494
- });
495
- if (!uniqueFilters[event.name]) {
496
- uniqueFilters[event.name] = [];
497
- }
498
- uniqueFilters[event.name].push(eventSignature);
499
- });
500
- Object.keys(uniqueFilters).forEach((name) => {
501
- const filters = uniqueFilters[name];
502
- if (filters.length === 1) {
503
- defineReadOnly(this.filters, name, this.filters[filters[0]]);
504
- }
505
- else {
506
- logger.warn(`Duplicate definition of ${name} (${filters.join(", ")})`);
507
- }
508
- });
509
- }
510
- defineReadOnly(this, "_runningEvents", {});
511
- defineReadOnly(this, "_wrappedEmits", {});
512
- if (addressOrName == null) {
513
- logger.throwArgumentError("invalid contract address or ENS name", "addressOrName", addressOrName);
514
- }
515
- defineReadOnly(this, "address", addressOrName);
516
- if (this.provider) {
517
- defineReadOnly(this, "resolvedAddress", resolveName(this.provider, addressOrName));
518
- }
519
- else {
520
- try {
521
- defineReadOnly(this, "resolvedAddress", Promise.resolve(getAddress(addressOrName)));
522
- }
523
- catch (error) {
524
- // Without a provider, we cannot use ENS names
525
- logger.throwError("provider is required to use ENS name as contract address", Logger.errors.UNSUPPORTED_OPERATION, {
526
- operation: "new Contract"
527
- });
528
- }
529
- }
530
- // Swallow bad ENS names to prevent Unhandled Exceptions
531
- this.resolvedAddress.catch((e) => { });
532
- const uniqueNames = {};
533
- const uniqueSignatures = {};
534
- Object.keys(this.interface.functions).forEach((signature) => {
535
- const fragment = this.interface.functions[signature];
536
- // Check that the signature is unique; if not the ABI generation has
537
- // not been cleaned or may be incorrectly generated
538
- if (uniqueSignatures[signature]) {
539
- logger.warn(`Duplicate ABI entry for ${JSON.stringify(signature)}`);
540
- return;
541
- }
542
- uniqueSignatures[signature] = true;
543
- // Track unique names; we only expose bare named functions if they
544
- // are ambiguous
545
- {
546
- const name = fragment.name;
547
- if (!uniqueNames[`%${name}`]) {
548
- uniqueNames[`%${name}`] = [];
549
- }
550
- uniqueNames[`%${name}`].push(signature);
551
- }
552
- if (this[signature] == null) {
553
- defineReadOnly(this, signature, buildDefault(this, fragment, true));
554
- }
555
- // We do not collapse simple calls on this bucket, which allows
556
- // frameworks to safely use this without introspection as well as
557
- // allows decoding error recovery.
558
- if (this.functions[signature] == null) {
559
- defineReadOnly(this.functions, signature, buildDefault(this, fragment, false));
560
- }
561
- if (this.callStatic[signature] == null) {
562
- defineReadOnly(this.callStatic, signature, buildCall(this, fragment, true));
563
- }
564
- if (this.populateTransaction[signature] == null) {
565
- defineReadOnly(this.populateTransaction, signature, buildPopulate(this, fragment));
566
- }
567
- if (this.estimateGas[signature] == null) {
568
- defineReadOnly(this.estimateGas, signature, buildEstimate(this, fragment));
569
- }
570
- });
571
- Object.keys(uniqueNames).forEach((name) => {
572
- // Ambiguous names to not get attached as bare names
573
- const signatures = uniqueNames[name];
574
- if (signatures.length > 1) {
575
- return;
576
- }
577
- // Strip off the leading "%" used for prototype protection
578
- name = name.substring(1);
579
- const signature = signatures[0];
580
- // If overwriting a member property that is null, swallow the error
581
- try {
582
- if (this[name] == null) {
583
- defineReadOnly(this, name, this[signature]);
584
- }
585
- }
586
- catch (e) { }
587
- if (this.functions[name] == null) {
588
- defineReadOnly(this.functions, name, this.functions[signature]);
589
- }
590
- if (this.callStatic[name] == null) {
591
- defineReadOnly(this.callStatic, name, this.callStatic[signature]);
592
- }
593
- if (this.populateTransaction[name] == null) {
594
- defineReadOnly(this.populateTransaction, name, this.populateTransaction[signature]);
595
- }
596
- if (this.estimateGas[name] == null) {
597
- defineReadOnly(this.estimateGas, name, this.estimateGas[signature]);
598
- }
599
- });
600
- }
601
- static getContractAddress(transaction) {
602
- return getContractAddress(transaction);
603
- }
604
- static getInterface(contractInterface) {
605
- if (Interface.isInterface(contractInterface)) {
606
- return contractInterface;
607
- }
608
- return new Interface(contractInterface);
609
- }
610
- // @TODO: Allow timeout?
611
- deployed() {
612
- return this._deployed();
613
- }
614
- _deployed(blockTag) {
615
- if (!this._deployedPromise) {
616
- // If we were just deployed, we know the transaction we should occur in
617
- if (this.deployTransaction) {
618
- this._deployedPromise = this.deployTransaction.wait().then(() => {
619
- return this;
620
- });
621
- }
622
- else {
623
- // @TODO: Once we allow a timeout to be passed in, we will wait
624
- // up to that many blocks for getCode
625
- // Otherwise, poll for our code to be deployed
626
- this._deployedPromise = this.provider.getCode(this.address, blockTag).then((code) => {
627
- if (code === "0x") {
628
- logger.throwError("contract not deployed", Logger.errors.UNSUPPORTED_OPERATION, {
629
- contractAddress: this.address,
630
- operation: "getDeployed"
631
- });
632
- }
633
- return this;
634
- });
635
- }
636
- }
637
- return this._deployedPromise;
638
- }
639
- // @TODO:
640
- // estimateFallback(overrides?: TransactionRequest): Promise<BigNumber>
641
- // @TODO:
642
- // estimateDeploy(bytecode: string, ...args): Promise<BigNumber>
643
- fallback(overrides) {
644
- if (!this.signer) {
645
- logger.throwError("sending a transactions require a signer", Logger.errors.UNSUPPORTED_OPERATION, { operation: "sendTransaction(fallback)" });
646
- }
647
- const tx = shallowCopy(overrides || {});
648
- ["from", "to"].forEach(function (key) {
649
- if (tx[key] == null) {
650
- return;
651
- }
652
- logger.throwError("cannot override " + key, Logger.errors.UNSUPPORTED_OPERATION, { operation: key });
653
- });
654
- tx.to = this.resolvedAddress;
655
- return this.deployed().then(() => {
656
- return this.signer.sendTransaction(tx);
657
- });
658
- }
659
- // Reconnect to a different signer or provider
660
- connect(signerOrProvider) {
661
- if (typeof (signerOrProvider) === "string") {
662
- signerOrProvider = new VoidSigner(signerOrProvider, this.provider);
663
- }
664
- const contract = new (this.constructor)(this.address, this.interface, signerOrProvider);
665
- if (this.deployTransaction) {
666
- defineReadOnly(contract, "deployTransaction", this.deployTransaction);
667
- }
668
- return contract;
669
- }
670
- // Re-attach to a different on-chain instance of this contract
671
- attach(addressOrName) {
672
- return new (this.constructor)(addressOrName, this.interface, this.signer || this.provider);
673
- }
674
- static isIndexed(value) {
675
- return Indexed.isIndexed(value);
676
- }
677
- _normalizeRunningEvent(runningEvent) {
678
- // Already have an instance of this event running; we can re-use it
679
- if (this._runningEvents[runningEvent.tag]) {
680
- return this._runningEvents[runningEvent.tag];
681
- }
682
- return runningEvent;
683
- }
684
- _getRunningEvent(eventName) {
685
- if (typeof (eventName) === "string") {
686
- // Listen for "error" events (if your contract has an error event, include
687
- // the full signature to bypass this special event keyword)
688
- if (eventName === "error") {
689
- return this._normalizeRunningEvent(new ErrorRunningEvent());
690
- }
691
- // Listen for any event that is registered
692
- if (eventName === "event") {
693
- return this._normalizeRunningEvent(new RunningEvent("event", null));
694
- }
695
- // Listen for any event
696
- if (eventName === "*") {
697
- return this._normalizeRunningEvent(new WildcardRunningEvent(this.address, this.interface));
698
- }
699
- // Get the event Fragment (throws if ambiguous/unknown event)
700
- const fragment = this.interface.getEvent(eventName);
701
- return this._normalizeRunningEvent(new FragmentRunningEvent(this.address, this.interface, fragment));
702
- }
703
- // We have topics to filter by...
704
- if (eventName.topics && eventName.topics.length > 0) {
705
- // Is it a known topichash? (throws if no matching topichash)
706
- try {
707
- const topic = eventName.topics[0];
708
- if (typeof (topic) !== "string") {
709
- throw new Error("invalid topic"); // @TODO: May happen for anonymous events
710
- }
711
- const fragment = this.interface.getEvent(topic);
712
- return this._normalizeRunningEvent(new FragmentRunningEvent(this.address, this.interface, fragment, eventName.topics));
713
- }
714
- catch (error) { }
715
- // Filter by the unknown topichash
716
- const filter = {
717
- address: this.address,
718
- topics: eventName.topics
719
- };
720
- return this._normalizeRunningEvent(new RunningEvent(getEventTag(filter), filter));
721
- }
722
- return this._normalizeRunningEvent(new WildcardRunningEvent(this.address, this.interface));
723
- }
724
- _checkRunningEvents(runningEvent) {
725
- if (runningEvent.listenerCount() === 0) {
726
- delete this._runningEvents[runningEvent.tag];
727
- // If we have a poller for this, remove it
728
- const emit = this._wrappedEmits[runningEvent.tag];
729
- if (emit && runningEvent.filter) {
730
- this.provider.off(runningEvent.filter, emit);
731
- delete this._wrappedEmits[runningEvent.tag];
732
- }
733
- }
734
- }
735
- // Subclasses can override this to gracefully recover
736
- // from parse errors if they wish
737
- _wrapEvent(runningEvent, log, listener) {
738
- const event = deepCopy(log);
739
- event.removeListener = () => {
740
- if (!listener) {
741
- return;
742
- }
743
- runningEvent.removeListener(listener);
744
- this._checkRunningEvents(runningEvent);
745
- };
746
- event.getBlock = () => { return this.provider.getBlock(log.blockHash); };
747
- event.getTransaction = () => { return this.provider.getTransaction(log.transactionHash); };
748
- event.getTransactionReceipt = () => { return this.provider.getTransactionReceipt(log.transactionHash); };
749
- // This may throw if the topics and data mismatch the signature
750
- runningEvent.prepareEvent(event);
751
- return event;
752
- }
753
- _addEventListener(runningEvent, listener, once) {
754
- if (!this.provider) {
755
- logger.throwError("events require a provider or a signer with a provider", Logger.errors.UNSUPPORTED_OPERATION, { operation: "once" });
756
- }
757
- runningEvent.addListener(listener, once);
758
- // Track this running event and its listeners (may already be there; but no hard in updating)
759
- this._runningEvents[runningEvent.tag] = runningEvent;
760
- // If we are not polling the provider, start polling
761
- if (!this._wrappedEmits[runningEvent.tag]) {
762
- const wrappedEmit = (log) => {
763
- let event = this._wrapEvent(runningEvent, log, listener);
764
- // Try to emit the result for the parameterized event...
765
- if (event.decodeError == null) {
766
- try {
767
- const args = runningEvent.getEmit(event);
768
- this.emit(runningEvent.filter, ...args);
769
- }
770
- catch (error) {
771
- event.decodeError = error.error;
772
- }
773
- }
774
- // Always emit "event" for fragment-base events
775
- if (runningEvent.filter != null) {
776
- this.emit("event", event);
777
- }
778
- // Emit "error" if there was an error
779
- if (event.decodeError != null) {
780
- this.emit("error", event.decodeError, event);
781
- }
782
- };
783
- this._wrappedEmits[runningEvent.tag] = wrappedEmit;
784
- // Special events, like "error" do not have a filter
785
- if (runningEvent.filter != null) {
786
- this.provider.on(runningEvent.filter, wrappedEmit);
787
- }
788
- }
789
- }
790
- queryFilter(event, fromBlockOrBlockhash, toBlock) {
791
- const runningEvent = this._getRunningEvent(event);
792
- const filter = shallowCopy(runningEvent.filter);
793
- if (typeof (fromBlockOrBlockhash) === "string" && isHexString(fromBlockOrBlockhash, 32)) {
794
- if (toBlock != null) {
795
- logger.throwArgumentError("cannot specify toBlock with blockhash", "toBlock", toBlock);
796
- }
797
- filter.blockHash = fromBlockOrBlockhash;
798
- }
799
- else {
800
- filter.fromBlock = ((fromBlockOrBlockhash != null) ? fromBlockOrBlockhash : 0);
801
- filter.toBlock = ((toBlock != null) ? toBlock : "latest");
802
- }
803
- return this.provider.getLogs(filter).then((logs) => {
804
- return logs.map((log) => this._wrapEvent(runningEvent, log, null));
805
- });
806
- }
807
- on(event, listener) {
808
- this._addEventListener(this._getRunningEvent(event), listener, false);
809
- return this;
810
- }
811
- once(event, listener) {
812
- this._addEventListener(this._getRunningEvent(event), listener, true);
813
- return this;
814
- }
815
- emit(eventName, ...args) {
816
- if (!this.provider) {
817
- return false;
818
- }
819
- const runningEvent = this._getRunningEvent(eventName);
820
- const result = (runningEvent.run(args) > 0);
821
- // May have drained all the "once" events; check for living events
822
- this._checkRunningEvents(runningEvent);
823
- return result;
824
- }
825
- listenerCount(eventName) {
826
- if (!this.provider) {
827
- return 0;
828
- }
829
- if (eventName == null) {
830
- return Object.keys(this._runningEvents).reduce((accum, key) => {
831
- return accum + this._runningEvents[key].listenerCount();
832
- }, 0);
833
- }
834
- return this._getRunningEvent(eventName).listenerCount();
835
- }
836
- listeners(eventName) {
837
- if (!this.provider) {
838
- return [];
839
- }
840
- if (eventName == null) {
841
- const result = [];
842
- for (let tag in this._runningEvents) {
843
- this._runningEvents[tag].listeners().forEach((listener) => {
844
- result.push(listener);
845
- });
846
- }
847
- return result;
848
- }
849
- return this._getRunningEvent(eventName).listeners();
850
- }
851
- removeAllListeners(eventName) {
852
- if (!this.provider) {
853
- return this;
854
- }
855
- if (eventName == null) {
856
- for (const tag in this._runningEvents) {
857
- const runningEvent = this._runningEvents[tag];
858
- runningEvent.removeAllListeners();
859
- this._checkRunningEvents(runningEvent);
860
- }
861
- return this;
862
- }
863
- // Delete any listeners
864
- const runningEvent = this._getRunningEvent(eventName);
865
- runningEvent.removeAllListeners();
866
- this._checkRunningEvents(runningEvent);
867
- return this;
868
- }
869
- off(eventName, listener) {
870
- if (!this.provider) {
871
- return this;
872
- }
873
- const runningEvent = this._getRunningEvent(eventName);
874
- runningEvent.removeListener(listener);
875
- this._checkRunningEvents(runningEvent);
876
- return this;
877
- }
878
- removeListener(eventName, listener) {
879
- return this.off(eventName, listener);
880
- }
881
- }
882
- class Contract extends BaseContract {
883
- }
884
-
885
- export { Contract as C };