tenderly_rs/services/contracts/
types.rs

1use std::collections::HashMap;
2
3use serde::{
4    Deserialize,
5    Serialize,
6};
7
8use crate::types::{
9    Network,
10    Path,
11    Web3Address,
12};
13
14/// Contract type
15#[derive(Debug, Clone)]
16pub struct Contract {
17    pub address: String,
18    pub network: Network,
19    pub display_name: Option<String>,
20    pub tags: Option<Vec<String>>,
21}
22
23/// Tenderly contract type alias (same as Contract)
24pub type TenderlyContract = Contract;
25
26/// Contract request for API
27#[derive(Debug, Clone, Serialize, Deserialize)]
28pub struct ContractRequest {
29    pub address: String,
30    #[serde(rename = "network_id")]
31    pub network_id: String,
32    #[serde(rename = "display_name", skip_serializing_if = "Option::is_none")]
33    pub display_name: Option<String>,
34}
35
36/// Get by parameters
37#[derive(Debug, Clone, Default)]
38pub struct GetByParams {
39    pub tags: Option<Vec<String>>,
40    pub display_names: Option<Vec<String>>,
41}
42
43/// Contract response from API
44#[derive(Debug, Clone, Deserialize)]
45pub struct ContractResponse {
46    pub id: String,
47    #[serde(rename = "account_type")]
48    pub account_type: String,
49    pub contract: InternalContract,
50    #[serde(rename = "display_name", default)]
51    pub display_name: String,
52    pub tags: Option<Vec<Tag>>,
53}
54
55#[derive(Debug, Clone, Deserialize)]
56pub struct Tag {
57    pub tag: String,
58}
59
60#[derive(Debug, Clone, Deserialize)]
61pub struct InternalContract {
62    pub address: String,
63    #[serde(rename = "network_id")]
64    pub network_id: String,
65}
66
67/// Update contract request
68#[derive(Debug, Clone)]
69pub struct UpdateContractRequest {
70    pub display_name: Option<String>,
71    pub append_tags: Option<Vec<String>>,
72}
73
74/// Solidity compiler version
75pub type SolidityCompilerVersions = String;
76
77/// Solc config
78#[derive(Debug, Clone, Serialize, Deserialize)]
79pub struct SolcConfig {
80    pub version: String,
81    pub sources: HashMap<Path, SourceContent>,
82    pub settings: serde_json::Value,
83}
84
85#[derive(Debug, Clone, Serialize, Deserialize)]
86pub struct SourceContent {
87    pub content: String,
88}
89
90/// Tenderly Solc config libraries
91pub type TenderlySolcConfigLibraries = HashMap<String, LibraryAddresses>;
92
93#[derive(Debug, Clone, Serialize, Deserialize)]
94pub struct LibraryAddresses {
95    pub addresses: HashMap<String, Web3Address>,
96}
97
98/// Verification request
99#[derive(Debug, Clone)]
100pub struct VerificationRequest {
101    pub contract_to_verify: String,
102    pub solc: SolcConfig,
103    pub config: VerificationConfig,
104}
105
106#[derive(Debug, Clone)]
107pub struct VerificationConfig {
108    pub mode: VerificationMode,
109}
110
111#[derive(Debug, Clone, Copy, PartialEq, Eq)]
112pub enum VerificationMode {
113    Private,
114    Public,
115}
116
117impl Serialize for VerificationMode {
118    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
119    where
120        S: serde::Serializer,
121    {
122        match self {
123            VerificationMode::Private => serializer.serialize_str("private"),
124            VerificationMode::Public => serializer.serialize_str("public"),
125        }
126    }
127}
128
129/// Verification response
130#[derive(Debug, Clone, Deserialize)]
131pub struct VerificationResponse {
132    #[serde(rename = "compilation_errors")]
133    pub compilation_errors: Option<Vec<CompilationErrorResponse>>,
134    pub results: Option<Vec<VerificationResult>>,
135}
136
137#[derive(Debug, Clone, Deserialize)]
138pub struct CompilationErrorResponse {
139    #[serde(rename = "source_location")]
140    pub source_location: SourceLocation,
141    #[serde(rename = "error_ype")]
142    pub error_type: String,
143    pub component: String,
144    pub message: String,
145    #[serde(rename = "formatted_message")]
146    pub formatted_message: String,
147}
148
149#[derive(Debug, Clone, Deserialize)]
150pub struct SourceLocation {
151    pub file: String,
152    pub start: u64,
153    pub end: u64,
154}
155
156#[derive(Debug, Clone, Deserialize)]
157pub struct VerificationResult {
158    #[serde(rename = "bytecode_mismatch_error")]
159    pub bytecode_mismatch_error: Option<BytecodeMismatchErrorResponse>,
160    #[serde(rename = "verified_contract")]
161    pub verified_contract: Option<InternalContract>,
162}
163
164#[derive(Debug, Clone, Deserialize, Default)]
165#[serde(default)]
166pub struct BytecodeMismatchErrorResponse {
167    #[serde(rename = "contract_id")]
168    pub contract_id: String,
169    #[serde(skip_serializing_if = "Option::is_none")]
170    pub expected: Option<String>,
171    #[serde(skip_serializing_if = "Option::is_none")]
172    pub got: Option<String>,
173    #[serde(skip_serializing_if = "Option::is_none")]
174    pub similarity: Option<f64>,
175    #[serde(rename = "assumed_reason")]
176    pub assumed_reason: String,
177}