@gearbox-protocol/sdk 14.12.0-next.34 → 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/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/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/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
|
@@ -0,0 +1,63 @@
|
|
|
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 helpers_exports = {};
|
|
20
|
+
__export(helpers_exports, {
|
|
21
|
+
DUST_THRESHOLD: () => DUST_THRESHOLD,
|
|
22
|
+
calcEstimatedProfit: () => calcEstimatedProfit,
|
|
23
|
+
calcRepaymentAmount: () => calcRepaymentAmount,
|
|
24
|
+
pickMainAsset: () => pickMainAsset
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(helpers_exports);
|
|
27
|
+
var import_constants = require("../../constants/index.js");
|
|
28
|
+
var import_utils = require("../../utils/index.js");
|
|
29
|
+
const DUST_THRESHOLD = 10n;
|
|
30
|
+
function calcRepaymentAmount(totalValue, liquidationDiscount) {
|
|
31
|
+
return totalValue * BigInt(liquidationDiscount) / import_constants.PERCENTAGE_FACTOR;
|
|
32
|
+
}
|
|
33
|
+
function calcEstimatedProfit(totalValue, liquidationDiscount) {
|
|
34
|
+
return totalValue * (import_constants.PERCENTAGE_FACTOR - BigInt(liquidationDiscount)) / import_constants.PERCENTAGE_FACTOR;
|
|
35
|
+
}
|
|
36
|
+
function pickMainAsset(ca, convert) {
|
|
37
|
+
let bestValue = 0n;
|
|
38
|
+
let bestToken;
|
|
39
|
+
for (const t of ca.tokens) {
|
|
40
|
+
if ((0, import_utils.hexEq)(t.token, ca.underlying)) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if ((t.mask & ca.enabledTokensMask) === 0n) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (t.balance <= DUST_THRESHOLD) {
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
const value = convert(t.token, t.balance);
|
|
50
|
+
if (value > bestValue) {
|
|
51
|
+
bestValue = value;
|
|
52
|
+
bestToken = t.token;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return bestToken;
|
|
56
|
+
}
|
|
57
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
58
|
+
0 && (module.exports = {
|
|
59
|
+
DUST_THRESHOLD,
|
|
60
|
+
calcEstimatedProfit,
|
|
61
|
+
calcRepaymentAmount,
|
|
62
|
+
pickMainAsset
|
|
63
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var liquidations_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(liquidations_exports);
|
|
18
|
+
__reExport(liquidations_exports, require("./helpers.js"), module.exports);
|
|
19
|
+
__reExport(liquidations_exports, require("./LiquidationsService.js"), module.exports);
|
|
20
|
+
__reExport(liquidations_exports, require("./MultichainLiquidationsService.js"), module.exports);
|
|
21
|
+
__reExport(liquidations_exports, require("./types.js"), module.exports);
|
|
22
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
23
|
+
0 && (module.exports = {
|
|
24
|
+
...require("./helpers.js"),
|
|
25
|
+
...require("./LiquidationsService.js"),
|
|
26
|
+
...require("./MultichainLiquidationsService.js"),
|
|
27
|
+
...require("./types.js")
|
|
28
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -18,11 +18,16 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var AbstractWithdrawalCompressorContract_exports = {};
|
|
20
20
|
__export(AbstractWithdrawalCompressorContract_exports, {
|
|
21
|
-
AbstractWithdrawalCompressorContract: () => AbstractWithdrawalCompressorContract
|
|
21
|
+
AbstractWithdrawalCompressorContract: () => AbstractWithdrawalCompressorContract,
|
|
22
|
+
iCreditAccountAbi: () => iCreditAccountAbi,
|
|
23
|
+
toClaimableWithdrawal: () => toClaimableWithdrawal,
|
|
24
|
+
toPendingWithdrawal: () => toPendingWithdrawal,
|
|
25
|
+
toRequestableWithdrawal: () => toRequestableWithdrawal
|
|
22
26
|
});
|
|
23
27
|
module.exports = __toCommonJS(AbstractWithdrawalCompressorContract_exports);
|
|
24
28
|
var import_viem = require("viem");
|
|
25
29
|
var import_base = require("../../base/index.js");
|
|
30
|
+
var import_utils = require("../../utils/index.js");
|
|
26
31
|
var import_intent_codec = require("./intent-codec.js");
|
|
27
32
|
const iCreditAccountAbi = [
|
|
28
33
|
{
|
|
@@ -33,12 +38,23 @@ const iCreditAccountAbi = [
|
|
|
33
38
|
stateMutability: "view"
|
|
34
39
|
}
|
|
35
40
|
];
|
|
41
|
+
const MAP_LABEL = "withdrawableAssets";
|
|
36
42
|
class AbstractWithdrawalCompressorContract extends import_base.BaseContract {
|
|
37
43
|
#sdk;
|
|
44
|
+
#withdrawableAssets;
|
|
38
45
|
constructor(sdk, args) {
|
|
39
46
|
super(sdk, args);
|
|
40
47
|
this.#sdk = sdk;
|
|
41
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* {@inheritDoc IWithdrawalCompressorContract.hydrate}
|
|
51
|
+
**/
|
|
52
|
+
hydrate(state) {
|
|
53
|
+
this.#withdrawableAssets = new import_utils.AddressMap(
|
|
54
|
+
Object.entries(state.withdrawableAssets),
|
|
55
|
+
MAP_LABEL
|
|
56
|
+
);
|
|
57
|
+
}
|
|
42
58
|
/**
|
|
43
59
|
* The contract is instantiated with the actual versioned ABI,
|
|
44
60
|
* this cast is type-level only (see {@link CommonAbi}).
|
|
@@ -46,18 +62,35 @@ class AbstractWithdrawalCompressorContract extends import_base.BaseContract {
|
|
|
46
62
|
get common() {
|
|
47
63
|
return this.contract;
|
|
48
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* {@inheritDoc IWithdrawalCompressorContract.state}
|
|
67
|
+
**/
|
|
68
|
+
get state() {
|
|
69
|
+
return this.#withdrawableAssets ? { withdrawableAssets: this.#withdrawableAssets.asRecord() } : void 0;
|
|
70
|
+
}
|
|
49
71
|
/**
|
|
50
72
|
* {@inheritDoc IWithdrawalCompressorContract.getWithdrawableAssets}
|
|
51
73
|
**/
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
|
|
74
|
+
getWithdrawableAssets(...creditManagers) {
|
|
75
|
+
const cache = this.#withdrawableAssets;
|
|
76
|
+
if (!cache) {
|
|
77
|
+
throw new Error(
|
|
78
|
+
"withdrawable assets are not loaded, call loadWithdrawableAssets first"
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
if (creditManagers.length === 0) {
|
|
82
|
+
return cache.values().flat();
|
|
83
|
+
}
|
|
84
|
+
return creditManagers.flatMap((cm) => cache.get(cm) ?? []);
|
|
55
85
|
}
|
|
56
86
|
/**
|
|
57
|
-
* {@inheritDoc IWithdrawalCompressorContract.
|
|
87
|
+
* {@inheritDoc IWithdrawalCompressorContract.loadWithdrawableAssets}
|
|
58
88
|
**/
|
|
59
|
-
async
|
|
60
|
-
|
|
89
|
+
async loadWithdrawableAssets(force) {
|
|
90
|
+
if (this.#withdrawableAssets && !force) {
|
|
91
|
+
return this.getWithdrawableAssets();
|
|
92
|
+
}
|
|
93
|
+
const cms = this.#sdk.marketRegister.creditManagers.map(
|
|
61
94
|
(cm) => cm.creditManager.address
|
|
62
95
|
);
|
|
63
96
|
const resp = await this.client.multicall({
|
|
@@ -72,22 +105,48 @@ class AbstractWithdrawalCompressorContract extends import_base.BaseContract {
|
|
|
72
105
|
allowFailure: true,
|
|
73
106
|
batchSize: 0
|
|
74
107
|
});
|
|
75
|
-
|
|
108
|
+
const cache = new import_utils.AddressMap(void 0, MAP_LABEL);
|
|
109
|
+
for (let i = 0; i < resp.length; i++) {
|
|
110
|
+
const r = resp[i];
|
|
76
111
|
if (r.status !== "success") {
|
|
77
112
|
this.logger?.warn(
|
|
78
113
|
`failed to get withdrawable assets of credit manager ${cms[i]}: ${r.error}`
|
|
79
114
|
);
|
|
80
|
-
|
|
115
|
+
continue;
|
|
81
116
|
}
|
|
82
|
-
|
|
83
|
-
|
|
117
|
+
if (r.result.length > 0) {
|
|
118
|
+
cache.upsert(
|
|
119
|
+
cms[i],
|
|
120
|
+
r.result.map((a) => toWithdrawableAsset(a, cms[i]))
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
this.#withdrawableAssets = cache;
|
|
125
|
+
return this.getWithdrawableAssets();
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* {@inheritDoc IWithdrawalCompressorContract.findWithdrawableAssets}
|
|
129
|
+
**/
|
|
130
|
+
async findWithdrawableAssets(creditManager, token) {
|
|
131
|
+
await this.loadWithdrawableAssets();
|
|
132
|
+
return this.getWithdrawableAssets(creditManager).filter(
|
|
133
|
+
(a) => (0, import_viem.isAddressEqual)(a.token, token)
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* {@inheritDoc IWithdrawalCompressorContract.findWithdrawableAssetsByPhantomToken}
|
|
138
|
+
**/
|
|
139
|
+
async findWithdrawableAssetsByPhantomToken(withdrawalPhantomToken) {
|
|
140
|
+
await this.loadWithdrawableAssets();
|
|
141
|
+
return this.getWithdrawableAssets().filter(
|
|
142
|
+
(a) => (0, import_viem.isAddressEqual)(a.withdrawalPhantomToken, withdrawalPhantomToken)
|
|
143
|
+
);
|
|
84
144
|
}
|
|
85
145
|
/**
|
|
86
146
|
* {@inheritDoc IWithdrawalCompressorContract.getWithdrawalPhantomToken}
|
|
87
147
|
**/
|
|
88
148
|
async getWithdrawalPhantomToken(creditManager, token) {
|
|
89
|
-
const
|
|
90
|
-
const asset = assets.find((a) => (0, import_viem.isAddressEqual)(a.token, token));
|
|
149
|
+
const [asset] = await this.findWithdrawableAssets(creditManager, token);
|
|
91
150
|
if (!asset) {
|
|
92
151
|
throw new Error(
|
|
93
152
|
`token ${token} is not withdrawable from credit manager ${creditManager}`
|
|
@@ -95,6 +154,14 @@ class AbstractWithdrawalCompressorContract extends import_base.BaseContract {
|
|
|
95
154
|
}
|
|
96
155
|
return asset.withdrawalPhantomToken;
|
|
97
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* {@inheritDoc IWithdrawalCompressorContract.getWithdrawalSourceToken}
|
|
159
|
+
**/
|
|
160
|
+
getWithdrawalSourceToken(withdrawalPhantomToken) {
|
|
161
|
+
return this.getWithdrawableAssets().find(
|
|
162
|
+
(a) => (0, import_viem.isAddressEqual)(a.withdrawalPhantomToken, withdrawalPhantomToken)
|
|
163
|
+
)?.token;
|
|
164
|
+
}
|
|
98
165
|
/**
|
|
99
166
|
* {@inheritDoc IWithdrawalCompressorContract.getCurrentWithdrawals}
|
|
100
167
|
**/
|
|
@@ -117,83 +184,80 @@ class AbstractWithdrawalCompressorContract extends import_base.BaseContract {
|
|
|
117
184
|
batchSize: 0
|
|
118
185
|
});
|
|
119
186
|
return {
|
|
120
|
-
claimable: claimable.map(
|
|
121
|
-
|
|
122
|
-
),
|
|
123
|
-
pending: pending.map((w) => toPendingWithdrawal(w, creditManager, this.version >= 313)).sort((a, b) => a.claimableAt < b.claimableAt ? -1 : 1)
|
|
187
|
+
claimable: claimable.map((w) => toClaimableWithdrawal(w, creditManager)),
|
|
188
|
+
pending: pending.map((w) => toPendingWithdrawal(w, creditManager)).sort((a, b) => a.claimableAt < b.claimableAt ? -1 : 1)
|
|
124
189
|
};
|
|
125
190
|
}
|
|
191
|
+
/**
|
|
192
|
+
* {@inheritDoc IWithdrawalCompressorContract.getExternalAccountCurrentWithdrawals}
|
|
193
|
+
**/
|
|
194
|
+
async getExternalAccountCurrentWithdrawals(_withdrawalToken, _account) {
|
|
195
|
+
this.#reportUnsupported("external account withdrawals");
|
|
196
|
+
return { claimable: [], pending: [] };
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* {@inheritDoc IWithdrawalCompressorContract.getWithdrawalStatus}
|
|
200
|
+
**/
|
|
201
|
+
async getWithdrawalStatus(...redeemers) {
|
|
202
|
+
if (redeemers.length === 0) {
|
|
203
|
+
return [];
|
|
204
|
+
}
|
|
205
|
+
this.#reportUnsupported("withdrawal status");
|
|
206
|
+
return redeemers.map(() => "NULL");
|
|
207
|
+
}
|
|
126
208
|
/**
|
|
127
209
|
* {@inheritDoc IWithdrawalCompressorContract.getWithdrawalRequestResult}
|
|
210
|
+
*
|
|
211
|
+
* Legacy compressors only support the 3-arg overload: `intent` and
|
|
212
|
+
* `withdrawalPhantomToken` are reported as unsupported (in non-strict mode
|
|
213
|
+
* the request is previewed without them).
|
|
128
214
|
**/
|
|
129
|
-
async getWithdrawalRequestResult(
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
215
|
+
async getWithdrawalRequestResult({
|
|
216
|
+
creditAccount,
|
|
217
|
+
token,
|
|
218
|
+
amount,
|
|
219
|
+
withdrawalPhantomToken,
|
|
220
|
+
intent
|
|
221
|
+
}) {
|
|
222
|
+
if (intent) {
|
|
223
|
+
this.#reportUnsupported("withdrawal intents");
|
|
224
|
+
} else if (withdrawalPhantomToken) {
|
|
225
|
+
this.#reportUnsupported("withdrawal config selection");
|
|
226
|
+
}
|
|
227
|
+
const resp = await this.common.read.getWithdrawalRequestResult([
|
|
136
228
|
creditAccount,
|
|
137
229
|
token,
|
|
138
230
|
amount
|
|
139
231
|
]);
|
|
140
|
-
return
|
|
141
|
-
token: resp.token,
|
|
142
|
-
amountIn: resp.amountIn,
|
|
143
|
-
outputs: [...resp.outputs],
|
|
144
|
-
requestCalls: [...resp.requestCalls],
|
|
145
|
-
claimableAt: resp.claimableAt
|
|
146
|
-
};
|
|
232
|
+
return toRequestableWithdrawal(resp);
|
|
147
233
|
}
|
|
148
234
|
/**
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
* throws if `sdk.strictContractTypes` is `true`, otherwise logs a warning
|
|
152
|
-
* and previews the request without the intent.
|
|
153
|
-
*
|
|
154
|
-
* The contract overload accepting `extraData` also requires the withdrawal
|
|
155
|
-
* phantom token, which is resolved here the same way the 3-arg overload
|
|
156
|
-
* does it internally: via `getWithdrawableAssets` of the account's credit
|
|
157
|
-
* manager.
|
|
235
|
+
* Reports that a feature is not supported by this compressor version:
|
|
236
|
+
* throws if `sdk.strictContractTypes` is `true`, otherwise logs a warning.
|
|
158
237
|
**/
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
throw new Error(message);
|
|
164
|
-
}
|
|
165
|
-
this.logger?.warn(`${message}, requesting withdrawal without intent`);
|
|
166
|
-
return this.common.read.getWithdrawalRequestResult([
|
|
167
|
-
creditAccount,
|
|
168
|
-
token,
|
|
169
|
-
amount
|
|
170
|
-
]);
|
|
238
|
+
#reportUnsupported(feature) {
|
|
239
|
+
const message = `${feature} is not supported by ${this.name} v${this.version}`;
|
|
240
|
+
if (this.#sdk.strictContractTypes) {
|
|
241
|
+
throw new Error(message);
|
|
171
242
|
}
|
|
172
|
-
|
|
173
|
-
const creditManager = await this.client.readContract({
|
|
174
|
-
address: creditAccount,
|
|
175
|
-
abi: iCreditAccountAbi,
|
|
176
|
-
functionName: "creditManager"
|
|
177
|
-
});
|
|
178
|
-
const withdrawalPhantomToken = await this.getWithdrawalPhantomToken(
|
|
179
|
-
creditManager,
|
|
180
|
-
token
|
|
181
|
-
);
|
|
182
|
-
return this.common.read.getWithdrawalRequestResult([
|
|
183
|
-
creditAccount,
|
|
184
|
-
token,
|
|
185
|
-
withdrawalPhantomToken,
|
|
186
|
-
amount,
|
|
187
|
-
extraData
|
|
188
|
-
]);
|
|
243
|
+
this.logger?.warn(message);
|
|
189
244
|
}
|
|
190
245
|
}
|
|
191
246
|
function toWithdrawableAsset(a, creditManager) {
|
|
192
247
|
return { creditManager, ...a };
|
|
193
248
|
}
|
|
194
|
-
function
|
|
249
|
+
function toRequestableWithdrawal(resp) {
|
|
250
|
+
return {
|
|
251
|
+
token: resp.token,
|
|
252
|
+
amountIn: resp.amountIn,
|
|
253
|
+
outputs: [...resp.outputs],
|
|
254
|
+
requestCalls: [...resp.requestCalls],
|
|
255
|
+
claimableAt: resp.claimableAt
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
function toClaimableWithdrawal(w, creditManager) {
|
|
195
259
|
let intent;
|
|
196
|
-
if (
|
|
260
|
+
if (creditManager && w.extraData && w.extraData !== "0x") {
|
|
197
261
|
intent = { ...(0, import_intent_codec.decodeDelayedIntent)(w.extraData), creditManager };
|
|
198
262
|
}
|
|
199
263
|
return {
|
|
@@ -205,9 +269,9 @@ function toClaimableWithdrawal(w, creditManager, decodeIntent) {
|
|
|
205
269
|
intent
|
|
206
270
|
};
|
|
207
271
|
}
|
|
208
|
-
function toPendingWithdrawal(w, creditManager
|
|
272
|
+
function toPendingWithdrawal(w, creditManager) {
|
|
209
273
|
let intent;
|
|
210
|
-
if (
|
|
274
|
+
if (creditManager && w.extraData && w.extraData !== "0x") {
|
|
211
275
|
intent = { ...(0, import_intent_codec.decodeDelayedIntent)(w.extraData), creditManager };
|
|
212
276
|
}
|
|
213
277
|
return {
|
|
@@ -220,5 +284,9 @@ function toPendingWithdrawal(w, creditManager, decodeIntent) {
|
|
|
220
284
|
}
|
|
221
285
|
// Annotate the CommonJS export names for ESM import in node:
|
|
222
286
|
0 && (module.exports = {
|
|
223
|
-
AbstractWithdrawalCompressorContract
|
|
287
|
+
AbstractWithdrawalCompressorContract,
|
|
288
|
+
iCreditAccountAbi,
|
|
289
|
+
toClaimableWithdrawal,
|
|
290
|
+
toPendingWithdrawal,
|
|
291
|
+
toRequestableWithdrawal
|
|
224
292
|
});
|
|
@@ -23,7 +23,22 @@ __export(WithdrawalCompressorV313Contract_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(WithdrawalCompressorV313Contract_exports);
|
|
24
24
|
var import_IWithdrawalCompressorV313 = require("../../../abi/IWithdrawalCompressorV313.js");
|
|
25
25
|
var import_AbstractWithdrawalCompressorContract = require("./AbstractWithdrawalCompressorContract.js");
|
|
26
|
+
var import_intent_codec = require("./intent-codec.js");
|
|
27
|
+
var import_types = require("./types.js");
|
|
26
28
|
const abi = import_IWithdrawalCompressorV313.iWithdrawalCompressorV313Abi;
|
|
29
|
+
const iWithdrawalStatusBatchAbi = [
|
|
30
|
+
{
|
|
31
|
+
type: "function",
|
|
32
|
+
name: "getWithdrawalStatus",
|
|
33
|
+
inputs: [
|
|
34
|
+
{ name: "redeemers", type: "address[]", internalType: "address[]" }
|
|
35
|
+
],
|
|
36
|
+
outputs: [
|
|
37
|
+
{ name: "", type: "uint8[]", internalType: "enum WithdrawalStatus[]" }
|
|
38
|
+
],
|
|
39
|
+
stateMutability: "view"
|
|
40
|
+
}
|
|
41
|
+
];
|
|
27
42
|
class WithdrawalCompressorV313Contract extends import_AbstractWithdrawalCompressorContract.AbstractWithdrawalCompressorContract {
|
|
28
43
|
constructor(sdk, address) {
|
|
29
44
|
super(sdk, {
|
|
@@ -33,6 +48,88 @@ class WithdrawalCompressorV313Contract extends import_AbstractWithdrawalCompress
|
|
|
33
48
|
version: 313
|
|
34
49
|
});
|
|
35
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* {@inheritDoc IWithdrawalCompressorContract.getExternalAccountCurrentWithdrawals}
|
|
53
|
+
**/
|
|
54
|
+
async getExternalAccountCurrentWithdrawals(withdrawalToken, account) {
|
|
55
|
+
const [claimable, pending] = await this.contract.read.getExternalAccountCurrentWithdrawals([
|
|
56
|
+
withdrawalToken,
|
|
57
|
+
account
|
|
58
|
+
]);
|
|
59
|
+
return {
|
|
60
|
+
claimable: claimable.map((w) => (0, import_AbstractWithdrawalCompressorContract.toClaimableWithdrawal)(w, void 0)),
|
|
61
|
+
pending: pending.map((w) => (0, import_AbstractWithdrawalCompressorContract.toPendingWithdrawal)(w, void 0)).sort((a, b) => a.claimableAt < b.claimableAt ? -1 : 1)
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* {@inheritDoc IWithdrawalCompressorContract.getWithdrawalStatus}
|
|
66
|
+
**/
|
|
67
|
+
async getWithdrawalStatus(...redeemers) {
|
|
68
|
+
if (redeemers.length === 0) {
|
|
69
|
+
return [];
|
|
70
|
+
}
|
|
71
|
+
const resp = await this.client.readContract({
|
|
72
|
+
address: this.address,
|
|
73
|
+
abi: iWithdrawalStatusBatchAbi,
|
|
74
|
+
functionName: "getWithdrawalStatus",
|
|
75
|
+
args: [redeemers]
|
|
76
|
+
});
|
|
77
|
+
return resp.map((s) => (0, import_types.toWithdrawalStatus)(s));
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* {@inheritDoc IWithdrawalCompressorContract.getWithdrawalRequestResult}
|
|
81
|
+
*
|
|
82
|
+
* When an intent is provided, it is abi-encoded and attached to the request
|
|
83
|
+
* as `extraData`. The contract overload accepting `extraData` also requires
|
|
84
|
+
* the withdrawal phantom token; when not provided by the caller, it is
|
|
85
|
+
* resolved the same way the 3-arg overload does it internally: via the
|
|
86
|
+
* withdrawable assets of the account's credit manager.
|
|
87
|
+
**/
|
|
88
|
+
async getWithdrawalRequestResult({
|
|
89
|
+
creditAccount,
|
|
90
|
+
token,
|
|
91
|
+
amount,
|
|
92
|
+
withdrawalPhantomToken,
|
|
93
|
+
intent
|
|
94
|
+
}) {
|
|
95
|
+
let resp;
|
|
96
|
+
if (intent) {
|
|
97
|
+
const extraData = (0, import_intent_codec.encodeDelayedIntent)(intent);
|
|
98
|
+
let phantomToken = withdrawalPhantomToken;
|
|
99
|
+
if (!phantomToken) {
|
|
100
|
+
const creditManager = await this.client.readContract({
|
|
101
|
+
address: creditAccount,
|
|
102
|
+
abi: import_AbstractWithdrawalCompressorContract.iCreditAccountAbi,
|
|
103
|
+
functionName: "creditManager"
|
|
104
|
+
});
|
|
105
|
+
phantomToken = await this.getWithdrawalPhantomToken(
|
|
106
|
+
creditManager,
|
|
107
|
+
token
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
resp = await this.contract.read.getWithdrawalRequestResult([
|
|
111
|
+
creditAccount,
|
|
112
|
+
token,
|
|
113
|
+
phantomToken,
|
|
114
|
+
amount,
|
|
115
|
+
extraData
|
|
116
|
+
]);
|
|
117
|
+
} else if (withdrawalPhantomToken) {
|
|
118
|
+
resp = await this.contract.read.getWithdrawalRequestResult([
|
|
119
|
+
creditAccount,
|
|
120
|
+
token,
|
|
121
|
+
withdrawalPhantomToken,
|
|
122
|
+
amount
|
|
123
|
+
]);
|
|
124
|
+
} else {
|
|
125
|
+
resp = await this.contract.read.getWithdrawalRequestResult([
|
|
126
|
+
creditAccount,
|
|
127
|
+
token,
|
|
128
|
+
amount
|
|
129
|
+
]);
|
|
130
|
+
}
|
|
131
|
+
return (0, import_AbstractWithdrawalCompressorContract.toRequestableWithdrawal)(resp);
|
|
132
|
+
}
|
|
36
133
|
}
|
|
37
134
|
// Annotate the CommonJS export names for ESM import in node:
|
|
38
135
|
0 && (module.exports = {
|
|
@@ -28,13 +28,7 @@ var import_WithdrawalCompressorV313Contract = require("./WithdrawalCompressorV31
|
|
|
28
28
|
function createWithdrawalCompressor(sdk) {
|
|
29
29
|
const location = (0, import_addresses.getWithdrawalCompressorAddress)(sdk.networkType);
|
|
30
30
|
if (!location) {
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
const cached = sdk.getContract(
|
|
34
|
-
location.address
|
|
35
|
-
);
|
|
36
|
-
if (cached) {
|
|
37
|
-
return cached;
|
|
31
|
+
return void 0;
|
|
38
32
|
}
|
|
39
33
|
switch (location.version) {
|
|
40
34
|
case 310:
|
|
@@ -3,6 +3,10 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
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
|
+
};
|
|
6
10
|
var __copyProps = (to, from, except, desc) => {
|
|
7
11
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
12
|
for (let key of __getOwnPropNames(from))
|
|
@@ -13,4 +17,20 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
13
17
|
};
|
|
14
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
19
|
var types_exports = {};
|
|
20
|
+
__export(types_exports, {
|
|
21
|
+
toWithdrawalStatus: () => toWithdrawalStatus
|
|
22
|
+
});
|
|
16
23
|
module.exports = __toCommonJS(types_exports);
|
|
24
|
+
const WITHDRAWAL_STATUSES = [
|
|
25
|
+
"NULL",
|
|
26
|
+
"PENDING",
|
|
27
|
+
"CLAIMABLE",
|
|
28
|
+
"CLAIMED"
|
|
29
|
+
];
|
|
30
|
+
function toWithdrawalStatus(status) {
|
|
31
|
+
return WITHDRAWAL_STATUSES[status] ?? "NULL";
|
|
32
|
+
}
|
|
33
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
34
|
+
0 && (module.exports = {
|
|
35
|
+
toWithdrawalStatus
|
|
36
|
+
});
|