@gearbox-protocol/sdk 9.16.1 → 10.0.0-next.1
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/AccountOpener.js +2 -5
- package/dist/cjs/dev/createAnvilClient.js +16 -13
- package/dist/cjs/dev/migrateFaucet.js +3 -6
- package/dist/cjs/permissionless/bindings/instance-manager.js +1 -1
- package/dist/cjs/plugins/accounts-counter/AccountsCounterPlugin.js +1 -1
- package/dist/cjs/plugins/degen-distributors/DegenDistributorsPlugin.js +1 -1
- package/dist/cjs/plugins/pools-history/Pools7DAgoPlugin.js +2 -2
- package/dist/cjs/plugins/zappers/ZappersPlugin.js +2 -2
- package/dist/cjs/sdk/GearboxSDK.js +70 -39
- package/dist/cjs/sdk/accountMigration/AbstractMigrateCreditAccountsService.js +1 -1
- package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +1 -1
- package/dist/cjs/sdk/accounts/CreditAccountsServiceV300.js +1 -1
- package/dist/cjs/sdk/base/BaseContract.js +6 -9
- package/dist/cjs/sdk/base/SDKConstruct.js +4 -7
- package/dist/cjs/sdk/chain/chains.js +1 -1
- package/dist/cjs/sdk/chain/index.js +1 -3
- package/dist/cjs/sdk/core/BotListV3Contract.js +5 -5
- package/dist/cjs/sdk/core/GearStakingV3Contract.js +1 -1
- package/dist/cjs/sdk/core/address-provider/AbstractAddressProviderContract.js +1 -1
- package/dist/cjs/sdk/core/address-provider/AddressProviderV300Contract.js +2 -2
- package/dist/cjs/sdk/core/address-provider/createAddressProvider.js +1 -1
- package/dist/cjs/sdk/gauges/GaugeStakingService.js +1 -1
- package/dist/cjs/sdk/market/MarketConfiguratorContract.js +3 -3
- package/dist/cjs/sdk/market/MarketRegister.js +20 -26
- package/dist/cjs/sdk/market/MarketSuite.js +1 -1
- package/dist/cjs/sdk/market/credit/CreditConfiguratorV300Contract.js +2 -2
- package/dist/cjs/sdk/market/credit/CreditConfiguratorV310Contract.js +2 -2
- package/dist/cjs/sdk/market/oracle/PriceOracleBaseContract.js +1 -1
- package/dist/cjs/sdk/market/oracle/PriceOracleV300Contract.js +1 -1
- package/dist/cjs/sdk/market/pricefeeds/AbstractLPPriceFeed.js +1 -1
- package/dist/cjs/sdk/market/pricefeeds/BalancerStablePriceFeed.js +1 -1
- package/dist/cjs/sdk/market/pricefeeds/BalancerWeightedPriceFeed.js +1 -1
- package/dist/cjs/sdk/market/pricefeeds/CurveCryptoPriceFeed.js +1 -1
- package/dist/cjs/sdk/market/pricefeeds/CurveStablePriceFeed.js +1 -1
- package/dist/cjs/sdk/market/pricefeeds/CurveUSDPriceFeed.js +1 -1
- package/dist/cjs/sdk/market/pricefeeds/Erc4626PriceFeed.js +2 -2
- package/dist/cjs/sdk/market/pricefeeds/MellowLRTPriceFeed.js +1 -1
- package/dist/cjs/sdk/market/pricefeeds/PriceFeedsRegister.js +2 -2
- package/dist/cjs/sdk/market/pricefeeds/WstETHPriceFeed.js +1 -1
- package/dist/cjs/sdk/market/pricefeeds/YearnPriceFeed.js +1 -1
- package/dist/cjs/sdk/plugins/BasePlugin.js +3 -6
- package/dist/cjs/sdk/plugins/V300StalenessPeriodPlugin.js +1 -1
- package/dist/cjs/sdk/router/RouterV300Contract.js +4 -4
- package/dist/esm/dev/AccountOpener.js +3 -6
- package/dist/esm/dev/createAnvilClient.js +21 -14
- package/dist/esm/dev/migrateFaucet.js +4 -7
- package/dist/esm/permissionless/bindings/instance-manager.js +1 -1
- package/dist/esm/plugins/accounts-counter/AccountsCounterPlugin.js +1 -1
- package/dist/esm/plugins/degen-distributors/DegenDistributorsPlugin.js +1 -1
- package/dist/esm/plugins/pools-history/Pools7DAgoPlugin.js +2 -2
- package/dist/esm/plugins/zappers/ZappersPlugin.js +2 -2
- package/dist/esm/sdk/GearboxSDK.js +78 -46
- package/dist/esm/sdk/accountMigration/AbstractMigrateCreditAccountsService.js +1 -1
- package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +1 -1
- package/dist/esm/sdk/accounts/CreditAccountsServiceV300.js +1 -1
- package/dist/esm/sdk/base/BaseContract.js +6 -9
- package/dist/esm/sdk/base/SDKConstruct.js +4 -7
- package/dist/esm/sdk/chain/chains.js +1 -1
- package/dist/esm/sdk/chain/index.js +0 -1
- package/dist/esm/sdk/core/BotListV3Contract.js +5 -5
- package/dist/esm/sdk/core/GearStakingV3Contract.js +1 -1
- package/dist/esm/sdk/core/address-provider/AbstractAddressProviderContract.js +1 -1
- package/dist/esm/sdk/core/address-provider/AddressProviderV300Contract.js +2 -2
- package/dist/esm/sdk/core/address-provider/createAddressProvider.js +1 -1
- package/dist/esm/sdk/gauges/GaugeStakingService.js +1 -1
- package/dist/esm/sdk/market/MarketConfiguratorContract.js +3 -3
- package/dist/esm/sdk/market/MarketRegister.js +20 -26
- package/dist/esm/sdk/market/MarketSuite.js +1 -1
- package/dist/esm/sdk/market/credit/CreditConfiguratorV300Contract.js +2 -2
- package/dist/esm/sdk/market/credit/CreditConfiguratorV310Contract.js +2 -2
- package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +1 -1
- package/dist/esm/sdk/market/oracle/PriceOracleV300Contract.js +1 -1
- package/dist/esm/sdk/market/pricefeeds/AbstractLPPriceFeed.js +1 -1
- package/dist/esm/sdk/market/pricefeeds/BalancerStablePriceFeed.js +1 -1
- package/dist/esm/sdk/market/pricefeeds/BalancerWeightedPriceFeed.js +1 -1
- package/dist/esm/sdk/market/pricefeeds/CurveCryptoPriceFeed.js +1 -1
- package/dist/esm/sdk/market/pricefeeds/CurveStablePriceFeed.js +1 -1
- package/dist/esm/sdk/market/pricefeeds/CurveUSDPriceFeed.js +1 -1
- package/dist/esm/sdk/market/pricefeeds/Erc4626PriceFeed.js +2 -2
- package/dist/esm/sdk/market/pricefeeds/MellowLRTPriceFeed.js +1 -1
- package/dist/esm/sdk/market/pricefeeds/PriceFeedsRegister.js +2 -2
- package/dist/esm/sdk/market/pricefeeds/WstETHPriceFeed.js +1 -1
- package/dist/esm/sdk/market/pricefeeds/YearnPriceFeed.js +1 -1
- package/dist/esm/sdk/plugins/BasePlugin.js +3 -6
- package/dist/esm/sdk/plugins/V300StalenessPeriodPlugin.js +1 -1
- package/dist/esm/sdk/router/RouterV300Contract.js +4 -4
- package/dist/types/dev/createAnvilClient.d.ts +1 -0
- package/dist/types/sdk/GearboxSDK.d.ts +51 -6
- package/dist/types/sdk/base/BaseContract.d.ts +0 -2
- package/dist/types/sdk/base/SDKConstruct.d.ts +2 -3
- package/dist/types/sdk/chain/index.d.ts +0 -1
- package/dist/types/sdk/plugins/BasePlugin.d.ts +1 -2
- package/package.json +1 -1
- package/dist/cjs/sdk/chain/Provider.js +0 -86
- package/dist/esm/sdk/chain/Provider.js +0 -61
- package/dist/types/sdk/chain/Provider.d.ts +0 -51
|
@@ -66,10 +66,7 @@ class AccountOpener extends import_sdk.SDKConstruct {
|
|
|
66
66
|
this.#service = service;
|
|
67
67
|
this.#allowMint = allowMint;
|
|
68
68
|
this.#logger = (0, import_sdk.childLogger)("AccountOpener", service.sdk.logger);
|
|
69
|
-
this.#anvil = (0, import_createAnvilClient.
|
|
70
|
-
chain: service.sdk.provider.chain,
|
|
71
|
-
transport: service.sdk.provider.transport
|
|
72
|
-
});
|
|
69
|
+
this.#anvil = (0, import_createAnvilClient.extendAnvilClient)(service.sdk.client);
|
|
73
70
|
try {
|
|
74
71
|
this.#faucet = faucet ?? service.sdk.addressProvider.getAddress("FAUCET");
|
|
75
72
|
} catch (_e) {
|
|
@@ -413,7 +410,7 @@ class AccountOpener extends import_sdk.SDKConstruct {
|
|
|
413
410
|
}
|
|
414
411
|
async #depositToPool(pool, depositor, amount) {
|
|
415
412
|
const { underlying, address } = pool;
|
|
416
|
-
const poolName = this.sdk.
|
|
413
|
+
const poolName = this.sdk.labelAddress(address);
|
|
417
414
|
const poolData = {
|
|
418
415
|
pool: address,
|
|
419
416
|
token: underlying,
|
|
@@ -21,29 +21,31 @@ __export(createAnvilClient_exports, {
|
|
|
21
21
|
anvilNodeInfo: () => anvilNodeInfo,
|
|
22
22
|
createAnvilClient: () => createAnvilClient,
|
|
23
23
|
evmMineDetailed: () => evmMineDetailed,
|
|
24
|
+
extendAnvilClient: () => extendAnvilClient,
|
|
24
25
|
isAnvil: () => isAnvil
|
|
25
26
|
});
|
|
26
27
|
module.exports = __toCommonJS(createAnvilClient_exports);
|
|
27
28
|
var import_viem = require("viem");
|
|
29
|
+
function extendAnvilClient(client) {
|
|
30
|
+
return client.extend((0, import_viem.testActions)({ mode: "anvil" })).extend(import_viem.walletActions).extend((c) => ({
|
|
31
|
+
anvilNodeInfo: () => anvilNodeInfo(c),
|
|
32
|
+
isAnvil: () => isAnvil(c),
|
|
33
|
+
evmMineDetailed: (timestamp) => evmMineDetailed(c, timestamp)
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
28
36
|
function createAnvilClient({
|
|
29
37
|
chain,
|
|
30
38
|
transport,
|
|
31
39
|
cacheTime = 0,
|
|
32
40
|
pollingInterval = 50
|
|
33
41
|
}) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
).extend(import_viem.publicActions).extend(import_viem.walletActions).extend((client) => ({
|
|
43
|
-
anvilNodeInfo: () => anvilNodeInfo(client),
|
|
44
|
-
isAnvil: () => isAnvil(client),
|
|
45
|
-
evmMineDetailed: (timestamp) => evmMineDetailed(client, timestamp)
|
|
46
|
-
}));
|
|
42
|
+
const client = (0, import_viem.createPublicClient)({
|
|
43
|
+
chain,
|
|
44
|
+
transport,
|
|
45
|
+
cacheTime,
|
|
46
|
+
pollingInterval
|
|
47
|
+
});
|
|
48
|
+
return extendAnvilClient(client);
|
|
47
49
|
}
|
|
48
50
|
async function isAnvil(client) {
|
|
49
51
|
try {
|
|
@@ -78,5 +80,6 @@ async function evmMineDetailed(client, timestamp) {
|
|
|
78
80
|
anvilNodeInfo,
|
|
79
81
|
createAnvilClient,
|
|
80
82
|
evmMineDetailed,
|
|
83
|
+
extendAnvilClient,
|
|
81
84
|
isAnvil
|
|
82
85
|
});
|
|
@@ -28,10 +28,7 @@ var import_v300 = require("../abi/v300.js");
|
|
|
28
28
|
var import_sdk = require("../sdk/index.js");
|
|
29
29
|
var import_createAnvilClient = require("./createAnvilClient.js");
|
|
30
30
|
async function unsafeMigrateFaucet(sdk, faucet) {
|
|
31
|
-
const anvil = (0, import_createAnvilClient.
|
|
32
|
-
chain: sdk.provider.chain,
|
|
33
|
-
transport: sdk.provider.transport
|
|
34
|
-
});
|
|
31
|
+
const anvil = (0, import_createAnvilClient.extendAnvilClient)(sdk.client);
|
|
35
32
|
let faucetAddr;
|
|
36
33
|
let owner;
|
|
37
34
|
if (faucet) {
|
|
@@ -47,7 +44,7 @@ async function unsafeMigrateFaucet(sdk, faucet) {
|
|
|
47
44
|
contracts: [
|
|
48
45
|
{
|
|
49
46
|
abi: import_v300.iAddressProviderV300Abi,
|
|
50
|
-
address: import_sdk.ADDRESS_PROVIDER[sdk.
|
|
47
|
+
address: import_sdk.ADDRESS_PROVIDER[sdk.networkType],
|
|
51
48
|
functionName: "getAddressOrRevert",
|
|
52
49
|
args: [(0, import_viem.stringToHex)("FAUCET", { size: 32 }), 0n]
|
|
53
50
|
},
|
|
@@ -100,7 +97,7 @@ async function migrateFaucet(sdk, faucet) {
|
|
|
100
97
|
} catch (e) {
|
|
101
98
|
sdk.logger?.error(`faucet migration failed: ${e}`);
|
|
102
99
|
}
|
|
103
|
-
return sdk.
|
|
100
|
+
return sdk.client.readContract({
|
|
104
101
|
abi: import_generated.iAddressProviderV310Abi,
|
|
105
102
|
address: sdk.addressProvider.address,
|
|
106
103
|
functionName: "getAddressOrRevert",
|
|
@@ -147,7 +147,7 @@ class InstanceManagerContract extends import_base_contract.BaseContract {
|
|
|
147
147
|
args: decoded ? {
|
|
148
148
|
target,
|
|
149
149
|
functionName: decoded.functionName,
|
|
150
|
-
|
|
150
|
+
data: (0, import_utils.json_stringify)(decoded.args)
|
|
151
151
|
} : {
|
|
152
152
|
target,
|
|
153
153
|
data
|
|
@@ -49,7 +49,7 @@ class AccountsCounterPlugin extends import_sdk.BasePlugin {
|
|
|
49
49
|
import_sdk.VERSION_RANGE_310
|
|
50
50
|
);
|
|
51
51
|
const cms = this.sdk.marketRegister.creditManagers;
|
|
52
|
-
const count = await this.sdk.
|
|
52
|
+
const count = await this.sdk.client.multicall({
|
|
53
53
|
contracts: cms.flatMap(
|
|
54
54
|
(cm) => [
|
|
55
55
|
{
|
|
@@ -37,7 +37,7 @@ class DegenDistributorsPlugin extends import_sdk.BasePlugin {
|
|
|
37
37
|
}, {})
|
|
38
38
|
);
|
|
39
39
|
this.sdk.logger?.debug(
|
|
40
|
-
`loading degen distributors for ${this.sdk.
|
|
40
|
+
`loading degen distributors for ${this.sdk.networkType}`
|
|
41
41
|
);
|
|
42
42
|
const distributors = await Promise.allSettled(
|
|
43
43
|
configurators.map((cfg) => cfg.getPeripheryContract("DEGEN_DISTRIBUTOR"))
|
|
@@ -30,7 +30,7 @@ class Pools7DAgoPlugin extends import_sdk.BasePlugin {
|
|
|
30
30
|
if (!force && this.loaded) {
|
|
31
31
|
return this.state;
|
|
32
32
|
}
|
|
33
|
-
const targetBlock = this.sdk.currentBlock - import_sdk.BLOCKS_PER_WEEK_BY_NETWORK[this.sdk.
|
|
33
|
+
const targetBlock = this.sdk.currentBlock - import_sdk.BLOCKS_PER_WEEK_BY_NETWORK[this.sdk.networkType];
|
|
34
34
|
const [marketCompressorAddress] = this.sdk.addressProvider.mustGetLatest(
|
|
35
35
|
import_sdk.AP_MARKET_COMPRESSOR,
|
|
36
36
|
import_sdk.VERSION_RANGE_310
|
|
@@ -39,7 +39,7 @@ class Pools7DAgoPlugin extends import_sdk.BasePlugin {
|
|
|
39
39
|
`loading pools 7d ago with market compressor ${marketCompressorAddress}`
|
|
40
40
|
);
|
|
41
41
|
const markets = this.sdk.marketRegister.markets;
|
|
42
|
-
const resp = await this.
|
|
42
|
+
const resp = await this.client.multicall({
|
|
43
43
|
allowFailure: true,
|
|
44
44
|
contracts: markets.map(
|
|
45
45
|
(m) => ({
|
|
@@ -42,7 +42,7 @@ class ZappersPlugin extends import_sdk.BasePlugin {
|
|
|
42
42
|
`loading zappers with periphery compressor ${pcAddr}`
|
|
43
43
|
);
|
|
44
44
|
const markets = this.sdk.marketRegister.markets;
|
|
45
|
-
const resp = await this.
|
|
45
|
+
const resp = await this.client.multicall({
|
|
46
46
|
contracts: markets.map(
|
|
47
47
|
(m) => ({
|
|
48
48
|
abi: import_peripheryCompressor.peripheryCompressorAbi,
|
|
@@ -132,7 +132,7 @@ class ZappersPlugin extends import_sdk.BasePlugin {
|
|
|
132
132
|
const extraZappersTokens = this.extraZappers.values().flatMap((l) => l.flatMap((z) => [z.tokenIn, z.tokenOut]));
|
|
133
133
|
for (const t of [...zappersTokens, ...extraZappersTokens]) {
|
|
134
134
|
this.sdk.tokensMeta.upsert(t.addr, t);
|
|
135
|
-
this.sdk.
|
|
135
|
+
this.sdk.addressLabels.set(t.addr, t.symbol);
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
}
|
|
@@ -36,11 +36,40 @@ var import_internal = require("./utils/internal/index.js");
|
|
|
36
36
|
var import_viem2 = require("./utils/viem/index.js");
|
|
37
37
|
const ERR_NOT_ATTACHED = new Error("Gearbox SDK not attached");
|
|
38
38
|
const STATE_VERSION = 1;
|
|
39
|
+
function createClient(opts, network) {
|
|
40
|
+
let transport;
|
|
41
|
+
if ("client" in opts) {
|
|
42
|
+
return opts.client;
|
|
43
|
+
}
|
|
44
|
+
if ("transport" in opts) {
|
|
45
|
+
transport = opts.transport;
|
|
46
|
+
} else {
|
|
47
|
+
const rpcs = opts.rpcURLs.map(
|
|
48
|
+
(url) => (0, import_viem.http)(url, { timeout: opts.timeout, retryCount: opts.retryCount })
|
|
49
|
+
);
|
|
50
|
+
transport = rpcs.length > 1 ? (0, import_viem.fallback)(rpcs) : rpcs[0];
|
|
51
|
+
}
|
|
52
|
+
const chain = network ? (0, import_viem.defineChain)({
|
|
53
|
+
...(0, import_chain.getChain)(network.networkType),
|
|
54
|
+
id: network.chainId
|
|
55
|
+
}) : void 0;
|
|
56
|
+
return (0, import_viem.createPublicClient)({ transport, chain });
|
|
57
|
+
}
|
|
58
|
+
async function attachClient(options, network) {
|
|
59
|
+
let { chainId, networkType } = network;
|
|
60
|
+
const attachClient2 = createClient(options);
|
|
61
|
+
if (!networkType) {
|
|
62
|
+
networkType = await (0, import_chain.detectNetwork)(attachClient2);
|
|
63
|
+
}
|
|
64
|
+
if (!chainId) {
|
|
65
|
+
chainId = await attachClient2.getChainId();
|
|
66
|
+
}
|
|
67
|
+
return createClient(options, { networkType, chainId });
|
|
68
|
+
}
|
|
39
69
|
class GearboxSDK {
|
|
40
70
|
#hooks = new import_internal.Hooks();
|
|
41
|
-
// Represents chain object
|
|
42
|
-
#provider;
|
|
43
71
|
plugins;
|
|
72
|
+
#client;
|
|
44
73
|
// Block which was use for data query
|
|
45
74
|
#currentBlock;
|
|
46
75
|
#timestamp;
|
|
@@ -53,6 +82,7 @@ class GearboxSDK {
|
|
|
53
82
|
#priceFeeds;
|
|
54
83
|
logger;
|
|
55
84
|
gasLimit;
|
|
85
|
+
addressLabels = new import_base.AddressLabeller();
|
|
56
86
|
/**
|
|
57
87
|
* Interest rate models can be reused across chain (and SDK operates on chain level)
|
|
58
88
|
* TODO: use whatever interface is necessary for InterestRateModels
|
|
@@ -88,27 +118,14 @@ class GearboxSDK {
|
|
|
88
118
|
strictContractTypes,
|
|
89
119
|
gasLimit
|
|
90
120
|
} = options;
|
|
91
|
-
let {
|
|
92
|
-
const
|
|
93
|
-
if (!networkType) {
|
|
94
|
-
networkType = await (0, import_chain.detectNetwork)(attachClient);
|
|
95
|
-
}
|
|
96
|
-
if (!chainId) {
|
|
97
|
-
chainId = await attachClient.getChainId();
|
|
98
|
-
}
|
|
121
|
+
let { addressProvider } = options;
|
|
122
|
+
const client = await attachClient(options, options);
|
|
99
123
|
if (!addressProvider) {
|
|
100
124
|
addressProvider = import_constants.ADDRESS_PROVIDER_V310;
|
|
101
125
|
}
|
|
102
|
-
const marketConfigurators = mcs ?? import_utils.TypedObjectUtils.keys(
|
|
103
|
-
const provider = new import_chain.Provider({
|
|
104
|
-
...options,
|
|
105
|
-
transport,
|
|
106
|
-
// pass transport to avoid creating a new transport in provider
|
|
107
|
-
chainId,
|
|
108
|
-
networkType
|
|
109
|
-
});
|
|
126
|
+
const marketConfigurators = mcs ?? import_utils.TypedObjectUtils.keys(client.chain.defaultMarketConfigurators);
|
|
110
127
|
return new GearboxSDK({
|
|
111
|
-
|
|
128
|
+
client,
|
|
112
129
|
logger,
|
|
113
130
|
plugins,
|
|
114
131
|
strictContractTypes,
|
|
@@ -125,13 +142,12 @@ class GearboxSDK {
|
|
|
125
142
|
}
|
|
126
143
|
static hydrate(options, state) {
|
|
127
144
|
const { logger, plugins, strictContractTypes, gasLimit, ...rest } = options;
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
chainId: state.chainId
|
|
131
|
-
networkType: state.network
|
|
145
|
+
const client = createClient(options, {
|
|
146
|
+
networkType: state.network,
|
|
147
|
+
chainId: state.chainId
|
|
132
148
|
});
|
|
133
149
|
return new GearboxSDK({
|
|
134
|
-
|
|
150
|
+
client,
|
|
135
151
|
plugins,
|
|
136
152
|
logger,
|
|
137
153
|
strictContractTypes,
|
|
@@ -139,10 +155,10 @@ class GearboxSDK {
|
|
|
139
155
|
}).#hydrate(rest, state);
|
|
140
156
|
}
|
|
141
157
|
constructor(options) {
|
|
142
|
-
this.#provider = options.provider;
|
|
143
158
|
this.logger = options.logger;
|
|
144
159
|
this.strictContractTypes = options.strictContractTypes ?? false;
|
|
145
160
|
this.plugins = options.plugins ?? {};
|
|
161
|
+
this.#client = options.client;
|
|
146
162
|
for (const plugin of Object.values(this.plugins)) {
|
|
147
163
|
plugin.sdk = this;
|
|
148
164
|
}
|
|
@@ -163,8 +179,8 @@ class GearboxSDK {
|
|
|
163
179
|
const re = this.#attachConfig ? "re" : "";
|
|
164
180
|
this.logger?.info(
|
|
165
181
|
{
|
|
166
|
-
networkType: this.
|
|
167
|
-
chainId: this.
|
|
182
|
+
networkType: this.networkType,
|
|
183
|
+
chainId: this.chainId,
|
|
168
184
|
addressProvider,
|
|
169
185
|
marketConfigurators,
|
|
170
186
|
blockNumber,
|
|
@@ -184,7 +200,7 @@ class GearboxSDK {
|
|
|
184
200
|
}
|
|
185
201
|
this.#attachConfig = opts;
|
|
186
202
|
const time = Date.now();
|
|
187
|
-
const block = await this.
|
|
203
|
+
const block = await this.client.getBlock(
|
|
188
204
|
blockNumber ? { blockNumber: BigInt(blockNumber) } : {
|
|
189
205
|
blockTag: "latest"
|
|
190
206
|
}
|
|
@@ -235,9 +251,7 @@ class GearboxSDK {
|
|
|
235
251
|
}
|
|
236
252
|
const re = this.#attachConfig ? "re" : "";
|
|
237
253
|
this.logger?.info(
|
|
238
|
-
{
|
|
239
|
-
networkType: this.provider.networkType
|
|
240
|
-
},
|
|
254
|
+
{ networkType: this.networkType },
|
|
241
255
|
`${re}hydrating sdk state`
|
|
242
256
|
);
|
|
243
257
|
this.#currentBlock = state.currentBlock;
|
|
@@ -306,6 +320,26 @@ class GearboxSDK {
|
|
|
306
320
|
timestamp: state.timestamp
|
|
307
321
|
});
|
|
308
322
|
}
|
|
323
|
+
get client() {
|
|
324
|
+
return this.#client;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Replaces client inflight
|
|
328
|
+
* You're responsible for all inconsistencies between new and old client
|
|
329
|
+
* @param options
|
|
330
|
+
*/
|
|
331
|
+
replaceClient(options, network) {
|
|
332
|
+
this.#client = createClient(options, network);
|
|
333
|
+
}
|
|
334
|
+
get networkType() {
|
|
335
|
+
return this.client.chain.network;
|
|
336
|
+
}
|
|
337
|
+
get chain() {
|
|
338
|
+
return this.client.chain;
|
|
339
|
+
}
|
|
340
|
+
get chainId() {
|
|
341
|
+
return this.client.chain.id;
|
|
342
|
+
}
|
|
309
343
|
/**
|
|
310
344
|
* Converts contract call into some human-friendly string
|
|
311
345
|
* This method is safe and should not throw
|
|
@@ -376,8 +410,8 @@ class GearboxSDK {
|
|
|
376
410
|
get state() {
|
|
377
411
|
return {
|
|
378
412
|
version: STATE_VERSION,
|
|
379
|
-
network: this.
|
|
380
|
-
chainId: this.
|
|
413
|
+
network: this.networkType,
|
|
414
|
+
chainId: this.chainId,
|
|
381
415
|
currentBlock: this.currentBlock,
|
|
382
416
|
timestamp: this.timestamp,
|
|
383
417
|
addressProvider: this.addressProvider.state,
|
|
@@ -407,7 +441,7 @@ class GearboxSDK {
|
|
|
407
441
|
);
|
|
408
442
|
}
|
|
409
443
|
if (!blockNumber || !timestamp) {
|
|
410
|
-
const block = await this.
|
|
444
|
+
const block = await this.client.getBlock({
|
|
411
445
|
blockTag: "latest"
|
|
412
446
|
});
|
|
413
447
|
blockNumber = block.number;
|
|
@@ -439,7 +473,7 @@ class GearboxSDK {
|
|
|
439
473
|
this.logger?.debug(
|
|
440
474
|
`getting logs from ${watchAddresses.length} addresses in [${fromBlock}:${blockNumber}]`
|
|
441
475
|
);
|
|
442
|
-
const logs = await (0, import_viem2.getLogsSafe)(this.
|
|
476
|
+
const logs = await (0, import_viem2.getLogsSafe)(this.client, {
|
|
443
477
|
fromBlock,
|
|
444
478
|
toBlock: blockNumber,
|
|
445
479
|
address: watchAddresses
|
|
@@ -496,9 +530,6 @@ class GearboxSDK {
|
|
|
496
530
|
}
|
|
497
531
|
return success;
|
|
498
532
|
}
|
|
499
|
-
get provider() {
|
|
500
|
-
return this.#provider;
|
|
501
|
-
}
|
|
502
533
|
get currentBlock() {
|
|
503
534
|
if (this.#currentBlock === void 0) {
|
|
504
535
|
throw ERR_NOT_ATTACHED;
|
|
@@ -593,7 +624,7 @@ class GearboxSDK {
|
|
|
593
624
|
* @returns
|
|
594
625
|
*/
|
|
595
626
|
labelAddress(address) {
|
|
596
|
-
return this.
|
|
627
|
+
return this.addressLabels.get(address);
|
|
597
628
|
}
|
|
598
629
|
}
|
|
599
630
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -77,7 +77,7 @@ class AbstractMigrateCreditAccountsService extends import_base.SDKConstruct {
|
|
|
77
77
|
address: previewerAddress,
|
|
78
78
|
abi: import_migration.accountMigratorPreviewerV310Abi,
|
|
79
79
|
client: {
|
|
80
|
-
public: this.sdk.
|
|
80
|
+
public: this.sdk.client
|
|
81
81
|
}
|
|
82
82
|
});
|
|
83
83
|
const { result } = await contract.simulate.previewMigration([
|
|
@@ -225,7 +225,7 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
225
225
|
}
|
|
226
226
|
async getActiveMigrationBots(accountsToCheck) {
|
|
227
227
|
const migrationBot = import_AbstractMigrateCreditAccountsService.AbstractMigrateCreditAccountsService.getMigrationBotAddress(
|
|
228
|
-
this.sdk.
|
|
228
|
+
this.sdk.chainId
|
|
229
229
|
);
|
|
230
230
|
if (migrationBot) {
|
|
231
231
|
const result = await this.client.multicall({
|
|
@@ -185,7 +185,7 @@ class CreditAccountServiceV300 extends import_AbstractCreditAccountsService.Abst
|
|
|
185
185
|
* @returns
|
|
186
186
|
*/
|
|
187
187
|
#prepareUnwrapAndWithdrawCallsV3(assets, claim, withdrawAll, creditManager) {
|
|
188
|
-
const network = this.sdk.
|
|
188
|
+
const network = this.sdk.networkType;
|
|
189
189
|
const suite = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
190
190
|
const cmAdapters = suite.creditManager.adapters.values().reduce((acc, a) => {
|
|
191
191
|
const contractLc = a.targetContract.toLowerCase();
|
|
@@ -44,7 +44,7 @@ class BaseContract extends import_SDKConstruct.SDKConstruct {
|
|
|
44
44
|
// add exceptions for better error decoding
|
|
45
45
|
abi: [...this.abi, ...import_errors.errorAbis],
|
|
46
46
|
client: {
|
|
47
|
-
public: sdk.
|
|
47
|
+
public: sdk.client
|
|
48
48
|
}
|
|
49
49
|
});
|
|
50
50
|
this.version = Number(args.version || 0);
|
|
@@ -64,7 +64,7 @@ class BaseContract extends import_SDKConstruct.SDKConstruct {
|
|
|
64
64
|
throw new Error(`Address can't be changed, currently: ${this.#address}`);
|
|
65
65
|
}
|
|
66
66
|
this.#address = (0, import_viem.getAddress)(address);
|
|
67
|
-
this.addressLabels.set(address, this.#name);
|
|
67
|
+
this.sdk.addressLabels.set(address, this.#name);
|
|
68
68
|
}
|
|
69
69
|
get name() {
|
|
70
70
|
return this.#name;
|
|
@@ -72,12 +72,12 @@ class BaseContract extends import_SDKConstruct.SDKConstruct {
|
|
|
72
72
|
set name(name) {
|
|
73
73
|
this.#name = name;
|
|
74
74
|
if (this.#address !== import_constants.ADDRESS_0X0) {
|
|
75
|
-
this.addressLabels.set(this.#address, name);
|
|
75
|
+
this.sdk.addressLabels.set(this.#address, name);
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
stateHuman(_ = true) {
|
|
79
79
|
return {
|
|
80
|
-
address: this.sdk.
|
|
80
|
+
address: this.sdk.labelAddress(this.address),
|
|
81
81
|
version: this.version,
|
|
82
82
|
contractType: this.contractType
|
|
83
83
|
};
|
|
@@ -124,7 +124,7 @@ class BaseContract extends import_SDKConstruct.SDKConstruct {
|
|
|
124
124
|
});
|
|
125
125
|
} else if (Array.isArray(decoded.args)) {
|
|
126
126
|
paramsHuman = decoded.args.map((value, i) => {
|
|
127
|
-
return `${abiItem.inputs[i].name}: ${abiItem.inputs[i].type === "address" ? this.
|
|
127
|
+
return `${abiItem.inputs[i].name}: ${abiItem.inputs[i].type === "address" ? this.labelAddress(value) : abiItem.inputs[i].type.startsWith("tuple") ? (0, import_utils.json_stringify)(value) : value}`;
|
|
128
128
|
});
|
|
129
129
|
} else {
|
|
130
130
|
paramsHuman = Object.entries(decoded.args || {}).map(
|
|
@@ -150,7 +150,7 @@ class BaseContract extends import_SDKConstruct.SDKConstruct {
|
|
|
150
150
|
}
|
|
151
151
|
async getVersion() {
|
|
152
152
|
this.version = Number(
|
|
153
|
-
await this.sdk.
|
|
153
|
+
await this.sdk.client.readContract({
|
|
154
154
|
abi: import_iVersion.iVersionAbi,
|
|
155
155
|
functionName: "version",
|
|
156
156
|
address: this.address
|
|
@@ -171,9 +171,6 @@ class BaseContract extends import_SDKConstruct.SDKConstruct {
|
|
|
171
171
|
tx.description = argsDescription || this.parseFunctionData(tx.callData);
|
|
172
172
|
return tx;
|
|
173
173
|
}
|
|
174
|
-
get addressLabels() {
|
|
175
|
-
return this.sdk.provider.addressLabels;
|
|
176
|
-
}
|
|
177
174
|
}
|
|
178
175
|
// Annotate the CommonJS export names for ESM import in node:
|
|
179
176
|
0 && (module.exports = {
|
|
@@ -30,14 +30,11 @@ class SDKConstruct {
|
|
|
30
30
|
constructor(sdk) {
|
|
31
31
|
this.sdk = sdk;
|
|
32
32
|
}
|
|
33
|
-
get
|
|
34
|
-
return this.sdk.
|
|
35
|
-
}
|
|
36
|
-
get network() {
|
|
37
|
-
return this.provider.networkType;
|
|
33
|
+
get networkType() {
|
|
34
|
+
return this.sdk.networkType;
|
|
38
35
|
}
|
|
39
36
|
get client() {
|
|
40
|
-
return this.
|
|
37
|
+
return this.sdk.client;
|
|
41
38
|
}
|
|
42
39
|
/**
|
|
43
40
|
* Indicates that contract state needs to be updated
|
|
@@ -49,7 +46,7 @@ class SDKConstruct {
|
|
|
49
46
|
this.#dirty = value;
|
|
50
47
|
}
|
|
51
48
|
labelAddress(address) {
|
|
52
|
-
return this.
|
|
49
|
+
return this.sdk.labelAddress(address);
|
|
53
50
|
}
|
|
54
51
|
/**
|
|
55
52
|
* Returns list of addresses that should be watched for events to sync state
|
|
@@ -314,7 +314,7 @@ function getChain(chainIdOrNetworkType) {
|
|
|
314
314
|
const network = typeof chainIdOrNetworkType === "string" ? chainIdOrNetworkType : getNetworkType(Number(chainIdOrNetworkType));
|
|
315
315
|
const chain = chains[network];
|
|
316
316
|
if (!chain) {
|
|
317
|
-
throw new Error(
|
|
317
|
+
throw new Error(`Unsupported network: ${network}`);
|
|
318
318
|
}
|
|
319
319
|
return chain;
|
|
320
320
|
}
|
|
@@ -17,10 +17,8 @@ var chain_exports = {};
|
|
|
17
17
|
module.exports = __toCommonJS(chain_exports);
|
|
18
18
|
__reExport(chain_exports, require("./chains.js"), module.exports);
|
|
19
19
|
__reExport(chain_exports, require("./detectNetwork.js"), module.exports);
|
|
20
|
-
__reExport(chain_exports, require("./Provider.js"), module.exports);
|
|
21
20
|
// Annotate the CommonJS export names for ESM import in node:
|
|
22
21
|
0 && (module.exports = {
|
|
23
22
|
...require("./chains.js"),
|
|
24
|
-
...require("./detectNetwork.js")
|
|
25
|
-
...require("./Provider.js")
|
|
23
|
+
...require("./detectNetwork.js")
|
|
26
24
|
});
|
|
@@ -30,19 +30,19 @@ class BotListContract extends import_base.BaseContract {
|
|
|
30
30
|
#currentBlock;
|
|
31
31
|
constructor(sdk, address) {
|
|
32
32
|
super(sdk, { addr: address, name: "BotListV3", abi });
|
|
33
|
-
this.#currentBlock = sdk.
|
|
33
|
+
this.#currentBlock = sdk.chain.firstBlock ?? 0n;
|
|
34
34
|
}
|
|
35
35
|
parseFunctionParams(params) {
|
|
36
36
|
switch (params.functionName) {
|
|
37
37
|
case "setCreditManagerApprovedStatus": {
|
|
38
38
|
const [creditManager, status] = params.args;
|
|
39
|
-
return [this.
|
|
39
|
+
return [this.labelAddress(creditManager), `${status}`];
|
|
40
40
|
}
|
|
41
41
|
case "setBotSpecialPermissions": {
|
|
42
42
|
const [bot, creditManager, permissions] = params.args;
|
|
43
43
|
return [
|
|
44
|
-
this.
|
|
45
|
-
this.
|
|
44
|
+
this.labelAddress(bot),
|
|
45
|
+
this.labelAddress(creditManager),
|
|
46
46
|
(0, import_constants.botPermissionsToString)(permissions)
|
|
47
47
|
];
|
|
48
48
|
}
|
|
@@ -51,7 +51,7 @@ class BotListContract extends import_base.BaseContract {
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
async syncState(toBlock) {
|
|
54
|
-
const logs = await this.
|
|
54
|
+
const logs = await this.client.getContractEvents({
|
|
55
55
|
address: this.address,
|
|
56
56
|
abi: this.abi,
|
|
57
57
|
fromBlock: this.#currentBlock,
|
|
@@ -33,7 +33,7 @@ class GearStakingContract extends import_base.BaseContract {
|
|
|
33
33
|
switch (params.functionName) {
|
|
34
34
|
case "setVotingContractStatus": {
|
|
35
35
|
const [address, status] = params.args;
|
|
36
|
-
return [this.
|
|
36
|
+
return [this.labelAddress(address), import_base.VotingContractStatus[status]];
|
|
37
37
|
}
|
|
38
38
|
default:
|
|
39
39
|
return void 0;
|
|
@@ -85,11 +85,11 @@ class AddressProviderV300Contract extends import_AbstractAddressProviderContract
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
async syncState(blockNumber) {
|
|
88
|
-
const fromBlock = this.sdk.
|
|
88
|
+
const fromBlock = this.sdk.chain.firstBlock;
|
|
89
89
|
this.logger?.debug(
|
|
90
90
|
`loading events from block ${fromBlock} to ${blockNumber}`
|
|
91
91
|
);
|
|
92
|
-
const events = await (0, import_viem2.getLogsSafe)(this.sdk.
|
|
92
|
+
const events = await (0, import_viem2.getLogsSafe)(this.sdk.client, {
|
|
93
93
|
address: this.address,
|
|
94
94
|
event: (0, import_viem.getAbiItem)({ abi: this.abi, name: "SetAddress" }),
|
|
95
95
|
fromBlock,
|
|
@@ -27,7 +27,7 @@ var import_constants = require("../../constants/index.js");
|
|
|
27
27
|
var import_AddressProviderV300Contract = require("./AddressProviderV300Contract.js");
|
|
28
28
|
var import_AddressProviderV310Contract = require("./AddressProviderV310Contract.js");
|
|
29
29
|
async function createAddressProvider(sdk, address) {
|
|
30
|
-
const v = await sdk.
|
|
30
|
+
const v = await sdk.client.readContract({
|
|
31
31
|
address,
|
|
32
32
|
abi: import_iVersion.iVersionAbi,
|
|
33
33
|
functionName: "version"
|
|
@@ -47,7 +47,7 @@ class GaugeStakingService extends import_base.SDKConstruct {
|
|
|
47
47
|
if (!gearStaking) {
|
|
48
48
|
throw new Error("gear staking contract is not set");
|
|
49
49
|
}
|
|
50
|
-
const [gauges, availableBalance, totalBalance, withdrawableAmounts, epoch] = await this.
|
|
50
|
+
const [gauges, availableBalance, totalBalance, withdrawableAmounts, epoch] = await this.client.multicall({
|
|
51
51
|
allowFailure: false,
|
|
52
52
|
contracts: [
|
|
53
53
|
{
|
|
@@ -37,18 +37,18 @@ class MarketConfiguratorContract extends import_base.BaseContract {
|
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
async loadCuratorName() {
|
|
40
|
-
this.#curatorName = await this.sdk.
|
|
40
|
+
this.#curatorName = await this.sdk.client.readContract({
|
|
41
41
|
address: this.address,
|
|
42
42
|
abi: this.abi,
|
|
43
43
|
functionName: "curatorName"
|
|
44
44
|
});
|
|
45
|
-
this.sdk.
|
|
45
|
+
this.sdk.addressLabels.set(
|
|
46
46
|
this.address,
|
|
47
47
|
`Market configurator ${this.#curatorName}`
|
|
48
48
|
);
|
|
49
49
|
}
|
|
50
50
|
async getPeripheryContract(contract) {
|
|
51
|
-
const resp = await this.sdk.
|
|
51
|
+
const resp = await this.sdk.client.readContract({
|
|
52
52
|
address: this.address,
|
|
53
53
|
abi: this.abi,
|
|
54
54
|
functionName: "getPeripheryContracts",
|