Code Samples To Get You Started
The guides in the following section are targeted at application developers as well as smart contract integrators that are interested in building on top of the KyberSwap Elastic ecosystem.
Given the composability of DeFi protocols, we recommend using Hardhat's mainnet forking feature to best stimulate mainnet conditions. This will enable integrations to be conveniently tested against existing protocols without having to bootstrap each and every protocol individually.
KyberSwap Elastic consists of multiple smart contracts, each having been deliberately confined to a specific function. If you would like to view the full list of contracts as well as their respective functions and variables, the contracts have been split according to the below:
- Core Libraries: Contains deployment contracts as well as multiple math contracts for safe handling of numbers.
- Periphery Core Contracts: Contracts which handle swap routing as well as management of liquidity positions.
- Peripheral Library Contracts: Contains the anti-sniping contract as well as various contracts to aid data queries.
- Peripheral Base Contracts: Helper contracts that process, validate, and store peripheral liquidity flows.
The contracts that are of particular interest are listed below:
- Factory: Handles deployment of Kyberswap Elastic pools and where administrative configurations are held, such as the whitelisting of NFT position managers, and government fee settings.
- QouterV2: Allows getting the expected amount out or amount in for a given swap without executing the swap.
- AntiSnipAttackPositionManager: Adds the anti-sniping attack feature to the liquidity additions or removals.
- TicksFeeReader: Handles the management of ticks as well as the corresponding positions and fees.
- TokenPositionDescriptor: Enables querying of position information.
- TokenPositionDescriptionProxy: An ERC1967 contract that implements an upgradeable proxy for the TokenPositionDescriptor contract.
Please refer to Elastic Contract Addresses for the full list of contracts which have been deployed across the supported chains.
As there are possibly multiple pools per token pair, the first step is to fetch pool addresses and determine which pool is most suitable for querying swap rates, trade execution and liquidity provision.