-
Notifications
You must be signed in to change notification settings - Fork 22
/
reth.go
118 lines (91 loc) · 3.78 KB
/
reth.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
110
111
112
113
114
115
116
117
118
package tokens
import (
"fmt"
"math/big"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/rocket-pool/node-manager-core/eth"
batch "github.com/rocket-pool/batch-query"
"github.com/rocket-pool/rocketpool-go/v2/core"
"github.com/rocket-pool/rocketpool-go/v2/rocketpool"
)
// ===============
// === Structs ===
// ===============
// Binding for RocketTokenRETH
type TokenReth struct {
// The rETH total supply
TotalSupply *core.SimpleField[*big.Int]
// The current ETH : rETH exchange rate
ExchangeRate *core.FormattedUint256Field[float64]
// The total amount of ETH collateral available for rETH trades
TotalCollateral *core.SimpleField[*big.Int]
// The rETH collateralization rate
CollateralRate *core.FormattedUint256Field[float64]
// === Internal fields ===
rp *rocketpool.RocketPool
reth *core.Contract
txMgr *eth.TransactionManager
}
// ====================
// === Constructors ===
// ====================
// Creates a new TokenReth contract binding
func NewTokenReth(rp *rocketpool.RocketPool) (*TokenReth, error) {
// Create the contract
reth, err := rp.GetContract(rocketpool.ContractName_RocketTokenRETH)
if err != nil {
return nil, fmt.Errorf("error getting rETH contract: %w", err)
}
return &TokenReth{
TotalSupply: core.NewSimpleField[*big.Int](reth, "totalSupply"),
ExchangeRate: core.NewFormattedUint256Field[float64](reth, "getExchangeRate"),
TotalCollateral: core.NewSimpleField[*big.Int](reth, "getTotalCollateral"),
CollateralRate: core.NewFormattedUint256Field[float64](reth, "getCollateralRate"),
rp: rp,
reth: reth,
txMgr: rp.GetTransactionManager(),
}, nil
}
// =============
// === Calls ===
// =============
// === Core ERC-20 functions ===
// Get the rETH balance of an address
func (c *TokenReth) BalanceOf(mc *batch.MultiCaller, balance_Out **big.Int, address common.Address) {
core.AddCall(mc, c.reth, balance_Out, "balanceOf", address)
}
// Get the rETH spending allowance of an address and spender
func (c *TokenReth) GetAllowance(mc *batch.MultiCaller, allowance_Out **big.Int, owner common.Address, spender common.Address) {
core.AddCall(mc, c.reth, allowance_Out, "allowance", owner, spender)
}
// === rETH functions ===
// Get the ETH value of an amount of rETH
func (c *TokenReth) GetEthValueOfReth(mc *batch.MultiCaller, value_Out **big.Int, rethAmount *big.Int) {
core.AddCall(mc, c.reth, value_Out, "getEthValue", rethAmount)
}
// Get the rETH value of an amount of ETH
func (c *TokenReth) GetRethValueOfEth(mc *batch.MultiCaller, value_Out **big.Int, ethAmount *big.Int) {
core.AddCall(mc, c.reth, value_Out, "getRethValue", ethAmount)
}
// ====================
// === Transactions ===
// ====================
// === Core ERC-20 functions ===
// Get info for approving rETH's usage by a spender
func (c *TokenReth) Approve(spender common.Address, amount *big.Int, opts *bind.TransactOpts) (*eth.TransactionInfo, error) {
return c.txMgr.CreateTransactionInfo(c.reth.Contract, "approve", opts, spender, amount)
}
// Get info for transferring rETH
func (c *TokenReth) Transfer(to common.Address, amount *big.Int, opts *bind.TransactOpts) (*eth.TransactionInfo, error) {
return c.txMgr.CreateTransactionInfo(c.reth.Contract, "transfer", opts, to, amount)
}
// Get info for transferring rETH from a sender
func (c *TokenReth) TransferFrom(from common.Address, to common.Address, amount *big.Int, opts *bind.TransactOpts) (*eth.TransactionInfo, error) {
return c.txMgr.CreateTransactionInfo(c.reth.Contract, "transferFrom", opts, from, to, amount)
}
// === rETH functions ===
// Get info for burning rETH for ETH
func (c *TokenReth) Burn(amount *big.Int, opts *bind.TransactOpts) (*eth.TransactionInfo, error) {
return c.txMgr.CreateTransactionInfo(c.reth.Contract, "burn", opts, amount)
}