dequanto 0.1.86 → 0.1.89

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 (33) hide show
  1. package/lib/cjs/contracts/ContractWriter.js +2 -2
  2. package/lib/cjs/contracts/ContractWriter.js.map +1 -1
  3. package/lib/cjs/contracts/deploy/Deployments.js +1 -1
  4. package/lib/cjs/contracts/deploy/Deployments.js.map +1 -1
  5. package/lib/cjs/contracts/deploy/proxy/$proxyDeploy.js +13 -14
  6. package/lib/cjs/contracts/deploy/proxy/$proxyDeploy.js.map +1 -1
  7. package/lib/cjs/txs/TxWriter.js +19 -7
  8. package/lib/cjs/txs/TxWriter.js.map +1 -1
  9. package/lib/cjs/txs/agents/BatchAgent.js +83 -0
  10. package/lib/cjs/txs/agents/BatchAgent.js.map +1 -0
  11. package/lib/cjs/txs/agents/TxWriterAccountAgents.js.map +1 -1
  12. package/lib/esm/contracts/ContractWriter.js.map +1 -1
  13. package/lib/esm/contracts/ContractWriter.mjs +2 -2
  14. package/lib/esm/contracts/deploy/Deployments.js.map +1 -1
  15. package/lib/esm/contracts/deploy/Deployments.mjs +1 -1
  16. package/lib/esm/contracts/deploy/proxy/$proxyDeploy.js.map +1 -1
  17. package/lib/esm/contracts/deploy/proxy/$proxyDeploy.mjs +13 -14
  18. package/lib/esm/txs/TxWriter.js.map +1 -1
  19. package/lib/esm/txs/TxWriter.mjs +19 -7
  20. package/lib/esm/txs/agents/BatchAgent.js.map +1 -0
  21. package/lib/esm/txs/agents/BatchAgent.mjs +78 -0
  22. package/lib/esm/txs/agents/TxWriterAccountAgents.js.map +1 -1
  23. package/lib/types/contracts/deploy/Deployments.d.ts +2 -0
  24. package/lib/types/txs/TxWriter.d.ts +6 -0
  25. package/lib/types/txs/agents/BatchAgent.d.ts +27 -0
  26. package/lib/types/txs/agents/TxWriterAccountAgents.d.ts +4 -2
  27. package/package.json +1 -1
  28. package/src/contracts/ContractWriter.ts +2 -2
  29. package/src/contracts/deploy/Deployments.ts +4 -1
  30. package/src/contracts/deploy/proxy/$proxyDeploy.ts +13 -13
  31. package/src/txs/TxWriter.ts +27 -9
  32. package/src/txs/agents/BatchAgent.ts +112 -0
  33. package/src/txs/agents/TxWriterAccountAgents.ts +4 -2
@@ -0,0 +1,112 @@
1
+ import { EoAccount } from '@dequanto/models/TAccount';
2
+ import { ITxWriterAgent } from './TxWriterAccountAgents';
3
+ import { ITxWriterEmitter, ITxWriterEvents, ITxWriterTransaction, TxWriter } from '../TxWriter';
4
+
5
+ import { ChainAccountService } from '@dequanto/ChainAccountService';
6
+ import { class_Dfr, class_EventEmitter } from 'atma-utils';
7
+ import { TEth } from '@dequanto/models/TEth';
8
+ import { $date } from '@dequanto/utils/$date';
9
+
10
+
11
+ import { $require } from '@dequanto/utils/$require';
12
+ import { $address } from '@dequanto/utils/$address';
13
+
14
+
15
+ export class BatchAgent implements ITxWriterAgent {
16
+
17
+ public transactions: MockTxWriter[] = []
18
+
19
+ constructor (public options?: {
20
+ // It is usefull to not batch the deployment transactions.
21
+ ignoreContractCreation?: boolean,
22
+ }) {
23
+
24
+ }
25
+
26
+ getTxData (): Pick<TEth.TxLike, "to" | "data" | "value">[] {
27
+ return this.transactions.map(tx => {
28
+ let data = tx.outerWriter.builder.getTxData();
29
+ return {
30
+ to: data.to,
31
+ value: data.value,
32
+ data: data.data,
33
+ };
34
+ })
35
+ }
36
+
37
+ async process (senderMix: string | EoAccount, account: TEth.IAccount, outerWriter: TxWriter) {
38
+
39
+ if (outerWriter.builder.data.to == null && this.options?.ignoreContractCreation != false) {
40
+ return null;
41
+ }
42
+
43
+ let sender = typeof senderMix === 'string'
44
+ ? await ChainAccountService.get(senderMix) as EoAccount
45
+ : senderMix;
46
+
47
+ let inner = new MockTxWriter(
48
+ sender,
49
+ account,
50
+ outerWriter,
51
+ );
52
+
53
+ this.transactions.forEach(tx => {
54
+ $require.eq(sender.address, tx.sender.address, `Expected the same SENDER for all batch transactions`);
55
+ $require.eq(sender.address, tx.sender.address, `Expected the same ACCOUNT for all batch transactions`);
56
+ });
57
+
58
+ this.transactions.push(inner);
59
+
60
+ await inner.process();
61
+ return inner;
62
+ }
63
+ }
64
+
65
+ export class MockTxWriter extends class_EventEmitter<ITxWriterEvents> implements ITxWriterEmitter {
66
+
67
+ onSent = new class_Dfr<string | TEth.Hex>()
68
+ onCompleted = new class_Dfr<TEth.TxReceipt>()
69
+ receipt: TEth.TxReceipt
70
+ tx: ITxWriterTransaction
71
+
72
+ constructor (
73
+ public sender: TEth.IAccount,
74
+ public account: TEth.IAccount,
75
+ public outerWriter: TxWriter,
76
+ ) {
77
+ super();
78
+ }
79
+
80
+ async process () {
81
+ let receipt = {
82
+ status: 1,
83
+ transactionHash: '0x',
84
+ transactionIndex: 0n,
85
+ blockHash: '0x',
86
+ blockNumber: 0,
87
+ from: $address.ZERO,
88
+ to: $address.ZERO,
89
+ cumulativeGasUsed: 0n,
90
+ gasUsed: 0n,
91
+ effectiveGasPrice: 0n,
92
+ logs: [],
93
+ logsBloom: '0x'
94
+ } as TEth.TxReceipt;
95
+
96
+ let tx = {
97
+ timestamp: $date.toUnixTimestamp(),
98
+ confirmations: 5,
99
+ hash: '0x',
100
+ receipt: receipt,
101
+ error: null,
102
+ knownLogs: null,
103
+ } as ITxWriterTransaction;
104
+
105
+ this.tx = tx;
106
+ this.emit('transactionHash', receipt.transactionHash);
107
+ this.emit('receipt', receipt);
108
+ this.onCompleted.resolve(receipt);
109
+ return this;
110
+
111
+ }
112
+ }
@@ -5,10 +5,12 @@ import { Erc4337Agent } from './Erc4337Agent';
5
5
  import { TimelockAgent } from './TimelockAgent';
6
6
 
7
7
 
8
+ export interface ITxWriterAgent {
9
+ process (sender: EoAccount, account: TAccount, outerWriter: TxWriter): Promise<ITxWriterEmitter>
10
+ }
8
11
 
9
- export interface ITxWriterAccountAgent {
12
+ export interface ITxWriterAccountAgent extends ITxWriterAgent{
10
13
  supports (account: TAccount): boolean
11
- process (sender: EoAccount, account: TAccount, outerWriter: TxWriter): Promise<ITxWriterEmitter>
12
14
  }
13
15
 
14
16
  export namespace TxWriterAccountAgents {