dequanto 0.1.75 → 0.1.80

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 (50) hide show
  1. package/lib/cjs/contracts/deploy/Deployments.js +4 -1
  2. package/lib/cjs/contracts/deploy/Deployments.js.map +1 -1
  3. package/lib/cjs/contracts/deploy/proxy/ProxyDeployment.js +11 -5
  4. package/lib/cjs/contracts/deploy/proxy/ProxyDeployment.js.map +1 -1
  5. package/lib/cjs/hardhat/HardhatProvider.js +3 -1
  6. package/lib/cjs/hardhat/HardhatProvider.js.map +1 -1
  7. package/lib/cjs/safe/GnosisSafeHandler.js +2 -1
  8. package/lib/cjs/safe/GnosisSafeHandler.js.map +1 -1
  9. package/lib/cjs/solidity/SlotsStorage.js +3 -6
  10. package/lib/cjs/solidity/SlotsStorage.js.map +1 -1
  11. package/lib/cjs/solidity/SolidityParser.js +12 -0
  12. package/lib/cjs/solidity/SolidityParser.js.map +1 -1
  13. package/lib/cjs/solidity/storage/SlotsStorageTransport.js +2 -2
  14. package/lib/cjs/solidity/storage/SlotsStorageTransport.js.map +1 -1
  15. package/lib/cjs/solidity/storage/handlers/SlotBytesHandler.js +1 -1
  16. package/lib/cjs/solidity/storage/handlers/SlotBytesHandler.js.map +1 -1
  17. package/lib/cjs/solidity/storage/handlers/SlotMappingHandler.js +1 -1
  18. package/lib/cjs/solidity/storage/handlers/SlotMappingHandler.js.map +1 -1
  19. package/lib/esm/contracts/deploy/Deployments.js.map +1 -1
  20. package/lib/esm/contracts/deploy/Deployments.mjs +4 -1
  21. package/lib/esm/contracts/deploy/proxy/ProxyDeployment.js.map +1 -1
  22. package/lib/esm/contracts/deploy/proxy/ProxyDeployment.mjs +11 -5
  23. package/lib/esm/hardhat/HardhatProvider.js.map +1 -1
  24. package/lib/esm/hardhat/HardhatProvider.mjs +3 -1
  25. package/lib/esm/safe/GnosisSafeHandler.js.map +1 -1
  26. package/lib/esm/safe/GnosisSafeHandler.mjs +2 -1
  27. package/lib/esm/solidity/SlotsStorage.js.map +1 -1
  28. package/lib/esm/solidity/SlotsStorage.mjs +3 -6
  29. package/lib/esm/solidity/SolidityParser.js.map +1 -1
  30. package/lib/esm/solidity/SolidityParser.mjs +12 -0
  31. package/lib/esm/solidity/storage/SlotsStorageTransport.js.map +1 -1
  32. package/lib/esm/solidity/storage/SlotsStorageTransport.mjs +2 -2
  33. package/lib/esm/solidity/storage/handlers/SlotBytesHandler.js.map +1 -1
  34. package/lib/esm/solidity/storage/handlers/SlotBytesHandler.mjs +1 -1
  35. package/lib/esm/solidity/storage/handlers/SlotMappingHandler.js.map +1 -1
  36. package/lib/esm/solidity/storage/handlers/SlotMappingHandler.mjs +1 -1
  37. package/lib/types/contracts/deploy/Deployments.d.ts +4 -0
  38. package/lib/types/contracts/deploy/proxy/ProxyDeployment.d.ts +1 -0
  39. package/lib/types/hardhat/HardhatProvider.d.ts +1 -0
  40. package/lib/types/solidity/storage/SlotsStorageTransport.d.ts +1 -1
  41. package/package.json +1 -1
  42. package/src/contracts/deploy/Deployments.ts +12 -1
  43. package/src/contracts/deploy/proxy/ProxyDeployment.ts +17 -12
  44. package/src/hardhat/HardhatProvider.ts +4 -1
  45. package/src/safe/GnosisSafeHandler.ts +2 -1
  46. package/src/solidity/SlotsStorage.ts +3 -6
  47. package/src/solidity/SolidityParser.ts +12 -1
  48. package/src/solidity/storage/SlotsStorageTransport.ts +2 -2
  49. package/src/solidity/storage/handlers/SlotBytesHandler.ts +1 -1
  50. package/src/solidity/storage/handlers/SlotMappingHandler.ts +1 -1
@@ -22,6 +22,7 @@ import { TAddress } from '@dequanto/models/TAddress';
22
22
  import { $promise } from '@dequanto/utils/$promise';
23
23
  import { l } from '@dequanto/utils/$logger';
24
24
  import { $bytecode } from '@dequanto/evm/utils/$bytecode';
25
+ import { THex } from '@dequanto/models/THex';
25
26
 
26
27
 
27
28
 
@@ -37,6 +38,13 @@ type TDeploymentOptions = {
37
38
 
38
39
  // Will be used for verification process
39
40
  proxyFor?: TAddress
41
+
42
+ deployment?: {
43
+ // Pending deployment transaction will be re-checked
44
+ tx?: TEth.Hex
45
+ // When false, the implementation won't be updated in proxy
46
+ upgradeProxy?: boolean
47
+ }
40
48
  }
41
49
  type TVerificationOptions = TDeploymentOptions & {
42
50
  // otherwise will be fetched from the deployment TX
@@ -252,6 +260,7 @@ export class Deployments {
252
260
  arguments: constructorArgs,
253
261
  client: this.client,
254
262
  deployer: this.deployer as any,
263
+ tx: opts.deployment?.tx
255
264
  });
256
265
 
257
266
  let deployment = await this.store.saveDeployment(deployedContract, {
@@ -304,6 +313,7 @@ export class Deployments {
304
313
  force: opts?.force,
305
314
  latest: this.opts?.checkBytecode !== false,
306
315
  verification: opts?.verification,
316
+ deployment: opts?.deployment
307
317
  });
308
318
 
309
319
  let data = serializeInitData(id, contractImpl, opts.initialize);
@@ -321,7 +331,8 @@ export class Deployments {
321
331
  implementation: {
322
332
  address: implementationAddress,
323
333
  initData: data
324
- }
334
+ },
335
+ upgradeImplementation: opts?.deployment?.upgradeProxy ?? true
325
336
  })
326
337
 
327
338
  if (contractImplDeployment.implementation == null) {
@@ -45,6 +45,7 @@ interface IDeploymentCtx {
45
45
  options?: {
46
46
  skipStorageLayoutCheck?: boolean
47
47
  }
48
+ upgradeImplementation?: boolean
48
49
  }
49
50
 
50
51
  interface IProxyDeploymentCtx extends IDeploymentCtx {
@@ -151,6 +152,7 @@ export class ProxyDeployment {
151
152
 
152
153
 
153
154
  let hasProxy = await deployments.has(Proxy, proxyOpts);
155
+ let shouldUpdate = ctx.upgradeImplementation ?? true;
154
156
  let {
155
157
  contract: contractProxy,
156
158
  receipt: contractProxyReceipt,
@@ -201,18 +203,21 @@ export class ProxyDeployment {
201
203
  let slotValue = await client.getStorageAt(contractProxy.address, SLOT);
202
204
  let address = `0x` + slotValue.slice(-40);
203
205
  if ($address.eq(address, implAddress) === false) {
204
- await this.requireCompatibleStorageLayout(proxyId, ctx);
205
-
206
- $logger.log(`Upgrading ProxyAdmin(${contractProxyAdmin.address}) to ${implAddress} (${v}) from ${address}`);
207
- let receipt = await Interfaces.call(
208
- deployer,
209
- contractProxyAdmin,
210
- Interfaces.TransparentProxy[v].contractProxyAdmin.upgradeAndCall,
211
- contractProxy.address,
212
- implAddress,
213
- null // data
214
- );
215
- await this.saveStorageLayout(proxyId, ctx);
206
+ if (shouldUpdate) {
207
+ await this.requireCompatibleStorageLayout(proxyId, ctx);
208
+ $logger.log(`Upgrading ProxyAdmin(${contractProxyAdmin.address}) to ${implAddress} (${v}) from ${address}`);
209
+ let receipt = await Interfaces.call(
210
+ deployer,
211
+ contractProxyAdmin,
212
+ Interfaces.TransparentProxy[v].contractProxyAdmin.upgradeAndCall,
213
+ contractProxy.address,
214
+ implAddress,
215
+ null // data
216
+ );
217
+ await this.saveStorageLayout(proxyId, ctx);
218
+ } else {
219
+ $logger.log(`Skip upgrade ProxyAdmin(${contractProxyAdmin.address}) to ${implAddress} (${v}) from ${address}`);
220
+ }
216
221
  }
217
222
  }
218
223
  if (hasProxy === false && contractProxyReceipt != null) {
@@ -142,6 +142,7 @@ export class HardhatProvider {
142
142
  deployer?: EoAccount
143
143
  arguments?: any[]
144
144
  client?: Web3Client
145
+ tx?: TEth.Hex
145
146
  }): Promise<{
146
147
  contract: T
147
148
  receipt: TEth.TxReceipt
@@ -155,7 +156,9 @@ export class HardhatProvider {
155
156
  let receipt: TEth.TxReceipt;
156
157
 
157
158
  try {
158
- receipt = await factory.deploy();
159
+ receipt = options?.tx
160
+ ? await client.getTransactionReceipt(options.tx)
161
+ : await factory.deploy();
159
162
  } catch (error) {
160
163
  let wrapped = new Error(`Deploy ${Ctor.name} failed: ` + error.message + `\n ${error.stack}`);
161
164
  (wrapped as any).data = error.data;
@@ -304,7 +304,8 @@ export class GnosisSafeHandler {
304
304
  if (typeof mix === 'object') {
305
305
  return mix;
306
306
  }
307
- return await ChainAccountService.get(mix)
307
+ let account = await ChainAccountService.get(mix);
308
+ return $require.notNull(account, `Account not found: ${mix}`);
308
309
  })
309
310
  .toArrayAsync();
310
311
 
@@ -104,12 +104,9 @@ export class SlotsStorage {
104
104
 
105
105
  if (is_Object(value)) {
106
106
  // object
107
- await alot
108
- .fromObject(value)
109
- .mapAsync(async entry => {
110
- await this.set([{ key: entry.key, type: 'key' }], entry.value);
111
- })
112
- .toArrayAsync();
107
+ for (let key in value) {
108
+ await this.set([{ key: key, type: 'key' }], value[key]);
109
+ }
113
110
  return;
114
111
  }
115
112
 
@@ -55,6 +55,18 @@ export namespace SolidityParser {
55
55
  })
56
56
  .toArrayAsync({ threads: 1 });
57
57
 
58
+ // fix: remove duplicates due to interfaces and multiple inheritance.
59
+ abisDef = alot(abisDef)
60
+ .map(def => {
61
+ let key = `${def.type} ${def.name} ${def.inputs?.map(input => input.type).join(',')}`;
62
+ return {
63
+ key,
64
+ def,
65
+ }
66
+ })
67
+ .distinctBy(x => x.key)
68
+ .map(x => x.def)
69
+ .toArray();
58
70
  return abisDef;
59
71
  }
60
72
 
@@ -91,7 +103,6 @@ export namespace SolidityParser {
91
103
  .mapAsync(async $event => Ast.getAbi($event, ctx, inheritanceChain))
92
104
  .toArrayAsync();
93
105
 
94
-
95
106
  return [
96
107
  ...abiFns,
97
108
  ...abiGetters,
@@ -169,13 +169,13 @@ export class SlotsStorageTransportForMapping implements ISlotsStorageTransport {
169
169
 
170
170
  }
171
171
 
172
- async getStorageAt (slot: string | number | bigint) {
172
+ async getStorageAt (slot: string | number | bigint, position: number, size: number) {
173
173
  let isValidType = typeof slot === 'number' || typeof slot === 'bigint' || $is.Hex(slot);
174
174
  if (isValidType === false) {
175
175
  throw new Error(`Mapping Slot reader supports only numbers for position ${slot}`);
176
176
  }
177
177
  let location = this.mapToGlobalSlot(BigInt(slot));
178
- let memory = await this.getUnderlyingTransport().getStorageAt(location, 0, 256);
178
+ let memory = await this.getUnderlyingTransport().getStorageAt(location, position, size);
179
179
  return memory;
180
180
  }
181
181
 
@@ -122,7 +122,7 @@ export class SlotBytesHandler extends ASlotsStorageHandler {
122
122
  let slotValue = await this.transport.setStorageAt(this.getSlot(i), 0, 256, buf);
123
123
  return slotValue;
124
124
  })
125
- .toArrayAsync()
125
+ .toArrayAsync({ threads: 1 })
126
126
  }
127
127
 
128
128
  protected getSlot (idx: number) {
@@ -30,7 +30,7 @@ export class SlotMappingHandler extends ASlotsStorageHandler {
30
30
  }
31
31
  let key = keys.shift();
32
32
  let storage = await this.getStorageInner(key);
33
- storage.set(keys, value);
33
+ await storage.set(keys, value);
34
34
  }
35
35
 
36
36
  async fetchAll () {