forked from rocket-pool/rocketpool-go
/
rpl-fixed.go
109 lines (93 loc) · 3.93 KB
/
rpl-fixed.go
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
108
109
package tokens
import (
"math/big"
"sync"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/PatriceVignola/rocketpool-go/rocketpool"
)
//
// Core ERC-20 functions
//
// Get fixed-supply RPL total supply
func GetFixedSupplyRPLTotalSupply(rp *rocketpool.RocketPool, opts *bind.CallOpts) (*big.Int, error) {
rocketTokenFixedSupplyRPL, err := getRocketTokenRPLFixedSupply(rp)
if err != nil {
return nil, err
}
return totalSupply(rocketTokenFixedSupplyRPL, "fixed-supply RPL", opts)
}
// Get fixed-supply RPL balance
func GetFixedSupplyRPLBalance(rp *rocketpool.RocketPool, address common.Address, opts *bind.CallOpts) (*big.Int, error) {
rocketTokenFixedSupplyRPL, err := getRocketTokenRPLFixedSupply(rp)
if err != nil {
return nil, err
}
return balanceOf(rocketTokenFixedSupplyRPL, "fixed-supply RPL", address, opts)
}
// Get fixed-supply RPL allowance
func GetFixedSupplyRPLAllowance(rp *rocketpool.RocketPool, owner, spender common.Address, opts *bind.CallOpts) (*big.Int, error) {
rocketTokenFixedSupplyRPL, err := getRocketTokenRPLFixedSupply(rp)
if err != nil {
return nil, err
}
return allowance(rocketTokenFixedSupplyRPL, "fixed-supply RPL", owner, spender, opts)
}
// Estimate the gas of TransferFixedSupplyRPL
func EstimateTransferFixedSupplyRPLGas(rp *rocketpool.RocketPool, to common.Address, amount *big.Int, opts *bind.TransactOpts) (rocketpool.GasInfo, error) {
rocketTokenFixedSupplyRPL, err := getRocketTokenRPLFixedSupply(rp)
if err != nil {
return rocketpool.GasInfo{}, err
}
return estimateTransferGas(rocketTokenFixedSupplyRPL, "fixed-supply RPL", to, amount, opts)
}
// Transfer fixed-supply RPL
func TransferFixedSupplyRPL(rp *rocketpool.RocketPool, to common.Address, amount *big.Int, opts *bind.TransactOpts) (common.Hash, error) {
rocketTokenFixedSupplyRPL, err := getRocketTokenRPLFixedSupply(rp)
if err != nil {
return common.Hash{}, err
}
return transfer(rocketTokenFixedSupplyRPL, "fixed-supply RPL", to, amount, opts)
}
// Estimate the gas of ApproveFixedSupplyRPL
func EstimateApproveFixedSupplyRPLGas(rp *rocketpool.RocketPool, spender common.Address, amount *big.Int, opts *bind.TransactOpts) (rocketpool.GasInfo, error) {
rocketTokenFixedSupplyRPL, err := getRocketTokenRPLFixedSupply(rp)
if err != nil {
return rocketpool.GasInfo{}, err
}
return estimateApproveGas(rocketTokenFixedSupplyRPL, "fixed-supply RPL", spender, amount, opts)
}
// Approve an fixed-supply RPL spender
func ApproveFixedSupplyRPL(rp *rocketpool.RocketPool, spender common.Address, amount *big.Int, opts *bind.TransactOpts) (common.Hash, error) {
rocketTokenFixedSupplyRPL, err := getRocketTokenRPLFixedSupply(rp)
if err != nil {
return common.Hash{}, err
}
return approve(rocketTokenFixedSupplyRPL, "fixed-supply RPL", spender, amount, opts)
}
// Estimate the gas of TransferFromFixedSupplyRPL
func EstimateTransferFromFixedSupplyRPLGas(rp *rocketpool.RocketPool, from, to common.Address, amount *big.Int, opts *bind.TransactOpts) (rocketpool.GasInfo, error) {
rocketTokenFixedSupplyRPL, err := getRocketTokenRPLFixedSupply(rp)
if err != nil {
return rocketpool.GasInfo{}, err
}
return estimateTransferFromGas(rocketTokenFixedSupplyRPL, "fixed-supply RPL", from, to, amount, opts)
}
// Transfer fixed-supply RPL from a sender
func TransferFromFixedSupplyRPL(rp *rocketpool.RocketPool, from, to common.Address, amount *big.Int, opts *bind.TransactOpts) (common.Hash, error) {
rocketTokenFixedSupplyRPL, err := getRocketTokenRPLFixedSupply(rp)
if err != nil {
return common.Hash{}, err
}
return transferFrom(rocketTokenFixedSupplyRPL, "fixed-supply RPL", from, to, amount, opts)
}
//
// Contracts
//
// Get contracts
var rocketTokenFixedSupplyRPLLock sync.Mutex
func getRocketTokenRPLFixedSupply(rp *rocketpool.RocketPool) (*rocketpool.Contract, error) {
rocketTokenFixedSupplyRPLLock.Lock()
defer rocketTokenFixedSupplyRPLLock.Unlock()
return rp.GetContract("rocketTokenRPLFixedSupply")
}