Skip to content

Commit

Permalink
✨ market: set custom name and symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
itofarina committed Apr 1, 2024
1 parent 9543710 commit 9bd8d2e
Show file tree
Hide file tree
Showing 11 changed files with 334 additions and 265 deletions.
5 changes: 5 additions & 0 deletions .changeset/purple-icons-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@exactly/protocol": patch
---

✨ market: set custom name and symbol
516 changes: 259 additions & 257 deletions .gas-snapshot

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions contracts/Market.sol
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ contract Market is Initializable, AccessControlUpgradeable, PausableUpgradeable,
/// @notice Initializes the contract.
/// @dev can only be called once.
function initialize(
string calldata assetSymbol,
uint8 maxFuturePools_,
uint128 earningsAccumulatorSmoothFactor_,
InterestRateModel interestRateModel_,
Expand All @@ -115,15 +116,13 @@ contract Market is Initializable, AccessControlUpgradeable, PausableUpgradeable,
__AccessControl_init();
__Pausable_init();

string memory assetSymbol = asset.symbol();
name = string.concat("exactly ", assetSymbol);
symbol = string.concat("exa", assetSymbol);
lastAccumulatorAccrual = uint32(block.timestamp);
lastFloatingDebtUpdate = uint32(block.timestamp);
lastAverageUpdate = uint32(block.timestamp);

_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);

setAssetSymbol(assetSymbol);
setMaxFuturePools(maxFuturePools_);
setEarningsAccumulatorSmoothFactor(earningsAccumulatorSmoothFactor_);
setInterestRateModel(interestRateModel_);
Expand Down Expand Up @@ -1038,6 +1037,13 @@ contract Market is Initializable, AccessControlUpgradeable, PausableUpgradeable,
emit FixedEarningsUpdate(block.timestamp, maturity, fixedPools[maturity].unassignedEarnings);
}

/// @notice Sets name and symbol for the Market.
/// @param assetSymbol the symbol for the underlying asset.
function setAssetSymbol(string calldata assetSymbol) public onlyRole(DEFAULT_ADMIN_ROLE) {
name = string.concat("exactly ", assetSymbol);
symbol = string.concat("exa", assetSymbol);
}

/// @notice Sets the rate charged to the fixed depositors that the floating pool suppliers will retain for initially
/// providing liquidity.
/// @param backupFeeRate_ percentage amount represented with 18 decimals.
Expand Down
1 change: 1 addition & 0 deletions deploy/Markets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const func: DeployFunction = async ({
init: {
methodName: "initialize",
args: [
symbol,
finance.futurePools,
earningsAccumulatorSmoothFactor,
ZeroAddress, // irm
Expand Down
2 changes: 2 additions & 0 deletions test/InstallmentsRouter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ contract InstallmentsRouterTest is Test {

market = Market(address(new ERC1967Proxy(address(new Market(usdc, auditor)), "")));
market.initialize(
"USDC.e",
3,
1e18,
InterestRateModel(address(new MockInterestRateModel(0.1e18))),
Expand All @@ -53,6 +54,7 @@ contract InstallmentsRouterTest is Test {

marketWETH = Market(address(new ERC1967Proxy(address(new Market(weth, auditor)), "")));
marketWETH.initialize(
"WETH",
3,
1e18,
InterestRateModel(address(new MockInterestRateModel(0.1e18))),
Expand Down
2 changes: 1 addition & 1 deletion test/InterestRateModel.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ contract InterestRateModelTest is Test {
}),
market
);
market.initialize(2, 2e18, irm, 2e16 / uint256(1 days), 1e17, 0, type(uint128).max, type(uint128).max);
market.initialize("", 2, 2e18, irm, 2e16 / uint256(1 days), 1e17, 0, type(uint128).max, type(uint128).max);
asset.mint(address(this), type(uint128).max);
asset.approve(address(market), type(uint128).max);
if (floatingAssets != 0) market.deposit(floatingAssets, address(this));
Expand Down
29 changes: 28 additions & 1 deletion test/Market.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,23 @@ contract MarketTest is Test {
irm = new MockInterestRateModel(0.1e18);

market = Market(address(new ERC1967Proxy(address(new Market(asset, auditor)), "")));
market.initialize(3, 1e18, InterestRateModel(address(irm)), 0.02e18 / uint256(1 days), 1e17, 0, 0.0046e18, 0.42e18);
market.initialize(
"DAI",
3,
1e18,
InterestRateModel(address(irm)),
0.02e18 / uint256(1 days),
1e17,
0,
0.0046e18,
0.42e18
);
vm.label(address(market), "MarketDAI");
daiPriceFeed = new MockPriceFeed(18, 1e18);

marketWETH = Market(address(new ERC1967Proxy(address(new Market(weth, auditor)), "")));
marketWETH.initialize(
"WETH",
12,
1e18,
InterestRateModel(address(irm)),
Expand Down Expand Up @@ -728,6 +739,7 @@ contract MarketTest is Test {
MockERC20 usdc = new MockERC20("USD Coin", "USDC", 6);
Market marketUSDC = Market(address(new ERC1967Proxy(address(new Market(usdc, auditor)), "")));
marketUSDC.initialize(
"USDC.e",
3,
1e18,
InterestRateModel(address(irm)),
Expand Down Expand Up @@ -2446,6 +2458,7 @@ contract MarketTest is Test {
MockStETH stETH = new MockStETH(1090725952265553962);
Market marketStETH = Market(address(new ERC1967Proxy(address(new Market(stETH, auditor)), "")));
marketStETH.initialize(
"",
3,
1e18,
InterestRateModel(address(irm)),
Expand Down Expand Up @@ -2479,6 +2492,7 @@ contract MarketTest is Test {
MockERC20 wbtc = new MockERC20("WBTC", "WBTC", 8);
Market marketWBTC = Market(address(new ERC1967Proxy(address(new Market(wbtc, auditor)), "")));
marketWBTC.initialize(
"WBTC",
3,
1e18,
InterestRateModel(address(irm)),
Expand Down Expand Up @@ -2515,6 +2529,7 @@ contract MarketTest is Test {
MockERC20 asset = new MockERC20(symbols[i], symbols[i], 18);
markets[i] = Market(address(new ERC1967Proxy(address(new Market(asset, auditor)), "")));
markets[i].initialize(
"",
3,
1e18,
InterestRateModel(address(irm)),
Expand Down Expand Up @@ -2827,6 +2842,18 @@ contract MarketTest is Test {
assertFalse(market.paused());
}

function testSetAssetSymbol() external {
market.setAssetSymbol("TEST");
assertEq(market.symbol(), "exaTEST");
assertEq(market.name(), "exactly TEST");
}

function testSetAssetSymbolNotAdmin() external {
vm.prank(BOB);
vm.expectRevert(bytes(""));
market.setAssetSymbol("TEST");
}

event MarketUpdate(
uint256 timestamp,
uint256 floatingDepositShares,
Expand Down
14 changes: 13 additions & 1 deletion test/Previewer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ contract PreviewerTest is Test {
}),
market
);
market.initialize(12, 1e18, irm, 0.02e18 / uint256(1 days), 0.1e18, 0, 0.0046e18, 0.42e18);
market.initialize("", 12, 1e18, irm, 0.02e18 / uint256(1 days), 0.1e18, 0, 0.0046e18, 0.42e18);
vm.label(address(market), "MarketDAI");
auditor.enableMarket(market, daiPriceFeed, 0.8e18);

Expand Down Expand Up @@ -444,6 +444,7 @@ contract PreviewerTest is Test {
MockERC20 weth = new MockERC20("WETH", "WETH", 18);
Market marketWETH = Market(address(new ERC1967Proxy(address(new Market(weth, auditor)), "")));
marketWETH.initialize(
"",
12,
1e18,
new InterestRateModel(
Expand Down Expand Up @@ -557,6 +558,7 @@ contract PreviewerTest is Test {
MockERC20 weth = new MockERC20("WETH", "WETH", 18);
Market marketWETH = Market(address(new ERC1967Proxy(address(new Market(weth, auditor)), "")));
marketWETH.initialize(
"WETH",
12,
1e18,
new InterestRateModel(
Expand Down Expand Up @@ -707,6 +709,7 @@ contract PreviewerTest is Test {
weth.mint(address(this), 1_000 ether);
Market marketWETH = Market(address(new ERC1967Proxy(address(new Market(weth, auditor)), "")));
marketWETH.initialize(
"WETH",
12,
1e18,
new InterestRateModel(
Expand Down Expand Up @@ -880,6 +883,7 @@ contract PreviewerTest is Test {
MockERC20 weth = new MockERC20("WETH", "WETH", 18);
Market marketWETH = Market(address(new ERC1967Proxy(address(new Market(weth, auditor)), "")));
marketWETH.initialize(
"WETH",
12,
1e18,
new InterestRateModel(
Expand Down Expand Up @@ -1214,6 +1218,7 @@ contract PreviewerTest is Test {
MockERC20 weth = new MockERC20("WETH", "WETH", 18);
Market marketWETH = Market(address(new ERC1967Proxy(address(new Market(weth, auditor)), "")));
marketWETH.initialize(
"WETH",
12,
1e18,
new InterestRateModel(
Expand Down Expand Up @@ -1294,6 +1299,7 @@ contract PreviewerTest is Test {
MockERC20 weth = new MockERC20("WETH", "WETH", 18);
Market marketWETH = Market(address(new ERC1967Proxy(address(new Market(weth, auditor)), "")));
marketWETH.initialize(
"WETH",
12,
1e18,
new InterestRateModel(
Expand Down Expand Up @@ -1346,6 +1352,7 @@ contract PreviewerTest is Test {
MockERC20 weth = new MockERC20("WETH", "WETH", 18);
Market marketWETH = Market(address(new ERC1967Proxy(address(new Market(weth, auditor)), "")));
marketWETH.initialize(
"WETH",
12,
1e18,
new InterestRateModel(
Expand Down Expand Up @@ -1410,6 +1417,7 @@ contract PreviewerTest is Test {
MockERC20 weth = new MockERC20("WETH", "WETH", 18);
Market marketWETH = Market(address(new ERC1967Proxy(address(new Market(weth, auditor)), "")));
marketWETH.initialize(
"WETH",
12,
1e18,
new InterestRateModel(
Expand Down Expand Up @@ -1529,6 +1537,7 @@ contract PreviewerTest is Test {
MockERC20 weth = new MockERC20("WETH", "WETH", 18);
Market marketWETH = Market(address(new ERC1967Proxy(address(new Market(weth, auditor)), "")));
marketWETH.initialize(
"WETH",
12,
1e18,
new InterestRateModel(
Expand Down Expand Up @@ -1578,6 +1587,7 @@ contract PreviewerTest is Test {
MockERC20 weth = new MockERC20("WETH", "WETH", 18);
Market marketWETH = Market(address(new ERC1967Proxy(address(new Market(weth, auditor)), "")));
marketWETH.initialize(
"WETH",
12,
1e18,
new InterestRateModel(
Expand Down Expand Up @@ -1899,6 +1909,7 @@ contract PreviewerTest is Test {
MockERC20 weth = new MockERC20("WETH", "WETH", 18);
Market marketWETH = Market(address(new ERC1967Proxy(address(new Market(weth, auditor)), "")));
marketWETH.initialize(
"WETH",
12,
1e18,
new InterestRateModel(
Expand Down Expand Up @@ -1937,6 +1948,7 @@ contract PreviewerTest is Test {
MockERC20 weth = new MockERC20("WETH", "WETH", 18);
Market marketWETH = Market(address(new ERC1967Proxy(address(new Market(weth, auditor)), "")));
marketWETH.initialize(
"WETH",
12,
1e18,
new InterestRateModel(
Expand Down
2 changes: 1 addition & 1 deletion test/Protocol.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ contract ProtocolTest is Test {
}),
market
);
market.initialize(MAX_FUTURE_POOLS, 2e18, irm, PENALTY_RATE, 1e17, RESERVE_FACTOR, 0.0046e18, 0.42e18);
market.initialize("", MAX_FUTURE_POOLS, 2e18, irm, PENALTY_RATE, 1e17, RESERVE_FACTOR, 0.0046e18, 0.42e18);
vm.label(address(market), string.concat("Market", i.toString()));
MockPriceFeed priceFeed = new MockPriceFeed(18, 1e18);
// market.setTreasury(address(this), 0.1e18);
Expand Down
15 changes: 14 additions & 1 deletion test/RewardsController.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ contract RewardsControllerTest is Test {

marketUSDC = Market(address(new ERC1967Proxy(address(new Market(usdc, auditor)), "")));
marketUSDC.initialize(
"USDC.e",
3,
1e18,
InterestRateModel(address(irm)),
Expand All @@ -58,6 +59,7 @@ contract RewardsControllerTest is Test {

marketWETH = Market(address(new ERC1967Proxy(address(new Market(weth, auditor)), "")));
marketWETH.initialize(
"WETH",
3,
1e18,
InterestRateModel(address(irm)),
Expand All @@ -72,6 +74,7 @@ contract RewardsControllerTest is Test {

marketWBTC = Market(address(new ERC1967Proxy(address(new Market(wbtc, auditor)), "")));
marketWBTC.initialize(
"WBTC",
3,
1e18,
InterestRateModel(address(irm)),
Expand Down Expand Up @@ -1528,7 +1531,17 @@ contract RewardsControllerTest is Test {
MockERC20 rewardAsset = new MockERC20("Reward", "RWD", 10);
MockERC20 asset = new MockERC20("Asset", "AST", 6);
Market market = Market(address(new ERC1967Proxy(address(new Market(asset, auditor)), "")));
market.initialize(3, 1e18, InterestRateModel(address(irm)), 0.02e18 / uint256(1 days), 1e17, 0, 0.0046e18, 0.42e18);
market.initialize(
"AST",
3,
1e18,
InterestRateModel(address(irm)),
0.02e18 / uint256(1 days),
1e17,
0,
0.0046e18,
0.42e18
);
auditor.enableMarket(market, new MockPriceFeed(18, 1e18), 0.8e18);

RewardsController.Config[] memory configs = new RewardsController.Config[](1);
Expand Down
1 change: 1 addition & 0 deletions test/hardhat/defaultEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export class DefaultEnv {
await marketProxy.waitForDeployment();
const market = new Contract(marketProxy.target as string, Market.interface, owner) as unknown as Market;
await market.initialize(
symbol,
12,
parseUnits("1"),
interestRateModel.target,
Expand Down

0 comments on commit 9bd8d2e

Please sign in to comment.