Skip to content

Commit

Permalink
fix(contracts): TokenVault cleanup (#31)
Browse files Browse the repository at this point in the history
* feat(docs): Add verification guideline for blockscout and etherscan

* fix(contracts): set broadcaster in deployOpportunityAdapter as it can be called directly

* fix(refactor): Cleanup TokenVault
  - vaultID -> vaultId
  - Better comments and naming

* fix(refactor): Use express relay package for interfaces
  • Loading branch information
m30m authored Mar 19, 2024
1 parent 6b232f9 commit a4e2838
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 67 deletions.
10 changes: 10 additions & 0 deletions per_multicall/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,13 @@ fs_permissions = [{ access = "read-write", path = "./"}]
```

This permits the vm to access any file in the root directory via read-write operations.

# Verification

For verifying contracts, you can use the `forge verify-contract` command.
For example, to verify the ERC1967Proxy contract on the Optimism network, you can run the following commands:

```
forge verify-contract --via-ir <contract-address> ERC1967Proxy --verifier blockscout --verifier-url https://optimism-sepolia.blockscout.com/api/
forge verify-contract --via-ir <contract-address> ERC1967Proxy --verifier-url https://api-sepolia-optimistic.etherscan.io/api
```
6 changes: 6 additions & 0 deletions per_multicall/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions per_multicall/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"dependencies": {
"@pythnetwork/express-relay-sdk-solidity": "^0.2.0",
"@pythnetwork/pyth-sdk-solidity": "^2.3.0"
}
}
1 change: 1 addition & 0 deletions per_multicall/remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ 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/
@pythnetwork/express-relay-sdk-solidity/=node_modules/@pythnetwork/express-relay-sdk-solidity
15 changes: 10 additions & 5 deletions per_multicall/script/Vault.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ contract VaultScript is Script {
address expressRelay,
address wethAddress
) public returns (address) {
(, uint256 skDeployer) = getDeployer();
vm.startBroadcast(skDeployer);
OpportunityAdapterUpgradable _opportunityAdapter = new OpportunityAdapterUpgradable();
// deploy proxy contract and point it to implementation
ERC1967Proxy proxy = new ERC1967Proxy(address(_opportunityAdapter), "");
Expand All @@ -58,15 +60,18 @@ contract VaultScript is Script {
payable(proxy)
);
opportunityAdapter.initialize(owner, admin, expressRelay, wethAddress);
vm.stopBroadcast();
return address(opportunityAdapter);
}

function upgradeOpportunityAdapter(address currentImplementation) public {
(address deployer, uint256 skDeployer) = getDeployer();
function upgradeOpportunityAdapter(address proxyAddress) public {
(, uint256 skDeployer) = getDeployer();
vm.startBroadcast(skDeployer);
OpportunityAdapterUpgradable _newImplementation = new OpportunityAdapterUpgradable();
// Proxy object is technically an OpportunityAdapterUpgradable because it points to an implementation
// of such contract. Therefore we can call the upgradeTo function on it.
OpportunityAdapterUpgradable proxy = OpportunityAdapterUpgradable(
payable(currentImplementation)
payable(proxyAddress)
);
proxy.upgradeTo(address(_newImplementation));
vm.stopBroadcast();
Expand Down Expand Up @@ -523,11 +528,11 @@ contract VaultScript is Script {
return balance;
}

function getVault(uint256 vaultID) public view returns (Vault memory) {
function getVault(uint256 vaultId) public view returns (Vault memory) {
string memory json = vm.readFile(latestEnvironmentPath);
address tokenVaultLatest = vm.parseJsonAddress(json, ".tokenVault");
Vault memory vault = TokenVault(payable(tokenVaultLatest)).getVault(
vaultID
vaultId
);
console.log(
"vault amounts are",
Expand Down
8 changes: 4 additions & 4 deletions per_multicall/src/ExpressRelay.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ pragma solidity ^0.8.13;

import "./Errors.sol";
import "./Structs.sol";
import "./ExpressRelayFeeReceiver.sol";

import "forge-std/console.sol";
import "openzeppelin-contracts/contracts/utils/Strings.sol";
import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import "@pythnetwork/express-relay-sdk-solidity/IExpressRelay.sol";
import "@pythnetwork/express-relay-sdk-solidity/IExpressRelayFeeReceiver.sol";

contract ExpressRelay {
contract ExpressRelay is IExpressRelay {
event ReceivedETH(address sender, uint256 amount);

// TODO: separate the notion operator into relayer and admin.
Expand Down Expand Up @@ -133,7 +133,7 @@ contract ExpressRelay {
uint256 feeProtocol = feeProtocolNumerator /
1000_000_000_000_000_000;
if (_isContract(feeReceiver)) {
ExpressRelayFeeReceiver(feeReceiver).receiveAuctionProceedings{
IExpressRelayFeeReceiver(feeReceiver).receiveAuctionProceedings{
value: feeProtocol
}(permissionKey);
} else {
Expand Down
8 changes: 0 additions & 8 deletions per_multicall/src/ExpressRelayFeeReceiver.sol

This file was deleted.

2 changes: 0 additions & 2 deletions per_multicall/src/OpportunityAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
pragma solidity ^0.8.13;

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";

abstract contract OpportunityAdapter is SigVerify {
Expand Down
2 changes: 0 additions & 2 deletions per_multicall/src/OpportunityAdapterUpgradable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ 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";
Expand Down
13 changes: 6 additions & 7 deletions per_multicall/src/SearcherVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
pragma solidity ^0.8.13;

import "openzeppelin-contracts/contracts/utils/Strings.sol";
import "forge-std/console.sol";

import "./Errors.sol";
import "./Structs.sol";
Expand Down Expand Up @@ -38,14 +37,14 @@ contract SearcherVault is SigVerify {
/**
* @notice doLiquidate function - liquidates a vault through express relay
*
* @param vaultID: ID of the vault to be liquidated
* @param vaultId: ID of the vault to be liquidated
* @param bid: size of the bid to pay to express relay
* @param validUntil: timestamp at which signatureSearcher is no longer valid
* @param updateData: data to update price feed with
* @param signatureSearcher: signature of the vaultID and bid, signed by the searcher's EOA, to be verified if msg.sender is express relay
* @param signatureSearcher: signature of the vaultId and bid, signed by the searcher's EOA, to be verified if msg.sender is express relay
*/
function doLiquidate(
uint256 vaultID,
uint256 vaultId,
uint256 bid,
uint256 validUntil,
bytes calldata updateData,
Expand All @@ -58,7 +57,7 @@ contract SearcherVault is SigVerify {
if (msg.sender == expressRelay) {
bool validSignatureSearcher = verifyCalldata(
owner,
abi.encode(vaultID, bid, validUntil),
abi.encode(vaultId, bid, validUntil),
signatureSearcher
);
if (!validSignatureSearcher) {
Expand All @@ -74,7 +73,7 @@ contract SearcherVault is SigVerify {

address payable vaultContract = payable(tokenVault);

Vault memory vault = TokenVault(vaultContract).getVault(vaultID);
Vault memory vault = TokenVault(vaultContract).getVault(vaultId);

address tokenDebt = vault.tokenDebt;
uint256 tokenAmount = vault.amountDebt;
Expand All @@ -83,7 +82,7 @@ contract SearcherVault is SigVerify {
bytes[] memory updateDatas = new bytes[](1);
updateDatas[0] = updateData;
TokenVault(vaultContract).liquidateWithPriceUpdate(
vaultID,
vaultId,
updateDatas
);
if (bid > 0) {
Expand Down
Loading

0 comments on commit a4e2838

Please sign in to comment.