Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding more vaults and param updates #723

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
6f9eb76
feat(protocol): vault maticxusdc-1 polygon add compoundv3 and adjust …
0xdcota Aug 16, 2023
67e9a06
feat(protocol): add weth-dai vault on ethmainnet with spark and morphos
0xdcota Aug 17, 2023
c7aa2f8
feat(protocol): add weth-dai and wbtc-dai on gnosis with agave
0xdcota Aug 17, 2023
1f8f7e0
fix(protocol): rebalancer handle diff when borrowingvault only assets
0xdcota Aug 17, 2023
28b1120
fix(protocol): rebalancer add check msg.sender as allowed flasher
0xdcota Aug 17, 2023
c2e1517
refactor(protocol): rebalancer add hardreset for entrypoint by timelock
0xdcota Aug 17, 2023
b4be90a
test(protocol): new rebalancer functions for only asset rebal in borr…
0xdcota Aug 17, 2023
4628763
chore(protocol): deploy new rebalancer all chains
0xdcota Aug 19, 2023
7bf900f
Merge pull request #722 from Fujicracy/protocol/fix/rebalancer-manage…
pedrovalido Aug 22, 2023
9b6fb53
feat(protocol): add usdt to vault config to arbitrum
0xdcota Aug 22, 2023
b921209
feat(protocol): add usdt to vault configs to eth mainnet
0xdcota Aug 22, 2023
c89b8aa
feat(protocol): add usdt to vault config to optimism
0xdcota Aug 22, 2023
55b9791
feat(protocol): add usdt to vault config to polygon
0xdcota Aug 22, 2023
82868f4
feat(protocol): add wmatic borrow-asset vault config to polygon
0xdcota Aug 22, 2023
8e5f08a
chore(frontend): uncomment vault with morphos now fixed onchain
0xdcota Aug 22, 2023
2d4135e
Merge branch 'protocol/feat/more-vaults-matic-wbtc-and-updates' of ht…
0xdcota Aug 22, 2023
c09c123
feat(protocol): add deploy config wbtc-usdc on gnosis
0xdcota Aug 23, 2023
cc946d7
feat(protocol): staked matic lst vaults polygon config
0xdcota Aug 23, 2023
cc7a7ce
chore(protocol): remove wsteth usdt vault with morphos from eth mainn…
0xdcota Aug 23, 2023
0b817e2
feat(protocol): deployed weth vaults for dai and usdt borrow asset al…
0xdcota Aug 24, 2023
f5bc078
chore(protocol): removed gnosis unused wbtc vault
0xdcota Aug 24, 2023
64f24f7
feat(protocol): gnosis wbtc vaults with beacon proxy
0xdcota Aug 24, 2023
537418d
feat(protocol): deployed lst matic vaults
0xdcota Aug 24, 2023
bf6c700
chore(sdk): add wbtc address
0xdcota Aug 24, 2023
b9bc8d9
chore(sdk): add wbtc and stmatic tokens
0xdcota Aug 24, 2023
ccb3c50
chore(sdk): add new set of borrowing vaults (wbtc collat, usdt borrow…
0xdcota Aug 24, 2023
9a5ab50
fix(sdk): xdai borrowing vaults
ferostabio Aug 24, 2023
d6963ab
Merge branch 'main' into protocol/feat/more-vaults-matic-wbtc-and-upd…
0xdcota Aug 25, 2023
18199ff
fix(sdk): all -> tryAll for rates
ferostabio Aug 25, 2023
ecd7701
fix(protocol): eth mainnet deployment config error in mapper for a-us…
0xdcota Aug 25, 2023
2d9750f
Merge branch 'protocol/feat/more-vaults-matic-wbtc-and-updates' of ht…
0xdcota Aug 25, 2023
1e99c2d
chore(protocol): add gnosis missing deployed borrowing vault wsteth-usdc
0xdcota Aug 25, 2023
ab9b99b
chore(frontend): stmatic logo
ferostabio Aug 28, 2023
3f02348
fix(sdk): addresses of the new vaults
brozorec Aug 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions packages/protocol/deploy-configs/arbitrum.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@
"providers": ["Aave_V3_Arbitrum", "Compound_V3_Arbitrum", "DForce_Arbitrum"],
"rating": 80
},
{
"collateral": "WETH",
"debt": "USDT",
"liqRatio": 820000000000000000,
"maxLtv": 780000000000000000,
"name": "BorrowingVault-WETHUSDT-1",
"providers": ["Aave_V3_Arbitrum", "DForce_Arbitrum"],
"rating": 80
},
{
"collateral": "WETH",
"debt": "DAI",
Expand Down
22 changes: 20 additions & 2 deletions packages/protocol/deploy-configs/ethereum.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
},
{
"asset": "USDT",
"market": "0x71fc860F7D3A592A4a98740e39dB31d25db65ae8",
"market": "0x3Ed3B47Dd13EC9a98b44e6204A523E766B225811",
"name": "Aave_V2"
}
],
Expand Down Expand Up @@ -194,7 +194,25 @@
"liqRatio": 820000000000000000,
"maxLtv": 780000000000000000,
"name": "BorrowingVault-WETHUSDC-3",
"providers": ["Morpho_Compound", "Morpho_Aave_V2"],
"providers": ["Morpho_Aave_V2","Morpho_Compound","Compound_V3"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting: space after the comma

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed that, though I just ran the standard json formatting and it breaks the providers like this:

{
      "collateral": "WETH",
      "debt": "USDC",
      "liqRatio": 820000000000000000,
      "maxLtv": 780000000000000000,
      "name": "BorrowingVault-WETHUSDC-3",
      "providers": [
        "Morpho_Aave_V2",
        "Morpho_Compound",
        "Compound_V3"
      ],
      "rating": 85
    },

Would this be ok?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if yes 👍, I will run it in all deploy-configs.

"rating": 85
},
{
"collateral": "WETH",
"debt": "USDT",
"liqRatio": 820000000000000000,
"maxLtv": 780000000000000000,
"name": "BorrowingVault-WETHUSDT-1",
"providers": ["Morpho_Aave_V2","Morpho_Compound"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting: space after the comma

"rating": 85
},
{
"collateral": "WETH",
"debt": "DAI",
"liqRatio": 820000000000000000,
"maxLtv": 800000000000000000,
"name": "BorrowingVault-WETHDAI-1",
"providers": ["Spark","Morpho_Compound", "Morpho_Aave_V2"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting: space after the comma

"rating": 85
},
{
Expand Down
27 changes: 27 additions & 0 deletions packages/protocol/deploy-configs/gnosis.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,33 @@
"name": "BorrowingVault-WSTETGNO-1",
"providers": ["Agave_Gnosis"],
"rating": 75
},
{
"collateral": "WETH",
"debt": "DAI",
"liqRatio": 800000000000000000,
"maxLtv": 750000000000000000,
"name": "BorrowingVault-WETHDAI-1",
"providers": ["Agave_Gnosis"],
"rating": 80
},
{
"collateral": "WBTC",
"debt": "USDC",
"liqRatio": 750000000000000000,
"maxLtv": 700000000000000000,
"name": "BorrowingVault-WBTCUSDC-1",
"providers": ["Agave_Gnosis"],
"rating": 80
},
{
"collateral": "WBTC",
"debt": "DAI",
"liqRatio": 750000000000000000,
"maxLtv": 700000000000000000,
"name": "BorrowingVault-WBTCDAI-1",
"providers": ["Agave_Gnosis"],
"rating": 80
}
],
"yield-vaults": [
Expand Down
9 changes: 9 additions & 0 deletions packages/protocol/deploy-configs/optimism.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@
"providers": ["DForce_Optimism", "Aave_V3_Optimism"],
"rating": 90
},
{
"collateral": "WETH",
"debt": "USDT",
"liqRatio": 820000000000000000,
"maxLtv": 800000000000000000,
"name": "BorrowingVault-WETHUSDT-1",
"providers": ["DForce_Optimism", "Aave_V3_Optimism"],
"rating": 80
},
{
"collateral": "WETH",
"debt": "DAI",
Expand Down
42 changes: 39 additions & 3 deletions packages/protocol/deploy-configs/polygon.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@
{
"collateral": "MATICX",
"debt": "USDC",
"liqRatio": 670000000000000000,
"maxLtv": 560000000000000000,
"liqRatio": 600000000000000000,
"maxLtv": 550000000000000000,
"name": "BorrowingVault-MATICXUSDC-1",
"providers": ["Aave_V3_Polygon"],
"providers": ["Aave_V3_Polygon","Compound_V3_Polygon"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting: space after the comma

"rating": 90
},
{
Expand Down Expand Up @@ -136,6 +136,42 @@
"name": "BorrowingVault-WETHDAI-2",
"providers": ["DForce_Polygon", "Aave_V2_Polygon", "Aave_V3_Polygon"],
"rating": 85
},
{
"collateral": "WETH",
"debt": "USDT",
"liqRatio": 820000000000000000,
"maxLtv": 800000000000000000,
"name": "BorrowingVault-WETHUSDT-1",
"providers": ["Aave_V2_Polygon", "Aave_V3_Polygon","DForce_Polygon"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting: space after the comma

"rating": 85
},
{
"collateral": "MATICX",
"debt": "WMATIC",
"liqRatio": 940000000000000000,
"maxLtv": 920000000000000000,
"name": "BorrowingVault-MATICXWMATIC-1",
"providers": ["Aave_V3_Polygon"],
"rating": 95
},
{
"collateral": "STMATIC",
"debt": "WMATIC",
"liqRatio": 940000000000000000,
"maxLtv": 920000000000000000,
"name": "BorrowingVault-STMATICWMATIC-1",
"providers": ["Aave_V3_Polygon"],
"rating": 95
},
{
"collateral": "STMATIC",
"debt": "MATICX",
"liqRatio": 940000000000000000,
"maxLtv": 920000000000000000,
"name": "BorrowingVault-STMATICMATICX-1",
"providers": ["Aave_V3_Polygon"],
"rating": 95
}
],
"yield-vaults": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x404CE931E95Bd8B53433e5f96e0F678f3C8bee9A
brozorec marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion packages/protocol/deployments/arbitrum/RebalancerManager
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0x3C4a35203013C26220281B425052A069c54bB0f4
0xc60BC5a846BE0312A25f7628fF505C774A43FEA2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x997102a0eC576a71B91B673eDfb673B3b2Ee922A
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x442Ff33a7759e3a82AaD380876Ea1B9D26997fCD
2 changes: 1 addition & 1 deletion packages/protocol/deployments/ethereum/RebalancerManager
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0xA2A7c7DC114765B21E7D167d9665D3992152E6d9
0x229195fE6CdB876eD7D55f939b5695e27B3cB425
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x2f4F37f06179d0e969D2350beE8ABe663De0dab7

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0xe3298F965553b4aeF40fBe4BBa916DEc12F3d694
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x848bE4352c984173D1927239f1c3a2b3FC3baf7b
2 changes: 1 addition & 1 deletion packages/protocol/deployments/gnosis/RebalancerManager
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0xD4444B5c9f2fD888AdCA17673056F4497E526448
0x1C3378782be2a268627194C95A06535e8945F618
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x2EDaEecDA025579be8A0B4E0C77401bB5a56f26A
brozorec marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion packages/protocol/deployments/optimism/RebalancerManager
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0x82a2646400032eaa9C32022F7b1d4335E1789F85
0x079bE6D395F6fF0090F5bdC20b4B618590A81b5D
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0xFcA5b6897Aa76e475a69F166c0a738541a0F22a0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x18534C6ed4c46bC1A3755aC8A2B218447f625528
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x0358734be360822845Db69d41781Bf3f4d71F5E9
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x0660a711812BE76C61ec704A1D39Fc9612dEAff9
2 changes: 1 addition & 1 deletion packages/protocol/deployments/polygon/RebalancerManager
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0x656337719FD1FD94914962f3752f6d04d437d62f
0x8aCc490C1c110fF070539e9fb283168412849292
48 changes: 40 additions & 8 deletions packages/protocol/src/RebalancerManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,28 @@ contract RebalancerManager is IRebalancerManager, SystemAccessControl {
}
vault.rebalance(assets, 0, from, to, 0, setToAsActiveProvider);
} else {
// BorrowingVault
if (debt == type(uint256).max) {
debt = from.getBorrowBalance(address(vault), vault);
}

// BorrowingVault
if (assets == 0 && debt == 0) {
// Should at least move some assets or debt across providers.
revert RebalancerManager__rebalanceVault_invalidAmount();
}
_checkDebtAmount(vault, debt, from);
if (!chief.allowedFlasher(address(flasher))) {
revert RebalancerManager__rebalanceVault_notValidFlasher();

if (debt == 0) {
// Rebalance only assets do not require flashloan
vault.rebalance(assets, 0, from, to, 0, setToAsActiveProvider);
} else {
// Check flasher is valid
if (!chief.allowedFlasher(address(flasher))) {
revert RebalancerManager__rebalanceVault_notValidFlasher();
}
_checkDebtAmount(vault, debt, from);
_checkLtvChange(vault, from, to, assets, debt);
_getFlashloan(vault, assets, debt, from, to, flasher, setToAsActiveProvider);
}
_checkLtvChange(vault, from, to, assets, debt);
_getFlashloan(vault, assets, debt, from, to, flasher, setToAsActiveProvider);
}

success = true;
Expand Down Expand Up @@ -271,6 +278,14 @@ contract RebalancerManager is IRebalancerManager, SystemAccessControl {
flasher.initiateFlashloan(debtAsset, debt, address(this), requestorCall);
}

/**
* @dev Reset the `_entryPoint` state variable.
*/
function _resetEntryPoint() private {
// Reset the `_entryPoint`.
_entryPoint = "";
}

/**
* @notice Callback function that completes execution logic of a rebalance
* operation with a flashloan.
Expand Down Expand Up @@ -299,6 +314,11 @@ contract RebalancerManager is IRebalancerManager, SystemAccessControl {
external
returns (bool success)
{
// Check caller is a valid flasher
if (!chief.allowedFlasher(msg.sender)) {
revert RebalancerManager__rebalanceVault_notValidFlasher();
}
// Check flashloan originator is reentering properly
_checkReentry(vault, assets, debt, from, to, flasher, setToAsActiveProvider);

IERC20 debtAsset = IERC20(vault.debtAsset());
Expand All @@ -315,8 +335,20 @@ contract RebalancerManager is IRebalancerManager, SystemAccessControl {

debtAsset.safeTransfer(address(flasher), debt + flashloanFee);

// Re-initialize the `_entryPoint`.
_entryPoint = "";
_resetEntryPoint();
success = true;
}

/**
* @dev Forces to reset the `_entryPoint` state variable.
* This is needed in emergency case that `_resetEntryPoint()` is not reached due to
* external failure in execution of `completeRebalance()`.
* Otherwise, RebalancerManager will remain inoperable.
*
* Requirements:
* - Must be called from the timelock.
*/
function hardResetEntryPoint() external onlyTimelock {
_resetEntryPoint();
}
}
37 changes: 36 additions & 1 deletion packages/protocol/test/mocking/vaults/VaultRebalancing.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,38 @@ contract VaultRebalancingUnitTests is MockingSetup, MockRoutines {
assertEq(mockProviderB.getBorrowBalance(address(bvault), IVault(address(bvault))), debt);
}

function test_rebalanceBorrowingVaultWithRebalancerOnlyPartialAssets() public {
uint256 assets = DEPOSIT_AMOUNT / 2; // ALICE, BOB, CHARLIE, DAVID

//rebalance only partial assets should be ok
rebalancer.rebalanceVault(bvault, assets, 0, mockProviderA, mockProviderB, flasher, false);
assertEq(mockProviderB.getDepositBalance(address(bvault), IVault(address(bvault))), assets);

MockFlasher invalidFlasher = new MockFlasher();
//rebalance only partial assets even with invalid flasher should be ok since only assets do not use flashloan
rebalancer.rebalanceVault(
bvault, assets, 0, mockProviderB, mockProviderA, invalidFlasher, false
);
assertEq(mockProviderB.getDepositBalance(address(bvault), IVault(address(bvault))), 0);
}

function test_rebalanceBorrowingVaultWithRebalancerOnlyFullAssets() public {
// Payback all debt properly.
do_payback(BORROW_AMOUNT, bvault, ALICE);
do_payback(BORROW_AMOUNT, bvault, BOB);
do_payback(BORROW_AMOUNT, bvault, CHARLIE);
do_payback(BORROW_AMOUNT, bvault, DAVID);

uint256 assets = 4 * DEPOSIT_AMOUNT + initVaultShares; // ALICE, BOB, CHARLIE, DAVID
//rebalance only partial assets should be ok
rebalancer.rebalanceVault(bvault, assets, 0, mockProviderA, mockProviderB, flasher, true);
assertEq(mockProviderA.getDepositBalance(address(bvault), IVault(address(bvault))), 0);
assertEq(mockProviderB.getDepositBalance(address(bvault), IVault(address(bvault))), assets);

ILendingProvider currentProvider = bvault.activeProvider();
assertEq(address(currentProvider), address(mockProviderB));
}

function test_rebalanceYieldVaultWithRebalancer() public {
uint256 assets = 4 * DEPOSIT_AMOUNT + initVaultShares; // ALICE, BOB, CHARLIE, DAVID

Expand Down Expand Up @@ -383,10 +415,13 @@ contract VaultRebalancingUnitTests is MockingSetup, MockRoutines {
function test_notValidFlasher() public {
uint256 assets = 4 * DEPOSIT_AMOUNT; // ALICE, BOB, CHARLIE, DAVID
MockFlasher invalidFlasher = new MockFlasher();
uint256 debt = 4 * BORROW_AMOUNT; // ALICE, BOB, CHARLIE, DAVID

//rebalance with invalid flasher should fail
vm.expectRevert(RebalancerManager.RebalancerManager__rebalanceVault_notValidFlasher.selector);
rebalancer.rebalanceVault(bvault, assets, 0, mockProviderA, mockProviderB, invalidFlasher, true);
rebalancer.rebalanceVault(
bvault, assets, debt, mockProviderA, mockProviderB, invalidFlasher, true
);
}

// error RebalancerManager__checkAssetsAmount_invalidAmount();
Expand Down
18 changes: 18 additions & 0 deletions packages/sdk/src/constants/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,24 @@ export const RETH_ADDRESS: AddressMap = {
[ChainId.GNOSIS]: Address.from(AddressZero),
};

export const WBTC_ADDRESS: AddressMap = {
[ChainId.ETHEREUM]: Address.from(
'0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599'
),
[ChainId.MATIC]: Address.from('0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6'),
[ChainId.FANTOM]: Address.from(AddressZero),
[ChainId.ARBITRUM]: Address.from(
'0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f'
),
[ChainId.OPTIMISM]: Address.from(
'0x68f180fcCe6836688e9084f035309E29Bf0A2095'
),
[ChainId.GOERLI]: Address.from(AddressZero),
[ChainId.OPTIMISM_GOERLI]: Address.from(AddressZero),
[ChainId.MATIC_MUMBAI]: Address.from(AddressZero),
[ChainId.GNOSIS]: Address.from('0x8e5bBbb09Ed1ebdE8674Cda39A0c169401db4252'),
};

export const GNO_ADDRESS: AddressMap = {
[ChainId.ETHEREUM]: Address.from(
'0x6810e776880C02933D47DB1b9fc05908e5386b96'
Expand Down
Loading