Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zellic audit #2 feedback #199

Merged
merged 28 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4072f81
forge install: create3
neodaoist Jan 10, 2023
fe69a21
Add basic CREATE3 scripting for deploying the core
neodaoist Jan 10, 2023
751e437
Remove unneeded remapping
neodaoist Jan 10, 2023
9e4ec97
Remove unneeded additional lib
neodaoist Jan 10, 2023
68226a7
Deterministic deploys are working
neodaoist Jan 14, 2023
b16b8fa
Update .env.template
neodaoist Jan 14, 2023
2bad2d9
Deterministic deploys
0xAlcibiades Jan 16, 2023
55a738d
POC bucket events supporting off-chain claim accounting
neodaoist Jan 20, 2023
66ccdda
idea: Add new event type for bucket being written into
neodaoist Jan 21, 2023
6706c00
Normalize event ordering slightly
neodaoist Jan 21, 2023
039b978
Replace dummy values with actual when emitting BucketAssignedExercise…
neodaoist Jan 24, 2023
bbd6e10
Lint
neodaoist Jan 24, 2023
5c4e2eb
Tweak comment for clarity
neodaoist Jan 24, 2023
655e0cc
Add claimId to BucketWrittenInto; Update topics
neodaoist Jan 25, 2023
7a6899d
Support off-chain claim accounting via bucket events
0xAlcibiades Jan 31, 2023
b6ba55b
:recycle: Address Zellic audit 2 feedback 3.1 -- Bucket for exercise(…
neodaoist Mar 30, 2023
30266a7
fmt
neodaoist Mar 30, 2023
597bf62
:recycle: Address Zellic audit 2 feedback 3.1
0xAlcibiades Mar 31, 2023
48cdbac
Syntax -- Rename OptionSettlementEngine to ValoremOptionsClearinghous…
neodaoist Apr 1, 2023
fa65a89
Semantics -- Correct mutability of feeBps from immutable to constant
neodaoist Apr 1, 2023
f3eca99
Re-enable integration tests; Exclude non-Clearinghouse from coverage
neodaoist Apr 1, 2023
3cbfc85
Keep contract name as `engine` in test suite
neodaoist Apr 3, 2023
973f348
Keep contract name as `engine` in test actors
neodaoist Apr 3, 2023
1fa785d
Update trust model based on latest impl
neodaoist Apr 3, 2023
9b8d5de
Update comment to reflect business logic
neodaoist Apr 3, 2023
74b2157
Update comment to reflect business logic
neodaoist Apr 3, 2023
d1f8870
Merge branch 'audit-fixes-2' into final-prep
neodaoist Apr 3, 2023
b7d28e2
Merge pull request #201 from valorem-labs-inc/final-prep
neodaoist Apr 3, 2023
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
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