@morpho-org/blue-sdk 1.0.1 → 1.0.2
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/package.json +10 -6
- package/src/addresses.ts +261 -0
- package/src/chain/chain.constants.ts +235 -0
- package/src/chain/chain.test.ts +51 -0
- package/src/chain/chain.types.ts +42 -0
- package/src/chain/chain.utils.ts +44 -0
- package/src/constants.ts +18 -0
- package/src/errors.ts +75 -0
- package/src/ethers/ethers.test.ts +17 -0
- package/src/ethers/safeGetAddress.ts +4 -0
- package/src/ethers/safeParseUnits.ts +29 -0
- package/src/evm.ts +172 -0
- package/src/helpers/format/format.test.ts +340 -0
- package/src/helpers/format/format.ts +416 -0
- package/src/helpers/getChecksumedAddress.ts +15 -0
- package/{lib/helpers/isZeroAddressOrUnset.d.ts → src/helpers/isZeroAddressOrUnset.ts} +7 -1
- package/src/helpers/locale.ts +108 -0
- package/src/holding/Holding.ts +109 -0
- package/src/market/Market.ts +479 -0
- package/src/market/MarketConfig.ts +108 -0
- package/src/market/MarketUtils.test.ts +25 -0
- package/src/market/MarketUtils.ts +467 -0
- package/src/maths/AdaptiveCurveIrmLib.ts +143 -0
- package/src/maths/MathLib.ts +208 -0
- package/src/maths/MathUtils.ts +31 -0
- package/src/maths/SharesMath.ts +40 -0
- package/src/notifications.ts +167 -0
- package/src/position/Position.ts +251 -0
- package/src/signatures/index.ts +18 -0
- package/src/signatures/manager.ts +50 -0
- package/src/signatures/permit.ts +126 -0
- package/src/signatures/permit2.ts +120 -0
- package/src/signatures/types.ts +18 -0
- package/src/signatures/utils.ts +83 -0
- package/src/tests/mocks/markets.ts +110 -0
- package/src/token/ERC20Metadata.ts +124 -0
- package/src/token/Token.ts +83 -0
- package/src/token/TokenNamespace.ts +76 -0
- package/src/token/WrappedToken.ts +142 -0
- package/src/types.ts +37 -0
- package/src/user/User.ts +32 -0
- package/src/user/user.types.ts +23 -0
- package/src/vault/Vault.ts +370 -0
- package/src/vault/VaultAllocation.ts +58 -0
- package/src/vault/VaultConfig.ts +55 -0
- package/src/vault/VaultUtils.ts +47 -0
- package/lib/addresses.d.ts +0 -168
- package/lib/addresses.js +0 -169
- package/lib/chain/chain.constants.d.ts +0 -3
- package/lib/chain/chain.constants.js +0 -232
- package/lib/chain/chain.types.d.ts +0 -20
- package/lib/chain/chain.types.js +0 -30
- package/lib/chain/chain.utils.d.ts +0 -14
- package/lib/chain/chain.utils.js +0 -30
- package/lib/chain/index.js +0 -18
- package/lib/constants.d.ts +0 -8
- package/lib/constants.js +0 -13
- package/lib/errors.d.ts +0 -37
- package/lib/errors.js +0 -71
- package/lib/ethers/index.js +0 -18
- package/lib/ethers/safeGetAddress.d.ts +0 -1
- package/lib/ethers/safeGetAddress.js +0 -6
- package/lib/ethers/safeParseUnits.d.ts +0 -2
- package/lib/ethers/safeParseUnits.js +0 -25
- package/lib/evm.d.ts +0 -36
- package/lib/evm.js +0 -113
- package/lib/helpers/format/format.d.ts +0 -98
- package/lib/helpers/format/format.js +0 -301
- package/lib/helpers/format/index.js +0 -17
- package/lib/helpers/getChecksumedAddress.d.ts +0 -7
- package/lib/helpers/getChecksumedAddress.js +0 -17
- package/lib/helpers/index.js +0 -20
- package/lib/helpers/isZeroAddressOrUnset.js +0 -14
- package/lib/helpers/locale.d.ts +0 -36
- package/lib/helpers/locale.js +0 -86
- package/lib/holding/Holding.d.ts +0 -60
- package/lib/holding/Holding.js +0 -31
- package/lib/holding/index.js +0 -17
- package/lib/index.d.ts +0 -33
- package/lib/index.js +0 -62
- package/lib/market/Market.d.ts +0 -159
- package/lib/market/Market.js +0 -240
- package/lib/market/MarketConfig.d.ts +0 -44
- package/lib/market/MarketConfig.js +0 -56
- package/lib/market/MarketUtils.d.ts +0 -165
- package/lib/market/MarketUtils.js +0 -182
- package/lib/market/index.js +0 -19
- package/lib/maths/AdaptiveCurveIrmLib.d.ts +0 -37
- package/lib/maths/AdaptiveCurveIrmLib.js +0 -116
- package/lib/maths/MathLib.d.ts +0 -94
- package/lib/maths/MathLib.js +0 -153
- package/lib/maths/MathUtils.d.ts +0 -15
- package/lib/maths/MathUtils.js +0 -33
- package/lib/maths/SharesMath.d.ts +0 -12
- package/lib/maths/SharesMath.js +0 -22
- package/lib/maths/index.js +0 -20
- package/lib/notifications.d.ts +0 -98
- package/lib/notifications.js +0 -52
- package/lib/position/Position.d.ts +0 -118
- package/lib/position/Position.js +0 -145
- package/lib/position/index.js +0 -17
- package/lib/signatures/index.d.ts +0 -12
- package/lib/signatures/index.js +0 -39
- package/lib/signatures/manager.d.ts +0 -10
- package/lib/signatures/manager.js +0 -37
- package/lib/signatures/permit.d.ts +0 -21
- package/lib/signatures/permit.js +0 -101
- package/lib/signatures/permit2.d.ts +0 -20
- package/lib/signatures/permit2.js +0 -91
- package/lib/signatures/types.d.ts +0 -13
- package/lib/signatures/types.js +0 -2
- package/lib/signatures/utils.d.ts +0 -6
- package/lib/signatures/utils.js +0 -44
- package/lib/tests/mocks/markets.d.ts +0 -17
- package/lib/tests/mocks/markets.js +0 -108
- package/lib/token/ERC20Metadata.d.ts +0 -249
- package/lib/token/ERC20Metadata.js +0 -81
- package/lib/token/Token.d.ts +0 -45
- package/lib/token/Token.js +0 -39
- package/lib/token/TokenNamespace.d.ts +0 -18
- package/lib/token/TokenNamespace.js +0 -55
- package/lib/token/WrappedToken.d.ts +0 -42
- package/lib/token/WrappedToken.js +0 -87
- package/lib/token/index.js +0 -18
- package/lib/types.d.ts +0 -29
- package/lib/types.js +0 -23
- package/lib/user/User.d.ts +0 -20
- package/lib/user/User.js +0 -11
- package/lib/user/index.js +0 -18
- package/lib/user/user.types.d.ts +0 -18
- package/lib/user/user.types.js +0 -2
- package/lib/vault/Vault.d.ts +0 -167
- package/lib/vault/Vault.js +0 -156
- package/lib/vault/VaultAllocation.d.ts +0 -38
- package/lib/vault/VaultAllocation.js +0 -18
- package/lib/vault/VaultConfig.d.ts +0 -23
- package/lib/vault/VaultConfig.js +0 -26
- package/lib/vault/VaultUtils.d.ts +0 -17
- package/lib/vault/VaultUtils.js +0 -17
- package/lib/vault/index.js +0 -20
- /package/{lib/chain/index.d.ts → src/chain/index.ts} +0 -0
- /package/{lib/ethers/index.d.ts → src/ethers/index.ts} +0 -0
- /package/{lib/helpers/format/index.d.ts → src/helpers/format/index.ts} +0 -0
- /package/{lib/helpers/index.d.ts → src/helpers/index.ts} +0 -0
- /package/{lib/holding/index.d.ts → src/holding/index.ts} +0 -0
- /package/{lib/market/index.d.ts → src/market/index.ts} +0 -0
- /package/{lib/maths/index.d.ts → src/maths/index.ts} +0 -0
- /package/{lib/position/index.d.ts → src/position/index.ts} +0 -0
- /package/{lib/token/index.d.ts → src/token/index.ts} +0 -0
- /package/{lib/user/index.d.ts → src/user/index.ts} +0 -0
- /package/{lib/vault/index.d.ts → src/vault/index.ts} +0 -0
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { RoundingDirection } from "../maths";
|
|
2
|
-
import { Address } from "../types";
|
|
3
|
-
import { Vault } from "../vault";
|
|
4
|
-
import { InputToken, Token } from "./Token";
|
|
5
|
-
export declare abstract class WrappedToken extends Token {
|
|
6
|
-
readonly underlying: Address;
|
|
7
|
-
protected abstract _wrap(amount: bigint, rounding: RoundingDirection): bigint;
|
|
8
|
-
protected abstract _unwrap(amount: bigint, rounding: RoundingDirection): bigint;
|
|
9
|
-
protected _noSlippage: boolean;
|
|
10
|
-
constructor(token: InputToken, underlying: Address);
|
|
11
|
-
/** The expected amount when wrapping `unwrappedAmount` */
|
|
12
|
-
toWrappedExactAmountIn(unwrappedAmount: bigint, slippage?: bigint, rounding?: RoundingDirection): bigint;
|
|
13
|
-
/** The amount of unwrappedTokens that should be wrapped to receive `wrappedAmount` */
|
|
14
|
-
toWrappedExactAmountOut(wrappedAmount: bigint, slippage?: bigint, rounding?: RoundingDirection): bigint;
|
|
15
|
-
/** The expected amount when unwrapping `wrappedAmount` */
|
|
16
|
-
toUnwrappedExactAmountIn(wrappedAmount: bigint, slippage?: bigint, rounding?: RoundingDirection): bigint;
|
|
17
|
-
/** The amount of wrappedTokens that should be unwrapped to receive `unwrappedAmount` */
|
|
18
|
-
toUnwrappedExactAmountOut(unwrappedAmount: bigint, slippage?: bigint, rounding?: RoundingDirection): bigint;
|
|
19
|
-
}
|
|
20
|
-
export declare class ConstantWrappedToken extends WrappedToken {
|
|
21
|
-
readonly underlying: Address;
|
|
22
|
-
private readonly _underlyingDecimals;
|
|
23
|
-
protected _noSlippage: boolean;
|
|
24
|
-
constructor(token: InputToken, underlying: Address, _underlyingDecimals?: number);
|
|
25
|
-
protected _wrap(amount: bigint): bigint;
|
|
26
|
-
protected _unwrap(amount: bigint): bigint;
|
|
27
|
-
}
|
|
28
|
-
export declare class ExchangeRateWrappedToken extends WrappedToken {
|
|
29
|
-
readonly underlying: Address;
|
|
30
|
-
wrappedTokenExchangeRate: bigint;
|
|
31
|
-
protected _wrap(amount: bigint, rounding: RoundingDirection): bigint;
|
|
32
|
-
protected _unwrap(amount: bigint, rounding: RoundingDirection): bigint;
|
|
33
|
-
constructor(token: InputToken, underlying: Address, wrappedTokenExchangeRate: bigint);
|
|
34
|
-
}
|
|
35
|
-
export declare class VaultToken extends WrappedToken {
|
|
36
|
-
readonly underlying: Address;
|
|
37
|
-
protected _wrap(amount: bigint, rounding: RoundingDirection): bigint;
|
|
38
|
-
protected _unwrap(amount: bigint, rounding: RoundingDirection): bigint;
|
|
39
|
-
totalAssets: bigint;
|
|
40
|
-
totalSupply: bigint;
|
|
41
|
-
constructor(token: InputToken, underlying: Address, { totalAssets, totalSupply }: Pick<Vault, "totalAssets" | "totalSupply">);
|
|
42
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.VaultToken = exports.ExchangeRateWrappedToken = exports.ConstantWrappedToken = exports.WrappedToken = void 0;
|
|
4
|
-
const ethers_1 = require("ethers");
|
|
5
|
-
const ethers_2 = require("../ethers");
|
|
6
|
-
const maths_1 = require("../maths");
|
|
7
|
-
const Token_1 = require("./Token");
|
|
8
|
-
class WrappedToken extends Token_1.Token {
|
|
9
|
-
constructor(token, underlying) {
|
|
10
|
-
super(token);
|
|
11
|
-
this.underlying = underlying;
|
|
12
|
-
this._noSlippage = false;
|
|
13
|
-
}
|
|
14
|
-
/** The expected amount when wrapping `unwrappedAmount` */
|
|
15
|
-
toWrappedExactAmountIn(unwrappedAmount, slippage = 0n, rounding = "Down") {
|
|
16
|
-
const wrappedAmount = this._wrap(unwrappedAmount, rounding);
|
|
17
|
-
if (this._noSlippage)
|
|
18
|
-
return wrappedAmount;
|
|
19
|
-
return maths_1.MathLib.wMul(wrappedAmount, maths_1.MathLib.WAD - slippage, "Down");
|
|
20
|
-
}
|
|
21
|
-
/** The amount of unwrappedTokens that should be wrapped to receive `wrappedAmount` */
|
|
22
|
-
toWrappedExactAmountOut(wrappedAmount, slippage = 0n, rounding = "Up") {
|
|
23
|
-
const wAmountTarget = this._noSlippage
|
|
24
|
-
? wrappedAmount
|
|
25
|
-
: maths_1.MathLib.wDiv(wrappedAmount, maths_1.MathLib.WAD - slippage, rounding);
|
|
26
|
-
return this._unwrap(wAmountTarget, rounding);
|
|
27
|
-
}
|
|
28
|
-
/** The expected amount when unwrapping `wrappedAmount` */
|
|
29
|
-
toUnwrappedExactAmountIn(wrappedAmount, slippage = 0n, rounding = "Down") {
|
|
30
|
-
const unwrappedAmount = this._unwrap(wrappedAmount, rounding);
|
|
31
|
-
if (this._noSlippage)
|
|
32
|
-
return unwrappedAmount;
|
|
33
|
-
return maths_1.MathLib.wMul(unwrappedAmount, maths_1.MathLib.WAD - slippage, "Up");
|
|
34
|
-
}
|
|
35
|
-
/** The amount of wrappedTokens that should be unwrapped to receive `unwrappedAmount` */
|
|
36
|
-
toUnwrappedExactAmountOut(unwrappedAmount, slippage = 0n, rounding = "Up") {
|
|
37
|
-
const unwrappedAmountToTarget = this._noSlippage
|
|
38
|
-
? unwrappedAmount
|
|
39
|
-
: maths_1.MathLib.wDiv(unwrappedAmount, maths_1.MathLib.WAD - slippage, rounding);
|
|
40
|
-
return this._wrap(unwrappedAmountToTarget, rounding);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
exports.WrappedToken = WrappedToken;
|
|
44
|
-
class ConstantWrappedToken extends WrappedToken {
|
|
45
|
-
constructor(token, underlying, _underlyingDecimals = 18) {
|
|
46
|
-
super(token, underlying);
|
|
47
|
-
this.underlying = underlying;
|
|
48
|
-
this._underlyingDecimals = _underlyingDecimals;
|
|
49
|
-
this._noSlippage = true;
|
|
50
|
-
}
|
|
51
|
-
_wrap(amount) {
|
|
52
|
-
return (0, ethers_2.safeParseUnits)((0, ethers_1.formatUnits)(amount, this._underlyingDecimals), this.decimals);
|
|
53
|
-
}
|
|
54
|
-
_unwrap(amount) {
|
|
55
|
-
return (0, ethers_2.safeParseUnits)((0, ethers_1.formatUnits)(amount, this.decimals), this._underlyingDecimals);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
exports.ConstantWrappedToken = ConstantWrappedToken;
|
|
59
|
-
class ExchangeRateWrappedToken extends WrappedToken {
|
|
60
|
-
_wrap(amount, rounding) {
|
|
61
|
-
return maths_1.MathLib.wDiv(amount, this.wrappedTokenExchangeRate, rounding);
|
|
62
|
-
}
|
|
63
|
-
_unwrap(amount, rounding) {
|
|
64
|
-
return maths_1.MathLib.wMul(amount, this.wrappedTokenExchangeRate, rounding);
|
|
65
|
-
}
|
|
66
|
-
constructor(token, underlying, wrappedTokenExchangeRate) {
|
|
67
|
-
super(token, underlying);
|
|
68
|
-
this.underlying = underlying;
|
|
69
|
-
this.wrappedTokenExchangeRate = wrappedTokenExchangeRate;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
exports.ExchangeRateWrappedToken = ExchangeRateWrappedToken;
|
|
73
|
-
class VaultToken extends WrappedToken {
|
|
74
|
-
_wrap(amount, rounding) {
|
|
75
|
-
return maths_1.SharesMath.toShares(amount, this.totalAssets, this.totalSupply, rounding);
|
|
76
|
-
}
|
|
77
|
-
_unwrap(amount, rounding) {
|
|
78
|
-
return maths_1.SharesMath.toAssets(amount, this.totalAssets, this.totalSupply, rounding);
|
|
79
|
-
}
|
|
80
|
-
constructor(token, underlying, { totalAssets, totalSupply }) {
|
|
81
|
-
super(token, underlying);
|
|
82
|
-
this.underlying = underlying;
|
|
83
|
-
this.totalAssets = totalAssets;
|
|
84
|
-
this.totalSupply = totalSupply;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
exports.VaultToken = VaultToken;
|
package/lib/token/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
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("./TokenNamespace"), exports);
|
|
18
|
-
__exportStar(require("./WrappedToken"), exports);
|
package/lib/types.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
export type Hex64 = string & {
|
|
2
|
-
__LENGTH__: 64;
|
|
3
|
-
};
|
|
4
|
-
/**
|
|
5
|
-
* The address of a Contract, or an EOA
|
|
6
|
-
*/
|
|
7
|
-
export type Address = string;
|
|
8
|
-
/**
|
|
9
|
-
* The id of a market used on the Blue contract
|
|
10
|
-
*/
|
|
11
|
-
export type MarketId = `0x${Hex64}` & {
|
|
12
|
-
__TYPE__: "marketId";
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* The possible transaction type on the Blue contract
|
|
16
|
-
*/
|
|
17
|
-
export declare enum TransactionType {
|
|
18
|
-
Supply = "Supply",
|
|
19
|
-
SupplyCollateral = "Supply Collateral",
|
|
20
|
-
Withdraw = "Withdraw",
|
|
21
|
-
WithdrawCollateral = "Withdraw Collateral",
|
|
22
|
-
Borrow = "Borrow",
|
|
23
|
-
Repay = "Repay"
|
|
24
|
-
}
|
|
25
|
-
export type Loadable<T> = T | undefined;
|
|
26
|
-
export type Failable<T> = T | null;
|
|
27
|
-
export type Fetchable<T> = Failable<Loadable<T>>;
|
|
28
|
-
export declare function isFetched<T>(v: Fetchable<T>): v is T;
|
|
29
|
-
export declare const isMarketId: (value: any) => value is MarketId;
|
package/lib/types.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isMarketId = exports.isFetched = exports.TransactionType = void 0;
|
|
4
|
-
const ethers_1 = require("ethers");
|
|
5
|
-
/**
|
|
6
|
-
* The possible transaction type on the Blue contract
|
|
7
|
-
*/
|
|
8
|
-
var TransactionType;
|
|
9
|
-
(function (TransactionType) {
|
|
10
|
-
TransactionType["Supply"] = "Supply";
|
|
11
|
-
TransactionType["SupplyCollateral"] = "Supply Collateral";
|
|
12
|
-
TransactionType["Withdraw"] = "Withdraw";
|
|
13
|
-
TransactionType["WithdrawCollateral"] = "Withdraw Collateral";
|
|
14
|
-
TransactionType["Borrow"] = "Borrow";
|
|
15
|
-
TransactionType["Repay"] = "Repay";
|
|
16
|
-
})(TransactionType || (exports.TransactionType = TransactionType = {}));
|
|
17
|
-
// TODO: replace with isDefined
|
|
18
|
-
function isFetched(v) {
|
|
19
|
-
return v !== undefined && v !== null;
|
|
20
|
-
}
|
|
21
|
-
exports.isFetched = isFetched;
|
|
22
|
-
const isMarketId = (value) => (0, ethers_1.isHexString)(value, 32);
|
|
23
|
-
exports.isMarketId = isMarketId;
|
package/lib/user/User.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Address } from "../types";
|
|
2
|
-
export declare class User {
|
|
3
|
-
/**
|
|
4
|
-
* The user's address.
|
|
5
|
-
*/
|
|
6
|
-
readonly address: Address;
|
|
7
|
-
/**
|
|
8
|
-
* Whether the bundler is authorized to manage the user's position on Morpho Blue.
|
|
9
|
-
*/
|
|
10
|
-
isBundlerAuthorized: boolean;
|
|
11
|
-
/**
|
|
12
|
-
* The user's nonce on Morpho Blue.
|
|
13
|
-
*/
|
|
14
|
-
morphoNonce: bigint;
|
|
15
|
-
constructor({ address, isBundlerAuthorized, morphoNonce, }: {
|
|
16
|
-
address: Address;
|
|
17
|
-
isBundlerAuthorized: boolean;
|
|
18
|
-
morphoNonce: bigint;
|
|
19
|
-
});
|
|
20
|
-
}
|
package/lib/user/User.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.User = void 0;
|
|
4
|
-
class User {
|
|
5
|
-
constructor({ address, isBundlerAuthorized, morphoNonce, }) {
|
|
6
|
-
this.address = address;
|
|
7
|
-
this.isBundlerAuthorized = isBundlerAuthorized;
|
|
8
|
-
this.morphoNonce = morphoNonce;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
exports.User = User;
|
package/lib/user/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
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("./user.types"), exports);
|
|
18
|
-
__exportStar(require("./User"), exports);
|
package/lib/user/user.types.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Token } from "../token";
|
|
2
|
-
export interface MaxBalanceDecomposition {
|
|
3
|
-
maxBalance: bigint;
|
|
4
|
-
decomposition: {
|
|
5
|
-
base: BalanceDecompositionFragment;
|
|
6
|
-
} & {
|
|
7
|
-
[T in Exclude<PeripheralTokenType, "base">]?: BalanceDecompositionFragment;
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
export type PeripheralTokenType = "base" | "wrapped" | "erc4626" | "wrapped-erc4626";
|
|
11
|
-
export interface PeripheralToken {
|
|
12
|
-
token: Token;
|
|
13
|
-
type: PeripheralTokenType;
|
|
14
|
-
}
|
|
15
|
-
export interface BalanceDecompositionFragment extends PeripheralToken {
|
|
16
|
-
underlyingValue: bigint;
|
|
17
|
-
value: bigint;
|
|
18
|
-
}
|
package/lib/user/user.types.js
DELETED
package/lib/vault/Vault.d.ts
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import { BigNumberish } from "ethers";
|
|
2
|
-
import { CapacityLimit } from "../market";
|
|
3
|
-
import { RoundingDirection } from "../maths";
|
|
4
|
-
import { Token } from "../token";
|
|
5
|
-
import { Address, MarketId } from "../types";
|
|
6
|
-
import { InputVaultAllocation, VaultAllocation } from "./VaultAllocation";
|
|
7
|
-
import { VaultConfig } from "./VaultConfig";
|
|
8
|
-
export interface Pending<T> {
|
|
9
|
-
value: T;
|
|
10
|
-
validAt: bigint;
|
|
11
|
-
}
|
|
12
|
-
export interface VaultPublicAllocatorConfig {
|
|
13
|
-
/**
|
|
14
|
-
* The PublicAllocator's admin address.
|
|
15
|
-
*/
|
|
16
|
-
admin: Address;
|
|
17
|
-
/**
|
|
18
|
-
* The PublicAllocator's reallocation fee (in native token).
|
|
19
|
-
*/
|
|
20
|
-
fee: bigint;
|
|
21
|
-
/**
|
|
22
|
-
* The PublicAllocator's reallocation fee accrued so far (in native token).
|
|
23
|
-
*/
|
|
24
|
-
accruedFee: bigint;
|
|
25
|
-
}
|
|
26
|
-
export interface InputVault {
|
|
27
|
-
config: VaultConfig;
|
|
28
|
-
curator: Address;
|
|
29
|
-
owner: Address;
|
|
30
|
-
guardian: Address;
|
|
31
|
-
fee: BigNumberish;
|
|
32
|
-
feeRecipient: Address;
|
|
33
|
-
skimRecipient: Address;
|
|
34
|
-
pendingTimelock: Pending<BigNumberish>;
|
|
35
|
-
pendingGuardian: Pending<Address>;
|
|
36
|
-
pendingOwner: Address;
|
|
37
|
-
timelock: BigNumberish;
|
|
38
|
-
supplyQueue: MarketId[];
|
|
39
|
-
withdrawQueue: MarketId[];
|
|
40
|
-
totalSupply: BigNumberish;
|
|
41
|
-
totalAssets: BigNumberish;
|
|
42
|
-
lastTotalAssets: BigNumberish;
|
|
43
|
-
publicAllocatorConfig?: VaultPublicAllocatorConfig;
|
|
44
|
-
}
|
|
45
|
-
export declare class Vault implements InputVault {
|
|
46
|
-
/**
|
|
47
|
-
* The MetaMorpho vault's config.
|
|
48
|
-
*/
|
|
49
|
-
readonly config: VaultConfig;
|
|
50
|
-
/**
|
|
51
|
-
* The MetaMorpho vault's owner address.
|
|
52
|
-
*/
|
|
53
|
-
owner: Address;
|
|
54
|
-
/**
|
|
55
|
-
* The MetaMorpho vault's curator address.
|
|
56
|
-
*/
|
|
57
|
-
curator: Address;
|
|
58
|
-
/**
|
|
59
|
-
* The MetaMorpho vault's guardian address.
|
|
60
|
-
*/
|
|
61
|
-
guardian: Address;
|
|
62
|
-
/**
|
|
63
|
-
* The MetaMorpho vault's skim recipient address (mostly used to skim reward tokens claimed to the vault).
|
|
64
|
-
*/
|
|
65
|
-
skimRecipient: Address;
|
|
66
|
-
/**
|
|
67
|
-
* The MetaMorpho vault's fee recipient address.
|
|
68
|
-
*/
|
|
69
|
-
feeRecipient: Address;
|
|
70
|
-
/**
|
|
71
|
-
* The MetaMorpho vault's timelock (in seconds).
|
|
72
|
-
*/
|
|
73
|
-
timelock: bigint;
|
|
74
|
-
/**
|
|
75
|
-
* The MetaMorpho vault's fee.
|
|
76
|
-
*/
|
|
77
|
-
fee: bigint;
|
|
78
|
-
/**
|
|
79
|
-
* The MetaMorpho vault's pending owner address and activation timestamp.
|
|
80
|
-
*/
|
|
81
|
-
pendingOwner: Address;
|
|
82
|
-
/**
|
|
83
|
-
* The MetaMorpho vault's pending guardian address and activation timestamp.
|
|
84
|
-
*/
|
|
85
|
-
pendingGuardian: Pending<Address>;
|
|
86
|
-
/**
|
|
87
|
-
* The MetaMorpho vault's pending timelock (in seconds) and activation timestamp.
|
|
88
|
-
*/
|
|
89
|
-
pendingTimelock: Pending<bigint>;
|
|
90
|
-
/**
|
|
91
|
-
* The MetaMorpho vault's ordered supply queue.
|
|
92
|
-
*/
|
|
93
|
-
supplyQueue: MarketId[];
|
|
94
|
-
/**
|
|
95
|
-
* The MetaMorpho vault's ordered withdraw queue.
|
|
96
|
-
*/
|
|
97
|
-
withdrawQueue: MarketId[];
|
|
98
|
-
/**
|
|
99
|
-
* The ERC4626 vault's total supply of shares.
|
|
100
|
-
*/
|
|
101
|
-
totalSupply: bigint;
|
|
102
|
-
/**
|
|
103
|
-
* The ERC4626 vault's total assets.
|
|
104
|
-
*/
|
|
105
|
-
totalAssets: bigint;
|
|
106
|
-
/**
|
|
107
|
-
* The MetaMorpho vault's last total assets used to calculate performance fees.
|
|
108
|
-
*/
|
|
109
|
-
lastTotalAssets: bigint;
|
|
110
|
-
/**
|
|
111
|
-
* The MetaMorpho vault's public allocator configuration.
|
|
112
|
-
*/
|
|
113
|
-
publicAllocatorConfig?: VaultPublicAllocatorConfig;
|
|
114
|
-
constructor({ config, curator, owner, guardian, publicAllocatorConfig, fee, feeRecipient, skimRecipient, pendingTimelock, pendingGuardian, pendingOwner, timelock, supplyQueue, withdrawQueue, totalSupply, totalAssets, lastTotalAssets, }: InputVault);
|
|
115
|
-
get address(): string;
|
|
116
|
-
get asset(): string;
|
|
117
|
-
/**
|
|
118
|
-
* The amount of interest in assets accrued since the last interaction with the vault.
|
|
119
|
-
*/
|
|
120
|
-
get totalInterest(): bigint;
|
|
121
|
-
toAssets(shares: BigNumberish, rounding?: RoundingDirection): bigint;
|
|
122
|
-
toShares(assets: BigNumberish, rounding?: RoundingDirection): bigint;
|
|
123
|
-
}
|
|
124
|
-
export interface CollateralAllocation {
|
|
125
|
-
address: Address;
|
|
126
|
-
lltvs: Set<bigint>;
|
|
127
|
-
oracles: Set<Address>;
|
|
128
|
-
markets: Set<MarketId>;
|
|
129
|
-
proportion: bigint;
|
|
130
|
-
}
|
|
131
|
-
export interface InputAccrualVault extends Omit<InputVault, "withdrawQueue" | "totalAssets"> {
|
|
132
|
-
}
|
|
133
|
-
export declare class AccrualVault extends Vault implements InputAccrualVault {
|
|
134
|
-
/**
|
|
135
|
-
* The allocation of the vault on each market enabled.
|
|
136
|
-
*/
|
|
137
|
-
readonly allocations: Map<MarketId, VaultAllocation>;
|
|
138
|
-
/**
|
|
139
|
-
* The ERC4626 vault's share token.
|
|
140
|
-
*/
|
|
141
|
-
token: Token;
|
|
142
|
-
/**
|
|
143
|
-
* The proportion of assets of the vault supplied to markets collateralized by each collateral asset.
|
|
144
|
-
*/
|
|
145
|
-
readonly collateralAllocations: Map<Address, CollateralAllocation>;
|
|
146
|
-
constructor(vault: InputAccrualVault,
|
|
147
|
-
/**
|
|
148
|
-
* The allocation of the vault on each market of the withdraw queue,
|
|
149
|
-
* in the same order as the withdraw queue.
|
|
150
|
-
*/
|
|
151
|
-
allocations: Omit<InputVaultAllocation, "proportion">[]);
|
|
152
|
-
/**
|
|
153
|
-
* The vault's liquidity directly available from allocated markets.
|
|
154
|
-
*/
|
|
155
|
-
get liquidity(): bigint;
|
|
156
|
-
/**
|
|
157
|
-
* The MetaMorpho vault's average APY on its assets, including the performance fee.
|
|
158
|
-
*/
|
|
159
|
-
get avgApy(): bigint;
|
|
160
|
-
/**
|
|
161
|
-
* The MetaMorpho vault's average APY on its assets, excluding the performance fee.
|
|
162
|
-
*/
|
|
163
|
-
get netApy(): bigint;
|
|
164
|
-
getDepositCapacityLimit(assets: bigint): CapacityLimit;
|
|
165
|
-
getWithdrawCapacityLimit(shares: bigint): CapacityLimit;
|
|
166
|
-
accrueInterest(timestamp: bigint): AccrualVault;
|
|
167
|
-
}
|
package/lib/vault/Vault.js
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AccrualVault = exports.Vault = void 0;
|
|
4
|
-
const ethers_1 = require("ethers");
|
|
5
|
-
const market_1 = require("../market");
|
|
6
|
-
const maths_1 = require("../maths");
|
|
7
|
-
const token_1 = require("../token");
|
|
8
|
-
const VaultAllocation_1 = require("./VaultAllocation");
|
|
9
|
-
const VaultUtils_1 = require("./VaultUtils");
|
|
10
|
-
class Vault {
|
|
11
|
-
constructor({ config, curator, owner, guardian, publicAllocatorConfig, fee, feeRecipient, skimRecipient, pendingTimelock, pendingGuardian, pendingOwner, timelock, supplyQueue, withdrawQueue, totalSupply, totalAssets, lastTotalAssets, }) {
|
|
12
|
-
this.config = config;
|
|
13
|
-
this.curator = curator;
|
|
14
|
-
this.owner = owner;
|
|
15
|
-
this.guardian = guardian;
|
|
16
|
-
this.fee = (0, ethers_1.toBigInt)(fee);
|
|
17
|
-
this.feeRecipient = feeRecipient;
|
|
18
|
-
this.skimRecipient = skimRecipient;
|
|
19
|
-
this.pendingTimelock = {
|
|
20
|
-
value: (0, ethers_1.toBigInt)(pendingTimelock.value),
|
|
21
|
-
validAt: pendingTimelock.validAt,
|
|
22
|
-
};
|
|
23
|
-
this.pendingGuardian = pendingGuardian;
|
|
24
|
-
this.pendingOwner = pendingOwner;
|
|
25
|
-
this.timelock = (0, ethers_1.toBigInt)(timelock);
|
|
26
|
-
this.supplyQueue = supplyQueue;
|
|
27
|
-
this.withdrawQueue = withdrawQueue;
|
|
28
|
-
this.totalSupply = (0, ethers_1.toBigInt)(totalSupply);
|
|
29
|
-
this.totalAssets = (0, ethers_1.toBigInt)(totalAssets);
|
|
30
|
-
this.lastTotalAssets = (0, ethers_1.toBigInt)(lastTotalAssets);
|
|
31
|
-
this.publicAllocatorConfig = publicAllocatorConfig;
|
|
32
|
-
}
|
|
33
|
-
get address() {
|
|
34
|
-
return this.config.address;
|
|
35
|
-
}
|
|
36
|
-
get asset() {
|
|
37
|
-
return this.config.asset;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* The amount of interest in assets accrued since the last interaction with the vault.
|
|
41
|
-
*/
|
|
42
|
-
get totalInterest() {
|
|
43
|
-
return maths_1.MathUtils.zeroFloorSub(this.totalAssets, this.lastTotalAssets);
|
|
44
|
-
}
|
|
45
|
-
toAssets(shares, rounding) {
|
|
46
|
-
return VaultUtils_1.VaultUtils.toAssets(shares, this, this.config, rounding);
|
|
47
|
-
}
|
|
48
|
-
toShares(assets, rounding) {
|
|
49
|
-
return VaultUtils_1.VaultUtils.toShares(assets, this, this.config, rounding);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
exports.Vault = Vault;
|
|
53
|
-
class AccrualVault extends Vault {
|
|
54
|
-
constructor(vault,
|
|
55
|
-
/**
|
|
56
|
-
* The allocation of the vault on each market of the withdraw queue,
|
|
57
|
-
* in the same order as the withdraw queue.
|
|
58
|
-
*/
|
|
59
|
-
allocations) {
|
|
60
|
-
super({
|
|
61
|
-
...vault,
|
|
62
|
-
withdrawQueue: allocations.map(({ position }) => position.market.id),
|
|
63
|
-
totalAssets: allocations.reduce((total, { position }) => total + position.supplyAssets, 0n),
|
|
64
|
-
});
|
|
65
|
-
this.allocations = new Map(allocations.map(({ config, position }) => [
|
|
66
|
-
position.market.id,
|
|
67
|
-
new VaultAllocation_1.VaultAllocation({
|
|
68
|
-
config,
|
|
69
|
-
position,
|
|
70
|
-
proportion: this.totalAssets === 0n
|
|
71
|
-
? 0n
|
|
72
|
-
: maths_1.MathLib.wDivDown(position.supplyAssets, this.totalAssets),
|
|
73
|
-
}),
|
|
74
|
-
]));
|
|
75
|
-
this.token = new token_1.Token(this.config);
|
|
76
|
-
this.collateralAllocations = new Map();
|
|
77
|
-
for (const { position, proportion } of this.allocations.values()) {
|
|
78
|
-
const address = position.market.config.collateralToken;
|
|
79
|
-
let exposure = this.collateralAllocations.get(address);
|
|
80
|
-
if (!exposure)
|
|
81
|
-
this.collateralAllocations.set(address, (exposure = {
|
|
82
|
-
address,
|
|
83
|
-
lltvs: new Set(),
|
|
84
|
-
oracles: new Set(),
|
|
85
|
-
markets: new Set(),
|
|
86
|
-
proportion: 0n,
|
|
87
|
-
}));
|
|
88
|
-
exposure.lltvs.add(position.market.config.lltv);
|
|
89
|
-
exposure.oracles.add(position.market.config.oracle);
|
|
90
|
-
exposure.markets.add(position.market.id);
|
|
91
|
-
exposure.proportion += proportion;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* The vault's liquidity directly available from allocated markets.
|
|
96
|
-
*/
|
|
97
|
-
get liquidity() {
|
|
98
|
-
return Array.from(this.allocations.values()).reduce((total, { position }) => total + position.withdrawCapacityLimit.value, 0n);
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* The MetaMorpho vault's average APY on its assets, including the performance fee.
|
|
102
|
-
*/
|
|
103
|
-
get avgApy() {
|
|
104
|
-
if (this.totalAssets === 0n)
|
|
105
|
-
return 0n;
|
|
106
|
-
return (Array.from(this.allocations.values()).reduce((total, { position }) => total + position.market.supplyApy * position.supplyAssets, 0n) / this.totalAssets);
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* The MetaMorpho vault's average APY on its assets, excluding the performance fee.
|
|
110
|
-
*/
|
|
111
|
-
get netApy() {
|
|
112
|
-
return maths_1.MathLib.wMulDown(this.avgApy, maths_1.MathLib.WAD - this.fee);
|
|
113
|
-
}
|
|
114
|
-
getDepositCapacityLimit(assets) {
|
|
115
|
-
const suppliable = Array.from(this.allocations.values()).reduce((total, { config: { cap }, position: { marketId, supplyAssets } }) => maths_1.MathLib.min(total +
|
|
116
|
-
(this.supplyQueue.includes(marketId)
|
|
117
|
-
? maths_1.MathUtils.zeroFloorSub(cap, supplyAssets)
|
|
118
|
-
: 0n), ethers_1.MaxUint256), 0n);
|
|
119
|
-
if (assets > suppliable)
|
|
120
|
-
return {
|
|
121
|
-
value: suppliable,
|
|
122
|
-
limiter: market_1.CapacityLimitReason.cap,
|
|
123
|
-
};
|
|
124
|
-
return {
|
|
125
|
-
value: assets,
|
|
126
|
-
limiter: market_1.CapacityLimitReason.balance,
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
getWithdrawCapacityLimit(shares) {
|
|
130
|
-
const assets = this.toAssets(shares);
|
|
131
|
-
const { liquidity } = this;
|
|
132
|
-
if (assets > liquidity)
|
|
133
|
-
return {
|
|
134
|
-
value: liquidity,
|
|
135
|
-
limiter: market_1.CapacityLimitReason.liquidity,
|
|
136
|
-
};
|
|
137
|
-
return {
|
|
138
|
-
value: assets,
|
|
139
|
-
limiter: market_1.CapacityLimitReason.balance,
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
accrueInterest(timestamp) {
|
|
143
|
-
const vault = new AccrualVault(this, Array.from(this.allocations.values(), ({ config, position }) => ({
|
|
144
|
-
config,
|
|
145
|
-
position: position.accrueInterest(timestamp),
|
|
146
|
-
})));
|
|
147
|
-
const feeAssets = maths_1.MathLib.wMulDown(vault.totalInterest, vault.fee);
|
|
148
|
-
vault.totalAssets -= feeAssets;
|
|
149
|
-
const feeShares = vault.toShares(feeAssets, "Down");
|
|
150
|
-
vault.totalAssets += feeAssets;
|
|
151
|
-
vault.totalSupply += feeShares;
|
|
152
|
-
vault.lastTotalAssets = vault.totalAssets;
|
|
153
|
-
return vault;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
exports.AccrualVault = AccrualVault;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { AccrualPosition } from "../position";
|
|
2
|
-
import { Pending } from "./Vault";
|
|
3
|
-
/**
|
|
4
|
-
* The vault's configuration of a market on the PublicAllocator.
|
|
5
|
-
*/
|
|
6
|
-
export interface VaultMarketPublicAllocatorConfig {
|
|
7
|
-
maxIn: bigint;
|
|
8
|
-
maxOut: bigint;
|
|
9
|
-
}
|
|
10
|
-
export interface VaultMarketConfig {
|
|
11
|
-
cap: bigint;
|
|
12
|
-
pendingCap: Pending<bigint>;
|
|
13
|
-
removableAt: bigint;
|
|
14
|
-
enabled: boolean;
|
|
15
|
-
readonly publicAllocatorConfig?: VaultMarketPublicAllocatorConfig;
|
|
16
|
-
}
|
|
17
|
-
export interface InputVaultAllocation {
|
|
18
|
-
config: VaultMarketConfig;
|
|
19
|
-
position: AccrualPosition;
|
|
20
|
-
proportion: bigint;
|
|
21
|
-
}
|
|
22
|
-
export declare class VaultAllocation implements InputVaultAllocation {
|
|
23
|
-
/**
|
|
24
|
-
* The vault's configuration on the corresponding market.
|
|
25
|
-
*/
|
|
26
|
-
config: VaultMarketConfig;
|
|
27
|
-
/**
|
|
28
|
-
* The vault's position on the corresponding market.
|
|
29
|
-
*/
|
|
30
|
-
readonly position: AccrualPosition;
|
|
31
|
-
/**
|
|
32
|
-
* The vault's proportion of assets supplied on the corresponding market,
|
|
33
|
-
* with regard to the total assets of the vault.
|
|
34
|
-
*/
|
|
35
|
-
readonly proportion: bigint;
|
|
36
|
-
constructor({ config, position, proportion }: InputVaultAllocation);
|
|
37
|
-
get utilization(): bigint;
|
|
38
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.VaultAllocation = void 0;
|
|
4
|
-
const ethers_1 = require("ethers");
|
|
5
|
-
const maths_1 = require("../maths");
|
|
6
|
-
class VaultAllocation {
|
|
7
|
-
constructor({ config, position, proportion }) {
|
|
8
|
-
this.config = config;
|
|
9
|
-
this.position = position;
|
|
10
|
-
this.proportion = proportion;
|
|
11
|
-
}
|
|
12
|
-
get utilization() {
|
|
13
|
-
if (this.config.cap === 0n)
|
|
14
|
-
return ethers_1.MaxUint256;
|
|
15
|
-
return maths_1.MathLib.wDivDown(this.position.supplyAssets, this.config.cap);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.VaultAllocation = VaultAllocation;
|