This repo exposes a liquidity bridge logic (LiquidityBridge.sol
), from an
on-chain exchange (IDexLogic.sol
), typically a Uniswap pool, to a mangrovian
order-book.
- Clone
- Run
npm install
- Install foundry
- Build/compile with
npm run build
(for the details, seepackage.json
.)
- Provide/Create an
.env
file following.envdist
format. - Specify the chain to test (polygon or mumbai) by setting
FOUNDRY_PROFILE
tomatic
,polygon
or any otherchain_name
. Private keys and url will processed inprocessEnv.sh
script. - Run
npm run anvil
to fork the chain - Run
source processEnv.sh; forge test -f $NODE_URL
to run the tests (you can also runnpm run test
)
- ✅ All tests are OK on
mumbai
(i.e.FOUNDRY_PROFILE=mumbai
), including a bridge from a UniswapV3 pool to a Mangrove order-book. - 🔴 On Polygon some tests will fail because additional work is required to make sure that tests are run on consistent token names. Sorry for the inconvenience.
To deploy a LiquidityBridge, you need to deploy the DexLogic first, then the Bridge. Then, some administration stuff is required to fund it and activate it.
💡 A recommandation for testing deployment could be (i) to create a fork on tenderly, (ii) export the corresponding url to
POLYGON_TENDERLY_NODE_URL
in.env
.
💡 Here is a list of commands to run for the deployment:
⚠️ Run them in the terminal as this a first time. If everything is ok, run them again with--broadcast
as additinonal argument to broadcast the transaction on the chain.
- Load the env variables:
source processEnv.sh
. It will set the chain, the private key, the admin (chief) address - Run
forge script script/DeployUniV3Bridge.s.sol -f $NODE_URL -s "deployDexLogic()" --private-key $PRIVATE_KEY
. - Save the DexLogic address in the
.env
file asDEXLOGIC
- Run
forge script script/DeployUniV3Bridge.s.sol -f $NODE_URL -s "deployBridge()" --private-key $PRIVATE_KEY
. Note that Bridge parameters used for deployment are part of theDeployUniV3Bridge.s.sol
file. - Save the Bridge address in the
.env
file asBRIDGE
- Now the following commands will fund, activate and deploy the offers of the bridge:
- Run
forge script script/BridgeAdmin.s.sol -f $NODE_URL --private-key $PRIVATE_KEY -s "fund()"
. Note that funded amount are in theBridgeAdmin.s.sol
file. - Run
forge script script/BridgeAdmin.s.sol -f $NODE_URL --private-key $PRIVATE_KEY -s "activate()"
- Run
forge script script/BridgeAdmin.s.sol -f $NODE_URL --private-key $PRIVATE_KEY -s "newOffers()"
Your brigde should now be ready to use.
- Set .env variable (including bridge address)
- Fork the target chain:
npm run anvil
- Display current order-book:
forge script BridgeCheckScript --tc BridgeCheckScript -f $ANVIL_URL -vv -s "displayOB()"
- Update
BridgeCheckScript
with the offer id you want to check (ask and bid) - Check the offer:
forge script BridgeCheckScript --tc BridgeCheckScript -f $ANVIL_URL -vv -s "snipeOffers()"
. Note:snipeOffers()
can be replaced bysnipeAsk()
orsnipeBid()
to check only one side of the offer-book.
- Gas estimation : I recommand to use the gas profile tool to estimate gas
taking an order of the Bridge. This part is essential because passed at the
constructor of
Direct
. - Improvements :
- Implement the dex logic into the Routing logic to avoid the non modularity
- What about creating an Abritageur Role (in addition to the Admin role)?
- Implement a tenacity behavior (taking reneg cost into acount and avoid certain renegs when more expensive than bridging)
- Better custom handling of all possible path (partially/totally filled, repost failed, etc.)