-
Notifications
You must be signed in to change notification settings - Fork 0
/
typings.go
135 lines (116 loc) · 4.79 KB
/
typings.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// description:
// @author renshiwei
// Date: 2023/5/24
// Package exitscan NodeDAO operator exit scan
package exitscan
import (
"fmt"
"github.com/NodeDAO/operator-sdk/contracts/withdrawalRequest"
"math/big"
)
type VnftOwner uint32
type StakeType uint32
const (
USER VnftOwner = iota
LiquidStaking
)
const (
VNFT StakeType = iota
NETH
)
func GetVnftOwner(stakeType StakeType) VnftOwner {
if stakeType == VNFT {
return USER
} else {
return LiquidStaking
}
}
type VnftRecord struct {
Network string
OperatorId *big.Int
TokenId *big.Int
Pubkey string
Type StakeType
}
func (v *VnftRecord) String() string {
return fmt.Sprintf("{Network:%s OperatorId:%s, TokenId:%s, Pubkey:%s, Type:%v}", v.Network, v.OperatorId.String(), v.TokenId.String(), v.Pubkey, v.Type)
}
type WithdrawalRequest struct {
ID *big.Int
WithdrawalRequestInfo *withdrawalRequest.WithdrawalRequestWithdrawalInfo
}
func (v *WithdrawalRequest) String() string {
return fmt.Sprintf("{ID:%s, WithdrawalRequestInfo:{OperatorId:%s, WithdrawHeight:%s, WithdrawNethAmount:%s, WithdrawExchange:%s, ClaimEthAmount:%s, Owner:%s, IsClaim:%v}}",
v.ID.String(),
v.WithdrawalRequestInfo.OperatorId,
v.WithdrawalRequestInfo.WithdrawHeight,
v.WithdrawalRequestInfo.WithdrawNethAmount,
v.WithdrawalRequestInfo.WithdrawExchange,
v.WithdrawalRequestInfo.ClaimEthAmount,
v.WithdrawalRequestInfo.Owner,
v.WithdrawalRequestInfo.IsClaim,
)
}
// VnftOwnerValidator 'VnftOwnerValidator' is used to verify that the relationship between the validator 'StakeType' and 'VnftOwner' is correct.
type VnftOwnerValidator interface {
// VerifyVnftOwner Verify that the stakeType of vnft tokenIds and vnftOwner match.
// ----------------------------------------------------------------
// The relationship between StakeType and VnftOwner is as follows:
// ----------------------
// StakeType | VnftOwner
// ----------------------
// VNFT | USER
// NETH | LiquidStaking
VerifyVnftOwner(network string, stakeType StakeType, vnftOwner VnftOwner, tokenIds []*big.Int) (bool, error)
}
// ExitScanner Scan the smart contract for records that need to be exited.
type ExitScanner interface {
ExitScan(operatorId *big.Int) ([]*VnftRecord, error)
}
// WithdrawalRequestScanner nETH exit depends on the WithdrawalRequest.
// vNFT exit can be used directly with Exit Scanner.
type WithdrawalRequestScanner interface {
ExitScanner
// WithdrawalRequestScan Scan for unclaimed Withdrawal Requests
WithdrawalRequestScan(operatorId *big.Int) ([]*withdrawalRequest.WithdrawalRequestWithdrawalInfo, error)
}
// ExitFilter filter the exit for vNFT and nETH.
// Validator's exit is asynchrony. The reasons for asynchrony are:
// 1. The validator exit goes through the lifetime of the beacon.
// 2. NodeDAO-Oracle is required to report to settle.
// --------------------------------------------
// Filter The operator needs to implement it by itself, and the easiest way is to use db.
// An example implementation will be provided, based on MySQL, see Example.
type ExitFilter interface {
// Filter To filter for exit
// @return []*VnftRecord{} Filtered
Filter(operatorId *big.Int, vnftRecords []*VnftRecord) ([]*VnftRecord, error)
}
// WithdrawalRequestFilter To filter for WithdrawalRequests.
// --------------------------------------------
// The simplest way to implement the operator is to use db, see example.
type WithdrawalRequestFilter interface {
// WithdrawalRequestFilter To filter for WithdrawalRequests.
// @return []*WithdrawalRequest Filtered WithdrawalRequests.
WithdrawalRequestFilter(operatorId *big.Int, withdrawalRequests []*WithdrawalRequest) ([]*WithdrawalRequest, error)
}
// WithdrawalRequestExitValidatorCounter Calculate the number of validators that need to be exited by a Withdrawal Request
type WithdrawalRequestExitValidatorCounter interface {
// ExitCounter Calculate the number of validators that need to be exited by a Withdrawal Request
// @param filterWithdrawalRequests A list of offline filtered Withdrawal Requests
ExitCounter(filterWithdrawalRequests []*WithdrawalRequest) (uint32, error)
}
// ExitMarker To perform a validator exit, it needs to be flagged, and then it is used for filter.
// --------------------------------------------
// The simplest way to implement the operator is to use db, see example.
type ExitMarker interface {
// ExitMark Mark the exit of the Vnft Record.
ExitMark(operatorId *big.Int, vnftRecords []*VnftRecord) error
}
// WithdrawalRequestMarker To mark deal for WithdrawalRequest.
// --------------------------------------------
// The simplest way to implement the operator is to use db, see example.
type WithdrawalRequestMarker interface {
// WithdrawalRequestMark To mark deal for WithdrawalRequest
WithdrawalRequestMark(operatorId *big.Int, withdrawalRequests []*WithdrawalRequest) error
}