@morpho-org/blue-sdk 1.0.0-integ-650.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +106 -0
- package/lib/addresses.d.ts +113 -0
- package/lib/addresses.js +162 -0
- package/lib/chain.d.ts +29 -0
- package/lib/chain.js +289 -0
- package/lib/chain.test.d.ts +1 -0
- package/lib/chain.test.js +21 -0
- package/lib/constants.d.ts +29 -0
- package/lib/constants.js +33 -0
- package/lib/errors.d.ts +58 -0
- package/lib/errors.js +119 -0
- package/lib/helpers/format/format.d.ts +122 -0
- package/lib/helpers/format/format.js +286 -0
- package/lib/helpers/format/format.test.d.ts +1 -0
- package/lib/helpers/format/format.test.js +255 -0
- package/lib/helpers/format/index.d.ts +1 -0
- package/lib/helpers/format/index.js +17 -0
- package/lib/helpers/index.d.ts +2 -0
- package/lib/helpers/index.js +18 -0
- package/lib/helpers/locale.d.ts +46 -0
- package/lib/helpers/locale.js +96 -0
- package/lib/holding/AssetBalances.d.ts +48 -0
- package/lib/holding/AssetBalances.js +42 -0
- package/lib/holding/Holding.d.ts +59 -0
- package/lib/holding/Holding.js +59 -0
- package/lib/holding/index.d.ts +2 -0
- package/lib/holding/index.js +18 -0
- package/lib/index.d.ts +25 -0
- package/lib/index.js +54 -0
- package/lib/market/Market.d.ts +329 -0
- package/lib/market/Market.js +460 -0
- package/lib/market/MarketConfig.d.ts +52 -0
- package/lib/market/MarketConfig.js +76 -0
- package/lib/market/MarketUtils.d.ts +232 -0
- package/lib/market/MarketUtils.js +263 -0
- package/lib/market/MarketUtils.test.d.ts +1 -0
- package/lib/market/MarketUtils.test.js +38 -0
- package/lib/market/index.d.ts +3 -0
- package/lib/market/index.js +19 -0
- package/lib/maths/AdaptiveCurveIrmLib.d.ts +39 -0
- package/lib/maths/AdaptiveCurveIrmLib.js +134 -0
- package/lib/maths/MathLib.d.ts +114 -0
- package/lib/maths/MathLib.js +175 -0
- package/lib/maths/SharesMath.d.ts +12 -0
- package/lib/maths/SharesMath.js +21 -0
- package/lib/maths/index.d.ts +3 -0
- package/lib/maths/index.js +19 -0
- package/lib/position/Position.d.ts +126 -0
- package/lib/position/Position.js +203 -0
- package/lib/position/index.d.ts +1 -0
- package/lib/position/index.js +17 -0
- package/lib/tests/mocks/markets.d.ts +19 -0
- package/lib/tests/mocks/markets.js +121 -0
- package/lib/token/ConstantWrappedToken.d.ts +18 -0
- package/lib/token/ConstantWrappedToken.js +36 -0
- package/lib/token/ExchangeRateWrappedToken.d.ts +11 -0
- package/lib/token/ExchangeRateWrappedToken.js +21 -0
- package/lib/token/Token.d.ts +46 -0
- package/lib/token/Token.js +64 -0
- package/lib/token/VaultToken.d.ts +14 -0
- package/lib/token/VaultToken.js +23 -0
- package/lib/token/WrappedToken.d.ts +17 -0
- package/lib/token/WrappedToken.js +33 -0
- package/lib/token/index.d.ts +5 -0
- package/lib/token/index.js +21 -0
- package/lib/types.d.ts +30 -0
- package/lib/types.js +22 -0
- package/lib/user/User.d.ts +20 -0
- package/lib/user/User.js +23 -0
- package/lib/user/index.d.ts +1 -0
- package/lib/user/index.js +17 -0
- package/lib/vault/Vault.d.ts +166 -0
- package/lib/vault/Vault.js +234 -0
- package/lib/vault/VaultConfig.d.ts +22 -0
- package/lib/vault/VaultConfig.js +32 -0
- package/lib/vault/VaultMarketAllocation.d.ts +20 -0
- package/lib/vault/VaultMarketAllocation.js +30 -0
- package/lib/vault/VaultMarketConfig.d.ts +43 -0
- package/lib/vault/VaultMarketConfig.js +43 -0
- package/lib/vault/VaultMarketPublicAllocatorConfig.d.ts +29 -0
- package/lib/vault/VaultMarketPublicAllocatorConfig.js +28 -0
- package/lib/vault/VaultUtils.d.ts +18 -0
- package/lib/vault/VaultUtils.js +20 -0
- package/lib/vault/index.d.ts +6 -0
- package/lib/vault/index.js +22 -0
- package/package.json +53 -0
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AccrualPosition = exports.Position = void 0;
|
|
4
|
+
const errors_1 = require("../errors");
|
|
5
|
+
const market_1 = require("../market");
|
|
6
|
+
class Position {
|
|
7
|
+
/**
|
|
8
|
+
* The user holding this position.
|
|
9
|
+
*/
|
|
10
|
+
user;
|
|
11
|
+
/**
|
|
12
|
+
* The id of the market on which this position is held.
|
|
13
|
+
*/
|
|
14
|
+
marketId;
|
|
15
|
+
/**
|
|
16
|
+
* The amount of supply shares held with this position.
|
|
17
|
+
*/
|
|
18
|
+
supplyShares;
|
|
19
|
+
/**
|
|
20
|
+
* The amount of borrow shares held with this position.
|
|
21
|
+
*/
|
|
22
|
+
borrowShares;
|
|
23
|
+
/**
|
|
24
|
+
* The amount of collateral assets held with this position.
|
|
25
|
+
*/
|
|
26
|
+
collateral;
|
|
27
|
+
constructor({ user, marketId, supplyShares, borrowShares, collateral, }) {
|
|
28
|
+
this.user = user;
|
|
29
|
+
this.marketId = marketId;
|
|
30
|
+
this.supplyShares = supplyShares;
|
|
31
|
+
this.borrowShares = borrowShares;
|
|
32
|
+
this.collateral = collateral;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.Position = Position;
|
|
36
|
+
class AccrualPosition extends Position {
|
|
37
|
+
/**
|
|
38
|
+
* The market on which this position is held.
|
|
39
|
+
*/
|
|
40
|
+
market;
|
|
41
|
+
constructor(position, market) {
|
|
42
|
+
super({ ...position, marketId: market.id });
|
|
43
|
+
this.market = market;
|
|
44
|
+
}
|
|
45
|
+
get supplyAssets() {
|
|
46
|
+
return this.market.toSupplyAssets(this.supplyShares);
|
|
47
|
+
}
|
|
48
|
+
get borrowAssets() {
|
|
49
|
+
return this.market.toBorrowAssets(this.borrowShares);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The value of this position's collateral quoted in loan assets.
|
|
53
|
+
*/
|
|
54
|
+
get collateralValue() {
|
|
55
|
+
return this.market.getCollateralValue(this.collateral);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The maximum amount of loan assets that can be borrowed against this position's collateral.
|
|
59
|
+
*/
|
|
60
|
+
get maxBorrowAssets() {
|
|
61
|
+
return this.market.getMaxBorrowAssets(this.collateral);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The maximum additional amount of assets that can be borrowed against this position's collateral.
|
|
65
|
+
*/
|
|
66
|
+
get maxBorrowableAssets() {
|
|
67
|
+
return this.market.getMaxBorrowableAssets(this);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The maximum amount of collateral that can be seized in exchange for the outstanding debt.
|
|
71
|
+
*/
|
|
72
|
+
get seizableCollateral() {
|
|
73
|
+
return this.market.getSeizableCollateral(this);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The maximum amount of collateral that can be withdrawn.
|
|
77
|
+
*/
|
|
78
|
+
get withdrawableCollateral() {
|
|
79
|
+
return this.market.getWithdrawableCollateral(this);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Whether this position is healthy.
|
|
83
|
+
*/
|
|
84
|
+
get isHealthy() {
|
|
85
|
+
return this.market.isHealthy(this);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The price of the collateral quoted in loan assets that would allow this position to be liquidated.
|
|
89
|
+
*/
|
|
90
|
+
get liquidationPrice() {
|
|
91
|
+
return this.market.getLiquidationPrice(this);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The variation of the price of the collateral quoted in loan assets that would allow this position to be liquidated,
|
|
95
|
+
* relative to the current collateral price (scaled by WAD).
|
|
96
|
+
*/
|
|
97
|
+
get priceVariationToLiquidation() {
|
|
98
|
+
return this.market.getPriceVariationToLiquidation(this);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* This position's Loan-To-Value (debt over collateral power, scaled by WAD).
|
|
102
|
+
* If the collateral price is 0, LTV is `MaxUint256`.
|
|
103
|
+
*/
|
|
104
|
+
get ltv() {
|
|
105
|
+
return this.market.getLtv(this);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* This position's health factor (collateral power over debt, scaled by WAD).
|
|
109
|
+
* If the debt is 0, health factor is `MaxUint256`.
|
|
110
|
+
*/
|
|
111
|
+
get healthFactor() {
|
|
112
|
+
return this.market.getHealthFactor(this);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The percentage of this position's borrow power currently used (scaled by WAD).
|
|
116
|
+
* If the collateral price is 0, usage is `MaxUint256`.
|
|
117
|
+
*/
|
|
118
|
+
get borrowCapacityUsage() {
|
|
119
|
+
return this.market.getBorrowCapacityUsage(this);
|
|
120
|
+
}
|
|
121
|
+
get borrowCapacityLimit() {
|
|
122
|
+
return this.market.getBorrowCapacityLimit(this);
|
|
123
|
+
}
|
|
124
|
+
get withdrawCapacityLimit() {
|
|
125
|
+
return this.market.getWithdrawCapacityLimit(this);
|
|
126
|
+
}
|
|
127
|
+
get withdrawCollateralCapacityLimit() {
|
|
128
|
+
return this.market.getWithdrawCollateralCapacityLimit(this);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Returns a new position derived from this position, whose interest has been accrued up to the given timestamp.
|
|
132
|
+
* @param timestamp The timestamp at which to accrue interest. Must be greater than or equal to the market's `lastUpdate`.
|
|
133
|
+
*/
|
|
134
|
+
accrueInterest(timestamp) {
|
|
135
|
+
return new AccrualPosition(this, this.market.accrueInterest(timestamp));
|
|
136
|
+
}
|
|
137
|
+
supply(assets, shares, timestamp) {
|
|
138
|
+
let { market } = this;
|
|
139
|
+
({ market, assets, shares } = market.supply(assets, shares, timestamp));
|
|
140
|
+
this.supplyShares += shares;
|
|
141
|
+
return {
|
|
142
|
+
position: new AccrualPosition(this, market),
|
|
143
|
+
assets,
|
|
144
|
+
shares,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
withdraw(assets, shares, timestamp) {
|
|
148
|
+
let { market } = this;
|
|
149
|
+
({ market, assets, shares } = market.withdraw(assets, shares, timestamp));
|
|
150
|
+
this.supplyShares -= shares;
|
|
151
|
+
if (this.supplyShares < 0n)
|
|
152
|
+
throw new errors_1.BlueErrors.InsufficientPosition(this.user, this.marketId);
|
|
153
|
+
return {
|
|
154
|
+
position: new AccrualPosition(this, market),
|
|
155
|
+
assets,
|
|
156
|
+
shares,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
supplyCollateral(assets) {
|
|
160
|
+
this.collateral += assets;
|
|
161
|
+
return new AccrualPosition(this, new market_1.Market(this.market));
|
|
162
|
+
}
|
|
163
|
+
withdrawCollateral(assets, timestamp) {
|
|
164
|
+
const market = this.market.accrueInterest(timestamp);
|
|
165
|
+
this.collateral -= assets;
|
|
166
|
+
if (this.collateral < 0n)
|
|
167
|
+
throw new errors_1.BlueErrors.InsufficientPosition(this.user, this.marketId);
|
|
168
|
+
if (!market.isHealthy(this))
|
|
169
|
+
throw new errors_1.BlueErrors.InsufficientCollateral(this.user, this.marketId);
|
|
170
|
+
return new AccrualPosition(this, market);
|
|
171
|
+
}
|
|
172
|
+
borrow(assets, shares, timestamp) {
|
|
173
|
+
let { market } = this;
|
|
174
|
+
({ market, assets, shares } = market.borrow(assets, shares, timestamp));
|
|
175
|
+
this.borrowShares += shares;
|
|
176
|
+
if (!market.isHealthy(this))
|
|
177
|
+
throw new errors_1.BlueErrors.InsufficientCollateral(this.user, this.marketId);
|
|
178
|
+
return {
|
|
179
|
+
position: new AccrualPosition(this, market),
|
|
180
|
+
assets,
|
|
181
|
+
shares,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
repay(assets, shares, timestamp) {
|
|
185
|
+
let { market } = this;
|
|
186
|
+
({ market, assets, shares } = market.repay(assets, shares, timestamp));
|
|
187
|
+
this.borrowShares -= shares;
|
|
188
|
+
if (this.borrowShares < 0n)
|
|
189
|
+
throw new errors_1.BlueErrors.InsufficientPosition(this.user, this.marketId);
|
|
190
|
+
return {
|
|
191
|
+
position: new AccrualPosition(this, market),
|
|
192
|
+
assets,
|
|
193
|
+
shares,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
getRepayCapacityLimit(loanTokenBalance) {
|
|
197
|
+
return this.market.getRepayCapacityLimit(this.borrowShares, loanTokenBalance);
|
|
198
|
+
}
|
|
199
|
+
getMaxCapacities(loanTokenBalance, collateralTokenBalance, options) {
|
|
200
|
+
return this.market.getMaxCapacities(this, loanTokenBalance, collateralTokenBalance, options);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
exports.AccrualPosition = AccrualPosition;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Position";
|
|
@@ -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("./Position"), exports);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { MarketConfig } from "../../market";
|
|
2
|
+
export declare const MAINNET_MARKETS: {
|
|
3
|
+
eth_wstEth: MarketConfig;
|
|
4
|
+
eth_wstEth_2: MarketConfig;
|
|
5
|
+
eth_rEth: MarketConfig;
|
|
6
|
+
usdt_wbtc: MarketConfig;
|
|
7
|
+
usdt_wstEth: MarketConfig;
|
|
8
|
+
usdc_wbtc: MarketConfig;
|
|
9
|
+
usdc_wstEth: MarketConfig;
|
|
10
|
+
usdc_sDai: MarketConfig;
|
|
11
|
+
idle_usdc: MarketConfig;
|
|
12
|
+
crvUsd_stkcvxcrvUSDTWBTCWETH: MarketConfig;
|
|
13
|
+
crvUsd_stkcvxcrvUSDCWBTCWETH: MarketConfig;
|
|
14
|
+
crvUsd_stkcvxcrvCRVUSDTBTCWSTETH: MarketConfig;
|
|
15
|
+
crvUsd_stkcvxTryLSD: MarketConfig;
|
|
16
|
+
crvUsd_stkcvxcrvUSDETHCRV: MarketConfig;
|
|
17
|
+
"crvUsd_stkcvx2BTC-f": MarketConfig;
|
|
18
|
+
usda_re7Eth: MarketConfig;
|
|
19
|
+
};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MAINNET_MARKETS = void 0;
|
|
4
|
+
const market_1 = require("../../market");
|
|
5
|
+
exports.MAINNET_MARKETS = {
|
|
6
|
+
eth_wstEth: new market_1.MarketConfig({
|
|
7
|
+
loanToken: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
|
8
|
+
collateralToken: "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0",
|
|
9
|
+
oracle: "0x2a01EB9496094dA03c4E364Def50f5aD1280AD72",
|
|
10
|
+
irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
|
|
11
|
+
lltv: 945000000000000000n,
|
|
12
|
+
}),
|
|
13
|
+
eth_wstEth_2: new market_1.MarketConfig({
|
|
14
|
+
loanToken: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
|
15
|
+
collateralToken: "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0",
|
|
16
|
+
oracle: "0xbD60A6770b27E084E8617335ddE769241B0e71D8",
|
|
17
|
+
irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
|
|
18
|
+
lltv: 945000000000000000n,
|
|
19
|
+
}),
|
|
20
|
+
eth_rEth: new market_1.MarketConfig({
|
|
21
|
+
loanToken: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
|
22
|
+
collateralToken: "0xae78736Cd615f374D3085123A210448E74Fc6393",
|
|
23
|
+
oracle: "0x1b4A3F92e5Fffd1d35A98751c9FE4472483579bB",
|
|
24
|
+
irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
|
|
25
|
+
lltv: 945000000000000000n,
|
|
26
|
+
}),
|
|
27
|
+
usdt_wbtc: new market_1.MarketConfig({
|
|
28
|
+
loanToken: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
|
|
29
|
+
collateralToken: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
|
|
30
|
+
oracle: "0x008bF4B1cDA0cc9f0e882E0697f036667652E1ef",
|
|
31
|
+
irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
|
|
32
|
+
lltv: 860000000000000000n,
|
|
33
|
+
}),
|
|
34
|
+
usdt_wstEth: new market_1.MarketConfig({
|
|
35
|
+
loanToken: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
|
|
36
|
+
collateralToken: "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0",
|
|
37
|
+
oracle: "0x95DB30fAb9A3754e42423000DF27732CB2396992",
|
|
38
|
+
irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
|
|
39
|
+
lltv: 860000000000000000n,
|
|
40
|
+
}),
|
|
41
|
+
usdc_wbtc: new market_1.MarketConfig({
|
|
42
|
+
// USDC(wBTC, 86%, Chainlink, AdaptiveCurve)
|
|
43
|
+
loanToken: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
44
|
+
collateralToken: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
|
|
45
|
+
oracle: "0xDddd770BADd886dF3864029e4B377B5F6a2B6b83",
|
|
46
|
+
irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
|
|
47
|
+
lltv: 860000000000000000n,
|
|
48
|
+
}),
|
|
49
|
+
usdc_wstEth: new market_1.MarketConfig({
|
|
50
|
+
// USDC(wstETH, 86%, Chainlink, AdaptiveCurve)
|
|
51
|
+
loanToken: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
52
|
+
collateralToken: "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0",
|
|
53
|
+
oracle: "0x48F7E36EB6B826B2dF4B2E630B62Cd25e89E40e2",
|
|
54
|
+
irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
|
|
55
|
+
lltv: 860000000000000000n,
|
|
56
|
+
}),
|
|
57
|
+
usdc_sDai: new market_1.MarketConfig({
|
|
58
|
+
// USDC(wstETH, 86%, Chainlink, AdaptiveCurve)
|
|
59
|
+
loanToken: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
60
|
+
collateralToken: "0x83F20F44975D03b1b09e64809B757c47f942BEeA",
|
|
61
|
+
oracle: "0x6CAFE228eC0B0bC2D076577d56D35Fe704318f6d",
|
|
62
|
+
irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
|
|
63
|
+
lltv: 96500000000000000000n,
|
|
64
|
+
}),
|
|
65
|
+
idle_usdc: new market_1.MarketConfig({
|
|
66
|
+
loanToken: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
67
|
+
collateralToken: "0x0000000000000000000000000000000000000000",
|
|
68
|
+
oracle: "0x0000000000000000000000000000000000000000",
|
|
69
|
+
irm: "0x0000000000000000000000000000000000000000",
|
|
70
|
+
lltv: 0n,
|
|
71
|
+
}),
|
|
72
|
+
crvUsd_stkcvxcrvUSDTWBTCWETH: new market_1.MarketConfig({
|
|
73
|
+
loanToken: "0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E",
|
|
74
|
+
collateralToken: "0xb0Ce26C88e4e7DCa51968b6047f44646f5064278",
|
|
75
|
+
oracle: "0x077Af6c2D4A75D4145d141F9e9421864C3940CB3",
|
|
76
|
+
irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
|
|
77
|
+
lltv: 860000000000000000n,
|
|
78
|
+
}),
|
|
79
|
+
crvUsd_stkcvxcrvUSDCWBTCWETH: new market_1.MarketConfig({
|
|
80
|
+
loanToken: "0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E",
|
|
81
|
+
collateralToken: "0x0ea1a65A2c255f24Ee8D81eA6AaC54Decd9d269e",
|
|
82
|
+
oracle: "0xd2F7C3B2fC97cC7b6AfDd76D163394680EFc35b9",
|
|
83
|
+
irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
|
|
84
|
+
lltv: 860000000000000000n,
|
|
85
|
+
}),
|
|
86
|
+
crvUsd_stkcvxcrvCRVUSDTBTCWSTETH: new market_1.MarketConfig({
|
|
87
|
+
loanToken: "0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E",
|
|
88
|
+
collateralToken: "0x3ce8Ec9f3d89aD0A2DdbCC3FDB8991BD241Fc82E",
|
|
89
|
+
oracle: "0xa9f7900476F43C45Ebf56cEa669B9c960C176112",
|
|
90
|
+
irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
|
|
91
|
+
lltv: 860000000000000000n,
|
|
92
|
+
}),
|
|
93
|
+
crvUsd_stkcvxTryLSD: new market_1.MarketConfig({
|
|
94
|
+
loanToken: "0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E",
|
|
95
|
+
collateralToken: "0x6BA072F0d22806F2C52e9792AF47f2D59103BEBE",
|
|
96
|
+
oracle: "0x18B0d7311a97c5377445C80c768ab5201Bb27B5a",
|
|
97
|
+
irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
|
|
98
|
+
lltv: 860000000000000000n,
|
|
99
|
+
}),
|
|
100
|
+
crvUsd_stkcvxcrvUSDETHCRV: new market_1.MarketConfig({
|
|
101
|
+
loanToken: "0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E",
|
|
102
|
+
collateralToken: "0xAc904BAfBb5FB04Deb2b6198FdCEedE75a78Ce5a",
|
|
103
|
+
oracle: "0xad7e157815df05029125B568E39d5402550d60bb",
|
|
104
|
+
irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
|
|
105
|
+
lltv: 860000000000000000n,
|
|
106
|
+
}),
|
|
107
|
+
"crvUsd_stkcvx2BTC-f": new market_1.MarketConfig({
|
|
108
|
+
loanToken: "0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E",
|
|
109
|
+
collateralToken: "0x385E12cf4040543Bc8C18e05C1298Be5B04f3f5e",
|
|
110
|
+
oracle: "0x20c4fA59f032bEC6de1905B7201CB88DFD968abA",
|
|
111
|
+
irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
|
|
112
|
+
lltv: 860000000000000000n,
|
|
113
|
+
}),
|
|
114
|
+
usda_re7Eth: new market_1.MarketConfig({
|
|
115
|
+
loanToken: "0x0000206329b97DB379d5E1Bf586BbDB969C63274",
|
|
116
|
+
collateralToken: "0x78Fc2c2eD1A4cDb5402365934aE5648aDAd094d0",
|
|
117
|
+
oracle: "0x76052A2A28fDCB8124f4686C63C68355b142de3B",
|
|
118
|
+
irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
|
|
119
|
+
lltv: 860000000000000000n,
|
|
120
|
+
}),
|
|
121
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { RoundingDirection } from "../maths";
|
|
2
|
+
import { Address } from "../types";
|
|
3
|
+
import { InputToken } from "./Token";
|
|
4
|
+
import { WrappedToken } from "./WrappedToken";
|
|
5
|
+
export declare class ConstantWrappedToken extends WrappedToken {
|
|
6
|
+
readonly underlying: Address;
|
|
7
|
+
private readonly _underlyingDecimals;
|
|
8
|
+
constructor(token: InputToken, underlying: Address, _underlyingDecimals?: number);
|
|
9
|
+
toWrappedExactAmountIn(unwrappedAmount: bigint, _slippage?: bigint, rounding?: RoundingDirection): bigint;
|
|
10
|
+
/** The amount of unwrappedTokens that should be wrapped to receive `wrappedAmount` */
|
|
11
|
+
toWrappedExactAmountOut(wrappedAmount: bigint, _slippage?: bigint, rounding?: RoundingDirection): bigint;
|
|
12
|
+
/** The expected amount when unwrapping `wrappedAmount` */
|
|
13
|
+
toUnwrappedExactAmountIn(wrappedAmount: bigint, _slippage?: bigint, rounding?: RoundingDirection): bigint;
|
|
14
|
+
/** The amount of wrappedTokens that should be unwrapped to receive `unwrappedAmount` */
|
|
15
|
+
toUnwrappedExactAmountOut(unwrappedAmount: bigint, _slippage?: bigint, rounding?: RoundingDirection): bigint;
|
|
16
|
+
protected _wrap(amount: bigint): bigint;
|
|
17
|
+
protected _unwrap(amount: bigint): bigint;
|
|
18
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConstantWrappedToken = void 0;
|
|
4
|
+
const maths_1 = require("../maths");
|
|
5
|
+
const WrappedToken_1 = require("./WrappedToken");
|
|
6
|
+
class ConstantWrappedToken extends WrappedToken_1.WrappedToken {
|
|
7
|
+
underlying;
|
|
8
|
+
_underlyingDecimals;
|
|
9
|
+
constructor(token, underlying, _underlyingDecimals = 18) {
|
|
10
|
+
super(token, underlying);
|
|
11
|
+
this.underlying = underlying;
|
|
12
|
+
this._underlyingDecimals = _underlyingDecimals;
|
|
13
|
+
}
|
|
14
|
+
toWrappedExactAmountIn(unwrappedAmount, _slippage, rounding = "Down") {
|
|
15
|
+
return super.toWrappedExactAmountIn(unwrappedAmount, 0n, rounding);
|
|
16
|
+
}
|
|
17
|
+
/** The amount of unwrappedTokens that should be wrapped to receive `wrappedAmount` */
|
|
18
|
+
toWrappedExactAmountOut(wrappedAmount, _slippage, rounding = "Up") {
|
|
19
|
+
return super.toWrappedExactAmountOut(wrappedAmount, 0n, rounding);
|
|
20
|
+
}
|
|
21
|
+
/** The expected amount when unwrapping `wrappedAmount` */
|
|
22
|
+
toUnwrappedExactAmountIn(wrappedAmount, _slippage, rounding = "Down") {
|
|
23
|
+
return super.toUnwrappedExactAmountIn(wrappedAmount, 0n, rounding);
|
|
24
|
+
}
|
|
25
|
+
/** The amount of wrappedTokens that should be unwrapped to receive `unwrappedAmount` */
|
|
26
|
+
toUnwrappedExactAmountOut(unwrappedAmount, _slippage, rounding = "Up") {
|
|
27
|
+
return super.toUnwrappedExactAmountOut(unwrappedAmount, 0n, rounding);
|
|
28
|
+
}
|
|
29
|
+
_wrap(amount) {
|
|
30
|
+
return maths_1.MathLib.mulDivDown(amount, 10n ** BigInt(this.decimals), 10n ** BigInt(this._underlyingDecimals));
|
|
31
|
+
}
|
|
32
|
+
_unwrap(amount) {
|
|
33
|
+
return maths_1.MathLib.mulDivDown(amount, 10n ** BigInt(this._underlyingDecimals), 10n ** BigInt(this.decimals));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.ConstantWrappedToken = ConstantWrappedToken;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RoundingDirection } from "../maths";
|
|
2
|
+
import { Address } from "../types";
|
|
3
|
+
import { InputToken } from "./Token";
|
|
4
|
+
import { WrappedToken } from "./WrappedToken";
|
|
5
|
+
export declare class ExchangeRateWrappedToken extends WrappedToken {
|
|
6
|
+
readonly underlying: Address;
|
|
7
|
+
wrappedTokenExchangeRate: bigint;
|
|
8
|
+
constructor(token: InputToken, underlying: Address, wrappedTokenExchangeRate: bigint);
|
|
9
|
+
protected _wrap(amount: bigint, rounding: RoundingDirection): bigint;
|
|
10
|
+
protected _unwrap(amount: bigint, rounding: RoundingDirection): bigint;
|
|
11
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExchangeRateWrappedToken = void 0;
|
|
4
|
+
const maths_1 = require("../maths");
|
|
5
|
+
const WrappedToken_1 = require("./WrappedToken");
|
|
6
|
+
class ExchangeRateWrappedToken extends WrappedToken_1.WrappedToken {
|
|
7
|
+
underlying;
|
|
8
|
+
wrappedTokenExchangeRate;
|
|
9
|
+
constructor(token, underlying, wrappedTokenExchangeRate) {
|
|
10
|
+
super(token, underlying);
|
|
11
|
+
this.underlying = underlying;
|
|
12
|
+
this.wrappedTokenExchangeRate = wrappedTokenExchangeRate;
|
|
13
|
+
}
|
|
14
|
+
_wrap(amount, rounding) {
|
|
15
|
+
return maths_1.MathLib.wDiv(amount, this.wrappedTokenExchangeRate, rounding);
|
|
16
|
+
}
|
|
17
|
+
_unwrap(amount, rounding) {
|
|
18
|
+
return maths_1.MathLib.wMul(amount, this.wrappedTokenExchangeRate, rounding);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.ExchangeRateWrappedToken = ExchangeRateWrappedToken;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ChainId } from "../chain";
|
|
2
|
+
import { RoundingDirection } from "../maths";
|
|
3
|
+
import { Address } from "../types";
|
|
4
|
+
export interface InputToken {
|
|
5
|
+
address: Address;
|
|
6
|
+
decimals: number;
|
|
7
|
+
symbol: string;
|
|
8
|
+
name?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class Token implements InputToken {
|
|
11
|
+
static native(chainId: ChainId): Token;
|
|
12
|
+
/**
|
|
13
|
+
* The token's address.
|
|
14
|
+
*/
|
|
15
|
+
readonly address: Address;
|
|
16
|
+
/**
|
|
17
|
+
* The token's number of decimals.
|
|
18
|
+
*/
|
|
19
|
+
readonly decimals: number;
|
|
20
|
+
/**
|
|
21
|
+
* The token's symbol.
|
|
22
|
+
*/
|
|
23
|
+
readonly symbol: string;
|
|
24
|
+
/**
|
|
25
|
+
* The name of the token (defaults to the symbol).
|
|
26
|
+
*/
|
|
27
|
+
readonly name: string;
|
|
28
|
+
constructor({ address, decimals, symbol, name }: InputToken);
|
|
29
|
+
}
|
|
30
|
+
export declare class TokenWithPrice extends Token {
|
|
31
|
+
/**
|
|
32
|
+
* Price of the token in USD (scaled by WAD).
|
|
33
|
+
*/
|
|
34
|
+
price?: bigint;
|
|
35
|
+
constructor(token: InputToken, price?: bigint);
|
|
36
|
+
/**
|
|
37
|
+
* Quotes an amount in USD (scaled by WAD) in this token.
|
|
38
|
+
* @param amount The amount of USD to quote.
|
|
39
|
+
*/
|
|
40
|
+
fromUsd(amount: bigint, rounding?: RoundingDirection): bigint | null;
|
|
41
|
+
/**
|
|
42
|
+
* Quotes an amount of tokens in USD (scaled by WAD).
|
|
43
|
+
* @param amount The amount of tokens to quote.
|
|
44
|
+
*/
|
|
45
|
+
toUsd(amount: bigint, rounding?: RoundingDirection): bigint | null;
|
|
46
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TokenWithPrice = exports.Token = void 0;
|
|
4
|
+
const addresses_1 = require("../addresses");
|
|
5
|
+
const chain_1 = require("../chain");
|
|
6
|
+
const maths_1 = require("../maths");
|
|
7
|
+
class Token {
|
|
8
|
+
static native(chainId) {
|
|
9
|
+
const currency = chain_1.ChainUtils.CHAIN_METADATA[chainId].nativeCurrency;
|
|
10
|
+
return new Token({ ...currency, address: addresses_1.NATIVE_ADDRESS });
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The token's address.
|
|
14
|
+
*/
|
|
15
|
+
address;
|
|
16
|
+
/**
|
|
17
|
+
* The token's number of decimals.
|
|
18
|
+
*/
|
|
19
|
+
decimals;
|
|
20
|
+
/**
|
|
21
|
+
* The token's symbol.
|
|
22
|
+
*/
|
|
23
|
+
symbol;
|
|
24
|
+
/**
|
|
25
|
+
* The name of the token (defaults to the symbol).
|
|
26
|
+
*/
|
|
27
|
+
name;
|
|
28
|
+
constructor({ address, decimals, symbol, name }) {
|
|
29
|
+
this.address = address;
|
|
30
|
+
this.decimals = decimals;
|
|
31
|
+
this.symbol = symbol;
|
|
32
|
+
this.name = name ?? symbol;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.Token = Token;
|
|
36
|
+
class TokenWithPrice extends Token {
|
|
37
|
+
/**
|
|
38
|
+
* Price of the token in USD (scaled by WAD).
|
|
39
|
+
*/
|
|
40
|
+
price;
|
|
41
|
+
constructor(token, price) {
|
|
42
|
+
super(token);
|
|
43
|
+
this.price = price;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Quotes an amount in USD (scaled by WAD) in this token.
|
|
47
|
+
* @param amount The amount of USD to quote.
|
|
48
|
+
*/
|
|
49
|
+
fromUsd(amount, rounding = "Down") {
|
|
50
|
+
if (this.price == null)
|
|
51
|
+
return null;
|
|
52
|
+
return maths_1.MathLib.mulDiv(amount, 10n ** BigInt(this.decimals), this.price, rounding);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Quotes an amount of tokens in USD (scaled by WAD).
|
|
56
|
+
* @param amount The amount of tokens to quote.
|
|
57
|
+
*/
|
|
58
|
+
toUsd(amount, rounding = "Down") {
|
|
59
|
+
if (this.price == null)
|
|
60
|
+
return null;
|
|
61
|
+
return maths_1.MathLib.mulDiv(amount, this.price, 10n ** BigInt(this.decimals), rounding);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.TokenWithPrice = TokenWithPrice;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { RoundingDirection } from "../maths";
|
|
2
|
+
import { InputVaultConfig } from "../vault/VaultConfig";
|
|
3
|
+
import { WrappedToken } from "./WrappedToken";
|
|
4
|
+
export declare class VaultToken extends WrappedToken {
|
|
5
|
+
decimalsOffset: bigint;
|
|
6
|
+
totalAssets: bigint;
|
|
7
|
+
totalSupply: bigint;
|
|
8
|
+
constructor(config: InputVaultConfig, { totalAssets, totalSupply }: {
|
|
9
|
+
totalAssets: bigint;
|
|
10
|
+
totalSupply: bigint;
|
|
11
|
+
});
|
|
12
|
+
protected _wrap(amount: bigint, rounding: RoundingDirection): bigint;
|
|
13
|
+
protected _unwrap(amount: bigint, rounding: RoundingDirection): bigint;
|
|
14
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VaultToken = void 0;
|
|
4
|
+
const VaultUtils_1 = require("../vault/VaultUtils");
|
|
5
|
+
const WrappedToken_1 = require("./WrappedToken");
|
|
6
|
+
class VaultToken extends WrappedToken_1.WrappedToken {
|
|
7
|
+
decimalsOffset;
|
|
8
|
+
totalAssets;
|
|
9
|
+
totalSupply;
|
|
10
|
+
constructor(config, { totalAssets, totalSupply }) {
|
|
11
|
+
super(config, config.asset);
|
|
12
|
+
this.totalAssets = totalAssets;
|
|
13
|
+
this.totalSupply = totalSupply;
|
|
14
|
+
this.decimalsOffset = config.decimalsOffset;
|
|
15
|
+
}
|
|
16
|
+
_wrap(amount, rounding) {
|
|
17
|
+
return VaultUtils_1.VaultUtils.toShares(amount, this, this, rounding);
|
|
18
|
+
}
|
|
19
|
+
_unwrap(amount, rounding) {
|
|
20
|
+
return VaultUtils_1.VaultUtils.toAssets(amount, this, this, rounding);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.VaultToken = VaultToken;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { RoundingDirection } from "../maths";
|
|
2
|
+
import { Address } from "../types";
|
|
3
|
+
import { InputToken, Token } from "./Token";
|
|
4
|
+
export declare abstract class WrappedToken extends Token {
|
|
5
|
+
readonly underlying: Address;
|
|
6
|
+
constructor(token: InputToken, underlying: Address);
|
|
7
|
+
/** The expected amount when wrapping `unwrappedAmount` */
|
|
8
|
+
toWrappedExactAmountIn(unwrappedAmount: bigint, slippage?: bigint, rounding?: RoundingDirection): bigint;
|
|
9
|
+
/** The amount of unwrappedTokens that should be wrapped to receive `wrappedAmount` */
|
|
10
|
+
toWrappedExactAmountOut(wrappedAmount: bigint, slippage?: bigint, rounding?: RoundingDirection): bigint;
|
|
11
|
+
/** The expected amount when unwrapping `wrappedAmount` */
|
|
12
|
+
toUnwrappedExactAmountIn(wrappedAmount: bigint, slippage?: bigint, rounding?: RoundingDirection): bigint;
|
|
13
|
+
/** The amount of wrappedTokens that should be unwrapped to receive `unwrappedAmount` */
|
|
14
|
+
toUnwrappedExactAmountOut(unwrappedAmount: bigint, slippage?: bigint, rounding?: RoundingDirection): bigint;
|
|
15
|
+
protected abstract _wrap(amount: bigint, rounding: RoundingDirection): bigint;
|
|
16
|
+
protected abstract _unwrap(amount: bigint, rounding: RoundingDirection): bigint;
|
|
17
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WrappedToken = void 0;
|
|
4
|
+
const maths_1 = require("../maths");
|
|
5
|
+
const Token_1 = require("./Token");
|
|
6
|
+
class WrappedToken extends Token_1.Token {
|
|
7
|
+
underlying;
|
|
8
|
+
constructor(token, underlying) {
|
|
9
|
+
super(token);
|
|
10
|
+
this.underlying = underlying;
|
|
11
|
+
}
|
|
12
|
+
/** The expected amount when wrapping `unwrappedAmount` */
|
|
13
|
+
toWrappedExactAmountIn(unwrappedAmount, slippage = 0n, rounding = "Down") {
|
|
14
|
+
const wrappedAmount = this._wrap(unwrappedAmount, rounding);
|
|
15
|
+
return maths_1.MathLib.wMul(wrappedAmount, maths_1.MathLib.WAD - slippage, "Down");
|
|
16
|
+
}
|
|
17
|
+
/** The amount of unwrappedTokens that should be wrapped to receive `wrappedAmount` */
|
|
18
|
+
toWrappedExactAmountOut(wrappedAmount, slippage = 0n, rounding = "Up") {
|
|
19
|
+
const wAmountTarget = maths_1.MathLib.wDiv(wrappedAmount, maths_1.MathLib.WAD - slippage, rounding);
|
|
20
|
+
return this._unwrap(wAmountTarget, rounding);
|
|
21
|
+
}
|
|
22
|
+
/** The expected amount when unwrapping `wrappedAmount` */
|
|
23
|
+
toUnwrappedExactAmountIn(wrappedAmount, slippage = 0n, rounding = "Down") {
|
|
24
|
+
const unwrappedAmount = this._unwrap(wrappedAmount, rounding);
|
|
25
|
+
return maths_1.MathLib.wMul(unwrappedAmount, maths_1.MathLib.WAD - slippage, "Up");
|
|
26
|
+
}
|
|
27
|
+
/** The amount of wrappedTokens that should be unwrapped to receive `unwrappedAmount` */
|
|
28
|
+
toUnwrappedExactAmountOut(unwrappedAmount, slippage = 0n, rounding = "Up") {
|
|
29
|
+
const unwrappedAmountToTarget = maths_1.MathLib.wDiv(unwrappedAmount, maths_1.MathLib.WAD - slippage, rounding);
|
|
30
|
+
return this._wrap(unwrappedAmountToTarget, rounding);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.WrappedToken = WrappedToken;
|