@gearbox-protocol/sdk 10.2.2 → 10.2.4

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.
@@ -315,6 +315,7 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
315
315
  creditManager: ca.creditManager,
316
316
  creditAccount: ca
317
317
  });
318
+ console.log("CLOSE", this.sdk.parseMultiCall(routerCloseResult.calls));
318
319
  const calls = [
319
320
  ...operation === "close" ? [] : priceUpdates,
320
321
  ...routerCloseResult.calls,
@@ -97,15 +97,18 @@ class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.Abst
97
97
  assetsToWithdraw,
98
98
  creditAccount: ca,
99
99
  permits,
100
- to
100
+ to,
101
+ tokensToClaim
101
102
  }) {
102
103
  const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
103
104
  const addCollateral = collateralAssets.filter((a) => a.balance > 0);
104
105
  const router = this.sdk.routerFor(ca);
105
106
  const claimPath = await router.findClaimAllRewards({
106
107
  calls: [],
108
+ tokensToClaim,
107
109
  creditAccount: ca
108
110
  });
111
+ console.log("claimPath", this.sdk.parseMultiCall(claimPath.calls));
109
112
  const priceUpdates = await this.getPriceUpdatesForFacade({
110
113
  creditManager: ca.creditManager,
111
114
  creditAccount: ca
@@ -132,14 +135,17 @@ class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.Abst
132
135
  assetsToWithdraw,
133
136
  creditAccount: ca,
134
137
  permits,
135
- to
138
+ to,
139
+ tokensToClaim
136
140
  }) {
137
141
  const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
138
142
  const router = this.sdk.routerFor(ca);
139
143
  const claimPath = await router.findClaimAllRewards({
140
144
  calls: [],
145
+ tokensToClaim,
141
146
  creditAccount: ca
142
147
  });
148
+ console.log("claimPath", this.sdk.parseMultiCall(claimPath.calls));
143
149
  const priceUpdates = await this.getPriceUpdatesForFacade({
144
150
  creditManager: ca.creditManager,
145
151
  creditAccount: ca
@@ -167,12 +173,14 @@ class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.Abst
167
173
  calls: legacyCalls,
168
174
  creditAccount: ca,
169
175
  minQuota,
170
- averageQuota
176
+ averageQuota,
177
+ tokensToClaim
171
178
  }) {
172
179
  const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
173
180
  const router = this.sdk.routerFor(ca);
174
181
  const claimPath = await router.findClaimAllRewards({
175
182
  calls: legacyCalls,
183
+ tokensToClaim,
176
184
  creditAccount: ca
177
185
  });
178
186
  if (claimPath.calls.length === 0) throw new Error("No path to execute");
@@ -146,7 +146,7 @@ class RouterV310Contract extends import_AbstractRouterContract.AbstractRouterCon
146
146
  * Implements {@link IRouterContract.findClaimAllRewards}
147
147
  */
148
148
  async findClaimAllRewards(props) {
149
- const tData = props.creditAccount.tokens.map((a) => ({
149
+ const tData = props.tokensToClaim.map((a) => ({
150
150
  balance: 0n,
151
151
  claimRewards: true,
152
152
  leftoverBalance: 0n,
@@ -21,13 +21,11 @@ __export(formatter_exports, {
21
21
  fmtBinaryMask: () => fmtBinaryMask,
22
22
  formatBN: () => formatBN,
23
23
  formatBNvalue: () => formatBNvalue,
24
- formatBn4dig: () => formatBn4dig,
25
24
  formatDuration: () => formatDuration,
26
25
  formatNumberToString_: () => formatNumberToString_,
27
26
  numberWithCommas: () => numberWithCommas,
28
27
  percentFmt: () => percentFmt,
29
- toBigInt: () => toBigInt,
30
- toHumanFormat: () => toHumanFormat
28
+ toBigInt: () => toBigInt
31
29
  });
32
30
  module.exports = __toCommonJS(formatter_exports);
33
31
  var import_date_fns = require("date-fns");
@@ -79,6 +77,9 @@ const limitNum = (n, d = 18) => {
79
77
  }
80
78
  };
81
79
  function toHumanFormat(num, precision = 2) {
80
+ if (num >= BigInt(1e18)) {
81
+ return `${formatBn4dig(num / BigInt(1e12), precision)}T`;
82
+ }
82
83
  if (num >= BigInt(1e15)) {
83
84
  return `${formatBn4dig(num / BigInt(1e9), precision)}Bn`;
84
85
  }
@@ -125,11 +126,9 @@ function formatNumberToString_(value) {
125
126
  fmtBinaryMask,
126
127
  formatBN,
127
128
  formatBNvalue,
128
- formatBn4dig,
129
129
  formatDuration,
130
130
  formatNumberToString_,
131
131
  numberWithCommas,
132
132
  percentFmt,
133
- toBigInt,
134
- toHumanFormat
133
+ toBigInt
135
134
  });
@@ -306,6 +306,7 @@ class AbstractCreditAccountService extends SDKConstruct {
306
306
  creditManager: ca.creditManager,
307
307
  creditAccount: ca
308
308
  });
309
+ console.log("CLOSE", this.sdk.parseMultiCall(routerCloseResult.calls));
309
310
  const calls = [
310
311
  ...operation === "close" ? [] : priceUpdates,
311
312
  ...routerCloseResult.calls,
@@ -74,15 +74,18 @@ class CreditAccountServiceV310 extends AbstractCreditAccountService {
74
74
  assetsToWithdraw,
75
75
  creditAccount: ca,
76
76
  permits,
77
- to
77
+ to,
78
+ tokensToClaim
78
79
  }) {
79
80
  const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
80
81
  const addCollateral = collateralAssets.filter((a) => a.balance > 0);
81
82
  const router = this.sdk.routerFor(ca);
82
83
  const claimPath = await router.findClaimAllRewards({
83
84
  calls: [],
85
+ tokensToClaim,
84
86
  creditAccount: ca
85
87
  });
88
+ console.log("claimPath", this.sdk.parseMultiCall(claimPath.calls));
86
89
  const priceUpdates = await this.getPriceUpdatesForFacade({
87
90
  creditManager: ca.creditManager,
88
91
  creditAccount: ca
@@ -109,14 +112,17 @@ class CreditAccountServiceV310 extends AbstractCreditAccountService {
109
112
  assetsToWithdraw,
110
113
  creditAccount: ca,
111
114
  permits,
112
- to
115
+ to,
116
+ tokensToClaim
113
117
  }) {
114
118
  const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
115
119
  const router = this.sdk.routerFor(ca);
116
120
  const claimPath = await router.findClaimAllRewards({
117
121
  calls: [],
122
+ tokensToClaim,
118
123
  creditAccount: ca
119
124
  });
125
+ console.log("claimPath", this.sdk.parseMultiCall(claimPath.calls));
120
126
  const priceUpdates = await this.getPriceUpdatesForFacade({
121
127
  creditManager: ca.creditManager,
122
128
  creditAccount: ca
@@ -144,12 +150,14 @@ class CreditAccountServiceV310 extends AbstractCreditAccountService {
144
150
  calls: legacyCalls,
145
151
  creditAccount: ca,
146
152
  minQuota,
147
- averageQuota
153
+ averageQuota,
154
+ tokensToClaim
148
155
  }) {
149
156
  const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
150
157
  const router = this.sdk.routerFor(ca);
151
158
  const claimPath = await router.findClaimAllRewards({
152
159
  calls: legacyCalls,
160
+ tokensToClaim,
153
161
  creditAccount: ca
154
162
  });
155
163
  if (claimPath.calls.length === 0) throw new Error("No path to execute");
@@ -123,7 +123,7 @@ class RouterV310Contract extends AbstractRouterContract {
123
123
  * Implements {@link IRouterContract.findClaimAllRewards}
124
124
  */
125
125
  async findClaimAllRewards(props) {
126
- const tData = props.creditAccount.tokens.map((a) => ({
126
+ const tData = props.tokensToClaim.map((a) => ({
127
127
  balance: 0n,
128
128
  claimRewards: true,
129
129
  leftoverBalance: 0n,
@@ -47,6 +47,9 @@ const limitNum = (n, d = 18) => {
47
47
  }
48
48
  };
49
49
  function toHumanFormat(num, precision = 2) {
50
+ if (num >= BigInt(1e18)) {
51
+ return `${formatBn4dig(num / BigInt(1e12), precision)}T`;
52
+ }
50
53
  if (num >= BigInt(1e15)) {
51
54
  return `${formatBn4dig(num / BigInt(1e9), precision)}Bn`;
52
55
  }
@@ -92,11 +95,9 @@ export {
92
95
  fmtBinaryMask,
93
96
  formatBN,
94
97
  formatBNvalue,
95
- formatBn4dig,
96
98
  formatDuration,
97
99
  formatNumberToString_,
98
100
  numberWithCommas,
99
101
  percentFmt,
100
- toBigInt,
101
- toHumanFormat
102
+ toBigInt
102
103
  };
@@ -12,13 +12,13 @@ export declare class CreditAccountServiceV310 extends AbstractCreditAccountServi
12
12
  /**
13
13
  * Implements {@link ICreditAccountsService.repayCreditAccount}
14
14
  */
15
- repayCreditAccount({ operation, collateralAssets, assetsToWithdraw, creditAccount: ca, permits, to, }: RepayCreditAccountProps): Promise<CreditAccountOperationResult>;
15
+ repayCreditAccount({ operation, collateralAssets, assetsToWithdraw, creditAccount: ca, permits, to, tokensToClaim, }: RepayCreditAccountProps): Promise<CreditAccountOperationResult>;
16
16
  /**
17
17
  * Implements {@link ICreditAccountsService.repayAndLiquidateCreditAccount}
18
18
  */
19
- repayAndLiquidateCreditAccount({ collateralAssets, assetsToWithdraw, creditAccount: ca, permits, to, }: RepayAndLiquidateCreditAccountProps): Promise<CreditAccountOperationResult>;
19
+ repayAndLiquidateCreditAccount({ collateralAssets, assetsToWithdraw, creditAccount: ca, permits, to, tokensToClaim, }: RepayAndLiquidateCreditAccountProps): Promise<CreditAccountOperationResult>;
20
20
  /**
21
21
  * Implements {@link ICreditAccountsService.claimFarmRewards}
22
22
  */
23
- claimFarmRewards({ calls: legacyCalls, creditAccount: ca, minQuota, averageQuota, }: ClaimFarmRewardsProps): Promise<CreditAccountOperationResult>;
23
+ claimFarmRewards({ calls: legacyCalls, creditAccount: ca, minQuota, averageQuota, tokensToClaim, }: ClaimFarmRewardsProps): Promise<CreditAccountOperationResult>;
24
24
  }
@@ -108,6 +108,7 @@ export interface RepayAndLiquidateCreditAccountProps {
108
108
  * permits of tokens to withdraw (in any permittable token is present)
109
109
  */
110
110
  permits: Record<string, PermitResult>;
111
+ tokensToClaim: Asset[];
111
112
  }
112
113
  export interface PrepareUpdateQuotasProps {
113
114
  /**
@@ -222,6 +223,7 @@ export interface ClaimFarmRewardsProps extends PrepareUpdateQuotasProps {
222
223
  * minimal credit account data on which operation is performed
223
224
  */
224
225
  creditAccount: RouterCASlice;
226
+ tokensToClaim: Asset[];
225
227
  }
226
228
  export interface EnableTokensProps {
227
229
  /**
@@ -180,6 +180,10 @@ export interface FindClaimAllRewardsProps {
180
180
  * Minimal credit account data on which operation is performed
181
181
  */
182
182
  creditAccount: RouterCASlice;
183
+ /**
184
+ * List of token rewards of which we want to claim and swap to underlying token during closing ca process
185
+ */
186
+ tokensToClaim: Array<Asset>;
183
187
  /**
184
188
  * Legacy property - array of MultiCall from getRewards
185
189
  */
@@ -5,8 +5,6 @@ export declare const toBigInt: (v: string | number | bigint | {
5
5
  export declare const percentFmt: (v: number | bigint | string, raw?: boolean) => string;
6
6
  export declare function formatBNvalue(num: number | bigint | string | undefined, decimals: number, precision?: number, raw?: boolean): string;
7
7
  export declare function formatBN(num: number | bigint | string | undefined, decimals: number, precision?: number): string;
8
- export declare function toHumanFormat(num: bigint, precision?: number): string;
9
- export declare function formatBn4dig(num: bigint, precision?: number): string;
10
8
  export declare function fmtBinaryMask(mask: bigint): string;
11
9
  export declare function numberWithCommas(x: number | bigint): string;
12
10
  export declare function formatDuration(seconds: number, raw?: boolean): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "10.2.2",
3
+ "version": "10.2.4",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",