Skip to content

Commit

Permalink
🚚 debt-manager: rename leverager and prepare deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
cruzdanilo authored and santichez committed Jun 1, 2023
1 parent 0bc8f01 commit e7a1bb2
Show file tree
Hide file tree
Showing 11 changed files with 162 additions and 152 deletions.
5 changes: 5 additions & 0 deletions .changeset/eighty-apples-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@exactly/protocol": patch
---

🚚 debt-manager: rename leverager
5 changes: 5 additions & 0 deletions .changeset/tidy-points-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@exactly/protocol": patch
---

✨ debt-manager: add rollover functions
80 changes: 40 additions & 40 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -10,51 +10,51 @@ AuditorTest:testEnableMarketAuditorMismatch() (gas: 24805)
AuditorTest:testEnableMarketShouldRevertWithInvalidPriceFeed() (gas: 149281)
AuditorTest:testEnterExitMarket() (gas: 178761)
AuditorTest:testExitMarketOwning() (gas: 177445)
DebtManagerTest:testApproveMaliciousMarket() (gas: 24198)
DebtManagerTest:testApproveMarket() (gas: 56626)
DebtManagerTest:testAvailableLiquidity() (gas: 95129)
DebtManagerTest:testCallReceiveFlashLoanFromAnyAddress() (gas: 25030)
DebtManagerTest:testDeleverage() (gas: 449866)
DebtManagerTest:testDeleverageHalfBorrowPosition() (gas: 488989)
DebtManagerTest:testFixedDeleverage() (gas: 429772)
DebtManagerTest:testFixedRoll() (gas: 515399)
DebtManagerTest:testFixedRollSameMaturityWithThreeLoops() (gas: 394620)
DebtManagerTest:testFixedRollWithAccurateBorrowSlippage() (gas: 693262)
DebtManagerTest:testFixedRollWithAccurateBorrowSlippageWithThreeLoops() (gas: 1026387)
DebtManagerTest:testFixedRollWithAccurateRepaySlippage() (gas: 693033)
DebtManagerTest:testFixedRollWithAccurateRepaySlippageWithThreeLoops() (gas: 1020901)
DebtManagerTest:testFixedToFloatingRoll() (gas: 461239)
DebtManagerTest:testFixedToFloatingRollHigherThanAvailableLiquidity() (gas: 528278)
DebtManagerTest:testFixedToFloatingRollHigherThanAvailableLiquidityWithSlippage() (gas: 722384)
DebtManagerTest:testFixedToFloatingRollHigherThanAvailableLiquidityWithSlippageWithThreeLoops() (gas: 879435)
DebtManagerTest:testFixedToFloatingRollWithAccurateSlippage() (gas: 601833)
DebtManagerTest:testFlashloanFeeGreaterThanZero() (gas: 400913)
DebtManagerTest:testFloatingToFixedRoll() (gas: 506215)
DebtManagerTest:testFloatingToFixedRollHigherThanAvailableLiquidity() (gas: 590990)
DebtManagerTest:testFloatingToFixedRollHigherThanAvailableLiquidityWithSlippage() (gas: 895933)
DebtManagerTest:testFloatingToFixedRollHigherThanAvailableLiquidityWithSlippageWithThreePools() (gas: 1105440)
DebtManagerTest:testFloatingToFixedRollWithAccurateSlippage() (gas: 724440)
DebtManagerTest:testFloatingToFixedRollWithAccurateSlippageWithPreviousPosition() (gas: 675341)
DebtManagerTest:testLateFixedDeleverage() (gas: 471140)
DebtManagerTest:testLateFixedRoll() (gas: 526100)
DebtManagerTest:testLateFixedRollWithThreeLoops() (gas: 707888)
DebtManagerTest:testLateFixedToFloatingRoll() (gas: 470476)
DebtManagerTest:testLateFixedToFloatingRollWithThreeLoops() (gas: 633670)
DebtManagerTest:testLeverage() (gas: 365839)
DebtManagerTest:testLeverageShouldFailWhenHealthFactorNearOne() (gas: 719054)
DebtManagerTest:testLeverageWithAlreadyDepositedAmount() (gas: 394197)
DebtManagerTest:testLeverageWithInvalidBalancerVault() (gas: 2691971)
DebtManagerTest:testMockBalancerVault() (gas: 3727680)
DebtManagerTest:testPartialFixedDeleverage() (gas: 516121)
DebtManagerTest:testPartialFixedRoll() (gas: 578742)
DebtManagerTest:testPartialFixedToFloatingRoll() (gas: 539354)
DebtManagerTest:testPartialLateFixedRoll() (gas: 571121)
DebtManagerTest:testPartialLateFixedToFloatingRoll() (gas: 538008)
InterestRateModelTest:testFixedBorrowRate() (gas: 8089)
InterestRateModelTest:testFloatingBorrowRate() (gas: 6236)
InterestRateModelTest:testMinFixedRate() (gas: 7610)
InterestRateModelTest:testRevertFixedMaxUtilizationLowerThanWad() (gas: 81593)
InterestRateModelTest:testRevertFloatingMaxUtilizationLowerThanWad() (gas: 81681)
LeveragerTest:testApproveMaliciousMarket() (gas: 24198)
LeveragerTest:testApproveMarket() (gas: 56626)
LeveragerTest:testAvailableLiquidity() (gas: 95129)
LeveragerTest:testCallReceiveFlashLoanFromAnyAddress() (gas: 25030)
LeveragerTest:testDeleverage() (gas: 449866)
LeveragerTest:testDeleverageHalfBorrowPosition() (gas: 488989)
LeveragerTest:testFixedDeleverage() (gas: 429772)
LeveragerTest:testFixedRoll() (gas: 515399)
LeveragerTest:testFixedRollSameMaturityWithThreeLoops() (gas: 394620)
LeveragerTest:testFixedRollWithAccurateBorrowSlippage() (gas: 693262)
LeveragerTest:testFixedRollWithAccurateBorrowSlippageWithThreeLoops() (gas: 1026387)
LeveragerTest:testFixedRollWithAccurateRepaySlippage() (gas: 693033)
LeveragerTest:testFixedRollWithAccurateRepaySlippageWithThreeLoops() (gas: 1020901)
LeveragerTest:testFixedToFloatingRoll() (gas: 461239)
LeveragerTest:testFixedToFloatingRollHigherThanAvailableLiquidity() (gas: 528278)
LeveragerTest:testFixedToFloatingRollHigherThanAvailableLiquidityWithSlippage() (gas: 722384)
LeveragerTest:testFixedToFloatingRollHigherThanAvailableLiquidityWithSlippageWithThreeLoops() (gas: 879435)
LeveragerTest:testFixedToFloatingRollWithAccurateSlippage() (gas: 601833)
LeveragerTest:testFlashloanFeeGreaterThanZero() (gas: 400913)
LeveragerTest:testFloatingToFixedRoll() (gas: 506215)
LeveragerTest:testFloatingToFixedRollHigherThanAvailableLiquidity() (gas: 590990)
LeveragerTest:testFloatingToFixedRollHigherThanAvailableLiquidityWithSlippage() (gas: 895933)
LeveragerTest:testFloatingToFixedRollHigherThanAvailableLiquidityWithSlippageWithThreePools() (gas: 1105440)
LeveragerTest:testFloatingToFixedRollWithAccurateSlippage() (gas: 724440)
LeveragerTest:testFloatingToFixedRollWithAccurateSlippageWithPreviousPosition() (gas: 675341)
LeveragerTest:testLateFixedDeleverage() (gas: 471140)
LeveragerTest:testLateFixedRoll() (gas: 526100)
LeveragerTest:testLateFixedRollWithThreeLoops() (gas: 707888)
LeveragerTest:testLateFixedToFloatingRoll() (gas: 470476)
LeveragerTest:testLateFixedToFloatingRollWithThreeLoops() (gas: 633670)
LeveragerTest:testLeverage() (gas: 365839)
LeveragerTest:testLeverageShouldFailWhenHealthFactorNearOne() (gas: 719054)
LeveragerTest:testLeverageWithAlreadyDepositedAmount() (gas: 394197)
LeveragerTest:testLeverageWithInvalidBalancerVault() (gas: 2691971)
LeveragerTest:testMockBalancerVault() (gas: 3727680)
LeveragerTest:testPartialFixedDeleverage() (gas: 516121)
LeveragerTest:testPartialFixedRoll() (gas: 578742)
LeveragerTest:testPartialFixedToFloatingRoll() (gas: 539354)
LeveragerTest:testPartialLateFixedRoll() (gas: 571121)
LeveragerTest:testPartialLateFixedToFloatingRoll() (gas: 538008)
MarketTest:testAccountLiquidityAdjustedDebt() (gas: 380765)
MarketTest:testAnotherUserRedeemWhenOwnerHasShortfall() (gas: 483813)
MarketTest:testAnotherUserWithdrawWhenOwnerHasShortfall() (gas: 472690)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { FixedPointMathLib } from "solmate/src/utils/FixedPointMathLib.sol";
import { Auditor, MarketNotListed } from "../Auditor.sol";
import { Market, ERC4626, FixedLib, Disagreement } from "../Market.sol";

/// @title Leverager
/// @title DebtManager
/// @notice Contract that leverages and deleverages the floating position of accounts interacting with Exactly Protocol.
contract Leverager {
contract DebtManager {
using FixedPointMathLib for uint256;
using SafeTransferLib for ERC20;
using FixedLib for FixedLib.Pool;
Expand Down
9 changes: 4 additions & 5 deletions deploy/Leverager.ts → deploy/DebtManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@ const func: DeployFunction = async ({ deployments: { deploy, get }, getNamedAcco
]);

await tenderlify(
"Leverager",
await deploy("Leverager", {
skipIfAlreadyDeployed: !JSON.parse(env.DEPLOY_LEVERAGER ?? "false"),
"DebtManager",
await deploy("DebtManager", {
skipIfAlreadyDeployed: !JSON.parse(env.DEPLOY_DEBT_MANAGER ?? "false"),
args: [auditor, balancerVault],
from: deployer,
log: true,
}),
);
};

func.tags = ["Leverager"];
func.tags = ["DebtManager"];
func.dependencies = ["Auditor", "Markets", "BalancerVault"];
func.skip = async ({ network }) => !network.config.leverager;

export default func;
12 changes: 6 additions & 6 deletions deploy/Markets.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { env } from "process";
import type { DeployFunction } from "hardhat-deploy/types";
import type { Auditor, ERC20, Leverager, Market, RewardsController } from "../types";
import type { Auditor, ERC20, DebtManager, Market, RewardsController } from "../types";
import { mockPrices } from "./mocks/Assets";
import transferOwnership from "./.utils/transferOwnership";
import executeOrPropose from "./.utils/executeOrPropose";
Expand All @@ -22,10 +22,10 @@ const func: DeployFunction = async ({
deployments: { deploy, get },
getNamedAccounts,
}) => {
const [rewards, leverager, auditor, { address: timelock }, { deployer, multisig, treasury = AddressZero }] =
const [rewards, debtManager, auditor, { address: timelock }, { deployer, multisig, treasury = AddressZero }] =
await Promise.all([
getContractOrNull<RewardsController>("RewardsController"),
getContractOrNull<Leverager>("Leverager"),
getContractOrNull<DebtManager>("DebtManager"),
getContract<Auditor>("Auditor"),
get("TimelockController"),
getNamedAccounts(),
Expand Down Expand Up @@ -167,11 +167,11 @@ const func: DeployFunction = async ({
}

if (
leverager &&
debtManager &&
(await auditor.allMarkets()).includes(market.address) &&
(await asset.allowance(leverager.address, market.address)).isZero()
(await asset.allowance(debtManager.address, market.address)).isZero()
) {
await (await leverager.approve(market.address)).wait();
await (await debtManager.approve(market.address)).wait();
}

await grantRole(market, await market.PAUSER_ROLE(), multisig);
Expand Down
18 changes: 8 additions & 10 deletions deploy/mocks/BalancerVault.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import type { DeployFunction } from "hardhat-deploy/types";
import Leverager from "../Leverager";

const func: DeployFunction = async ({
ethers: {
constants: { AddressZero },
},
deployments: { getOrNull, save },
network: { live },
}) => {
if (!(await getOrNull("BalancerVault")) && !live) await save("BalancerVault", { address: AddressZero, abi: [] });
const func: DeployFunction = async ({ deployments: { deploy }, getNamedAccounts }) => {
const { deployer } = await getNamedAccounts();
await deploy("BalancerVault", {
skipIfAlreadyDeployed: true,
contract: "MockBalancerVault",
from: deployer,
log: true,
});
};

func.tags = ["BalancerVault"];
func.skip = Leverager.skip;

export default func;
3 changes: 3 additions & 0 deletions deployments/mainnet/BalancerVault.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"address": "0xBA12222222228d8Ba445958a75a0704d566BF2C8"
}
7 changes: 2 additions & 5 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default {
},
networks: {
mainnet: { priceDecimals: 18, timelockDelay: 24 * 3_600, url: env.MAINNET_NODE ?? "", finance: { futurePools: 3 } },
optimism: { priceDecimals: 8, timelockDelay: 24 * 3_600, url: env.OPTIMISM_NODE ?? "", leverager: true },
optimism: { priceDecimals: 8, timelockDelay: 24 * 3_600, url: env.OPTIMISM_NODE ?? "" },
goerli: { priceDecimals: 8, url: env.GOERLI_NODE ?? "" },
},
namedAccounts: {
Expand Down Expand Up @@ -155,7 +155,7 @@ extendConfig((hardhatConfig, { finance }) => {
if (live) {
networkConfig.safeTxService = `https://safe-transaction-${networkName}.safe.global`;
if (env.MNEMONIC) networkConfig.accounts = { ...defaultHdAccountsConfigParams, mnemonic: env.MNEMONIC };
} else Object.assign(networkConfig, { priceDecimals: 8, allowUnlimitedContractSize: true, leverager: true });
} else Object.assign(networkConfig, { priceDecimals: 8, allowUnlimitedContractSize: true });
networkConfig.finance = {
...finance,
...networkConfig.finance,
Expand Down Expand Up @@ -233,22 +233,19 @@ declare module "hardhat/types/config" {
export interface HttpNetworkUserConfig {
priceDecimals: number;
timelockDelay?: number;
leverager?: boolean;
finance?: Partial<FinanceConfig>;
}

export interface HardhatNetworkConfig {
priceDecimals: number;
timelockDelay: undefined;
leverager: boolean;
safeTxService: undefined;
finance: FinanceConfig;
}

export interface HttpNetworkConfig {
priceDecimals: number;
timelockDelay?: number;
leverager?: boolean;
safeTxService: string;
finance: FinanceConfig;
}
Expand Down
19 changes: 11 additions & 8 deletions test/20_leverager.ts → test/20_debt_manager.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
import { expect } from "chai";
import { ethers, deployments } from "hardhat";
import type { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import type { Market, Leverager, ERC20 } from "../types";
import type { Market, DebtManager, ERC20 } from "../types";

describe("Leverager", function () {
describe("DebtManager", function () {
let usdc: ERC20;
let marketUSDC: Market;
let leverager: Leverager;
let debtManager: DebtManager;
let alice: SignerWithAddress;

before(async () => {
[alice] = await ethers.getUnnamedSigners();
});

beforeEach(async () => {
await deployments.fixture("Leverager");
await deployments.fixture("DebtManager");
usdc = await ethers.getContract<ERC20>("USDC");
marketUSDC = await ethers.getContract<Market>("MarketUSDC");
leverager = await ethers.getContract<Leverager>("Leverager", alice);
debtManager = await ethers.getContract<DebtManager>("DebtManager", alice);
});

describe("GIVEN an approval of the MarketUSDC to spend USDC from the leverage contract", () => {
it("THEN the tx should emit Approval", async () => {
await expect(leverager.approve(marketUSDC.address))
await expect(debtManager.approve(marketUSDC.address))
.to.emit(usdc, "Approval")
.withArgs(leverager.address, marketUSDC.address, ethers.constants.MaxUint256);
.withArgs(debtManager.address, marketUSDC.address, ethers.constants.MaxUint256);
});
});
describe("AND GIVEN an approval of an invalid address to spend USDC from the leverage contract", () => {
it("THEN the tx should revert", async () => {
await expect(leverager.approve(leverager.address)).to.be.revertedWithCustomError(leverager, "MarketNotListed");
await expect(debtManager.approve(debtManager.address)).to.be.revertedWithCustomError(
debtManager,
"MarketNotListed",
);
});
});
});
Loading

0 comments on commit e7a1bb2

Please sign in to comment.