Skip to content
Merged
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: 2 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts.git
branch = tags/v5.2.0
[submodule "lib/chainlink"]
path = lib/chainlink
url = https://github.com/smartcontractkit/chainlink
ignore = untracked
[submodule "lib/openzeppelin-contracts-upgradeable"]
path = lib/openzeppelin-contracts-upgradeable
url = https://github.com/openzeppelin/openzeppelin-contracts-upgradeable
branch = v4.8.1
branch = tags/v5.2.0
[submodule "lib/lyra-utils"]
path = lib/lyra-utils
url = https://github.com/lyra-finance/lyra-utils
8 changes: 6 additions & 2 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ optimizer = true
optimizer_runs = 800
fs_permissions = [{ access = "read-write", path = "./"}]

solc_version="0.8.20"
solc_version = "0.8.27"

evm_version="shanghai"
evm_version = "shanghai"

# for tests:
gas_limit = "18446744073709551615"
memory_limit = 8796093022208

[fmt]
line_length = 120
Expand Down
2 changes: 1 addition & 1 deletion lib/openzeppelin-contracts
2 changes: 1 addition & 1 deletion lib/openzeppelin-contracts-upgradeable
4 changes: 2 additions & 2 deletions src/SecurityModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ contract SecurityModule is Ownable2Step, ISecurityModule {
/// @dev Mapping of (address => isWhitelistedModule)
mapping(address => bool) public isWhitelisted;

constructor(ISubAccounts _subAccounts, ICashAsset _cashAsset, IManager accountManager) {
constructor(ISubAccounts _subAccounts, ICashAsset _cashAsset, IManager accountManager) Ownable(msg.sender) {
subAccounts = _subAccounts;
cashAsset = _cashAsset;
stableAsset = cashAsset.wrappedAsset();
stableDecimals = stableAsset.decimals();

accountId = ISubAccounts(_subAccounts).createAccount(address(this), accountManager);
stableAsset.safeApprove(address(_cashAsset), type(uint).max);
stableAsset.approve(address(_cashAsset), type(uint).max);
}

/////////////////////////////
Expand Down
14 changes: 9 additions & 5 deletions src/SubAccounts.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.18;

import "openzeppelin/token/ERC721/ERC721.sol";
import "openzeppelin/utils/math/SafeCast.sol";
import "openzeppelin/security/ReentrancyGuard.sol";
import "openzeppelin/utils/ReentrancyGuard.sol";
import {ISubAccounts} from "./interfaces/ISubAccounts.sol";
import "openzeppelin/utils/cryptography/EIP712.sol";
import "openzeppelin/utils/cryptography/SignatureChecker.sol";
Expand Down Expand Up @@ -83,7 +83,7 @@ contract SubAccounts is Allowances, ERC721, EIP712, ReentrancyGuard, ISubAccount
*/
function createAccountWithApproval(address owner, address spender, IManager _manager) external returns (uint newId) {
newId = _createAccount(owner, _manager);
_approve(spender, newId);
_approve(spender, newId, address(0));
}

/**
Expand Down Expand Up @@ -659,14 +659,18 @@ contract SubAccounts is Allowances, ERC721, EIP712, ReentrancyGuard, ISubAccount
// Access //
////////////

function _isApprovedOrOwner(address spender, uint accountId) internal view returns (bool) {
address owner = _ownerOf(accountId);
return _isAuthorized(owner, spender, accountId);
}

/**
* @dev giving managers exclusive rights to transfer account ownerships
* @dev this function overrides ERC721._isApprovedOrOwner(spender, tokenId);
*
*/
function _isApprovedOrOwner(address spender, uint accountId) internal view override returns (bool) {
if (super._isApprovedOrOwner(spender, accountId)) return true;

function _isAuthorized(address owner, address spender, uint accountId) internal view override returns (bool) {
if (super._isAuthorized(owner, spender, accountId)) return true;
// check if caller is manager
return address(manager[accountId]) == msg.sender;
}
Expand Down
1 change: 1 addition & 0 deletions src/assets/CashAsset.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ contract CashAsset is ICashAsset, Ownable2Step, ManagerWhitelist {

constructor(ISubAccounts _subAccounts, IERC20Metadata _wrappedAsset, IInterestRateModel _rateModel)
ManagerWhitelist(_subAccounts)
Ownable(msg.sender)
{
wrappedAsset = _wrappedAsset;
stableDecimals = _wrappedAsset.decimals();
Expand Down
2 changes: 2 additions & 0 deletions src/assets/utils/PositionTracking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ contract PositionTracking is Ownable2Step, IPositionTracking {
/// @dev Snapshot of total position before a trade, used to determine if a trade increases or decreases total position
mapping(IManager manager => mapping(uint tradeId => OISnapshot)) public totalPositionBeforeTrade;

constructor() Ownable(msg.sender) {}

/////////////////////
// Owner-only //
/////////////////////
Expand Down
2 changes: 1 addition & 1 deletion src/feeds/BaseLyraFeed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ abstract contract BaseLyraFeed is EIP712, Ownable2Step, IDataReceiver, IBaseLyra
// Constructor //
////////////////////////

constructor(string memory name, string memory version) EIP712(name, version) {}
constructor(string memory name, string memory version) EIP712(name, version) Ownable(msg.sender) {}

////////////////////////
// Owner Only Actions //
Expand Down
4 changes: 2 additions & 2 deletions src/feeds/SFPSpotFeed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.18;

// inherited
import {Ownable2Step} from "openzeppelin/access/Ownable2Step.sol";
import "openzeppelin/access/Ownable2Step.sol";

// interfaces
import {ISpotFeed} from "../interfaces/ISpotFeed.sol";
Expand All @@ -22,7 +22,7 @@ contract SFPSpotFeed is ISpotFeed, Ownable2Step {
uint public minPrice = 0.98e18;
uint public maxPrice = 1.2e18;

constructor(IStrandsSFP _strandsSFP) {
constructor(IStrandsSFP _strandsSFP) Ownable(msg.sender) {
strandsSFP = _strandsSFP;
}

Expand Down
2 changes: 2 additions & 0 deletions src/feeds/static/LyraRateFeedStatic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ contract LyraRateFeedStatic is Ownable2Step, IInterestRateFeed {
int64 public rate;
uint64 public confidence;

constructor() Ownable(msg.sender) {}

////////////////////////
// Public Functions //
////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion src/feeds/static/LyraStaticSpotDiffFeed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ contract LyraStaticSpotDiffFeed is Ownable2Step, ISpotDiffFeed {
// Constructor //
////////////////////////

constructor() {}
constructor() Ownable(msg.sender) {}

////////////////////////
// Public Functions //
Expand Down
2 changes: 1 addition & 1 deletion src/feeds/static/LyraStaticSpotFeed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ contract LyraStaticSpotFeed is Ownable2Step, ISpotFeed {
// Constructor //
////////////////////////

constructor() {}
constructor() Ownable(msg.sender) {}

////////////////////////
// Public Functions //
Expand Down
2 changes: 1 addition & 1 deletion src/l2/LyraERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ contract LyraERC20 is Ownable2Step, ERC20 {

event MinterConfigured(address indexed minter, bool enabled);

constructor(string memory name_, string memory symbol_, uint8 decimals_) ERC20(name_, symbol_) {
constructor(string memory name_, string memory symbol_, uint8 decimals_) ERC20(name_, symbol_) Ownable(msg.sender) {
_decimals = decimals_;
}

Expand Down
4 changes: 2 additions & 2 deletions src/liquidation/DutchAuction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {IDutchAuction} from "../interfaces/IDutchAuction.sol";
import {ISubAccounts} from "../interfaces/ISubAccounts.sol";

// inherited
import "openzeppelin/security/ReentrancyGuard.sol";
import "openzeppelin/utils/ReentrancyGuard.sol";
import "openzeppelin/utils/math/SafeCast.sol";
import "openzeppelin/utils/math/SignedMath.sol";
import "lyra-utils/decimals/DecimalMath.sol";
Expand Down Expand Up @@ -80,7 +80,7 @@ contract DutchAuction is IDutchAuction, Ownable2Step, ReentrancyGuard {
// Constructor //
////////////////////////

constructor(ISubAccounts _subAccounts, ISecurityModule _securityModule, ICashAsset _cash) Ownable2Step() {
constructor(ISubAccounts _subAccounts, ISecurityModule _securityModule, ICashAsset _cash) Ownable(msg.sender) {
subAccounts = _subAccounts;
securityModule = _securityModule;
cash = _cash;
Expand Down
2 changes: 1 addition & 1 deletion src/risk-managers/BaseManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ abstract contract BaseManager is IBaseManager, Ownable2Step {
ICashAsset _cashAsset,
IDutchAuction _liquidation,
IBasePortfolioViewer _viewer
) Ownable2Step() {
) Ownable(msg.sender) {
subAccounts = _subAccounts;
cashAsset = _cashAsset;
liquidation = _liquidation;
Expand Down
2 changes: 1 addition & 1 deletion src/risk-managers/BasePortfolioViewer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ contract BasePortfolioViewer is Ownable2Step, IBasePortfolioViewer {
/// @dev OI fee rate in BPS. Charged fee = contract traded * OIFee * future price
mapping(address asset => uint) public OIFeeRateBPS;

constructor(ISubAccounts _subAccounts, ICashAsset _cash) {
constructor(ISubAccounts _subAccounts, ICashAsset _cash) Ownable(msg.sender) {
subAccounts = _subAccounts;
cashAsset = _cash;
}
Expand Down
2 changes: 1 addition & 1 deletion src/risk-managers/PMRM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.18;
import "openzeppelin/utils/math/SafeCast.sol";
import "openzeppelin/utils/math/Math.sol";
import "openzeppelin/utils/math/SignedMath.sol";
import "openzeppelin/security/ReentrancyGuard.sol";
import "openzeppelin/utils/ReentrancyGuard.sol";

import "lyra-utils/encoding/OptionEncoding.sol";
import "lyra-utils/decimals/DecimalMath.sol";
Expand Down
4 changes: 2 additions & 2 deletions src/risk-managers/PMRMLib.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.18;

import {Ownable2Step} from "openzeppelin/access/Ownable2Step.sol";
import "openzeppelin/access/Ownable2Step.sol";
import {SafeCast} from "openzeppelin/utils/math/SafeCast.sol";
import {SignedMath} from "openzeppelin/utils/math/SignedMath.sol";
import {Math} from "openzeppelin/utils/math/Math.sol";
Expand All @@ -27,7 +27,7 @@ contract PMRMLib is IPMRMLib, Ownable2Step {
MarginParameters internal marginParams;
VolShockParameters internal volShockParams;

constructor() Ownable2Step() {}
constructor() Ownable(msg.sender) {}

///////////
// Admin //
Expand Down
2 changes: 1 addition & 1 deletion src/risk-managers/StandardManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.13;
import "openzeppelin/utils/math/SafeCast.sol";
import "openzeppelin/utils/math/SignedMath.sol";
import "openzeppelin/utils/math/Math.sol";
import "openzeppelin/security/ReentrancyGuard.sol";
import "openzeppelin/utils/ReentrancyGuard.sol";

import "lyra-utils/decimals/DecimalMath.sol";
import "lyra-utils/decimals/SignedDecimalMath.sol";
Expand Down
2 changes: 1 addition & 1 deletion test/account/unit-tests/Permit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ contract UNIT_AccountPermit is Test, AccountTestBase {

function _signPermit(uint pk, IAllowances.PermitAllowance memory permit) internal view returns (bytes memory) {
bytes32 structHash = PermitAllowanceLib.hash(permit);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(pk, ECDSA.toTypedDataHash(domainSeparator, structHash));
(uint8 v, bytes32 r, bytes32 s) = vm.sign(pk, MessageHashUtils.toTypedDataHash(domainSeparator, structHash));
return bytes.concat(r, s, bytes1(v));
}
}
3 changes: 2 additions & 1 deletion test/assets/perpAsset/unit-tests/Funding.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity ^0.8.13;

import "forge-std/Test.sol";
import "forge-std/console2.sol";
import "openzeppelin/access/Ownable.sol";

import "../../../../src/SubAccounts.sol";
import "../../../../src/assets/PerpAsset.sol";
Expand Down Expand Up @@ -88,7 +89,7 @@ contract UNIT_PerpAssetFunding is Test {

function testCannotSetSpotFeedFromNonOwner() public {
vm.prank(alice);
vm.expectRevert(bytes("Ownable: caller is not the owner"));
vm.expectRevert(abi.encodeWithSelector(Ownable.OwnableUnauthorizedAccount.selector, alice));
perp.setSpotFeed(ISpotFeed(address(0)));
}

Expand Down
2 changes: 1 addition & 1 deletion test/feed/integration-tests/sfp-contracts/StrandsSFP.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ contract StrandsSFP is ERC4626 {
constructor(IERC20 depositToken) ERC4626(depositToken) ERC20("Strands Segregated Fund Proxy", "Strands.sfp") {}

function getSharePrice() external view returns (uint) {
return _convertToAssets(1 ether, Math.Rounding.Down);
return _convertToAssets(1 ether, Math.Rounding.Floor);
}
}
16 changes: 8 additions & 8 deletions test/feed/unit-tests/BaseFeed.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ contract UNIT_LyraSpotFeed is LyraFeedTestUtils {
bytes32 structHash = hashFeedData(feed, spotData);

// signed by pk
(uint8 v, bytes32 r, bytes32 s) = vm.sign(pk, ECDSA.toTypedDataHash(feed.domainSeparator(), structHash));
(uint8 v, bytes32 r, bytes32 s) = vm.sign(pk, MessageHashUtils.toTypedDataHash(feed.domainSeparator(), structHash));
spotData.signatures[0] = bytes.concat(r, s, bytes1(v));
spotData.signers[0] = pkOwner;
// signed by pk2
(v, r, s) = vm.sign(pk2, ECDSA.toTypedDataHash(feed.domainSeparator(), structHash));
(v, r, s) = vm.sign(pk2, MessageHashUtils.toTypedDataHash(feed.domainSeparator(), structHash));
spotData.signatures[1] = bytes.concat(r, s, bytes1(v));
spotData.signers[1] = pkOwner2;

Expand All @@ -93,7 +93,7 @@ contract UNIT_LyraSpotFeed is LyraFeedTestUtils {
bytes32 structHash = hashFeedData(feed, spotData);

// signed by pk
(uint8 v, bytes32 r, bytes32 s) = vm.sign(pk, ECDSA.toTypedDataHash(feed.domainSeparator(), structHash));
(uint8 v, bytes32 r, bytes32 s) = vm.sign(pk, MessageHashUtils.toTypedDataHash(feed.domainSeparator(), structHash));
spotData.signatures[0] = bytes.concat(r, s, bytes1(v));
spotData.signers[0] = pkOwner;

Expand All @@ -110,11 +110,11 @@ contract UNIT_LyraSpotFeed is LyraFeedTestUtils {
bytes32 structHash = hashFeedData(feed, spotData);

// signatures[0]: signed by pk
(uint8 v, bytes32 r, bytes32 s) = vm.sign(pk, ECDSA.toTypedDataHash(feed.domainSeparator(), structHash));
(uint8 v, bytes32 r, bytes32 s) = vm.sign(pk, MessageHashUtils.toTypedDataHash(feed.domainSeparator(), structHash));
spotData.signatures[0] = bytes.concat(r, s, bytes1(v));
spotData.signers[0] = pkOwner;
// signatures[1]: signed by pk
(v, r, s) = vm.sign(pk, ECDSA.toTypedDataHash(feed.domainSeparator(), structHash));
(v, r, s) = vm.sign(pk, MessageHashUtils.toTypedDataHash(feed.domainSeparator(), structHash));
spotData.signatures[1] = bytes.concat(r, s, bytes1(v));
spotData.signers[1] = pkOwner;

Expand All @@ -140,15 +140,15 @@ contract UNIT_LyraSpotFeed is LyraFeedTestUtils {
bytes32 structHash = hashFeedData(feed, spotData);

// signed by pk
(uint8 v, bytes32 r, bytes32 s) = vm.sign(pk, ECDSA.toTypedDataHash(feed.domainSeparator(), structHash));
(uint8 v, bytes32 r, bytes32 s) = vm.sign(pk, MessageHashUtils.toTypedDataHash(feed.domainSeparator(), structHash));
spotData.signatures[0] = bytes.concat(r, s, bytes1(v));
spotData.signers[0] = pkOwner;
// signed by pk2 (valid)
(v, r, s) = vm.sign(pk2, ECDSA.toTypedDataHash(feed.domainSeparator(), structHash));
(v, r, s) = vm.sign(pk2, MessageHashUtils.toTypedDataHash(feed.domainSeparator(), structHash));
spotData.signatures[1] = bytes.concat(r, s, bytes1(v));
spotData.signers[1] = pkOwner2;
// signatures[2]: signed by pk again
(v, r, s) = vm.sign(pk, ECDSA.toTypedDataHash(feed.domainSeparator(), structHash));
(v, r, s) = vm.sign(pk, MessageHashUtils.toTypedDataHash(feed.domainSeparator(), structHash));
spotData.signatures[2] = bytes.concat(r, s, bytes1(v));
spotData.signers[2] = pkOwner;

Expand Down
2 changes: 1 addition & 1 deletion test/feed/unit-tests/LyraFeedTestUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ contract LyraFeedTestUtils is Test {
{
bytes32 structHash = hashFeedData(feed, feedData);
bytes32 domainSeparator = feed.domainSeparator();
(uint8 v, bytes32 r, bytes32 s) = vm.sign(privateKey, ECDSA.toTypedDataHash(domainSeparator, structHash));
(uint8 v, bytes32 r, bytes32 s) = vm.sign(privateKey, MessageHashUtils.toTypedDataHash(domainSeparator, structHash));
feedData.signatures[0] = bytes.concat(r, s, bytes1(v));

// fill in signer if not set yet
Expand Down
2 changes: 1 addition & 1 deletion test/feed/unit-tests/LyraForwardFeed.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ contract UNIT_LyraForwardFeed is LyraFeedTestUtils {
abi.encode(defaultExpiry, settlementStartAggregate, currentSpotAggregate, newDiff, defaultConfidence);
feed.acceptData(_signFeedData(feed, pk, feedData));

vm.expectRevert("SafeCast: value must be positive");
vm.expectRevert(abi.encodeWithSelector(SafeCast.SafeCastOverflowedIntToUint.selector, -10e18));
feed.getForwardPrice(defaultExpiry);

vm.warp(block.timestamp + 1);
Expand Down
6 changes: 3 additions & 3 deletions test/integration-tests/assets/perpAsset/Migration.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ contract INTEGRATION_PerpMigration is IntegrationTestBase {

function testCannotOpenNewTrade() public {
// trade should revert
vm.expectRevert(bytes("ReentrancyGuard: reentrant call"));
vm.expectRevert(ReentrancyGuard.ReentrancyGuardReentrantCall.selector);
_tradePerpContract(markets["weth"].perp, danielAcc, bobAcc, 1e18);

// daniel and bob balances should not have changed
Expand All @@ -59,7 +59,7 @@ contract INTEGRATION_PerpMigration is IntegrationTestBase {

function testCannotTradeAfterDisabled() public {
// trade should revert
vm.expectRevert(bytes("ReentrancyGuard: reentrant call"));
vm.expectRevert(ReentrancyGuard.ReentrancyGuardReentrantCall.selector);
_tradePerpContract(markets["weth"].perp, charlieAcc, aliceAcc, 2e18);

// alice and charlie balances should not have changed
Expand Down Expand Up @@ -89,7 +89,7 @@ contract INTEGRATION_PerpMigration is IntegrationTestBase {

function testCannotPartiallyReduceBalances() public {
// trade should revert
vm.expectRevert(bytes("ReentrancyGuard: reentrant call"));
vm.expectRevert(ReentrancyGuard.ReentrancyGuardReentrantCall.selector);
_tradePerpContract(markets["weth"].perp, charlieAcc, aliceAcc, 5e17);
}

Expand Down
2 changes: 1 addition & 1 deletion test/integration-tests/shared/IntegrationTestBase.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ contract IntegrationTestBase is Test {
{
bytes32 structHash = hashFeedData(feed, feedData);
bytes32 domainSeparator = feed.domainSeparator();
(uint8 v, bytes32 r, bytes32 s) = vm.sign(privateKey, ECDSA.toTypedDataHash(domainSeparator, structHash));
(uint8 v, bytes32 r, bytes32 s) = vm.sign(privateKey, MessageHashUtils.toTypedDataHash(domainSeparator, structHash));
feedData.signatures[0] = bytes.concat(r, s, bytes1(v));
feedData.signers[0] = vm.addr(privateKey);

Expand Down
Loading
Loading