Skip to content

Commit f870e54

Browse files
committed
fix: remove as much sdk-gov as I can
1 parent 061ef76 commit f870e54

27 files changed

+221
-99
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"@gearbox-protocol/sdk-gov": "^2.21.0",
3636
"@redstone-finance/evm-connector": "^0.6.2",
3737
"abitype": "^1.0.6",
38+
"date-fns": "^4.1.0",
3839
"eventemitter3": "^5.0.1",
3940
"redstone-protocol": "^1.0.5",
4041
"viem": "^2.21.16"

src/GearboxSDK.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import type { NetworkType } from "@gearbox-protocol/sdk-gov";
2-
import { formatBN, TIMELOCK } from "@gearbox-protocol/sdk-gov";
31
import { EventEmitter } from "eventemitter3";
42
import type { Address, Hex, Log } from "viem";
53
import { http } from "viem";
64

75
import type { BaseContract } from "./base";
6+
import type { NetworkType } from "./chain";
87
import { Provider } from "./chain";
98
import {
109
ADDRESS_PROVIDER,
1110
AP_BOT_LIST,
1211
AP_GEAR_STAKING,
1312
AP_GEAR_TOKEN,
1413
AP_ROUTER,
14+
TIMELOCK,
1515
} from "./constants";
1616
import {
1717
AddressProviderContractV3_1,
@@ -24,7 +24,7 @@ import { RouterV3Contract } from "./router";
2424
import type { SDKEventsMap } from "./SDKEvents";
2525
import type { GearboxState } from "./state/state";
2626
import type { ILogger, MultiCall } from "./types";
27-
import { AddressMap } from "./utils";
27+
import { AddressMap, formatBN } from "./utils";
2828
import { createAnvilClient } from "./utils/viem";
2929

3030
export interface SDKAttachOptions {
@@ -167,7 +167,9 @@ export class GearboxSDK extends EventEmitter<SDKEventsMap> {
167167
);
168168

169169
this.#marketRegister = new MarketRegister(this);
170-
await this.#marketRegister.loadMarkets([TIMELOCK.Mainnet]);
170+
await this.#marketRegister.loadMarkets([
171+
TIMELOCK[this.provider.networkType],
172+
]);
171173

172174
try {
173175
const router = this.#addressProvider.getLatestVersion(AP_ROUTER);

src/base/AddressLabeller.ts

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
1-
import {
2-
contractsByNetwork,
3-
emergencyLiquidators,
4-
MULTISIG,
5-
ROUTER_MULTISIG_ADDRESS,
6-
tickerTokensByNetwork,
7-
tokenDataByNetwork,
8-
TREASURY,
9-
VETO_ADMIN,
10-
} from "@gearbox-protocol/sdk-gov";
111
import type { Address } from "viem";
122

13-
import type { NetworkType } from "../chain";
143
import { NOT_DEPLOYED } from "../constants";
154
import { AddressMap } from "../utils";
165
import type { IAddressLabeller } from "./IAddressLabeller";
@@ -44,40 +33,3 @@ export class AddressLabeller implements IAddressLabeller {
4433
return this.#labels.asRecord();
4534
}
4635
}
47-
48-
/**
49-
* This method is using sdk-gov, and is not part of the interface, so it'll be easier to remove it once we get rid of sdk-gov
50-
* @param labeller
51-
* @param network
52-
*/
53-
export function initLegacyLabels(
54-
labeller: IAddressLabeller,
55-
network: NetworkType,
56-
): void {
57-
Object.entries(tokenDataByNetwork[network]).forEach(([label, address]) => {
58-
labeller.set(address, label);
59-
});
60-
61-
Object.entries(tickerTokensByNetwork[network]).forEach(([label, address]) => {
62-
labeller.set(address, label);
63-
});
64-
65-
Object.entries(contractsByNetwork[network]).forEach(([label, address]) => {
66-
labeller.set(address, label);
67-
});
68-
69-
const multisigs = [
70-
{ safe: MULTISIG, label: "Multisig" },
71-
{ safe: ROUTER_MULTISIG_ADDRESS, label: "RouterMultisig" },
72-
{ safe: VETO_ADMIN, label: "VetoAdmin" },
73-
{ safe: TREASURY, label: "Treasury" },
74-
];
75-
76-
multisigs.forEach(({ safe, label }) => {
77-
labeller.set(safe[network], label);
78-
});
79-
80-
emergencyLiquidators.forEach(address => {
81-
labeller.set(address, "EmergencyLiquidator");
82-
});
83-
}

src/base/IAddressLabeller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Address } from "@gearbox-protocol/sdk-gov";
1+
import type { Address } from "viem";
22

33
/**
44
* Helper interface to ease v3.1 refactoring and migration from static methods

src/chain/Provider.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import type { NetworkType } from "@gearbox-protocol/sdk-gov";
21
import type { Chain, PublicClient } from "viem";
32
import { createPublicClient, defineChain, http } from "viem";
43

54
import { AddressLabeller } from "../base/AddressLabeller";
65
import type { IAddressLabeller } from "../base/IAddressLabeller";
6+
import type { NetworkType } from "./chains";
77
import { chains } from "./chains";
88

99
export interface ProviderOptions {
@@ -18,11 +18,7 @@ export class Provider {
1818
public readonly chain: Chain;
1919
public readonly networkType: NetworkType;
2020
public readonly publicClient: PublicClient;
21-
22-
/**
23-
* Note: use interface here to hide implementation that uses sdk-gov
24-
*/
25-
readonly addressLabels: IAddressLabeller;
21+
public readonly addressLabels: IAddressLabeller;
2622

2723
constructor(opts: ProviderOptions) {
2824
const { chainId, networkType, rpcURL, timeout = 120_000 } = opts;

src/constants/address-provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { NetworkType } from "@gearbox-protocol/sdk-gov";
21
import type { Address } from "viem";
32

3+
import type { NetworkType } from "../chain";
44
import { NOT_DEPLOYED } from "./addresses";
55

66
export const NO_VERSION = 0;

src/constants/addresses.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import type { Address } from "viem";
22

3+
import type { NetworkType } from "../chain";
4+
35
/**
46
* Address 0x0000000000000000000000000000000000000000
57
*/
@@ -10,3 +12,20 @@ export const ADDRESS_0X0: Address =
1012
* Dummy address to satisfy `0x${string}` typecheck, but fail on `isAddress` check
1113
*/
1214
export const NOT_DEPLOYED = "0xNOT DEPLOYED";
15+
16+
/**
17+
* Well-known USDC token address used to determine NetworkType on testnets with different chain ids
18+
*/
19+
export const USDC: Record<NetworkType, Address> = {
20+
Mainnet: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
21+
Arbitrum: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
22+
Optimism: "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85",
23+
Base: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
24+
};
25+
26+
export const TIMELOCK: Record<NetworkType, Address> = {
27+
Mainnet: "0xa133C9A92Fb8dDB962Af1cbae58b2723A0bdf23b",
28+
Arbitrum: "0x148DD932eCe1155c11006F5650c6Ff428f8D374A",
29+
Optimism: "0x148DD932eCe1155c11006F5650c6Ff428f8D374A",
30+
Base: NOT_DEPLOYED,
31+
};

src/constants/bot-permissions.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
export enum BotPermissions {
2+
ADD_COLLATERAL = 1,
3+
INCREASE_DEBT = 1 << 1,
4+
DECREASE_DEBT = 1 << 2,
5+
ENABLE_TOKEN = 1 << 3,
6+
DISABLE_TOKEN = 1 << 4,
7+
WITHDRAW_COLLATERAL = 1 << 5,
8+
UPDATE_QUOTA = 1 << 6,
9+
REVOKE_ALLOWANCES = 1 << 7,
10+
11+
EXTERNAL_CALLS = 1 << 16,
12+
13+
ALL_CREDIT_FACADE_CALLS = ADD_COLLATERAL |
14+
WITHDRAW_COLLATERAL |
15+
INCREASE_DEBT |
16+
DECREASE_DEBT |
17+
ENABLE_TOKEN |
18+
DISABLE_TOKEN |
19+
UPDATE_QUOTA |
20+
REVOKE_ALLOWANCES,
21+
22+
ALLS = ALL_CREDIT_FACADE_CALLS | EXTERNAL_CALLS,
23+
}
24+
25+
export function botPermissionsToString(value: bigint): string {
26+
let result = "";
27+
for (let i = 0; i < 16; i++) {
28+
if ((value & (1n << BigInt(i))) !== 0n) {
29+
if (result.length > 0) {
30+
result += " | ";
31+
}
32+
result += BotPermissions[1 << i];
33+
}
34+
}
35+
return result;
36+
}

src/constants/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from "./address-provider";
22
export * from "./addresses";
3+
export * from "./bot-permissions";
34
export * from "./math";

src/core/BotListV3Contract.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { botPermissionsToString } from "@gearbox-protocol/sdk-gov";
21
import type { Address, DecodeFunctionDataReturnType, Log } from "viem";
32
import { parseEventLogs } from "viem";
43

54
import { botListV3Abi } from "../abi";
65
import { BaseContract } from "../base";
6+
import { botPermissionsToString } from "../constants";
77
import type { GearboxSDK } from "../GearboxSDK";
88
import type { BotListState } from "../state";
99

0 commit comments

Comments
 (0)