Skip to content

Commit

Permalink
feat: added contracts, tests, and workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
heueristik committed Oct 16, 2023
1 parent 5f9a383 commit d51846b
Show file tree
Hide file tree
Showing 70 changed files with 8,271 additions and 3,815 deletions.
3 changes: 3 additions & 0 deletions .czrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"path": "cz-conventional-changelog"
}
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# EditorConfig http://EditorConfig.org

# top-most EditorConfig file
root = true

# All files
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.sol]
indent_size = 4
31 changes: 31 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# GENERAL

## The network used for testing purposes
NETWORK_NAME="mainnet" # ["mainnet", "goerli", "polygon", "polygonMumbai"]

# CONTRACTS

## Hex encoded private keys separated by a comma `,`a
PRIVATE_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" # Default hardhat account 0 private key. DON'T USE FOR DEPLOYMENTS

## Infura credentials
INFURA_API_KEY="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"

## Gas Reporting
REPORT_GAS='true'
COINMARKETCAP_API_KEY="zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz"

## Block explorers
ETHERSCAN_API_KEY="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
POLYGONSCAN_API_KEY="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
BASESCAN_API_KEY="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"

# SUBGRAPH

## The Graph credentials
GRAPH_KEY="zzzzzzzzzzzz"

## Subgraph
SUBGRAPH_NAME="osx"
SUBGRAPH_VERSION="alice-debug-1s"
SUBGRAPH_NETWORK_NAME="goerli" # ["mainnet", "goerli", "polygon", "polygonMumbai"]
38 changes: 38 additions & 0 deletions .github/workflows/contracts-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: 'Contracts'

env:
INFURA_API_KEY: ${{ secrets.INFURA_API_KEY }}
working-directory: contracts

on:
push:
paths:
- 'contracts/**'
- '.github/workflows/contracts-*.yml'

jobs:
tests:
runs-on: 'ubuntu-latest'
defaults:
run:
working-directory: ${{env.working-directory}}
steps:
- name: 'Check out the repo'
uses: 'actions/checkout@v3'

- name: 'Install Node.js'
uses: 'actions/setup-node@v3'
with:
cache: 'yarn'
node-version: 16

- name: 'Install general dependencies'
run: 'yarn install'

- name: 'Build the contracts'
run: 'yarn build'
working-directory: contracts

- name: 'Test the contracts and generate the coverage report'
run: 'yarn coverage'
working-directory: contracts
1 change: 1 addition & 0 deletions .github/workflows/subgraph-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Subgraph
on:
push:
paths:
- 'contracts/**'
- 'subgraph/**'
- '.github/workflows/subgraph-*.yml'

Expand Down
7 changes: 7 additions & 0 deletions contracts/.solcover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
istanbulReporter: ['html', 'lcov'],
providerOptions: {
privateKey: process.env.PRIVATE_KEY,
},
skipFiles: ['test'],
};
19 changes: 19 additions & 0 deletions contracts/.solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "solhint:recommended",
"plugins": ["prettier"],
"rules": {
"code-complexity": ["error", 8],
"compiler-version": ["error", "^0.8.8"],
"func-visibility": ["error", {"ignoreConstructors": true}],
"max-line-length": ["off", 100],
"named-parameters-mapping": "warn",
"no-console": "error",
"not-rely-on-time": "error",
"prettier/prettier": [
"error",
{
"endOfLine": "auto"
}
]
}
}
3 changes: 3 additions & 0 deletions contracts/.solhintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# directories
**/artifacts
**/node_modules
35 changes: 35 additions & 0 deletions contracts/docs/templates/common.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{{h 2}} {{visibility}} {{toLowerCase type}} {{name}}

{{{natspec.notice}}}

{{#if signature}}
```solidity
{{{signature}}}
```
{{/if}}

{{#if natspec.params}}
| Input | Type | Description |
|:----- | ---- | ----------- |
{{#each params}}
| `{{{name}}}` | `{{{type}}}` | {{{joinLines natspec}}} |
{{/each}}
{{#if natspec.returns}}
| **Output** | |
{{#each returns}}
| {{#if name}} `{{name}}` {{else}} `{{@index}}` {{/if}} | `{{type}}` | {{{joinLines natspec}}} |
{{/each}}
{{/if}}
{{else}}
{{#if natspec.returns}}
| Output | Type | Description |
| ------ | ---- | ----------- |
{{#each returns}}
| {{#if name}} `{{{name}}}` {{else}} `{{{@index}}}` {{/if}} | `{{type}}` | {{{joinLines natspec}}} |
{{/each}}
{{/if}}
{{/if}}

{{#if natspec.dev}}
*{{{natspec.dev}}}*
{{/if}}
12 changes: 12 additions & 0 deletions contracts/docs/templates/contract.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## Description

{{{natspec.notice}}}

{{{natspec.dev}}}

## Implementation

{{#each items}}
{{>item}}
{{/each}}
<!--CONTRACT_END-->
9 changes: 9 additions & 0 deletions contracts/docs/templates/enum.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{>common}}

```solidity
enum {{name}} {
{{#each members}}
{{name}}{{#unless @last}},{{/unless}}
{{/each}}
}
```
1 change: 1 addition & 0 deletions contracts/docs/templates/error.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{>common}}
1 change: 1 addition & 0 deletions contracts/docs/templates/event.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{>common}}
1 change: 1 addition & 0 deletions contracts/docs/templates/function.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{>common}}
69 changes: 69 additions & 0 deletions contracts/docs/templates/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import {HelperOptions, Utils} from 'handlebars';

/**
* Returns a Markdown heading marker. An optional number increases the heading level.
*
* Input Output
* {{h}} {{name}} # Name
* {{h 2}} {{name}} ## Name
*/
export function h(opts: HelperOptions): string;
export function h(hsublevel: number, opts: HelperOptions): string;
export function h(hsublevel: number | HelperOptions, opts?: HelperOptions) {
const {hlevel} = getHLevel(hsublevel, opts);
return new Array(hlevel).fill('#').join('');
}

/**
* Delineates a section where headings should be increased by 1 or a custom number.
*
* {{#hsection}}
* {{>partial-with-headings}}
* {{/hsection}}
*/
export function hsection(opts: HelperOptions): string;
export function hsection(hsublevel: number, opts: HelperOptions): string;
export function hsection(
this: unknown,
hsublevel: number | HelperOptions,
opts?: HelperOptions
) {
let hlevel;
({hlevel, opts} = getHLevel(hsublevel, opts));
opts.data = Utils.createFrame(opts.data);
opts.data.hlevel = hlevel;
return opts.fn(this as unknown, opts);
}

/**
* Helper for dealing with the optional hsublevel argument.
*/
function getHLevel(hsublevel: number | HelperOptions, opts?: HelperOptions) {
if (opts === undefined) {
throw Error('opts are undefined');
}
if (typeof hsublevel === 'number') {
hsublevel = Math.max(1, hsublevel);
} else {
opts = hsublevel;
hsublevel = 1;
}
const contextHLevel: number = opts.data?.hlevel ?? 0;
return {opts, hlevel: contextHLevel + hsublevel};
}

export function trim(text: string) {
if (typeof text === 'string') {
return text.trim();
}
}

export function toLowerCase(text: string) {
return text.toLowerCase();
}

export function joinLines(text?: string) {
if (typeof text === 'string') {
return text.replace(/\n+/g, ' ');
}
}
1 change: 1 addition & 0 deletions contracts/docs/templates/modifier.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{>common}}
7 changes: 7 additions & 0 deletions contracts/docs/templates/page.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

{{#each items}}
{{#hsection}}
{{>item}}
{{/hsection}}

{{/each}}
9 changes: 9 additions & 0 deletions contracts/docs/templates/struct.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{>common}}

```solidity
struct {{name}} {
{{#each members}}
{{{typeName.typeDescriptions.typeString}}} {{name}};
{{/each}}
}
```
1 change: 1 addition & 0 deletions contracts/docs/templates/user-defined-value-type.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{>common}}
1 change: 1 addition & 0 deletions contracts/docs/templates/variable.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{>common}}
Loading

0 comments on commit d51846b

Please sign in to comment.