@gearbox-protocol/sdk 16.0.0-next.18 → 16.0.0-next.19
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/index.js +3 -21
- package/dist/cjs/common-utils/test-utils/index.js +4 -3
- package/dist/cjs/common-utils/utils/index.js +3 -22
- package/dist/cjs/common-utils/utils/strategies/index.js +3 -0
- package/dist/cjs/common-utils/utils/strategies/strategy-info/cm-availability-condition.js +5 -5
- package/dist/cjs/common-utils/utils/strategies/strategy-info/credit-manager-issues.js +135 -0
- package/dist/cjs/common-utils/utils/strategies/strategy-info/get-cm-you-can-earn.js +12 -23
- package/dist/cjs/common-utils/utils/strategies/strategy-info/index.js +3 -0
- package/dist/cjs/onchain/accounts/index.js +2 -3
- package/dist/cjs/onchain/accounts/intents/guards.js +55 -50
- package/dist/cjs/onchain/accounts/intents/index.js +7 -8
- package/dist/cjs/onchain/accounts/intents/math.js +15 -22
- package/dist/cjs/onchain/accounts/intents/open-strategy.js +5 -5
- package/dist/cjs/onchain/accounts/intents/plan.js +27 -41
- package/dist/cjs/onchain/accounts/intents/realize.js +14 -21
- package/dist/cjs/onchain/accounts/intents/tail.js +2 -2
- package/dist/cjs/onchain/accounts/intents/testing/sdk-mock.js +1 -0
- package/dist/cjs/onchain/accounts/intents/view.js +1 -0
- package/dist/cjs/onchain/constants/index.js +1 -0
- package/dist/cjs/onchain/constants/math.js +11 -0
- package/dist/cjs/onchain/index.js +32 -3
- package/dist/cjs/onchain/validation/checks.js +250 -0
- package/dist/cjs/onchain/validation/index.js +29 -0
- package/dist/cjs/onchain/{accounts/intents → validation}/refusal.js +12 -1
- package/dist/cjs/onchain/validation/token.js +29 -0
- package/dist/cjs/preview/index.js +10 -0
- package/dist/cjs/preview/preview/buildDelayedPreview.js +1 -0
- package/dist/cjs/preview/preview/previewAdjustCreditAccount.js +1 -0
- package/dist/cjs/preview/preview/previewOpenCreditAccount.js +1 -0
- package/dist/cjs/preview/validate/checkOperation.js +173 -0
- package/dist/cjs/preview/validate/checkSimulation.js +52 -0
- package/dist/cjs/preview/validate/index.js +6 -0
- package/dist/cjs/sdk/index.js +4 -0
- package/dist/cjs/sdk/prepare/PrepareApi.js +17 -13
- package/dist/cjs/sdk/prepare/index.js +4 -0
- package/dist/cjs/sdk/prepare/types.js +4 -0
- package/dist/esm/common-utils/index.js +2 -11
- package/dist/esm/common-utils/test-utils/index.js +4 -3
- package/dist/esm/common-utils/utils/index.js +2 -12
- package/dist/esm/common-utils/utils/strategies/index.js +2 -1
- package/dist/esm/common-utils/utils/strategies/strategy-info/cm-availability-condition.js +5 -5
- package/dist/esm/common-utils/utils/strategies/strategy-info/credit-manager-issues.js +133 -0
- package/dist/esm/common-utils/utils/strategies/strategy-info/get-cm-you-can-earn.js +12 -23
- package/dist/esm/common-utils/utils/strategies/strategy-info/index.js +2 -1
- package/dist/esm/dev/AccountOpener.js +1 -1
- package/dist/esm/dev/withdrawalUtils.js +1 -1
- package/dist/esm/onchain/accounts/CreditAccountsServiceV310.js +2 -2
- package/dist/esm/onchain/accounts/index.js +2 -2
- package/dist/esm/onchain/accounts/intents/guards.js +55 -50
- package/dist/esm/onchain/accounts/intents/index.js +5 -5
- package/dist/esm/onchain/accounts/intents/math.js +14 -21
- package/dist/esm/onchain/accounts/intents/open-strategy.js +4 -4
- package/dist/esm/onchain/accounts/intents/plan.js +15 -29
- package/dist/esm/onchain/accounts/intents/realize.js +12 -19
- package/dist/esm/onchain/accounts/intents/tail.js +1 -1
- package/dist/esm/onchain/accounts/intents/testing/sdk-mock.js +1 -0
- package/dist/esm/onchain/accounts/intents/view.js +1 -0
- package/dist/esm/onchain/accounts/liquidations/LiquidationsService.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
- package/dist/esm/onchain/base/TokensMeta.js +3 -3
- package/dist/esm/onchain/chain/detectNetwork.js +1 -1
- package/dist/esm/onchain/constants/index.js +2 -2
- package/dist/esm/onchain/constants/math.js +11 -1
- package/dist/esm/onchain/core/createAddressProvider.js +1 -1
- package/dist/esm/onchain/index.js +7 -3
- package/dist/esm/onchain/market/adapters/contracts/AccountMigratorAdapterContract.js +1 -1
- package/dist/esm/onchain/market/adapters/contracts/ERC4626AdapterContract.js +1 -1
- package/dist/esm/onchain/market/credit/CreditFacadeV310BaseContract.js +1 -1
- package/dist/esm/onchain/market/pool/PoolV310Contract.js +1 -1
- package/dist/esm/onchain/market/zapper/IETHZapperContract.js +1 -1
- package/dist/esm/onchain/market/zapper/ZapperContract.js +1 -1
- package/dist/esm/onchain/pools/PoolService.js +1 -1
- package/dist/esm/onchain/utils/viem/simulateWithPriceUpdates.js +1 -1
- package/dist/esm/onchain/validation/checks.js +230 -0
- package/dist/esm/onchain/validation/index.js +4 -0
- package/dist/esm/onchain/{accounts/intents → validation}/refusal.js +12 -2
- package/dist/esm/onchain/validation/token.js +27 -0
- package/dist/esm/preview/index.js +5 -1
- package/dist/esm/preview/preview/buildDelayedPreview.js +1 -0
- package/dist/esm/preview/preview/previewAdjustCreditAccount.js +1 -0
- package/dist/esm/preview/preview/previewOpenCreditAccount.js +1 -0
- package/dist/esm/preview/simulate/simulatePoolOperation.js +1 -1
- package/dist/esm/preview/trace/extractTransfers.js +1 -1
- package/dist/esm/preview/validate/checkOperation.js +171 -0
- package/dist/esm/preview/validate/checkSimulation.js +51 -0
- package/dist/esm/preview/validate/index.js +3 -0
- package/dist/esm/sdk/index.js +2 -1
- package/dist/esm/sdk/prepare/PrepareApi.js +15 -11
- package/dist/esm/sdk/prepare/index.js +2 -1
- package/dist/esm/sdk/prepare/types.js +2 -1
- package/dist/types/common-utils/index.d.ts +2 -12
- package/dist/types/common-utils/utils/index.d.ts +2 -13
- package/dist/types/common-utils/utils/strategies/index.d.ts +2 -1
- package/dist/types/common-utils/utils/strategies/strategy-info/credit-manager-issues.d.ts +34 -0
- package/dist/types/common-utils/utils/strategies/strategy-info/index.d.ts +2 -1
- package/dist/types/model/previews.d.ts +22 -0
- package/dist/types/onchain/accounts/index.d.ts +2 -2
- package/dist/types/onchain/accounts/intents/guards.d.ts +8 -4
- package/dist/types/onchain/accounts/intents/index.d.ts +4 -3
- package/dist/types/onchain/accounts/intents/math.d.ts +2 -1
- package/dist/types/onchain/accounts/intents/plan.d.ts +3 -0
- package/dist/types/onchain/accounts/intents/types.d.ts +7 -1
- package/dist/types/onchain/constants/index.d.ts +2 -2
- package/dist/types/onchain/constants/math.d.ts +9 -1
- package/dist/types/onchain/index.d.ts +7 -3
- package/dist/types/onchain/validation/checks.d.ts +167 -0
- package/dist/types/onchain/validation/index.d.ts +4 -0
- package/dist/types/onchain/{accounts/intents → validation}/refusal.d.ts +100 -31
- package/dist/types/onchain/validation/token.d.ts +17 -0
- package/dist/types/preview/index.d.ts +5 -1
- package/dist/types/preview/validate/checkOperation.d.ts +46 -0
- package/dist/types/preview/validate/checkSimulation.d.ts +34 -0
- package/dist/types/preview/validate/index.d.ts +3 -0
- package/dist/types/sdk/index.d.ts +2 -2
- package/dist/types/sdk/prepare/index.d.ts +2 -2
- package/dist/types/sdk/prepare/types.d.ts +2 -2
- package/package.json +1 -1
- package/dist/cjs/common-utils/utils/strategies/strategy-info/get-cm-you-can-earn.spec.js +0 -267
- package/dist/cjs/common-utils/utils/validation/index.js +0 -23
- package/dist/cjs/common-utils/utils/validation/is-zero-balance.js +0 -7
- package/dist/cjs/common-utils/utils/validation/validate-balance.js +0 -22
- package/dist/cjs/common-utils/utils/validation/validate-balance.spec.js +0 -54
- package/dist/cjs/common-utils/utils/validation/validate-balances.js +0 -17
- package/dist/cjs/common-utils/utils/validation/validate-balances.spec.js +0 -45
- package/dist/cjs/common-utils/utils/validation/validate-credit-manager.js +0 -8
- package/dist/cjs/common-utils/utils/validation/validate-credit-manager.spec.js +0 -36
- package/dist/cjs/common-utils/utils/validation/validate-hf.js +0 -10
- package/dist/cjs/common-utils/utils/validation/validate-hf.spec.js +0 -26
- package/dist/cjs/common-utils/utils/validation/validate-open-account-pool-quota-status.js +0 -14
- package/dist/cjs/common-utils/utils/validation/validate-open-account-pool-quota-status.spec.js +0 -29
- package/dist/cjs/common-utils/utils/validation/validate-open-account-pool-status.js +0 -37
- package/dist/cjs/common-utils/utils/validation/validate-open-account-pool-status.spec.js +0 -98
- package/dist/cjs/common-utils/utils/validation/validate-open-account.js +0 -18
- package/dist/cjs/common-utils/utils/validation/validate-open-account.spec.js +0 -56
- package/dist/cjs/common-utils/utils/validation/validate-quota.js +0 -23
- package/dist/cjs/common-utils/utils/validation/validate-quota.spec.js +0 -88
- package/dist/cjs/common-utils/utils/validation/validate-token-to-obtain.js +0 -18
- package/dist/cjs/common-utils/utils/validation/validate-token-to-obtain.spec.js +0 -36
- package/dist/cjs/common-utils/utils/validation/validation-types.js +0 -1
- package/dist/esm/common-utils/utils/strategies/strategy-info/get-cm-you-can-earn.spec.js +0 -264
- package/dist/esm/common-utils/utils/validation/index.js +0 -12
- package/dist/esm/common-utils/utils/validation/is-zero-balance.js +0 -6
- package/dist/esm/common-utils/utils/validation/validate-balance.js +0 -21
- package/dist/esm/common-utils/utils/validation/validate-balance.spec.js +0 -54
- package/dist/esm/common-utils/utils/validation/validate-balances.js +0 -16
- package/dist/esm/common-utils/utils/validation/validate-balances.spec.js +0 -45
- package/dist/esm/common-utils/utils/validation/validate-credit-manager.js +0 -7
- package/dist/esm/common-utils/utils/validation/validate-credit-manager.spec.js +0 -36
- package/dist/esm/common-utils/utils/validation/validate-hf.js +0 -8
- package/dist/esm/common-utils/utils/validation/validate-hf.spec.js +0 -26
- package/dist/esm/common-utils/utils/validation/validate-open-account-pool-quota-status.js +0 -13
- package/dist/esm/common-utils/utils/validation/validate-open-account-pool-quota-status.spec.js +0 -29
- package/dist/esm/common-utils/utils/validation/validate-open-account-pool-status.js +0 -36
- package/dist/esm/common-utils/utils/validation/validate-open-account-pool-status.spec.js +0 -98
- package/dist/esm/common-utils/utils/validation/validate-open-account.js +0 -17
- package/dist/esm/common-utils/utils/validation/validate-open-account.spec.js +0 -56
- package/dist/esm/common-utils/utils/validation/validate-quota.js +0 -22
- package/dist/esm/common-utils/utils/validation/validate-quota.spec.js +0 -88
- package/dist/esm/common-utils/utils/validation/validate-token-to-obtain.js +0 -17
- package/dist/esm/common-utils/utils/validation/validate-token-to-obtain.spec.js +0 -36
- package/dist/esm/common-utils/utils/validation/validation-types.js +0 -1
- package/dist/types/common-utils/utils/strategies/strategy-info/get-cm-you-can-earn.spec.d.ts +0 -1
- package/dist/types/common-utils/utils/validation/index.d.ts +0 -12
- package/dist/types/common-utils/utils/validation/is-zero-balance.d.ts +0 -4
- package/dist/types/common-utils/utils/validation/validate-balance.d.ts +0 -25
- package/dist/types/common-utils/utils/validation/validate-balance.spec.d.ts +0 -1
- package/dist/types/common-utils/utils/validation/validate-balances.d.ts +0 -13
- package/dist/types/common-utils/utils/validation/validate-balances.spec.d.ts +0 -1
- package/dist/types/common-utils/utils/validation/validate-credit-manager.d.ts +0 -13
- package/dist/types/common-utils/utils/validation/validate-credit-manager.spec.d.ts +0 -1
- package/dist/types/common-utils/utils/validation/validate-hf.d.ts +0 -12
- package/dist/types/common-utils/utils/validation/validate-hf.spec.d.ts +0 -1
- package/dist/types/common-utils/utils/validation/validate-open-account-pool-quota-status.d.ts +0 -10
- package/dist/types/common-utils/utils/validation/validate-open-account-pool-quota-status.spec.d.ts +0 -1
- package/dist/types/common-utils/utils/validation/validate-open-account-pool-status.d.ts +0 -26
- package/dist/types/common-utils/utils/validation/validate-open-account-pool-status.spec.d.ts +0 -1
- package/dist/types/common-utils/utils/validation/validate-open-account.d.ts +0 -25
- package/dist/types/common-utils/utils/validation/validate-open-account.spec.d.ts +0 -1
- package/dist/types/common-utils/utils/validation/validate-quota.d.ts +0 -24
- package/dist/types/common-utils/utils/validation/validate-quota.spec.d.ts +0 -1
- package/dist/types/common-utils/utils/validation/validate-token-to-obtain.d.ts +0 -17
- package/dist/types/common-utils/utils/validation/validate-token-to-obtain.spec.d.ts +0 -1
- package/dist/types/common-utils/utils/validation/validation-types.d.ts +0 -10
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_onchain_utils_formatter = require("../../../../onchain/utils/formatter.js");
|
|
3
|
-
const require_common_utils_utils_strategies_strategy_info_get_cm_you_can_earn = require("./get-cm-you-can-earn.js");
|
|
4
|
-
const require_common_utils_test_utils_index = require("../../../test-utils/index.js");
|
|
5
|
-
let vitest = require("vitest");
|
|
6
|
-
//#region src/common-utils/utils/strategies/strategy-info/get-cm-you-can-earn.spec.ts
|
|
7
|
-
(0, vitest.describe)("getCMYouCanEarn", () => {
|
|
8
|
-
const collateralTokenAddress = "0xcd5fe23c85820f7b72d0926fc9b05b43e359b7ee";
|
|
9
|
-
const targetTokenAddress = "0xe72b141df173b999ae7c1adcbf60cc9833ce56a8";
|
|
10
|
-
const underlyingTokenAddress = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2";
|
|
11
|
-
const deth = "0x871ab8e36cae9af35c6a3488b049965233deb7ed";
|
|
12
|
-
const nativeTokenAddress = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
13
|
-
const wrappedNativeTokenAddress = underlyingTokenAddress;
|
|
14
|
-
const tokenDataList = {
|
|
15
|
-
[collateralTokenAddress]: require_common_utils_test_utils_index.buildTokenData(collateralTokenAddress, "weETH"),
|
|
16
|
-
[targetTokenAddress]: require_common_utils_test_utils_index.buildTokenData(targetTokenAddress, "ethPlus"),
|
|
17
|
-
[underlyingTokenAddress]: require_common_utils_test_utils_index.buildTokenData(underlyingTokenAddress, "WETH"),
|
|
18
|
-
[nativeTokenAddress]: require_common_utils_test_utils_index.buildTokenData(nativeTokenAddress, "ETH"),
|
|
19
|
-
[deth]: require_common_utils_test_utils_index.buildTokenData(deth, "dETH")
|
|
20
|
-
};
|
|
21
|
-
const poolAddress = "0x0000000000000000000000000000000000000POOL";
|
|
22
|
-
const creditManager = require_common_utils_test_utils_index.buildCreditManager({
|
|
23
|
-
address: "0x0000000000000000000000000000000000000CM1",
|
|
24
|
-
pool: poolAddress,
|
|
25
|
-
underlyingToken: underlyingTokenAddress,
|
|
26
|
-
collateralTokens: [
|
|
27
|
-
collateralTokenAddress,
|
|
28
|
-
underlyingTokenAddress,
|
|
29
|
-
targetTokenAddress,
|
|
30
|
-
deth
|
|
31
|
-
],
|
|
32
|
-
supportedTokens: {
|
|
33
|
-
[collateralTokenAddress]: true,
|
|
34
|
-
[underlyingTokenAddress]: true,
|
|
35
|
-
[targetTokenAddress]: true,
|
|
36
|
-
[deth]: true
|
|
37
|
-
},
|
|
38
|
-
liquidationThresholds: {
|
|
39
|
-
[collateralTokenAddress]: 9300n,
|
|
40
|
-
[targetTokenAddress]: 9300n,
|
|
41
|
-
[underlyingTokenAddress]: 9500n,
|
|
42
|
-
[deth]: 8800n
|
|
43
|
-
},
|
|
44
|
-
quotas: {
|
|
45
|
-
[targetTokenAddress]: require_common_utils_test_utils_index.buildQuota({
|
|
46
|
-
isActive: true,
|
|
47
|
-
limit: 5000000000000000000000n,
|
|
48
|
-
quotaIncreaseFee: 0n,
|
|
49
|
-
rate: 100n,
|
|
50
|
-
token: "0xe72b141df173b999ae7c1adcbf60cc9833ce56a8",
|
|
51
|
-
totalQuoted: 1708445825184283030000n
|
|
52
|
-
}),
|
|
53
|
-
[collateralTokenAddress]: require_common_utils_test_utils_index.buildQuota({
|
|
54
|
-
token: collateralTokenAddress,
|
|
55
|
-
rate: 0n,
|
|
56
|
-
limit: require_onchain_utils_formatter.toBN("1000000", 18)
|
|
57
|
-
}),
|
|
58
|
-
[deth]: require_common_utils_test_utils_index.buildQuota({
|
|
59
|
-
isActive: true,
|
|
60
|
-
limit: 500000000000000000000n,
|
|
61
|
-
quotaIncreaseFee: 0n,
|
|
62
|
-
rate: 100n,
|
|
63
|
-
token: deth,
|
|
64
|
-
totalQuoted: 28666207338545540000n
|
|
65
|
-
})
|
|
66
|
-
},
|
|
67
|
-
isQuoted: (t) => t.toLowerCase() !== underlyingTokenAddress,
|
|
68
|
-
feeInterest: 2e3,
|
|
69
|
-
isPaused: false,
|
|
70
|
-
baseBorrowRate: 18991,
|
|
71
|
-
maxDebt: 250000000000000000000n,
|
|
72
|
-
minDebt: 10000000000000000000n,
|
|
73
|
-
availableToBorrow: 859640767327531138355n
|
|
74
|
-
});
|
|
75
|
-
const pools = { [poolAddress]: require_common_utils_test_utils_index.buildPool({
|
|
76
|
-
address: poolAddress,
|
|
77
|
-
chainId: 1,
|
|
78
|
-
network: "Mainnet",
|
|
79
|
-
underlyingToken: underlyingTokenAddress,
|
|
80
|
-
dieselToken: poolAddress,
|
|
81
|
-
isPaused: false,
|
|
82
|
-
version: 310,
|
|
83
|
-
expectedLiquidity: 5596004266940175413222n,
|
|
84
|
-
expectedLiquidityLimit: 6903325375622920584635n,
|
|
85
|
-
availableLiquidity: 1307321108682745171413n,
|
|
86
|
-
interestModel: {
|
|
87
|
-
interestModel: "0x12e6e5c6fe4b37576dd4052e03a97ee7b9c29e86",
|
|
88
|
-
U_1: 7000n,
|
|
89
|
-
U_2: 9200n,
|
|
90
|
-
R_base: 0n,
|
|
91
|
-
R_slope1: 113n,
|
|
92
|
-
R_slope2: 150n,
|
|
93
|
-
R_slope3: 1236n,
|
|
94
|
-
version: 310,
|
|
95
|
-
isBorrowingMoreU2Forbidden: true
|
|
96
|
-
}
|
|
97
|
-
}) };
|
|
98
|
-
const allPrices = { [poolAddress]: {
|
|
99
|
-
[collateralTokenAddress]: 347896889077n,
|
|
100
|
-
[targetTokenAddress]: 342474099875n,
|
|
101
|
-
[underlyingTokenAddress]: 320438727057n,
|
|
102
|
-
[deth]: 322630065873n
|
|
103
|
-
} };
|
|
104
|
-
const walletBalances = {
|
|
105
|
-
[underlyingTokenAddress]: 0n,
|
|
106
|
-
[collateralTokenAddress]: 6191758000000000000n,
|
|
107
|
-
[targetTokenAddress]: 0n
|
|
108
|
-
};
|
|
109
|
-
const apyList = {
|
|
110
|
-
apyList: {
|
|
111
|
-
[targetTokenAddress]: 24600,
|
|
112
|
-
[collateralTokenAddress]: 27612,
|
|
113
|
-
[deth]: 16600
|
|
114
|
-
},
|
|
115
|
-
extraCollateralAPYList: { [poolAddress]: { [targetTokenAddress]: {
|
|
116
|
-
address: targetTokenAddress,
|
|
117
|
-
pool: poolAddress,
|
|
118
|
-
symbol: "ETHPlus",
|
|
119
|
-
type: "relative",
|
|
120
|
-
value: 0
|
|
121
|
-
} } },
|
|
122
|
-
pointsList: {
|
|
123
|
-
[collateralTokenAddress]: {
|
|
124
|
-
symbol: "weETH",
|
|
125
|
-
address: "0xcd5fe23c85820f7b72d0926fc9b05b43e359b7ee",
|
|
126
|
-
debtRewards: void 0,
|
|
127
|
-
rewards: [{
|
|
128
|
-
name: "Ether.fi",
|
|
129
|
-
units: "points",
|
|
130
|
-
multiplier: 200n,
|
|
131
|
-
type: "etherfi"
|
|
132
|
-
}]
|
|
133
|
-
},
|
|
134
|
-
[deth]: {
|
|
135
|
-
address: "0x871ab8e36cae9af35c6a3488b049965233deb7ed",
|
|
136
|
-
debtRewards: void 0,
|
|
137
|
-
rewards: [{
|
|
138
|
-
name: "Makina",
|
|
139
|
-
units: "points",
|
|
140
|
-
multiplier: 36000n,
|
|
141
|
-
type: "makina"
|
|
142
|
-
}],
|
|
143
|
-
symbol: "DETH"
|
|
144
|
-
}
|
|
145
|
-
},
|
|
146
|
-
extraCollateralPointsList: {},
|
|
147
|
-
poolRewardsList: {},
|
|
148
|
-
tokenExtraRewardsList: {},
|
|
149
|
-
poolExternalAPYList: {},
|
|
150
|
-
poolExtraAPYList: {}
|
|
151
|
-
};
|
|
152
|
-
(0, vitest.it)("computes expected earnings for APY-only scenario", () => {
|
|
153
|
-
const strategy = {
|
|
154
|
-
id: "test-strategy",
|
|
155
|
-
tokenOutAddress: targetTokenAddress,
|
|
156
|
-
chainId: 1,
|
|
157
|
-
network: "Mainnet"
|
|
158
|
-
};
|
|
159
|
-
const result = require_common_utils_utils_strategies_strategy_info_get_cm_you_can_earn.getCMYouCanEarn({
|
|
160
|
-
creditManager,
|
|
161
|
-
pools,
|
|
162
|
-
strategy,
|
|
163
|
-
delayedPhantoms: {},
|
|
164
|
-
apyList,
|
|
165
|
-
tokensList: tokenDataList,
|
|
166
|
-
walletBalances,
|
|
167
|
-
nativeTokenAddress,
|
|
168
|
-
wrappedNativeTokenAddress,
|
|
169
|
-
allPrices,
|
|
170
|
-
slippage: 10,
|
|
171
|
-
quotaReserve: 500
|
|
172
|
-
});
|
|
173
|
-
(0, vitest.expect)(result.status).toEqual("ok");
|
|
174
|
-
(0, vitest.expect)(result.data?.info?.maxAPY).toEqual({
|
|
175
|
-
overallAPY: 7.392,
|
|
176
|
-
overallAPYBigInt: 73920n,
|
|
177
|
-
overallAPYStatus: "calculated"
|
|
178
|
-
});
|
|
179
|
-
(0, vitest.expect)(result.data?.earnings).toEqual({
|
|
180
|
-
earnings: 496914282513333354n,
|
|
181
|
-
earningsUSD: 1592305801450150145856n
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
(0, vitest.it)("computes expected earnings for APY and points scenario", () => {
|
|
185
|
-
const strategy = {
|
|
186
|
-
id: "test-strategy",
|
|
187
|
-
tokenOutAddress: collateralTokenAddress,
|
|
188
|
-
chainId: 1,
|
|
189
|
-
network: "Mainnet"
|
|
190
|
-
};
|
|
191
|
-
const result = require_common_utils_utils_strategies_strategy_info_get_cm_you_can_earn.getCMYouCanEarn({
|
|
192
|
-
creditManager,
|
|
193
|
-
pools,
|
|
194
|
-
strategy,
|
|
195
|
-
delayedPhantoms: {},
|
|
196
|
-
apyList,
|
|
197
|
-
tokensList: tokenDataList,
|
|
198
|
-
walletBalances,
|
|
199
|
-
nativeTokenAddress,
|
|
200
|
-
wrappedNativeTokenAddress,
|
|
201
|
-
allPrices,
|
|
202
|
-
slippage: 10,
|
|
203
|
-
quotaReserve: 500
|
|
204
|
-
});
|
|
205
|
-
(0, vitest.expect)(result.status).toEqual("ok");
|
|
206
|
-
(0, vitest.expect)(result.data?.info?.maxAPY).toEqual({
|
|
207
|
-
overallAPY: 11.233,
|
|
208
|
-
overallAPYBigInt: 112330n,
|
|
209
|
-
overallAPYStatus: "calculated"
|
|
210
|
-
});
|
|
211
|
-
(0, vitest.expect)(result.data?.earnings).toEqual({
|
|
212
|
-
earnings: 755118795383153892n,
|
|
213
|
-
earningsUSD: 2419693055693930817344n
|
|
214
|
-
});
|
|
215
|
-
(0, vitest.expect)(result.data?.points?.info).toEqual(apyList.pointsList?.[collateralTokenAddress] || {});
|
|
216
|
-
(0, vitest.expect)(result.data?.points).toEqual({
|
|
217
|
-
debtRates: {
|
|
218
|
-
rewards: [],
|
|
219
|
-
rates: []
|
|
220
|
-
},
|
|
221
|
-
info: apyList.pointsList?.[collateralTokenAddress] || {},
|
|
222
|
-
rates: [2454n]
|
|
223
|
-
});
|
|
224
|
-
});
|
|
225
|
-
(0, vitest.it)("computes expected earnings for points-only scenario", () => {
|
|
226
|
-
const strategy = {
|
|
227
|
-
id: "test-strategy",
|
|
228
|
-
tokenOutAddress: deth,
|
|
229
|
-
chainId: 1,
|
|
230
|
-
network: "Mainnet"
|
|
231
|
-
};
|
|
232
|
-
const result = require_common_utils_utils_strategies_strategy_info_get_cm_you_can_earn.getCMYouCanEarn({
|
|
233
|
-
creditManager,
|
|
234
|
-
pools,
|
|
235
|
-
strategy,
|
|
236
|
-
delayedPhantoms: {},
|
|
237
|
-
apyList,
|
|
238
|
-
tokensList: tokenDataList,
|
|
239
|
-
walletBalances,
|
|
240
|
-
nativeTokenAddress,
|
|
241
|
-
wrappedNativeTokenAddress,
|
|
242
|
-
allPrices,
|
|
243
|
-
slippage: 10,
|
|
244
|
-
quotaReserve: 500
|
|
245
|
-
});
|
|
246
|
-
(0, vitest.expect)(result.status).toEqual("ok");
|
|
247
|
-
(0, vitest.expect)(result.data?.info?.maxAPY).toEqual({
|
|
248
|
-
overallAPY: void 0,
|
|
249
|
-
overallAPYBigInt: void 0,
|
|
250
|
-
overallAPYStatus: "negativeForPoints"
|
|
251
|
-
});
|
|
252
|
-
(0, vitest.expect)(result.data?.earnings).toEqual({
|
|
253
|
-
earnings: null,
|
|
254
|
-
earningsUSD: null
|
|
255
|
-
});
|
|
256
|
-
(0, vitest.expect)(result.data?.points?.info).toEqual(apyList.pointsList?.[deth] || {});
|
|
257
|
-
(0, vitest.expect)(result.data?.points).toEqual({
|
|
258
|
-
debtRates: {
|
|
259
|
-
rewards: [],
|
|
260
|
-
rates: []
|
|
261
|
-
},
|
|
262
|
-
info: apyList.pointsList?.[deth] || {},
|
|
263
|
-
rates: [259920n]
|
|
264
|
-
});
|
|
265
|
-
});
|
|
266
|
-
});
|
|
267
|
-
//#endregion
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_common_utils_utils_validation_validate_hf = require("./validate-hf.js");
|
|
3
|
-
const require_common_utils_utils_validation_validate_open_account_pool_quota_status = require("./validate-open-account-pool-quota-status.js");
|
|
4
|
-
const require_common_utils_utils_validation_validate_open_account_pool_status = require("./validate-open-account-pool-status.js");
|
|
5
|
-
const require_common_utils_utils_validation_is_zero_balance = require("./is-zero-balance.js");
|
|
6
|
-
const require_common_utils_utils_validation_validate_balance = require("./validate-balance.js");
|
|
7
|
-
const require_common_utils_utils_validation_validate_balances = require("./validate-balances.js");
|
|
8
|
-
const require_common_utils_utils_validation_validate_credit_manager = require("./validate-credit-manager.js");
|
|
9
|
-
const require_common_utils_utils_validation_validate_quota = require("./validate-quota.js");
|
|
10
|
-
const require_common_utils_utils_validation_validate_open_account = require("./validate-open-account.js");
|
|
11
|
-
const require_common_utils_utils_validation_validate_token_to_obtain = require("./validate-token-to-obtain.js");
|
|
12
|
-
require("./validation-types.js");
|
|
13
|
-
exports.MIN_HF_LIMITED = require_common_utils_utils_validation_validate_hf.MIN_HF_LIMITED;
|
|
14
|
-
exports.isZeroBalance = require_common_utils_utils_validation_is_zero_balance.isZeroBalance;
|
|
15
|
-
exports.validateBalance = require_common_utils_utils_validation_validate_balance.validateBalance;
|
|
16
|
-
exports.validateBalances = require_common_utils_utils_validation_validate_balances.validateBalances;
|
|
17
|
-
exports.validateCreditManager = require_common_utils_utils_validation_validate_credit_manager.validateCreditManager;
|
|
18
|
-
exports.validateHF = require_common_utils_utils_validation_validate_hf.validateHF;
|
|
19
|
-
exports.validateOpenAccount = require_common_utils_utils_validation_validate_open_account.validateOpenAccount;
|
|
20
|
-
exports.validateOpenAccountPoolQuotaStatus = require_common_utils_utils_validation_validate_open_account_pool_quota_status.validateOpenAccountPoolQuotaStatus;
|
|
21
|
-
exports.validateOpenAccountPoolStatus = require_common_utils_utils_validation_validate_open_account_pool_status.validateOpenAccountPoolStatus;
|
|
22
|
-
exports.validateQuota = require_common_utils_utils_validation_validate_quota.validateQuota;
|
|
23
|
-
exports.validateTokenToObtain = require_common_utils_utils_validation_validate_token_to_obtain.validateTokenToObtain;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
require("../constants.js");
|
|
3
|
-
const require_common_utils_utils_validation_is_zero_balance = require("./is-zero-balance.js");
|
|
4
|
-
//#region src/common-utils/utils/validation/validate-balance.ts
|
|
5
|
-
function validateBalance({ amount, tokenAddress, maxAmount = 0n, zeroCheck = true, single }) {
|
|
6
|
-
const safeAddress = tokenAddress || "";
|
|
7
|
-
if (!safeAddress) return {
|
|
8
|
-
message: "unknownToken",
|
|
9
|
-
token: safeAddress
|
|
10
|
-
};
|
|
11
|
-
if (maxAmount < amount) return {
|
|
12
|
-
message: "insufficientFunds",
|
|
13
|
-
token: safeAddress
|
|
14
|
-
};
|
|
15
|
-
if (zeroCheck && require_common_utils_utils_validation_is_zero_balance.isZeroBalance(amount)) return {
|
|
16
|
-
message: single ? "enterAmount" : "zeroBalance",
|
|
17
|
-
token: safeAddress
|
|
18
|
-
};
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
|
-
//#endregion
|
|
22
|
-
exports.validateBalance = validateBalance;
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_common_utils_utils_validation_validate_balance = require("./validate-balance.js");
|
|
3
|
-
const require_common_utils_test_utils_index = require("../../test-utils/index.js");
|
|
4
|
-
let vitest = require("vitest");
|
|
5
|
-
//#region src/common-utils/utils/validation/validate-balance.spec.ts
|
|
6
|
-
(0, vitest.describe)("validateBalance", () => {
|
|
7
|
-
(0, vitest.it)("returns null when all conditions are met", () => {
|
|
8
|
-
const result = require_common_utils_utils_validation_validate_balance.validateBalance({
|
|
9
|
-
amount: 1000n,
|
|
10
|
-
tokenAddress: require_common_utils_test_utils_index.mockToken1,
|
|
11
|
-
maxAmount: 2000n,
|
|
12
|
-
zeroCheck: true,
|
|
13
|
-
single: false
|
|
14
|
-
});
|
|
15
|
-
(0, vitest.expect)(result).toBeNull();
|
|
16
|
-
});
|
|
17
|
-
(0, vitest.it)("returns error when amount exceeds maxAmount", () => {
|
|
18
|
-
const result = require_common_utils_utils_validation_validate_balance.validateBalance({
|
|
19
|
-
amount: 3000n,
|
|
20
|
-
tokenAddress: require_common_utils_test_utils_index.mockToken1,
|
|
21
|
-
maxAmount: 2000n,
|
|
22
|
-
zeroCheck: true,
|
|
23
|
-
single: false
|
|
24
|
-
});
|
|
25
|
-
(0, vitest.expect)(result).toEqual({
|
|
26
|
-
message: "insufficientFunds",
|
|
27
|
-
token: require_common_utils_test_utils_index.mockToken1
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
(0, vitest.it)("returns error when amount is too small with zeroCheck", () => {
|
|
31
|
-
const result = require_common_utils_utils_validation_validate_balance.validateBalance({
|
|
32
|
-
amount: 5n,
|
|
33
|
-
tokenAddress: require_common_utils_test_utils_index.mockToken1,
|
|
34
|
-
maxAmount: 2000n,
|
|
35
|
-
zeroCheck: true,
|
|
36
|
-
single: false
|
|
37
|
-
});
|
|
38
|
-
(0, vitest.expect)(result).toEqual({
|
|
39
|
-
message: "zeroBalance",
|
|
40
|
-
token: require_common_utils_test_utils_index.mockToken1
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
(0, vitest.it)("returns null when zeroCheck is false and amount is small", () => {
|
|
44
|
-
const result = require_common_utils_utils_validation_validate_balance.validateBalance({
|
|
45
|
-
amount: 5n,
|
|
46
|
-
tokenAddress: require_common_utils_test_utils_index.mockToken1,
|
|
47
|
-
maxAmount: 2000n,
|
|
48
|
-
zeroCheck: false,
|
|
49
|
-
single: false
|
|
50
|
-
});
|
|
51
|
-
(0, vitest.expect)(result).toBeNull();
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
//#endregion
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_common_utils_utils_validation_validate_balance = require("./validate-balance.js");
|
|
3
|
-
//#region src/common-utils/utils/validation/validate-balances.ts
|
|
4
|
-
function validateBalances({ balances, assets, zeroCheck = true }) {
|
|
5
|
-
for (const { token: tokenAddress, balance: amount } of assets) {
|
|
6
|
-
const e = require_common_utils_utils_validation_validate_balance.validateBalance({
|
|
7
|
-
tokenAddress,
|
|
8
|
-
amount,
|
|
9
|
-
maxAmount: balances[(tokenAddress || "").toLowerCase()] || 0n,
|
|
10
|
-
zeroCheck
|
|
11
|
-
});
|
|
12
|
-
if (e !== null) return e;
|
|
13
|
-
}
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
//#endregion
|
|
17
|
-
exports.validateBalances = validateBalances;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_common_utils_utils_validation_validate_balances = require("./validate-balances.js");
|
|
3
|
-
const require_common_utils_test_utils_index = require("../../test-utils/index.js");
|
|
4
|
-
let vitest = require("vitest");
|
|
5
|
-
//#region src/common-utils/utils/validation/validate-balances.spec.ts
|
|
6
|
-
(0, vitest.describe)("validateBalances", () => {
|
|
7
|
-
(0, vitest.it)("returns null when all balances are valid", () => {
|
|
8
|
-
const result = require_common_utils_utils_validation_validate_balances.validateBalances({
|
|
9
|
-
balances: {
|
|
10
|
-
[require_common_utils_test_utils_index.mockToken1]: 2000n,
|
|
11
|
-
[require_common_utils_test_utils_index.mockToken2]: 3000n
|
|
12
|
-
},
|
|
13
|
-
assets: [{
|
|
14
|
-
token: require_common_utils_test_utils_index.mockToken1,
|
|
15
|
-
balance: 1000n
|
|
16
|
-
}, {
|
|
17
|
-
token: require_common_utils_test_utils_index.mockToken2,
|
|
18
|
-
balance: 2000n
|
|
19
|
-
}],
|
|
20
|
-
zeroCheck: true
|
|
21
|
-
});
|
|
22
|
-
(0, vitest.expect)(result).toBeNull();
|
|
23
|
-
});
|
|
24
|
-
(0, vitest.it)("returns error when any balance is invalid", () => {
|
|
25
|
-
const result = require_common_utils_utils_validation_validate_balances.validateBalances({
|
|
26
|
-
balances: {
|
|
27
|
-
[require_common_utils_test_utils_index.mockToken1]: 500n,
|
|
28
|
-
[require_common_utils_test_utils_index.mockToken2]: 3000n
|
|
29
|
-
},
|
|
30
|
-
assets: [{
|
|
31
|
-
token: require_common_utils_test_utils_index.mockToken1,
|
|
32
|
-
balance: 1000n
|
|
33
|
-
}, {
|
|
34
|
-
token: require_common_utils_test_utils_index.mockToken2,
|
|
35
|
-
balance: 2000n
|
|
36
|
-
}],
|
|
37
|
-
zeroCheck: true
|
|
38
|
-
});
|
|
39
|
-
(0, vitest.expect)(result).toEqual({
|
|
40
|
-
message: "insufficientFunds",
|
|
41
|
-
token: require_common_utils_test_utils_index.mockToken1
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
//#endregion
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
//#region src/common-utils/utils/validation/validate-credit-manager.ts
|
|
3
|
-
function validateCreditManager({ creditManager, allowPausedCm }) {
|
|
4
|
-
if (creditManager.isPaused && !allowPausedCm) return { message: "paused" };
|
|
5
|
-
return null;
|
|
6
|
-
}
|
|
7
|
-
//#endregion
|
|
8
|
-
exports.validateCreditManager = validateCreditManager;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_common_utils_utils_validation_validate_credit_manager = require("./validate-credit-manager.js");
|
|
3
|
-
const require_common_utils_test_utils_index = require("../../test-utils/index.js");
|
|
4
|
-
let vitest = require("vitest");
|
|
5
|
-
//#region src/common-utils/utils/validation/validate-credit-manager.spec.ts
|
|
6
|
-
const mockCreditManager = require_common_utils_test_utils_index.buildCreditManager({ isPaused: false });
|
|
7
|
-
(0, vitest.describe)("validateCreditManager", () => {
|
|
8
|
-
(0, vitest.it)("returns null when credit manager is not paused", () => {
|
|
9
|
-
const result = require_common_utils_utils_validation_validate_credit_manager.validateCreditManager({
|
|
10
|
-
creditManager: mockCreditManager,
|
|
11
|
-
allowPausedCm: false
|
|
12
|
-
});
|
|
13
|
-
(0, vitest.expect)(result).toBeNull();
|
|
14
|
-
});
|
|
15
|
-
(0, vitest.it)("returns null when credit manager is paused but allowed", () => {
|
|
16
|
-
const result = require_common_utils_utils_validation_validate_credit_manager.validateCreditManager({
|
|
17
|
-
creditManager: require_common_utils_test_utils_index.buildCreditManager({
|
|
18
|
-
...mockCreditManager,
|
|
19
|
-
isPaused: true
|
|
20
|
-
}),
|
|
21
|
-
allowPausedCm: true
|
|
22
|
-
});
|
|
23
|
-
(0, vitest.expect)(result).toBeNull();
|
|
24
|
-
});
|
|
25
|
-
(0, vitest.it)("returns error when credit manager is paused and not allowed", () => {
|
|
26
|
-
const result = require_common_utils_utils_validation_validate_credit_manager.validateCreditManager({
|
|
27
|
-
creditManager: require_common_utils_test_utils_index.buildCreditManager({
|
|
28
|
-
...mockCreditManager,
|
|
29
|
-
isPaused: true
|
|
30
|
-
}),
|
|
31
|
-
allowPausedCm: false
|
|
32
|
-
});
|
|
33
|
-
(0, vitest.expect)(result).toEqual({ message: "paused" });
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
//#endregion
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
//#region src/common-utils/utils/validation/validate-hf.ts
|
|
3
|
-
const MIN_HF_LIMITED = 10100n;
|
|
4
|
-
function validateHF({ hf, hfCheck = true }) {
|
|
5
|
-
if (hfCheck && (hf === void 0 || hf <= 10100n)) return { message: "hfTooLow" };
|
|
6
|
-
return null;
|
|
7
|
-
}
|
|
8
|
-
//#endregion
|
|
9
|
-
exports.MIN_HF_LIMITED = MIN_HF_LIMITED;
|
|
10
|
-
exports.validateHF = validateHF;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_common_utils_utils_validation_validate_hf = require("./validate-hf.js");
|
|
3
|
-
let vitest = require("vitest");
|
|
4
|
-
//#region src/common-utils/utils/validation/validate-hf.spec.ts
|
|
5
|
-
(0, vitest.describe)("validateHF", () => {
|
|
6
|
-
(0, vitest.it)("returns null when HF is above minimum", () => {
|
|
7
|
-
const result = require_common_utils_utils_validation_validate_hf.validateHF({ hf: 15e3 });
|
|
8
|
-
(0, vitest.expect)(result).toBeNull();
|
|
9
|
-
});
|
|
10
|
-
(0, vitest.it)("returns error when HF is undefined", () => {
|
|
11
|
-
const result = require_common_utils_utils_validation_validate_hf.validateHF({ hf: void 0 });
|
|
12
|
-
(0, vitest.expect)(result).toEqual({ message: "hfTooLow" });
|
|
13
|
-
});
|
|
14
|
-
(0, vitest.it)("returns error when HF is too low", () => {
|
|
15
|
-
const result = require_common_utils_utils_validation_validate_hf.validateHF({ hf: Number(require_common_utils_utils_validation_validate_hf.MIN_HF_LIMITED) });
|
|
16
|
-
(0, vitest.expect)(result).toEqual({ message: "hfTooLow" });
|
|
17
|
-
});
|
|
18
|
-
(0, vitest.it)("returns null when hfCheck is false and HF is too low", () => {
|
|
19
|
-
const result = require_common_utils_utils_validation_validate_hf.validateHF({
|
|
20
|
-
hf: Number(require_common_utils_utils_validation_validate_hf.MIN_HF_LIMITED - 1n),
|
|
21
|
-
hfCheck: false
|
|
22
|
-
});
|
|
23
|
-
(0, vitest.expect)(result).toBeNull();
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
//#endregion
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
//#region src/common-utils/utils/validation/validate-open-account-pool-quota-status.ts
|
|
3
|
-
function validateOpenAccountPoolQuotaStatus(targetToken, creditManager, amountToBorrow) {
|
|
4
|
-
const quota = creditManager.quotas[targetToken];
|
|
5
|
-
if (quota) {
|
|
6
|
-
if ((quota.isActive ? quota.limit : 0n) - quota.totalQuoted < amountToBorrow) return {
|
|
7
|
-
message: "insufficientQuota",
|
|
8
|
-
token: targetToken
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
return null;
|
|
12
|
-
}
|
|
13
|
-
//#endregion
|
|
14
|
-
exports.validateOpenAccountPoolQuotaStatus = validateOpenAccountPoolQuotaStatus;
|
package/dist/cjs/common-utils/utils/validation/validate-open-account-pool-quota-status.spec.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_common_utils_utils_validation_validate_open_account_pool_quota_status = require("./validate-open-account-pool-quota-status.js");
|
|
3
|
-
const require_common_utils_test_utils_index = require("../../test-utils/index.js");
|
|
4
|
-
let vitest = require("vitest");
|
|
5
|
-
//#region src/common-utils/utils/validation/validate-open-account-pool-quota-status.spec.ts
|
|
6
|
-
const mockCreditManager = require_common_utils_test_utils_index.buildCreditManager({ quotas: { [require_common_utils_test_utils_index.mockToken1]: require_common_utils_test_utils_index.buildQuota({
|
|
7
|
-
token: require_common_utils_test_utils_index.mockToken1,
|
|
8
|
-
limit: 1000000n,
|
|
9
|
-
totalQuoted: 500000n,
|
|
10
|
-
rate: 0n
|
|
11
|
-
}) } });
|
|
12
|
-
(0, vitest.describe)("validateOpenAccountPoolQuotaStatus", () => {
|
|
13
|
-
(0, vitest.it)("returns null when quota is sufficient", () => {
|
|
14
|
-
const result = require_common_utils_utils_validation_validate_open_account_pool_quota_status.validateOpenAccountPoolQuotaStatus(require_common_utils_test_utils_index.mockToken1, mockCreditManager, 100000n);
|
|
15
|
-
(0, vitest.expect)(result).toBeNull();
|
|
16
|
-
});
|
|
17
|
-
(0, vitest.it)("returns error when quota is insufficient", () => {
|
|
18
|
-
const result = require_common_utils_utils_validation_validate_open_account_pool_quota_status.validateOpenAccountPoolQuotaStatus(require_common_utils_test_utils_index.mockToken1, mockCreditManager, 600000n);
|
|
19
|
-
(0, vitest.expect)(result).toEqual({
|
|
20
|
-
message: "insufficientQuota",
|
|
21
|
-
token: require_common_utils_test_utils_index.mockToken1
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
(0, vitest.it)("returns null when token has no quota", () => {
|
|
25
|
-
const result = require_common_utils_utils_validation_validate_open_account_pool_quota_status.validateOpenAccountPoolQuotaStatus("0x9999999999999999999999999999999999999999", mockCreditManager, 100000n);
|
|
26
|
-
(0, vitest.expect)(result).toBeNull();
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
//#endregion
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_onchain_utils_bigint_math = require("../../../onchain/utils/bigint-math.js");
|
|
3
|
-
const require_common_utils_utils_validation_validate_open_account_pool_quota_status = require("./validate-open-account-pool-quota-status.js");
|
|
4
|
-
//#region src/common-utils/utils/validation/validate-open-account-pool-status.ts
|
|
5
|
-
function validateOpenAccountPoolStatus(props) {
|
|
6
|
-
const { debt, creditManager, pool, targetToken } = props;
|
|
7
|
-
const effectiveDebt = require_onchain_utils_bigint_math.BigIntMath.max(creditManager.minDebt, debt);
|
|
8
|
-
const hasDebtLimit = creditManager.totalDebtLimit >= 0n;
|
|
9
|
-
const debtLimitLeft = require_onchain_utils_bigint_math.BigIntMath.max(creditManager.totalDebtLimit - creditManager.totalDebt, 0n);
|
|
10
|
-
const { totalDebtLimit = 0n, totalBorrowed = 0n } = pool || {};
|
|
11
|
-
const hasPoolDebtLimit = totalDebtLimit > 0n;
|
|
12
|
-
const poolDebtLimitLeft = totalDebtLimit - totalBorrowed;
|
|
13
|
-
const canOpenMinDebt = creditManager.minDebt <= debtLimitLeft && creditManager.minDebt <= poolDebtLimitLeft && creditManager.minDebt <= creditManager.availableToBorrow;
|
|
14
|
-
const minPositionSize = require_onchain_utils_bigint_math.BigIntMath.min(require_onchain_utils_bigint_math.BigIntMath.min(debtLimitLeft, poolDebtLimitLeft), creditManager.availableToBorrow);
|
|
15
|
-
if (hasDebtLimit && effectiveDebt > debtLimitLeft) return {
|
|
16
|
-
message: "insufficientDebtLimit",
|
|
17
|
-
amount: debtLimitLeft,
|
|
18
|
-
solutionAmount: canOpenMinDebt ? minPositionSize : void 0
|
|
19
|
-
};
|
|
20
|
-
if (hasPoolDebtLimit && effectiveDebt > poolDebtLimitLeft) return {
|
|
21
|
-
message: "insufficientPoolDebtLimit",
|
|
22
|
-
amount: poolDebtLimitLeft,
|
|
23
|
-
solutionAmount: canOpenMinDebt ? minPositionSize : void 0
|
|
24
|
-
};
|
|
25
|
-
if (effectiveDebt > creditManager.availableToBorrow) return {
|
|
26
|
-
message: "insufficientPoolLiquidity",
|
|
27
|
-
amount: creditManager.availableToBorrow,
|
|
28
|
-
solutionAmount: canOpenMinDebt ? minPositionSize : void 0
|
|
29
|
-
};
|
|
30
|
-
if (targetToken !== null) {
|
|
31
|
-
const quotaError = require_common_utils_utils_validation_validate_open_account_pool_quota_status.validateOpenAccountPoolQuotaStatus(targetToken, creditManager, effectiveDebt);
|
|
32
|
-
if (quotaError) return quotaError;
|
|
33
|
-
}
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
//#endregion
|
|
37
|
-
exports.validateOpenAccountPoolStatus = validateOpenAccountPoolStatus;
|