-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathharbergerMinter.py
76 lines (60 loc) · 2.45 KB
/
harbergerMinter.py
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
import smartpy as sp
class HarbergerMinter(sp.Contract):
"""This contract implements a basic minter for Harberger fee tokens.
"""
def __init__(self, metadata):
"""Initializes the contract.
"""
# Define the contract storage data types for clarity
self.init_type(sp.TRecord(
# The contract metadata
metadata=sp.TBigMap(sp.TString, sp.TBytes),
# The token contract address
token_contract=sp.TOption(sp.TAddress)))
# Initialize the contract storage
self.init(
metadata=metadata,
token_contract=sp.none)
@sp.entry_point
def mint_token(self, params):
# Define the input parameter data type
sp.set_type(params, sp.TRecord(
metadata=sp.TMap(sp.TString, sp.TBytes),
price=sp.TMutez,
fee=sp.TNat).layout(
("metadata", ("price", "fee"))))
# Check that no tez have been transferred
sp.verify(sp.amount == sp.mutez(0), message="HM_TEZ_TRANSFER")
# Check that the fee is not larger than 25%
sp.verify(params.fee <= 250, message="HM_WRONG_FEE")
# Send the mint information to the token contract
mint_handle = sp.contract(
t=sp.TRecord(
creator=sp.TAddress,
metadata=sp.TMap(sp.TString, sp.TBytes),
price=sp.TMutez,
fee=sp.TNat).layout(
("creator", ("metadata", ("price", "fee")))),
address=self.data.token_contract.open_some(),
entry_point="mint").open_some()
sp.transfer(
arg=sp.record(
creator=sp.sender,
metadata=params.metadata,
price=params.price,
fee=params.fee),
amount=sp.mutez(0),
destination=mint_handle)
@sp.entry_point
def set_token_contract(self, token_contract):
"""Sets the token contract.
"""
# Define the input parameter data type
sp.set_type(token_contract, sp.TAddress)
# Check that the token contract has not been set before
sp.verify(~self.data.token_contract.is_some(),
message="HM_TOKEN_CONTRACT_ALREADY_SET")
# Set the token contract address
self.data.token_contract = sp.some(token_contract)
sp.add_compilation_target("harbergerMinter", HarbergerMinter(
metadata=sp.utils.metadata_of_url("ipfs://aaa")))