The contracts in this repository are used in Skip Go API to enable any-to-any swaps as part of multi-chain workflows.
Skip Go is a unified REST API, Widget, and Core Package that helps developers create more seamless cross-chain experiences for their end users with IBC (Inter-Blockchain Communication protocol).
Skip Go API is designed so that even developers who are new to IBC can offer incredible cross-chain experiences, like swaps and transfers between any two IBC-enabled chains and tokens in as few transactions as possible, with reliable multi-chain relaying, packet tracking, and more.
The on-chain components of the swapping functionality consist of:
- A main entry point contract
- Chain/dex-specific swap adapter contracts
- Chain-specific IBC transfer adapter contracts
The entry point contract is responsible for providing a standardized interface (w/ safety checks) to interact with Skip Swap across all CosmWasm-enabled chains. The contract:
- Performs basic validation on the call data.
- If a fee swap is provided, queries the swap adapter contract to determine how much of the coin sent with the contract call is needed to receive the required fee coin(s), and dispatches the swap.
- Dispatches the user swap provided in the call data to the relevant swap adapter contract.
- Verifies the amount out received from the swap(s) is greater than the minimum amount required by the caller after all fees have been subtracted (swap, ibc, affiliate).
- Dispatches one of the following post-swap actions with the received funds from the swap:
- Transfer to an address on the same chain.
- IBC transfer to an address on a different chain (which allows for multi-hop IBC transfers or contract calls if the destination chains support it).
- Call a contract on the same chain.
Swap Adapter contracts are developed and deployed for each swap venue supported by Skip Swap. The contracts are responsible for:
- Taking the standardized entry point swap operations message format and converting it to the specific swap venue's format.
- Swapping by calling the swap venue's respective smart contract or module.
- Providing query methods that can be called by the entry point contract (generally, to any external actor) to simulate multi-hop swaps that either specify an exact amount in (estimating how much would be received from the swap) or an exact amount out (estimating how much is required to get the specified amount out).
IBC Transfer adapter contracts are developed and deployed for each chain supported by Skip Swap. The contracts are responsible for:
- Dispatching the IBC transfer (with the appropriate IBC fees if required).
- Failing the entire transaction if the IBC transfer errors on the swap chain (sending the caller back their original funds).
- Refunding the caller on the swap chain if the IBC transfer errors or times out once it reaches the destination chain (also refunding unused IBC fees).
A simplified example flow showcasing the interactions between the contracts is as follows:
- A user calls
swap_and_action
on the entry point contract. - The entry point contract performs pre-swap validation checks on the user call.
- The entry point contract calls
swap
on the relevant swap adapter contract, sending the coin to swap to the swap adapter contract. - The swap adapter contract swaps the coin sent by the entry point contract to the desired output denom through the relevant swap venue.
- The swap adapter contract calls
transfer_funds_back
on itself, which transfers the post-swap contract balance back to the entry point contract. - The entry point contract performs post-swap validation checks, ensuring the minimum amount out specified in the original call is satisfied.
- The entry point contract calls
ibc_transfer
on the IBC transfer adapter contract.- Note: The entry point contract dispatches one of three post swap actions. This simplified example flow is just showing the IBC transfer post swap action.
- The IBC transfer adapter contract dispatches the IBC transfer. Bon voyage!
The repository is organized in the following way:
│
├── contracts/ <- Contains all contracts
│ ├── entry-point/ <- Contains source code and tests for entry point contract
│ └── adapters/ <- Contains source code and tests for all network adapter contracts
│ ├── ibc/
│ │ ├── ibc-hooks/
│ │ └── neutron-transfer/
│ └── swap/
│ ├── astroport/
│ └── osmosis-poolmanager/
│
├── deployed-contracts/ <- Contains deployed contracts info for each network
│ ├── neutron/
│ └── osmosis/
│
├── packages/ <- Contains all package code used by the contracts
│ └── skip/
│
├── scripts/ <- Contains all configs and deployment scripts
│ ├── configs/
│ ├── deploy.py
│ └── requirements.txt
│
├── README.md
├── Cargo.lock
├── Cargo.toml
├── Makefile
└── README.md
All tests can be found in the tests folder in each respective contract package.
Run all tests in the repo:
make test
Note: Due to the nature of the adapter contracts using stargate messages and interacting with chain-specific modules, integration testing is conducted on the respective testnets. See Deployment section for deployment instructions.
The repository's CI is triggered on pull requests and will fail if any error or warnings appear running the check
, clippy
, and fmt
commands found in the Makefile.
Each command and how to run them are as follows:
cargo check --target wasm32-unknown-unknown
is used to compile the contracts and verify they are valid wasm:
make check
clippy
is used for linting:
make clippy
rustfmt
is used for formatting:
make fmt
To deploy the Skip Swap contracts, the steps are as follows:
-
Build the optimized wasm bytecode of the contracts by running (they will appear in an artifacts folder):
make optimize
-
Ensure you have python 3.10 installed to run the deploy script. Download python 3.10 if you don't have it installed.
python3.10 --version
-
Go into the scripts directory and create a virtual environment to download the python dependencies:
cd scripts python3.10 -m venv venv
-
Activate virtual environment, (venv) will show on left-hand side of shell
source venv/bin/activate
-
Install all the dependencies:
pip install -r requirements.txt
-
Add the mnemonic of the deployer address in the respsective chain's config toml file (located in configs folder):
# Enter your mnemonic here MNEMONIC = "<YOUR MNEMONIC HERE>"
-
Generate the entry point contract address using
instatiate2
which generates determinsitic cosmwasm contract addresses. This is necessary to allow the adapter contracts to whitelist the entry point contract before it is instantiated. To do this, you will need the daemon of the respective chain you are deploying on, and running the following command for the chain's CLI (replace osmosisd with network client being used):osmosisd query wasm build-address <CHECK SUM HASH OF CONTRACT> <ADDRESS THAT WILL INSTANTIATE> <SALT AS HEX STRING (31 is b'1')>
-
Add the generated entry point address in the respective chain's config toml file
# @DEV MUST CHANGE SALT ACCORDINGLY TO OBTAIN THIS PRE GENERATED ADDRESS ENTRY_POINT_PRE_GENERATED_ADDRESS = "<PRE GENERATED ADDRESS HERE>"
-
Update the salt used in the config if needed (default is "1", which is 31 in the chain daemon generator)
# SALT USED TO GENERATE A DETERMINSTIC ADDRESS SALT = "1"
-
Run the deploy script with the following format (changing the chain [options: osmosis, neutron] and network [options: testnet, mainnet] depending on what is to be deployed):
python deploy.py <CHAIN> <NETWORK>
Example:
python deploy.py osmosis testnet
Note: If deploying injective, must run this command instead:
python deploy_injective.py injective mainnet
-
After running the deploy script, a toml file will be added/updated in the deployed-contracts/{CHAIN} folder with all relevant info for the deployment.
Skip helps developers provide extraordinary user experiences across all stages of the transaction lifecycle, from transaction construction, through cross-chain relaying + tracking, to block construction.