Skip to content

Commit 31eb98f

Browse files
committed
finalize opportunity adapter docs dump
1 parent 703c905 commit 31eb98f

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

pages/express-relay/how-express-relay-works/opportunities.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ The Opportunity Adapter contract enables searchers to engage with opportunities
2727

2828
Thus, the Opportunity Adapter unifies the disparate interfaces of different protocols with respect to their different opportunities. This unification in a single interface is what makes Express Relay an opportunity hub connecting protocols and searchers.
2929

30+
To use the Opportunity Adapter workflow, a searcher submits a bid with the target contract set to the `OpportunityAdapterFactory` contract. Each searcher has their own `OpportunityAdapter` contract per chain that is created when they first interact with `OpportunityAdapterFactory`. The factory contract then routes the transaction of a searcher to its corresponding `OpportunityAdapter` contract.
31+
3032
### Permit2
3133

3234
The `OpportunityAdapter` contract uses the [Permit2](https://github.com/Uniswap/permit2) token approval system, which handles the validation of a searcher's signature. Permit2 enables users to authorize token approvals for specific transaction data. In combination with Permit2, `OpportunityAdapter` allows a searcher to authorize use of their tokens only with a call to a particular contract with specified calldata and conditional on receipt of a set of specified `buyTokens`.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ The integration consists of 2 main steps:
88

99
- Integrate your searcher service with the [auction server](./integrate-as-searcher/auction-server)
1010
- \[Optional\] Use [OpportunityAdapter](./integrate-as-searcher/opportunity-adapter) and setup a wallet with the necessary tokens and approvals
11+
12+
You can also find a list of relevant contract addresses [here](./contract-addresses).

pages/express-relay/integrate-as-searcher/auction-server.mdx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,20 +146,26 @@ If you prefer to use your own custom contracts rather than the `OpportunityAdpat
146146
```solidity
147147
...
148148
function callLiquidation(Opportunity memory opp){
149+
for (uint i=0; i<opp.sell_tokens.length; i++) {
150+
let token = opp.sell_tokens[i];
151+
IERC20(token.contract).approve(opp.contract, token.amount);
152+
}
149153
150-
// this is a simplified version since sell and buy tokens are
151-
// an array and multiple assets may be necessary for the liquidation
152-
assert(opp.buy_tokens.length == 1);
153-
assert(opp.sell_tokens.length == 1);
154-
155-
IERC20(opp.sell_tokens[0].contract).approve(opp.contract, opp.sell_tokens[0].amount);
156-
157-
before = IERC20(opp.buy_tokens[0].contract).balanceOf(address(this));
154+
uint256[] before = new uint256[](opp.buy_tokens.length);
155+
for (uint j=0; j<opp.buy_tokens.length; j++) {
156+
let token = opp.buy_tokens[j];
157+
before = IERC20(token.contract).balanceOf(address(this));
158+
}
159+
158160
opp.target_contract.call{value: opp.target_call_value}(opp.target_calldata);
159161
160-
after = IERC20(opp.buy_tokens[0].target_contract).balanceOf(address(this));
162+
uint256[] after = new uint256[](opp.buy_tokens.length);
163+
for (uint j=0; j<opp.buy_tokens.length; j++) {
164+
let token = opp.buy_tokens[j];
165+
after = IERC20(token.target_contract).balanceOf(address(this));
161166
162-
assert(after == before + opportunity.buy_tokens[0].amount)
167+
assert(after[j] == before[j] + token.amount);
168+
}
163169
}
164170
...
165171
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
11
# Integrate with opportunity adapter
2+
3+
The `OpportunityAdapter` is a utility contract that can be used for easier integration with express relay while maintaining maximum security. In this integration, searchers use the `Permit2` contract for safe asset management (`ERC20` tokens and Wrapped ETH) and the adapter contract to transfer bids, execute the opportunity, and ensure the assets are transferred correctly. Using the `OpportunityAdapter` means that a searcher does not need to deploy their own custom contract for inventory management and routing to the protocol contracts where liquidation takes place.
4+
5+
After [integrating with the auction server](./auction-server), you can integrate with the `OpportunityAdapter` framework via the following steps:
6+
1. Hold your assets in your wallet. You will need to own all assets you expect to provide as `sell_tokens` to different opportunities. You will also need to approve `WETH`, as the `OpportunityAdapter` will pay your bids by deducting the bid amounts from your wallet's `WETH` balance.
7+
2. Approve your assets to the `Permit2` contract, `0x000000000022D473030F116dDEE9F6B43aC78BA3`.
8+
3. When bidding, set `target_contract` to the `OpportunityAdapterFactory` and craft your `target_calldata` based on the format of the `OpportunityAdapter`. The express relay [JavaScript SDK](https://www.npmjs.com/package/@pythnetwork/express-relay-evm-js) and [Python SDK](https://pypi.org/project/express-relay/) have helper functions that handle this step for you.

0 commit comments

Comments
 (0)