/
index.ts
1356 lines (1169 loc) · 41 KB
/
index.ts
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
import { IQuery } from "../indexer/internal/queryBuilder";
import Deferred from "../helpers/deferred";
import { BigNumber as BigNumberJs } from "bignumber.js";
export type tTokenSymbol = "DAI" | "USDT" | "USDC" | "ETH" | string;
interface IEnsAddresses {
seller?: string;
arbitrator?: string;
marketplace?: string;
}
/**
* Properties of a token, incl. decimals as in its rounding precision.
*/
export interface IToken {
/** 'DAI' | 'USDT' | 'USDC' | 'ETH' | string */
symbol?: tTokenSymbol;
address?: string;
/** Number of token decimals. To get "human readable" format, divide the amount by pow(10, decimals) */
decimals?: number;
}
/**
* Payment data input
*/
export interface IPaymentProps {
/** Amount in token */
amount: string | BigNumberJs | number;
/** Whom is the payment for */
seller: string;
/** Initial challenge period (in seconds) */
challengePeriod: number;
/** Address of the token used in the payment (skip or set to null for ETH) */
tokenAddress?: string;
/** address of a marketplace that has facilitated the payment */
marketplace?: string;
/** Marketplace fee in % (can be 0 even if a marketplace was set but doesn't charge fee) */
marketplaceFee?: number;
/** Address of the arbitrator. null for no arbitrator */
arbitrator?: string | null;
/** Arbitrator's fee in %. Can be 0 */
arbitratorFee?: number;
/** By how much will the challenge period get extended after a challenge (in seconds) */
challengePeriodExtension?: number;
}
export interface IValidateProps extends IPaymentProps {
buyer: string;
}
export interface IPaymentPropsData extends IPaymentProps {
ensAddresses?: IEnsAddresses;
}
export interface IArbitratorData {
address: string;
fee: number;
splitBuyer: number;
splitSeller: number;
}
export enum EscrowStatus {
UNPAID = "Unpaid",
PAID = "Paid",
RELEASED = "Released",
PERIOD_EXPIRED = "Period Expired",
REFUNDED = "Refunded",
CHALLENGED = "Challenged",
SETTLED = "Settled",
}
export type tEscrowParty = "buyer" | "seller" | null;
/**
* Full status of an escrow.
*/
export interface IEscrowStatus {
/** The current state of an escrow (PAID | UNPAID | RELEASED | PERIOD_EXPIRED | REFUNDED | CHALLENGED | SETTLED). */
state: EscrowStatus;
/** True if the payment was already withdrawn from the escrow */
claimed: boolean;
/** Who sent the latest challenge ('buyer', 'seller', or null when there's been no challenge) */
latestChallengeBy: tEscrowParty;
/** Who sent the latest settlement offer ('buyer', 'seller', or null if there's been no offer) */
latestSettlementOfferBy: tEscrowParty;
}
export interface EscrowStatusView {
amount: BigNumberJs; // ERC20 | Ether
escrow_id: number;
status: keyof typeof EscrowStatus;
// Addresses
marketplace: string | null;
buyer: string;
seller: string;
currency: string;
challenge_period: number;
challenge_period_start: number;
challenge_period_end: number;
// Split
split_seller: number;
split_buyer: number;
split_protocol: number;
split_marketplace: number;
// Consensus
consensus_seller: number;
consensus_buyer: number;
claimed: boolean;
// Arbitration
arbitrator?: string;
arbitrator_fee?: number;
arbitrated: boolean;
arbitrator_proposer?: string;
status_arbitration?: string;
// Settlement
latest_settlement_offer_address?: string;
latest_settlement_offer_seller?: number;
latest_settlement_offer_buyer?: number;
paid_at: number;
}
/**
* Detailed information about the escrow
*
* @example // A returned object might look e.g. like this:
* {
* challengePeriod: 1209600,
* challengePeriodStart: "2023-01-24T11:54:33.000Z",
* challengePeriodEnd: "2023-02-07T11:54:33.000Z",
* status: {
* state: "Paid",
* latestChallengeBy: null,
* latestSettlementOfferBy: null,
* claimed: false
* },
* escrowId: 434,
* amount: "2500000000",
* marketplace: "0xf8C03F09b4f53FDc05b57c7846da5F428798f187",
* buyer: "0x1cB9dc49C0cC09D72E8dA74a9Ea956A0b1A65ab4",
* seller: "0xA98135151f8dCd5632A63CC6358f5684c62B041D",
* splitMarketplace: 10,
* splitBuyer: 0,
* splitSeller: 100,
* splitProtocol: 0.69,
* consensusBuyer: 0,
* consensusSeller: 1,
* arbitration: {
* arbitrator: "0x3C86F543e64810E1d843809B2b70a4FDcC3b9B66",
* consensusSeller: true,
* consensusBuyer: true,
* arbitrated: false,
* arbitratorFee: 0
* },
* settlement: null,
* token: {
* address: "0x7eD124F79447a1390281c88bB9bca2AC4F009BBE"
* }
* }
*/
export interface IEscrowData {
/** Amount in token's (or ETH's) wei unit */
amount: BigNumberJs; // ERC20 | Ether
escrowId: number;
/** See the interface for more details */
status: IEscrowStatus;
/** Marketplace address */
marketplace: string | null;
/** Buyer (payer) address */
buyer: string;
/** Seller (payee) address */
seller: string;
/** Information about the payment token */
token: IToken;
/** How much a challenge period will extend by if challenged */
challengePeriod: number;
/** Current challenge period start (either payment time or the latest challenge) */
challengePeriodStart: Date;
/** Current challenge period end (when it will be possible to claim the payment) */
challengePeriodEnd: Date;
/** How much (%) of the payment is meant for the buyer (default 0) */
splitBuyer: number;
/**
* How much (%) of the payment is meant for the seller (default 100).
* Buyer and seller splits are "gross", i.e. before fee deduction.
* They are recalculated at the time of the claim based on fee and the latest status of the escrow
*/
splitSeller: number;
/** Protocol fee (%) */
splitProtocol: number;
/** Marketplace fee (%) */
splitMarketplace: number;
/**
* Indicates status of the payment from buyer's and seller's side.
* Negative value means that party was challenged.
*
* Examples for various states: <br/>
* 0, 1: Paid - If the payment is claimed after challenge period ends, consensus remains like this <br/>
* 1, 1: Released by buyer <br/>
* 1,-1: 1x Challenged by buyer - If the payment is claimed after CP ends, consensus remains like this <br/>
* -1, 2: 1x Challenged by buyer and 1x by Seller <br/>
* 2,-2: 2x Challenged by buyer, 1x by seller <br/>
* 3, 2: Released, Refunded, or Settled. Deduct 1 from each consensus number to calculate number of challenges
*/
consensusBuyer: number;
/** See consensusBuyer for details */
consensusSeller: number;
/** When was the payment sent to the escrow */
createdAt?: Date;
/** Address that sent the latest settlement offer (if any) */
latestSettlementOfferAddress?: string;
/** What was the proposed seller's split in the latest settlement offer */
latestSettlementOfferSeller?: number;
/** What was the proposed seller's split in the latest settlement offer */
latestSettlementOfferBuyer?: number;
/** ENS Addresses */
ensAddresses?: IEnsAddresses;
}
export interface IEscrowDataWithTokenInfo extends IEscrowData {
tokenInfo: IToken;
}
/**
* Returned from confirmed callbacks and includes basic information about the minted transaction and the event it emitted
*/
export interface GenericParsedTxPayload {
/** Name of the event */
name: string;
/** Transaction hash */
transactionHash: string;
/** Number of the block in which the transaction was minted */
blockNumber: number;
/** ID of the escrow that the transaction created or acted upon */
escrowId: number;
}
/**
* Escrow data returned after an arbitrator is approved for the escrow
*/
export interface ApproveArbitratorParsedPayload extends GenericParsedTxPayload {
/** Address of the arbitrator. null for no arbitrator */
arbitrator: string | null;
/** Arbitrator's fee (%, can be 0) */
arbitratorFee: number;
/** Has the escrow been decided by the arbitrator, false if value === null // TODO: verify if true */
statusArbitration: "ArbitratorApproved";
}
/**
* Escrow data sent after a settlement offer is approved and the payment is settled
*/
export interface ApproveSettlementParsedPayload extends GenericParsedTxPayload {
/* The date when payment has been settled at */
settledAt: Date;
/** How much was the buyer offered in the latest settlement offer */
latestSettlementOfferBuyer: number;
/** How much was the seller offered in the latest settlement offer */
latestSettlementOfferSeller: number;
/** Who sent the payment */
buyer: string;
/** Whom is the payment for */
seller: string;
/** By how much will the challenge period get extended after a challenge (in seconds) */
challengePeriodExtension: number;
/** When does the current challenge period start (seconds in Unix epoch) */
challengePeriodStart: Date;
/** When does the current challenge period end (seconds in Unix epoch) */
challengePeriodEnd: Date;
/** address of a marketplace that has facilitated the payment */
marketplace: string;
/** Fee for the marketplace (can be 0 even if a marketplace was set but doesn't charge fee) */
marketplaceFee: number;
/** Token used in the payment (null for ETH) */
currency: string | null;
/** True if the payment was already withdrawn from the escrow */
claimed: boolean;
/** Buyer's agreement on the arbitrator */
consensusBuyer: number;
/** Seller's agreement on the arbitrator */
consensusSeller: number;
/** Current buyer's split based on the latest action on the escrow */
splitBuyer: number;
/** Current seller's split based on the latest action on the escrow */
splitSeller: number;
/** Marketplace fee (bips) */
splitMarketplace: number;
/** Protocol fee (bips) */
splitProtocol: number;
/** Amount in token */
amount: string;
/** Buyer's final share in percentage incl. fees */
amountBuyer: string;
/** Seller's final share in percentage incl. fees */
amountSeller: string;
/** Marketplace's final share in percentage incl. fees */
amountMarketplace: string;
/** Protocol's final share in percentage incl. fees */
amountProtocol: string;
/** Arbitrator's final share in percentage incl. fees */
amountArbitrator: string;
}
/**
* Escrow data returned from the contract after an arbitration is sent
*/
export interface ArbitrateParsedPayload extends GenericParsedTxPayload {
/** Date/time when the arbitration was sent and the payment was settled */
settledAt: Date;
/** Who sent the payment */
buyer: string;
/** Whom is the payment for */
seller: string;
/** By how much will the challenge period get extended after a challenge (in seconds) */
challengePeriodExtension: number;
/** When does the current challenge period start (seconds in Unix epoch) */
challengePeriodStart: Date;
/** When does the current challenge period end (seconds in Unix epoch) */
challengePeriodEnd: Date;
/** address of a marketplace that has facilitated the payment */
marketplace: string;
/** Fee for the marketplace (can be 0 even if a marketplace was set but doesn't charge fee) */
marketplaceFee: number;
/** Token used in the payment (null for ETH) */
currency: string | null;
/** True if the payment was already withdrawn from the escrow */
claimed: boolean;
/** Buyer's agreement on the arbitrator */
consensusBuyer: number;
/** Seller's agreement on the arbitrator */
consensusSeller: number;
/** Current buyer's split based on the latest action on the escrow */
splitBuyer: number;
/** Current seller's split based on the latest action on the escrow */
splitSeller: number;
/** Marketplace fee (bips) */
splitMarketplace: number;
/** Protocol fee (bips) */
splitProtocol: number;
/** Amount in token */
amount: string;
/** Buyer's final share in percentage incl. fees */
amountBuyer: string;
/** Seller's final share in percentage incl. fees */
amountSeller: string;
/** Marketplace's final share in percentage incl. fees */
amountMarketplace: string;
/** Protocol's final share in percentage incl. fees */
amountProtocol: string;
/** Arbitrator's final share in percentage incl. fees */
amountArbitrator: string;
}
/**
* Escrow data returned after a challenge is sent
*/
export interface ChallengeParsedPayload extends GenericParsedTxPayload {
/* The date when payment has been challenged at */
challengedAt: Date;
/** Who sent the payment */
buyer: string;
/** Whom is the payment for */
seller: string;
/** By how much will the challenge period get extended after a challenge (in seconds) */
challengePeriodExtension: number;
/** When does the current challenge period start (seconds in Unix epoch) */
challengePeriodStart: Date;
/** When does the current challenge period end (seconds in Unix epoch) */
challengePeriodEnd: Date;
/** address of a marketplace that has facilitated the payment */
marketplace: string;
/** Fee for the marketplace (can be 0 even if a marketplace was set but doesn't charge fee) */
marketplaceFee: number;
/** Token used in the payment (null for ETH) */
currency: string | null;
/** True if the payment was already withdrawn from the escrow */
claimed: boolean;
/** Buyer's agreement on the arbitrator */
consensusBuyer: number;
/** Seller's agreement on the arbitrator */
consensusSeller: number;
/** Buyer's split after the challenge (100 if the buyer challenged, 0 if the seller challenged */
splitBuyer: number;
/** Seller's split after the challenge (0 if the buyer challenged, 100 if the seller challenged */
splitSeller: number;
/** Marketplace fee (%) */
splitMarketplace: number;
/** Protocol fee (%) */
splitProtocol: number;
/** Amount in token */
amount: string;
}
/** Amounts (in ETH's or token's WEIs) sent to all the parties after the escrow was closed */
export interface ClaimParsedPayload extends GenericParsedTxPayload {
amountBuyer: string;
amountSeller: string;
amountMarketplace: string;
amountProtocol: string;
amountArbitrator: string;
}
/**
* Amounts (in ETH's or token's WEIs) sent to all the parties after multiple escrows were closed
*/
export interface MultipleClaimParsedPayload extends GenericParsedTxPayload {
/** The data for a single claim of an escrow share. (array with amountBuyer, amountSeller, amountMarketplace, amountProtocol, amountArbitrator) */
payload: ClaimParsedPayload[];
}
/**
* Details of a settlement offer returned from the contract after the offer was sent
*/
export interface OfferSettlementParsedPayload extends GenericParsedTxPayload {
/* Date/time of the offer */
settlementOfferAt: Date;
/** Buyer's share in the offer */
latestSettlementOfferBuyer: number;
/** Seller's share in the offer */
latestSettlementOfferSeller: number;
/** Address of who sent the offer. */
latestSettlementOfferAddress: string;
}
/**
* Escrow data returned after the payment was sent and the escrow was created
*/
export interface PayParsedPayload extends GenericParsedTxPayload {
/** Date/time of the payment */
paidAt: Date;
/** Address of the arbitrator (null if none) */
arbitrator: string;
/** Arbitrator's fee (%, can be 0) */
arbitratorFee: number;
/** Who sent the payment */
buyer: string;
/** Whom is the payment for */
seller: string;
/** Initial challenge period (in seconds) */
challengePeriod: number;
/** By how much will the challenge period get extended after a challenge (in seconds) */
challengePeriodExtension: number;
/** When does the current challenge period start */
challengePeriodStart: Date;
/** When does the current challenge period end */
challengePeriodEnd: Date;
/** Address of a marketplace that has facilitated the payment */
marketplace: string;
/** Fee for the marketplace (can be 0 even if a marketplace was set but doesn't charge fee) */
marketplaceFee: number;
/** Token used in the payment (null for ETH) */
tokenAddress?: string;
/** True if the payment was already withdrawn from the escrow */
claimed: boolean;
/** Buyer's agreement on the arbitrator */
consensusBuyer: number;
/** Seller's agreement on the arbitrator */
consensusSeller: number;
/** Buyer's split of the escrow (0 by default) */
splitBuyer: number;
/** Seller's split of the escrow (100 by default) */
splitSeller: number;
/** Marketplace fee (%) */
splitMarketplace: number;
/** Protocol fee (%) */
splitProtocol: number;
/** Amount in token */
amount: string;
/** Current buyer's share (in ETH or token) based on the latest status of the escrow */
amountBuyer: string;
/** Current seller's share (in ETH or token) based on the latest status of the escrow */
amountSeller: string;
/** Current marketplace feee (in ETH or token) based on the latest status of the escrow */
amountMarketplace: string;
/** Current arbitrator feee (in ETH or token) based on the latest status of the escrow */
amountArbitrator: string;
/** Current protocol feee (in ETH or token) based on the latest status of the escrow */
amountProtocol: string;
}
/**
* Details about arbitrator proposal
*/
export interface ProposalArbitratorParsedPayload
extends GenericParsedTxPayload {
/** Address of the arbitrator. null for no arbitrator */
arbitrator: string | null;
/** Arbitrator's fee in bips. Can be 0 */
arbitratorFee: number;
/** Address of the proposer */
proposer: string;
/** status of the arbitration */
statusArbitration: "ArbitratorProposed";
}
/**
* Data about a released escrow
*/
export interface ReleaseParsedPayload extends GenericParsedTxPayload {
/** Date/time when the escrow was released */
releasedAt: Date;
/** Escrow buyer (who paid and released the escrow) */
buyer: string;
/** Seller (to whom the payment was paid and released) */
seller: string;
/** What was the challenge period extension */
challengePeriodExtension: number;
/** When did the last challenge period start */
challengePeriodStart: Date;
/** When did the last challenge period end */
challengePeriodEnd: Date;
/** Marketplace address */
marketplace: string;
/** Marketplace fee (in %) */
marketplaceFee: number;
/** Payment token address (null for ETH) */
currency: string;
/** If the payment was claimed (always true in this case since release automatically claims) */
claimed: boolean;
/** Buyer's consensus about the escrow (always positive in this case since the buyer just released) */
consensusBuyer: number;
/** Seller's consensus */
consensusSeller: number;
/** Buyer's split (0 in this case) */
splitBuyer: number;
/** Seller's split (100 in this case) */
splitSeller: number;
/** Marketplace fee (in %) */
splitMarketplace: number;
/** Protocol fee (in %) */
splitProtocol: number;
/** Total escrow amount in ETH's or token's WEI */
amount: string;
/** Amount that was sent to the buyer (0 in this case) */
amountBuyer: string;
/** Amount that was sent to the buyer (total amount - fees in this case) */
amountSeller: string;
/** Amount sent to the marketplace in ETH's or token's WEI */
amountMarketplace: string;
/** Amount sent to the protocol in ETH's or token's WEI */
amountProtocol: string;
/** Amount sent to the arbitrator in ETH's or token's WEI */
amountArbitrator: string;
}
/**
* Callbacks available for all SDK functions that interact with the contract
*/
export interface IGenericTransactionCallbacks {
/** Triggered when the function attempts to connect to the wallet */
connectingWallet?: (payload?: any) => void;
/** When the wallet is successfully connected */
connected?: (payload?: any) => void;
/** If the user is not connected to the default network and is being asked to switch by the global configuration */
switchingNetwork?: (payload?: any) => void;
/** When the transaction is being broadcasted */
broadcasting?: (payload?: any) => void;
/** When the transaction was broadcasted (provides txn hash and other relevant info) */
broadcasted?: (payload: any) => void;
/** When the transaction was minted (provides detailed information about the escrow after the update) */
confirmed?: (payload: any) => void;
}
/**
* Passed to the callbacks when the payment is being broadcasted and confirmed
*/
export interface IPayTransactionPayload {
transactionHash: string;
/** Name of the event ("Pay") */
name?: string;
/** Number of the block in which the payment transaction was minted */
blockNumber?: number;
/** Escrow Id generated by the contract (available only in confirmed callback) */
escrowId?: number;
/** Arbitrator fee specified in the payment (%, can be 0) */
arbitratorFee?: number;
/** When was the payment sent */
paidAt?: Date;
/** Arbitrator address (null if none) */
arbitrator?: string;
/** Address of the buyer (who sent the payment) */
buyer?: string;
/** Address of the seller (whom is the payment for) */
seller?: string;
/** Initial challenge period (seconds) */
challengePeriod?: number;
/** By how much does the challenge period extend after each challenge */
challengePeriodExtension?: number;
/** When does the current challenge period start (same as paidAt in this case) */
challengePeriodStart?: Date;
/** When does the current challenge period end (paidAt + challengePeriod in this case) */
challengePeriodEnd?: Date;
/** Address of the marketplace that facilitated the payment (null if none) */
marketplace?: string;
/** Marketplace fee (%, can be 0 even if a marketplace was defined) */
marketplaceFee?: number;
/** Address of the escrowed token (null for ETH) */
tokenAddress?: string;
/** If the payment was claimed (always false here) */
claimed?: boolean;
/** Buyer's consensus over the escrow (0 in this case) */
consensusBuyer?: number;
/** Seller's consensus over the scrow (1 in this case) */
consensusSeller?: number;
/** Buyer's split of the payment (0 in this case) */
splitBuyer?: number;
/** Seller's split of the payment (100 in this case) */
splitSeller?: number;
/** Marketplace fee (%) */
splitMarketplace?: number;
/** Protocol fee (%) */
splitProtocol?: number;
/** Payment amount in ETH's or token's WEI */
amount?: string;
/** Amount (in ETH's or token's WEI) which the buyer would receive if the payment was claimed as is (0 in this case) */
amountBuyer?: string;
/** Amount (in ETH's or token's WEI) which the seller would receive if the payment was claimed as is (amount - fees in this case) */
amountSeller?: string;
/** Amount (in ETH's or token's WEI) which the marketplace would receive if the payment was claimed as is (amount * fee in this case) */
amountMarketplace?: string;
/** Amount (in ETH's or token's WEI) which the arbitrator would receive if the payment was claimed as is (amount * fee in this case) */
amountArbitrator?: string;
/** Amount (in ETH's or token's WEI) which the protocol would receive if the payment was claimed as is (amount * fee in this case) */
amountProtocol?: string;
}
/**
* Callbacks specific to the initial escrow Payment
*/
export interface IPayTransactionCallbacks extends IGenericTransactionCallbacks {
/** Called when the transaction is broadcasted (includes payment details) */
broadcasted?: (data: IPayTransactionPayload) => void;
/** Called when the transaction is minted (includes payment details) */
confirmed?: (data: IPayTransactionPayload) => void;
}
export interface IReleasedTransactionPayload extends ReleaseParsedPayload {}
export interface IReleasedTransactionBroadcastPayload {
transactionHash: string;
}
/**
* Callbacks specific for escrow release
*/
export interface IReleaseTransactionCallbacks
extends IGenericTransactionCallbacks {
/** Called when the transaction is broadcasted, */
broadcasted?: (data: IReleasedTransactionBroadcastPayload) => void;
/** Called when the transaction is minted (provides details about the escrow after the release) */
confirmed?: (data: IReleasedTransactionPayload) => void;
}
/**
* Details about a settlement offer broadcasted to the network
*/
export interface ISettlementTransactionPayload {
transactionHash: string;
/** Buyer's share (in %) proposed int the offer */
splitBuyer: number;
/** Seller's share (in %) proposed int the offer */
splitSeller: number;
}
/**
* Callbacks specific for settlement approval
*/
export interface ISettlementApproveTransactionCallbacks
extends IGenericTransactionCallbacks {
/** Called when the transaction is broadcasted (includes details about the offer) */
broadcasted?: (data: ISettlementTransactionPayload) => void;
/** Called when the transaction is minted (includes details about the settled escrow) */
confirmed?: (data: ApproveSettlementParsedPayload) => void;
}
/**
* Callbacks specific for settlement offer
*/
export interface ISettlementOfferTransactionCallbacks
extends IGenericTransactionCallbacks {
/** Called when the transaction is broadcasted (includes details about the offer) */
broadcasted?: (data: ISettlementTransactionPayload) => void;
/** Called when the transaction is minted (includes details about the escrow with the offer) */
confirmed?: (data: OfferSettlementParsedPayload) => void;
}
/**
*
*/
export interface IAddArbitratorTransactionPayload {
transactionHash: string;
}
export interface IChallengeTransactionPayload {
transactionHash: string;
}
/**
* Callbacks specific to sending a challenge
*/
export interface IChallengeTransactionCallbacks
extends IGenericTransactionCallbacks {
/** Called when the transaction is broadcasted (includes txn hash) */
broadcasted?: (data: IChallengeTransactionPayload) => void;
/** Called when the transaction is minted (includes details of the escrow after the challenge) */
confirmed?: (data: IChallengeTransactionPayload) => void;
}
/**
* Data provided to callbacks called from proposing or approving an arbitrator
*/
export interface IArbitrationTransactionPayload {
transactionHash: string;
/** Arbitrator's address sent in the proposal or approval */
arbitrator: string;
/** Arbitrator's fee sent in the proposal or approval */
arbitratorFee: number;
}
/**
* Data provided to callbacks called from arbitration
*/
export interface IArbitrateTransactionPayload {
transactionHash: string;
/** Buyer's share defined in the arbitration */
splitBuyer: number;
/** Seller's share defined in the arbitration */
splitSeller: number;
}
/**
* Callbacks specific to arbitrator-related functions
*/
export interface IArbitrationTransactionCallbacks
extends IGenericTransactionCallbacks {
/** Called when the transaction is broadcasted */
broadcasted?: (
data: IArbitrationTransactionPayload | IArbitrateTransactionPayload,
) => void;
/** Called when the transaction is minted */
confirmed?: (
data:
| ProposalArbitratorParsedPayload
| ApproveArbitratorParsedPayload
| ArbitrateParsedPayload,
) => void;
}
/**
* Provided in the refund callbacks
*/
export interface IRefundTransactionPayload {
transactionHash: string;
}
/**
* Refund-specific callbacks
*/
export interface IRefundTransactionCallbacks
extends IGenericTransactionCallbacks {
/** Called when the transaction is broadcasted (includes txn hash) */
broadcasted?: (data: IRefundTransactionPayload) => void;
/** Called when the transaction is minted (includes detailed escrow data after the refund) */
confirmed?: (data: IRefundTransactionPayload) => void;
}
/**
* Provided in the claim callbacks
*/
export interface IClaimTransactionPayload {
transactionHash: string;
}
/**
* Claim-specific callbacks
*/
export interface IClaimTransactionCallbacks
extends IGenericTransactionCallbacks {
/** Called when the transaction is broadcasted (includes txn hash) */
broadcasted?: (data: IClaimTransactionPayload) => void;
/** Called when the transaction is minted (includes detailed escrow data after the claim) */
confirmed?: (data: IClaimTransactionPayload) => void;
}
export interface IPaymentModalProps {
paymentProps: IPaymentProps;
deferredPromise: Deferred<any>;
callbacks?: IPayTransactionCallbacks;
}
export interface IReleaseModalProps {
escrowId: number;
deferredPromise: Deferred<any>;
callbacks?: IReleaseTransactionCallbacks;
}
export interface IRefundModalProps {
escrowId: number;
deferredPromise: Deferred<any>;
callbacks?: IRefundTransactionCallbacks;
}
export interface IChallengeModalProps {
escrowId: number;
deferredPromise: Deferred<any>;
callbacks?: IChallengeTransactionCallbacks;
}
export interface IArbitrationModalProps {
escrowId: number;
deferredPromise: Deferred<any>;
callbacks?: IArbitrationTransactionCallbacks;
}
export type tConnectedUser =
| "buyer"
| "seller"
| "arbitrator"
| "marketplace"
| "other";
/**
* Information about user's balance in an escrow at its current state
*/
export interface IBalance {
/** Amount in ETH's or token's WEI */
amount: string;
/** Amount converted to USD (using Coingecko's API on the client side) */
amountInUSD?: string;
/** Information about the token */
token?: IToken;
/** Whether the balance is still waiting for the challenge period to end, or is ready to claim */
status: "Pending" | "Ready to claim";
}
export interface IBalanceResponse {
pending: IBalance[];
readyForClaim: IBalance[];
}
/**
* More detailed information about user's balance in an escrow
*/
export interface IBalanceWithTokenInfo extends IBalance {
/** Amount converted to human readable form */
displayableAmount: string | BigNumberJs;
/** Helper field used when calculating with other BigNumber fields */
amountBN: BigNumberJs;
/** User's role in the escrow ('buyer' | 'seller' | 'arbitrator' | 'marketplace' | 'other') */
connectedUser: tConnectedUser;
/** Address of the connected user */
connectedWallet: string;
/** Indicates status of the payment (PAID | UNPAID | RELEASED | PERIOD_EXPIRED | REFUNDED | CHALLENGED | SETTLED) */
statusEscrow: IEscrowStatus;
}
/**
* The indexer returns user's contract balance in this structure. Also,
* SDK's modal to claim user's balance consumes this as an input to display the balance for the user before claiming
*
* @example How returned values might look like for pending and claimable ETH/USDT/USDC balance
* {
* pending: [
* {
* token: {
* address: "0x0000000000000000000000000000000000000000",
* symbol: "ETH",
* decimals: 18
* },
* status: "Pending",
* amount: "1586200000000000000",
* total: "1586200000000000000",
* displayableAmount: "1.5862",
* amountBN: "1.5862"
* }
* ],
* readyForClaim: [
* {
* token: {
* address: "0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8",
* symbol: "USDC",
* decimals: 6
* },
* status: "Ready to claim",
* amount: "1786200000",
* total: "1786200000",
* displayableAmount: "1786.2",
* amountBN: "1786.2"
* },
* {
* token: {
* address: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
* symbol: "USDT",
* decimals: 6
* },
* status: "Ready to claim",
* amount: "2379300000",
* total: "2379300000",
* displayableAmount: "2379.3",
* amountBN: "2379.3"
* }
* ]
* }
*/
export interface GetResponseUserBalance {
/** Balance in escrows where the challenge period hasn't ended yet */
pending: IBalanceWithTokenInfo[];
/** Balance that can be claimed from the contract */
readyForClaim: IBalanceWithTokenInfo[];
}
export interface IClaimMultipleModalProps {
escrowIds: number[];
balances: GetResponseUserBalance;
deferredPromise: Deferred<any>;