Skip to content

Commit

Permalink
Merge pull request #199 from valorem-labs-inc/audit-fixes-2
Browse files Browse the repository at this point in the history
Zellic audit #2 feedback
  • Loading branch information
0xAlcibiades authored Apr 4, 2023
2 parents f085ad0 + b7d28e2 commit 30f1778
Show file tree
Hide file tree
Showing 23 changed files with 507 additions and 417 deletions.
24 changes: 16 additions & 8 deletions .env.template
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
# Chain-specific
RPC_URL="XYZ"
GOERLI_RPC_URL="XYZ"
SEPOLIA_RPC_URL="XYZ"
PRIVATE_KEY="XYZ"
ETHERSCAN_API_KEY="XYZ"
# RPC Nodes
MAINNET_RPC_URL=""
GOERLI_RPC_URL=""
ARBITRUM_RPC_URL=""
ARBITRUM_GOERLI_RPC_URL=""

# Project
FEE_TO="XYZ"
# FeeTo Address
FEE_TO=""

# Credentials
PRIVATE_KEY=""
ETHERSCAN_API_KEY=""
ARBISCAN_API_KEY=""

# Salts
SALT_GENERATOR=""
SALT_ENGINE=""
229 changes: 82 additions & 147 deletions .gas-snapshot

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
RPC_URL: https://eth-mainnet.alchemyapi.io/v2/SzNcOCE77s6nmGIal7MxtuzF--q2HZgx

- name: Run tests
run: forge test --optimize --no-match-contract integration
run: forge test --optimize
env:
RPC_URL: https://eth-mainnet.alchemyapi.io/v2/SzNcOCE77s6nmGIal7MxtuzF--q2HZgx

Expand All @@ -47,7 +47,7 @@ jobs:
- name: Filter coverage directories
run: |
sudo apt update && sudo apt install -y lcov
lcov --remove lcov.info 'src/interfaces/*' 'test/*' 'script/*' --output-file lcov.info --rc lcov_branch_coverage=1
lcov --remove lcov.info 'src/TokenURIGenerator.sol' 'src/interfaces/*' 'test/*' 'script/*' --output-file lcov.info --rc lcov_branch_coverage=1
- uses: codecov/codecov-action@v3
with:
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Valorem Options V1 Core
# Valorem Options Clearinghouse V1

![ci](https://github.com/valorem-labs-inc/valorem-core/actions/workflows/CI.yml/badge.svg)
[![codecov](https://codecov.io/gh/valorem-labs-inc/valorem-core/branch/master/graph/badge.svg?token=M52NC4Q3SW)](https://codecov.io/gh/valorem-labs-inc/valorem-core)
Expand All @@ -13,9 +13,9 @@

## Introduction to the Protocol

The Valorem Options V1 Core consists of a settlement engine which allows users to write options, exercise options, and redeem claims on assets, while handling fair assignment of exercises to claims written. It is designed to be gas efficient, minimal, and provide a secure settlement layer upon which more complex systems can be built.
The Valorem Options Clearinghouse V1 consists of a clearing and settling engine which allows users to write options, exercise options, and redeem claims on assets, while handling fair assignment of exercises to claims written. It is designed to be gas efficient, minimal, and provide a secure settlement layer upon which more complex systems can be built.

The Settlement Engine follows the [ERC-1155 multi-token](https://eips.ethereum.org/EIPS/eip-1155) standard. Options can be written for any pair of valid ERC-20 assets (excluding rebasing, fee-on-transfer, and ERC-777 tokens). When written, an options contract is represented by semi-fungible Option tokens, which can be bought/sold/transferred between addresses like any ERC-1155 token.
The Clearinghouse follows the [ERC-1155 multi-token](https://eips.ethereum.org/EIPS/eip-1155) standard. Options can be written for any pair of valid ERC-20 assets (excluding rebasing, fee-on-transfer, and ERC-777 tokens). When written, an option contract is represented by semi-fungible Option tokens, which can be bought/sold/transferred between addresses like any ERC-1155 token.

An option writer's claim to the underlying asset(s) (if not exercised) and exercise asset(s) (if exercised) is represented by a non-fungible option lot Claim token. This Claim NFT can be redeemed for their share of the underlying plus exercise assets, based on currently exercised.

Expand All @@ -28,7 +28,7 @@ The structure of an option is as follows:
- **Exercise timestamp:** the timestamp after which this option can be exercised and physically settled.
- **Expiry timestamp:** the timestamp before which this option can be exercised.

The Core is unopinionated on the type of option (call vs. put), where, when, or for how much an option is bought/sold, and whether or not the option is profitable when exercised. Because all options written with Valorem are fully collateralized, physical settlement at exercise or redeem time is instant and gas-efficient.
The Clearinghouse is unopinionated on the type of option (call vs. put), where, when, or for how much an option is bought/sold, and whether or not the option is profitable when exercised. Because all options written with Valorem are fully collateralized, physical settlement at exercise or redeem time is instant and gas-efficient.

Read the [litepaper](https://valorem.xyz/docs/valorem-options-litepaper/) for more insight into the business use cases that Valorem enables.

Expand Down
31 changes: 31 additions & 0 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: BUSL 1.1
// Valorem Labs Inc. (c) 2023.
pragma solidity 0.8.16;

import "forge-std/Script.sol";

import "../src/TokenURIGenerator.sol";
import "../src/ValoremOptionsClearinghouse.sol";

contract DeployScript is Script {
// Command to deploy:
// forge script script/Deploy.s.sol --rpc-url=<RPC_URL> --broadcast --slow

function run() public {
// Get environment variables.
address feeTo = vm.envAddress("FEE_TO");
uint256 privateKey = vm.envUint("PRIVATE_KEY");
bytes32 saltGenerator = keccak256(bytes(vm.envString("SALT_GENERATOR")));
bytes32 saltEngine = keccak256(bytes(vm.envString("SALT_ENGINE")));

// Deploy TokenURIGenerator.
vm.startBroadcast(privateKey);
TokenURIGenerator generator = new TokenURIGenerator{salt: saltGenerator}();
vm.stopBroadcast();

// Deploy ValoremOptionsClearinghouse.
vm.startBroadcast(privateKey);
new ValoremOptionsClearinghouse{salt: saltEngine}(feeTo, address(generator));
vm.stopBroadcast();
}
}
25 changes: 0 additions & 25 deletions script/ValoremDeploy.s.sol

This file was deleted.

10 changes: 5 additions & 5 deletions src/TokenURIGenerator.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// SPDX-License-Identifier: BUSL 1.1
// Valorem Labs Inc. (c) 2022.
// Valorem Labs Inc. (c) 2023.
pragma solidity 0.8.16;

import "base64/Base64.sol";
import "solmate/tokens/ERC20.sol";

import "./interfaces/IOptionSettlementEngine.sol";
import "./interfaces/IValoremOptionsClearinghouse.sol";
import "./interfaces/ITokenURIGenerator.sol";

/// @title Library to dynamically generate Valorem token URIs
Expand Down Expand Up @@ -65,7 +65,7 @@ contract TokenURIGenerator is ITokenURIGenerator {
function generateDescription(TokenURIParams memory params) public pure returns (string memory) {
return string(
abi.encodePacked(
"NFT representing a Valorem options contract. ",
"NFT representing a Valorem option contract. ",
params.underlyingSymbol,
" Address: ",
addressToString(params.underlyingAsset),
Expand Down Expand Up @@ -108,7 +108,7 @@ contract TokenURIGenerator is ITokenURIGenerator {
function _generateHeaderSection(
string memory _underlyingSymbol,
string memory _exerciseSymbol,
IOptionSettlementEngine.TokenType _tokenType
IValoremOptionsClearinghouse.TokenType _tokenType
) internal pure returns (string memory) {
return string(
abi.encodePacked(
Expand All @@ -119,7 +119,7 @@ contract TokenURIGenerator is ITokenURIGenerator {
_exerciseSymbol,
"</text>"
),
_tokenType == IOptionSettlementEngine.TokenType.Option
_tokenType == IValoremOptionsClearinghouse.TokenType.Option
?
"<text x='16px' y='80px' font-size='16' fill='#fff' font-family='Helvetica' font-weight='300'>Long Call</text>"
:
Expand Down
Loading

0 comments on commit 30f1778

Please sign in to comment.