@morpho-org/blue-sdk 2.0.0-next.13 → 2.0.0-next.15
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/market/MarketUtils.js +8 -4
- package/lib/token/ConstantWrappedToken.js +1 -1
- package/lib/token/Token.d.ts +13 -13
- package/lib/token/Token.js +15 -17
- package/lib/vault/Vault.d.ts +8 -0
- package/package.json +2 -2
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { keccak_256 } from "@noble/hashes/sha3";
|
|
2
|
+
import { bytesToHex, hexToBytes } from "@noble/hashes/utils";
|
|
2
3
|
import { LIQUIDATION_CURSOR, MAX_LIQUIDATION_INCENTIVE_FACTOR, ORACLE_PRICE_SCALE, SECONDS_PER_YEAR, } from "../constants.js";
|
|
3
4
|
import { MathLib, SharesMath } from "../math/index.js";
|
|
4
5
|
/**
|
|
@@ -11,11 +12,14 @@ export var MarketUtils;
|
|
|
11
12
|
* @param market The market params.
|
|
12
13
|
*/
|
|
13
14
|
function getMarketId(market) {
|
|
14
|
-
return `0x${
|
|
15
|
-
market.collateralToken
|
|
15
|
+
return `0x${bytesToHex(keccak_256(hexToBytes(`${market.loanToken.substring(2).toLowerCase().padStart(64, "0") +
|
|
16
|
+
market.collateralToken
|
|
17
|
+
.substring(2)
|
|
18
|
+
.toLowerCase()
|
|
19
|
+
.padStart(64, "0") +
|
|
16
20
|
market.oracle.substring(2).padStart(64, "0") +
|
|
17
21
|
market.irm.substring(2).toLowerCase().padStart(64, "0") +
|
|
18
|
-
BigInt(market.lltv).toString(16).padStart(64, "0")}`)
|
|
22
|
+
BigInt(market.lltv).toString(16).padStart(64, "0")}`)))}`;
|
|
19
23
|
}
|
|
20
24
|
MarketUtils.getMarketId = getMarketId;
|
|
21
25
|
/**
|
|
@@ -2,7 +2,7 @@ import { MathLib } from "../math/index.js";
|
|
|
2
2
|
import { WrappedToken } from "./WrappedToken.js";
|
|
3
3
|
export class ConstantWrappedToken extends WrappedToken {
|
|
4
4
|
underlyingDecimals;
|
|
5
|
-
constructor(token, underlying, underlyingDecimals =
|
|
5
|
+
constructor(token, underlying, underlyingDecimals = 0) {
|
|
6
6
|
super(token, underlying);
|
|
7
7
|
this.underlyingDecimals = BigInt(underlyingDecimals);
|
|
8
8
|
}
|
package/lib/token/Token.d.ts
CHANGED
|
@@ -3,9 +3,10 @@ import { type RoundingDirection } from "../math/index.js";
|
|
|
3
3
|
import type { Address, BigIntish } from "../types.js";
|
|
4
4
|
export interface InputToken {
|
|
5
5
|
address: Address;
|
|
6
|
-
decimals: BigIntish;
|
|
7
|
-
symbol: string;
|
|
8
6
|
name?: string;
|
|
7
|
+
symbol?: string;
|
|
8
|
+
decimals?: BigIntish;
|
|
9
|
+
price?: BigIntish;
|
|
9
10
|
}
|
|
10
11
|
export declare class Token implements InputToken {
|
|
11
12
|
static native(chainId: ChainId): Token;
|
|
@@ -14,33 +15,32 @@ export declare class Token implements InputToken {
|
|
|
14
15
|
*/
|
|
15
16
|
readonly address: Address;
|
|
16
17
|
/**
|
|
17
|
-
* The token's
|
|
18
|
+
* The token's name.
|
|
18
19
|
*/
|
|
19
|
-
readonly
|
|
20
|
+
readonly name?: string;
|
|
20
21
|
/**
|
|
21
22
|
* The token's symbol.
|
|
22
23
|
*/
|
|
23
|
-
readonly symbol
|
|
24
|
+
readonly symbol?: string;
|
|
24
25
|
/**
|
|
25
|
-
* The
|
|
26
|
+
* The token's number of decimals. Defaults to 0.
|
|
26
27
|
*/
|
|
27
|
-
readonly
|
|
28
|
-
constructor({ address, decimals, symbol, name }: InputToken);
|
|
29
|
-
}
|
|
30
|
-
export declare class TokenWithPrice extends Token {
|
|
28
|
+
readonly decimals: number;
|
|
31
29
|
/**
|
|
32
30
|
* Price of the token in USD (scaled by WAD).
|
|
33
31
|
*/
|
|
34
32
|
price?: bigint;
|
|
35
|
-
constructor(
|
|
33
|
+
constructor({ address, name, symbol, decimals, price }: InputToken);
|
|
36
34
|
/**
|
|
37
35
|
* Quotes an amount in USD (scaled by WAD) in this token.
|
|
36
|
+
* Returns `undefined` iff the token's price is undefined.
|
|
38
37
|
* @param amount The amount of USD to quote.
|
|
39
38
|
*/
|
|
40
|
-
fromUsd(amount: bigint, rounding?: RoundingDirection): bigint |
|
|
39
|
+
fromUsd(amount: bigint, rounding?: RoundingDirection): bigint | undefined;
|
|
41
40
|
/**
|
|
42
41
|
* Quotes an amount of tokens in USD (scaled by WAD).
|
|
42
|
+
* Returns `undefined` iff the token's price is undefined.
|
|
43
43
|
* @param amount The amount of tokens to quote.
|
|
44
44
|
*/
|
|
45
|
-
toUsd(amount: bigint, rounding?: RoundingDirection): bigint |
|
|
45
|
+
toUsd(amount: bigint, rounding?: RoundingDirection): bigint | undefined;
|
|
46
46
|
}
|
package/lib/token/Token.js
CHANGED
|
@@ -11,49 +11,47 @@ export class Token {
|
|
|
11
11
|
*/
|
|
12
12
|
address;
|
|
13
13
|
/**
|
|
14
|
-
* The token's
|
|
14
|
+
* The token's name.
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
name;
|
|
17
17
|
/**
|
|
18
18
|
* The token's symbol.
|
|
19
19
|
*/
|
|
20
20
|
symbol;
|
|
21
21
|
/**
|
|
22
|
-
* The
|
|
22
|
+
* The token's number of decimals. Defaults to 0.
|
|
23
23
|
*/
|
|
24
|
-
|
|
25
|
-
constructor({ address, decimals, symbol, name }) {
|
|
26
|
-
this.address = address;
|
|
27
|
-
this.decimals = Number(decimals);
|
|
28
|
-
this.symbol = symbol;
|
|
29
|
-
this.name = name ?? symbol;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
export class TokenWithPrice extends Token {
|
|
24
|
+
decimals;
|
|
33
25
|
/**
|
|
34
26
|
* Price of the token in USD (scaled by WAD).
|
|
35
27
|
*/
|
|
36
28
|
price;
|
|
37
|
-
constructor(
|
|
38
|
-
|
|
39
|
-
this.
|
|
29
|
+
constructor({ address, name, symbol, decimals = 0, price }) {
|
|
30
|
+
this.address = address;
|
|
31
|
+
this.name = name;
|
|
32
|
+
this.symbol = symbol;
|
|
33
|
+
this.decimals = Number(decimals);
|
|
34
|
+
if (price != null)
|
|
35
|
+
this.price = BigInt(price);
|
|
40
36
|
}
|
|
41
37
|
/**
|
|
42
38
|
* Quotes an amount in USD (scaled by WAD) in this token.
|
|
39
|
+
* Returns `undefined` iff the token's price is undefined.
|
|
43
40
|
* @param amount The amount of USD to quote.
|
|
44
41
|
*/
|
|
45
42
|
fromUsd(amount, rounding = "Down") {
|
|
46
43
|
if (this.price == null)
|
|
47
|
-
return
|
|
44
|
+
return;
|
|
48
45
|
return MathLib.mulDiv(amount, 10n ** BigInt(this.decimals), this.price, rounding);
|
|
49
46
|
}
|
|
50
47
|
/**
|
|
51
48
|
* Quotes an amount of tokens in USD (scaled by WAD).
|
|
49
|
+
* Returns `undefined` iff the token's price is undefined.
|
|
52
50
|
* @param amount The amount of tokens to quote.
|
|
53
51
|
*/
|
|
54
52
|
toUsd(amount, rounding = "Down") {
|
|
55
53
|
if (this.price == null)
|
|
56
|
-
return
|
|
54
|
+
return;
|
|
57
55
|
return MathLib.mulDiv(amount, this.price, 10n ** BigInt(this.decimals), rounding);
|
|
58
56
|
}
|
|
59
57
|
}
|
package/lib/vault/Vault.d.ts
CHANGED
|
@@ -41,6 +41,14 @@ export interface InputVault extends InputVaultConfig {
|
|
|
41
41
|
publicAllocatorConfig?: VaultPublicAllocatorConfig;
|
|
42
42
|
}
|
|
43
43
|
export declare class Vault extends VaultToken implements InputVault {
|
|
44
|
+
/**
|
|
45
|
+
* The vault's share token's name.
|
|
46
|
+
*/
|
|
47
|
+
readonly name: string;
|
|
48
|
+
/**
|
|
49
|
+
* The vault's share token's symbol.
|
|
50
|
+
*/
|
|
51
|
+
readonly symbol: string;
|
|
44
52
|
/**
|
|
45
53
|
* The MetaMorpho vault's owner address.
|
|
46
54
|
*/
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@morpho-org/blue-sdk",
|
|
3
3
|
"description": "Framework-agnostic package that defines Morpho-related entity classes (such as `Market`, `Token`, `Vault`).",
|
|
4
|
-
"version": "2.0.0-next.
|
|
4
|
+
"version": "2.0.0-next.15",
|
|
5
5
|
"author": "Morpho Association <contact@morpho.org>",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Rubilmax <rmilon@gmail.com>"
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"lib"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"
|
|
22
|
+
"@noble/hashes": "^1.5.0"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"@morpho-org/morpho-ts": "^2.0.0-next.7"
|