@gearbox-protocol/sdk 7.11.0-next.3 → 7.11.0
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/adapters/AdaptersPlugin.js +3 -2
- package/dist/cjs/bots/BotsPlugin.js +17 -29
- package/dist/cjs/dev/AccountsCounterPlugin.js +10 -19
- package/dist/cjs/dev/createTransport.js +2 -1
- package/dist/cjs/sdk/GearboxSDK.js +3 -13
- package/dist/cjs/sdk/chain/chains.js +21 -10
- package/dist/cjs/sdk/constants/address-provider.js +2 -1
- package/dist/cjs/sdk/constants/addresses.js +8 -4
- package/dist/cjs/sdk/constants/networks.js +5 -2
- package/dist/cjs/sdk/plugins/V300StalenessPeriodPlugin.js +1 -3
- package/dist/cjs/sdk/router/RouterV300Contract.js +2 -1
- package/dist/cjs/sdk/sdk-gov-legacy/contracts/contracts.js +74 -37
- package/dist/cjs/sdk/sdk-gov-legacy/tokens/token.js +4 -2
- package/dist/cjs/sdk/sdk-gov-legacy/tokens/tokenData.js +2 -1
- package/dist/cjs/sdk/sdk-legacy/core/endpoint.js +2 -1
- package/dist/cjs/sdk/sdk-legacy/gearboxRewards/api.js +159 -94
- package/dist/cjs/sdk/sdk-legacy/gearboxRewards/apy.js +1 -1
- package/dist/cjs/sdk/sdk-legacy/index.js +2 -0
- package/dist/cjs/{pools7DAgo/types.js → sdk/sdk-legacy/pathfinder/core.js} +2 -2
- package/dist/cjs/{pools7DAgo → sdk/sdk-legacy/pathfinder}/index.js +4 -6
- package/dist/cjs/sdk/utils/viem/simulateWithPriceUpdates.js +1 -0
- package/dist/cjs/zappers/ZappersPlugin.js +4 -13
- package/dist/esm/adapters/AdaptersPlugin.js +3 -2
- package/dist/esm/bots/BotsPlugin.js +17 -29
- package/dist/esm/dev/AccountsCounterPlugin.js +10 -19
- package/dist/esm/dev/createTransport.js +2 -1
- package/dist/esm/sdk/GearboxSDK.js +3 -13
- package/dist/esm/sdk/chain/chains.js +22 -10
- package/dist/esm/sdk/constants/address-provider.js +2 -1
- package/dist/esm/sdk/constants/addresses.js +8 -4
- package/dist/esm/sdk/constants/networks.js +5 -2
- package/dist/esm/sdk/plugins/V300StalenessPeriodPlugin.js +1 -3
- package/dist/esm/sdk/router/RouterV300Contract.js +2 -1
- package/dist/esm/sdk/sdk-gov-legacy/contracts/contracts.js +74 -37
- package/dist/esm/sdk/sdk-gov-legacy/tokens/token.js +4 -2
- package/dist/esm/sdk/sdk-gov-legacy/tokens/tokenData.js +2 -1
- package/dist/esm/sdk/sdk-legacy/core/endpoint.js +2 -1
- package/dist/esm/sdk/sdk-legacy/gearboxRewards/api.js +159 -94
- package/dist/esm/sdk/sdk-legacy/gearboxRewards/apy.js +1 -1
- package/dist/esm/sdk/sdk-legacy/index.js +1 -0
- package/dist/esm/sdk/sdk-legacy/pathfinder/index.js +1 -0
- package/dist/esm/sdk/utils/viem/simulateWithPriceUpdates.js +1 -0
- package/dist/esm/zappers/ZappersPlugin.js +4 -13
- package/dist/types/adapters/AdaptersPlugin.d.ts +4 -5
- package/dist/types/bots/BotsPlugin.d.ts +3 -5
- package/dist/types/bots/types.d.ts +2 -2
- package/dist/types/dev/AccountsCounterPlugin.d.ts +2 -4
- package/dist/types/sdk/GearboxSDK.d.ts +3 -4
- package/dist/types/sdk/chain/chains.d.ts +2 -2
- package/dist/types/sdk/plugins/V300StalenessPeriodPlugin.d.ts +2 -3
- package/dist/types/sdk/plugins/types.d.ts +15 -33
- package/dist/types/sdk/sdk-legacy/gearboxRewards/api.d.ts +27 -16
- package/dist/types/sdk/sdk-legacy/gearboxRewards/apy.d.ts +15 -9
- package/dist/types/sdk/sdk-legacy/index.d.ts +1 -0
- package/dist/types/sdk/sdk-legacy/pathfinder/core.d.ts +14 -0
- package/dist/types/sdk/sdk-legacy/pathfinder/index.d.ts +1 -0
- package/dist/types/zappers/ZappersPlugin.d.ts +4 -5
- package/package.json +1 -1
- package/dist/cjs/degenDistributors/DegenDistributorsPlugin.js +0 -110
- package/dist/cjs/degenDistributors/index.js +0 -24
- package/dist/cjs/degenDistributors/package.json +0 -1
- package/dist/cjs/degenDistributors/types.js +0 -16
- package/dist/cjs/pools7DAgo/Pools7DAgoPlugin.js +0 -116
- package/dist/cjs/pools7DAgo/package.json +0 -1
- package/dist/esm/degenDistributors/DegenDistributorsPlugin.js +0 -86
- package/dist/esm/degenDistributors/index.js +0 -2
- package/dist/esm/degenDistributors/package.json +0 -1
- package/dist/esm/pools7DAgo/Pools7DAgoPlugin.js +0 -99
- package/dist/esm/pools7DAgo/index.js +0 -2
- package/dist/esm/pools7DAgo/package.json +0 -1
- package/dist/esm/pools7DAgo/types.js +0 -0
- package/dist/types/degenDistributors/DegenDistributorsPlugin.d.ts +0 -22
- package/dist/types/degenDistributors/index.d.ts +0 -2
- package/dist/types/degenDistributors/types.d.ts +0 -4
- package/dist/types/pools7DAgo/Pools7DAgoPlugin.d.ts +0 -22
- package/dist/types/pools7DAgo/index.d.ts +0 -2
- package/dist/types/pools7DAgo/types.d.ts +0 -9
- /package/dist/esm/{degenDistributors/types.js → sdk/sdk-legacy/pathfinder/core.js} +0 -0
|
@@ -8,48 +8,10 @@ import { GearboxBackendApi } from "../core/endpoint.js";
|
|
|
8
8
|
import { BigIntMath } from "../utils/math.js";
|
|
9
9
|
import { MerkleXYZApi } from "./merklAPI.js";
|
|
10
10
|
class GearboxRewardsApi {
|
|
11
|
-
static async
|
|
12
|
-
provider,
|
|
13
|
-
account,
|
|
14
|
-
currentTokenData,
|
|
15
|
-
network,
|
|
16
|
-
airdropDistributorAddress,
|
|
17
|
-
reportError
|
|
18
|
-
}) {
|
|
19
|
-
if (!airdropDistributorAddress) return [];
|
|
20
|
-
const [claimedRespUnsafe, merkleDataRespUnsafe] = await Promise.allSettled([
|
|
21
|
-
this.getClaimed({ airdropDistributorAddress, provider, account }),
|
|
22
|
-
this.getMerkle(provider, airdropDistributorAddress, network, account)
|
|
23
|
-
]);
|
|
24
|
-
const claimedResp = this.extractFulfilled(claimedRespUnsafe, reportError, "getLmRewardsV2") || 0n;
|
|
25
|
-
const merkleDataResp = this.extractFulfilled(
|
|
26
|
-
merkleDataRespUnsafe,
|
|
27
|
-
reportError,
|
|
28
|
-
"getLmRewardsV2"
|
|
29
|
-
);
|
|
30
|
-
const amountOnContract = this.getAmountOnContract({
|
|
31
|
-
account,
|
|
32
|
-
merkleData: merkleDataResp
|
|
33
|
-
});
|
|
34
|
-
const diff = amountOnContract - claimedResp;
|
|
35
|
-
const availableToClaimV2 = BigIntMath.max(0n, diff);
|
|
36
|
-
const rewards = [
|
|
37
|
-
{
|
|
38
|
-
amount: availableToClaimV2,
|
|
39
|
-
type: "merkleV2",
|
|
40
|
-
rewardToken: currentTokenData.GEAR,
|
|
41
|
-
rewardTokenDecimals: 18,
|
|
42
|
-
rewardTokenSymbol: "GEAR"
|
|
43
|
-
}
|
|
44
|
-
];
|
|
45
|
-
return rewards;
|
|
46
|
-
}
|
|
47
|
-
static async getLmRewardsV3({
|
|
11
|
+
static async getLmRewardsInfo({
|
|
48
12
|
pools,
|
|
49
|
-
tokensList,
|
|
50
13
|
provider,
|
|
51
|
-
|
|
52
|
-
reportError
|
|
14
|
+
tokensList
|
|
53
15
|
}) {
|
|
54
16
|
const poolByStakedDiesel = Object.values(pools).reduce((acc, p) => {
|
|
55
17
|
p.stakedDieselToken.forEach((t) => {
|
|
@@ -60,85 +22,155 @@ class GearboxRewardsApi {
|
|
|
60
22
|
});
|
|
61
23
|
return acc;
|
|
62
24
|
}, {});
|
|
63
|
-
const
|
|
64
|
-
|
|
25
|
+
const poolByDiesel = Object.values(pools).reduce(
|
|
26
|
+
(acc, p) => {
|
|
27
|
+
acc[p.dieselToken] = p.address;
|
|
28
|
+
return acc;
|
|
29
|
+
},
|
|
30
|
+
{}
|
|
31
|
+
);
|
|
32
|
+
const poolByItsToken = { ...poolByStakedDiesel, ...poolByDiesel };
|
|
33
|
+
const poolStakedTokens = TypedObjectUtils.keys(poolByStakedDiesel);
|
|
34
|
+
const allPoolTokens = TypedObjectUtils.keys(poolByItsToken);
|
|
35
|
+
const farmInfoCalls = poolStakedTokens.map((address) => ({
|
|
65
36
|
address,
|
|
66
37
|
abi: iFarmingPoolAbi,
|
|
67
38
|
functionName: "farmInfo",
|
|
68
39
|
args: []
|
|
69
40
|
}));
|
|
70
|
-
const
|
|
41
|
+
const farmSupplyCalls = allPoolTokens.map((address) => ({
|
|
71
42
|
address,
|
|
72
|
-
abi:
|
|
73
|
-
functionName: "
|
|
43
|
+
abi: iFarmingPoolAbi,
|
|
44
|
+
functionName: "totalSupply",
|
|
74
45
|
args: []
|
|
75
46
|
}));
|
|
76
|
-
const
|
|
47
|
+
const rewardTokenCalls = poolStakedTokens.map((address) => ({
|
|
77
48
|
address,
|
|
78
|
-
abi:
|
|
79
|
-
functionName: "
|
|
80
|
-
args: [
|
|
49
|
+
abi: POOL_REWARDS_ABI,
|
|
50
|
+
functionName: "rewardsToken",
|
|
51
|
+
args: []
|
|
81
52
|
}));
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
]
|
|
88
|
-
const safeResponse = this.extractFulfilled(response, reportError, "v3Rewards") || [];
|
|
53
|
+
const mc = await provider.multicall({
|
|
54
|
+
allowFailure: false,
|
|
55
|
+
contracts: [...farmInfoCalls, ...farmSupplyCalls, ...rewardTokenCalls]
|
|
56
|
+
});
|
|
57
|
+
const mcResponse = mc;
|
|
58
|
+
const [...restMCResponse] = mcResponse;
|
|
89
59
|
const farmInfoCallsEnd = farmInfoCalls.length;
|
|
90
|
-
const farmInfo =
|
|
60
|
+
const farmInfo = restMCResponse.slice(
|
|
91
61
|
0,
|
|
92
62
|
farmInfoCallsEnd
|
|
93
63
|
);
|
|
94
|
-
const
|
|
95
|
-
const
|
|
64
|
+
const farmSupplyCallsEnd = farmInfoCallsEnd + farmSupplyCalls.length;
|
|
65
|
+
const farmSupply = restMCResponse.slice(
|
|
96
66
|
farmInfoCallsEnd,
|
|
97
|
-
|
|
67
|
+
farmSupplyCallsEnd
|
|
98
68
|
);
|
|
99
|
-
const
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
69
|
+
const rewardTokenCallsEnd = farmSupplyCallsEnd + rewardTokenCalls.length;
|
|
70
|
+
const rewardTokens = restMCResponse.slice(
|
|
71
|
+
farmSupplyCallsEnd,
|
|
72
|
+
rewardTokenCallsEnd
|
|
103
73
|
);
|
|
104
|
-
const
|
|
105
|
-
(
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return {
|
|
112
|
-
pool,
|
|
113
|
-
poolToken: address,
|
|
114
|
-
rewardToken,
|
|
115
|
-
rewardTokenDecimals: tokensList[rewardToken]?.decimals || 18,
|
|
116
|
-
rewardTokenSymbol: tokensList[rewardToken]?.symbol || "unknown",
|
|
117
|
-
amount: farmed ?? 0n,
|
|
118
|
-
type: "stakedV3"
|
|
119
|
-
};
|
|
120
|
-
}
|
|
74
|
+
const infoByPool = poolStakedTokens.reduce(
|
|
75
|
+
(acc, p, index) => {
|
|
76
|
+
const info = farmInfo[index];
|
|
77
|
+
if (info) acc[p] = info;
|
|
78
|
+
return acc;
|
|
79
|
+
},
|
|
80
|
+
{}
|
|
121
81
|
);
|
|
122
|
-
const
|
|
123
|
-
(acc,
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
acc.zero.push(r);
|
|
82
|
+
const rewardTokenPool = poolStakedTokens.reduce(
|
|
83
|
+
(acc, p, index) => {
|
|
84
|
+
const token = rewardTokens[index];
|
|
85
|
+
if (token) {
|
|
86
|
+
acc[p] = token.toLowerCase();
|
|
128
87
|
}
|
|
129
88
|
return acc;
|
|
130
89
|
},
|
|
131
|
-
{
|
|
90
|
+
{}
|
|
91
|
+
);
|
|
92
|
+
const stakedTokenRewards = allPoolTokens.reduce(
|
|
93
|
+
(acc, pool) => {
|
|
94
|
+
const info = infoByPool[pool];
|
|
95
|
+
const token = rewardTokenPool[pool];
|
|
96
|
+
const tokenData = tokensList[token];
|
|
97
|
+
const baseReward = info && tokenData ? {
|
|
98
|
+
pool: poolByItsToken[pool],
|
|
99
|
+
duration: BigInt(info.duration),
|
|
100
|
+
finished: BigInt(info.finished),
|
|
101
|
+
reward: info.reward,
|
|
102
|
+
balance: info.balance,
|
|
103
|
+
symbol: tokenData.symbol
|
|
104
|
+
} : void 0;
|
|
105
|
+
if (baseReward) acc.base[pool] = baseReward;
|
|
106
|
+
acc.all[pool] = [...baseReward ? [baseReward] : []];
|
|
107
|
+
return acc;
|
|
108
|
+
},
|
|
109
|
+
{ base: {}, all: {} }
|
|
132
110
|
);
|
|
133
|
-
|
|
111
|
+
const rewardPoolsSupply = allPoolTokens.reduce(
|
|
112
|
+
(acc, address, i) => {
|
|
113
|
+
acc[address] = farmSupply[i] || 0n;
|
|
114
|
+
return acc;
|
|
115
|
+
},
|
|
116
|
+
{}
|
|
117
|
+
);
|
|
118
|
+
return {
|
|
119
|
+
rewardPoolsInfo: stakedTokenRewards.all,
|
|
120
|
+
baseRewardPoolsInfo: stakedTokenRewards.base,
|
|
121
|
+
rewardPoolsSupply
|
|
122
|
+
};
|
|
134
123
|
}
|
|
135
|
-
static async
|
|
124
|
+
static async getLmRewardsV2({
|
|
125
|
+
provider,
|
|
126
|
+
account,
|
|
127
|
+
currentTokenData,
|
|
128
|
+
network,
|
|
129
|
+
airdropDistributorAddress
|
|
130
|
+
}) {
|
|
131
|
+
if (!airdropDistributorAddress) return { rewards: [] };
|
|
132
|
+
const [claimedResp, merkleDataResp] = await Promise.all([
|
|
133
|
+
this.getClaimed({ airdropDistributorAddress, provider, account }),
|
|
134
|
+
this.getMerkle(provider, airdropDistributorAddress, network, account)
|
|
135
|
+
]);
|
|
136
|
+
const amountOnContract = this.getAmountOnContract({
|
|
137
|
+
account,
|
|
138
|
+
merkleData: merkleDataResp
|
|
139
|
+
});
|
|
140
|
+
const diff = amountOnContract - claimedResp;
|
|
141
|
+
const availableToClaimV2 = BigIntMath.max(0n, diff);
|
|
142
|
+
const rewards = [
|
|
143
|
+
{
|
|
144
|
+
amount: availableToClaimV2,
|
|
145
|
+
type: "merkleV2",
|
|
146
|
+
rewardToken: currentTokenData.GEAR,
|
|
147
|
+
rewardTokenDecimals: 18,
|
|
148
|
+
rewardTokenSymbol: "GEAR"
|
|
149
|
+
}
|
|
150
|
+
];
|
|
151
|
+
return { rewards };
|
|
152
|
+
}
|
|
153
|
+
static async getLmRewardsV3({
|
|
136
154
|
pools,
|
|
155
|
+
baseRewardPoolsInfo,
|
|
156
|
+
currentTokenData,
|
|
157
|
+
tokensList,
|
|
158
|
+
provider,
|
|
137
159
|
account,
|
|
138
160
|
network,
|
|
139
161
|
reportError
|
|
140
162
|
}) {
|
|
141
|
-
const
|
|
163
|
+
const poolTokens = Object.keys(baseRewardPoolsInfo);
|
|
164
|
+
const [gearboxLmResponse, merkleXYZLMResponse] = await Promise.allSettled([
|
|
165
|
+
provider.multicall({
|
|
166
|
+
allowFailure: false,
|
|
167
|
+
contracts: poolTokens.map((address) => ({
|
|
168
|
+
address,
|
|
169
|
+
abi: iFarmingPoolAbi,
|
|
170
|
+
functionName: "farmed",
|
|
171
|
+
args: [account]
|
|
172
|
+
}))
|
|
173
|
+
}),
|
|
142
174
|
axios.get(
|
|
143
175
|
MerkleXYZApi.getUserRewardsUrl({
|
|
144
176
|
params: {
|
|
@@ -148,10 +180,15 @@ class GearboxRewardsApi {
|
|
|
148
180
|
})
|
|
149
181
|
)
|
|
150
182
|
]);
|
|
183
|
+
const gearboxLm = this.extractFulfilled(
|
|
184
|
+
gearboxLmResponse,
|
|
185
|
+
reportError,
|
|
186
|
+
"v3Rewards"
|
|
187
|
+
) || [];
|
|
151
188
|
const merkleXYZLm = this.extractFulfilled(
|
|
152
189
|
merkleXYZLMResponse,
|
|
153
190
|
reportError,
|
|
154
|
-
"
|
|
191
|
+
"merkleRewards"
|
|
155
192
|
)?.data;
|
|
156
193
|
const poolByItsToken = Object.values(pools).reduce((acc, p) => {
|
|
157
194
|
p.stakedDieselToken.forEach((t) => {
|
|
@@ -189,7 +226,34 @@ class GearboxRewardsApi {
|
|
|
189
226
|
});
|
|
190
227
|
return acc;
|
|
191
228
|
}, {});
|
|
192
|
-
|
|
229
|
+
const gearboxLmRewards = poolTokens.map((address, i) => {
|
|
230
|
+
const info = baseRewardPoolsInfo[address];
|
|
231
|
+
const rewardToken = currentTokenData[info.symbol];
|
|
232
|
+
return {
|
|
233
|
+
pool: info.pool,
|
|
234
|
+
poolToken: address,
|
|
235
|
+
rewardToken,
|
|
236
|
+
rewardTokenDecimals: tokensList[rewardToken]?.decimals || 18,
|
|
237
|
+
rewardTokenSymbol: info.symbol,
|
|
238
|
+
amount: gearboxLm[i] || 0n,
|
|
239
|
+
type: "stakedV3"
|
|
240
|
+
};
|
|
241
|
+
});
|
|
242
|
+
const { zero, nonZero } = gearboxLmRewards.reduce(
|
|
243
|
+
(acc, r) => {
|
|
244
|
+
const amount = r.amount || 0n;
|
|
245
|
+
if (amount > 0n) {
|
|
246
|
+
acc.nonZero.push(r);
|
|
247
|
+
} else {
|
|
248
|
+
acc.zero.push(r);
|
|
249
|
+
}
|
|
250
|
+
return acc;
|
|
251
|
+
},
|
|
252
|
+
{ nonZero: [], zero: [] }
|
|
253
|
+
);
|
|
254
|
+
return {
|
|
255
|
+
rewards: [...nonZero, ...Object.values(extraRewards), zero]
|
|
256
|
+
};
|
|
193
257
|
}
|
|
194
258
|
static extractFulfilled(r, reportError, description) {
|
|
195
259
|
if (r.status === "fulfilled") {
|
|
@@ -294,7 +358,8 @@ class GearboxRewardsApi {
|
|
|
294
358
|
account,
|
|
295
359
|
merkleData
|
|
296
360
|
}) {
|
|
297
|
-
const {
|
|
361
|
+
const { claims = {} } = merkleData || {};
|
|
362
|
+
const { amount } = claims[getAddress(account)] || {};
|
|
298
363
|
return BigInt(amount || 0);
|
|
299
364
|
}
|
|
300
365
|
}
|
|
@@ -20,7 +20,7 @@ class GearboxRewardsApy {
|
|
|
20
20
|
if (!isV3 || !stakedDieselToken) return [];
|
|
21
21
|
const info = rewardPoolsInfo[stakedDieselToken];
|
|
22
22
|
if (!info) return [];
|
|
23
|
-
const extra =
|
|
23
|
+
const extra = info.map(
|
|
24
24
|
(inf) => this.getPoolSingleExtraLmAPY_V3({
|
|
25
25
|
...restProps,
|
|
26
26
|
stakedDieselToken,
|
|
@@ -9,6 +9,7 @@ export * from "./core/pool.js";
|
|
|
9
9
|
export * from "./core/strategy.js";
|
|
10
10
|
export * from "./core/transactions.js";
|
|
11
11
|
export * from "./gearboxRewards/index.js";
|
|
12
|
+
export * from "./pathfinder/index.js";
|
|
12
13
|
export * from "./payload/creditAccount.js";
|
|
13
14
|
export * from "./payload/creditManager.js";
|
|
14
15
|
export * from "./payload/creditSession.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./core.js";
|
|
@@ -8,16 +8,10 @@ import {
|
|
|
8
8
|
class ZappersPlugin extends SDKConstruct {
|
|
9
9
|
#zappers;
|
|
10
10
|
version = 1;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
// }
|
|
14
|
-
async syncState() {
|
|
15
|
-
await this.load();
|
|
11
|
+
async attach() {
|
|
12
|
+
await this.loadZappers();
|
|
16
13
|
}
|
|
17
|
-
async
|
|
18
|
-
if (!force && this.loaded) {
|
|
19
|
-
return this.state;
|
|
20
|
-
}
|
|
14
|
+
async loadZappers() {
|
|
21
15
|
this.#zappers = new AddressMap(void 0, "zappers");
|
|
22
16
|
const [pcAddr] = this.sdk.addressProvider.mustGetLatest(
|
|
23
17
|
AP_PERIPHERY_COMPRESSOR,
|
|
@@ -54,7 +48,6 @@ class ZappersPlugin extends SDKConstruct {
|
|
|
54
48
|
}
|
|
55
49
|
}
|
|
56
50
|
this.#loadZapperTokens();
|
|
57
|
-
return this.state;
|
|
58
51
|
}
|
|
59
52
|
get zappers() {
|
|
60
53
|
if (!this.#zappers) {
|
|
@@ -62,9 +55,6 @@ class ZappersPlugin extends SDKConstruct {
|
|
|
62
55
|
}
|
|
63
56
|
return this.#zappers;
|
|
64
57
|
}
|
|
65
|
-
get loaded() {
|
|
66
|
-
return !!this.#zappers;
|
|
67
|
-
}
|
|
68
58
|
stateHuman(_) {
|
|
69
59
|
return this.zappers.values().flatMap(
|
|
70
60
|
(l) => l.flatMap((z) => ({
|
|
@@ -78,6 +68,7 @@ class ZappersPlugin extends SDKConstruct {
|
|
|
78
68
|
}
|
|
79
69
|
get state() {
|
|
80
70
|
return {
|
|
71
|
+
version: this.version,
|
|
81
72
|
zappers: this.zappers.asRecord()
|
|
82
73
|
};
|
|
83
74
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import type { BaseState, IBaseContract, IGearboxSDKPlugin } from "../sdk/index.js";
|
|
1
|
+
import type { BaseState, IBaseContract, IGearboxSDKPlugin, IPluginState } from "../sdk/index.js";
|
|
2
2
|
import { SDKConstruct } from "../sdk/index.js";
|
|
3
|
-
export declare class AdaptersPlugin extends SDKConstruct implements IGearboxSDKPlugin<
|
|
3
|
+
export declare class AdaptersPlugin extends SDKConstruct implements IGearboxSDKPlugin<IPluginState> {
|
|
4
4
|
readonly name = "Adapters";
|
|
5
5
|
readonly version = 1;
|
|
6
|
-
readonly loaded = true;
|
|
7
6
|
createContract(data: BaseState): IBaseContract | undefined;
|
|
8
7
|
stateHuman(_?: boolean): {};
|
|
9
|
-
get state():
|
|
10
|
-
hydrate(_:
|
|
8
|
+
get state(): IPluginState;
|
|
9
|
+
hydrate(_: IPluginState): void;
|
|
11
10
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Address } from "viem";
|
|
2
2
|
import type { GearboxSDK, IGearboxSDKPlugin } from "../sdk/index.js";
|
|
3
|
-
import {
|
|
3
|
+
import { SDKConstruct } from "../sdk/index.js";
|
|
4
4
|
import { PartialLiquidationBotV300Contract } from "./PartialLiquidationBotV300Contract.js";
|
|
5
5
|
import { PartialLiquidationBotV310Contract } from "./PartialLiquidationBotV310Contract.js";
|
|
6
6
|
import { type BotsPluginState, type BotsPluginStateHuman, type BotState } from "./types.js";
|
|
@@ -13,13 +13,11 @@ export declare class BotsPlugin extends SDKConstruct implements IGearboxSDKPlugi
|
|
|
13
13
|
#private;
|
|
14
14
|
readonly version = 1;
|
|
15
15
|
constructor(sdk: GearboxSDK);
|
|
16
|
+
attach(): Promise<void>;
|
|
16
17
|
syncState(): Promise<void>;
|
|
17
|
-
get loaded(): boolean;
|
|
18
|
-
load(force?: boolean): Promise<BotsPluginState>;
|
|
19
|
-
stateHuman(raw?: boolean): BotsPluginStateHuman;
|
|
20
|
-
get botsByMarket(): AddressMap<PartialLiquidationBotContract[]>;
|
|
21
18
|
botsByMarketConfigurator(mc: Address): PartialLiquidationBotContract[];
|
|
22
19
|
get allBots(): PartialLiquidationBotContract[];
|
|
20
|
+
stateHuman(raw?: boolean): BotsPluginStateHuman;
|
|
23
21
|
get state(): BotsPluginState;
|
|
24
22
|
hydrate(state: BotsPluginState): void;
|
|
25
23
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from "abitype";
|
|
2
2
|
import type { Address } from "viem";
|
|
3
3
|
import type { iPeripheryCompressorAbi } from "../abi/compressors.js";
|
|
4
|
-
import type { BaseContractStateHuman, Unarray } from "../sdk/index.js";
|
|
4
|
+
import type { BaseContractStateHuman, IPluginState, Unarray } from "../sdk/index.js";
|
|
5
5
|
export type BotState = Unarray<AbiParametersToPrimitiveTypes<ExtractAbiFunction<typeof iPeripheryCompressorAbi, "getBots">["outputs"]>>;
|
|
6
6
|
export interface BotParameters {
|
|
7
7
|
treasury: Address;
|
|
@@ -31,7 +31,7 @@ export interface BotsPluginStateHuman {
|
|
|
31
31
|
*/
|
|
32
32
|
bots: Record<string, BotStateHuman[]>;
|
|
33
33
|
}
|
|
34
|
-
export interface BotsPluginState {
|
|
34
|
+
export interface BotsPluginState extends IPluginState {
|
|
35
35
|
/**
|
|
36
36
|
* Mapping market configurator address to bot states
|
|
37
37
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Address } from "viem";
|
|
2
|
-
import type { IGearboxSDKPlugin } from "../sdk/index.js";
|
|
2
|
+
import type { IGearboxSDKPlugin, IPluginState } from "../sdk/index.js";
|
|
3
3
|
import { AddressMap, SDKConstruct } from "../sdk/index.js";
|
|
4
|
-
export interface AccountsCounterPluginState {
|
|
4
|
+
export interface AccountsCounterPluginState extends IPluginState {
|
|
5
5
|
/**
|
|
6
6
|
* Mapping of credit manager addresses to the number of accounts
|
|
7
7
|
*/
|
|
@@ -13,9 +13,7 @@ export declare class AccountsCounterPlugin extends SDKConstruct implements IGear
|
|
|
13
13
|
attach(): Promise<void>;
|
|
14
14
|
syncState(): Promise<void>;
|
|
15
15
|
get accounts(): AddressMap<bigint>;
|
|
16
|
-
get loaded(): boolean;
|
|
17
16
|
forCreditManager(addr: Address): bigint;
|
|
18
|
-
load(force?: boolean): Promise<AccountsCounterPluginState>;
|
|
19
17
|
get state(): AccountsCounterPluginState;
|
|
20
18
|
hydrate(state: AccountsCounterPluginState): void;
|
|
21
19
|
}
|
|
@@ -60,7 +60,6 @@ export interface SyncStateOptions {
|
|
|
60
60
|
}
|
|
61
61
|
export type SDKHooks = {
|
|
62
62
|
syncState: [SyncStateOptions];
|
|
63
|
-
rehydrate: [SyncStateOptions];
|
|
64
63
|
};
|
|
65
64
|
export declare class GearboxSDK<const Plugins extends PluginsMap = {}> {
|
|
66
65
|
#private;
|
|
@@ -84,8 +83,8 @@ export declare class GearboxSDK<const Plugins extends PluginsMap = {}> {
|
|
|
84
83
|
* Token metadata such as symbol and decimals
|
|
85
84
|
*/
|
|
86
85
|
readonly tokensMeta: TokensMeta;
|
|
87
|
-
addHook: <K extends
|
|
88
|
-
removeHook: <K extends
|
|
86
|
+
addHook: <K extends "syncState">(hookName: K, fn: (...args: SDKHooks[K]) => void | Promise<void>) => void;
|
|
87
|
+
removeHook: <K extends "syncState">(hookName: K, fn: (...args: SDKHooks[K]) => void | Promise<void>) => void;
|
|
89
88
|
static attach<const Plugins extends PluginsMap>(options: SDKOptions<Plugins> & Partial<NetworkOptions> & ConnectionOptions & TransportOptions): Promise<GearboxSDK<Plugins>>;
|
|
90
89
|
static hydrate<const Plugins extends PluginsMap>(options: HydrateOptions<Plugins> & ConnectionOptions & TransportOptions, state: GearboxState<Plugins>): GearboxSDK<Plugins>;
|
|
91
90
|
private constructor();
|
|
@@ -97,7 +96,7 @@ export declare class GearboxSDK<const Plugins extends PluginsMap = {}> {
|
|
|
97
96
|
/**
|
|
98
97
|
* Rehydrate existing SDK from new state without re-creating instance
|
|
99
98
|
*/
|
|
100
|
-
rehydrate(state: GearboxState<Plugins>):
|
|
99
|
+
rehydrate(state: GearboxState<Plugins>): void;
|
|
101
100
|
/**
|
|
102
101
|
* Converts contract call into some human-friendly string
|
|
103
102
|
* This method is safe and should not throw
|
|
@@ -23,8 +23,8 @@ export interface GearboxChain extends Chain {
|
|
|
23
23
|
*/
|
|
24
24
|
alchemyDomain?: string;
|
|
25
25
|
}
|
|
26
|
-
export declare const SUPPORTED_NETWORKS: readonly ["Mainnet", "Arbitrum", "Optimism", "Base", "Sonic", "MegaETH", "Monad", "Berachain", "Avalanche", "BNB", "WorldChain"];
|
|
27
|
-
export declare const NetworkType: z.ZodEnum<["Mainnet", "Arbitrum", "Optimism", "Base", "Sonic", "MegaETH", "Monad", "Berachain", "Avalanche", "BNB", "WorldChain"]>;
|
|
26
|
+
export declare const SUPPORTED_NETWORKS: readonly ["Mainnet", "Arbitrum", "Optimism", "Base", "Sonic", "MegaETH", "Monad", "Berachain", "Avalanche", "BNB", "WorldChain", "Etherlink"];
|
|
27
|
+
export declare const NetworkType: z.ZodEnum<["Mainnet", "Arbitrum", "Optimism", "Base", "Sonic", "MegaETH", "Monad", "Berachain", "Avalanche", "BNB", "WorldChain", "Etherlink"]>;
|
|
28
28
|
export type NetworkType = z.infer<typeof NetworkType>;
|
|
29
29
|
export declare const chains: Record<NetworkType, GearboxChain>;
|
|
30
30
|
export declare function getChain(chainIdOrNetworkType: number | bigint | NetworkType): GearboxChain;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Address } from "viem";
|
|
2
2
|
import { SDKConstruct } from "../base/index.js";
|
|
3
3
|
import type { GearboxSDK } from "../GearboxSDK.js";
|
|
4
|
-
import type { IGearboxSDKPlugin } from "./types.js";
|
|
4
|
+
import type { IGearboxSDKPlugin, IPluginState } from "./types.js";
|
|
5
5
|
export interface StalenessEvent {
|
|
6
6
|
oracle: Address;
|
|
7
7
|
priceFeed: Address;
|
|
@@ -9,7 +9,7 @@ export interface StalenessEvent {
|
|
|
9
9
|
stalenessPeriod: number;
|
|
10
10
|
reserve: boolean;
|
|
11
11
|
}
|
|
12
|
-
export interface V300StalenessPeriodPluginState {
|
|
12
|
+
export interface V300StalenessPeriodPluginState extends IPluginState {
|
|
13
13
|
events: StalenessEvent[];
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
@@ -22,7 +22,6 @@ export declare class V300StalenessPeriodPlugin extends SDKConstruct implements I
|
|
|
22
22
|
#private;
|
|
23
23
|
readonly version = 1;
|
|
24
24
|
constructor(sdk: GearboxSDK);
|
|
25
|
-
get loaded(): boolean;
|
|
26
25
|
attach(): Promise<void>;
|
|
27
26
|
syncState(): Promise<void>;
|
|
28
27
|
get state(): V300StalenessPeriodPluginState;
|
|
@@ -1,47 +1,20 @@
|
|
|
1
1
|
import type { BaseState, IBaseContract } from "../base/index.js";
|
|
2
2
|
import type { GearboxSDK } from "../GearboxSDK.js";
|
|
3
|
-
export
|
|
3
|
+
export interface IPluginState {
|
|
4
4
|
version: number;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
loaded: true;
|
|
9
|
-
} & State));
|
|
10
|
-
export type IGearboxSDKPluginConstructor<TState extends Record<keyof TState, unknown>, TPlugin extends IGearboxSDKPlugin<TState>> = new (sdk: GearboxSDK<any>) => TPlugin;
|
|
11
|
-
export interface IGearboxSDKPlugin<TState extends Record<keyof TState, unknown> = {}> {
|
|
5
|
+
}
|
|
6
|
+
export type IGearboxSDKPluginConstructor<TState extends IPluginState | undefined, TPlugin extends IGearboxSDKPlugin<TState>> = new (sdk: GearboxSDK<any>) => TPlugin;
|
|
7
|
+
export interface IGearboxSDKPlugin<TState extends IPluginState | undefined> {
|
|
12
8
|
/**
|
|
13
9
|
* Plugin version, used to check if the plugin state is compatible with the plugin during hydration
|
|
14
10
|
*/
|
|
15
11
|
version: number;
|
|
16
|
-
/**
|
|
17
|
-
* Indicates that plugins state is ready to use
|
|
18
|
-
* It does not matter how this state was obtained, be it via attach, hydrate or on-demand load
|
|
19
|
-
*/
|
|
20
|
-
loaded: boolean;
|
|
21
|
-
/**
|
|
22
|
-
* Plugin state, can be hydarted/dehydrated
|
|
23
|
-
*/
|
|
24
|
-
state: TState;
|
|
25
|
-
/**
|
|
26
|
-
* Loads state on demand
|
|
27
|
-
* If it's already loaded, does nothing and returns the same state, unless force is set to true
|
|
28
|
-
* @param force
|
|
29
|
-
* @returns
|
|
30
|
-
*/
|
|
31
|
-
load?: (force?: boolean) => Promise<TState>;
|
|
32
12
|
/**
|
|
33
13
|
* Called after SDK is attached
|
|
34
|
-
* Plugins are not required to implement this. For example plugin can be stateless, or load state on demand only
|
|
35
14
|
* @param sdk
|
|
36
15
|
* @returns
|
|
37
16
|
*/
|
|
38
17
|
attach?: () => Promise<void>;
|
|
39
|
-
/**
|
|
40
|
-
* Loads plugin state from dehydrated state
|
|
41
|
-
* @param state
|
|
42
|
-
* @returns
|
|
43
|
-
*/
|
|
44
|
-
hydrate?: (state: TState) => void;
|
|
45
18
|
/**
|
|
46
19
|
* Called after SDK state is already synced, meaning that block number and timestamp are accessible from SDK
|
|
47
20
|
*
|
|
@@ -51,7 +24,6 @@ export interface IGearboxSDKPlugin<TState extends Record<keyof TState, unknown>
|
|
|
51
24
|
syncState?: () => Promise<void>;
|
|
52
25
|
/**
|
|
53
26
|
* Can be called by SDK to create some auxiliary contracts, such as zappers and adapters
|
|
54
|
-
* Otherwise they are created as BaseContract instances by sdk
|
|
55
27
|
* @param params
|
|
56
28
|
* @returns
|
|
57
29
|
*/
|
|
@@ -62,11 +34,21 @@ export interface IGearboxSDKPlugin<TState extends Record<keyof TState, unknown>
|
|
|
62
34
|
* @returns
|
|
63
35
|
*/
|
|
64
36
|
stateHuman?: (raw?: boolean) => unknown;
|
|
37
|
+
/**
|
|
38
|
+
* Plugin state, can be hydarted/dehydrated
|
|
39
|
+
*/
|
|
40
|
+
state: TState;
|
|
41
|
+
/**
|
|
42
|
+
* Loads plugin state from dehydrated state
|
|
43
|
+
* @param state
|
|
44
|
+
* @returns
|
|
45
|
+
*/
|
|
46
|
+
hydrate?: (state: TState) => void;
|
|
65
47
|
}
|
|
66
48
|
/**
|
|
67
49
|
* Helper type that extracts the state type from a plugin instance
|
|
68
50
|
*/
|
|
69
|
-
export type PluginState<T> = T extends IGearboxSDKPlugin<infer TState> ?
|
|
51
|
+
export type PluginState<T> = T extends IGearboxSDKPlugin<infer TState> ? TState : never;
|
|
70
52
|
/**
|
|
71
53
|
* Mapping between plugin name and plugin instance
|
|
72
54
|
*/
|