LogoLogo
  • Welcome to FlowX Finance
    • ๐Ÿ”ฎProtocol Overview
    • ๐Ÿ•ถ๏ธOur Advantages
    • ๐ŸšฉGetting Started
    • ๐Ÿ—บ๏ธRoadmap
  • PROTOCOL
    • โš–๏ธSwap
    • ๐Ÿ›žDEX Aggregator
    • ๐ŸŽฐLucky Swap
    • โš—๏ธLiquidity Pools
    • ๐ŸŽš๏ธPosition Management
    • ๐ŸชฃFarming as a Service
    • ๐Ÿ’ฐEarning Protocol Fee
    • ๐ŸTrading Competition
    • ๐Ÿ’ฌReferral
  • Tokenomics
    • ๐Ÿš‡FLX Token
    • ๐ŸšŠxFLX Governance Token
  • CONTRACT
    • ๐Ÿ“„GenesiX Farming
    • ๐Ÿ“„Swap
  • ๐Ÿ”ฆGuide
    • How to add Liquidity V3
  • REFERENCES
    • ๐Ÿ›ก๏ธAudit
    • ๐Ÿ–ผ๏ธMedia Kit
    • ๐ŸคPartners
    • ๐ŸงฐSDK
    • ๐Ÿ–ฅ๏ธAggregator Widget
  • ARCHIVED
    • Claim Token
    • ๐ŸงชGenesiX Farming
  • Developer
    • Overview
    • FlowX SDK
      • Getting Started
      • Retrieve coin
      • Swap Aggregator
      • AMM Management
        • Pool Management
        • Position Management
      • CLMM Management
        • Pool Management
        • Position Management
      • Auto Invest
      • Limit Order
  • FlowX Widget
  • Privacy & Terms
    • Risk Disclaimer
    • Terms of Service
  • Social
    • Website
    • Twitter
    • Telegram Channel
    • Discord
Powered by GitBook
On this page
  • Create Plan
  • Remove or cancle plan

Was this helpful?

  1. Developer
  2. FlowX SDK

Auto Invest

Create Plan

// Initialize a new transaction instance to manage the on-chain operations.
const tx = new Transaction();

// Create an AutoInvest instance for the "mainnet" network to automate the investment process.
const autoInvest = new AutoInvest("mainnet");

// Instantiate a PlanBuilder to configure the details of the investment plan.
const planBuilder = new PlanBuilder();

// Create a Coin instance representing the token to be sold in the investment process.
const sellCoin = new Coin("0TokenSell");

// Associate the transaction instance with the AutoInvest instance to track operations.
autoInvest.tx(tx);

// Perform a deposit of the specified token using the `AutoInvest` instance.
// - `type`: Specifies the token type being sold.
// - `object`: Represents the token amount to be deposited using the `sellCoin.take()` function.
// - `owner`: Your account address ('0xAddress').
// - `amount`: The amount of tokens to deposit, specified as a string (e.g., 1000000000000).
// - `client`: The provider instance responsible for blockchain interaction.
// - `tx`: The initialized transaction object to include the deposit action.
autoInvest.deposit({
  type: tokenSell.type,
  object: await sellCoin.take({
    owner: '0xAddress', // Replace with your actual account address
    amount: '1000000000000', // Token amount in smallest units
    client: provider as any,
    tx,
  }),
});

// Determine the plan's start time based on the `instantStart` flag.
// - If `instantStart` is true, the plan starts immediately (`undefined`).
// - Otherwise, a custom start date (`customDate`) is used. Milisecond, example: new Date().getTime() 
const startTime = instantStart ? undefined : customDate;

// Build the investment plan using the PlanBuilder instance by setting various parameters:
// - `setReceiver`: Specifies the wallet address to receive the invested tokens.
// - `setSubscriptionStartTime`: Defines when the subscription will start.
// - `setOwner`: Sets the account that owns the investment plan.
// - `setSubscriptionAmount`: Calculates the per-cycle investment amount using the `BigNumberInstance`.
// - `setSubscriptionCycle`: Defines the cycle frequency using the mapped time unit ["HOUR, DAY, WEEK"] and frequency value.
// - `setExecutionLimit`: Limits the number of investment cycles to the specified `repeat` value.
// - `setSourceAsset`: Specifies the asset being sold, normalized using `normalizeStructTag`.
// - `setTargetAsset`: Specifies the asset being purchased, normalized using `normalizeStructTag`.
// - `build()`: Finalizes the plan configuration.
const plan = planBuilder
  .setReceiver("0xAddress")
  .setSubscriptionStartTime(startTime)
  .setOwner("0xAddess")
  .setSubscriptionAmount(
    BigNumberInstance('1000000000000').div(repeat).toFixed(0)
  )
  .setSubscriptionCycle("DAY", 10) //for example execute for each 10 days
  .setExecutionLimit(10) //number order you want to buy, for example with this setup, you need 100 days to execute order.
  .setSourceAsset(normalizeStructTag(tokenSell.type))
  .setTargetAsset(normalizeStructTag(tokenBuy.type))
  .build();


autoInvest.createPlan(plan);

Remove or cancle plan

const tx = new Transaction();
autoInvest.tx(tx);
autoInvest.removePlan({ planId });
PreviousPosition ManagementNextLimit Order

Last updated 1 month ago

Was this helpful?