Turbos
  • 📖About Turbos
    • Getting Started
    • About Turbos Finance
    • Why Sui Network
  • 📽️Products
    • Concentrated Liquidity AMM
      • Fee Tier for Token Pairs
      • Oracle
    • Automated Rebalance Vault
      • Step-by-Step Guide
      • Referral Program
    • TurboStar
    • TurbosBoost
  • 💡Protocol Concepts
    • About Concentrated Liquidity
    • Fee Tiers
    • Glossary
  • 🪙Tokenomics
    • TURBOS
    • Token Utility
    • Emission Distribution
  • ⚙️Others
    • Roadmap
    • Audits
    • Brand kit
    • Risks
    • Token Address
  • Developer Docs
    • Dev Overview
    • via SDK
      • Get Started
      • Initialize SDK
      • Clmm
        • getConfig
        • getFeesConfig
        • getPools
        • getPool
        • createPool
        • createAndAddLiquidity
        • increaseLiquidity
        • decreaseLiquidity
        • removeLiquidityAndBurn
        • preSwap
        • swap
        • collect Fees
        • collect Rewards
        • Fee
        • Liquidity and coin amounts calculation
        • APR calculation
      • Vault
        • createAndDepositVault
        • depositVault
        • withdrawVault
        • withdrawAllVault
        • collectClmmRewardDirectReturnVault
        • closeVault
        • computeTokenWithdrawVaultSwapResult
        • getVaultBalanceAmount
        • getMyVaults
  • Turbos Fun
    • Base
    • Create Pool
    • Calculate Token Amount
    • Buy
    • Sell
  • 📱Socials
    • Official website
    • Twitter
    • Discord
    • Medium
    • Zealy
  • Tutorials
    • Supported Wallets
      • SafePal Wallet
    • Move tutorial
    • Sui tutorial
Powered by GitBook
On this page
  1. Turbos Fun

Sell

Examples

SellOptions

interface sellOptions extends BuyOptions {}

Sell

async sell(options: sellOptions) {
    const { coinType, tx, walletAddress, isExact, threshold, amount } = options;
    const txb = tx || new Transaction();
    const coinAmount = new Decimal(amount)
      .mul(10 ** (!isExact ? this.quote_decimals : this.token_decimals))
      .toFixed(0);
    const { tokenAmount, thresholdAmount } = await this.calculateTokenAndThresholdAmount({
      coinType,
      threshold,
      amount: coinAmount,
      atob: false,
      isExact,
    });
    const coinBalance = coinWithBalance({
      type: coinType,
      balance: Number(isExact ? coinAmount : tokenAmount),
    });
    console.log(coinAmount, tokenAmount, thresholdAmount);
    txb.setSenderIfNotSet(walletAddress);
    const [sui_coin_returned, remaining_token_coin] = txb.moveCall({
      target: `${pakcageId}::parrot_fun::sell`,
      arguments: [
        txb.object(globalConfig),
        txb.object(funConfig),
        coinBalance,
        txb.pure.u64(coinAmount),
        txb.pure.u64(thresholdAmount),
        txb.pure.bool(isExact),
      ],
      typeArguments: [coinType],
    });
    txb.transferObjects([sui_coin_returned!, remaining_token_coin!], walletAddress);
    return txb;
  }

calculateTokenAndThresholdAmount

PreviousBuyNextSupported Wallets

Last updated 3 days ago