@gearbox-protocol/sdk 14.4.0 → 14.4.2
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.
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
var createAnvilClient_exports = {};
|
|
20
30
|
__export(createAnvilClient_exports, {
|
|
@@ -26,11 +36,26 @@ __export(createAnvilClient_exports, {
|
|
|
26
36
|
});
|
|
27
37
|
module.exports = __toCommonJS(createAnvilClient_exports);
|
|
28
38
|
var import_viem = require("viem");
|
|
39
|
+
let dealModulePromise;
|
|
40
|
+
async function loadDeal() {
|
|
41
|
+
dealModulePromise ??= import("viem-deal").catch(() => null);
|
|
42
|
+
const mod = await dealModulePromise;
|
|
43
|
+
if (!mod) {
|
|
44
|
+
throw new Error(
|
|
45
|
+
"createAnvilClient: deal action requires the 'viem-deal' package; install it as a dependency"
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
return mod.deal;
|
|
49
|
+
}
|
|
29
50
|
function extendAnvilClient(client) {
|
|
30
|
-
return client.extend((0, import_viem.testActions)({ mode: "anvil" })).extend(import_viem.walletActions).extend((c) => ({
|
|
51
|
+
return client.extend(() => ({ mode: "anvil" })).extend((0, import_viem.testActions)({ mode: "anvil" })).extend(import_viem.walletActions).extend((c) => ({
|
|
31
52
|
anvilNodeInfo: () => anvilNodeInfo(c),
|
|
32
53
|
isAnvil: () => isAnvil(c),
|
|
33
|
-
evmMineDetailed: (timestamp) => evmMineDetailed(c, timestamp)
|
|
54
|
+
evmMineDetailed: (timestamp) => evmMineDetailed(c, timestamp),
|
|
55
|
+
deal: async (params) => {
|
|
56
|
+
const deal = await loadDeal();
|
|
57
|
+
await deal(c, params);
|
|
58
|
+
}
|
|
34
59
|
}));
|
|
35
60
|
}
|
|
36
61
|
function createAnvilClient({
|
|
@@ -39,13 +64,21 @@ function createAnvilClient({
|
|
|
39
64
|
cacheTime = 0,
|
|
40
65
|
pollingInterval = 50
|
|
41
66
|
}) {
|
|
42
|
-
|
|
67
|
+
return (0, import_viem.createTestClient)({
|
|
68
|
+
mode: "anvil",
|
|
43
69
|
chain,
|
|
44
70
|
transport,
|
|
45
71
|
cacheTime,
|
|
46
72
|
pollingInterval
|
|
47
|
-
})
|
|
48
|
-
|
|
73
|
+
}).extend(import_viem.publicActions).extend(import_viem.walletActions).extend((c) => ({
|
|
74
|
+
anvilNodeInfo: () => anvilNodeInfo(c),
|
|
75
|
+
isAnvil: () => isAnvil(c),
|
|
76
|
+
evmMineDetailed: (timestamp) => evmMineDetailed(c, timestamp),
|
|
77
|
+
deal: async (params) => {
|
|
78
|
+
const deal = await loadDeal();
|
|
79
|
+
await deal(c, params);
|
|
80
|
+
}
|
|
81
|
+
}));
|
|
49
82
|
}
|
|
50
83
|
async function isAnvil(client) {
|
|
51
84
|
try {
|
|
@@ -28,8 +28,8 @@ __export(create2_exports, {
|
|
|
28
28
|
handleSalt: () => handleSalt
|
|
29
29
|
});
|
|
30
30
|
module.exports = __toCommonJS(create2_exports);
|
|
31
|
+
var import_abitype = require("abitype");
|
|
31
32
|
var import_viem = require("viem");
|
|
32
|
-
var import_utils = require("viem/utils");
|
|
33
33
|
const PUBLIC_CREATE2_FACTORY = "0x4e59b44847b379578588920ca78fbf26c0b4956c";
|
|
34
34
|
function handleSalt(salt) {
|
|
35
35
|
if (salt.slice(0, 2) !== "0x" || salt.length !== 66) {
|
|
@@ -63,7 +63,7 @@ function createCreate2DeployRawTx(bytecode, salt) {
|
|
|
63
63
|
type: "fallback"
|
|
64
64
|
}
|
|
65
65
|
];
|
|
66
|
-
const signature = (0,
|
|
66
|
+
const signature = (0, import_abitype.formatAbiItem)(deterministicDeployerAbi[0]);
|
|
67
67
|
const contractMethod = {
|
|
68
68
|
name: "fallback",
|
|
69
69
|
inputs: [],
|
|
@@ -1,9 +1,30 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
createTestClient,
|
|
3
|
+
publicActions,
|
|
4
|
+
testActions,
|
|
5
|
+
toHex,
|
|
6
|
+
walletActions
|
|
7
|
+
} from "viem";
|
|
8
|
+
let dealModulePromise;
|
|
9
|
+
async function loadDeal() {
|
|
10
|
+
dealModulePromise ??= import("viem-deal").catch(() => null);
|
|
11
|
+
const mod = await dealModulePromise;
|
|
12
|
+
if (!mod) {
|
|
13
|
+
throw new Error(
|
|
14
|
+
"createAnvilClient: deal action requires the 'viem-deal' package; install it as a dependency"
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
return mod.deal;
|
|
18
|
+
}
|
|
2
19
|
function extendAnvilClient(client) {
|
|
3
|
-
return client.extend(testActions({ mode: "anvil" })).extend(walletActions).extend((c) => ({
|
|
20
|
+
return client.extend(() => ({ mode: "anvil" })).extend(testActions({ mode: "anvil" })).extend(walletActions).extend((c) => ({
|
|
4
21
|
anvilNodeInfo: () => anvilNodeInfo(c),
|
|
5
22
|
isAnvil: () => isAnvil(c),
|
|
6
|
-
evmMineDetailed: (timestamp) => evmMineDetailed(c, timestamp)
|
|
23
|
+
evmMineDetailed: (timestamp) => evmMineDetailed(c, timestamp),
|
|
24
|
+
deal: async (params) => {
|
|
25
|
+
const deal = await loadDeal();
|
|
26
|
+
await deal(c, params);
|
|
27
|
+
}
|
|
7
28
|
}));
|
|
8
29
|
}
|
|
9
30
|
function createAnvilClient({
|
|
@@ -12,13 +33,21 @@ function createAnvilClient({
|
|
|
12
33
|
cacheTime = 0,
|
|
13
34
|
pollingInterval = 50
|
|
14
35
|
}) {
|
|
15
|
-
|
|
36
|
+
return createTestClient({
|
|
37
|
+
mode: "anvil",
|
|
16
38
|
chain,
|
|
17
39
|
transport,
|
|
18
40
|
cacheTime,
|
|
19
41
|
pollingInterval
|
|
20
|
-
})
|
|
21
|
-
|
|
42
|
+
}).extend(publicActions).extend(walletActions).extend((c) => ({
|
|
43
|
+
anvilNodeInfo: () => anvilNodeInfo(c),
|
|
44
|
+
isAnvil: () => isAnvil(c),
|
|
45
|
+
evmMineDetailed: (timestamp) => evmMineDetailed(c, timestamp),
|
|
46
|
+
deal: async (params) => {
|
|
47
|
+
const deal = await loadDeal();
|
|
48
|
+
await deal(c, params);
|
|
49
|
+
}
|
|
50
|
+
}));
|
|
22
51
|
}
|
|
23
52
|
async function isAnvil(client) {
|
|
24
53
|
try {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { formatAbiItem } from "abitype";
|
|
1
2
|
import {
|
|
2
3
|
getCreate2Address,
|
|
3
4
|
stringToHex
|
|
4
5
|
} from "viem";
|
|
5
|
-
import { formatAbiItem } from "viem/utils";
|
|
6
6
|
const PUBLIC_CREATE2_FACTORY = "0x4e59b44847b379578588920ca78fbf26c0b4956c";
|
|
7
7
|
function handleSalt(salt) {
|
|
8
8
|
if (salt.slice(0, 2) !== "0x" || salt.length !== 66) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Block, Chain, Client, Hex, Prettify, PublicClient, TestActions, TestRpcSchema, Transport, WalletClient } from "viem";
|
|
1
|
+
import type { Account, Address, Block, Chain, Client, Hex, Prettify, PublicClient, TestActions, TestRpcSchema, Transport, WalletClient } from "viem";
|
|
2
2
|
export interface AnvilNodeInfo {
|
|
3
3
|
currentBlockNumber: string;
|
|
4
4
|
currentBlockTimestamp: number;
|
|
@@ -30,6 +30,20 @@ export type AnvilRPCSchema = [
|
|
|
30
30
|
ReturnType: Block<Hex>[];
|
|
31
31
|
}
|
|
32
32
|
];
|
|
33
|
+
export interface AnvilDealParameters {
|
|
34
|
+
/**
|
|
35
|
+
* ERC20 token address.
|
|
36
|
+
*/
|
|
37
|
+
erc20: Address;
|
|
38
|
+
/**
|
|
39
|
+
* Account that should receive the tokens.
|
|
40
|
+
*/
|
|
41
|
+
account: Account | Address;
|
|
42
|
+
/**
|
|
43
|
+
* Token amount in raw units (no decimals applied).
|
|
44
|
+
*/
|
|
45
|
+
amount: bigint;
|
|
46
|
+
}
|
|
33
47
|
export type AnvilActions = {
|
|
34
48
|
anvilNodeInfo: () => Promise<AnvilNodeInfo>;
|
|
35
49
|
isAnvil: () => Promise<boolean>;
|
|
@@ -38,6 +52,11 @@ export type AnvilActions = {
|
|
|
38
52
|
* Block timestamp in seconds
|
|
39
53
|
*/
|
|
40
54
|
timestamp: bigint | number) => Promise<Block<Hex> | undefined>;
|
|
55
|
+
/**
|
|
56
|
+
* Deals ERC20 tokens to an account by overriding the storage of
|
|
57
|
+
* `balanceOf(account)`. Requires `viem-deal` as a peer dependency.
|
|
58
|
+
*/
|
|
59
|
+
deal: (params: AnvilDealParameters) => Promise<void>;
|
|
41
60
|
};
|
|
42
61
|
export type AnvilClient = Prettify<{
|
|
43
62
|
mode: "anvil";
|
|
@@ -48,6 +67,14 @@ export interface AnvilClientConfig<transport extends Transport = Transport, chai
|
|
|
48
67
|
cacheTime?: number;
|
|
49
68
|
pollingInterval?: number;
|
|
50
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Extends an arbitrary viem `PublicClient` with anvil + wallet actions plus
|
|
72
|
+
* the SDK's bonus actions (`anvilNodeInfo`, `isAnvil`, `evmMineDetailed`,
|
|
73
|
+
* `deal`).
|
|
74
|
+
*
|
|
75
|
+
* Used to lift `sdk.client` into an `AnvilClient` shape on the fly when test
|
|
76
|
+
* RPCs (impersonateAccount, setBalance, setStorageAt, ...) are needed.
|
|
77
|
+
*/
|
|
51
78
|
export declare function extendAnvilClient(client: PublicClient): AnvilClient;
|
|
52
79
|
export declare function createAnvilClient({ chain, transport, cacheTime, pollingInterval, }: AnvilClientConfig): AnvilClient;
|
|
53
80
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gearbox-protocol/sdk",
|
|
3
|
-
"version": "14.4.
|
|
3
|
+
"version": "14.4.2",
|
|
4
4
|
"description": "Gearbox SDK",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "./dist/cjs/sdk/index.js",
|
|
@@ -109,6 +109,11 @@
|
|
|
109
109
|
"axios": "^1.0.0",
|
|
110
110
|
"viem-deal": "^2.0.4"
|
|
111
111
|
},
|
|
112
|
+
"peerDependenciesMeta": {
|
|
113
|
+
"viem-deal": {
|
|
114
|
+
"optional": true
|
|
115
|
+
}
|
|
116
|
+
},
|
|
112
117
|
"commitlint": {
|
|
113
118
|
"extends": [
|
|
114
119
|
"@commitlint/config-conventional"
|