@gearbox-protocol/sdk 14.12.0-next.69 → 14.12.0-next.70
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/common-utils/charts/credit-session.js +0 -1
- package/dist/cjs/common-utils/index.js +1 -1
- package/dist/cjs/common-utils/utils/creditAccount/index.js +1 -1
- package/dist/cjs/common-utils/utils/creditAccount/quota-utils.js +0 -1
- package/dist/cjs/common-utils/utils/index.js +1 -1
- package/dist/cjs/common-utils/utils/strategies/strategy-info/get-cm-you-can-earn.js +1 -1
- package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +81 -66
- package/dist/cjs/sdk/accounts/index.js +2 -0
- package/dist/cjs/sdk/accounts/intents/index.js +388 -0
- package/dist/cjs/sdk/accounts/intents/intents/index.js +14 -0
- package/dist/cjs/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.fixtures.js +121 -0
- package/dist/cjs/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.js +15 -0
- package/dist/cjs/sdk/accounts/intents/intents/resume/close/close.fixtures.js +108 -0
- package/dist/cjs/sdk/accounts/intents/intents/resume/close/close.js +51 -0
- package/dist/cjs/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.fixtures.js +130 -0
- package/dist/cjs/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.js +83 -0
- package/dist/cjs/sdk/accounts/intents/intents/resume/deposit/deposit.fixtures.js +117 -0
- package/dist/cjs/sdk/accounts/intents/intents/resume/deposit/deposit.js +15 -0
- package/dist/cjs/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.fixtures.js +95 -0
- package/dist/cjs/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.js +15 -0
- package/dist/cjs/sdk/accounts/intents/intents/resume/index.js +13 -0
- package/dist/cjs/sdk/accounts/intents/intents/resume/withdraw/withdraw.fixtures.js +138 -0
- package/dist/cjs/sdk/accounts/intents/intents/resume/withdraw/withdraw.js +161 -0
- package/dist/cjs/sdk/accounts/intents/operations/add-collateral/index.js +17 -0
- package/dist/cjs/sdk/accounts/intents/operations/claim-delayed/index.js +54 -0
- package/dist/cjs/sdk/accounts/intents/operations/close-credit-account/index.js +26 -0
- package/dist/cjs/sdk/accounts/intents/operations/decrease-debt/index.js +12 -0
- package/dist/cjs/sdk/accounts/intents/operations/increase-debt/index.js +12 -0
- package/dist/cjs/sdk/accounts/intents/operations/index.js +27 -0
- package/dist/cjs/sdk/accounts/intents/operations/quota-update/index.js +22 -0
- package/dist/cjs/sdk/accounts/intents/operations/repay-credit-account/index.js +22 -0
- package/dist/cjs/sdk/accounts/intents/operations/start-delayed-withdrawal/index.js +18 -0
- package/dist/cjs/sdk/accounts/intents/operations/swap/index.js +18 -0
- package/dist/cjs/sdk/accounts/intents/operations/types.js +1 -0
- package/dist/cjs/sdk/accounts/intents/operations/unwrap-rwa-collateral/index.js +27 -0
- package/dist/cjs/sdk/accounts/intents/operations/withdraw-collateral/index.js +43 -0
- package/dist/cjs/sdk/accounts/intents/operations/wrap-rwa-collateral/index.js +27 -0
- package/dist/cjs/sdk/accounts/intents/quoters/close.js +58 -0
- package/dist/cjs/sdk/accounts/intents/quoters/index.js +7 -0
- package/dist/cjs/sdk/accounts/intents/quoters/swap.js +79 -0
- package/dist/cjs/sdk/accounts/intents/testing/expect.js +167 -0
- package/dist/cjs/sdk/accounts/intents/testing/resume.js +172 -0
- package/dist/cjs/sdk/accounts/intents/testing/sdk-mock.js +179 -0
- package/dist/cjs/sdk/accounts/intents/types.js +1 -0
- package/dist/cjs/sdk/accounts/intents/utils/assemble-operation-calls.js +7 -0
- package/dist/cjs/sdk/accounts/intents/utils/borrowed-amount-plus-interest-and-fees.js +13 -0
- package/dist/cjs/sdk/accounts/intents/utils/common.js +43 -0
- package/dist/cjs/sdk/accounts/intents/utils/convert-amount.js +37 -0
- package/dist/cjs/sdk/accounts/intents/utils/index.js +19 -0
- package/dist/cjs/sdk/accounts/intents/utils/quotas-for-update.js +122 -0
- package/dist/cjs/sdk/accounts/intents/utils/simulate-adjust-state.js +39 -0
- package/dist/cjs/sdk/accounts/intents/utils/simulate-assets.js +69 -0
- package/dist/cjs/sdk/accounts/intents/utils/with-quota-update.js +13 -0
- package/dist/cjs/sdk/index.js +2 -0
- package/dist/esm/common-utils/charts/credit-session.js +0 -1
- package/dist/esm/common-utils/index.js +1 -1
- package/dist/esm/common-utils/utils/creditAccount/index.js +1 -1
- package/dist/esm/common-utils/utils/creditAccount/quota-utils.js +0 -1
- package/dist/esm/common-utils/utils/index.js +1 -1
- package/dist/esm/common-utils/utils/strategies/strategy-info/get-cm-you-can-earn.js +1 -1
- package/dist/esm/dev/AccountOpener.js +1 -1
- package/dist/esm/dev/withdrawalUtils.js +1 -1
- package/dist/esm/preview/simulate/simulatePoolOperation.js +1 -1
- package/dist/esm/preview/trace/extractTransfers.js +1 -1
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +83 -68
- package/dist/esm/sdk/accounts/index.js +2 -1
- package/dist/esm/sdk/accounts/intents/index.js +387 -0
- package/dist/esm/sdk/accounts/intents/intents/index.js +8 -0
- package/dist/esm/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.fixtures.js +107 -0
- package/dist/esm/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.js +14 -0
- package/dist/esm/sdk/accounts/intents/intents/resume/close/close.fixtures.js +94 -0
- package/dist/esm/sdk/accounts/intents/intents/resume/close/close.js +50 -0
- package/dist/esm/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.fixtures.js +114 -0
- package/dist/esm/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.js +82 -0
- package/dist/esm/sdk/accounts/intents/intents/resume/deposit/deposit.fixtures.js +110 -0
- package/dist/esm/sdk/accounts/intents/intents/resume/deposit/deposit.js +14 -0
- package/dist/esm/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.fixtures.js +88 -0
- package/dist/esm/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.js +14 -0
- package/dist/esm/sdk/accounts/intents/intents/resume/index.js +7 -0
- package/dist/esm/sdk/accounts/intents/intents/resume/withdraw/withdraw.fixtures.js +121 -0
- package/dist/esm/sdk/accounts/intents/intents/resume/withdraw/withdraw.js +160 -0
- package/dist/esm/sdk/accounts/intents/operations/add-collateral/index.js +16 -0
- package/dist/esm/sdk/accounts/intents/operations/claim-delayed/index.js +52 -0
- package/dist/esm/sdk/accounts/intents/operations/close-credit-account/index.js +25 -0
- package/dist/esm/sdk/accounts/intents/operations/decrease-debt/index.js +11 -0
- package/dist/esm/sdk/accounts/intents/operations/increase-debt/index.js +11 -0
- package/dist/esm/sdk/accounts/intents/operations/index.js +14 -0
- package/dist/esm/sdk/accounts/intents/operations/quota-update/index.js +21 -0
- package/dist/esm/sdk/accounts/intents/operations/repay-credit-account/index.js +21 -0
- package/dist/esm/sdk/accounts/intents/operations/start-delayed-withdrawal/index.js +17 -0
- package/dist/esm/sdk/accounts/intents/operations/swap/index.js +17 -0
- package/dist/esm/sdk/accounts/intents/operations/types.js +1 -0
- package/dist/esm/sdk/accounts/intents/operations/unwrap-rwa-collateral/index.js +26 -0
- package/dist/esm/sdk/accounts/intents/operations/withdraw-collateral/index.js +42 -0
- package/dist/esm/sdk/accounts/intents/operations/wrap-rwa-collateral/index.js +26 -0
- package/dist/esm/sdk/accounts/intents/quoters/close.js +56 -0
- package/dist/esm/sdk/accounts/intents/quoters/index.js +3 -0
- package/dist/esm/sdk/accounts/intents/quoters/swap.js +77 -0
- package/dist/esm/sdk/accounts/intents/testing/expect.js +162 -0
- package/dist/esm/sdk/accounts/intents/testing/resume.js +157 -0
- package/dist/esm/sdk/accounts/intents/testing/sdk-mock.js +172 -0
- package/dist/esm/sdk/accounts/intents/types.js +1 -0
- package/dist/esm/sdk/accounts/intents/utils/assemble-operation-calls.js +6 -0
- package/dist/esm/sdk/accounts/intents/utils/borrowed-amount-plus-interest-and-fees.js +12 -0
- package/dist/esm/sdk/accounts/intents/utils/common.js +40 -0
- package/dist/esm/sdk/accounts/intents/utils/convert-amount.js +36 -0
- package/dist/esm/sdk/accounts/intents/utils/index.js +9 -0
- package/dist/esm/sdk/accounts/intents/utils/quotas-for-update.js +121 -0
- package/dist/esm/sdk/accounts/intents/utils/simulate-adjust-state.js +38 -0
- package/dist/esm/sdk/accounts/intents/utils/simulate-assets.js +68 -0
- package/dist/esm/sdk/accounts/intents/utils/with-quota-update.js +12 -0
- package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +1 -1
- package/dist/esm/sdk/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
- package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
- package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
- package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
- package/dist/esm/sdk/base/TokensMeta.js +2 -2
- package/dist/esm/sdk/chain/detectNetwork.js +1 -1
- package/dist/esm/sdk/core/createAddressProvider.js +1 -1
- package/dist/esm/sdk/index.js +2 -1
- package/dist/esm/sdk/market/credit/CreditFacadeV310BaseContract.js +1 -1
- package/dist/esm/sdk/market/pool/PoolV310Contract.js +1 -1
- package/dist/esm/sdk/market/zapper/IETHZapperContract.js +1 -1
- package/dist/esm/sdk/market/zapper/ZapperContract.js +1 -1
- package/dist/esm/sdk/pools/PoolService.js +1 -1
- package/dist/esm/sdk/utils/viem/simulateWithPriceUpdates.js +1 -1
- package/dist/types/common-utils/index.d.ts +19 -19
- package/dist/types/common-utils/static/index.d.ts +1 -1
- package/dist/types/common-utils/utils/apy/index.d.ts +1 -1
- package/dist/types/common-utils/utils/creditAccount/calc-health-factor.d.ts +1 -1
- package/dist/types/common-utils/utils/creditAccount/calc-overall-apy.d.ts +1 -1
- package/dist/types/common-utils/utils/creditAccount/calc-quota-borrow-rate.d.ts +1 -1
- package/dist/types/common-utils/utils/creditAccount/debt.d.ts +1 -1
- package/dist/types/common-utils/utils/creditAccount/index.d.ts +1 -1
- package/dist/types/common-utils/utils/creditAccount/liquidation-price.d.ts +1 -1
- package/dist/types/common-utils/utils/creditAccount/quota-utils.d.ts +0 -1
- package/dist/types/common-utils/utils/creditAccount/sort.d.ts +1 -1
- package/dist/types/common-utils/utils/index.d.ts +3 -3
- package/dist/types/common-utils/utils/strategies/credit-managers/get-wallet-balances-allowed-on-cm.d.ts +1 -1
- package/dist/types/common-utils/utils/strategies/strategy-info/calculate-total-apy.d.ts +1 -1
- package/dist/types/common-utils/utils/strategies/strategy-info/calculate-total-points.d.ts +1 -1
- package/dist/types/common-utils/utils/strategies/strategy-info/types.d.ts +1 -1
- package/dist/types/common-utils/utils/strategies/tokens/add-amount-in-target.d.ts +1 -1
- package/dist/types/common-utils/utils/strategies/tokens/get-list-with-amount-in-target.d.ts +1 -1
- package/dist/types/common-utils/utils/strategies/types/credit-manager-data-legacy.d.ts +1 -1
- package/dist/types/common-utils/utils/strategies/types/strategies-cm-list.d.ts +1 -1
- package/dist/types/common-utils/utils/strategies/types/strategy-earnings.d.ts +1 -1
- package/dist/types/common-utils/utils/strategies/types/strategy.d.ts +1 -1
- package/dist/types/common-utils/utils/validation/validate-open-account.d.ts +1 -1
- package/dist/types/common-utils/utils/validation/validate-quota.d.ts +1 -1
- package/dist/types/plugins/apy/ApyPlugin.d.ts +1 -1
- package/dist/types/plugins/apy/pool-apy-utils.d.ts +1 -1
- package/dist/types/plugins/apy/strategy-data-source.d.ts +1 -1
- package/dist/types/plugins/apy/types.d.ts +1 -1
- package/dist/types/plugins/remote-configs/CustomConfigSource.d.ts +1 -1
- package/dist/types/plugins/remote-configs/RemoteConfigSource.d.ts +1 -1
- package/dist/types/plugins/remote-configs/RemoteConfigsPlugin.d.ts +1 -1
- package/dist/types/plugins/remote-configs/index.d.ts +1 -1
- package/dist/types/plugins/remote-configs/types.d.ts +1 -1
- package/dist/types/rewards/rewards/extra-apy.d.ts +1 -1
- package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +30 -10
- package/dist/types/sdk/accounts/index.d.ts +2 -1
- package/dist/types/sdk/accounts/intents/index.d.ts +22 -0
- package/dist/types/sdk/accounts/intents/intents/index.d.ts +8 -0
- package/dist/types/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.d.ts +13 -0
- package/dist/types/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.fixtures.d.ts +38 -0
- package/dist/types/sdk/accounts/intents/intents/resume/close/close.d.ts +26 -0
- package/dist/types/sdk/accounts/intents/intents/resume/close/close.fixtures.d.ts +63 -0
- package/dist/types/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.d.ts +26 -0
- package/dist/types/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.fixtures.d.ts +86 -0
- package/dist/types/sdk/accounts/intents/intents/resume/deposit/deposit.d.ts +13 -0
- package/dist/types/sdk/accounts/intents/intents/resume/deposit/deposit.fixtures.d.ts +48 -0
- package/dist/types/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.d.ts +13 -0
- package/dist/types/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.fixtures.d.ts +46 -0
- package/dist/types/sdk/accounts/intents/intents/resume/index.d.ts +7 -0
- package/dist/types/sdk/accounts/intents/intents/resume/withdraw/withdraw.d.ts +33 -0
- package/dist/types/sdk/accounts/intents/intents/resume/withdraw/withdraw.fixtures.d.ts +68 -0
- package/dist/types/sdk/accounts/intents/operations/add-collateral/index.d.ts +23 -0
- package/dist/types/sdk/accounts/intents/operations/claim-delayed/index.d.ts +55 -0
- package/dist/types/sdk/accounts/intents/operations/close-credit-account/index.d.ts +22 -0
- package/dist/types/sdk/accounts/intents/operations/decrease-debt/index.d.ts +18 -0
- package/dist/types/sdk/accounts/intents/operations/increase-debt/index.d.ts +18 -0
- package/dist/types/sdk/accounts/intents/operations/index.d.ts +14 -0
- package/dist/types/sdk/accounts/intents/operations/quota-update/index.d.ts +24 -0
- package/dist/types/sdk/accounts/intents/operations/repay-credit-account/index.d.ts +32 -0
- package/dist/types/sdk/accounts/intents/operations/start-delayed-withdrawal/index.d.ts +23 -0
- package/dist/types/sdk/accounts/intents/operations/swap/index.d.ts +28 -0
- package/dist/types/sdk/accounts/intents/operations/types.d.ts +21 -0
- package/dist/types/sdk/accounts/intents/operations/unwrap-rwa-collateral/index.d.ts +30 -0
- package/dist/types/sdk/accounts/intents/operations/withdraw-collateral/index.d.ts +36 -0
- package/dist/types/sdk/accounts/intents/operations/wrap-rwa-collateral/index.d.ts +30 -0
- package/dist/types/sdk/accounts/intents/quoters/close.d.ts +43 -0
- package/dist/types/sdk/accounts/intents/quoters/index.d.ts +3 -0
- package/dist/types/sdk/accounts/intents/quoters/swap.d.ts +43 -0
- package/dist/types/sdk/accounts/intents/testing/expect.d.ts +52 -0
- package/dist/types/sdk/accounts/intents/testing/resume.d.ts +84 -0
- package/dist/types/sdk/accounts/intents/testing/sdk-mock.d.ts +90 -0
- package/dist/types/sdk/accounts/intents/types.d.ts +75 -0
- package/dist/types/sdk/accounts/intents/utils/assemble-operation-calls.d.ts +10 -0
- package/dist/types/sdk/accounts/intents/utils/borrowed-amount-plus-interest-and-fees.d.ts +17 -0
- package/dist/types/sdk/accounts/intents/utils/common.d.ts +19 -0
- package/dist/types/sdk/accounts/intents/utils/convert-amount.d.ts +13 -0
- package/dist/types/sdk/accounts/intents/utils/index.d.ts +9 -0
- package/dist/types/sdk/accounts/intents/utils/quotas-for-update.d.ts +35 -0
- package/dist/types/sdk/accounts/intents/utils/simulate-adjust-state.d.ts +19 -0
- package/dist/types/sdk/accounts/intents/utils/simulate-assets.d.ts +21 -0
- package/dist/types/sdk/accounts/intents/utils/with-quota-update.d.ts +16 -0
- package/dist/types/sdk/accounts/types.d.ts +20 -0
- package/dist/types/sdk/index.d.ts +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sdk_utils_mappers = require("../../../utils/mappers.js");
|
|
3
|
+
const require_common_utils_utils_creditAccount_quota_utils = require("../../../../common-utils/utils/creditAccount/quota-utils.js");
|
|
4
|
+
//#region src/sdk/accounts/intents/utils/quotas-for-update.ts
|
|
5
|
+
function getQuotasForUpdate({ assetsBefore, assetsAfter, initialQuotas, quotaReserve = 0, liquidationThresholds: liquidationThresholdsMap, quotas: quotasMap, maxDebt, underlyingToken, convert }) {
|
|
6
|
+
const underlyingTokenLc = underlyingToken.toLowerCase();
|
|
7
|
+
const assetsBeforeLc = assetsBefore.map((a) => ({
|
|
8
|
+
...a,
|
|
9
|
+
token: a.token.toLowerCase()
|
|
10
|
+
}));
|
|
11
|
+
const assetsAfterLc = assetsAfter.map((a) => ({
|
|
12
|
+
...a,
|
|
13
|
+
token: a.token.toLowerCase()
|
|
14
|
+
}));
|
|
15
|
+
const { spend, obtain } = collectQuotaChange(assetsBeforeLc, assetsAfterLc);
|
|
16
|
+
const initialQuotasLc = initialQuotas.map((a) => {
|
|
17
|
+
const tokenLc = a.token.toLowerCase();
|
|
18
|
+
return [tokenLc, {
|
|
19
|
+
...a,
|
|
20
|
+
token: tokenLc
|
|
21
|
+
}];
|
|
22
|
+
});
|
|
23
|
+
const initialQuotasRecord = require_sdk_utils_mappers.TypedObjectUtils.fromEntries(initialQuotasLc);
|
|
24
|
+
const liquidationThresholds = require_sdk_utils_mappers.TypedObjectUtils.fromEntries(liquidationThresholdsMap.entries().map(([token, lt]) => [token.toLowerCase(), BigInt(lt)]));
|
|
25
|
+
const quotas = require_sdk_utils_mappers.TypedObjectUtils.fromEntries(quotasMap.values().map((q) => {
|
|
26
|
+
const token = q.token.toLowerCase();
|
|
27
|
+
return [token, {
|
|
28
|
+
token,
|
|
29
|
+
rate: BigInt(q.rate),
|
|
30
|
+
quotaIncreaseFee: BigInt(q.quotaIncreaseFee),
|
|
31
|
+
totalQuoted: q.totalQuoted,
|
|
32
|
+
limit: q.limit,
|
|
33
|
+
isActive: q.isActive
|
|
34
|
+
}];
|
|
35
|
+
}));
|
|
36
|
+
const assetsWithAmountInTarget = getBalancesAfterWithFullySpent(assetsAfterLc, spend, initialQuotasRecord).map((a) => {
|
|
37
|
+
return {
|
|
38
|
+
...a,
|
|
39
|
+
amountInTarget: convert(a.token, underlyingTokenLc, a.balance)
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
const quotaResult = require_common_utils_utils_creditAccount_quota_utils.calcQuotaUpdate({
|
|
43
|
+
quotas,
|
|
44
|
+
initialQuotas: initialQuotasRecord,
|
|
45
|
+
assetsAfterUpdate: constructAssetRecord(assetsWithAmountInTarget),
|
|
46
|
+
allowedToObtain: constructAssetRecord(obtain),
|
|
47
|
+
allowedToSpend: constructAssetRecord(spend),
|
|
48
|
+
quotaReserve: BigInt(quotaReserve),
|
|
49
|
+
maxDebt,
|
|
50
|
+
liquidationThresholds,
|
|
51
|
+
calcModification: void 0
|
|
52
|
+
});
|
|
53
|
+
return filterQuotaUpdates(quotaResult.desiredQuota, quotaResult.quotaIncrease, quotaResult.quotaDecrease, [...new Set([...spend, ...obtain].map((q) => q.token)).values()]);
|
|
54
|
+
}
|
|
55
|
+
function collectQuotaChange(assetsBefore, assetsAfter) {
|
|
56
|
+
const before = new Map(assetsBefore.map((a) => [a.token, a.balance]));
|
|
57
|
+
const after = new Map(assetsAfter.map((a) => [a.token, a.balance]));
|
|
58
|
+
const tokens = /* @__PURE__ */ new Set([...before.keys(), ...after.keys()]);
|
|
59
|
+
const spend = [];
|
|
60
|
+
const obtain = [];
|
|
61
|
+
for (const token of tokens) {
|
|
62
|
+
const delta = (after.get(token) ?? 0n) - (before.get(token) ?? 0n);
|
|
63
|
+
if (delta > 0n) obtain.push({
|
|
64
|
+
token,
|
|
65
|
+
balance: delta
|
|
66
|
+
});
|
|
67
|
+
else if (delta < 0n) spend.push({
|
|
68
|
+
token,
|
|
69
|
+
balance: -delta
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
spend,
|
|
74
|
+
obtain
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* SDK `getSingleQuotaChange` requires `assetAfter` to emit quota decreases.
|
|
79
|
+
* Simulation drops zero balances, so fully spent collaterals (e.g. claim
|
|
80
|
+
* phantom) vanish — reinsert them with balance 0 when they still have
|
|
81
|
+
* initial quota so `calcQuotaUpdate` can zero / remove that quota.
|
|
82
|
+
*/
|
|
83
|
+
function getBalancesAfterWithFullySpent(assetsAfter, tokensSpend, initialQuotas) {
|
|
84
|
+
const assetsAfterRecord = new Map(assetsAfter.map((a) => [a.token, a]));
|
|
85
|
+
for (const s of tokensSpend) {
|
|
86
|
+
if (assetsAfterRecord.has(s.token)) continue;
|
|
87
|
+
if ((initialQuotas[s.token]?.quota ?? 0n) > 0n) assetsAfterRecord.set(s.token, {
|
|
88
|
+
token: s.token,
|
|
89
|
+
balance: 0n
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return [...assetsAfterRecord.values()];
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Restricts quota updates to only tokens that were intended to change.
|
|
96
|
+
*/
|
|
97
|
+
function filterQuotaUpdates(desiredQuota, quotaIncrease, quotaDecrease, tokensToUpdate) {
|
|
98
|
+
if (tokensToUpdate.length === 0) return {
|
|
99
|
+
desiredQuota: {},
|
|
100
|
+
quotaIncrease: [],
|
|
101
|
+
quotaDecrease: []
|
|
102
|
+
};
|
|
103
|
+
const allowed = new Set(tokensToUpdate);
|
|
104
|
+
const restrictedDesired = {};
|
|
105
|
+
for (const token of tokensToUpdate) {
|
|
106
|
+
const asset = desiredQuota[token];
|
|
107
|
+
if (asset) restrictedDesired[token] = asset;
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
desiredQuota: restrictedDesired,
|
|
111
|
+
quotaIncrease: quotaIncrease.filter((a) => allowed.has(a.token)),
|
|
112
|
+
quotaDecrease: quotaDecrease.filter((a) => allowed.has(a.token))
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
function constructAssetRecord(a) {
|
|
116
|
+
return a.reduce((acc, asset) => {
|
|
117
|
+
acc[asset.token] = asset;
|
|
118
|
+
return acc;
|
|
119
|
+
}, {});
|
|
120
|
+
}
|
|
121
|
+
//#endregion
|
|
122
|
+
exports.getQuotasForUpdate = getQuotasForUpdate;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sdk_accounts_intents_utils_quotas_for_update = require("./quotas-for-update.js");
|
|
3
|
+
const require_sdk_accounts_intents_utils_simulate_assets = require("./simulate-assets.js");
|
|
4
|
+
//#region src/sdk/accounts/intents/utils/simulate-adjust-state.ts
|
|
5
|
+
function simulateState(props) {
|
|
6
|
+
const market = props.sdk.marketRegister.findByCreditManager(props.creditAccount.creditManager);
|
|
7
|
+
const convert = (token, to, amount) => market.priceOracle.convert(token, to, amount);
|
|
8
|
+
const creditManager = props.sdk.marketRegister.findCreditManager(props.creditAccount.creditManager);
|
|
9
|
+
const { assets, totalValue, debt } = require_sdk_accounts_intents_utils_simulate_assets.simulateOperationAssets({
|
|
10
|
+
initialAssets: props.creditAccount.tokens,
|
|
11
|
+
operations: props.operations,
|
|
12
|
+
underlyingToken: props.creditAccount.underlying,
|
|
13
|
+
debt: props.creditAccount.accountDebt,
|
|
14
|
+
convert
|
|
15
|
+
});
|
|
16
|
+
const quotaResult = require_sdk_accounts_intents_utils_quotas_for_update.getQuotasForUpdate({
|
|
17
|
+
assetsBefore: props.creditAccount.tokens,
|
|
18
|
+
assetsAfter: assets,
|
|
19
|
+
liquidationThresholds: creditManager.creditManager.liquidationThresholds,
|
|
20
|
+
quotas: market.pool.pqk.quotas,
|
|
21
|
+
initialQuotas: props.creditAccount.tokens,
|
|
22
|
+
quotaReserve: props.quotaReserve,
|
|
23
|
+
underlyingToken: props.creditAccount.underlying,
|
|
24
|
+
maxDebt: creditManager.creditFacade.maxDebt,
|
|
25
|
+
convert
|
|
26
|
+
});
|
|
27
|
+
return {
|
|
28
|
+
state: {
|
|
29
|
+
kind: "adjust",
|
|
30
|
+
totalValue,
|
|
31
|
+
accountDebt: debt,
|
|
32
|
+
assets,
|
|
33
|
+
quotas: quotaResult.desiredQuota
|
|
34
|
+
},
|
|
35
|
+
quotaResult
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
exports.simulateState = simulateState;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sdk_utils_bigint_math = require("../../../utils/bigint-math.js");
|
|
3
|
+
//#region src/sdk/accounts/intents/utils/simulate-assets.ts
|
|
4
|
+
/** Apply an op chain to CA token balances. Address keys are lowercased. */
|
|
5
|
+
function simulateOperationAssets({ initialAssets, operations, underlyingToken, debt, convert }) {
|
|
6
|
+
let debtAfter = debt;
|
|
7
|
+
const balances = /* @__PURE__ */ new Map();
|
|
8
|
+
for (const asset of initialAssets) {
|
|
9
|
+
const token = asset.token.toLowerCase();
|
|
10
|
+
balances.set(token, (balances.get(token) ?? 0n) + asset.balance);
|
|
11
|
+
}
|
|
12
|
+
const get = (token) => balances.get(token.toLowerCase()) ?? 0n;
|
|
13
|
+
const set = (token, balance) => {
|
|
14
|
+
const key = token.toLowerCase();
|
|
15
|
+
if (balance <= 0n) balances.delete(key);
|
|
16
|
+
else balances.set(key, balance);
|
|
17
|
+
};
|
|
18
|
+
for (const op of operations) switch (op.type) {
|
|
19
|
+
case "changeQuota":
|
|
20
|
+
case "closeCreditAccount":
|
|
21
|
+
case "repayCreditAccount": break;
|
|
22
|
+
case "increaseDebt":
|
|
23
|
+
debtAfter = debtAfter + op.amount;
|
|
24
|
+
set(underlyingToken, get(underlyingToken) + op.amount);
|
|
25
|
+
break;
|
|
26
|
+
case "decreaseDebt":
|
|
27
|
+
debtAfter = require_sdk_utils_bigint_math.BigIntMath.max(0n, debtAfter - op.amount);
|
|
28
|
+
set(underlyingToken, get(underlyingToken) - op.amount);
|
|
29
|
+
break;
|
|
30
|
+
case "addCollateral":
|
|
31
|
+
set(op.token, get(op.token) + op.amount);
|
|
32
|
+
break;
|
|
33
|
+
case "withdrawCollateral":
|
|
34
|
+
set(op.token, get(op.token) - op.amount);
|
|
35
|
+
break;
|
|
36
|
+
case "swap":
|
|
37
|
+
for (const swapInput of op.from) set(swapInput.token, get(swapInput.token) - swapInput.balance);
|
|
38
|
+
set(op.tokenOut, get(op.tokenOut) + op.amountOut);
|
|
39
|
+
break;
|
|
40
|
+
case "wrapRwaCollateral":
|
|
41
|
+
set(op.tokenIn, get(op.tokenIn) - op.amount);
|
|
42
|
+
set(op.tokenOut, get(op.tokenOut) + op.amountOut);
|
|
43
|
+
break;
|
|
44
|
+
case "unwrapRwaCollateral":
|
|
45
|
+
set(op.tokenIn, get(op.tokenIn) - op.amount);
|
|
46
|
+
set(op.tokenOut, get(op.tokenOut) + op.amountOut);
|
|
47
|
+
break;
|
|
48
|
+
case "startDelayedWithdrawal":
|
|
49
|
+
set(op.token, get(op.token) - op.amountIn);
|
|
50
|
+
for (const out of op.outputs) set(out.token, get(out.token) + out.amount);
|
|
51
|
+
break;
|
|
52
|
+
case "claimDelayedWithdrawal":
|
|
53
|
+
set(op.withdrawalPhantomToken, get(op.withdrawalPhantomToken) - op.withdrawalTokenSpent);
|
|
54
|
+
for (const out of op.outputs) set(out.token, get(out.token) + out.amount);
|
|
55
|
+
}
|
|
56
|
+
const assets = [...balances.entries()].map(([token, balance]) => ({
|
|
57
|
+
token: token.toLowerCase(),
|
|
58
|
+
balance
|
|
59
|
+
}));
|
|
60
|
+
return {
|
|
61
|
+
assets,
|
|
62
|
+
totalValue: assets.reduce((acc, a) => {
|
|
63
|
+
return acc + convert(a.token, underlyingToken, a.balance);
|
|
64
|
+
}, 0n),
|
|
65
|
+
debt: debtAfter
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
exports.simulateOperationAssets = simulateOperationAssets;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sdk_accounts_intents_operations_quota_update_index = require("../operations/quota-update/index.js");
|
|
3
|
+
require("../operations/index.js");
|
|
4
|
+
//#region src/sdk/accounts/intents/utils/with-quota-update.ts
|
|
5
|
+
function getOperationsWithQuotaUpdate({ operations: coreOps, state, creditAccount, sdk, options }) {
|
|
6
|
+
return state.quotaResult.quotaIncrease.length + state.quotaResult.quotaDecrease.length === 0 ? coreOps : [...coreOps, require_sdk_accounts_intents_operations_quota_update_index.buildQuotaUpdateOperation({
|
|
7
|
+
update: state.quotaResult,
|
|
8
|
+
creditAccount,
|
|
9
|
+
sdk
|
|
10
|
+
}, options)];
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
exports.getOperationsWithQuotaUpdate = getOperationsWithQuotaUpdate;
|
package/dist/cjs/sdk/index.js
CHANGED
|
@@ -104,6 +104,7 @@ const require_sdk_market_rwa_RWARegistry = require("./market/rwa/RWARegistry.js"
|
|
|
104
104
|
const require_sdk_market_rwa_types = require("./market/rwa/types.js");
|
|
105
105
|
require("./market/index.js");
|
|
106
106
|
const require_sdk_accounts_CreditAccountsServiceV310 = require("./accounts/CreditAccountsServiceV310.js");
|
|
107
|
+
const require_sdk_accounts_intents_index = require("./accounts/intents/index.js");
|
|
107
108
|
const require_sdk_accounts_liquidations_constants = require("./accounts/liquidations/constants.js");
|
|
108
109
|
const require_sdk_accounts_liquidations_LiquidationsService = require("./accounts/liquidations/LiquidationsService.js");
|
|
109
110
|
const require_sdk_accounts_liquidations_MultichainLiquidationsService = require("./accounts/liquidations/MultichainLiquidationsService.js");
|
|
@@ -194,6 +195,7 @@ exports.ChainNotConfiguredError = require_sdk_core_errors.ChainNotConfiguredErro
|
|
|
194
195
|
exports.CompositePriceFeedContract = require_sdk_market_pricefeeds_CompositePriceFeed.CompositePriceFeedContract;
|
|
195
196
|
exports.Construct = require_sdk_base_Construct.Construct;
|
|
196
197
|
exports.ContractParseError = require_sdk_base_BaseContract.ContractParseError;
|
|
198
|
+
exports.CreditAccountOperationsService = require_sdk_accounts_intents_index.CreditAccountOperationsService;
|
|
197
199
|
exports.CreditAccountsServiceV310 = require_sdk_accounts_CreditAccountsServiceV310.CreditAccountsServiceV310;
|
|
198
200
|
exports.CreditConfiguratorV310Contract = require_sdk_market_credit_CreditConfiguratorV310Contract.CreditConfiguratorV310Contract;
|
|
199
201
|
exports.CreditFacadeV310BaseContract = require_sdk_market_credit_CreditFacadeV310BaseContract.CreditFacadeV310BaseContract;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { TypedObjectUtils } from "../../sdk/utils/mappers.js";
|
|
2
2
|
import { PERCENTAGE_DECIMALS } from "../../sdk/constants/math.js";
|
|
3
3
|
import { toBigInt } from "../../sdk/utils/formatter.js";
|
|
4
|
-
import "../../sdk/index.js";
|
|
5
4
|
//#region src/common-utils/charts/credit-session.ts
|
|
6
5
|
const CREDIT_SESSION_STATUS_BY_ID = {
|
|
7
6
|
0: "active",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AxiosCache } from "./axios-cache/AxiosCache.js";
|
|
2
2
|
import "./axios-cache/index.js";
|
|
3
3
|
import { BigIntMath } from "../sdk/utils/bigint-math.js";
|
|
4
|
+
import { calcDefaultQuota, calcQuotaUpdate, calcRecommendedQuota, roundUpQuota } from "./utils/creditAccount/quota-utils.js";
|
|
4
5
|
import { ChartsCreditManagerData } from "./charts/credit-manager.js";
|
|
5
6
|
import { CREDIT_SESSION_ID_BY_STATUS, CREDIT_SESSION_STATUS_BY_ID, CreditSession, CreditSessionFiltered, UserCreditSessionsBuilder } from "./charts/credit-session.js";
|
|
6
7
|
import { ChartsPoolData, UserPoolData } from "./charts/pool.js";
|
|
@@ -38,7 +39,6 @@ import { calcRelativeBaseBorrowRate } from "./utils/creditAccount/calc-relative-
|
|
|
38
39
|
import { calcMaxDebtIncrease, calcMaxLendingDebt } from "./utils/creditAccount/debt.js";
|
|
39
40
|
import { getTimeToLiquidation } from "./utils/creditAccount/get-time-to-liquidation.js";
|
|
40
41
|
import { liquidationPrice } from "./utils/creditAccount/liquidation-price.js";
|
|
41
|
-
import { calcDefaultQuota, calcQuotaUpdate, calcRecommendedQuota, roundUpQuota } from "./utils/creditAccount/quota-utils.js";
|
|
42
42
|
import { getDefaultAsset } from "./utils/strategies/assets/assets.js";
|
|
43
43
|
import { checkBoolean } from "./utils/strategies/availability/check-boolean.js";
|
|
44
44
|
import { checkDegenNFT } from "./utils/strategies/availability/check-degen-nft.js";
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { calcDefaultQuota, calcQuotaUpdate, calcRecommendedQuota, roundUpQuota } from "./quota-utils.js";
|
|
1
2
|
import { calcQuotaBorrowRate } from "./calc-quota-borrow-rate.js";
|
|
2
3
|
import { amountAbcComparator, assetComparator, sortAssets, sortBalances, tokensAbcComparator } from "./sort.js";
|
|
3
4
|
import { calcHealthFactor } from "./calc-health-factor.js";
|
|
@@ -6,5 +7,4 @@ import { calcRelativeBaseBorrowRate } from "./calc-relative-base-borrow-rate.js"
|
|
|
6
7
|
import { calcMaxDebtIncrease, calcMaxLendingDebt } from "./debt.js";
|
|
7
8
|
import { getTimeToLiquidation } from "./get-time-to-liquidation.js";
|
|
8
9
|
import { liquidationPrice } from "./liquidation-price.js";
|
|
9
|
-
import { calcDefaultQuota, calcQuotaUpdate, calcRecommendedQuota, roundUpQuota } from "./quota-utils.js";
|
|
10
10
|
export { amountAbcComparator, assetComparator, calcDefaultQuota, calcHealthFactor, calcMaxDebtIncrease, calcMaxLendingDebt, calcOverallAPY, calcQuotaBorrowRate, calcQuotaUpdate, calcRecommendedQuota, calcRelativeBaseBorrowRate, getTimeToLiquidation, liquidationPrice, roundUpQuota, sortAssets, sortBalances, tokensAbcComparator };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { BigIntMath } from "../../../sdk/utils/bigint-math.js";
|
|
2
2
|
import { MIN_INT96, PERCENTAGE_FACTOR } from "../../../sdk/constants/math.js";
|
|
3
|
-
import "../../../sdk/index.js";
|
|
4
3
|
//#region src/common-utils/utils/creditAccount/quota-utils.ts
|
|
5
4
|
/**
|
|
6
5
|
* Rounds quota deltas to protocol precision step (`PERCENTAGE_FACTOR`).
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BigIntMath } from "../../sdk/utils/bigint-math.js";
|
|
2
|
+
import { calcDefaultQuota, calcQuotaUpdate, calcRecommendedQuota, roundUpQuota } from "./creditAccount/quota-utils.js";
|
|
2
3
|
import { BONUS_APY_FROM_POINTS } from "./apy/bonus-apy-from-points.js";
|
|
3
4
|
import { calculateBorrowRateFromUtilization } from "./apy/calculate-borrow-rate-from-utilization.js";
|
|
4
5
|
import { PriceUtils } from "./price-math.js";
|
|
@@ -31,7 +32,6 @@ import { calcRelativeBaseBorrowRate } from "./creditAccount/calc-relative-base-b
|
|
|
31
32
|
import { calcMaxDebtIncrease, calcMaxLendingDebt } from "./creditAccount/debt.js";
|
|
32
33
|
import { getTimeToLiquidation } from "./creditAccount/get-time-to-liquidation.js";
|
|
33
34
|
import { liquidationPrice } from "./creditAccount/liquidation-price.js";
|
|
34
|
-
import { calcDefaultQuota, calcQuotaUpdate, calcRecommendedQuota, roundUpQuota } from "./creditAccount/quota-utils.js";
|
|
35
35
|
import "./creditAccount/index.js";
|
|
36
36
|
import { getDefaultAsset } from "./strategies/assets/assets.js";
|
|
37
37
|
import { checkBoolean } from "./strategies/availability/check-boolean.js";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BigIntMath } from "../../../../sdk/utils/bigint-math.js";
|
|
2
2
|
import { LEVERAGE_DECIMALS } from "../../../../sdk/constants/math.js";
|
|
3
3
|
import { formatBN, toBN, toBigInt } from "../../../../sdk/utils/formatter.js";
|
|
4
|
+
import { calcQuotaUpdate } from "../../creditAccount/quota-utils.js";
|
|
4
5
|
import { PriceUtils } from "../../price-math.js";
|
|
5
6
|
import { calculateEarnings } from "../../apy/calculate-earnings.js";
|
|
6
7
|
import { calculateEffectiveBorrowRate } from "../../apy/calculate-effective-borrow-rate.js";
|
|
@@ -12,7 +13,6 @@ import { getRecommendedDebt } from "../leverage/get-recommended-debt.js";
|
|
|
12
13
|
import { AssetUtils } from "../../assets-math.js";
|
|
13
14
|
import { EMPTY_OBJECT } from "../../constants.js";
|
|
14
15
|
import { calcHealthFactor } from "../../creditAccount/calc-health-factor.js";
|
|
15
|
-
import { calcQuotaUpdate } from "../../creditAccount/quota-utils.js";
|
|
16
16
|
import { getCMAllowedCollaterals } from "../credit-managers/get-cm-allowed-collaterals.js";
|
|
17
17
|
import { getListWithAmountInTarget } from "../tokens/get-list-with-amount-in-target.js";
|
|
18
18
|
import { getWalletBalancesAllowedOnCM } from "../credit-managers/get-wallet-balances-allowed-on-cm.js";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { ierc20Abi } from "../abi/iERC20.js";
|
|
1
2
|
import { iCreditFacadeV310Abi } from "../abi/310/generated.js";
|
|
2
3
|
import { AddressMap } from "../sdk/utils/AddressMap.js";
|
|
3
4
|
import { AddressSet } from "../sdk/utils/AddressSet.js";
|
|
4
5
|
import { AssetsMap } from "../sdk/utils/AssetsMap.js";
|
|
5
6
|
import { childLogger } from "../sdk/utils/childLogger.js";
|
|
6
|
-
import { ierc20Abi } from "../abi/iERC20.js";
|
|
7
7
|
import "../sdk/constants/addresses.js";
|
|
8
8
|
import { MAX_UINT256, PERCENTAGE_FACTOR } from "../sdk/constants/math.js";
|
|
9
9
|
import { SDKConstruct } from "../sdk/base/SDKConstruct.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { iWithdrawalCompressorV313Abi } from "../abi/IWithdrawalCompressorV313.js";
|
|
1
2
|
import { getNetworkType } from "../sdk/chain/chains.js";
|
|
2
3
|
import { getWithdrawalCompressorAddress } from "../sdk/accounts/withdrawal-compressor/addresses.js";
|
|
3
|
-
import { iWithdrawalCompressorV313Abi } from "../abi/IWithdrawalCompressorV313.js";
|
|
4
4
|
import "../sdk/index.js";
|
|
5
5
|
import { iMidasDataFeedAbi, iMidasRedemptionVaultAbi, midasGatewayAbi, midasRedeemerAbi, midasRedemptionVaultPhantomTokenAbi, securitizeRedeemerAbi, securitizeRedemptionGatewayAbi, securitizeRedemptionPhantomTokenAbi } from "./withdrawalAbi.js";
|
|
6
6
|
import { erc20Abi, hexToString, parseAbi, parseEther } from "viem";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { iPoolV310Abi } from "../../abi/310/generated.js";
|
|
2
1
|
import { iZapperAbi } from "../../abi/iZapper.js";
|
|
2
|
+
import { iPoolV310Abi } from "../../abi/310/generated.js";
|
|
3
3
|
import { asPreviewSimulationError } from "./errors.js";
|
|
4
4
|
//#region src/preview/simulate/simulatePoolOperation.ts
|
|
5
5
|
function previewRead(operation) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { ierc20Abi } from "../../abi/iERC20.js";
|
|
1
2
|
import { iCreditFacadeV310Abi } from "../../abi/310/generated.js";
|
|
2
3
|
import { AddressMap } from "../../sdk/utils/AddressMap.js";
|
|
3
|
-
import { ierc20Abi } from "../../abi/iERC20.js";
|
|
4
4
|
import "../../sdk/index.js";
|
|
5
5
|
import { UnexpectedFacadeEventOrderError } from "./errors.js";
|
|
6
6
|
import { getAddress, isAddressEqual, parseEventLogs } from "viem";
|