-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from violetprotocol/dev
v0.1.0
- Loading branch information
Showing
57 changed files
with
18,290 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
extends: | ||
- "@commitlint/config-conventional" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"path": "cz-conventional-changelog" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
INFURA_API_KEY="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" | ||
MNEMONIC="here is where your twelve words mnemonic should be put my friend" | ||
PRIVATE_KEY="0xyourprivatekey" | ||
|
||
# Block explorer API keys | ||
ARBSCAN_API_KEY="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" | ||
BSCSCAN_API_KEY="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" | ||
ETHERSCAN_API_KEY="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" | ||
OPTIMISM_API_KEY="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" | ||
POLYGONSCAN_API_KEY="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" | ||
SNOWTRACE_API_KEY="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# directories | ||
.yarn/ | ||
**/.coverage_artifacts | ||
**/.coverage_cache | ||
**/.coverage_contracts | ||
**/artifacts | ||
**/build | ||
**/cache | ||
**/coverage | ||
**/dist | ||
**/node_modules | ||
**/types | ||
|
||
# files | ||
*.env | ||
*.log | ||
.pnp.* | ||
coverage.json | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
extends: | ||
- "eslint:recommended" | ||
- "plugin:@typescript-eslint/eslint-recommended" | ||
- "plugin:@typescript-eslint/recommended" | ||
- "prettier" | ||
parser: "@typescript-eslint/parser" | ||
parserOptions: | ||
project: "tsconfig.json" | ||
plugins: | ||
- "@typescript-eslint" | ||
root: true | ||
rules: | ||
"@typescript-eslint/no-floating-promises": | ||
- error | ||
- ignoreIIFE: true | ||
ignoreVoid: true | ||
"@typescript-eslint/no-inferrable-types": "off" | ||
"@typescript-eslint/no-unused-vars": | ||
- error | ||
- argsIgnorePattern: "_" | ||
varsIgnorePattern: "_" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# directories | ||
.yarn/* | ||
!.yarn/patches | ||
!.yarn/releases | ||
!.yarn/plugins | ||
!.yarn/sdks | ||
!.yarn/versions | ||
**/artifacts | ||
**/build | ||
**/cache | ||
**/coverage | ||
**/.coverage_artifacts | ||
**/.coverage_cache | ||
**/.coverage_contracts | ||
**/dist | ||
**/node_modules | ||
|
||
# files | ||
*.env | ||
*.log | ||
.pnp.* | ||
coverage.json | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# types | ||
src/types/* | ||
!src/types/common.ts | ||
!src/types/Greeter.ts | ||
|
||
# factories | ||
!src/types/factories | ||
src/types/factories/* | ||
!src/types/factories/Greeter__factory.ts | ||
|
||
# miscellaneous | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
yarn dlx commitlint --edit $1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
yarn dlx lint-staged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"*.{js,json,md,sol,ts,yaml,yml}": [ | ||
"prettier --config ./.prettierrc.yaml --write" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# directories | ||
.yarn/ | ||
**/.coverage_artifacts | ||
**/.coverage_cache | ||
**/.coverage_contracts | ||
**/artifacts | ||
**/build | ||
**/cache | ||
**/coverage | ||
**/dist | ||
**/node_modules | ||
**/types | ||
|
||
# files | ||
*.env | ||
*.log | ||
.pnp.* | ||
coverage.json | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
arrowParens: avoid | ||
bracketSpacing: true | ||
endOfLine: auto | ||
printWidth: 120 | ||
singleQuote: false | ||
tabWidth: 2 | ||
trailingComma: all | ||
|
||
overrides: | ||
- files: "*.sol" | ||
options: | ||
tabWidth: 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const shell = require("shelljs"); | ||
|
||
module.exports = { | ||
istanbulReporter: ["html", "lcov"], | ||
providerOptions: { | ||
mnemonic: process.env.MNEMONIC, | ||
}, | ||
skipFiles: ["test"], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"extends": "solhint:recommended", | ||
"plugins": ["prettier"], | ||
"rules": { | ||
"code-complexity": ["error", 8], | ||
"compiler-version": ["error", ">=0.8.4"], | ||
"const-name-snakecase": "off", | ||
"constructor-syntax": "error", | ||
"func-visibility": ["error", { "ignoreConstructors": true }], | ||
"max-line-length": ["error", 120], | ||
"not-rely-on-time": "off", | ||
"prettier/prettier": [ | ||
"error", | ||
{ | ||
"endOfLine": "auto" | ||
} | ||
], | ||
"reason-string": ["warn", { "maxLength": 64 }] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# directories | ||
**/artifacts | ||
**/node_modules |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
nodeLinker: node-modules | ||
|
||
plugins: | ||
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs | ||
spec: "@yarnpkg/plugin-interactive-tools" | ||
|
||
yarnPath: .yarn/releases/yarn-3.1.0.cjs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,147 @@ | ||
# ethereum-access-token | ||
# Ethereum Access Token | ||
|
||
Implemention of [EIP-712](https://eips.ethereum.org/EIPS/eip-721) for signed access token verification. | ||
|
||
Tokens authorise a user to perform specific on-chain interactions as determined by the token issuer. | ||
|
||
Tokens are in the form: | ||
|
||
```json | ||
{ | ||
"expiry": <unix_seconds-uint256>, | ||
"functionCall": { | ||
"functionSignature": <solidity_function_sig_hex-string>, | ||
"target": <contract_address_of_tx_target-string>, | ||
"caller": <user_address_of_tx_caller-string>, | ||
"parameters": <hexadecimal_representation_of_parameters-string> | ||
} | ||
} | ||
``` | ||
|
||
Tokens are signed according to [EIP-712](https://eips.ethereum.org/EIPS/eip-721) using `signTypedData` and are verified on-chain through the `Auth.sol` contract `verify` function. | ||
|
||
Parameters are abi-encoded similarly to how solidity does it. This is to ensure that we are signing the data that we expect to see during the transaction. Due to the entrypoint transaction containing signature-relevant parts, these parameters will be excluding all parts relating to the signature and expiry of the AuthToken. Example: | ||
|
||
If the function to be called is the following: | ||
|
||
```solidity | ||
function transfer(address recipient, uint256 amount) public; | ||
``` | ||
|
||
then the version that requires authorisation is the following: | ||
|
||
```solidity | ||
function tranfer( | ||
uint8 v, | ||
bytes32 r, | ||
bytes32 s, | ||
uint256 expiry, | ||
address recipient, | ||
uint256 amount | ||
) public requiresAuth; | ||
``` | ||
|
||
and parameters to the function are the original `address recipient` and `uint256 amount` which will be encoded as follows: | ||
`abi.encodeWithSignature('transfer(address,uint256)', recipient, amount)` | ||
|
||
## Usage | ||
|
||
### Pre Requisites | ||
|
||
Before running any command, you need to create a `.env` file and set a BIP-39 compatible mnemonic as an environment | ||
variable. Follow the example in `.env.example`. If you don't already have a mnemonic, use this [website](https://iancoleman.io/bip39/) to generate one. | ||
|
||
Then, proceed with installing dependencies: | ||
|
||
```sh | ||
yarn install | ||
``` | ||
|
||
### Compile | ||
|
||
Compile the smart contracts with Hardhat: | ||
|
||
```sh | ||
$ yarn compile | ||
``` | ||
|
||
### TypeChain | ||
|
||
Compile the smart contracts and generate TypeChain artifacts: | ||
|
||
```sh | ||
$ yarn typechain | ||
``` | ||
|
||
### Lint Solidity | ||
|
||
Lint the Solidity code: | ||
|
||
```sh | ||
$ yarn lint:sol | ||
``` | ||
|
||
### Lint TypeScript | ||
|
||
Lint the TypeScript code: | ||
|
||
```sh | ||
$ yarn lint:ts | ||
``` | ||
|
||
### Test | ||
|
||
Run the Mocha tests: | ||
|
||
```sh | ||
$ yarn test | ||
``` | ||
|
||
### Coverage | ||
|
||
Generate the code coverage report: | ||
|
||
```sh | ||
$ yarn coverage | ||
``` | ||
|
||
### Report Gas | ||
|
||
See the gas usage per unit test and average gas per method call: | ||
|
||
```sh | ||
$ REPORT_GAS=true yarn test | ||
``` | ||
|
||
### Clean | ||
|
||
Delete the smart contract artifacts, the coverage reports and the Hardhat cache: | ||
|
||
```sh | ||
$ yarn clean | ||
``` | ||
|
||
### Deploy | ||
|
||
Deploy the contracts to Hardhat Network: | ||
|
||
```sh | ||
$ yarn deploy --greeting "Bonjour, le monde!" | ||
``` | ||
|
||
## Syntax Highlighting | ||
|
||
If you use VSCode, you can enjoy syntax highlighting for your Solidity code via the | ||
[vscode-solidity](https://github.com/juanfranblanco/vscode-solidity) extension. The recommended approach to set the | ||
compiler version is to add the following fields to your VSCode user settings: | ||
|
||
```json | ||
{ | ||
"solidity.compileUsingRemoteVersion": "v0.8.4+commit.c7e474f2", | ||
"solidity.defaultCompiler": "remote" | ||
} | ||
``` | ||
|
||
Where of course `v0.8.4+commit.c7e474f2` can be replaced with any other version. |
Oops, something went wrong.