@morpho-org/blue-sdk 5.16.0 → 5.17.0
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/lib/cjs/package.json +1 -0
- package/lib/{position → cjs/position}/PreLiquidationPosition.d.ts +3 -3
- package/lib/{position → cjs/position}/PreLiquidationPosition.js +16 -16
- package/lib/{preLiquidation.d.ts → cjs/preLiquidation.d.ts} +1 -1
- package/lib/{preLiquidation.js → cjs/preLiquidation.js} +2 -2
- package/lib/{vault → cjs/vault}/index.d.ts +1 -1
- package/lib/{vault → cjs/vault}/index.js +1 -1
- package/lib/{vault → cjs/vault}/v2/VaultV2.d.ts +5 -5
- package/lib/{vault → cjs/vault}/v2/VaultV2.js +25 -25
- package/lib/{vault → cjs/vault}/v2/VaultV2Adapter.d.ts +2 -2
- package/lib/{vault → cjs/vault}/v2/VaultV2MorphoMarketV1Adapter.d.ts +7 -7
- package/lib/{vault → cjs/vault}/v2/VaultV2MorphoMarketV1Adapter.js +9 -9
- package/lib/{vault → cjs/vault}/v2/VaultV2MorphoMarketV1AdapterV2.d.ts +6 -6
- package/lib/{vault → cjs/vault}/v2/VaultV2MorphoMarketV1AdapterV2.js +8 -8
- package/lib/{vault → cjs/vault}/v2/VaultV2MorphoVaultV1Adapter.d.ts +6 -6
- package/lib/{vault → cjs/vault}/v2/VaultV2MorphoVaultV1Adapter.js +2 -2
- package/lib/esm/addresses.d.ts +2231 -0
- package/lib/esm/addresses.js +1309 -0
- package/lib/esm/chain.d.ts +405 -0
- package/lib/esm/chain.js +276 -0
- package/lib/esm/constants.d.ts +20 -0
- package/lib/esm/constants.js +21 -0
- package/lib/esm/errors.d.ts +101 -0
- package/lib/esm/errors.js +192 -0
- package/lib/esm/holding/AssetBalances.d.ts +48 -0
- package/lib/esm/holding/AssetBalances.js +38 -0
- package/lib/esm/holding/Holding.d.ts +63 -0
- package/lib/esm/holding/Holding.js +63 -0
- package/lib/esm/holding/index.d.ts +2 -0
- package/lib/esm/holding/index.js +2 -0
- package/lib/esm/index.d.ts +14 -0
- package/lib/esm/index.js +14 -0
- package/lib/esm/market/Market.d.ts +424 -0
- package/lib/esm/market/Market.js +576 -0
- package/lib/esm/market/MarketParams.d.ts +74 -0
- package/lib/esm/market/MarketParams.js +91 -0
- package/lib/esm/market/MarketUtils.d.ts +273 -0
- package/lib/esm/market/MarketUtils.js +323 -0
- package/lib/esm/market/index.d.ts +3 -0
- package/lib/esm/market/index.js +3 -0
- package/lib/esm/math/AdaptiveCurveIrmLib.d.ts +40 -0
- package/lib/esm/math/AdaptiveCurveIrmLib.js +133 -0
- package/lib/esm/math/MathLib.d.ts +102 -0
- package/lib/esm/math/MathLib.js +168 -0
- package/lib/esm/math/SharesMath.d.ts +12 -0
- package/lib/esm/math/SharesMath.js +18 -0
- package/lib/esm/math/index.d.ts +3 -0
- package/lib/esm/math/index.js +3 -0
- package/lib/esm/package.json +1 -0
- package/lib/esm/position/Position.d.ts +147 -0
- package/lib/esm/position/Position.js +237 -0
- package/lib/esm/position/PreLiquidationPosition.d.ts +60 -0
- package/lib/esm/position/PreLiquidationPosition.js +97 -0
- package/lib/esm/position/index.d.ts +2 -0
- package/lib/esm/position/index.js +2 -0
- package/lib/esm/preLiquidation.d.ts +15 -0
- package/lib/esm/preLiquidation.js +91 -0
- package/lib/esm/token/ConstantWrappedToken.d.ts +17 -0
- package/lib/esm/token/ConstantWrappedToken.js +30 -0
- package/lib/esm/token/Eip5267Domain.d.ts +55 -0
- package/lib/esm/token/Eip5267Domain.js +66 -0
- package/lib/esm/token/ExchangeRateWrappedToken.d.ts +11 -0
- package/lib/esm/token/ExchangeRateWrappedToken.js +17 -0
- package/lib/esm/token/Token.d.ts +52 -0
- package/lib/esm/token/Token.js +62 -0
- package/lib/esm/token/VaultToken.d.ts +23 -0
- package/lib/esm/token/VaultToken.js +27 -0
- package/lib/esm/token/WrappedToken.d.ts +17 -0
- package/lib/esm/token/WrappedToken.js +29 -0
- package/lib/esm/token/index.d.ts +6 -0
- package/lib/esm/token/index.js +6 -0
- package/lib/esm/types.d.ts +26 -0
- package/lib/esm/types.js +13 -0
- package/lib/esm/user/User.d.ts +20 -0
- package/lib/esm/user/User.js +19 -0
- package/lib/esm/user/index.d.ts +1 -0
- package/lib/esm/user/index.js +1 -0
- package/lib/esm/utils.d.ts +13 -0
- package/lib/esm/utils.js +10 -0
- package/lib/esm/vault/Vault.d.ts +214 -0
- package/lib/esm/vault/Vault.js +289 -0
- package/lib/esm/vault/VaultConfig.d.ts +11 -0
- package/lib/esm/vault/VaultConfig.js +10 -0
- package/lib/esm/vault/VaultMarketAllocation.d.ts +20 -0
- package/lib/esm/vault/VaultMarketAllocation.js +27 -0
- package/lib/esm/vault/VaultMarketConfig.d.ts +43 -0
- package/lib/esm/vault/VaultMarketConfig.js +39 -0
- package/lib/esm/vault/VaultMarketPublicAllocatorConfig.d.ts +29 -0
- package/lib/esm/vault/VaultMarketPublicAllocatorConfig.js +24 -0
- package/lib/esm/vault/VaultUser.d.ts +26 -0
- package/lib/esm/vault/VaultUser.js +24 -0
- package/lib/esm/vault/VaultUtils.d.ts +16 -0
- package/lib/esm/vault/VaultUtils.js +17 -0
- package/lib/esm/vault/index.d.ts +8 -0
- package/lib/esm/vault/index.js +8 -0
- package/lib/esm/vault/v2/VaultV2.d.ts +87 -0
- package/lib/esm/vault/v2/VaultV2.js +154 -0
- package/lib/esm/vault/v2/VaultV2Adapter.d.ts +29 -0
- package/lib/esm/vault/v2/VaultV2Adapter.js +12 -0
- package/lib/esm/vault/v2/VaultV2MorphoMarketV1Adapter.d.ts +30 -0
- package/lib/esm/vault/v2/VaultV2MorphoMarketV1Adapter.js +54 -0
- package/lib/esm/vault/v2/VaultV2MorphoMarketV1AdapterV2.d.ts +33 -0
- package/lib/esm/vault/v2/VaultV2MorphoMarketV1AdapterV2.js +63 -0
- package/lib/esm/vault/v2/VaultV2MorphoVaultV1Adapter.d.ts +24 -0
- package/lib/esm/vault/v2/VaultV2MorphoVaultV1Adapter.js +36 -0
- package/lib/esm/vault/v2/index.d.ts +5 -0
- package/lib/esm/vault/v2/index.js +5 -0
- package/package.json +16 -7
- package/src/index.ts +14 -0
- /package/lib/{addresses.d.ts → cjs/addresses.d.ts} +0 -0
- /package/lib/{addresses.js → cjs/addresses.js} +0 -0
- /package/lib/{chain.d.ts → cjs/chain.d.ts} +0 -0
- /package/lib/{chain.js → cjs/chain.js} +0 -0
- /package/lib/{constants.d.ts → cjs/constants.d.ts} +0 -0
- /package/lib/{constants.js → cjs/constants.js} +0 -0
- /package/lib/{errors.d.ts → cjs/errors.d.ts} +0 -0
- /package/lib/{errors.js → cjs/errors.js} +0 -0
- /package/lib/{holding → cjs/holding}/AssetBalances.d.ts +0 -0
- /package/lib/{holding → cjs/holding}/AssetBalances.js +0 -0
- /package/lib/{holding → cjs/holding}/Holding.d.ts +0 -0
- /package/lib/{holding → cjs/holding}/Holding.js +0 -0
- /package/lib/{holding → cjs/holding}/index.d.ts +0 -0
- /package/lib/{holding → cjs/holding}/index.js +0 -0
- /package/lib/{index.d.ts → cjs/index.d.ts} +0 -0
- /package/lib/{index.js → cjs/index.js} +0 -0
- /package/lib/{market → cjs/market}/Market.d.ts +0 -0
- /package/lib/{market → cjs/market}/Market.js +0 -0
- /package/lib/{market → cjs/market}/MarketParams.d.ts +0 -0
- /package/lib/{market → cjs/market}/MarketParams.js +0 -0
- /package/lib/{market → cjs/market}/MarketUtils.d.ts +0 -0
- /package/lib/{market → cjs/market}/MarketUtils.js +0 -0
- /package/lib/{market → cjs/market}/index.d.ts +0 -0
- /package/lib/{market → cjs/market}/index.js +0 -0
- /package/lib/{math → cjs/math}/AdaptiveCurveIrmLib.d.ts +0 -0
- /package/lib/{math → cjs/math}/AdaptiveCurveIrmLib.js +0 -0
- /package/lib/{math → cjs/math}/MathLib.d.ts +0 -0
- /package/lib/{math → cjs/math}/MathLib.js +0 -0
- /package/lib/{math → cjs/math}/SharesMath.d.ts +0 -0
- /package/lib/{math → cjs/math}/SharesMath.js +0 -0
- /package/lib/{math → cjs/math}/index.d.ts +0 -0
- /package/lib/{math → cjs/math}/index.js +0 -0
- /package/lib/{position → cjs/position}/Position.d.ts +0 -0
- /package/lib/{position → cjs/position}/Position.js +0 -0
- /package/lib/{position → cjs/position}/index.d.ts +0 -0
- /package/lib/{position → cjs/position}/index.js +0 -0
- /package/lib/{token → cjs/token}/ConstantWrappedToken.d.ts +0 -0
- /package/lib/{token → cjs/token}/ConstantWrappedToken.js +0 -0
- /package/lib/{token → cjs/token}/Eip5267Domain.d.ts +0 -0
- /package/lib/{token → cjs/token}/Eip5267Domain.js +0 -0
- /package/lib/{token → cjs/token}/ExchangeRateWrappedToken.d.ts +0 -0
- /package/lib/{token → cjs/token}/ExchangeRateWrappedToken.js +0 -0
- /package/lib/{token → cjs/token}/Token.d.ts +0 -0
- /package/lib/{token → cjs/token}/Token.js +0 -0
- /package/lib/{token → cjs/token}/VaultToken.d.ts +0 -0
- /package/lib/{token → cjs/token}/VaultToken.js +0 -0
- /package/lib/{token → cjs/token}/WrappedToken.d.ts +0 -0
- /package/lib/{token → cjs/token}/WrappedToken.js +0 -0
- /package/lib/{token → cjs/token}/index.d.ts +0 -0
- /package/lib/{token → cjs/token}/index.js +0 -0
- /package/lib/{types.d.ts → cjs/types.d.ts} +0 -0
- /package/lib/{types.js → cjs/types.js} +0 -0
- /package/lib/{user → cjs/user}/User.d.ts +0 -0
- /package/lib/{user → cjs/user}/User.js +0 -0
- /package/lib/{user → cjs/user}/index.d.ts +0 -0
- /package/lib/{user → cjs/user}/index.js +0 -0
- /package/lib/{utils.d.ts → cjs/utils.d.ts} +0 -0
- /package/lib/{utils.js → cjs/utils.js} +0 -0
- /package/lib/{vault → cjs/vault}/Vault.d.ts +0 -0
- /package/lib/{vault → cjs/vault}/Vault.js +0 -0
- /package/lib/{vault → cjs/vault}/VaultConfig.d.ts +0 -0
- /package/lib/{vault → cjs/vault}/VaultConfig.js +0 -0
- /package/lib/{vault → cjs/vault}/VaultMarketAllocation.d.ts +0 -0
- /package/lib/{vault → cjs/vault}/VaultMarketAllocation.js +0 -0
- /package/lib/{vault → cjs/vault}/VaultMarketConfig.d.ts +0 -0
- /package/lib/{vault → cjs/vault}/VaultMarketConfig.js +0 -0
- /package/lib/{vault → cjs/vault}/VaultMarketPublicAllocatorConfig.d.ts +0 -0
- /package/lib/{vault → cjs/vault}/VaultMarketPublicAllocatorConfig.js +0 -0
- /package/lib/{vault → cjs/vault}/VaultUser.d.ts +0 -0
- /package/lib/{vault → cjs/vault}/VaultUser.js +0 -0
- /package/lib/{vault → cjs/vault}/VaultUtils.d.ts +0 -0
- /package/lib/{vault → cjs/vault}/VaultUtils.js +0 -0
- /package/lib/{vault → cjs/vault}/v2/VaultV2Adapter.js +0 -0
- /package/lib/{vault → cjs/vault}/v2/index.d.ts +0 -0
- /package/lib/{vault → cjs/vault}/v2/index.js +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Time } from "@morpho-org/morpho-ts";
|
|
2
|
+
/**
|
|
3
|
+
* The liquidation cursor used to calculate the liquidation incentive. Hardcoded to 30%.
|
|
4
|
+
*/
|
|
5
|
+
export const LIQUIDATION_CURSOR = 300000000000000000n;
|
|
6
|
+
/**
|
|
7
|
+
* The maximum liquidation incentive factor. Hardcoded to 115%.
|
|
8
|
+
*/
|
|
9
|
+
export const MAX_LIQUIDATION_INCENTIVE_FACTOR = 1150000000000000000n;
|
|
10
|
+
/**
|
|
11
|
+
* The scale of the oracle price. Hardcoded to 1e36.
|
|
12
|
+
*/
|
|
13
|
+
export const ORACLE_PRICE_SCALE = 1000000000000000000000000000000000000n;
|
|
14
|
+
/**
|
|
15
|
+
* The default slippage tolerance used in the SDK. Hardcoded to 0.03%.
|
|
16
|
+
*/
|
|
17
|
+
export const DEFAULT_SLIPPAGE_TOLERANCE = 300000000000000n;
|
|
18
|
+
/**
|
|
19
|
+
* The number of seconds in a year.
|
|
20
|
+
*/
|
|
21
|
+
export const SECONDS_PER_YEAR = Time.s.from.y(1n);
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { type Hex } from "viem";
|
|
2
|
+
import type { Address, MarketId } from "./types.js";
|
|
3
|
+
export declare class InvalidMarketParamsError extends Error {
|
|
4
|
+
readonly data: Hex;
|
|
5
|
+
constructor(data: Hex);
|
|
6
|
+
}
|
|
7
|
+
export declare class UnknownDataError extends Error {
|
|
8
|
+
}
|
|
9
|
+
export declare class UnknownTokenError extends UnknownDataError {
|
|
10
|
+
readonly address: Address;
|
|
11
|
+
constructor(address: Address);
|
|
12
|
+
}
|
|
13
|
+
export declare class UnknownTokenPriceError extends UnknownDataError {
|
|
14
|
+
readonly address: Address;
|
|
15
|
+
constructor(address: Address);
|
|
16
|
+
}
|
|
17
|
+
export declare class UnknownMarketParamsError extends UnknownDataError {
|
|
18
|
+
readonly marketId: MarketId;
|
|
19
|
+
constructor(marketId: MarketId);
|
|
20
|
+
}
|
|
21
|
+
export declare class UnknownVaultConfigError extends UnknownDataError {
|
|
22
|
+
readonly vault: Address;
|
|
23
|
+
constructor(vault: Address);
|
|
24
|
+
}
|
|
25
|
+
export declare class UnsupportedChainIdError extends Error {
|
|
26
|
+
readonly chainId: number;
|
|
27
|
+
constructor(chainId: number);
|
|
28
|
+
}
|
|
29
|
+
export declare class UnsupportedPreLiquidationParamsError extends Error {
|
|
30
|
+
readonly lltv: bigint;
|
|
31
|
+
constructor(lltv: bigint);
|
|
32
|
+
}
|
|
33
|
+
export declare class UnsupportedVaultV2AdapterError extends Error {
|
|
34
|
+
readonly address: Address;
|
|
35
|
+
constructor(address: Address);
|
|
36
|
+
}
|
|
37
|
+
export declare namespace BlueErrors {
|
|
38
|
+
class AlreadySet extends Error {
|
|
39
|
+
readonly name: string;
|
|
40
|
+
readonly value: string;
|
|
41
|
+
constructor(name: string, value: string);
|
|
42
|
+
}
|
|
43
|
+
class InvalidInterestAccrual extends Error {
|
|
44
|
+
readonly marketId: MarketId;
|
|
45
|
+
readonly timestamp: bigint;
|
|
46
|
+
readonly lastUpdate: bigint;
|
|
47
|
+
constructor(marketId: MarketId, timestamp: bigint, lastUpdate: bigint);
|
|
48
|
+
}
|
|
49
|
+
class InconsistentInput extends Error {
|
|
50
|
+
readonly assets: bigint;
|
|
51
|
+
readonly shares: bigint;
|
|
52
|
+
constructor(assets: bigint, shares: bigint);
|
|
53
|
+
}
|
|
54
|
+
class InsufficientLiquidity extends Error {
|
|
55
|
+
readonly marketId: MarketId;
|
|
56
|
+
constructor(marketId: MarketId);
|
|
57
|
+
}
|
|
58
|
+
class UnknownOraclePrice extends Error {
|
|
59
|
+
readonly marketId: MarketId;
|
|
60
|
+
constructor(marketId: MarketId);
|
|
61
|
+
}
|
|
62
|
+
class InsufficientPosition extends Error {
|
|
63
|
+
readonly user: Address;
|
|
64
|
+
readonly marketId: MarketId;
|
|
65
|
+
constructor(user: Address, marketId: MarketId);
|
|
66
|
+
}
|
|
67
|
+
class InsufficientCollateral extends Error {
|
|
68
|
+
readonly user: Address;
|
|
69
|
+
readonly marketId: MarketId;
|
|
70
|
+
constructor(user: Address, marketId: MarketId);
|
|
71
|
+
}
|
|
72
|
+
class ExpiredSignature extends Error {
|
|
73
|
+
readonly deadline: bigint;
|
|
74
|
+
constructor(deadline: bigint);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
export declare namespace VaultV2Errors {
|
|
78
|
+
class InvalidInterestAccrual extends Error {
|
|
79
|
+
readonly vault: Address;
|
|
80
|
+
readonly timestamp: bigint;
|
|
81
|
+
readonly lastUpdate: bigint;
|
|
82
|
+
constructor(vault: Address, timestamp: bigint, lastUpdate: bigint);
|
|
83
|
+
}
|
|
84
|
+
class UnsupportedLiquidityAdapter extends Error {
|
|
85
|
+
readonly address: Address;
|
|
86
|
+
constructor(address: Address);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
export declare class UnknownFactory extends Error {
|
|
90
|
+
constructor();
|
|
91
|
+
}
|
|
92
|
+
export declare class UnknownOfFactory extends Error {
|
|
93
|
+
readonly factory: Address;
|
|
94
|
+
readonly address: Address;
|
|
95
|
+
constructor(factory: Address, address: Address);
|
|
96
|
+
}
|
|
97
|
+
export interface ErrorClass<E extends Error = Error> {
|
|
98
|
+
new (...args: any[]): E;
|
|
99
|
+
}
|
|
100
|
+
export declare function _try<T, ErrorClasses extends readonly ErrorClass[] = []>(accessor: () => Promise<T>, ...errorClasses: ErrorClasses): Promise<T | undefined>;
|
|
101
|
+
export declare function _try<T, ErrorClasses extends readonly ErrorClass[] = []>(accessor: () => T, ...errorClasses: ErrorClasses): T | undefined;
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { formatUnits } from "viem";
|
|
2
|
+
export class InvalidMarketParamsError extends Error {
|
|
3
|
+
data;
|
|
4
|
+
constructor(data) {
|
|
5
|
+
super(`cannot decode valid MarketParams from "${data}"`);
|
|
6
|
+
this.data = data;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export class UnknownDataError extends Error {
|
|
10
|
+
}
|
|
11
|
+
export class UnknownTokenError extends UnknownDataError {
|
|
12
|
+
address;
|
|
13
|
+
constructor(address) {
|
|
14
|
+
super(`unknown token ${address}`);
|
|
15
|
+
this.address = address;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export class UnknownTokenPriceError extends UnknownDataError {
|
|
19
|
+
address;
|
|
20
|
+
constructor(address) {
|
|
21
|
+
super(`unknown price of token ${address}`);
|
|
22
|
+
this.address = address;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export class UnknownMarketParamsError extends UnknownDataError {
|
|
26
|
+
marketId;
|
|
27
|
+
constructor(marketId) {
|
|
28
|
+
super(`unknown config for market ${marketId}`);
|
|
29
|
+
this.marketId = marketId;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export class UnknownVaultConfigError extends UnknownDataError {
|
|
33
|
+
vault;
|
|
34
|
+
constructor(vault) {
|
|
35
|
+
super(`unknown config for vault ${vault}`);
|
|
36
|
+
this.vault = vault;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export class UnsupportedChainIdError extends Error {
|
|
40
|
+
chainId;
|
|
41
|
+
constructor(chainId) {
|
|
42
|
+
super(`unsupported chain ${chainId}`);
|
|
43
|
+
this.chainId = chainId;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export class UnsupportedPreLiquidationParamsError extends Error {
|
|
47
|
+
lltv;
|
|
48
|
+
constructor(lltv) {
|
|
49
|
+
super(`unsupported pre liquidation params for lltv ${formatUnits(lltv, 16)}%`);
|
|
50
|
+
this.lltv = lltv;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export class UnsupportedVaultV2AdapterError extends Error {
|
|
54
|
+
address;
|
|
55
|
+
constructor(address) {
|
|
56
|
+
super(`vault v2 adapter "${address}" is not supported`);
|
|
57
|
+
this.address = address;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export var BlueErrors;
|
|
61
|
+
(function (BlueErrors) {
|
|
62
|
+
class AlreadySet extends Error {
|
|
63
|
+
name;
|
|
64
|
+
value;
|
|
65
|
+
constructor(name, value) {
|
|
66
|
+
super(`${name} is already set to ${value}`);
|
|
67
|
+
this.name = name;
|
|
68
|
+
this.value = value;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
BlueErrors.AlreadySet = AlreadySet;
|
|
72
|
+
class InvalidInterestAccrual extends Error {
|
|
73
|
+
marketId;
|
|
74
|
+
timestamp;
|
|
75
|
+
lastUpdate;
|
|
76
|
+
constructor(marketId, timestamp, lastUpdate) {
|
|
77
|
+
super(`invalid interest accrual on market ${marketId}: accrual timestamp ${timestamp} can't be prior to last update ${lastUpdate}`);
|
|
78
|
+
this.marketId = marketId;
|
|
79
|
+
this.timestamp = timestamp;
|
|
80
|
+
this.lastUpdate = lastUpdate;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
BlueErrors.InvalidInterestAccrual = InvalidInterestAccrual;
|
|
84
|
+
class InconsistentInput extends Error {
|
|
85
|
+
assets;
|
|
86
|
+
shares;
|
|
87
|
+
constructor(assets, shares) {
|
|
88
|
+
super(`inconsistent input assets "${assets}" and shares "${shares}"`);
|
|
89
|
+
this.assets = assets;
|
|
90
|
+
this.shares = shares;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
BlueErrors.InconsistentInput = InconsistentInput;
|
|
94
|
+
class InsufficientLiquidity extends Error {
|
|
95
|
+
marketId;
|
|
96
|
+
constructor(marketId) {
|
|
97
|
+
super(`insufficient liquidity on market ${marketId}`);
|
|
98
|
+
this.marketId = marketId;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
BlueErrors.InsufficientLiquidity = InsufficientLiquidity;
|
|
102
|
+
class UnknownOraclePrice extends Error {
|
|
103
|
+
marketId;
|
|
104
|
+
constructor(marketId) {
|
|
105
|
+
super(`unknown oracle price of market "${marketId}"`);
|
|
106
|
+
this.marketId = marketId;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
BlueErrors.UnknownOraclePrice = UnknownOraclePrice;
|
|
110
|
+
class InsufficientPosition extends Error {
|
|
111
|
+
user;
|
|
112
|
+
marketId;
|
|
113
|
+
constructor(user, marketId) {
|
|
114
|
+
super(`insufficient position for user ${user} on market ${marketId}`);
|
|
115
|
+
this.user = user;
|
|
116
|
+
this.marketId = marketId;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
BlueErrors.InsufficientPosition = InsufficientPosition;
|
|
120
|
+
class InsufficientCollateral extends Error {
|
|
121
|
+
user;
|
|
122
|
+
marketId;
|
|
123
|
+
constructor(user, marketId) {
|
|
124
|
+
super(`insufficient collateral for user ${user} on market ${marketId}`);
|
|
125
|
+
this.user = user;
|
|
126
|
+
this.marketId = marketId;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
BlueErrors.InsufficientCollateral = InsufficientCollateral;
|
|
130
|
+
class ExpiredSignature extends Error {
|
|
131
|
+
deadline;
|
|
132
|
+
constructor(deadline) {
|
|
133
|
+
super(`expired signature deadline "${deadline}"`);
|
|
134
|
+
this.deadline = deadline;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
BlueErrors.ExpiredSignature = ExpiredSignature;
|
|
138
|
+
})(BlueErrors || (BlueErrors = {}));
|
|
139
|
+
export var VaultV2Errors;
|
|
140
|
+
(function (VaultV2Errors) {
|
|
141
|
+
class InvalidInterestAccrual extends Error {
|
|
142
|
+
vault;
|
|
143
|
+
timestamp;
|
|
144
|
+
lastUpdate;
|
|
145
|
+
constructor(vault, timestamp, lastUpdate) {
|
|
146
|
+
super(`invalid interest accrual on vault ${vault}: accrual timestamp ${timestamp} can't be prior to last update ${lastUpdate}`);
|
|
147
|
+
this.vault = vault;
|
|
148
|
+
this.timestamp = timestamp;
|
|
149
|
+
this.lastUpdate = lastUpdate;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
VaultV2Errors.InvalidInterestAccrual = InvalidInterestAccrual;
|
|
153
|
+
class UnsupportedLiquidityAdapter extends Error {
|
|
154
|
+
address;
|
|
155
|
+
constructor(address) {
|
|
156
|
+
super(`unsupported liquidity adapter "${address}"`);
|
|
157
|
+
this.address = address;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
VaultV2Errors.UnsupportedLiquidityAdapter = UnsupportedLiquidityAdapter;
|
|
161
|
+
})(VaultV2Errors || (VaultV2Errors = {}));
|
|
162
|
+
export class UnknownFactory extends Error {
|
|
163
|
+
constructor() {
|
|
164
|
+
super(`unknown factory`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
export class UnknownOfFactory extends Error {
|
|
168
|
+
factory;
|
|
169
|
+
address;
|
|
170
|
+
constructor(factory, address) {
|
|
171
|
+
super(`address "${address}" is not from the ${factory} factory`);
|
|
172
|
+
this.factory = factory;
|
|
173
|
+
this.address = address;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
export function _try(accessor, ...errorClasses) {
|
|
177
|
+
const maybeCatchError = (error) => {
|
|
178
|
+
if (errorClasses.length === 0 ||
|
|
179
|
+
errorClasses.some((errorClass) => error instanceof errorClass))
|
|
180
|
+
return;
|
|
181
|
+
throw error;
|
|
182
|
+
};
|
|
183
|
+
try {
|
|
184
|
+
const res = accessor();
|
|
185
|
+
if (res instanceof Promise)
|
|
186
|
+
return res.catch(maybeCatchError);
|
|
187
|
+
return res;
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
return maybeCatchError(error);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Token } from "../token/Token.js";
|
|
2
|
+
export type PeripheralBalanceType = "base" | "wrapped" | "staked-wrapped" | "vault" | "wrapped-vault" | "unwrapped-staked-wrapped";
|
|
3
|
+
/**
|
|
4
|
+
* Represents the balance of a requested token and the balance quoted in the corresponding source token:
|
|
5
|
+
* ```{
|
|
6
|
+
* type: "staked-wrapped",
|
|
7
|
+
* srcToken: ETH,
|
|
8
|
+
* srcAmount: 1 ETH,
|
|
9
|
+
* dstAmount: 1.2 wstETH
|
|
10
|
+
* }```
|
|
11
|
+
*/
|
|
12
|
+
export interface PeripheralBalance {
|
|
13
|
+
/**
|
|
14
|
+
* The type of balance conversion.
|
|
15
|
+
*/
|
|
16
|
+
type: PeripheralBalanceType;
|
|
17
|
+
/**
|
|
18
|
+
* The source token held corresponding to the type of balance conversion.
|
|
19
|
+
*/
|
|
20
|
+
srcToken: Token;
|
|
21
|
+
/**
|
|
22
|
+
* The source amount of source token held.
|
|
23
|
+
*/
|
|
24
|
+
srcAmount: bigint;
|
|
25
|
+
/**
|
|
26
|
+
* The corresponding amount of token held after conversion of the whole balance `srcAmount`.
|
|
27
|
+
*/
|
|
28
|
+
dstAmount: bigint;
|
|
29
|
+
}
|
|
30
|
+
export interface IAssetBalances extends Omit<PeripheralBalance, "type"> {
|
|
31
|
+
}
|
|
32
|
+
export declare class AssetBalances {
|
|
33
|
+
/**
|
|
34
|
+
* The total balance of all types of related tokens.
|
|
35
|
+
*/
|
|
36
|
+
total: bigint;
|
|
37
|
+
/**
|
|
38
|
+
* The balance of each type of related tokens and the corresponding underlying balance.
|
|
39
|
+
*/
|
|
40
|
+
allocations: {
|
|
41
|
+
base: PeripheralBalance;
|
|
42
|
+
} & {
|
|
43
|
+
[T in Exclude<PeripheralBalanceType, "base">]?: PeripheralBalance;
|
|
44
|
+
};
|
|
45
|
+
constructor(balance: IAssetBalances);
|
|
46
|
+
add(balance: PeripheralBalance): this;
|
|
47
|
+
sub(balance: PeripheralBalance): this;
|
|
48
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export class AssetBalances {
|
|
2
|
+
/**
|
|
3
|
+
* The total balance of all types of related tokens.
|
|
4
|
+
*/
|
|
5
|
+
total;
|
|
6
|
+
/**
|
|
7
|
+
* The balance of each type of related tokens and the corresponding underlying balance.
|
|
8
|
+
*/
|
|
9
|
+
allocations;
|
|
10
|
+
constructor(balance) {
|
|
11
|
+
this.total = balance.dstAmount;
|
|
12
|
+
this.allocations = {
|
|
13
|
+
base: { ...balance, type: "base" },
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
add(balance) {
|
|
17
|
+
this.total += balance.dstAmount;
|
|
18
|
+
const allocation = (this.allocations[balance.type] ??= {
|
|
19
|
+
...balance,
|
|
20
|
+
srcAmount: 0n,
|
|
21
|
+
dstAmount: 0n,
|
|
22
|
+
});
|
|
23
|
+
allocation.srcAmount += balance.srcAmount;
|
|
24
|
+
allocation.dstAmount += balance.dstAmount;
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
sub(balance) {
|
|
28
|
+
this.total -= balance.dstAmount;
|
|
29
|
+
const allocation = (this.allocations[balance.type] ??= {
|
|
30
|
+
...balance,
|
|
31
|
+
srcAmount: 0n,
|
|
32
|
+
dstAmount: 0n,
|
|
33
|
+
});
|
|
34
|
+
allocation.srcAmount -= balance.srcAmount;
|
|
35
|
+
allocation.dstAmount -= balance.dstAmount;
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Address, BigIntish } from "../types.js";
|
|
2
|
+
export declare const ERC20_ALLOWANCE_RECIPIENTS: readonly ["morpho", "permit2", "bundler3.generalAdapter1"];
|
|
3
|
+
export type Erc20AllowanceRecipient = (typeof ERC20_ALLOWANCE_RECIPIENTS)[number];
|
|
4
|
+
export interface Permit2Allowance {
|
|
5
|
+
amount: bigint;
|
|
6
|
+
expiration: bigint;
|
|
7
|
+
nonce: bigint;
|
|
8
|
+
}
|
|
9
|
+
export interface IPermit2Allowance {
|
|
10
|
+
amount: BigIntish;
|
|
11
|
+
expiration: BigIntish;
|
|
12
|
+
nonce: BigIntish;
|
|
13
|
+
}
|
|
14
|
+
export interface IHolding {
|
|
15
|
+
user: Address;
|
|
16
|
+
token: Address;
|
|
17
|
+
erc20Allowances: {
|
|
18
|
+
[key in Erc20AllowanceRecipient]: bigint;
|
|
19
|
+
};
|
|
20
|
+
permit2BundlerAllowance: IPermit2Allowance;
|
|
21
|
+
erc2612Nonce?: bigint;
|
|
22
|
+
canTransfer?: boolean;
|
|
23
|
+
balance: bigint;
|
|
24
|
+
}
|
|
25
|
+
export declare class Holding implements IHolding {
|
|
26
|
+
/**
|
|
27
|
+
* The user of this holding.
|
|
28
|
+
*/
|
|
29
|
+
readonly user: Address;
|
|
30
|
+
/**
|
|
31
|
+
* The token in which this holding is denominated.
|
|
32
|
+
*/
|
|
33
|
+
readonly token: Address;
|
|
34
|
+
/**
|
|
35
|
+
* Whether the user is allowed to transfer this holding's balance.
|
|
36
|
+
*/
|
|
37
|
+
canTransfer?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* ERC20 allowance for this token from the user to the allowance recipient.
|
|
40
|
+
*/
|
|
41
|
+
readonly erc20Allowances: {
|
|
42
|
+
[key in Erc20AllowanceRecipient]: bigint;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Permit2 allowance for this token from the user to the allowance recipient.
|
|
46
|
+
*/
|
|
47
|
+
readonly permit2BundlerAllowance: Permit2Allowance;
|
|
48
|
+
/**
|
|
49
|
+
* ERC-2612 Permit nonce of the user for this token.
|
|
50
|
+
* `undefined` if the token does not support ERC-2612.
|
|
51
|
+
*/
|
|
52
|
+
erc2612Nonce?: bigint;
|
|
53
|
+
/**
|
|
54
|
+
* Allows to customize the setter behavior in child classes.
|
|
55
|
+
*/
|
|
56
|
+
protected _balance: bigint;
|
|
57
|
+
constructor({ user, token, erc20Allowances, permit2BundlerAllowance, balance, erc2612Nonce, canTransfer, }: IHolding);
|
|
58
|
+
/**
|
|
59
|
+
* The balance of the user for this token.
|
|
60
|
+
*/
|
|
61
|
+
get balance(): bigint;
|
|
62
|
+
set balance(value: bigint);
|
|
63
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { entries, fromEntries } from "@morpho-org/morpho-ts";
|
|
2
|
+
export const ERC20_ALLOWANCE_RECIPIENTS = [
|
|
3
|
+
"morpho",
|
|
4
|
+
"permit2",
|
|
5
|
+
"bundler3.generalAdapter1",
|
|
6
|
+
];
|
|
7
|
+
export class Holding {
|
|
8
|
+
/**
|
|
9
|
+
* The user of this holding.
|
|
10
|
+
*/
|
|
11
|
+
user;
|
|
12
|
+
/**
|
|
13
|
+
* The token in which this holding is denominated.
|
|
14
|
+
*/
|
|
15
|
+
token;
|
|
16
|
+
/**
|
|
17
|
+
* Whether the user is allowed to transfer this holding's balance.
|
|
18
|
+
*/
|
|
19
|
+
canTransfer;
|
|
20
|
+
/**
|
|
21
|
+
* ERC20 allowance for this token from the user to the allowance recipient.
|
|
22
|
+
*/
|
|
23
|
+
erc20Allowances;
|
|
24
|
+
/**
|
|
25
|
+
* Permit2 allowance for this token from the user to the allowance recipient.
|
|
26
|
+
*/
|
|
27
|
+
permit2BundlerAllowance;
|
|
28
|
+
/**
|
|
29
|
+
* ERC-2612 Permit nonce of the user for this token.
|
|
30
|
+
* `undefined` if the token does not support ERC-2612.
|
|
31
|
+
*/
|
|
32
|
+
erc2612Nonce;
|
|
33
|
+
/**
|
|
34
|
+
* Allows to customize the setter behavior in child classes.
|
|
35
|
+
*/
|
|
36
|
+
_balance;
|
|
37
|
+
constructor({ user, token, erc20Allowances, permit2BundlerAllowance, balance, erc2612Nonce, canTransfer, }) {
|
|
38
|
+
this.user = user;
|
|
39
|
+
this.token = token;
|
|
40
|
+
this._balance = balance;
|
|
41
|
+
this.canTransfer = canTransfer;
|
|
42
|
+
this.erc20Allowances = fromEntries(entries(erc20Allowances).map(([address, allowance]) => [
|
|
43
|
+
address,
|
|
44
|
+
allowance,
|
|
45
|
+
]));
|
|
46
|
+
this.permit2BundlerAllowance = {
|
|
47
|
+
amount: BigInt(permit2BundlerAllowance.amount),
|
|
48
|
+
expiration: BigInt(permit2BundlerAllowance.expiration),
|
|
49
|
+
nonce: BigInt(permit2BundlerAllowance.nonce),
|
|
50
|
+
};
|
|
51
|
+
if (erc2612Nonce != null)
|
|
52
|
+
this.erc2612Nonce = erc2612Nonce;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The balance of the user for this token.
|
|
56
|
+
*/
|
|
57
|
+
get balance() {
|
|
58
|
+
return this._balance;
|
|
59
|
+
}
|
|
60
|
+
set balance(value) {
|
|
61
|
+
this._balance = value;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from "./addresses.js";
|
|
2
|
+
export * from "./constants.js";
|
|
3
|
+
export * from "./errors.js";
|
|
4
|
+
export * from "./market/index.js";
|
|
5
|
+
export * from "./chain.js";
|
|
6
|
+
export * from "./token/index.js";
|
|
7
|
+
export * from "./types.js";
|
|
8
|
+
export * from "./math/index.js";
|
|
9
|
+
export * from "./user/index.js";
|
|
10
|
+
export * from "./holding/index.js";
|
|
11
|
+
export * from "./position/index.js";
|
|
12
|
+
export * from "./vault/index.js";
|
|
13
|
+
export * from "./preLiquidation.js";
|
|
14
|
+
export * from "./utils.js";
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from "./addresses.js";
|
|
2
|
+
export * from "./constants.js";
|
|
3
|
+
export * from "./errors.js";
|
|
4
|
+
export * from "./market/index.js";
|
|
5
|
+
export * from "./chain.js";
|
|
6
|
+
export * from "./token/index.js";
|
|
7
|
+
export * from "./types.js";
|
|
8
|
+
export * from "./math/index.js";
|
|
9
|
+
export * from "./user/index.js";
|
|
10
|
+
export * from "./holding/index.js";
|
|
11
|
+
export * from "./position/index.js";
|
|
12
|
+
export * from "./vault/index.js";
|
|
13
|
+
export * from "./preLiquidation.js";
|
|
14
|
+
export * from "./utils.js";
|