neo3/neo_contract/famous/
contracts.rs

1//! Famous contract addresses and information for Neo N3 mainnet and testnet.
2//!
3//! This module provides script hashes and information about well-known
4//! contracts deployed on Neo N3 networks that developers may want to interact with.
5
6use crate::neo_types::script_hash::ScriptHash;
7use std::str::FromStr;
8
9use crate::{neo_contract::ContractError, prelude::*};
10
11/// Enum defining which Neo N3 network a contract is deployed on
12#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13pub enum Network {
14	/// Neo N3 Mainnet
15	MainNet,
16	/// Neo N3 Testnet
17	TestNet,
18	/// Private network
19	PrivateNet,
20}
21
22impl Network {
23	/// Convert a string to a Network enum
24	pub fn from_str(s: &str) -> Option<Self> {
25		match s.to_lowercase().as_str() {
26			"mainnet" => Some(Network::MainNet),
27			"testnet" => Some(Network::TestNet),
28			"privatenet" => Some(Network::PrivateNet),
29			_ => None,
30		}
31	}
32
33	/// Convert Network enum to string
34	pub fn to_string(&self) -> String {
35		match self {
36			Network::MainNet => "mainnet".to_string(),
37			Network::TestNet => "testnet".to_string(),
38			Network::PrivateNet => "privatenet".to_string(),
39		}
40	}
41}
42
43/// Represents a famous contract with its metadata
44#[derive(Debug, Clone)]
45pub struct FamousContract {
46	/// Script hash of the contract
47	pub script_hash: ScriptHash,
48	/// Human-readable name of the contract
49	pub name: String,
50	/// Optional description of what the contract does
51	pub description: Option<String>,
52	/// Network the contract is deployed on
53	pub network: Network,
54	/// Contract type or category
55	pub contract_type: String,
56}
57
58impl FamousContract {
59	/// Creates a new famous contract instance
60	pub fn new(
61		script_hash: &str,
62		name: &str,
63		description: Option<&str>,
64		network: Network,
65		contract_type: &str,
66	) -> Result<Self, ContractError> {
67		let script_hash = ScriptHash::from_str(script_hash)
68			.map_err(|e| ContractError::InvalidScriptHash(format!("Invalid script hash: {}", e)))?;
69
70		Ok(Self {
71			script_hash,
72			name: name.to_string(),
73			description: description.map(|d| d.to_string()),
74			network,
75			contract_type: contract_type.to_string(),
76		})
77	}
78}
79
80// Mainnet DeFi contracts
81pub fn flamingo_flm_token() -> FamousContract {
82	FamousContract::new(
83		"0x4d9eab13620fe3569ba3b0e56e2877739e4145e3",
84		"Flamingo FLM Token",
85		Some("Native governance token for the Flamingo Finance platform"),
86		Network::MainNet,
87		"NEP-17 Token",
88	)
89	.unwrap()
90}
91
92pub fn flamingo_flamingo_finance() -> FamousContract {
93	FamousContract::new(
94		"0x1a4e5b62b908c758417eb525ecba58752a947f2b",
95		"Flamingo Finance",
96		Some("Interoperable, full-stack DeFi protocol on Neo"),
97		Network::MainNet,
98		"DeFi Platform",
99	)
100	.unwrap()
101}
102
103// Mainnet NFT contracts
104pub fn ghostmarket() -> FamousContract {
105	FamousContract::new(
106		"0xced5862a6c2f0c70b82b8017e845fb1a31c62c9c",
107		"GhostMarket",
108		Some("Multi-chain NFT marketplace"),
109		Network::MainNet,
110		"NFT Marketplace",
111	)
112	.unwrap()
113}
114
115pub fn neoburger_dao() -> FamousContract {
116	FamousContract::new(
117		"0x48c40d4666f93408be1bef038b6722404d9a4c2a",
118		"NeoBurger DAO",
119		Some("Governance platform and vote delegation for Neo"),
120		Network::MainNet,
121		"DAO",
122	)
123	.unwrap()
124}
125
126pub fn neocompound() -> FamousContract {
127	FamousContract::new(
128		"0xcd21f4a5dc6a6da341764e7dc9f15f8b38880f49",
129		"NeoCompound",
130		Some("Gas staking platform on Neo N3"),
131		Network::MainNet,
132		"Staking",
133	)
134	.unwrap()
135}
136
137// Mainnet infrastructure contracts
138pub fn neo_name_service() -> FamousContract {
139	FamousContract::new(
140		"0x7a8fcf0392cd625647907afa8e45cc66872b596b",
141		"Neo Name Service",
142		Some("Domain name service for Neo N3"),
143		Network::MainNet,
144		"Name Service",
145	)
146	.unwrap()
147}
148
149pub fn bridge_neo_to_eth() -> FamousContract {
150	FamousContract::new(
151		"0xd8dd5a0871eb44992cda9c6b49b3954206d6c8a5",
152		"Poly Network Bridge (Neo)",
153		Some("Cross-chain bridge connecting Neo to other blockchains"),
154		Network::MainNet,
155		"Bridge",
156	)
157	.unwrap()
158}
159
160// Testnet contracts
161pub fn testnet_nns() -> FamousContract {
162	FamousContract::new(
163		"0x50ac1c37690cc2cfc594472833cf57e299e1d367",
164		"Testnet NNS",
165		Some("Neo Name Service on testnet"),
166		Network::TestNet,
167		"Name Service",
168	)
169	.unwrap()
170}
171
172pub fn testnet_faucet() -> FamousContract {
173	FamousContract::new(
174		"0xd65c5d2764b3850a7f7ab14e04f866e9ceab46e1",
175		"Testnet Faucet",
176		Some("Contract for distributing testnet NEO and GAS"),
177		Network::TestNet,
178		"Utility",
179	)
180	.unwrap()
181}
182
183/// Returns all famous contracts for the specified network
184pub fn get_famous_contracts(network: Network) -> Vec<FamousContract> {
185	match network {
186		Network::MainNet => vec![
187			flamingo_flm_token(),
188			flamingo_flamingo_finance(),
189			ghostmarket(),
190			neoburger_dao(),
191			neocompound(),
192			neo_name_service(),
193			bridge_neo_to_eth(),
194		],
195		Network::TestNet => vec![testnet_nns(), testnet_faucet()],
196		Network::PrivateNet => vec![],
197	}
198}
199
200/// Returns all famous contracts across all networks
201pub fn get_all_famous_contracts() -> Vec<FamousContract> {
202	let mut contracts = get_famous_contracts(Network::MainNet);
203	contracts.extend(get_famous_contracts(Network::TestNet));
204	contracts
205}
206
207#[cfg(test)]
208mod tests {
209	use super::*;
210
211	#[test]
212	fn test_get_famous_contracts() {
213		let mainnet_contracts = get_famous_contracts(Network::MainNet);
214		assert!(!mainnet_contracts.is_empty());
215
216		let testnet_contracts = get_famous_contracts(Network::TestNet);
217		assert!(!testnet_contracts.is_empty());
218
219		let all_contracts = get_all_famous_contracts();
220		assert_eq!(all_contracts.len(), mainnet_contracts.len() + testnet_contracts.len());
221	}
222}