Home

Awesome

10Kswap Contracts for Cairo

Introducing 10KSwap: An AMM protocol that advances with Ethereum<br/>

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.<br /> 2). A more generic and accessible development scaffolding.<br /> 3). SDK and DeFi contract libraries to facilitate dapp development.<br />

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

Contracts

l0k_factory

l0k_factory.cairo

Events

func PairCreated(token0 : felt, token1 : felt, pair : felt, index : felt):
end

constructor

func constructor(pairClass : felt, feeToSetter : felt):
end

Read Functions

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

Write Functions

createPair
func createPair(tokenA : felt, tokenB : felt) -> (pair : felt):
end
setFeeTo
func setFeeTo(feeTo : felt) -> ():
end
setFeeToSetter
func setFeeToSetter(feeToSetter : felt) -> ():
end

l0k_pair

l0k_pair.cairo

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

Events

Mint
func Mint(sender : felt, amount0 : Uint256, amount1 : Uint256):
end
Burn
func Burn(sender : felt, amount0 : Uint256, amount1 : Uint256, to : felt):
end
Swap
func Swap(
    sender : felt,
    amount0In : Uint256,
    amount1In : Uint256,
    amount0Out : Uint256,
    amount1Out : Uint256,
    to : felt,
):
end
Sync
func Sync(reserve0 : felt, reserve1 : felt):
end

Read Functions

MINIMUM_LIQUIDITY
func MINIMUM_LIQUIDITY() -> (MINIMUM_LIQUIDITY : felt):
end
factory
func factory() -> (factory : felt):
end
token0
func token0() -> (token0 : felt):
end
token1
func token1() -> (token1 : felt):
end
blockTimestampLast
func blockTimestampLast() -> (blockTimestampLast : felt):
end
price0CumulativeLast
func price0CumulativeLast() -> (price0CumulativeLast : felt):
end
price1CumulativeLast
func price1CumulativeLast() -> (price1CumulativeLast : felt):
end
kLast
func kLast() -> (kLast : felt):
end
getReserves
func getReserves() -> (reserve0 : felt, reserve1 : felt, blockTimestampLast : felt):
end

Write Functions

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

called once by the factory at time of deployment

mint
func mint(to : felt) -> (liquidity : Uint256):
end
burn
func burn(to : felt) -> (amount0 : Uint256, amount1 : Uint256):
end
swap
func swap(amount0Out : Uint256, amount1Out : Uint256, to : felt) -> ():
end
skim
func skim() -> (to : felt):
end
sync
func sync() -> ():
end

l0k_router

l0k_router.cairo

Read Functions

factory
func factory() -> (factory : felt):
end
quote
func quote(amountA : Uint256, reserveA : felt, reserveB : felt) -> (amountB : Uint256):
end
getAmountOut
func getAmountOut(amountIn : Uint256, reserveIn : felt, reserveOut : felt) -> (amountOut : Uint256):
end
getAmountIn
func getAmountOut(amountOut : Uint256, reserveIn : felt, reserveOut : felt) -> (amountIn : Uint256):
end
getAmountsOut
func getAmountsOut(amountIn : Uint256, path_len : felt, path : felt*) -> (amounts_len : felt, amounts : Uint256*):
end
getAmountsIn
func getAmountsIn(amountOut : Uint256, path_len : felt, path : felt*) -> (amounts_len : felt, amounts : Uint256*):
end

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
removeLiquidity
func removeLiquidity(
    tokenA : felt,
    tokenB : felt,
    liquidity : Uint256,
    amountAMin : Uint256,
    amountBMin : Uint256,
    to : felt,
    deadline : felt,
) -> (amountA : Uint256, amountB : Uint256):
end
swapExactTokensForTokens
func swapExactTokensForTokens(
    amountIn : Uint256,
    amountOutMin : Uint256,
    path_len : felt,
    path : felt*,
    to : felt,
    deadline : felt,
) -> (amounts_len : felt, amounts : Uint256*):
end
swapTokensForExactTokens
func swapTokensForExactTokens(
    amountOut : Uint256,
    amountInMax : Uint256,
    path_len : felt,
    path : felt*,
    to : felt,
    deadline : felt,
) -> (amounts_len : felt, amounts : Uint256*):
end
swapExactTokensForTokensSupportingFeeOnTransferTokens
func swapExactTokensForTokensSupportingFeeOnTransferTokens(
    amountIn : Uint256,
    amountOutMin : Uint256,
    path_len : felt,
    path : felt*,
    to : felt,
    deadline : felt,
):
end