Skip to content

Commit

Permalink
Post deploy changes (#67)
Browse files Browse the repository at this point in the history
* CowSwapDex refactor (#64)

* fix: sell amount when posting CowSwap orders
* chore: streamline the initiation of cow swap order
* chore: restored option to not transfer rewards from Liquidator to CowSwapDex in the case an order has expired or was cancelled.
* chore: refactoring of Hardhat tasks including cowswap-quote, dex-init-swap and liq-init-swap
* chore: added HH task proxy-cancel
* chore: refactored HH tasks to use resolveAssetToken instead of resolveToken so token addresses not in config can be used
* chore: improved error handling of CowSwap API calls

* chore: simplified CowSwapDex with governor pre approving sell tokens

* chore: updates references to CowSwapSeller (#65)

* chore: updates references to CowSwapSeller

* chore: updates yarn clean including web package

* feat: added HH task for cowswap-status and cowswap-cancel
chore: more refactoring of cowswap HH tasks
chore: added new CowSwapDex contract address to config

Co-authored-by: doncesarts <doncesarts@gmail.com>

* Hacken audit response items (#66)

* fix: liq-settle-swap Harhdat task
* chore: added worked example to _chargePerformanceFeeHelper
* chore: added worked example of donation fee to donate Natspec
* chore: increased test coverage

Co-authored-by: doncesarts <doncesarts@gmail.com>
  • Loading branch information
naddison36 and doncesarts committed Oct 29, 2022
1 parent 46d1952 commit 1779626
Show file tree
Hide file tree
Showing 30 changed files with 790 additions and 897 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ jobs:
matrix:
script:
- coverage
- coverage:fork
# - coverage:fork
- coverage:fork:all
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
Expand Down
135 changes: 0 additions & 135 deletions contracts/peripheral/Cowswap/CowSwapSeller.sol

This file was deleted.

13 changes: 4 additions & 9 deletions contracts/peripheral/Cowswap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@

The [CoW Protocol](https://cow.fi/) lets people swap assets MEV protected at the best exchange rate by leveraging its batch settlement layer built on top of DeFi’s favorite AMMs and DEX Aggregators.

* [Tutorials: Submit orders via the API](https://docs.cow.fi/tutorials/how-to-submit-orders-via-the-api)
* [API Swapper Docs](https://api.cow.fi/docs/#/default/get_api_v1_account__owner__orders)
- [Tutorials: Submit orders via the API](https://docs.cow.fi/tutorials/how-to-submit-orders-via-the-api)
- [API Swapper Docs](https://api.cow.fi/docs/#/default/get_api_v1_account__owner__orders)

## Contracts
## Contracts

* [CowSwapSeller](./CowSwapSeller.sol) sets ERC20 token allowance and presign CowSwap orders.
* [ICowSettlement](./ICowSettlement.sol) Gnosis Protocol v2 Settlement Interface.
- [ICowSettlement](./ICowSettlement.sol) Gnosis Protocol v2 Settlement Interface.

## Diagrams

`CowSwapSeller` contract

![CowSwapSeller](../../../docs/CowSwapSeller.svg)
5 changes: 4 additions & 1 deletion contracts/vault/fee/PerfFeeAbstractVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ abstract contract PerfFeeAbstractVault is FeeAdminAbstractVault {
perfFeesAssetPerShare = PERF_ASSETS_PER_SHARE_SCALE;
}

/// @notice Helper function to charge a performance fee since using currentAssetPerShare
/// @notice Helper function to charge a performance fee in the form of vault shares since the last time a performance fee was charged.
/// As an example, if the assets per share increased by 0.1% in the last week and the performance fee is 4%, the vault shares will be
/// increased by 0.1% * 4% = 0.004% as a fee. If there was 100,000 vault shares, 4 (100,000 * 0.004%) vault shares will be minted as a
/// performance fee. This dilutes the assets per shares of the existing vault shareholders by 0.004%.
/// @dev Created for saving gas by not reading totalSupply() twice.
/// @param currentAssetsPerShare Current assetsPerShare
/// @param totalShares total shares in the vault.
Expand Down
34 changes: 17 additions & 17 deletions contracts/vault/liquidator/Liquidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -414,13 +414,13 @@ contract Liquidator is Initializable, ImmutableModule, InitializableReentrancyGu

IERC20(rewardToken).safeIncreaseAllowance(address(syncSwapper), rewards);

DexSwapData memory swapData = DexSwapData(
rewardToken, //fromAsset
rewards, //fromAssetAmount
assetToken, //toAsset
minAssets, //minAssets
data
);
DexSwapData memory swapData = DexSwapData({
fromAsset: rewardToken,
fromAssetAmount: rewards,
toAsset: assetToken,
minToAssetAmount: minAssets,
data: data
});

assets = syncSwapper.swap(swapData);

Expand All @@ -441,13 +441,13 @@ contract Liquidator is Initializable, ImmutableModule, InitializableReentrancyGu

IERC20(rewardToken).safeIncreaseAllowance(address(asyncSwapper), rewards);

DexSwapData memory swapData = DexSwapData(
rewardToken, //fromAsset
rewards, //fromAssetAmount
assetToken, //toAsset
0, //minAssets is not used on async dex
data //data(bytes orderUid, uint256 fromAssetFeeAmount, address receiver)
);
DexSwapData memory swapData = DexSwapData({
fromAsset: rewardToken,
fromAssetAmount: rewards,
toAsset: assetToken,
minToAssetAmount: 0, // is not used on async dex
data: data // data(bytes orderUid, bool transfer) for cow swap
});

// initiates swap on-chain , then off-chain data should monitor when swap is done (fail or success) and call `settleSwap`
asyncSwapper.initiateSwap(swapData);
Expand Down Expand Up @@ -525,14 +525,14 @@ contract Liquidator is Initializable, ImmutableModule, InitializableReentrancyGu
}

/**
* @notice Swap the collected rewards to desired asset.
* initiateSwap must be called first before settleSwap
* @notice settles the last batch swap of rewards for assets.
* `initiateSwap` must be called and the swap executed before `settleSwap`.
*
* @dev Emits the `SwapSettled` event with the `batch`, `rewards` and `assets` return parameters.
*
* @param rewardToken Address of the rewards being sold.
* @param assetToken Address of the assets being purchased.
* @param assets Amount of assets to swapped.
* @param assets Amount of purchaed assets received from the swap.
*/
function settleSwap(
address rewardToken,
Expand Down
5 changes: 5 additions & 0 deletions contracts/vault/liquidator/LiquidatorStreamAbstractVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ abstract contract LiquidatorStreamAbstractVault is AbstractVault, LiquidatorAbst
* @notice Converts donated tokens into vault assets, mints shares so the assets per share
* does not increase initially, and then burns the new shares over a period of time
* so the assets per share gradually increases.
* For example, if 1,000 DAI is being donated is worth 800 vault shares and the donation fee is 16%. 128 (800 * 16%)
* of the new vault shares are minted to the fee receiver. The remaining 672 vault shares are minted to the vault so
* the assets per shares of the shareholders does not increase. Over the next week the new vault shares will be burnt
* which will increase the assets per share to the shareholders.
*
* @param token The address of the token being donated to the vault.
@ @param amount The amount of tokens being donated to the vault.
*/
Expand Down

0 comments on commit 1779626

Please sign in to comment.