You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: src/content/docs/protocol/v2/solver.mdx
+76-8
Original file line number
Diff line number
Diff line change
@@ -184,9 +184,13 @@ def get_orders():
184
184
185
185
<GetQuotesclient:visible/>
186
186
187
-
#### Subscribe to orders
187
+
#### Subscribe to orders (WIP)
188
188
189
-
Order subscription is WIP. We are looking for feedback as to which methods are best.
189
+
This section is heavily work in progress and is very likely to be significantly changed. We are very open to feedback and exploring alternatives.
190
+
191
+
As an alternative to polling orders, you can also subscribe to new orders. The Catalyst order server exposes a websocket endpoint that broadcasts new orders as they arrive. This significantly decreases latency at the cost of increased complexity.
192
+
193
+
Unlike the API endpoint, orders delivered over the websocket connected are not filterable. It is assumed that the consumer will filter orders locally.
190
194
191
195
### Evaluate Orders
192
196
@@ -430,6 +434,7 @@ If the transaction is to Bitcoin, the address (`getOrderData.order.orderData.out
430
434
<th>Name</th>
431
435
<th>Encoding Scheme</th>
432
436
<th>Prefix</th>
437
+
<th>Hash Length</th>
433
438
</tr>
434
439
</thead>
435
440
<tbody>
@@ -438,36 +443,42 @@ If the transaction is to Bitcoin, the address (`getOrderData.order.orderData.out
438
443
<td>Unknown</td>
439
444
<td>Ignore</td>
440
445
<td></td>
446
+
<td></td>
441
447
</tr>
442
448
<tr>
443
449
<td>1</td>
444
450
<td>P2PKH</td>
445
451
<td>Base58Check(00+PKH)</td>
446
452
<td>1*</td>
453
+
<td>20</td>
447
454
</tr>
448
455
<tr>
449
456
<td>2</td>
450
457
<td>P2SH</td>
451
458
<td>Base58Check(05+SH)</td>
452
459
<td>3*</td>
460
+
<td>20</td>
453
461
</tr>
454
462
<tr>
455
463
<td>3</td>
456
464
<td>P2WPKH</td>
457
465
<td>Bech32</td>
458
466
<td>b1cq</td>
467
+
<td>20</td>
459
468
</tr>
460
469
<tr>
461
470
<td>4</td>
462
471
<td>P2WSH</td>
463
472
<td>Bech32</td>
464
473
<td>b1cq</td>
474
+
<td>32</td>
465
475
</tr>
466
476
<tr>
467
477
<td>5</td>
468
478
<td>P2TR</td>
469
479
<td>Bech32m</td>
470
480
<td>b1cp</td>
481
+
<td>32</td>
471
482
</tr>
472
483
</tbody>
473
484
</table>
@@ -485,30 +496,87 @@ Once the address is generate, make a transaction that has an **exact** output th
485
496
486
497
## From Bitcoin
487
498
488
-
### Quote Open Order
499
+
While Bitcoin has scripts, Bitcoin scripts are only contains spending conditions so unlike a VM chain, we can't pull funds from the user after a signed message. As a result, the order flow is flipped and the solver signed the VM order.
500
+
501
+
#### Encoding a Bitcoin Address
502
+
503
+
Your solver needs to be able to generate a Bitcoin deposit address. It is technically possible to use the same address for every single order. If you do this, it is very important that the amounts are unique for every single order. It is recommended to use different addresses for every order. Bitcoin does not charge extract to collect UTXOs from different addresses.
489
504
490
-
Unlike forVM, to solve Bitcoin to EVM orders you need to be able to submit quotes to the UI. The UI may request a quote from you.
505
+
The Bitcoin address is encoded in2 fields: `token`and`address`. The token field is used to block tokens from filling Bitcoin orders andto encode the address version. See this [table](#bitcoin-deliveries) for converting address types to versions.
491
506
492
-
TODO: Some endpoint that includes an approximate quote.
507
+
The `address`is used to encode either the public key hash, script hash, or witness hash. The table mentioned above contains the encoding schemes for various Bitcoin address versions. Hashes of 20bytes (P2PKH, P2SH, andP2WSH) should be padded with0s on the right side. (`0xabcdef...00000`)
493
508
494
-
### Return Signed Orders
509
+
### Quote Open Order (WIP)
510
+
511
+
Solvers forBTC to VM needs to be able to quote orders for comparison with other solvers. To start quoting, solvers needs to subscribe to requests quote from the order server. Upon requests for quotes, the solver needs to respond with a quote. The quote needs to be valid for at least 60 seconds. (30 second quote life, 30 order life)
512
+
513
+
If a quote is issued, the solver needs to be able to respond with a signed order. If the solver doesn't respond with the same (or better) order when the order is requested within 30 seconds, the solver may be blacklisted.
514
+
515
+
```typescript
516
+
//TODO: make this proper logic rather than pseudo-logic.
517
+
const websocketServer;
518
+
//1. Define an evaluation logic. This evaluation logic may
519
+
// be as simple as either accepting or rejecting the order
520
+
// based on the reference rate.
521
+
function orderEvaluations(order: any): any| undefined {...}
522
+
//2. Subscribe to the Quotes
523
+
websocketServer.onRequestForQuote((order) => {
524
+
const quoted = orderEvaluations(order);
525
+
if (quoted !== undefined)
526
+
//3. Respond to the request for quote.
527
+
websocketServer.respond(quoted);
528
+
});
529
+
```
495
530
496
-
TODO: If you are chosen to be the solver for the Bitcoin to VM order, you need to generate a signed order. This works opposite of the flow forVM chains where the user would be the one signing orders. This may seem riskier but don't worry. We will make the order exclusive to the user & the UI's executor. This is important since the Cross Cats UI can guarantee that the assets will be delivered through a UI controlled but user owned Bitcoin address.
531
+
### Return Signed Orders (WIP)
497
532
498
-
## Prove Orders
533
+
The UI compares all received quotes from solvers and chooses the quote from the best solver. Once the user's deposit is confirmed, the UI requests the solver for a signed order. The signer has to send back a signed order that matches with quote given (within expiry). It is important that the returned order is exclusive to the user & the UI's executor (see code). This is important since the Cross Cats UI can guarantee that the assets will be delivered through a UI controlled but user owned Bitcoin address.
534
+
535
+
```typescript
536
+
const websocketServer;
537
+
//1. We need to sign the order request.
538
+
// Importantly, we also need to validate that this is a valid
539
+
// request.
540
+
function signOrderRequest(signOrderRequest: any): any| undefined {
if (evaluationResponse === undefined) return undefined;
543
+
...
544
+
}
545
+
//2. Listen to request for signed orders
546
+
websocketServer.onRequestForOrder((request) => {
547
+
const signedOrder = signOrderRequest(order);
548
+
if (quoted === undefined) {
549
+
//3. Respond to the request for quote.
550
+
websocketServer.respond("no");
551
+
} else {
552
+
websocketServer.respond(signedOrder);
553
+
}
554
+
});
555
+
```
556
+
557
+
Once
558
+
559
+
## Prove Orders (WIP)
499
560
500
561
If a Solvers' orders get challenged, they need to prove delivery. In exchange for these proofs, Solvers collect the collateral provided by Challengers.
501
562
563
+
Initially, Cata Labs will prove every single order for completeness.
564
+
502
565
503
566
## Challenger
504
567
505
568
Challengers work to ensure that solvers stay honest. Solvers submit collateral when claiming transaction. If Solvers aren't honest, Challengers can claim the collateral if they prove that Solvers havn't done settled their claimed orders.
506
569
570
+
Initially, Cata Labs will prove every single order for completeness.
507
571
508
572
## Broadcast Orders
509
573
510
574
The first step of any order is broadcasting it. For solvers this can be seen as the 0'th step, since it is required before solvers can collect the orders from the order server.
511
575
576
+
:::tip[Proof of Work]
577
+
Submitting orders can easily be used to DDoS the order server. As a protection, the order server requires submitting a piece of PoW to rate-limit submissions.
0 commit comments