DCA

Automated Dollar-Cost Averaging (DCA) strategy to invest steadily over time, minimizing the impact of market volatility and building positions across multiple assets or pools with ease.

DCA

const dca = new Aftermath("MAINNET").Dca();\

Fetch Orders

Active and Past Orders

const allOrders = await dca.getActiveDcaOrders({
  walletAddress: "0x..",
});

Response

{
  "active": [
    {
      "objectId": "0x..",
      "overview": [
        // ..
      ],
      "failed": [
        // ..
      ],
      "trades": [
        // ..
      ]
    }
  ],
  "past": [
    // ..
  ]
}

Active Orders

const activeOrders = await dca.getActiveDcaOrders({
  walletAddress: "0x..",
});

const pastOrders = await dca.getPastDcaOrders({
  walletAddress: "0x..",
});

Response

{
  "activeOrders": [
    {
      "objectId": "0x..",
      "overview": {
        "allocatedCoin": {
          "coin": "0x..",
          "amount": "1_000_000n"
        },
        "buyCoin": {
          "coin": "0x..",
          "amount": "1_000_000n"
        },
        "totalSpent": "1_000_000n",
        "intervalMs": 60000,
        "totalTrades": 2,
        "tradesRemaining": 1,
        "maxSlippageBps": 10000,
        "progress": 0.5,
        "recipient": "0x..",
        "created": {
          "time": "1721129837764",
          "tnxDigest": "AZLn7s4X..."
        },
        "nextTrade": {
          "time": 1721129777764,
          "tnxDigest": "AZLn7s4X..."
        }
      },
      "failed": [
        {
          "timestamp": 1721129777764,
          "reason": "INTERNAL"
        }
      ],
      "trades": [
        {
          "allocatedCoin": {
            "coin": "0x..",
            "amount": "1_000_000n"
          },
          "buyCoin": {
            "coin": "0x..",
            "amount": "1_000_000n"
          },
          "tnxDigest": "AZLn7s4X...",
          "tnxDate": "1731751113062",
          "rate": 0.00490028
        }
      ]
    }
  ]
}

Error Codes

Create Order

Final minimum and maximum strategy values should be multipled by "coinPerTradeAmount". E.g. user inputs minimum price equal 1SUI ~ 2.0 wUSDC trading 10 Sui to wUSDC in 5 trades. Final minimum price will be (2.0 * 10 SUI) * decimals (wUSDC)

Code Example

const tx = dca.getCreateDcaOrderTx({
  walletAddress: "0x..",
  allocateCoinType: "0x2::sui::SUI",
  allocateCoinAmount: BigInt(10_000_000_000), // 10 SUI
  buyCoinType: "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN",
  frequencyMs: 60000,
  tradesAmount: 5,
  delayTimeMs: 0,
  maxAllowableSlippageBps: 100,
  coinPerTradeAmount: BigInt(2_000_000_000), // 2 SUI
  customRecipient: "0x..",
  strategy: {
    minPrice: BigInt(4_000_000), // 1SUI ~ 2.0
    maxPrice: BigInt(8_000_000), // 1SUI ~ 4.0
  },
});

Cancel Order

Signed Message Inputs

Close DCA Order Inputs

Code Example

const signedMessage = dca.closeDcaOrderMessageToSign({
	action: "CANCEL_DCA_ORDER",
	order_object_id: "0x.."
});

const success = await dca.closeDcaOrder({
	...signedMessage,
	walletAddress: "0x..",
});

Last updated