dequanto 0.1.80 → 0.1.84

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 (79) 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/Deployments.js +2 -1
  4. package/lib/cjs/contracts/deploy/Deployments.js.map +1 -1
  5. package/lib/cjs/contracts/deploy/proxy/ProxyDeployment.js +1 -1
  6. package/lib/cjs/contracts/deploy/proxy/ProxyDeployment.js.map +1 -1
  7. package/lib/cjs/erc4337/Erc4337Factory.js +0 -1
  8. package/lib/cjs/erc4337/Erc4337Factory.js.map +1 -1
  9. package/lib/cjs/indexer/EventsIndexer.js +14 -2
  10. package/lib/cjs/indexer/EventsIndexer.js.map +1 -1
  11. package/lib/cjs/prebuilt-factories/TimelockControllerFactory.js +251 -0
  12. package/lib/cjs/prebuilt-factories/TimelockControllerFactory.js.map +1 -0
  13. package/lib/cjs/services/TimelockService/TimelockService.js +52 -2
  14. package/lib/cjs/services/TimelockService/TimelockService.js.map +1 -1
  15. package/lib/cjs/txs/TxWriter.js +1 -1
  16. package/lib/cjs/txs/TxWriter.js.map +1 -1
  17. package/lib/cjs/txs/agents/TimelockAgent.js +90 -0
  18. package/lib/cjs/txs/agents/TimelockAgent.js.map +1 -0
  19. package/lib/cjs/txs/agents/TxWriterAccountAgents.js +2 -0
  20. package/lib/cjs/txs/agents/TxWriterAccountAgents.js.map +1 -1
  21. package/lib/cjs/utils/$account.js +17 -1
  22. package/lib/cjs/utils/$account.js.map +1 -1
  23. package/lib/cjs/utils/$bigint.js +19 -2
  24. package/lib/cjs/utils/$bigint.js.map +1 -1
  25. package/lib/cjs/utils/$date.js +11 -0
  26. package/lib/cjs/utils/$date.js.map +1 -1
  27. package/lib/esm/blocks/BlockDateResolver.js.map +1 -1
  28. package/lib/esm/blocks/BlockDateResolver.mjs +59 -23
  29. package/lib/esm/contracts/deploy/Deployments.js.map +1 -1
  30. package/lib/esm/contracts/deploy/Deployments.mjs +2 -1
  31. package/lib/esm/contracts/deploy/proxy/ProxyDeployment.js.map +1 -1
  32. package/lib/esm/contracts/deploy/proxy/ProxyDeployment.mjs +1 -1
  33. package/lib/esm/erc4337/Erc4337Factory.js.map +1 -1
  34. package/lib/esm/erc4337/Erc4337Factory.mjs +0 -1
  35. package/lib/esm/indexer/EventsIndexer.js.map +1 -1
  36. package/lib/esm/indexer/EventsIndexer.mjs +14 -2
  37. package/lib/esm/prebuilt-factories/TimelockControllerFactory.js.map +1 -0
  38. package/lib/esm/prebuilt-factories/TimelockControllerFactory.mjs +244 -0
  39. package/lib/esm/services/TimelockService/TimelockService.js.map +1 -1
  40. package/lib/esm/services/TimelockService/TimelockService.mjs +52 -2
  41. package/lib/esm/txs/TxWriter.js.map +1 -1
  42. package/lib/esm/txs/TxWriter.mjs +1 -1
  43. package/lib/esm/txs/agents/TimelockAgent.js.map +1 -0
  44. package/lib/esm/txs/agents/TimelockAgent.mjs +85 -0
  45. package/lib/esm/txs/agents/TxWriterAccountAgents.js.map +1 -1
  46. package/lib/esm/txs/agents/TxWriterAccountAgents.mjs +2 -0
  47. package/lib/esm/utils/$account.js.map +1 -1
  48. package/lib/esm/utils/$account.mjs +17 -1
  49. package/lib/esm/utils/$bigint.js.map +1 -1
  50. package/lib/esm/utils/$bigint.mjs +19 -2
  51. package/lib/esm/utils/$date.js.map +1 -1
  52. package/lib/esm/utils/$date.mjs +11 -0
  53. package/lib/types/blocks/BlockDateResolver.d.ts +7 -5
  54. package/lib/types/contracts/deploy/Deployments.d.ts +3 -0
  55. package/lib/types/contracts/deploy/proxy/ProxyDeployment.d.ts +1 -0
  56. package/lib/types/models/TAccount.d.ts +7 -1
  57. package/lib/types/prebuilt-factories/TimelockControllerFactory.d.ts +188 -0
  58. package/lib/types/services/TimelockService/TimelockService.d.ts +18 -3
  59. package/lib/types/txs/TxWriter.d.ts +20 -13
  60. package/lib/types/txs/agents/TimelockAgent.d.ts +26 -0
  61. package/lib/types/txs/agents/TxWriterAccountAgents.d.ts +2 -2
  62. package/lib/types/utils/$account.d.ts +2 -1
  63. package/lib/types/utils/$bigint.d.ts +2 -1
  64. package/lib/types/utils/$date.d.ts +1 -0
  65. package/package.json +1 -1
  66. package/src/blocks/BlockDateResolver.ts +61 -28
  67. package/src/contracts/deploy/Deployments.ts +5 -1
  68. package/src/contracts/deploy/proxy/ProxyDeployment.ts +2 -1
  69. package/src/erc4337/Erc4337Factory.ts +0 -2
  70. package/src/indexer/EventsIndexer.ts +18 -3
  71. package/src/models/TAccount.ts +11 -1
  72. package/src/prebuilt-factories/TimelockControllerFactory.ts +582 -0
  73. package/src/services/TimelockService/TimelockService.ts +83 -7
  74. package/src/txs/TxWriter.ts +29 -17
  75. package/src/txs/agents/TimelockAgent.ts +116 -0
  76. package/src/txs/agents/TxWriterAccountAgents.ts +4 -2
  77. package/src/utils/$account.ts +18 -2
  78. package/src/utils/$bigint.ts +19 -2
  79. package/src/utils/$date.ts +11 -1
@@ -2,14 +2,15 @@ import { Web3Client } from '../clients/Web3Client';
2
2
  export declare class BlockDateResolver {
3
3
  client: Web3Client;
4
4
  private AVG_INITIAL;
5
- private closestTime;
6
- private closestIdx;
7
- private maxBlock;
8
- private known;
9
- private q;
5
+ private _known;
6
+ private _requestedDate;
10
7
  constructor(client: Web3Client);
11
8
  getDate(blockNumber: number): Promise<Date>;
12
9
  getBlockNumberFor(date: Date): Promise<number>;
10
+ getBlockInfoFor(date: Date): Promise<{
11
+ block: number;
12
+ timestamp: number;
13
+ }>;
13
14
  private moveNext;
14
15
  /**
15
16
  * Returns index of the first known block, which is most near to specified block (it can be before or after the specified date).
@@ -28,4 +29,5 @@ export declare class BlockDateResolver {
28
29
  private getAvgBlockCountBetween;
29
30
  /** With N>1 blocks we can better find out the AVG block time */
30
31
  private refineAvg;
32
+ private getBlock;
31
33
  }
@@ -18,12 +18,14 @@ type TDeploymentOptions = {
18
18
  deployment?: {
19
19
  tx?: TEth.Hex;
20
20
  upgradeProxy?: boolean;
21
+ owner?: TEth.IAccount;
21
22
  };
22
23
  };
23
24
  export declare class Deployments {
24
25
  client: Web3Client;
25
26
  deployer: IAccount;
26
27
  opts: {
28
+ owner?: IAccount;
27
29
  Proxy?: Constructor<ContractBase>;
28
30
  ProxyAdmin?: Constructor<IProxyAdmin>;
29
31
  directory?: string;
@@ -43,6 +45,7 @@ export declare class Deployments {
43
45
  private _proxyDeployment;
44
46
  private _config;
45
47
  constructor(client: Web3Client, deployer: IAccount, opts?: {
48
+ owner?: IAccount;
46
49
  Proxy?: Constructor<ContractBase>;
47
50
  ProxyAdmin?: Constructor<IProxyAdmin>;
48
51
  directory?: string;
@@ -22,6 +22,7 @@ export interface IBeacon extends ContractBase {
22
22
  interface IDeploymentCtx {
23
23
  ImplementationContract: Constructor<ContractBase>;
24
24
  deployer: IAccount;
25
+ owner?: IAccount;
25
26
  deployments: Deployments;
26
27
  implementation: {
27
28
  address: TAddress;
@@ -3,7 +3,7 @@ import { TAddress } from './TAddress';
3
3
  import { TEth } from './TEth';
4
4
  import { TPlatform } from './TPlatform';
5
5
  export interface IAccount {
6
- type?: 'eoa' | 'safe' | 'erc4337';
6
+ type?: 'eoa' | 'safe' | 'erc4337' | 'timelock';
7
7
  name?: string;
8
8
  platform?: TPlatform;
9
9
  address?: TAddress;
@@ -41,5 +41,11 @@ export interface Erc4337Account extends IAccount {
41
41
  platform: TPlatform;
42
42
  operator: EoAccount;
43
43
  }
44
+ export interface TimelockAccount extends IAccount {
45
+ type: 'timelock';
46
+ provider?: 'default' | string;
47
+ platform: TPlatform;
48
+ operator: EoAccount;
49
+ }
44
50
  export type TAccount = string | IAccount | EoAccount | SafeAccount | Erc4337Account;
45
51
  export {};
@@ -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?;
@@ -18,6 +22,10 @@ export declare class TimelockService implements ITimelockService {
18
22
  status: ETimelockTxStatus;
19
23
  schedule: ITimelockTx;
20
24
  }>;
25
+ getPendingFromTx(txHash: TEth.Hex): Promise<{
26
+ status: ETimelockTxStatus;
27
+ schedule: ITimelockTx;
28
+ }>;
21
29
  executePendingByTitle(sender: IAccount, title: string): Promise<{
22
30
  tx: TxWriter;
23
31
  schedule: ITimelockTx;
@@ -39,6 +47,12 @@ export declare class TimelockService implements ITimelockService {
39
47
  schedule: ITimelockTx;
40
48
  tx?: TEth.Hex;
41
49
  }>;
50
+ processData(sender: IAccount, builder: TxDataBuilder): Promise<{
51
+ prevStatus: ETimelockTxStatus;
52
+ status: ETimelockTxStatus;
53
+ schedule: ITimelockTx;
54
+ tx?: TEth.Hex;
55
+ }>;
42
56
  /** Schedules-Wait-Execute a task distinguished by the unique task name
43
57
  *
44
58
  * 1. if schedule doesn't exist, create it
@@ -104,5 +118,6 @@ export declare class TimelockService implements ITimelockService {
104
118
  private getTxParamsNormalizedFromContract;
105
119
  private getTxParamsNormalizedFromContractBatch;
106
120
  private getStore;
121
+ static config(config: Partial<typeof CONFIG>): void;
107
122
  }
108
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
  }
@@ -6,8 +6,9 @@ export declare namespace $bigint {
6
6
  function max(...args: bigint[]): bigint;
7
7
  function min(...args: bigint[]): bigint;
8
8
  function toBigInt(amount: string | number | bigint | Uint8Array): bigint;
9
+ function from(amount: number | bigint | string): bigint;
9
10
  /**
10
- * @param amount e.g "2.4 ether", "10 gwei", "1.7^18", "123456"
11
+ * @param amount e.g "2.4 ether", "10 gwei", "1.7^18", "123456", "1.7e18"
11
12
  */
12
13
  function parse(amount: string): bigint;
13
14
  function ensureWei(amount: number | bigint, decimals: number): bigint;
@@ -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.80",
3
+ "version": "0.1.84",
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 {
@@ -44,6 +44,8 @@ type TDeploymentOptions = {
44
44
  tx?: TEth.Hex
45
45
  // When false, the implementation won't be updated in proxy
46
46
  upgradeProxy?: boolean
47
+ // Owner, if differes from deployer
48
+ owner?: TEth.IAccount
47
49
  }
48
50
  }
49
51
  type TVerificationOptions = TDeploymentOptions & {
@@ -75,6 +77,7 @@ export class Deployments {
75
77
  }
76
78
 
77
79
  constructor(public client: Web3Client, public deployer: IAccount, public opts: {
80
+ owner?: IAccount
78
81
  Proxy?: Constructor<ContractBase>,
79
82
  ProxyAdmin?: Constructor<IProxyAdmin>
80
83
  directory?: string
@@ -327,12 +330,13 @@ export class Deployments {
327
330
  ImplementationContract: CtorImpl,
328
331
  proxyId: proxyId,
329
332
  deployer: this.deployer,
333
+ owner: opts.deployment?.owner ?? this.opts?.owner ?? this.deployer,
330
334
  deployments: this,
331
335
  implementation: {
332
336
  address: implementationAddress,
333
337
  initData: data
334
338
  },
335
- upgradeImplementation: opts?.deployment?.upgradeProxy ?? true
339
+ upgradeImplementation: opts.deployment?.upgradeProxy ?? true
336
340
  })
337
341
 
338
342
  if (contractImplDeployment.implementation == null) {