Skip to content

Commit 39a8757

Browse files
author
cwsnt
committed
SOV:4621 migrated to foundry docs
1 parent 94f13d5 commit 39a8757

254 files changed

Lines changed: 34361 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,68 @@
1414
- [brownie](https://github.com/eth-brownie/brownie/) v1.12.4 or greater
1515
- [solc-select](https://github.com/crytic/solc-select) only if you are having multiple solc installed locally and globally.
1616

17+
## Documentation Generation
18+
19+
The project uses Foundry's built-in documentation generator to create comprehensive documentation from NatSpec comments in the smart contracts.
20+
21+
### Prerequisites
22+
23+
1. Install Rust and Cargo (required for mdBook):
24+
```bash
25+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
26+
```
27+
28+
2. Install mdBook using Cargo:
29+
```bash
30+
cargo install mdbook
31+
```
32+
33+
### Available Documentation Scripts
34+
35+
The following npm scripts are available for documentation:
36+
37+
1. Generate documentation:
38+
```bash
39+
yarn doc:forge
40+
```
41+
42+
2. View documentation in browser:
43+
```bash
44+
yarn doc:serve
45+
```
46+
47+
3. Generate and view documentation in one command:
48+
```bash
49+
yarn doc:forge-all
50+
```
51+
52+
### Documentation Structure
53+
54+
- Documentation is generated from NatSpec comments in the contracts
55+
- Output is stored in `foundry/docs/`
56+
- Documentation is served at `http://localhost:3000` by default
57+
- The documentation includes:
58+
- Contract interfaces and inheritance
59+
- Function documentation
60+
- Events documentation
61+
- State variables
62+
- Custom errors
63+
64+
### Updating Documentation
65+
66+
1. Add or update NatSpec comments in your Solidity files
67+
2. Run `yarn doc:forge` to regenerate the documentation
68+
3. View changes using `yarn doc:serve`
69+
70+
### Configuration
71+
72+
Documentation generation settings can be found in `foundry.toml`:
73+
```toml
74+
[doc]
75+
out = 'foundry/docs'
76+
ignore = ['contracts/mockup/**/*.sol','contracts/testhelpers/**/*.sol']
77+
```
78+
1779
## Setup and Testing
1880

1981
First install all the npm packages:

foundry/docs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
book/

foundry/docs/book.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
table {
2+
margin: 0 auto;
3+
border-collapse: collapse;
4+
width: 100%;
5+
}
6+
7+
table td:first-child {
8+
width: 15%;
9+
}
10+
11+
table td:nth-child(2) {
12+
width: 25%;
13+
}

foundry/docs/book.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[book]
2+
src = "src"
3+
title = ""
4+
5+
[output.html]
6+
no-section-label = true
7+
additional-js = ["solidity.min.js"]
8+
additional-css = ["book.css"]
9+
git-repository-url = "https://github.com/DistributedCollective/Sovryn-smart-contracts"
10+
11+
[output.html.fold]
12+
enable = true

foundry/docs/solidity.min.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
hljs.registerLanguage("solidity",(()=>{"use strict";function e(){try{return!0
2+
}catch(e){return!1}}
3+
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|\$)/
4+
;e()&&(a=a.source.replace(/\\b/g,"(?<!\\$)\\b"));var s={className:"number",
5+
begin:a,relevance:0},n={
6+
keyword:"assembly let function if switch case default for leave break continue u256 jump jumpi stop return revert selfdestruct invalid",
7+
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",
8+
literal:"true false"},i={className:"string",
9+
begin:/\bhex'(([0-9a-fA-F]{2}_?)*[0-9a-fA-F]{2})?'/},t={className:"string",
10+
begin:/\bhex"(([0-9a-fA-F]{2}_?)*[0-9a-fA-F]{2})?"/};function r(e){
11+
return e.inherit(e.APOS_STRING_MODE,{begin:/(\bunicode)?'/})}function l(e){
12+
return e.inherit(e.QUOTE_STRING_MODE,{begin:/(\bunicode)?"/})}var o={
13+
SOL_ASSEMBLY_KEYWORDS:n,baseAssembly:e=>{
14+
var a=r(e),o=l(e),c=/[A-Za-z_$][A-Za-z_$0-9.]*/,d=e.inherit(e.TITLE_MODE,{
15+
begin:/[A-Za-z$_][0-9A-Za-z$_]*/,lexemes:c,keywords:n}),u={className:"params",
16+
begin:/\(/,end:/\)/,excludeBegin:!0,excludeEnd:!0,lexemes:c,keywords:n,
17+
contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,a,o,s]},_={
18+
className:"operator",begin:/:=|->/};return{keywords:n,lexemes:c,
19+
contains:[a,o,i,t,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,s,_,{
20+
className:"function",lexemes:c,beginKeywords:"function",end:"{",excludeEnd:!0,
21+
contains:[d,u,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,_]}]}},
22+
solAposStringMode:r,solQuoteStringMode:l,HEX_APOS_STRING_MODE:i,
23+
HEX_QUOTE_STRING_MODE:t,SOL_NUMBER:s,isNegativeLookbehindAvailable:e}
24+
;const{baseAssembly:c,solAposStringMode:d,solQuoteStringMode:u,HEX_APOS_STRING_MODE:_,HEX_QUOTE_STRING_MODE:m,SOL_NUMBER:b,isNegativeLookbehindAvailable:E}=o
25+
;return e=>{for(var a=d(e),s=u(e),n=[],i=0;i<32;i++)n[i]=i+1
26+
;var t=n.map((e=>8*e)),r=[];for(i=0;i<=80;i++)r[i]=i
27+
;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={
28+
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",
29+
literal:"true false wei gwei szabo finney ether seconds minutes hours days weeks years",
30+
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"
31+
},O={className:"operator",begin:/[+\-!~*\/%<>&^|=]/
32+
},C=/[A-Za-z_$][A-Za-z_$0-9]*/,N={className:"params",begin:/\(/,end:/\)/,
33+
excludeBegin:!0,excludeEnd:!0,lexemes:C,keywords:p,
34+
contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,a,s,b,"self"]},f={
35+
begin:/\.\s*/,end:/[^A-Za-z0-9$_\.]/,excludeBegin:!0,excludeEnd:!0,keywords:{
36+
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"
37+
},relevance:2},y=e.inherit(e.TITLE_MODE,{begin:/[A-Za-z$_][0-9A-Za-z$_]*/,
38+
lexemes:C,keywords:p}),w={className:"built_in",
39+
begin:(E()?"(?<!\\$)\\b":"\\b")+"(gas|value|salt)(?=:)"};function x(e,a){return{
40+
begin:(E()?"(?<!\\$)\\b":"\\b")+e+"\\.\\s*",end:/[^A-Za-z0-9$_\.]/,
41+
excludeBegin:!1,excludeEnd:!0,lexemes:C,keywords:{built_in:e+" "+a},
42+
contains:[f],relevance:10}}var h=c(e),v=e.inherit(h,{
43+
contains:h.contains.concat([{begin:/\./,end:/[^A-Za-z0-9$.]/,excludeBegin:!0,
44+
excludeEnd:!0,keywords:{built_in:"slot offset length address selector"},
45+
relevance:2},{begin:/_/,end:/[^A-Za-z0-9$.]/,excludeBegin:!0,excludeEnd:!0,
46+
keywords:{built_in:"slot offset"},relevance:2}])});return{aliases:["sol"],
47+
keywords:p,lexemes:C,
48+
contains:[a,s,_,m,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,b,w,O,{
49+
className:"function",lexemes:C,
50+
beginKeywords:"function modifier event constructor fallback receive error",
51+
end:/[{;]/,excludeEnd:!0,
52+
contains:[y,N,w,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE],illegal:/%/
53+
},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,{
54+
className:"class",lexemes:C,beginKeywords:"contract interface library",end:"{",
55+
excludeEnd:!0,illegal:/[:"\[\]]/,contains:[{beginKeywords:"is",lexemes:C
56+
},y,N,w,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE]},{lexemes:C,
57+
beginKeywords:"struct enum",end:"{",excludeEnd:!0,illegal:/[:"\[\]]/,
58+
contains:[y,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE]},{
59+
beginKeywords:"import",end:";",lexemes:C,keywords:"import from as",
60+
contains:[y,a,s,_,m,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,O]},{
61+
beginKeywords:"using",end:";",lexemes:C,keywords:"using for",
62+
contains:[y,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,O]},{className:"meta",
63+
beginKeywords:"pragma",end:";",lexemes:C,keywords:{
64+
keyword:"pragma solidity experimental abicoder",
65+
built_in:"ABIEncoderV2 SMTChecker v1 v2"},
66+
contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,e.inherit(a,{
67+
className:"meta-string"}),e.inherit(s,{className:"meta-string"})]},{
68+
beginKeywords:"assembly",end:/\b\B/,
69+
contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,e.inherit(v,{begin:"{",
70+
end:"}",endsParent:!0,contains:v.contains.concat([e.inherit(v,{begin:"{",
71+
end:"}",contains:v.contains.concat(["self"])})])})]}],illegal:/#/}}})());
72+
73+
// Ugly hack to reload HLJS
74+
hljs.initHighlightingOnLoad();

0 commit comments

Comments
 (0)