Skip to content

Commit

Permalink
feat: (#39) Add evm contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
OT-kraftchain committed Dec 10, 2024
1 parent 54965f8 commit fe43b16
Show file tree
Hide file tree
Showing 31 changed files with 21,241 additions and 26 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: Set up JDK 1.8
uses: actions/setup-java@v2
with:
distribution: temurin
java-version: '8'
cache: 'gradle'
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
- name: Unit Tests
run: ./gradlew --info --warning-mode=all clean test
run: ./gradlew --info --warning-mode=all clean test
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,10 @@ gradle.properties
.java-version

*.deploy.properties
!dev.deploy.properties
!dev.deploy.properties

node_modules/
artifacts/
typechain-types/
cache/
cache_hardhat/
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "lib/openzeppelin-contracts-upgradeable"]
path = lib/openzeppelin-contracts-upgradeable
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,34 @@ Clone this repo:
git clone https://github.com/AxLabs/grantshares-contracts.git
```

### Neo N3 contracts
The GrantShares contracts use the [neow3j](https://neow3j.io) devpack and compiler which in turn uses Gradle as the
build tool. The contracts are located in the `main` source set.

Test can be executed with the following command. Note, that you need a running Docker deamon for the tests to work.
### Solidity contracts
Since this project also has solidity code, we need to install the foundry toolchain by running the following commands:
```shell
curl -L https://foundry.paradigm.xyz | bash
source ~/.bashrc #this might differ if using a different shell
foundryup
```

### Testing
After installing these, the tests can be executed with the following command (Note that you need a running Docker daemon for the tests to work):

```shell
./gradlew test
```

## Deployment

The scripts and configurations to deploy the contracts are in the `deploy` source set.
### Neo N3 contracts
The scripts and configurations to deploy the neoN3 contracts are in the `deploy` source set.
Some basic scripts for invoking the contracts via the neow3j SDK are also located there.

### Solidity contracts
//TODO: Add deployment instructions for solidity contracts

## Security Audit

The smart contracts have been audited by [Red4Sec](https://red4sec.com/en). The audit report can be found [here](https://bit.ly/3wZ14uI).
Expand Down
19 changes: 18 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'java'
id 'io.neow3j.gradle-plugin' version '3.21.1'
id "com.github.node-gradle.node" version "7.1.0"
}

sourceCompatibility = JavaVersion.VERSION_1_8
Expand Down Expand Up @@ -38,6 +39,22 @@ tasks.withType(Test) {
useJUnitPlatform()
}

node {
version = '20.18.1'
download = true
}

task compileSolidity(type : Exec) {
dependsOn('npmInstall')
commandLine 'forge', 'compile'
}

task testSolidity(type: Exec) {
dependsOn('compileSolidity')
commandLine 'forge', 'test'
}
test.dependsOn('testSolidity')

neow3jCompile {
className = "com.axlabs.neo.grantshares.GrantSharesTreasury"
}
}
7 changes: 7 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[profile.default]
src = 'src/main/solidity'
test = 'src/test/solidity'
out = 'artifacts'
libs = ['lib']

# See more config options https://github.com/foundry-rs/foundry/tree/master/config
51 changes: 51 additions & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import fs from "fs";
import "@typechain/hardhat";
import "hardhat-preprocessor";
import { HardhatUserConfig, task } from "hardhat/config";

import example from "./src/deploy/typescript/example";

function getRemappings() {
return fs
.readFileSync("remappings.txt", "utf8")
.split("\n")
.filter(Boolean)
.map((line) => line.trim().split("="));
}

task("example", "Example task").setAction(example);

const config: HardhatUserConfig = {
solidity: {
version: "0.8.20",
settings: {
optimizer: {
enabled: true,
runs: 200,
},
},
},
paths: {
sources: "./src/main/solidity", // Use ./src rather than ./contracts as Hardhat expects
cache: "./cache_hardhat", // Use a different cache for Hardhat than Foundry
},
// This fully resolves paths for imports in the ./lib directory for Hardhat
//@ts-ignore
preprocess: {
//@ts-ignore
eachLine: (hre) => ({
transform: (line: string) => {
if (line.match(/^\s*import /i)) {
getRemappings().forEach(([find, replace]) => {
if (line.match(find)) {
line = line.replace(find, replace);
}
});
}
return line;
},
}),
},
};

export default config;
1 change: 1 addition & 0 deletions lib/forge-std
Submodule forge-std added at 1eea5b
1 change: 1 addition & 0 deletions lib/openzeppelin-contracts
Submodule openzeppelin-contracts added at 69c8de
1 change: 1 addition & 0 deletions lib/openzeppelin-contracts-upgradeable
Loading

0 comments on commit fe43b16

Please sign in to comment.