-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(contracts): make opportunity adapter upgradable (#30)
* feat(contracts): make opportunity adapter upgradable * Improve scripts for upgaradble adapter * Bump auction server
- Loading branch information
Showing
12 changed files
with
184 additions
and
22 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 |
---|---|---|
|
@@ -37,6 +37,9 @@ jobs: | |
- name: Install forge dependencies 2 | ||
working-directory: per_multicall | ||
run: forge install OpenZeppelin/openzeppelin-contracts --no-git --no-commit | ||
- name: Install forge dependencies 3 | ||
working-directory: per_multicall | ||
run: forge install OpenZeppelin/[email protected] --no-git --no-commit | ||
- uses: pre-commit/[email protected] | ||
if: ${{ github.event_name == 'pull_request' }} | ||
with: | ||
|
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 |
---|---|---|
|
@@ -24,6 +24,7 @@ COPY --from=npm_build /src/per_multicall/node_modules/ /src/per_multicall/node_m | |
WORKDIR /src/per_multicall | ||
RUN forge install foundry-rs/forge-std --no-git --no-commit | ||
RUN forge install OpenZeppelin/openzeppelin-contracts --no-git --no-commit | ||
RUN forge install OpenZeppelin/[email protected] --no-git --no-commit | ||
|
||
# Build auction-server | ||
WORKDIR /src | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
|
@@ -8,6 +8,7 @@ Run the following commands to install necessary libraries: | |
$ npm install | ||
$ forge install foundry-rs/forge-std --no-git --no-commit | ||
$ forge install OpenZeppelin/openzeppelin-contracts --no-git --no-commit | ||
$ forge install OpenZeppelin/[email protected] --no-git --no-commit | ||
``` | ||
|
||
## Repo contracts | ||
|
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,6 +1,6 @@ | ||
@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/ | ||
ds-test/=lib/forge-std/lib/ds-test/src/ | ||
erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/ | ||
forge-std/=lib/forge-std/src/ | ||
openzeppelin-contracts/=lib/openzeppelin-contracts/ | ||
openzeppelin-contracts-upgradable/=lib/openzeppelin-contracts-upgradable/ | ||
@pythnetwork/pyth-sdk-solidity=node_modules/@pythnetwork/pyth-sdk-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
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
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
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 |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// Copyright (C) 2024 Lavra Holdings Limited - All Rights Reserved | ||
pragma solidity ^0.8.13; | ||
|
||
import "./Errors.sol"; | ||
import "./Structs.sol"; | ||
import "./ExpressRelayFeeReceiver.sol"; | ||
import "./SigVerify.sol"; | ||
import "./ExpressRelay.sol"; | ||
import "./WETH9.sol"; | ||
|
||
import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; | ||
import "forge-std/console.sol"; | ||
import "openzeppelin-contracts/contracts/utils/Strings.sol"; | ||
import "openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol"; | ||
import "openzeppelin-contracts-upgradeable/contracts/proxy/utils/UUPSUpgradeable.sol"; | ||
import "openzeppelin-contracts-upgradeable/contracts/access/Ownable2StepUpgradeable.sol"; | ||
import {OpportunityAdapter} from "./OpportunityAdapter.sol"; | ||
|
||
contract OpportunityAdapterUpgradable is | ||
Initializable, | ||
Ownable2StepUpgradeable, | ||
UUPSUpgradeable, | ||
OpportunityAdapter | ||
{ | ||
event ContractUpgraded( | ||
address oldImplementation, | ||
address newImplementation | ||
); | ||
|
||
// The contract will have an owner and an admin | ||
// The owner will have all the power over it. | ||
// The admin can set some config parameters only. | ||
function initialize( | ||
address owner, | ||
address admin, | ||
address expressRelay, | ||
address weth | ||
) public initializer { | ||
require(owner != address(0), "owner is zero address"); | ||
require(admin != address(0), "admin is zero address"); | ||
require(expressRelay != address(0), "expressRelay is zero address"); | ||
require(weth != address(0), "weth is zero address"); | ||
|
||
__Ownable_init(); | ||
__UUPSUpgradeable_init(); | ||
|
||
OpportunityAdapter._initialize(admin, expressRelay, weth); | ||
|
||
// We need to transfer the ownership from deployer to the new owner | ||
_transferOwnership(owner); | ||
} | ||
|
||
/// Ensures the contract cannot be uninitialized and taken over. | ||
/// @custom:oz-upgrades-unsafe-allow constructor | ||
constructor() initializer {} | ||
|
||
// Only allow the owner to upgrade the proxy to a new implementation. | ||
function _authorizeUpgrade(address) internal override onlyOwner {} | ||
|
||
// We have not overridden these methods in Pyth contracts implementation. | ||
// But we are overriding them here because there was no owner before and | ||
// `_authorizeUpgrade` would cause a revert for these. Now we have an owner, and | ||
// because we want to test for the magic. We are overriding these methods. | ||
function upgradeTo(address newImplementation) external override onlyProxy { | ||
address oldImplementation = _getImplementation(); | ||
_authorizeUpgrade(newImplementation); | ||
_upgradeToAndCallUUPS(newImplementation, new bytes(0), false); | ||
|
||
magicCheck(); | ||
|
||
emit ContractUpgraded(oldImplementation, _getImplementation()); | ||
} | ||
|
||
function upgradeToAndCall( | ||
address newImplementation, | ||
bytes memory data | ||
) external payable override onlyProxy { | ||
address oldImplementation = _getImplementation(); | ||
_authorizeUpgrade(newImplementation); | ||
_upgradeToAndCallUUPS(newImplementation, data, true); | ||
|
||
magicCheck(); | ||
|
||
emit ContractUpgraded(oldImplementation, _getImplementation()); | ||
} | ||
|
||
function magicCheck() internal view { | ||
// Calling a method using `this.<method>` will cause a contract call that will use | ||
// the new contract. This call will fail if the method does not exists or the magic | ||
// is different. | ||
if (this.opportunityAdapterUpgradableMagic() != 0x12d9987e) | ||
revert InvalidMagicValue(); | ||
} | ||
|
||
function opportunityAdapterUpgradableMagic() public pure returns (uint32) { | ||
return 0x12d9987e; | ||
} | ||
|
||
function version() public pure returns (string memory) { | ||
return "0.1.0"; | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -26,6 +26,7 @@ COPY --from=npm_build /src/per_multicall/node_modules/ /src/per_multicall/node_m | |
WORKDIR /src/per_multicall | ||
RUN forge install foundry-rs/forge-std --no-git --no-commit | ||
RUN forge install OpenZeppelin/openzeppelin-contracts --no-git --no-commit | ||
RUN forge install OpenZeppelin/[email protected] --no-git --no-commit | ||
RUN forge build --via-ir | ||
|
||
|
||
|