Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Swap

Hierarchy

  • Tx
    • Swap

Index

Constructors

constructor

  • new Swap(swapProgramAddress?: string, spltProgramAddress?: string, splataProgramAddress?: string, nodeUrl: string): Swap
  • Parameters

    • swapProgramAddress: string = ...
    • spltProgramAddress: string = ...
    • splataProgramAddress: string = ...
    • nodeUrl: string

    Returns Swap

Properties

connection

connection: Connection

nodeUrl

nodeUrl: string

Readonly splataProgramId

splataProgramId: PublicKey

Readonly spltProgramId

spltProgramId: PublicKey

Readonly swapProgramId

swapProgramId: PublicKey

Static oracle

oracle: { deposit: (deltaA: bigint, deltaB: bigint, reserveA: bigint, reserveB: bigint, liquidity: bigint) => { deltaA: bigint; deltaB: bigint; lpt: bigint; newLiquidity: bigint; newReserveA: bigint; newReserveB: bigint }; extract: (a: bigint, b: bigint, reserveA: bigint, reserveB: bigint) => bigint[]; fee: (askAmount: bigint, feeRatio: bigint, taxRatio: bigint) => { askAmount: bigint; fee: bigint; tax: bigint }; inverseSwap: (askAmount: bigint, reserveBid: bigint, reserveAsk: bigint, feeRatio: bigint, taxRatio: bigint) => bigint; rake: (amount: bigint, bidReserve: bigint, askReserve: bigint, feeRatio: bigint, taxRatio: bigint) => bigint; sided_deposit: (deltaA: bigint, deltaB: bigint, reserveA: bigint, reserveB: bigint, liquidity: bigint, feeRatio: bigint, taxRatio: bigint) => { deltaA: bigint; deltaB: bigint; lpt: bigint; newLiquidity: bigint; newReserveA: bigint; newReserveB: bigint }; slippage: (bidAmount: bigint, reserveBid: bigint, reserveAsk: bigint, feeRatio: bigint, taxRatio: bigint) => bigint; swap: (bidAmount: bigint, reserveBid: bigint, reserveAsk: bigint, feeRatio: bigint, taxRatio: bigint) => { askAmount: bigint; newReserveAsk: bigint; newReserveBid: bigint; tax: bigint }; withdraw: (lpt: bigint, liquidity: bigint, reserveA: bigint, reserveB: bigint) => { deltaA: bigint; deltaB: bigint; newReserveA: bigint; newReserveB: bigint } } = ...

Type declaration

  • deposit: (deltaA: bigint, deltaB: bigint, reserveA: bigint, reserveB: bigint, liquidity: bigint) => { deltaA: bigint; deltaB: bigint; lpt: bigint; newLiquidity: bigint; newReserveA: bigint; newReserveB: bigint }
      • (deltaA: bigint, deltaB: bigint, reserveA: bigint, reserveB: bigint, liquidity: bigint): { deltaA: bigint; deltaB: bigint; lpt: bigint; newLiquidity: bigint; newReserveA: bigint; newReserveB: bigint }
      • Parameters

        • deltaA: bigint
        • deltaB: bigint
        • reserveA: bigint
        • reserveB: bigint
        • liquidity: bigint

        Returns { deltaA: bigint; deltaB: bigint; lpt: bigint; newLiquidity: bigint; newReserveA: bigint; newReserveB: bigint }

        • deltaA: bigint
        • deltaB: bigint
        • lpt: bigint
        • newLiquidity: bigint
        • newReserveA: bigint
        • newReserveB: bigint
  • extract: (a: bigint, b: bigint, reserveA: bigint, reserveB: bigint) => bigint[]
      • (a: bigint, b: bigint, reserveA: bigint, reserveB: bigint): bigint[]
      • Parameters

        • a: bigint
        • b: bigint
        • reserveA: bigint
        • reserveB: bigint

        Returns bigint[]

  • fee: (askAmount: bigint, feeRatio: bigint, taxRatio: bigint) => { askAmount: bigint; fee: bigint; tax: bigint }
      • (askAmount: bigint, feeRatio: bigint, taxRatio: bigint): { askAmount: bigint; fee: bigint; tax: bigint }
      • Parameters

        • askAmount: bigint
        • feeRatio: bigint
        • taxRatio: bigint

        Returns { askAmount: bigint; fee: bigint; tax: bigint }

        • askAmount: bigint
        • fee: bigint
        • tax: bigint
  • inverseSwap: (askAmount: bigint, reserveBid: bigint, reserveAsk: bigint, feeRatio: bigint, taxRatio: bigint) => bigint
      • (askAmount: bigint, reserveBid: bigint, reserveAsk: bigint, feeRatio: bigint, taxRatio: bigint): bigint
      • Parameters

        • askAmount: bigint
        • reserveBid: bigint
        • reserveAsk: bigint
        • feeRatio: bigint
        • taxRatio: bigint

        Returns bigint

  • rake: (amount: bigint, bidReserve: bigint, askReserve: bigint, feeRatio: bigint, taxRatio: bigint) => bigint
      • (amount: bigint, bidReserve: bigint, askReserve: bigint, feeRatio: bigint, taxRatio: bigint): bigint
      • Parameters

        • amount: bigint
        • bidReserve: bigint
        • askReserve: bigint
        • feeRatio: bigint
        • taxRatio: bigint

        Returns bigint

  • sided_deposit: (deltaA: bigint, deltaB: bigint, reserveA: bigint, reserveB: bigint, liquidity: bigint, feeRatio: bigint, taxRatio: bigint) => { deltaA: bigint; deltaB: bigint; lpt: bigint; newLiquidity: bigint; newReserveA: bigint; newReserveB: bigint }
      • (deltaA: bigint, deltaB: bigint, reserveA: bigint, reserveB: bigint, liquidity: bigint, feeRatio: bigint, taxRatio: bigint): { deltaA: bigint; deltaB: bigint; lpt: bigint; newLiquidity: bigint; newReserveA: bigint; newReserveB: bigint }
      • Parameters

        • deltaA: bigint
        • deltaB: bigint
        • reserveA: bigint
        • reserveB: bigint
        • liquidity: bigint
        • feeRatio: bigint
        • taxRatio: bigint

        Returns { deltaA: bigint; deltaB: bigint; lpt: bigint; newLiquidity: bigint; newReserveA: bigint; newReserveB: bigint }

        • deltaA: bigint
        • deltaB: bigint
        • lpt: bigint
        • newLiquidity: bigint
        • newReserveA: bigint
        • newReserveB: bigint
  • slippage: (bidAmount: bigint, reserveBid: bigint, reserveAsk: bigint, feeRatio: bigint, taxRatio: bigint) => bigint
      • (bidAmount: bigint, reserveBid: bigint, reserveAsk: bigint, feeRatio: bigint, taxRatio: bigint): bigint
      • Slippage rate describes how price changes It's decimalized by 9

        Parameters

        • bidAmount: bigint
        • reserveBid: bigint
        • reserveAsk: bigint
        • feeRatio: bigint
        • taxRatio: bigint

        Returns bigint

  • swap: (bidAmount: bigint, reserveBid: bigint, reserveAsk: bigint, feeRatio: bigint, taxRatio: bigint) => { askAmount: bigint; newReserveAsk: bigint; newReserveBid: bigint; tax: bigint }
      • (bidAmount: bigint, reserveBid: bigint, reserveAsk: bigint, feeRatio: bigint, taxRatio: bigint): { askAmount: bigint; newReserveAsk: bigint; newReserveBid: bigint; tax: bigint }
      • Parameters

        • bidAmount: bigint
        • reserveBid: bigint
        • reserveAsk: bigint
        • feeRatio: bigint
        • taxRatio: bigint

        Returns { askAmount: bigint; newReserveAsk: bigint; newReserveBid: bigint; tax: bigint }

        • askAmount: bigint
        • newReserveAsk: bigint
        • newReserveBid: bigint
        • tax: bigint
  • withdraw: (lpt: bigint, liquidity: bigint, reserveA: bigint, reserveB: bigint) => { deltaA: bigint; deltaB: bigint; newReserveA: bigint; newReserveB: bigint }
      • (lpt: bigint, liquidity: bigint, reserveA: bigint, reserveB: bigint): { deltaA: bigint; deltaB: bigint; newReserveA: bigint; newReserveB: bigint }
      • Parameters

        • lpt: bigint
        • liquidity: bigint
        • reserveA: bigint
        • reserveB: bigint

        Returns { deltaA: bigint; deltaB: bigint; newReserveA: bigint; newReserveB: bigint }

        • deltaA: bigint
        • deltaB: bigint
        • newReserveA: bigint
        • newReserveB: bigint

Methods

addLiquidity

  • addLiquidity(deltaA: bigint, deltaB: bigint, poolAddress: string, srcAAddress: string, srcBAddress: string, wallet: WalletInterface): Promise<{ lptAddress: string; txId: string }>
  • Add liquidity

    Parameters

    • deltaA: bigint

      Number of A will be deposited

    • deltaB: bigint

      Number of B will be deposited

    • poolAddress: string
    • srcAAddress: string
    • srcBAddress: string
    • wallet: WalletInterface

    Returns Promise<{ lptAddress: string; txId: string }>

    Transaction id, LPT address

addSidedLiquidity

  • addSidedLiquidity(deltaA: bigint, deltaB: bigint, poolAddress: string, srcAAddress: string, srcBAddress: string, wallet: WalletInterface): Promise<{ lptAddress: string; txId: string }>
  • Add sided liquidity

    Parameters

    • deltaA: bigint

      Number of A will be deposited

    • deltaB: bigint

      Number of B will be deposited

    • poolAddress: string
    • srcAAddress: string
    • srcBAddress: string
    • wallet: WalletInterface

    Returns Promise<{ lptAddress: string; txId: string }>

    Transaction id, LPT address

closeLPT

  • closeLPT(lptAddress: string, wallet: WalletInterface): Promise<{ txId: String }>

derivePoolAddress

  • derivePoolAddress(mintAuthorityAddress: string, freezeAuthorityAddress: string): Promise<undefined | string>
  • Derive the corresponding pool address to the splt mint

    Parameters

    • mintAuthorityAddress: string
    • freezeAuthorityAddress: string

    Returns Promise<undefined | string>

freezePool

  • freezePool(poolAddress: string, wallet: WalletInterface): Promise<{ txId: string }>

getLPTData

  • getLPTData(lptAddress: string): Promise<AccountData & { pool: string }>
  • Get lpt data Indentical to get account (SPLT) data, but with pool check

    Parameters

    • lptAddress: string

    Returns Promise<AccountData & { pool: string }>

getPoolData

  • getPoolData(poolAddress: string): Promise<PoolData>

initializeLPT

  • initializeLPT(mintLPTAddress: string, ownerAddress: string, wallet: WalletInterface): Promise<{ accountAddress: string; txId: string }>
  • Initialize LPT This function is rarely used. Any related accounts will be auto initialized by amm contract

    Parameters

    Returns Promise<{ accountAddress: string; txId: string }>

initializePool

  • initializePool(deltaA: bigint, deltaB: bigint, feeRatio: bigint, taxRatio: bigint, ownerAddress: string, srcAAddress: string, srcBAddress: string, taxmanAddress: string, wallet: WalletInterface): Promise<{ lptAddress: string; mintLPTAddress: string; poolAddress: string; txId: string }>
  • Initialize a swap pool

    Parameters

    • deltaA: bigint

      Number of A (then first token)

    • deltaB: bigint

      Number of B (then second token)

    • feeRatio: bigint
    • taxRatio: bigint
    • ownerAddress: string

      Pool owner address

    • srcAAddress: string

      A source address

    • srcBAddress: string

      B source address

    • taxmanAddress: string

      Foundation SEN account address

    • wallet: WalletInterface

    Returns Promise<{ lptAddress: string; mintLPTAddress: string; poolAddress: string; txId: string }>

    Transaction id, pool address, mint LPT address, lpt address

parseLPTData

parsePoolData

removeLiquidity

  • removeLiquidity(lpt: bigint, poolAddress: string, dstAAddress: string, dstBAddress: string, wallet: WalletInterface): Promise<{ lptAddress: string; txId: string }>
  • Remove liquidity

    Parameters

    • lpt: bigint

      Number of lpt will be withdrawn

    • poolAddress: string
    • dstAAddress: string
    • dstBAddress: string
    • wallet: WalletInterface

    Returns Promise<{ lptAddress: string; txId: string }>

    Transaction id, LPT address

route

  • Route

    Parameters

    • amount: bigint

      that's mean amount of biding tokens

    • limit: bigint

      that's mean the flooring amount of asking tokens

    • routingAddress: RoutingAddress[]

      is array of RoutingAddress include in poolAddress, srcAddress and dstAddress

    • wallet: WalletInterface

    Returns Promise<{ dst: string; txId: string }>

swap

  • swap(amount: bigint, limit: bigint, poolAddress: string, srcAddress: string, dstAddress: string, wallet: WalletInterface): Promise<{ txId: string }>
  • Swap

    Parameters

    • amount: bigint

      Amount of biding tokens

    • limit: bigint

      The flooring amount of asking tokens

    • poolAddress: string
    • srcAddress: string
    • dstAddress: string
    • wallet: WalletInterface

    Returns Promise<{ txId: string }>

thawPool

  • thawPool(poolAddress: string, wallet: WalletInterface): Promise<{ txId: string }>

transferPoolOwnership

  • transferPoolOwnership(poolAddress: string, newOwnerAddress: string, wallet: WalletInterface): Promise<{ txId: string }>
  • Transfer pool's ownership

    Parameters

    Returns Promise<{ txId: string }>

transferTaxman

  • transferTaxman(poolAddress: string, newTaxmanAddress: string, wallet: WalletInterface): Promise<{ txId: string }>
  • Transfer taxman

    Parameters

    Returns Promise<{ txId: string }>

unwatch

  • unwatch(watchId: number): Promise<void>
  • Unwatch a watcher by watch id

    Parameters

    • watchId: number

    Returns Promise<void>

updateFee

  • updateFee(feeRatio: bigint, taxRatio: bigint, poolAddress: string, wallet: WalletInterface): Promise<{ txId: string }>
  • Update fee & tax

    Parameters

    • feeRatio: bigint

      Fee (10^8 precision)

    • taxRatio: bigint

      Tax (10^8 precision)

    • poolAddress: string
    • wallet: WalletInterface

    Returns Promise<{ txId: string }>

watch

  • watch(callback: (error: null | string, data: null | (Omit<SwapAccountChangeInfo, "data"> & { data: PoolData })) => void, filters?: GetProgramAccountsFilter[]): number

wrapSol

  • wrapSol(amount: bigint, wallet: WalletInterface): Promise<{ accountAddress: string; txId: string }>

Generated using TypeDoc