forked from svanas/delphereum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb3.eth.chi.pas
104 lines (83 loc) · 2.81 KB
/
web3.eth.chi.pas
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
{******************************************************************************}
{ }
{ Delphereum }
{ }
{ Copyright(c) 2020 Stefan van As <[email protected]> }
{ Github Repository <https://github.com/svanas/delphereum> }
{ }
{ Distributed under Creative Commons NonCommercial (aka CC BY-NC) license. }
{ }
{******************************************************************************}
unit web3.eth.chi;
{$I web3.inc}
interface
uses
// Velthuis' BigNumbers
Velthuis.BigIntegers,
// web3
web3,
web3.eth,
web3.eth.erc20,
web3.eth.gas,
web3.eth.types,
web3.utils;
type
TGasToken = class abstract(TERC20)
public
constructor Create(aClient: TWeb3); reintroduce;
// Address on mainnet where this token is deployed
class function DeployedAt: TAddress; virtual; abstract;
// Estimate the number of gas units needed for Mint
procedure Mint(from: TAddress; amount: BigInteger; callback: TAsyncQuantity); overload;
// Mint gas tokens
procedure Mint(from: TPrivateKey; amount: BigInteger; callback: TAsyncReceipt); overload;
end;
TGasTokenClass = class of TGasToken;
TGST1 = class(TGasToken)
public
class function DeployedAt: TAddress; override;
end;
TGST2 = class(TGasToken)
public
class function DeployedAt: TAddress; override;
end;
TCHI = class(TGasToken)
public
class function DeployedAt: TAddress; override;
end;
implementation
{ TGasToken }
constructor TGasToken.Create(aClient: TWeb3);
begin
inherited Create(aClient, Self.DeployedAt);
end;
// Estimate the number of gas units needed for Mint
procedure TGasToken.Mint(from: TAddress; amount: BigInteger; callback: TAsyncQuantity);
begin
estimateGas(
Self.Client, from, Self.Contract,
'mint(uint256)', [web3.utils.toHex(amount)], 0, callback);
end;
// Mint gas tokens
procedure TGasToken.Mint(from: TPrivateKey; amount: BigInteger; callback: TAsyncReceipt);
begin
web3.eth.write(
Self.Client, from, Self.Contract,
'mint(uint256)', [web3.utils.toHex(amount)], 5200000, callback);
end;
{ TGST1 }
class function TGST1.DeployedAt: TAddress;
begin
Result := TAddress('0x88d60255F917e3eb94eaE199d827DAd837fac4cB');
end;
{ TGST2 }
class function TGST2.DeployedAt: TAddress;
begin
Result := TAddress('0x0000000000b3F879cb30FE243b4Dfee438691c04');
end;
{ TCHI }
class function TCHI.DeployedAt: TAddress;
begin
Result := TAddress('0x0000000000004946c0e9F43F4Dee607b0eF1fA1c');
end;
end.