SF Swap Core
September 2024
Abstract
This technical whitepaper explains some of the design decisions behind the Stochastic.Finance Swap (further: SFSwap) core contracts. It covers the contracts’ features including arbitrary pairs between ERC20 (further: Stable Coin) and ERC1155 (further: Trade Coin), an AMM that allowes traders to watch liquidity of pairs and collect a price information, swaps that allow traders to buy/sell options produced on Stochastic.Finance DAPP. This whitepaper describes the mechanics of SFSwap “core” contracts including the pair contract that stores liquidity providers’ funds—and the factory contract used to instantiate pair contracts.
1. Introduction
SFSwap is an on-chain system of smart contracts on the Ethereum blockchain, implementing an automated liquidity protocol based on a “constant product formula” with additional features. Mostly it enables the creation only of arbitrary ERC20/ERC1155 pairs. Each SFSwap pair stores pooled reserves of two assets (Stable Coin and Trade Coin), and provides liquidity for those two assets, maintaining the invariant that the product of the reserves cannot decrease. Traders pay zero fee (read in ??? "Zero fee policy" section) on trades, which goes to liquidity providers. The contracts are non-upgradeable. As discussed in section ???, SFSwap also has all safety and security fixes, as well as rearchitecting the implementation, reducing SFSwap’s attack surface.
This paper describes the mechanics of that core contract, as well as the factory contract used to instantiate those contracts. Actually using SFSwap will require calling the pair contract through a “router” contract that computes the trade or deposit amount and transfers funds to the pair contract
2. Features
2.1 ERC-20/ERC-1155 pairs
SFSwap allows liquidity providers to create pair contracts only for Stable Coin and any parts (ERC-1155 ids) or Trade Coin.