@morpho-org/blue-sdk 1.0.2 → 1.0.4
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/addresses.d.ts +156 -0
- package/lib/addresses.js +160 -0
- package/lib/chain/chain.constants.d.ts +3 -0
- package/lib/chain/chain.constants.js +232 -0
- package/lib/chain/chain.test.d.ts +1 -0
- package/lib/chain/chain.test.js +37 -0
- package/lib/chain/chain.types.d.ts +20 -0
- package/lib/chain/chain.types.js +30 -0
- package/lib/chain/chain.utils.d.ts +14 -0
- package/lib/chain/chain.utils.js +30 -0
- package/lib/chain/index.js +18 -0
- package/lib/constants.d.ts +8 -0
- package/lib/constants.js +13 -0
- package/lib/errors.d.ts +37 -0
- package/lib/errors.js +71 -0
- package/lib/ethers/ethers.test.d.ts +1 -0
- package/lib/ethers/ethers.test.js +11 -0
- package/lib/ethers/index.js +18 -0
- package/lib/ethers/safeGetAddress.d.ts +1 -0
- package/lib/ethers/safeGetAddress.js +6 -0
- package/lib/ethers/safeParseUnits.d.ts +2 -0
- package/lib/ethers/safeParseUnits.js +25 -0
- package/lib/evm.d.ts +36 -0
- package/lib/evm.js +113 -0
- package/lib/helpers/format/format.d.ts +98 -0
- package/lib/helpers/format/format.js +301 -0
- package/lib/helpers/format/format.test.d.ts +1 -0
- package/lib/helpers/format/format.test.js +257 -0
- package/lib/helpers/format/index.js +17 -0
- package/lib/helpers/getChecksumedAddress.d.ts +7 -0
- package/lib/helpers/getChecksumedAddress.js +17 -0
- package/lib/helpers/index.js +20 -0
- package/{src/helpers/isZeroAddressOrUnset.ts → lib/helpers/isZeroAddressOrUnset.d.ts} +1 -7
- package/lib/helpers/isZeroAddressOrUnset.js +14 -0
- package/lib/helpers/locale.d.ts +36 -0
- package/lib/helpers/locale.js +86 -0
- package/lib/holding/Holding.d.ts +60 -0
- package/lib/holding/Holding.js +31 -0
- package/lib/holding/index.js +17 -0
- package/{src/index.ts → lib/index.d.ts} +0 -1
- package/lib/index.js +62 -0
- package/lib/market/Market.d.ts +159 -0
- package/lib/market/Market.js +240 -0
- package/lib/market/MarketConfig.d.ts +44 -0
- package/lib/market/MarketConfig.js +56 -0
- package/lib/market/MarketUtils.d.ts +165 -0
- package/lib/market/MarketUtils.js +182 -0
- package/lib/market/MarketUtils.test.d.ts +1 -0
- package/lib/market/MarketUtils.test.js +19 -0
- package/lib/market/index.js +19 -0
- package/lib/maths/AdaptiveCurveIrmLib.d.ts +37 -0
- package/lib/maths/AdaptiveCurveIrmLib.js +116 -0
- package/lib/maths/MathLib.d.ts +94 -0
- package/lib/maths/MathLib.js +153 -0
- package/lib/maths/MathUtils.d.ts +15 -0
- package/lib/maths/MathUtils.js +33 -0
- package/lib/maths/SharesMath.d.ts +12 -0
- package/lib/maths/SharesMath.js +22 -0
- package/lib/maths/index.js +20 -0
- package/lib/notifications.d.ts +98 -0
- package/lib/notifications.js +52 -0
- package/lib/position/Position.d.ts +118 -0
- package/lib/position/Position.js +145 -0
- package/lib/position/index.js +17 -0
- package/lib/signatures/index.d.ts +12 -0
- package/lib/signatures/index.js +39 -0
- package/lib/signatures/manager.d.ts +10 -0
- package/lib/signatures/manager.js +37 -0
- package/lib/signatures/permit.d.ts +21 -0
- package/lib/signatures/permit.js +101 -0
- package/lib/signatures/permit2.d.ts +20 -0
- package/lib/signatures/permit2.js +91 -0
- package/lib/signatures/types.d.ts +13 -0
- package/lib/signatures/types.js +2 -0
- package/lib/signatures/utils.d.ts +6 -0
- package/lib/signatures/utils.js +44 -0
- package/lib/tests/mocks/markets.d.ts +17 -0
- package/lib/tests/mocks/markets.js +108 -0
- package/lib/token/ERC20Metadata.d.ts +249 -0
- package/lib/token/ERC20Metadata.js +81 -0
- package/lib/token/Token.d.ts +45 -0
- package/lib/token/Token.js +39 -0
- package/lib/token/TokenNamespace.d.ts +18 -0
- package/lib/token/TokenNamespace.js +55 -0
- package/lib/token/WrappedToken.d.ts +42 -0
- package/lib/token/WrappedToken.js +87 -0
- package/lib/token/index.js +18 -0
- package/lib/types.d.ts +29 -0
- package/lib/types.js +23 -0
- package/lib/user/User.d.ts +20 -0
- package/lib/user/User.js +11 -0
- package/lib/user/index.js +18 -0
- package/lib/user/user.types.d.ts +18 -0
- package/lib/user/user.types.js +2 -0
- package/lib/vault/Vault.d.ts +167 -0
- package/lib/vault/Vault.js +156 -0
- package/lib/vault/VaultAllocation.d.ts +38 -0
- package/lib/vault/VaultAllocation.js +18 -0
- package/lib/vault/VaultConfig.d.ts +23 -0
- package/lib/vault/VaultConfig.js +26 -0
- package/lib/vault/VaultUtils.d.ts +17 -0
- package/lib/vault/VaultUtils.js +17 -0
- package/lib/vault/index.js +20 -0
- package/package.json +7 -11
- package/src/addresses.ts +0 -261
- package/src/chain/chain.constants.ts +0 -235
- package/src/chain/chain.test.ts +0 -51
- package/src/chain/chain.types.ts +0 -42
- package/src/chain/chain.utils.ts +0 -44
- package/src/constants.ts +0 -18
- package/src/errors.ts +0 -75
- package/src/ethers/ethers.test.ts +0 -17
- package/src/ethers/safeGetAddress.ts +0 -4
- package/src/ethers/safeParseUnits.ts +0 -29
- package/src/evm.ts +0 -172
- package/src/helpers/format/format.test.ts +0 -340
- package/src/helpers/format/format.ts +0 -416
- package/src/helpers/getChecksumedAddress.ts +0 -15
- package/src/helpers/locale.ts +0 -108
- package/src/holding/Holding.ts +0 -109
- package/src/market/Market.ts +0 -479
- package/src/market/MarketConfig.ts +0 -108
- package/src/market/MarketUtils.test.ts +0 -25
- package/src/market/MarketUtils.ts +0 -467
- package/src/maths/AdaptiveCurveIrmLib.ts +0 -143
- package/src/maths/MathLib.ts +0 -208
- package/src/maths/MathUtils.ts +0 -31
- package/src/maths/SharesMath.ts +0 -40
- package/src/notifications.ts +0 -167
- package/src/position/Position.ts +0 -251
- package/src/signatures/index.ts +0 -18
- package/src/signatures/manager.ts +0 -50
- package/src/signatures/permit.ts +0 -126
- package/src/signatures/permit2.ts +0 -120
- package/src/signatures/types.ts +0 -18
- package/src/signatures/utils.ts +0 -83
- package/src/tests/mocks/markets.ts +0 -110
- package/src/token/ERC20Metadata.ts +0 -124
- package/src/token/Token.ts +0 -83
- package/src/token/TokenNamespace.ts +0 -76
- package/src/token/WrappedToken.ts +0 -142
- package/src/types.ts +0 -37
- package/src/user/User.ts +0 -32
- package/src/user/user.types.ts +0 -23
- package/src/vault/Vault.ts +0 -370
- package/src/vault/VaultAllocation.ts +0 -58
- package/src/vault/VaultConfig.ts +0 -55
- package/src/vault/VaultUtils.ts +0 -47
- /package/{src/chain/index.ts → lib/chain/index.d.ts} +0 -0
- /package/{src/ethers/index.ts → lib/ethers/index.d.ts} +0 -0
- /package/{src/helpers/format/index.ts → lib/helpers/format/index.d.ts} +0 -0
- /package/{src/helpers/index.ts → lib/helpers/index.d.ts} +0 -0
- /package/{src/holding/index.ts → lib/holding/index.d.ts} +0 -0
- /package/{src/market/index.ts → lib/market/index.d.ts} +0 -0
- /package/{src/maths/index.ts → lib/maths/index.d.ts} +0 -0
- /package/{src/position/index.ts → lib/position/index.d.ts} +0 -0
- /package/{src/token/index.ts → lib/token/index.d.ts} +0 -0
- /package/{src/user/index.ts → lib/user/index.d.ts} +0 -0
- /package/{src/vault/index.ts → lib/vault/index.d.ts} +0 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
type LocaleSymbols = {
|
|
2
|
+
decimalSymbol: string;
|
|
3
|
+
groupSymbol: string;
|
|
4
|
+
locale: string;
|
|
5
|
+
};
|
|
6
|
+
export type LocaleParts = LocaleSymbols & {
|
|
7
|
+
value: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* @returns the locale symbols for the given locale defaulting to en-US
|
|
11
|
+
*/
|
|
12
|
+
export declare const getLocaleSymbols: (locale: string) => LocaleSymbols;
|
|
13
|
+
/**
|
|
14
|
+
* @returns the effective browser locale
|
|
15
|
+
*/
|
|
16
|
+
export declare const getEffectiveLocale: () => string;
|
|
17
|
+
/**
|
|
18
|
+
* @returns the value as a string with the given locale symbols
|
|
19
|
+
* @param numStr the number as a string in the "from" locale (e.g. "1,2345.6" for en-US)
|
|
20
|
+
* @param from the locale the numStr is in (e.g. "en-US")
|
|
21
|
+
* @param to the locale to convert to (e.g. "fr-FR")
|
|
22
|
+
*/
|
|
23
|
+
export declare const convertNumStrToLocal: (numStr: string, from: string, to: string) => string;
|
|
24
|
+
/**
|
|
25
|
+
* @returns the value as a string in the effective browser locale
|
|
26
|
+
* @param numStr the number as a string in the effective browser locale (e.g. "1,2345.6" for en-US)
|
|
27
|
+
* @param to the locale to use (e.g. "fr-FR")
|
|
28
|
+
*/
|
|
29
|
+
export declare const convertNumStrFromEffectiveTo: (numStr: string, to: string) => string;
|
|
30
|
+
/**
|
|
31
|
+
* @returns the value as a string with the given locale symbols either from the given locale or the effective browser locale
|
|
32
|
+
* @param numStr the number as a string in english format (e.g. "1,2345.6")
|
|
33
|
+
* @param locale optional - the locale to use (e.g. "fr-FR")
|
|
34
|
+
*/
|
|
35
|
+
export declare const getEnUSNumberToLocalParts: (numStr: string, locale?: string) => LocaleParts;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getEnUSNumberToLocalParts = exports.convertNumStrFromEffectiveTo = exports.convertNumStrToLocal = exports.getEffectiveLocale = exports.getLocaleSymbols = void 0;
|
|
4
|
+
const _convertEnNumStrToLocale = (numStr, localSymbols) => {
|
|
5
|
+
return numStr
|
|
6
|
+
.replaceAll(",", "#TEMP#")
|
|
7
|
+
.replaceAll(".", localSymbols.decimalSymbol)
|
|
8
|
+
.replaceAll("#TEMP#", localSymbols.groupSymbol);
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* @returns the locale symbols for the given locale defaulting to en-US
|
|
12
|
+
*/
|
|
13
|
+
const getLocaleSymbols = (locale) => {
|
|
14
|
+
let formatter;
|
|
15
|
+
const formatterOptions = {
|
|
16
|
+
useGrouping: true,
|
|
17
|
+
maximumFractionDigits: 1,
|
|
18
|
+
minimumFractionDigits: 1,
|
|
19
|
+
};
|
|
20
|
+
try {
|
|
21
|
+
formatter = new Intl.NumberFormat(locale, formatterOptions);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
formatter = new Intl.NumberFormat("en-US", formatterOptions);
|
|
25
|
+
}
|
|
26
|
+
const parts = formatter.formatToParts(12345.6);
|
|
27
|
+
const decimalSymbol = parts.find((part) => part.type === "decimal").value;
|
|
28
|
+
const groupSymbol = parts.find((part) => part.type === "group").value;
|
|
29
|
+
return { decimalSymbol, groupSymbol, locale };
|
|
30
|
+
};
|
|
31
|
+
exports.getLocaleSymbols = getLocaleSymbols;
|
|
32
|
+
/**
|
|
33
|
+
* @returns the effective browser locale
|
|
34
|
+
*/
|
|
35
|
+
const getEffectiveLocale = () => {
|
|
36
|
+
if (typeof window !== "undefined") {
|
|
37
|
+
try {
|
|
38
|
+
const locale = navigator?.language || document?.documentElement?.lang || "en-US";
|
|
39
|
+
new Intl.NumberFormat(locale);
|
|
40
|
+
return locale;
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
return "en-US";
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return "en-US";
|
|
47
|
+
};
|
|
48
|
+
exports.getEffectiveLocale = getEffectiveLocale;
|
|
49
|
+
/**
|
|
50
|
+
* @returns the value as a string with the given locale symbols
|
|
51
|
+
* @param numStr the number as a string in the "from" locale (e.g. "1,2345.6" for en-US)
|
|
52
|
+
* @param from the locale the numStr is in (e.g. "en-US")
|
|
53
|
+
* @param to the locale to convert to (e.g. "fr-FR")
|
|
54
|
+
*/
|
|
55
|
+
const convertNumStrToLocal = (numStr, from, to) => {
|
|
56
|
+
const fromSymbols = (0, exports.getLocaleSymbols)(from);
|
|
57
|
+
const toSymbols = (0, exports.getLocaleSymbols)(to);
|
|
58
|
+
return numStr
|
|
59
|
+
.replaceAll(fromSymbols.groupSymbol, "#GROUP#")
|
|
60
|
+
.replaceAll(fromSymbols.decimalSymbol, "#DECIMAL#")
|
|
61
|
+
.replaceAll("#GROUP#", toSymbols.groupSymbol)
|
|
62
|
+
.replaceAll("#DECIMAL#", toSymbols.decimalSymbol);
|
|
63
|
+
};
|
|
64
|
+
exports.convertNumStrToLocal = convertNumStrToLocal;
|
|
65
|
+
/**
|
|
66
|
+
* @returns the value as a string in the effective browser locale
|
|
67
|
+
* @param numStr the number as a string in the effective browser locale (e.g. "1,2345.6" for en-US)
|
|
68
|
+
* @param to the locale to use (e.g. "fr-FR")
|
|
69
|
+
*/
|
|
70
|
+
const convertNumStrFromEffectiveTo = (numStr, to) => {
|
|
71
|
+
const from = (0, exports.getEffectiveLocale)();
|
|
72
|
+
return (0, exports.convertNumStrToLocal)(numStr, from, to);
|
|
73
|
+
};
|
|
74
|
+
exports.convertNumStrFromEffectiveTo = convertNumStrFromEffectiveTo;
|
|
75
|
+
/**
|
|
76
|
+
* @returns the value as a string with the given locale symbols either from the given locale or the effective browser locale
|
|
77
|
+
* @param numStr the number as a string in english format (e.g. "1,2345.6")
|
|
78
|
+
* @param locale optional - the locale to use (e.g. "fr-FR")
|
|
79
|
+
*/
|
|
80
|
+
const getEnUSNumberToLocalParts = (numStr, locale) => {
|
|
81
|
+
const _locale = locale || (0, exports.getEffectiveLocale)();
|
|
82
|
+
const localSymbols = (0, exports.getLocaleSymbols)(_locale);
|
|
83
|
+
const value = _convertEnNumStrToLocale(numStr, localSymbols);
|
|
84
|
+
return { ...localSymbols, value };
|
|
85
|
+
};
|
|
86
|
+
exports.getEnUSNumberToLocalParts = getEnUSNumberToLocalParts;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { BigNumberish } from "ethers";
|
|
2
|
+
import { Address } from "../types";
|
|
3
|
+
export declare const ERC20_ALLOWANCE_RECIPIENTS: readonly ["morpho", "permit2", "bundler"];
|
|
4
|
+
export declare const PERMIT2_ALLOWANCE_RECIPIENTS: readonly ["morpho", "bundler"];
|
|
5
|
+
export type Erc20AllowanceRecipient = (typeof ERC20_ALLOWANCE_RECIPIENTS)[number];
|
|
6
|
+
export type Permit2AllowanceRecipient = (typeof PERMIT2_ALLOWANCE_RECIPIENTS)[number];
|
|
7
|
+
export interface Permit2Allowance {
|
|
8
|
+
amount: bigint;
|
|
9
|
+
expiration: bigint;
|
|
10
|
+
nonce: bigint;
|
|
11
|
+
}
|
|
12
|
+
export interface InputHolding {
|
|
13
|
+
user: Address;
|
|
14
|
+
token: Address;
|
|
15
|
+
erc20Allowances: {
|
|
16
|
+
[key in Erc20AllowanceRecipient]: BigNumberish;
|
|
17
|
+
};
|
|
18
|
+
permit2Allowances: {
|
|
19
|
+
[key in Permit2AllowanceRecipient]: Permit2Allowance;
|
|
20
|
+
};
|
|
21
|
+
erc2612Nonce?: BigNumberish;
|
|
22
|
+
canTransfer?: boolean;
|
|
23
|
+
balance: BigNumberish;
|
|
24
|
+
}
|
|
25
|
+
export declare class Holding implements InputHolding {
|
|
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
|
+
* The balance of the user for this token.
|
|
36
|
+
*/
|
|
37
|
+
balance: bigint;
|
|
38
|
+
/**
|
|
39
|
+
* Whether the user is allowed to transfer this holding's balance.
|
|
40
|
+
*/
|
|
41
|
+
canTransfer?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* ERC20 allowance for this token from the user to the allowance recipient.
|
|
44
|
+
*/
|
|
45
|
+
readonly erc20Allowances: {
|
|
46
|
+
[key in Erc20AllowanceRecipient]: bigint;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Permit2 allowance for this token from the user to the allowance recipient.
|
|
50
|
+
*/
|
|
51
|
+
readonly permit2Allowances: {
|
|
52
|
+
[key in Permit2AllowanceRecipient]: Permit2Allowance;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* ERC-2612 Permit nonce of the user for this token.
|
|
56
|
+
* `undefined` if the token does not support ERC-2612.
|
|
57
|
+
*/
|
|
58
|
+
erc2612Nonce?: bigint;
|
|
59
|
+
constructor({ user, token, erc20Allowances, permit2Allowances, balance, erc2612Nonce, canTransfer, }: InputHolding);
|
|
60
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Holding = exports.PERMIT2_ALLOWANCE_RECIPIENTS = exports.ERC20_ALLOWANCE_RECIPIENTS = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
|
+
const addresses_1 = require("../addresses");
|
|
7
|
+
exports.ERC20_ALLOWANCE_RECIPIENTS = [
|
|
8
|
+
"morpho",
|
|
9
|
+
"permit2",
|
|
10
|
+
"bundler",
|
|
11
|
+
];
|
|
12
|
+
exports.PERMIT2_ALLOWANCE_RECIPIENTS = [
|
|
13
|
+
"morpho",
|
|
14
|
+
"bundler",
|
|
15
|
+
];
|
|
16
|
+
class Holding {
|
|
17
|
+
constructor({ user, token, erc20Allowances, permit2Allowances, balance, erc2612Nonce, canTransfer = true, }) {
|
|
18
|
+
this.user = user;
|
|
19
|
+
this.token = token;
|
|
20
|
+
this.balance = (0, ethers_1.toBigInt)(balance);
|
|
21
|
+
this.canTransfer = token === addresses_1.NATIVE_ADDRESS || canTransfer;
|
|
22
|
+
this.erc20Allowances = (0, morpho_ts_1.fromEntries)((0, morpho_ts_1.entries)(erc20Allowances).map(([address, allowance]) => [
|
|
23
|
+
address,
|
|
24
|
+
(0, ethers_1.toBigInt)(allowance),
|
|
25
|
+
]));
|
|
26
|
+
this.permit2Allowances = permit2Allowances;
|
|
27
|
+
if (erc2612Nonce != null)
|
|
28
|
+
this.erc2612Nonce = (0, ethers_1.toBigInt)(erc2612Nonce);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.Holding = Holding;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./Holding"), exports);
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
|
+
};
|
|
21
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
+
if (mod && mod.__esModule) return mod;
|
|
23
|
+
var result = {};
|
|
24
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
+
__setModuleDefault(result, mod);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.vault = exports.ethers = exports.helpers = exports.user = exports.signatures = exports.notifications = exports.maths = exports.types = exports.holding = exports.position = exports.token = exports.chain = exports.market = exports.errors = exports.constants = exports.evm = void 0;
|
|
30
|
+
__exportStar(require("./addresses"), exports);
|
|
31
|
+
__exportStar(require("./evm"), exports);
|
|
32
|
+
__exportStar(require("./constants"), exports);
|
|
33
|
+
__exportStar(require("./errors"), exports);
|
|
34
|
+
__exportStar(require("./market"), exports);
|
|
35
|
+
__exportStar(require("./chain"), exports);
|
|
36
|
+
__exportStar(require("./token"), exports);
|
|
37
|
+
__exportStar(require("./types"), exports);
|
|
38
|
+
__exportStar(require("./maths"), exports);
|
|
39
|
+
__exportStar(require("./notifications"), exports);
|
|
40
|
+
__exportStar(require("./signatures"), exports);
|
|
41
|
+
__exportStar(require("./user"), exports);
|
|
42
|
+
__exportStar(require("./holding"), exports);
|
|
43
|
+
__exportStar(require("./position"), exports);
|
|
44
|
+
__exportStar(require("./helpers"), exports);
|
|
45
|
+
__exportStar(require("./ethers"), exports);
|
|
46
|
+
__exportStar(require("./vault"), exports);
|
|
47
|
+
exports.evm = __importStar(require("./evm"));
|
|
48
|
+
exports.constants = __importStar(require("./constants"));
|
|
49
|
+
exports.errors = __importStar(require("./errors"));
|
|
50
|
+
exports.market = __importStar(require("./market"));
|
|
51
|
+
exports.chain = __importStar(require("./chain"));
|
|
52
|
+
exports.token = __importStar(require("./token"));
|
|
53
|
+
exports.position = __importStar(require("./position"));
|
|
54
|
+
exports.holding = __importStar(require("./holding"));
|
|
55
|
+
exports.types = __importStar(require("./types"));
|
|
56
|
+
exports.maths = __importStar(require("./maths"));
|
|
57
|
+
exports.notifications = __importStar(require("./notifications"));
|
|
58
|
+
exports.signatures = __importStar(require("./signatures"));
|
|
59
|
+
exports.user = __importStar(require("./user"));
|
|
60
|
+
exports.helpers = __importStar(require("./helpers"));
|
|
61
|
+
exports.ethers = __importStar(require("./ethers"));
|
|
62
|
+
exports.vault = __importStar(require("./vault"));
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { BigNumberish, Provider } from "ethers";
|
|
2
|
+
import { ViewOverrides } from "ethers-types/dist/common";
|
|
3
|
+
import { ChainId } from "../chain";
|
|
4
|
+
import { RoundingDirection } from "../maths";
|
|
5
|
+
import { MarketId } from "../types";
|
|
6
|
+
import { MarketConfig } from "./MarketConfig";
|
|
7
|
+
export declare enum CapacityLimitReason {
|
|
8
|
+
liquidity = "Liquidity",
|
|
9
|
+
balance = "Balance",
|
|
10
|
+
position = "Position",
|
|
11
|
+
collateral = "Collateral",
|
|
12
|
+
cap = "Cap"
|
|
13
|
+
}
|
|
14
|
+
export interface CapacityLimit {
|
|
15
|
+
value: bigint;
|
|
16
|
+
limiter: CapacityLimitReason;
|
|
17
|
+
}
|
|
18
|
+
export interface MaxPositionCapacities {
|
|
19
|
+
supply: CapacityLimit;
|
|
20
|
+
withdraw: CapacityLimit;
|
|
21
|
+
borrow: CapacityLimit;
|
|
22
|
+
repay: CapacityLimit;
|
|
23
|
+
supplyCollateral: CapacityLimit;
|
|
24
|
+
withdrawCollateral: CapacityLimit;
|
|
25
|
+
}
|
|
26
|
+
export interface InputMarket {
|
|
27
|
+
config: MarketConfig;
|
|
28
|
+
totalSupplyAssets: BigNumberish;
|
|
29
|
+
totalBorrowAssets: BigNumberish;
|
|
30
|
+
totalSupplyShares: BigNumberish;
|
|
31
|
+
totalBorrowShares: BigNumberish;
|
|
32
|
+
lastUpdate: BigNumberish;
|
|
33
|
+
fee: BigNumberish;
|
|
34
|
+
price: BigNumberish;
|
|
35
|
+
rateAtTarget?: BigNumberish;
|
|
36
|
+
}
|
|
37
|
+
export declare class Market implements InputMarket {
|
|
38
|
+
static fetchFromId(id: MarketId, runner: {
|
|
39
|
+
provider: Provider;
|
|
40
|
+
}, { chainId, overrides, }?: {
|
|
41
|
+
chainId?: ChainId;
|
|
42
|
+
overrides?: ViewOverrides;
|
|
43
|
+
}): Promise<Market>;
|
|
44
|
+
static fetchFromConfig(config: MarketConfig, runner: {
|
|
45
|
+
provider: Provider;
|
|
46
|
+
}, { chainId, overrides, }?: {
|
|
47
|
+
chainId?: ChainId;
|
|
48
|
+
overrides?: ViewOverrides;
|
|
49
|
+
}): Promise<Market>;
|
|
50
|
+
/**
|
|
51
|
+
* The market's config.
|
|
52
|
+
*/
|
|
53
|
+
readonly config: MarketConfig;
|
|
54
|
+
/**
|
|
55
|
+
* The amount of loan assets supplied in total on the market.
|
|
56
|
+
*/
|
|
57
|
+
totalSupplyAssets: bigint;
|
|
58
|
+
/**
|
|
59
|
+
* The amount of loan assets supplied in total on the market.
|
|
60
|
+
*/
|
|
61
|
+
totalBorrowAssets: bigint;
|
|
62
|
+
/**
|
|
63
|
+
* The amount of loan assets supplied in total on the market.
|
|
64
|
+
*/
|
|
65
|
+
totalSupplyShares: bigint;
|
|
66
|
+
/**
|
|
67
|
+
* The amount of loan assets supplied in total on the market.
|
|
68
|
+
*/
|
|
69
|
+
totalBorrowShares: bigint;
|
|
70
|
+
/**
|
|
71
|
+
* The block timestamp (in __seconds__) when the interest was last accrued.
|
|
72
|
+
*/
|
|
73
|
+
lastUpdate: bigint;
|
|
74
|
+
/**
|
|
75
|
+
* The fee percentage of the market, scaled by WAD.
|
|
76
|
+
*/
|
|
77
|
+
fee: bigint;
|
|
78
|
+
/**
|
|
79
|
+
* The price as returned by the market's oracle.
|
|
80
|
+
*/
|
|
81
|
+
price: bigint;
|
|
82
|
+
/**
|
|
83
|
+
* If the market uses the Adaptive Curve IRM, the rate at target utilization.
|
|
84
|
+
* Undefined otherwise.
|
|
85
|
+
*/
|
|
86
|
+
rateAtTarget?: bigint;
|
|
87
|
+
constructor({ config, totalSupplyAssets, totalBorrowAssets, totalSupplyShares, totalBorrowShares, lastUpdate, fee, price, rateAtTarget, }: InputMarket);
|
|
88
|
+
get id(): MarketId;
|
|
89
|
+
get isIdle(): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* @warning Cannot be used to calculate the liquidity available inside a callback,
|
|
92
|
+
* because the balance of Blue may be lower than the market's liquidity due to assets being transferred out prior to the callback.
|
|
93
|
+
*/
|
|
94
|
+
get liquidity(): bigint;
|
|
95
|
+
get utilization(): bigint;
|
|
96
|
+
get apyAtTarget(): bigint | undefined;
|
|
97
|
+
get supplyRate(): bigint;
|
|
98
|
+
get borrowRate(): bigint;
|
|
99
|
+
get supplyApy(): bigint;
|
|
100
|
+
get borrowApy(): bigint;
|
|
101
|
+
accrueInterest(timestamp: BigNumberish): Market;
|
|
102
|
+
getLiquidityToUtilization(utilization: BigNumberish): bigint;
|
|
103
|
+
getCollateralValue(collateral: BigNumberish): bigint;
|
|
104
|
+
getMaxBorrowAssets(collateral: BigNumberish): bigint;
|
|
105
|
+
getMaxBorrowableAssets(position: {
|
|
106
|
+
collateral: BigNumberish;
|
|
107
|
+
borrowShares: BigNumberish;
|
|
108
|
+
}): bigint;
|
|
109
|
+
getLiquidationSeizedAssets(repaidShares: BigNumberish): bigint;
|
|
110
|
+
getLiquidationRepaidShares(seizedAssets: BigNumberish): bigint;
|
|
111
|
+
getSeizableCollateral(position: {
|
|
112
|
+
collateral: BigNumberish;
|
|
113
|
+
borrowShares: BigNumberish;
|
|
114
|
+
}): bigint;
|
|
115
|
+
getWithdrawableCollateral(position: {
|
|
116
|
+
collateral: BigNumberish;
|
|
117
|
+
borrowShares: BigNumberish;
|
|
118
|
+
}): bigint;
|
|
119
|
+
isHealthy(position: {
|
|
120
|
+
collateral: BigNumberish;
|
|
121
|
+
borrowShares: BigNumberish;
|
|
122
|
+
}): boolean;
|
|
123
|
+
getLiquidationPrice(position: {
|
|
124
|
+
collateral: BigNumberish;
|
|
125
|
+
borrowShares: BigNumberish;
|
|
126
|
+
}): bigint | null;
|
|
127
|
+
getPriceVariationToLiquidation(position: {
|
|
128
|
+
collateral: BigNumberish;
|
|
129
|
+
borrowShares: BigNumberish;
|
|
130
|
+
}): bigint | null;
|
|
131
|
+
getHealthFactor(position: {
|
|
132
|
+
collateral: BigNumberish;
|
|
133
|
+
borrowShares: BigNumberish;
|
|
134
|
+
}): bigint | null;
|
|
135
|
+
getLtv(position: {
|
|
136
|
+
collateral: BigNumberish;
|
|
137
|
+
borrowShares: BigNumberish;
|
|
138
|
+
}): bigint | null;
|
|
139
|
+
getBorrowCapacityUsage(position: {
|
|
140
|
+
collateral: BigNumberish;
|
|
141
|
+
borrowShares: BigNumberish;
|
|
142
|
+
}): bigint | null;
|
|
143
|
+
toSupplyAssets(shares: BigNumberish, rounding?: RoundingDirection): bigint;
|
|
144
|
+
toSupplyShares(assets: BigNumberish, rounding?: RoundingDirection): bigint;
|
|
145
|
+
toBorrowAssets(shares: BigNumberish, rounding?: RoundingDirection): bigint;
|
|
146
|
+
toBorrowShares(assets: BigNumberish, rounding?: RoundingDirection): bigint;
|
|
147
|
+
getBorrowCapacityLimit(collateral: bigint): CapacityLimit;
|
|
148
|
+
getRepayCapacityLimit(borrowShares: bigint, loanTokenBalance: bigint): CapacityLimit;
|
|
149
|
+
getWithdrawCapacityLimit(supplyShares: bigint): CapacityLimit;
|
|
150
|
+
getWithdrawCollateralCapacityLimit(position: {
|
|
151
|
+
collateral: bigint;
|
|
152
|
+
borrowShares: bigint;
|
|
153
|
+
}): CapacityLimit;
|
|
154
|
+
getMaxCapacities(position: {
|
|
155
|
+
collateral: bigint;
|
|
156
|
+
supplyShares: bigint;
|
|
157
|
+
borrowShares: bigint;
|
|
158
|
+
}, loanTokenBalance: bigint, collateralTokenBalance: bigint): MaxPositionCapacities;
|
|
159
|
+
}
|