@gearbox-protocol/sdk 17.13.0-next.1 → 17.13.0-next.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.
- package/dist/cjs/dev/ltUtils.js +3 -2
- package/dist/cjs/model/errors/index.js +3 -0
- package/dist/cjs/model/errors/operation-errors.js +27 -0
- package/dist/cjs/model/index.js +3 -0
- package/dist/cjs/onchain/accounts/intents/index.js +1 -0
- package/dist/cjs/onchain/accounts/intents/operations.js +1 -1
- package/dist/cjs/onchain/accounts/intents/plan.js +21 -0
- package/dist/cjs/onchain/accounts/intents/realize.js +29 -7
- package/dist/cjs/onchain/accounts/intents/resolveQuotaUpdate.js +146 -0
- package/dist/cjs/onchain/accounts/intents/tests/update-quota.fixtures.js +102 -0
- package/dist/cjs/onchain/accounts/intents/utils/index.js +1 -0
- package/dist/cjs/onchain/accounts/intents/utils/quotas-for-update.js +28 -10
- package/dist/cjs/onchain/accounts/liquidations/LiquidationsService.js +5 -2
- package/dist/cjs/onchain/accounts/liquidations/partialLiquidation.js +4 -4
- package/dist/cjs/onchain/constants/index.js +1 -0
- package/dist/cjs/onchain/constants/math.js +6 -0
- package/dist/cjs/onchain/index.js +9 -0
- package/dist/cjs/onchain/positions/calcHealthFactor.js +1 -1
- package/dist/cjs/onchain/preview/preview/CreditAccountState.js +4 -2
- package/dist/cjs/onchain/validation/bundles/checkCreditOperation.js +2 -0
- package/dist/cjs/onchain/validation/bundles/checkQuotaUpdates.js +45 -0
- package/dist/cjs/onchain/validation/bundles/index.js +2 -0
- package/dist/cjs/onchain/validation/checks/checkMaxQuota.js +18 -0
- package/dist/cjs/onchain/validation/checks/checkQuotaActive.js +10 -0
- package/dist/cjs/onchain/validation/checks/checkQuotaChange.js +18 -0
- package/dist/cjs/onchain/validation/checks/index.js +6 -0
- package/dist/cjs/onchain/validation/index.js +8 -0
- package/dist/cjs/sdk/prepare/PrepareApi.js +10 -0
- package/dist/esm/dev/ltUtils.js +3 -2
- package/dist/esm/model/errors/index.js +2 -2
- package/dist/esm/model/errors/operation-errors.js +25 -1
- package/dist/esm/model/index.js +2 -2
- package/dist/esm/onchain/accounts/intents/index.js +2 -1
- package/dist/esm/onchain/accounts/intents/operations.js +1 -1
- package/dist/esm/onchain/accounts/intents/plan.js +22 -2
- package/dist/esm/onchain/accounts/intents/realize.js +29 -7
- package/dist/esm/onchain/accounts/intents/resolveQuotaUpdate.js +145 -0
- package/dist/esm/onchain/accounts/intents/tests/update-quota.fixtures.js +92 -0
- package/dist/esm/onchain/accounts/intents/utils/index.js +2 -2
- package/dist/esm/onchain/accounts/intents/utils/quotas-for-update.js +28 -11
- package/dist/esm/onchain/accounts/liquidations/LiquidationsService.js +5 -2
- package/dist/esm/onchain/accounts/liquidations/partialLiquidation.js +4 -4
- package/dist/esm/onchain/constants/index.js +2 -2
- package/dist/esm/onchain/constants/math.js +6 -1
- package/dist/esm/onchain/index.js +6 -2
- package/dist/esm/onchain/positions/calcHealthFactor.js +1 -1
- package/dist/esm/onchain/preview/preview/CreditAccountState.js +4 -2
- package/dist/esm/onchain/validation/bundles/checkCreditOperation.js +2 -0
- package/dist/esm/onchain/validation/bundles/checkQuotaUpdates.js +44 -0
- package/dist/esm/onchain/validation/bundles/index.js +2 -1
- package/dist/esm/onchain/validation/checks/checkMaxQuota.js +17 -0
- package/dist/esm/onchain/validation/checks/checkQuotaActive.js +9 -0
- package/dist/esm/onchain/validation/checks/checkQuotaChange.js +17 -0
- package/dist/esm/onchain/validation/checks/index.js +4 -1
- package/dist/esm/onchain/validation/index.js +5 -1
- package/dist/esm/sdk/prepare/PrepareApi.js +10 -0
- package/dist/types/model/errors/index.d.ts +2 -2
- package/dist/types/model/errors/operation-errors.d.ts +39 -1
- package/dist/types/model/index.d.ts +2 -2
- package/dist/types/onchain/accounts/index.d.ts +2 -2
- package/dist/types/onchain/accounts/intents/index.d.ts +2 -2
- package/dist/types/onchain/accounts/intents/operations.d.ts +9 -3
- package/dist/types/onchain/accounts/intents/plan.d.ts +19 -2
- package/dist/types/onchain/accounts/intents/resolveQuotaUpdate.d.ts +34 -0
- package/dist/types/onchain/accounts/intents/tests/update-quota.fixtures.d.ts +49 -0
- package/dist/types/onchain/accounts/intents/types.d.ts +19 -2
- package/dist/types/onchain/accounts/intents/utils/index.d.ts +2 -2
- package/dist/types/onchain/accounts/intents/utils/quotas-for-update.d.ts +23 -5
- package/dist/types/onchain/accounts/liquidations/LiquidationsService.d.ts +5 -1
- package/dist/types/onchain/accounts/liquidations/partialLiquidation.d.ts +9 -1
- package/dist/types/onchain/constants/index.d.ts +2 -2
- package/dist/types/onchain/constants/math.d.ts +6 -1
- package/dist/types/onchain/index.d.ts +7 -3
- package/dist/types/onchain/preview/preview/CreditAccountState.d.ts +2 -1
- package/dist/types/onchain/validation/bundles/checkCreditOperation.d.ts +2 -2
- package/dist/types/onchain/validation/bundles/checkQuotaUpdates.d.ts +16 -0
- package/dist/types/onchain/validation/bundles/index.d.ts +2 -1
- package/dist/types/onchain/validation/checks/checkMaxQuota.d.ts +16 -0
- package/dist/types/onchain/validation/checks/checkQuotaActive.d.ts +13 -0
- package/dist/types/onchain/validation/checks/checkQuotaChange.d.ts +17 -0
- package/dist/types/onchain/validation/checks/index.d.ts +4 -1
- package/dist/types/onchain/validation/index.d.ts +5 -1
- package/dist/types/onchain/validation/raise.d.ts +2 -2
- package/dist/types/sdk/execute/types.d.ts +1 -1
- package/dist/types/sdk/index.d.ts +2 -2
- package/dist/types/sdk/prepare/PrepareApi.d.ts +6 -2
- package/dist/types/sdk/prepare/index.d.ts +2 -2
- package/dist/types/sdk/prepare/types.d.ts +22 -2
- package/package.json +1 -1
|
@@ -43,7 +43,7 @@ function calcHealthFactor(props) {
|
|
|
43
43
|
const quota = snapshot.quotas.find((q) => (0, viem.isAddressEqual)(q.token, token));
|
|
44
44
|
const quotaBalance = quota && (active.get(token) ?? false) ? quota.balance : 0n;
|
|
45
45
|
const quotaWeighted = (convertToUSD(underlying, quotaBalance) ?? 0n) * require_onchain_constants_math.PERCENTAGE_FACTOR;
|
|
46
|
-
return acc + (quota ? require_onchain_utils_bigint_math.BigIntMath.min(quotaWeighted, tokenLtWeighted) : tokenLtWeighted);
|
|
46
|
+
return acc + (quota || active.get(token) ? require_onchain_utils_bigint_math.BigIntMath.min(quotaWeighted, tokenLtWeighted) : tokenLtWeighted);
|
|
47
47
|
}, 0n);
|
|
48
48
|
const borrowedValue = convertToUSD(underlying, snapshot.totalDebt) ?? 0n;
|
|
49
49
|
const hf = borrowedValue > 0n ? assetValue / borrowedValue : 0n;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_onchain_utils_AssetsMap = require("../../utils/AssetsMap.js");
|
|
3
3
|
const require_onchain_constants_math = require("../../constants/math.js");
|
|
4
|
+
const require_onchain_accounts_quota_utils = require("../../accounts/quota-utils.js");
|
|
4
5
|
let viem = require("viem");
|
|
5
6
|
//#region src/onchain/preview/preview/CreditAccountState.ts
|
|
6
7
|
/**
|
|
@@ -130,7 +131,8 @@ var CreditAccountState = class CreditAccountState {
|
|
|
130
131
|
/**
|
|
131
132
|
* Applies a relative `updateQuota` change to the token's quota:
|
|
132
133
|
* `MIN_INT96` is the facade "disable quota" sentinel and zeroes it, other
|
|
133
|
-
* changes are
|
|
134
|
+
* changes are rounded toward zero to a `PERCENTAGE_FACTOR` step, as the
|
|
135
|
+
* facade does, and added with the result clamped at zero (quotas cannot go
|
|
134
136
|
* negative on-chain).
|
|
135
137
|
*/
|
|
136
138
|
updateQuota(token, change) {
|
|
@@ -138,7 +140,7 @@ var CreditAccountState = class CreditAccountState {
|
|
|
138
140
|
this.quotas.upsert(token, 0n);
|
|
139
141
|
return;
|
|
140
142
|
}
|
|
141
|
-
const next = this.quotas.getOrZero(token) + change;
|
|
143
|
+
const next = this.quotas.getOrZero(token) + require_onchain_accounts_quota_utils.roundUpQuota(change);
|
|
142
144
|
this.quotas.upsert(token, next > 0n ? next : 0n);
|
|
143
145
|
}
|
|
144
146
|
};
|
|
@@ -10,6 +10,7 @@ const require_onchain_validation_bundles_checkIncreaseDebt = require("./checkInc
|
|
|
10
10
|
const require_onchain_validation_bundles_checkIncreaseQuota = require("./checkIncreaseQuota.js");
|
|
11
11
|
const require_onchain_validation_bundles_checkMarket = require("./checkMarket.js");
|
|
12
12
|
const require_onchain_validation_bundles_checkObtained = require("./checkObtained.js");
|
|
13
|
+
const require_onchain_validation_bundles_checkQuotaUpdates = require("./checkQuotaUpdates.js");
|
|
13
14
|
const require_onchain_validation_bundles_checkRWAOpening = require("./checkRWAOpening.js");
|
|
14
15
|
//#region src/onchain/validation/bundles/checkCreditOperation.ts
|
|
15
16
|
/**
|
|
@@ -41,6 +42,7 @@ async function checkCreditOperation(args) {
|
|
|
41
42
|
...require_onchain_validation_bundles_checkIncreaseDebt.checkIncreaseDebt(suite, preview, underlying),
|
|
42
43
|
...require_onchain_validation_bundles_checkObtained.checkObtained(suite, preview),
|
|
43
44
|
...require_onchain_validation_bundles_checkAccountQuotas.checkAccountQuotas(suite, preview),
|
|
45
|
+
...require_onchain_validation_bundles_checkQuotaUpdates.checkQuotaUpdates(suite, preview, underlying),
|
|
44
46
|
...require_onchain_validation_bundles_checkIncreaseQuota.checkIncreaseQuota(market, preview, underlying),
|
|
45
47
|
...require_onchain_validation_bundles_checkHealthFactors.checkHealthFactors({
|
|
46
48
|
totalDebt: preview.totalDebt,
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_onchain_constants_math = require("../../constants/math.js");
|
|
3
|
+
const require_model_errors_operation_errors = require("../../../model/errors/operation-errors.js");
|
|
4
|
+
require("../../../model/index.js");
|
|
5
|
+
const require_onchain_validation_helpers_amount = require("../helpers/amount.js");
|
|
6
|
+
require("../helpers/index.js");
|
|
7
|
+
const require_onchain_validation_checks_checkForbiddenToken = require("../checks/checkForbiddenToken.js");
|
|
8
|
+
const require_onchain_validation_checks_checkMaxQuota = require("../checks/checkMaxQuota.js");
|
|
9
|
+
require("../checks/index.js");
|
|
10
|
+
let viem = require("viem");
|
|
11
|
+
//#region src/onchain/validation/bundles/checkQuotaUpdates.ts
|
|
12
|
+
/**
|
|
13
|
+
* What the facade reverts on in each quota the operation touches: an increase
|
|
14
|
+
* on a forbidden token, an increase on an account that ends with zero debt, and
|
|
15
|
+
* a resulting quota above `MAX_QUOTA_MULTIPLIER × maxDebt`.
|
|
16
|
+
*/
|
|
17
|
+
function checkQuotaUpdates(suite, preview, underlying) {
|
|
18
|
+
const isAdjust = preview.operation === "AdjustCreditAccount";
|
|
19
|
+
const changes = (isAdjust ? preview.quotasChange : preview.quotas).filter((q) => q.value !== 0n);
|
|
20
|
+
const increases = changes.filter((q) => q.value > 0n);
|
|
21
|
+
const { minDebt, maxDebt } = suite.creditFacade;
|
|
22
|
+
const maxQuota = require_onchain_constants_math.MAX_QUOTA_MULTIPLIER * maxDebt;
|
|
23
|
+
const forbidden = increases.flatMap((q) => require_onchain_validation_checks_checkForbiddenToken.checkForbiddenToken({
|
|
24
|
+
token: q.token,
|
|
25
|
+
isForbidden: suite.isForbidden(q.token.address)
|
|
26
|
+
}));
|
|
27
|
+
const isZeroDebt = isAdjust && increases.length > 0 && preview.totalDebt.value === 0n ? [require_model_errors_operation_errors.debtOutOfRange({
|
|
28
|
+
requested: require_onchain_validation_helpers_amount.amountOf(underlying, 0n),
|
|
29
|
+
minDebt: require_onchain_validation_helpers_amount.amountOf(underlying, minDebt),
|
|
30
|
+
maxDebt: require_onchain_validation_helpers_amount.amountOf(underlying, maxDebt)
|
|
31
|
+
})] : [];
|
|
32
|
+
const aboveMax = changes.flatMap((q) => require_onchain_validation_checks_checkMaxQuota.checkMaxQuota({
|
|
33
|
+
token: q.token,
|
|
34
|
+
requested: preview.quotas.find((r) => (0, viem.isAddressEqual)(r.token.address, q.token.address))?.value ?? 0n,
|
|
35
|
+
maxQuota,
|
|
36
|
+
underlying
|
|
37
|
+
}));
|
|
38
|
+
return [
|
|
39
|
+
...forbidden,
|
|
40
|
+
...isZeroDebt,
|
|
41
|
+
...aboveMax
|
|
42
|
+
];
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
exports.checkQuotaUpdates = checkQuotaUpdates;
|
|
@@ -8,6 +8,7 @@ const require_onchain_validation_bundles_checkIncreaseDebt = require("./checkInc
|
|
|
8
8
|
const require_onchain_validation_bundles_checkIncreaseQuota = require("./checkIncreaseQuota.js");
|
|
9
9
|
const require_onchain_validation_bundles_checkMarket = require("./checkMarket.js");
|
|
10
10
|
const require_onchain_validation_bundles_checkObtained = require("./checkObtained.js");
|
|
11
|
+
const require_onchain_validation_bundles_checkQuotaUpdates = require("./checkQuotaUpdates.js");
|
|
11
12
|
const require_onchain_validation_bundles_checkMidasAccountGreenlist = require("./checkMidasAccountGreenlist.js");
|
|
12
13
|
const require_onchain_validation_bundles_checkRWAOpenRequirements = require("./checkRWAOpenRequirements.js");
|
|
13
14
|
const require_onchain_validation_bundles_checkRWAOpening = require("./checkRWAOpening.js");
|
|
@@ -30,6 +31,7 @@ exports.checkMidasAccountGreenlist = require_onchain_validation_bundles_checkMid
|
|
|
30
31
|
exports.checkObtained = require_onchain_validation_bundles_checkObtained.checkObtained;
|
|
31
32
|
exports.checkPoolFunding = require_onchain_validation_bundles_checkPoolFunding.checkPoolFunding;
|
|
32
33
|
exports.checkPoolOperation = require_onchain_validation_bundles_checkPoolOperation.checkPoolOperation;
|
|
34
|
+
exports.checkQuotaUpdates = require_onchain_validation_bundles_checkQuotaUpdates.checkQuotaUpdates;
|
|
33
35
|
exports.checkRWAOpenRequirements = require_onchain_validation_bundles_checkRWAOpenRequirements.checkRWAOpenRequirements;
|
|
34
36
|
exports.checkRWAOpening = require_onchain_validation_bundles_checkRWAOpening.checkRWAOpening;
|
|
35
37
|
exports.checkWallet = require_onchain_validation_bundles_checkWallet.checkWallet;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_model_errors_operation_errors = require("../../../model/errors/operation-errors.js");
|
|
3
|
+
require("../../../model/index.js");
|
|
4
|
+
const require_onchain_validation_helpers_amount = require("../helpers/amount.js");
|
|
5
|
+
require("../helpers/index.js");
|
|
6
|
+
//#region src/onchain/validation/checks/checkMaxQuota.ts
|
|
7
|
+
/** The facade's per-token quota ceiling. */
|
|
8
|
+
function checkMaxQuota(args) {
|
|
9
|
+
const { token, requested, maxQuota, underlying } = args;
|
|
10
|
+
if (requested <= maxQuota) return [];
|
|
11
|
+
return [require_model_errors_operation_errors.quotaAboveMax({
|
|
12
|
+
token,
|
|
13
|
+
requested: require_onchain_validation_helpers_amount.amountOf(underlying, requested),
|
|
14
|
+
maxQuota: require_onchain_validation_helpers_amount.amountOf(underlying, maxQuota)
|
|
15
|
+
})];
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
exports.checkMaxQuota = checkMaxQuota;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_model_errors_operation_errors = require("../../../model/errors/operation-errors.js");
|
|
3
|
+
require("../../../model/index.js");
|
|
4
|
+
//#region src/onchain/validation/checks/checkQuotaActive.ts
|
|
5
|
+
/** A token whose quota the keeper does not manage at all. */
|
|
6
|
+
function checkQuotaActive(args) {
|
|
7
|
+
return args.isActive ? [] : [require_model_errors_operation_errors.quotaInactive(args.token)];
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
exports.checkQuotaActive = checkQuotaActive;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_model_errors_operation_errors = require("../../../model/errors/operation-errors.js");
|
|
3
|
+
require("../../../model/index.js");
|
|
4
|
+
const require_onchain_validation_helpers_amount = require("../helpers/amount.js");
|
|
5
|
+
require("../helpers/index.js");
|
|
6
|
+
//#region src/onchain/validation/checks/checkQuotaChange.ts
|
|
7
|
+
/** A quota update that rounds to nothing. */
|
|
8
|
+
function checkQuotaChange(args) {
|
|
9
|
+
const { token, current, requested, change, underlying } = args;
|
|
10
|
+
if (change !== 0n) return [];
|
|
11
|
+
return [require_model_errors_operation_errors.quotaUnchanged({
|
|
12
|
+
token,
|
|
13
|
+
current: require_onchain_validation_helpers_amount.amountOf(underlying, current),
|
|
14
|
+
requested: require_onchain_validation_helpers_amount.amountOf(underlying, requested)
|
|
15
|
+
})];
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
exports.checkQuotaChange = checkQuotaChange;
|
|
@@ -9,9 +9,12 @@ const require_onchain_validation_checks_checkForbiddenToken = require("./checkFo
|
|
|
9
9
|
const require_onchain_validation_checks_checkLeverage = require("./checkLeverage.js");
|
|
10
10
|
const require_onchain_validation_checks_checkLiquidatorEligible = require("./checkLiquidatorEligible.js");
|
|
11
11
|
const require_onchain_validation_checks_checkMarketExpired = require("./checkMarketExpired.js");
|
|
12
|
+
const require_onchain_validation_checks_checkMaxQuota = require("./checkMaxQuota.js");
|
|
12
13
|
const require_onchain_validation_checks_checkPoolLiquidity = require("./checkPoolLiquidity.js");
|
|
13
14
|
const require_onchain_validation_checks_checkPoolPaused = require("./checkPoolPaused.js");
|
|
14
15
|
const require_onchain_validation_checks_checkPoolSunset = require("./checkPoolSunset.js");
|
|
16
|
+
const require_onchain_validation_checks_checkQuotaActive = require("./checkQuotaActive.js");
|
|
17
|
+
const require_onchain_validation_checks_checkQuotaChange = require("./checkQuotaChange.js");
|
|
15
18
|
const require_onchain_validation_checks_checkQuotaCount = require("./checkQuotaCount.js");
|
|
16
19
|
const require_onchain_validation_checks_checkQuotaLimit = require("./checkQuotaLimit.js");
|
|
17
20
|
const require_onchain_validation_checks_checkReservePriceLimited = require("./checkReservePriceLimited.js");
|
|
@@ -25,9 +28,12 @@ exports.checkForbiddenToken = require_onchain_validation_checks_checkForbiddenTo
|
|
|
25
28
|
exports.checkLeverage = require_onchain_validation_checks_checkLeverage.checkLeverage;
|
|
26
29
|
exports.checkLiquidatorEligible = require_onchain_validation_checks_checkLiquidatorEligible.checkLiquidatorEligible;
|
|
27
30
|
exports.checkMarketExpired = require_onchain_validation_checks_checkMarketExpired.checkMarketExpired;
|
|
31
|
+
exports.checkMaxQuota = require_onchain_validation_checks_checkMaxQuota.checkMaxQuota;
|
|
28
32
|
exports.checkPoolLiquidity = require_onchain_validation_checks_checkPoolLiquidity.checkPoolLiquidity;
|
|
29
33
|
exports.checkPoolPaused = require_onchain_validation_checks_checkPoolPaused.checkPoolPaused;
|
|
30
34
|
exports.checkPoolSunset = require_onchain_validation_checks_checkPoolSunset.checkPoolSunset;
|
|
35
|
+
exports.checkQuotaActive = require_onchain_validation_checks_checkQuotaActive.checkQuotaActive;
|
|
36
|
+
exports.checkQuotaChange = require_onchain_validation_checks_checkQuotaChange.checkQuotaChange;
|
|
31
37
|
exports.checkQuotaCount = require_onchain_validation_checks_checkQuotaCount.checkQuotaCount;
|
|
32
38
|
exports.checkQuotaLimit = require_onchain_validation_checks_checkQuotaLimit.checkQuotaLimit;
|
|
33
39
|
exports.checkReservePriceLimited = require_onchain_validation_checks_checkReservePriceLimited.checkReservePriceLimited;
|
|
@@ -13,9 +13,12 @@ const require_onchain_validation_checks_checkForbiddenToken = require("./checks/
|
|
|
13
13
|
const require_onchain_validation_checks_checkLeverage = require("./checks/checkLeverage.js");
|
|
14
14
|
const require_onchain_validation_checks_checkLiquidatorEligible = require("./checks/checkLiquidatorEligible.js");
|
|
15
15
|
const require_onchain_validation_checks_checkMarketExpired = require("./checks/checkMarketExpired.js");
|
|
16
|
+
const require_onchain_validation_checks_checkMaxQuota = require("./checks/checkMaxQuota.js");
|
|
16
17
|
const require_onchain_validation_checks_checkPoolLiquidity = require("./checks/checkPoolLiquidity.js");
|
|
17
18
|
const require_onchain_validation_checks_checkPoolPaused = require("./checks/checkPoolPaused.js");
|
|
18
19
|
const require_onchain_validation_checks_checkPoolSunset = require("./checks/checkPoolSunset.js");
|
|
20
|
+
const require_onchain_validation_checks_checkQuotaActive = require("./checks/checkQuotaActive.js");
|
|
21
|
+
const require_onchain_validation_checks_checkQuotaChange = require("./checks/checkQuotaChange.js");
|
|
19
22
|
const require_onchain_validation_checks_checkQuotaCount = require("./checks/checkQuotaCount.js");
|
|
20
23
|
const require_onchain_validation_checks_checkQuotaLimit = require("./checks/checkQuotaLimit.js");
|
|
21
24
|
const require_onchain_validation_checks_checkReservePriceLimited = require("./checks/checkReservePriceLimited.js");
|
|
@@ -29,6 +32,7 @@ const require_onchain_validation_bundles_checkIncreaseDebt = require("./bundles/
|
|
|
29
32
|
const require_onchain_validation_bundles_checkIncreaseQuota = require("./bundles/checkIncreaseQuota.js");
|
|
30
33
|
const require_onchain_validation_bundles_checkMarket = require("./bundles/checkMarket.js");
|
|
31
34
|
const require_onchain_validation_bundles_checkObtained = require("./bundles/checkObtained.js");
|
|
35
|
+
const require_onchain_validation_bundles_checkQuotaUpdates = require("./bundles/checkQuotaUpdates.js");
|
|
32
36
|
const require_onchain_validation_bundles_checkMidasAccountGreenlist = require("./bundles/checkMidasAccountGreenlist.js");
|
|
33
37
|
const require_onchain_validation_bundles_checkRWAOpenRequirements = require("./bundles/checkRWAOpenRequirements.js");
|
|
34
38
|
const require_onchain_validation_bundles_checkRWAOpening = require("./bundles/checkRWAOpening.js");
|
|
@@ -68,6 +72,7 @@ exports.checkLiquidationFunding = require_onchain_validation_bundles_checkLiquid
|
|
|
68
72
|
exports.checkLiquidatorEligible = require_onchain_validation_checks_checkLiquidatorEligible.checkLiquidatorEligible;
|
|
69
73
|
exports.checkMarket = require_onchain_validation_bundles_checkMarket.checkMarket;
|
|
70
74
|
exports.checkMarketExpired = require_onchain_validation_checks_checkMarketExpired.checkMarketExpired;
|
|
75
|
+
exports.checkMaxQuota = require_onchain_validation_checks_checkMaxQuota.checkMaxQuota;
|
|
71
76
|
exports.checkMidasAccountGreenlist = require_onchain_validation_bundles_checkMidasAccountGreenlist.checkMidasAccountGreenlist;
|
|
72
77
|
exports.checkObtained = require_onchain_validation_bundles_checkObtained.checkObtained;
|
|
73
78
|
exports.checkOperation = require_onchain_validation_checkOperation.checkOperation;
|
|
@@ -76,8 +81,11 @@ exports.checkPoolLiquidity = require_onchain_validation_checks_checkPoolLiquidit
|
|
|
76
81
|
exports.checkPoolOperation = require_onchain_validation_bundles_checkPoolOperation.checkPoolOperation;
|
|
77
82
|
exports.checkPoolPaused = require_onchain_validation_checks_checkPoolPaused.checkPoolPaused;
|
|
78
83
|
exports.checkPoolSunset = require_onchain_validation_checks_checkPoolSunset.checkPoolSunset;
|
|
84
|
+
exports.checkQuotaActive = require_onchain_validation_checks_checkQuotaActive.checkQuotaActive;
|
|
85
|
+
exports.checkQuotaChange = require_onchain_validation_checks_checkQuotaChange.checkQuotaChange;
|
|
79
86
|
exports.checkQuotaCount = require_onchain_validation_checks_checkQuotaCount.checkQuotaCount;
|
|
80
87
|
exports.checkQuotaLimit = require_onchain_validation_checks_checkQuotaLimit.checkQuotaLimit;
|
|
88
|
+
exports.checkQuotaUpdates = require_onchain_validation_bundles_checkQuotaUpdates.checkQuotaUpdates;
|
|
81
89
|
exports.checkRWAOpenRequirements = require_onchain_validation_bundles_checkRWAOpenRequirements.checkRWAOpenRequirements;
|
|
82
90
|
exports.checkRWAOpening = require_onchain_validation_bundles_checkRWAOpening.checkRWAOpening;
|
|
83
91
|
exports.checkReservePriceLimited = require_onchain_validation_checks_checkReservePriceLimited.checkReservePriceLimited;
|
|
@@ -372,6 +372,16 @@ var PrepareApi = class extends require_onchain_base_MultichainConstruct.Multicha
|
|
|
372
372
|
});
|
|
373
373
|
}
|
|
374
374
|
/**
|
|
375
|
+
* {@inheritDoc IOpportunitiesPrepare.updateQuota}
|
|
376
|
+
**/
|
|
377
|
+
async updateQuota(position, params) {
|
|
378
|
+
return this.#startIntent(position, params, {
|
|
379
|
+
type: "UPDATE_QUOTA",
|
|
380
|
+
token: params.token,
|
|
381
|
+
quota: params.quota
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
375
385
|
* {@inheritDoc IOpportunitiesPrepare.leverageBand}
|
|
376
386
|
**/
|
|
377
387
|
leverageBand(strategy, collateral, targetHF, position) {
|
package/dist/esm/dev/ltUtils.js
CHANGED
|
@@ -14,13 +14,14 @@ import { erc20Abi, parseEther } from "viem";
|
|
|
14
14
|
*/
|
|
15
15
|
async function setLTs(anvil, cm, newLTs, logger) {
|
|
16
16
|
const configuratorAddr = await impresonateCCOwner(anvil, cm);
|
|
17
|
-
for (const [t, lt] of Object.entries(newLTs)) await anvil.
|
|
17
|
+
for (const [t, lt] of Object.entries(newLTs)) await anvil.writeContractSync({
|
|
18
18
|
chain: anvil.chain,
|
|
19
19
|
address: cm.creditConfigurator.baseParams.addr,
|
|
20
20
|
account: configuratorAddr,
|
|
21
21
|
abi: iCreditConfiguratorV310Abi,
|
|
22
22
|
functionName: "setLiquidationThreshold",
|
|
23
|
-
args: [t, lt]
|
|
23
|
+
args: [t, lt],
|
|
24
|
+
throwOnReceiptRevert: true
|
|
24
25
|
});
|
|
25
26
|
await anvil.stopImpersonatingAccount({ address: configuratorAddr });
|
|
26
27
|
await logLTs(anvil, cm, TypedObjectUtils.keys(newLTs), logger);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "./base.js";
|
|
2
2
|
import { creditAccountFrozen, liquidatorNotEligible, notEmergencyLiquidator } from "./liquidation-errors.js";
|
|
3
|
-
import { accountNotMidasGreenlisted, creditManagerPaused, debtOutOfRange, forbiddenToken, insufficientAllowance, insufficientBalance, insufficientCollateral, insufficientPoolLiquidity, leverageOutOfRange, marketExpired, poolPaused, poolSunset, quotaCountExceeded, quotaLimitReached, reservePriceLimited, rwaOpenRequirementsNotMet } from "./operation-errors.js";
|
|
3
|
+
import { accountNotMidasGreenlisted, creditManagerPaused, debtOutOfRange, forbiddenToken, insufficientAllowance, insufficientBalance, insufficientCollateral, insufficientPoolLiquidity, leverageOutOfRange, marketExpired, poolPaused, poolSunset, quotaAboveMax, quotaCountExceeded, quotaInactive, quotaLimitReached, quotaUnchanged, reservePriceLimited, rwaOpenRequirementsNotMet } from "./operation-errors.js";
|
|
4
4
|
import { unpriceableTokenError } from "./oracle-errors.js";
|
|
5
5
|
import { creditAccountNotEmpty, creditAccountNotFound, multipleDelayedWithdrawals, noDelayedRoute, noRecordedIntent, noStrategyTargetCollateral, unexpectedFailure, unsupportedCollateralToken, unsupportedTokenPair, withdrawalInProgress } from "./prepare-errors.js";
|
|
6
6
|
import { malformedTransaction } from "./preview-errors.js";
|
|
7
|
-
export { accountNotMidasGreenlisted, creditAccountFrozen, creditAccountNotEmpty, creditAccountNotFound, creditManagerPaused, debtOutOfRange, forbiddenToken, insufficientAllowance, insufficientBalance, insufficientCollateral, insufficientPoolLiquidity, leverageOutOfRange, liquidatorNotEligible, malformedTransaction, marketExpired, multipleDelayedWithdrawals, noDelayedRoute, noRecordedIntent, noStrategyTargetCollateral, notEmergencyLiquidator, poolPaused, poolSunset, quotaCountExceeded, quotaLimitReached, reservePriceLimited, rwaOpenRequirementsNotMet, unexpectedFailure, unpriceableTokenError, unsupportedCollateralToken, unsupportedTokenPair, withdrawalInProgress };
|
|
7
|
+
export { accountNotMidasGreenlisted, creditAccountFrozen, creditAccountNotEmpty, creditAccountNotFound, creditManagerPaused, debtOutOfRange, forbiddenToken, insufficientAllowance, insufficientBalance, insufficientCollateral, insufficientPoolLiquidity, leverageOutOfRange, liquidatorNotEligible, malformedTransaction, marketExpired, multipleDelayedWithdrawals, noDelayedRoute, noRecordedIntent, noStrategyTargetCollateral, notEmergencyLiquidator, poolPaused, poolSunset, quotaAboveMax, quotaCountExceeded, quotaInactive, quotaLimitReached, quotaUnchanged, reservePriceLimited, rwaOpenRequirementsNotMet, unexpectedFailure, unpriceableTokenError, unsupportedCollateralToken, unsupportedTokenPair, withdrawalInProgress };
|
|
@@ -100,6 +100,30 @@ function quotaCountExceeded(count, max) {
|
|
|
100
100
|
max
|
|
101
101
|
};
|
|
102
102
|
}
|
|
103
|
+
/** {@inheritDoc QuotaInactiveError} */
|
|
104
|
+
function quotaInactive(token) {
|
|
105
|
+
return {
|
|
106
|
+
code: "quotaInactive",
|
|
107
|
+
message: `${token.symbol} has no active quota in this market.`,
|
|
108
|
+
token
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/** {@inheritDoc QuotaUnchangedError} */
|
|
112
|
+
function quotaUnchanged(args) {
|
|
113
|
+
return {
|
|
114
|
+
code: "quotaUnchanged",
|
|
115
|
+
message: `${args.token.symbol} quota of ${args.requested.value} rounds to the current ${args.current.value}.`,
|
|
116
|
+
...args
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/** {@inheritDoc QuotaAboveMaxError} */
|
|
120
|
+
function quotaAboveMax(args) {
|
|
121
|
+
return {
|
|
122
|
+
code: "quotaAboveMax",
|
|
123
|
+
message: `${args.token.symbol} quota of ${args.requested.value} exceeds maxQuota ${args.maxQuota.value}.`,
|
|
124
|
+
...args
|
|
125
|
+
};
|
|
126
|
+
}
|
|
103
127
|
/** {@inheritDoc InsufficientBalanceError} */
|
|
104
128
|
function insufficientBalance(args = {}) {
|
|
105
129
|
const { required, held } = args;
|
|
@@ -134,4 +158,4 @@ function accountNotMidasGreenlisted(args) {
|
|
|
134
158
|
};
|
|
135
159
|
}
|
|
136
160
|
//#endregion
|
|
137
|
-
export { accountNotMidasGreenlisted, creditManagerPaused, debtOutOfRange, forbiddenToken, insufficientAllowance, insufficientBalance, insufficientCollateral, insufficientPoolLiquidity, leverageOutOfRange, marketExpired, poolPaused, poolSunset, quotaCountExceeded, quotaLimitReached, reservePriceLimited, rwaOpenRequirementsNotMet };
|
|
161
|
+
export { accountNotMidasGreenlisted, creditManagerPaused, debtOutOfRange, forbiddenToken, insufficientAllowance, insufficientBalance, insufficientCollateral, insufficientPoolLiquidity, leverageOutOfRange, marketExpired, poolPaused, poolSunset, quotaAboveMax, quotaCountExceeded, quotaInactive, quotaLimitReached, quotaUnchanged, reservePriceLimited, rwaOpenRequirementsNotMet };
|
package/dist/esm/model/index.js
CHANGED
|
@@ -15,7 +15,7 @@ import { ANALYTICS_POSITIONS_DEFAULT_LIMIT, ANALYTICS_POSITIONS_MAX_LIMIT, analy
|
|
|
15
15
|
import "./curators.js";
|
|
16
16
|
import "./delayed-intents.js";
|
|
17
17
|
import { creditAccountFrozen, liquidatorNotEligible, notEmergencyLiquidator } from "./errors/liquidation-errors.js";
|
|
18
|
-
import { accountNotMidasGreenlisted, creditManagerPaused, debtOutOfRange, forbiddenToken, insufficientAllowance, insufficientBalance, insufficientCollateral, insufficientPoolLiquidity, leverageOutOfRange, marketExpired, poolPaused, poolSunset, quotaCountExceeded, quotaLimitReached, reservePriceLimited, rwaOpenRequirementsNotMet } from "./errors/operation-errors.js";
|
|
18
|
+
import { accountNotMidasGreenlisted, creditManagerPaused, debtOutOfRange, forbiddenToken, insufficientAllowance, insufficientBalance, insufficientCollateral, insufficientPoolLiquidity, leverageOutOfRange, marketExpired, poolPaused, poolSunset, quotaAboveMax, quotaCountExceeded, quotaInactive, quotaLimitReached, quotaUnchanged, reservePriceLimited, rwaOpenRequirementsNotMet } from "./errors/operation-errors.js";
|
|
19
19
|
import { unpriceableTokenError } from "./errors/oracle-errors.js";
|
|
20
20
|
import { creditAccountNotEmpty, creditAccountNotFound, multipleDelayedWithdrawals, noDelayedRoute, noRecordedIntent, noStrategyTargetCollateral, unexpectedFailure, unsupportedCollateralToken, unsupportedTokenPair, withdrawalInProgress } from "./errors/prepare-errors.js";
|
|
21
21
|
import { malformedTransaction } from "./errors/preview-errors.js";
|
|
@@ -33,4 +33,4 @@ import { safeValue, sdkErr, sdkOk } from "./result.js";
|
|
|
33
33
|
import "./rewards.js";
|
|
34
34
|
import "./withdrawals.js";
|
|
35
35
|
import { positionClaimableWithdrawalSchema, positionPendingWithdrawalSchema, positionWithdrawalsSchema, withdrawalOutputAmountSchema } from "./withdrawals.schema.js";
|
|
36
|
-
export { ANALYTICS_POSITIONS_DEFAULT_LIMIT, ANALYTICS_POSITIONS_MAX_LIMIT, CHART_METRIC_UNITS, CHART_RANGES, CHART_UNAVAILABLE_CODES, FILTER_ALL, KYC_REGISTRATION_LINKS, POOL_OPPORTUNITY_CHART_METRICS, POOL_POSITION_CHART_METRICS, PROTOCOL_CHART_METRICS, RWA_FACTORY_SECURITIZE, RWA_FACTORY_TYPES, RWA_PROTOCOLS, SECURITIZE_REGISTER_VAULT_TYPES, STRATEGY_OPPORTUNITY_CHART_METRICS, STRATEGY_POSITION_CHART_METRICS, STRATEGY_POSITION_COLLATERAL_ERROR, accountNotMidasGreenlisted, amountSchema, analyticsChartQueryOptionsSchema, analyticsChartQueryParamsSchema, analyticsChartQuerySchema, analyticsPositionListOptionsSchema, analyticsPositionListQueryParamsSchema, analyticsPositionListQuerySchema, analyticsPositionPageSchema, analyticsPositionSchema, analyticsPositionSortFieldSchema, analyticsSortDirectionSchema, apyBreakdownSchema, asEstimated, assetTypeSchema, backendPreferred, booleanParamSchema, borrowRateBreakdownSchema, bpsSchema, chainFailedSchema, chainIdSchema, chainMetadataSchema, chainSucceededSchema, chartBundleSchemaFor, chartDenominationSchema, chartMetricSchema, chartQueryCodec, chartQueryParamsSchema, chartQuerySchema, chartRangeSchema, chartSeriesSchema, chartValueSchema, chartWindowSchema, compareTagOf, creditAccountFrozen, creditAccountNotEmpty, creditAccountNotFound, creditManagerPaused, curatorNameSchema, curatorSchema, dataSourceSchema, debtOutOfRange, delayedReceivedAssetSchema, encodeFlag, filterAllSchema, filterable, forbiddenToken, instantReceivedAssetSchema, insufficientAllowance, insufficientBalance, insufficientCollateral, insufficientPoolLiquidity, isFilterSet, kycRequirementSchema, leverageOutOfRange, leverageSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionId, liquidationPositionSchema, liquidatorNotEligible, malformedTransaction, marketExpired, matchesLiquidatableAccountFilter, matchesOpportunityFilter, matchesPositionFilter, multipleDelayedWithdrawals, noDelayedRoute, noRecordedIntent, noStrategyTargetCollateral, notEmergencyLiquidator, noticeKindSchema, noticeSchema, offchainOnly, onchainOnly, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterQueryParamsSchema, opportunityFilterQuerySchema, opportunityFilterSchema, opportunityId, opportunityKeySchema, opportunityKindSchema, opportunitySchema, opportunityTotalsSchema, pnlBreakdownSchema, pointRewardsSchema, pointsProgramPnLSchema, pointsProgramSchema, pointsRewardsPnLSchema, poolOpportunityChartMetricSchema, poolOpportunityDetailSchema, poolOpportunityId, poolOpportunityKeySchema, poolOpportunitySchema, poolPaused, poolPositionChartMetricSchema, poolPositionId, poolPositionKeySchema, poolPositionSchema, poolSunset, positionClaimableWithdrawalSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionId, positionKeySchema, positionKindSchema, positionPendingWithdrawalSchema, positionSchema, positionTransactionKindSchema, positionTransactionSchema, positionWithdrawalsSchema, positionsTotalsSchema, priceFeedDataSchema, priceFeedSummarySchema, protocolChartMetricSchema, quotaAssetSchema, quotaCountExceeded, quotaLimitReached, rateCurvePointSchema, rateCurveSchema, receivedAssetSchema, reservePriceLimited, responseMetadataSchema, responseSchema, rewardsPnLSchema, rewardsSchema, rwaOpenRequirementsNotMet, rwaProtocolSchema, safeValue, sdkErr, sdkOk, strategyOpportunityChartMetricSchema, strategyOpportunityDetailSchema, strategyOpportunityId, strategyOpportunityKeySchema, strategyOpportunitySchema, strategyPositionChartMetricSchema, strategyPositionId, strategyPositionKeySchema, strategyPositionSchema, timestampSchema, tokenAmountSchema, tokenQuotaRateSchema, tokenRewardsPnLSchema, tokenRewardsSchema, tokenSchema, tolerance, txCallSchema, underlyingTokenSchema, unexpectedFailure, unpriceableTokenError, unsupportedCollateralToken, unsupportedTokenPair, withdrawalInProgress, withdrawalOutputAmountSchema };
|
|
36
|
+
export { ANALYTICS_POSITIONS_DEFAULT_LIMIT, ANALYTICS_POSITIONS_MAX_LIMIT, CHART_METRIC_UNITS, CHART_RANGES, CHART_UNAVAILABLE_CODES, FILTER_ALL, KYC_REGISTRATION_LINKS, POOL_OPPORTUNITY_CHART_METRICS, POOL_POSITION_CHART_METRICS, PROTOCOL_CHART_METRICS, RWA_FACTORY_SECURITIZE, RWA_FACTORY_TYPES, RWA_PROTOCOLS, SECURITIZE_REGISTER_VAULT_TYPES, STRATEGY_OPPORTUNITY_CHART_METRICS, STRATEGY_POSITION_CHART_METRICS, STRATEGY_POSITION_COLLATERAL_ERROR, accountNotMidasGreenlisted, amountSchema, analyticsChartQueryOptionsSchema, analyticsChartQueryParamsSchema, analyticsChartQuerySchema, analyticsPositionListOptionsSchema, analyticsPositionListQueryParamsSchema, analyticsPositionListQuerySchema, analyticsPositionPageSchema, analyticsPositionSchema, analyticsPositionSortFieldSchema, analyticsSortDirectionSchema, apyBreakdownSchema, asEstimated, assetTypeSchema, backendPreferred, booleanParamSchema, borrowRateBreakdownSchema, bpsSchema, chainFailedSchema, chainIdSchema, chainMetadataSchema, chainSucceededSchema, chartBundleSchemaFor, chartDenominationSchema, chartMetricSchema, chartQueryCodec, chartQueryParamsSchema, chartQuerySchema, chartRangeSchema, chartSeriesSchema, chartValueSchema, chartWindowSchema, compareTagOf, creditAccountFrozen, creditAccountNotEmpty, creditAccountNotFound, creditManagerPaused, curatorNameSchema, curatorSchema, dataSourceSchema, debtOutOfRange, delayedReceivedAssetSchema, encodeFlag, filterAllSchema, filterable, forbiddenToken, instantReceivedAssetSchema, insufficientAllowance, insufficientBalance, insufficientCollateral, insufficientPoolLiquidity, isFilterSet, kycRequirementSchema, leverageOutOfRange, leverageSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionId, liquidationPositionSchema, liquidatorNotEligible, malformedTransaction, marketExpired, matchesLiquidatableAccountFilter, matchesOpportunityFilter, matchesPositionFilter, multipleDelayedWithdrawals, noDelayedRoute, noRecordedIntent, noStrategyTargetCollateral, notEmergencyLiquidator, noticeKindSchema, noticeSchema, offchainOnly, onchainOnly, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterQueryParamsSchema, opportunityFilterQuerySchema, opportunityFilterSchema, opportunityId, opportunityKeySchema, opportunityKindSchema, opportunitySchema, opportunityTotalsSchema, pnlBreakdownSchema, pointRewardsSchema, pointsProgramPnLSchema, pointsProgramSchema, pointsRewardsPnLSchema, poolOpportunityChartMetricSchema, poolOpportunityDetailSchema, poolOpportunityId, poolOpportunityKeySchema, poolOpportunitySchema, poolPaused, poolPositionChartMetricSchema, poolPositionId, poolPositionKeySchema, poolPositionSchema, poolSunset, positionClaimableWithdrawalSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionId, positionKeySchema, positionKindSchema, positionPendingWithdrawalSchema, positionSchema, positionTransactionKindSchema, positionTransactionSchema, positionWithdrawalsSchema, positionsTotalsSchema, priceFeedDataSchema, priceFeedSummarySchema, protocolChartMetricSchema, quotaAboveMax, quotaAssetSchema, quotaCountExceeded, quotaInactive, quotaLimitReached, quotaUnchanged, rateCurvePointSchema, rateCurveSchema, receivedAssetSchema, reservePriceLimited, responseMetadataSchema, responseSchema, rewardsPnLSchema, rewardsSchema, rwaOpenRequirementsNotMet, rwaProtocolSchema, safeValue, sdkErr, sdkOk, strategyOpportunityChartMetricSchema, strategyOpportunityDetailSchema, strategyOpportunityId, strategyOpportunityKeySchema, strategyOpportunitySchema, strategyPositionChartMetricSchema, strategyPositionId, strategyPositionKeySchema, strategyPositionSchema, timestampSchema, tokenAmountSchema, tokenQuotaRateSchema, tokenRewardsPnLSchema, tokenRewardsSchema, tokenSchema, tolerance, txCallSchema, underlyingTokenSchema, unexpectedFailure, unpriceableTokenError, unsupportedCollateralToken, unsupportedTokenPair, withdrawalInProgress, withdrawalOutputAmountSchema };
|
|
@@ -16,7 +16,7 @@ import { calcLeverageBand } from "./leverage-band.js";
|
|
|
16
16
|
import { maxBorrow } from "./maxBorrow.js";
|
|
17
17
|
import { maxWithdrawCollateral } from "./maxWithdrawCollateral.js";
|
|
18
18
|
import { buildOpenStrategyState } from "./open-strategy.js";
|
|
19
|
-
import { planAddCollateral, planAdjustLeverage, planAdjustLeverageDelayed, planDeposit, planRepay, planWithdraw, planWithdrawAsset, planWithdrawDelayed } from "./plan.js";
|
|
19
|
+
import { planAddCollateral, planAdjustLeverage, planAdjustLeverageDelayed, planDeposit, planRepay, planUpdateQuota, planWithdraw, planWithdrawAsset, planWithdrawDelayed } from "./plan.js";
|
|
20
20
|
import { withdrawLimits } from "./withdraw-limits.js";
|
|
21
21
|
import { realize } from "./realize.js";
|
|
22
22
|
import { planTail, projectTail } from "./tail.js";
|
|
@@ -64,6 +64,7 @@ var CreditAccountOperationsService = class extends SDKConstruct {
|
|
|
64
64
|
case "DEPOSIT": return planDeposit(intent, view);
|
|
65
65
|
case "REPAY": return planRepay(intent, view);
|
|
66
66
|
case "WITHDRAW": return planWithdraw(intent, view);
|
|
67
|
+
case "UPDATE_QUOTA": return planUpdateQuota(intent, view);
|
|
67
68
|
default: throw new Error(`${intent.type} - not implemented`);
|
|
68
69
|
}
|
|
69
70
|
}, limits));
|
|
@@ -67,7 +67,7 @@ function buildQuotaUpdateOperation(input) {
|
|
|
67
67
|
const quotaAssets = [...update.quotaIncrease, ...update.quotaDecrease];
|
|
68
68
|
const calls = quotaAssets.length === 0 ? [] : sdk.accounts.prepareUpdateQuotas(creditAccount.creditFacade, {
|
|
69
69
|
averageQuota: quotaAssets,
|
|
70
|
-
minQuota: quotaAssets
|
|
70
|
+
minQuota: input.minQuota ?? quotaAssets
|
|
71
71
|
});
|
|
72
72
|
return {
|
|
73
73
|
type: "changeQuota",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MAX_UINT256, PERCENTAGE_FACTOR } from "../../constants/math.js";
|
|
1
|
+
import { MAX_UINT256, PERCENTAGE_FACTOR, isZeroBalance } from "../../constants/math.js";
|
|
2
2
|
import "../../constants/index.js";
|
|
3
3
|
import { debtOutOfRange, insufficientBalance, leverageOutOfRange } from "../../../model/errors/operation-errors.js";
|
|
4
4
|
import { noDelayedRoute, unsupportedCollateralToken } from "../../../model/errors/prepare-errors.js";
|
|
@@ -86,6 +86,26 @@ function planRepay(intent, view) {
|
|
|
86
86
|
];
|
|
87
87
|
}
|
|
88
88
|
/**
|
|
89
|
+
* One token's quota changes; no balance moves and debt is untouched.
|
|
90
|
+
*
|
|
91
|
+
* Only a token the account holds can be quoted here, and only on an account
|
|
92
|
+
* that owes something: the facade refuses any quota change at zero debt.
|
|
93
|
+
*/
|
|
94
|
+
function planUpdateQuota(intent, view) {
|
|
95
|
+
const U = view.underlying;
|
|
96
|
+
if (eq(intent.token, U) || isZeroBalance(view.balanceOf(intent.token))) throw new IntentPreviewError(unsupportedCollateralToken(toToken(view.sdk, intent.token)), `updateQuota: ${intent.token} is the underlying or not held by the account`);
|
|
97
|
+
if (view.debt <= 0n) throw new IntentPreviewError(debtOutOfRange({
|
|
98
|
+
requested: toTokenAmount(view.sdk, U, 0n),
|
|
99
|
+
minDebt: toTokenAmount(view.sdk, U, view.debtLimits.minDebt),
|
|
100
|
+
maxDebt: toTokenAmount(view.sdk, U, view.debtLimits.maxDebt)
|
|
101
|
+
}), "updateQuota: the account has zero debt");
|
|
102
|
+
return [{
|
|
103
|
+
kind: "updateQuota",
|
|
104
|
+
token: intent.token,
|
|
105
|
+
quota: intent.quota
|
|
106
|
+
}];
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
89
109
|
* Intent 2.1: `W` of value leaves, debt shrinks by `D0 · W / C0` so leverage
|
|
90
110
|
* holds. Both are funded by the source `S`.
|
|
91
111
|
*/
|
|
@@ -407,4 +427,4 @@ function assertPositive(amount, flow) {
|
|
|
407
427
|
if (amount <= 0n) throw new IntentPreviewError(insufficientBalance(), `${flow}: amount must be positive`);
|
|
408
428
|
}
|
|
409
429
|
//#endregion
|
|
410
|
-
export { RAISED, planAddCollateral, planAdjustLeverage, planAdjustLeverageDelayed, planDeposit, planFinishClaimOnly, planFinishCloseAccount, planFinishDecreaseLeverage, planFinishWithdraw, planRepay, planWithdraw, planWithdrawAsset, planWithdrawDelayed };
|
|
430
|
+
export { RAISED, planAddCollateral, planAdjustLeverage, planAdjustLeverageDelayed, planDeposit, planFinishClaimOnly, planFinishCloseAccount, planFinishDecreaseLeverage, planFinishWithdraw, planRepay, planUpdateQuota, planWithdraw, planWithdrawAsset, planWithdrawDelayed };
|
|
@@ -13,6 +13,7 @@ import { collectPriceImpact } from "./utils/price-impact.js";
|
|
|
13
13
|
import { clearedQuotas, getQuotasForUpdate, quotasAfterUpdate, withDirectTransferQuota } from "./utils/quotas-for-update.js";
|
|
14
14
|
import { createRouterPaths } from "./utils/router-path.js";
|
|
15
15
|
import { buildAddCollateralOperation, buildClaimDelayedWithdrawalOperation, buildCloseSwapOperation, buildDecreaseDebtOperation, buildIncreaseDebtOperation, buildQuotaUpdateOperation, buildStartDelayedWithdrawalOperation, buildSwapOperation, buildUnwrapRwaCollateralOperation, buildWithdrawCollateralOperation, buildWrapRwaCollateralOperation, instantOutput } from "./operations.js";
|
|
16
|
+
import { resolveQuotaUpdate } from "./resolveQuotaUpdate.js";
|
|
16
17
|
import { withdrawLimits } from "./withdraw-limits.js";
|
|
17
18
|
//#region src/onchain/accounts/intents/realize.ts
|
|
18
19
|
/**
|
|
@@ -98,10 +99,11 @@ async function realize(steps, props) {
|
|
|
98
99
|
traded.returnedUnd += underlyingValue(returned);
|
|
99
100
|
};
|
|
100
101
|
/**
|
|
101
|
-
* Set by a
|
|
102
|
-
*
|
|
102
|
+
* Set by a step that settles the quotas itself, mid-walk instead of at the
|
|
103
|
+
* end, whatever the balances turn out to be: `clearQuotas` at none,
|
|
104
|
+
* `updateQuota` at the one the intent names.
|
|
103
105
|
*/
|
|
104
|
-
let
|
|
106
|
+
let plannedQuotas;
|
|
105
107
|
/**
|
|
106
108
|
* Whether anything leaves the account, which is what makes the credit manager
|
|
107
109
|
* judge the closing collateral check at safe prices.
|
|
@@ -147,14 +149,34 @@ async function realize(steps, props) {
|
|
|
147
149
|
}));
|
|
148
150
|
break;
|
|
149
151
|
}
|
|
150
|
-
case "clearQuotas":
|
|
151
|
-
cleared = clearedQuotas(creditAccount.tokens);
|
|
152
|
+
case "clearQuotas": {
|
|
153
|
+
const cleared = clearedQuotas(creditAccount.tokens);
|
|
154
|
+
plannedQuotas = cleared;
|
|
152
155
|
if (cleared.quotaDecrease.length > 0) push(buildQuotaUpdateOperation({
|
|
153
156
|
update: cleared,
|
|
154
157
|
creditAccount,
|
|
155
158
|
sdk
|
|
156
159
|
}));
|
|
157
160
|
break;
|
|
161
|
+
}
|
|
162
|
+
case "updateQuota": {
|
|
163
|
+
const { update, minQuota } = resolveQuotaUpdate({
|
|
164
|
+
sdk,
|
|
165
|
+
creditAccount,
|
|
166
|
+
token: step.token,
|
|
167
|
+
quota: step.quota,
|
|
168
|
+
quotaReserve,
|
|
169
|
+
limits: props.limits
|
|
170
|
+
});
|
|
171
|
+
plannedQuotas = update;
|
|
172
|
+
push(buildQuotaUpdateOperation({
|
|
173
|
+
update,
|
|
174
|
+
creditAccount,
|
|
175
|
+
sdk,
|
|
176
|
+
minQuota
|
|
177
|
+
}));
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
158
180
|
case "convert": {
|
|
159
181
|
const amount = amountOf(step.amount);
|
|
160
182
|
if (amount <= 0n) {
|
|
@@ -335,7 +357,7 @@ async function realize(steps, props) {
|
|
|
335
357
|
const floor = ledger.snapshot();
|
|
336
358
|
const { assets, debt } = floor;
|
|
337
359
|
const projected = expected.snapshot();
|
|
338
|
-
const quotas =
|
|
360
|
+
const quotas = plannedQuotas ?? withDirectTransferQuota(getQuotasForUpdate({
|
|
339
361
|
assetsBefore: creditAccount.tokens,
|
|
340
362
|
assetsAfter: assets,
|
|
341
363
|
initialQuotas: creditAccount.tokens,
|
|
@@ -398,7 +420,7 @@ async function realize(steps, props) {
|
|
|
398
420
|
after: projected.assets,
|
|
399
421
|
limits: props.limits
|
|
400
422
|
});
|
|
401
|
-
if (!
|
|
423
|
+
if (!plannedQuotas && quotas.quotaIncrease.length + quotas.quotaDecrease.length > 0) {
|
|
402
424
|
assertQuotaAvailable(sdk, market, quotas.quotaIncrease, props.limits);
|
|
403
425
|
push(buildQuotaUpdateOperation({
|
|
404
426
|
update: quotas,
|