Skip to content

Commit d4286b9

Browse files
authored
Merge pull request #39 from 0xProject/chai-bridge-orders
Add ChaiBridge order type
2 parents 1652556 + 1e43cbf commit d4286b9

1 file changed

Lines changed: 70 additions & 0 deletions

File tree

order-types/chai-bridge.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# ChaiBridge Orders
2+
3+
`ChaiBridge` orders allow market makers to earn the [Dai Savings Rate](https://community-development.makerdao.com/makerdao-mcd-faqs/faqs/dsr) while providing liquidity in Dai. This uses a combination of the [Chai token contract](https://chai.money/about.html) and the [ERC20BridgeProxy](../asset-proxy/erc20-bridge-proxy.md#erc20bridgeproxy) to create a user experience that is comparable to filling regular Dai-denominated orders.
4+
5+
## ChaiBridge contract
6+
7+
The `ChaiBridge` contract is a thin adapter between the Chai token contract and the `ERC20BridgeProxy` contract. Calling `ChaiBridge.bridgeTransferFrom` will perform the following steps:
8+
9+
1. Ensure that the sender is the `ERC20BridgeProxy`
10+
1. Withdraw `amount` of Dai from the maker's (`from` address) Chai token balance
11+
1. Transfer `amount` of Dai to the taker (`to` address)
12+
13+
This allows the `ERC20BridgeProxy` to transfer Dai from the maker's address to the taker's address, even though the maker is actually only holding Chai tokens (which are earning the Dai Savings Rate).
14+
15+
## Errors
16+
17+
The `ChaiBridge` contract's `bridgeTransferFrom` method may revert with the following errors:
18+
19+
| Error | Condition |
20+
| ----------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
21+
| [StandardError("ChaiBridge/ONLY_CALLABLE_BY_ERC20_BRIDGE_PROXY")](../v3/v3-specification.md#standard-error) | `bridgeTransferFrom` was called by an address other than the `ERC20BridgeProxy` |
22+
| [StandardError("ChaiBridge/DRAW_DAI_FAILED")](../v3/v3-specification.md#standard-error) | The `ChaiBridge` was not able to withdraw the specified `amount` of Dai from the maker's Chai tokens for any reason |
23+
24+
## Setup for ChaiBridge orders
25+
26+
In order for a maker to begin providing Dai liquidity through the `ChaiBridge` contract, the maker must first convert their Dai to Chai and then approve the `ChaiBridge` contract to spend their Chai tokens.
27+
28+
```typescript
29+
const MAX_UINT256 = new BigNumber(2).pow(256).minus(1);
30+
31+
// Approve Chai contract to spend maker's Dai
32+
await daiToken
33+
.approve(chaiToken.address, MAX_UINT256)
34+
.awaitTransactionSuccess({ from: makerAddress });
35+
36+
// 10 Dai
37+
const daiAmount = Web3Wrapper.toBaseUnitAmount(10, 18);
38+
39+
// Convert maker's Dai to Chai
40+
await chaiToken
41+
.join(makerAddress, daiAmount)
42+
.awaitTransactionSuccess({ from: makerAddress });
43+
44+
// Approve ChaiBridge contract to spend maker's Chai
45+
await chaiToken.approve(chaiBridge.address, MAX_UINT256);
46+
```
47+
48+
## Creating a ChaiBridge order
49+
50+
The [`makerAssetData`](../v3/v3-specification.md#orders) of an order must be encoded using [`ERC20Bridge` assetData](../asset-proxy/erc20-bridge-proxy.md#encoding-assetdata) which specifies the `ChaiBridge` contract:
51+
52+
```solidity
53+
bytes memory makerAssetData = abi.encodeWithSelector(
54+
// Id of ERC20BridgeProxy
55+
0xdc1600f3,
56+
// Dai mainnet address. This field will be ignored by the `ChaiBridge` contract. However,
57+
// it should be specified in order to standardize the parsing of `assetData` across different bridges.
58+
0x6B175474E89094C44Da98b954EedeAC495271d0F,
59+
// ChaiBridge mainnet address
60+
0x77C31EbA23043B9a72d13470F3A3a311344D7438,
61+
// The `bridgeData` field will be ignored.
62+
""
63+
);
64+
```
65+
66+
This results in the following `makerAssetData`: `0xdc1600f30000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000077c31eba23043b9a72d13470f3a3a311344d743800000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000`.
67+
68+
## Filling a ChaiBridge order
69+
70+
Once a maker has completed the prerequisite setup and created an order with valid `ChaiBridge` `makerAssetData`, a taker can fill the order via the [Exchange contract](https://github.com/0xProject/0x-protocol-specification/blob/master/v3/v3-specification.md#exchange) with no additonal allowances. These orders are functionally equivalent to a normal Dai order, where the `makerAssetAmount` of the order specifies the amount of Dai that will be transferred. The only difference to the taker is slightly increased gas costs (currently approximately 150K extra gas).

0 commit comments

Comments
 (0)