@gearbox-protocol/sdk 3.0.0-vfour.387 → 3.0.0-vfour.389
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/sdk/accounts/CreditAccountsService.js +28 -0
- package/dist/cjs/sdk/plugins/V300StalenessPeriodPlugin.js +13 -6
- package/dist/cjs/sdk/sdk-legacy/core/transactions.js +30 -0
- package/dist/esm/sdk/accounts/CreditAccountsService.js +28 -0
- package/dist/esm/sdk/plugins/V300StalenessPeriodPlugin.js +13 -6
- package/dist/esm/sdk/sdk-legacy/core/transactions.js +29 -0
- package/dist/types/sdk/accounts/CreditAccountsService.d.ts +9 -1
- package/dist/types/sdk/accounts/types.d.ts +5 -0
- package/dist/types/sdk/sdk-legacy/core/transactions.d.ts +15 -1
- package/package.json +1 -1
|
@@ -621,6 +621,34 @@ class CreditAccountsService extends import_base.SDKConstruct {
|
|
|
621
621
|
const tx = cm.creditFacade.multicall(ca.creditAccount, calls);
|
|
622
622
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
623
623
|
}
|
|
624
|
+
/**
|
|
625
|
+
* Executes enable/disable tokens specified by given tokens lists and token prices
|
|
626
|
+
* @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
|
|
627
|
+
* @param {Array<Asset>} enabledTokens - list of tokens to enable {@link Asset};
|
|
628
|
+
* @param {Array<Asset>} disabledTokens - list of tokens to disable {@link Asset};
|
|
629
|
+
* @returns All necessary data to execute the transaction (call, credit facade)
|
|
630
|
+
*/
|
|
631
|
+
async enableTokens({
|
|
632
|
+
enabledTokens,
|
|
633
|
+
disabledTokens,
|
|
634
|
+
creditAccount: ca
|
|
635
|
+
}) {
|
|
636
|
+
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
637
|
+
const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
|
|
638
|
+
ca.creditManager,
|
|
639
|
+
ca,
|
|
640
|
+
void 0
|
|
641
|
+
);
|
|
642
|
+
const calls = [
|
|
643
|
+
...priceUpdatesCalls,
|
|
644
|
+
...disabledTokens.map(
|
|
645
|
+
(token) => this.#prepareDisableToken(ca.creditFacade, token)
|
|
646
|
+
),
|
|
647
|
+
...this.#prepareEnableTokens(ca.creditFacade, enabledTokens)
|
|
648
|
+
];
|
|
649
|
+
const tx = cm.creditFacade.multicall(ca.creditAccount, calls);
|
|
650
|
+
return { tx, calls, creditFacade: cm.creditFacade };
|
|
651
|
+
}
|
|
624
652
|
/**
|
|
625
653
|
* Executes swap specified by given calls, update quotas of affected tokens
|
|
626
654
|
- Open credit account is executed in the following order: price update -> increase debt -> add collateral ->
|
|
@@ -51,10 +51,16 @@ class V300StalenessPeriodPlugin extends import_base.SDKConstruct {
|
|
|
51
51
|
}
|
|
52
52
|
const events = await this.client.getLogs({
|
|
53
53
|
address: addresses,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
events: [
|
|
55
|
+
(0, import_viem.getAbiItem)({
|
|
56
|
+
abi: import_v300.iPriceOracleV300Abi,
|
|
57
|
+
name: "SetReservePriceFeed"
|
|
58
|
+
}),
|
|
59
|
+
(0, import_viem.getAbiItem)({
|
|
60
|
+
abi: import_v300.iPriceOracleV300Abi,
|
|
61
|
+
name: "SetPriceFeed"
|
|
62
|
+
})
|
|
63
|
+
],
|
|
58
64
|
fromBlock,
|
|
59
65
|
toBlock,
|
|
60
66
|
strict: true
|
|
@@ -68,9 +74,10 @@ class V300StalenessPeriodPlugin extends import_base.SDKConstruct {
|
|
|
68
74
|
const token = (0, import_viem.getAddress)(e.args.token);
|
|
69
75
|
const stalenessPeriod = e.args.stalenessPeriod;
|
|
70
76
|
for (const o of oracles) {
|
|
71
|
-
const
|
|
77
|
+
const map = e.eventName === "SetReservePriceFeed" ? o.reservePriceFeeds : o.mainPriceFeeds;
|
|
78
|
+
const pf = map.get(token);
|
|
72
79
|
if ((0, import_utils.hexEq)(pf?.address, priceFeed) && (0, import_utils.hexEq)(o.address, oracle)) {
|
|
73
|
-
|
|
80
|
+
map.upsert(
|
|
74
81
|
token,
|
|
75
82
|
new import_market.PriceFeedRef(this.sdk, priceFeed, stalenessPeriod)
|
|
76
83
|
);
|
|
@@ -27,6 +27,7 @@ __export(transactions_exports, {
|
|
|
27
27
|
TxClaimRewards: () => TxClaimRewards,
|
|
28
28
|
TxCloseAccount: () => TxCloseAccount,
|
|
29
29
|
TxDecreaseBorrowAmount: () => TxDecreaseBorrowAmount,
|
|
30
|
+
TxEnableTokens: () => TxEnableTokens,
|
|
30
31
|
TxGaugeClaim: () => TxGaugeClaim,
|
|
31
32
|
TxGaugeStake: () => TxGaugeStake,
|
|
32
33
|
TxGaugeUnstake: () => TxGaugeUnstake,
|
|
@@ -102,6 +103,8 @@ class TxSerializer {
|
|
|
102
103
|
return new TxStakeDiesel(params);
|
|
103
104
|
case "TxUnstakeDiesel":
|
|
104
105
|
return new TxUnstakeDiesel(params);
|
|
106
|
+
case "TxEnableTokens":
|
|
107
|
+
return new TxEnableTokens(params);
|
|
105
108
|
default:
|
|
106
109
|
throw new Error(`Unknown transaction for parsing: ${e.type}`);
|
|
107
110
|
}
|
|
@@ -612,6 +615,32 @@ class TxRemoveBot extends import_eventOrTx.EVMTx {
|
|
|
612
615
|
};
|
|
613
616
|
}
|
|
614
617
|
}
|
|
618
|
+
class TxEnableTokens extends import_eventOrTx.EVMTx {
|
|
619
|
+
enabledTokens;
|
|
620
|
+
disabledTokens;
|
|
621
|
+
creditManagerName;
|
|
622
|
+
constructor(opts) {
|
|
623
|
+
super(opts);
|
|
624
|
+
this.enabledTokens = opts.enabledTokens.map((a) => opts.tokensList[a]);
|
|
625
|
+
this.disabledTokens = opts.disabledTokens.map((a) => opts.tokensList[a]);
|
|
626
|
+
this.creditManagerName = opts.creditManagerName;
|
|
627
|
+
}
|
|
628
|
+
toString() {
|
|
629
|
+
const enabledSymbols = this.enabledTokens.map((t) => t?.title);
|
|
630
|
+
const disabledSymbols = this.disabledTokens.map((t) => t?.title);
|
|
631
|
+
const currentSentences = [
|
|
632
|
+
enabledSymbols.length > 0 ? `enabled: ${enabledSymbols.join(", ")}` : "",
|
|
633
|
+
disabledSymbols.length > 0 ? `disabled: ${disabledSymbols.join(", ")}` : ""
|
|
634
|
+
].filter((s) => !!s);
|
|
635
|
+
return `Credit Account ${this.creditManagerName}: ${currentSentences.join("; ")}`;
|
|
636
|
+
}
|
|
637
|
+
serialize() {
|
|
638
|
+
return {
|
|
639
|
+
type: "TxEnableTokens",
|
|
640
|
+
content: JSON.stringify(this)
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
}
|
|
615
644
|
// Annotate the CommonJS export names for ESM import in node:
|
|
616
645
|
0 && (module.exports = {
|
|
617
646
|
TXSwap,
|
|
@@ -623,6 +652,7 @@ class TxRemoveBot extends import_eventOrTx.EVMTx {
|
|
|
623
652
|
TxClaimRewards,
|
|
624
653
|
TxCloseAccount,
|
|
625
654
|
TxDecreaseBorrowAmount,
|
|
655
|
+
TxEnableTokens,
|
|
626
656
|
TxGaugeClaim,
|
|
627
657
|
TxGaugeStake,
|
|
628
658
|
TxGaugeUnstake,
|
|
@@ -625,6 +625,34 @@ class CreditAccountsService extends SDKConstruct {
|
|
|
625
625
|
const tx = cm.creditFacade.multicall(ca.creditAccount, calls);
|
|
626
626
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
627
627
|
}
|
|
628
|
+
/**
|
|
629
|
+
* Executes enable/disable tokens specified by given tokens lists and token prices
|
|
630
|
+
* @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
|
|
631
|
+
* @param {Array<Asset>} enabledTokens - list of tokens to enable {@link Asset};
|
|
632
|
+
* @param {Array<Asset>} disabledTokens - list of tokens to disable {@link Asset};
|
|
633
|
+
* @returns All necessary data to execute the transaction (call, credit facade)
|
|
634
|
+
*/
|
|
635
|
+
async enableTokens({
|
|
636
|
+
enabledTokens,
|
|
637
|
+
disabledTokens,
|
|
638
|
+
creditAccount: ca
|
|
639
|
+
}) {
|
|
640
|
+
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
641
|
+
const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
|
|
642
|
+
ca.creditManager,
|
|
643
|
+
ca,
|
|
644
|
+
void 0
|
|
645
|
+
);
|
|
646
|
+
const calls = [
|
|
647
|
+
...priceUpdatesCalls,
|
|
648
|
+
...disabledTokens.map(
|
|
649
|
+
(token) => this.#prepareDisableToken(ca.creditFacade, token)
|
|
650
|
+
),
|
|
651
|
+
...this.#prepareEnableTokens(ca.creditFacade, enabledTokens)
|
|
652
|
+
];
|
|
653
|
+
const tx = cm.creditFacade.multicall(ca.creditAccount, calls);
|
|
654
|
+
return { tx, calls, creditFacade: cm.creditFacade };
|
|
655
|
+
}
|
|
628
656
|
/**
|
|
629
657
|
* Executes swap specified by given calls, update quotas of affected tokens
|
|
630
658
|
- Open credit account is executed in the following order: price update -> increase debt -> add collateral ->
|
|
@@ -28,10 +28,16 @@ class V300StalenessPeriodPlugin extends SDKConstruct {
|
|
|
28
28
|
}
|
|
29
29
|
const events = await this.client.getLogs({
|
|
30
30
|
address: addresses,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
events: [
|
|
32
|
+
getAbiItem({
|
|
33
|
+
abi: iPriceOracleV300Abi,
|
|
34
|
+
name: "SetReservePriceFeed"
|
|
35
|
+
}),
|
|
36
|
+
getAbiItem({
|
|
37
|
+
abi: iPriceOracleV300Abi,
|
|
38
|
+
name: "SetPriceFeed"
|
|
39
|
+
})
|
|
40
|
+
],
|
|
35
41
|
fromBlock,
|
|
36
42
|
toBlock,
|
|
37
43
|
strict: true
|
|
@@ -45,9 +51,10 @@ class V300StalenessPeriodPlugin extends SDKConstruct {
|
|
|
45
51
|
const token = getAddress(e.args.token);
|
|
46
52
|
const stalenessPeriod = e.args.stalenessPeriod;
|
|
47
53
|
for (const o of oracles) {
|
|
48
|
-
const
|
|
54
|
+
const map = e.eventName === "SetReservePriceFeed" ? o.reservePriceFeeds : o.mainPriceFeeds;
|
|
55
|
+
const pf = map.get(token);
|
|
49
56
|
if (hexEq(pf?.address, priceFeed) && hexEq(o.address, oracle)) {
|
|
50
|
-
|
|
57
|
+
map.upsert(
|
|
51
58
|
token,
|
|
52
59
|
new PriceFeedRef(this.sdk, priceFeed, stalenessPeriod)
|
|
53
60
|
);
|
|
@@ -56,6 +56,8 @@ class TxSerializer {
|
|
|
56
56
|
return new TxStakeDiesel(params);
|
|
57
57
|
case "TxUnstakeDiesel":
|
|
58
58
|
return new TxUnstakeDiesel(params);
|
|
59
|
+
case "TxEnableTokens":
|
|
60
|
+
return new TxEnableTokens(params);
|
|
59
61
|
default:
|
|
60
62
|
throw new Error(`Unknown transaction for parsing: ${e.type}`);
|
|
61
63
|
}
|
|
@@ -566,6 +568,32 @@ class TxRemoveBot extends EVMTx {
|
|
|
566
568
|
};
|
|
567
569
|
}
|
|
568
570
|
}
|
|
571
|
+
class TxEnableTokens extends EVMTx {
|
|
572
|
+
enabledTokens;
|
|
573
|
+
disabledTokens;
|
|
574
|
+
creditManagerName;
|
|
575
|
+
constructor(opts) {
|
|
576
|
+
super(opts);
|
|
577
|
+
this.enabledTokens = opts.enabledTokens.map((a) => opts.tokensList[a]);
|
|
578
|
+
this.disabledTokens = opts.disabledTokens.map((a) => opts.tokensList[a]);
|
|
579
|
+
this.creditManagerName = opts.creditManagerName;
|
|
580
|
+
}
|
|
581
|
+
toString() {
|
|
582
|
+
const enabledSymbols = this.enabledTokens.map((t) => t?.title);
|
|
583
|
+
const disabledSymbols = this.disabledTokens.map((t) => t?.title);
|
|
584
|
+
const currentSentences = [
|
|
585
|
+
enabledSymbols.length > 0 ? `enabled: ${enabledSymbols.join(", ")}` : "",
|
|
586
|
+
disabledSymbols.length > 0 ? `disabled: ${disabledSymbols.join(", ")}` : ""
|
|
587
|
+
].filter((s) => !!s);
|
|
588
|
+
return `Credit Account ${this.creditManagerName}: ${currentSentences.join("; ")}`;
|
|
589
|
+
}
|
|
590
|
+
serialize() {
|
|
591
|
+
return {
|
|
592
|
+
type: "TxEnableTokens",
|
|
593
|
+
content: JSON.stringify(this)
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
}
|
|
569
597
|
export {
|
|
570
598
|
TXSwap,
|
|
571
599
|
TxAddBot,
|
|
@@ -576,6 +604,7 @@ export {
|
|
|
576
604
|
TxClaimRewards,
|
|
577
605
|
TxCloseAccount,
|
|
578
606
|
TxDecreaseBorrowAmount,
|
|
607
|
+
TxEnableTokens,
|
|
579
608
|
TxGaugeClaim,
|
|
580
609
|
TxGaugeStake,
|
|
581
610
|
TxGaugeUnstake,
|
|
@@ -5,7 +5,7 @@ import type { GearboxSDK } from "../GearboxSDK.js";
|
|
|
5
5
|
import type { OnDemandPriceUpdate, 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, ClaimFarmRewardsProps, CloseCreditAccountProps, CloseCreditAccountResult, CreditAccountFilter, CreditAccountOperationResult, ExecuteSwapProps, OpenCAProps, RepayAndLiquidateCreditAccountProps, RepayCreditAccountProps, Rewards, UpdateQuotasProps, WithdrawCollateralProps } from "./types.js";
|
|
8
|
+
import type { AddCollateralProps, ChangeDeptProps, ClaimFarmRewardsProps, CloseCreditAccountProps, CloseCreditAccountResult, CreditAccountFilter, CreditAccountOperationResult, EnableTokensProps, ExecuteSwapProps, OpenCAProps, RepayAndLiquidateCreditAccountProps, RepayCreditAccountProps, Rewards, UpdateQuotasProps, WithdrawCollateralProps } from "./types.js";
|
|
9
9
|
export interface CreditAccountServiceOptions {
|
|
10
10
|
batchSize?: number;
|
|
11
11
|
}
|
|
@@ -197,6 +197,14 @@ export declare class CreditAccountsService extends SDKConstruct {
|
|
|
197
197
|
* @returns All necessary data to execute the transaction (call, credit facade)
|
|
198
198
|
*/
|
|
199
199
|
claimFarmRewards({ tokensToDisable, calls: claimCalls, creditAccount: ca, minQuota, averageQuota, }: ClaimFarmRewardsProps): Promise<CreditAccountOperationResult>;
|
|
200
|
+
/**
|
|
201
|
+
* Executes enable/disable tokens specified by given tokens lists and token prices
|
|
202
|
+
* @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
|
|
203
|
+
* @param {Array<Asset>} enabledTokens - list of tokens to enable {@link Asset};
|
|
204
|
+
* @param {Array<Asset>} disabledTokens - list of tokens to disable {@link Asset};
|
|
205
|
+
* @returns All necessary data to execute the transaction (call, credit facade)
|
|
206
|
+
*/
|
|
207
|
+
enableTokens({ enabledTokens, disabledTokens, creditAccount: ca, }: EnableTokensProps): Promise<CreditAccountOperationResult>;
|
|
200
208
|
/**
|
|
201
209
|
* Executes swap specified by given calls, update quotas of affected tokens
|
|
202
210
|
- Open credit account is executed in the following order: price update -> increase debt -> add collateral ->
|
|
@@ -65,6 +65,11 @@ export interface ClaimFarmRewardsProps extends PrepareUpdateQuotasProps {
|
|
|
65
65
|
calls: Array<MultiCall>;
|
|
66
66
|
creditAccount: RouterCASlice;
|
|
67
67
|
}
|
|
68
|
+
export interface EnableTokensProps {
|
|
69
|
+
disabledTokens: Array<Address>;
|
|
70
|
+
enabledTokens: Array<Address>;
|
|
71
|
+
creditAccount: RouterCASlice;
|
|
72
|
+
}
|
|
68
73
|
export interface OpenCAProps extends PrepareUpdateQuotasProps {
|
|
69
74
|
ethAmount: bigint;
|
|
70
75
|
collateral: Array<Asset>;
|
|
@@ -4,7 +4,7 @@ import type { TokenData } from "../tokens/tokenData.js";
|
|
|
4
4
|
import type { EVMTxProps } from "./eventOrTx.js";
|
|
5
5
|
import { EVMTx } from "./eventOrTx.js";
|
|
6
6
|
export interface TxSerialized {
|
|
7
|
-
type: "TxAddLiquidity" | "TxRemoveLiquidity" | "TxSwap" | "TxAddCollateral" | "TxIncreaseBorrowAmount" | "TxDecreaseBorrowAmount" | "TxRepayAccount" | "TxCloseAccount" | "TxApprove" | "TxOpenMultitokenAccount" | "TxClaimNFT" | "TxClaimRewards" | "TxUpdateQuota" | "TxGaugeStake" | "TxGaugeUnstake" | "TxGaugeClaim" | "TxGaugeVote" | "TxWithdrawCollateral" | "TxAddBot" | "TxRemoveBot" | "TxLiquidateAccount" | "TxStakeDiesel" | "TxUnstakeDiesel";
|
|
7
|
+
type: "TxAddLiquidity" | "TxRemoveLiquidity" | "TxSwap" | "TxAddCollateral" | "TxIncreaseBorrowAmount" | "TxDecreaseBorrowAmount" | "TxRepayAccount" | "TxCloseAccount" | "TxApprove" | "TxOpenMultitokenAccount" | "TxClaimNFT" | "TxClaimRewards" | "TxUpdateQuota" | "TxGaugeStake" | "TxGaugeUnstake" | "TxGaugeClaim" | "TxGaugeVote" | "TxWithdrawCollateral" | "TxAddBot" | "TxRemoveBot" | "TxLiquidateAccount" | "TxStakeDiesel" | "TxUnstakeDiesel" | "TxEnableTokens";
|
|
8
8
|
content: string;
|
|
9
9
|
}
|
|
10
10
|
export declare class TxSerializer {
|
|
@@ -278,4 +278,18 @@ export declare class TxRemoveBot extends EVMTx {
|
|
|
278
278
|
toString(): string;
|
|
279
279
|
serialize(): TxSerialized;
|
|
280
280
|
}
|
|
281
|
+
interface EnableTokensProps extends EVMTxProps {
|
|
282
|
+
enabledTokens: Array<Address>;
|
|
283
|
+
disabledTokens: Array<Address>;
|
|
284
|
+
creditManagerName: string;
|
|
285
|
+
tokensList: Record<Address, TokenData>;
|
|
286
|
+
}
|
|
287
|
+
export declare class TxEnableTokens extends EVMTx {
|
|
288
|
+
readonly enabledTokens: Array<TokenData>;
|
|
289
|
+
readonly disabledTokens: Array<TokenData>;
|
|
290
|
+
readonly creditManagerName: string;
|
|
291
|
+
constructor(opts: EnableTokensProps);
|
|
292
|
+
toString(): string;
|
|
293
|
+
serialize(): TxSerialized;
|
|
294
|
+
}
|
|
281
295
|
export {};
|