dequanto 0.2.52 → 0.2.55
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.
- package/lib/cjs/contracts/ContractStorageReaderBase.js.map +1 -1
- package/lib/cjs/contracts/deploy/proxy/$proxyDeploy.js +4 -4
- package/lib/cjs/contracts/deploy/proxy/$proxyDeploy.js.map +1 -1
- package/lib/cjs/gen/Generator.js +1 -0
- package/lib/cjs/gen/Generator.js.map +1 -1
- package/lib/cjs/gen/GeneratorFromAbi.js +38 -9
- package/lib/cjs/gen/GeneratorFromAbi.js.map +1 -1
- package/lib/cjs/gen/GeneratorStorageReader.js +13 -2
- package/lib/cjs/gen/GeneratorStorageReader.js.map +1 -1
- package/lib/cjs/solidity/SlotsParser/Ast.js +20 -2
- package/lib/cjs/solidity/SlotsParser/Ast.js.map +1 -1
- package/lib/cjs/solidity/SlotsParser.js +31 -19
- package/lib/cjs/solidity/SlotsParser.js.map +1 -1
- package/lib/cjs/solidity/SlotsStorage.js +4 -1
- package/lib/cjs/solidity/SlotsStorage.js.map +1 -1
- package/lib/cjs/solidity/storage/SlotsStorageTransport.js +6 -9
- package/lib/cjs/solidity/storage/SlotsStorageTransport.js.map +1 -1
- package/lib/cjs/solidity/storage/handlers/SlotDynamicArrayHandler.js +1 -1
- package/lib/cjs/solidity/storage/handlers/SlotDynamicArrayHandler.js.map +1 -1
- package/lib/cjs/utils/$bigint.js +3 -1
- package/lib/cjs/utils/$bigint.js.map +1 -1
- package/lib/esm/contracts/ContractStorageReaderBase.js.map +1 -1
- package/lib/esm/contracts/deploy/proxy/$proxyDeploy.js.map +1 -1
- package/lib/esm/contracts/deploy/proxy/$proxyDeploy.mjs +4 -4
- package/lib/esm/gen/Generator.js.map +1 -1
- package/lib/esm/gen/Generator.mjs +1 -0
- package/lib/esm/gen/GeneratorFromAbi.js.map +1 -1
- package/lib/esm/gen/GeneratorFromAbi.mjs +38 -9
- package/lib/esm/gen/GeneratorStorageReader.js.map +1 -1
- package/lib/esm/gen/GeneratorStorageReader.mjs +13 -2
- package/lib/esm/solidity/SlotsParser/Ast.js.map +1 -1
- package/lib/esm/solidity/SlotsParser/Ast.mjs +20 -2
- package/lib/esm/solidity/SlotsParser.js.map +1 -1
- package/lib/esm/solidity/SlotsParser.mjs +31 -19
- package/lib/esm/solidity/SlotsStorage.js.map +1 -1
- package/lib/esm/solidity/SlotsStorage.mjs +4 -1
- package/lib/esm/solidity/storage/SlotsStorageTransport.js.map +1 -1
- package/lib/esm/solidity/storage/SlotsStorageTransport.mjs +6 -9
- package/lib/esm/solidity/storage/handlers/SlotDynamicArrayHandler.js.map +1 -1
- package/lib/esm/solidity/storage/handlers/SlotDynamicArrayHandler.mjs +1 -1
- package/lib/esm/utils/$bigint.js.map +1 -1
- package/lib/esm/utils/$bigint.mjs +3 -1
- package/lib/types/contracts/ContractStorageReaderBase.d.ts +2 -2
- package/lib/types/gen/Generator.d.ts +17 -0
- package/lib/types/gen/GeneratorFromAbi.d.ts +7 -0
- package/lib/types/gen/GeneratorStorageReader.d.ts +1 -0
- package/lib/types/solidity/SlotsParser/models.d.ts +6 -1
- package/lib/types/solidity/SlotsStorage.d.ts +4 -4
- package/lib/types/solidity/storage/SlotsStorageTransport.d.ts +5 -5
- package/lib/types/utils/$bigint.d.ts +1 -1
- package/package.json +2 -2
- package/src/contracts/ContractStorageReaderBase.ts +2 -2
- package/src/contracts/deploy/proxy/$proxyDeploy.ts +4 -4
- package/src/gen/Generator.ts +4 -0
- package/src/gen/GeneratorFromAbi.ts +40 -10
- package/src/gen/GeneratorStorageReader.ts +20 -7
- package/src/solidity/SlotsParser/Ast.ts +20 -2
- package/src/solidity/SlotsParser/models.ts +5 -1
- package/src/solidity/SlotsParser.ts +38 -22
- package/src/solidity/SlotsStorage.ts +8 -3
- package/src/solidity/storage/SlotsStorageTransport.ts +6 -9
- package/src/solidity/storage/handlers/SlotDynamicArrayHandler.ts +1 -1
- package/src/utils/$bigint.ts +4 -1
- package/tsconfig.json +2 -1
- package/lib/cjs/gen/Ast.js +0 -14
- package/lib/cjs/gen/Ast.js.map +0 -1
- package/lib/esm/gen/Ast.js.map +0 -1
- package/lib/esm/gen/Ast.mjs +0 -10
- package/lib/types/gen/Ast.d.ts +0 -3
- package/src/gen/Ast.ts +0 -12
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TEth } from 'dequanto/models/TEth'
|
|
1
2
|
import type { SourceFile } from './SourceFile'
|
|
2
3
|
|
|
3
4
|
export type TSourceFileImport = {
|
|
@@ -8,7 +9,7 @@ export type TSourceFileImport = {
|
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
export interface ISlotVarDefinition {
|
|
11
|
-
slot:
|
|
12
|
+
slot: bigint
|
|
12
13
|
position: number
|
|
13
14
|
name: string
|
|
14
15
|
type: string
|
|
@@ -20,6 +21,9 @@ export interface ISlotVarDefinition {
|
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
|
|
24
|
+
/** Slot definitions accepted from callers, including older generated readers. */
|
|
25
|
+
export type ISlotVarDefinitionInput = Omit<ISlotVarDefinition, 'slot'> & { slot: number | bigint | TEth.Hex | string };
|
|
26
|
+
|
|
23
27
|
export interface ISlotsParserOption {
|
|
24
28
|
/* Optionally provide additional sources in memory */
|
|
25
29
|
files?: { path: string, content: string }[]
|
|
@@ -4,7 +4,9 @@ import type {
|
|
|
4
4
|
ArrayTypeName,
|
|
5
5
|
ContractDefinition,
|
|
6
6
|
ElementaryTypeName,
|
|
7
|
+
Expression,
|
|
7
8
|
Mapping,
|
|
9
|
+
StateVariableDeclarationVariable,
|
|
8
10
|
StructDefinition,
|
|
9
11
|
TypeName,
|
|
10
12
|
UserDefinedTypeName
|
|
@@ -19,6 +21,7 @@ import { Ast } from './SlotsParser/Ast';
|
|
|
19
21
|
import { ISlotsParserOption, ISlotVarDefinition } from './SlotsParser/models';
|
|
20
22
|
|
|
21
23
|
import type { TAbiInput } from 'dequanto/types/TAbi';
|
|
24
|
+
import { $bigint } from 'dequanto/utils/$bigint';
|
|
22
25
|
|
|
23
26
|
const SLOT_SIZE = 256;
|
|
24
27
|
export namespace SlotsParser {
|
|
@@ -34,7 +37,7 @@ export namespace SlotsParser {
|
|
|
34
37
|
let util = TypeAbiUtil.get(input)
|
|
35
38
|
if (util) {
|
|
36
39
|
return {
|
|
37
|
-
slot: null as
|
|
40
|
+
slot: null as bigint,
|
|
38
41
|
position: null as number,
|
|
39
42
|
name: input.name,
|
|
40
43
|
size: await util.sizeOf(),
|
|
@@ -81,10 +84,20 @@ export namespace SlotsParser {
|
|
|
81
84
|
})
|
|
82
85
|
.toArray();
|
|
83
86
|
|
|
84
|
-
let offset = { slot:
|
|
87
|
+
let offset = { slot: 0n, position: 0 };
|
|
88
|
+
let contract = inheritanceChain[inheritanceChain.length - 1]?.contract;
|
|
89
|
+
if (Ast.isContractDefinition(contract) && contract.storageLayout != null) {
|
|
90
|
+
// The most derived contract sets the base slot for the entire inheritance chain.
|
|
91
|
+
let baseSlot = $require.notNull(Ast.evaluate<bigint>(contract.storageLayout), `StorageLayout eval failed`);
|
|
92
|
+
if (baseSlot < 0n || baseSlot >= 2n ** 256n) {
|
|
93
|
+
throw new Error('Custom storage layout must be within the uint256 slot range');
|
|
94
|
+
}
|
|
95
|
+
offset.slot = baseSlot;
|
|
96
|
+
}
|
|
85
97
|
slotsDef = applyPositions(slotsDef, offset);
|
|
86
98
|
return slotsDef;
|
|
87
99
|
}
|
|
100
|
+
|
|
88
101
|
async function extractSlotsSingle (contract: TypeUtil.ITypeCtx, opts?: {
|
|
89
102
|
withConstants?: boolean
|
|
90
103
|
withImmutables?: boolean
|
|
@@ -92,6 +105,9 @@ export namespace SlotsParser {
|
|
|
92
105
|
|
|
93
106
|
let vars = Ast.isStructDefinition(contract.contract) ? contract.contract.members : alot(Ast.getVariableDeclarations(contract.contract))
|
|
94
107
|
.map($var => {
|
|
108
|
+
if (($var as StateVariableDeclarationVariable).isTransient) {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
95
111
|
if ($var.isDeclaredConst && opts?.withConstants !== true) {
|
|
96
112
|
return null;
|
|
97
113
|
}
|
|
@@ -108,7 +124,7 @@ export namespace SlotsParser {
|
|
|
108
124
|
let util = TypeUtil.get(v.typeName, contract);
|
|
109
125
|
if (util) {
|
|
110
126
|
let $var = {
|
|
111
|
-
slot: null as
|
|
127
|
+
slot: null as bigint,
|
|
112
128
|
position: null as number,
|
|
113
129
|
name: v.name,
|
|
114
130
|
size: await util.sizeOf(),
|
|
@@ -137,8 +153,8 @@ export namespace SlotsParser {
|
|
|
137
153
|
return slotsDef;
|
|
138
154
|
}
|
|
139
155
|
|
|
140
|
-
function applyPositions ($vars: ISlotVarDefinition[], offset?: { slot: number, position: number }) {
|
|
141
|
-
|
|
156
|
+
function applyPositions ($vars: ISlotVarDefinition[], offset?: { slot: number | bigint, position: number }) {
|
|
157
|
+
let cursor = { slot: BigInt(offset?.slot ?? 0), position: offset?.position ?? 0 };
|
|
142
158
|
|
|
143
159
|
$vars.forEach($var => {
|
|
144
160
|
if ($var.memory === 'constant' || $var.memory === 'immutable') {
|
|
@@ -146,38 +162,38 @@ export namespace SlotsParser {
|
|
|
146
162
|
return;
|
|
147
163
|
}
|
|
148
164
|
if ($var.size === Infinity) {
|
|
149
|
-
if (
|
|
165
|
+
if (cursor.position > 0) {
|
|
150
166
|
// was previously moved further in a slot, so just take the next slot
|
|
151
|
-
|
|
152
|
-
|
|
167
|
+
cursor.position = 0;
|
|
168
|
+
cursor.slot += 1n;
|
|
153
169
|
}
|
|
154
170
|
|
|
155
|
-
$var.slot =
|
|
171
|
+
$var.slot = cursor.slot;
|
|
156
172
|
$var.position = 0;
|
|
157
173
|
|
|
158
174
|
// move to the start of the next slot
|
|
159
|
-
|
|
160
|
-
|
|
175
|
+
cursor.slot += 1n;
|
|
176
|
+
cursor.position = 0;
|
|
161
177
|
return;
|
|
162
178
|
}
|
|
163
|
-
if ($var.size <= SLOT_SIZE -
|
|
164
|
-
$var.slot =
|
|
165
|
-
$var.position =
|
|
166
|
-
|
|
179
|
+
if ($var.size <= SLOT_SIZE - cursor.position && TypeUtil.isComplexType($var.type) === false) {
|
|
180
|
+
$var.slot = cursor.slot;
|
|
181
|
+
$var.position = cursor.position;
|
|
182
|
+
cursor.position += $var.size;
|
|
167
183
|
return;
|
|
168
184
|
}
|
|
169
|
-
if (
|
|
170
|
-
|
|
171
|
-
|
|
185
|
+
if (cursor.position > 0) {
|
|
186
|
+
cursor.slot += 1n;
|
|
187
|
+
cursor.position = 0;
|
|
172
188
|
// > moves to next slot
|
|
173
189
|
}
|
|
174
|
-
$var.slot =
|
|
175
|
-
$var.position =
|
|
190
|
+
$var.slot = cursor.slot;
|
|
191
|
+
$var.position = cursor.position;
|
|
176
192
|
|
|
177
193
|
let slots = Math.floor($var.size / SLOT_SIZE);
|
|
178
194
|
|
|
179
|
-
|
|
180
|
-
|
|
195
|
+
cursor.slot += BigInt(slots);
|
|
196
|
+
cursor.position = $var.size % SLOT_SIZE;
|
|
181
197
|
});
|
|
182
198
|
return $vars;
|
|
183
199
|
}
|
|
@@ -13,7 +13,7 @@ import { SlotMappingHandler } from './storage/handlers/SlotMappingHandler';
|
|
|
13
13
|
import { SlotStringHandler } from './storage/handlers/SlotStringHandler';
|
|
14
14
|
import { Accessor, IAccessorItem } from './storage/Accessor';
|
|
15
15
|
import { SlotStructHandler } from './storage/handlers/SlotStructHandler';
|
|
16
|
-
import { ISlotVarDefinition } from './SlotsParser/models';
|
|
16
|
+
import { ISlotVarDefinition, ISlotVarDefinitionInput } from './SlotsParser/models';
|
|
17
17
|
import { $types } from './utils/$types';
|
|
18
18
|
import { SlotBytesHandler } from './storage/handlers/SlotBytesHandler';
|
|
19
19
|
import { SlotValueConstantHandler } from './storage/handlers/SlotValueConstantHandler';
|
|
@@ -22,7 +22,7 @@ import { TEth } from 'dequanto/models/TEth';
|
|
|
22
22
|
|
|
23
23
|
export class SlotsStorage {
|
|
24
24
|
|
|
25
|
-
static createWithClient(client: Web3Client, address: TAddress, slots:
|
|
25
|
+
static createWithClient(client: Web3Client, address: TAddress, slots: ISlotVarDefinitionInput[], params?: {
|
|
26
26
|
blockNumber?: number
|
|
27
27
|
storageOffset?: TEth.Hex | bigint
|
|
28
28
|
}) {
|
|
@@ -35,8 +35,13 @@ export class SlotsStorage {
|
|
|
35
35
|
return new SlotsStorage(transport, slots)
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
public slots: ISlotVarDefinition[];
|
|
39
39
|
|
|
40
|
+
constructor(public transport: ISlotsStorageTransport, slots: ISlotVarDefinitionInput[]) {
|
|
41
|
+
this.slots = slots.map(slot => ({
|
|
42
|
+
...slot,
|
|
43
|
+
slot: slot.slot == null ? null : BigInt(slot.slot)
|
|
44
|
+
}));
|
|
40
45
|
}
|
|
41
46
|
|
|
42
47
|
async get<T = any>(path?: string | (string | number | bigint)[] |IAccessorItem[]): Promise<T> {
|
|
@@ -56,7 +56,7 @@ export class SlotsCursorTransport implements ISlotsStorageTransport {
|
|
|
56
56
|
return this.transport.extractMappingKeys(ctx)
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
mapToGlobalSlot (slot =
|
|
59
|
+
mapToGlobalSlot (slot: string | number | bigint = 0n) {
|
|
60
60
|
return BigInt(this.cursor.slot) + BigInt(slot);
|
|
61
61
|
}
|
|
62
62
|
}
|
|
@@ -109,7 +109,7 @@ export class SlotsStorageTransport implements ISlotsStorageTransport {
|
|
|
109
109
|
throw new Error(`SlotMappingReader does not support the fetchAll method, as the size could be infinite`);
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
mapToGlobalSlot (slot =
|
|
112
|
+
mapToGlobalSlot (slot: string | number | bigint = 0n) {
|
|
113
113
|
return BigInt(slot);
|
|
114
114
|
}
|
|
115
115
|
|
|
@@ -122,26 +122,23 @@ export class SlotsStorageTransportForArray implements ISlotsStorageTransport {
|
|
|
122
122
|
|
|
123
123
|
|
|
124
124
|
|
|
125
|
-
constructor (public transport: ISlotsStorageTransport, private slotNr: number | bigint, private elementI: number = 0, private slotsPerElement: number =
|
|
125
|
+
constructor (public transport: ISlotsStorageTransport, private slotNr: number | bigint, private elementI: number = 0, private slotsPerElement: number | bigint = 1n, private slot?: ISlotVarDefinition) {
|
|
126
126
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
async getStorageAt (slot: string | number | bigint, position = 0, size = 256) {
|
|
130
|
-
if (typeof slot !== 'number') {
|
|
131
|
-
throw new Error(`Array slot reader supports only numeric positions. Slot ${slot}`);
|
|
132
|
-
}
|
|
133
130
|
let location = this.mapToGlobalSlot(slot);
|
|
134
131
|
let memory = await this.getUnderlyingTransport().getStorageAt(location, position, size);
|
|
135
132
|
return memory;
|
|
136
133
|
}
|
|
137
134
|
|
|
138
135
|
async setStorageAt(slot: string | number | bigint, position: number, size: number, buffer: string | number | bigint | boolean): Promise<void> {
|
|
139
|
-
let location = this.mapToGlobalSlot(
|
|
136
|
+
let location = this.mapToGlobalSlot(BigInt(slot));
|
|
140
137
|
let memory = await this.transport.setStorageAt(location, position, size, buffer);
|
|
141
138
|
return memory;
|
|
142
139
|
}
|
|
143
140
|
|
|
144
|
-
mapToGlobalSlot (slotPositionNr: number | bigint =
|
|
141
|
+
mapToGlobalSlot (slotPositionNr: string | number | bigint = 0n) {
|
|
145
142
|
let packedRoot = this.transport?.mapToGlobalSlot(this.slotNr) ?? 0n;
|
|
146
143
|
let packedNextHash = $abiUtils.encodePacked({
|
|
147
144
|
value: $hex.padBytes($hex.toHexBuffer(packedRoot), 32),
|
|
@@ -165,7 +162,7 @@ export class SlotsStorageTransportForArray implements ISlotsStorageTransport {
|
|
|
165
162
|
}
|
|
166
163
|
|
|
167
164
|
export class SlotsStorageTransportForMapping implements ISlotsStorageTransport {
|
|
168
|
-
constructor (public transport: ISlotsStorageTransport, private slotNr: number, private key: any, private slotsPerElement: number =
|
|
165
|
+
constructor (public transport: ISlotsStorageTransport, private slotNr: number | bigint, private key: any, private slotsPerElement: number | bigint = 1n) {
|
|
169
166
|
|
|
170
167
|
}
|
|
171
168
|
|
|
@@ -48,7 +48,7 @@ export class SlotDynamicArrayHandler extends ASlotDynamicArray {
|
|
|
48
48
|
let baseSlots = await SlotsParser.slotsFromAbi(baseType);
|
|
49
49
|
|
|
50
50
|
// take the last slot index as that one will give us the TOTAL SLOTs per element
|
|
51
|
-
let slotsPerElement = baseSlots[baseSlots.length - 1].slot +
|
|
51
|
+
let slotsPerElement = baseSlots[baseSlots.length - 1].slot + 1n;
|
|
52
52
|
|
|
53
53
|
let transport = new SlotsStorageTransportForArray(this.transport, this.slot.slot, key.key, slotsPerElement, this.slot);
|
|
54
54
|
let storage = new SlotsStorage(transport, baseSlots);
|
package/src/utils/$bigint.ts
CHANGED
|
@@ -68,9 +68,12 @@ export namespace $bigint {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
/**
|
|
71
|
-
* @param amount e.g "2.4 ether", "10 gwei", "1.7^18", "123456", "1.7e18"
|
|
71
|
+
* @param amount e.g "2.4 ether", "10 gwei", "1.7^18", "123456", "1.7e18", "1_000_000"
|
|
72
72
|
*/
|
|
73
73
|
export function parse (amount: string): bigint {
|
|
74
|
+
// clean 1_000
|
|
75
|
+
amount = amount.replaceAll('_', '');
|
|
76
|
+
|
|
74
77
|
if (/^\d+$/.test(amount) || $is.Hex(amount) ) {
|
|
75
78
|
return BigInt(amount);
|
|
76
79
|
}
|
package/tsconfig.json
CHANGED
package/lib/cjs/gen/Ast.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
//import parser from '@solidity-parser/parser';
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.Ast = void 0;
|
|
5
|
-
class Ast {
|
|
6
|
-
static parse(source) {
|
|
7
|
-
// let ast = parser.parse(source, {
|
|
8
|
-
// tolerant: true,
|
|
9
|
-
// });
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
exports.Ast = Ast;
|
|
13
|
-
//# sourceMappingURL=Ast.js.map
|
|
14
|
-
//# sourceMappingURL=Ast.ts.map
|
package/lib/cjs/gen/Ast.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Ast.js","sourceRoot":"","sources":["../../../src/gen/Ast.ts"],"names":[],"mappings":";AAAA,+CAA+C;;;AAG/C,MAAa,GAAG;IAEZ,MAAM,CAAC,KAAK,CAAE,MAAc;QACxB,mCAAmC;QACnC,sBAAsB;QACtB,MAAM;IAEV,CAAC;CACJ;AARD,kBAQC"}
|
package/lib/esm/gen/Ast.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Ast.js","sourceRoot":"","sources":["../../../src/gen/Ast.ts"],"names":[],"mappings":";AAAA,+CAA+C;;;AAG/C,MAAa,GAAG;IAEZ,MAAM,CAAC,KAAK,CAAE,MAAc;QACxB,mCAAmC;QACnC,sBAAsB;QACtB,MAAM;IAEV,CAAC;CACJ;AARD,kBAQC"}
|
package/lib/esm/gen/Ast.mjs
DELETED
package/lib/types/gen/Ast.d.ts
DELETED