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

feat: generate contract docs with forge doc #154

Merged
merged 3 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ cache
dist
node_modules
typechain-types
docs
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/zeta-chain/protocol-contracts"

[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();
90 changes: 90 additions & 0 deletions docs/src/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# ZetaChain Protocol Contracts

This repository contains ZetaChain protocol contracts: Solidity source code,
generated Go bindings, deployed contract addresses and helper utilities.

## Importing Protocol Contracts

As a dApp developer, you can install the protocol contracts package into your
project:

```
yarn add --dev @zetachain/protocol-contracts
```

Getting the TSS address on BSC testnet:

```ts
import { getAddress } from "@zetachain/protocol-contracts";

getAddress("tss", "zeta_testnet");
```

Getting a ZRC-20 BSC USDT on ZetaChain Mainnet Beta:

```ts
import { getAddress } from "@zetachain/protocol-contracts";

getAddress("zrc20", "zeta_mainnet", "USDT.BSC");
```

The third argument (symbol) is only used when querying ZRC-20 addresses to
specify which token address is needed.

To view a table of all contracts visit the [Contract Addresses](https://www.zetachain.com/docs/reference/contracts/) page in the docs.

Importing
[`ZetaInterfaces`](https://www.zetachain.com/docs/developers/cross-chain-messaging/connector/)
and `ZetaInteractor` for cross-chain messaging:

```solidity
import "@zetachain/protocol-contracts/contracts/evm/interfaces/ZetaInterfaces.sol";
import "@zetachain/protocol-contracts/contracts/evm/tools/ZetaInteractor.sol";
```

Importing [ZRC20](https://www.zetachain.com/docs/developers/tokens/zrc20/)
and the [system
contract](https://www.zetachain.com/docs/developers/omnichain/system-contract/)
for omni-chain smart contracts:

```solidity
import "@zetachain/protocol-contracts/contracts/zevm/interfaces/IZRC20.sol";
import "@zetachain/protocol-contracts/contracts/zevm/interfaces/zContract.sol";
import "@zetachain/protocol-contracts/contracts/zevm/SystemContract.sol";
```

## Prerequisites for Development

Before you can contribute to this project, you must have the following installed:

- [Node.js](https://nodejs.org/)
- [Yarn](https://yarnpkg.com/)
- [jq](https://stedolan.github.io/jq/)
- [abigen](https://geth.ethereum.org/docs/tools/abigen)

## Compiling Contracts

To compile the contracts, run the following command:

```
yarn compile
```

This will compile the Solidity contracts and output the resulting JSON artifacts
to the `artifacts` directory.

## Generating Go Bindings and Contract Addresses

To generate Go bindings for the Solidity contracts and fetch, run the following command:

```
yarn generate
```

This will use `abigen` to generate Go bindings for the contracts and output the
resulting Go files to the `pkg` directory.

## Contributing

If you would like to contribute to this project, please fork the repository and
submit a pull request. All contributions are welcome!
72 changes: 72 additions & 0 deletions docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Summary
- [Home](README.md)
# contracts
- [❱ evm](contracts/evm/README.md)
- [❱ interfaces](contracts/evm/interfaces/README.md)
- [ConnectorErrors](contracts/evm/interfaces/ConnectorErrors.sol/interface.ConnectorErrors.md)
- [ZetaErrors](contracts/evm/interfaces/ZetaErrors.sol/interface.ZetaErrors.md)
- [ZetaInteractorErrors](contracts/evm/interfaces/ZetaInteractorErrors.sol/interface.ZetaInteractorErrors.md)
- [ZetaInterfaces](contracts/evm/interfaces/ZetaInterfaces.sol/interface.ZetaInterfaces.md)
- [ZetaConnector](contracts/evm/interfaces/ZetaInterfaces.sol/interface.ZetaConnector.md)
- [ZetaReceiver](contracts/evm/interfaces/ZetaInterfaces.sol/interface.ZetaReceiver.md)
- [ZetaTokenConsumer](contracts/evm/interfaces/ZetaInterfaces.sol/interface.ZetaTokenConsumer.md)
- [ZetaCommonErrors](contracts/evm/interfaces/ZetaInterfaces.sol/interface.ZetaCommonErrors.md)
- [ZetaNonEthInterface](contracts/evm/interfaces/ZetaNonEthInterface.sol/interface.ZetaNonEthInterface.md)
- [❱ testing](contracts/evm/testing/README.md)
- [Victim](contracts/evm/testing/AttackerContract.sol/interface.Victim.md)
- [AttackerContract](contracts/evm/testing/AttackerContract.sol/contract.AttackerContract.md)
- [ERC20Mock](contracts/evm/testing/ERC20Mock.sol/contract.ERC20Mock.md)
- [INonfungiblePositionManager](contracts/evm/testing/TestUniswapV3Contracts.sol/interface.INonfungiblePositionManager.md)
- [IPoolInitializer](contracts/evm/testing/TestUniswapV3Contracts.sol/interface.IPoolInitializer.md)
- [ZetaInteractorMock](contracts/evm/testing/ZetaInteractorMock.sol/contract.ZetaInteractorMock.md)
- [ZetaReceiverMock](contracts/evm/testing/ZetaReceiverMock.sol/contract.ZetaReceiverMock.md)
- [❱ tools](contracts/evm/tools/README.md)
- [❱ interfaces](contracts/evm/tools/interfaces/README.md)
- [ConcentratedLiquidityPoolFactory](contracts/evm/tools/interfaces/TridentConcentratedLiquidityPoolFactory.sol/interface.ConcentratedLiquidityPoolFactory.md)
- [IPoolRouter](contracts/evm/tools/interfaces/TridentIPoolRouter.sol/interface.IPoolRouter.md)
- [Ownable](contracts/evm/tools/ImmutableCreate2Factory.sol/interface.Ownable.md)
- [ImmutableCreate2Factory](contracts/evm/tools/ImmutableCreate2Factory.sol/contract.ImmutableCreate2Factory.md)
- [ZetaInteractor](contracts/evm/tools/ZetaInteractor.sol/abstract.ZetaInteractor.md)
- [ZetaTokenConsumerUniV3Errors](contracts/evm/tools/ZetaTokenConsumerPancakeV3.strategy.sol/interface.ZetaTokenConsumerUniV3Errors.md)
- [WETH9](contracts/evm/tools/ZetaTokenConsumerPancakeV3.strategy.sol/interface.WETH9.md)
- [ISwapRouterPancake](contracts/evm/tools/ZetaTokenConsumerPancakeV3.strategy.sol/interface.ISwapRouterPancake.md)
- [ZetaTokenConsumerPancakeV3](contracts/evm/tools/ZetaTokenConsumerPancakeV3.strategy.sol/contract.ZetaTokenConsumerPancakeV3.md)
- [ZetaTokenConsumerTridentErrors](contracts/evm/tools/ZetaTokenConsumerTrident.strategy.sol/interface.ZetaTokenConsumerTridentErrors.md)
- [WETH9](contracts/evm/tools/ZetaTokenConsumerTrident.strategy.sol/interface.WETH9.md)
- [ZetaTokenConsumerTrident](contracts/evm/tools/ZetaTokenConsumerTrident.strategy.sol/contract.ZetaTokenConsumerTrident.md)
- [ZetaTokenConsumerUniV2Errors](contracts/evm/tools/ZetaTokenConsumerUniV2.strategy.sol/interface.ZetaTokenConsumerUniV2Errors.md)
- [ZetaTokenConsumerUniV2](contracts/evm/tools/ZetaTokenConsumerUniV2.strategy.sol/contract.ZetaTokenConsumerUniV2.md)
- [ZetaTokenConsumerUniV3Errors](contracts/evm/tools/ZetaTokenConsumerUniV3.strategy.sol/interface.ZetaTokenConsumerUniV3Errors.md)
- [WETH9](contracts/evm/tools/ZetaTokenConsumerUniV3.strategy.sol/interface.WETH9.md)
- [ZetaTokenConsumerUniV3](contracts/evm/tools/ZetaTokenConsumerUniV3.strategy.sol/contract.ZetaTokenConsumerUniV3.md)
- [ERC20Custody](contracts/evm/ERC20Custody.sol/contract.ERC20Custody.md)
- [ZetaEth](contracts/evm/Zeta.eth.sol/contract.ZetaEth.md)
- [ZetaNonEth](contracts/evm/Zeta.non-eth.sol/contract.ZetaNonEth.md)
- [ZetaConnectorBase](contracts/evm/ZetaConnector.base.sol/contract.ZetaConnectorBase.md)
- [ZetaConnectorEth](contracts/evm/ZetaConnector.eth.sol/contract.ZetaConnectorEth.md)
- [ZetaConnectorNonEth](contracts/evm/ZetaConnector.non-eth.sol/contract.ZetaConnectorNonEth.md)
- [❱ zevm](contracts/zevm/README.md)
- [❱ interfaces](contracts/zevm/interfaces/README.md)
- [IUniswapV2Router01](contracts/zevm/interfaces/IUniswapV2Router01.sol/interface.IUniswapV2Router01.md)
- [IUniswapV2Router02](contracts/zevm/interfaces/IUniswapV2Router02.sol/interface.IUniswapV2Router02.md)
- [IWETH9](contracts/zevm/interfaces/IWZETA.sol/interface.IWETH9.md)
- [IZRC20](contracts/zevm/interfaces/IZRC20.sol/interface.IZRC20.md)
- [zContext](contracts/zevm/interfaces/zContract.sol/struct.zContext.md)
- [zContract](contracts/zevm/interfaces/zContract.sol/interface.zContract.md)
- [❱ testing](contracts/zevm/testing/README.md)
- [SystemContractErrors](contracts/zevm/testing/SystemContractMock.sol/interface.SystemContractErrors.md)
- [SystemContractMock](contracts/zevm/testing/SystemContractMock.sol/contract.SystemContractMock.md)
- [ISystem](contracts/zevm/Interfaces.sol/interface.ISystem.md)
- [IZRC20](contracts/zevm/Interfaces.sol/interface.IZRC20.md)
- [IZRC20Metadata](contracts/zevm/Interfaces.sol/interface.IZRC20Metadata.md)
- [CoinType](contracts/zevm/Interfaces.sol/enum.CoinType.md)
- [SystemContractErrors](contracts/zevm/SystemContract.sol/interface.SystemContractErrors.md)
- [SystemContract](contracts/zevm/SystemContract.sol/contract.SystemContract.md)
- [UniswapImports](contracts/zevm/Uniswap.sol/contract.UniswapImports.md)
- [UniswapImports](contracts/zevm/UniswapPeriphery.sol/contract.UniswapImports.md)
- [WETH9](contracts/zevm/WZETA.sol/contract.WETH9.md)
- [ZRC20Errors](contracts/zevm/ZRC20.sol/interface.ZRC20Errors.md)
- [ZRC20](contracts/zevm/ZRC20.sol/contract.ZRC20.md)
- [ZetaInterfaces](contracts/zevm/ZetaConnectorZEVM.sol/interface.ZetaInterfaces.md)
- [ZetaReceiver](contracts/zevm/ZetaConnectorZEVM.sol/interface.ZetaReceiver.md)
- [ZetaConnectorZEVM](contracts/zevm/ZetaConnectorZEVM.sol/contract.ZetaConnectorZEVM.md)
5 changes: 5 additions & 0 deletions docs/src/contracts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@


# Contents
- [evm](/contracts/evm)
- [zevm](/contracts/zevm)
Loading
Loading