Skip to content

Commit

Permalink
Merge pull request #432 from primitivefinance/v1.4.0-beta-release-prep
Browse files Browse the repository at this point in the history
Deployment addresses, audit commits, updated docs
  • Loading branch information
Alexangelj authored Oct 23, 2023
2 parents c35bbfc + 99bc530 commit 00a770c
Show file tree
Hide file tree
Showing 18 changed files with 1,844 additions and 513 deletions.
84 changes: 32 additions & 52 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,52 +1,32 @@
TestRMM01:testFuzz_changeParameters(uint16,uint16,uint16) (runs: 10000, μ: 363354, ~: 363518)
TestRMM01:testFuzz_createPool(uint16,uint16,uint16,uint16,uint16,uint128,uint128) (runs: 10000, μ: 201062, ~: 190373)
TestRMM01:testFuzz_fund_then_draw(uint64) (runs: 10000, μ: 640427, ~: 640432)
TestRMM01:test_allocate_balances_increase() (gas: 747698)
TestRMM01:test_allocate_does_not_modify_timestamp() (gas: 721218)
TestRMM01:test_allocate_liquidity_overflow_reverts() (gas: 333599)
TestRMM01:test_allocate_modifies_liquidity() (gas: 731248)
TestRMM01:test_allocate_non_existent_pool_reverts() (gas: 46168)
TestRMM01:test_allocate_reserves_increase() (gas: 748973)
TestRMM01:test_allocate_reserves_increase_six_decimals() (gas: 749333)
TestRMM01:test_allocate_zero_liquidity_reverts() (gas: 333596)
TestRMM01:test_changeParameters_priority_fee_success() (gas: 363537)
TestRMM01:test_claim_credits_balance_asset() (gas: 1739536)
TestRMM01:test_claim_get_balance_returns_fee_amount_asset() (gas: 1126889)
TestRMM01:test_claim_get_balance_returns_fee_amount_quote() (gas: 1267102)
TestRMM01:test_claim_position_owed_amounts_returns_zero() (gas: 1138770)
TestRMM01:test_claim_small_liquidity_does_not_steal_fees() (gas: 1835588)
TestRMM01:test_claim_succeeds() (gas: 1552908)
TestRMM01:test_createPair_fetch_pair_data_returns_token_data() (gas: 1482969)
TestRMM01:test_createPair_fetch_pair_id_returns_non_zero() (gas: 1478372)
TestRMM01:test_createPair_nonce_increments_returns_one() (gas: 1478880)
TestRMM01:test_createPair_success() (gas: 1476912)
TestRMM01:test_createPool_non_controlled_default_jit() (gas: 183374)
TestRMM01:test_deallocate_max() (gas: 900263)
TestRMM01:test_deposit_ether_balance_equals_zero() (gas: 159134)
TestRMM01:test_deposit_ether_balance_of_weth_equals_msg_value() (gas: 159696)
TestRMM01:test_deposit_increases_user_weth_balance() (gas: 167619)
TestRMM01:test_deposit_reserve_equals_msg_value() (gas: 164251)
TestRMM01:test_deposit_weth_total_supply_equals_msg_value() (gas: 161475)
TestRMM01:test_draw_max_balance() (gas: 557773)
TestRMM01:test_draw_reduces_user_balance() (gas: 557859)
TestRMM01:test_draw_weth_transfers_ether() (gas: 242314)
TestRMM01:test_fund_increases_user_balance() (gas: 482493)
TestRMM01:test_fund_max_balance() (gas: 482492)
TestRMM01:test_revert_changeParameters_invalid_fee() (gas: 348973)
TestRMM01:test_revert_changeParameters_invalid_jit() (gas: 348576)
TestRMM01:test_revert_changeParameters_not_controller() (gas: 347545)
TestRMM01:test_revert_changeParameters_priority_fee_above_max() (gas: 360133)
TestRMM01:test_revert_claim_no_position() (gas: 336074)
TestRMM01:test_revert_createPair_asset_lower_decimal_bound() (gas: 1387955)
TestRMM01:test_revert_createPair_asset_upper_decimal_bound() (gas: 1388031)
TestRMM01:test_revert_createPair_exists() (gas: 346704)
TestRMM01:test_revert_createPair_quote_lower_decimal_bound() (gas: 1388035)
TestRMM01:test_revert_createPair_quote_upper_decimal_bound() (gas: 1388111)
TestRMM01:test_revert_createPair_same_token() (gas: 699838)
TestRMM01:test_revert_createPool_above_max_pairs() (gas: 1033031)
TestRMM01:test_revert_createPool_above_max_pools() (gas: 27892)
TestRMM01:test_revert_createPool_priority_fee_invalid_fee() (gas: 65236)
TestRMM01:test_revert_createPool_zero_price() (gas: 19257)
TestRMM01:test_revert_draw_greater_than_balance() (gas: 339917)
TestRMM01:test_swap_increases_user_balance_token_out() (gas: 1107628)
TestRMM01:test_version() (gas: 6969)
TestGas:test_gas_chain_allocate_deallocate_from_portfolio_balance() (gas: 155363)
TestGas:test_gas_chain_create_allocate_from_portfolio() (gas: 460784)
TestGas:test_gas_chain_swap_allocate_from_portfolio() (gas: 327801)
TestGas:test_gas_chain_swap_deallocate_create_allocate_from_portfolio() (gas: 470302)
TestGas:test_gas_create_pool_allocate_transfer_from_wallet() (gas: 460492)
TestGas:test_gas_multi_allocate_10() (gas: 853389)
TestGas:test_gas_multi_allocate_100() (gas: 7461628)
TestGas:test_gas_multi_allocate_2() (gas: 395302)
TestGas:test_gas_multi_allocate_25() (gas: 1769294)
TestGas:test_gas_multi_allocate_2_pairs() (gas: 515736)
TestGas:test_gas_multi_allocate_5() (gas: 564596)
TestGas:test_gas_multi_allocate_50() (gas: 3460599)
TestGas:test_gas_multi_create_pool_100() (gas: 264444)
TestGas:test_gas_multi_deallocate_10() (gas: 448246)
TestGas:test_gas_multi_deallocate_100() (gas: 4156306)
TestGas:test_gas_multi_deallocate_2() (gas: 264442)
TestGas:test_gas_multi_deallocate_25() (gas: 857111)
TestGas:test_gas_multi_deallocate_2_pool_2_pair() (gas: 365064)
TestGas:test_gas_multi_deallocate_5() (gas: 330573)
TestGas:test_gas_multi_deallocate_50() (gas: 1724360)
TestGas:test_gas_multi_swap_10() (gas: 1100287)
TestGas:test_gas_multi_swap_100() (gas: 12966986)
TestGas:test_gas_multi_swap_2() (gas: 389117)
TestGas:test_gas_multi_swap_25() (gas: 2788271)
TestGas:test_gas_multi_swap_5() (gas: 641773)
TestGas:test_gas_multi_swap_50() (gas: 5859558)
TestGas:test_gas_single_allocate() (gas: 339512)
TestGas:test_gas_single_allocate_from_portfolio_balance() (gas: 339459)
TestGas:test_gas_single_deallocate() (gas: 244731)
TestGas:test_gas_single_swap() (gas: 307095)
TestGas:test_gas_single_swap_from_portfolio_balance() (gas: 305376)
TestGas:test_gas_single_swap_from_wallet() (gas: 307011)
2 changes: 1 addition & 1 deletion .github/workflows/gas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ jobs:
with:
version: nightly

- name: Run gas profiling for RMM01Portfolio
- name: Run gas profiling
run: FOUNDRY_PROFILE=optimized forge test --gas-report --match-contract TestGas

2 changes: 1 addition & 1 deletion .github/workflows/optimized.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ jobs:
- name: Run build
run: FOUNDRY_PROFILE=optimized forge build --sizes --skip test

- name: Run tests RMM01Portfolio
- name: Run tests
run: FOUNDRY_PROFILE=optimized forge test
107 changes: 84 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,62 @@
> Beta: Not production ready. Pending on-going audits.
> Beta: Portfolio is experimental software. Use at your own risk.
# Portfolio by Primitive
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/primitivefinance/portfolio#contributing) [![](https://dcbadge.vercel.app/api/server/primitive?style=flat)](https://discord.gg/primitive) [![Twitter Badge](https://badgen.net/badge/icon/twitter?icon=twitter&label)](https://twitter.com/primitivefi)

Portfolio is an automated market making protocol for implementing custom liquidity distribution strategies at the lowest cost possible.

[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/primitivefinance/portfolio#contributing) [![](https://dcbadge.vercel.app/api/server/primitive?style=flat)](https://discord.gg/primitive) [![Twitter Badge](https://badgen.net/badge/icon/twitter?icon=twitter&label)](https://twitter.com/primitivefi)
## Table of Contents

- [Overview](#overview)
- [Deployments](#deployments)
- [Security](#security)
- [Install](#install)
- [Documentation](#documentation)
- [Resources](#resources)
- [Contributing](#contributing)
- [License](#license)

## Overview

Portfolio is an automated market making protocol for creating custom liquidity distribution strategies at the lowest cost possible. Each pool in Portfolio can be created with a default strategy or custom strategy that defines a trading function, determining the available prices offered by the provider's liquidity. These pools all exist within the single Portfolio smart contract resulting in significantly lower gas costs for liquidity providers and swappers.

Read the local [docs](./docs/src/), hosted docs [docs.primitive.xyz](https://docs.primitive.xyz), or the [formal specification](https://primitive.xyz/whitepaper) for more information.


## Deployments

### Canonical Cross-chain Deployment Addresses

| Contract | Canonical cross-chain address |
| -------------------- | -------------------------------------------- |
| Portfolio 1.3.0-beta | `0x82360b9a2076a09ea8abe2b3e11aed89de3a02d1` |
| Portfolio 1.4.0-beta | `todo` |

### Deployments by Chain

| Network | Portfolio 1.3.0-beta | Portfolio v1.4.0-beta |
| -------- | ----------------------------------------------------------------------------------------------------------------------------- | --------------------- |
| Ethereum | [0x82360b9a2076a09ea8abe2b3e11aed89de3a02d1](https://etherscan.io/address/0x82360b9a2076a09ea8abe2b3e11aed89de3a02d1 ) | todo |
| Base | n/a | todo |
| Sepolia | [0x82360b9a2076a09ea8abe2b3e11aed89de3a02d1](https://sepolia.etherscan.io/address/0x82360b9a2076a09ea8abe2b3e11aed89de3a02d1) | todo |

## Installation
# Security

[Visit Primitive Security](https://www.primitive.xyz/security) to view a comprehensive overview of the security initiatives of Portfolio.

## Audits

| Security Firm | Date | Review Time | Status | Final Commit w/ Fixes |
| ------------------------------------------------------------------------------------------------------------- | ---------- | ----------- | --------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| [ChainSecurity](https://github.com/primitivefinance/security/blob/main/audits/portfolio/chainsecurity.pdf) | 2022-05-31 | 8-weeks | Completed | [c6f692f41c1d20ac09acb832923bd46500fd8e06](https://github.com/primitivefinance/portfolio/commit/c6f692f41c1d20ac09acb832923bd46500fd8e06) |
| [Trail of Bits](https://github.com/primitivefinance/security/blob/main/audits/portfolio/trailofbits.pdf) | 2023-01-31 | 8-weeks | Completed | n/a |
| [Spearbit #1](https://github.com/primitivefinance/security/blob/main/audits/portfolio/spearbit.pdf) | 2023-03-31 | 5-weeks | Completed | [tag/v1.1.0-beta](https://github.com/primitivefinance/portfolio/releases/tag/v1.1.0-beta) |
| [Spearbit #1 Extension](https://github.com/primitivefinance/security/blob/main/audits/portfolio/spearbit.pdf) | 2023-05-12 | 2-weeks | Competed | [36e9efa28332fa03f6d5910edda2fec2f5937190](https://github.com/primitivefinance/portfolio/commit/36e9efa28332fa03f6d5910edda2fec2f5937190 ) |
| Spearbit #2 | 2023-07-78 | 2-weeks | Completed | [tag/v1.4.0-beta-spearbit-2023-08-complete](https://github.com/primitivefinance/portfolio/releases/tag/v1.4.0-beta-spearbit-2023-08-complete) |

## Install

To install locally and compile contracts:

#### [Required] Foundry. [Source](https://github.com/foundry-rs/foundry).
If not installed, run the following:
Expand All @@ -17,26 +67,40 @@ curl -L https://foundry.paradigm.xyz | bash
# Restart terminal or reload `PATH`, then run foundryup
foundryup
```
#### [Required] Install Deps
```bash
forge install
```

### Install & Run
#### Usage

##### Testing
```bash
forge install & forge test
FOUNDRY_PROFILE=test forge test
```

# Security
##### Building
```bash
FOUNDRY_PROFILE=optimized forge build --skip test
```

[Visit Primitive Security](https://www.primitive.xyz/security) to view a comprehensive overview of the security initiatives of Portfolio.
##### Coverage

[Optional] Install coverage gutters [vs code extension](https://github.com/ryanluker/vscode-coverage-gutters).

Then run this to generate a coverage report:

```bash
forge coverage --report lcov
```

### Install Artifacts via NPM
To install the artifacts to use in your own project:

## Audits

| Security Firm | Review Time | Status |
| ------------------ | ----------- | --------- |
| ChainSecurity | 8-weeks | Completed |
| Trail of Bits | 8-weeks | Completed |
| Spearbit | 5-weeks | Completed |
| Spearbit Extension | 2-weeks | Competed |
| Spearbit Extension #2 | 2-weeks | Pending |
```bash
npm install @primitivexyz/portfolio
```


# Documentation
Expand Down Expand Up @@ -73,15 +137,7 @@ cd docs
mdbook serve --open
```

## coverage

[Optional] Install coverage gutters [vs code extension](https://github.com/ryanluker/vscode-coverage-gutters).

Then run this to generate a coverage report:

```bash
forge coverage --report lcov
```

## Resources

Expand Down Expand Up @@ -113,3 +169,8 @@ When making a pull request:
- New tests for all new features or code paths.
- If making a modification to third-party dependencies, yarn audit passes.
- A descriptive summary of the PR has been provided.


## Copyright

[AGPL-3.0](./LICENSE) © 2023 Primitive Bits, Inc.
40 changes: 40 additions & 0 deletions contracts/PortfolioRegistry.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.4;

import "./interfaces/IERC20.sol";
import "./interfaces/IPortfolioRegistry.sol";
import "solmate/auth/Owned.sol";

interface PortfolioLike {
function setProtocolFee(uint256) external;
function claimFee(address, uint256) external;
}

/// @dev Basic registry with a single owner.
contract PortfolioRegistry is IPortfolioRegistry, Owned {
constructor(address owner_) Owned(owner_) { }

function controller() external view returns (address) {
return owner;
}

function setFee(address portfolio, uint256 fee) external onlyOwner {
PortfolioLike(portfolio).setProtocolFee(fee);
}

function claimFee(
address portfolio,
address token,
uint256 amount
) public onlyOwner {
PortfolioLike(portfolio).claimFee(token, amount);
}

function withdraw(address token, uint256 amount) external onlyOwner {
require(amount > 0, "SimpleRegistry/invalid-amount");
require(
IERC20(token).transfer(msg.sender, amount),
"SimpleRegistry/transfer-failed"
);
}
}
Loading

0 comments on commit 00a770c

Please sign in to comment.