@gearbox-protocol/sdk 14.12.0-next.17 → 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 +9 -55
- 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 +8 -53
- 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 +3 -11
- package/dist/types/sdk/accounts/index.d.ts +1 -0
- package/dist/types/sdk/accounts/types.d.ts +4 -18
- 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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const iMidasIssuanceVaultAdapterV310Abi = [
|
|
2
2
|
{
|
|
3
3
|
type: "function",
|
|
4
4
|
inputs: [],
|
|
@@ -234,5 +234,5 @@ const iMidasIssuanceVaultAdapterAbi = [
|
|
|
234
234
|
}
|
|
235
235
|
];
|
|
236
236
|
export {
|
|
237
|
-
|
|
237
|
+
iMidasIssuanceVaultAdapterV310Abi
|
|
238
238
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const iMidasRedemptionVaultAdapterV310Abi = [
|
|
2
2
|
{
|
|
3
3
|
type: "function",
|
|
4
4
|
inputs: [],
|
|
@@ -361,7 +361,7 @@ const iMidasRedemptionVaultAdapterAbi = [
|
|
|
361
361
|
name: "TokenNotAllowedException"
|
|
362
362
|
}
|
|
363
363
|
];
|
|
364
|
-
const
|
|
364
|
+
const iMidasRedemptionVaultGatewayV310Abi = [
|
|
365
365
|
{
|
|
366
366
|
type: "function",
|
|
367
367
|
inputs: [],
|
|
@@ -592,6 +592,6 @@ const iMidasRedemptionVaultGatewayAbi = [
|
|
|
592
592
|
}
|
|
593
593
|
];
|
|
594
594
|
export {
|
|
595
|
-
|
|
596
|
-
|
|
595
|
+
iMidasRedemptionVaultAdapterV310Abi,
|
|
596
|
+
iMidasRedemptionVaultGatewayV310Abi
|
|
597
597
|
};
|
|
@@ -18,8 +18,9 @@ export * from "./iLidoV1Adapter.js";
|
|
|
18
18
|
export * from "./iMellow4626VaultAdapter.js";
|
|
19
19
|
export * from "./iMellowClaimerAdapter.js";
|
|
20
20
|
export * from "./iMellowWrapperAdapter.js";
|
|
21
|
-
export * from "./
|
|
22
|
-
export * from "./
|
|
21
|
+
export * from "./iMidasGatewayAdapterV311.js";
|
|
22
|
+
export * from "./iMidasIssuanceVaultAdapterV310.js";
|
|
23
|
+
export * from "./iMidasRedemptionVaultAdapterV310.js";
|
|
23
24
|
export * from "./iPendleRouterAdapter.js";
|
|
24
25
|
export * from "./iStakingRewardsAdapter.js";
|
|
25
26
|
export * from "./iTraderJoeRouterAdapter.js";
|
|
@@ -3275,7 +3275,7 @@ const iMellowWrapperAbi = [
|
|
|
3275
3275
|
stateMutability: "nonpayable"
|
|
3276
3276
|
}
|
|
3277
3277
|
];
|
|
3278
|
-
const
|
|
3278
|
+
const iMidasIssuanceVaultV310Abi = [
|
|
3279
3279
|
{
|
|
3280
3280
|
type: "function",
|
|
3281
3281
|
name: "depositInstant",
|
|
@@ -4812,7 +4812,7 @@ export {
|
|
|
4812
4812
|
iKelpLRTWithdrawalManagerGatewayAbi,
|
|
4813
4813
|
iMellowClaimerAbi,
|
|
4814
4814
|
iMellowWrapperAbi,
|
|
4815
|
-
|
|
4815
|
+
iMidasIssuanceVaultV310Abi,
|
|
4816
4816
|
iPendleRouterAbi,
|
|
4817
4817
|
iStakingRewardsAbi,
|
|
4818
4818
|
iTraderJoeRouterAbi,
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import {
|
|
2
|
+
decodeAbiParameters
|
|
3
|
+
} from "viem";
|
|
4
|
+
import {
|
|
5
|
+
MissingSerializedParamsError
|
|
6
|
+
} from "../../../sdk/index.js";
|
|
7
|
+
import {
|
|
8
|
+
iMidasGatewayAdapterV311Abi,
|
|
9
|
+
iMidasGatewayV311Abi
|
|
10
|
+
} from "../abi/adapters/index.js";
|
|
11
|
+
import { AbstractAdapterContract } from "./AbstractAdapter.js";
|
|
12
|
+
const abi = iMidasGatewayAdapterV311Abi;
|
|
13
|
+
const protocolAbi = iMidasGatewayV311Abi;
|
|
14
|
+
class MidasGatewayAdapterContract extends AbstractAdapterContract {
|
|
15
|
+
#gateway;
|
|
16
|
+
#mToken;
|
|
17
|
+
#referrerId;
|
|
18
|
+
#allowedInputTokens;
|
|
19
|
+
#allowedOutputTokens;
|
|
20
|
+
constructor(options, args) {
|
|
21
|
+
super(options, { ...args, abi, protocolAbi });
|
|
22
|
+
if (args.baseParams.serializedParams) {
|
|
23
|
+
const decoded = decodeAbiParameters(
|
|
24
|
+
[
|
|
25
|
+
{ type: "address", name: "creditManager" },
|
|
26
|
+
{ type: "address", name: "targetContract" },
|
|
27
|
+
{ type: "address", name: "gateway" },
|
|
28
|
+
{ type: "address", name: "mToken" },
|
|
29
|
+
{ type: "bytes32", name: "referrerId" },
|
|
30
|
+
{ type: "address[]", name: "allowedInputTokens" },
|
|
31
|
+
{ type: "address[]", name: "allowedOutputTokens" },
|
|
32
|
+
{ type: "address[]", name: "allowedPhantomTokens" }
|
|
33
|
+
],
|
|
34
|
+
args.baseParams.serializedParams
|
|
35
|
+
);
|
|
36
|
+
this.#gateway = decoded[2];
|
|
37
|
+
this.#mToken = decoded[3];
|
|
38
|
+
this.#referrerId = decoded[4];
|
|
39
|
+
this.#allowedInputTokens = [...decoded[5]];
|
|
40
|
+
this.#allowedOutputTokens = decoded[6].map((token, index) => ({
|
|
41
|
+
token,
|
|
42
|
+
phantomToken: decoded[7][index]
|
|
43
|
+
}));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
get gateway() {
|
|
47
|
+
if (!this.#gateway) throw new MissingSerializedParamsError("gateway");
|
|
48
|
+
return this.#gateway;
|
|
49
|
+
}
|
|
50
|
+
get mToken() {
|
|
51
|
+
if (!this.#mToken) throw new MissingSerializedParamsError("mToken");
|
|
52
|
+
return this.#mToken;
|
|
53
|
+
}
|
|
54
|
+
get referrerId() {
|
|
55
|
+
if (this.#referrerId === void 0)
|
|
56
|
+
throw new MissingSerializedParamsError("referrerId");
|
|
57
|
+
return this.#referrerId;
|
|
58
|
+
}
|
|
59
|
+
get allowedInputTokens() {
|
|
60
|
+
if (!this.#allowedInputTokens)
|
|
61
|
+
throw new MissingSerializedParamsError("allowedInputTokens");
|
|
62
|
+
return this.#allowedInputTokens;
|
|
63
|
+
}
|
|
64
|
+
get allowedOutputTokens() {
|
|
65
|
+
if (!this.#allowedOutputTokens)
|
|
66
|
+
throw new MissingSerializedParamsError("allowedOutputTokens");
|
|
67
|
+
return this.#allowedOutputTokens;
|
|
68
|
+
}
|
|
69
|
+
stateHuman(raw) {
|
|
70
|
+
return {
|
|
71
|
+
...super.stateHuman(raw),
|
|
72
|
+
gateway: this.#gateway ? this.labelAddress(this.#gateway) : void 0,
|
|
73
|
+
mToken: this.#mToken ? this.labelAddress(this.#mToken) : void 0,
|
|
74
|
+
referrerId: this.#referrerId,
|
|
75
|
+
allowedInputTokens: this.#allowedInputTokens?.map(
|
|
76
|
+
(t) => this.labelAddress(t)
|
|
77
|
+
),
|
|
78
|
+
allowedOutputTokens: this.#allowedOutputTokens?.map((t) => ({
|
|
79
|
+
token: this.labelAddress(t.token),
|
|
80
|
+
phantomToken: this.labelAddress(t.phantomToken)
|
|
81
|
+
}))
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
decodeDiffLeftovers(decoded, balances) {
|
|
85
|
+
switch (decoded.functionName) {
|
|
86
|
+
case "depositInstantDiff": {
|
|
87
|
+
const [tokenIn, leftoverAmount] = decoded.args;
|
|
88
|
+
return [{ tokenIn, leftoverAmount }];
|
|
89
|
+
}
|
|
90
|
+
// redemptions spend the mToken down to the leftover, tokenOut arg is
|
|
91
|
+
// the received token
|
|
92
|
+
case "redeemInstantDiff":
|
|
93
|
+
case "redeemRequestDiff": {
|
|
94
|
+
const [, leftoverAmount] = decoded.args;
|
|
95
|
+
return [{ tokenIn: this.mToken, leftoverAmount }];
|
|
96
|
+
}
|
|
97
|
+
default:
|
|
98
|
+
return super.decodeDiffLeftovers(decoded, balances);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
export {
|
|
103
|
+
MidasGatewayAdapterContract
|
|
104
|
+
};
|
|
@@ -4,11 +4,11 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
MissingSerializedParamsError
|
|
6
6
|
} from "../../../sdk/index.js";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { iMidasIssuanceVaultAdapterV310Abi } from "../abi/adapters/index.js";
|
|
8
|
+
import { iMidasIssuanceVaultV310Abi } from "../abi/targetContractAbi.js";
|
|
9
9
|
import { AbstractAdapterContract } from "./AbstractAdapter.js";
|
|
10
|
-
const abi =
|
|
11
|
-
const protocolAbi =
|
|
10
|
+
const abi = iMidasIssuanceVaultAdapterV310Abi;
|
|
11
|
+
const protocolAbi = iMidasIssuanceVaultV310Abi;
|
|
12
12
|
class MidasIssuanceVaultAdapterContract extends AbstractAdapterContract {
|
|
13
13
|
#mToken;
|
|
14
14
|
#referrerId;
|
|
@@ -5,12 +5,12 @@ import {
|
|
|
5
5
|
MissingSerializedParamsError
|
|
6
6
|
} from "../../../sdk/index.js";
|
|
7
7
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
iMidasRedemptionVaultAdapterV310Abi,
|
|
9
|
+
iMidasRedemptionVaultGatewayV310Abi
|
|
10
10
|
} from "../abi/adapters/index.js";
|
|
11
11
|
import { AbstractAdapterContract } from "./AbstractAdapter.js";
|
|
12
|
-
const abi =
|
|
13
|
-
const protocolAbi =
|
|
12
|
+
const abi = iMidasRedemptionVaultAdapterV310Abi;
|
|
13
|
+
const protocolAbi = iMidasRedemptionVaultGatewayV310Abi;
|
|
14
14
|
class MidasRedemptionVaultAdapterContract extends AbstractAdapterContract {
|
|
15
15
|
#gateway;
|
|
16
16
|
#mToken;
|
|
@@ -23,6 +23,7 @@ export * from "./MellowClaimerAdapterContract.js";
|
|
|
23
23
|
export * from "./MellowDVVAdapterContract.js";
|
|
24
24
|
export * from "./MellowERC4626VaultAdapterContract.js";
|
|
25
25
|
export * from "./MellowWrapperAdapterContract.js";
|
|
26
|
+
export * from "./MidasGatewayAdapterContract.js";
|
|
26
27
|
export * from "./MidasIssuanceVaultAdapterContract.js";
|
|
27
28
|
export * from "./MidasRedemptionVaultAdapterContract.js";
|
|
28
29
|
export * from "./PendleRouterAdapterContract.js";
|
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
MellowDVVAdapterContract,
|
|
27
27
|
MellowERC4626VaultAdapterContract,
|
|
28
28
|
MellowWrapperAdapterContract,
|
|
29
|
+
MidasGatewayAdapterContract,
|
|
29
30
|
MidasIssuanceVaultAdapterContract,
|
|
30
31
|
MidasRedemptionVaultAdapterContract,
|
|
31
32
|
PendleRouterAdapterContract,
|
|
@@ -94,6 +95,8 @@ function createAdapter(options, data, strict) {
|
|
|
94
95
|
return new MellowERC4626VaultAdapterContract(options, data);
|
|
95
96
|
case "ADAPTER::MELLOW_WRAPPER":
|
|
96
97
|
return new MellowWrapperAdapterContract(options, data);
|
|
98
|
+
case "ADAPTER::MIDAS_GATEWAY":
|
|
99
|
+
return new MidasGatewayAdapterContract(options, data);
|
|
97
100
|
case "ADAPTER::MIDAS_ISSUANCE_VAULT":
|
|
98
101
|
return new MidasIssuanceVaultAdapterContract(options, data);
|
|
99
102
|
case "ADAPTER::MIDAS_REDEMPTION_VAULT":
|
|
@@ -24,6 +24,7 @@ var AdapterType = /* @__PURE__ */ ((AdapterType2) => {
|
|
|
24
24
|
AdapterType2["MELLOW_DVV"] = "MELLOW_DVV";
|
|
25
25
|
AdapterType2["MELLOW_ERC4626_VAULT"] = "MELLOW_ERC4626_VAULT";
|
|
26
26
|
AdapterType2["MELLOW_WRAPPER"] = "MELLOW_WRAPPER";
|
|
27
|
+
AdapterType2["MIDAS_GATEWAY"] = "MIDAS_GATEWAY";
|
|
27
28
|
AdapterType2["MIDAS_ISSUANCE_VAULT"] = "MIDAS_ISSUANCE_VAULT";
|
|
28
29
|
AdapterType2["MIDAS_REDEMPTION_VAULT"] = "MIDAS_REDEMPTION_VAULT";
|
|
29
30
|
AdapterType2["PENDLE_ROUTER"] = "PENDLE_ROUTER";
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import { iWithdrawalCompressorV310Abi } from "../../abi/IWithdrawalCompressorV310.js";
|
|
2
|
-
import { iWithdrawalCompressorV311Abi } from "../../abi/IWithdrawalCompressorV311.js";
|
|
3
1
|
import {
|
|
4
2
|
AddressMap,
|
|
5
|
-
BasePlugin
|
|
6
|
-
getWithdrawalCompressorAddress
|
|
3
|
+
BasePlugin
|
|
7
4
|
} from "../../sdk/index.js";
|
|
8
5
|
const MAP_LABEL = "delayedWithdrawal";
|
|
9
6
|
class DelayedWithdrawalPlugin extends BasePlugin {
|
|
@@ -12,44 +9,29 @@ class DelayedWithdrawalPlugin extends BasePlugin {
|
|
|
12
9
|
if (!force && this.loaded) {
|
|
13
10
|
return this.state;
|
|
14
11
|
}
|
|
15
|
-
|
|
12
|
+
this.#withdrawableAssets = new AddressMap(void 0, MAP_LABEL);
|
|
13
|
+
const compressor = this.sdk.withdrawalCompressor();
|
|
16
14
|
this.sdk.logger?.debug(
|
|
17
|
-
`loading delayed withdrawal plugin with compressor ${compressor}`
|
|
15
|
+
`loading delayed withdrawal plugin with compressor ${compressor.address}`
|
|
18
16
|
);
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
const resp = await compressor.getWithdrawableAssetsBatch();
|
|
18
|
+
const byCreditManager = /* @__PURE__ */ new Map();
|
|
19
|
+
for (const cfg of resp) {
|
|
20
|
+
const assets = byCreditManager.get(cfg.creditManager) ?? [];
|
|
21
|
+
assets.push({
|
|
22
|
+
...cfg,
|
|
23
|
+
disabled: isConfigToOmit({
|
|
24
|
+
creditManager: cfg.creditManager,
|
|
25
|
+
token: cfg.token,
|
|
26
|
+
withdrawalPhantomToken: cfg.withdrawalPhantomToken,
|
|
27
|
+
underlying: cfg.underlying
|
|
27
28
|
})
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const cm = creditManagers[index];
|
|
35
|
-
if (r.status === "success" && r.result?.length > 0) {
|
|
36
|
-
const configsToShow = r.result;
|
|
37
|
-
this.#withdrawableAssets?.upsert(
|
|
38
|
-
cm.creditManager.address,
|
|
39
|
-
configsToShow.map((cfg) => ({
|
|
40
|
-
...cfg,
|
|
41
|
-
creditManager: cm.creditManager.address,
|
|
42
|
-
disabled: isConfigToOmit({
|
|
43
|
-
creditManager: cm.creditManager.address,
|
|
44
|
-
token: cfg.token,
|
|
45
|
-
withdrawalPhantomToken: cfg.withdrawalPhantomToken,
|
|
46
|
-
underlying: cfg.underlying
|
|
47
|
-
})
|
|
48
|
-
}))
|
|
49
|
-
);
|
|
50
|
-
} else {
|
|
51
|
-
}
|
|
52
|
-
});
|
|
29
|
+
});
|
|
30
|
+
byCreditManager.set(cfg.creditManager, assets);
|
|
31
|
+
}
|
|
32
|
+
for (const [creditManager, assets] of byCreditManager) {
|
|
33
|
+
this.#withdrawableAssets.upsert(creditManager, assets);
|
|
34
|
+
}
|
|
53
35
|
return this.state;
|
|
54
36
|
}
|
|
55
37
|
get loaded() {
|
|
@@ -5,7 +5,8 @@ import {
|
|
|
5
5
|
parseEventLogs
|
|
6
6
|
} from "viem";
|
|
7
7
|
import {
|
|
8
|
-
CreditAccountsServiceV310
|
|
8
|
+
CreditAccountsServiceV310,
|
|
9
|
+
createWithdrawalCompressor
|
|
9
10
|
} from "./accounts/index.js";
|
|
10
11
|
import { ChainContractsRegister } from "./base/index.js";
|
|
11
12
|
import { getChain } from "./chain/index.js";
|
|
@@ -534,6 +535,17 @@ class OnchainSDK extends ChainContractsRegister {
|
|
|
534
535
|
const [routerAddr, routerV] = routerEntry;
|
|
535
536
|
return createRouter(this, routerAddr, routerV);
|
|
536
537
|
}
|
|
538
|
+
/**
|
|
539
|
+
* Lazily returns a withdrawal compressor contract for the current chain.
|
|
540
|
+
*
|
|
541
|
+
* @param version - Desired compressor version; when omitted, the latest
|
|
542
|
+
* version supported on the current chain is used.
|
|
543
|
+
* @throws If no withdrawal compressor of the given version is supported
|
|
544
|
+
* on the current chain.
|
|
545
|
+
**/
|
|
546
|
+
withdrawalCompressor(version) {
|
|
547
|
+
return createWithdrawalCompressor(this, version);
|
|
548
|
+
}
|
|
537
549
|
}
|
|
538
550
|
export {
|
|
539
551
|
OnchainSDK,
|
|
@@ -6,13 +6,10 @@ import {
|
|
|
6
6
|
import { creditAccountCompressorAbi } from "../../abi/compressors/creditAccountCompressor.js";
|
|
7
7
|
import { peripheryCompressorAbi } from "../../abi/compressors/peripheryCompressor.js";
|
|
8
8
|
import { rewardsCompressorAbi } from "../../abi/compressors/rewardsCompressor.js";
|
|
9
|
-
import { iWithdrawalCompressorV310Abi } from "../../abi/IWithdrawalCompressorV310.js";
|
|
10
|
-
import { iWithdrawalCompressorV311Abi } from "../../abi/IWithdrawalCompressorV311.js";
|
|
11
9
|
import { iBaseRewardPoolAbi } from "../../abi/iBaseRewardPool.js";
|
|
12
10
|
import { ierc4626AdapterAbi } from "../../abi/ierc4626Adapter.js";
|
|
13
11
|
import { iRWAFactoryAbi } from "../../abi/rwa/iRWAFactory.js";
|
|
14
12
|
import { SDKConstruct } from "../base/index.js";
|
|
15
|
-
import { chains } from "../chain/chains.js";
|
|
16
13
|
import {
|
|
17
14
|
ADDRESS_0X0,
|
|
18
15
|
AP_CREDIT_ACCOUNT_COMPRESSOR,
|
|
@@ -34,19 +31,6 @@ import {
|
|
|
34
31
|
extractQuotaTokens,
|
|
35
32
|
mergePriceUpdates
|
|
36
33
|
} from "./multicall-utils.js";
|
|
37
|
-
const COMPRESSORS = {
|
|
38
|
-
[chains.Mainnet.id]: {
|
|
39
|
-
address: "0x36F3d0Bb73CBC2E94fE24dF0f26a689409cF9023",
|
|
40
|
-
version: 310
|
|
41
|
-
},
|
|
42
|
-
[chains.Monad.id]: {
|
|
43
|
-
address: "0x36F3d0Bb73CBC2E94fE24dF0f26a689409cF9023",
|
|
44
|
-
version: 310
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
function getWithdrawalCompressorAddress(chainId) {
|
|
48
|
-
return COMPRESSORS[chainId];
|
|
49
|
-
}
|
|
50
34
|
class CreditAccountsServiceV310 extends SDKConstruct {
|
|
51
35
|
#compressor;
|
|
52
36
|
#batchSize;
|
|
@@ -797,22 +781,8 @@ class CreditAccountsServiceV310 extends SDKConstruct {
|
|
|
797
781
|
amount,
|
|
798
782
|
token
|
|
799
783
|
}) {
|
|
800
|
-
const compressor =
|
|
801
|
-
|
|
802
|
-
throw new Error(
|
|
803
|
-
`No compressor for current chain ${this.sdk.networkType}`
|
|
804
|
-
);
|
|
805
|
-
const contract = getContract({
|
|
806
|
-
address: compressor.address,
|
|
807
|
-
abi: compressor.version === 310 ? iWithdrawalCompressorV310Abi : iWithdrawalCompressorV311Abi,
|
|
808
|
-
client: this.client
|
|
809
|
-
});
|
|
810
|
-
const resp = await contract.read.getWithdrawalRequestResult([
|
|
811
|
-
creditAccount,
|
|
812
|
-
token,
|
|
813
|
-
amount
|
|
814
|
-
]);
|
|
815
|
-
return resp;
|
|
784
|
+
const compressor = this.sdk.withdrawalCompressor();
|
|
785
|
+
return compressor.getWithdrawalRequestResult(creditAccount, token, amount);
|
|
816
786
|
}
|
|
817
787
|
/**
|
|
818
788
|
* {@inheritDoc ICreditAccountsService.getPendingWithdrawals}
|
|
@@ -820,26 +790,12 @@ class CreditAccountsServiceV310 extends SDKConstruct {
|
|
|
820
790
|
async getPendingWithdrawals({
|
|
821
791
|
creditAccount
|
|
822
792
|
}) {
|
|
823
|
-
const compressor =
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
const contract = getContract({
|
|
829
|
-
address: compressor.address,
|
|
830
|
-
abi: compressor.version === 310 ? iWithdrawalCompressorV310Abi : iWithdrawalCompressorV311Abi,
|
|
831
|
-
client: this.client
|
|
832
|
-
});
|
|
833
|
-
const resp = await contract.read.getCurrentWithdrawals([creditAccount]);
|
|
834
|
-
const claimableNow = resp?.[0] || [];
|
|
835
|
-
const pendingResult = [...resp?.[1] || []].sort(
|
|
836
|
-
(a, b) => a.claimableAt < b.claimableAt ? -1 : 1
|
|
837
|
-
);
|
|
838
|
-
const respResult = {
|
|
839
|
-
claimableNow: [...claimableNow],
|
|
840
|
-
pending: pendingResult
|
|
793
|
+
const compressor = this.sdk.withdrawalCompressor();
|
|
794
|
+
const { claimable, pending } = await compressor.getCurrentWithdrawals(creditAccount);
|
|
795
|
+
return {
|
|
796
|
+
claimableNow: claimable,
|
|
797
|
+
pending
|
|
841
798
|
};
|
|
842
|
-
return respResult;
|
|
843
799
|
}
|
|
844
800
|
/**
|
|
845
801
|
* {@inheritDoc ICreditAccountsService.startDelayedWithdrawal}
|
|
@@ -1873,6 +1829,5 @@ class CreditAccountsServiceV310 extends SDKConstruct {
|
|
|
1873
1829
|
}
|
|
1874
1830
|
}
|
|
1875
1831
|
export {
|
|
1876
|
-
CreditAccountsServiceV310
|
|
1877
|
-
getWithdrawalCompressorAddress
|
|
1832
|
+
CreditAccountsServiceV310
|
|
1878
1833
|
};
|
|
@@ -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
|
+
};
|