erc20/
erc20.rs

1use casper_contract_schema::*;
2
3pub fn example_erc20_schema() -> ContractSchema {
4    ContractSchema {
5        casper_contract_schema_version: 1,
6        toolchain: String::from("rustc 1.73.0 (cc66ad468 2023-10-03)"),
7        contract_name: String::from("Erc20"),
8        contract_version: String::from("0.1.0"),
9        authors: vec![String::from("John Doe <john@doe.com>")],
10        repository: Some(String::from(
11            "https://github.com/casper-ecosystem/casper-contract-schema",
12        )),
13        homepage: Some(String::from("https://john.doe.com")),
14        errors: vec![
15            UserError {
16                name: String::from("InsufficientFunds"),
17                description: Some(String::from("Insufficient funds")),
18                discriminant: 100u16,
19            },
20            UserError {
21                name: String::from("InsufficientAllowance"),
22                description: Some(String::from("Insufficient allowance")),
23                discriminant: 101u16,
24            },
25        ],
26        types: vec![
27            CustomType::Struct {
28                name: TypeName::new("Transfer"),
29                description: Some(String::from("Transfer event")),
30                members: vec![
31                    StructMember::new(
32                        "from",
33                        "Sender of tokens.",
34                        NamedCLType::Option(Box::new(NamedCLType::Key)),
35                    ),
36                    StructMember::new(
37                        "to",
38                        "Recipient of tokens.",
39                        NamedCLType::Option(Box::new(NamedCLType::Key)),
40                    ),
41                    StructMember::new("value", "Transfered amount.", NamedCLType::U256),
42                ],
43            },
44            CustomType::Struct {
45                name: TypeName::new("Approval"),
46                description: Some(String::from("Approval event")),
47                members: vec![
48                    StructMember::new("owner", "", NamedCLType::Option(Box::new(NamedCLType::Key))),
49                    StructMember::new(
50                        "spender",
51                        "",
52                        NamedCLType::Option(Box::new(NamedCLType::Key)),
53                    ),
54                    StructMember::new("value", "", NamedCLType::U256),
55                ],
56            },
57        ],
58        entry_points: vec![
59            Entrypoint {
60                name: String::from("transfer"),
61                description: Some(String::from("Transfer tokens to another account")),
62                is_mutable: true,
63                arguments: vec![
64                    Argument::new("recipient", "", NamedCLType::Key),
65                    Argument::new("amount", "", NamedCLType::U256),
66                ],
67                return_ty: NamedCLType::Unit.into(),
68                is_contract_context: true,
69                access: Access::Public,
70            },
71            Entrypoint {
72                name: String::from("transfer_from"),
73                description: Some(String::from("Transfer tokens from one account to another")),
74                is_mutable: true,
75                arguments: vec![
76                    Argument::new("owner", "", NamedCLType::Key),
77                    Argument::new("recipient", "", NamedCLType::Key),
78                    Argument::new("amount", "", NamedCLType::U256),
79                ],
80                return_ty: NamedCLType::Unit.into(),
81                is_contract_context: true,
82                access: Access::Public,
83            },
84            Entrypoint {
85                name: String::from("approve"),
86                description: Some(String::from(
87                    "Approve spender to use tokens on behalf of the owner",
88                )),
89                is_mutable: true,
90                arguments: vec![
91                    Argument::new("spender", "", NamedCLType::Key),
92                    Argument::new("amount", "", NamedCLType::U256),
93                ],
94                return_ty: NamedCLType::Unit.into(),
95                is_contract_context: true,
96                access: Access::Public,
97            },
98            Entrypoint {
99                name: String::from("allowance"),
100                description: Some(String::from(
101                    "Check the amount of tokens that an owner allowed to a spender",
102                )),
103                is_mutable: false,
104                arguments: vec![
105                    Argument::new("owner", "", NamedCLType::Key),
106                    Argument::new("spender", "", NamedCLType::Key),
107                ],
108                return_ty: NamedCLType::U256.into(),
109                is_contract_context: true,
110                access: Access::Public,
111            },
112            Entrypoint {
113                name: String::from("balance_of"),
114                description: Some(String::from(
115                    "Check the amount of tokens owned by an account",
116                )),
117                is_mutable: false,
118                arguments: vec![Argument::new("owner", "", NamedCLType::Key)],
119                return_ty: NamedCLType::U256.into(),
120                is_contract_context: true,
121                access: Access::Public,
122            },
123            Entrypoint {
124                name: String::from("total_supply"),
125                description: Some(String::from("Check the total supply of tokens")),
126                is_mutable: false,
127                arguments: vec![],
128                return_ty: NamedCLType::U256.into(),
129                is_contract_context: true,
130                access: Access::Public,
131            },
132        ],
133        events: vec![
134            Event::new("event_Transfer", "Transfer"),
135            Event::new("event_Approval", "Approval"),
136        ],
137        call: Some(CallMethod::new(
138            "erc20.wasm",
139            "Fungible token",
140            vec![
141                Argument::new("name", "Name of the token", NamedCLType::String),
142                Argument::new("symbol", "Symbol of the token", NamedCLType::String),
143                Argument::new("decimals", "Number of decimals", NamedCLType::U8),
144                Argument::new(
145                    "initial_supply",
146                    "Initial supply of tokens",
147                    NamedCLType::U256,
148                ),
149            ],
150        )),
151    }
152}
153
154pub fn main() {
155    let schema = example_erc20_schema();
156    let pretty_json = serde_json::to_string_pretty(&schema).unwrap();
157    println!("{}", pretty_json);
158}