Uniswap

Create DEX swaps using Uniswap

These connectors are used to buy and sell on Uniswap and to add or remove liquidity from the protocol. Uniswap is an AMM (Automated Market Marker) all swaps are conducted at market value, utilize slippage to prevent runaway price changes.

Buy

Buy tokens on Uniswap at market value

spells.add({
  connector: "uniswap",
  method: "buy",
  args: [buyAddr, sellAddr, buyAmt, unitAmt, getId, setId]
});

Parameter

Type

Description

buyAddr

address

The token address to buy.

sellAddr

address

The token address to sell.

buyAmt

number

The amount of tokens to buy.

unitAmt

number

The unit amount of sellAmt/buyAmt with slippage.

getId

number

ID fetches the buy amount of buy token.

setId

number

ID stores the sold amount of sell token.

Sell

Sell ETH or ERC20 on Uniswap at market value

spells.add({
  connector: "uniswap",
  method: "sell",
mad    args: [buyAddr, sellAddr, sellAmt, unitAmt, getId, setId]
});

Parameter

Type

Description

buyAddr

address

The token address to buy.

sellAddr

address

The token address to sell.

sellAmt

number

The amount of tokens to sell.

unitAmt

number

The unit amount of sellAmt/buyAmt with slippage.

getId

number

ID fetches the sell amount of sell token.

setId

number

ID stores the bought amount of buy token.

Deposit Liquidity

Deposit Liquidity into Uniswap

spells.add({
  connector: "uniswap",
  method: "deposit",
  args: [tokenA, tokenB, amtA, unitAmt, slippage, getId, setId]
});

Parameter

Type

Description

tokenA

address

The token A address.

tokenB

address

The token B address.

amtA

number

The amount of token A.

unitAmt

number

The unit amount of amtB/amtA with slippage.

slippage

number

The slippage amount.

getId

number

ID fetches the amount of token to deposit.

setId

number

ID stores the amount of token deposited.

Withdraw Liquidity

Withdraw Liquidity from Uniswap

spells.add({
  connector: "uniswap",
  method: "withdraw",
  args: [tokenA, tokenB, uniAmt, unitAmtA, unitAmtB, getId, setIds]
});

Parameter

Type

Description

tokenA

address

The token A address.

tokenB

address

The token B address

uniAmt

number

The uni token amount.

unitAmtA

number

The unit amount of amtA/uniAmt with slippage.

unitAmtB

number

unit amount of amtB/uniAmt with slippage.

getId

number

ID fetches the uni token amount to withdraw.

setIds

number array

ID stores the amount of tokenA and tokenB withdrawn. If not sure, pass `["0", "0"]`

Last updated