Skip to content

ENS naming for contracts #10605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 27 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c6286df
add reverseclaimer naming
abhijeetbhagat May 2, 2025
69e023c
refactor
abhijeetbhagat May 5, 2025
3eb8738
add naming crate
abhijeetbhagat May 5, 2025
6cbf627
fmt
abhijeetbhagat May 5, 2025
42612c5
record naming metric
abhijeetbhagat May 7, 2025
ba2c0e8
Merge branch 'master' into ens-naming-for-contracts
abhijeetbhagat May 9, 2025
46edd96
add name arg to forge for naming existing contract
abhijeetbhagat May 10, 2025
30aa9db
add auto naming contract via forge name
abhijeetbhagat May 12, 2025
eb566cc
call subcommand for naming
abhijeetbhagat May 12, 2025
2fd339b
refactor
abhijeetbhagat May 15, 2025
f99c256
add auto-name flag to forge create for auto generating name
abhijeetbhagat May 15, 2025
83aebca
add support for naming contracts via forge script
abhijeetbhagat May 19, 2025
9b88580
wip: integration test
abhijeetbhagat May 20, 2025
3589426
Revert "wip: integration test"
abhijeetbhagat May 22, 2025
69485cc
fix warnings
abhijeetbhagat May 22, 2025
f84aa30
merge master
abhijeetbhagat May 22, 2025
6a22750
resolve conflict
abhijeetbhagat May 22, 2025
8b38769
add tests for parsing
abhijeetbhagat May 22, 2025
9f62d62
minor fixes
abhijeetbhagat May 23, 2025
c4be344
conflict fixes
abhijeetbhagat May 23, 2025
1a59f2a
add top level doc for enscribe
abhijeetbhagat May 23, 2025
ea2f64f
Merge branch 'master' into ens-naming-for-contracts
abhijeetbhagat May 24, 2025
1c1ee30
Merge branch 'master' into ens-naming-for-contracts
abhijeetbhagat May 27, 2025
addd2d8
Merge branch 'foundry-rs:master' into ens-naming-for-contracts
abhijeetbhagat May 29, 2025
7e8f2d3
add integration test to set ens name
abhijeetbhagat May 28, 2025
8ef3f0e
add integration test to set ens name
abhijeetbhagat May 29, 2025
5c639f9
Merge branch 'master' into ens-naming-for-contracts
abhijeetbhagat May 31, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 119 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ members = [
"crates/forge/",
"crates/script-sequence/",
"crates/macros/",
"crates/enscribe/",
"crates/test-utils/",
"crates/lint/",
]
Expand Down Expand Up @@ -197,6 +198,8 @@ foundry-test-utils = { path = "crates/test-utils" }
foundry-wallets = { path = "crates/wallets" }
foundry-linking = { path = "crates/linking" }

enscribe = { path = "crates/enscribe" }

# solc & compilation utilities
foundry-block-explorers = { version = "0.17.0", default-features = false }
foundry-compilers = { version = "0.16.1", default-features = false }
Expand Down
37 changes: 37 additions & 0 deletions crates/enscribe/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[package]
name = "enscribe"
description = "setting ens names for smart contracts"

version.workspace = true
edition.workspace = true
rust-version.workspace = true
authors.workspace = true
license.workspace = true
homepage.workspace = true
repository.workspace = true

[lints]
workspace = true

[dependencies]
eyre.workspace = true

foundry-cli.workspace = true
foundry-common.workspace = true
foundry-config.workspace = true

alloy-ens = { workspace = true, features = ["provider"] }
alloy-contract.workspace = true
alloy-provider = { workspace = true, features = ["reqwest", "ws", "ipc"] }
alloy-primitives.workspace = true
alloy-sol-types.workspace = true
reqwest.workspace = true
serde_json.workspace = true
serde.workspace = true
uuid = { version = "1.16.0", features = ["v4"] }

[dev-dependencies]
wiremock = "0.6"
tokio.workspace = true
reqwest.workspace = true
serial_test = "3.2.0"
67 changes: 67 additions & 0 deletions crates/enscribe/src/abi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
use alloy_sol_types::sol;
sol! {
/// ENS Registry contract.
#[sol(rpc)]
contract EnsRegistry {
/// Sets subnode record
function setSubnodeRecord(
bytes32 node,
bytes32 label,
address owner,
address resolver,
uint64 ttl
) external;

/// checks if an ens name record already exists
function recordExists(bytes32 node) external returns (bool);
/// returns the owner of this node
function owner(bytes32 node) external returns (address);
}

/// ENS Name Wrapper contract
#[sol(rpc)]
contract NameWrapper {
function isWrapped(bytes32 node) external returns (bool);
function setSubnodeRecord(
bytes32 node,
string label,
address owner,
address resolver,
uint64 ttl,
uint32 fuses,
uint64 expiry,
) external;
}

/// ENS Public Resolver contract
#[sol(rpc)]
contract PublicResolver {
function setAddr(bytes32 node, address addr) external;
function addr(bytes32 node) external returns (address);
function setName(bytes32 node, string newName) external;
}

/// ENS Reverse Registrar contract
#[sol(rpc)]
contract ReverseRegistrar {
function setName(string memory name) external returns (bytes32);
function setNameForAddr(address addr, address owner, address resolver, string name) external;
}

/// Enscribe contract
#[sol(rpc)]
contract Enscribe {
function setName(
address contractAddress,
string label,
string parentName,
bytes32 parentNode
) external returns (bool success);
}

/// Ownable contract
#[sol(rpc)]
contract Ownable {
function owner() external returns (address);
}
}
8 changes: 8 additions & 0 deletions crates/enscribe/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//! enscribe does ENS name setting for contracts.

#[allow(clippy::too_many_arguments)]
mod abi;
pub(crate) mod logger;
pub mod name;

pub use name::set_primary_name;
59 changes: 59 additions & 0 deletions crates/enscribe/src/logger.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
use eyre::Result;
use serde_json::json;
use uuid::Uuid;

static METRICS_API_URL: &str = "https://app.enscribe.xyz/api/v1/config";

pub(crate) struct MetricLogger {
corelation_id: String,
client: reqwest::Client,
deployer_address: String,
network: u64,
op_type: String,
contract_type: String,
contract_addr: String,
ens_name: String,
}

impl MetricLogger {
pub(crate) fn new(
deployer_address: String,
network: u64,
op_type: String,
contract_type: String,
contract_addr: String,
ens_name: String,
) -> Self {
let client = reqwest::Client::new();
let corelation_id = Uuid::new_v4().to_string();

Self {
corelation_id,
client,
deployer_address,
network,
op_type,
contract_type,
contract_addr,
ens_name,
}
}

pub(crate) async fn log(&self, step: &str, txn_hash: &str) -> Result<()> {
self.client.post(METRICS_API_URL).json(&json!({
"co_id": self.corelation_id,
"step": step.to_owned(),
"txn_hash": txn_hash,
"contract_type": self.contract_type,
"contract_address": self.contract_addr,
"ens_name": self.ens_name,
"deployer_address": self.deployer_address,
"network": self.network,
"timestamp": std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH)?.as_secs(),
"source": "forge",
"op_type": self.op_type,
})).send().await?;

Ok(())
}
}
Loading
Loading