-
Notifications
You must be signed in to change notification settings - Fork 8
/
relayer.gen.go
1524 lines (1328 loc) · 49.6 KB
/
relayer.gen.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
// sequence-relayer v0.4.1 1e27d0fd295aa5897878939595ef0c6adc54b1a3
// --
// Code generated by webrpc-gen@v0.18.6 with golang generator. DO NOT EDIT.
//
// webrpc-gen -schema=relayer.ridl -target=golang -pkg=proto -client -out=./clients/relayer.gen.go
package proto
import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"net/url"
"time"
"github.com/0xsequence/go-sequence/lib/prototyp"
"github.com/shopspring/decimal"
)
// WebRPC description and code-gen version
func WebRPCVersion() string {
return "v1"
}
// Schema version of your RIDL schema
func WebRPCSchemaVersion() string {
return "v0.4.1"
}
// Schema hash generated from your RIDL schema
func WebRPCSchemaHash() string {
return "1e27d0fd295aa5897878939595ef0c6adc54b1a3"
}
//
// Common types
//
type ETHTxnStatus uint
const (
ETHTxnStatus_UNKNOWN ETHTxnStatus = 0
// txn rejected by relayer
ETHTxnStatus_DROPPED ETHTxnStatus = 1
// txn accepted by relayer, waiting to be sent
ETHTxnStatus_QUEUED ETHTxnStatus = 2
// txn sent, waiting for txn to be mined
ETHTxnStatus_SENT ETHTxnStatus = 3
// txn mined, all txns in the bundle succeeded
ETHTxnStatus_SUCCEEDED ETHTxnStatus = 4
// txn mined, but some txns in the bundle failed
ETHTxnStatus_PARTIALLY_FAILED ETHTxnStatus = 5
// txn mined, but all txns in the bundle failed
ETHTxnStatus_FAILED ETHTxnStatus = 6
)
var ETHTxnStatus_name = map[uint]string{
0: "UNKNOWN",
1: "DROPPED",
2: "QUEUED",
3: "SENT",
4: "SUCCEEDED",
5: "PARTIALLY_FAILED",
6: "FAILED",
}
var ETHTxnStatus_value = map[string]uint{
"UNKNOWN": 0,
"DROPPED": 1,
"QUEUED": 2,
"SENT": 3,
"SUCCEEDED": 4,
"PARTIALLY_FAILED": 5,
"FAILED": 6,
}
func (x ETHTxnStatus) String() string {
return ETHTxnStatus_name[uint(x)]
}
func (x ETHTxnStatus) MarshalText() ([]byte, error) {
return []byte(ETHTxnStatus_name[uint(x)]), nil
}
func (x *ETHTxnStatus) UnmarshalText(b []byte) error {
*x = ETHTxnStatus(ETHTxnStatus_value[string(b)])
return nil
}
func (x *ETHTxnStatus) Is(values ...ETHTxnStatus) bool {
if x == nil {
return false
}
for _, v := range values {
if *x == v {
return true
}
}
return false
}
type TransferType uint32
const (
TransferType_SEND TransferType = 0
TransferType_RECEIVE TransferType = 1
TransferType_BRIDGE_DEPOSIT TransferType = 2
TransferType_BRIDGE_WITHDRAW TransferType = 3
TransferType_BURN TransferType = 4
TransferType_UNKNOWN TransferType = 5
)
var TransferType_name = map[uint32]string{
0: "SEND",
1: "RECEIVE",
2: "BRIDGE_DEPOSIT",
3: "BRIDGE_WITHDRAW",
4: "BURN",
5: "UNKNOWN",
}
var TransferType_value = map[string]uint32{
"SEND": 0,
"RECEIVE": 1,
"BRIDGE_DEPOSIT": 2,
"BRIDGE_WITHDRAW": 3,
"BURN": 4,
"UNKNOWN": 5,
}
func (x TransferType) String() string {
return TransferType_name[uint32(x)]
}
func (x TransferType) MarshalText() ([]byte, error) {
return []byte(TransferType_name[uint32(x)]), nil
}
func (x *TransferType) UnmarshalText(b []byte) error {
*x = TransferType(TransferType_value[string(b)])
return nil
}
func (x *TransferType) Is(values ...TransferType) bool {
if x == nil {
return false
}
for _, v := range values {
if *x == v {
return true
}
}
return false
}
type FeeTokenType uint32
const (
FeeTokenType_UNKNOWN FeeTokenType = 0
FeeTokenType_ERC20_TOKEN FeeTokenType = 1
FeeTokenType_ERC1155_TOKEN FeeTokenType = 2
)
var FeeTokenType_name = map[uint32]string{
0: "UNKNOWN",
1: "ERC20_TOKEN",
2: "ERC1155_TOKEN",
}
var FeeTokenType_value = map[string]uint32{
"UNKNOWN": 0,
"ERC20_TOKEN": 1,
"ERC1155_TOKEN": 2,
}
func (x FeeTokenType) String() string {
return FeeTokenType_name[uint32(x)]
}
func (x FeeTokenType) MarshalText() ([]byte, error) {
return []byte(FeeTokenType_name[uint32(x)]), nil
}
func (x *FeeTokenType) UnmarshalText(b []byte) error {
*x = FeeTokenType(FeeTokenType_value[string(b)])
return nil
}
func (x *FeeTokenType) Is(values ...FeeTokenType) bool {
if x == nil {
return false
}
for _, v := range values {
if *x == v {
return true
}
}
return false
}
type SortOrder uint32
const (
SortOrder_DESC SortOrder = 0
SortOrder_ASC SortOrder = 1
)
var SortOrder_name = map[uint32]string{
0: "DESC",
1: "ASC",
}
var SortOrder_value = map[string]uint32{
"DESC": 0,
"ASC": 1,
}
func (x SortOrder) String() string {
return SortOrder_name[uint32(x)]
}
func (x SortOrder) MarshalText() ([]byte, error) {
return []byte(SortOrder_name[uint32(x)]), nil
}
func (x *SortOrder) UnmarshalText(b []byte) error {
*x = SortOrder(SortOrder_value[string(b)])
return nil
}
func (x *SortOrder) Is(values ...SortOrder) bool {
if x == nil {
return false
}
for _, v := range values {
if *x == v {
return true
}
}
return false
}
type Version struct {
WebrpcVersion string `json:"webrpcVersion"`
SchemaVersion string `json:"schemaVersion"`
SchemaHash string `json:"schemaHash"`
AppVersion string `json:"appVersion"`
}
type RuntimeStatus struct {
// overall status, true/false
HealthOK bool `json:"healthOK"`
StartTime time.Time `json:"startTime"`
Uptime uint64 `json:"uptime"`
Ver string `json:"ver"`
Branch string `json:"branch"`
CommitHash string `json:"commitHash"`
UseEIP1559 bool `json:"useEIP1559"`
Senders []*SenderStatus `json:"senders"`
Checks *RuntimeChecks `json:"checks"`
NumTxnsRelayed *NumTxnsRelayed `json:"numTxnsRelayed"`
}
type SenderStatus struct {
Index uint32 `json:"index"`
Address string `json:"address"`
EtherBalance float64 `json:"etherBalance"`
Active bool `json:"active"`
}
type RuntimeChecks struct {
}
type NumTxnsRelayed struct {
Prev uint64 `json:"prev"`
Current uint64 `json:"current"`
Period uint64 `json:"period"`
}
type SequenceContext struct {
Factory string `json:"factory"`
MainModule string `json:"mainModule"`
MainModuleUpgradable string `json:"mainModuleUpgradable"`
GuestModule string `json:"guestModule"`
Utils string `json:"utils"`
}
type GasTank struct {
ID uint64 `json:"id" db:"id,omitempty"`
Name string `json:"name" db:"name"`
CurrentBalance decimal.Decimal `json:"currentBalance" db:"current_balance"`
Unlimited bool `json:"unlimited" db:"unlimited"`
FeeMarkupFactor decimal.Decimal `json:"feeMarkupFactor" db:"fee_markup_factor"`
UpdatedAt *time.Time `json:"updatedAt" db:"updated_at,omitempty"`
CreatedAt *time.Time `json:"createdAt" db:"created_at,omitempty"`
}
type GasTankBalanceAdjustment struct {
GasTankID uint64 `json:"gasTankId" db:"gas_tank_id"`
Nonce uint64 `json:"nonce" db:"nonce"`
Amount decimal.Decimal `json:"amount" db:"amount"`
TotalBalance decimal.Decimal `json:"totalBalance" db:"total_balance"`
BalanceTimestamp time.Time `json:"balanceTimestamp" db:"balance_timestamp"`
CreatedAt *time.Time `json:"createdAt" db:"created_at,omitempty"`
}
type GasSponsor struct {
ID uint64 `json:"id" db:"id,omitempty"`
GasTankID uint64 `json:"gasTankId" db:"gas_tank_id,omitempty"`
ProjectID uint64 `json:"projectId" db:"project_id"`
Address prototyp.Hash `json:"address" db:"address"`
Name string `json:"name" db:"name"`
Active bool `json:"active" db:"active"`
UpdatedAt *time.Time `json:"updatedAt" db:"updated_at,omitempty"`
CreatedAt *time.Time `json:"createdAt" db:"created_at,omitempty"`
DeletedAt *time.Time `json:"-" db:"deleted_at,omitempty"`
}
type GasSponsorUsage struct {
Name string `json:"name" db:"name"`
ID uint64 `json:"id" db:"gas_sponsor_id,omitempty"`
TotalGasUsed int64 `json:"totalGasUsed" db:"total_gas_used"`
TotalTxnFees float64 `json:"totalTxnFees" db:"total_txn_fees"`
TotalTxnFeesUSD decimal.Decimal `json:"totalTxnFeesUsd" db:"total_txn_fees_usd"`
AvgGasPrice float64 `json:"avgGasPrice" db:"avg_gas_price"`
TotalTxns int64 `json:"totalTxns" db:"total_txns"`
StartTime *time.Time `json:"startTime"`
EndTime *time.Time `json:"endTime"`
}
// TODO: rename this to MetaTxnRaw (eventually), we can leave it for now to not break compat
// or name it, MetaTxnArgs ..?
type MetaTxn struct {
WalletAddress string `json:"walletAddress" db:"wallet_address"`
// TODO (later): rename this to `to: string`
Contract string `json:"contract" db:"to_address"`
// TODO: rename to 'execdata'
Input string `json:"input" db:"tx_data"`
}
// TODO: review
type MetaTxnLog struct {
ID uint64 `json:"id" db:"id,omitempty"`
ProjectID uint64 `json:"projectId" db:"project_id"`
// this is optional, but we don't specify txnHash?: string,
// otherwise it sets go.field.type to pointer-type which we dont want.
TxnHash prototyp.HashMaybe `json:"txnHash" db:"txn_hash"`
// TODO: this should be txnNonce?: string, but pgx giving issues
// with *prototyp.BigInt scanning
TxnNonce prototyp.BigInt `json:"txnNonce" db:"txn_nonce"`
MetaTxnID *string `json:"metaTxnID" db:"meta_txn_id"`
TxnStatus ETHTxnStatus `json:"txnStatus" db:"txn_status"`
TxnRevertReason string `json:"txnRevertReason" db:"txn_revert_reason"`
Requeues uint `json:"requeues" db:"requeues"`
QueuedAt *time.Time `json:"queuedAt" db:"queued_at,omitempty"`
SentAt *time.Time `json:"sentAt" db:"sent_at,omitempty"`
MinedAt *time.Time `json:"minedAt" db:"mined_at,omitempty"`
Target prototyp.Hash `json:"target" db:"target"`
Input prototyp.Hash `json:"input" db:"input"`
// TODO: review this field.. we may not want it.. what goes in here..? is it just
// the input/target from MetaTxn above? we already have these as separate columns..
TxnArgs map[string]interface{} `json:"txnArgs" db:"txn_args"`
TxnReceipt map[string]interface{} `json:"txnReceipt" db:"txn_receipt,omitempty"`
WalletAddress prototyp.Hash `json:"walletAddress" db:"wallet_address"`
MetaTxnNonce prototyp.BigInt `json:"metaTxnNonce" db:"metatx_nonce"`
GasLimit uint64 `json:"gasLimit" db:"gas_limit"`
GasPrice prototyp.BigInt `json:"gasPrice" db:"gas_price"`
GasUsed uint64 `json:"gasUsed" db:"gas_used"`
GasEstimated uint64 `json:"gasEstimated" db:"gas_estimated"`
GasFeeMarkup *uint64 `json:"gasFeeMarkup" db:"gas_fee_markup"`
UsdRate prototyp.BigInt `json:"usdRate" db:"usd_rate"`
CreditsUsed uint64 `json:"creditsUsed" db:"credits_used"`
IsWhitelisted bool `json:"isWhitelisted" db:"is_whitelisted,omitempty"`
GasSponsor *uint64 `json:"gasSponsor" db:"gas_sponsor_id,omitempty"`
GasTank *uint64 `json:"gasTank" db:"gas_tank_id,omitempty"`
UpdatedAt *time.Time `json:"updatedAt" db:"updated_at,omitempty"`
CreatedAt *time.Time `json:"createdAt" db:"created_at,omitempty"`
}
// TODO: review
type MetaTxnEntry struct {
ID uint64 `json:"id" db:"id,omitempty"`
MetaTxnID string `json:"metaTxnID" db:"metatx_logs_id"`
TxnStatus ETHTxnStatus `json:"txnStatus" db:"status"`
TxnRevertReason string `json:"txnRevertReason" db:"revert_reason"`
Index uint64 `json:"index" db:"index"`
Logs []interface{} `json:"logs" db:"logs,omitempty"`
UpdatedAt *time.Time `json:"updatedAt" db:"updated_at,omitempty"`
CreatedAt *time.Time `json:"createdAt" db:"created_at,omitempty"`
}
type MetaTxnReceipt struct {
ID string `json:"id"`
Status string `json:"status"`
RevertReason *string `json:"revertReason"`
Index uint `json:"index"`
Logs []*MetaTxnReceiptLog `json:"logs"`
Receipts []*MetaTxnReceipt `json:"receipts"`
TxnReceipt string `json:"txnReceipt"`
}
type MetaTxnReceiptLog struct {
Address string `json:"address"`
Topics []string `json:"topics"`
Data string `json:"data"`
}
// TODO: review and update this type ..
type Transaction struct {
TxnHash *string `json:"txnHash"`
BlockNumber uint64 `json:"blockNumber"`
ChainId uint64 `json:"chainId"`
MetaTxnID *string `json:"metaTxnID"`
Transfers []*TxnLogTransfer `json:"transfers"`
// TODO: review ..
Users map[string]*TxnLogUser `json:"users"`
// - contracts?: map<string, Contract> TODO: review.. this gives us contract metadata which is useful
// - tokenMetadata?: map<string,map<string,TokenMetadata>>
Timestamp *time.Time `json:"timestamp" db:"ts,omitempty"`
}
// TODO: remove this.. we're not going to include username here anymore, the client will have to do it.
type TxnLogUser struct {
Username string `json:"username"`
}
type TxnLogTransfer struct {
TransferType TransferType `json:"transferType"`
ContractAddress string `json:"contractAddress"`
From string `json:"from"`
To string `json:"to"`
Ids []prototyp.BigInt `json:"ids"`
Amounts []prototyp.BigInt `json:"amounts"`
}
type SentTransactionsFilter struct {
Pending *bool `json:"pending"`
Failed *bool `json:"failed"`
}
type SimulateResult struct {
Executed bool `json:"executed"`
Succeeded bool `json:"succeeded"`
Result *string `json:"result"`
Reason *string `json:"reason"`
GasUsed uint `json:"gasUsed"`
GasLimit uint `json:"gasLimit"`
}
type FeeOption struct {
Token *FeeToken `json:"token"`
To string `json:"to"`
Value string `json:"value"`
GasLimit uint `json:"gasLimit"`
}
type FeeToken struct {
ChainId uint64 `json:"chainId"`
Name string `json:"name"`
Symbol string `json:"symbol"`
Type FeeTokenType `json:"type"`
Decimals *uint32 `json:"decimals"`
LogoURL string `json:"logoURL"`
ContractAddress *string `json:"contractAddress"`
TokenID *string `json:"tokenID"`
}
// Page represents a results page. This can be used both to request a page and
// to store the state of a page.
type Page struct {
// Common for both numbered pages and cursor: Number of items per page
PageSize *uint32 `json:"pageSize"`
// Numbered pages: Page number, this is multiplied by the value of the <pageSize> parameter.
Page *uint32 `json:"page"`
More *bool `json:"more"`
// Number of total items on this query.
TotalRecords *uint64 `json:"totalRecords"`
// Cursor: column to compare before/after to
Column *string `json:"column"`
// Cursor: return column < before - include to get previous page
Before *interface{} `json:"before"`
// Cursor: return column > after - include to get next page
After *interface{} `json:"after"`
// Sorting filter
Sort []*SortBy `json:"sort"`
}
type SortBy struct {
Column string `json:"column"`
Order SortOrder `json:"order"`
}
var WebRPCServices = map[string][]string{
"Relayer": {
"Ping",
"Version",
"RuntimeStatus",
"GetSequenceContext",
"GetChainID",
"SendMetaTxn",
"GetMetaTxnNonce",
"GetMetaTxnReceipt",
"Simulate",
"UpdateMetaTxnGasLimits",
"FeeTokens",
"FeeOptions",
"GetMetaTxnNetworkFeeOptions",
"GetMetaTransactions",
"SentTransactions",
"PendingTransactions",
"GetGasTank",
"AddGasTank",
"UpdateGasTank",
"GetGasSponsor",
"AddressGasSponsors",
"ListGasSponsors",
"AddGasSponsor",
"UpdateGasSponsor",
"RemoveGasSponsor",
"ReportGasSponsorUsage",
"NextGasTankBalanceAdjustmentNonce",
"AdjustGasTankBalance",
"GetGasTankBalanceAdjustment",
"ListGasTankBalanceAdjustments",
},
}
//
// Server types
//
type Relayer interface {
Ping(ctx context.Context) (bool, error)
Version(ctx context.Context) (*Version, error)
RuntimeStatus(ctx context.Context) (*RuntimeStatus, error)
GetSequenceContext(ctx context.Context) (*SequenceContext, error)
// TODO: return a string instead
GetChainID(ctx context.Context) (uint64, error)
//
// Transactions
//
// TODO (future): rename this to just, 'SendTransaction(txn: MetaTransaction)' or 'SendTransaction(txn: SignedTransaction)', or something..
// TODO: rename return txnHash: string to metaTxnID: string
SendMetaTxn(ctx context.Context, call *MetaTxn, quote *string) (bool, string, error)
GetMetaTxnNonce(ctx context.Context, walletContractAddress string, space *string) (string, error)
// TODO: one day, make GetMetaTxnReceipt respond immediately with receipt or not
// and add WaitTransactionReceipt method, which will block and wait, similar to how GetMetaTxnReceipt
// is implemented now.
// For backwards compat, we can leave the current GetMetaTxnReceipt how it is, an deprecate it, and introduce
// new, GetTransactionReceipt and WaitTransactionReceipt methods
// we can also accept metaTxnId and txnHash .. so can take either or.. I wonder if ERC-4337 has any convention on this?
GetMetaTxnReceipt(ctx context.Context, metaTxID string) (*MetaTxnReceipt, error)
Simulate(ctx context.Context, wallet string, transactions string) ([]*SimulateResult, error)
// TODO: deprecated, to be removed by https://github.com/0xsequence/stack/pull/356 at a later date
UpdateMetaTxnGasLimits(ctx context.Context, walletAddress string, walletConfig interface{}, payload string) (string, error)
FeeTokens(ctx context.Context) (bool, []*FeeToken, error)
FeeOptions(ctx context.Context, wallet string, to string, data string, simulate *bool) ([]*FeeOption, bool, *string, error)
// TODO: deprecated, to be removed by https://github.com/0xsequence/stack/pull/356 at a later date
GetMetaTxnNetworkFeeOptions(ctx context.Context, walletConfig interface{}, payload string) ([]*FeeOption, error)
GetMetaTransactions(ctx context.Context, projectId uint64, gasTankId uint64, page *Page) (*Page, []*MetaTxnLog, error)
// Sent transactions from an account. If filter is omitted then it will return all transactions.
SentTransactions(ctx context.Context, filter *SentTransactionsFilter, page *Page) (*Page, []*Transaction, error)
// Pending transactions waiting to be mined for an account. This endpoint is just a sugar of `SentTransactions`
// with the filter set to pending: true.
PendingTransactions(ctx context.Context, page *Page) (*Page, []*Transaction, error)
GetGasTank(ctx context.Context, id uint64) (*GasTank, error)
AddGasTank(ctx context.Context, name string, feeMarkupFactor float64, unlimited *bool) (bool, *GasTank, error)
UpdateGasTank(ctx context.Context, id uint64, name *string, feeMarkupFactor *float64, unlimited *bool) (bool, *GasTank, error)
GetGasSponsor(ctx context.Context, id uint64) (*GasSponsor, error)
AddressGasSponsors(ctx context.Context, address string, page *Page) (*Page, []*GasSponsor, error)
ListGasSponsors(ctx context.Context, projectId uint64, gasTankId uint64, page *Page) (*Page, []*GasSponsor, error)
AddGasSponsor(ctx context.Context, projectId uint64, gasTankId uint64, address string, name *string, active *bool) (bool, *GasSponsor, error)
UpdateGasSponsor(ctx context.Context, id uint64, name *string, active *bool) (bool, *GasSponsor, error)
RemoveGasSponsor(ctx context.Context, id uint64) (bool, error)
ReportGasSponsorUsage(ctx context.Context, projectId uint64, gasTankId uint64, startTime *time.Time, endTime *time.Time) ([]*GasSponsorUsage, error)
NextGasTankBalanceAdjustmentNonce(ctx context.Context, id uint64) (uint64, error)
AdjustGasTankBalance(ctx context.Context, id uint64, nonce uint64, amount float64) (bool, *GasTankBalanceAdjustment, error)
GetGasTankBalanceAdjustment(ctx context.Context, id uint64, nonce uint64) (*GasTankBalanceAdjustment, error)
ListGasTankBalanceAdjustments(ctx context.Context, id uint64, page *Page) (*Page, []*GasTankBalanceAdjustment, error)
}
//
// Client types
//
type RelayerClient interface {
Ping(ctx context.Context) (bool, error)
Version(ctx context.Context) (*Version, error)
RuntimeStatus(ctx context.Context) (*RuntimeStatus, error)
GetSequenceContext(ctx context.Context) (*SequenceContext, error)
// TODO: return a string instead
GetChainID(ctx context.Context) (uint64, error)
//
// Transactions
//
// TODO (future): rename this to just, 'SendTransaction(txn: MetaTransaction)' or 'SendTransaction(txn: SignedTransaction)', or something..
// TODO: rename return txnHash: string to metaTxnID: string
SendMetaTxn(ctx context.Context, call *MetaTxn, quote *string) (bool, string, error)
GetMetaTxnNonce(ctx context.Context, walletContractAddress string, space *string) (string, error)
// TODO: one day, make GetMetaTxnReceipt respond immediately with receipt or not
// and add WaitTransactionReceipt method, which will block and wait, similar to how GetMetaTxnReceipt
// is implemented now.
// For backwards compat, we can leave the current GetMetaTxnReceipt how it is, an deprecate it, and introduce
// new, GetTransactionReceipt and WaitTransactionReceipt methods
// we can also accept metaTxnId and txnHash .. so can take either or.. I wonder if ERC-4337 has any convention on this?
GetMetaTxnReceipt(ctx context.Context, metaTxID string) (*MetaTxnReceipt, error)
Simulate(ctx context.Context, wallet string, transactions string) ([]*SimulateResult, error)
// TODO: deprecated, to be removed by https://github.com/0xsequence/stack/pull/356 at a later date
UpdateMetaTxnGasLimits(ctx context.Context, walletAddress string, walletConfig interface{}, payload string) (string, error)
FeeTokens(ctx context.Context) (bool, []*FeeToken, error)
FeeOptions(ctx context.Context, wallet string, to string, data string, simulate *bool) ([]*FeeOption, bool, *string, error)
// TODO: deprecated, to be removed by https://github.com/0xsequence/stack/pull/356 at a later date
GetMetaTxnNetworkFeeOptions(ctx context.Context, walletConfig interface{}, payload string) ([]*FeeOption, error)
GetMetaTransactions(ctx context.Context, projectId uint64, gasTankId uint64, page *Page) (*Page, []*MetaTxnLog, error)
// Sent transactions from an account. If filter is omitted then it will return all transactions.
SentTransactions(ctx context.Context, filter *SentTransactionsFilter, page *Page) (*Page, []*Transaction, error)
// Pending transactions waiting to be mined for an account. This endpoint is just a sugar of `SentTransactions`
// with the filter set to pending: true.
PendingTransactions(ctx context.Context, page *Page) (*Page, []*Transaction, error)
GetGasTank(ctx context.Context, id uint64) (*GasTank, error)
AddGasTank(ctx context.Context, name string, feeMarkupFactor float64, unlimited *bool) (bool, *GasTank, error)
UpdateGasTank(ctx context.Context, id uint64, name *string, feeMarkupFactor *float64, unlimited *bool) (bool, *GasTank, error)
GetGasSponsor(ctx context.Context, id uint64) (*GasSponsor, error)
AddressGasSponsors(ctx context.Context, address string, page *Page) (*Page, []*GasSponsor, error)
ListGasSponsors(ctx context.Context, projectId uint64, gasTankId uint64, page *Page) (*Page, []*GasSponsor, error)
AddGasSponsor(ctx context.Context, projectId uint64, gasTankId uint64, address string, name *string, active *bool) (bool, *GasSponsor, error)
UpdateGasSponsor(ctx context.Context, id uint64, name *string, active *bool) (bool, *GasSponsor, error)
RemoveGasSponsor(ctx context.Context, id uint64) (bool, error)
ReportGasSponsorUsage(ctx context.Context, projectId uint64, gasTankId uint64, startTime *time.Time, endTime *time.Time) ([]*GasSponsorUsage, error)
NextGasTankBalanceAdjustmentNonce(ctx context.Context, id uint64) (uint64, error)
AdjustGasTankBalance(ctx context.Context, id uint64, nonce uint64, amount float64) (bool, *GasTankBalanceAdjustment, error)
GetGasTankBalanceAdjustment(ctx context.Context, id uint64, nonce uint64) (*GasTankBalanceAdjustment, error)
ListGasTankBalanceAdjustments(ctx context.Context, id uint64, page *Page) (*Page, []*GasTankBalanceAdjustment, error)
}
//
// Client
//
const RelayerPathPrefix = "/rpc/Relayer/"
type relayerClient struct {
client HTTPClient
urls [30]string
}
func NewRelayerClient(addr string, client HTTPClient) RelayerClient {
prefix := urlBase(addr) + RelayerPathPrefix
urls := [30]string{
prefix + "Ping",
prefix + "Version",
prefix + "RuntimeStatus",
prefix + "GetSequenceContext",
prefix + "GetChainID",
prefix + "SendMetaTxn",
prefix + "GetMetaTxnNonce",
prefix + "GetMetaTxnReceipt",
prefix + "Simulate",
prefix + "UpdateMetaTxnGasLimits",
prefix + "FeeTokens",
prefix + "FeeOptions",
prefix + "GetMetaTxnNetworkFeeOptions",
prefix + "GetMetaTransactions",
prefix + "SentTransactions",
prefix + "PendingTransactions",
prefix + "GetGasTank",
prefix + "AddGasTank",
prefix + "UpdateGasTank",
prefix + "GetGasSponsor",
prefix + "AddressGasSponsors",
prefix + "ListGasSponsors",
prefix + "AddGasSponsor",
prefix + "UpdateGasSponsor",
prefix + "RemoveGasSponsor",
prefix + "ReportGasSponsorUsage",
prefix + "NextGasTankBalanceAdjustmentNonce",
prefix + "AdjustGasTankBalance",
prefix + "GetGasTankBalanceAdjustment",
prefix + "ListGasTankBalanceAdjustments",
}
return &relayerClient{
client: client,
urls: urls,
}
}
func (c *relayerClient) Ping(ctx context.Context) (bool, error) {
out := struct {
Ret0 bool `json:"status"`
}{}
resp, err := doHTTPRequest(ctx, c.client, c.urls[0], nil, &out)
if resp != nil {
cerr := resp.Body.Close()
if err == nil && cerr != nil {
err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr))
}
}
return out.Ret0, err
}
func (c *relayerClient) Version(ctx context.Context) (*Version, error) {
out := struct {
Ret0 *Version `json:"version"`
}{}
resp, err := doHTTPRequest(ctx, c.client, c.urls[1], nil, &out)
if resp != nil {
cerr := resp.Body.Close()
if err == nil && cerr != nil {
err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr))
}
}
return out.Ret0, err
}
func (c *relayerClient) RuntimeStatus(ctx context.Context) (*RuntimeStatus, error) {
out := struct {
Ret0 *RuntimeStatus `json:"status"`
}{}
resp, err := doHTTPRequest(ctx, c.client, c.urls[2], nil, &out)
if resp != nil {
cerr := resp.Body.Close()
if err == nil && cerr != nil {
err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr))
}
}
return out.Ret0, err
}
func (c *relayerClient) GetSequenceContext(ctx context.Context) (*SequenceContext, error) {
out := struct {
Ret0 *SequenceContext `json:"data"`
}{}
resp, err := doHTTPRequest(ctx, c.client, c.urls[3], nil, &out)
if resp != nil {
cerr := resp.Body.Close()
if err == nil && cerr != nil {
err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr))
}
}
return out.Ret0, err
}
func (c *relayerClient) GetChainID(ctx context.Context) (uint64, error) {
out := struct {
Ret0 uint64 `json:"chainID"`
}{}
resp, err := doHTTPRequest(ctx, c.client, c.urls[4], nil, &out)
if resp != nil {
cerr := resp.Body.Close()
if err == nil && cerr != nil {
err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr))
}
}
return out.Ret0, err
}
func (c *relayerClient) SendMetaTxn(ctx context.Context, call *MetaTxn, quote *string) (bool, string, error) {
in := struct {
Arg0 *MetaTxn `json:"call"`
Arg1 *string `json:"quote"`
}{call, quote}
out := struct {
Ret0 bool `json:"status"`
Ret1 string `json:"txnHash"`
}{}
resp, err := doHTTPRequest(ctx, c.client, c.urls[5], in, &out)
if resp != nil {
cerr := resp.Body.Close()
if err == nil && cerr != nil {
err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr))
}
}
return out.Ret0, out.Ret1, err
}
func (c *relayerClient) GetMetaTxnNonce(ctx context.Context, walletContractAddress string, space *string) (string, error) {
in := struct {
Arg0 string `json:"walletContractAddress"`
Arg1 *string `json:"space"`
}{walletContractAddress, space}
out := struct {
Ret0 string `json:"nonce"`
}{}
resp, err := doHTTPRequest(ctx, c.client, c.urls[6], in, &out)
if resp != nil {
cerr := resp.Body.Close()
if err == nil && cerr != nil {
err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr))
}
}
return out.Ret0, err
}
func (c *relayerClient) GetMetaTxnReceipt(ctx context.Context, metaTxID string) (*MetaTxnReceipt, error) {
in := struct {
Arg0 string `json:"metaTxID"`
}{metaTxID}
out := struct {
Ret0 *MetaTxnReceipt `json:"receipt"`
}{}
resp, err := doHTTPRequest(ctx, c.client, c.urls[7], in, &out)
if resp != nil {
cerr := resp.Body.Close()
if err == nil && cerr != nil {
err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr))
}
}
return out.Ret0, err
}
func (c *relayerClient) Simulate(ctx context.Context, wallet string, transactions string) ([]*SimulateResult, error) {
in := struct {
Arg0 string `json:"wallet"`
Arg1 string `json:"transactions"`
}{wallet, transactions}
out := struct {
Ret0 []*SimulateResult `json:"results"`
}{}
resp, err := doHTTPRequest(ctx, c.client, c.urls[8], in, &out)
if resp != nil {
cerr := resp.Body.Close()
if err == nil && cerr != nil {
err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr))
}
}
return out.Ret0, err
}
func (c *relayerClient) UpdateMetaTxnGasLimits(ctx context.Context, walletAddress string, walletConfig interface{}, payload string) (string, error) {
in := struct {
Arg0 string `json:"walletAddress"`
Arg1 interface{} `json:"walletConfig"`
Arg2 string `json:"payload"`
}{walletAddress, walletConfig, payload}
out := struct {
Ret0 string `json:"payload"`
}{}
resp, err := doHTTPRequest(ctx, c.client, c.urls[9], in, &out)
if resp != nil {
cerr := resp.Body.Close()
if err == nil && cerr != nil {
err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr))
}
}
return out.Ret0, err
}
func (c *relayerClient) FeeTokens(ctx context.Context) (bool, []*FeeToken, error) {
out := struct {
Ret0 bool `json:"isFeeRequired"`
Ret1 []*FeeToken `json:"tokens"`
}{}
resp, err := doHTTPRequest(ctx, c.client, c.urls[10], nil, &out)
if resp != nil {
cerr := resp.Body.Close()
if err == nil && cerr != nil {
err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr))
}
}
return out.Ret0, out.Ret1, err
}
func (c *relayerClient) FeeOptions(ctx context.Context, wallet string, to string, data string, simulate *bool) ([]*FeeOption, bool, *string, error) {
in := struct {
Arg0 string `json:"wallet"`
Arg1 string `json:"to"`
Arg2 string `json:"data"`
Arg3 *bool `json:"simulate"`
}{wallet, to, data, simulate}
out := struct {
Ret0 []*FeeOption `json:"options"`
Ret1 bool `json:"sponsored"`
Ret2 *string `json:"quote"`
}{}
resp, err := doHTTPRequest(ctx, c.client, c.urls[11], in, &out)
if resp != nil {
cerr := resp.Body.Close()
if err == nil && cerr != nil {
err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr))
}
}
return out.Ret0, out.Ret1, out.Ret2, err
}
func (c *relayerClient) GetMetaTxnNetworkFeeOptions(ctx context.Context, walletConfig interface{}, payload string) ([]*FeeOption, error) {
in := struct {
Arg0 interface{} `json:"walletConfig"`
Arg1 string `json:"payload"`
}{walletConfig, payload}
out := struct {
Ret0 []*FeeOption `json:"options"`
}{}
resp, err := doHTTPRequest(ctx, c.client, c.urls[12], in, &out)
if resp != nil {
cerr := resp.Body.Close()
if err == nil && cerr != nil {
err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr))
}
}
return out.Ret0, err
}
func (c *relayerClient) GetMetaTransactions(ctx context.Context, projectId uint64, gasTankId uint64, page *Page) (*Page, []*MetaTxnLog, error) {
in := struct {
Arg0 uint64 `json:"projectId"`
Arg1 uint64 `json:"gasTankId"`
Arg2 *Page `json:"page"`
}{projectId, gasTankId, page}
out := struct {
Ret0 *Page `json:"page"`
Ret1 []*MetaTxnLog `json:"transactions"`
}{}
resp, err := doHTTPRequest(ctx, c.client, c.urls[13], in, &out)
if resp != nil {
cerr := resp.Body.Close()
if err == nil && cerr != nil {
err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr))
}
}
return out.Ret0, out.Ret1, err
}
func (c *relayerClient) SentTransactions(ctx context.Context, filter *SentTransactionsFilter, page *Page) (*Page, []*Transaction, error) {
in := struct {
Arg0 *SentTransactionsFilter `json:"filter"`
Arg1 *Page `json:"page"`
}{filter, page}
out := struct {
Ret0 *Page `json:"page"`
Ret1 []*Transaction `json:"transactions"`
}{}
resp, err := doHTTPRequest(ctx, c.client, c.urls[14], in, &out)
if resp != nil {
cerr := resp.Body.Close()
if err == nil && cerr != nil {
err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr))
}
}
return out.Ret0, out.Ret1, err
}
func (c *relayerClient) PendingTransactions(ctx context.Context, page *Page) (*Page, []*Transaction, error) {
in := struct {
Arg0 *Page `json:"page"`
}{page}
out := struct {
Ret0 *Page `json:"page"`
Ret1 []*Transaction `json:"transactions"`
}{}
resp, err := doHTTPRequest(ctx, c.client, c.urls[15], in, &out)
if resp != nil {
cerr := resp.Body.Close()
if err == nil && cerr != nil {
err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr))
}
}
return out.Ret0, out.Ret1, err
}
func (c *relayerClient) GetGasTank(ctx context.Context, id uint64) (*GasTank, error) {
in := struct {
Arg0 uint64 `json:"id"`
}{id}
out := struct {
Ret0 *GasTank `json:"gasTank"`