generated from PaulRBerg/foundry-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from Tenderize/nv/audit-fixes
Clean up code, factory, deployment scripts, more tests
- Loading branch information
Showing
15 changed files
with
336 additions
and
389 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
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
Submodule openzeppelin-contracts
added at
dbb610
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,29 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.17; | ||
|
||
import { Script, console2 } from "forge-std/Script.sol"; | ||
import { SwapFactory } from "@tenderize/swap/Factory.sol"; | ||
import { ERC1967Proxy } from "openzeppelin-contracts/proxy/ERC1967/ERC1967Proxy.sol"; | ||
|
||
address constant FACTORY = address(0); | ||
|
||
uint256 constant VERSION = 1; | ||
|
||
contract Swap_Deploy is Script { | ||
// Contracts are deployed deterministically. | ||
// e.g. `foo = new Foo{salt: salt}(constructorArgs)` | ||
// The presence of the salt argument tells forge to use https://github.com/Arachnid/deterministic-deployment-proxy | ||
bytes32 constant SALT = bytes32(VERSION); | ||
|
||
// Start broadcasting with private key from `.env` file | ||
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); | ||
|
||
function run() public { | ||
vm.startBroadcast(deployerPrivateKey); | ||
address fac = address(new SwapFactory{ salt: SALT }()); | ||
address proxy = address(new ERC1967Proxy{ salt: SALT }(fac, abi.encodeWithSelector(SwapFactory.initialize.selector))); | ||
console2.log("SwapFactory deployed at: ", proxy); | ||
console2.log("Implementation deployed at: ", fac); | ||
vm.stopBroadcast(); | ||
} | ||
} |
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,68 @@ | ||
// SPDX-License-Identifier: MIT | ||
// | ||
// _____ _ _ | ||
// |_ _| | | (_) | ||
// | | ___ _ __ __| | ___ _ __ _ _______ | ||
// | |/ _ \ '_ \ / _` |/ _ \ '__| |_ / _ \ | ||
// | | __/ | | | (_| | __/ | | |/ / __/ | ||
// \_/\___|_| |_|\__,_|\___|_| |_/___\___| | ||
// | ||
// Copyright (c) Tenderize Labs Ltd | ||
|
||
pragma solidity ^0.8.20; | ||
|
||
import { Owned } from "solmate/auth/Owned.sol"; | ||
import { ERC1967Proxy } from "openzeppelin-contracts/proxy/ERC1967/ERC1967Proxy.sol"; | ||
import { TenderSwap, ConstructorConfig } from "@tenderize/swap/Swap.sol"; | ||
|
||
import { OwnableUpgradeable } from "openzeppelin-contracts-upgradeable/access/OwnableUpgradeable.sol"; | ||
import { Initializable } from "openzeppelin-contracts-upgradeable/proxy/utils/Initializable.sol"; | ||
import { UUPSUpgradeable } from "openzeppelin-contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; | ||
|
||
// Used for subgraph indexing and atomic deployments | ||
|
||
contract SwapFactory is Initializable, UUPSUpgradeable, OwnableUpgradeable { | ||
event SwapDeployed(address underlying, address swap, address implementation); | ||
event SwapUpgraded(address underlying, address swap, address implementation); | ||
|
||
mapping(address pool => uint256 v) public version; | ||
|
||
function initialize() public initializer { | ||
__Ownable_init(); | ||
__UUPSUpgradeable_init(); | ||
} | ||
|
||
constructor() { | ||
_disableInitializers(); | ||
} | ||
|
||
function deploy(ConstructorConfig memory cfg) external onlyOwner returns (address proxy, address implementation) { | ||
uint256 v = 1; | ||
// Deploy the implementation | ||
implementation = address(new TenderSwap{ salt: bytes32(v) }(cfg)); | ||
// deploy the contract | ||
proxy = address( | ||
new ERC1967Proxy{ salt: bytes32("tenderswap") }(implementation, abi.encodeWithSelector(TenderSwap.initialize.selector)) | ||
); | ||
|
||
TenderSwap(proxy).transferOwnership(owner()); | ||
version[proxy] = v; | ||
emit SwapDeployed(address(cfg.UNDERLYING), proxy, implementation); | ||
} | ||
|
||
function upgrade(ConstructorConfig memory cfg, address swapProxy) external onlyOwner returns (address implementation) { | ||
if (TenderSwap(swapProxy).UNDERLYING() != cfg.UNDERLYING) { | ||
revert("SwapFactory: UNDERLYING_MISMATCH"); | ||
} | ||
|
||
uint256 v = ++version[swapProxy]; | ||
|
||
implementation = address(new TenderSwap{ salt: bytes32(v) }(cfg)); | ||
|
||
TenderSwap(swapProxy).upgradeTo(implementation); | ||
} | ||
|
||
///@dev required by the OZ UUPS module | ||
// solhint-disable-next-line no-empty-blocks | ||
function _authorizeUpgrade(address) internal override onlyOwner { } | ||
} |
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
Oops, something went wrong.