-
Notifications
You must be signed in to change notification settings - Fork 1
/
transaction_service.proto
1442 lines (1203 loc) · 54.9 KB
/
transaction_service.proto
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
syntax = "proto3";
package code.transaction.v2;
option go_package = "github.com/code-payments/code-protobuf-api/generated/go/transaction/v2;transaction";
option java_package = "com.codeinc.gen.transaction.v2";
option objc_class_prefix = "APBTransactionV2";
import "common/v1/model.proto";
import "google/protobuf/timestamp.proto";
import "validate/validate.proto";
service Transaction {
// SubmitIntent is the mechanism for client and server to agree upon a set of
// client actions to execute on the blockchain using the Code sequencer for
// fulfillment.
//
// Transactions are never exchanged between client and server. Instead, the
// required accounts and arguments for instructions known to each actor are
// exchanged to allow independent and local transaction construction.
//
// Client and server are expected to fully validate the intent. Proofs will
// be provided for any parameter requiring one. Signatures should only be
// generated after approval of all transactions.
//
// This RPC is not a traditional streaming endpoint. It bundles two unary calls
// to enable DB-level transaction semantics.
//
// The high-level happy path flow for the RPC is as follows:
// 1. Client initiates a stream and sends SubmitIntentRequest.SubmitActions
// 2. Server validates the intent, its actions and metadata
// 3a. If there are transactions requiring the user's signature, then server
// returns SubmitIntentResponse.ServerParameters
// 3b. Otherwise, server returns SubmitIntentResponse.Success and closes the
// stream
// 4. For each transaction requiring the user's signature, the client locally
// constructs it, performs validation and collects the signature
// 5. Client sends SubmitIntentRequest.SubmitSignatures with the signature
// list generated from 4
// 6. Server validates all signatures are submitted and are the expected values
// using locally constructed transactions.
// 7. Server returns SubmitIntentResponse.Success and closes the stream
// In the error case:
// * Server will return SubmitIntentResponse.Error and close the stream
// * Client will close the stream
rpc SubmitIntent(stream SubmitIntentRequest) returns (stream SubmitIntentResponse);
// GetIntentMetadata gets basic metadata on an intent. It can also be used
// to fetch the status of submitted intents. Metadata exists only for intents
// that have been successfully submitted.
rpc GetIntentMetadata(GetIntentMetadataRequest) returns (GetIntentMetadataResponse);
// GetPrivacyUpgradeStatus gets the status of a private transaction and the
// ability to upgrade it to permanent privacy.
rpc GetPrivacyUpgradeStatus(GetPrivacyUpgradeStatusRequest) returns (GetPrivacyUpgradeStatusResponse);
// GetPrioritizedIntentsForPrivacyUpgrade allows clients to get private
// intent actions that can be upgraded in a secure and verifiable manner.
rpc GetPrioritizedIntentsForPrivacyUpgrade(GetPrioritizedIntentsForPrivacyUpgradeRequest) returns (GetPrioritizedIntentsForPrivacyUpgradeResponse);
// GetLimits gets limits for money moving intents for an owner account in an
// identity-aware manner
rpc GetLimits(GetLimitsRequest) returns (GetLimitsResponse);
// GetPaymentHistory gets an owner account's payment history inferred from intents
//
// Deprecated: Payment history has migrated to chats
rpc GetPaymentHistory(GetPaymentHistoryRequest) returns (GetPaymentHistoryResponse);
// CanWithdrawToAccount provides hints to clients for submitting withdraw intents.
// The RPC indicates if a withdrawal is possible, and how it should be performed.
rpc CanWithdrawToAccount(CanWithdrawToAccountRequest) returns (CanWithdrawToAccountResponse);
// Airdrop airdrops Kin to the requesting account
rpc Airdrop(AirdropRequest) returns (AirdropResponse);
// Swap performs an on-chain swap. The high-level flow mirrors SubmitIntent
// closely. However, due to the time-sensitive nature and unreliability of
// swaps, they do not fit within the broader intent system. This results in
// a few key differences:
// * Transactions are submitted on a best-effort basis outside of the Code
// Sequencer within the RPC handler
// * Balance changes are applied after the transaction has finalized
// * Transactions use recent blockhashes over a nonce
//
// The transaction will have the following instruction format:
// 1. ComputeBudget::SetComputeUnitLimit
// 2. ComputeBudget::SetComputeUnitPrice
// 3. SwapValidator::PreSwap
// 4. Dynamic swap instruction
// 5. SwapValidator::PostSwap
//
// Note: Currently limited to swapping USDC to Kin.
// Note: Kin is deposited into the primary account.
rpc Swap(stream SwapRequest) returns (stream SwapResponse);
// DeclareFiatOnrampPurchaseAttempt is called whenever a user attempts to use a fiat
// onramp to purchase crypto for use in Code.
rpc DeclareFiatOnrampPurchaseAttempt(DeclareFiatOnrampPurchaseAttemptRequest) returns (DeclareFiatOnrampPurchaseAttemptResponse);
}
//
// Request and Response Definitions
//
message SubmitIntentRequest {
oneof request {
option (validate.required) = true;
SubmitActions submit_actions = 1;
SubmitSignatures submit_signatures = 2;
}
message SubmitActions {
// The globally unique client generated intent ID. Use the original intent
// ID when operating on actions that mutate the intent.
common.v1.IntentId id = 1 [(validate.rules).message.required = true];
// The verified owner account public key
common.v1.SolanaAccountId owner = 2 [(validate.rules).message.required = true];
// Additional metadata that describes the high-level intention
Metadata metadata = 3 [(validate.rules).message.required = true];
// The set of all ordered actions required to fulfill the intent
repeated Action actions = 4 [(validate.rules).repeated = {
min_items: 1
max_items: 256 // Arbitrary
}];
// The signature is of serialize(SubmitActions) without this field set using the
// private key of the owner account. This provides an authentication mechanism
// to the RPC.
common.v1.Signature signature = 5 [(validate.rules).message.required = true];
// Device token for antispam measures against fake devices
common.v1.DeviceToken device_token = 6;
}
message SubmitSignatures {
// The set of all signatures for each transaction requiring signature from the
// authority accounts.
repeated common.v1.Signature signatures = 1 [(validate.rules).repeated = {
min_items: 1
max_items: 256 // Assumes at most 1 client signatures per action
}];
}
}
message SubmitIntentResponse {
oneof response {
option (validate.required) = true;
ServerParameters server_parameters = 1;
Success success = 2;
Error error = 3;
}
message ServerParameters {
// The set of all server paremeters required to fill missing transaction
// details. Server guarantees to provide a message for each client action
// in an order consistent with the received action list.
repeated ServerParameter server_parameters = 1 [(validate.rules).repeated = {
min_items: 1
max_items: 256 // Arbitrary, but must match SubmitActions.actions.max_items
}];
}
message Success {
Code code = 1;
enum Code {
// The intent was successfully created and is now scheduled.
OK = 0;
}
// todo: Revisit if we need side-effects. Clients are effecitively doing
// local simulation now with the privacy solution.
}
message Error {
Code code = 1;
enum Code {
// Denied by a guard (spam, money laundering, etc)
DENIED = 0;
// The intent is invalid.
INVALID_INTENT = 1;
// There is an issue with provided signatures.
SIGNATURE_ERROR = 2;
// Server detected client has stale state.
STALE_STATE = 3;
}
repeated ErrorDetails error_details = 2;
}
}
message GetIntentMetadataRequest {
// The intent ID to query
common.v1.IntentId intent_id = 1 [(validate.rules).message.required = true];
// The verified owner account public key when not signing with the rendezvous
// key. Only owner accounts involved in the intent can access the metadata.
common.v1.SolanaAccountId owner = 2;
// The signature is of serialize(GetIntentStatusRequest) without this field set
// using the private key of the rendezvous or owner account. This provides an
// authentication mechanism to the RPC.
common.v1.Signature signature = 3 [(validate.rules).message.required = true];
}
message GetIntentMetadataResponse {
Result result = 1;
enum Result {
OK = 0;
NOT_FOUND = 1;
}
Metadata metadata = 2;
}
message GetPrivacyUpgradeStatusRequest {
// The intent ID
common.v1.IntentId intent_id = 1 [(validate.rules).message.required = true];
// The action ID for private transaction
uint32 action_id = 2;
}
message GetPrivacyUpgradeStatusResponse {
Result result = 1;
enum Result {
OK = 0;
// The provided intent ID doesn't exist
INTENT_NOT_FOUND = 1;
// The provided action ID doesn't exist
ACTION_NOT_FOUND = 2;
// The provided action doesn't map to a private transaction
INVALID_ACTION = 3;
}
Status status = 2;
enum Status {
UNKNOWN = 0;
// The transaction for the temporary private transaction was submitted and
// finalized. The opportunity to upgrade was missed.
TEMPORARY_TRANSACTION_FINALIZED = 1;
// The next block of transactions hasn't been created. Wait and try again
// later.
WAITING_FOR_NEXT_BLOCK = 2;
// The transaction can be upgraded to permanent privacy
READY_FOR_UPGRADE = 3;
// The transaction has already been upgraded
ALREADY_UPGRADED = 4;
}
}
message GetPrioritizedIntentsForPrivacyUpgradeRequest {
// The owner account to query against for upgradeable intents.
common.v1.SolanaAccountId owner = 1 [(validate.rules).message.required = true];
// The maximum number of intents to return in the response. Default is 10.
uint32 limit = 2 [(validate.rules).uint32.lte = 100];
// The signature is of serialize(GetPrioritizedIntentsForPrivacyUpgradeRequest)
// without this field set using the private key of the owner account. This
// provides an authentication mechanism to the RPC.
common.v1.Signature signature = 3 [(validate.rules).message.required = true];
}
message GetPrioritizedIntentsForPrivacyUpgradeResponse {
Result result = 1;
enum Result {
OK = 0;
NOT_FOUND = 1;
}
// Ordered from highest to lowest priority
repeated UpgradeableIntent items = 2 [(validate.rules).repeated = {
max_items: 100
}];
}
message GetLimitsRequest {
// The owner account whose limits will be calculated. Any other owner accounts
// linked with the same identity of the owner will also be applied.
common.v1.SolanaAccountId owner = 1 [(validate.rules).message.required = true];
// The signature is of serialize(GetLimitsRequest) without this field set
// using the private key of the owner account. This provides an authentication
// mechanism to the RPC.
common.v1.Signature signature = 2 [(validate.rules).message.required = true];
// All transactions starting at this time will be incorporated into the consumed
// limit calculation. Clients should set this to the start of the current day in
// the client's current time zone (because server has no knowledge of this atm).
google.protobuf.Timestamp consumed_since = 3 [(validate.rules).timestamp.required = true];
}
message GetLimitsResponse {
Result result = 1;
enum Result {
OK = 0;
}
// Send limits keyed by currency
map<string, SendLimit> send_limits_by_currency = 2;
// Deposit limits
DepositLimit deposit_limit = 3;
// Micro payment limits keyed by currency
map<string, MicroPaymentLimit> micro_payment_limits_by_currency = 4;
// Buy module limits keyed by currency
map<string, BuyModuleLimit> buy_module_limits_by_currency = 5;
}
message GetPaymentHistoryRequest {
// The owner account to get payment history for
common.v1.SolanaAccountId owner = 1 [(validate.rules).message.required = true];
// An optional history cursor indicating where in the history to resume from.
Cursor cursor = 2;
// The number of results to return per request. Default is 100.
uint32 page_size = 3 [(validate.rules).uint32.lte = 100];
// The order in which to return history items from the cursor.
Direction direction = 4;
enum Direction {
// ASC direction returns all history items in ascending order.
ASC = 0;
// DESC direction returns all history items in descending order.
DESC = 1;
}
// The signature is of serialize(GetPaymentHistoryRequest) without this field set
// using the private key of the owner account. This provides an authentication
// mechanism to the RPC.
common.v1.Signature signature = 5 [(validate.rules).message.required = true];
}
message GetPaymentHistoryResponse {
Result result = 1;
enum Result {
OK = 0;
NOT_FOUND = 1;
}
repeated PaymentHistoryItem items = 2 [(validate.rules).repeated = {
max_items: 100
}];
}
message CanWithdrawToAccountRequest {
common.v1.SolanaAccountId account = 1 [(validate.rules).message.required = true];
}
message CanWithdrawToAccountResponse {
// Metadata so the client knows how to withdraw to the account. Server cannot
// provide precalculated addresses in this response to maintain non-custodial
// status.
AccountType account_type = 2;
enum AccountType {
Unknown = 0; // Server cannot determine
TokenAccount = 1; // Client uses the address as is in SubmitIntent
OwnerAccount = 2; // Client locally derives the ATA to use in SubmitIntent
}
// Server-controlled flag to indicate if the account can be withdrawn to.
// There are several reasons server may deny it, including:
// - Wrong type of Code account
// - Not wanting to subsidize the creation of an ATA
// - Unsupported external account type (eg. token account but of the wrong mint)
// This is guaranteed to be false when account_type = Unknown.
bool is_valid_payment_destination = 1;
// Token account requires initialization before the withdrawal can occur.
// Server has chosen not to subsidize the fees. The response is guaranteed
// to have set is_valid_payment_destination = false in this case.
bool requires_initialization = 3;
}
message AirdropRequest {
// The type of airdrop to claim
AirdropType airdrop_type = 1 [(validate.rules).enum = {
not_in: [0, 1] // UNKNOWN, GIVE_FIRST_KIN
}];
// The owner account to airdrop Kin to
common.v1.SolanaAccountId owner = 2 [(validate.rules).message.required = true];
// The signature is of serialize(AirdropRequest) without this field set
// using the private key of the owner account. This provides an authentication
// mechanism to the RPC.
common.v1.Signature signature = 3 [(validate.rules).message.required = true];
}
message AirdropResponse {
Result result = 1;
enum Result {
OK = 0;
// Airdrops are unavailable
UNAVAILABLE = 1;
// The airdrop has already been claimed by the owner
ALREADY_CLAIMED = 2;
}
// Exchange data for the amount of Kin airdropped when successful
ExchangeData exchange_data = 2;
}
message SwapRequest {
oneof request {
option (validate.required) = true;
Initiate initiate = 1;
SubmitSignature submit_signature = 2;
}
message Initiate {
// The verified owner account public key
common.v1.SolanaAccountId owner = 1 [(validate.rules).message.required = true];
// The user authority account that will sign to authorize the swap. Ideally,
// this is an account derived off the owner account that is solely responsible
// for swapping.
common.v1.SolanaAccountId swap_authority = 2 [(validate.rules).message.required = true];
// Maximum amount to swap from the source mint, in quarks. If value is set to zero,
// the entire amount will be swapped.
uint64 limit = 3;
// Whether the client wants the RPC to wait for blockchain status. If false,
// then the RPC will return Success when the swap is submitted to the blockchain.
// Otherwise, the RPC will observe and report back the status of the transaction.
bool wait_for_blockchain_status = 4;
// The signature is of serialize(Initiate) without this field set using the
// private key of the owner account. This provides an authentication mechanism
// to the RPC.
common.v1.Signature signature = 5 [(validate.rules).message.required = true];
}
message SubmitSignature {
// The signature for the locally constructed swap transaction
common.v1.Signature signature = 1 [(validate.rules).message.required = true];
}
}
message SwapResponse {
oneof response {
option (validate.required) = true;
ServerParameters server_parameters = 1;
Success success = 2;
Error error = 3;
}
message ServerParameters {
// Subisdizer account that will be paying for the swap
common.v1.SolanaAccountId payer = 1 [(validate.rules).message.required = true];
// Recent blockhash
common.v1.Blockhash recent_blockhash = 2 [(validate.rules).message.required = true];
// Compute unit limit provided to the ComputeBudget::SetComputeUnitLimit
// instruction. If the value is 0, then the instruction can be omitted.
uint32 compute_unit_limit = 3;
// Compute unit price provided in the ComputeBudget::SetComputeUnitPrice
// instruction. If the value is 0, then the instruction can be omitted.
uint64 compute_unit_price = 4;
// On-chain program that will be performing the swap
common.v1.SolanaAccountId swap_program = 5 [(validate.rules).message.required = true];
// Accounts provided to the swap instruction
repeated common.v1.InstructionAccount swap_ixn_accounts = 6 [(validate.rules).repeated = {
min_items: 1
max_items: 64
}];
// Instruction data for the swap instruction
bytes swap_ixn_data = 7 [(validate.rules).bytes = {
min_len: 1
max_len: 256 // Arbitrary
}];
// Maximum quarks that will be sent out of the source account after
// executing the swap. If not, the validation instruction will cause
// the transaction to fail.
uint64 max_to_send = 8 [(validate.rules).uint64.gt = 0];
// Minimum quarks that will be received into the destination account
// after executing the swap. If not, the validation instruction will
// cause the transaction to fail.
uint64 min_to_receive = 9 [(validate.rules).uint64.gt = 0];
// Nonce to use in swap validator state account PDA
common.v1.SolanaAccountId nonce = 10 [(validate.rules).message.required = true];
}
message Success {
Code code = 1;
enum Code {
// The swap was submitted to the blockchain.
SWAP_SUBMITTED = 0;
// The swap was finalized on the blockchain.
SWAP_FINALIZED = 1;
}
}
message Error {
Code code = 1;
enum Code {
// Denied by a guard (spam, money laundering, etc)
DENIED = 0;
// There is an issue with the provided signature.
SIGNATURE_ERROR = 2;
// The swap failed server-side validation
INVALID_SWAP = 3;
// The submitted swap transaction failed. Attempt the swap again.
SWAP_FAILED = 4;
}
repeated ErrorDetails error_details = 2;
}
}
message DeclareFiatOnrampPurchaseAttemptRequest {
// The owner account invoking the buy module
common.v1.SolanaAccountId owner = 1 [(validate.rules).message.required = true];
// The amount being purchased
ExchangeDataWithoutRate purchase_amount = 2 [(validate.rules).message.required = true];
// A nonce value unique to the purchase. If it's included in a memo for the
// transaction for the deposit to the owner, then purchase_amount will be used
// for display values. Otherwise, the amount will be inferred from the transaction.
common.v1.UUID nonce = 3 [(validate.rules).message.required = true];
// The signature is of serialize(DeclareFiatOnrampPurchaseAttemptRequest) without
// this field set using the private key of the owner account. This provides an
// authentication mechanism to the RPC.
common.v1.Signature signature = 4 [(validate.rules).message.required = true];
}
message DeclareFiatOnrampPurchaseAttemptResponse {
Result result = 1;
enum Result {
OK = 0;
// The owner account is not valid (ie. it isn't a Code account)
INVALID_OWNER = 1;
// The currency isn't supported
UNSUPPORTED_CURRENCY = 2;
// The amount specified exceeds limits
AMOUNT_EXCEEDS_MAXIMUM = 3;
}
}
//
// Metadata definitions
//
// Metadata describes the high-level details of an intent
message Metadata {
oneof type {
option (validate.required) = true;
OpenAccountsMetadata open_accounts = 1;
SendPrivatePaymentMetadata send_private_payment = 2;
ReceivePaymentsPrivatelyMetadata receive_payments_privately = 3;
UpgradePrivacyMetadata upgrade_privacy = 4;
MigrateToPrivacy2022Metadata migrate_to_privacy_2022 = 5;
SendPublicPaymentMetadata send_public_payment = 6;
ReceivePaymentsPubliclyMetadata receive_payments_publicly = 7;
EstablishRelationshipMetadata establish_relationship = 8;
}
}
// Open a set of accounts. Currently, clients should only use this for new users
// to open all required accounts up front (buckets, incoming, and outgoing).
//
// Action Spec:
//
// actions = [OpenAccountAction(PRIMARY)]
// for account in [TEMPORARY_INCOMING, TEMPORARY_OUTGOING, BUCKET_1_KIN, ... , BUCKET_1_000_000_KIN]
// actions.push_back(OpenAccountAction(account))
// actions.push_back(CloseDormantAccount(account))
message OpenAccountsMetadata {
// Nothing is currently required
}
// Sends a payment to a destination account with initial temporary privacy. Clients
// should also reorganize their bucket accounts and rotate their temporary outgoing
// account.
//
// Action Spec (In Person Cash Payment or Withdrawal or Tip):
//
// actions = [
// // Section 1: Transfer ExchangeData.Quarks from BUCKET_X_KIN accounts to TEMPORARY_OUTGOING account with reogranizations
//
// TemporaryPrivacyExchangeAction(BUCKET_X_KIN, BUCKET_X_KIN, multiple * bucketSize),
// TemporaryPrivacyTransferAction(BUCKET_X_KIN, TEMPORARY_OUTGOING[index], multiple * bucketSize),
// ...,
// TemporaryPrivacyExchangeAction(BUCKET_X_KIN, BUCKET_X_KIN, multiple * bucketSize),
// TemporaryPrivacyTransferAction(BUCKET_X_KIN, TEMPORARY_OUTGOING[index], multiple * bucketSize),
//
// // Section 2: Rotate TEMPORARY_OUTGOING account
//
// // Below must appear last in this exact order
// NoPrivacyWithdrawAction(TEMPORARY_OUTGOING[index], destination, ExchangeData.Quarks),
// OpenAccountAction(TEMPORARY_OUTGOING[index + 1]),
// CloseDormantAccount(TEMPORARY_OUTGOING[index + 1]),
// ]
//
// Action Spec (Remote Send):
//
// actions = [
// // Section 1: Open REMOTE_SEND_GIFT_CARD account
//
// OpenAccountAction(REMOTE_SEND_GIFT_CARD),
//
// // Section 2: Transfer ExchangeData.Quarks from BUCKET_X_KIN accounts to TEMPORARY_OUTGOING account with reogranizations
//
// TemporaryPrivacyExchangeAction(BUCKET_X_KIN, BUCKET_X_KIN, multiple * bucketSize),
// TemporaryPrivacyTransferAction(BUCKET_X_KIN, TEMPORARY_OUTGOING[index], multiple * bucketSize),
// ...,
// TemporaryPrivacyExchangeAction(BUCKET_X_KIN, BUCKET_X_KIN, multiple * bucketSize),
// TemporaryPrivacyTransferAction(BUCKET_X_KIN, TEMPORARY_OUTGOING[index], multiple * bucketSize),
//
// // Section 3: Rotate TEMPORARY_OUTGOING account
//
// // Below must appear last in this exact order
// NoPrivacyWithdrawAction(TEMPORARY_OUTGOING[index], REMOTE_SEND_GIFT_CARD, ExchangeData.Quarks),
// OpenAccountAction(TEMPORARY_OUTGOING[index + 1]),
// CloseDormantAccount(TEMPORARY_OUTGOING[index + 1]),
//
// // Section 4: Close REMOTE_SEND_GIFT_CARD if not redeemed after period of time
//
// CloseDormantAccount(REMOTE_SEND_GIFT_CARD),
//
// Action Spec (Micro Payment):
//
// actions = [
// // Section 1: Transfer ExchangeData.Quarks from BUCKET_X_KIN accounts to TEMPORARY_OUTGOING account with reogranizations
//
// TemporaryPrivacyExchangeAction(BUCKET_X_KIN, BUCKET_X_KIN, multiple * bucketSize),
// TemporaryPrivacyTransferAction(BUCKET_X_KIN, TEMPORARY_OUTGOING[index], multiple * bucketSize),
// ...,
// TemporaryPrivacyExchangeAction(BUCKET_X_KIN, BUCKET_X_KIN, multiple * bucketSize),
// TemporaryPrivacyTransferAction(BUCKET_X_KIN, TEMPORARY_OUTGOING[index], multiple * bucketSize),
//
// // Section 2: Fee payments
//
// // Hard-coded Code $0.01 USD fee to a dynamic fee account
// FeePayment(TEMPORARY_OUTGOING[index], codeFeeAccount, $0.01 USD of Kin),
//
// // Additional fees, exactly as specified in the original payment request
// FeePayment(TEMPORARY_OUTGOING[index], additionalFeeAccount0, additionalFeeQuarks0),
// ...
// FeePayment(TEMPORARY_OUTGOING[index], additionalFeeAccountN, additionalFeeQuarksN),
//
// // Section 3: Rotate TEMPORARY_OUTGOING account
//
// // Below must appear last in this exact order
// NoPrivacyWithdrawAction(TEMPORARY_OUTGOING[index], destination, ExchangeData.Quarks - $0.01 USD of Kin - additionalFeeQuarks0 - ... - additionalFeeQuarksN),
// OpenAccountAction(TEMPORARY_OUTGOING[index + 1]),
// CloseDormantAccount(TEMPORARY_OUTGOING[index + 1]),
// ]
message SendPrivatePaymentMetadata {
// The destination token account to send funds to
common.v1.SolanaAccountId destination = 1 [(validate.rules).message.required = true];
// The exchange data of total funds being sent to the destination
ExchangeData exchange_data = 2 [(validate.rules).message.required = true];
// Is the payment a withdrawal? For destinations that are not Code temporary
// accounts, this must be set to true.
bool is_withdrawal = 3;
// Is the payment for a remote send?
bool is_remote_send = 4;
// Is the payment for a tip?
bool is_tip = 5;
// If is_tip is true, the user being tipped
TippedUser tipped_user = 6;
}
// Send a payment to a destination account publicly.
//
// Action Spec:
//
// source = PRIMARY or RELATIONSHIP
// actions = [NoPrivacyTransferAction(source, destination, ExchangeData.Quarks)]
message SendPublicPaymentMetadata {
// The primary or relatinship account where funds will be sent from. The primary
// account is assumed if this field is not set for backwards compatibility with
// old clients.
common.v1.SolanaAccountId source = 4;
// The destination token account to send funds to. This cannot be a Code
// temporary account.
common.v1.SolanaAccountId destination = 1 [(validate.rules).message.required = true];
// The exchange data of total funds being sent to the destination
ExchangeData exchange_data = 2 [(validate.rules).message.required = true];
// Is the payment a withdrawal? Currently, this is always true.
bool is_withdrawal = 3 [(validate.rules).bool.const = true];
}
// Receive funds into an organizer with initial temporary privacy. Clients should
// also reorganize their bucket accounts and rotate their temporary incoming account
// as applicable. Only accounts owned and derived by a user's 12 words should operate
// as a source in this intent type to guarantee privacy upgradeability.
//
// Action Spec (Payment):
//
// actions = [
// // Section 1: Transfer Quarks from TEMPORARY_INCOMING account to BUCKET_X_KIN accounts with reorganizations
//
// TemporaryPrivacyTransferAction(TEMPORARY_INCOMING[index], BUCKET_X_KIN, multiple * bucketSize),
// TemporaryPrivacyExchangeAction(BUCKET_X_KIN, BUCKET_X_KIN, multiple * bucketSize),
// ...,
// TemporaryPrivacyTransferAction(TEMPORARY_INCOMING[index], BUCKET_X_KIN, multiple * bucketSize),
// TemporaryPrivacyExchangeAction(BUCKET_X_KIN, BUCKET_X_KIN, multiple * bucketSize),
//
// // Section 2: Rotate TEMPORARY_INCOMING account
//
// // Below must appear last in this exact order
// CloseEmptyAccountAction(TEMPORARY_INCOMING[index]),
// OpenAccountAction(TEMPORARY_INCOMING[index + 1])
// CloseDormantAccount(TEMPORARY_INCOMING[index + 1]),
// ]
//
// Action Spec (Deposit):
//
// source = PRIMARY or RELATIONSHIP
// actions = [
// TemporaryPrivacyTransferAction(source, BUCKET_X_KIN, multiple * bucketSize),
// TemporaryPrivacyExchangeAction(BUCKET_X_KIN, BUCKET_X_KIN, multiple * bucketSize),
// ...,
// TemporaryPrivacyTransferAction(source, BUCKET_X_KIN, multiple * bucketSize),
// TemporaryPrivacyExchangeAction(BUCKET_X_KIN, BUCKET_X_KIN, multiple * bucketSize),
// ]
message ReceivePaymentsPrivatelyMetadata {
// The temporary incoming, primary or relationship account to receive funds from
common.v1.SolanaAccountId source = 1 [(validate.rules).message.required = true];
// The exact amount of Kin in quarks being received
uint64 quarks = 2 [(validate.rules).uint64.gt = 0];
// Is the receipt of funds from a deposit? If true, the source account must
// be a primary or relationship account. Otherwise, it must be from a temporary
// incoming account.
bool is_deposit = 3;
}
// Receive funds into a user-owned account publicly. All use cases of this intent
// close the account, so all funds must be moved. Use this intent to receive payments
// from an account not owned by a user's 12 words into a temporary incoming account,
// which will guarantee privacy upgradeability.
//
// Action Spec (Remote Send):
//
// actions = [NoPrivacyWithdrawAction(REMOTE_SEND_GIFT_CARD, TEMPORARY_INCOMING[latest_index], quarks)]
message ReceivePaymentsPubliclyMetadata {
// The remote send gift card to receive funds from
common.v1.SolanaAccountId source = 1 [(validate.rules).message.required = true];
// The exact amount of Kin in quarks being received
uint64 quarks = 2 [(validate.rules).uint64.gt = 0];
// Is the receipt of funds from a remote send gift card? Currently, this is
// the only use case for this intent and validation enforces the flag to true.
bool is_remote_send = 3 [(validate.rules).bool.const = true];
// If is_remote_send is true, is the gift card being voided? The user owner
// account's 12 words that issued the gift card may only set this flag to true.
// Functionally, this doesn't affect the intent, but rather if we decide to show
// it in a user-friendly payment history.
bool is_issuer_voiding_gift_card = 4;
// If is_remote_send is true, the original exchange data that was provided as
// part of creating the gift card account. This is purely a server-provided value.
// SubmitIntent will disallow this being set.
ExchangeData exchange_data = 5;
}
// Upgrade existing private transactions from temporary to permanent privacy.
message UpgradePrivacyMetadata {
// Nothing is currently required
}
// Migrates existing users prior to the privacy implementation by:
// 1. If there are funds in the LEGACY_PRIMARY_2022 account, then move them
// to the new PRIMARY account, so the client can later simulate a deposit
// by submitting a *separate* ReceivePaymentsPrivately intent.
// 2. Close the LEGACY_PRIMARY_2022 account.
//
// Prereqs:
// - OpenAccounts intent has been submitted
//
// Action spec:
//
// if balance == 0 {
// actions = [CloseEmptyAccountAction(LEGACY_PRIMARY_2022)]
// } else {
// actions = [NoPrivacyWitdraw(LEGACY_PRIMARY_2022, PRIMARY, Quarks)]
// }
message MigrateToPrivacy2022Metadata {
// The exact amount of Kin in quarks being migrated. Set this to zero if
// the account is empty.
uint64 quarks = 1;
}
// Establishes a long-lived private relationship between a user and another
// entity.
//
// Prereqs:
// - OpenAccounts intent has been submitted
//
// Action spec:
//
// actions = [OpenAccountAction(RELATIONSHIP)]
message EstablishRelationshipMetadata {
common.v1.Relationship relationship = 1 [(validate.rules).message.required = true];
}
//
// Action Definitions
//
// Action is a well-defined, ordered and small set of transactions for a unit of work
// that the client wants to perform on the blockchain. Clients provide parameters known
// to them in the action.
message Action {
// The ID of this action, which is unique within an intent. It must match
// the index of the action's location in the SubmitAction's actions field.
uint32 id = 1;
// The type of action to perform.
oneof type {
option (validate.required) = true;
OpenAccountAction open_account = 2;
CloseEmptyAccountAction close_empty_account = 3;
CloseDormantAccountAction close_dormant_account = 4;
NoPrivacyTransferAction no_privacy_transfer = 5;
NoPrivacyWithdrawAction no_privacy_withdraw = 6;
TemporaryPrivacyTransferAction temporary_privacy_transfer = 7;
TemporaryPrivacyExchangeAction temporary_privacy_exchange = 8;
PermanentPrivacyUpgradeAction permanent_privacy_upgrade = 9;
FeePaymentAction fee_payment = 10;
}
}
// Transaction 1
// Instructions:
// 1. system::AdvanceNonce
// 2. timelock::Initialize
// Client Signature Required: No
//
// All OpenAccountActions for non-primary accounts must be followed with an associated
// CloseDormantAccountAction to enable server to perform cleanup.
message OpenAccountAction {
// The type of account, which will dictate its intended use
common.v1.AccountType account_type = 1 [(validate.rules).enum.not_in = 0];
// The owner of the account. For accounts liked to a user's 12 words, this is
// the verified parent owner account public key. All other account types should
// set this to the authority value.
common.v1.SolanaAccountId owner = 2 [(validate.rules).message.required = true];
// The index used to for accounts that are derived from owner
uint64 index = 3;
// The public key of the private key that has authority over the opened token account
common.v1.SolanaAccountId authority = 4 [(validate.rules).message.required = true];
// The token account being opened
common.v1.SolanaAccountId token = 5 [(validate.rules).message.required = true];
// The signature is of serialize(OpenAccountAction) without this field set
// using the private key of the authority account. This provides a proof
// of authorization to link authority to owner.
common.v1.Signature authority_signature = 6 [(validate.rules).message.required = true];
}
// Transaction 1
// Instructions:
// 1. system::AdvanceNonce
// 2. timelock::BurnDustWithAuthority (max 1 Kin)
// 3. timelock::CloseAccounts
// Client Signature Required: Yes
message CloseEmptyAccountAction {
// The type of account being closed
common.v1.AccountType account_type = 1 [(validate.rules).enum.not_in = 0];
// The public key of the private key that has authority over the token account
// that should be closed
common.v1.SolanaAccountId authority = 2 [(validate.rules).message.required = true];
// The token account being closed
common.v1.SolanaAccountId token = 3 [(validate.rules).message.required = true];
}
// Transaction 1
// Instructions:
// 1. system::AdvanceNonce
// 2. memo::Memo
// 3. timelock::RevokeLockWithAuthority
// 4. timelock::DeactivateLock
// 5. timelock::Withdraw (token -> primary)
// 6. timelock::CloseAccounts
// Client Signature Required: Yes
message CloseDormantAccountAction {
// The type of account being closed
common.v1.AccountType account_type = 1 [(validate.rules).enum.not_in = 0];
// The public key of the private key that has authority over the token account
// that should be closed
common.v1.SolanaAccountId authority = 2 [(validate.rules).message.required = true];
// The token account being closed
common.v1.SolanaAccountId token = 3 [(validate.rules).message.required = true];
// The destination where funds are withdrawn to
common.v1.SolanaAccountId destination = 4 [(validate.rules).message.required = true];
}
// Transaction 1
// Instructions:
// 1. system::AdvanceNonce
// 2. memo::Memo
// 3. timelock::TransferWithAuthority (source -> destination)
// Client Signature Required: Yes
message NoPrivacyTransferAction {
// The public key of the private key that has authority over source
common.v1.SolanaAccountId authority = 1 [(validate.rules).message.required = true];
// The source account where funds are transferred from
common.v1.SolanaAccountId source = 2 [(validate.rules).message.required = true];
// The destination account where funds are transferred to
common.v1.SolanaAccountId destination = 3 [(validate.rules).message.required = true];
// The Kin quark amount to transfer
uint64 amount = 4 [(validate.rules).uint64.gt = 0];
}
// Transaction 1
// Instructions:
// 1. system::AdvanceNonce
// 2. memo::Memo
// 3. timelock::RevokeLockWithAuthority
// 4. timelock::DeactivateLock
// 5. timelock::Withdraw (source -> destination)
// 6. timelock::CloseAccounts
// Client Signature Required: Yes
message NoPrivacyWithdrawAction {
// The public key of the private key that has authority over source
common.v1.SolanaAccountId authority = 1 [(validate.rules).message.required = true];
// The source account where funds are transferred from
common.v1.SolanaAccountId source = 2 [(validate.rules).message.required = true];
// The destination account where funds are transferred to
common.v1.SolanaAccountId destination = 3 [(validate.rules).message.required = true];
// The intended Kin quark amount to withdraw
uint64 amount = 4 [(validate.rules).uint64.gt = 0];
// Whether the account is closed afterwards. This is always true, since there
// are no current se cases to leave it open.
bool should_close = 5 [(validate.rules).bool.const = true];
}
// Transaction 1
// Instructions:
// 1. system::AdvanceNonce
// 2. memo::Memo
// 3. splitter::TransferWithCommitment (treasury -> destination)
// Client Signature Required: No
//
// Transaction 2
// Instructions:
// 1. system::AdvanceNonce
// 2. memo::Memo
// 3. timelock::TransferWithAuthority (source -> commitment)
// Client Signature Required: Yes
message TemporaryPrivacyTransferAction {
// The public key of the private key that has authority over source
common.v1.SolanaAccountId authority = 1 [(validate.rules).message.required = true];