Skip to content

Commit 0db80cd

Browse files
committed
feat: major reorg of docs
1 parent b744822 commit 0db80cd

File tree

11 files changed

+554
-441
lines changed

11 files changed

+554
-441
lines changed

astro.config.mjs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,18 @@ export default defineConfig({
4747
},
4848
},
4949
{
50-
label: "Protocol",
50+
label: "V1: Cross-Chain AMM",
5151
autogenerate: {
5252
directory: "protocol",
5353
},
5454
},
55+
{
56+
label: "Cross-Cats: Cross-Chain Intents",
57+
badge: "Closed Alpha",
58+
autogenerate: {
59+
directory: "cross-cats",
60+
},
61+
},
5562
{
5663
label: "Generalised Incentives",
5764
autogenerate: {
@@ -66,7 +73,6 @@ export default defineConfig({
6673
},
6774
{
6875
label: "Underwriter",
69-
badge: "Open Beta!",
7076
autogenerate: {
7177
directory: "underwriter",
7278
},

public/d2/docs/protocol/v2/solving-0.svg renamed to public/d2/docs/cross-cats/cross-cats-0.svg

Lines changed: 22 additions & 22 deletions
Loading

public/d2/docs/protocol/liquidity-pools-0.svg

Lines changed: 203 additions & 203 deletions
Loading

public/d2/docs/protocol/tx-lifecycle-0.svg

Lines changed: 173 additions & 173 deletions
Loading
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
title: "ERC7863 Compatible"
3+
description: "Cross Cats is ERC7863 compatible with a few non-breaking changes."
4+
sidebar:
5+
order: 2
6+
---
7+
8+
Catalyst is [ERC-7683](https://eips.ethereum.org/EIPS/eip-7683)* compatible. *The implementation differs in 2 ways:
9+
10+
1. A Catalyst [OrderKey](https://github.com/catalystdao/cross-cats/blob/7e07281eef10ffadc10f9f75eb42d1c2419224ca/src/interfaces/Structs.sol#L41-L65) is returned on `initiate(...)`. For implementations that wants to verify that orders were correctly collected, this adds options for further data validation. This change is compatible with ERC-7683 since it does not change any function signatures and ERC-7683 specifies that the function has no return.
11+
2. ERC-7683 defines the 2 elements of `Output`, `token` and `recipient` to be type `address`. The type of both elements have been changed to `bytes32`. Solidity ABI encoding encodes structs elements such that they fill 32 bytes. As a result, all returned objects of `ResolvedCrossChainOrder` remains compatible with implementations that assumes these are `address` (except these values are truncated).
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
title: "Asset Delivery Callbacks"
3+
description: "Cross-Cats supports callbacks on both output delivery and input delivery."
4+
sidebar:
5+
order: 101
6+
---
7+
8+
Cross-Cats supporting making external on delivery of assets. However, there are several important implementation quirks that you need to be aware of.
9+
10+
```solidity
11+
// SPDX-License-Identifier: MIT
12+
pragma solidity >=0.8.0;
13+
14+
/**
15+
* @notice Implement callback handling for Cross cats payouts, both outputs and inputs.
16+
* @dev Callbacks are opt-in. If you opt-in, take care to not revert.
17+
* Funds are likely in danger if the calls revert. Please be careful.
18+
*
19+
* If you don't need this functionality, stay away.
20+
* To enable for outputs, set `remoteCall` to the calldata. recipient is called.
21+
* To enable for inputs, use fillerData version 2. You set a hash of the data.
22+
* The first 20 bytes of the data is called.
23+
*/
24+
interface ICrossCatsCallback {
25+
/**
26+
* @notice If configured, is called when the output is filled on the destination chain.
27+
* @dev If the transaction reverts, 1 million gas is provided.
28+
* If the transaction doesn't revert, only enough gas to execute the transaction is given + a buffer of 1/63'th.
29+
* The recipient is called.
30+
* If the call reverts, funds are still delivered to the recipient.
31+
* Please ensure that funds are safely handled on your side.
32+
*/
33+
function outputFilled(bytes32 token, uint256 amount, bytes calldata executionData) external;
34+
35+
/**
36+
* @notice If configured, is called when the input is sent to the filler.
37+
* May be called for under the following conditions:
38+
* - The inputs is purchased by someone else (/UW)
39+
* - The inputs are optimistically refunded.
40+
* - Output delivery was proven.
41+
*
42+
* You can use this function to add custom conditions to purchasing an order / uw.
43+
* If you revert, your order cannot be purchased.
44+
* @dev If this call reverts / uses a ton of gas, the data has to be modified (modifyOrderFillerdata)
45+
* This function can ONLY be called by the filler itself rather than anyone.
46+
* If the fillerAddress is unable to call modifyOrderFillerdata, take care to ensure the function
47+
* never reverts as otherwise the inputs are locked.
48+
*
49+
* executionData is never explicitly provided on chain, only a hash of it is. If this is not
50+
* publicly known, it can act as a kind of secret and people cannot call the main functions.
51+
* If you lose it you will have to call modifyOrderFillerdata which only the registered filler can.
52+
*
53+
* The address to call is the first 20 bytes of the data to execute.
54+
*
55+
* @param orderKeyHash Hash of the order key. Can be used for identification.
56+
* @param executionData Custom data that the filler asked to be provided with the call.
57+
*/
58+
function inputsFilled(bytes32 orderKeyHash, bytes calldata executionData) external;
59+
}
60+
```
61+
62+
(WIP)
63+
64+
## Output delivery
65+
66+
## Input Delivery
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
title: "Cross Cats: Solving Liquidity x Bitcoin"
33
description: "Catalyst v2 will support Bitcoin swaps. This is facilitated through intent based swaps that are verified through an on-chain Bitcoin SPV client. This provides: Fast settlement, Competitive rates, and near full security."
44
sidebar:
5-
order: 7
5+
order: 1
66
---
77

88
Cross-Cats is an intent-based cross-chain swap protocol built with flexibility in mind. The core idea is to allow anyone to create a request for anything provable. At launch, EVM settlements and Bitcoin transactions will be part of the provable set. Bitcoin transactions are proven using a Bitcoin SPV (light client) and allows VM chain payments to be conditional on Bitcoin transactions.
99

1010

11-
```d2 animateInterval=10000
11+
```d2 animateInterval=5000
1212
style.fill: transparent
1313
direction: right
1414
Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
11
---
22
title: "Becoming a Cross Cats solver"
3-
description: "Cross Cats allows solvers to collect order flow to and from various VM chains and to and from Bitcoin. Compared to competing solution, capital hungry solvers can sacrafise some margin on quick payouts by using the underwriting network to their advantage."
3+
description: "Cross Cats allows solvers to collect order flow to and from various VM chains and to and from Bitcoin. Compared to competing solution, capital hungry solvers can improve their capital turnaround by using the underwriting network to their advantage."
44
sidebar:
5-
order: 8
5+
order: 3
66
---
77

88
import { Tabs, TabItem } from '@astrojs/starlight/components';
9-
import GetQuotes from '../../../../components/solver/GetQuotes.svelte';
9+
import GetQuotes from '../../../components/solver/GetQuotes.svelte';
1010

1111
If you aren't interested in the order structure in Solidity, skip to [From VM](#from-evm). For API documentation, refer to the [API Swagger documentation](https://catalyst-order-server-0140d799e2f7.herokuapp.com/api
1212
).
1313

14-
Catalyst is [ERC-7683](https://www.erc7683.org)* compatible. *The implementation differs in 2 ways:
15-
16-
1. A Catalyst [OrderKey](https://github.com/catalystdao/cross-cats/blob/7e07281eef10ffadc10f9f75eb42d1c2419224ca/src/interfaces/Structs.sol#L41-L65) is returned on `initiate(...)`. For implementations that wants to verify that orders were correctly collected, this adds options for further data validation. This change is compatible with ERC-7683 since it does not change any function signatures and ERC-7683 specifies that the function has no return.
17-
2. ERC-7683 defines the 2 elements of `Output`, `token` and `recipient` to be type `address`. The type of both elements have been changed to `bytes32`. Solidity ABI encoding encodes structs elements such that they fill 32 bytes. As a result, all returned objects of `ResolvedCrossChainOrder` remains compatible with implementations that assumes these are `address` (except these values are truncated).
18-
1914
Cross Cats uses 3 order structures:
2015
1. [CrossChainOrder](https://github.com/catalystdao/cross-cats/blob/7e07281eef10ffadc10f9f75eb42d1c2419224ca/src/interfaces/ISettlementContract.sol#L6-L27) is a generic **input** order with an ERC-7683 compatible structure. Importantly, orderData contains the secret sauce and surely differs between ERC-7683 supporting implementations.
21-
2. [ResolvedCrossChainOrder](https://github.com/catalystdao/cross-cats/blob/7e07281eef10ffadc10f9f75eb42d1c2419224ca/src/interfaces/ISettlementContract.sol#L29-L52) is a **quote** description that describes the value of a cross-chain order at a specific moment in time. It is ERC-7683 compliant* and allows solvers to easily compare resolution of order across protocols.
22-
3. Catalyst [OrderKey](https://github.com/catalystdao/cross-cats/blob/7e07281eef10ffadc10f9f75eb42d1c2419224ca/src/interfaces/Structs.sol#L41-L65) are used to keep track of a Catalyst order through its **lifetime**. It contains Catalyst specific context and describes orders in depth. The hash of this struct is used to index the state progress of orders.
16+
2. [ResolvedCrossChainOrder](https://github.com/catalystdao/cross-cats/blob/7e07281eef10ffadc10f9f75eb42d1c2419224ca/src/interfaces/ISettlementContract.sol#L29-L52) is a **quote** description that describes the value of a cross-chain order at a specific moment in time. It is ERC-7683 compliant[*](/cross-cats/erc7683) and allows solvers to easily compare resolution of order across protocols.
17+
3. Catalyst [OrderKey](https://github.com/catalystdao/cross-cats/blob/7e07281eef10ffadc10f9f75eb42d1c2419224ca/src/interfaces/Structs.sol#L41-L65) are used to keep track of a Catalyst order through its **lifetime**. It contains Catalyst specific context and describes orders in depth.
2318

24-
The generic CrossChainOrder can be seen below. `CrossChainOrder.orderData` is an ABI encoded order struct.
19+
The generic ERC7683 CrossChainOrder can be seen below. `CrossChainOrder.orderData` is an ABI encoded order struct.
2520
```solidity
2621
struct CrossChainOrder {
2722
address settlementContract;
@@ -34,21 +29,20 @@ struct CrossChainOrder {
3429
}
3530
```
3631

37-
Currently, Cross-Cats supports 2 order structs:
32+
Importantly, the field `orderData` is encoded uniquely by Cross-Cats. Currently, 2 order structs are supported:
3833
```solidity
39-
/// @notice Supports many inputs (same chain) to many outputs (different chains)
34+
/// @notice Simpler and slightly cheaper for order types with fixed inputs and outputs.
4035
struct LimitOrderData {
4136
uint32 proofDeadline;
4237
uint32 challengeDeadline;
4338
address collateralToken;
4439
uint256 fillerCollateralAmount;
4540
uint256 challengerCollateralAmount;
4641
address localOracle;
47-
bytes32 remoteOracle;
4842
Input[] inputs;
49-
Output[] outputs;
43+
OutputDescription[] outputs;
5044
}
51-
/// @notice Supports Dutch Auctions on both input and output (1 to 1).
45+
/// @notice Supports Dutch Auctions on both input and output and support for additional custom order verification.
5246
struct DutchOrderData {
5347
bytes32 verificationContext;
5448
address verificationContract;
@@ -58,29 +52,39 @@ struct DutchOrderData {
5852
uint256 fillerCollateralAmount;
5953
uint256 challengerCollateralAmount;
6054
address localOracle;
61-
bytes32 remoteOracle;
6255
uint32 slopeStartingTime;
63-
int256 inputSlope;
64-
int256 outputSlope;
65-
Input input;
66-
Output output;
56+
/// @dev Input rate of change.
57+
int256[] inputSlopes;
58+
/// @dev Output rate of change.
59+
int256[] outputSlopes;
60+
Input[] inputs;
61+
OutputDescription[] outputs;
6762
}
6863
69-
// With the input and output struct defined as:
64+
// With the input and output structs defined as:
7065
struct Input {
7166
address token;
7267
uint256 amount;
7368
}
74-
struct Output {
69+
70+
struct OutputDescription {
71+
/// @dev Contract on the destination that tells whether an order was filled.
72+
/// Format is bytes32() slice of the encoded bytearray from the messaging protocol (or bytes32(0) if local)
73+
bytes32 remoteOracle;
74+
/// @dev The address of the ERC20 token on the destination chain
75+
/// @dev address(0) used as a sentinel for the native token
7576
bytes32 token;
77+
/// @dev The amount of the token to be sent
7678
uint256 amount;
79+
/// @dev The address to receive the output tokens
7780
bytes32 recipient;
81+
/// @dev The destination chain for this output
7882
uint32 chainId;
83+
bytes remoteCall;
7984
}
8085
```
8186

82-
Users will generate a `CrossChainOrder` with the appropriate order data and sign them with Permit2, generating an approval & order description with a single signature. The signed struct with be a new struct where `
83-
orderData` will be of the order type struct.
87+
Users will generate a `CrossChainOrder` with the appropriate order data and sign it with Permit2, thus generating an approval & order description with a single signature. The signed struct with be a new struct where `orderData` will be an abi.encoded order type.
8488

8589
## From EVM
8690

@@ -99,17 +103,18 @@ The order server stores orders in their dictionary format. This allows integrato
99103
// Lets define the 2 Order data types.
100104
type DutchAuctionData = {
101105
type: "DutchAuction", // should not be submitted on-chain but can be used to differentiate order types.
106+
verificationContext: string;
107+
verificationContract: string;
102108
proofDeadline: number,
103109
challengeDeadline: number,
104110
collateralToken: string,
105111
fillerCollateralAmount: string,
106112
challengerCollateralAmount: string,
107113
localOracle: string,
108-
remoteOracle: string,
109114
slopeStartingTime: number,
110-
inputSlope: string,
111-
outputSlope: string,
112-
inputs: {}[], // Even though `inputs` is provided as an array, to submit on-chain it needs to be provided as a single input named `input`
115+
inputSlopes: string[],
116+
outputSlopes: string[],
117+
inputs: {}[],
113118
outputs: {}[]
114119
}
115120

@@ -121,7 +126,6 @@ type LimitOrderData = {
121126
fillerCollateralAmount: string,
122127
challengerCollateralAmount: string,
123128
localOracle: string,
124-
remoteOracle: string,
125129
inputs: {}[],
126130
outputs: {}[]
127131
}
@@ -141,7 +145,7 @@ const API_URL = "https://orders.catalyst.exchange/"
141145

142146
type GetOrderData = {
143147
order: CrossChainOrder,
144-
orderKeyHash: string | undefined, // initially but will become always defined.
148+
orderKeyHash: string
145149
quote: {
146150
fromAssets: string[],
147151
toAssets: string[],
@@ -334,7 +338,7 @@ Asset delivery depends on whether the destination is a VM chain or Bitcoin. For
334338

335339
### EVM deliveries
336340

337-
Call the destination chain oracle `GetOrderData.order.orderData.remoteOracle`. You can get remote chain from each output `GetOrderData.order.orderData.outputs[].chainId`.
341+
Call the destination chain oracle `GetOrderData.order.orderData.outputs[].remoteOracle` on the remote chain `GetOrderData.order.orderData.outputs[].chainId`.
338342

339343
<Tabs syncKey="lang">
340344
<TabItem label="Typescript">
@@ -350,14 +354,18 @@ const oracleAbi = "...";
350354
// For simplicity, this function assumes that all outputs goes to
351355
// the same chain but it may not be the case.
352356
async function fillSingleChainOrder(order: CrossChainOrder) {
353-
const oracle = new ethers.Contract(order.orderData.remoteOracle, oracleAbi, signer);
354357

355358
let recordedChain;
359+
let recordedOracle;
356360
for (const output of order.orderData.outputs) {
357361
if (recordedChain === undefined) recordedChain = output.chainId;
362+
if (recodedOracle === undefined) recodedOracle = output.remoteOracle
358363
if (recordedChain !== output.chainId)
359364
throw Error(`Mixed ChainIds, seen ${recordedChain} and ${output.chainId}`);
365+
if (recodedOracle !== output.remoteOracle)
366+
throw Error(`Mixed Oracles, seen ${recodedOracle} and ${output.remoteOracle}`);
360367
}
368+
const oracle = new ethers.Contract(recordedOracle, oracleAbi, signer);
361369

362370
// TODO: Set approvals for the oracleAddress for the value of the output.
363371

@@ -383,17 +391,22 @@ oracleAbi = "...";
383391
# For simplicity, this function assumes that all outputs goes to the same chain but it may not be the case.
384392
def fill_single_chain_order(order):
385393
oracle_address = order['orderData']['remoteOracle']
386-
oracle = web3.eth.contract(address=oracle_address, abi=oracle_abi)
387394

388395
recordedChain = "";
396+
recordedOracle = "";
389397
for (output in order['orderData']['outputs']):
390398
if (recordedChain == ""):
391399
recordedChain = output.chainId
400+
if (recordedOracle == ""):
401+
recordedOracle = output.remoteOracle
392402
if (recordedChain != output.chainId):
393403
raise Exception(f"Mixed ChainIds, seen {recordedChain} and {output.chainId}");
404+
if (recordedOracle != output.remoteOracle):
405+
raise Exception(f"Mixed Oracles, seen {recordedOracle} and {output.remoteOracle}");
394406

395-
# TODO: Set approvals for the oracleAddress for the value of the output.
407+
oracle = web3.eth.contract(address=recordedOracle, abi=oracle_abi)
396408

409+
# TODO: Set approvals for the oracleAddress for the value of the output.
397410

398411
# We need to provide fill times. These have to be set to proofTime.
399412
# These are used to ensure you can't reuse fills.
@@ -420,7 +433,7 @@ def fill_single_chain_order(order):
420433

421434
To identify whether an order contains a Bitcoin transaction, check the output token: `GetOrderData.order.orderData.outputs[].token`. If the output is Bitcoin, the following must hold:
422435
- The first 30 bytes should be equal to `0x000000000000000000000000BC0000000000000000000000000000000000`. Notice the 13'th byte is `0xBC`.
423-
- The 31'th byte is reserved and not checked.
436+
- The 31'th byte is the number of confirmations before the order can be verified on-chain. 0 implies 1.
424437
- The 32'th byte contains an address version identifier. Decode as uint8.
425438

426439
If the transaction is to Bitcoin, the address (`GetOrderData.order.orderData.outputs[].recipient`) will contain the relevant destination hash or witness which is not the address!
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
title: "Underwriting & Purchasing Orders"
3+
description: "Security, speed, and cost. Underwriting allows customizing these parameters exactly providing a 2 fold improvement: 1. Faster solver payouts allowing for greater capital velocity. 2. Faster user payouts improving the user experience."
4+
sidebar:
5+
order: 21
6+
---
7+
8+
Catalyst will support underwriting. In-code it is referred to as purchasing an order since this is exactly what happens.
9+
10+
When a filler is initiating
11+
12+
```solidity
13+
function purchaseOrder(OrderKey calldata orderKey, bytes calldata fillerData, uint256 minDiscount) external;
14+
````

0 commit comments

Comments
 (0)