@gearbox-protocol/sdk 10.2.9 → 10.3.0

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.
Files changed (24) hide show
  1. package/dist/cjs/abi/IWithdrawalCompressorV310.js +184 -0
  2. package/dist/cjs/permissionless/utils/price-update/get-prices.js +3 -0
  3. package/dist/cjs/plugins/delayed-withdrawal/DelayedWithdrawalPlugin.js +105 -0
  4. package/dist/cjs/plugins/delayed-withdrawal/index.js +24 -0
  5. package/dist/cjs/plugins/delayed-withdrawal/package.json +1 -0
  6. package/dist/cjs/plugins/delayed-withdrawal/types.js +16 -0
  7. package/dist/cjs/sdk/accountMigration/AbstractMigrateCreditAccountsService.js +4 -6
  8. package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +102 -84
  9. package/dist/esm/abi/IWithdrawalCompressorV310.js +160 -0
  10. package/dist/esm/permissionless/utils/price-update/get-prices.js +3 -0
  11. package/dist/esm/plugins/delayed-withdrawal/DelayedWithdrawalPlugin.js +85 -0
  12. package/dist/esm/plugins/delayed-withdrawal/index.js +2 -0
  13. package/dist/esm/plugins/delayed-withdrawal/package.json +1 -0
  14. package/dist/esm/plugins/delayed-withdrawal/types.js +0 -0
  15. package/dist/esm/sdk/accountMigration/AbstractMigrateCreditAccountsService.js +4 -6
  16. package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +99 -82
  17. package/dist/types/abi/IWithdrawalCompressorV310.d.ts +208 -0
  18. package/dist/types/plugins/delayed-withdrawal/DelayedWithdrawalPlugin.d.ts +20 -0
  19. package/dist/types/plugins/delayed-withdrawal/index.d.ts +2 -0
  20. package/dist/types/plugins/delayed-withdrawal/types.d.ts +10 -0
  21. package/dist/types/sdk/accountMigration/AbstractMigrateCreditAccountsService.d.ts +1 -1
  22. package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +16 -3
  23. package/dist/types/sdk/accounts/types.d.ts +42 -20
  24. package/package.json +1 -1
@@ -0,0 +1,208 @@
1
+ export declare const iWithdrawalCompressorV310Abi: readonly [{
2
+ readonly type: "function";
3
+ readonly inputs: readonly [];
4
+ readonly name: "contractType";
5
+ readonly outputs: readonly [{
6
+ readonly name: "";
7
+ readonly internalType: "bytes32";
8
+ readonly type: "bytes32";
9
+ }];
10
+ readonly stateMutability: "view";
11
+ }, {
12
+ readonly type: "function";
13
+ readonly inputs: readonly [{
14
+ readonly name: "creditAccount";
15
+ readonly internalType: "address";
16
+ readonly type: "address";
17
+ }];
18
+ readonly name: "getCurrentWithdrawals";
19
+ readonly outputs: readonly [{
20
+ readonly name: "";
21
+ readonly internalType: "struct ClaimableWithdrawal[]";
22
+ readonly type: "tuple[]";
23
+ readonly components: readonly [{
24
+ readonly name: "token";
25
+ readonly internalType: "address";
26
+ readonly type: "address";
27
+ }, {
28
+ readonly name: "withdrawalPhantomToken";
29
+ readonly internalType: "address";
30
+ readonly type: "address";
31
+ }, {
32
+ readonly name: "withdrawalTokenSpent";
33
+ readonly internalType: "uint256";
34
+ readonly type: "uint256";
35
+ }, {
36
+ readonly name: "outputs";
37
+ readonly internalType: "struct WithdrawalOutput[]";
38
+ readonly type: "tuple[]";
39
+ readonly components: readonly [{
40
+ readonly name: "token";
41
+ readonly internalType: "address";
42
+ readonly type: "address";
43
+ }, {
44
+ readonly name: "isDelayed";
45
+ readonly internalType: "bool";
46
+ readonly type: "bool";
47
+ }, {
48
+ readonly name: "amount";
49
+ readonly internalType: "uint256";
50
+ readonly type: "uint256";
51
+ }];
52
+ }, {
53
+ readonly name: "claimCalls";
54
+ readonly internalType: "struct MultiCall[]";
55
+ readonly type: "tuple[]";
56
+ readonly components: readonly [{
57
+ readonly name: "target";
58
+ readonly internalType: "address";
59
+ readonly type: "address";
60
+ }, {
61
+ readonly name: "callData";
62
+ readonly internalType: "bytes";
63
+ readonly type: "bytes";
64
+ }];
65
+ }];
66
+ }, {
67
+ readonly name: "";
68
+ readonly internalType: "struct PendingWithdrawal[]";
69
+ readonly type: "tuple[]";
70
+ readonly components: readonly [{
71
+ readonly name: "token";
72
+ readonly internalType: "address";
73
+ readonly type: "address";
74
+ }, {
75
+ readonly name: "withdrawalPhantomToken";
76
+ readonly internalType: "address";
77
+ readonly type: "address";
78
+ }, {
79
+ readonly name: "expectedOutputs";
80
+ readonly internalType: "struct WithdrawalOutput[]";
81
+ readonly type: "tuple[]";
82
+ readonly components: readonly [{
83
+ readonly name: "token";
84
+ readonly internalType: "address";
85
+ readonly type: "address";
86
+ }, {
87
+ readonly name: "isDelayed";
88
+ readonly internalType: "bool";
89
+ readonly type: "bool";
90
+ }, {
91
+ readonly name: "amount";
92
+ readonly internalType: "uint256";
93
+ readonly type: "uint256";
94
+ }];
95
+ }, {
96
+ readonly name: "claimableAt";
97
+ readonly internalType: "uint256";
98
+ readonly type: "uint256";
99
+ }];
100
+ }];
101
+ readonly stateMutability: "view";
102
+ }, {
103
+ readonly type: "function";
104
+ readonly inputs: readonly [{
105
+ readonly name: "creditManager";
106
+ readonly internalType: "address";
107
+ readonly type: "address";
108
+ }];
109
+ readonly name: "getWithdrawableAssets";
110
+ readonly outputs: readonly [{
111
+ readonly name: "";
112
+ readonly internalType: "struct WithdrawableAsset[]";
113
+ readonly type: "tuple[]";
114
+ readonly components: readonly [{
115
+ readonly name: "token";
116
+ readonly internalType: "address";
117
+ readonly type: "address";
118
+ }, {
119
+ readonly name: "withdrawalPhantomToken";
120
+ readonly internalType: "address";
121
+ readonly type: "address";
122
+ }, {
123
+ readonly name: "underlying";
124
+ readonly internalType: "address";
125
+ readonly type: "address";
126
+ }, {
127
+ readonly name: "withdrawalLength";
128
+ readonly internalType: "uint256";
129
+ readonly type: "uint256";
130
+ }];
131
+ }];
132
+ readonly stateMutability: "view";
133
+ }, {
134
+ readonly type: "function";
135
+ readonly inputs: readonly [{
136
+ readonly name: "creditAccount";
137
+ readonly internalType: "address";
138
+ readonly type: "address";
139
+ }, {
140
+ readonly name: "token";
141
+ readonly internalType: "address";
142
+ readonly type: "address";
143
+ }, {
144
+ readonly name: "amount";
145
+ readonly internalType: "uint256";
146
+ readonly type: "uint256";
147
+ }];
148
+ readonly name: "getWithdrawalRequestResult";
149
+ readonly outputs: readonly [{
150
+ readonly name: "";
151
+ readonly internalType: "struct RequestableWithdrawal";
152
+ readonly type: "tuple";
153
+ readonly components: readonly [{
154
+ readonly name: "token";
155
+ readonly internalType: "address";
156
+ readonly type: "address";
157
+ }, {
158
+ readonly name: "amountIn";
159
+ readonly internalType: "uint256";
160
+ readonly type: "uint256";
161
+ }, {
162
+ readonly name: "outputs";
163
+ readonly internalType: "struct WithdrawalOutput[]";
164
+ readonly type: "tuple[]";
165
+ readonly components: readonly [{
166
+ readonly name: "token";
167
+ readonly internalType: "address";
168
+ readonly type: "address";
169
+ }, {
170
+ readonly name: "isDelayed";
171
+ readonly internalType: "bool";
172
+ readonly type: "bool";
173
+ }, {
174
+ readonly name: "amount";
175
+ readonly internalType: "uint256";
176
+ readonly type: "uint256";
177
+ }];
178
+ }, {
179
+ readonly name: "requestCalls";
180
+ readonly internalType: "struct MultiCall[]";
181
+ readonly type: "tuple[]";
182
+ readonly components: readonly [{
183
+ readonly name: "target";
184
+ readonly internalType: "address";
185
+ readonly type: "address";
186
+ }, {
187
+ readonly name: "callData";
188
+ readonly internalType: "bytes";
189
+ readonly type: "bytes";
190
+ }];
191
+ }, {
192
+ readonly name: "claimableAt";
193
+ readonly internalType: "uint256";
194
+ readonly type: "uint256";
195
+ }];
196
+ }];
197
+ readonly stateMutability: "view";
198
+ }, {
199
+ readonly type: "function";
200
+ readonly inputs: readonly [];
201
+ readonly name: "version";
202
+ readonly outputs: readonly [{
203
+ readonly name: "";
204
+ readonly internalType: "uint256";
205
+ readonly type: "uint256";
206
+ }];
207
+ readonly stateMutability: "view";
208
+ }];
@@ -0,0 +1,20 @@
1
+ import type { Address } from "viem";
2
+ import type { IGearboxSDKPlugin } from "../../sdk/index.js";
3
+ import { AddressMap, BasePlugin } from "../../sdk/index.js";
4
+ import type { WithdrawableAsset, WithdrawableAssetStateHuman } from "./types.js";
5
+ export interface DelayedWithdrawalPluginState {
6
+ withdrawableAssets: Record<Address, Array<WithdrawableAsset>>;
7
+ }
8
+ export declare class DelayedWithdrawalPlugin extends BasePlugin<DelayedWithdrawalPluginState> implements IGearboxSDKPlugin<DelayedWithdrawalPluginState> {
9
+ #private;
10
+ load(force?: boolean): Promise<DelayedWithdrawalPluginState>;
11
+ get loaded(): boolean;
12
+ /**
13
+ * Returns a map of cmAddress -> array of delayed assets
14
+ * @throws if plugin is not attached
15
+ */
16
+ get withdrawableAssets(): AddressMap<Array<WithdrawableAsset>>;
17
+ stateHuman(_?: boolean): WithdrawableAssetStateHuman[];
18
+ get state(): DelayedWithdrawalPluginState;
19
+ hydrate(state: DelayedWithdrawalPluginState): void;
20
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./DelayedWithdrawalPlugin.js";
2
+ export * from "./types.js";
@@ -0,0 +1,10 @@
1
+ import type { Address, GetContractReturnType, PublicClient } from "viem";
2
+ import type { iWithdrawalCompressorV310Abi } from "../../abi/IWithdrawalCompressorV310.js";
3
+ import type { BaseContractStateHuman } from "../../sdk/index.js";
4
+ type WithdrawalCompressorV310InstanceType = GetContractReturnType<typeof iWithdrawalCompressorV310Abi, PublicClient>;
5
+ export type WithdrawableAsset = Awaited<ReturnType<WithdrawalCompressorV310InstanceType["read"]["getWithdrawableAssets"]>>[number] & {
6
+ creditManager: Address;
7
+ };
8
+ export interface WithdrawableAssetStateHuman extends WithdrawableAsset, BaseContractStateHuman {
9
+ }
10
+ export {};
@@ -35,5 +35,5 @@ export declare abstract class AbstractMigrateCreditAccountsService extends SDKCo
35
35
  };
36
36
  static getTokensAfterMigration<T extends Asset>(balances: Array<T> | Record<Address, T>, chainId: number): Array<T>;
37
37
  static checkSourceCreditManager(sourceCreditManager: Address, migrationBot: Address, sdk: GearboxSDK): boolean;
38
- static isSourceMigratableToTargetCM(targetTokensToMigrate: Array<Asset>, source: CreditAccountData_Legacy, target: CreditManagerData_Legacy, delayedPhantoms: Record<Address, object>, sdk: GearboxSDK): boolean;
38
+ static isSourceMigratableToTargetCM(targetTokensToMigrate: Array<Asset>, source: CreditAccountData_Legacy, target: CreditManagerData_Legacy, delayedPhantoms: Record<Address, boolean>, sdk: GearboxSDK): boolean;
39
39
  }
@@ -5,10 +5,11 @@ import type { GearboxSDK } from "../GearboxSDK.js";
5
5
  import type { OnDemandPriceUpdates, PriceUpdateV300, PriceUpdateV310, UpdatePriceFeedsResult } from "../market/index.js";
6
6
  import { type Asset, type RouterCASlice } from "../router/index.js";
7
7
  import type { MultiCall } from "../types/index.js";
8
- import type { AddCollateralProps, ChangeDeptProps, ClaimDelayedProps, CloseCreditAccountProps, CloseCreditAccountResult, CreditAccountOperationResult, EnableTokensProps, ExecuteSwapProps, FullyLiquidateProps, GetConnectedBotsResult, GetConnectedMigrationBotsResult, GetCreditAccountsOptions, OpenCAProps, PermitResult, PrepareUpdateQuotasProps, PriceUpdatesOptions, Rewards, StartDelayedWithdrawalProps, UpdateQuotasProps } from "./types.js";
8
+ import type { AddCollateralProps, ChangeDeptProps, ClaimDelayedProps, CloseCreditAccountProps, CloseCreditAccountResult, CreditAccountOperationResult, EnableTokensProps, ExecuteSwapProps, FullyLiquidateProps, GetConnectedBotsResult, GetConnectedMigrationBotsResult, GetCreditAccountsOptions, GetPendingWithdrawalsProps, GetPendingWithdrawalsResult, OpenCAProps, PermitResult, PrepareUpdateQuotasProps, PreviewDelayedWithdrawalProps, PreviewDelayedWithdrawalResult, PriceUpdatesOptions, Rewards, StartDelayedWithdrawalProps, UpdateQuotasProps } from "./types.js";
9
9
  export interface CreditAccountServiceOptions {
10
10
  batchSize?: number;
11
11
  }
12
+ export declare function getWithdrawalCompressorAddress(chainId: number): "0xfB79b6713fe214B8748ED7b0db1f93E4f1aC9d29" | undefined;
12
13
  export declare abstract class AbstractCreditAccountService extends SDKConstruct {
13
14
  #private;
14
15
  constructor(sdk: GearboxSDK, options?: CreditAccountServiceOptions);
@@ -115,20 +116,32 @@ export declare abstract class AbstractCreditAccountService extends SDKConstruct
115
116
  * @returns All necessary data to execute the transaction (call, credit facade)
116
117
  */
117
118
  executeSwap({ creditAccount, calls: swapCalls, minQuota, averageQuota, }: ExecuteSwapProps): Promise<CreditAccountOperationResult>;
119
+ /**
120
+ * Preview delayed withdrawal for given token
121
+ * @param props - {@link PreviewDelayedWithdrawalProps}
122
+ * @returns
123
+ */
124
+ previewDelayedWithdrawal({ creditAccount, amount, token, }: PreviewDelayedWithdrawalProps): Promise<PreviewDelayedWithdrawalResult>;
125
+ /**
126
+ * Get claimable and pending withdrawals of an account
127
+ * @param props - {@link GetPendingWithdrawalsProps}
128
+ * @returns
129
+ */
130
+ getPendingWithdrawals({ creditAccount, }: GetPendingWithdrawalsProps): Promise<GetPendingWithdrawalsResult>;
118
131
  /**
119
132
  * Start delayed withdrawal for given token
120
133
  - Withdrawal is executed in the following order: price update -> execute withdraw calls -> update quotas
121
134
  * @param props - {@link StartDelayedWithdrawalProps}
122
135
  * @returns
123
136
  */
124
- startDelayedWithdrawal_Mellow({ creditAccount, minQuota, averageQuota, instantWithdrawals, delayedWithdrawals, sourceAmount, sourceToken, }: StartDelayedWithdrawalProps): Promise<CreditAccountOperationResult>;
137
+ startDelayedWithdrawal({ creditAccount, minQuota, averageQuota, preview, }: StartDelayedWithdrawalProps): Promise<CreditAccountOperationResult>;
125
138
  /**
126
139
  * Claim tokens with delayed withdrawal
127
140
  - Claim is executed in the following order: price update -> execute claim calls -> update quotas
128
141
  * @param props - {@link ClaimDelayedProps}
129
142
  * @returns
130
143
  */
131
- claimDelayed_Mellow({ creditAccount, minQuota, averageQuota, sourceToken, phantom, target, }: ClaimDelayedProps): Promise<CreditAccountOperationResult>;
144
+ claimDelayed({ creditAccount, minQuota, averageQuota, claimableNow, }: ClaimDelayedProps): Promise<CreditAccountOperationResult>;
132
145
  /**
133
146
  * Executes enable/disable tokens specified by given tokens lists and token prices
134
147
  * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
@@ -1,5 +1,6 @@
1
- import type { Address, ContractFunctionArgs } from "viem";
1
+ import type { Address, ContractFunctionArgs, GetContractReturnType, PublicClient } from "viem";
2
2
  import type { creditAccountCompressorAbi } from "../../abi/compressors/creditAccountCompressor.js";
3
+ import type { iWithdrawalCompressorV310Abi } from "../../abi/IWithdrawalCompressorV310.js";
3
4
  import type { LiquidationBotType as LiquidationBotTypeSDK } from "../../plugins/bots/types.js";
4
5
  import type { MigrationBotType } from "../accountMigration/types.js";
5
6
  import type { ConnectedBotData, CreditAccountData } from "../base/index.js";
@@ -168,41 +169,50 @@ export interface ExecuteSwapProps extends PrepareUpdateQuotasProps {
168
169
  */
169
170
  creditAccount: RouterCASlice;
170
171
  }
171
- export interface StartDelayedWithdrawalProps extends PrepareUpdateQuotasProps {
172
+ export interface PreviewDelayedWithdrawalProps {
172
173
  /**
173
174
  * Amount of source token (ex. cp0xlrt)
174
175
  */
175
- sourceAmount: bigint;
176
+ amount: bigint;
176
177
  /**
177
178
  * Address of source token (ex. cp0xlrt)
178
179
  */
179
- sourceToken: Address;
180
- /**
181
- * Array of token which can be instantly withdrawn
182
- */
183
- instantWithdrawals: Array<Asset>;
180
+ token: Address;
184
181
  /**
185
- * Array of token which will be withdrawn with a delay
182
+ * Minimal credit account data on which operation is performed
186
183
  */
187
- delayedWithdrawals: Array<Asset>;
184
+ creditAccount: Address;
185
+ }
186
+ export interface GetPendingWithdrawalsProps {
188
187
  /**
189
188
  * Minimal credit account data on which operation is performed
190
189
  */
191
- creditAccount: RouterCASlice;
190
+ creditAccount: Address;
192
191
  }
193
- export interface ClaimDelayedProps extends PrepareUpdateQuotasProps {
192
+ type WithdrawalCompressorV310InstanceType = GetContractReturnType<typeof iWithdrawalCompressorV310Abi, PublicClient>;
193
+ export type PreviewDelayedWithdrawalResult = Awaited<ReturnType<WithdrawalCompressorV310InstanceType["read"]["getWithdrawalRequestResult"]>>;
194
+ type PendingWithdrawalResult = Awaited<ReturnType<WithdrawalCompressorV310InstanceType["read"]["getCurrentWithdrawals"]>>;
195
+ export type PendingWithdrawal = PendingWithdrawalResult[1][number];
196
+ export type ClaimableWithdrawal = PendingWithdrawalResult[0][number];
197
+ export interface GetPendingWithdrawalsResult {
198
+ claimableNow: Array<ClaimableWithdrawal>;
199
+ pending: Array<PendingWithdrawal>;
200
+ }
201
+ export interface StartDelayedWithdrawalProps extends PrepareUpdateQuotasProps {
194
202
  /**
195
- * Address of source token (ex. sp0xlrt)
203
+ * Withdrawal preview
196
204
  */
197
- sourceToken: Address;
205
+ preview: PreviewDelayedWithdrawalResult;
198
206
  /**
199
- * Amount of phantom token
207
+ * Minimal credit account data on which operation is performed
200
208
  */
201
- phantom: Asset;
209
+ creditAccount: RouterCASlice;
210
+ }
211
+ export interface ClaimDelayedProps extends PrepareUpdateQuotasProps {
202
212
  /**
203
- * Amount of target token
213
+ * assets claimable now from getPendingWithdrawals
204
214
  */
205
- target: Asset;
215
+ claimableNow: GetPendingWithdrawalsResult["claimableNow"][number];
206
216
  /**
207
217
  * Minimal credit account data on which operation is performed
208
218
  */
@@ -486,14 +496,26 @@ export interface ICreditAccountsService extends SDKConstruct {
486
496
  * @param props - {@link StartDelayedWithdrawalProps}
487
497
  * @returns All necessary data to execute the transaction (call, credit facade)
488
498
  */
489
- startDelayedWithdrawal_Mellow(props: StartDelayedWithdrawalProps): Promise<CreditAccountOperationResult>;
499
+ startDelayedWithdrawal(props: StartDelayedWithdrawalProps): Promise<CreditAccountOperationResult>;
500
+ /**
501
+ * Preview delayed withdrawal for given token
502
+ * @param props - {@link PreviewDelayedWithdrawalProps}
503
+ * @returns
504
+ */
505
+ previewDelayedWithdrawal(props: PreviewDelayedWithdrawalProps): Promise<PreviewDelayedWithdrawalResult>;
506
+ /**
507
+ * Get claimable and pending withdrawals of an account
508
+ * @param props - {@link GetPendingWithdrawalsProps}
509
+ * @returns
510
+ */
511
+ getPendingWithdrawals(props: GetPendingWithdrawalsProps): Promise<GetPendingWithdrawalsResult>;
490
512
  /**
491
513
  * Claim tokens with delayed withdrawal
492
514
  - Claim is executed in the following order: price update -> execute claim calls -> update quotas
493
515
  * @param props - {@link ClaimDelayedProps}
494
516
  * @returns
495
517
  */
496
- claimDelayed_Mellow(props: ClaimDelayedProps): Promise<CreditAccountOperationResult>;
518
+ claimDelayed(props: ClaimDelayedProps): Promise<CreditAccountOperationResult>;
497
519
  /**
498
520
  * Executes enable/disable tokens specified by given tokens lists and token prices
499
521
  * @param props - {@link EnableTokensProps}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "10.2.9",
3
+ "version": "10.3.0",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",