@gearbox-protocol/sdk 13.3.3 → 13.4.0-beta.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.
- package/dist/cjs/permissionless/utils/price-update/get-price-update-tx.js +3 -15
- package/dist/cjs/sdk/GearboxSDK.js +135 -20
- package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +196 -340
- package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +30 -35
- package/dist/cjs/sdk/accounts/multicall-utils.js +91 -0
- package/dist/cjs/sdk/base/BaseContract.js +26 -6
- package/dist/cjs/sdk/base/ChainContractsRegister.js +39 -2
- package/dist/cjs/sdk/base/Construct.js +15 -3
- package/dist/cjs/sdk/base/TokensMeta.js +23 -0
- package/dist/cjs/sdk/constants/address-provider.js +0 -22
- package/dist/cjs/sdk/core/AbstractAddressProviderContract.js +15 -0
- package/dist/cjs/sdk/market/MarketRegister.js +74 -3
- package/dist/cjs/sdk/market/credit/CreditFacadeV310Contract.js +6 -0
- package/dist/cjs/sdk/market/oracle/PriceOracleBaseContract.js +31 -50
- package/dist/cjs/sdk/market/pricefeeds/PriceFeedRef.js +16 -0
- package/dist/cjs/sdk/market/pricefeeds/PriceFeedsRegister.js +55 -12
- package/dist/cjs/sdk/options.js +30 -24
- package/dist/cjs/sdk/plugins/BasePlugin.js +24 -0
- package/dist/cjs/sdk/pools/AbstractPoolService.js +6 -0
- package/dist/cjs/sdk/router/AbstractRouterContract.js +4 -1
- package/dist/cjs/sdk/router/RouterV310Contract.js +20 -15
- package/dist/cjs/sdk/utils/AddressMap.js +53 -17
- package/dist/cjs/sdk/utils/AddressSet.js +9 -0
- package/dist/esm/permissionless/utils/price-update/get-price-update-tx.js +6 -20
- package/dist/esm/sdk/GearboxSDK.js +135 -20
- package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +204 -342
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +30 -35
- package/dist/esm/sdk/accounts/multicall-utils.js +69 -0
- package/dist/esm/sdk/base/BaseContract.js +26 -6
- package/dist/esm/sdk/base/ChainContractsRegister.js +39 -2
- package/dist/esm/sdk/base/Construct.js +15 -3
- package/dist/esm/sdk/base/TokensMeta.js +23 -0
- package/dist/esm/sdk/constants/address-provider.js +0 -21
- package/dist/esm/sdk/core/AbstractAddressProviderContract.js +15 -0
- package/dist/esm/sdk/market/MarketRegister.js +74 -3
- package/dist/esm/sdk/market/credit/CreditFacadeV310Contract.js +6 -0
- package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +31 -50
- package/dist/esm/sdk/market/pricefeeds/PriceFeedRef.js +16 -0
- package/dist/esm/sdk/market/pricefeeds/PriceFeedsRegister.js +55 -12
- package/dist/esm/sdk/options.js +30 -24
- package/dist/esm/sdk/plugins/BasePlugin.js +24 -0
- package/dist/esm/sdk/pools/AbstractPoolService.js +6 -0
- package/dist/esm/sdk/router/AbstractRouterContract.js +4 -1
- package/dist/esm/sdk/router/RouterV310Contract.js +20 -15
- package/dist/esm/sdk/utils/AddressMap.js +53 -17
- package/dist/esm/sdk/utils/AddressSet.js +9 -0
- package/dist/types/permissionless/bindings/price-feed-store.d.ts +1 -2
- package/dist/types/permissionless/bindings/types.d.ts +0 -4
- package/dist/types/permissionless/utils/price-update/get-price-update-tx.d.ts +1 -3
- package/dist/types/sdk/GearboxSDK.d.ts +236 -34
- package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +92 -147
- package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +14 -5
- package/dist/types/sdk/accounts/multicall-utils.d.ts +39 -0
- package/dist/types/sdk/accounts/types.d.ts +237 -40
- package/dist/types/sdk/base/BaseContract.d.ts +67 -6
- package/dist/types/sdk/base/ChainContractsRegister.d.ts +51 -2
- package/dist/types/sdk/base/Construct.d.ts +31 -0
- package/dist/types/sdk/base/PlaceholderContract.d.ts +3 -0
- package/dist/types/sdk/base/SDKConstruct.d.ts +10 -0
- package/dist/types/sdk/base/TokensMeta.d.ts +59 -2
- package/dist/types/sdk/base/types.d.ts +185 -25
- package/dist/types/sdk/chain/chains.d.ts +78 -18
- package/dist/types/sdk/chain/detectNetwork.d.ts +7 -0
- package/dist/types/sdk/constants/address-provider.d.ts +4 -3
- package/dist/types/sdk/core/AbstractAddressProviderContract.d.ts +23 -0
- package/dist/types/sdk/core/types.d.ts +46 -0
- package/dist/types/sdk/market/MarketRegister.d.ts +81 -0
- package/dist/types/sdk/market/adapters/PlaceholderAdapterContracts.d.ts +3 -0
- package/dist/types/sdk/market/credit/CreditFacadeV310Contract.d.ts +1 -0
- package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +40 -50
- package/dist/types/sdk/market/oracle/types.d.ts +78 -59
- package/dist/types/sdk/market/pricefeeds/AbstractLPPriceFeed.d.ts +3 -0
- package/dist/types/sdk/market/pricefeeds/AbstractPriceFeed.d.ts +3 -0
- package/dist/types/sdk/market/pricefeeds/PriceFeedRef.d.ts +22 -2
- package/dist/types/sdk/market/pricefeeds/PriceFeedsRegister.d.ts +80 -16
- package/dist/types/sdk/market/pricefeeds/getRawPriceUpdates.d.ts +2 -2
- package/dist/types/sdk/market/pricefeeds/types.d.ts +75 -11
- package/dist/types/sdk/options.d.ts +13 -4
- package/dist/types/sdk/plugins/BasePlugin.d.ts +39 -0
- package/dist/types/sdk/plugins/types.d.ts +73 -43
- package/dist/types/sdk/pools/AbstractPoolService.d.ts +12 -0
- package/dist/types/sdk/pools/types.d.ts +75 -6
- package/dist/types/sdk/router/AbstractRouterContract.d.ts +21 -2
- package/dist/types/sdk/router/RouterV310Contract.d.ts +27 -15
- package/dist/types/sdk/router/types.d.ts +47 -70
- package/dist/types/sdk/types/state.d.ts +32 -3
- package/dist/types/sdk/utils/AddressMap.d.ts +61 -17
- package/dist/types/sdk/utils/AddressSet.d.ts +15 -0
- package/package.json +4 -2
|
@@ -27,7 +27,7 @@ var import_math = require("../constants/math.js");
|
|
|
27
27
|
var import_AbstractCreditAccountsService = require("./AbstractCreditAccountsService.js");
|
|
28
28
|
class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.AbstractCreditAccountService {
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
30
|
+
* {@inheritDoc ICreditAccountsService.setBot}
|
|
31
31
|
*/
|
|
32
32
|
async setBot({
|
|
33
33
|
botAddress,
|
|
@@ -37,10 +37,6 @@ class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.Abst
|
|
|
37
37
|
const cm = this.sdk.marketRegister.findCreditManager(
|
|
38
38
|
targetContract.creditManager
|
|
39
39
|
);
|
|
40
|
-
const priceUpdatesCalls = targetContract.type === "creditAccount" ? await this.getPriceUpdatesForFacade({
|
|
41
|
-
creditManager: targetContract.creditManager,
|
|
42
|
-
creditAccount: targetContract
|
|
43
|
-
}) : [];
|
|
44
40
|
const permissions = defaultPermissions !== null ? defaultPermissions : await (0, import_viem.getContract)({
|
|
45
41
|
address: botAddress,
|
|
46
42
|
client: this.sdk.client,
|
|
@@ -64,12 +60,16 @@ class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.Abst
|
|
|
64
60
|
args: [botAddress, permissions]
|
|
65
61
|
})
|
|
66
62
|
};
|
|
67
|
-
const calls =
|
|
63
|
+
const calls = targetContract.type === "creditAccount" ? await this.prependPriceUpdates(
|
|
64
|
+
targetContract.creditManager,
|
|
65
|
+
[addBotCall],
|
|
66
|
+
targetContract
|
|
67
|
+
) : [addBotCall];
|
|
68
68
|
const tx = targetContract.type === "creditAccount" ? cm.creditFacade.multicall(targetContract.creditAccount, calls) : void 0;
|
|
69
69
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
72
|
-
*
|
|
72
|
+
* {@inheritDoc ICreditAccountsService.withdrawCollateral}
|
|
73
73
|
*/
|
|
74
74
|
async withdrawCollateral({
|
|
75
75
|
creditAccount,
|
|
@@ -81,12 +81,7 @@ class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.Abst
|
|
|
81
81
|
const cm = this.sdk.marketRegister.findCreditManager(
|
|
82
82
|
creditAccount.creditManager
|
|
83
83
|
);
|
|
84
|
-
const
|
|
85
|
-
creditManager: creditAccount.creditManager,
|
|
86
|
-
creditAccount
|
|
87
|
-
});
|
|
88
|
-
const calls = [
|
|
89
|
-
...priceUpdatesCalls,
|
|
84
|
+
const operationCalls = [
|
|
90
85
|
...assetsToWithdraw.map(
|
|
91
86
|
(a) => this.prepareWithdrawToken(
|
|
92
87
|
creditAccount.creditFacade,
|
|
@@ -100,11 +95,16 @@ class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.Abst
|
|
|
100
95
|
averageQuota
|
|
101
96
|
})
|
|
102
97
|
];
|
|
98
|
+
const calls = await this.prependPriceUpdates(
|
|
99
|
+
creditAccount.creditManager,
|
|
100
|
+
operationCalls,
|
|
101
|
+
creditAccount
|
|
102
|
+
);
|
|
103
103
|
const tx = cm.creditFacade.multicall(creditAccount.creditAccount, calls);
|
|
104
104
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
105
105
|
}
|
|
106
106
|
/**
|
|
107
|
-
*
|
|
107
|
+
* {@inheritDoc ICreditAccountsService.repayCreditAccount}
|
|
108
108
|
*/
|
|
109
109
|
async repayCreditAccount({
|
|
110
110
|
operation,
|
|
@@ -122,12 +122,7 @@ class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.Abst
|
|
|
122
122
|
tokensToClaim,
|
|
123
123
|
creditAccount: ca
|
|
124
124
|
});
|
|
125
|
-
const
|
|
126
|
-
creditManager: ca.creditManager,
|
|
127
|
-
creditAccount: ca
|
|
128
|
-
});
|
|
129
|
-
const calls = [
|
|
130
|
-
...operation === "close" ? [] : priceUpdates,
|
|
125
|
+
const operationCalls = [
|
|
131
126
|
...this.prepareAddCollateral(ca.creditFacade, addCollateral, permits),
|
|
132
127
|
...this.prepareDisableQuotas(ca),
|
|
133
128
|
...this.prepareDecreaseDebt(ca),
|
|
@@ -136,11 +131,12 @@ class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.Abst
|
|
|
136
131
|
(t) => this.prepareWithdrawToken(ca.creditFacade, t.token, import_math.MAX_UINT256, to)
|
|
137
132
|
)
|
|
138
133
|
];
|
|
134
|
+
const calls = operation === "close" ? operationCalls : await this.prependPriceUpdates(ca.creditManager, operationCalls, ca);
|
|
139
135
|
const tx = operation === "close" ? cm.creditFacade.closeCreditAccount(ca.creditAccount, calls) : cm.creditFacade.multicall(ca.creditAccount, calls);
|
|
140
136
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
141
137
|
}
|
|
142
138
|
/**
|
|
143
|
-
*
|
|
139
|
+
* {@inheritDoc ICreditAccountsService.repayAndLiquidateCreditAccount}
|
|
144
140
|
*/
|
|
145
141
|
async repayAndLiquidateCreditAccount({
|
|
146
142
|
collateralAssets,
|
|
@@ -156,19 +152,19 @@ class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.Abst
|
|
|
156
152
|
tokensToClaim,
|
|
157
153
|
creditAccount: ca
|
|
158
154
|
});
|
|
159
|
-
const priceUpdates = await this.getPriceUpdatesForFacade({
|
|
160
|
-
creditManager: ca.creditManager,
|
|
161
|
-
creditAccount: ca
|
|
162
|
-
});
|
|
163
155
|
const addCollateral = collateralAssets.filter((a) => a.balance > 0);
|
|
164
|
-
const
|
|
165
|
-
...priceUpdates,
|
|
156
|
+
const operationCalls = [
|
|
166
157
|
...this.prepareAddCollateral(ca.creditFacade, addCollateral, permits),
|
|
167
158
|
...claimPath.calls,
|
|
168
159
|
...assetsToWithdraw.map(
|
|
169
160
|
(t) => this.prepareWithdrawToken(ca.creditFacade, t.token, import_math.MAX_UINT256, to)
|
|
170
161
|
)
|
|
171
162
|
];
|
|
163
|
+
const calls = await this.prependPriceUpdates(
|
|
164
|
+
ca.creditManager,
|
|
165
|
+
operationCalls,
|
|
166
|
+
ca
|
|
167
|
+
);
|
|
172
168
|
const tx = cm.creditFacade.liquidateCreditAccount(
|
|
173
169
|
ca.creditAccount,
|
|
174
170
|
to,
|
|
@@ -177,7 +173,7 @@ class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.Abst
|
|
|
177
173
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
178
174
|
}
|
|
179
175
|
/**
|
|
180
|
-
*
|
|
176
|
+
* {@inheritDoc ICreditAccountsService.claimFarmRewards}
|
|
181
177
|
*/
|
|
182
178
|
async claimFarmRewards({
|
|
183
179
|
calls: externalCalls,
|
|
@@ -198,16 +194,15 @@ class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.Abst
|
|
|
198
194
|
});
|
|
199
195
|
}
|
|
200
196
|
if (claimPath.calls.length === 0) throw new Error("No path to execute");
|
|
201
|
-
const
|
|
202
|
-
creditManager: ca.creditManager,
|
|
203
|
-
creditAccount: ca,
|
|
204
|
-
desiredQuotas: averageQuota
|
|
205
|
-
});
|
|
206
|
-
const calls = [
|
|
207
|
-
...priceUpdatesCalls,
|
|
197
|
+
const operationCalls = [
|
|
208
198
|
...claimPath.calls,
|
|
209
199
|
...this.prepareUpdateQuotas(ca.creditFacade, { minQuota, averageQuota })
|
|
210
200
|
];
|
|
201
|
+
const calls = await this.prependPriceUpdates(
|
|
202
|
+
ca.creditManager,
|
|
203
|
+
operationCalls,
|
|
204
|
+
ca
|
|
205
|
+
);
|
|
211
206
|
const tx = cm.creditFacade.multicall(ca.creditAccount, calls);
|
|
212
207
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
213
208
|
}
|
|
@@ -0,0 +1,91 @@
|
|
|
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 multicall_utils_exports = {};
|
|
20
|
+
__export(multicall_utils_exports, {
|
|
21
|
+
extractPriceUpdates: () => extractPriceUpdates,
|
|
22
|
+
extractQuotaTokens: () => extractQuotaTokens,
|
|
23
|
+
mergePriceUpdates: () => mergePriceUpdates
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(multicall_utils_exports);
|
|
26
|
+
var import_viem = require("viem");
|
|
27
|
+
var import_generated = require("../../abi/310/generated.js");
|
|
28
|
+
var import_AddressMap = require("../utils/AddressMap.js");
|
|
29
|
+
var import_AddressSet = require("../utils/AddressSet.js");
|
|
30
|
+
const ON_DEMAND_SELECTOR = (0, import_viem.toFunctionSelector)(
|
|
31
|
+
(0, import_viem.getAbiItem)({
|
|
32
|
+
abi: import_generated.iCreditFacadeMulticallV310Abi,
|
|
33
|
+
name: "onDemandPriceUpdates"
|
|
34
|
+
})
|
|
35
|
+
);
|
|
36
|
+
const UPDATE_QUOTA_SELECTOR = (0, import_viem.toFunctionSelector)(
|
|
37
|
+
(0, import_viem.getAbiItem)({
|
|
38
|
+
abi: import_generated.iCreditFacadeMulticallV310Abi,
|
|
39
|
+
name: "updateQuota"
|
|
40
|
+
})
|
|
41
|
+
);
|
|
42
|
+
function extractPriceUpdates(calls) {
|
|
43
|
+
const priceUpdates = [];
|
|
44
|
+
const remainingCalls = [];
|
|
45
|
+
for (const call of calls) {
|
|
46
|
+
if (isOnDemandPriceUpdateCall(call)) {
|
|
47
|
+
const decoded = (0, import_viem.decodeFunctionData)({
|
|
48
|
+
abi: import_generated.iCreditFacadeMulticallV310Abi,
|
|
49
|
+
data: call.callData
|
|
50
|
+
});
|
|
51
|
+
const updates = decoded.args[0];
|
|
52
|
+
priceUpdates.push(...updates);
|
|
53
|
+
} else {
|
|
54
|
+
remainingCalls.push(call);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return { priceUpdates, remainingCalls };
|
|
58
|
+
}
|
|
59
|
+
function extractQuotaTokens(calls) {
|
|
60
|
+
const tokens = new import_AddressSet.AddressSet();
|
|
61
|
+
for (const { callData } of calls) {
|
|
62
|
+
if (callData.slice(0, 10) !== UPDATE_QUOTA_SELECTOR) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const decoded = (0, import_viem.decodeFunctionData)({
|
|
66
|
+
abi: import_generated.iCreditFacadeMulticallV310Abi,
|
|
67
|
+
data: callData
|
|
68
|
+
});
|
|
69
|
+
const [token, quotaChange] = decoded.args;
|
|
70
|
+
if (quotaChange > 0n) {
|
|
71
|
+
tokens.add(token);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return tokens;
|
|
75
|
+
}
|
|
76
|
+
function mergePriceUpdates(existing, generated) {
|
|
77
|
+
const seen = new import_AddressMap.AddressMap();
|
|
78
|
+
for (const u of [...generated, ...existing]) {
|
|
79
|
+
seen.upsert(u.priceFeed, u);
|
|
80
|
+
}
|
|
81
|
+
return seen.values();
|
|
82
|
+
}
|
|
83
|
+
function isOnDemandPriceUpdateCall(call) {
|
|
84
|
+
return call.callData.slice(0, 10) === ON_DEMAND_SELECTOR;
|
|
85
|
+
}
|
|
86
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
87
|
+
0 && (module.exports = {
|
|
88
|
+
extractPriceUpdates,
|
|
89
|
+
extractQuotaTokens,
|
|
90
|
+
mergePriceUpdates
|
|
91
|
+
});
|
|
@@ -45,11 +45,30 @@ class ContractParseError extends import_viem.BaseError {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
class BaseContract extends import_Construct.Construct {
|
|
48
|
+
/**
|
|
49
|
+
* Viem contract instance for direct read calls
|
|
50
|
+
**/
|
|
48
51
|
contract;
|
|
52
|
+
/**
|
|
53
|
+
* Contract ABI
|
|
54
|
+
**/
|
|
49
55
|
abi;
|
|
56
|
+
/**
|
|
57
|
+
* Gearbox contract type identifier (e.g. `"CREDIT_MANAGER"`), or empty string if unknown.
|
|
58
|
+
**/
|
|
50
59
|
contractType;
|
|
60
|
+
/**
|
|
61
|
+
* Contract version number.
|
|
62
|
+
* @default 0
|
|
63
|
+
**/
|
|
51
64
|
version;
|
|
65
|
+
/**
|
|
66
|
+
* On-chain address of the contract.
|
|
67
|
+
**/
|
|
52
68
|
address;
|
|
69
|
+
/**
|
|
70
|
+
* Display name for the contract.
|
|
71
|
+
**/
|
|
53
72
|
name;
|
|
54
73
|
constructor(options, args) {
|
|
55
74
|
super(options);
|
|
@@ -73,6 +92,7 @@ class BaseContract extends import_Construct.Construct {
|
|
|
73
92
|
register.setAddressLabel(this.address, this.name);
|
|
74
93
|
}
|
|
75
94
|
}
|
|
95
|
+
/** {@inheritDoc IBaseContract.stateHuman} */
|
|
76
96
|
stateHuman(_ = true) {
|
|
77
97
|
return {
|
|
78
98
|
address: this.labelAddress(this.address),
|
|
@@ -81,9 +101,10 @@ class BaseContract extends import_Construct.Construct {
|
|
|
81
101
|
};
|
|
82
102
|
}
|
|
83
103
|
/**
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
|
|
104
|
+
* Applies an on-chain event to update this contract's local state.
|
|
105
|
+
*
|
|
106
|
+
* @param _log - Decoded event log emitted by this contract.
|
|
107
|
+
**/
|
|
87
108
|
processLog(_log) {
|
|
88
109
|
}
|
|
89
110
|
/**
|
|
@@ -158,9 +179,8 @@ class BaseContract extends import_Construct.Construct {
|
|
|
158
179
|
}
|
|
159
180
|
}
|
|
160
181
|
/**
|
|
161
|
-
* Same as {@link
|
|
162
|
-
* @param calldata
|
|
163
|
-
* @returns
|
|
182
|
+
* Same as {@link stringifyFunctionData}, but throws if error occurs.
|
|
183
|
+
* @param calldata - Raw ABI-encoded calldata.
|
|
164
184
|
*/
|
|
165
185
|
mustStringifyFunctionData(calldata) {
|
|
166
186
|
const decoded = (0, import_viem.decodeFunctionData)({
|
|
@@ -32,8 +32,8 @@ class ChainContractsRegister {
|
|
|
32
32
|
labels = new import_AddressMap.AddressMap([], "labels");
|
|
33
33
|
client;
|
|
34
34
|
/**
|
|
35
|
-
*
|
|
36
|
-
|
|
35
|
+
* Shared token metadata (symbol, decimals) for all tokens known on this chain.
|
|
36
|
+
**/
|
|
37
37
|
tokensMeta;
|
|
38
38
|
logger;
|
|
39
39
|
constructor(client, logger) {
|
|
@@ -41,6 +41,9 @@ class ChainContractsRegister {
|
|
|
41
41
|
this.tokensMeta = new import_TokensMeta.TokensMeta(client);
|
|
42
42
|
this.logger = logger;
|
|
43
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Clears all registered contracts, address labels, and token metadata.
|
|
46
|
+
**/
|
|
44
47
|
resetContracts() {
|
|
45
48
|
this.logger?.debug(
|
|
46
49
|
`resetting contacts register with ${this.contracts.size} contracts`
|
|
@@ -49,9 +52,19 @@ class ChainContractsRegister {
|
|
|
49
52
|
this.contracts.clear();
|
|
50
53
|
this.tokensMeta.reset();
|
|
51
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Looks up a contract by address.
|
|
57
|
+
* @param address - On-chain address.
|
|
58
|
+
* @returns The contract wrapper, or `undefined` if not registered.
|
|
59
|
+
*/
|
|
52
60
|
getContract(address) {
|
|
53
61
|
return this.contracts.get(address);
|
|
54
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Looks up a contract by address, throwing if not found.
|
|
65
|
+
* @param address - On-chain address.
|
|
66
|
+
* @throws If no contract is registered at this address.
|
|
67
|
+
*/
|
|
55
68
|
mustGetContract(address) {
|
|
56
69
|
const contract = this.contracts.mustGet(address);
|
|
57
70
|
if (!contract) {
|
|
@@ -59,9 +72,21 @@ class ChainContractsRegister {
|
|
|
59
72
|
}
|
|
60
73
|
return contract;
|
|
61
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Registers (or replaces) a contract at the given address.
|
|
77
|
+
* @param address - On-chain address.
|
|
78
|
+
* @param contract - Contract wrapper instance.
|
|
79
|
+
*/
|
|
62
80
|
setContract(address, contract) {
|
|
63
81
|
this.contracts.upsert(address, contract);
|
|
64
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Assigns a human-readable label to an address for use in logging and
|
|
85
|
+
* parsed call output.
|
|
86
|
+
* @param address - On-chain address.
|
|
87
|
+
* @param label - Static label string, or a function that receives the
|
|
88
|
+
* current label and returns a new one.
|
|
89
|
+
*/
|
|
65
90
|
setAddressLabel(address, label) {
|
|
66
91
|
if (address === import_addresses.NOT_DEPLOYED) {
|
|
67
92
|
return;
|
|
@@ -72,13 +97,25 @@ class ChainContractsRegister {
|
|
|
72
97
|
this.labels.upsert(address, label(this.labels.get(address)));
|
|
73
98
|
}
|
|
74
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Returns a display string for an address, incorporating its label if one exists.
|
|
102
|
+
* @param address - On-chain address.
|
|
103
|
+
* @param omitAddress - When `true`, returns only the label (no address prefix).
|
|
104
|
+
* Falls back to the raw address when no label is set.
|
|
105
|
+
*/
|
|
75
106
|
labelAddress(address, omitAddress) {
|
|
76
107
|
const label = this.labels.get(address);
|
|
77
108
|
return label ? omitAddress ? label : `${address} [${label}]` : address;
|
|
78
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* The viem {@link Chain} object for this register's connected client.
|
|
112
|
+
**/
|
|
79
113
|
get chain() {
|
|
80
114
|
return this.client.chain;
|
|
81
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Numeric chain ID (e.g. `1` for Ethereum mainnet).
|
|
118
|
+
**/
|
|
82
119
|
get chainId() {
|
|
83
120
|
return this.client.chain.id;
|
|
84
121
|
}
|
|
@@ -27,9 +27,6 @@ class Construct {
|
|
|
27
27
|
logger;
|
|
28
28
|
client;
|
|
29
29
|
#register;
|
|
30
|
-
/**
|
|
31
|
-
* Indicates that contract state needs to be updated
|
|
32
|
-
*/
|
|
33
30
|
#dirty = false;
|
|
34
31
|
constructor(options) {
|
|
35
32
|
if (options instanceof import_ChainContractsRegister.ChainContractsRegister) {
|
|
@@ -61,12 +58,22 @@ class Construct {
|
|
|
61
58
|
safeGetRegister() {
|
|
62
59
|
return this.#register;
|
|
63
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* The viem {@link Chain} object associated with the connected client.
|
|
63
|
+
**/
|
|
64
64
|
get chain() {
|
|
65
65
|
return this.client.chain;
|
|
66
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Numeric chain ID (e.g. `1` for Ethereum mainnet).
|
|
69
|
+
**/
|
|
67
70
|
get chainId() {
|
|
68
71
|
return this.client.chain.id;
|
|
69
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Gearbox network type for this chain (e.g. `"Mainnet"`, `"Arbitrum"`).
|
|
75
|
+
* @throws If the chain was not created by the Gearbox SDK.
|
|
76
|
+
*/
|
|
70
77
|
get networkType() {
|
|
71
78
|
if ("network" in this.chain) {
|
|
72
79
|
return this.chain.network;
|
|
@@ -74,6 +81,7 @@ class Construct {
|
|
|
74
81
|
throw new Error(`chain ${this.chain.id} is not a Gearbox SDK chain`);
|
|
75
82
|
}
|
|
76
83
|
/**
|
|
84
|
+
* @internal
|
|
77
85
|
* Indicates that contract state diverged from onchain state and needs to be updated
|
|
78
86
|
*/
|
|
79
87
|
get dirty() {
|
|
@@ -82,6 +90,9 @@ class Construct {
|
|
|
82
90
|
set dirty(value) {
|
|
83
91
|
this.#dirty = value;
|
|
84
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* Information about tokens known on this chain
|
|
95
|
+
*/
|
|
85
96
|
get tokensMeta() {
|
|
86
97
|
return this.register.tokensMeta;
|
|
87
98
|
}
|
|
@@ -89,6 +100,7 @@ class Construct {
|
|
|
89
100
|
return this.#register?.labelAddress(address, omitAddress) ?? address;
|
|
90
101
|
}
|
|
91
102
|
/**
|
|
103
|
+
* @internal
|
|
92
104
|
* Returns list of addresses that should be watched for events to sync state
|
|
93
105
|
*/
|
|
94
106
|
get watchAddresses() {
|
|
@@ -30,13 +30,26 @@ class TokensMeta extends import_utils.AddressMap {
|
|
|
30
30
|
super(void 0, "tokensMeta");
|
|
31
31
|
this.#client = client;
|
|
32
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Clears all token metadata
|
|
35
|
+
**/
|
|
33
36
|
reset() {
|
|
34
37
|
this.clear();
|
|
35
38
|
this.#phantomTokensLoaded = void 0;
|
|
36
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Returns the symbol string for a token.
|
|
42
|
+
* @param token - Token address.
|
|
43
|
+
* @throws If the token is not in the registry.
|
|
44
|
+
*/
|
|
37
45
|
symbol(token) {
|
|
38
46
|
return this.mustGet(token).symbol;
|
|
39
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Returns the decimal count for a token.
|
|
50
|
+
* @param token - Token address.
|
|
51
|
+
* @throws If the token is not in the registry.
|
|
52
|
+
*/
|
|
40
53
|
decimals(token) {
|
|
41
54
|
return this.mustGet(token).decimals;
|
|
42
55
|
}
|
|
@@ -71,9 +84,19 @@ class TokensMeta extends import_utils.AddressMap {
|
|
|
71
84
|
const asStr = (0, import_utils.formatBN)(amount, this.decimals(token), precision);
|
|
72
85
|
return symbol ? `${asStr} ${this.symbol(token)}` : asStr;
|
|
73
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Finds a token by its symbol (e.g. `"USDC"`).
|
|
89
|
+
* @param symbol - Case-sensitive ticker symbol.
|
|
90
|
+
* @returns The matching metadata, or `undefined` if no token has this symbol.
|
|
91
|
+
*/
|
|
74
92
|
findBySymbol(symbol) {
|
|
75
93
|
return this.values().find((v) => v.symbol === symbol);
|
|
76
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Finds a token by its symbol, throwing if not found.
|
|
97
|
+
* @param symbol - Case-sensitive ticker symbol.
|
|
98
|
+
* @throws If no token matches the symbol.
|
|
99
|
+
*/
|
|
77
100
|
mustFindBySymbol(symbol) {
|
|
78
101
|
const meta = this.findBySymbol(symbol);
|
|
79
102
|
if (!meta) {
|
|
@@ -18,7 +18,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var address_provider_exports = {};
|
|
20
20
|
__export(address_provider_exports, {
|
|
21
|
-
ADDRESS_PROVIDER: () => ADDRESS_PROVIDER,
|
|
22
21
|
ADDRESS_PROVIDER_V310: () => ADDRESS_PROVIDER_V310,
|
|
23
22
|
AP_ACCOUNT_FACTORY: () => AP_ACCOUNT_FACTORY,
|
|
24
23
|
AP_ACL: () => AP_ACL,
|
|
@@ -55,7 +54,6 @@ __export(address_provider_exports, {
|
|
|
55
54
|
NO_VERSION: () => NO_VERSION
|
|
56
55
|
});
|
|
57
56
|
module.exports = __toCommonJS(address_provider_exports);
|
|
58
|
-
var import_addresses = require("./addresses.js");
|
|
59
57
|
const NO_VERSION = 0;
|
|
60
58
|
const AP_ACCOUNT_FACTORY = "ACCOUNT_FACTORY";
|
|
61
59
|
const AP_ACL = "ACL";
|
|
@@ -89,29 +87,9 @@ const AP_WETH_GATEWAY = "WETH_GATEWAY";
|
|
|
89
87
|
const AP_WETH_TOKEN = "WETH_TOKEN";
|
|
90
88
|
const AP_ZAPPER_REGISTER = "ZAPPER_REGISTER";
|
|
91
89
|
const AP_ZERO_PRICE_FEED = "ZERO_PRICE_FEED";
|
|
92
|
-
const ADDRESS_PROVIDER = {
|
|
93
|
-
Mainnet: "0x9ea7b04Da02a5373317D745c1571c84aaD03321D",
|
|
94
|
-
Arbitrum: "0x7d04eCdb892Ae074f03B5D0aBA03796F90F3F2af",
|
|
95
|
-
Optimism: "0x3761ca4BFAcFCFFc1B8034e69F19116dD6756726",
|
|
96
|
-
Base: import_addresses.NOT_DEPLOYED,
|
|
97
|
-
Sonic: "0x4b27b296273B72d7c7bfee1ACE93DC081467C41B",
|
|
98
|
-
// New networks
|
|
99
|
-
MegaETH: import_addresses.NOT_DEPLOYED,
|
|
100
|
-
Monad: import_addresses.NOT_DEPLOYED,
|
|
101
|
-
Berachain: import_addresses.NOT_DEPLOYED,
|
|
102
|
-
Avalanche: import_addresses.NOT_DEPLOYED,
|
|
103
|
-
BNB: import_addresses.NOT_DEPLOYED,
|
|
104
|
-
WorldChain: import_addresses.NOT_DEPLOYED,
|
|
105
|
-
Etherlink: import_addresses.NOT_DEPLOYED,
|
|
106
|
-
Hemi: import_addresses.NOT_DEPLOYED,
|
|
107
|
-
Lisk: import_addresses.NOT_DEPLOYED,
|
|
108
|
-
Plasma: import_addresses.NOT_DEPLOYED,
|
|
109
|
-
Somnia: import_addresses.NOT_DEPLOYED
|
|
110
|
-
};
|
|
111
90
|
const ADDRESS_PROVIDER_V310 = "0xF7f0a609BfAb9a0A98786951ef10e5FE26cC1E38";
|
|
112
91
|
// Annotate the CommonJS export names for ESM import in node:
|
|
113
92
|
0 && (module.exports = {
|
|
114
|
-
ADDRESS_PROVIDER,
|
|
115
93
|
ADDRESS_PROVIDER_V310,
|
|
116
94
|
AP_ACCOUNT_FACTORY,
|
|
117
95
|
AP_ACL,
|
|
@@ -56,6 +56,9 @@ class AbstractAddressProviderContract extends import_base.BaseContract {
|
|
|
56
56
|
this.#addresses[k][version] = overriden;
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* {@inheritDoc IAddressProviderContract.getAddress}
|
|
61
|
+
**/
|
|
59
62
|
getAddress(contract, version = import_constants.NO_VERSION) {
|
|
60
63
|
if (!this.#addresses[contract]) {
|
|
61
64
|
throw new Error(`Address ${contract}, version: ${version} not found`);
|
|
@@ -66,6 +69,9 @@ class AbstractAddressProviderContract extends import_base.BaseContract {
|
|
|
66
69
|
}
|
|
67
70
|
return result;
|
|
68
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* {@inheritDoc IAddressProviderContract.getLatest}
|
|
74
|
+
**/
|
|
69
75
|
getLatest(contract, range) {
|
|
70
76
|
const allVersions = this.#addresses[contract];
|
|
71
77
|
if (!allVersions) {
|
|
@@ -85,6 +91,9 @@ class AbstractAddressProviderContract extends import_base.BaseContract {
|
|
|
85
91
|
}
|
|
86
92
|
return [address, version];
|
|
87
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* {@inheritDoc IAddressProviderContract.mustGetLatest}
|
|
96
|
+
**/
|
|
88
97
|
mustGetLatest(contract, range) {
|
|
89
98
|
const result = this.getLatest(contract, range);
|
|
90
99
|
if (!result) {
|
|
@@ -92,6 +101,9 @@ class AbstractAddressProviderContract extends import_base.BaseContract {
|
|
|
92
101
|
}
|
|
93
102
|
return result;
|
|
94
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* {@inheritDoc IAddressProviderContract.state}
|
|
106
|
+
**/
|
|
95
107
|
get state() {
|
|
96
108
|
return {
|
|
97
109
|
baseParams: {
|
|
@@ -103,6 +115,9 @@ class AbstractAddressProviderContract extends import_base.BaseContract {
|
|
|
103
115
|
addresses: this.#addresses
|
|
104
116
|
};
|
|
105
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* {@inheritDoc IAddressProviderContract.stateHuman}
|
|
120
|
+
**/
|
|
106
121
|
stateHuman(raw = true) {
|
|
107
122
|
return {
|
|
108
123
|
...super.stateHuman(raw),
|