-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample_erc20.clj
executable file
·107 lines (90 loc) · 2.54 KB
/
example_erc20.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
(ns web3.lib.example-erc20
(:require [std.lang :as l]
[std.lib :as h]))
(l/script :solidity
{:require [[rt.solidity :as s]]
:static {:contract ["ExampleSample"]}})
(definterface.sol IERC20
[^{:- [:external]
:static/returns :bool}
transfer [:address to
:uint value]
^{:- [:external :view]
:static/returns :uint}
balanceOf [:address owner]])
(defevent.sol EventPayment
[:address from-address]
[:address to-address]
[:uint amount]
[:address token-address])
(defaddress.sol ^{:- [:public]}
g:SiteAuthority)
;;
;; CONTRUCTOR
;;
(defconstructor.sol
__init__
[]
(:= -/g:SiteAuthority s/msg-sender))
(defn.sol ^{:- [:external :payable]}
make-payment-erc20
"adds supporting keys to the contract"
{:added "4.0"}
[:address token-address :uint amount]
(s/require (not= s/msg-value amount)
"Cannot be zero")
(var (-/IERC20 erc20) (-/IERC20 token-address))
(. erc20 (transfer -/g:SiteAuthority
amount))
(emit (-/EventPayment {:from-address s/msg-sender
:to-address -/g:SiteAuthority
:amount amount
:token-address token-address})))
(defn.sol ^{:- [:external :payable]}
makePayment
"adds supporting keys to the contract"
{:added "4.0"}
[:address token-address :uint amount]
(s/require (not= s/msg-value amount)
"Cannot be zero")
(var (-/IERC20 erc20) (-/IERC20 token-address))
(. erc20 (transfer -/g:SiteAuthority
amount))
(emit (-/EventPayment {:from-address s/msg-sender
:to-address -/g:SiteAuthority
:amount amount
:token-address token-address})))
(defn.sol ^{:- [:external :view]
:static/returns :uint}
get-account-balance
"adds supporting keys to the contract"
{:added "4.0"}
[:address token-address]
(var (-/IERC20 erc20) (-/IERC20 token-address))
(return (. erc20 (balanceOf s/msg-sender))))
(defn.sol ^{:- [:external :view]
:static/returns :address}
get-sender
"adds supporting keys to the contract"
{:added "4.0"}
[]
(return s/msg-sender))
(def +default-contract+
{:ns (h/ns-sym)
:name "ExampleSample"
:args []
:interfaces [-/IERC20]})
(comment
(std.string/join
"\n"
["// SPDX-License-Identifier: GPL-3.0"
"pragma solidity >=0.7.0 <0.9.0;"
""
(+ "contract " name " {")
"}"])
(s/rt:print)
(s/rt:start-ganache-server)
(l/rt:restart))
(comment
(s/with:temp
(add-stuff 1 2)))