Skip to content

Commit 8cb8c04

Browse files
committed
up - up - update
1 parent 8d46c78 commit 8cb8c04

File tree

1 file changed

+40
-5
lines changed

1 file changed

+40
-5
lines changed

pages/express-relay/integrate-as-protocol.mdx

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Steps } from 'nextra/components'
2+
13
# How to Integrate Express Relay as a Protocol
24

35
This guide explains how to integrate Express Relay as a protocol.
@@ -39,13 +41,16 @@ Then add the following line to `remappings.txt` file:
3941

4042
### Modifying the Protocol's Contract
4143

44+
The protocol's contract needs to be updated to:
45+
46+
1. Consume `isPermissioned` method from `IExpressRelay` interface to Permit Express Relay transactions.
47+
1. Implement the `IExpressRelayFeeReceiver` interface to receive funds from Express Relay.
4248

43-
`IExpressRelay` interface exposes the `isPermissioned` function to check if Express Relay can liquidate a position.
49+
#### Permit Express Relay Transactions
4450

4551
The `isPermissioned` function takes two arguments:
4652
1. `protocolFeeReceiver`: The address of the protocol's contract. If the protocol's contract is the contract that receives fees from the Express Relay server, this should be the address of that contract. (IS IT WORTH MENTIONING HERE????)
47-
2. `permissionId`: A unique identifier for the liquidation opportunity.
48-
53+
1. `permissionId`: A unique identifier for the liquidation opportunity.
4954

5055
```solidity copy
5156
import "@pythnetwork/express-relay-sdk-solidity/IExpressRelay.sol";
@@ -64,9 +69,24 @@ require(
6469
```
6570

6671

72+
#### Set up Fee Receiver
73+
74+
The `IExpressRelayFeeReceiver` interface requires the protocol's contract to implement the `receiveAuctionProceedings` function. The Express Relay server calls this function to send funds to the protocol's contract.
75+
76+
```solidity copy
77+
interface IExpressRelayFeeReceiver {
78+
function receiveAuctionProceedings(
79+
bytes calldata permissionKey
80+
) external payable;
81+
}
82+
```
83+
84+
85+
86+
6787

6888

69-
The following code snippet shows a sample liquidation how to update the protocol's contract to permit Express Relay transactions:
89+
The following code snippet shows a sample liquidation method and updates to the protocol's contract to permit Express Relay transactions:
7090

7191
```solidity showLineNumbers {1,2,12,14,39-43} copy
7292
import "@pythnetwork/express-relay-sdk-solidity/IExpressRelay.sol";
@@ -102,6 +122,7 @@ contract EasyLend is IExpressRelayFeeReceiver {
102122
function liquidate(uint256 vaultID) public {
103123
Vault memory vault = _vaults[vaultID];
104124
uint256 vaultHealth = _getVaultHealth(vault);
125+
// Proceed only if the vault health is below the minimum health ratio
105126
if (vaultHealth >= vault.minHealthRatio) {
106127
revert InvalidLiquidation();
107128
}
@@ -120,5 +141,19 @@ contract EasyLend is IExpressRelayFeeReceiver {
120141
_vaults[vaultID].amountDebt = 0;
121142
}
122143
144+
/**
145+
* @notice receiveAuctionProceedings function - receives native token from the express relay
146+
* You can use permission key to distribute the received funds to users who got liquidated, LPs, etc...
147+
*
148+
* @param permissionKey: permission key that was used for the auction
149+
*/
150+
function receiveAuctionProceedings(
151+
bytes calldata permissionKey
152+
) external payable {
153+
emit VaultReceivedETH(msg.sender, msg.value, permissionKey);
154+
}
155+
123156
}
124-
```
157+
```
158+
159+

0 commit comments

Comments
 (0)