Skip to content

Commit cc941aa

Browse files
committed
docs: document approve and bridge project
1 parent 0875fce commit cc941aa

1 file changed

Lines changed: 45 additions & 19 deletions

File tree

README.md

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,92 @@
1-
## Foundry
1+
## Approve and bridge
2+
This is a simple implementation of approve and bridge contracts.
23

3-
**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.**
4+
It is provided as a reference pattern to construct [post-hooks](https://docs.cow.fi/cow-protocol/reference/core/intents/hooks) for CoW protocol's Swap and Bridge feature.
45

5-
Foundry consists of:
6+
## How it works
67

7-
- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools).
8-
- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
9-
- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network.
10-
- **Chisel**: Fast, utilitarian, and verbose solidity REPL.
8+
The general idea is:
9+
1. A user creates an order where the `recipient` is modified to a smart contract wallet they control (for example, a 1-1 Safe or a [cow-shed](https://github.com/cowdao-grants/cow-shed)).
10+
2. The swap executes, and the user controlled wallet receives the buy amount (including the surplus).
11+
3. Within the same CoW settlement transaction, a [post-hooks](https://docs.cow.fi/cow-protocol/reference/core/intents/hooks) executes initiating the bridging process for the full amount.
12+
4. Eventually, the bridge will be completed. The recipient of the buy tokens in the target chain is typically the user that initiated the swap (and not the smart contract wallet used for bridging)
1113

12-
## Documentation
14+
## Bridge provider helper contracts
15+
Each bridge provider creates their own helper contract. As a reference [ApproveAndBridge](src/mixin/ApproveAndBridge.sol) abstract contract implements the common logic and defines some `virtual` functions to be overridden by the bridge provider helper contract.
1316

14-
https://book.getfoundry.sh/
17+
The helper contract makes 2 assumptions:
18+
* The contract assumes it is being called using a `delegatecall` from the account that has the proceeds of the swap.
19+
* The balance of the account matches what the user intents to bridge. This is a simple way to handle CoW protocol's `surplus`.
20+
- This can be achieved if the smart contract wallet is only used for bridging and is set as the `recipient` in the order.
21+
- For example, the user sell 100 DAI for 100 USDC, but the solvers manage to give the user 101 USDC, then the contract will have exactly 101 USDC in its balance.
22+
23+
The main logic is defined in `approveAndBridge` function, which:
24+
1. Get the balance of the bridged asset (includes `surplus` from the swap)
25+
2. Performs some validations (like the `minAmount` tokens to bridge)
26+
3. Sets the allowance, so the bridging protocol can pull the bridged amount.
27+
4. Initiate the bridging process. Typically, the assets will be transferred to the bridging protocol.
28+
29+
The bridge provider helper contract overrides the function:
30+
* `bridge`: Implements the specific logic for the bridge provider.
31+
* `bridgeApprovalTarget`: Returns the address of the contract that should be approved to bridge the token.
32+
33+
34+
## Disclaimer
35+
36+
This repository is provided solely as a reference and for informational purposes.
37+
38+
The smart contracts and related materials included here are not audited, may contain vulnerabilities, and must not be relied upon in production or for any security-critical use without independent review and testing.
39+
40+
Certain contracts and examples may be contributed by third parties. Inclusion in this repository does not constitute an endorsement, recommendation, or warranty by the maintainers. The maintainers make no representations or guarantees regarding correctness, security, or fitness for any particular purpose, and disclaim all liability for any loss or damage arising from the use of these materials.
1541

1642
## Usage
1743

1844
### Build
1945

2046
```shell
21-
$ forge build
47+
forge build
2248
```
2349

2450
### Test
2551

2652
```shell
27-
$ forge test
53+
forge test
2854
```
2955

3056
### Format
3157

3258
```shell
33-
$ forge fmt
59+
forge fmt
3460
```
3561

3662
### Gas Snapshots
3763

3864
```shell
39-
$ forge snapshot
65+
forge snapshot
4066
```
4167

4268
### Anvil
4369

4470
```shell
45-
$ anvil
71+
anvil
4672
```
4773

4874
### Deploy
4975

5076
```shell
51-
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>
77+
forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>
5278
```
5379

5480
### Cast
5581

5682
```shell
57-
$ cast <subcommand>
83+
cast <subcommand>
5884
```
5985

6086
### Help
6187

6288
```shell
63-
$ forge --help
64-
$ anvil --help
65-
$ cast --help
89+
forge --help
90+
anvil --help
91+
cast --help
6692
```

0 commit comments

Comments
 (0)