@morpho-org/blue-sdk 1.0.0 → 1.0.1
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 +168 -0
- package/lib/addresses.js +169 -0
- package/lib/chain/chain.constants.d.ts +3 -0
- package/lib/chain/chain.constants.js +232 -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/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/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/lib/index.d.ts +33 -0
- 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/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 +5 -5
- 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
package/src/token/Token.ts
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { BigNumberish, parseUnits } from "ethers";
|
|
2
|
-
|
|
3
|
-
import { MathLib, RoundingDirection } from "../maths";
|
|
4
|
-
import { Address } from "../types";
|
|
5
|
-
|
|
6
|
-
export interface InputToken {
|
|
7
|
-
address: Address;
|
|
8
|
-
decimals: number;
|
|
9
|
-
symbol: string;
|
|
10
|
-
name?: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export class Token implements InputToken {
|
|
14
|
-
/**
|
|
15
|
-
* The token's address.
|
|
16
|
-
*/
|
|
17
|
-
public readonly address: Address;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* The token's number of decimals.
|
|
21
|
-
*/
|
|
22
|
-
public readonly decimals: number;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* The token's symbol.
|
|
26
|
-
*/
|
|
27
|
-
public readonly symbol: string;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* The name of the token (defaults to the symbol).
|
|
31
|
-
*/
|
|
32
|
-
public readonly name: string;
|
|
33
|
-
|
|
34
|
-
constructor({ address, decimals, symbol, name }: InputToken) {
|
|
35
|
-
this.address = address;
|
|
36
|
-
this.decimals = decimals;
|
|
37
|
-
this.symbol = symbol;
|
|
38
|
-
this.name = name ?? symbol;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export class TokenWithPrice extends Token {
|
|
43
|
-
/**
|
|
44
|
-
* Price of the token in USD (scaled by WAD).
|
|
45
|
-
*/
|
|
46
|
-
public price?: bigint;
|
|
47
|
-
|
|
48
|
-
constructor(token: InputToken, price?: bigint) {
|
|
49
|
-
super(token);
|
|
50
|
-
|
|
51
|
-
this.price = price;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Quotes an amount in USD (scaled by WAD) in this token.
|
|
56
|
-
* @param amount The amount of USD to quote.
|
|
57
|
-
*/
|
|
58
|
-
fromUsd(amount: BigNumberish, rounding: RoundingDirection = "Down") {
|
|
59
|
-
if (this.price == null) return null;
|
|
60
|
-
|
|
61
|
-
return MathLib.mulDiv(
|
|
62
|
-
amount,
|
|
63
|
-
parseUnits("1", this.decimals),
|
|
64
|
-
this.price,
|
|
65
|
-
rounding
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Quotes an amount of tokens in USD (scaled by WAD).
|
|
71
|
-
* @param amount The amount of tokens to quote.
|
|
72
|
-
*/
|
|
73
|
-
toUsd(amount: BigNumberish, rounding: RoundingDirection = "Down") {
|
|
74
|
-
if (this.price == null) return null;
|
|
75
|
-
|
|
76
|
-
return MathLib.mulDiv(
|
|
77
|
-
amount,
|
|
78
|
-
this.price,
|
|
79
|
-
parseUnits("1", this.decimals),
|
|
80
|
-
rounding
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { Provider } from "ethers";
|
|
2
|
-
import { WStEth__factory } from "ethers-types";
|
|
3
|
-
import { ViewOverrides } from "ethers-types/dist/common";
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
NATIVE_ADDRESS,
|
|
7
|
-
getChainAddresses,
|
|
8
|
-
getUnwrappedToken,
|
|
9
|
-
} from "../addresses";
|
|
10
|
-
import { ChainId, ChainUtils } from "../chain";
|
|
11
|
-
import { Address } from "../types";
|
|
12
|
-
|
|
13
|
-
import { ERC20Metadata__factory } from "./ERC20Metadata";
|
|
14
|
-
import { Token as TokenClass } from "./Token";
|
|
15
|
-
import { ConstantWrappedToken, ExchangeRateWrappedToken } from "./WrappedToken";
|
|
16
|
-
|
|
17
|
-
export class Token extends TokenClass {}
|
|
18
|
-
|
|
19
|
-
export { TokenWithPrice } from "./Token";
|
|
20
|
-
|
|
21
|
-
export namespace Token {
|
|
22
|
-
export function native(chainId: ChainId) {
|
|
23
|
-
const currency = ChainUtils.chainMetadata[chainId].nativeCurrency;
|
|
24
|
-
|
|
25
|
-
return new Token({ ...currency, address: NATIVE_ADDRESS });
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export async function fetch(
|
|
29
|
-
address: Address,
|
|
30
|
-
runner: { provider: Provider },
|
|
31
|
-
{
|
|
32
|
-
chainId,
|
|
33
|
-
overrides = {},
|
|
34
|
-
}: { chainId?: ChainId; overrides?: ViewOverrides } = {}
|
|
35
|
-
) {
|
|
36
|
-
chainId ??= ChainUtils.parseSupportedChainId(
|
|
37
|
-
(await runner.provider.getNetwork()).chainId
|
|
38
|
-
);
|
|
39
|
-
if (address === NATIVE_ADDRESS) return Token.native(chainId);
|
|
40
|
-
|
|
41
|
-
const erc20 = ERC20Metadata__factory.connect(address, chainId, runner);
|
|
42
|
-
|
|
43
|
-
const [decimals, symbol, name] = await Promise.all([
|
|
44
|
-
erc20.decimals(overrides),
|
|
45
|
-
erc20.symbol(overrides),
|
|
46
|
-
erc20.name(overrides),
|
|
47
|
-
]);
|
|
48
|
-
|
|
49
|
-
const token = {
|
|
50
|
-
address,
|
|
51
|
-
decimals: parseInt(decimals.toString()),
|
|
52
|
-
symbol,
|
|
53
|
-
name,
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const { wstEth, stEth } = getChainAddresses(chainId);
|
|
57
|
-
|
|
58
|
-
switch (address) {
|
|
59
|
-
case wstEth: {
|
|
60
|
-
if (stEth) {
|
|
61
|
-
const wstEthToken = WStEth__factory.connect(wstEth!, runner);
|
|
62
|
-
const stEthPerWstEth = await wstEthToken.stEthPerToken(overrides);
|
|
63
|
-
return new ExchangeRateWrappedToken(token, stEth, stEthPerWstEth);
|
|
64
|
-
}
|
|
65
|
-
break;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const unwrapToken = getUnwrappedToken(address, chainId);
|
|
70
|
-
if (unwrapToken) {
|
|
71
|
-
return new ConstantWrappedToken(token, unwrapToken, token.decimals); //TODO fetch underlying token's decimals if it can be different form token's decimals
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return new Token(token);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { formatUnits } from "ethers";
|
|
2
|
-
|
|
3
|
-
import { safeParseUnits } from "../ethers";
|
|
4
|
-
import { MathLib, RoundingDirection, SharesMath } from "../maths";
|
|
5
|
-
import { Address } from "../types";
|
|
6
|
-
import { Vault } from "../vault";
|
|
7
|
-
|
|
8
|
-
import { InputToken, Token } from "./Token";
|
|
9
|
-
|
|
10
|
-
export abstract class WrappedToken extends Token {
|
|
11
|
-
protected abstract _wrap(amount: bigint, rounding: RoundingDirection): bigint;
|
|
12
|
-
protected abstract _unwrap(
|
|
13
|
-
amount: bigint,
|
|
14
|
-
rounding: RoundingDirection
|
|
15
|
-
): bigint;
|
|
16
|
-
|
|
17
|
-
protected _noSlippage = false;
|
|
18
|
-
|
|
19
|
-
constructor(token: InputToken, readonly underlying: Address) {
|
|
20
|
-
super(token);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/** The expected amount when wrapping `unwrappedAmount` */
|
|
24
|
-
toWrappedExactAmountIn(
|
|
25
|
-
unwrappedAmount: bigint,
|
|
26
|
-
slippage = 0n,
|
|
27
|
-
rounding: RoundingDirection = "Down"
|
|
28
|
-
) {
|
|
29
|
-
const wrappedAmount = this._wrap(unwrappedAmount, rounding);
|
|
30
|
-
if (this._noSlippage) return wrappedAmount;
|
|
31
|
-
return MathLib.wMul(wrappedAmount, MathLib.WAD - slippage, "Down");
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/** The amount of unwrappedTokens that should be wrapped to receive `wrappedAmount` */
|
|
35
|
-
toWrappedExactAmountOut(
|
|
36
|
-
wrappedAmount: bigint,
|
|
37
|
-
slippage = 0n,
|
|
38
|
-
rounding: RoundingDirection = "Up"
|
|
39
|
-
) {
|
|
40
|
-
const wAmountTarget = this._noSlippage
|
|
41
|
-
? wrappedAmount
|
|
42
|
-
: MathLib.wDiv(wrappedAmount, MathLib.WAD - slippage, rounding);
|
|
43
|
-
return this._unwrap(wAmountTarget, rounding);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/** The expected amount when unwrapping `wrappedAmount` */
|
|
47
|
-
toUnwrappedExactAmountIn(
|
|
48
|
-
wrappedAmount: bigint,
|
|
49
|
-
slippage = 0n,
|
|
50
|
-
rounding: RoundingDirection = "Down"
|
|
51
|
-
) {
|
|
52
|
-
const unwrappedAmount = this._unwrap(wrappedAmount, rounding);
|
|
53
|
-
if (this._noSlippage) return unwrappedAmount;
|
|
54
|
-
return MathLib.wMul(unwrappedAmount, MathLib.WAD - slippage, "Up");
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/** The amount of wrappedTokens that should be unwrapped to receive `unwrappedAmount` */
|
|
58
|
-
toUnwrappedExactAmountOut(
|
|
59
|
-
unwrappedAmount: bigint,
|
|
60
|
-
slippage = 0n,
|
|
61
|
-
rounding: RoundingDirection = "Up"
|
|
62
|
-
) {
|
|
63
|
-
const unwrappedAmountToTarget = this._noSlippage
|
|
64
|
-
? unwrappedAmount
|
|
65
|
-
: MathLib.wDiv(unwrappedAmount, MathLib.WAD - slippage, rounding);
|
|
66
|
-
return this._wrap(unwrappedAmountToTarget, rounding);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export class ConstantWrappedToken extends WrappedToken {
|
|
71
|
-
protected _noSlippage = true;
|
|
72
|
-
|
|
73
|
-
constructor(
|
|
74
|
-
token: InputToken,
|
|
75
|
-
readonly underlying: Address,
|
|
76
|
-
private readonly _underlyingDecimals = 18
|
|
77
|
-
) {
|
|
78
|
-
super(token, underlying);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
protected _wrap(amount: bigint) {
|
|
82
|
-
return safeParseUnits(
|
|
83
|
-
formatUnits(amount, this._underlyingDecimals),
|
|
84
|
-
this.decimals
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
protected _unwrap(amount: bigint) {
|
|
88
|
-
return safeParseUnits(
|
|
89
|
-
formatUnits(amount, this.decimals),
|
|
90
|
-
this._underlyingDecimals
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export class ExchangeRateWrappedToken extends WrappedToken {
|
|
96
|
-
protected _wrap(amount: bigint, rounding: RoundingDirection) {
|
|
97
|
-
return MathLib.wDiv(amount, this.wrappedTokenExchangeRate, rounding);
|
|
98
|
-
}
|
|
99
|
-
protected _unwrap(amount: bigint, rounding: RoundingDirection) {
|
|
100
|
-
return MathLib.wMul(amount, this.wrappedTokenExchangeRate, rounding);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
constructor(
|
|
104
|
-
token: InputToken,
|
|
105
|
-
readonly underlying: Address,
|
|
106
|
-
public wrappedTokenExchangeRate: bigint
|
|
107
|
-
) {
|
|
108
|
-
super(token, underlying);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export class VaultToken extends WrappedToken {
|
|
113
|
-
protected _wrap(amount: bigint, rounding: RoundingDirection) {
|
|
114
|
-
return SharesMath.toShares(
|
|
115
|
-
amount,
|
|
116
|
-
this.totalAssets,
|
|
117
|
-
this.totalSupply,
|
|
118
|
-
rounding
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
protected _unwrap(amount: bigint, rounding: RoundingDirection) {
|
|
122
|
-
return SharesMath.toAssets(
|
|
123
|
-
amount,
|
|
124
|
-
this.totalAssets,
|
|
125
|
-
this.totalSupply,
|
|
126
|
-
rounding
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
public totalAssets: bigint;
|
|
131
|
-
public totalSupply: bigint;
|
|
132
|
-
|
|
133
|
-
constructor(
|
|
134
|
-
token: InputToken,
|
|
135
|
-
readonly underlying: Address,
|
|
136
|
-
{ totalAssets, totalSupply }: Pick<Vault, "totalAssets" | "totalSupply">
|
|
137
|
-
) {
|
|
138
|
-
super(token, underlying);
|
|
139
|
-
this.totalAssets = totalAssets;
|
|
140
|
-
this.totalSupply = totalSupply;
|
|
141
|
-
}
|
|
142
|
-
}
|
package/src/types.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { isHexString } from "ethers";
|
|
2
|
-
|
|
3
|
-
export type Hex64 = string & { __LENGTH__: 64 };
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* The address of a Contract, or an EOA
|
|
7
|
-
*/
|
|
8
|
-
export type Address = string;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* The id of a market used on the Blue contract
|
|
12
|
-
*/
|
|
13
|
-
export type MarketId = `0x${Hex64}` & { __TYPE__: "marketId" };
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* The possible transaction type on the Blue contract
|
|
17
|
-
*/
|
|
18
|
-
export enum TransactionType {
|
|
19
|
-
Supply = "Supply",
|
|
20
|
-
SupplyCollateral = "Supply Collateral",
|
|
21
|
-
Withdraw = "Withdraw",
|
|
22
|
-
WithdrawCollateral = "Withdraw Collateral",
|
|
23
|
-
Borrow = "Borrow",
|
|
24
|
-
Repay = "Repay",
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export type Loadable<T> = T | undefined;
|
|
28
|
-
export type Failable<T> = T | null;
|
|
29
|
-
export type Fetchable<T> = Failable<Loadable<T>>;
|
|
30
|
-
|
|
31
|
-
// TODO: replace with isDefined
|
|
32
|
-
export function isFetched<T>(v: Fetchable<T>): v is T {
|
|
33
|
-
return v !== undefined && v !== null;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export const isMarketId = (value: any): value is MarketId =>
|
|
37
|
-
isHexString(value, 32);
|
package/src/user/User.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { Address } from "../types";
|
|
2
|
-
|
|
3
|
-
export class User {
|
|
4
|
-
/**
|
|
5
|
-
* The user's address.
|
|
6
|
-
*/
|
|
7
|
-
public readonly address: Address;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Whether the bundler is authorized to manage the user's position on Morpho Blue.
|
|
11
|
-
*/
|
|
12
|
-
public isBundlerAuthorized: boolean;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* The user's nonce on Morpho Blue.
|
|
16
|
-
*/
|
|
17
|
-
public morphoNonce: bigint;
|
|
18
|
-
|
|
19
|
-
constructor({
|
|
20
|
-
address,
|
|
21
|
-
isBundlerAuthorized,
|
|
22
|
-
morphoNonce,
|
|
23
|
-
}: {
|
|
24
|
-
address: Address;
|
|
25
|
-
isBundlerAuthorized: boolean;
|
|
26
|
-
morphoNonce: bigint;
|
|
27
|
-
}) {
|
|
28
|
-
this.address = address;
|
|
29
|
-
this.isBundlerAuthorized = isBundlerAuthorized;
|
|
30
|
-
this.morphoNonce = morphoNonce;
|
|
31
|
-
}
|
|
32
|
-
}
|
package/src/user/user.types.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Token } from "../token";
|
|
2
|
-
|
|
3
|
-
export interface MaxBalanceDecomposition {
|
|
4
|
-
maxBalance: bigint;
|
|
5
|
-
decomposition: { base: BalanceDecompositionFragment } & {
|
|
6
|
-
[T in Exclude<PeripheralTokenType, "base">]?: BalanceDecompositionFragment;
|
|
7
|
-
};
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export type PeripheralTokenType =
|
|
11
|
-
| "base"
|
|
12
|
-
| "wrapped"
|
|
13
|
-
| "erc4626"
|
|
14
|
-
| "wrapped-erc4626";
|
|
15
|
-
export interface PeripheralToken {
|
|
16
|
-
token: Token;
|
|
17
|
-
type: PeripheralTokenType;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface BalanceDecompositionFragment extends PeripheralToken {
|
|
21
|
-
underlyingValue: bigint;
|
|
22
|
-
value: bigint;
|
|
23
|
-
}
|