Skip to content

Commit

Permalink
feat: build process improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
drewstone committed Oct 26, 2024
1 parent 548efac commit 4fb4cb0
Show file tree
Hide file tree
Showing 27 changed files with 126 additions and 24 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,35 @@ Add this to your `Cargo.toml`:
symbiotic-rs = { version = "0.1.0" }
```

## Adding new contracts

To add new contracts to the Rust bindings, follow these steps:

1. Add the contract import to `contracts/src/Utility.sol`:
```solidity
import "path/to/NewContract.sol";
```

2. Add the JSON file for the new contract to the list in `build.rs`:
```rust
let json_files = vec![
// ... existing files ...
"contracts/out/NewContract.sol/NewContract.json",
];
```

3. Expose the new contract in `src/lib.rs`:
```rust
sol!(
#[allow(missing_docs)]
#[sol(rpc)]
#[derive(Debug, Serialize, Deserialize)]
NewContract,
"json/NewContract.json"
);
```

These steps will ensure that the new contract is properly imported, its JSON artifact is copied to the correct location, and it's exposed in the Rust bindings for use in your project.



47 changes: 47 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::env;
use std::fs;
use std::path::PathBuf;
use std::process::Command;

Expand Down Expand Up @@ -52,4 +53,50 @@ fn main() {
);
}
}

// Create a new directory for JSON files
let json_dir = root.join("json");
fs::create_dir_all(&json_dir).expect("Failed to create JSON directory");

// List of JSON files to move
let json_files = vec![
"contracts/out/DelegatorFactory.sol/DelegatorFactory.json",
"contracts/out/NetworkRegistry.sol/NetworkRegistry.json",
"contracts/out/OperatorRegistry.sol/OperatorRegistry.json",
"contracts/out/SlasherFactory.sol/SlasherFactory.json",
"contracts/out/VaultConfigurator.sol/VaultConfigurator.json",
"contracts/out/VaultFactory.sol/VaultFactory.json",
"contracts/out/BaseSlasher.sol/BaseSlasher.json",
"contracts/out/Slasher.sol/Slasher.json",
"contracts/out/VetoSlasher.sol/VetoSlasher.json",
"contracts/out/MetadataService.sol/MetadataService.json",
"contracts/out/NetworkMiddlewareService.sol/NetworkMiddlewareService.json",
"contracts/out/OptInService.sol/OptInService.json",
"contracts/out/BaseDelegator.sol/BaseDelegator.json",
"contracts/out/FullRestakeDelegator.sol/FullRestakeDelegator.json",
"contracts/out/NetworkRestakeDelegator.sol/NetworkRestakeDelegator.json",
"contracts/out/OperatorSpecificDelegator.sol/OperatorSpecificDelegator.json",
"contracts/out/Hints.sol/Hints.json",
"contracts/out/DelegatorHints.sol/BaseDelegatorHints.json",
"contracts/out/OptInServiceHints.sol/OptInServiceHints.json",
"contracts/out/SlasherHints.sol/SlasherHints.json",
"contracts/out/VaultHints.sol/VaultHints.json",
"contracts/out/Vault.sol/Vault.json",
"contracts/out/VaultStorage.sol/VaultStorage.json",
"contracts/out/VaultTokenized.sol/VaultTokenized.json",
];

for json_file in json_files {
let source = root.join(json_file);
let destination = root.join("json").join(json_file.split('/').last().unwrap());

if let Err(e) = fs::copy(&source, &destination) {
println!("Failed to copy {}: {}", json_file, e);
} else {
println!("Copied {} to {}", source.display(), destination.display());
}
}

// Update cargo to rerun if any JSON file changes
println!("cargo:rerun-if-changed={}", json_dir.display());
}
1 change: 1 addition & 0 deletions json/BaseDelegator.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions json/BaseDelegatorHints.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions json/BaseSlasher.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions json/DelegatorFactory.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions json/FullRestakeDelegator.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions json/Hints.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"abi":[{"type":"error","name":"ExternalCall","inputs":[]}],"bytecode":{"object":"0x","sourceMap":"","linkReferences":{}},"deployedBytecode":{"object":"0x","sourceMap":"","linkReferences":{}},"methodIdentifiers":{},"rawMetadata":"{\"compiler\":{\"version\":\"0.8.25+commit.b61c2a91\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[],\"name\":\"ExternalCall\",\"type\":\"error\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"lib/core/src/contracts/hints/Hints.sol\":\"Hints\"},\"evmVersion\":\"paris\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":200},\"remappings\":[\":@openzeppelin/contracts-upgradeable/=lib/core/lib/openzeppelin-contracts-upgradeable/contracts/\",\":@openzeppelin/contracts/=lib/core/lib/openzeppelin-contracts/contracts/\",\":core/=lib/core/\",\":ds-test/=lib/core/lib/openzeppelin-contracts-upgradeable/lib/forge-std/lib/ds-test/src/\",\":erc4626-tests/=lib/core/lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/\",\":forge-std/=lib/forge-std/src/\",\":openzeppelin-contracts-upgradeable/=lib/core/lib/openzeppelin-contracts-upgradeable/\",\":openzeppelin-contracts/=lib/core/lib/openzeppelin-contracts/\"]},\"sources\":{\"lib/core/lib/openzeppelin-contracts/contracts/utils/Address.sol\":{\"keccak256\":\"0xaf28a975a78550e45f65e559a3ad6a5ad43b9b8a37366999abd1b7084eb70721\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://b7bd24e224f67f65bfadf85dc2929fa965456bb2415478bd0125471b5ce35245\",\"dweb:/ipfs/QmRaydGr8BTHs1kvaZfsNU69pKzUAGFrvABn1KiRSbE51y\"]},\"lib/core/src/contracts/common/StaticDelegateCallable.sol\":{\"keccak256\":\"0x566e57984d5bf9d821b6242c66545209fcc8f5de997057532861bfc0768bad65\",\"license\":\"BUSL-1.1\",\"urls\":[\"bzz-raw://a0c937b0294b1675357db7ef0a663878a1738477e38e45ca5aa8238a50afadc9\",\"dweb:/ipfs/Qmcrg3JU1YJhs3McSxm9egRKZnBiPyaxcxZyVAPnPRBhpq\"]},\"lib/core/src/contracts/hints/Hints.sol\":{\"keccak256\":\"0x8b565df1ae35993c097a9e642002782a8f451f6fd01809cad6bcd345bdf1b99c\",\"license\":\"BUSL-1.1\",\"urls\":[\"bzz-raw://99a19adb01e350a92f534095b3078229df1f2f83077992d75d58d8684be45971\",\"dweb:/ipfs/QmbmwcuswVbzvwHQFTtrJG86oV98GnfxqYTb8cV8u1acox\"]},\"lib/core/src/interfaces/common/IStaticDelegateCallable.sol\":{\"keccak256\":\"0xa335d4e81b9071b7de66ef92b43ff20671d86516eb1be46fef29a3483cd3f5d5\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://d464b9db863c14c05547d2b23352f2e9b7b784799cf09f6bbc4906a2a74e3516\",\"dweb:/ipfs/QmUVWzFvJz7eEbDQKiFTTzwi7TEbjcs3VmwdM4kuptAKvi\"]}},\"version\":1}","metadata":{"compiler":{"version":"0.8.25+commit.b61c2a91"},"language":"Solidity","output":{"abi":[{"inputs":[],"type":"error","name":"ExternalCall"}],"devdoc":{"kind":"dev","methods":{},"version":1},"userdoc":{"kind":"user","methods":{},"version":1}},"settings":{"remappings":["@openzeppelin/contracts-upgradeable/=lib/core/lib/openzeppelin-contracts-upgradeable/contracts/","@openzeppelin/contracts/=lib/core/lib/openzeppelin-contracts/contracts/","core/=lib/core/","ds-test/=lib/core/lib/openzeppelin-contracts-upgradeable/lib/forge-std/lib/ds-test/src/","erc4626-tests/=lib/core/lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/","forge-std/=lib/forge-std/src/","openzeppelin-contracts-upgradeable/=lib/core/lib/openzeppelin-contracts-upgradeable/","openzeppelin-contracts/=lib/core/lib/openzeppelin-contracts/"],"optimizer":{"enabled":true,"runs":200},"metadata":{"bytecodeHash":"ipfs"},"compilationTarget":{"lib/core/src/contracts/hints/Hints.sol":"Hints"},"evmVersion":"paris","libraries":{}},"sources":{"lib/core/lib/openzeppelin-contracts/contracts/utils/Address.sol":{"keccak256":"0xaf28a975a78550e45f65e559a3ad6a5ad43b9b8a37366999abd1b7084eb70721","urls":["bzz-raw://b7bd24e224f67f65bfadf85dc2929fa965456bb2415478bd0125471b5ce35245","dweb:/ipfs/QmRaydGr8BTHs1kvaZfsNU69pKzUAGFrvABn1KiRSbE51y"],"license":"MIT"},"lib/core/src/contracts/common/StaticDelegateCallable.sol":{"keccak256":"0x566e57984d5bf9d821b6242c66545209fcc8f5de997057532861bfc0768bad65","urls":["bzz-raw://a0c937b0294b1675357db7ef0a663878a1738477e38e45ca5aa8238a50afadc9","dweb:/ipfs/Qmcrg3JU1YJhs3McSxm9egRKZnBiPyaxcxZyVAPnPRBhpq"],"license":"BUSL-1.1"},"lib/core/src/contracts/hints/Hints.sol":{"keccak256":"0x8b565df1ae35993c097a9e642002782a8f451f6fd01809cad6bcd345bdf1b99c","urls":["bzz-raw://99a19adb01e350a92f534095b3078229df1f2f83077992d75d58d8684be45971","dweb:/ipfs/QmbmwcuswVbzvwHQFTtrJG86oV98GnfxqYTb8cV8u1acox"],"license":"BUSL-1.1"},"lib/core/src/interfaces/common/IStaticDelegateCallable.sol":{"keccak256":"0xa335d4e81b9071b7de66ef92b43ff20671d86516eb1be46fef29a3483cd3f5d5","urls":["bzz-raw://d464b9db863c14c05547d2b23352f2e9b7b784799cf09f6bbc4906a2a74e3516","dweb:/ipfs/QmUVWzFvJz7eEbDQKiFTTzwi7TEbjcs3VmwdM4kuptAKvi"],"license":"MIT"}},"version":1},"id":55}
1 change: 1 addition & 0 deletions json/MetadataService.json

Large diffs are not rendered by default.

Loading

0 comments on commit 4fb4cb0

Please sign in to comment.