Skip to content

Commit 0bae84e

Browse files
authored
Merge pull request #1 from taurusgroup/first-draft
First release
2 parents 7d169fd + 6dd2f74 commit 0bae84e

File tree

146 files changed

+27296
-804
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

146 files changed

+27296
-804
lines changed

.github/workflows/ci.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Foundry CI
2+
3+
on:
4+
push:
5+
branches: [dev, master, main]
6+
pull_request:
7+
branches: [dev, master, main]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: Install Foundry
17+
uses: foundry-rs/foundry-toolchain@v1
18+
with:
19+
version: nightly
20+
21+
- name: Run Forge install
22+
run: forge install
23+
24+
- name: Run Forge build
25+
run: forge build --sizes
26+
27+
- name: Run Forge tests
28+
run: forge test -vvv

.gitignore

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Compiler files
22
cache/
33
out/
4+
docOut/
45

56
# Ignores development broadcast logs
67
!/broadcast
@@ -15,4 +16,11 @@ docs/
1516

1617
.vscode
1718
/node_modules
18-
bin/
19+
bin/
20+
21+
#drawio
22+
*.bkp
23+
24+
#hardhat
25+
artifacts/
26+
cache_hardhat/

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
[submodule "lib/ccip"]
55
path = lib/ccip
66
url = https://github.com/smartcontractkit/ccip
7+
[submodule "lib/forge-std"]
8+
path = lib/forge-std
9+
url = https://github.com/foundry-rs/forge-std

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2024 Taurus SA
4+
5+
Permission is hereby granted, free of charge, to any person obtaining
6+
a copy of this software and associated documentation files (the
7+
"Software"), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included
14+
in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
# CCIPSender
2+
3+
> This project is a proof-of-concept to demonstration interactions with the CCIP bridge.
4+
>
5+
> It's not designed to be production code, it's not security-audited, use at your own risk.
6+
7+
## Overview
8+
9+
A sender contract serves as an entrypoint between your end user and the router contract from Chainlink. This contract is under your control and can be used to offer more possibility of customization.
10+
11+
The sender contract will be the main entrypoint for your user to bridge tokens. It will contain all the logic to transfer tokens and send messages.
12+
13+
More information is available in the [CCIP Chainlink website](https://docs.chain.link/ccip) and in the library CCIP in github [smartcontractkit/ccip](https://github.com/smartcontractkit/ccip)
14+
15+
The main reference is the [CCIP masterclass](https://andrej-rakic.gitbook.io/chainlink-ccip/ccip-masterclass/exercise-1-transfer-tokens)
16+
17+
## Configuration and usage
18+
19+
To allow bidirectional transactions, you must deploy the sender contract on each blockchain.
20+
21+
Let's look at the example of a bridge between Polygon and Avalanche.
22+
23+
After deployment of the contracts, the first step is to establish the link between Polygon and Avalanche.
24+
25+
### Allow list chains
26+
27+
We will allow Avalanche to be a destination chain. We call the function `setAllowlistChain()` to do this.
28+
29+
```solidity
30+
function setAllowlistChain(uint64 _chainSelector, bool allowedSourceChain, bool allowedDestinationChain)
31+
```
32+
33+
Example:
34+
35+
```solidity
36+
setAllowlistChain(6433500567565415381, false, true)
37+
```
38+
39+
And Polygon too
40+
41+
```solidity
42+
setAllowlistChain(4051577828743386545, false, true)
43+
```
44+
45+
The configuration of the source chain is only useful if we use a receiver contract, but this is not the case for the moment.
46+
47+
48+
### Activate fee tokens
49+
50+
We will now set the fee payment for our two senders contracts.
51+
52+
For Polygon, we will authorize to pay the fees in MATIC, the Polygon PoS native token
53+
54+
For Avalanche, we will authorize to pay the fees in AVAX, the Avalanche native token.
55+
56+
The selected id for native token is zero, the function has to be called in the two blockchains
57+
58+
```solidity
59+
changeStatusFeePaymentMethod(0, true);
60+
```
61+
62+
For non-native token, we use another function `setFeePaymentMethod`:
63+
64+
```solidity
65+
function setFeePaymentMethod(IERC20 tokenAddress_, string calldata label_)
66+
```
67+
68+
### Authorize user to use the contracts
69+
70+
Our function `transferTokens` from our sender contract is protected by an access control. Only authorized users can transfer tokens. You have to grant the corresponding role to your brider's users.
71+
72+
```solidity
73+
grantRole(bytes32 role, address account)
74+
```
75+
76+
Example:
77+
78+
```solidity
79+
grantRole(`b0f04d2e44f4b417ab78712b52802767b073e39f75dba9f6e3a31125b053f026`, <Sender address>)
80+
```
81+
82+
### Fund the sender contract
83+
84+
It is important to fund our sender contract to pay the fees.
85+
86+
For that, we will call the function ` depositNativeTokens()` with our account holding native tokens.
87+
88+
### Approve the sender contract
89+
90+
With our bridge user, we authorize the bridge to transfer our tokens in our name.
91+
92+
This is done with the classic ERC-20 `approve` function.
93+
94+
95+
## Module
96+
97+
We divided the code into several components called modules. Each module is responsible to perform specific task.
98+
99+
| **Group** | **Contract name** | **Description** |
100+
| :------------ | :------------------- | :----------------------------------------------------------- |
101+
| | CCIPSender | Our main contract to deploy |
102+
| | CCIPBaseSender | Our base contract providing the public transfer functions |
103+
| Security | | |
104+
| | AuthorizationModule | Manage the access control |
105+
| Wrappers | | |
106+
| | CCIPSenderBuild | Build a CCIP message |
107+
| | CCIPContractBalance | Withdraw native and fee tokens from the contracts |
108+
| Configuration | | |
109+
| | CCIPAllowlistedChain | Set and define the blockchain supported by the sender contract. |
110+
| | CCIPRouterManage | Store the router contracts address and associated functions |
111+
| | CCIPSenderPayment | Compute fee required to transmit the transfer message |
112+
113+
114+
115+
## Documentation
116+
117+
Here a summary of the main documentation
118+
119+
| Document | Link/Files |
120+
| ----------------------- | -------------------------------------- |
121+
| Technical documentation | [doc/technical](./doc/technical.md) |
122+
| Toolchain | [doc/TOOLCHAIN.md](./doc/TOOLCHAIN.md) |
123+
| Surya report | [doc/schem/surya](./doc/schema/surya) |
124+
125+
## Deployment
126+
127+
The main contract is `CCIPSender`. This contract has to be deployed on each source chain where you want perform transfers.
128+
129+
![UML](./doc/schema/uml.png)
130+
131+
## Usage
132+
133+
*Explain how it works.*
134+
135+
136+
## Toolchain installation
137+
138+
The contracts are developed and tested with [Foundry](https://book.getfoundry.sh), a smart contract development toolchain.
139+
140+
To install the Foundry suite, please refer to the official instructions in the [Foundry book](https://book.getfoundry.sh/getting-started/installation).
141+
142+
## Initialization
143+
144+
You must first initialize the submodules, with
145+
146+
```
147+
forge install
148+
```
149+
150+
See also the command's [documentation](https://book.getfoundry.sh/reference/forge/forge-install).
151+
152+
Later you can update all the submodules with:
153+
154+
```
155+
forge update
156+
```
157+
158+
See also the command's [documentation](https://book.getfoundry.sh/reference/forge/forge-update).
159+
160+
161+
162+
## Compilation
163+
164+
The official documentation is available in the Foundry [website](https://book.getfoundry.sh/reference/forge/build-commands)
165+
166+
```
167+
forge build --contracts src/deplyoment/CCIPSender.sol
168+
```
169+
170+
## Testing
171+
172+
You can run the tests with
173+
174+
```
175+
forge test
176+
```
177+
178+
To run a specific test, use
179+
180+
```
181+
forge test --match-contract <contract name> --match-test <function name>
182+
```
183+
184+
See also the test framework's [official documentation](https://book.getfoundry.sh/forge/tests), and that of the [test commands](https://book.getfoundry.sh/reference/forge/test-commands).
185+
186+
### Coverage
187+
188+
* Perform a code coverage
189+
190+
```
191+
forge coverage
192+
```
193+
194+
* Generate LCOV report
195+
196+
```
197+
forge coverage --report lcov
198+
```
199+
200+
- Generate `index.html`
201+
202+
```bash
203+
forge coverage --report lcov && genhtml lcov.info --branch-coverage --output-dir coverage
204+
```
205+
206+
See [Solidity Coverage in VS Code with Foundry](https://mirror.xyz/devanon.eth/RrDvKPnlD-pmpuW7hQeR5wWdVjklrpOgPCOA-PJkWFU) & [Foundry forge coverage](https://www.rareskills.io/post/foundry-forge-coverage)
207+
208+
## Intellectual property
209+
210+
The original code is copyright (c) Taurus 2024, and is released under [MIT license](LICENSE).

0 commit comments

Comments
 (0)