Skip to content

Commit

Permalink
Merge pull request #4 from superform-xyz/fixSuperVaults
Browse files Browse the repository at this point in the history
fix: super vaults missed feature - SUP-8620
  • Loading branch information
0xTimepunk authored Oct 1, 2024
2 parents fdde0f6 + 798b847 commit 0e6bd16
Show file tree
Hide file tree
Showing 12 changed files with 492 additions and 436 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ cache/
out/

# Ignores development broadcast logs
!/broadcast
/broadcast/*/31337/
/broadcast/**/dry-run/
/broadcast

# Docs
docs/
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ update:; forge update
# Build & test
build :; FOUNDRY_PROFILE=production forge build
build-sizes :; FOUNDRY_PROFILE=production forge build --sizes
test-vvv :; forge test --match-test testSuperVaultConstructorReverts --evm-version cancun -vvvvv
test-vvv :; forge test --match-test test_superVault_rebalance --evm-version cancun -vv
ftest :; forge test --evm-version cancun
coverage :; forge coverage --evm-version cancun --report lcov
clean :; forge clean
Expand Down

This file was deleted.

76 changes: 0 additions & 76 deletions broadcast/Deploy.SuperVault.s.sol/8453/run-1727341735.json

This file was deleted.

2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ out = "out"
script = "script"
src = "src"
test = "test"
auto_detect_remappings = true
auto_detect_remappings = false
assertions_revert = true # see https://t.me/foundry_rs/36706
legacy_assertions = false # see https://t.me/foundry_rs/36706
gas_limit = "18446744073709551615" # see https://t.me/foundry_rs/36706
Expand Down
2 changes: 1 addition & 1 deletion script/deployments/staging/8453/8453.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"Moonwell": "0x3392F08d93de2e1675C2e0D19f3Ed021746F742c" /// 100% moonwell flagship supervault
"Moonwell": "0xd8ba05abcbe0baf1ee748104da11fb8f717fd291" /// 100% moonwell flagship supervault
}
4 changes: 3 additions & 1 deletion script/forge-scripts/Deploy.SuperVault.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ contract MainnetDeploySuperVault is Script {

/// 100% in the morpho moonwell USDC
uint256[] memory superformIds = new uint256[](1);
superformIds[0] = 53_060_340_969_226_234_633_364_492_417_650_658_771_681_951_352_098_198_744_034_590;
superformIds[0] = 53_060_340_969_225_424_123_272_122_895_191_053_251_498_236_784_870_936_252_229_868;

uint256[] memory startingWeights = new uint256[](1);
startingWeights[0] = 10_000;

/// TODO WARNING!: Change this before making it the official SuperVault
address refundsReceiver = 0x48aB8AdF869Ba9902Ad483FB1Ca2eFDAb6eabe92;
new SuperVault(
superRegistry,
0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913, // USDC
Expand Down
4 changes: 3 additions & 1 deletion script/utils/deploy_supervault.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

export ETHEREUM_RPC_URL=$(op read op://5ylebqljbh3x6zomdxi3qd7tsa/ETHEREUM_RPC_URL/credential)
export BSC_RPC_URL=$(op read op://5ylebqljbh3x6zomdxi3qd7tsa/BSC_RPC_URL/credential)
export AVALANCHE_RPC_URL=$(op read op://5ylebqljbh3x6zomdxi3qd7tsa/AVALANCHE_RPC_URL/credential)
Expand All @@ -10,4 +12,4 @@ export FANTOM_RPC_URL=$(op read op://5ylebqljbh3x6zomdxi3qd7tsa/FANTOM_RPC_URL/c
Run the script
echo Deploying super vault: ...

forge script script/forge-scripts/Deploy.SuperVault.s.sol:MainnetDeploySuperVault --sig "deploySuperVault(bool,uint256)" true 8453 --rpc-url $BASE_RPC_URL --legacy --account default --sender 0x48aB8AdF869Ba9902Ad483FB1Ca2eFDAb6eabe92 --broadcast
forge script script/forge-scripts/Deploy.SuperVault.s.sol:MainnetDeploySuperVault --sig "deploySuperVault(bool,uint256)" true 8453 --rpc-url $BASE_RPC_URL --legacy --account default --sender 0x48aB8AdF869Ba9902Ad483FB1Ca2eFDAb6eabe92 --broadcast
2 changes: 1 addition & 1 deletion script/utils/verify_contracts_staging.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ export OPTIMISM_RPC_URL=$(op read op://5ylebqljbh3x6zomdxi3qd7tsa/OPTIMISM_RPC_U
export BASE_RPC_URL=$(op read op://5ylebqljbh3x6zomdxi3qd7tsa/BASE_RPC_URL/credential)
export FANTOM_RPC_URL=$(op read op://5ylebqljbh3x6zomdxi3qd7tsa/FANTOM_RPC_URL/credential)

forge verify-contract 0x3392F08d93de2e1675C2e0D19f3Ed021746F742c "src/SuperVault.sol:SuperVault" --chain-id 8453 --num-of-optimizations 200 --watch --compiler-version v0.8.23+commit.f704f362 --guess-constructor-args --rpc-url $BASE_RPC_URL --etherscan-api-key "$BASESCAN_API_KEY"
forge verify-contract 0xd8ba05abcbe0baf1ee748104da11fb8f717fd291 "src/SuperVault.sol:SuperVault" --chain-id 8453 --num-of-optimizations 200 --watch --compiler-version v0.8.23+commit.f704f362 --guess-constructor-args --rpc-url $BASE_RPC_URL --etherscan-api-key "$BASESCAN_API_KEY"
55 changes: 33 additions & 22 deletions src/ISuperVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,24 @@ interface ISuperVault is IERC1155Receiver {
uint256[] weights;
}

/// @notice Struct to hold rebalance arguments
/// @param superformIdsRebalanceFrom Array of superform IDs to rebalance from
/// @param amountsRebalanceFrom Array of amounts to rebalance from each superform
/// @param superformIdsRebalanceTo Array of superform IDs to rebalance to
/// @param weightsOfRedestribution Array of weights for redistribution
/// @param rebalanceFromMsgValue Message value for rebalancing from
/// @param rebalanceToMsgValue Message value for rebalancing to
/// @param slippage Slippage tolerance for the rebalance
struct RebalanceArgs {
uint256[] superformIdsRebalanceFrom;
uint256[] amountsRebalanceFrom;
uint256[] finalSuperformIds;
uint256[] weightsOfRedestribution;
uint256 rebalanceFromMsgValue;
uint256 rebalanceToMsgValue;
uint256 slippage;
}

//////////////////////////////////////////////////////////////
// ERRORS //
//////////////////////////////////////////////////////////////
Expand All @@ -40,8 +58,14 @@ interface ISuperVault is IERC1155Receiver {
/// @notice Error thrown when the block chain ID is out of bounds
error BLOCK_CHAIN_ID_OUT_OF_BOUNDS();

/// @notice Error thrown when a duplicate superform ID is provided
error DUPLICATE_SUPERFORM_ID();
/// @notice Error thrown when a superform does not exist
error SUPERFORM_DOES_NOT_EXIST(uint256 superformId);

/// @notice Error thrown when a superform ID is invalid
error INVALID_SUPERFORM_ID_REBALANCE_FROM();

/// @notice Error thrown when a superform ID is not found in the final superform IDs
error REBALANCE_FROM_ID_NOT_FOUND_IN_FINAL_IDS();

//////////////////////////////////////////////////////////////
// EVENTS //
Expand All @@ -52,8 +76,9 @@ interface ISuperVault is IERC1155Receiver {
event RefundsReceiverSet(address refundReceiver);

/// @notice Emitted when the SuperVault is rebalanced
/// @param finalSuperformIds Array of final superform IDs of the SuperVault
/// @param finalWeights Array of final weights of the SuperVault
event Rebalanced(uint256[] finalWeights);
event RebalanceComplete(uint256[] finalSuperformIds, uint256[] finalWeights);

/// @notice Emitted when the deposit limit is set
/// @param depositLimit The new deposit limit
Expand All @@ -64,23 +89,9 @@ interface ISuperVault is IERC1155Receiver {
//////////////////////////////////////////////////////////////

/// @notice Rebalances the SuperVault
/// @dev TODO slippage per vault?
/// @param superformIdsRebalanceFrom Array of superform IDs to rebalance from
/// @param amountsRebalanceFrom Array of amounts to rebalance from each superform
/// @param superformIdsRebalanceTo Array of superform IDs to rebalance to
/// @param weightsOfRedestribution Array of weights for redistribution
/// @param rebalanceFromMsgValue Message value for rebalancing from
/// @param rebalanceToMsgValue Message value for rebalancing to
/// @param slippage Slippage tolerance for the rebalance
function rebalance(
uint256[] memory superformIdsRebalanceFrom,
uint256[] memory amountsRebalanceFrom,
uint256[] memory superformIdsRebalanceTo,
uint256[] memory weightsOfRedestribution,
uint256 rebalanceFromMsgValue,
uint256 rebalanceToMsgValue,
uint256 slippage
)
external
payable;
/// @notice the logic is as follows:
/// select the ids to rebalance from
/// send an amount to take from those ids
/// the total underlying asset amount is redestributed according to the desired weights
function rebalance(RebalanceArgs memory rebalanceArgs_) external payable;
}
Loading

0 comments on commit 0e6bd16

Please sign in to comment.