Skip to content

10k-swap/10k_swap-contracts

Repository files navigation

10Kswap Contracts for Cairo

Introducing 10KSwap: An AMM protocol that advances with Ethereum

10KSwap(10kswap.com), being built on StarkNet, is an AMM protocol that advances with Ethereum. 10K aims to revolutionize the performance of the AMM protocol by leveraging the rollup feature, bringing lower fees, less friction, and ultimately better liquidity to the L2 world and advance DeFi adoption.

10KSwap is the first open source AMM deployed on StarkNet Mainnet. We trust Ethereum and StarkNet, which represents the most advanced rollup trend. With its unique Cairo-VM giving developers a new development option, higher TPS and a computational cost that can be ignored. We believe AMM will be the most direct beneficiary of these two features.

With Cairo-VM, the gas cost required to perform calculation is much lower than for state updates, and on top of this we will increase the appropriate amount of calculation to reduce the number of state updates, continue to improve contract performance, and further reduce gas costs. Ensuring that 10K brings users a lightning-fast trading experience while enjoying the security of broad consensus - that's what every DeFi user wants to see, and we look forward to exploring this magical starfield with the pioneers on StarkNet.

10KSwap has adopted an immutable scheme where the protocol does not serve centralized interests. When it is fully delivered by the creator, the power is left to the community. It is a reflection of the spirit of decentralization, and our desire to work with users to make the impossible triangle possible.

In subsequent developments, we will continue to explore the potential of zk-tech to develop an AMM that is more LP friendly and allows for finer control of liquidity distribution.

The key technology is how to use Cairo to develop the "Rich Convex Function", and we will bring the results to the community. All the development process is open source and available as reference material, hoping to motivate more Dapp developers to inspire them to get involved in the L2 ecosystem and build DeFi. The following three products will be brought to the community.

1). A summary tutorial related to development.
2). A more generic and accessible development scaffolding.
3). SDK and DeFi contract libraries to facilitate dapp development.

10Kswap was online. To preview

https://10kswap.com

preview

Get started

Clone this repo

git clone git@github.com:0x60018/10k_swap-contracts.git
cd 10k_swap-contracts

Install dependencies

yarn install

Compile a contract

npx hardhat starknet-compile contracts/l0k_factory.cairo

Run a test that interacts with the compiled contract

npx hardhat test l0k_factory.test.ts

Branches

  • main Stable version
  • develop New PRs and features

Contracts

l0k_factory

l0k_factory.cairo

  • Mainnet Adddress: 0x01c0a36e26a8f822e0d81f20a5a562b16a8f8a3dfd99801367dd2aea8f1a87a2
  • Goerli Adddress: 0x06c31f39524388c982045988de3788530605ed08b10389def2e7b1dd09d19308

Events

func PairCreated(token0 : felt, token1 : felt, pair : felt, index : felt):
end
  • token0 is guaranteed to be strictly less than token1 by sort order.
  • pair token0 & token1 pair address
  • index pair index, start from 0

constructor

func constructor(pairClass : felt, feeToSetter : felt):
end
  • pairClass l0k_pair contract class hash
  • feeToSetter feeTo address manager

Read Functions

feeTo
func feeTo() -> (feeTo : felt):
end
  • Returns feeTo
feeToSetter
func feeToSetter() -> (feeToSetter : felt):
end
  • Returns feeToSetter
getPair
func getPair(token0 : felt, token1 : felt) -> (pair : felt):
end
  • token0 -
  • token1 -
  • Returns pair
allPairs
func allPairs(index : felt) -> (pair : felt):
end
  • index pair index
  • Returns pair
allPairsLength
func allPairsLength() -> (length : felt):
end
  • Returns length

Write Functions

createPair
func createPair(tokenA : felt, tokenB : felt) -> (pair : felt):
end
  • tokenA A token address
  • tokenB B token address
  • Returns pair
  • Emits PairCreated
setFeeTo
func setFeeTo(feeTo : felt) -> ():
end
  • feeTo -
setFeeToSetter
func setFeeToSetter(feeToSetter : felt) -> ():
end
  • feeToSetter -

l0k_pair

l0k_pair.cairo

  • ClassHash: 0x231adde42526bad434ca2eb983efdd64472638702f87f97e6e3c084f264e06f

ERC20 functions and events based on openzeppelin cairo, click here for details.
Thanks to openzeppelin for powering cairo.

Events

Mint
func Mint(sender : felt, amount0 : Uint256, amount1 : Uint256):
end
  • sender Minter
  • amount0 Token0 amount
  • amount1 Token1 amount
Burn
func Burn(sender : felt, amount0 : Uint256, amount1 : Uint256, to : felt):
end
  • sender Burner
  • amount0 Token0 amount
  • amount1 Token1 amount
  • to Recipient
Swap
func Swap(
    sender : felt,
    amount0In : Uint256,
    amount1In : Uint256,
    amount0Out : Uint256,
    amount1Out : Uint256,
    to : felt,
):
end
  • sender Swaper
  • amount0In Token0 in amount
  • amount1In Token1 in amount
  • amount0Out Token0 out amount
  • amount1Out Token1 out amount
  • to Recipient
Sync
func Sync(reserve0 : felt, reserve1 : felt):
end
  • reserve0 Token0 quantity in pair
  • reserve1 Token1 quantity in pair

Read Functions

MINIMUM_LIQUIDITY
func MINIMUM_LIQUIDITY() -> (MINIMUM_LIQUIDITY : felt):
end
  • MINIMUM_LIQUIDITY -
factory
func factory() -> (factory : felt):
end
  • factory l0k_factory contract
token0
func token0() -> (token0 : felt):
end
  • token0 -
token1
func token1() -> (token1 : felt):
end
  • token1 -
blockTimestampLast
func blockTimestampLast() -> (blockTimestampLast : felt):
end
  • blockTimestampLast -
price0CumulativeLast
func price0CumulativeLast() -> (price0CumulativeLast : felt):
end
  • price0CumulativeLast -
price1CumulativeLast
func price1CumulativeLast() -> (price1CumulativeLast : felt):
end
  • price1CumulativeLast -
kLast
func kLast() -> (kLast : felt):
end
  • kLast -
getReserves
func getReserves() -> (reserve0 : felt, reserve1 : felt, blockTimestampLast : felt):
end
  • reserve0 Token0 quantity in pair
  • reserve1 reserve1 quantity in pair
  • blockTimestampLast -

Write Functions

initialize
func initialize() -> (token0 : felt, token1 : felt):
end

called once by the factory at time of deployment

  • token0 -
  • token1 -
mint
func mint(to : felt) -> (liquidity : Uint256):
end
  • to Recipient
  • RETURNS: liquidity Pair token quantity
  • Emits Mint, Sync, TransferERC20
burn
func burn(to : felt) -> (amount0 : Uint256, amount1 : Uint256):
end
  • to Recipient
  • RETURNS: amount0 Received token0 quantity, amount1 Received token0 quantity
  • Emits Burn, Sync, TransferERC20
swap
func swap(amount0Out : Uint256, amount1Out : Uint256, to : felt) -> ():
end
  • amount0Out -
  • amount1Out -
  • to Recipient
  • Emits Swap, Sync
skim
func skim() -> (to : felt):
end
  • to Recipient
sync
func sync() -> ():
end
  • Emits Sync

l0k_router

l0k_router.cairo

  • Mainnet Adddress: 0x07a6f98c03379b9513ca84cca1373ff452a7462a3b61598f0af5bb27ad7f76d1
  • Goerli Adddress: 0x00975910cd99bc56bd289eaaa5cee6cd557f0ddafdb2ce6ebea15b158eb2c664

Read Functions

factory
func factory() -> (factory : felt):
end
  • factory l0k_factory contract
quote
func quote(amountA : Uint256, reserveA : felt, reserveB : felt) -> (amountB : Uint256):
end
  • amountA TokenA quantity
  • reserveA TokenA quantity in pair
  • reserveB TokenB quantity in pair
  • Returns amountB Received tokenB quantity
getAmountOut
func getAmountOut(amountIn : Uint256, reserveIn : felt, reserveOut : felt) -> (amountOut : Uint256):
end
  • amountIn TokenIn quantity
  • reserveIn TokenIn quantity in pair
  • reserveOut TokenOut quantity in pair
  • Returns amountOut Received tokenOut quantity
getAmountIn
func getAmountOut(amountOut : Uint256, reserveIn : felt, reserveOut : felt) -> (amountIn : Uint256):
end
  • amountOut TokenOut quantity
  • reserveIn TokenIn quantity in pair
  • reserveOut TokenOut quantity in pair
  • Returns amountIn Received tokenIn quantity
getAmountsOut
func getAmountsOut(amountIn : Uint256, path_len : felt, path : felt*) -> (amounts_len : felt, amounts : Uint256*):
end
  • amountIn TokenIn quantity
  • path_len Path's length
  • path [TokenA, TokenB, ...]
  • Returns amounts_len amounts's length, amounts received tokens amount
getAmountsIn
func getAmountsIn(amountOut : Uint256, path_len : felt, path : felt*) -> (amounts_len : felt, amounts : Uint256*):
end
  • amountOut TokenOut quantity
  • path_len Path's length
  • path [TokenB, TokenA, ...]
  • Returns amounts_len amounts's length, amounts send tokens amount

Write Functions

addLiquidity
func addLiquidity(
    tokenA : felt,
    tokenB : felt,
    amountADesired : Uint256,
    amountBDesired : Uint256,
    amountAMin : Uint256,
    amountBMin : Uint256,
    to : felt,
    deadline : felt,
) -> (amountA : Uint256, amountB : Uint256, liquidity : Uint256):
end
  • tokenA TokenA address
  • tokenB TokenB address
  • amountADesired -
  • amountBDesired -
  • amountAMin -
  • amountBMin -
  • to Recipient
  • deadline Expired timestamp(unix)
  • Returns amountA Used tokenA quantity, amountB Used tokenB quantity, liquidity Pair token quantity
removeLiquidity
func removeLiquidity(
    tokenA : felt,
    tokenB : felt,
    liquidity : Uint256,
    amountAMin : Uint256,
    amountBMin : Uint256,
    to : felt,
    deadline : felt,
) -> (amountA : Uint256, amountB : Uint256):
end
  • tokenA TokenA address
  • tokenB TokenB address
  • liquidity Pair token quantity
  • amountAMin -
  • amountBMin -
  • to Recipient
  • deadline Expired timestamp(unix)
  • Returns amountA Received tokenA quantity, amountB Received tokenB quantity
swapExactTokensForTokens
func swapExactTokensForTokens(
    amountIn : Uint256,
    amountOutMin : Uint256,
    path_len : felt,
    path : felt*,
    to : felt,
    deadline : felt,
) -> (amounts_len : felt, amounts : Uint256*):
end
  • amountIn -
  • amountOutMin -
  • path_len -
  • path -
  • to Recipient
  • deadline Expired timestamp(unix)
  • Returns amounts_len amounts's length, amounts received tokens amount
swapTokensForExactTokens
func swapTokensForExactTokens(
    amountOut : Uint256,
    amountInMax : Uint256,
    path_len : felt,
    path : felt*,
    to : felt,
    deadline : felt,
) -> (amounts_len : felt, amounts : Uint256*):
end
  • amountOut -
  • amountInMax -
  • path_len -
  • path -
  • to Recipient
  • deadline Expired timestamp(unix)
  • Returns amounts_len amounts's length, amounts send tokens amount
swapExactTokensForTokensSupportingFeeOnTransferTokens
func swapExactTokensForTokensSupportingFeeOnTransferTokens(
    amountIn : Uint256,
    amountOutMin : Uint256,
    path_len : felt,
    path : felt*,
    to : felt,
    deadline : felt,
):
end
  • amountIn -
  • amountOutMin -
  • path_len -
  • path -
  • to Recipient
  • deadline Expired timestamp(unix)
  • Returns amounts_len amounts's length, amounts send tokens amount

About

A decentralized ZK Rollup AMM written in Cairo for StarkNet.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published