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