@gearbox-protocol/sdk 11.0.0-next.2 → 11.0.0-next.3
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/dist/cjs/dev/index.js +2 -0
- package/dist/cjs/dev/replaceStorage.js +77 -0
- package/dist/esm/dev/createAnvilClient.js +1 -6
- package/dist/esm/dev/index.js +1 -0
- package/dist/esm/dev/replaceStorage.js +56 -0
- package/dist/types/dev/index.d.ts +1 -0
- package/dist/types/dev/replaceStorage.d.ts +24 -0
- package/package.json +1 -1
package/dist/cjs/dev/index.js
CHANGED
|
@@ -27,6 +27,7 @@ __reExport(dev_exports, require("./ltUtils.js"), module.exports);
|
|
|
27
27
|
__reExport(dev_exports, require("./migrateFaucet.js"), module.exports);
|
|
28
28
|
__reExport(dev_exports, require("./mint/index.js"), module.exports);
|
|
29
29
|
__reExport(dev_exports, require("./RevolverTransport.js"), module.exports);
|
|
30
|
+
__reExport(dev_exports, require("./replaceStorage.js"), module.exports);
|
|
30
31
|
__reExport(dev_exports, require("./types.js"), module.exports);
|
|
31
32
|
// Annotate the CommonJS export names for ESM import in node:
|
|
32
33
|
0 && (module.exports = {
|
|
@@ -42,5 +43,6 @@ __reExport(dev_exports, require("./types.js"), module.exports);
|
|
|
42
43
|
...require("./migrateFaucet.js"),
|
|
43
44
|
...require("./mint/index.js"),
|
|
44
45
|
...require("./RevolverTransport.js"),
|
|
46
|
+
...require("./replaceStorage.js"),
|
|
45
47
|
...require("./types.js")
|
|
46
48
|
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var replaceStorage_exports = {};
|
|
20
|
+
__export(replaceStorage_exports, {
|
|
21
|
+
replaceStorage: () => replaceStorage
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(replaceStorage_exports);
|
|
24
|
+
var import_viem = require("viem");
|
|
25
|
+
var import_actions = require("viem/actions");
|
|
26
|
+
async function replaceStorage(client, params) {
|
|
27
|
+
const { value, slotMatch, address, abi, functionName, args } = params;
|
|
28
|
+
const newValHex = (0, import_viem.numberToHex)(params.value, { size: 32 });
|
|
29
|
+
const { accessList } = await client.createAccessList({
|
|
30
|
+
to: address,
|
|
31
|
+
data: (0, import_viem.encodeFunctionData)({
|
|
32
|
+
abi,
|
|
33
|
+
functionName,
|
|
34
|
+
args
|
|
35
|
+
})
|
|
36
|
+
});
|
|
37
|
+
for (const { address: addr_, storageKeys } of accessList) {
|
|
38
|
+
const addr = addr_.toLowerCase();
|
|
39
|
+
for (const slot of storageKeys) {
|
|
40
|
+
try {
|
|
41
|
+
const result = await (0, import_actions.readContract)(client, {
|
|
42
|
+
abi,
|
|
43
|
+
address,
|
|
44
|
+
functionName,
|
|
45
|
+
args,
|
|
46
|
+
stateOverride: [
|
|
47
|
+
{
|
|
48
|
+
address: addr,
|
|
49
|
+
stateDiff: [
|
|
50
|
+
{
|
|
51
|
+
slot,
|
|
52
|
+
value: newValHex
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
});
|
|
58
|
+
if (slotMatch(
|
|
59
|
+
result,
|
|
60
|
+
value
|
|
61
|
+
)) {
|
|
62
|
+
await client.setStorageAt({
|
|
63
|
+
address,
|
|
64
|
+
index: slot,
|
|
65
|
+
value: newValHex
|
|
66
|
+
});
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
} catch {
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
75
|
+
0 && (module.exports = {
|
|
76
|
+
replaceStorage
|
|
77
|
+
});
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createPublicClient,
|
|
3
|
-
testActions,
|
|
4
|
-
toHex,
|
|
5
|
-
walletActions
|
|
6
|
-
} from "viem";
|
|
1
|
+
import { createPublicClient, testActions, toHex, walletActions } from "viem";
|
|
7
2
|
function extendAnvilClient(client) {
|
|
8
3
|
return client.extend(testActions({ mode: "anvil" })).extend(walletActions).extend((c) => ({
|
|
9
4
|
anvilNodeInfo: () => anvilNodeInfo(c),
|
package/dist/esm/dev/index.js
CHANGED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {
|
|
2
|
+
encodeFunctionData,
|
|
3
|
+
numberToHex
|
|
4
|
+
} from "viem";
|
|
5
|
+
import { readContract } from "viem/actions";
|
|
6
|
+
async function replaceStorage(client, params) {
|
|
7
|
+
const { value, slotMatch, address, abi, functionName, args } = params;
|
|
8
|
+
const newValHex = numberToHex(params.value, { size: 32 });
|
|
9
|
+
const { accessList } = await client.createAccessList({
|
|
10
|
+
to: address,
|
|
11
|
+
data: encodeFunctionData({
|
|
12
|
+
abi,
|
|
13
|
+
functionName,
|
|
14
|
+
args
|
|
15
|
+
})
|
|
16
|
+
});
|
|
17
|
+
for (const { address: addr_, storageKeys } of accessList) {
|
|
18
|
+
const addr = addr_.toLowerCase();
|
|
19
|
+
for (const slot of storageKeys) {
|
|
20
|
+
try {
|
|
21
|
+
const result = await readContract(client, {
|
|
22
|
+
abi,
|
|
23
|
+
address,
|
|
24
|
+
functionName,
|
|
25
|
+
args,
|
|
26
|
+
stateOverride: [
|
|
27
|
+
{
|
|
28
|
+
address: addr,
|
|
29
|
+
stateDiff: [
|
|
30
|
+
{
|
|
31
|
+
slot,
|
|
32
|
+
value: newValHex
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
});
|
|
38
|
+
if (slotMatch(
|
|
39
|
+
result,
|
|
40
|
+
value
|
|
41
|
+
)) {
|
|
42
|
+
await client.setStorageAt({
|
|
43
|
+
address,
|
|
44
|
+
index: slot,
|
|
45
|
+
value: newValHex
|
|
46
|
+
});
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
} catch {
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export {
|
|
55
|
+
replaceStorage
|
|
56
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Abi } from "abitype";
|
|
2
|
+
import { type ContractFunctionArgs, type ContractFunctionName, type ContractFunctionParameters, type ReadContractReturnType } from "viem";
|
|
3
|
+
import type { AnvilClient } from "./createAnvilClient.js";
|
|
4
|
+
export type ReplaceStorageParams<abi extends Abi | readonly unknown[] = Abi, functionName extends ContractFunctionName<abi, "pure" | "view"> = ContractFunctionName<abi, "pure" | "view">, args extends ContractFunctionArgs<abi, "pure" | "view", functionName> = ContractFunctionArgs<abi, "pure" | "view", functionName>> = ContractFunctionParameters<abi, "pure" | "view", functionName, args, false> & {
|
|
5
|
+
/**
|
|
6
|
+
* New value to set
|
|
7
|
+
*/
|
|
8
|
+
value: bigint;
|
|
9
|
+
/**
|
|
10
|
+
* Comparison function, that returns true if value read from contract matches new value
|
|
11
|
+
* @param readVal - value read by contract function, can be tuple, struct, etc...
|
|
12
|
+
* @param value - new value to be set
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
slotMatch: (readVal: ReadContractReturnType<abi, functionName, args>, value: bigint) => boolean;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Replaces bigint value in contract storage
|
|
19
|
+
* Success is checked by reading contract function and asserting that its return contains new value
|
|
20
|
+
* @param client
|
|
21
|
+
* @param params
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
export declare function replaceStorage<const abi extends Abi | readonly unknown[], functionName extends ContractFunctionName<abi, "pure" | "view">, const args extends ContractFunctionArgs<abi, "pure" | "view", functionName>>(client: AnvilClient, params: ReplaceStorageParams<abi, functionName, args>): Promise<void>;
|