@@ -80,8 +80,10 @@
|
|
80
80
|
/// @notice Create a pToken and activate it on Euler. pTokens are protected wrappers around assets that prevent borrowing.
|
81
81
|
/// @param underlying The address of an ERC20-compliant token. There must already be an activated market on Euler for this underlying, and it must have a non-zero collateral factor.
|
82
82
|
/// @return The created pToken, or an existing one if already activated.
|
83
83
|
function activatePToken(address underlying) external nonReentrant returns (address) {
|
84
|
+
require(pTokenLookup[underlying] == address(0), "e/nested-ptoken");
|
85
|
+
|
84
86
|
if (reversePTokenLookup[underlying] != address(0)) return reversePTokenLookup[underlying];
|
85
87
|
|
86
88
|
{
|
87
89
|
AssetConfig memory config = resolveAssetConfig(underlying);
|
@@ -441,13 +441,13 @@
|
|
441
441
|
|
442
442
|
if (owed > prevOwed) {
|
443
443
|
uint change = owed - prevOwed;
|
444
444
|
emit Borrow(assetCache.underlying, account, change);
|
445
|
-
emitViaProxy_Transfer(dTokenAddress, address(0), account, change);
|
445
|
+
emitViaProxy_Transfer(dTokenAddress, address(0), account, change / assetCache.underlyingDecimalsScaler);
|
446
446
|
} else if (prevOwed > owed) {
|
447
447
|
uint change = prevOwed - owed;
|
448
448
|
emit Repay(assetCache.underlying, account, change);
|
449
|
-
emitViaProxy_Transfer(dTokenAddress, account, address(0), change);
|
449
|
+
emitViaProxy_Transfer(dTokenAddress, account, address(0), change / assetCache.underlyingDecimalsScaler);
|
450
450
|
}
|
451
451
|
}
|
452
452
|
|
453
453
|
function increaseBorrow(AssetStorage storage assetStorage, AssetCache memory assetCache, address dTokenAddress, address account, uint amount) internal {
|
@@ -497,9 +497,9 @@
|
|
497
497
|
|
498
498
|
if (toOwed == 0) doEnterMarket(to, assetCache.underlying);
|
499
499
|
|
500
500
|
// If amount was rounded up, transfer exact amount owed
|
501
|
-
if (amount > fromOwed && amount - fromOwed < INTERNAL_DEBT_PRECISION) amount = fromOwed;
|
501
|
+
if (amount > fromOwed && amount - fromOwed < INTERNAL_DEBT_PRECISION * assetCache.underlyingDecimalsScaler) amount = fromOwed;
|
502
502
|
|
503
503
|
require(fromOwed >= amount, "e/insufficient-balance");
|
504
504
|
unchecked { fromOwed -= amount; }
|
505
505
|
|
@@ -27,11 +27,11 @@
|
|
27
27
|
}
|
28
28
|
|
29
29
|
function getNewMarketParameters(address underlying) external returns (NewMarketParameters memory);
|
30
30
|
|
31
|
-
function requireLiquidity(address account) external;
|
32
|
-
function computeLiquidity(address account) external returns (LiquidityStatus memory status);
|
33
|
-
function computeAssetLiquidities(address account) external returns (AssetLiquidity[] memory assets);
|
31
|
+
function requireLiquidity(address account) external view;
|
32
|
+
function computeLiquidity(address account) external view returns (LiquidityStatus memory status);
|
33
|
+
function computeAssetLiquidities(address account) external view returns (AssetLiquidity[] memory assets);
|
34
34
|
|
35
|
-
function getPrice(address underlying) external returns (uint twap, uint twapPeriod);
|
36
|
-
function getPriceFull(address underlying) external returns (uint twap, uint twapPeriod, uint currPrice);
|
35
|
+
function getPrice(address underlying) external view returns (uint twap, uint twapPeriod);
|
36
|
+
function getPriceFull(address underlying) external view returns (uint twap, uint twapPeriod, uint currPrice);
|
37
37
|
}
|
@@ -22,24 +22,16 @@
|
|
22
22
|
// Accessing parameters
|
23
23
|
|
24
24
|
function unpackTrailingParamMsgSender() internal pure returns (address msgSender) {
|
25
25
|
assembly {
|
26
|
-
|
27
|
-
|
28
|
-
calldatacopy(12, sub(calldatasize(), 40), 20)
|
29
|
-
msgSender := mload(0)
|
26
|
+
msgSender := shr(96, calldataload(sub(calldatasize(), 40)))
|
30
27
|
}
|
31
28
|
}
|
32
29
|
|
33
30
|
function unpackTrailingParams() internal pure returns (address msgSender, address proxyAddr) {
|
34
31
|
assembly {
|
35
|
-
|
36
|
-
|
37
|
-
calldatacopy(12, sub(calldatasize(), 40), 20)
|
38
|
-
msgSender := mload(0)
|
39
|
-
|
40
|
-
calldatacopy(12, sub(calldatasize(), 20), 20)
|
41
|
-
proxyAddr := mload(0)
|
32
|
+
msgSender := shr(96, calldataload(sub(calldatasize(), 40)))
|
33
|
+
proxyAddr := shr(96, calldataload(sub(calldatasize(), 20)))
|
42
34
|
}
|
43
35
|
}
|
44
36
|
|
45
37
|
|
@@ -18,8 +18,14 @@
|
|
18
18
|
function transfer(address to, uint value) external returns (bool);
|
19
19
|
function transferFrom(address from, address to, uint value) external returns (bool);
|
20
20
|
}
|
21
21
|
|
22
|
+
interface IERC20Permit {
|
23
|
+
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
|
24
|
+
function permit(address holder, address spender, uint256 nonce, uint256 expiry, bool allowed, uint8 v, bytes32 r, bytes32 s) external;
|
25
|
+
function permit(address owner, address spender, uint value, uint deadline, bytes calldata signature) external;
|
26
|
+
}
|
27
|
+
|
22
28
|
interface IERC3156FlashBorrower {
|
23
29
|
function onFlashLoan(address initiator, address token, uint256 amount, uint256 fee, bytes calldata data) external returns (bytes32);
|
24
30
|
}
|
25
31
|
|
@@ -52,8 +52,15 @@
|
|
52
52
|
modifier reentrantOK() { // documentation only
|
53
53
|
_;
|
54
54
|
}
|
55
55
|
|
56
|
+
// Used to flag functions which do not modify storage, but do perform a delegate call
|
57
|
+
// to a view function, which prohibits a standard view modifier. The flag is used to
|
58
|
+
// patch state mutability in compiled ABIs and interfaces.
|
59
|
+
modifier staticDelegate() {
|
60
|
+
_;
|
61
|
+
}
|
62
|
+
|
56
63
|
// WARNING: Must be very careful with this modifier. It resets the free memory pointer
|
57
64
|
// to the value it was when the function started. This saves gas if more memory will
|
58
65
|
// be allocated in the future. However, if the memory will be later referenced
|
59
66
|
// (for example because the function has returned a pointer to it) then you cannot
|
@@ -20,11 +20,12 @@
|
|
20
20
|
uint internal constant RESERVE_FEE_SCALE = 4_000_000_000; // must fit into a uint32
|
21
21
|
uint32 internal constant DEFAULT_RESERVE_FEE = uint32(0.23 * 4_000_000_000);
|
22
22
|
uint internal constant INITIAL_INTEREST_ACCUMULATOR = 1e27;
|
23
23
|
uint internal constant AVERAGE_LIQUIDITY_PERIOD = 24 * 60 * 60;
|
24
|
-
uint16 internal constant MIN_UNISWAP3_OBSERVATION_CARDINALITY =
|
24
|
+
uint16 internal constant MIN_UNISWAP3_OBSERVATION_CARDINALITY = 144;
|
25
25
|
uint24 internal constant DEFAULT_TWAP_WINDOW_SECONDS = 30 * 60;
|
26
26
|
uint32 internal constant DEFAULT_BORROW_FACTOR = uint32(0.28 * 4_000_000_000);
|
27
|
+
uint32 internal constant SELF_COLLATERAL_FACTOR = uint32(0.95 * 4_000_000_000);
|
27
28
|
|
28
29
|
|
29
30
|
// Implementation internals
|
30
31
|
|
@@ -74,12 +75,16 @@
|
|
74
75
|
// Classes
|
75
76
|
uint internal constant MODULEID__IRM_CLASS__STABLE = 2_000_500;
|
76
77
|
uint internal constant MODULEID__IRM_CLASS__MAJOR = 2_000_501;
|
77
78
|
uint internal constant MODULEID__IRM_CLASS__MIDCAP = 2_000_502;
|
79
|
+
uint internal constant MODULEID__IRM_CLASS__MEGA = 2_000_503;
|
78
80
|
|
79
81
|
// Swap types
|
80
82
|
uint internal constant SWAP_TYPE__UNI_EXACT_INPUT_SINGLE = 1;
|
81
83
|
uint internal constant SWAP_TYPE__UNI_EXACT_INPUT = 2;
|
82
84
|
uint internal constant SWAP_TYPE__UNI_EXACT_OUTPUT_SINGLE = 3;
|
83
85
|
uint internal constant SWAP_TYPE__UNI_EXACT_OUTPUT = 4;
|
84
86
|
uint internal constant SWAP_TYPE__1INCH = 5;
|
87
|
+
|
88
|
+
uint internal constant SWAP_TYPE__UNI_EXACT_OUTPUT_SINGLE_REPAY = 6;
|
89
|
+
uint internal constant SWAP_TYPE__UNI_EXACT_OUTPUT_REPAY = 7;
|
85
90
|
}
|