Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6001536
Added the withdraw batch function
crazybuster Aug 14, 2022
d4d934e
Added test for withdraw
crazybuster Aug 14, 2022
8eaf874
test against withdrawing multiple assests
crazybuster Aug 14, 2022
152a499
New comments on withdraw
crazybuster Aug 14, 2022
58d1260
Cleaned up for lint
crazybuster Aug 23, 2022
e80a7b7
Prettier
crazybuster Aug 23, 2022
2d2aeec
Merge branch 'master' into yupan/withdraw-batch
sparrowDom Dec 5, 2022
1771559
clean up the code and tests
sparrowDom Dec 5, 2022
ec81ea6
add a deploy script and a fork test
sparrowDom Dec 6, 2022
b52a15b
prettier
sparrowDom Dec 6, 2022
c704e88
re-introduce back the check
sparrowDom Dec 6, 2022
79c52fe
improve documentation and add more checks to tests
sparrowDom Dec 6, 2022
6423fd1
Merge branch 'master' into yupan/withdraw-batch
sparrowDom Dec 8, 2022
d1557be
minor comment and text changes
sparrowDom Dec 8, 2022
514b051
update strategy addresses
sparrowDom Dec 8, 2022
e704bf6
Merge remote-tracking branch 'origin/master' into yupan/withdraw-batch
sparrowDom Jan 20, 2023
3b3a92c
Merge branch 'master' into yupan/withdraw-batch
DanielVF Jan 26, 2023
eacd53f
update brownie abi. Fix deploy script for when the proposal has not y…
sparrowDom Jan 30, 2023
817c9c1
prettier
sparrowDom Jan 30, 2023
4f70328
some refactoring
sparrowDom Jan 30, 2023
be2efe4
simplify contract test
sparrowDom Jan 30, 2023
9a5b00a
prettier
sparrowDom Jan 30, 2023
b07035a
remove only
sparrowDom Jan 30, 2023
dc918cc
use depositAll to rather deploy funds more efficiently as the strategy
sparrowDom Jan 30, 2023
647b3e2
prettier
sparrowDom Jan 30, 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
2 changes: 1 addition & 1 deletion brownie/abi/vault_admin.json

Large diffs are not rendered by default.

11 changes: 2 additions & 9 deletions brownie/metastrategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@
import world
import math

#CONFIGURATION - unfortunately this address changes until we deploy it to mainnet
OUSD_META_STRATEGY = '0xb12C3410C44854054c217fbF79dFf38ffD1C0676'
BUSD_STRATEGY = '0x6996352570817113965b0325005f868B1Fe2f2e9'
# Define which meta strategy should be set as default USDT asset strategy. Important for
# supplying liquidity when minting using USDT
USDT_DEFAULT_META_STRATEGY = OUSD_META_STRATEGY
#USDT_DEFAULT_META_STRATEGY = BUSD_STRATEGY
#END COFIGURATION

me = ORIGINTEAM
some_gas_price = 100
Expand All @@ -30,6 +22,8 @@
DAI_BAGS = '0x40ec5b33f54e0e8a33a975908c5ba1c14e5bbbdf' #polygon bridge
DAI_BAGS_2 = '0x5d3a536e4d6dbd6114cc1ead35777bab948e3643' #this is compound cDai. Don't touch this!
CURVE_FACTORY = '0xB9fC157394Af804a3578134A6585C0dc9cc990d4'
OUSD_META_STRATEGY = '0x89Eb88fEdc50FC77ae8a18aAD1cA0ac27f777a90'
USDT_DEFAULT_META_STRATEGY = OUSD_META_STRATEGY

threepool_lp = load_contract('threepool_lp', THREEPOOL_LP)
ousd_metapool = load_contract('ousd_metapool', OUSD_METAPOOL)
Expand All @@ -52,7 +46,6 @@
frax.transfer(me, frax.balanceOf(FRAX_BAGS), {'from': FRAX_BAGS})
busd.transfer(me, busd.balanceOf(BUSD_BAGS), {'from': BUSD_BAGS})
meta_strat = load_contract('convex_strat', OUSD_META_STRATEGY)
busd_strat = load_contract('convex_strat', BUSD_STRATEGY)

# approve ousd and 3poolLp to be used by ousd_metapool
threepool_lp.approve(ousd_metapool, int(0), OPTS)
Expand Down
12 changes: 12 additions & 0 deletions contracts/contracts/interfaces/IVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ interface IVault {
uint256[] calldata _amounts
) external;

function withdrawFromStrategy(
address _strategyFromAddress,
address[] calldata _assets,
uint256[] calldata _amounts
) external;

function depositToStrategy(
address _strategyToAddress,
address[] calldata _assets,
uint256[] calldata _amounts
) external;

// VaultCore.sol
function mint(
address _asset,
Expand Down
90 changes: 83 additions & 7 deletions contracts/contracts/vault/VaultAdmin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ contract VaultAdmin is VaultStorage {
}

/**
* @notice Move assets from one Strategy to another
* @dev Move assets from one Strategy to another
* @param _strategyFromAddress Address of Strategy to move assets from.
* @param _strategyToAddress Address of Strategy to move assets to.
* @param _assets Array of asset address that will be moved
Expand All @@ -246,27 +246,103 @@ contract VaultAdmin is VaultStorage {
uint256[] calldata _amounts
) external onlyGovernorOrStrategist {
require(
strategies[_strategyFromAddress].isSupported,
"Invalid from Strategy"
strategies[_strategyToAddress].isSupported,
"Invalid to Strategy"
);
require(_assets.length == _amounts.length, "Parameter length mismatch");
_withdrawFromStrategy(
_strategyToAddress,
_strategyFromAddress,
_assets,
_amounts
);

IStrategy strategyTo = IStrategy(_strategyToAddress);
for (uint256 i = 0; i < _assets.length; i++) {
require(strategyTo.supportsAsset(_assets[i]), "Asset unsupported");
}
// Tell new Strategy to deposit into protocol
strategyTo.depositAll();
}

/**
* @dev Deposit multiple assets from the vault into the strategy.
* @param _strategyToAddress Address of the Strategy to deposit assets into.
* @param _assets Array of asset address that will be deposited into the strategy.
* @param _amounts Array of amounts of each corresponding asset to deposit.
*/
function depositToStrategy(
address _strategyToAddress,
address[] calldata _assets,
uint256[] calldata _amounts
) external onlyGovernorOrStrategist {
_depositToStrategy(_strategyToAddress, _assets, _amounts);
}

function _depositToStrategy(
address _strategyToAddress,
address[] calldata _assets,
uint256[] calldata _amounts
) internal {
require(
strategies[_strategyToAddress].isSupported,
"Invalid to Strategy"
);
require(_assets.length == _amounts.length, "Parameter length mismatch");

IStrategy strategyFrom = IStrategy(_strategyFromAddress);
IStrategy strategyTo = IStrategy(_strategyToAddress);

for (uint256 i = 0; i < _assets.length; i++) {
require(strategyTo.supportsAsset(_assets[i]), "Asset unsupported");
// Withdraw from Strategy and pass other Strategy as recipient
strategyFrom.withdraw(address(strategyTo), _assets[i], _amounts[i]);
// Send required amount of funds to the strategy
IERC20(_assets[i]).safeTransfer(_strategyToAddress, _amounts[i]);
}
// Tell new Strategy to deposit into protocol

// Deposit all the funds that have been sent to the strategy
strategyTo.depositAll();
}

/**
* @dev Withdraw multiple assets from the strategy to the vault.
* @param _strategyFromAddress Address of the Strategy to withdraw assets from.
* @param _assets Array of asset address that will be withdrawn from the strategy.
* @param _amounts Array of amounts of each corresponding asset to withdraw.
*/
function withdrawFromStrategy(
address _strategyFromAddress,
address[] calldata _assets,
uint256[] calldata _amounts
) external onlyGovernorOrStrategist {
_withdrawFromStrategy(
address(this),
_strategyFromAddress,
_assets,
_amounts
);
}

/**
* @param _recipient can either be a strategy or the Vault
*/
function _withdrawFromStrategy(
address _recipient,
address _strategyFromAddress,
address[] calldata _assets,
uint256[] calldata _amounts
) internal {
require(
strategies[_strategyFromAddress].isSupported,
"Invalid from Strategy"
);
require(_assets.length == _amounts.length, "Parameter length mismatch");

IStrategy strategyFrom = IStrategy(_strategyFromAddress);
for (uint256 i = 0; i < _assets.length; i++) {
// Withdraw from Strategy to the recipient
strategyFrom.withdraw(_recipient, _assets[i], _amounts[i]);
}
}

/**
* @dev Sets the maximum allowable difference between
* total supply and backing assets' value.
Expand Down
36 changes: 36 additions & 0 deletions contracts/deploy/048_deposit_withdraw_tooling.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const { deploymentWithProposal } = require("../utils/deploy");
const addresses = require("../utils/addresses");

module.exports = deploymentWithProposal(
{ deployName: "048_deposit_withdraw_tooling", forceDeploy: false },
async ({
assetAddresses,
deployWithConfirmation,
ethers,
getTxOpts,
withConfirmation,
}) => {
const { deployerAddr, governorAddr } = await getNamedAccounts();
const sDeployer = await ethers.provider.getSigner(deployerAddr);

// Current contracts
const cVaultProxy = await ethers.getContract("VaultProxy");

const dVaultAdmin = await deployWithConfirmation("VaultAdmin");
const cVault = await ethers.getContractAt("Vault", cVaultProxy.address);

// Governance Actions
// ----------------
return {
name: "Deploy new withdrawal utils",
actions: [
// 1. Set VaultAdmin implementation
{
contract: cVault,
signature: "setAdminImpl(address)",
args: [dVaultAdmin.address],
},
],
};
}
);
1 change: 1 addition & 0 deletions contracts/test/_fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ async function defaultFixture() {
tusd = await ethers.getContractAt(erc20Abi, addresses.mainnet.TUSD);
usdc = await ethers.getContractAt(erc20Abi, addresses.mainnet.USDC);
cusdt = await ethers.getContractAt(erc20Abi, addresses.mainnet.cUSDT);
cdai = await ethers.getContractAt(erc20Abi, addresses.mainnet.cDAI);
cusdc = await ethers.getContractAt(erc20Abi, addresses.mainnet.cUSDC);
comp = await ethers.getContractAt(erc20Abi, addresses.mainnet.COMP);
crv = await ethers.getContractAt(erc20Abi, addresses.mainnet.CRV);
Expand Down
Loading