@gearbox-protocol/sdk 14.12.0-next.33 → 14.12.0-next.35
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/abi/IWithdrawalCompressorV313.js +136 -0
- package/dist/cjs/plugins/delayed-withdrawal/DelayedWithdrawalPlugin.js +24 -33
- package/dist/cjs/preview/prerequisites/buildCollateralPrerequisites.js +39 -3
- package/dist/cjs/preview/prerequisites/checkPrerequisites.js +2 -1
- package/dist/cjs/preview/preview/buildDelayedPreview.js +6 -5
- package/dist/cjs/preview/preview/previewOperation.js +4 -1
- package/dist/cjs/sdk/MultichainSDK.js +7 -0
- package/dist/cjs/sdk/OnchainSDK.js +14 -4
- package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +16 -3
- package/dist/cjs/sdk/accounts/index.js +2 -0
- package/dist/cjs/sdk/accounts/liquidations/LiquidationsService.js +207 -0
- package/dist/cjs/sdk/accounts/liquidations/MultichainLiquidationsService.js +65 -0
- package/dist/cjs/sdk/accounts/liquidations/helpers.js +63 -0
- package/dist/cjs/sdk/accounts/liquidations/index.js +28 -0
- package/dist/cjs/sdk/accounts/liquidations/types.js +16 -0
- package/dist/cjs/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.js +142 -74
- package/dist/cjs/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +97 -0
- package/dist/cjs/sdk/accounts/withdrawal-compressor/createWithdrawalCompressor.js +1 -7
- package/dist/cjs/sdk/accounts/withdrawal-compressor/types.js +20 -0
- package/dist/esm/abi/IWithdrawalCompressorV313.js +136 -0
- package/dist/esm/plugins/delayed-withdrawal/DelayedWithdrawalPlugin.js +24 -33
- package/dist/esm/preview/prerequisites/buildCollateralPrerequisites.js +43 -4
- package/dist/esm/preview/prerequisites/checkPrerequisites.js +2 -1
- package/dist/esm/preview/preview/buildDelayedPreview.js +6 -5
- package/dist/esm/preview/preview/previewOperation.js +4 -1
- package/dist/esm/sdk/MultichainSDK.js +7 -0
- package/dist/esm/sdk/OnchainSDK.js +16 -5
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +16 -3
- package/dist/esm/sdk/accounts/index.js +1 -0
- package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +188 -0
- package/dist/esm/sdk/accounts/liquidations/MultichainLiquidationsService.js +41 -0
- package/dist/esm/sdk/accounts/liquidations/helpers.js +36 -0
- package/dist/esm/sdk/accounts/liquidations/index.js +4 -0
- package/dist/esm/sdk/accounts/liquidations/types.js +0 -0
- package/dist/esm/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.js +138 -74
- package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +104 -1
- package/dist/esm/sdk/accounts/withdrawal-compressor/createWithdrawalCompressor.js +1 -7
- package/dist/esm/sdk/accounts/withdrawal-compressor/types.js +12 -0
- package/dist/types/abi/IWithdrawalCompressorV313.d.ts +200 -0
- package/dist/types/plugins/delayed-withdrawal/DelayedWithdrawalPlugin.d.ts +7 -7
- package/dist/types/preview/prerequisites/buildCollateralPrerequisites.d.ts +1 -0
- package/dist/types/preview/prerequisites/types.d.ts +10 -2
- package/dist/types/preview/preview/buildDelayedPreview.d.ts +7 -2
- package/dist/types/sdk/MultichainSDK.d.ts +6 -0
- package/dist/types/sdk/OnchainSDK.d.ts +8 -5
- package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +1 -1
- package/dist/types/sdk/accounts/index.d.ts +1 -0
- package/dist/types/sdk/accounts/liquidations/LiquidationsService.d.ts +20 -0
- package/dist/types/sdk/accounts/liquidations/MultichainLiquidationsService.d.ts +23 -0
- package/dist/types/sdk/accounts/liquidations/helpers.d.ts +34 -0
- package/dist/types/sdk/accounts/liquidations/index.d.ts +4 -0
- package/dist/types/sdk/accounts/liquidations/types.d.ts +172 -0
- package/dist/types/sdk/accounts/types.d.ts +6 -0
- package/dist/types/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.d.ts +80 -6
- package/dist/types/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.d.ts +222 -0
- package/dist/types/sdk/accounts/withdrawal-compressor/createWithdrawalCompressor.d.ts +5 -4
- package/dist/types/sdk/accounts/withdrawal-compressor/types.d.ts +106 -7
- package/dist/types/sdk/types/state.d.ts +8 -0
- package/package.json +1 -1
|
@@ -102,6 +102,100 @@ const iWithdrawalCompressorV313Abi = [
|
|
|
102
102
|
],
|
|
103
103
|
stateMutability: "view"
|
|
104
104
|
},
|
|
105
|
+
{
|
|
106
|
+
type: "function",
|
|
107
|
+
name: "getExternalAccountCurrentWithdrawals",
|
|
108
|
+
inputs: [
|
|
109
|
+
{ name: "withdrawalToken", type: "address", internalType: "address" },
|
|
110
|
+
{ name: "account", type: "address", internalType: "address" }
|
|
111
|
+
],
|
|
112
|
+
outputs: [
|
|
113
|
+
{
|
|
114
|
+
name: "",
|
|
115
|
+
type: "tuple[]",
|
|
116
|
+
internalType: "struct ClaimableWithdrawal[]",
|
|
117
|
+
components: [
|
|
118
|
+
{ name: "token", type: "address", internalType: "address" },
|
|
119
|
+
{
|
|
120
|
+
name: "withdrawalPhantomToken",
|
|
121
|
+
type: "address",
|
|
122
|
+
internalType: "address"
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
name: "withdrawalTokenSpent",
|
|
126
|
+
type: "uint256",
|
|
127
|
+
internalType: "uint256"
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
name: "outputs",
|
|
131
|
+
type: "tuple[]",
|
|
132
|
+
internalType: "struct WithdrawalOutput[]",
|
|
133
|
+
components: [
|
|
134
|
+
{ name: "token", type: "address", internalType: "address" },
|
|
135
|
+
{ name: "isDelayed", type: "bool", internalType: "bool" },
|
|
136
|
+
{ name: "amount", type: "uint256", internalType: "uint256" }
|
|
137
|
+
]
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
name: "claimCalls",
|
|
141
|
+
type: "tuple[]",
|
|
142
|
+
internalType: "struct MultiCall[]",
|
|
143
|
+
components: [
|
|
144
|
+
{ name: "target", type: "address", internalType: "address" },
|
|
145
|
+
{ name: "callData", type: "bytes", internalType: "bytes" }
|
|
146
|
+
]
|
|
147
|
+
},
|
|
148
|
+
{ name: "extraData", type: "bytes", internalType: "bytes" }
|
|
149
|
+
]
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
name: "",
|
|
153
|
+
type: "tuple[]",
|
|
154
|
+
internalType: "struct PendingWithdrawal[]",
|
|
155
|
+
components: [
|
|
156
|
+
{ name: "token", type: "address", internalType: "address" },
|
|
157
|
+
{
|
|
158
|
+
name: "withdrawalPhantomToken",
|
|
159
|
+
type: "address",
|
|
160
|
+
internalType: "address"
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
name: "expectedOutputs",
|
|
164
|
+
type: "tuple[]",
|
|
165
|
+
internalType: "struct WithdrawalOutput[]",
|
|
166
|
+
components: [
|
|
167
|
+
{ name: "token", type: "address", internalType: "address" },
|
|
168
|
+
{ name: "isDelayed", type: "bool", internalType: "bool" },
|
|
169
|
+
{ name: "amount", type: "uint256", internalType: "uint256" }
|
|
170
|
+
]
|
|
171
|
+
},
|
|
172
|
+
{ name: "claimableAt", type: "uint256", internalType: "uint256" },
|
|
173
|
+
{ name: "extraData", type: "bytes", internalType: "bytes" }
|
|
174
|
+
]
|
|
175
|
+
}
|
|
176
|
+
],
|
|
177
|
+
stateMutability: "view"
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
type: "function",
|
|
181
|
+
name: "getWithdrawalStatus",
|
|
182
|
+
inputs: [{ name: "redeemer", type: "address", internalType: "address" }],
|
|
183
|
+
outputs: [
|
|
184
|
+
{ name: "", type: "uint8", internalType: "enum WithdrawalStatus" }
|
|
185
|
+
],
|
|
186
|
+
stateMutability: "view"
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
type: "function",
|
|
190
|
+
name: "getWithdrawalStatus",
|
|
191
|
+
inputs: [
|
|
192
|
+
{ name: "redeemers", type: "address[]", internalType: "address[]" }
|
|
193
|
+
],
|
|
194
|
+
outputs: [
|
|
195
|
+
{ name: "", type: "uint8[]", internalType: "enum WithdrawalStatus[]" }
|
|
196
|
+
],
|
|
197
|
+
stateMutability: "view"
|
|
198
|
+
},
|
|
105
199
|
{
|
|
106
200
|
type: "function",
|
|
107
201
|
name: "getWithdrawableAssets",
|
|
@@ -175,6 +269,48 @@ const iWithdrawalCompressorV313Abi = [
|
|
|
175
269
|
],
|
|
176
270
|
stateMutability: "view"
|
|
177
271
|
},
|
|
272
|
+
{
|
|
273
|
+
type: "function",
|
|
274
|
+
name: "getWithdrawalRequestResult",
|
|
275
|
+
inputs: [
|
|
276
|
+
{ name: "creditAccount", type: "address", internalType: "address" },
|
|
277
|
+
{ name: "token", type: "address", internalType: "address" },
|
|
278
|
+
{ name: "withdrawalToken", type: "address", internalType: "address" },
|
|
279
|
+
{ name: "amount", type: "uint256", internalType: "uint256" }
|
|
280
|
+
],
|
|
281
|
+
outputs: [
|
|
282
|
+
{
|
|
283
|
+
name: "",
|
|
284
|
+
type: "tuple",
|
|
285
|
+
internalType: "struct RequestableWithdrawal",
|
|
286
|
+
components: [
|
|
287
|
+
{ name: "token", type: "address", internalType: "address" },
|
|
288
|
+
{ name: "amountIn", type: "uint256", internalType: "uint256" },
|
|
289
|
+
{
|
|
290
|
+
name: "outputs",
|
|
291
|
+
type: "tuple[]",
|
|
292
|
+
internalType: "struct WithdrawalOutput[]",
|
|
293
|
+
components: [
|
|
294
|
+
{ name: "token", type: "address", internalType: "address" },
|
|
295
|
+
{ name: "isDelayed", type: "bool", internalType: "bool" },
|
|
296
|
+
{ name: "amount", type: "uint256", internalType: "uint256" }
|
|
297
|
+
]
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
name: "requestCalls",
|
|
301
|
+
type: "tuple[]",
|
|
302
|
+
internalType: "struct MultiCall[]",
|
|
303
|
+
components: [
|
|
304
|
+
{ name: "target", type: "address", internalType: "address" },
|
|
305
|
+
{ name: "callData", type: "bytes", internalType: "bytes" }
|
|
306
|
+
]
|
|
307
|
+
},
|
|
308
|
+
{ name: "claimableAt", type: "uint256", internalType: "uint256" }
|
|
309
|
+
]
|
|
310
|
+
}
|
|
311
|
+
],
|
|
312
|
+
stateMutability: "view"
|
|
313
|
+
},
|
|
178
314
|
{
|
|
179
315
|
type: "function",
|
|
180
316
|
name: "getWithdrawalRequestResult",
|
|
@@ -24,16 +24,31 @@ module.exports = __toCommonJS(DelayedWithdrawalPlugin_exports);
|
|
|
24
24
|
var import_sdk = require("../../sdk/index.js");
|
|
25
25
|
const MAP_LABEL = "delayedWithdrawal";
|
|
26
26
|
class DelayedWithdrawalPlugin extends import_sdk.BasePlugin {
|
|
27
|
-
#withdrawableAssets;
|
|
28
27
|
async load(force) {
|
|
29
28
|
if (!force && this.loaded) {
|
|
30
29
|
return this.state;
|
|
31
30
|
}
|
|
32
|
-
this
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
await this.sdk.withdrawalCompressor?.loadWithdrawableAssets(force);
|
|
32
|
+
return this.state;
|
|
33
|
+
}
|
|
34
|
+
get loaded() {
|
|
35
|
+
return !!this.sdk.withdrawalCompressor?.state;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Returns a map of cmAddress -> array of delayed assets
|
|
39
|
+
* @throws if withdrawable assets have not been loaded
|
|
40
|
+
*/
|
|
41
|
+
get withdrawableAssets() {
|
|
42
|
+
const compressor = this.sdk.withdrawalCompressor;
|
|
43
|
+
if (!compressor?.state) {
|
|
44
|
+
throw new Error("withdrawable assets are not loaded");
|
|
45
|
+
}
|
|
46
|
+
const result = new import_sdk.AddressMap(
|
|
47
|
+
void 0,
|
|
48
|
+
MAP_LABEL
|
|
49
|
+
);
|
|
50
|
+
for (const cfg of compressor.getWithdrawableAssets()) {
|
|
51
|
+
const assets = result.get(cfg.creditManager) ?? [];
|
|
37
52
|
assets.push({
|
|
38
53
|
...cfg,
|
|
39
54
|
disabled: isConfigToOmit({
|
|
@@ -43,25 +58,9 @@ class DelayedWithdrawalPlugin extends import_sdk.BasePlugin {
|
|
|
43
58
|
underlying: cfg.underlying
|
|
44
59
|
})
|
|
45
60
|
});
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
for (const [creditManager, assets] of byCreditManager) {
|
|
49
|
-
this.#withdrawableAssets.upsert(creditManager, assets);
|
|
61
|
+
result.upsert(cfg.creditManager, assets);
|
|
50
62
|
}
|
|
51
|
-
return
|
|
52
|
-
}
|
|
53
|
-
get loaded() {
|
|
54
|
-
return !!this.#withdrawableAssets;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Returns a map of cmAddress -> array of delayed assets
|
|
58
|
-
* @throws if plugin is not attached
|
|
59
|
-
*/
|
|
60
|
-
get withdrawableAssets() {
|
|
61
|
-
if (!this.#withdrawableAssets) {
|
|
62
|
-
throw new Error("withdrawable assets plugin not attached");
|
|
63
|
-
}
|
|
64
|
-
return this.#withdrawableAssets;
|
|
63
|
+
return result;
|
|
65
64
|
}
|
|
66
65
|
stateHuman(_) {
|
|
67
66
|
return this.withdrawableAssets.values().flatMap((cm) => {
|
|
@@ -76,15 +75,7 @@ class DelayedWithdrawalPlugin extends import_sdk.BasePlugin {
|
|
|
76
75
|
});
|
|
77
76
|
}
|
|
78
77
|
get state() {
|
|
79
|
-
return {
|
|
80
|
-
withdrawableAssets: this.withdrawableAssets.asRecord()
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
hydrate(state) {
|
|
84
|
-
this.#withdrawableAssets = new import_sdk.AddressMap(
|
|
85
|
-
Object.entries(state.withdrawableAssets),
|
|
86
|
-
MAP_LABEL
|
|
87
|
-
);
|
|
78
|
+
return {};
|
|
88
79
|
}
|
|
89
80
|
}
|
|
90
81
|
function getConfigKey(config) {
|
|
@@ -21,10 +21,13 @@ __export(buildCollateralPrerequisites_exports, {
|
|
|
21
21
|
buildCollateralPrerequisites: () => buildCollateralPrerequisites
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(buildCollateralPrerequisites_exports);
|
|
24
|
+
var import_viem = require("viem");
|
|
24
25
|
var import_sdk = require("../../sdk/index.js");
|
|
26
|
+
var import_AllowancePrerequisite = require("./AllowancePrerequisite.js");
|
|
27
|
+
var import_BalancePrerequisite = require("./BalancePrerequisite.js");
|
|
25
28
|
var import_helpers = require("./helpers.js");
|
|
26
29
|
async function buildCollateralPrerequisites(spenderOptions, multicall, ctx) {
|
|
27
|
-
const { sdk, wallet } = ctx;
|
|
30
|
+
const { sdk, wallet, value = 0n } = ctx;
|
|
28
31
|
const required = new import_sdk.AssetsMap();
|
|
29
32
|
for (const op of multicall) {
|
|
30
33
|
if (op.operation !== "AddCollateral" || op.amount === 0n) {
|
|
@@ -32,12 +35,45 @@ async function buildCollateralPrerequisites(spenderOptions, multicall, ctx) {
|
|
|
32
35
|
}
|
|
33
36
|
required.inc(op.token, op.amount);
|
|
34
37
|
}
|
|
35
|
-
if (required.size === 0) {
|
|
38
|
+
if (required.size === 0 && value === 0n) {
|
|
36
39
|
return [];
|
|
37
40
|
}
|
|
38
|
-
const spender = await sdk.accounts.getApprovalAddress(spenderOptions);
|
|
39
41
|
const prereqs = [];
|
|
42
|
+
if (value > 0n) {
|
|
43
|
+
prereqs.push(
|
|
44
|
+
new import_BalancePrerequisite.BalancePrerequisite({
|
|
45
|
+
token: import_sdk.NATIVE_ADDRESS,
|
|
46
|
+
owner: wallet,
|
|
47
|
+
required: value
|
|
48
|
+
})
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
if (required.size === 0) {
|
|
52
|
+
return prereqs;
|
|
53
|
+
}
|
|
54
|
+
const spender = await sdk.accounts.getApprovalAddress(spenderOptions);
|
|
55
|
+
const weth = sdk.addressProvider.getAddress(import_sdk.AP_WETH_TOKEN, import_sdk.NO_VERSION);
|
|
40
56
|
for (const [token, amount] of required.entries()) {
|
|
57
|
+
if (value > 0n && (0, import_viem.isAddressEqual)(token, weth)) {
|
|
58
|
+
prereqs.push(
|
|
59
|
+
new import_AllowancePrerequisite.AllowancePrerequisite({
|
|
60
|
+
token,
|
|
61
|
+
owner: wallet,
|
|
62
|
+
spender,
|
|
63
|
+
required: amount
|
|
64
|
+
})
|
|
65
|
+
);
|
|
66
|
+
if (amount > value) {
|
|
67
|
+
prereqs.push(
|
|
68
|
+
new import_BalancePrerequisite.BalancePrerequisite({
|
|
69
|
+
token,
|
|
70
|
+
owner: wallet,
|
|
71
|
+
required: amount - value
|
|
72
|
+
})
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
41
77
|
prereqs.push(
|
|
42
78
|
...(0, import_helpers.allowanceAndBalance)({
|
|
43
79
|
token,
|
|
@@ -32,7 +32,8 @@ async function checkPrerequisites(input, options) {
|
|
|
32
32
|
const ctx = {
|
|
33
33
|
sdk,
|
|
34
34
|
wallet,
|
|
35
|
-
blockNumber: options?.blockNumber
|
|
35
|
+
blockNumber: options?.blockNumber,
|
|
36
|
+
value: input.value ?? 0n
|
|
36
37
|
};
|
|
37
38
|
const prereqs = await buildPrerequisites(tx, ctx);
|
|
38
39
|
return Promise.all(prereqs.map((p) => p.verify(ctx)));
|
|
@@ -25,7 +25,7 @@ var import_viem = require("viem");
|
|
|
25
25
|
var import_common_utils = require("../../common-utils/index.js");
|
|
26
26
|
var import_sdk = require("../../sdk/index.js");
|
|
27
27
|
var import_types = require("./types.js");
|
|
28
|
-
function buildDelayedPreview(afterInstant, before, detected, convert) {
|
|
28
|
+
function buildDelayedPreview(afterInstant, before, detected, convert, receivedToken) {
|
|
29
29
|
const { request, intent } = detected;
|
|
30
30
|
const post = afterInstant.clone();
|
|
31
31
|
const converter = makeSafeConverter(convert);
|
|
@@ -33,7 +33,7 @@ function buildDelayedPreview(afterInstant, before, detected, convert) {
|
|
|
33
33
|
const collateralWithdrawn = new import_sdk.AssetsMap();
|
|
34
34
|
switch (intent?.type) {
|
|
35
35
|
case "CLOSE_ACCOUNT":
|
|
36
|
-
return buildClosePreview(post, converter);
|
|
36
|
+
return buildClosePreview(post, converter, receivedToken);
|
|
37
37
|
case "DECREASE_LEVERAGE":
|
|
38
38
|
repayFromClaim(post, request.claimToken, converter.convert, claimed);
|
|
39
39
|
break;
|
|
@@ -104,16 +104,17 @@ function totalValueInUnderlying(post, convert, dust) {
|
|
|
104
104
|
(token, balance) => balance > dust ? convert(token, post.underlying, balance) : 0n
|
|
105
105
|
);
|
|
106
106
|
}
|
|
107
|
-
function buildClosePreview(post, converter) {
|
|
107
|
+
function buildClosePreview(post, converter, receivedToken) {
|
|
108
108
|
const totalValue = totalValueInUnderlying(post, converter.convert, 0n);
|
|
109
109
|
return {
|
|
110
110
|
operation: "CloseCreditAccount",
|
|
111
111
|
permanent: false,
|
|
112
112
|
creditManager: post.creditManager,
|
|
113
113
|
creditAccount: post.creditAccount,
|
|
114
|
-
// Oracle estimate
|
|
114
|
+
// Oracle estimate computed in the underlying; RWA underlyings convert
|
|
115
|
+
// 1:1 with their vault asset, so the amount holds for `receivedToken`
|
|
115
116
|
receivedAmount: {
|
|
116
|
-
token:
|
|
117
|
+
token: receivedToken,
|
|
117
118
|
balance: import_common_utils.BigIntMath.max(totalValue - post.totalDebt, 0n)
|
|
118
119
|
},
|
|
119
120
|
error: converter.error
|
|
@@ -74,6 +74,8 @@ async function previewMulticallOperation(input, operation, options) {
|
|
|
74
74
|
operation.creditManager
|
|
75
75
|
);
|
|
76
76
|
const convert = (token, to, amount) => market.priceOracle.convert(token, to, amount);
|
|
77
|
+
const meta = sdk.tokensMeta.get(market.underlying);
|
|
78
|
+
const receivedToken = meta && sdk.tokensMeta.isRWAUnderlying(meta) ? meta.asset : market.underlying;
|
|
77
79
|
return {
|
|
78
80
|
operation: "DelayedCreditAccountOperation",
|
|
79
81
|
creditAccount: operation.creditAccount,
|
|
@@ -84,7 +86,8 @@ async function previewMulticallOperation(input, operation, options) {
|
|
|
84
86
|
after.account,
|
|
85
87
|
before,
|
|
86
88
|
delayed,
|
|
87
|
-
convert
|
|
89
|
+
convert,
|
|
90
|
+
receivedToken
|
|
88
91
|
)
|
|
89
92
|
};
|
|
90
93
|
}
|
|
@@ -21,6 +21,7 @@ __export(MultichainSDK_exports, {
|
|
|
21
21
|
MultichainSDK: () => MultichainSDK
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(MultichainSDK_exports);
|
|
24
|
+
var import_accounts = require("./accounts/index.js");
|
|
24
25
|
var import_chains = require("./chain/chains.js");
|
|
25
26
|
var import_core = require("./core/index.js");
|
|
26
27
|
var import_updates = require("./market/pricefeeds/updates/index.js");
|
|
@@ -30,6 +31,11 @@ class MultichainSDK {
|
|
|
30
31
|
#redstoneCache;
|
|
31
32
|
#pythCache;
|
|
32
33
|
#logger;
|
|
34
|
+
/**
|
|
35
|
+
* Namespace for liquidatable credit accounts discovery across all
|
|
36
|
+
* configured chains.
|
|
37
|
+
*/
|
|
38
|
+
liquidations;
|
|
33
39
|
constructor(options) {
|
|
34
40
|
this.#chains = /* @__PURE__ */ new Map();
|
|
35
41
|
this.#logger = options.logger;
|
|
@@ -57,6 +63,7 @@ class MultichainSDK {
|
|
|
57
63
|
);
|
|
58
64
|
this.#chains.set(network, sdk);
|
|
59
65
|
}
|
|
66
|
+
this.liquidations = new import_accounts.MultichainLiquidationsService(this);
|
|
60
67
|
}
|
|
61
68
|
/**
|
|
62
69
|
* Attach all configured chains in parallel.
|
|
@@ -67,6 +67,7 @@ class OnchainSDK extends import_base.ChainContractsRegister {
|
|
|
67
67
|
#rwa;
|
|
68
68
|
#marketRegister;
|
|
69
69
|
#priceFeeds;
|
|
70
|
+
#withdrawalCompressor;
|
|
70
71
|
/**
|
|
71
72
|
* Gas limit applied to read-only `eth_call` requests.
|
|
72
73
|
**/
|
|
@@ -83,6 +84,10 @@ class OnchainSDK extends import_base.ChainContractsRegister {
|
|
|
83
84
|
* Namespace for pool operations.
|
|
84
85
|
*/
|
|
85
86
|
pools;
|
|
87
|
+
/**
|
|
88
|
+
* Namespace for liquidatable credit accounts discovery.
|
|
89
|
+
*/
|
|
90
|
+
liquidations;
|
|
86
91
|
/**
|
|
87
92
|
* @param network - Gearbox network type (e.g. `"Mainnet"`, `"Monad"`).
|
|
88
93
|
* @param clientOptions - Connection options (RPC URLs, transport, or client).
|
|
@@ -109,6 +114,8 @@ class OnchainSDK extends import_base.ChainContractsRegister {
|
|
|
109
114
|
}
|
|
110
115
|
this.accounts = new import_accounts.CreditAccountsServiceV310(this);
|
|
111
116
|
this.pools = new import_pools.PoolService(this);
|
|
117
|
+
this.liquidations = new import_accounts.LiquidationsService(this);
|
|
118
|
+
this.#withdrawalCompressor = (0, import_accounts.createWithdrawalCompressor)(this);
|
|
112
119
|
}
|
|
113
120
|
/**
|
|
114
121
|
* Initialises the SDK by reading live on-chain state.
|
|
@@ -255,6 +262,9 @@ class OnchainSDK extends import_base.ChainContractsRegister {
|
|
|
255
262
|
this.#marketRegister.hydrate(state);
|
|
256
263
|
this.#rwa = new import_market.RWARegistry(this);
|
|
257
264
|
this.#rwa.setState(state.rwa);
|
|
265
|
+
if (state.withdrawals) {
|
|
266
|
+
this.#withdrawalCompressor?.hydrate(state.withdrawals);
|
|
267
|
+
}
|
|
258
268
|
for (const [name, plugin] of import_utils.TypedObjectUtils.entries(this.plugins)) {
|
|
259
269
|
const pluginState = state.plugins[name];
|
|
260
270
|
if (plugin.hydrate && pluginState) {
|
|
@@ -319,6 +329,7 @@ class OnchainSDK extends import_base.ChainContractsRegister {
|
|
|
319
329
|
addressProvider: this.addressProvider.state,
|
|
320
330
|
...this.marketRegister.state,
|
|
321
331
|
rwa: this.#rwa.state,
|
|
332
|
+
withdrawals: this.#withdrawalCompressor?.state,
|
|
322
333
|
plugins: Object.fromEntries(
|
|
323
334
|
import_utils.TypedObjectUtils.entries(this.plugins).map(([name, plugin]) => [
|
|
324
335
|
name,
|
|
@@ -536,12 +547,11 @@ class OnchainSDK extends import_base.ChainContractsRegister {
|
|
|
536
547
|
return (0, import_router.createRouter)(this, routerAddr, routerV);
|
|
537
548
|
}
|
|
538
549
|
/**
|
|
539
|
-
*
|
|
540
|
-
*
|
|
541
|
-
* @throws If no withdrawal compressor is supported on the current chain.
|
|
550
|
+
* Withdrawal compressor contract for the current chain, or `undefined`
|
|
551
|
+
* when no withdrawal compressor is supported on it.
|
|
542
552
|
**/
|
|
543
553
|
get withdrawalCompressor() {
|
|
544
|
-
return
|
|
554
|
+
return this.#withdrawalCompressor;
|
|
545
555
|
}
|
|
546
556
|
}
|
|
547
557
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -771,14 +771,16 @@ class CreditAccountsServiceV310 extends import_base.SDKConstruct {
|
|
|
771
771
|
creditAccount,
|
|
772
772
|
amount,
|
|
773
773
|
token,
|
|
774
|
+
withdrawalPhantomToken,
|
|
774
775
|
intent
|
|
775
776
|
}) {
|
|
776
|
-
return this
|
|
777
|
+
return this.#withdrawalCompressor.getWithdrawalRequestResult({
|
|
777
778
|
creditAccount,
|
|
778
779
|
token,
|
|
779
780
|
amount,
|
|
781
|
+
withdrawalPhantomToken,
|
|
780
782
|
intent
|
|
781
|
-
);
|
|
783
|
+
});
|
|
782
784
|
}
|
|
783
785
|
/**
|
|
784
786
|
* {@inheritDoc ICreditAccountsService.getPendingWithdrawals}
|
|
@@ -786,7 +788,7 @@ class CreditAccountsServiceV310 extends import_base.SDKConstruct {
|
|
|
786
788
|
async getPendingWithdrawals({
|
|
787
789
|
creditAccount
|
|
788
790
|
}) {
|
|
789
|
-
const { claimable, pending } = await this
|
|
791
|
+
const { claimable, pending } = await this.#withdrawalCompressor.getCurrentWithdrawals(creditAccount);
|
|
790
792
|
return {
|
|
791
793
|
claimableNow: claimable,
|
|
792
794
|
pending
|
|
@@ -1853,6 +1855,17 @@ class CreditAccountsServiceV310 extends import_base.SDKConstruct {
|
|
|
1853
1855
|
}
|
|
1854
1856
|
return suite.creditFacade.multicall(creditAccount, calls);
|
|
1855
1857
|
}
|
|
1858
|
+
/**
|
|
1859
|
+
* Withdrawal compressor of the current chain.
|
|
1860
|
+
* @throws If no withdrawal compressor is supported on the current chain.
|
|
1861
|
+
**/
|
|
1862
|
+
get #withdrawalCompressor() {
|
|
1863
|
+
const compressor = this.sdk.withdrawalCompressor;
|
|
1864
|
+
if (!compressor) {
|
|
1865
|
+
throw new Error(`no withdrawal compressor on ${this.sdk.networkType}`);
|
|
1866
|
+
}
|
|
1867
|
+
return compressor;
|
|
1868
|
+
}
|
|
1856
1869
|
}
|
|
1857
1870
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1858
1871
|
0 && (module.exports = {
|
|
@@ -16,11 +16,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
16
16
|
var accounts_exports = {};
|
|
17
17
|
module.exports = __toCommonJS(accounts_exports);
|
|
18
18
|
__reExport(accounts_exports, require("./CreditAccountsServiceV310.js"), module.exports);
|
|
19
|
+
__reExport(accounts_exports, require("./liquidations/index.js"), module.exports);
|
|
19
20
|
__reExport(accounts_exports, require("./types.js"), module.exports);
|
|
20
21
|
__reExport(accounts_exports, require("./withdrawal-compressor/index.js"), module.exports);
|
|
21
22
|
// Annotate the CommonJS export names for ESM import in node:
|
|
22
23
|
0 && (module.exports = {
|
|
23
24
|
...require("./CreditAccountsServiceV310.js"),
|
|
25
|
+
...require("./liquidations/index.js"),
|
|
24
26
|
...require("./types.js"),
|
|
25
27
|
...require("./withdrawal-compressor/index.js")
|
|
26
28
|
});
|