-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCXTZ.py
More file actions
42 lines (32 loc) · 1.58 KB
/
CXTZ.py
File metadata and controls
42 lines (32 loc) · 1.58 KB
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
import smartpy as sp
CTErrors = sp.io.import_script_from_url(
"file:contracts/errors/CTokenErrors.py")
EC = CTErrors.ErrorCodes
CToken = sp.io.import_script_from_url("file:contracts/CToken.py")
"""
CXTZ: CToken that wraps XTZ
"""
class CXTZ(CToken.CToken):
def __init__(self, comptroller_, interestRateModel_, administrator_, metadata_, token_metadata_):
initialExchangeRateMantissa = sp.nat(int(1e18))
CToken.CToken.__init__(self, comptroller_, interestRateModel_,
initialExchangeRateMantissa, administrator_, metadata_, token_metadata_)
def getCashImpl(self):
return sp.utils.mutez_to_nat(sp.balance)
def doTransferOut(self, to_, amount, isContract=False):
sp.if isContract:
sp.transfer(sp.unit, sp.utils.nat_to_mutez(amount), sp.contract(
sp.TUnit, to_, "receive").open_some(message="bad contract destination"))
sp.else:
sp.send(to_, sp.utils.nat_to_mutez(amount))
def doTransferIn(self, from_, amount):
sp.if sp.utils.mutez_to_nat(sp.amount) > amount:
sp.send(from_, sp.utils.nat_to_mutez(sp.as_nat(sp.utils.mutez_to_nat(sp.amount) - amount)))
sp.else:
sp.verify(sp.utils.mutez_to_nat(sp.amount)
== amount, EC.CT_INVALID_MUTEZ)
def getMintTokens(self, mintAmount):
# add adjustment by mintAmount due to balance being updated from the start of transaction
return self.getActualAmount(mintAmount, True, mintAmount)
def verifySweepMutez(self):
sp.verify(False, EC.CT_SWEEP_XTZ)