Skip to content

Commit 92acaff

Browse files
authored
Merge pull request #410 from Gearbox-protocol/base-contract
feat: refactor to better reuse code between permissionless/sdk
2 parents b0ed003 + 9ffaa99 commit 92acaff

File tree

166 files changed

+1578
-1830
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

166 files changed

+1578
-1830
lines changed

scripts/example.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { writeFile } from "node:fs/promises";
33
import { pino } from "pino";
44

55
import { AccountsCounterPlugin } from "../src/plugins/accounts-counter/index.js";
6+
import { AdaptersPlugin } from "../src/plugins/adapters/AdaptersPlugin.js";
67
import { BotsPlugin } from "../src/plugins/bots/index.js";
78
import { DegenDistributorsPlugin } from "../src/plugins/degen-distributors/index.js";
89
import { Pools7DAgoPlugin } from "../src/plugins/pools-history/index.js";
@@ -30,14 +31,15 @@ async function example(): Promise<void> {
3031
const sdk = await GearboxSDK.attach({
3132
rpcURLs: [RPC],
3233
timeout: 480_000,
33-
// blockNumber: 22118452, // 21977000, // 22118452
34+
blockNumber: 23928400,
3435
// redstoneHistoricTimestamp: true,
3536
// addressProvider: ADDRESS_PROVIDER,
3637
// marketConfigurators: [],
3738
logger,
3839
// ignoreUpdateablePrices: true,
3940
strictContractTypes: true,
4041
plugins: {
42+
adapters: new AdaptersPlugin(true),
4143
zappers: new ZappersPlugin([], true),
4244
bots: new BotsPlugin(true),
4345
degen: new DegenDistributorsPlugin(true),
@@ -47,9 +49,11 @@ async function example(): Promise<void> {
4749
},
4850
redstone: {
4951
ignoreMissingFeeds: true,
52+
historicTimestamp: true,
5053
},
5154
pyth: {
5255
ignoreMissingFeeds: true,
56+
historicTimestamp: true,
5357
},
5458
});
5559

@@ -80,11 +84,11 @@ async function example(): Promise<void> {
8084
const prefix = RPC.includes("127.0.0.1") ? "anvil_" : "";
8185
const net = sdk.networkType;
8286
await writeFile(
83-
`tmp/state_${kind}_human_${net}_${prefix}${sdk.currentBlock}.json`,
87+
`tmp/state_next_${kind}_human_${net}_${prefix}${sdk.currentBlock}.json`,
8488
json_stringify(sdk.stateHuman()),
8589
);
8690
await writeFile(
87-
`tmp/state_${kind}_${net}_${prefix}${sdk.currentBlock}.json`,
91+
`tmp/state_next_${kind}_${net}_${prefix}${sdk.currentBlock}.json`,
8892
json_stringify(sdk.state),
8993
);
9094

src/dev/create2.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
import { getCode, sendTransaction } from "viem/actions";
2525

2626
import type { GearboxSDK, ILogger } from "../sdk/index.js";
27-
import { SDKConstruct } from "../sdk/index.js";
27+
import { Construct } from "../sdk/index.js";
2828

2929
export const PUBLIC_CREATE2_FACTORY: Address =
3030
"0x4e59b44847b379578588920ca78fbf26c0b4956c";
@@ -69,7 +69,7 @@ export class Create2Deployer<
6969
transport extends Transport = Transport,
7070
chain extends Chain = Chain,
7171
account extends Account = Account,
72-
> extends SDKConstruct {
72+
> extends Construct {
7373
#walletClient: WalletClient<transport, chain, account>;
7474
#logger?: ILogger;
7575

src/dev/mint/AbstractMinter.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import { type Address, parseEther } from "viem";
22
import { ierc20Abi } from "../../abi/iERC20.js";
3-
import {
4-
type GearboxSDK,
5-
type ILogger,
6-
SDKConstruct,
7-
} from "../../sdk/index.js";
3+
import { type GearboxSDK, SDKConstruct } from "../../sdk/index.js";
84
import { iOwnableAbi } from "../abi.js";
95
import type { AnvilClient } from "../createAnvilClient.js";
106
import type { IMinter } from "./types.js";
@@ -14,14 +10,12 @@ export default abstract class AbstractMinter
1410
implements IMinter
1511
{
1612
protected readonly anvil: AnvilClient;
17-
protected readonly logger?: ILogger;
18-
public readonly name: string;
13+
public name: string;
1914

20-
constructor(sdk: GearboxSDK, anvil: AnvilClient, name = "Minter") {
15+
constructor(sdk: GearboxSDK, anvil: AnvilClient) {
2116
super(sdk);
2217
this.anvil = anvil;
23-
this.name = name;
24-
this.logger = sdk.logger?.child?.({ name }) ?? sdk.logger;
18+
this.name = this.constructor.name;
2519
}
2620

2721
public async tryMint(

src/dev/mint/DealMinter.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
import type { Address, TestClient } from "viem";
2-
import type { GearboxSDK } from "../../sdk/index.js";
3-
import type { AnvilClient } from "../createAnvilClient.js";
42
import AbstractMinter from "./AbstractMinter.js";
53
import type { IMinter } from "./types.js";
64

75
export class DealMinter extends AbstractMinter implements IMinter {
8-
constructor(sdk: GearboxSDK, anvil: AnvilClient) {
9-
super(sdk, anvil, "DealMinter");
10-
}
11-
126
public override async mint(
137
token: Address,
148
dest: Address,

src/dev/mint/DirectMinter.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
import { type Address, parseAbi } from "viem";
2-
import type { GearboxSDK } from "../../sdk/index.js";
3-
import type { AnvilClient } from "../createAnvilClient.js";
42
import AbstractMinter from "./AbstractMinter.js";
53
import type { IMinter } from "./types.js";
64

75
export class DirectMinter extends AbstractMinter implements IMinter {
8-
constructor(sdk: GearboxSDK, anvil: AnvilClient) {
9-
super(sdk, anvil, "DirectMinter");
10-
}
11-
126
public override async mint(
137
token: Address,
148
dest: Address,

src/dev/mint/FallbackMinter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export class FallbackMinter extends AbstractMinter implements IMinter {
88
#minters: IMinter[];
99

1010
constructor(sdk: GearboxSDK, anvil: AnvilClient, minters: IMinter[]) {
11-
super(sdk, anvil, "FallbackMinter");
11+
super(sdk, anvil);
1212
this.#minters = minters;
1313
}
1414

src/dev/mint/TransferMinter.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
import { type Address, parseAbi } from "viem";
22
import { ierc20Abi } from "../../abi/iERC20.js";
3-
import type { GearboxSDK } from "../../sdk/index.js";
4-
import type { AnvilClient } from "../createAnvilClient.js";
53
import AbstractMinter from "./AbstractMinter.js";
64
import type { IMinter } from "./types.js";
75

86
export class TransferMinter extends AbstractMinter implements IMinter {
9-
constructor(sdk: GearboxSDK, anvil: AnvilClient) {
10-
super(sdk, anvil, "TransferMinter");
11-
}
12-
137
public override async mint(
148
token: Address,
159
dest: Address,

src/permissionless/bindings/address-provider.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
import { type Address, type PublicClient, stringToHex } from "viem";
2-
import { iAddressProviderV310Abi } from "../../abi/310/generated.js";
3-
import { BaseContract } from "./base-contract.js";
1+
import {
2+
type Address,
3+
type Chain,
4+
type PublicClient,
5+
stringToHex,
6+
type Transport,
7+
} from "viem";
8+
import { AddressProviderV310Contract } from "../../sdk/index.js";
49

5-
const abi = iAddressProviderV310Abi;
6-
7-
export class AddressProviderContract extends BaseContract<typeof abi> {
8-
constructor(address: Address, client: PublicClient) {
9-
super(abi, address, client, "AddressProvider");
10+
export class AddressProviderContract extends AddressProviderV310Contract {
11+
constructor(addr: Address, client: PublicClient<Transport, Chain>) {
12+
super({ client }, addr);
1013
}
1114

1215
async getAddressOrRevert(key: string, version = 0n): Promise<Address> {

src/permissionless/bindings/base-contract.ts

Lines changed: 0 additions & 220 deletions
This file was deleted.

0 commit comments

Comments
 (0)