Smart Contract API
Create a Pair
createPair
/// SwapFactory.cdc
pub fun createPair(
token0Vault: @FungibleToken.Vault,
token1Vault: @FungibleToken.Vault,
accountCreationFee: @FungibleToken.Vault,
stableMode: Bool
): Addressimport FlowToken from 0x1654653399040a61
import FungibleToken from 0xf233dcee88fe0abe
import SwapFactory from 0xb063c16cac85dbd1
// Deploy a SwapPair given token{0|1}'s TokenName and contract address.
//`stableMode` specifies whether the pair uses Uniswap-V2 algorithm (stableMode:false) or Solidly-Stableswap algorithm (stableMode:true).
transaction(Token0Name: String, Token0Addr: Address, Token1Name: String, Token1Addr: Address, stableMode: Bool) {
prepare(userAccount: AuthAccount) {
let flowVaultRef = userAccount.borrow<&FlowToken.Vault>(from: /storage/flowTokenVault)!
assert(flowVaultRef.balance >= 0.002, message: "Insufficient balance to create pair, minimum balance requirement: 0.002 flow")
let accountCreationFeeVault <- flowVaultRef.withdraw(amount: 0.001)
let token0Vault <- getAccount(Token0Addr).contracts.borrow<&FungibleToken>(name: Token0Name)!.createEmptyVault()
let token1Vault <- getAccount(Token1Addr).contracts.borrow<&FungibleToken>(name: Token1Name)!.createEmptyVault()
SwapFactory.createPair(token0Vault: <-token0Vault, token1Vault: <-token1Vault, accountCreationFee: <-accountCreationFeeVault, stableMode: stableMode)
}
}Get Pair & LpToken Info
Get Pairs' Addresses
Param
Type
Comments
getPairInfo
Param
Type
Comments
LpTokenCollection
Swap
Calculate output / input amount
getAmountsOut
Param
Type
Comments
getAmountsIn
Param
Type
Comments
Perform chained-swap
swapExactTokensForTokens
Param
Type
Comments
swapTokensForExactTokens
Param
Type
Comments
Helper functions and Raw apis
Helper functions in SwapConfig
Raw apis in SwapPair
Add & Remove Liquidity
AddLiquidity
RemoveLiquidity
Build a TWAP Oracle
Fixed-window TWAP oracle example:
Sliding-window TWAP oracle example
Flashloan
Flashloan Interfaces
Example usage
Last updated