Skip to content

Commit

Permalink
Update readme and add docs (#31)
Browse files Browse the repository at this point in the history
* Update readme
* Generate contract docs
* Deploy verified contracts
  • Loading branch information
alexkeating authored Jun 20, 2023
1 parent 1ee0d62 commit 575807f
Show file tree
Hide file tree
Showing 20 changed files with 2,943 additions and 63 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# Perpetual Protocol Optimizoors

<p align="center">
<b>This repo does not contain production ready code and is still a work in progress.</b>
</p>
⚠️ **This code is not audited. Use at your own risk.**

- [About](#about)
- [Development](#development)
- [Instructions](#instructions)
- [Contracts](docs/src/SUMMARY.md)
- [Addresses](#addresses)
- [License](#license)


## About

Perpetual Optimizoors provides a calldata-optimized router for [Perpetual Protocol](https://perp.com/),
Expand All @@ -32,6 +33,12 @@ forge test
forge build
```

## Addresses

| Name | Address |
|----------|:-------------:|
| Perpetual Router Factory | 0xbF2870611603b2f02B8616E0fE65C60f7657a0f4|

### How it works

We have a router factory which deploys calldata optimized routers for specific functionality within
Expand Down
174 changes: 174 additions & 0 deletions broadcast/Deploy.s.sol/10/run-1687281092.json

Large diffs are not rendered by default.

123 changes: 63 additions & 60 deletions broadcast/Deploy.s.sol/10/run-latest.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
book/
13 changes: 13 additions & 0 deletions docs/book.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
table {
margin: 0 auto;
border-collapse: collapse;
width: 100%;
}

table td:first-child {
width: 15%;
}

table td:nth-child(2) {
width: 25%;
}
12 changes: 12 additions & 0 deletions docs/book.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[book]
src = "src"
title = ""

[output.html]
no-section-label = true
additional-js = ["solidity.min.js"]
additional-css = ["book.css"]
git-repository-url = "https://github.com/ScopeLift/optimizoors-perpetual-protocol"

[output.html.fold]
enable = true
74 changes: 74 additions & 0 deletions docs/solidity.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
hljs.registerLanguage("solidity",(()=>{"use strict";function e(){try{return!0
}catch(e){return!1}}
var a=/-?(\b0[xX]([a-fA-F0-9]_?)*[a-fA-F0-9]|(\b[1-9](_?\d)*(\.((\d_?)*\d)?)?|\.\d(_?\d)*)([eE][-+]?\d(_?\d)*)?|\b0)(?!\w|\$)/
;e()&&(a=a.source.replace(/\\b/g,"(?<!\\$)\\b"));var s={className:"number",
begin:a,relevance:0},n={
keyword:"assembly let function if switch case default for leave break continue u256 jump jumpi stop return revert selfdestruct invalid",
built_in:"add sub mul div sdiv mod smod exp not lt gt slt sgt eq iszero and or xor byte shl shr sar addmod mulmod signextend keccak256 pc pop dup1 dup2 dup3 dup4 dup5 dup6 dup7 dup8 dup9 dup10 dup11 dup12 dup13 dup14 dup15 dup16 swap1 swap2 swap3 swap4 swap5 swap6 swap7 swap8 swap9 swap10 swap11 swap12 swap13 swap14 swap15 swap16 mload mstore mstore8 sload sstore msize gas address balance selfbalance caller callvalue calldataload calldatasize calldatacopy codesize codecopy extcodesize extcodecopy returndatasize returndatacopy extcodehash create create2 call callcode delegatecall staticcall log0 log1 log2 log3 log4 chainid origin gasprice basefee blockhash coinbase timestamp number difficulty gaslimit",
literal:"true false"},i={className:"string",
begin:/\bhex'(([0-9a-fA-F]{2}_?)*[0-9a-fA-F]{2})?'/},t={className:"string",
begin:/\bhex"(([0-9a-fA-F]{2}_?)*[0-9a-fA-F]{2})?"/};function r(e){
return e.inherit(e.APOS_STRING_MODE,{begin:/(\bunicode)?'/})}function l(e){
return e.inherit(e.QUOTE_STRING_MODE,{begin:/(\bunicode)?"/})}var o={
SOL_ASSEMBLY_KEYWORDS:n,baseAssembly:e=>{
var a=r(e),o=l(e),c=/[A-Za-z_$][A-Za-z_$0-9.]*/,d=e.inherit(e.TITLE_MODE,{
begin:/[A-Za-z$_][0-9A-Za-z$_]*/,lexemes:c,keywords:n}),u={className:"params",
begin:/\(/,end:/\)/,excludeBegin:!0,excludeEnd:!0,lexemes:c,keywords:n,
contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,a,o,s]},_={
className:"operator",begin:/:=|->/};return{keywords:n,lexemes:c,
contains:[a,o,i,t,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,s,_,{
className:"function",lexemes:c,beginKeywords:"function",end:"{",excludeEnd:!0,
contains:[d,u,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,_]}]}},
solAposStringMode:r,solQuoteStringMode:l,HEX_APOS_STRING_MODE:i,
HEX_QUOTE_STRING_MODE:t,SOL_NUMBER:s,isNegativeLookbehindAvailable:e}
;const{baseAssembly:c,solAposStringMode:d,solQuoteStringMode:u,HEX_APOS_STRING_MODE:_,HEX_QUOTE_STRING_MODE:m,SOL_NUMBER:b,isNegativeLookbehindAvailable:E}=o
;return e=>{for(var a=d(e),s=u(e),n=[],i=0;i<32;i++)n[i]=i+1
;var t=n.map((e=>8*e)),r=[];for(i=0;i<=80;i++)r[i]=i
;var l=n.map((e=>"bytes"+e)).join(" ")+" ",o=t.map((e=>"uint"+e)).join(" ")+" ",g=t.map((e=>"int"+e)).join(" ")+" ",M=[].concat.apply([],t.map((e=>r.map((a=>e+"x"+a))))),p={
keyword:"var bool string int uint "+g+o+"byte bytes "+l+"fixed ufixed "+M.map((e=>"fixed"+e)).join(" ")+" "+M.map((e=>"ufixed"+e)).join(" ")+" enum struct mapping address new delete if else for while continue break return throw emit try catch revert unchecked _ function modifier event constructor fallback receive error virtual override constant immutable anonymous indexed storage memory calldata external public internal payable pure view private returns import from as using pragma contract interface library is abstract type assembly",
literal:"true false wei gwei szabo finney ether seconds minutes hours days weeks years",
built_in:"self this super selfdestruct suicide now msg block tx abi blockhash gasleft assert require Error Panic sha3 sha256 keccak256 ripemd160 ecrecover addmod mulmod log0 log1 log2 log3 log4"
},O={className:"operator",begin:/[+\-!~*\/%<>&^|=]/
},C=/[A-Za-z_$][A-Za-z_$0-9]*/,N={className:"params",begin:/\(/,end:/\)/,
excludeBegin:!0,excludeEnd:!0,lexemes:C,keywords:p,
contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,a,s,b,"self"]},f={
begin:/\.\s*/,end:/[^A-Za-z0-9$_\.]/,excludeBegin:!0,excludeEnd:!0,keywords:{
built_in:"gas value selector address length push pop send transfer call callcode delegatecall staticcall balance code codehash wrap unwrap name creationCode runtimeCode interfaceId min max"
},relevance:2},y=e.inherit(e.TITLE_MODE,{begin:/[A-Za-z$_][0-9A-Za-z$_]*/,
lexemes:C,keywords:p}),w={className:"built_in",
begin:(E()?"(?<!\\$)\\b":"\\b")+"(gas|value|salt)(?=:)"};function x(e,a){return{
begin:(E()?"(?<!\\$)\\b":"\\b")+e+"\\.\\s*",end:/[^A-Za-z0-9$_\.]/,
excludeBegin:!1,excludeEnd:!0,lexemes:C,keywords:{built_in:e+" "+a},
contains:[f],relevance:10}}var h=c(e),v=e.inherit(h,{
contains:h.contains.concat([{begin:/\./,end:/[^A-Za-z0-9$.]/,excludeBegin:!0,
excludeEnd:!0,keywords:{built_in:"slot offset length address selector"},
relevance:2},{begin:/_/,end:/[^A-Za-z0-9$.]/,excludeBegin:!0,excludeEnd:!0,
keywords:{built_in:"slot offset"},relevance:2}])});return{aliases:["sol"],
keywords:p,lexemes:C,
contains:[a,s,_,m,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,b,w,O,{
className:"function",lexemes:C,
beginKeywords:"function modifier event constructor fallback receive error",
end:/[{;]/,excludeEnd:!0,
contains:[y,N,w,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE],illegal:/%/
},x("msg","gas value data sender sig"),x("block","blockhash coinbase difficulty gaslimit basefee number timestamp chainid"),x("tx","gasprice origin"),x("abi","decode encode encodePacked encodeWithSelector encodeWithSignature encodeCall"),x("bytes","concat"),f,{
className:"class",lexemes:C,beginKeywords:"contract interface library",end:"{",
excludeEnd:!0,illegal:/[:"\[\]]/,contains:[{beginKeywords:"is",lexemes:C
},y,N,w,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE]},{lexemes:C,
beginKeywords:"struct enum",end:"{",excludeEnd:!0,illegal:/[:"\[\]]/,
contains:[y,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE]},{
beginKeywords:"import",end:";",lexemes:C,keywords:"import from as",
contains:[y,a,s,_,m,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,O]},{
beginKeywords:"using",end:";",lexemes:C,keywords:"using for",
contains:[y,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,O]},{className:"meta",
beginKeywords:"pragma",end:";",lexemes:C,keywords:{
keyword:"pragma solidity experimental abicoder",
built_in:"ABIEncoderV2 SMTChecker v1 v2"},
contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,e.inherit(a,{
className:"meta-string"}),e.inherit(s,{className:"meta-string"})]},{
beginKeywords:"assembly",end:/\b\B/,
contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,e.inherit(v,{begin:"{",
end:"}",endsParent:!0,contains:v.contains.concat([e.inherit(v,{begin:"{",
end:"}",contains:v.contains.concat(["self"])})])})]}],illegal:/#/}}})());

// Ugly hack to reload HLJS
hljs.initHighlightingOnLoad();
49 changes: 49 additions & 0 deletions docs/src/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Perpetual Protocol Optimizoors

⚠️ **This code is not audited. Use at your own risk.**

- [About](#about)
- [Development](#development)
- [Instructions](#instructions)
- [License](#license)


## About

Perpetual Optimizoors provides a calldata-optimized router for [Perpetual Protocol](https://perp.com/),
providing significant gas savings to users. This work was funded by an Ethereum Foundation
[grant](https://blog.ethereum.org/2023/02/14/layer-2-grants-roundup). Read our [blog post](https://www.scopelift.co/blog/calldata-optimizooooors) to learn more about how we optimize protocols on L2.

## Development

### Instructions

To get started, clone this repo, then follow the below instructions:

```sh
# run these commands from the workspace root!
cp .env.example .env

# Run tests
forge test

# Build smart contracts
forge build
```

### How it works

We have a router factory which deploys calldata optimized routers for specific functionality within
Perpetual Protocol. Currently, we have two types of routers. One that has the functionality for opening and closing
positions which we call the `PositionRouter`, and another to deposit ERC20 or Ethereum into a Perpetual vault which
we call the `DepositRouter`.

There will be one `PositionRouter` contract per position token. For example if a user is opening a vETH
position they will have to call the vETH position router. The same is also true for a `DepositRouter`. There
will a `DepositRouter` contract per token.

## License

This project is available under the [MIT](LICENSE.txt) license.

Copyright (c) 2023 ScopeLift
13 changes: 13 additions & 0 deletions docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Summary
- [Home](README.md)
# src
- [❱ interface](src/interface/README.md)
- [IAccountBalance](src/interface/IAccountBalance.sol/interface.IAccountBalance.md)
- [IClearingHouse](src/interface/IClearingHouse.sol/interface.IClearingHouse.md)
- [IVault](src/interface/IVault.sol/interface.IVault.md)
- [❱ lib](src/lib/README.md)
- [AccountMarket](src/lib/AccountMarket.sol/library.AccountMarket.md)
- [Create2](src/lib/Create2.sol/library.Create2.md)
- [DepositRouter](src/DepositRouter.sol/contract.DepositRouter.md)
- [PerpetualPositionRouter](src/PerpetualPositionRouter.sol/contract.PerpetualPositionRouter.md)
- [PerpetualRouterFactory](src/PerpetualRouterFactory.sol/contract.PerpetualRouterFactory.md)
59 changes: 59 additions & 0 deletions docs/src/src/DepositRouter.sol/contract.DepositRouter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# DepositRouter
[Git Source](https://github.com/ScopeLift/optimizoors-perpetual-protocol/blob/1a3cdb1ddd1ba9b2c3010057997c040c5a815dac/src/DepositRouter.sol)

A router for depositing funds into the Perpetual vault. It supports a single ERC20 token
and Ether.


## State Variables
### TOKEN
The token that is being deposited into the router.


```solidity
address public immutable TOKEN;
```


### PERPETUAL_VAULT
The contract for the Perpetual vault where the deposits are sent.


```solidity
IVault public immutable PERPETUAL_VAULT;
```


## Functions
### constructor


```solidity
constructor(address token, IVault vault);
```
**Parameters**

|Name|Type|Description|
|----|----|-----------|
|`token`|`address`|Address of the token that is being deposited into the router.|
|`vault`|`IVault`|Address of the Perpetual vault where the deposits are sent.|


### fallback

Deposits the router's token into the Perpetual vault.


```solidity
fallback() external payable;
```

### receive

Deposits Ether into the Perpetual vault.


```solidity
receive() external payable;
```

Loading

0 comments on commit 575807f

Please sign in to comment.