@gearbox-protocol/sdk 8.19.1 → 8.19.3
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.
|
@@ -286,11 +286,17 @@ class AccountOpener extends import_sdk.SDKConstruct {
|
|
|
286
286
|
async #depositIntoPools(targets) {
|
|
287
287
|
this.#logger?.debug("checking and topping up pools if necessary");
|
|
288
288
|
const minAvailableByPool = {};
|
|
289
|
-
for (
|
|
289
|
+
for (let i = 0; i < targets.length; i++) {
|
|
290
|
+
const t = targets[i];
|
|
290
291
|
const leverage = this.#getLeverage(t);
|
|
291
292
|
const cm = this.sdk.marketRegister.findCreditManager(t.creditManager);
|
|
292
293
|
const minDebt = this.#minDebtMultiplier * cm.creditFacade.minDebt / import_sdk.PERCENTAGE_FACTOR;
|
|
293
|
-
|
|
294
|
+
let amount = minDebt * (leverage - import_sdk.PERCENTAGE_FACTOR) / import_sdk.PERCENTAGE_FACTOR * this.#poolDepositMultiplier / import_sdk.PERCENTAGE_FACTOR;
|
|
295
|
+
amount = amount > cm.creditFacade.maxDebt ? cm.creditFacade.maxDebt : amount;
|
|
296
|
+
minAvailableByPool[cm.pool] = (minAvailableByPool[cm.pool] ?? 0n) + amount;
|
|
297
|
+
this.#logger?.debug(
|
|
298
|
+
`target #${i + 1} (${this.labelAddress(t.target)}) needs ${this.sdk.tokensMeta.formatBN(cm.underlying, amount)} ${this.sdk.tokensMeta.symbol(cm.underlying)} in pool (leverage: ${Number(leverage / import_sdk.PERCENTAGE_FACTOR)}%)`
|
|
299
|
+
);
|
|
294
300
|
}
|
|
295
301
|
let totalUSD = 0n;
|
|
296
302
|
const deposits = [];
|
|
@@ -694,7 +700,8 @@ class AccountOpener extends import_sdk.SDKConstruct {
|
|
|
694
700
|
const cm = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
695
701
|
const lt = BigInt(cm.creditManager.liquidationThresholds.mustGet(target));
|
|
696
702
|
const d = 50n;
|
|
697
|
-
|
|
703
|
+
const result = import_sdk.PERCENTAGE_FACTOR * (1n + (lt - d) / (import_sdk.PERCENTAGE_FACTOR - lt));
|
|
704
|
+
return result > import_sdk.PERCENTAGE_FACTOR * 10n ? import_sdk.PERCENTAGE_FACTOR * 10n : result;
|
|
698
705
|
}
|
|
699
706
|
get faucet() {
|
|
700
707
|
if (!this.#faucet) {
|
|
@@ -278,11 +278,17 @@ class AccountOpener extends SDKConstruct {
|
|
|
278
278
|
async #depositIntoPools(targets) {
|
|
279
279
|
this.#logger?.debug("checking and topping up pools if necessary");
|
|
280
280
|
const minAvailableByPool = {};
|
|
281
|
-
for (
|
|
281
|
+
for (let i = 0; i < targets.length; i++) {
|
|
282
|
+
const t = targets[i];
|
|
282
283
|
const leverage = this.#getLeverage(t);
|
|
283
284
|
const cm = this.sdk.marketRegister.findCreditManager(t.creditManager);
|
|
284
285
|
const minDebt = this.#minDebtMultiplier * cm.creditFacade.minDebt / PERCENTAGE_FACTOR;
|
|
285
|
-
|
|
286
|
+
let amount = minDebt * (leverage - PERCENTAGE_FACTOR) / PERCENTAGE_FACTOR * this.#poolDepositMultiplier / PERCENTAGE_FACTOR;
|
|
287
|
+
amount = amount > cm.creditFacade.maxDebt ? cm.creditFacade.maxDebt : amount;
|
|
288
|
+
minAvailableByPool[cm.pool] = (minAvailableByPool[cm.pool] ?? 0n) + amount;
|
|
289
|
+
this.#logger?.debug(
|
|
290
|
+
`target #${i + 1} (${this.labelAddress(t.target)}) needs ${this.sdk.tokensMeta.formatBN(cm.underlying, amount)} ${this.sdk.tokensMeta.symbol(cm.underlying)} in pool (leverage: ${Number(leverage / PERCENTAGE_FACTOR)}%)`
|
|
291
|
+
);
|
|
286
292
|
}
|
|
287
293
|
let totalUSD = 0n;
|
|
288
294
|
const deposits = [];
|
|
@@ -686,7 +692,8 @@ class AccountOpener extends SDKConstruct {
|
|
|
686
692
|
const cm = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
687
693
|
const lt = BigInt(cm.creditManager.liquidationThresholds.mustGet(target));
|
|
688
694
|
const d = 50n;
|
|
689
|
-
|
|
695
|
+
const result = PERCENTAGE_FACTOR * (1n + (lt - d) / (PERCENTAGE_FACTOR - lt));
|
|
696
|
+
return result > PERCENTAGE_FACTOR * 10n ? PERCENTAGE_FACTOR * 10n : result;
|
|
690
697
|
}
|
|
691
698
|
get faucet() {
|
|
692
699
|
if (!this.#faucet) {
|