@gearbox-protocol/sdk 3.0.0-vfour.376 → 3.0.0-vfour.378
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/dev/AccountOpener.js +7 -7
- package/dist/cjs/sdk/accounts/CreditAccountsService.js +15 -19
- package/dist/esm/dev/AccountOpener.js +7 -7
- package/dist/esm/sdk/accounts/CreditAccountsService.js +16 -20
- package/dist/types/dev/AccountOpener.d.ts +12 -1
- package/dist/types/sdk/accounts/CreditAccountsService.d.ts +2 -0
- package/package.json +1 -1
|
@@ -104,7 +104,7 @@ class AccountOpener extends import_sdk.SDKConstruct {
|
|
|
104
104
|
return results;
|
|
105
105
|
}
|
|
106
106
|
async #openAccount(input, index, total) {
|
|
107
|
-
const { creditManager, collateral } = input;
|
|
107
|
+
const { creditManager, target: collateral } = input;
|
|
108
108
|
const cm = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
109
109
|
const symbol = this.sdk.tokensMeta.symbol(collateral);
|
|
110
110
|
const logger = this.#logger?.child?.({
|
|
@@ -167,16 +167,16 @@ class AccountOpener extends import_sdk.SDKConstruct {
|
|
|
167
167
|
async prepareOpen(input) {
|
|
168
168
|
const {
|
|
169
169
|
creditManager,
|
|
170
|
-
|
|
170
|
+
target,
|
|
171
171
|
leverage = DEFAULT_LEVERAGE,
|
|
172
172
|
slippage = 50
|
|
173
173
|
} = input;
|
|
174
174
|
const borrower = await this.#getBorrower();
|
|
175
175
|
const cm = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
176
|
-
const symbol = this.sdk.tokensMeta.symbol(
|
|
176
|
+
const symbol = this.sdk.tokensMeta.symbol(target);
|
|
177
177
|
const logger = this.#logger?.child?.({
|
|
178
178
|
creditManager: cm.name,
|
|
179
|
-
|
|
179
|
+
target: symbol
|
|
180
180
|
});
|
|
181
181
|
const { minDebt, underlying } = cm.creditFacade;
|
|
182
182
|
const expectedBalances = [];
|
|
@@ -198,19 +198,19 @@ class AccountOpener extends import_sdk.SDKConstruct {
|
|
|
198
198
|
expectedBalances,
|
|
199
199
|
leftoverBalances,
|
|
200
200
|
slippage,
|
|
201
|
-
target
|
|
201
|
+
target
|
|
202
202
|
});
|
|
203
203
|
logger?.debug(strategy, "found open strategy");
|
|
204
204
|
const debt = minDebt * BigInt(leverage - 1);
|
|
205
205
|
const averageQuota = this.#getCollateralQuota(
|
|
206
206
|
cm,
|
|
207
|
-
|
|
207
|
+
target,
|
|
208
208
|
strategy.amount,
|
|
209
209
|
debt
|
|
210
210
|
);
|
|
211
211
|
const minQuota = this.#getCollateralQuota(
|
|
212
212
|
cm,
|
|
213
|
-
|
|
213
|
+
target,
|
|
214
214
|
strategy.minAmount,
|
|
215
215
|
debt
|
|
216
216
|
);
|
|
@@ -716,6 +716,8 @@ class CreditAccountsService extends import_base.SDKConstruct {
|
|
|
716
716
|
}
|
|
717
717
|
/**
|
|
718
718
|
* Returns raw txs that are needed to update all price feeds so that all credit accounts (possibly from different markets) compute
|
|
719
|
+
*
|
|
720
|
+
* This can be used by batch liquidator
|
|
719
721
|
* @param accounts
|
|
720
722
|
* @returns
|
|
721
723
|
*/
|
|
@@ -744,19 +746,11 @@ class CreditAccountsService extends import_base.SDKConstruct {
|
|
|
744
746
|
return this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(priceFeeds);
|
|
745
747
|
}
|
|
746
748
|
async getUpdateForAccount(creditManager, creditAccount, desiredQuotas) {
|
|
747
|
-
const tokensByPool = /* @__PURE__ */ new Map();
|
|
748
|
-
const oracleByPool = /* @__PURE__ */ new Map();
|
|
749
749
|
const quotaRecord = desiredQuotas ? (0, import_router.assetsMap)(desiredQuotas) : desiredQuotas;
|
|
750
750
|
const caBalancesRecord = creditAccount ? (0, import_router.assetsMap)(creditAccount.tokens) : creditAccount;
|
|
751
751
|
const market = this.sdk.marketRegister.findByCreditManager(creditManager);
|
|
752
752
|
const cm = this.sdk.marketRegister.findCreditManager(creditManager).creditManager;
|
|
753
|
-
const
|
|
754
|
-
oracleByPool.set(pool, market.priceOracle);
|
|
755
|
-
const insertToken = (p, t) => {
|
|
756
|
-
const tokens = tokensByPool.get(p) ?? /* @__PURE__ */ new Set();
|
|
757
|
-
tokens.add(t);
|
|
758
|
-
tokensByPool.set(pool, tokens);
|
|
759
|
-
};
|
|
753
|
+
const tokens = /* @__PURE__ */ new Set([(0, import_viem.getAddress)(cm.underlying)]);
|
|
760
754
|
for (const t of cm.collateralTokens) {
|
|
761
755
|
if (creditAccount && caBalancesRecord && quotaRecord) {
|
|
762
756
|
const balanceAsset = caBalancesRecord.get(t);
|
|
@@ -765,28 +759,30 @@ class CreditAccountsService extends import_base.SDKConstruct {
|
|
|
765
759
|
const isEnabled = (mask & creditAccount.enabledTokensMask) !== 0n;
|
|
766
760
|
const quotaAsset = quotaRecord.get(t);
|
|
767
761
|
const quotaBalance = quotaAsset?.balance || 0n;
|
|
768
|
-
if (balance > 10n && isEnabled || quotaBalance > 0)
|
|
769
|
-
|
|
762
|
+
if (balance > 10n && isEnabled || quotaBalance > 0) {
|
|
763
|
+
tokens.add((0, import_viem.getAddress)(t));
|
|
764
|
+
}
|
|
770
765
|
} else if (creditAccount && caBalancesRecord) {
|
|
771
766
|
const balanceAsset = caBalancesRecord.get(t);
|
|
772
767
|
const balance = balanceAsset?.balance || 0n;
|
|
773
768
|
const mask = balanceAsset?.mask || 0n;
|
|
774
769
|
const isEnabled = (mask & creditAccount.enabledTokensMask) !== 0n;
|
|
775
|
-
if (balance > 10n && isEnabled)
|
|
770
|
+
if (balance > 10n && isEnabled) {
|
|
771
|
+
tokens.add((0, import_viem.getAddress)(t));
|
|
772
|
+
}
|
|
776
773
|
} else if (quotaRecord) {
|
|
777
774
|
const quotaAsset = quotaRecord.get(t);
|
|
778
775
|
const quotaBalance = quotaAsset?.balance || 0n;
|
|
779
|
-
if (quotaBalance > 0)
|
|
776
|
+
if (quotaBalance > 0) {
|
|
777
|
+
tokens.add((0, import_viem.getAddress)(t));
|
|
778
|
+
}
|
|
780
779
|
}
|
|
781
780
|
}
|
|
782
|
-
const priceFeeds =
|
|
783
|
-
|
|
784
|
-
const tokens = Array.from(tokensByPool.get(pool2) ?? []);
|
|
785
|
-
priceFeeds.push(...oracle.priceFeedsForTokens(tokens));
|
|
786
|
-
}
|
|
781
|
+
const priceFeeds = market.priceOracle.priceFeedsForTokens(Array.from(tokens));
|
|
782
|
+
const tStr = Array.from(tokens).map((t) => this.labelAddress(t)).join(", ");
|
|
787
783
|
this.#logger?.debug(
|
|
788
784
|
{ account: creditAccount?.creditAccount, manager: cm.name },
|
|
789
|
-
`generating price feed updates for ${priceFeeds.length} price feeds`
|
|
785
|
+
`generating price feed updates for ${tStr} from ${priceFeeds.length} price feeds`
|
|
790
786
|
);
|
|
791
787
|
return this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(
|
|
792
788
|
priceFeeds,
|
|
@@ -90,7 +90,7 @@ class AccountOpener extends SDKConstruct {
|
|
|
90
90
|
return results;
|
|
91
91
|
}
|
|
92
92
|
async #openAccount(input, index, total) {
|
|
93
|
-
const { creditManager, collateral } = input;
|
|
93
|
+
const { creditManager, target: collateral } = input;
|
|
94
94
|
const cm = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
95
95
|
const symbol = this.sdk.tokensMeta.symbol(collateral);
|
|
96
96
|
const logger = this.#logger?.child?.({
|
|
@@ -153,16 +153,16 @@ class AccountOpener extends SDKConstruct {
|
|
|
153
153
|
async prepareOpen(input) {
|
|
154
154
|
const {
|
|
155
155
|
creditManager,
|
|
156
|
-
|
|
156
|
+
target,
|
|
157
157
|
leverage = DEFAULT_LEVERAGE,
|
|
158
158
|
slippage = 50
|
|
159
159
|
} = input;
|
|
160
160
|
const borrower = await this.#getBorrower();
|
|
161
161
|
const cm = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
162
|
-
const symbol = this.sdk.tokensMeta.symbol(
|
|
162
|
+
const symbol = this.sdk.tokensMeta.symbol(target);
|
|
163
163
|
const logger = this.#logger?.child?.({
|
|
164
164
|
creditManager: cm.name,
|
|
165
|
-
|
|
165
|
+
target: symbol
|
|
166
166
|
});
|
|
167
167
|
const { minDebt, underlying } = cm.creditFacade;
|
|
168
168
|
const expectedBalances = [];
|
|
@@ -184,19 +184,19 @@ class AccountOpener extends SDKConstruct {
|
|
|
184
184
|
expectedBalances,
|
|
185
185
|
leftoverBalances,
|
|
186
186
|
slippage,
|
|
187
|
-
target
|
|
187
|
+
target
|
|
188
188
|
});
|
|
189
189
|
logger?.debug(strategy, "found open strategy");
|
|
190
190
|
const debt = minDebt * BigInt(leverage - 1);
|
|
191
191
|
const averageQuota = this.#getCollateralQuota(
|
|
192
192
|
cm,
|
|
193
|
-
|
|
193
|
+
target,
|
|
194
194
|
strategy.amount,
|
|
195
195
|
debt
|
|
196
196
|
);
|
|
197
197
|
const minQuota = this.#getCollateralQuota(
|
|
198
198
|
cm,
|
|
199
|
-
|
|
199
|
+
target,
|
|
200
200
|
strategy.minAmount,
|
|
201
201
|
debt
|
|
202
202
|
);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { encodeFunctionData } from "viem";
|
|
1
|
+
import { encodeFunctionData, getAddress } from "viem";
|
|
2
2
|
import {
|
|
3
3
|
iCreditAccountCompressorAbi,
|
|
4
4
|
iPeripheryCompressorAbi,
|
|
@@ -720,6 +720,8 @@ class CreditAccountsService extends SDKConstruct {
|
|
|
720
720
|
}
|
|
721
721
|
/**
|
|
722
722
|
* Returns raw txs that are needed to update all price feeds so that all credit accounts (possibly from different markets) compute
|
|
723
|
+
*
|
|
724
|
+
* This can be used by batch liquidator
|
|
723
725
|
* @param accounts
|
|
724
726
|
* @returns
|
|
725
727
|
*/
|
|
@@ -748,19 +750,11 @@ class CreditAccountsService extends SDKConstruct {
|
|
|
748
750
|
return this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(priceFeeds);
|
|
749
751
|
}
|
|
750
752
|
async getUpdateForAccount(creditManager, creditAccount, desiredQuotas) {
|
|
751
|
-
const tokensByPool = /* @__PURE__ */ new Map();
|
|
752
|
-
const oracleByPool = /* @__PURE__ */ new Map();
|
|
753
753
|
const quotaRecord = desiredQuotas ? assetsMap(desiredQuotas) : desiredQuotas;
|
|
754
754
|
const caBalancesRecord = creditAccount ? assetsMap(creditAccount.tokens) : creditAccount;
|
|
755
755
|
const market = this.sdk.marketRegister.findByCreditManager(creditManager);
|
|
756
756
|
const cm = this.sdk.marketRegister.findCreditManager(creditManager).creditManager;
|
|
757
|
-
const
|
|
758
|
-
oracleByPool.set(pool, market.priceOracle);
|
|
759
|
-
const insertToken = (p, t) => {
|
|
760
|
-
const tokens = tokensByPool.get(p) ?? /* @__PURE__ */ new Set();
|
|
761
|
-
tokens.add(t);
|
|
762
|
-
tokensByPool.set(pool, tokens);
|
|
763
|
-
};
|
|
757
|
+
const tokens = /* @__PURE__ */ new Set([getAddress(cm.underlying)]);
|
|
764
758
|
for (const t of cm.collateralTokens) {
|
|
765
759
|
if (creditAccount && caBalancesRecord && quotaRecord) {
|
|
766
760
|
const balanceAsset = caBalancesRecord.get(t);
|
|
@@ -769,28 +763,30 @@ class CreditAccountsService extends SDKConstruct {
|
|
|
769
763
|
const isEnabled = (mask & creditAccount.enabledTokensMask) !== 0n;
|
|
770
764
|
const quotaAsset = quotaRecord.get(t);
|
|
771
765
|
const quotaBalance = quotaAsset?.balance || 0n;
|
|
772
|
-
if (balance > 10n && isEnabled || quotaBalance > 0)
|
|
773
|
-
|
|
766
|
+
if (balance > 10n && isEnabled || quotaBalance > 0) {
|
|
767
|
+
tokens.add(getAddress(t));
|
|
768
|
+
}
|
|
774
769
|
} else if (creditAccount && caBalancesRecord) {
|
|
775
770
|
const balanceAsset = caBalancesRecord.get(t);
|
|
776
771
|
const balance = balanceAsset?.balance || 0n;
|
|
777
772
|
const mask = balanceAsset?.mask || 0n;
|
|
778
773
|
const isEnabled = (mask & creditAccount.enabledTokensMask) !== 0n;
|
|
779
|
-
if (balance > 10n && isEnabled)
|
|
774
|
+
if (balance > 10n && isEnabled) {
|
|
775
|
+
tokens.add(getAddress(t));
|
|
776
|
+
}
|
|
780
777
|
} else if (quotaRecord) {
|
|
781
778
|
const quotaAsset = quotaRecord.get(t);
|
|
782
779
|
const quotaBalance = quotaAsset?.balance || 0n;
|
|
783
|
-
if (quotaBalance > 0)
|
|
780
|
+
if (quotaBalance > 0) {
|
|
781
|
+
tokens.add(getAddress(t));
|
|
782
|
+
}
|
|
784
783
|
}
|
|
785
784
|
}
|
|
786
|
-
const priceFeeds =
|
|
787
|
-
|
|
788
|
-
const tokens = Array.from(tokensByPool.get(pool2) ?? []);
|
|
789
|
-
priceFeeds.push(...oracle.priceFeedsForTokens(tokens));
|
|
790
|
-
}
|
|
785
|
+
const priceFeeds = market.priceOracle.priceFeedsForTokens(Array.from(tokens));
|
|
786
|
+
const tStr = Array.from(tokens).map((t) => this.labelAddress(t)).join(", ");
|
|
791
787
|
this.#logger?.debug(
|
|
792
788
|
{ account: creditAccount?.creditAccount, manager: cm.name },
|
|
793
|
-
`generating price feed updates for ${priceFeeds.length} price feeds`
|
|
789
|
+
`generating price feed updates for ${tStr} from ${priceFeeds.length} price feeds`
|
|
794
790
|
);
|
|
795
791
|
return this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(
|
|
796
792
|
priceFeeds,
|
|
@@ -8,7 +8,18 @@ export interface AccountOpenerOptions {
|
|
|
8
8
|
}
|
|
9
9
|
export interface TargetAccount {
|
|
10
10
|
creditManager: Address;
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Everything will be swapped into this token in the end
|
|
13
|
+
*/
|
|
14
|
+
target: Address;
|
|
15
|
+
/**
|
|
16
|
+
* This token will be provided as collateral, defaults to underlying token
|
|
17
|
+
* Expected to be found on borrower's address before opening the account
|
|
18
|
+
* Can be claimed from faucet
|
|
19
|
+
*
|
|
20
|
+
* TODO: not implemented
|
|
21
|
+
*/
|
|
22
|
+
collateral?: Address;
|
|
12
23
|
leverage?: number;
|
|
13
24
|
slippage?: number;
|
|
14
25
|
}
|
|
@@ -224,6 +224,8 @@ export declare class CreditAccountsService extends SDKConstruct {
|
|
|
224
224
|
openCA({ ethAmount, creditManager, collateral, permits, debt, withdrawDebt, referralCode, to, calls: openPathCalls, minQuota, averageQuota, }: OpenCAProps): Promise<CreditAccountOperationResult>;
|
|
225
225
|
/**
|
|
226
226
|
* Returns raw txs that are needed to update all price feeds so that all credit accounts (possibly from different markets) compute
|
|
227
|
+
*
|
|
228
|
+
* This can be used by batch liquidator
|
|
227
229
|
* @param accounts
|
|
228
230
|
* @returns
|
|
229
231
|
*/
|