@gearbox-protocol/sdk 14.12.0-next.16 → 14.12.0-next.18
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/{IWithdrawalCompressorV312.js → IWithdrawalCompressorV313.js} +49 -6
- package/dist/cjs/abi/compressors/subcompressors/withdrawal/mellowWithdrawalSubcompressor.js +45 -1
- package/dist/cjs/abi/compressors/subcompressors/withdrawal/midasWithdrawalSubcompressor.js +45 -1
- package/dist/cjs/abi/compressors/subcompressors/withdrawal/securitizeRedemptionSubcompressor.js +45 -1
- package/dist/cjs/abi/compressors/withdrawalCompressor.js +45 -1
- package/dist/cjs/dev/index.js +3 -1
- package/dist/cjs/dev/withdrawalAbi.js +2105 -0
- package/dist/cjs/dev/withdrawalUtils.js +271 -0
- package/dist/cjs/permissionless/bindings/factory/rate-keeper-factory.js +35 -0
- package/dist/cjs/permissionless/bindings/market-configurator.js +11 -0
- package/dist/cjs/plugins/adapters/abi/adapters/iMidasGatewayAdapterV311.js +1015 -0
- package/dist/cjs/plugins/adapters/abi/adapters/{iMidasIssuanceVaultAdapter.js → iMidasIssuanceVaultAdapterV310.js} +6 -6
- package/dist/cjs/plugins/adapters/abi/adapters/{iMidasRedemptionVault.js → iMidasRedemptionVaultAdapterV310.js} +9 -9
- package/dist/cjs/plugins/adapters/abi/adapters/index.js +6 -4
- package/dist/cjs/plugins/adapters/abi/conctructorAbi.js +3 -0
- package/dist/cjs/plugins/adapters/abi/targetContractAbi.js +3 -3
- package/dist/cjs/plugins/adapters/contracts/MidasGatewayAdapterContract.js +121 -0
- package/dist/cjs/plugins/adapters/contracts/MidasIssuanceVaultAdapterContract.js +2 -2
- package/dist/cjs/plugins/adapters/contracts/MidasRedemptionVaultAdapterContract.js +2 -2
- package/dist/cjs/plugins/adapters/contracts/index.js +2 -0
- package/dist/cjs/plugins/adapters/createAdapter.js +2 -0
- package/dist/cjs/plugins/adapters/types.js +1 -0
- package/dist/cjs/plugins/delayed-withdrawal/DelayedWithdrawalPlugin.js +20 -37
- package/dist/cjs/sdk/OnchainSDK.js +11 -0
- package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +11 -58
- package/dist/cjs/sdk/accounts/index.js +3 -1
- package/dist/cjs/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.js +229 -0
- package/dist/cjs/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +40 -0
- package/dist/cjs/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +40 -0
- package/dist/cjs/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +40 -0
- package/dist/cjs/sdk/accounts/withdrawal-compressor/addresses.js +52 -0
- package/dist/cjs/sdk/accounts/withdrawal-compressor/createWithdrawalCompressor.js +53 -0
- package/dist/cjs/sdk/accounts/withdrawal-compressor/index.js +36 -0
- package/dist/cjs/sdk/accounts/withdrawal-compressor/intent.js +172 -0
- package/dist/cjs/sdk/accounts/withdrawal-compressor/types.js +16 -0
- package/dist/esm/abi/{IWithdrawalCompressorV312.js → IWithdrawalCompressorV313.js} +45 -2
- package/dist/esm/abi/compressors/subcompressors/withdrawal/mellowWithdrawalSubcompressor.js +45 -1
- package/dist/esm/abi/compressors/subcompressors/withdrawal/midasWithdrawalSubcompressor.js +45 -1
- package/dist/esm/abi/compressors/subcompressors/withdrawal/securitizeRedemptionSubcompressor.js +45 -1
- package/dist/esm/abi/compressors/withdrawalCompressor.js +45 -1
- package/dist/esm/dev/index.js +1 -0
- package/dist/esm/dev/withdrawalAbi.js +2074 -0
- package/dist/esm/dev/withdrawalUtils.js +259 -0
- package/dist/esm/permissionless/bindings/factory/rate-keeper-factory.js +11 -0
- package/dist/esm/permissionless/bindings/market-configurator.js +11 -0
- package/dist/esm/plugins/adapters/abi/adapters/iMidasGatewayAdapterV311.js +990 -0
- package/dist/esm/plugins/adapters/abi/adapters/{iMidasIssuanceVaultAdapter.js → iMidasIssuanceVaultAdapterV310.js} +2 -2
- package/dist/esm/plugins/adapters/abi/adapters/{iMidasRedemptionVault.js → iMidasRedemptionVaultAdapterV310.js} +4 -4
- package/dist/esm/plugins/adapters/abi/adapters/index.js +3 -2
- package/dist/esm/plugins/adapters/abi/conctructorAbi.js +3 -0
- package/dist/esm/plugins/adapters/abi/targetContractAbi.js +2 -2
- package/dist/esm/plugins/adapters/contracts/MidasGatewayAdapterContract.js +104 -0
- package/dist/esm/plugins/adapters/contracts/MidasIssuanceVaultAdapterContract.js +4 -4
- package/dist/esm/plugins/adapters/contracts/MidasRedemptionVaultAdapterContract.js +4 -4
- package/dist/esm/plugins/adapters/contracts/index.js +1 -0
- package/dist/esm/plugins/adapters/createAdapter.js +3 -0
- package/dist/esm/plugins/adapters/types.js +1 -0
- package/dist/esm/plugins/delayed-withdrawal/DelayedWithdrawalPlugin.js +21 -39
- package/dist/esm/sdk/OnchainSDK.js +13 -1
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +10 -56
- package/dist/esm/sdk/accounts/index.js +1 -0
- package/dist/esm/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.js +205 -0
- package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +16 -0
- package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +16 -0
- package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +16 -0
- package/dist/esm/sdk/accounts/withdrawal-compressor/addresses.js +28 -0
- package/dist/esm/sdk/accounts/withdrawal-compressor/createWithdrawalCompressor.js +29 -0
- package/dist/esm/sdk/accounts/withdrawal-compressor/index.js +8 -0
- package/dist/esm/sdk/accounts/withdrawal-compressor/intent.js +137 -0
- package/dist/esm/sdk/accounts/withdrawal-compressor/types.js +0 -0
- package/dist/types/abi/{IWithdrawalCompressorV312.d.ts → IWithdrawalCompressorV313.d.ts} +74 -1
- package/dist/types/abi/compressors/subcompressors/withdrawal/mellowWithdrawalSubcompressor.d.ts +77 -0
- package/dist/types/abi/compressors/subcompressors/withdrawal/midasWithdrawalSubcompressor.d.ts +77 -0
- package/dist/types/abi/compressors/subcompressors/withdrawal/securitizeRedemptionSubcompressor.d.ts +77 -0
- package/dist/types/abi/compressors/withdrawalCompressor.d.ts +77 -0
- package/dist/types/dev/index.d.ts +1 -0
- package/dist/types/dev/withdrawalAbi.d.ts +1584 -0
- package/dist/types/dev/withdrawalUtils.d.ts +19 -0
- package/dist/types/permissionless/bindings/compressors/withdrawal-compressor.d.ts +77 -0
- package/dist/types/permissionless/bindings/factory/rate-keeper-factory.d.ts +179 -0
- package/dist/types/permissionless/bindings/market-configurator.d.ts +2 -0
- package/dist/types/plugins/adapters/abi/adapters/iMidasGatewayAdapterV311.d.ts +754 -0
- package/dist/types/plugins/adapters/abi/adapters/{iMidasIssuanceVaultAdapter.d.ts → iMidasIssuanceVaultAdapterV310.d.ts} +1 -1
- package/dist/types/plugins/adapters/abi/adapters/{iMidasRedemptionVault.d.ts → iMidasRedemptionVaultAdapterV310.d.ts} +2 -2
- package/dist/types/plugins/adapters/abi/adapters/index.d.ts +3 -2
- package/dist/types/plugins/adapters/abi/targetContractAbi.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/MidasGatewayAdapterContract.d.ts +790 -0
- package/dist/types/plugins/adapters/contracts/index.d.ts +1 -0
- package/dist/types/plugins/adapters/types.d.ts +2 -1
- package/dist/types/plugins/delayed-withdrawal/types.d.ts +4 -17
- package/dist/types/sdk/OnchainSDK.d.ts +10 -1
- package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +4 -12
- package/dist/types/sdk/accounts/index.d.ts +1 -0
- package/dist/types/sdk/accounts/types.d.ts +5 -19
- package/dist/types/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.d.ts +35 -0
- package/dist/types/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.d.ts +334 -0
- package/dist/types/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.d.ts +338 -0
- package/dist/types/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.d.ts +300 -0
- package/dist/types/sdk/accounts/withdrawal-compressor/addresses.d.ts +21 -0
- package/dist/types/sdk/accounts/withdrawal-compressor/createWithdrawalCompressor.d.ts +11 -0
- package/dist/types/sdk/accounts/withdrawal-compressor/index.d.ts +8 -0
- package/dist/types/sdk/accounts/withdrawal-compressor/intent.d.ts +106 -0
- package/dist/types/sdk/accounts/withdrawal-compressor/types.d.ts +122 -0
- package/package.json +1 -1
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { isAddressEqual } from "viem";
|
|
2
|
+
import { BaseContract } from "../../base/index.js";
|
|
3
|
+
import { decodeDelayedIntent, encodeDelayedIntent } from "./intent.js";
|
|
4
|
+
const iCreditAccountAbi = [
|
|
5
|
+
{
|
|
6
|
+
type: "function",
|
|
7
|
+
name: "creditManager",
|
|
8
|
+
inputs: [],
|
|
9
|
+
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
10
|
+
stateMutability: "view"
|
|
11
|
+
}
|
|
12
|
+
];
|
|
13
|
+
class AbstractWithdrawalCompressorContract extends BaseContract {
|
|
14
|
+
#sdk;
|
|
15
|
+
constructor(sdk, args) {
|
|
16
|
+
super(sdk, args);
|
|
17
|
+
this.#sdk = sdk;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The contract is instantiated with the actual versioned ABI,
|
|
21
|
+
* this cast is type-level only (see {@link CommonAbi}).
|
|
22
|
+
**/
|
|
23
|
+
get common() {
|
|
24
|
+
return this.contract;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* {@inheritDoc IWithdrawalCompressorContract.getWithdrawableAssets}
|
|
28
|
+
**/
|
|
29
|
+
async getWithdrawableAssets(creditManager) {
|
|
30
|
+
const resp = await this.common.read.getWithdrawableAssets([creditManager]);
|
|
31
|
+
return resp.map((a) => toWithdrawableAsset(a, creditManager));
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* {@inheritDoc IWithdrawalCompressorContract.getWithdrawableAssetsBatch}
|
|
35
|
+
**/
|
|
36
|
+
async getWithdrawableAssetsBatch(creditManagers) {
|
|
37
|
+
const cms = creditManagers ?? this.#sdk.marketRegister.creditManagers.map(
|
|
38
|
+
(cm) => cm.creditManager.address
|
|
39
|
+
);
|
|
40
|
+
const resp = await this.client.multicall({
|
|
41
|
+
contracts: cms.map(
|
|
42
|
+
(cm) => ({
|
|
43
|
+
address: this.address,
|
|
44
|
+
abi: this.abi,
|
|
45
|
+
functionName: "getWithdrawableAssets",
|
|
46
|
+
args: [cm]
|
|
47
|
+
})
|
|
48
|
+
),
|
|
49
|
+
allowFailure: true,
|
|
50
|
+
batchSize: 0
|
|
51
|
+
});
|
|
52
|
+
return resp.flatMap((r, i) => {
|
|
53
|
+
if (r.status !== "success") {
|
|
54
|
+
this.logger?.warn(
|
|
55
|
+
`failed to get withdrawable assets of credit manager ${cms[i]}: ${r.error}`
|
|
56
|
+
);
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
59
|
+
return r.result.map((a) => toWithdrawableAsset(a, cms[i]));
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* {@inheritDoc IWithdrawalCompressorContract.getCurrentWithdrawals}
|
|
64
|
+
**/
|
|
65
|
+
async getCurrentWithdrawals(creditAccount) {
|
|
66
|
+
const [[claimable, pending], creditManager] = await this.client.multicall({
|
|
67
|
+
contracts: [
|
|
68
|
+
{
|
|
69
|
+
address: this.address,
|
|
70
|
+
abi: this.abi,
|
|
71
|
+
functionName: "getCurrentWithdrawals",
|
|
72
|
+
args: [creditAccount]
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
address: creditAccount,
|
|
76
|
+
abi: iCreditAccountAbi,
|
|
77
|
+
functionName: "creditManager"
|
|
78
|
+
}
|
|
79
|
+
],
|
|
80
|
+
allowFailure: false,
|
|
81
|
+
batchSize: 0
|
|
82
|
+
});
|
|
83
|
+
return {
|
|
84
|
+
claimable: claimable.map(
|
|
85
|
+
(w) => toClaimableWithdrawal(w, creditManager, this.version >= 313)
|
|
86
|
+
),
|
|
87
|
+
pending: pending.map(toPendingWithdrawal).sort((a, b) => a.claimableAt < b.claimableAt ? -1 : 1)
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* {@inheritDoc IWithdrawalCompressorContract.getWithdrawalRequestResult}
|
|
92
|
+
**/
|
|
93
|
+
async getWithdrawalRequestResult(creditAccount, token, amount, intent) {
|
|
94
|
+
const resp = intent ? await this.#getWithdrawalRequestResultWithIntent(
|
|
95
|
+
creditAccount,
|
|
96
|
+
token,
|
|
97
|
+
amount,
|
|
98
|
+
intent
|
|
99
|
+
) : await this.common.read.getWithdrawalRequestResult([
|
|
100
|
+
creditAccount,
|
|
101
|
+
token,
|
|
102
|
+
amount
|
|
103
|
+
]);
|
|
104
|
+
return {
|
|
105
|
+
token: resp.token,
|
|
106
|
+
amountIn: resp.amountIn,
|
|
107
|
+
outputs: resp.outputs.map(toWithdrawalOutput),
|
|
108
|
+
requestCalls: resp.requestCalls.map(toMultiCall),
|
|
109
|
+
claimableAt: resp.claimableAt
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Previews a delayed withdrawal request with an intent attached as
|
|
114
|
+
* `extraData`. Only supported on v313+ compressors; on older versions,
|
|
115
|
+
* throws if `sdk.strictContractTypes` is `true`, otherwise logs a warning
|
|
116
|
+
* and previews the request without the intent.
|
|
117
|
+
*
|
|
118
|
+
* The contract overload accepting `extraData` also requires the withdrawal
|
|
119
|
+
* phantom token, which is resolved here the same way the 3-arg overload
|
|
120
|
+
* does it internally: via `getWithdrawableAssets` of the account's credit
|
|
121
|
+
* manager.
|
|
122
|
+
**/
|
|
123
|
+
async #getWithdrawalRequestResultWithIntent(creditAccount, token, amount, intent) {
|
|
124
|
+
if (this.version < 313) {
|
|
125
|
+
const message = `withdrawal intents are not supported by ${this.name} v${this.version}`;
|
|
126
|
+
if (this.#sdk.strictContractTypes) {
|
|
127
|
+
throw new Error(message);
|
|
128
|
+
}
|
|
129
|
+
this.logger?.warn(`${message}, requesting withdrawal without intent`);
|
|
130
|
+
return this.common.read.getWithdrawalRequestResult([
|
|
131
|
+
creditAccount,
|
|
132
|
+
token,
|
|
133
|
+
amount
|
|
134
|
+
]);
|
|
135
|
+
}
|
|
136
|
+
const extraData = encodeDelayedIntent(intent);
|
|
137
|
+
const creditManager = await this.client.readContract({
|
|
138
|
+
address: creditAccount,
|
|
139
|
+
abi: iCreditAccountAbi,
|
|
140
|
+
functionName: "creditManager"
|
|
141
|
+
});
|
|
142
|
+
const assets = await this.common.read.getWithdrawableAssets([
|
|
143
|
+
creditManager
|
|
144
|
+
]);
|
|
145
|
+
const asset = assets.find((a) => isAddressEqual(a.token, token));
|
|
146
|
+
if (!asset) {
|
|
147
|
+
throw new Error(
|
|
148
|
+
`token ${token} is not withdrawable from credit manager ${creditManager}`
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
return this.common.read.getWithdrawalRequestResult([
|
|
152
|
+
creditAccount,
|
|
153
|
+
token,
|
|
154
|
+
asset.withdrawalPhantomToken,
|
|
155
|
+
amount,
|
|
156
|
+
extraData
|
|
157
|
+
]);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
function toWithdrawalOutput(o) {
|
|
161
|
+
return { token: o.token, isDelayed: o.isDelayed, amount: o.amount };
|
|
162
|
+
}
|
|
163
|
+
function toMultiCall(c) {
|
|
164
|
+
return { target: c.target, callData: c.callData };
|
|
165
|
+
}
|
|
166
|
+
function toWithdrawableAsset(a, creditManager) {
|
|
167
|
+
return {
|
|
168
|
+
creditManager,
|
|
169
|
+
token: a.token,
|
|
170
|
+
withdrawalPhantomToken: a.withdrawalPhantomToken,
|
|
171
|
+
underlying: a.underlying,
|
|
172
|
+
withdrawalLength: a.withdrawalLength,
|
|
173
|
+
maxWithdrawals: a.maxWithdrawals
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function toClaimableWithdrawal(w, creditManager, decodeIntent) {
|
|
177
|
+
let intent;
|
|
178
|
+
if (decodeIntent) {
|
|
179
|
+
if (!w.extraData || w.extraData === "0x") {
|
|
180
|
+
throw new Error(
|
|
181
|
+
`claimable withdrawal of ${w.token} has no delayed intent in extraData`
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
intent = { ...decodeDelayedIntent(w.extraData), creditManager };
|
|
185
|
+
}
|
|
186
|
+
return {
|
|
187
|
+
token: w.token,
|
|
188
|
+
withdrawalPhantomToken: w.withdrawalPhantomToken,
|
|
189
|
+
withdrawalTokenSpent: w.withdrawalTokenSpent,
|
|
190
|
+
outputs: w.outputs.map(toWithdrawalOutput),
|
|
191
|
+
claimCalls: w.claimCalls.map(toMultiCall),
|
|
192
|
+
intent
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
function toPendingWithdrawal(w) {
|
|
196
|
+
return {
|
|
197
|
+
token: w.token,
|
|
198
|
+
withdrawalPhantomToken: w.withdrawalPhantomToken,
|
|
199
|
+
expectedOutputs: w.expectedOutputs.map(toWithdrawalOutput),
|
|
200
|
+
claimableAt: w.claimableAt
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
export {
|
|
204
|
+
AbstractWithdrawalCompressorContract
|
|
205
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { iWithdrawalCompressorV310Abi } from "../../../abi/IWithdrawalCompressorV310.js";
|
|
2
|
+
import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
|
|
3
|
+
const abi = iWithdrawalCompressorV310Abi;
|
|
4
|
+
class WithdrawalCompressorV310Contract extends AbstractWithdrawalCompressorContract {
|
|
5
|
+
constructor(sdk, address) {
|
|
6
|
+
super(sdk, {
|
|
7
|
+
addr: address,
|
|
8
|
+
name: "WithdrawalCompressorV310",
|
|
9
|
+
abi,
|
|
10
|
+
version: 310
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
WithdrawalCompressorV310Contract
|
|
16
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { iWithdrawalCompressorV311Abi } from "../../../abi/IWithdrawalCompressorV311.js";
|
|
2
|
+
import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
|
|
3
|
+
const abi = iWithdrawalCompressorV311Abi;
|
|
4
|
+
class WithdrawalCompressorV311Contract extends AbstractWithdrawalCompressorContract {
|
|
5
|
+
constructor(sdk, address) {
|
|
6
|
+
super(sdk, {
|
|
7
|
+
addr: address,
|
|
8
|
+
name: "WithdrawalCompressorV311",
|
|
9
|
+
abi,
|
|
10
|
+
version: 311
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
WithdrawalCompressorV311Contract
|
|
16
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { iWithdrawalCompressorV313Abi } from "../../../abi/IWithdrawalCompressorV313.js";
|
|
2
|
+
import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
|
|
3
|
+
const abi = iWithdrawalCompressorV313Abi;
|
|
4
|
+
class WithdrawalCompressorV313Contract extends AbstractWithdrawalCompressorContract {
|
|
5
|
+
constructor(sdk, address) {
|
|
6
|
+
super(sdk, {
|
|
7
|
+
addr: address,
|
|
8
|
+
name: "WithdrawalCompressorV313",
|
|
9
|
+
abi,
|
|
10
|
+
version: 313
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
WithdrawalCompressorV313Contract
|
|
16
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const WITHDRAWAL_COMPRESSORS = {
|
|
2
|
+
Mainnet: {
|
|
3
|
+
310: "0x36F3d0Bb73CBC2E94fE24dF0f26a689409cF9023",
|
|
4
|
+
313: "0x9605D59E40963ADce8a6895Aa3Fa497320Ef3F3b"
|
|
5
|
+
},
|
|
6
|
+
Monad: {
|
|
7
|
+
310: "0x36F3d0Bb73CBC2E94fE24dF0f26a689409cF9023"
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
function getWithdrawalCompressorAddress(network, version) {
|
|
11
|
+
const deployments = WITHDRAWAL_COMPRESSORS[network];
|
|
12
|
+
if (!deployments) {
|
|
13
|
+
return void 0;
|
|
14
|
+
}
|
|
15
|
+
if (version !== void 0) {
|
|
16
|
+
const address2 = deployments[version];
|
|
17
|
+
return address2 ? { address: address2, version } : void 0;
|
|
18
|
+
}
|
|
19
|
+
const latest = Object.keys(deployments).map(Number).sort((a, b) => b - a)[0];
|
|
20
|
+
if (latest === void 0) {
|
|
21
|
+
return void 0;
|
|
22
|
+
}
|
|
23
|
+
const address = deployments[latest];
|
|
24
|
+
return address ? { address, version: latest } : void 0;
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
getWithdrawalCompressorAddress
|
|
28
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { getWithdrawalCompressorAddress } from "./addresses.js";
|
|
2
|
+
import { WithdrawalCompressorV310Contract } from "./WithdrawalCompressorV310Contract.js";
|
|
3
|
+
import { WithdrawalCompressorV311Contract } from "./WithdrawalCompressorV311Contract.js";
|
|
4
|
+
import { WithdrawalCompressorV313Contract } from "./WithdrawalCompressorV313Contract.js";
|
|
5
|
+
function createWithdrawalCompressor(sdk, version) {
|
|
6
|
+
const location = getWithdrawalCompressorAddress(sdk.networkType, version);
|
|
7
|
+
if (!location) {
|
|
8
|
+
throw new Error(
|
|
9
|
+
`no withdrawal compressor${version ? ` v${version}` : ""} on ${sdk.networkType}`
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
const cached = sdk.getContract(
|
|
13
|
+
location.address
|
|
14
|
+
);
|
|
15
|
+
if (cached) {
|
|
16
|
+
return cached;
|
|
17
|
+
}
|
|
18
|
+
switch (location.version) {
|
|
19
|
+
case 310:
|
|
20
|
+
return new WithdrawalCompressorV310Contract(sdk, location.address);
|
|
21
|
+
case 311:
|
|
22
|
+
return new WithdrawalCompressorV311Contract(sdk, location.address);
|
|
23
|
+
case 313:
|
|
24
|
+
return new WithdrawalCompressorV313Contract(sdk, location.address);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
createWithdrawalCompressor
|
|
29
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./AbstractWithdrawalCompressorContract.js";
|
|
2
|
+
export * from "./addresses.js";
|
|
3
|
+
export * from "./createWithdrawalCompressor.js";
|
|
4
|
+
export * from "./intent.js";
|
|
5
|
+
export * from "./types.js";
|
|
6
|
+
export * from "./WithdrawalCompressorV310Contract.js";
|
|
7
|
+
export * from "./WithdrawalCompressorV311Contract.js";
|
|
8
|
+
export * from "./WithdrawalCompressorV313Contract.js";
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { decodeAbiParameters, encodeAbiParameters } from "viem";
|
|
2
|
+
import { z } from "zod/v4";
|
|
3
|
+
import { ZodAddress } from "../../utils/index.js";
|
|
4
|
+
const delayedIncreaseLeverageIntentSchema = z.object({
|
|
5
|
+
type: z.literal("INCREASE_LEVERAGE"),
|
|
6
|
+
to: ZodAddress()
|
|
7
|
+
});
|
|
8
|
+
const delayedDepositIntentSchema = z.object({
|
|
9
|
+
type: z.literal("DEPOSIT")
|
|
10
|
+
});
|
|
11
|
+
const delayedDepositAndIncreaseLeverageIntentSchema = z.object({
|
|
12
|
+
type: z.literal("DEPOSIT_AND_INCREASE_LEVERAGE")
|
|
13
|
+
});
|
|
14
|
+
const delayedWithdrawCollateralIntentSchema = z.object({
|
|
15
|
+
type: z.literal("WITHDRAW_COLLATERAL"),
|
|
16
|
+
to: ZodAddress(),
|
|
17
|
+
withdrawToken: ZodAddress(),
|
|
18
|
+
withdrawAmount: z.bigint()
|
|
19
|
+
});
|
|
20
|
+
const delayedCloseAccountIntentSchema = z.object({
|
|
21
|
+
type: z.literal("CLOSE_ACCOUNT"),
|
|
22
|
+
to: ZodAddress()
|
|
23
|
+
});
|
|
24
|
+
const delayedAddCollateralIntentSchema = z.object({
|
|
25
|
+
type: z.literal("ADD_COLLATERAL")
|
|
26
|
+
});
|
|
27
|
+
const delayedDecreaseLeverageIntentSchema = z.object({
|
|
28
|
+
type: z.literal("DECREASE_LEVERAGE")
|
|
29
|
+
});
|
|
30
|
+
const delayedIntentSchema = z.discriminatedUnion("type", [
|
|
31
|
+
delayedIncreaseLeverageIntentSchema,
|
|
32
|
+
delayedDepositIntentSchema,
|
|
33
|
+
delayedDepositAndIncreaseLeverageIntentSchema,
|
|
34
|
+
delayedWithdrawCollateralIntentSchema,
|
|
35
|
+
delayedCloseAccountIntentSchema,
|
|
36
|
+
delayedAddCollateralIntentSchema,
|
|
37
|
+
delayedDecreaseLeverageIntentSchema
|
|
38
|
+
]);
|
|
39
|
+
const DELAYED_INTENT_VERSION = 1;
|
|
40
|
+
const DELAYED_INTENT_TYPES = {
|
|
41
|
+
INCREASE_LEVERAGE: 1,
|
|
42
|
+
DEPOSIT: 2,
|
|
43
|
+
DEPOSIT_AND_INCREASE_LEVERAGE: 3,
|
|
44
|
+
WITHDRAW_COLLATERAL: 4,
|
|
45
|
+
CLOSE_ACCOUNT: 5,
|
|
46
|
+
ADD_COLLATERAL: 6,
|
|
47
|
+
DECREASE_LEVERAGE: 7
|
|
48
|
+
};
|
|
49
|
+
const HEADER_PARAMS = [
|
|
50
|
+
{ type: "uint8", name: "version" },
|
|
51
|
+
{ type: "uint8", name: "intentType" }
|
|
52
|
+
];
|
|
53
|
+
const TO_PARAMS = [...HEADER_PARAMS, { type: "address", name: "to" }];
|
|
54
|
+
const WITHDRAW_COLLATERAL_PARAMS = [
|
|
55
|
+
...TO_PARAMS,
|
|
56
|
+
{ type: "address", name: "withdrawToken" },
|
|
57
|
+
{ type: "uint256", name: "withdrawAmount" }
|
|
58
|
+
];
|
|
59
|
+
function encodeDelayedIntent(intent) {
|
|
60
|
+
const parsed = delayedIntentSchema.parse(intent);
|
|
61
|
+
const version = DELAYED_INTENT_VERSION;
|
|
62
|
+
const intentType = DELAYED_INTENT_TYPES[parsed.type];
|
|
63
|
+
switch (parsed.type) {
|
|
64
|
+
case "INCREASE_LEVERAGE":
|
|
65
|
+
case "CLOSE_ACCOUNT":
|
|
66
|
+
return encodeAbiParameters(TO_PARAMS, [version, intentType, parsed.to]);
|
|
67
|
+
case "WITHDRAW_COLLATERAL":
|
|
68
|
+
return encodeAbiParameters(WITHDRAW_COLLATERAL_PARAMS, [
|
|
69
|
+
version,
|
|
70
|
+
intentType,
|
|
71
|
+
parsed.to,
|
|
72
|
+
parsed.withdrawToken,
|
|
73
|
+
parsed.withdrawAmount
|
|
74
|
+
]);
|
|
75
|
+
case "DEPOSIT":
|
|
76
|
+
case "DEPOSIT_AND_INCREASE_LEVERAGE":
|
|
77
|
+
case "ADD_COLLATERAL":
|
|
78
|
+
case "DECREASE_LEVERAGE":
|
|
79
|
+
return encodeAbiParameters(HEADER_PARAMS, [version, intentType]);
|
|
80
|
+
default: {
|
|
81
|
+
const t = parsed;
|
|
82
|
+
throw new Error(`unknown delayed intent: ${JSON.stringify(t)}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function decodeDelayedIntent(data) {
|
|
87
|
+
const [version, intentType] = decodeAbiParameters(HEADER_PARAMS, data);
|
|
88
|
+
if (version !== DELAYED_INTENT_VERSION) {
|
|
89
|
+
throw new Error(`unsupported delayed intent version: ${version}`);
|
|
90
|
+
}
|
|
91
|
+
switch (intentType) {
|
|
92
|
+
case DELAYED_INTENT_TYPES.INCREASE_LEVERAGE: {
|
|
93
|
+
const [, , to] = decodeAbiParameters(TO_PARAMS, data);
|
|
94
|
+
return delayedIntentSchema.parse({ type: "INCREASE_LEVERAGE", to });
|
|
95
|
+
}
|
|
96
|
+
case DELAYED_INTENT_TYPES.DEPOSIT:
|
|
97
|
+
return { type: "DEPOSIT" };
|
|
98
|
+
case DELAYED_INTENT_TYPES.DEPOSIT_AND_INCREASE_LEVERAGE:
|
|
99
|
+
return { type: "DEPOSIT_AND_INCREASE_LEVERAGE" };
|
|
100
|
+
case DELAYED_INTENT_TYPES.WITHDRAW_COLLATERAL: {
|
|
101
|
+
const [, , to, withdrawToken, withdrawAmount] = decodeAbiParameters(
|
|
102
|
+
WITHDRAW_COLLATERAL_PARAMS,
|
|
103
|
+
data
|
|
104
|
+
);
|
|
105
|
+
return delayedIntentSchema.parse({
|
|
106
|
+
type: "WITHDRAW_COLLATERAL",
|
|
107
|
+
to,
|
|
108
|
+
withdrawToken,
|
|
109
|
+
withdrawAmount
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
case DELAYED_INTENT_TYPES.CLOSE_ACCOUNT: {
|
|
113
|
+
const [, , to] = decodeAbiParameters(TO_PARAMS, data);
|
|
114
|
+
return delayedIntentSchema.parse({ type: "CLOSE_ACCOUNT", to });
|
|
115
|
+
}
|
|
116
|
+
case DELAYED_INTENT_TYPES.ADD_COLLATERAL:
|
|
117
|
+
return { type: "ADD_COLLATERAL" };
|
|
118
|
+
case DELAYED_INTENT_TYPES.DECREASE_LEVERAGE:
|
|
119
|
+
return { type: "DECREASE_LEVERAGE" };
|
|
120
|
+
default:
|
|
121
|
+
throw new Error(`unknown delayed intent type: ${intentType}`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
export {
|
|
125
|
+
DELAYED_INTENT_TYPES,
|
|
126
|
+
DELAYED_INTENT_VERSION,
|
|
127
|
+
decodeDelayedIntent,
|
|
128
|
+
delayedAddCollateralIntentSchema,
|
|
129
|
+
delayedCloseAccountIntentSchema,
|
|
130
|
+
delayedDecreaseLeverageIntentSchema,
|
|
131
|
+
delayedDepositAndIncreaseLeverageIntentSchema,
|
|
132
|
+
delayedDepositIntentSchema,
|
|
133
|
+
delayedIncreaseLeverageIntentSchema,
|
|
134
|
+
delayedIntentSchema,
|
|
135
|
+
delayedWithdrawCollateralIntentSchema,
|
|
136
|
+
encodeDelayedIntent
|
|
137
|
+
};
|
|
File without changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const iWithdrawalCompressorV313Abi: readonly [{
|
|
2
2
|
readonly type: "function";
|
|
3
3
|
readonly name: "contractType";
|
|
4
4
|
readonly inputs: readonly [];
|
|
@@ -138,6 +138,79 @@ export declare const iWithdrawalCompressorV312Abi: readonly [{
|
|
|
138
138
|
}];
|
|
139
139
|
}];
|
|
140
140
|
readonly stateMutability: "view";
|
|
141
|
+
}, {
|
|
142
|
+
readonly type: "function";
|
|
143
|
+
readonly name: "getWithdrawalRequestResult";
|
|
144
|
+
readonly inputs: readonly [{
|
|
145
|
+
readonly name: "creditAccount";
|
|
146
|
+
readonly type: "address";
|
|
147
|
+
readonly internalType: "address";
|
|
148
|
+
}, {
|
|
149
|
+
readonly name: "token";
|
|
150
|
+
readonly type: "address";
|
|
151
|
+
readonly internalType: "address";
|
|
152
|
+
}, {
|
|
153
|
+
readonly name: "withdrawalToken";
|
|
154
|
+
readonly type: "address";
|
|
155
|
+
readonly internalType: "address";
|
|
156
|
+
}, {
|
|
157
|
+
readonly name: "amount";
|
|
158
|
+
readonly type: "uint256";
|
|
159
|
+
readonly internalType: "uint256";
|
|
160
|
+
}, {
|
|
161
|
+
readonly name: "extraData";
|
|
162
|
+
readonly type: "bytes";
|
|
163
|
+
readonly internalType: "bytes";
|
|
164
|
+
}];
|
|
165
|
+
readonly outputs: readonly [{
|
|
166
|
+
readonly name: "";
|
|
167
|
+
readonly type: "tuple";
|
|
168
|
+
readonly internalType: "struct RequestableWithdrawal";
|
|
169
|
+
readonly components: readonly [{
|
|
170
|
+
readonly name: "token";
|
|
171
|
+
readonly type: "address";
|
|
172
|
+
readonly internalType: "address";
|
|
173
|
+
}, {
|
|
174
|
+
readonly name: "amountIn";
|
|
175
|
+
readonly type: "uint256";
|
|
176
|
+
readonly internalType: "uint256";
|
|
177
|
+
}, {
|
|
178
|
+
readonly name: "outputs";
|
|
179
|
+
readonly type: "tuple[]";
|
|
180
|
+
readonly internalType: "struct WithdrawalOutput[]";
|
|
181
|
+
readonly components: readonly [{
|
|
182
|
+
readonly name: "token";
|
|
183
|
+
readonly type: "address";
|
|
184
|
+
readonly internalType: "address";
|
|
185
|
+
}, {
|
|
186
|
+
readonly name: "isDelayed";
|
|
187
|
+
readonly type: "bool";
|
|
188
|
+
readonly internalType: "bool";
|
|
189
|
+
}, {
|
|
190
|
+
readonly name: "amount";
|
|
191
|
+
readonly type: "uint256";
|
|
192
|
+
readonly internalType: "uint256";
|
|
193
|
+
}];
|
|
194
|
+
}, {
|
|
195
|
+
readonly name: "requestCalls";
|
|
196
|
+
readonly type: "tuple[]";
|
|
197
|
+
readonly internalType: "struct MultiCall[]";
|
|
198
|
+
readonly components: readonly [{
|
|
199
|
+
readonly name: "target";
|
|
200
|
+
readonly type: "address";
|
|
201
|
+
readonly internalType: "address";
|
|
202
|
+
}, {
|
|
203
|
+
readonly name: "callData";
|
|
204
|
+
readonly type: "bytes";
|
|
205
|
+
readonly internalType: "bytes";
|
|
206
|
+
}];
|
|
207
|
+
}, {
|
|
208
|
+
readonly name: "claimableAt";
|
|
209
|
+
readonly type: "uint256";
|
|
210
|
+
readonly internalType: "uint256";
|
|
211
|
+
}];
|
|
212
|
+
}];
|
|
213
|
+
readonly stateMutability: "view";
|
|
141
214
|
}, {
|
|
142
215
|
readonly type: "function";
|
|
143
216
|
readonly name: "getWithdrawalRequestResult";
|
package/dist/types/abi/compressors/subcompressors/withdrawal/mellowWithdrawalSubcompressor.d.ts
CHANGED
|
@@ -66,6 +66,10 @@ export declare const mellowWithdrawalSubcompressorAbi: readonly [{
|
|
|
66
66
|
readonly type: "bytes";
|
|
67
67
|
readonly internalType: "bytes";
|
|
68
68
|
}];
|
|
69
|
+
}, {
|
|
70
|
+
readonly name: "extraData";
|
|
71
|
+
readonly type: "bytes";
|
|
72
|
+
readonly internalType: "bytes";
|
|
69
73
|
}];
|
|
70
74
|
}, {
|
|
71
75
|
readonly name: "";
|
|
@@ -142,6 +146,79 @@ export declare const mellowWithdrawalSubcompressorAbi: readonly [{
|
|
|
142
146
|
}];
|
|
143
147
|
}];
|
|
144
148
|
readonly stateMutability: "view";
|
|
149
|
+
}, {
|
|
150
|
+
readonly type: "function";
|
|
151
|
+
readonly name: "getWithdrawalRequestResult";
|
|
152
|
+
readonly inputs: readonly [{
|
|
153
|
+
readonly name: "creditAccount";
|
|
154
|
+
readonly type: "address";
|
|
155
|
+
readonly internalType: "address";
|
|
156
|
+
}, {
|
|
157
|
+
readonly name: "token";
|
|
158
|
+
readonly type: "address";
|
|
159
|
+
readonly internalType: "address";
|
|
160
|
+
}, {
|
|
161
|
+
readonly name: "withdrawalToken";
|
|
162
|
+
readonly type: "address";
|
|
163
|
+
readonly internalType: "address";
|
|
164
|
+
}, {
|
|
165
|
+
readonly name: "amount";
|
|
166
|
+
readonly type: "uint256";
|
|
167
|
+
readonly internalType: "uint256";
|
|
168
|
+
}, {
|
|
169
|
+
readonly name: "";
|
|
170
|
+
readonly type: "bytes";
|
|
171
|
+
readonly internalType: "bytes";
|
|
172
|
+
}];
|
|
173
|
+
readonly outputs: readonly [{
|
|
174
|
+
readonly name: "requestableWithdrawal";
|
|
175
|
+
readonly type: "tuple";
|
|
176
|
+
readonly internalType: "struct RequestableWithdrawal";
|
|
177
|
+
readonly components: readonly [{
|
|
178
|
+
readonly name: "token";
|
|
179
|
+
readonly type: "address";
|
|
180
|
+
readonly internalType: "address";
|
|
181
|
+
}, {
|
|
182
|
+
readonly name: "amountIn";
|
|
183
|
+
readonly type: "uint256";
|
|
184
|
+
readonly internalType: "uint256";
|
|
185
|
+
}, {
|
|
186
|
+
readonly name: "outputs";
|
|
187
|
+
readonly type: "tuple[]";
|
|
188
|
+
readonly internalType: "struct WithdrawalOutput[]";
|
|
189
|
+
readonly components: readonly [{
|
|
190
|
+
readonly name: "token";
|
|
191
|
+
readonly type: "address";
|
|
192
|
+
readonly internalType: "address";
|
|
193
|
+
}, {
|
|
194
|
+
readonly name: "isDelayed";
|
|
195
|
+
readonly type: "bool";
|
|
196
|
+
readonly internalType: "bool";
|
|
197
|
+
}, {
|
|
198
|
+
readonly name: "amount";
|
|
199
|
+
readonly type: "uint256";
|
|
200
|
+
readonly internalType: "uint256";
|
|
201
|
+
}];
|
|
202
|
+
}, {
|
|
203
|
+
readonly name: "requestCalls";
|
|
204
|
+
readonly type: "tuple[]";
|
|
205
|
+
readonly internalType: "struct MultiCall[]";
|
|
206
|
+
readonly components: readonly [{
|
|
207
|
+
readonly name: "target";
|
|
208
|
+
readonly type: "address";
|
|
209
|
+
readonly internalType: "address";
|
|
210
|
+
}, {
|
|
211
|
+
readonly name: "callData";
|
|
212
|
+
readonly type: "bytes";
|
|
213
|
+
readonly internalType: "bytes";
|
|
214
|
+
}];
|
|
215
|
+
}, {
|
|
216
|
+
readonly name: "claimableAt";
|
|
217
|
+
readonly type: "uint256";
|
|
218
|
+
readonly internalType: "uint256";
|
|
219
|
+
}];
|
|
220
|
+
}];
|
|
221
|
+
readonly stateMutability: "view";
|
|
145
222
|
}, {
|
|
146
223
|
readonly type: "function";
|
|
147
224
|
readonly name: "getWithdrawalRequestResult";
|