-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9527b99
commit 58899f1
Showing
85 changed files
with
18,430 additions
and
18,247 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
*.sol linguist-language=Solidity | ||
*.sol linguist-language=Solidity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
/out | ||
/out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[submodule "lib/geb-safe-manager"] | ||
path = lib/geb-safe-manager | ||
url = https://github.com/reflexer-labs/geb-safe-manager.git | ||
[submodule "lib/geb-safe-manager"] | ||
path = lib/geb-safe-manager | ||
url = https://github.com/reflexer-labs/geb-safe-manager.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
os: | ||
- linux | ||
language: nix | ||
nix: 2.3.6 | ||
before_install: | ||
- nix-env -iA nixpkgs.cachix | ||
- echo "trusted-users = root travis" | sudo tee -a /etc/nix/nix.conf && sudo pkill nix-daemon | ||
- cachix use maker | ||
- git clone --recursive https://github.com/dapphub/dapptools $HOME/.dapp/dapptools | ||
- nix-env -f https://github.com/makerdao/makerpkgs/tarball/master -iA dappPkgsVersions.hevm-0_41_0.dapp | ||
script: | ||
- dapp --use solc:0.6.7 test | ||
os: | ||
- linux | ||
language: nix | ||
nix: 2.3.6 | ||
before_install: | ||
- nix-env -iA nixpkgs.cachix | ||
- echo "trusted-users = root travis" | sudo tee -a /etc/nix/nix.conf && sudo pkill nix-daemon | ||
- cachix use maker | ||
- git clone --recursive https://github.com/dapphub/dapptools $HOME/.dapp/dapptools | ||
- nix-env -f https://github.com/makerdao/makerpkgs/tarball/master -iA dappPkgsVersions.hevm-0_41_0.dapp | ||
script: | ||
- dapp --use solc:0.6.7 test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
all :; dapp build | ||
clean :; dapp clean | ||
test :; dapp test | ||
deploy :; dapp create SafeSaviourLike | ||
all :; dapp build | ||
clean :; dapp clean | ||
test :; dapp test | ||
deploy :; dapp create SafeSaviourLike |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
# GEB Safe Saviours | ||
|
||
This repository contains several SAFE saviours that can be attached to GEB Safes and protect them from liquidation. | ||
|
||
For more details on what saviours are and how they generally work, read the [official documentation](https://docs.reflexer.finance/integrations/safe-protection). | ||
|
||
# Saviour Types | ||
|
||
- **CompoundSystemCoinSafeSaviour**: this saviour lends system coins on a Compound like market and repays a Safe's debt when it's liquidated | ||
- **GeneralTokenReserveSafeSaviour**: this saviour uses collateral to top up a Safe and save it | ||
- **NativeUnderlyingUniswapV2SafeSaviour**: this saviour withdraws liquidity from Uniswap V2 and repays debt and/or tops up a Safe in order to save it | ||
- **NativeUnderlyingUniswapV3SafeSaviour**: this saviour withdraws liquidity from Uniswap V3 and repays debt and/or tops up a Safe in order to save it | ||
- **SystemCoinUniswapV2SafeSaviour**: this saviour withdraws liquidity from Uniswap V2, swaps one of the tokens for the Safe's collateral and repays debt and/or tops up the Safe in order to save it | ||
- **SystemCoinUniswapV3SafeSaviour**: this saviour withdraws liquidity from Uniswap V3, swaps one of the tokens for the Safe's collateral and repays debt and/or tops up the Safe in order to save it | ||
- **YearnSystemCoinSafeSaviour**: this saviour lends system coins in a Yearn strategy vault and repays a Safe's debt when it's liquidated | ||
# GEB Safe Saviours | ||
|
||
This repository contains several SAFE saviours that can be attached to GEB Safes and protect them from liquidation. | ||
|
||
For more details on what saviours are and how they generally work, read the [official documentation](https://docs.reflexer.finance/integrations/safe-protection). | ||
|
||
# Saviour Types | ||
|
||
- **CompoundSystemCoinSafeSaviour**: this saviour lends system coins on a Compound like market and repays a Safe's debt when it's liquidated | ||
- **GeneralTokenReserveSafeSaviour**: this saviour uses collateral to top up a Safe and save it | ||
- **NativeUnderlyingUniswapV2SafeSaviour**: this saviour withdraws liquidity from Uniswap V2 and repays debt and/or tops up a Safe in order to save it | ||
- **NativeUnderlyingUniswapV3SafeSaviour**: this saviour withdraws liquidity from Uniswap V3 and repays debt and/or tops up a Safe in order to save it | ||
- **SystemCoinUniswapV2SafeSaviour**: this saviour withdraws liquidity from Uniswap V2, swaps one of the tokens for the Safe's collateral and repays debt and/or tops up the Safe in order to save it | ||
- **SystemCoinUniswapV3SafeSaviour**: this saviour withdraws liquidity from Uniswap V3, swaps one of the tokens for the Safe's collateral and repays debt and/or tops up the Safe in order to save it | ||
- **YearnSystemCoinSafeSaviour**: this saviour lends system coins in a Yearn strategy vault and repays a Safe's debt when it's liquidated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,111 +1,111 @@ | ||
pragma solidity ^0.6.7; | ||
|
||
contract SAFESaviourRegistry { | ||
// --- Auth --- | ||
mapping (address => uint256) public authorizedAccounts; | ||
/** | ||
* @notice Add auth to an account | ||
* @param account Account to add auth to | ||
*/ | ||
function addAuthorization(address account) external isAuthorized { | ||
authorizedAccounts[account] = 1; | ||
emit AddAuthorization(account); | ||
} | ||
/** | ||
* @notice Remove auth from an account | ||
* @param account Account to remove auth from | ||
*/ | ||
function removeAuthorization(address account) external isAuthorized { | ||
authorizedAccounts[account] = 0; | ||
emit RemoveAuthorization(account); | ||
} | ||
/** | ||
* @notice Checks whether msg.sender can call an authed function | ||
**/ | ||
modifier isAuthorized { | ||
require(authorizedAccounts[msg.sender] == 1, "SAFESaviourRegistry/account-not-authorized"); | ||
_; | ||
} | ||
|
||
// --- Other Modifiers --- | ||
modifier isSaviour { | ||
require(saviours[msg.sender] == 1, "SAFESaviourRegistry/not-a-saviour"); | ||
_; | ||
} | ||
|
||
// --- Variables --- | ||
// Minimum amount of time that needs to elapse for a specific SAFE to be saved again | ||
uint256 public saveCooldown; | ||
|
||
// Timestamp for the last time when a specific SAFE has been saved | ||
mapping(bytes32 => mapping(address => uint256)) public lastSaveTime; | ||
|
||
// Whitelisted saviours | ||
mapping(address => uint256) public saviours; | ||
|
||
// --- Events --- | ||
event AddAuthorization(address account); | ||
event RemoveAuthorization(address account); | ||
event ModifyParameters(bytes32 parameter, uint256 val); | ||
event ToggleSaviour(address saviour, uint256 whitelistState); | ||
event MarkSave(bytes32 indexed collateralType, address indexed safeHandler); | ||
|
||
constructor(uint256 saveCooldown_) public { | ||
require(saveCooldown_ > 0, "SAFESaviourRegistry/null-save-cooldown"); | ||
authorizedAccounts[msg.sender] = 1; | ||
saveCooldown = saveCooldown_; | ||
emit ModifyParameters("saveCooldown", saveCooldown_); | ||
} | ||
|
||
// --- Boolean Logic --- | ||
function either(bool x, bool y) internal pure returns (bool z) { | ||
assembly{ z := or(x, y)} | ||
} | ||
|
||
// --- Math --- | ||
function addition(uint256 x, uint256 y) internal pure returns (uint256 z) { | ||
require((z = x + y) >= x, "SAFESaviourRegistry/add-uint-uint-overflow"); | ||
} | ||
|
||
// --- Administration --- | ||
/* | ||
* @notice Change the saveCooldown value | ||
* @param parameter Name of the parameter to change | ||
* @param val The new value for the param | ||
*/ | ||
function modifyParameters(bytes32 parameter, uint256 val) external isAuthorized { | ||
require(val > 0, "SAFESaviourRegistry/null-val"); | ||
if (parameter == "saveCooldown") { | ||
saveCooldown = val; | ||
} else revert("SAFESaviourRegistry/modify-unrecognized-param"); | ||
emit ModifyParameters(parameter, val); | ||
} | ||
/* | ||
* @notice Whitelist/blacklist a saviour contract | ||
* @param saviour The saviour contract to whitelist/blacklist | ||
*/ | ||
function toggleSaviour(address saviour) external isAuthorized { | ||
if (saviours[saviour] == 0) { | ||
saviours[saviour] = 1; | ||
} else { | ||
saviours[saviour] = 0; | ||
} | ||
emit ToggleSaviour(saviour, saviours[saviour]); | ||
} | ||
|
||
// --- Core Logic --- | ||
/* | ||
* @notice Mark a new SAFE as just having been saved | ||
* @param collateralType The collateral type backing the SAFE | ||
* @param safeHandler The SAFE's handler | ||
*/ | ||
function markSave(bytes32 collateralType, address safeHandler) external isSaviour { | ||
require( | ||
either(lastSaveTime[collateralType][safeHandler] == 0, | ||
addition(lastSaveTime[collateralType][safeHandler], saveCooldown) < now), | ||
"SAFESaviourRegistry/wait-more-to-save" | ||
); | ||
lastSaveTime[collateralType][safeHandler] = now; | ||
emit MarkSave(collateralType, safeHandler); | ||
} | ||
} | ||
pragma solidity ^0.6.7; | ||
|
||
contract SAFESaviourRegistry { | ||
// --- Auth --- | ||
mapping (address => uint256) public authorizedAccounts; | ||
/** | ||
* @notice Add auth to an account | ||
* @param account Account to add auth to | ||
*/ | ||
function addAuthorization(address account) external isAuthorized { | ||
authorizedAccounts[account] = 1; | ||
emit AddAuthorization(account); | ||
} | ||
/** | ||
* @notice Remove auth from an account | ||
* @param account Account to remove auth from | ||
*/ | ||
function removeAuthorization(address account) external isAuthorized { | ||
authorizedAccounts[account] = 0; | ||
emit RemoveAuthorization(account); | ||
} | ||
/** | ||
* @notice Checks whether msg.sender can call an authed function | ||
**/ | ||
modifier isAuthorized { | ||
require(authorizedAccounts[msg.sender] == 1, "SAFESaviourRegistry/account-not-authorized"); | ||
_; | ||
} | ||
|
||
// --- Other Modifiers --- | ||
modifier isSaviour { | ||
require(saviours[msg.sender] == 1, "SAFESaviourRegistry/not-a-saviour"); | ||
_; | ||
} | ||
|
||
// --- Variables --- | ||
// Minimum amount of time that needs to elapse for a specific SAFE to be saved again | ||
uint256 public saveCooldown; | ||
|
||
// Timestamp for the last time when a specific SAFE has been saved | ||
mapping(bytes32 => mapping(address => uint256)) public lastSaveTime; | ||
|
||
// Whitelisted saviours | ||
mapping(address => uint256) public saviours; | ||
|
||
// --- Events --- | ||
event AddAuthorization(address account); | ||
event RemoveAuthorization(address account); | ||
event ModifyParameters(bytes32 parameter, uint256 val); | ||
event ToggleSaviour(address saviour, uint256 whitelistState); | ||
event MarkSave(bytes32 indexed collateralType, address indexed safeHandler); | ||
|
||
constructor(uint256 saveCooldown_) public { | ||
require(saveCooldown_ > 0, "SAFESaviourRegistry/null-save-cooldown"); | ||
authorizedAccounts[msg.sender] = 1; | ||
saveCooldown = saveCooldown_; | ||
emit ModifyParameters("saveCooldown", saveCooldown_); | ||
} | ||
|
||
// --- Boolean Logic --- | ||
function either(bool x, bool y) internal pure returns (bool z) { | ||
assembly{ z := or(x, y)} | ||
} | ||
|
||
// --- Math --- | ||
function addition(uint256 x, uint256 y) internal pure returns (uint256 z) { | ||
require((z = x + y) >= x, "SAFESaviourRegistry/add-uint-uint-overflow"); | ||
} | ||
|
||
// --- Administration --- | ||
/* | ||
* @notice Change the saveCooldown value | ||
* @param parameter Name of the parameter to change | ||
* @param val The new value for the param | ||
*/ | ||
function modifyParameters(bytes32 parameter, uint256 val) external isAuthorized { | ||
require(val > 0, "SAFESaviourRegistry/null-val"); | ||
if (parameter == "saveCooldown") { | ||
saveCooldown = val; | ||
} else revert("SAFESaviourRegistry/modify-unrecognized-param"); | ||
emit ModifyParameters(parameter, val); | ||
} | ||
/* | ||
* @notice Whitelist/blacklist a saviour contract | ||
* @param saviour The saviour contract to whitelist/blacklist | ||
*/ | ||
function toggleSaviour(address saviour) external isAuthorized { | ||
if (saviours[saviour] == 0) { | ||
saviours[saviour] = 1; | ||
} else { | ||
saviours[saviour] = 0; | ||
} | ||
emit ToggleSaviour(saviour, saviours[saviour]); | ||
} | ||
|
||
// --- Core Logic --- | ||
/* | ||
* @notice Mark a new SAFE as just having been saved | ||
* @param collateralType The collateral type backing the SAFE | ||
* @param safeHandler The SAFE's handler | ||
*/ | ||
function markSave(bytes32 collateralType, address safeHandler) external isSaviour { | ||
require( | ||
either(lastSaveTime[collateralType][safeHandler] == 0, | ||
addition(lastSaveTime[collateralType][safeHandler], saveCooldown) < now), | ||
"SAFESaviourRegistry/wait-more-to-save" | ||
); | ||
lastSaveTime[collateralType][safeHandler] = now; | ||
emit MarkSave(collateralType, safeHandler); | ||
} | ||
} |
Oops, something went wrong.