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: pages/express-relay/how-express-relay-works.mdx
+1-2Lines changed: 1 addition & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,13 +10,12 @@ Express Relay solves the problem of MEV by providing protocol developers with an
10
10
Developers specify a set of operations in their protocol that must be accessed through Express Relay.
11
11
Searchers then participate in an off-chain auction to access these operations.
12
12
Their bids in the auction are used to determine the order in which their transactions will be executed.
13
-
The winners' transactions are forwarded to the Express Relay smart contract. As part of the transaction, searchers must pay their specified bid.
13
+
The winners' transactions are forwarded to the Express Relay smart contract. As part of the transaction, searchers must pay their specified bid.
14
14
The auction profits are then split between the integrated protocol and other participants in Express Relay.
15
15
16
16

17
17

18
18
19
-
20
19
The diagram above shows how Express Relay changes the MEV landscape for a liquidation.
21
20
In the status quo (above), Searchers tip miners to guarantee that their liquidation transaction lands on-chain and that their transaction directly interacts with the protocol, exposing the liquidation opportunity.
22
21
With Express Relay (down), Searchers submit bids for their transaction to the Express Relay auction.
The auction in Express Relay is held off-chain at the auction server.
4
-
Bids arrive at the auction server and compete against other bids, vying for the same [permission key](./permissioning.mdx).
3
+
The auction in Express Relay is held off-chain at the auction server.
4
+
Bids arrive at the auction server and compete against other bids, vying for the same [permission key](./permissioning.mdx).
5
5
A relayer selected by governance serves as the auctioneer and determines the auction in line with the criterion of maximizing the revenue shared back to the protocol that generated this opportunity. That means the auctioneer is expected to forward on-chain the subset of bids that maximizes the revenue back to the protocol.
6
6
7
7
Thus, the Express Relay auction is analogous to a sealed-bid auction, i.e., participants in the auction will not have the contents of their bid disclosed publicly unless they win the auction and are forwarded on-chain.
@@ -10,11 +10,12 @@ The forwarded subset of transactions is submitted on-chain and first processed b
10
10
11
11
Generally, the auction server expects bids to execute successfully on-chain. Falback bids are also forwarded in case of execution failures for the predicted winners.
12
12
13
-
The `ExpressRelay` contract extracts the payment of the specified bid amount only if the searcher's bid is successfully executed on-chain.
13
+
The `ExpressRelay` contract extracts the payment of the specified bid amount only if the searcher's bid is successfully executed on-chain.
14
14
Hence, the Express Relay auction can be seen as a generalization of a [first-price sealed-bid auction](https://en.wikipedia.org/wiki/First-price_sealed-bid_auction), in that multiple bids can win and pay their first price.
15
15
16
16
The revenue from the auction is shared amongst relevant stakeholders in the Express Relay system. These stakeholders include:
17
+
17
18
- the protocol that generates the relevant opportunity
18
19
- the relayer, which handles running the off-chain components of the system
19
20
20
-
The Express Relay contract enforces the exact revenue splits and is subject to change based on governance decisions.
21
+
The Express Relay contract enforces the exact revenue splits and is subject to change based on governance decisions.
Copy file name to clipboardExpand all lines: pages/express-relay/how-express-relay-works/opportunities.mdx
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Opportunities
2
2
3
-
In the context of Express Relay, an opportunity refers to a potential transaction that a searcher can execute on a protocol. Typically, the term "opportunity" is used for such transactions that are lucrative and therefore competed for by many searchers.
3
+
In the context of Express Relay, an opportunity refers to a potential transaction that a searcher can execute on a protocol. Typically, the term "opportunity" is used for such transactions that are lucrative and therefore competed for by many searchers.
4
4
5
5
In the pre-Express Relay world, opportunities therefore corresponded to MEV: a protocol generated MEV when an opportunity appeared on that protocol and searchers bid up the right to execute the opportunity at the validator level.
6
6
@@ -11,6 +11,7 @@ In the context of Express Relay, the value deriving from an opportunity no longe
11
11
Opportunities do not refer to only transactions that use an oracle. In truth, any transaction that is lucrative but limited (available to only the first user(s) who executes it) generates MEV. As a result, Express Relay and the opportunity schema have been designed to be oracle-agnostic.
12
12
13
13
Examples of opportunities include:
14
+
14
15
- liquidations
15
16
- open trade offers
16
17
- NFT mints
@@ -19,6 +20,7 @@ Examples of opportunities include:
19
20
## Opportunity Adapter
20
21
21
22
The Opportunity Adapter contract enables searchers to engage with opportunities from different protocols without needing to do any bespoke integration work per protocol. Instead of exposing lower-level fields determined by protocols (e.g. `amountCollateral`, `addressBorrower`), the Opportunity Adapter abstracts away the semantics of the opportunity and instead [exposes the fundamental traits](https://github.com/pyth-network/per/blob/30c3fc695034f518225f8255ebe8423604e8aca3/contracts/src/opportunity-adapter/Structs.sol#L20-L23) of any opportunity:
23
+
22
24
- the tokens sold by the searcher
23
25
- the tokens bought by the searcher
24
26
- the identity of the searcher executing this opportunity
`permissionId` is a `bytes` object that represents the unique identifying information of a position within the protocol. `permissionId` allows the system to distinguish between bids competing on different opportunities and thereby run more scoped and efficient auctions.
3
+
`permissionId` is a `bytes` object that represents the unique identifier of a position within the protocol. `permissionId` allows the system to distinguish between bids competing on different opportunities and thereby run more scoped and efficient auctions.
4
4
5
-
Each borrower has a unique position for some protocols, so the borrower address uniquely identifies a position.
6
-
In other protocols, each borrower might have multiple positions, distinguished by the address of the collateral asset or by a `uint256` ID number.
5
+
Each borrower has a unique position for some protocols, so the borrower address uniquely identifies a position.
6
+
In other protocols, each borrower might have multiple positions, distinguished by the address of the collateral asset or by a `uint256` ID number.
7
7
In those cases, the information set that uniquely identifies a position would include multiple fields.
8
8
9
-
`permissionId` can be the concatenation of all these fields in bytes format. You can call `abi.encode(){:solidity}` to concatenate these fields together.
9
+
`permissionId` can be the concatenation of all these fields in bytes format. You can call `abi.encode(){:solidity}` to concatenate these fields together.
10
10
11
11
For example, if a protocol featured a unique position per borrower, then it could form `permissionId` as
12
12
@@ -20,9 +20,9 @@ On the other hand, if a protocol allowed a borrower to open as many new position
The Express Relay contract uses the `permissionId` to toggle permissions for interacting with the protocol.
23
+
The Express Relay contract uses the `permissionId` to toggle permissions for interacting with the protocol.
24
24
This toggling is checked within the protocol's code to ensure that the current transaction is within the context of Express Relay so that the recaptured value can be returned to the protocol. In particular, the Express Relay contract checks the toggling of the `permissionKey`, which is the concatenation of the protocol address and the `permissionId`:
Copy file name to clipboardExpand all lines: pages/express-relay/index.mdx
+4-8Lines changed: 4 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,11 +9,11 @@ import CodeIcon from "../../components/icons/CodeIcon";
9
9
10
10
Express Relay is a priority auction that enables protocols to eliminate [Maximal Extractable Value](https://www.ledger.com/academy/glossary/maximal-extractable-value-mev) (MEV).
11
11
12
-
-**For Protocol Developers:** Express Relay allows protocols to recapture MEV and access a network of searchers.
13
-
With Express Relay, protocols don't need to spend time and energy bootstrapping a protocol-specific searcher network.
12
+
-**For Protocol Developers:** Express Relay allows protocols to recapture MEV and access a network of searchers.
13
+
With Express Relay, protocols don't need to spend time and energy bootstrapping a protocol-specific searcher network.
14
14
15
-
-**For Searchers:** Express Relay provides easy and unified access by aggregating liquidation and other MEV opportunities across integrated DeFi protocols.
16
-
Searchers integrate once and gain access to all existing and future opportunities.
15
+
-**For Searchers:** Express Relay provides easy and unified access by aggregating liquidation and other MEV opportunities across integrated DeFi protocols.
16
+
Searchers integrate once and gain access to all existing and future opportunities.
17
17
18
18
## Integration
19
19
@@ -50,7 +50,3 @@ To learn more about Express Relay, refer to the following resources:
@@ -16,7 +16,7 @@ To integrate with Express Relay, your protocol's contract must check if Express
16
16
<Steps>
17
17
### Install the Express Relay SDK
18
18
19
-
Pyth provides a [Solidity SDK](https://www.npmjs.com/package/@pythnetwork/express-relay-sdk-solidity) to help developers integrate Express Relay into their DeFi protocol.
19
+
Pyth provides a [Solidity SDK](https://www.npmjs.com/package/@pythnetwork/express-relay-sdk-solidity) to help developers integrate Express Relay into their DeFi protocol.
20
20
The SDK exposes [`IExpressRelay`](https://github.com/pyth-network/pyth-crosschain/blob/main/express_relay/sdk/solidity/IExpressRelay.sol) and [`IExpressRelayFeeReceiver`](https://github.com/pyth-network/pyth-crosschain/blob/main/express_relay/sdk/solidity/IExpressRelayFeeReceiver.sol) interfaces to interact with Express Relay.
21
21
22
22
<Tabsitems={['Hardhat', 'Foundry']}>
@@ -26,6 +26,7 @@ The SDK exposes [`IExpressRelay`](https://github.com/pyth-network/pyth-crosschai
@@ -48,20 +50,21 @@ Then add the following line to `remappings.txt` file:
48
50
The following steps show how to modify your protocol's contract to verify if the current transaction is permissioned by Express Relay and to receive the auction proceeds.
49
51
50
52
1. Call the [`isPermissioned`](https://github.com/pyth-network/pyth-crosschain/blob/main/express_relay/sdk/solidity/IExpressRelay.sol#L10C14-L10C28) method from `IExpressRelay` interface to make sure the current transaction is permissioned by Express Relay.
51
-
1. Implement the [`IExpressRelayFeeReceiver`](https://github.com/pyth-network/pyth-crosschain/blob/main/express_relay/sdk/solidity/IExpressRelayFeeReceiver.sol#L4) interface to **receive** auction proceeds.
53
+
1. Implement the [`IExpressRelayFeeReceiver`](https://github.com/pyth-network/pyth-crosschain/blob/main/express_relay/sdk/solidity/IExpressRelayFeeReceiver.sol#L4) interface to **receive** auction proceeds.
52
54
53
55
#### 1. Verify Permissioning
54
56
55
57
The `isPermissioned` function takes two arguments:
58
+
56
59
1.`protocolFeeReceiver`: The address to receive the protocol's share of auction proceeds.
57
60
1.`permissionId`: A unique identifier for the opportunity.
The `permissionId` represents a unique identifier of an opportunity.
78
-
For a liquidation opportunity, the vault address or ID could be concatenated into `bytes` format.
79
-
Consult [`Permissioning`](./how-express-relay-works/permissioning.mdx) for more information on generating permission IDs.
81
+
The `permissionId` represents a unique identifier of an opportunity. For a
82
+
liquidation opportunity, the vault address or ID could be concatenated into
83
+
`bytes` format. Consult
84
+
[`Permissioning`](./how-express-relay-works/permissioning.mdx) for more
85
+
information on generating permission IDs.
80
86
</Callout>
81
87
82
88
#### 2. Set up Fee Receiver
89
+
83
90
Express Relay will call the `receiveAuctionProceedings` method present in `IExpressRelayFeeReceiver`. The call will transfer the protocol's share of the auction proceeds to the `protocolFeeReceiver` address.
84
91
85
92
```solidity copy
86
93
interface IExpressRelayFeeReceiver {
87
-
function receiveAuctionProceedings(
88
-
bytes calldata permissionKey
89
-
) external payable;
94
+
function receiveAuctionProceedings(
95
+
bytes calldata permissionKey
96
+
) external payable;
90
97
}
98
+
91
99
```
92
100
93
101
The following code snippet shows a sample Express Relay-integrated contract that performs liquidation.
@@ -144,10 +152,10 @@ contract EasyLend is IExpressRelayFeeReceiver {
144
152
abi.encode(vaultID) // permissionId generated from the unique vault ID
@@ -166,8 +174,8 @@ contract EasyLend is IExpressRelayFeeReceiver {
166
174
167
175
}
168
176
```
169
-
</Steps>
170
177
178
+
</Steps>
171
179
172
180
## Expose Opportunities to Searchers
173
181
@@ -180,7 +188,7 @@ The JSON payload should contain opportunities in the following format:
180
188
```bash copy
181
189
{
182
190
"target_calldata": "0xdeadbeef", // Calldata to execute the opportunity
183
-
"chain_id": "op_sepolia",
191
+
"chain_id": "op_sepolia",
184
192
"target_contract": "0xcA11bde05977b3631167028862bE2a173976CA11", // Protocol contract address to call
185
193
"permission_key": "0xcafebabe", // Unique identifier for the opportunity
186
194
"target_call_value": "1", // Value (in Wei) to send to the protocol contract.
@@ -200,14 +208,12 @@ The JSON payload should contain opportunities in the following format:
200
208
}
201
209
```
202
210
203
-
204
211
Each protocol integrated with Express Relay must actively monitor for new opportunities.
205
212
Protocols can do this by indexing the chain, listening to protocol events, or querying protocol state through an RPC provider.
206
213
207
214
Check the [`monitor.ts`](https://github.com/pyth-network/pyth-crosschain/blob/main/express_relay/examples/easy_lend/src/monitor.ts) script,
208
215
which fetches opportunities for the below-mentioned [Easy Lend](https://github.com/pyth-network/pyth-crosschain/tree/main/express_relay/examples/easy_lend) example and exposes them to Express Relay for auction.
209
216
210
-
211
217
## Additional Resources
212
218
213
219
You may find these additional resources helpful for integrating Express Relay as a protocol.
@@ -227,4 +233,4 @@ The [Error Codes](./error-codes.mdx) page lists the error codes returned by Expr
227
233
228
234
### API Reference
229
235
230
-
The [API Reference](https://per-staging.dourolabs.app/redoc/) provides detailed information on Express Relay APIs for submitting opportunities.
236
+
The [API Reference](https://per-staging.dourolabs.app/redoc/) provides detailed information on Express Relay APIs for submitting opportunities.
0 commit comments