Skip to content

Commit

Permalink
Progress
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenshively committed Sep 21, 2023
1 parent 19fd94f commit 10438ee
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 37 deletions.
28 changes: 14 additions & 14 deletions core/.gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
BorrowerGasTest:test_addMargin() (gas: 16203)
BorrowerGasTest:test_borrow() (gas: 110026)
BorrowerGasTest:test_borrow() (gas: 110015)
BorrowerGasTest:test_getUniswapPositions() (gas: 5219)
BorrowerGasTest:test_modify() (gas: 81623)
BorrowerGasTest:test_modifyWithAnte() (gas: 88078)
BorrowerGasTest:test_modify() (gas: 81612)
BorrowerGasTest:test_modifyWithAnte() (gas: 88067)
BorrowerGasTest:test_repay() (gas: 65245)
BorrowerGasTest:test_uniswapDepositInBorrower() (gas: 257235)
BorrowerGasTest:test_uniswapDepositInBorrower() (gas: 257224)
BorrowerGasTest:test_uniswapDepositStandard() (gas: 167558)
BorrowerGasTest:test_uniswapWithdraw() (gas: 147232)
BorrowerGasTest:test_withdraw() (gas: 105143)
FactoryGasTest:test_createBorrower() (gas: 156525)
FactoryGasTest:test_createMarket() (gas: 3915299)
BorrowerGasTest:test_uniswapWithdraw() (gas: 147224)
BorrowerGasTest:test_withdraw() (gas: 105132)
FactoryGasTest:test_createBorrower() (gas: 156474)
FactoryGasTest:test_createMarket() (gas: 3918370)
LenderGasTest:test_accrueInterest() (gas: 46070)
LenderGasTest:test_borrow() (gas: 40834)
LenderGasTest:test_deposit() (gas: 53422)
LenderGasTest:test_depositWithCourier() (gas: 53568)
LenderGasTest:test_redeem() (gas: 53114)
LenderGasTest:test_redeemWithCourier() (gas: 83487)
LenderGasTest:test_redeemWithCourier() (gas: 83479)
LenderGasTest:test_repay() (gas: 44774)
LiquidatorGasTest:test_noCallbackOneAsset() (gas: 50880)
LiquidatorGasTest:test_noCallbackTwoAssets() (gas: 59061)
LiquidatorGasTest:test_noCallbackTwoAssetsAndUniswapPosition() (gas: 95497)
LiquidatorGasTest:test_warn() (gas: 34363)
LiquidatorGasTest:test_withCallbackAndSwap() (gas: 130045)
LiquidatorGasTest:test_noCallbackOneAsset() (gas: 50869)
LiquidatorGasTest:test_noCallbackTwoAssets() (gas: 59050)
LiquidatorGasTest:test_noCallbackTwoAssetsAndUniswapPosition() (gas: 95488)
LiquidatorGasTest:test_warn() (gas: 34352)
LiquidatorGasTest:test_withCallbackAndSwap() (gas: 130034)
VolatilityGasTest:test_consult() (gas: 43075)
VolatilityGasTest:test_updateNoBinarySearch() (gas: 145980)
10 changes: 5 additions & 5 deletions core/.storage-layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ forge inspect --pretty src/Borrower.sol:Borrower storage-layout
forge inspect --pretty src/Factory.sol:Factory storage-layout
| Name | Type | Slot | Offset | Bytes | Contract |
|---------------|---------------------------------------------------------------|------|--------|-------|-------------------------|
| rewardsToken | contract ERC20 | 0 | 0 | 20 | src/Factory.sol:Factory |
| getMarket | mapping(contract IUniswapV3Pool => struct Factory.Market) | 1 | 0 | 32 | src/Factory.sol:Factory |
| getParameters | mapping(contract IUniswapV3Pool => struct Factory.Parameters) | 2 | 0 | 32 | src/Factory.sol:Factory |
| isLender | mapping(address => bool) | 3 | 0 | 32 | src/Factory.sol:Factory |
| isBorrower | mapping(address => bool) | 4 | 0 | 32 | src/Factory.sol:Factory |
| getMarket | mapping(contract IUniswapV3Pool => struct Factory.Market) | 0 | 0 | 32 | src/Factory.sol:Factory |
| getParameters | mapping(contract IUniswapV3Pool => struct Factory.Parameters) | 1 | 0 | 32 | src/Factory.sol:Factory |
| isLender | mapping(address => bool) | 2 | 0 | 32 | src/Factory.sol:Factory |
| isBorrower | mapping(address => bool) | 3 | 0 | 32 | src/Factory.sol:Factory |
| rewardsToken | contract ERC20 | 4 | 0 | 20 | src/Factory.sol:Factory |
| couriers | mapping(uint32 => struct Factory.Courier) | 5 | 0 | 32 | src/Factory.sol:Factory |
| isCourier | mapping(address => bool) | 6 | 0 | 32 | src/Factory.sol:Factory |

41 changes: 23 additions & 18 deletions core/src/Factory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ contract Factory {

event EnrollCourier(uint32 indexed id, address indexed wallet, uint16 cut);

event SetMarketConfig(IUniswapV3Pool indexed pool, MarketConfig config);

// This `Factory` can create a `Market` for any Uniswap V3 pool
struct Market {
// The `Lender` of `token0` in the Uniswap pool
Expand Down Expand Up @@ -186,7 +188,8 @@ contract Factory {
DEFAULT_RESERVE_FACTOR,
DEFAULT_RATE_MODEL,
DEFAULT_RATE_MODEL
)
),
0
);

emit CreateMarket(pool, lender0, lender1);
Expand Down Expand Up @@ -262,39 +265,41 @@ contract Factory {
lender.setRewardsRate(rate);
}

function governMarketConfig(IUniswapV3Pool pool, MarketConfig memory marketConfig) external {
function governMarketConfig(IUniswapV3Pool pool, MarketConfig memory config) external {
require(msg.sender == GOVERNOR);

require(
// ante: max
(marketConfig.ante <= CONSTRAINT_ANTE_MAX) &&
(config.ante <= CONSTRAINT_ANTE_MAX) &&
// nSigma: min, max
(CONSTRAINT_N_SIGMA_MIN <= marketConfig.nSigma && marketConfig.nSigma <= CONSTRAINT_N_SIGMA_MAX) &&
(CONSTRAINT_N_SIGMA_MIN <= config.nSigma && config.nSigma <= CONSTRAINT_N_SIGMA_MAX) &&
// manipulationThresholdDivisor: min, max
(CONSTRAINT_MANIPULATION_THRESHOLD_DIVISOR_MIN <= marketConfig.manipulationThresholdDivisor &&
marketConfig.manipulationThresholdDivisor <= CONSTRAINT_MANIPULATION_THRESHOLD_DIVISOR_MAX) &&
(CONSTRAINT_MANIPULATION_THRESHOLD_DIVISOR_MIN <= config.manipulationThresholdDivisor &&
config.manipulationThresholdDivisor <= CONSTRAINT_MANIPULATION_THRESHOLD_DIVISOR_MAX) &&
// reserveFactor0: min, max
(CONSTRAINT_RESERVE_FACTOR_MIN <= marketConfig.reserveFactor0 &&
marketConfig.reserveFactor0 <= CONSTRAINT_RESERVE_FACTOR_MAX) &&
(CONSTRAINT_RESERVE_FACTOR_MIN <= config.reserveFactor0 &&
config.reserveFactor0 <= CONSTRAINT_RESERVE_FACTOR_MAX) &&
// reserveFactor1: min, max
(CONSTRAINT_RESERVE_FACTOR_MIN <= marketConfig.reserveFactor1 &&
marketConfig.reserveFactor1 <= CONSTRAINT_RESERVE_FACTOR_MAX),
(CONSTRAINT_RESERVE_FACTOR_MIN <= config.reserveFactor1 &&
config.reserveFactor1 <= CONSTRAINT_RESERVE_FACTOR_MAX),
"Aloe: constraints"
);

_setMarketConfig(pool, marketConfig);
_setMarketConfig(pool, config, getParameters[pool].pausedUntilTime);
}

function _setMarketConfig(IUniswapV3Pool pool, MarketConfig memory marketConfig) private {
function _setMarketConfig(IUniswapV3Pool pool, MarketConfig memory config, uint32 pausedUntilTime) private {
getParameters[pool] = Parameters({
ante: marketConfig.ante,
nSigma: marketConfig.nSigma,
manipulationThresholdDivisor: marketConfig.manipulationThresholdDivisor,
pausedUntilTime: 0
ante: config.ante,
nSigma: config.nSigma,
manipulationThresholdDivisor: config.manipulationThresholdDivisor,
pausedUntilTime: pausedUntilTime
});

Market memory market = getMarket[pool];
market.lender0.setRateModelAndReserveFactor(marketConfig.rateModel0, marketConfig.reserveFactor0);
market.lender1.setRateModelAndReserveFactor(marketConfig.rateModel1, marketConfig.reserveFactor1);
market.lender0.setRateModelAndReserveFactor(config.rateModel0, config.reserveFactor0);
market.lender1.setRateModelAndReserveFactor(config.rateModel1, config.reserveFactor1);

emit SetMarketConfig(pool, config);
}
}

0 comments on commit 10438ee

Please sign in to comment.