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

Chore/arbitrum rinkeby deployment #458

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
node_modules/
build/
artifacts/
types/
cache/
coverage
coverage.json
.env
Expand Down
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,50 @@ $ npm run coverage

The full report can be viewed by opening the `coverage/index.html` file in a browser.

## Testnet deployments

deployer: 0x775d1377223c9338771CbF955A9a53147219ea4A


weth: 0xE32513090f05ED2eE5F3c5819C9Cce6d020Fefe7


usdc: 0x3C6c9B6b41B9E0d82FeD45d9502edFFD5eD3D737


addressbook: 0x2d3E178FFd961BD8C0b035C926F9f2363a436DdC


otokenFactory: 0xcBcC61d56bb2cD6076E2268Ea788F51309FA253B


otoken: 0x07F00EB70837091b2D23c902561CE8D1b4df4702


whitelist: 0x0cc0b0C984036e0942544F70A5708Ab16463cd31


oracle: 0xe4d64aed5e76bCcE2C255f3c819f4C3817D42f19


pool: 0xDD91EB7C3822552D89a5Cb8D4166B1EB19A36Ff2


calculator: 0xa91B46bDDB891fED2cEE626FB03E2929702951A6


vault: 0x15887BD136Cdc8F170B8564e2E4568ee19C035F7


controller: 0xb2923CAbbC7dd78e9573D1D6d755E75dCB49CE47


pricer: 0xFfe61399050D2ACABa00419248B8616A4Bf56F9E


eth-pricer-bot: 0x282f13b62b4341801210657e3aa4ee1df69f4083


## Security And Bug Bounty Program

The security of the Opyn protocol is our highest priority. Our team has created a protocol that we believe is safe and dependable, and has been audited by OpenZeppelin. All smart contract code is publicly verifiable and we have a bug bounty for undiscovered vulnerabilities.
Expand Down
84 changes: 57 additions & 27 deletions contracts/core/Controller.sol
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ contract Controller is Initializable, OwnableUpgradeSafe, ReentrancyGuardUpgrade
/// @dev mapping to store amount of naked margin vaults in pool
mapping(address => uint256) internal nakedPoolBalance;

///@dev mapping to store liquidation states of a naked margin vault
mapping(address => mapping(uint256 => MarginVault.VaultLiquidationDetails)) internal vaultLiquidationDetails;

/// @notice emits an event when an account operator is updated for a specific account owner
event AccountOperatorUpdated(address indexed accountOwner, address indexed operator, bool isSet);
/// @notice emits an event when a new vault is opened
Expand Down Expand Up @@ -187,13 +190,13 @@ contract Controller is Initializable, OwnableUpgradeSafe, ReentrancyGuardUpgrade
/// @notice emits an event when a vault is liquidated
event VaultLiquidated(
address indexed liquidator,
address indexed receiver,
address receiver,
address indexed vaultOwner,
uint256 auctionPrice,
uint256 auctionStartingRound,
uint256 collateralPayout,
uint256 debtAmount,
uint256 vaultId
uint256 vaultId,
address indexed series
);
/// @notice emits an event when a call action is executed
event CallExecuted(address indexed from, address indexed to, bytes data);
Expand Down Expand Up @@ -448,6 +451,14 @@ contract Controller is Initializable, OwnableUpgradeSafe, ReentrancyGuardUpgrade
vaultLatestUpdate[_owner][_vaultId] = now;
}

/**
* @notice clear a vaults liquidation details
* @param _vaultId vaultId to return balances for
*/
function clearVaultLiquidationDetails(uint256 _vaultId) external {
delete vaultLiquidationDetails[msg.sender][_vaultId];
}

/**
* @notice check if a specific address is an operator for an owner account
* @param _owner account owner address
Expand Down Expand Up @@ -494,18 +505,34 @@ contract Controller is Initializable, OwnableUpgradeSafe, ReentrancyGuardUpgrade
return netValue;
}

/**
* @notice return a vault's past liquidation details
* @param _owner account owner of the vault
* @param _vaultId vaultId to return balances for
* @return series address liquidated
* @return amount of shorts liquidated
* @return amount of collateral transferred for liquidation
*/
function getVaultLiquidationDetails(address _owner, uint256 _vaultId)
external
view
returns (
address,
uint256,
uint256
)
{
MarginVault.VaultLiquidationDetails memory vault = vaultLiquidationDetails[_owner][_vaultId];
return (vault.series, vault.shortAmount, vault.collateralAmount);
}

/**
* @notice check if a vault is liquidatable in a specific round id
* @param _owner vault owner address
* @param _vaultId vault id to check
* @param _roundId chainlink round id to check vault status at
* @return isUnderCollat, true if vault is undercollateralized, the price of 1 repaid otoken and the otoken collateral dust amount
*/
function isLiquidatable(
address _owner,
uint256 _vaultId,
uint256 _roundId
)
function isLiquidatable(address _owner, uint256 _vaultId)
external
view
returns (
Expand All @@ -514,7 +541,7 @@ contract Controller is Initializable, OwnableUpgradeSafe, ReentrancyGuardUpgrade
uint256
)
{
(, bool isUnderCollat, uint256 price, uint256 dust) = _isLiquidatable(_owner, _vaultId, _roundId);
(, bool isUnderCollat, uint256 price, uint256 dust) = _isLiquidatable(_owner, _vaultId);
return (isUnderCollat, price, dust);
}

Expand Down Expand Up @@ -986,8 +1013,7 @@ contract Controller is Initializable, OwnableUpgradeSafe, ReentrancyGuardUpgrade
// collateralDust is the minimum amount of collateral that can be left in the vault when a partial liquidation occurs
(MarginVault.Vault memory vault, bool isUnderCollat, uint256 price, uint256 collateralDust) = _isLiquidatable(
_args.owner,
_args.vaultId,
_args.roundId
_args.vaultId
);

require(isUnderCollat, "C33");
Expand All @@ -1004,7 +1030,21 @@ contract Controller is Initializable, OwnableUpgradeSafe, ReentrancyGuardUpgrade
// burn short otoken from liquidator address, index of short otoken hardcoded at 0
// this should always work, if vault have no short otoken, it will not reach this step
OtokenInterface(vault.shortOtokens[0]).burnOtoken(msg.sender, _args.amount);

// increment the vault liquidation details to store the fact that this vault was liquidated
MarginVault.VaultLiquidationDetails storage vaultLiqDetails = vaultLiquidationDetails[_args.owner][
_args.vaultId
];
address series = vault.shortOtokens[0];
if (vaultLiqDetails.series == vault.shortOtokens[0]) {
vaultLiqDetails.shortAmount = uint128(uint256(vaultLiqDetails.shortAmount).add(_args.amount));
vaultLiqDetails.collateralAmount = uint128(
uint256(vaultLiqDetails.collateralAmount).add(collateralToSell)
);
} else {
vaultLiqDetails.series = vault.shortOtokens[0];
vaultLiqDetails.shortAmount = uint128(_args.amount);
vaultLiqDetails.collateralAmount = uint128(collateralToSell);
}
// decrease amount of collateral in liquidated vault, index of collateral to decrease is hardcoded at 0
vaults[_args.owner][_args.vaultId].removeCollateral(vault.collateralAssets[0], collateralToSell, 0);

Expand All @@ -1021,10 +1061,10 @@ contract Controller is Initializable, OwnableUpgradeSafe, ReentrancyGuardUpgrade
_args.receiver,
_args.owner,
price,
_args.roundId,
collateralToSell,
_args.amount,
_args.vaultId
_args.vaultId,
series
);
}

Expand Down Expand Up @@ -1066,14 +1106,9 @@ contract Controller is Initializable, OwnableUpgradeSafe, ReentrancyGuardUpgrade
* @notice check if a vault is liquidatable in a specific round id
* @param _owner vault owner address
* @param _vaultId vault id to check
* @param _roundId chainlink round id to check vault status at
* @return vault struct, isLiquidatable, true if vault is undercollateralized, the price of 1 repaid otoken and the otoken collateral dust amount
*/
function _isLiquidatable(
address _owner,
uint256 _vaultId,
uint256 _roundId
)
function _isLiquidatable(address _owner, uint256 _vaultId)
internal
view
returns (
Expand All @@ -1087,12 +1122,7 @@ contract Controller is Initializable, OwnableUpgradeSafe, ReentrancyGuardUpgrade
_owner,
_vaultId
);
(bool isUnderCollat, uint256 price, uint256 collateralDust) = calculator.isLiquidatable(
vault,
typeVault,
latestUpdateTimestamp,
_roundId
);
(bool isUnderCollat, uint256 price, uint256 collateralDust) = calculator.isLiquidatable(vault, typeVault);

return (vault, isUnderCollat, price, collateralDust);
}
Expand Down
Loading