Skip to content

Commit

Permalink
evm: DST20 support (#2231)
Browse files Browse the repository at this point in the history
* Run code during finalize_block instead of through FFI

* Remove FFI code, move contract and utils to new crate

* Undo more changes

* Declare addresses in contracts crate

* Rename contracts to ain-contracts

* Fix clippy errors

* Remove extra new line, update gitignore

* Undo old changes

* Remove unwraps

* Add test header

* Refactor to use `get_contract_storage`

* Make `basic` optional in `apply`

* Rename to `pkg_install_solc`

* Fix make.sh, remove redundant clone

* Compile multiple contracts

* Add DST20 support

* Only deploy DST20 of DATs

* Use executor state for bridge, add more tests

* Add tests, fix empty balance bridge issue

Bridge issue pending PR #2221

* Refactor rest of DST20 tests

* Add 0 balance test

* Fix lints

* Use SOLC_PATH, fix build, add more tests

* Add check for same token ID

* Move BridgeTx into SystemTx

* Validate DST20 code during transferdomain

* Check for address usage before deployment

* Add feature flag for transferdomain

* Feature flag every edges

* Trigger actions

* Remove unused attributes

---------

Co-authored-by: Prasanna Loganathar <[email protected]>
Co-authored-by: jouzo <[email protected]>
Co-authored-by: Jouzo <[email protected]>
  • Loading branch information
4 people authored Jul 28, 2023
1 parent ca8b35e commit e9daefb
Show file tree
Hide file tree
Showing 23 changed files with 1,396 additions and 126 deletions.
3 changes: 3 additions & 0 deletions lib/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions lib/ain-contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ ethereum = "0.14.0"
serde_json = "1.0.96"
hex = "0.4.3"
lazy_static = "1.4"
sha3 = "0.10.6"
sp-core = "20.0.0"

[build-dependencies]
ethers = "2.0.7"
Expand Down
75 changes: 41 additions & 34 deletions lib/ain-contracts/build.rs
Original file line number Diff line number Diff line change
@@ -1,47 +1,54 @@
use anyhow::anyhow;
use ethers_solc::{Project, ProjectPathsConfig};
use ethers_solc::{Project, ProjectPathsConfig, Solc};
use std::env;
use std::fs;
use std::path::PathBuf;

fn main() -> Result<(), Box<dyn std::error::Error>> {
// compile solidity project
// configure `root` as our project root
let root = PathBuf::from("counter_contract");
if !root.exists() {
return Err("Project root {root:?} does not exists!".into());
}
let contracts = vec![("counter_contract", "Counter"), ("dst20", "DST20")];

let paths = ProjectPathsConfig::builder()
.root(&root)
.sources(&root)
.build()?;

let project = Project::builder()
.paths(paths)
.set_auto_detect(true)
.no_artifacts()
.build()?;
let output = project.compile().unwrap();
let artifacts = output.into_artifacts();

for (id, artifact) in artifacts {
if id.name == "Counter" {
let abi = artifact.abi.ok_or_else(|| anyhow!("ABI not found"))?;
let bytecode = artifact.deployed_bytecode.expect("No bytecode found");

fs::create_dir_all("counter_contract/output/")?;
fs::write(
PathBuf::from("counter_contract/output/bytecode.json"),
serde_json::to_string(&bytecode).unwrap().as_bytes(),
)?;
fs::write(
PathBuf::from("counter_contract/output/abi.json"),
serde_json::to_string(&abi).unwrap().as_bytes(),
)?;
for (file_path, contract_name) in contracts {
let solc = Solc::new(env::var("SOLC_PATH")?);
let root = PathBuf::from(file_path);
if !root.exists() {
return Err("Project root {root:?} does not exists!".into());
}
}

project.rerun_if_sources_changed();
let paths = ProjectPathsConfig::builder()
.root(&root)
.sources(&root)
.build()?;

let project = Project::builder()
.solc(solc)
.paths(paths)
.set_auto_detect(true)
.no_artifacts()
.build()?;
let output = project.compile().unwrap();
let artifacts = output.into_artifacts();

for (id, artifact) in artifacts {
if id.name == contract_name {
let abi = artifact.abi.ok_or_else(|| anyhow!("ABI not found"))?;
let bytecode = artifact.deployed_bytecode.expect("No bytecode found");

fs::create_dir_all(format!("{file_path}/output/"))?;
fs::write(
PathBuf::from(format!("{file_path}/output/bytecode.json")),
serde_json::to_string(&bytecode).unwrap().as_bytes(),
)?;
fs::write(
PathBuf::from(format!("{file_path}/output/abi.json")),
serde_json::to_string(&abi).unwrap().as_bytes(),
)?;
}
}

project.rerun_if_sources_changed();
}

Ok(())
}
2 changes: 1 addition & 1 deletion lib/ain-contracts/counter_contract/Counter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ pragma solidity >=0.8.2 <0.9.0;
*/
contract Counter {
uint256 public number;
}
}
Loading

0 comments on commit e9daefb

Please sign in to comment.