Skip to content

Commit 996ec1f

Browse files
committed
la Tierra es un dado roído y ya redondo a fuerza de rodar a la aventura
0 parents  commit 996ec1f

File tree

16 files changed

+542
-0
lines changed

16 files changed

+542
-0
lines changed

.github/workflows/test.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
8+
env:
9+
FOUNDRY_PROFILE: ci
10+
11+
jobs:
12+
check:
13+
name: Foundry project
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
submodules: recursive
19+
20+
- name: Install Foundry
21+
uses: foundry-rs/foundry-toolchain@v1
22+
23+
- name: Show Forge version
24+
run: |
25+
forge --version
26+
27+
- name: Run Forge fmt
28+
run: |
29+
forge fmt --check
30+
id: fmt
31+
32+
- name: Run Forge build
33+
run: |
34+
forge build --sizes
35+
id: build
36+
37+
- name: Run Forge tests
38+
run: |
39+
forge test -vvv
40+
id: test

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Compiler files
2+
cache/
3+
out/
4+
5+
# Ignores development broadcast logs
6+
!/broadcast
7+
/broadcast/*/31337/
8+
/broadcast/**/dry-run/
9+
10+
# Docs
11+
docs/
12+
13+
# Dotenv file
14+
.env

.gitmodules

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[submodule "lib/forge-std"]
2+
path = lib/forge-std
3+
url = https://github.com/foundry-rs/forge-std
4+
[submodule "lib/openzeppelin-contracts"]
5+
path = lib/openzeppelin-contracts
6+
url = https://github.com/OpenZeppelin/openzeppelin-contracts
7+
[submodule "lib/zenith"]
8+
path = lib/zenith
9+
url = https://github.com/init4tech/zenith

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Signet Solidity Examples
2+
3+
This repo contains solidity examples using the [Signet Orders] system to do
4+
some fun and suprising things 🎀
5+
6+
Signet Orders are cross-chain, instant, atomic, and composable. Because Outputs
7+
are effectively MEV, you can do some really interesting things with them. Like
8+
[MevWallet], Signet Orders allow you to leverage MEV Searchers to:
9+
10+
- Move assets across chains
11+
- Invoke functions on other chains
12+
- Schedule transactions or function invocations
13+
- Capture MEV produced by your application
14+
- Impress your friends
15+
- And more!
16+
17+
[MevWallet]: https://github.com/blunt-instruments/MevWallet
18+
[Signet Orders]: https://signet.sh/docs/learn-about-signet/cross-chain-transfers/
19+
20+
## Main Examples
21+
22+
- [`SignetStd.sol`](./src/SignetStd.sol) - A simple contract that
23+
auto-configures Signet system parameters, based on the chain id.
24+
- [`Flash.sol`](./src/examples/Flash.sol) - Allows your contract to flash borrow
25+
any asset (provided some searcher will provide it). Flash loans work by having an input and output of the same asset. The Output is then used as the Input to its own Order. This is pretty neat 🎀
26+
- [`GetOut.sol`](./src/examples/GetOut.sol) - A shortcut contract for
27+
exiting Signet (by offering searchers a 50 bps fee).
28+
- [`PayMe.sol`](./src/examples/PayMe.sol) - Payment gating for smart contracts,
29+
using a Signet Order with no inputs. These ensures that contract execution is invalid unless SOMEONE has filled the Order. Unlike traditional payment gates that check `msg.value`, this does NOT require the calling contract to manage cash flow. Instead _any third party_ can fill the order. The calling contract can be blind to the payment. This greatly simplifies contract logic required
30+
to implement payment gates.
31+
- [`PayYou.sol`](./src/examples/PayYou.sol) - The opposite of payment gating,
32+
this allows a contract to generate MEV by offering a Signet Order with no outputs. This payment becomes a bounty for calling the contract, and functions as an incentivized scheduling system.
33+
34+
## Basic Repo Instructions
35+
36+
### Build
37+
38+
```shell
39+
$ forge build
40+
```
41+
42+
### Test
43+
44+
```shell
45+
$ forge test
46+
```
47+
48+
### Format
49+
50+
```shell
51+
$ forge fmt
52+
```

foundry.lock

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"lib/zenith": {
3+
"tag": {
4+
"name": "v0.1.55",
5+
"rev": "914146a3904541192f2cb0906c0990cc6f90b1e3"
6+
}
7+
},
8+
"lib/forge-std": {
9+
"tag": {
10+
"name": "v1.10.0",
11+
"rev": "8bbcf6e3f8f62f419e5429a0bd89331c85c37824"
12+
}
13+
},
14+
"lib/openzeppelin-contracts": {
15+
"tag": {
16+
"name": "v5.4.0",
17+
"rev": "c64a1edb67b6e3f4a15cca8909c9482ad33a02b0"
18+
}
19+
}
20+
}

foundry.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[profile.default]
2+
src = "src"
3+
out = "out"
4+
libs = ["lib"]
5+
6+
via-ir = true
7+
8+
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options

lib/forge-std

Submodule forge-std added at 8bbcf6e

lib/openzeppelin-contracts

Submodule openzeppelin-contracts added at c64a1ed

lib/zenith

Submodule zenith added at 914146a

src/SignetStd.sol

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.8.13;
3+
4+
import {RollupOrders} from "zenith/src/orders/RollupOrders.sol";
5+
import {RollupPassage} from "zenith/src/passage/RollupPassage.sol";
6+
import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
7+
8+
import {PecorinoConstants} from "./chains/Pecorino.sol";
9+
10+
contract SignetStd {
11+
/// @notice The native asset address, used as a sentinel for native USD on
12+
/// the rollup, or native ETH on the host.
13+
address constant NATIVE_ASSET = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
14+
15+
/// @notice The chain ID of the host network.
16+
uint32 internal immutable HOST_CHAIN_ID;
17+
18+
/// @notice The Rollup Passage contract.
19+
RollupPassage internal immutable PASSAGE;
20+
/// @notice The Rollup Orders contract.
21+
RollupOrders internal immutable ORDERS;
22+
23+
/// @notice The WETH token address.
24+
IERC20 internal immutable WETH;
25+
/// @notice The WBTC token address.
26+
IERC20 internal immutable WBTC;
27+
/// @notice The WUSD token address.
28+
IERC20 internal immutable WUSD;
29+
30+
/// @notice The USDC token address on the host network.
31+
address internal immutable HOST_USDC;
32+
/// @notice The USDT token address on the host network.
33+
address internal immutable HOST_USDT;
34+
/// @notice The WBTC token address on the host network.
35+
address internal immutable HOST_WBTC;
36+
/// @notice The WETH token address on the host network.
37+
address internal immutable HOST_WETH;
38+
39+
constructor() {
40+
// Auto-configure based on the chain ID.
41+
if (block.chainid == PecorinoConstants.ROLLUP_CHAIN_ID) {
42+
HOST_CHAIN_ID = PecorinoConstants.HOST_CHAIN_ID;
43+
44+
PASSAGE = PecorinoConstants.PECORINO_ROLLUP_PASSAGE;
45+
ORDERS = PecorinoConstants.PECORINO_ROLLUP_ORDERS;
46+
47+
WETH = PecorinoConstants.WETH;
48+
WBTC = PecorinoConstants.WBTC;
49+
WUSD = PecorinoConstants.WUSD;
50+
51+
HOST_USDC = PecorinoConstants.HOST_USDC;
52+
HOST_USDT = PecorinoConstants.HOST_USDT;
53+
HOST_WBTC = PecorinoConstants.HOST_WBTC;
54+
HOST_WETH = PecorinoConstants.HOST_WETH;
55+
} else {
56+
revert("Unsupported chain");
57+
}
58+
}
59+
60+
/// @notice Creates an Input struct for the RollupOrders.
61+
/// @param token The address of the token.
62+
/// @param amount The amount of the token.
63+
/// @return input The created Input struct.
64+
function makeInput(address token, uint256 amount) internal pure returns (RollupOrders.Input memory input) {
65+
input.token = token;
66+
input.amount = amount;
67+
}
68+
69+
/// @notice Creates an Output struct for the RollupOrders.
70+
/// @param token The address of the token.
71+
/// @param amount The amount of the token.
72+
/// @param recipient The address to receive the output tokens.
73+
/// @param chainId The chain ID for the output.
74+
/// @return output The created Output struct.
75+
function makeOutput(address token, uint256 amount, address recipient, uint32 chainId)
76+
private
77+
pure
78+
returns (RollupOrders.Output memory output)
79+
{
80+
output.token = token;
81+
output.amount = amount;
82+
output.recipient = recipient;
83+
output.chainId = chainId;
84+
}
85+
86+
/// @notice Creates an Output struct for the host network.
87+
/// @param token The address of the token.
88+
/// @param amount The amount of the token.
89+
/// @param recipient The address to receive the output tokens.
90+
/// @return output The created Output struct for the host network.
91+
function makeHostOutput(address token, uint256 amount, address recipient)
92+
internal
93+
view
94+
returns (RollupOrders.Output memory output)
95+
{
96+
return makeOutput(token, amount, recipient, HOST_CHAIN_ID);
97+
}
98+
99+
/// @notice Creates an Output struct for the rollup network.
100+
/// @param token The address of the token.
101+
/// @param amount The amount of the token.
102+
/// @param recipient The address to receive the output tokens.
103+
/// @return output The created Output struct for the rollup network.
104+
function makeRollupOutput(address token, uint256 amount, address recipient)
105+
internal
106+
view
107+
returns (RollupOrders.Output memory output)
108+
{
109+
return makeOutput(token, amount, recipient, uint32(block.chainid));
110+
}
111+
112+
/// @notice Creates an Output struct for the host USDC token.
113+
/// @param amount The amount of USDC to receive.
114+
/// @param recipient The address to receive the USDC tokens.
115+
/// @return output The created Output struct for the host USDC token.
116+
function hostUsdcOutput(uint256 amount, address recipient)
117+
internal
118+
view
119+
returns (RollupOrders.Output memory output)
120+
{
121+
return makeHostOutput(HOST_USDC, amount, recipient);
122+
}
123+
124+
/// @notice Creates an Output struct for the host USDT token.
125+
/// @param amount The amount of USDT to receive.
126+
/// @param recipient The address to receive the USDT tokens.
127+
/// @return output The created Output struct for the host USDT token.
128+
function hostUsdtOutput(uint256 amount, address recipient)
129+
internal
130+
view
131+
returns (RollupOrders.Output memory output)
132+
{
133+
return makeHostOutput(HOST_USDT, amount, recipient);
134+
}
135+
136+
/// @notice Creates an Output struct for the host WBTC token.
137+
/// @param amount The amount of WBTC to receive.
138+
/// @param recipient The address to receive the WBTC tokens.
139+
/// @return output The created Output struct for the host WBTC token.
140+
function hostWbtcOutput(uint256 amount, address recipient)
141+
internal
142+
view
143+
returns (RollupOrders.Output memory output)
144+
{
145+
return makeHostOutput(HOST_WBTC, amount, recipient);
146+
}
147+
148+
/// @notice Creates an Output struct for the host WETH token.
149+
/// @param amount The amount of WETH to receive.
150+
/// @param recipient The address to receive the WETH tokens.
151+
/// @return output The created Output struct for the host WETH token.
152+
function hostWethOutput(uint256 amount, address recipient)
153+
internal
154+
view
155+
returns (RollupOrders.Output memory output)
156+
{
157+
return makeHostOutput(HOST_WETH, amount, recipient);
158+
}
159+
160+
/// @notice Creates an Output struct for the host native asset (ETH).
161+
/// @param amount The amount of native asset to receive.
162+
/// @param recipient The address to receive the native asset.
163+
/// @return output The created Output struct for the host native asset.
164+
function hostEthOutput(uint256 amount, address recipient)
165+
internal
166+
view
167+
returns (RollupOrders.Output memory output)
168+
{
169+
return makeHostOutput(NATIVE_ASSET, amount, recipient);
170+
}
171+
}

0 commit comments

Comments
 (0)