-
Notifications
You must be signed in to change notification settings - Fork 19
/
chain_events.go
1020 lines (880 loc) · 25 KB
/
chain_events.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) 2022 Gobalsky Labs Limited
//
// Use of this software is governed by the Business Source License included
// in the LICENSE.VEGA file and at https://www.mariadb.com/bsl11.
//
// Change Date: 18 months from the later of the date of the first publicly
// available Distribution of this version of the repository, and 25 June 2022.
//
// On the date above, in accordance with the Business Source License, use
// of this software will be governed by version 3 or later of the GNU General
// Public License.
//lint:file-ignore ST1003 Ignore underscores in names, this is straight copied from the proto package to ease introducing the domain types
package types
import (
"errors"
"fmt"
"code.vegaprotocol.io/vega/libs/crypto"
"code.vegaprotocol.io/vega/libs/num"
vegapb "code.vegaprotocol.io/vega/protos/vega"
commandspb "code.vegaprotocol.io/vega/protos/vega/commands/v1"
)
type WithdrawExt struct {
Ext isWithdrawExtExt
}
func (x *WithdrawExt) String() string {
return fmt.Sprintf(
"ext(%s)",
reflectPointerToString(x.Ext),
)
}
func (x *WithdrawExt) IntoProto() *vegapb.WithdrawExt {
if x == nil {
return nil
}
switch st := x.Ext.(type) {
case *WithdrawExtErc20:
return &vegapb.WithdrawExt{
Ext: st.IntoProto(),
}
default:
return nil
}
}
func (x *WithdrawExt) GetErc20() *WithdrawExtErc20 {
switch st := x.Ext.(type) {
case *WithdrawExtErc20:
return st
default:
return nil
}
}
func WithdrawExtFromProto(extProto *vegapb.WithdrawExt) *WithdrawExt {
if extProto == nil {
return nil
}
var src isWithdrawExtExt
switch st := extProto.Ext.(type) {
case *vegapb.WithdrawExt_Erc20:
src = WithdrawExtErc20FromProto(st)
}
return &WithdrawExt{
Ext: src,
}
}
type isWithdrawExtExt interface {
isWithdrawExtExt()
String() string
}
type WithdrawExtErc20 struct {
Erc20 *Erc20WithdrawExt
}
func (x *WithdrawExtErc20) isWithdrawExtExt() {}
func (x *WithdrawExtErc20) String() string {
return fmt.Sprintf(
"erc20(%s)",
reflectPointerToString(x.Erc20),
)
}
func (x *WithdrawExtErc20) IntoProto() *vegapb.WithdrawExt_Erc20 {
return &vegapb.WithdrawExt_Erc20{
Erc20: x.Erc20.IntoProto(),
}
}
func (x *WithdrawExtErc20) GetReceiverAddress() string {
return x.Erc20.ReceiverAddress
}
func WithdrawExtErc20FromProto(erc20 *vegapb.WithdrawExt_Erc20) *WithdrawExtErc20 {
return &WithdrawExtErc20{
Erc20: Erc20WithdrawExtFromProto(erc20.Erc20),
}
}
type Erc20WithdrawExt struct {
ReceiverAddress string
}
func (x *Erc20WithdrawExt) String() string {
return fmt.Sprintf("receiverAddress(%s)", x.ReceiverAddress)
}
func (x *Erc20WithdrawExt) IntoProto() *vegapb.Erc20WithdrawExt {
return &vegapb.Erc20WithdrawExt{
ReceiverAddress: x.ReceiverAddress,
}
}
func Erc20WithdrawExtFromProto(erc20 *vegapb.Erc20WithdrawExt) *Erc20WithdrawExt {
return &Erc20WithdrawExt{
ReceiverAddress: crypto.EthereumChecksumAddress(erc20.ReceiverAddress),
}
}
type WithdrawalStatus = vegapb.Withdrawal_Status
const (
// WithdrawalStatusUnspecified Default value, always invalid.
WithdrawalStatusUnspecified WithdrawalStatus = 0
// WithdrawalStatusOpen The withdrawal is open and being processed by the network.
WithdrawalStatusOpen WithdrawalStatus = 1
// WithdrawalStatusRejected The withdrawal have been rejected.
WithdrawalStatusRejected WithdrawalStatus = 2
// WithdrawalStatusFinalized The withdrawal went through and is fully finalised, the funds are removed from the
// Vega network and are unlocked on the foreign chain bridge, for example, on the Ethereum network.
WithdrawalStatusFinalized WithdrawalStatus = 3
)
type Withdrawal struct {
// ID Unique identifier for the withdrawal
ID string
// PartyID Unique party identifier of the user initiating the withdrawal
PartyID string
// Amount The amount to be withdrawn
Amount *num.Uint
// Asset The asset we want to withdraw funds from
Asset string
// Status The status of the withdrawal
Status WithdrawalStatus
// Ref The reference which is used by the foreign chain
// to refer to this withdrawal
Ref string
// TxHash The hash of the foreign chain for this transaction
TxHash string
// CreationDate Timestamp for when the network started to process this withdrawal
CreationDate int64
// WithdrawalDate Timestamp for when the withdrawal was finalised by the network
WithdrawalDate int64
// ExpirationDate The time until when the withdrawal is valid
ExpirationDate int64
// Ext Foreign chain specifics
Ext *WithdrawExt
}
func (w *Withdrawal) IntoProto() *vegapb.Withdrawal {
return &vegapb.Withdrawal{
Id: w.ID,
PartyId: w.PartyID,
Amount: num.UintToString(w.Amount),
Asset: w.Asset,
Status: w.Status,
Ref: w.Ref,
TxHash: w.TxHash,
Expiry: w.ExpirationDate,
CreatedTimestamp: w.CreationDate,
WithdrawnTimestamp: w.WithdrawalDate,
Ext: w.Ext.IntoProto(),
}
}
func WithdrawalFromProto(w *vegapb.Withdrawal) *Withdrawal {
amt, _ := num.UintFromString(w.Amount, 10)
return &Withdrawal{
ID: w.Id,
PartyID: w.PartyId,
Amount: amt,
Asset: w.Asset,
Status: w.Status,
Ref: w.Ref,
TxHash: w.TxHash,
ExpirationDate: w.Expiry,
CreationDate: w.CreatedTimestamp,
WithdrawalDate: w.WithdrawnTimestamp,
Ext: WithdrawExtFromProto(w.Ext),
}
}
type DepositStatus = vegapb.Deposit_Status
const (
// DepositStatusUnspecified Default value, always invalid.
DepositStatusUnspecified DepositStatus = 0
// DepositStatusOpen The deposit is being processed by the network.
DepositStatusOpen DepositStatus = 1
// DepositStatusCancelled The deposit has been cancelled by the network.
DepositStatusCancelled DepositStatus = 2
// DepositStatusFinalized The deposit has been finalised and accounts have been updated.
DepositStatusFinalized DepositStatus = 3
)
// Deposit represent a deposit on to the Vega network.
type Deposit struct {
// ID Unique identifier for the deposit
ID string
// Status of the deposit
Status DepositStatus
// Party identifier of the user initiating the deposit
PartyID string
// Asset The Vega asset targeted by this deposit
Asset string
// Amount The amount to be deposited
Amount *num.Uint
// TxHash The hash of the transaction from the foreign chain
TxHash string
// Timestamp for when the Vega account was updated with the deposit
CreditDate int64
// Timestamp for when the deposit was created on the Vega network
CreationDate int64
}
func (d *Deposit) IntoProto() *vegapb.Deposit {
return &vegapb.Deposit{
Id: d.ID,
Status: d.Status,
PartyId: d.PartyID,
Asset: d.Asset,
Amount: num.UintToString(d.Amount),
TxHash: d.TxHash,
CreditedTimestamp: d.CreditDate,
CreatedTimestamp: d.CreationDate,
}
}
func (d *Deposit) String() string {
return fmt.Sprintf(
"ID(%s) status(%s) partyID(%s) asset(%s) amount(%s) txHash(%s) creditDate(%v) creationDate(%v)",
d.ID,
d.Status.String(),
d.PartyID,
d.Asset,
uintPointerToString(d.Amount),
d.TxHash,
d.CreditDate,
d.CreationDate,
)
}
func DepositFromProto(d *vegapb.Deposit) *Deposit {
amt, _ := num.UintFromString(d.Amount, 10)
return &Deposit{
ID: d.Id,
Status: d.Status,
PartyID: d.PartyId,
Asset: d.Asset,
Amount: amt,
TxHash: d.TxHash,
CreditDate: d.CreditedTimestamp,
CreationDate: d.CreatedTimestamp,
}
}
type ChainEventERC20 struct {
ERC20 *ERC20Event
}
func NewChainEventERC20FromProto(p *commandspb.ChainEvent_Erc20) (*ChainEventERC20, error) {
c := ChainEventERC20{}
var err error
c.ERC20, err = NewERC20Event(p.Erc20)
if err != nil {
return nil, err
}
return &c, nil
}
func (c ChainEventERC20) IntoProto() *commandspb.ChainEvent_Erc20 {
p := &commandspb.ChainEvent_Erc20{
Erc20: c.ERC20.IntoProto(),
}
return p
}
func (c ChainEventERC20) String() string {
return fmt.Sprintf(
"erc20(%s)",
reflectPointerToString(c.ERC20),
)
}
type BuiltinAssetDeposit struct {
// A Vega network internal asset identifier
VegaAssetID string
// A Vega party identifier (pub-key)
PartyID string
// The amount to be deposited
Amount *num.Uint
}
func NewBuiltinAssetDepositFromProto(p *vegapb.BuiltinAssetDeposit) (*BuiltinAssetDeposit, error) {
amount := num.UintZero()
if len(p.Amount) > 0 {
var overflowed bool
amount, overflowed = num.UintFromString(p.Amount, 10)
if overflowed {
return nil, errors.New("invalid amount")
}
}
return &BuiltinAssetDeposit{
VegaAssetID: p.VegaAssetId,
PartyID: p.PartyId,
Amount: amount,
}, nil
}
func (b BuiltinAssetDeposit) IntoProto() *vegapb.BuiltinAssetDeposit {
return &vegapb.BuiltinAssetDeposit{
VegaAssetId: b.VegaAssetID,
PartyId: b.PartyID,
Amount: num.UintToString(b.Amount),
}
}
func (b BuiltinAssetDeposit) String() string {
return fmt.Sprintf(
"party(%s) vegaAssetID(%s) amount(%s)",
b.PartyID,
b.VegaAssetID,
uintPointerToString(b.Amount),
)
}
func (b BuiltinAssetDeposit) GetVegaAssetID() string {
return b.VegaAssetID
}
type BuiltinAssetWithdrawal struct {
// A Vega network internal asset identifier
VegaAssetID string
// A Vega network party identifier (pub-key)
PartyID string
// The amount to be withdrawn
Amount *num.Uint
}
func NewBuiltinAssetWithdrawalFromProto(p *vegapb.BuiltinAssetWithdrawal) (*BuiltinAssetWithdrawal, error) {
amount := num.UintZero()
if len(p.Amount) > 0 {
var overflowed bool
amount, overflowed = num.UintFromString(p.Amount, 10)
if overflowed {
return nil, errors.New("invalid amount")
}
}
return &BuiltinAssetWithdrawal{
VegaAssetID: p.VegaAssetId,
PartyID: p.PartyId,
Amount: amount,
}, nil
}
func (b BuiltinAssetWithdrawal) IntoProto() *vegapb.BuiltinAssetWithdrawal {
return &vegapb.BuiltinAssetWithdrawal{
VegaAssetId: b.VegaAssetID,
PartyId: b.PartyID,
Amount: num.UintToString(b.Amount),
}
}
func (b BuiltinAssetWithdrawal) String() string {
return fmt.Sprintf(
"partyID(%s) vegaAssetID(%s) amount(%s)",
b.PartyID,
b.VegaAssetID,
uintPointerToString(b.Amount),
)
}
func (b BuiltinAssetWithdrawal) GetVegaAssetID() string {
return b.VegaAssetID
}
type ChainEventBuiltin struct {
Builtin *BuiltinAssetEvent
}
func NewChainEventBuiltinFromProto(p *commandspb.ChainEvent_Builtin) (*ChainEventBuiltin, error) {
c := ChainEventBuiltin{}
var err error
c.Builtin, err = NewBuiltinAssetEventFromProto(p.Builtin)
if err != nil {
return nil, err
}
return &c, nil
}
func (c ChainEventBuiltin) IntoProto() *commandspb.ChainEvent_Builtin {
ceb := &commandspb.ChainEvent_Builtin{
Builtin: c.Builtin.IntoProto(),
}
return ceb
}
func (c ChainEventBuiltin) String() string {
return fmt.Sprintf(
"builtin(%s)",
reflectPointerToString(c.Builtin),
)
}
type BuiltinAssetEvent struct {
// Types that are valid to be assigned to Action:
// *BuiltinAssetEvent_Deposit
// *BuiltinAssetEvent_Withdrawal
Action builtinAssetEventAction
}
type builtinAssetEventAction interface {
isBuiltinAssetEvent()
oneOfProto() interface{}
String() string
}
func NewBuiltinAssetEventFromProto(p *vegapb.BuiltinAssetEvent) (*BuiltinAssetEvent, error) {
var (
ae = &BuiltinAssetEvent{}
err error
)
switch e := p.Action.(type) {
case *vegapb.BuiltinAssetEvent_Deposit:
ae.Action, err = NewBuiltinAssetEventDeposit(e)
return ae, err
case *vegapb.BuiltinAssetEvent_Withdrawal:
ae.Action, err = NewBuiltinAssetEventWithdrawal(e)
return ae, err
default:
return nil, errors.New("unknown asset event type")
}
}
func (c BuiltinAssetEvent) IntoProto() *vegapb.BuiltinAssetEvent {
action := c.Action.oneOfProto()
ceb := &vegapb.BuiltinAssetEvent{}
switch a := action.(type) {
case *vegapb.BuiltinAssetEvent_Deposit:
ceb.Action = a
case *vegapb.BuiltinAssetEvent_Withdrawal:
ceb.Action = a
}
return ceb
}
func (c BuiltinAssetEvent) String() string {
return fmt.Sprintf(
"action(%s)",
reflectPointerToString(c.Action),
)
}
type BuiltinAssetEventDeposit struct {
Deposit *BuiltinAssetDeposit
}
func (b BuiltinAssetEventDeposit) String() string {
return fmt.Sprintf(
"deposit(%s)",
reflectPointerToString(b.Deposit),
)
}
func NewBuiltinAssetEventDeposit(p *vegapb.BuiltinAssetEvent_Deposit) (*BuiltinAssetEventDeposit, error) {
dep, err := NewBuiltinAssetDepositFromProto(p.Deposit)
if err != nil {
return nil, err
}
return &BuiltinAssetEventDeposit{
Deposit: dep,
}, nil
}
func (b BuiltinAssetEventDeposit) IntoProto() *vegapb.BuiltinAssetEvent_Deposit {
p := &vegapb.BuiltinAssetEvent_Deposit{
Deposit: b.Deposit.IntoProto(),
}
return p
}
func (b BuiltinAssetEventDeposit) isBuiltinAssetEvent() {}
func (b BuiltinAssetEventDeposit) oneOfProto() interface{} {
return b.IntoProto()
}
type BuiltinAssetEventWithdrawal struct {
Withdrawal *BuiltinAssetWithdrawal
}
func (b BuiltinAssetEventWithdrawal) String() string {
return fmt.Sprintf(
"withdrawal(%s)",
reflectPointerToString(b.Withdrawal),
)
}
func NewBuiltinAssetEventWithdrawal(p *vegapb.BuiltinAssetEvent_Withdrawal) (*BuiltinAssetEventWithdrawal, error) {
withdrawal, err := NewBuiltinAssetWithdrawalFromProto(p.Withdrawal)
if err != nil {
return nil, err
}
return &BuiltinAssetEventWithdrawal{
Withdrawal: withdrawal,
}, nil
}
func (b BuiltinAssetEventWithdrawal) IntoProto() *vegapb.BuiltinAssetEvent_Withdrawal {
p := &vegapb.BuiltinAssetEvent_Withdrawal{
Withdrawal: b.Withdrawal.IntoProto(),
}
return p
}
func (b BuiltinAssetEventWithdrawal) isBuiltinAssetEvent() {}
func (b BuiltinAssetEventWithdrawal) oneOfProto() interface{} {
return b.IntoProto()
}
type ERC20Event struct {
// Index of the transaction
Index uint64
// The block in which the transaction was added
Block uint64
// The action
//
// Types that are valid to be assigned to Action:
// *ERC20EventAssetList
// *ERC20EventAssetDelist
// *ERC20EventDeposit
// *ERC20EventWithdrawal
// *ERC20EventAssetLimitsUpdated
// *ERC20BridgeStopped
// *ERC20BridgeRemoved
Action erc20EventAction
}
type erc20EventAction interface {
isErc20EventAction()
oneOfProto() interface{}
String() string
}
func NewERC20Event(p *vegapb.ERC20Event) (*ERC20Event, error) {
e := ERC20Event{
Index: p.Index,
Block: p.Block,
}
var err error
switch a := p.Action.(type) {
case *vegapb.ERC20Event_AssetDelist:
e.Action = NewERC20EventAssetDelist(a)
return &e, nil
case *vegapb.ERC20Event_AssetList:
e.Action = NewERC20EventAssetList(a)
return &e, nil
case *vegapb.ERC20Event_Deposit:
e.Action, err = NewERC20EventDeposit(a)
if err != nil {
return nil, err
}
return &e, nil
case *vegapb.ERC20Event_Withdrawal:
e.Action = NewERC20EventWithdrawal(a)
return &e, nil
case *vegapb.ERC20Event_AssetLimitsUpdated:
e.Action = NewERC20EventAssetLimitsUpdated(a)
return &e, nil
case *vegapb.ERC20Event_BridgeStopped:
e.Action = NewERC20EventBridgeStopped(a)
return &e, nil
case *vegapb.ERC20Event_BridgeResumed:
e.Action = NewERC20EventBridgeResumed(a)
return &e, nil
default:
return nil, errors.New("unknown erc20 event type")
}
}
func (e ERC20Event) IntoProto() *vegapb.ERC20Event {
p := &vegapb.ERC20Event{
Index: e.Index,
Block: e.Block,
}
switch a := e.Action.(type) {
case *ERC20EventAssetDelist:
p.Action = a.IntoProto()
case *ERC20EventAssetList:
p.Action = a.IntoProto()
case *ERC20EventDeposit:
p.Action = a.IntoProto()
case *ERC20EventWithdrawal:
p.Action = a.IntoProto()
default:
return nil
}
return p
}
func (e ERC20Event) String() string {
return fmt.Sprintf(
"index(%v) block(%v) action(%s)",
e.Index,
e.Block,
reflectPointerToString(e.Action),
)
}
type ERC20EventAssetDelist struct {
AssetDelist *ERC20AssetDelist
}
func (e ERC20EventAssetDelist) String() string {
return fmt.Sprintf(
"assetDelist(%s)",
reflectPointerToString(e.AssetDelist),
)
}
func (ERC20EventAssetDelist) isErc20EventAction() {}
func (e ERC20EventAssetDelist) oneOfProto() interface{} {
return e.AssetDelist.IntoProto()
}
func NewERC20EventAssetDelist(p *vegapb.ERC20Event_AssetDelist) *ERC20EventAssetDelist {
return &ERC20EventAssetDelist{
AssetDelist: NewERC20AssetDelistFromProto(p.AssetDelist),
}
}
func (e ERC20EventAssetDelist) IntoProto() *vegapb.ERC20Event_AssetDelist {
return &vegapb.ERC20Event_AssetDelist{
AssetDelist: e.AssetDelist.IntoProto(),
}
}
type ERC20AssetDelist struct {
// The Vega network internal identifier of the asset
VegaAssetID string
}
func NewERC20AssetDelistFromProto(p *vegapb.ERC20AssetDelist) *ERC20AssetDelist {
return &ERC20AssetDelist{
VegaAssetID: p.VegaAssetId,
}
}
func (e ERC20AssetDelist) IntoProto() *vegapb.ERC20AssetDelist {
return &vegapb.ERC20AssetDelist{
VegaAssetId: e.VegaAssetID,
}
}
func (e ERC20AssetDelist) String() string {
return fmt.Sprintf("vegaAssetID(%s)", e.VegaAssetID)
}
type ERC20EventAssetList struct {
AssetList *ERC20AssetList
}
func (ERC20EventAssetList) isErc20EventAction() {}
func (e ERC20EventAssetList) oneOfProto() interface{} {
return e.AssetList.IntoProto()
}
func (e ERC20EventAssetList) String() string {
return fmt.Sprintf(
"assetList(%s)",
reflectPointerToString(e.AssetList),
)
}
func NewERC20EventAssetList(p *vegapb.ERC20Event_AssetList) *ERC20EventAssetList {
return &ERC20EventAssetList{
AssetList: NewERC20AssetListFromProto(p.AssetList),
}
}
func (e ERC20EventAssetList) IntoProto() *vegapb.ERC20Event_AssetList {
return &vegapb.ERC20Event_AssetList{
AssetList: e.AssetList.IntoProto(),
}
}
type ERC20AssetList struct {
// The Vega network internal identifier of the asset
VegaAssetID string
// ethereum address of the asset
AssetSource string
}
func NewERC20AssetListFromProto(p *vegapb.ERC20AssetList) *ERC20AssetList {
return &ERC20AssetList{
VegaAssetID: p.VegaAssetId,
AssetSource: p.AssetSource,
}
}
func (e ERC20AssetList) IntoProto() *vegapb.ERC20AssetList {
return &vegapb.ERC20AssetList{
VegaAssetId: e.VegaAssetID,
}
}
func (e ERC20AssetList) String() string {
return fmt.Sprintf(
"vegaAssetID(%s)",
e.VegaAssetID,
)
}
func (e ERC20AssetList) GetVegaAssetID() string {
return e.VegaAssetID
}
type ERC20EventWithdrawal struct {
Withdrawal *ERC20Withdrawal
}
func (ERC20EventWithdrawal) isErc20EventAction() {}
func (e ERC20EventWithdrawal) oneOfProto() interface{} {
return e.Withdrawal.IntoProto()
}
func (e ERC20EventWithdrawal) String() string {
return fmt.Sprintf(
"withdrawal(%s)",
reflectPointerToString(e.Withdrawal),
)
}
func NewERC20EventWithdrawal(p *vegapb.ERC20Event_Withdrawal) *ERC20EventWithdrawal {
return &ERC20EventWithdrawal{
Withdrawal: NewERC20WithdrawalFromProto(p.Withdrawal),
}
}
func (e ERC20EventWithdrawal) IntoProto() *vegapb.ERC20Event_Withdrawal {
return &vegapb.ERC20Event_Withdrawal{
Withdrawal: e.Withdrawal.IntoProto(),
}
}
type ERC20Withdrawal struct {
// The Vega network internal identifier of the asset
VegaAssetID string
// The target Ethereum wallet address
TargetEthereumAddress string
// The reference nonce used for the transaction
ReferenceNonce string
}
func NewERC20WithdrawalFromProto(p *vegapb.ERC20Withdrawal) *ERC20Withdrawal {
return &ERC20Withdrawal{
VegaAssetID: p.VegaAssetId,
TargetEthereumAddress: p.TargetEthereumAddress,
ReferenceNonce: p.ReferenceNonce,
}
}
func (e ERC20Withdrawal) IntoProto() *vegapb.ERC20Withdrawal {
return &vegapb.ERC20Withdrawal{
VegaAssetId: e.VegaAssetID,
TargetEthereumAddress: e.TargetEthereumAddress,
ReferenceNonce: e.ReferenceNonce,
}
}
func (e ERC20Withdrawal) String() string {
return fmt.Sprintf(
"vegaAssetID(%s) referenceNonce(%s) targetEthereumAddress(%s)",
e.VegaAssetID,
e.ReferenceNonce,
e.TargetEthereumAddress,
)
}
func (e ERC20Withdrawal) GetVegaAssetID() string {
return e.VegaAssetID
}
type ERC20EventDeposit struct {
Deposit *ERC20Deposit
}
func (e ERC20EventDeposit) String() string {
return fmt.Sprintf(
"deposit(%s)",
reflectPointerToString(e.Deposit),
)
}
func (ERC20EventDeposit) isErc20EventAction() {}
func (e ERC20EventDeposit) oneOfProto() interface{} {
return e.Deposit.IntoProto()
}
func NewERC20EventDeposit(p *vegapb.ERC20Event_Deposit) (*ERC20EventDeposit, error) {
e := ERC20EventDeposit{}
var err error
e.Deposit, err = NewERC20DepositFromProto(p.Deposit)
if err != nil {
return nil, err
}
return &e, nil
}
func (e ERC20EventDeposit) IntoProto() *vegapb.ERC20Event_Deposit {
p := vegapb.ERC20Event_Deposit{
Deposit: e.Deposit.IntoProto(),
}
return &p
}
type ERC20Deposit struct {
// The vega network internal identifier of the asset
VegaAssetID string
// The Ethereum wallet that initiated the deposit
SourceEthereumAddress string
// The Vega party identifier (pub-key) which is the target of the deposit
TargetPartyID string
// The amount to be deposited
Amount *num.Uint
}
func NewERC20DepositFromProto(p *vegapb.ERC20Deposit) (*ERC20Deposit, error) {
e := ERC20Deposit{
VegaAssetID: p.VegaAssetId,
SourceEthereumAddress: p.SourceEthereumAddress,
TargetPartyID: p.TargetPartyId,
}
if len(p.Amount) > 0 {
var failed bool
e.Amount, failed = num.UintFromString(p.Amount, 10)
if failed {
return nil, fmt.Errorf("failed to convert numerical string to Uint: %v", p.Amount)
}
}
return &e, nil
}
func (e ERC20Deposit) IntoProto() *vegapb.ERC20Deposit {
return &vegapb.ERC20Deposit{
VegaAssetId: e.VegaAssetID,
SourceEthereumAddress: e.SourceEthereumAddress,
TargetPartyId: e.TargetPartyID,
Amount: num.UintToString(e.Amount),
}
}
func (e ERC20Deposit) String() string {
return fmt.Sprintf(
"vegaAssetID(%s) targetPartyID(%s) amount(%s) sourceEthereumAddress(%s)",
e.VegaAssetID,
e.TargetPartyID,
uintPointerToString(e.Amount),
e.SourceEthereumAddress,
)
}
func (e ERC20Deposit) GetVegaAssetID() string {
return e.VegaAssetID
}
type ERC20EventAssetLimitsUpdated struct {
AssetLimitsUpdated *ERC20AssetLimitsUpdated
}
func (ERC20EventAssetLimitsUpdated) isErc20EventAction() {}
func (e ERC20EventAssetLimitsUpdated) oneOfProto() interface{} {
return e.AssetLimitsUpdated.IntoProto()
}
func (e ERC20EventAssetLimitsUpdated) String() string {
return fmt.Sprintf(
"assetLimitsUpdated(%s)",
reflectPointerToString(e.AssetLimitsUpdated),
)
}
func NewERC20EventAssetLimitsUpdated(p *vegapb.ERC20Event_AssetLimitsUpdated) *ERC20EventAssetLimitsUpdated {
return &ERC20EventAssetLimitsUpdated{
AssetLimitsUpdated: NewERC20AssetLimitsUpdatedFromProto(p.AssetLimitsUpdated),
}
}
func (e ERC20EventAssetLimitsUpdated) IntoProto() *vegapb.ERC20Event_AssetLimitsUpdated {
return &vegapb.ERC20Event_AssetLimitsUpdated{
AssetLimitsUpdated: e.AssetLimitsUpdated.IntoProto(),
}
}
type ERC20AssetLimitsUpdated struct {
VegaAssetID string
SourceEthereumAddress string
LifetimeLimits *num.Uint
WithdrawThreshold *num.Uint
}
func NewERC20AssetLimitsUpdatedFromProto(p *vegapb.ERC20AssetLimitsUpdated) *ERC20AssetLimitsUpdated {
lifetimeLimits, _ := num.UintFromString(p.LifetimeLimits, 10)
withdrawThreshold, _ := num.UintFromString(p.WithdrawThreshold, 10)
return &ERC20AssetLimitsUpdated{
VegaAssetID: p.VegaAssetId,
SourceEthereumAddress: p.SourceEthereumAddress,
LifetimeLimits: lifetimeLimits,
WithdrawThreshold: withdrawThreshold,
}
}
func (e ERC20AssetLimitsUpdated) IntoProto() *vegapb.ERC20AssetLimitsUpdated {
return &vegapb.ERC20AssetLimitsUpdated{
VegaAssetId: e.VegaAssetID,
SourceEthereumAddress: e.SourceEthereumAddress,
LifetimeLimits: num.UintToString(e.LifetimeLimits),
WithdrawThreshold: num.UintToString(e.WithdrawThreshold),
}
}
func (e ERC20AssetLimitsUpdated) String() string {
return fmt.Sprintf(
"vegaAssetID(%s) sourceEthereumAddress(%s) lifetimeLimits(%s) withdrawThreshold(%s)",
e.VegaAssetID,
e.SourceEthereumAddress,
uintPointerToString(e.LifetimeLimits),
uintPointerToString(e.WithdrawThreshold),
)
}
func (e ERC20AssetLimitsUpdated) GetVegaAssetID() string {
return e.VegaAssetID
}
type ERC20EventBridgeStopped struct {
BridgeStopped bool
}
func (ERC20EventBridgeStopped) isErc20EventAction() {}
func (e ERC20EventBridgeStopped) oneOfProto() interface{} {
return e.IntoProto()
}
func (e ERC20EventBridgeStopped) String() string {
return fmt.Sprintf(
"bridgeStopped(%v)",
e.BridgeStopped,
)
}
func NewERC20EventBridgeStopped(p *vegapb.ERC20Event_BridgeStopped) *ERC20EventBridgeStopped {
return &ERC20EventBridgeStopped{
BridgeStopped: p.BridgeStopped,
}
}
func (e ERC20EventBridgeStopped) IntoProto() *vegapb.ERC20Event_BridgeStopped {
return &vegapb.ERC20Event_BridgeStopped{
BridgeStopped: e.BridgeStopped,
}
}
type ERC20EventBridgeResumed struct {
BridgeResumed bool
}
func (ERC20EventBridgeResumed) isErc20EventAction() {}
func (e ERC20EventBridgeResumed) oneOfProto() interface{} {
return e.IntoProto()