dequanto 0.1.81 → 0.1.85

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 (61) hide show
  1. package/lib/cjs/blocks/BlockDateResolver.js +59 -23
  2. package/lib/cjs/blocks/BlockDateResolver.js.map +1 -1
  3. package/lib/cjs/contracts/deploy/proxy/$proxyDeploy.js +5 -1
  4. package/lib/cjs/contracts/deploy/proxy/$proxyDeploy.js.map +1 -1
  5. package/lib/cjs/erc4337/Erc4337Factory.js +0 -1
  6. package/lib/cjs/erc4337/Erc4337Factory.js.map +1 -1
  7. package/lib/cjs/prebuilt-factories/TimelockControllerFactory.js +251 -0
  8. package/lib/cjs/prebuilt-factories/TimelockControllerFactory.js.map +1 -0
  9. package/lib/cjs/services/TimelockService/TimelockService.js +24 -4
  10. package/lib/cjs/services/TimelockService/TimelockService.js.map +1 -1
  11. package/lib/cjs/txs/TxWriter.js +1 -1
  12. package/lib/cjs/txs/TxWriter.js.map +1 -1
  13. package/lib/cjs/txs/agents/TimelockAgent.js +90 -0
  14. package/lib/cjs/txs/agents/TimelockAgent.js.map +1 -0
  15. package/lib/cjs/txs/agents/TxWriterAccountAgents.js +2 -0
  16. package/lib/cjs/txs/agents/TxWriterAccountAgents.js.map +1 -1
  17. package/lib/cjs/utils/$account.js +17 -1
  18. package/lib/cjs/utils/$account.js.map +1 -1
  19. package/lib/cjs/utils/$date.js +11 -0
  20. package/lib/cjs/utils/$date.js.map +1 -1
  21. package/lib/esm/blocks/BlockDateResolver.js.map +1 -1
  22. package/lib/esm/blocks/BlockDateResolver.mjs +59 -23
  23. package/lib/esm/contracts/deploy/proxy/$proxyDeploy.js.map +1 -1
  24. package/lib/esm/contracts/deploy/proxy/$proxyDeploy.mjs +5 -1
  25. package/lib/esm/erc4337/Erc4337Factory.js.map +1 -1
  26. package/lib/esm/erc4337/Erc4337Factory.mjs +0 -1
  27. package/lib/esm/prebuilt-factories/TimelockControllerFactory.js.map +1 -0
  28. package/lib/esm/prebuilt-factories/TimelockControllerFactory.mjs +244 -0
  29. package/lib/esm/services/TimelockService/TimelockService.js.map +1 -1
  30. package/lib/esm/services/TimelockService/TimelockService.mjs +24 -4
  31. package/lib/esm/txs/TxWriter.js.map +1 -1
  32. package/lib/esm/txs/TxWriter.mjs +1 -1
  33. package/lib/esm/txs/agents/TimelockAgent.js.map +1 -0
  34. package/lib/esm/txs/agents/TimelockAgent.mjs +85 -0
  35. package/lib/esm/txs/agents/TxWriterAccountAgents.js.map +1 -1
  36. package/lib/esm/txs/agents/TxWriterAccountAgents.mjs +2 -0
  37. package/lib/esm/utils/$account.js.map +1 -1
  38. package/lib/esm/utils/$account.mjs +17 -1
  39. package/lib/esm/utils/$date.js.map +1 -1
  40. package/lib/esm/utils/$date.mjs +11 -0
  41. package/lib/types/blocks/BlockDateResolver.d.ts +7 -5
  42. package/lib/types/models/TAccount.d.ts +7 -1
  43. package/lib/types/prebuilt-factories/TimelockControllerFactory.d.ts +188 -0
  44. package/lib/types/services/TimelockService/TimelockService.d.ts +14 -3
  45. package/lib/types/txs/TxWriter.d.ts +20 -13
  46. package/lib/types/txs/agents/TimelockAgent.d.ts +26 -0
  47. package/lib/types/txs/agents/TxWriterAccountAgents.d.ts +2 -2
  48. package/lib/types/utils/$account.d.ts +2 -1
  49. package/lib/types/utils/$date.d.ts +1 -0
  50. package/package.json +1 -1
  51. package/src/blocks/BlockDateResolver.ts +61 -28
  52. package/src/contracts/deploy/proxy/$proxyDeploy.ts +5 -1
  53. package/src/erc4337/Erc4337Factory.ts +0 -2
  54. package/src/models/TAccount.ts +11 -1
  55. package/src/prebuilt-factories/TimelockControllerFactory.ts +582 -0
  56. package/src/services/TimelockService/TimelockService.ts +48 -8
  57. package/src/txs/TxWriter.ts +29 -17
  58. package/src/txs/agents/TimelockAgent.ts +116 -0
  59. package/src/txs/agents/TxWriterAccountAgents.ts +4 -2
  60. package/src/utils/$account.ts +18 -2
  61. package/src/utils/$date.ts +11 -1
@@ -0,0 +1,188 @@
1
+ import { TAddress } from '../models/TAddress';
2
+ import type { TEth } from '../models/TEth';
3
+ import type { TimelockController as TimelockControllerType } from '../prebuilt/openzeppelin/TimelockController';
4
+ export declare function TimelockControllerFactory(): typeof TimelockControllerType;
5
+ export type TTimelockControllerTypes = {
6
+ Events: {
7
+ CallExecuted: {
8
+ outputParams: {
9
+ id: TEth.Hex;
10
+ index: bigint;
11
+ target: TAddress;
12
+ value: bigint;
13
+ data: TEth.Hex;
14
+ };
15
+ outputArgs: [id: TEth.Hex, index: bigint, target: TAddress, value: bigint, data: TEth.Hex];
16
+ };
17
+ CallSalt: {
18
+ outputParams: {
19
+ id: TEth.Hex;
20
+ salt: TEth.Hex;
21
+ };
22
+ outputArgs: [id: TEth.Hex, salt: TEth.Hex];
23
+ };
24
+ CallScheduled: {
25
+ outputParams: {
26
+ id: TEth.Hex;
27
+ index: bigint;
28
+ target: TAddress;
29
+ value: bigint;
30
+ data: TEth.Hex;
31
+ predecessor: TEth.Hex;
32
+ delay: bigint;
33
+ };
34
+ outputArgs: [id: TEth.Hex, index: bigint, target: TAddress, value: bigint, data: TEth.Hex, predecessor: TEth.Hex, delay: bigint];
35
+ };
36
+ Cancelled: {
37
+ outputParams: {
38
+ id: TEth.Hex;
39
+ };
40
+ outputArgs: [id: TEth.Hex];
41
+ };
42
+ MinDelayChange: {
43
+ outputParams: {
44
+ oldDuration: bigint;
45
+ newDuration: bigint;
46
+ };
47
+ outputArgs: [oldDuration: bigint, newDuration: bigint];
48
+ };
49
+ RoleAdminChanged: {
50
+ outputParams: {
51
+ role: TEth.Hex;
52
+ previousAdminRole: TEth.Hex;
53
+ newAdminRole: TEth.Hex;
54
+ };
55
+ outputArgs: [role: TEth.Hex, previousAdminRole: TEth.Hex, newAdminRole: TEth.Hex];
56
+ };
57
+ RoleGranted: {
58
+ outputParams: {
59
+ role: TEth.Hex;
60
+ account: TAddress;
61
+ _sender: TAddress;
62
+ };
63
+ outputArgs: [role: TEth.Hex, account: TAddress, _sender: TAddress];
64
+ };
65
+ RoleRevoked: {
66
+ outputParams: {
67
+ role: TEth.Hex;
68
+ account: TAddress;
69
+ _sender: TAddress;
70
+ };
71
+ outputArgs: [role: TEth.Hex, account: TAddress, _sender: TAddress];
72
+ };
73
+ };
74
+ Methods: {
75
+ CANCELLER_ROLE: {
76
+ method: "CANCELLER_ROLE";
77
+ arguments: [];
78
+ };
79
+ DEFAULT_ADMIN_ROLE: {
80
+ method: "DEFAULT_ADMIN_ROLE";
81
+ arguments: [];
82
+ };
83
+ EXECUTOR_ROLE: {
84
+ method: "EXECUTOR_ROLE";
85
+ arguments: [];
86
+ };
87
+ PROPOSER_ROLE: {
88
+ method: "PROPOSER_ROLE";
89
+ arguments: [];
90
+ };
91
+ TIMELOCK_ADMIN_ROLE: {
92
+ method: "TIMELOCK_ADMIN_ROLE";
93
+ arguments: [];
94
+ };
95
+ cancel: {
96
+ method: "cancel";
97
+ arguments: [id: TEth.Hex];
98
+ };
99
+ execute: {
100
+ method: "execute";
101
+ arguments: [target: TAddress, value: bigint, payload: TEth.Hex, predecessor: TEth.Hex, salt: TEth.Hex];
102
+ };
103
+ executeBatch: {
104
+ method: "executeBatch";
105
+ arguments: [targets: TAddress[], values: bigint[], payloads: TEth.Hex[], predecessor: TEth.Hex, salt: TEth.Hex];
106
+ };
107
+ getMinDelay: {
108
+ method: "getMinDelay";
109
+ arguments: [];
110
+ };
111
+ getRoleAdmin: {
112
+ method: "getRoleAdmin";
113
+ arguments: [role: TEth.Hex];
114
+ };
115
+ getTimestamp: {
116
+ method: "getTimestamp";
117
+ arguments: [id: TEth.Hex];
118
+ };
119
+ grantRole: {
120
+ method: "grantRole";
121
+ arguments: [role: TEth.Hex, account: TAddress];
122
+ };
123
+ hasRole: {
124
+ method: "hasRole";
125
+ arguments: [role: TEth.Hex, account: TAddress];
126
+ };
127
+ hashOperation: {
128
+ method: "hashOperation";
129
+ arguments: [target: TAddress, value: bigint, data: TEth.Hex, predecessor: TEth.Hex, salt: TEth.Hex];
130
+ };
131
+ hashOperationBatch: {
132
+ method: "hashOperationBatch";
133
+ arguments: [targets: TAddress[], values: bigint[], payloads: TEth.Hex[], predecessor: TEth.Hex, salt: TEth.Hex];
134
+ };
135
+ isOperation: {
136
+ method: "isOperation";
137
+ arguments: [id: TEth.Hex];
138
+ };
139
+ isOperationDone: {
140
+ method: "isOperationDone";
141
+ arguments: [id: TEth.Hex];
142
+ };
143
+ isOperationPending: {
144
+ method: "isOperationPending";
145
+ arguments: [id: TEth.Hex];
146
+ };
147
+ isOperationReady: {
148
+ method: "isOperationReady";
149
+ arguments: [id: TEth.Hex];
150
+ };
151
+ onERC1155BatchReceived: {
152
+ method: "onERC1155BatchReceived";
153
+ arguments: [input0: TAddress, input1: TAddress, input2: bigint[], input3: bigint[], input4: TEth.Hex];
154
+ };
155
+ onERC1155Received: {
156
+ method: "onERC1155Received";
157
+ arguments: [input0: TAddress, input1: TAddress, input2: bigint, input3: bigint, input4: TEth.Hex];
158
+ };
159
+ onERC721Received: {
160
+ method: "onERC721Received";
161
+ arguments: [input0: TAddress, input1: TAddress, input2: bigint, input3: TEth.Hex];
162
+ };
163
+ renounceRole: {
164
+ method: "renounceRole";
165
+ arguments: [role: TEth.Hex, account: TAddress];
166
+ };
167
+ revokeRole: {
168
+ method: "revokeRole";
169
+ arguments: [role: TEth.Hex, account: TAddress];
170
+ };
171
+ schedule: {
172
+ method: "schedule";
173
+ arguments: [target: TAddress, value: bigint, data: TEth.Hex, predecessor: TEth.Hex, salt: TEth.Hex, delay: bigint];
174
+ };
175
+ scheduleBatch: {
176
+ method: "scheduleBatch";
177
+ arguments: [targets: TAddress[], values: bigint[], payloads: TEth.Hex[], predecessor: TEth.Hex, salt: TEth.Hex, delay: bigint];
178
+ };
179
+ supportsInterface: {
180
+ method: "supportsInterface";
181
+ arguments: [interfaceId: TEth.Hex];
182
+ };
183
+ updateDelay: {
184
+ method: "updateDelay";
185
+ arguments: [newDelay: bigint];
186
+ };
187
+ };
188
+ };
@@ -1,11 +1,15 @@
1
- import { TimelockController } from '../../prebuilt/openzeppelin/TimelockController';
2
- import { ContractBase } from '../../contracts/ContractBase';
3
1
  import { IAccount } from '../../models/TAccount';
4
2
  import { TEth } from '../../models/TEth';
5
3
  import { TxWriter } from '../../txs/TxWriter';
6
4
  import { ITimelockTx, ITimelockTxParams, ITimelockService, ETimelockTxStatus } from './ITimelockService';
7
5
  import { TTxWriteMethodKeys } from '../../utils/types';
8
- type TTimelockController = ContractBase & Pick<TimelockController, 'schedule' | 'scheduleBatch' | 'execute' | 'executeBatch' | 'getMinDelay' | 'cancel'>;
6
+ import type { TimelockController } from '../../prebuilt/openzeppelin/TimelockController';
7
+ import type { ContractBase } from '../../contracts/ContractBase';
8
+ import { TxDataBuilder } from '../../txs/TxDataBuilder';
9
+ declare const CONFIG: {
10
+ dir: string;
11
+ };
12
+ type TTimelockController = ContractBase & Pick<TimelockController, 'schedule' | 'scheduleBatch' | 'execute' | 'executeBatch' | 'getMinDelay' | 'cancel' | 'extractLogsCallScheduled' | 'extractLogsCallSalt'>;
9
13
  export declare class TimelockService implements ITimelockService {
10
14
  private timelock;
11
15
  private options?;
@@ -43,6 +47,12 @@ export declare class TimelockService implements ITimelockService {
43
47
  schedule: ITimelockTx;
44
48
  tx?: TEth.Hex;
45
49
  }>;
50
+ processData(sender: IAccount, builder: TxDataBuilder): Promise<{
51
+ prevStatus: ETimelockTxStatus;
52
+ status: ETimelockTxStatus;
53
+ schedule: ITimelockTx;
54
+ tx?: TEth.Hex;
55
+ }>;
46
56
  /** Schedules-Wait-Execute a task distinguished by the unique task name
47
57
  *
48
58
  * 1. if schedule doesn't exist, create it
@@ -108,5 +118,6 @@ export declare class TimelockService implements ITimelockService {
108
118
  private getTxParamsNormalizedFromContract;
109
119
  private getTxParamsNormalizedFromContractBatch;
110
120
  private getStore;
121
+ static config(config: Partial<typeof CONFIG>): void;
111
122
  }
112
123
  export {};
@@ -9,7 +9,7 @@ import { ITxLogItem } from './receipt/ITxLogItem';
9
9
  import { ISafeServiceTransport } from '../safe/transport/ISafeServiceTransport';
10
10
  import { TEth } from '../models/TEth';
11
11
  import { SafeServiceTypes } from '../safe/types/SafeServiceTypes';
12
- interface ITxWriterEvents {
12
+ export interface ITxWriterEvents {
13
13
  transactionHash(hash: TEth.Hex): any;
14
14
  receipt(receipt: TEth.TxReceipt): any;
15
15
  confirmation(confNumber: number, receipt: TEth.TxReceipt): any;
@@ -18,6 +18,22 @@ interface ITxWriterEvents {
18
18
  log(message: string): any;
19
19
  safeTxProposed(safeTx: SafeServiceTypes.ProposeTransactionProps): any;
20
20
  }
21
+ export interface ITxWriterEmitter {
22
+ onSent: PromiseLike<string | TEth.Hex>;
23
+ onCompleted: PromiseLike<TEth.TxReceipt>;
24
+ tx: ITxWriterTransaction;
25
+ receipt: TEth.TxReceipt;
26
+ on(event: keyof ITxWriterEvents, callback: Function): any | this;
27
+ }
28
+ export interface ITxWriterTransaction {
29
+ timestamp: number;
30
+ confirmations: number;
31
+ hash?: TEth.Hex;
32
+ timeout?: NodeJS.Timer;
33
+ receipt?: TEth.TxReceipt;
34
+ error?: Error;
35
+ knownLogs?: ITxLogItem[];
36
+ }
21
37
  export interface ITxWriterOptions {
22
38
  timeout?: number | boolean;
23
39
  retries?: number;
@@ -47,7 +63,7 @@ export interface ITxWriterOptions {
47
63
  */
48
64
  silent?: boolean;
49
65
  }
50
- export declare class TxWriter extends class_EventEmitter<ITxWriterEvents> {
66
+ export declare class TxWriter extends class_EventEmitter<ITxWriterEvents> implements ITxWriterEmitter {
51
67
  client: Web3Client;
52
68
  builder: TxDataBuilder;
53
69
  account: TAccount;
@@ -59,16 +75,8 @@ export declare class TxWriter extends class_EventEmitter<ITxWriterEvents> {
59
75
  onConfirmed(waitForCount: number): Promise<string>;
60
76
  wait(): Promise<TEth.TxReceipt>;
61
77
  id: string;
62
- tx: {
63
- timestamp: number;
64
- confirmations: number;
65
- hash?: TEth.Hex;
66
- timeout?: NodeJS.Timer;
67
- receipt?: TEth.TxReceipt;
68
- error?: Error;
69
- knownLogs?: ITxLogItem[];
70
- };
71
- txs: TxWriter['tx'][];
78
+ tx: ITxWriterTransaction;
79
+ txs: ITxWriterTransaction[];
72
80
  options: ITxWriterOptions;
73
81
  private logger;
74
82
  private confirmationAwaiters;
@@ -106,4 +114,3 @@ export type TTxWriterJson = {
106
114
  txs: TxWriter['txs'];
107
115
  builder: ReturnType<TxDataBuilder['toJSON']>;
108
116
  };
109
- export {};
@@ -0,0 +1,26 @@
1
+ import { EoAccount, TAccount, TimelockAccount } from '../../models/TAccount';
2
+ import { ITxWriterAccountAgent } from './TxWriterAccountAgents';
3
+ import { ITxWriterEmitter, ITxWriterEvents, ITxWriterTransaction, TxWriter } from '../TxWriter';
4
+ import { class_Dfr, class_EventEmitter } from 'atma-utils';
5
+ import { TEth } from '../../models/TEth';
6
+ import { ITimelockTx } from '../../services/TimelockService/ITimelockService';
7
+ import { Web3Client } from '../../clients/Web3Client';
8
+ import { TimelockService } from '../../services/TimelockService/TimelockService';
9
+ export declare class TimelockAgent implements ITxWriterAccountAgent {
10
+ supports(account: TAccount): account is TimelockAccount;
11
+ process(senderMix: string | EoAccount, timelockAccount: TimelockAccount, outerWriter: TxWriter): Promise<TimelockTxWriter>;
12
+ }
13
+ export declare class TimelockTxWriter extends class_EventEmitter<ITxWriterEvents> implements ITxWriterEmitter {
14
+ private client;
15
+ private sender;
16
+ private service;
17
+ private outerWriter;
18
+ onSent: class_Dfr<string>;
19
+ onCompleted: class_Dfr<TEth.TxReceipt>;
20
+ receipt: TEth.TxReceipt;
21
+ tx: ITxWriterTransaction;
22
+ schedule: ITimelockTx;
23
+ delayTimer: any;
24
+ constructor(client: Web3Client, sender: TEth.IAccount, service: TimelockService, outerWriter: TxWriter);
25
+ process(): Promise<this>;
26
+ }
@@ -1,8 +1,8 @@
1
1
  import type { EoAccount, TAccount } from '../../models/TAccount';
2
- import type { TxWriter } from '../TxWriter';
2
+ import type { ITxWriterEmitter, TxWriter } from '../TxWriter';
3
3
  export interface ITxWriterAccountAgent {
4
4
  supports(account: TAccount): boolean;
5
- process(sender: EoAccount, account: TAccount, outerWriter: TxWriter): Promise<TxWriter>;
5
+ process(sender: EoAccount, account: TAccount, outerWriter: TxWriter): Promise<ITxWriterEmitter>;
6
6
  }
7
7
  export declare namespace TxWriterAccountAgents {
8
8
  function register(agent: ITxWriterAccountAgent): void;
@@ -1,6 +1,7 @@
1
- import { EoAccount, Erc4337Account, SafeAccount, TAccount } from "../models/TAccount";
1
+ import { EoAccount, Erc4337Account, SafeAccount, TAccount, TimelockAccount } from "../models/TAccount";
2
2
  export declare namespace $account {
3
3
  function getSender(account: TAccount): EoAccount;
4
4
  function isSafe(account: TAccount): account is SafeAccount;
5
5
  function isErc4337(account: TAccount): account is Erc4337Account;
6
+ function isTimelock(account: TAccount): account is TimelockAccount;
6
7
  }
@@ -55,6 +55,7 @@ export declare namespace $date {
55
55
  function dayEnd(date?: Date): Date;
56
56
  function weekStart(date?: Date): Date;
57
57
  function weekEnd(date?: Date): Date;
58
+ function weekNumber(date?: Date): number;
58
59
  function monthStart(date?: Date): Date;
59
60
  function monthEnd(date?: Date): Date;
60
61
  /** date1 + X === date2 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dequanto",
3
- "version": "0.1.81",
3
+ "version": "0.1.85",
4
4
  "author": {
5
5
  "name": "Alex Kit",
6
6
  "email": "alex.kit@atmajs.com"
@@ -1,6 +1,9 @@
1
+ import alot from 'alot';
2
+ import memd from 'memd';
1
3
  import { Web3Client } from '@dequanto/clients/Web3Client';
4
+ import { TEth } from '@dequanto/models/TEth';
2
5
  import { $block } from '@dequanto/utils/$block';
3
- import alot from 'alot';
6
+ import { $date } from '@dequanto/utils/$date';
4
7
 
5
8
  export class BlockDateResolver {
6
9
  private AVG_INITIAL = {
@@ -9,24 +12,22 @@ export class BlockDateResolver {
9
12
  polygon: 3_000,
10
13
  };
11
14
 
12
- private closestTime: number;
13
- private closestIdx: number;
14
- private maxBlock: number;
15
15
 
16
- private known = [] as IKnownBlock[]
17
- private q: Date;
16
+
17
+ private _known = [] as IKnownBlock[]
18
+ private _requestedDate: Date;
18
19
 
19
20
  constructor(public client: Web3Client) {
20
21
 
21
22
  }
22
23
 
23
24
  async getDate (blockNumber: number): Promise<Date> {
24
- let block = await this.client.getBlock(blockNumber);
25
+ let block = await this.getBlock(blockNumber);
25
26
  return new Date(block.timestamp * 1000);
26
27
  }
27
28
 
28
29
  async getBlockNumberFor (date: Date): Promise<number> {
29
- this.q = date;
30
+ this._requestedDate = date;
30
31
 
31
32
  let avg = this.AVG_INITIAL[this.client.platform] ?? this.client.blockTimeAvg ?? this.AVG_INITIAL['eth'];
32
33
  let now = new Date();
@@ -36,38 +37,65 @@ export class BlockDateResolver {
36
37
  avg,
37
38
  };
38
39
 
39
- this.maxBlock = topBlock.blockNumber;
40
- this.known.push(topBlock);
41
- return await this.moveNext(date, {
40
+
41
+ this._known.push(topBlock);
42
+ const result = await this.moveNext(date, {
42
43
  closestTime: null,
43
44
  blockNumber: null,
45
+ date: null
44
46
  });
47
+ return result.blockNumber;
48
+ }
49
+
50
+ async getBlockInfoFor (date: Date): Promise<{ block: number, timestamp: number }> {
51
+ this._requestedDate = date;
52
+
53
+ let avg = this.AVG_INITIAL[this.client.platform] ?? this.client.blockTimeAvg ?? this.AVG_INITIAL['eth'];
54
+ let now = new Date();
55
+ let topBlock = <IKnownBlock> {
56
+ blockNumber: await this.client.getBlockNumberCached(),
57
+ date: now,
58
+ avg,
59
+ };
60
+
61
+ this._known.push(topBlock);
62
+ const result = await this.moveNext(date, {
63
+ closestTime: null,
64
+ blockNumber: null,
65
+ date: null,
66
+ });
67
+ return {
68
+ block: result.blockNumber,
69
+ timestamp: result.date ? $date.toUnixTimestamp(result.date) : null,
70
+ };
45
71
  }
46
72
 
47
73
  private async moveNext (date: Date, ctx: {
48
74
  closestTime: number;
49
75
  blockNumber: number;
50
- }) {
76
+ date: Date;
77
+ }): Promise<IKnownBlock> {
51
78
 
52
79
  let closestIndex = this.getClosest(date);
53
- let block = this.known[closestIndex];
80
+ let block = this._known[closestIndex];
54
81
  let timeDiff = this.diffTime(block.date, date);
55
82
 
56
83
  let timeDistance = Math.abs(timeDiff);
57
84
  const BLOCKS_TOLERANCE = 2;
58
85
  if (timeDistance <= block.avg * BLOCKS_TOLERANCE) {
59
- return block.blockNumber;
86
+ return block;
60
87
  }
61
88
  if (ctx.closestTime != null && timeDistance >= ctx.closestTime) {
62
- return ctx.blockNumber;
89
+ return ctx;
63
90
  }
64
91
 
65
92
  ctx.closestTime = timeDistance;
66
93
  ctx.blockNumber = block.blockNumber;
94
+ ctx.date = block.date;
67
95
 
68
96
  let nextInfo = await this.checkPoint(block, timeDiff);
69
97
  if (nextInfo == null) {
70
- return block.blockNumber;
98
+ return block;
71
99
  }
72
100
 
73
101
  return this.moveNext(date, ctx);
@@ -77,11 +105,11 @@ export class BlockDateResolver {
77
105
  * Returns index of the first known block, which is most near to specified block (it can be before or after the specified date).
78
106
  */
79
107
  private getClosest (date: Date) {
80
- let entry = alot(this.known).map(x => [
108
+ let entry = alot(this._known).map(x => [
81
109
  this.diffTimeAbs(x.date, date),
82
110
  x
83
111
  ] as const).minItem(x => x[0])[1];
84
- let i = this.known.indexOf(entry);
112
+ let i = this._known.indexOf(entry);
85
113
  return i;
86
114
  }
87
115
 
@@ -92,7 +120,7 @@ export class BlockDateResolver {
92
120
  }
93
121
  let blockNumber = anchor.blockNumber + diffCount;
94
122
  if (blockNumber < 0) {
95
- throw new Error(`Date Out of range: ${ this.q.toISOString() }. Based on the AVG block time, the blockchain was not active on that date`);
123
+ throw new Error(`Date Out of range: ${ this._requestedDate.toISOString() }. Based on the AVG block time, the blockchain was not active on that date`);
96
124
  }
97
125
  let date = await this.getBlockDate(blockNumber);
98
126
  let info = {
@@ -106,18 +134,18 @@ export class BlockDateResolver {
106
134
 
107
135
  /** Add a know block to set */
108
136
  private push(info: IKnownBlock) {
109
- for (let i = 0; i < this.known.length; i++) {
110
- let x = this.known[i];
137
+ for (let i = 0; i < this._known.length; i++) {
138
+ let x = this._known[i];
111
139
  if (info.date < x.date) {
112
- this.known.splice(i, 0, info);
140
+ this._known.splice(i, 0, info);
113
141
  return;
114
142
  }
115
143
  }
116
- this.known.push(info);
144
+ this._known.push(info);
117
145
  }
118
146
  /** Loads the block and gets the Date of the block */
119
147
  private async getBlockDate (blockNumber: number) {
120
- let block = await this.client.getBlock(blockNumber);
148
+ let block = await this.getBlock(blockNumber);
121
149
  if (block == null) {
122
150
  throw new Error(`Block not loaded: ${blockNumber}`);
123
151
  }
@@ -139,16 +167,21 @@ export class BlockDateResolver {
139
167
  }
140
168
  /** With N>1 blocks we can better find out the AVG block time */
141
169
  private refineAvg () {
142
- for (let i = 1; i < this.known.length; i++) {
143
- let info = this.known[i];
144
- let prev = this.known[i - 1];
170
+ for (let i = 1; i < this._known.length; i++) {
171
+ let info = this._known[i];
172
+ let prev = this._known[i - 1];
145
173
 
146
174
  info.avg = this.getAvgBlockCountBetween(prev, info);
147
175
  if (i === 1) {
148
- this.known[0].avg = info.avg;
176
+ this._known[0].avg = info.avg;
149
177
  }
150
178
  }
151
179
  }
180
+
181
+ @memd.deco.memoize()
182
+ private getBlock (blockNumber: number): Promise<TEth.Block> {
183
+ return this.client.getBlock(blockNumber);
184
+ }
152
185
  }
153
186
 
154
187
  interface IKnownBlock {
@@ -34,6 +34,7 @@ export namespace $proxyDeploy {
34
34
 
35
35
  ctx ??= {};
36
36
 
37
+ let rgxGap = /^_+gap$/;
37
38
  let oldMemory = oldVars.map(getMemoryPosition);
38
39
  let oldLastSlot = alot(oldVars).max(x => x.slot);
39
40
  for (let i = 0; i < newVars.length; i++) {
@@ -60,6 +61,9 @@ export namespace $proxyDeploy {
60
61
  }
61
62
  continue;
62
63
  }
64
+ if (rgxGap.test(newVar.name)) {
65
+ continue;
66
+ }
63
67
  let isLastVariable = newVar.slot === oldLastSlot;
64
68
  let oldVar = oldVars.find(x => x.slot === newVar.slot && x.position === newVar.position);
65
69
  if (oldVar != null) {
@@ -98,7 +102,7 @@ export namespace $proxyDeploy {
98
102
  return true;
99
103
  });
100
104
  collisions = collisions.filter(x => {
101
- return /gap/.test(x.variable.name) === false;
105
+ return rgxGap.test(x.variable.name) === false;
102
106
  });
103
107
  if (collisions.length > 0) {
104
108
  if (collisions.length === 1) {
@@ -27,8 +27,6 @@ export class Erc4337Factory {
27
27
 
28
28
  $require.notNull(provider, `No 4337 provider information found for ${name} and platform "${platform}"`);
29
29
 
30
- console.log(`CreateService`, provider.contracts.entryPoint);
31
-
32
30
  return new Erc4337Service(client, explorer, {
33
31
  addresses: {
34
32
  entryPoint: provider.contracts.entryPoint,
@@ -4,7 +4,7 @@ import { TEth } from './TEth';
4
4
  import { TPlatform } from './TPlatform';
5
5
 
6
6
  export interface IAccount {
7
- type?: 'eoa' | 'safe' | 'erc4337'
7
+ type?: 'eoa' | 'safe' | 'erc4337' | 'timelock'
8
8
  name?: string
9
9
  platform?: TPlatform
10
10
 
@@ -58,4 +58,14 @@ export interface Erc4337Account extends IAccount {
58
58
  operator: EoAccount
59
59
  }
60
60
 
61
+ export interface TimelockAccount extends IAccount {
62
+ type: 'timelock'
63
+ provider?: 'default' | string
64
+
65
+ // Erc4337 account must include platform information
66
+ platform: TPlatform
67
+
68
+ operator: EoAccount
69
+ }
70
+
61
71
  export type TAccount = string | IAccount | EoAccount | SafeAccount | Erc4337Account;