@gearbox-protocol/sdk 10.2.10 → 10.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/abi/IWithdrawalCompressorV310.js +184 -0
- package/dist/cjs/permissionless/bindings/instance-manager.js +11 -0
- package/dist/cjs/plugins/delayed-withdrawal/DelayedWithdrawalPlugin.js +105 -0
- package/dist/cjs/plugins/delayed-withdrawal/index.js +24 -0
- package/dist/cjs/plugins/delayed-withdrawal/package.json +1 -0
- package/dist/cjs/plugins/delayed-withdrawal/types.js +16 -0
- package/dist/cjs/sdk/accountMigration/AbstractMigrateCreditAccountsService.js +4 -6
- package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +102 -84
- package/dist/esm/abi/IWithdrawalCompressorV310.js +160 -0
- package/dist/esm/permissionless/bindings/instance-manager.js +11 -0
- package/dist/esm/plugins/delayed-withdrawal/DelayedWithdrawalPlugin.js +85 -0
- package/dist/esm/plugins/delayed-withdrawal/index.js +2 -0
- package/dist/esm/plugins/delayed-withdrawal/package.json +1 -0
- package/dist/esm/plugins/delayed-withdrawal/types.js +0 -0
- package/dist/esm/sdk/accountMigration/AbstractMigrateCreditAccountsService.js +4 -6
- package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +99 -82
- package/dist/types/abi/IWithdrawalCompressorV310.d.ts +208 -0
- package/dist/types/plugins/delayed-withdrawal/DelayedWithdrawalPlugin.d.ts +20 -0
- package/dist/types/plugins/delayed-withdrawal/index.d.ts +2 -0
- package/dist/types/plugins/delayed-withdrawal/types.d.ts +10 -0
- package/dist/types/sdk/accountMigration/AbstractMigrateCreditAccountsService.d.ts +1 -1
- package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +16 -3
- package/dist/types/sdk/accounts/types.d.ts +42 -20
- package/package.json +1 -1
|
@@ -0,0 +1,184 @@
|
|
|
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 IWithdrawalCompressorV310_exports = {};
|
|
20
|
+
__export(IWithdrawalCompressorV310_exports, {
|
|
21
|
+
iWithdrawalCompressorV310Abi: () => iWithdrawalCompressorV310Abi
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(IWithdrawalCompressorV310_exports);
|
|
24
|
+
const iWithdrawalCompressorV310Abi = [
|
|
25
|
+
{
|
|
26
|
+
type: "function",
|
|
27
|
+
inputs: [],
|
|
28
|
+
name: "contractType",
|
|
29
|
+
outputs: [{ name: "", internalType: "bytes32", type: "bytes32" }],
|
|
30
|
+
stateMutability: "view"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
type: "function",
|
|
34
|
+
inputs: [
|
|
35
|
+
{ name: "creditAccount", internalType: "address", type: "address" }
|
|
36
|
+
],
|
|
37
|
+
name: "getCurrentWithdrawals",
|
|
38
|
+
outputs: [
|
|
39
|
+
{
|
|
40
|
+
name: "",
|
|
41
|
+
internalType: "struct ClaimableWithdrawal[]",
|
|
42
|
+
type: "tuple[]",
|
|
43
|
+
components: [
|
|
44
|
+
{ name: "token", internalType: "address", type: "address" },
|
|
45
|
+
{
|
|
46
|
+
name: "withdrawalPhantomToken",
|
|
47
|
+
internalType: "address",
|
|
48
|
+
type: "address"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: "withdrawalTokenSpent",
|
|
52
|
+
internalType: "uint256",
|
|
53
|
+
type: "uint256"
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: "outputs",
|
|
57
|
+
internalType: "struct WithdrawalOutput[]",
|
|
58
|
+
type: "tuple[]",
|
|
59
|
+
components: [
|
|
60
|
+
{ name: "token", internalType: "address", type: "address" },
|
|
61
|
+
{ name: "isDelayed", internalType: "bool", type: "bool" },
|
|
62
|
+
{ name: "amount", internalType: "uint256", type: "uint256" }
|
|
63
|
+
]
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: "claimCalls",
|
|
67
|
+
internalType: "struct MultiCall[]",
|
|
68
|
+
type: "tuple[]",
|
|
69
|
+
components: [
|
|
70
|
+
{ name: "target", internalType: "address", type: "address" },
|
|
71
|
+
{ name: "callData", internalType: "bytes", type: "bytes" }
|
|
72
|
+
]
|
|
73
|
+
}
|
|
74
|
+
]
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: "",
|
|
78
|
+
internalType: "struct PendingWithdrawal[]",
|
|
79
|
+
type: "tuple[]",
|
|
80
|
+
components: [
|
|
81
|
+
{ name: "token", internalType: "address", type: "address" },
|
|
82
|
+
{
|
|
83
|
+
name: "withdrawalPhantomToken",
|
|
84
|
+
internalType: "address",
|
|
85
|
+
type: "address"
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
name: "expectedOutputs",
|
|
89
|
+
internalType: "struct WithdrawalOutput[]",
|
|
90
|
+
type: "tuple[]",
|
|
91
|
+
components: [
|
|
92
|
+
{ name: "token", internalType: "address", type: "address" },
|
|
93
|
+
{ name: "isDelayed", internalType: "bool", type: "bool" },
|
|
94
|
+
{ name: "amount", internalType: "uint256", type: "uint256" }
|
|
95
|
+
]
|
|
96
|
+
},
|
|
97
|
+
{ name: "claimableAt", internalType: "uint256", type: "uint256" }
|
|
98
|
+
]
|
|
99
|
+
}
|
|
100
|
+
],
|
|
101
|
+
stateMutability: "view"
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
type: "function",
|
|
105
|
+
inputs: [
|
|
106
|
+
{ name: "creditManager", internalType: "address", type: "address" }
|
|
107
|
+
],
|
|
108
|
+
name: "getWithdrawableAssets",
|
|
109
|
+
outputs: [
|
|
110
|
+
{
|
|
111
|
+
name: "",
|
|
112
|
+
internalType: "struct WithdrawableAsset[]",
|
|
113
|
+
type: "tuple[]",
|
|
114
|
+
components: [
|
|
115
|
+
{ name: "token", internalType: "address", type: "address" },
|
|
116
|
+
{
|
|
117
|
+
name: "withdrawalPhantomToken",
|
|
118
|
+
internalType: "address",
|
|
119
|
+
type: "address"
|
|
120
|
+
},
|
|
121
|
+
{ name: "underlying", internalType: "address", type: "address" },
|
|
122
|
+
{
|
|
123
|
+
name: "withdrawalLength",
|
|
124
|
+
internalType: "uint256",
|
|
125
|
+
type: "uint256"
|
|
126
|
+
}
|
|
127
|
+
]
|
|
128
|
+
}
|
|
129
|
+
],
|
|
130
|
+
stateMutability: "view"
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
type: "function",
|
|
134
|
+
inputs: [
|
|
135
|
+
{ name: "creditAccount", internalType: "address", type: "address" },
|
|
136
|
+
{ name: "token", internalType: "address", type: "address" },
|
|
137
|
+
{ name: "amount", internalType: "uint256", type: "uint256" }
|
|
138
|
+
],
|
|
139
|
+
name: "getWithdrawalRequestResult",
|
|
140
|
+
outputs: [
|
|
141
|
+
{
|
|
142
|
+
name: "",
|
|
143
|
+
internalType: "struct RequestableWithdrawal",
|
|
144
|
+
type: "tuple",
|
|
145
|
+
components: [
|
|
146
|
+
{ name: "token", internalType: "address", type: "address" },
|
|
147
|
+
{ name: "amountIn", internalType: "uint256", type: "uint256" },
|
|
148
|
+
{
|
|
149
|
+
name: "outputs",
|
|
150
|
+
internalType: "struct WithdrawalOutput[]",
|
|
151
|
+
type: "tuple[]",
|
|
152
|
+
components: [
|
|
153
|
+
{ name: "token", internalType: "address", type: "address" },
|
|
154
|
+
{ name: "isDelayed", internalType: "bool", type: "bool" },
|
|
155
|
+
{ name: "amount", internalType: "uint256", type: "uint256" }
|
|
156
|
+
]
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
name: "requestCalls",
|
|
160
|
+
internalType: "struct MultiCall[]",
|
|
161
|
+
type: "tuple[]",
|
|
162
|
+
components: [
|
|
163
|
+
{ name: "target", internalType: "address", type: "address" },
|
|
164
|
+
{ name: "callData", internalType: "bytes", type: "bytes" }
|
|
165
|
+
]
|
|
166
|
+
},
|
|
167
|
+
{ name: "claimableAt", internalType: "uint256", type: "uint256" }
|
|
168
|
+
]
|
|
169
|
+
}
|
|
170
|
+
],
|
|
171
|
+
stateMutability: "view"
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
type: "function",
|
|
175
|
+
inputs: [],
|
|
176
|
+
name: "version",
|
|
177
|
+
outputs: [{ name: "", internalType: "uint256", type: "uint256" }],
|
|
178
|
+
stateMutability: "view"
|
|
179
|
+
}
|
|
180
|
+
];
|
|
181
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
182
|
+
0 && (module.exports = {
|
|
183
|
+
iWithdrawalCompressorV310Abi
|
|
184
|
+
});
|
|
@@ -26,6 +26,7 @@ var import_instanceManager = require("../../abi/310/instanceManager.js");
|
|
|
26
26
|
var import_camelotV3Worker = require("../../abi/router/camelotV3Worker.js");
|
|
27
27
|
var import_erc4626Worker = require("../../abi/router/erc4626Worker.js");
|
|
28
28
|
var import_gearboxRouter = require("../../abi/router/gearboxRouter.js");
|
|
29
|
+
var import_mellow4626Worker = require("../../abi/router/mellow4626Worker.js");
|
|
29
30
|
var import_pendleRouterWorker = require("../../abi/router/pendleRouterWorker.js");
|
|
30
31
|
var import_uniswapV3Worker = require("../../abi/router/uniswapV3Worker.js");
|
|
31
32
|
var import_utils = require("../../sdk/utils/index.js");
|
|
@@ -90,6 +91,16 @@ class InstanceManagerContract extends import_base_contract.BaseContract {
|
|
|
90
91
|
if (!parsedData.functionName.startsWith("Unknown function")) {
|
|
91
92
|
return parsedData;
|
|
92
93
|
}
|
|
94
|
+
const mellow4626Worker = new import_base_contract.BaseContract(
|
|
95
|
+
import_mellow4626Worker.mellow4626WorkerAbi,
|
|
96
|
+
target,
|
|
97
|
+
this.client,
|
|
98
|
+
"Mellow4626Worker"
|
|
99
|
+
);
|
|
100
|
+
parsedData = mellow4626Worker.parseFunctionData(calldata);
|
|
101
|
+
if (!parsedData.functionName.startsWith("Unknown function")) {
|
|
102
|
+
return parsedData;
|
|
103
|
+
}
|
|
93
104
|
const pendleRouterWorker = new import_base_contract.BaseContract(
|
|
94
105
|
import_pendleRouterWorker.pendleRouterWorkerAbi,
|
|
95
106
|
target,
|
|
@@ -0,0 +1,105 @@
|
|
|
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 DelayedWithdrawalPlugin_exports = {};
|
|
20
|
+
__export(DelayedWithdrawalPlugin_exports, {
|
|
21
|
+
DelayedWithdrawalPlugin: () => DelayedWithdrawalPlugin
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(DelayedWithdrawalPlugin_exports);
|
|
24
|
+
var import_IWithdrawalCompressorV310 = require("../../abi/IWithdrawalCompressorV310.js");
|
|
25
|
+
var import_sdk = require("../../sdk/index.js");
|
|
26
|
+
const MAP_LABEL = "delayedWithdrawal";
|
|
27
|
+
class DelayedWithdrawalPlugin extends import_sdk.BasePlugin {
|
|
28
|
+
#withdrawableAssets;
|
|
29
|
+
async load(force) {
|
|
30
|
+
if (!force && this.loaded) {
|
|
31
|
+
return this.state;
|
|
32
|
+
}
|
|
33
|
+
const compressor = (0, import_sdk.getWithdrawalCompressorAddress)(this.sdk.chainId);
|
|
34
|
+
this.sdk.logger?.debug(
|
|
35
|
+
`loading delayed withdrawal plugin with compressor ${compressor}`
|
|
36
|
+
);
|
|
37
|
+
const creditManagers = this.sdk.marketRegister.creditManagers;
|
|
38
|
+
const resp = await this.client.multicall({
|
|
39
|
+
contracts: compressor ? creditManagers.map(
|
|
40
|
+
(cm) => ({
|
|
41
|
+
abi: import_IWithdrawalCompressorV310.iWithdrawalCompressorV310Abi,
|
|
42
|
+
address: compressor,
|
|
43
|
+
functionName: "getWithdrawableAssets",
|
|
44
|
+
args: [cm.creditManager.address]
|
|
45
|
+
})
|
|
46
|
+
) : [],
|
|
47
|
+
allowFailure: true
|
|
48
|
+
});
|
|
49
|
+
this.#withdrawableAssets = new import_sdk.AddressMap(void 0, MAP_LABEL);
|
|
50
|
+
resp.forEach((r, index) => {
|
|
51
|
+
const cm = creditManagers[index];
|
|
52
|
+
if (r.status === "success") {
|
|
53
|
+
this.#withdrawableAssets?.upsert(
|
|
54
|
+
cm.creditManager.address,
|
|
55
|
+
r.result.map((cfg) => ({
|
|
56
|
+
...cfg,
|
|
57
|
+
creditManager: cm.creditManager.address
|
|
58
|
+
}))
|
|
59
|
+
);
|
|
60
|
+
} else {
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
return this.state;
|
|
64
|
+
}
|
|
65
|
+
get loaded() {
|
|
66
|
+
return !!this.#withdrawableAssets;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Returns a map of cmAddress -> array of delayed assets
|
|
70
|
+
* @throws if plugin is not attached
|
|
71
|
+
*/
|
|
72
|
+
get withdrawableAssets() {
|
|
73
|
+
if (!this.#withdrawableAssets) {
|
|
74
|
+
throw new Error("withdrawable assets plugin not attached");
|
|
75
|
+
}
|
|
76
|
+
return this.#withdrawableAssets;
|
|
77
|
+
}
|
|
78
|
+
stateHuman(_) {
|
|
79
|
+
return this.withdrawableAssets.values().flatMap((cm) => {
|
|
80
|
+
const cmAssets = cm.map((a) => {
|
|
81
|
+
return {
|
|
82
|
+
address: a.creditManager,
|
|
83
|
+
version: this.version,
|
|
84
|
+
...a
|
|
85
|
+
};
|
|
86
|
+
});
|
|
87
|
+
return cmAssets;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
get state() {
|
|
91
|
+
return {
|
|
92
|
+
withdrawableAssets: this.withdrawableAssets.asRecord()
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
hydrate(state) {
|
|
96
|
+
this.#withdrawableAssets = new import_sdk.AddressMap(
|
|
97
|
+
Object.entries(state.withdrawableAssets),
|
|
98
|
+
MAP_LABEL
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
103
|
+
0 && (module.exports = {
|
|
104
|
+
DelayedWithdrawalPlugin
|
|
105
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
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 delayed_withdrawal_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(delayed_withdrawal_exports);
|
|
18
|
+
__reExport(delayed_withdrawal_exports, require("./DelayedWithdrawalPlugin.js"), module.exports);
|
|
19
|
+
__reExport(delayed_withdrawal_exports, require("./types.js"), module.exports);
|
|
20
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
21
|
+
0 && (module.exports = {
|
|
22
|
+
...require("./DelayedWithdrawalPlugin.js"),
|
|
23
|
+
...require("./types.js")
|
|
24
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type": "commonjs"}
|
|
@@ -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);
|
|
@@ -32,7 +32,7 @@ class AbstractMigrateCreditAccountsService extends import_base.SDKConstruct {
|
|
|
32
32
|
#logger;
|
|
33
33
|
#version;
|
|
34
34
|
#service;
|
|
35
|
-
// TODO:
|
|
35
|
+
// TODO: HARDCODED
|
|
36
36
|
static V300_TO_V310_TOKENS_OVERRIDES = {
|
|
37
37
|
[import_chains.chains.Mainnet.id]: {
|
|
38
38
|
// stkcvxRLUSD_USDC
|
|
@@ -43,17 +43,15 @@ class AbstractMigrateCreditAccountsService extends import_base.SDKConstruct {
|
|
|
43
43
|
["0xcB5D10A57Aeb622b92784D53F730eE2210ab370E".toLowerCase()]: "0x00F7C0d39B05089e93858A82439EA17dE7160B5a".toLowerCase()
|
|
44
44
|
}
|
|
45
45
|
};
|
|
46
|
+
// TODO: HARDCODED
|
|
46
47
|
static accountMigratorBot = "0x286Fe53994f5668D56538Aa10eaa3Ac36f878e9C".toLowerCase();
|
|
47
|
-
//
|
|
48
|
+
// TODO: HARDCODED
|
|
48
49
|
static accountMigratorPreviewer = "0x6523B8c9daB92eea7944a79b4Dbb598c7934DCca".toLowerCase();
|
|
49
|
-
// "0x5514de935f39AB0a137b4A1c984c872513C02f29".toLowerCase() as Address;
|
|
50
|
-
// "0xe6d2A2477722Af204899cfd3257A43aDAE1Ea264".toLowerCase() as Address;
|
|
51
|
-
// 0x99B63E7030e6f066731CF4e166e87D1D18e98B45.toLowerCase() as Address;
|
|
52
50
|
constructor(sdk, version) {
|
|
53
51
|
super(sdk);
|
|
54
52
|
this.#version = version;
|
|
55
53
|
this.#service = (0, import_createCreditAccountService.createCreditAccountService)(this.sdk, version);
|
|
56
|
-
this.#logger = (0, import_utils.childLogger)("
|
|
54
|
+
this.#logger = (0, import_utils.childLogger)("MigrateCreditAccountsService", sdk.logger);
|
|
57
55
|
this.#logger?.debug(
|
|
58
56
|
`Created MigrateCreditAccountsService with version: ${this.#version}`
|
|
59
57
|
);
|
|
@@ -18,7 +18,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var AbstractCreditAccountsService_exports = {};
|
|
20
20
|
__export(AbstractCreditAccountsService_exports, {
|
|
21
|
-
AbstractCreditAccountService: () => AbstractCreditAccountService
|
|
21
|
+
AbstractCreditAccountService: () => AbstractCreditAccountService,
|
|
22
|
+
getWithdrawalCompressorAddress: () => getWithdrawalCompressorAddress
|
|
22
23
|
});
|
|
23
24
|
module.exports = __toCommonJS(AbstractCreditAccountsService_exports);
|
|
24
25
|
var import_viem = require("viem");
|
|
@@ -26,15 +27,20 @@ var import_generated = require("../../abi/310/generated.js");
|
|
|
26
27
|
var import_creditAccountCompressor = require("../../abi/compressors/creditAccountCompressor.js");
|
|
27
28
|
var import_peripheryCompressor = require("../../abi/compressors/peripheryCompressor.js");
|
|
28
29
|
var import_rewardsCompressor = require("../../abi/compressors/rewardsCompressor.js");
|
|
30
|
+
var import_IWithdrawalCompressorV310 = require("../../abi/IWithdrawalCompressorV310.js");
|
|
29
31
|
var import_iBaseRewardPool = require("../../abi/iBaseRewardPool.js");
|
|
30
32
|
var import_v300 = require("../../abi/v300.js");
|
|
31
33
|
var import_AbstractMigrateCreditAccountsService = require("../accountMigration/AbstractMigrateCreditAccountsService.js");
|
|
32
34
|
var import_base = require("../base/index.js");
|
|
33
35
|
var import_constants = require("../constants/index.js");
|
|
34
|
-
var import__ = require("../index.js");
|
|
35
36
|
var import_router = require("../router/index.js");
|
|
37
|
+
var import_sdk_legacy = require("../sdk-legacy/index.js");
|
|
36
38
|
var import_utils = require("../utils/index.js");
|
|
37
39
|
var import_viem2 = require("../utils/viem/index.js");
|
|
40
|
+
function getWithdrawalCompressorAddress(chainId) {
|
|
41
|
+
const compressor = chainId === 1 ? "0xfB79b6713fe214B8748ED7b0db1f93E4f1aC9d29" : void 0;
|
|
42
|
+
return compressor;
|
|
43
|
+
}
|
|
38
44
|
class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
39
45
|
#compressor;
|
|
40
46
|
#batchSize;
|
|
@@ -421,7 +427,7 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
421
427
|
throw new Error("debt increase or decrease must be non-zero");
|
|
422
428
|
}
|
|
423
429
|
const isDecrease = amount < 0n;
|
|
424
|
-
const change =
|
|
430
|
+
const change = import_sdk_legacy.BigIntMath.abs(amount);
|
|
425
431
|
const cm = this.sdk.marketRegister.findCreditManager(
|
|
426
432
|
creditAccount.creditManager
|
|
427
433
|
);
|
|
@@ -487,34 +493,93 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
487
493
|
const tx = cm.creditFacade.multicall(creditAccount.creditAccount, calls);
|
|
488
494
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
489
495
|
}
|
|
496
|
+
/**
|
|
497
|
+
* Preview delayed withdrawal for given token
|
|
498
|
+
* @param props - {@link PreviewDelayedWithdrawalProps}
|
|
499
|
+
* @returns
|
|
500
|
+
*/
|
|
501
|
+
async previewDelayedWithdrawal({
|
|
502
|
+
creditAccount,
|
|
503
|
+
amount,
|
|
504
|
+
token
|
|
505
|
+
}) {
|
|
506
|
+
const compressor = getWithdrawalCompressorAddress(this.sdk.chainId);
|
|
507
|
+
if (!compressor)
|
|
508
|
+
throw new Error(
|
|
509
|
+
`No compressor for current chain ${this.sdk.networkType}`
|
|
510
|
+
);
|
|
511
|
+
const contract = (0, import_viem.getContract)({
|
|
512
|
+
address: compressor,
|
|
513
|
+
abi: import_IWithdrawalCompressorV310.iWithdrawalCompressorV310Abi,
|
|
514
|
+
client: this.client
|
|
515
|
+
});
|
|
516
|
+
const resp = await contract.read.getWithdrawalRequestResult([
|
|
517
|
+
creditAccount,
|
|
518
|
+
token,
|
|
519
|
+
amount
|
|
520
|
+
]);
|
|
521
|
+
return resp;
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* Get claimable and pending withdrawals of an account
|
|
525
|
+
* @param props - {@link GetPendingWithdrawalsProps}
|
|
526
|
+
* @returns
|
|
527
|
+
*/
|
|
528
|
+
async getPendingWithdrawals({
|
|
529
|
+
creditAccount
|
|
530
|
+
}) {
|
|
531
|
+
const compressor = getWithdrawalCompressorAddress(this.sdk.chainId);
|
|
532
|
+
if (!compressor)
|
|
533
|
+
throw new Error(
|
|
534
|
+
`No compressor for current chain ${this.sdk.networkType}`
|
|
535
|
+
);
|
|
536
|
+
const contract = (0, import_viem.getContract)({
|
|
537
|
+
address: compressor,
|
|
538
|
+
abi: import_IWithdrawalCompressorV310.iWithdrawalCompressorV310Abi,
|
|
539
|
+
client: this.client
|
|
540
|
+
});
|
|
541
|
+
const resp = await contract.read.getCurrentWithdrawals([creditAccount]);
|
|
542
|
+
const claimableNow = resp?.[0] || [];
|
|
543
|
+
const pendingResult = [...resp?.[1] || []].sort(
|
|
544
|
+
(a, b) => a.claimableAt < b.claimableAt ? -1 : 1
|
|
545
|
+
);
|
|
546
|
+
const respResult = {
|
|
547
|
+
claimableNow: [...claimableNow],
|
|
548
|
+
pending: pendingResult
|
|
549
|
+
};
|
|
550
|
+
return respResult;
|
|
551
|
+
}
|
|
490
552
|
/**
|
|
491
553
|
* Start delayed withdrawal for given token
|
|
492
554
|
- Withdrawal is executed in the following order: price update -> execute withdraw calls -> update quotas
|
|
493
555
|
* @param props - {@link StartDelayedWithdrawalProps}
|
|
494
556
|
* @returns
|
|
495
557
|
*/
|
|
496
|
-
async
|
|
558
|
+
async startDelayedWithdrawal({
|
|
497
559
|
creditAccount,
|
|
498
560
|
minQuota,
|
|
499
561
|
averageQuota,
|
|
500
|
-
|
|
501
|
-
delayedWithdrawals,
|
|
502
|
-
sourceAmount,
|
|
503
|
-
sourceToken
|
|
562
|
+
preview
|
|
504
563
|
}) {
|
|
505
564
|
const cm = this.sdk.marketRegister.findCreditManager(
|
|
506
565
|
creditAccount.creditManager
|
|
507
566
|
);
|
|
508
|
-
const
|
|
509
|
-
|
|
510
|
-
|
|
567
|
+
const record = preview.outputs.reduce((acc, o) => {
|
|
568
|
+
const token = o.token.toLowerCase();
|
|
569
|
+
acc[token] = (acc[token] || 0n) + o.amount;
|
|
570
|
+
return acc;
|
|
571
|
+
}, {});
|
|
572
|
+
const balances = Object.entries(record).filter(([, a]) => a > 10n);
|
|
511
573
|
const storeExpectedBalances = {
|
|
512
574
|
target: cm.creditFacade.address,
|
|
513
575
|
callData: (0, import_viem.encodeFunctionData)({
|
|
514
576
|
abi: import_v300.iCreditFacadeV300MulticallAbi,
|
|
515
577
|
functionName: "storeExpectedBalances",
|
|
516
578
|
args: [
|
|
517
|
-
balances.map((
|
|
579
|
+
balances.map(([token, amount]) => ({
|
|
580
|
+
token,
|
|
581
|
+
amount: import_sdk_legacy.BigIntMath.max(0n, amount - 10n)
|
|
582
|
+
}))
|
|
518
583
|
]
|
|
519
584
|
})
|
|
520
585
|
};
|
|
@@ -531,38 +596,10 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
531
596
|
creditAccount,
|
|
532
597
|
desiredQuotas: averageQuota
|
|
533
598
|
});
|
|
534
|
-
const mellowAdapter = cm.creditManager.adapters.mustGet(sourceToken);
|
|
535
|
-
const redeem = {
|
|
536
|
-
target: mellowAdapter.address,
|
|
537
|
-
callData: (0, import_viem.encodeFunctionData)({
|
|
538
|
-
abi: ierc4626AdapterAbi,
|
|
539
|
-
functionName: "redeem",
|
|
540
|
-
args: [sourceAmount, import_constants.ADDRESS_0X0, import_constants.ADDRESS_0X0]
|
|
541
|
-
})
|
|
542
|
-
};
|
|
543
|
-
const CLAIMER = "0x25024a3017B8da7161d8c5DCcF768F8678fB5802";
|
|
544
|
-
const mellowClaimerAdapter = cm.creditManager.adapters.mustGet(CLAIMER);
|
|
545
|
-
const multiAcceptContract = (0, import_viem.getContract)({
|
|
546
|
-
address: mellowClaimerAdapter.address,
|
|
547
|
-
abi: iMellowClaimerAdapterAbi,
|
|
548
|
-
client: this.client
|
|
549
|
-
});
|
|
550
|
-
const indices = await multiAcceptContract.read.getMultiVaultSubvaultIndices(
|
|
551
|
-
[sourceToken]
|
|
552
|
-
);
|
|
553
|
-
const multiaccept = {
|
|
554
|
-
target: mellowClaimerAdapter.address,
|
|
555
|
-
callData: (0, import_viem.encodeFunctionData)({
|
|
556
|
-
abi: iMellowClaimerAdapterAbi,
|
|
557
|
-
functionName: "multiAccept",
|
|
558
|
-
args: [sourceToken, ...indices]
|
|
559
|
-
})
|
|
560
|
-
};
|
|
561
599
|
const calls = [
|
|
562
600
|
...priceUpdatesCalls,
|
|
563
601
|
storeExpectedBalances,
|
|
564
|
-
|
|
565
|
-
multiaccept,
|
|
602
|
+
...preview.requestCalls,
|
|
566
603
|
compareBalances,
|
|
567
604
|
...this.prepareUpdateQuotas(creditAccount.creditFacade, {
|
|
568
605
|
minQuota,
|
|
@@ -578,24 +615,35 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
578
615
|
* @param props - {@link ClaimDelayedProps}
|
|
579
616
|
* @returns
|
|
580
617
|
*/
|
|
581
|
-
async
|
|
618
|
+
async claimDelayed({
|
|
582
619
|
creditAccount,
|
|
583
620
|
minQuota,
|
|
584
621
|
averageQuota,
|
|
585
|
-
|
|
586
|
-
phantom,
|
|
587
|
-
target
|
|
622
|
+
claimableNow
|
|
588
623
|
}) {
|
|
624
|
+
const zeroDebt = creditAccount.debt === 0n;
|
|
589
625
|
const cm = this.sdk.marketRegister.findCreditManager(
|
|
590
626
|
creditAccount.creditManager
|
|
591
627
|
);
|
|
628
|
+
const record = claimableNow.outputs.reduce(
|
|
629
|
+
(acc, o) => {
|
|
630
|
+
const token = o.token.toLowerCase();
|
|
631
|
+
acc[token] = (acc[token] || 0n) + o.amount;
|
|
632
|
+
return acc;
|
|
633
|
+
},
|
|
634
|
+
{}
|
|
635
|
+
);
|
|
636
|
+
const balances = Object.entries(record).filter(([, a]) => a > 10n);
|
|
592
637
|
const storeExpectedBalances = {
|
|
593
638
|
target: cm.creditFacade.address,
|
|
594
639
|
callData: (0, import_viem.encodeFunctionData)({
|
|
595
640
|
abi: import_v300.iCreditFacadeV300MulticallAbi,
|
|
596
641
|
functionName: "storeExpectedBalances",
|
|
597
642
|
args: [
|
|
598
|
-
|
|
643
|
+
balances.map(([token, amount]) => ({
|
|
644
|
+
token,
|
|
645
|
+
amount: import_sdk_legacy.BigIntMath.max(0n, amount - 10n)
|
|
646
|
+
}))
|
|
599
647
|
]
|
|
600
648
|
})
|
|
601
649
|
};
|
|
@@ -607,39 +655,21 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
607
655
|
args: []
|
|
608
656
|
})
|
|
609
657
|
};
|
|
610
|
-
const priceUpdatesCalls = await this.getPriceUpdatesForFacade({
|
|
658
|
+
const priceUpdatesCalls = zeroDebt ? [] : await this.getPriceUpdatesForFacade({
|
|
611
659
|
creditManager: creditAccount.creditManager,
|
|
612
660
|
creditAccount,
|
|
613
661
|
desiredQuotas: averageQuota
|
|
614
662
|
});
|
|
615
|
-
const
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
address: mellowClaimerAdapter.address,
|
|
619
|
-
abi: iMellowClaimerAdapterAbi,
|
|
620
|
-
client: this.client
|
|
663
|
+
const quotaCalls = zeroDebt ? [] : this.prepareUpdateQuotas(creditAccount.creditFacade, {
|
|
664
|
+
minQuota,
|
|
665
|
+
averageQuota
|
|
621
666
|
});
|
|
622
|
-
const indices = await multiAcceptContract.read.getUserSubvaultIndices([
|
|
623
|
-
sourceToken,
|
|
624
|
-
creditAccount.creditAccount
|
|
625
|
-
]);
|
|
626
|
-
const multiaccept = {
|
|
627
|
-
target: mellowClaimerAdapter.address,
|
|
628
|
-
callData: (0, import_viem.encodeFunctionData)({
|
|
629
|
-
abi: iMellowClaimerAdapterAbi,
|
|
630
|
-
functionName: "multiAcceptAndClaim",
|
|
631
|
-
args: [sourceToken, ...indices, import_constants.ADDRESS_0X0, phantom.balance]
|
|
632
|
-
})
|
|
633
|
-
};
|
|
634
667
|
const calls = [
|
|
635
668
|
...priceUpdatesCalls,
|
|
636
669
|
storeExpectedBalances,
|
|
637
|
-
|
|
670
|
+
...claimableNow.claimCalls,
|
|
638
671
|
compareBalances,
|
|
639
|
-
...
|
|
640
|
-
minQuota,
|
|
641
|
-
averageQuota
|
|
642
|
-
})
|
|
672
|
+
...quotaCalls
|
|
643
673
|
];
|
|
644
674
|
const tx = cm.creditFacade.multicall(creditAccount.creditAccount, calls);
|
|
645
675
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
@@ -1143,20 +1173,8 @@ const iMellowClaimerAdapterAbi = [
|
|
|
1143
1173
|
stateMutability: "nonpayable"
|
|
1144
1174
|
}
|
|
1145
1175
|
];
|
|
1146
|
-
const ierc4626AdapterAbi = [
|
|
1147
|
-
{
|
|
1148
|
-
type: "function",
|
|
1149
|
-
inputs: [
|
|
1150
|
-
{ name: "shares", internalType: "uint256", type: "uint256" },
|
|
1151
|
-
{ name: "", internalType: "address", type: "address" },
|
|
1152
|
-
{ name: "", internalType: "address", type: "address" }
|
|
1153
|
-
],
|
|
1154
|
-
name: "redeem",
|
|
1155
|
-
outputs: [{ name: "useSafePrices", internalType: "bool", type: "bool" }],
|
|
1156
|
-
stateMutability: "nonpayable"
|
|
1157
|
-
}
|
|
1158
|
-
];
|
|
1159
1176
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1160
1177
|
0 && (module.exports = {
|
|
1161
|
-
AbstractCreditAccountService
|
|
1178
|
+
AbstractCreditAccountService,
|
|
1179
|
+
getWithdrawalCompressorAddress
|
|
1162
1180
|
});
|