# Class: DCA

## DCA(options)

Service class to handle interacting with the Cask DCA system.

## Constructor

#### new DCA(options)

Create an instance of the DCA service.

##### Parameters:

Name | Type | Description
--- | --- | ---
`options` |  | See CaskSDK configuration.

See:
  - CaskSDK

### Members

#### STATUS

Status of an DCA

#### SWAP_PROTOCOL

Swap protocol used for DCA

### Methods

#### (async) assetDefinition() → {Promise.<DCA.DCAAssetDefinition>}

Get the specified asset definition from the asset manifest.

##### Returns:

Type
  Promise.<DCA.DCAAssetDefinition>

#### (async) assetPrice() → {Promise.<string>}

Get the current price of a DCA asset denominated in the vault base asset.

##### Returns:

Type
  Promise.<string>

#### (async) cancel(dcaId) → {Promise.<{tx: *}>}

Cancel a DCA.

##### Parameters:

Name | Type | Description
--- | --- | ---
`dcaId` | string | DCA ID

##### Returns:

Type
  Promise.<{tx: *}>

#### (async) create(args) → {DCA.CreateDCAResult}

Create a new DCA.

##### Parameters:

Name | Type | Description
--- | --- | ---
`args` | Object | Function arguments ###### Properties
Name | Type | Attributes | Description
--- | --- | --- | ---
`asset` | string |  | Address of asset to DCA
`amountSimple` | float | <optional> | Amount of vault baseAsset value to spend per DCA purchase swap (simple format)
`amountAsset` | string | <optional> | Amount of vault baseAsset value to spend per DCA purchase swap (asset format)
`amount` | string | <optional> | Alias for `amountAsset`
`totalAmountSimple` | float | <optional> | Total amount of vault baseAsset value to spend over the lifetime of the DCA (simple format)
`totalAmountAsset` | string | <optional> | Total amount of vault baseAsset value to spend over the lifetime of the DCA (asset format)
`totalAmount` | string | <optional> | Alias for `totalAmountAsset`
`minPriceSimple` | float | <optional> | Minimum price (in vault baseAssset value) the asset must be for the purchase swap to be attempted (simple format)
`minPriceAsset` | string | <optional> | Minimum price (in vault baseAssset value) the asset must be for the purchase swap to be attempted (asset format)
`minPrice` | string | <optional> | Alias for `minPriceAsset`
`maxPriceSimple` | float | <optional> | Maximum price (in vault baseAssset value) the asset must be for the purchase swap to be attempted (simple format)
`maxPriceAsset` | string | <optional> | Maximum price (in vault baseAssset value) the asset must be for the purchase swap to be attempted (asset format)
`maxPrice` | string | <optional> | Alias for `maxPriceAsset`
`period` | number |  | Period (in seconds) of each DCA purchase swap
`maxSlippageBps` | number |  | Maximum slippage (in BPS) to allow during a purchase swap attempt

##### Returns:

Type
  DCA.CreateDCAResult

#### (async) estimatedCommitment(address, periodopt)

Get the estimated spend for a DCA for a specific period.

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`address` | string |  |  | User address
`period` | number | <optional> | 1 month | Commitment period (in seconds)

#### (async) get(dcaId) → {Promise.<DCA.DCADetail>}

Get the details of a specific DCA.

##### Parameters:

Name | Type | Description
--- | --- | ---
`dcaId` |  |

See:
  - The SDK guide for more details on unit formatting at https://docs.cask.fi/developer-docs/javascript-sdk

##### Returns:

Type
  Promise.<DCA.DCADetail>

#### (async) history(dcaId, queryoptsopt) → {Promise.<Array.<DCA.Event>>}

Get history for a DCA flow.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`dcaId` | string |  | DCA ID
`queryopts` |  | <optional> | Optional query options ###### Properties
Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`limit` |  | <optional> | 10 | Limit
`offset` |  | <optional> | 0 | Offset
`orderBy` |  | <optional> | timestamp | Order by
`orderDirection` |  | <optional> | desc | Order direction, one of asc or desc
`options` |  | <optional> |  | Optional options to pass to apollo for graphQL

##### Returns:

Type
  Promise.<Array.<DCA.Event>>

#### (async) init(args)

Initialize the DCA service.

##### Parameters:

Name | Type | Description
--- | --- | ---
`args` | Object | Function arguments ###### Properties
Name | Type | Attributes | Description
--- | --- | --- | ---
`ethersConnection` | EthersConnection | <optional> | EthersConnection instance

#### (async) loadDCAManifest() → {Promise.<Object>}

Load the DCA asset manifest.

##### Returns:

Type
  Promise.<Object>

#### (async) pause(dcaId) → {Promise.<{tx: *}>}

Pause an active DCA.

##### Parameters:

Name | Type | Description
--- | --- | ---
`dcaId` | string | DCA ID

##### Returns:

Type
  Promise.<{tx: *}>

#### (async) resume(dcaId) → {Promise.<{tx: *}>}

Resume a paused DCA.

##### Parameters:

Name | Type | Description
--- | --- | ---
`dcaId` | string | DCA ID

##### Returns:

Type
  Promise.<{tx: *}>

#### serviceAvailable() → {boolean}

See if the DCA service is available on the currently connected chain.

##### Returns:

Type
  boolean

#### serviceParameters() → {DCA.ServiceParameters}

Retrieve service configuration parameters for the DCA service.

##### Returns:

Type
  DCA.ServiceParameters

### Type Definitions

#### CreateDCAResult

##### Properties:

Name | Type | Description
--- | --- | ---
`tx` | Object | Create Transaction
`chainId` | number | Chain ID that the transaction took place on
`dcaId` | string | ID of newly created DCA
`user` | string | Owner of DCA
`to` | string | Address which will receive purchased assets for the DCA
`inputAsset` | string | Address of the input asset used for the DCA
`outputAsset` | string | Address of the purchased DCA asset
`amount` | string | Amount (in vault baseAsset value) for each purchase swap of the DCA
`totalAmount` | string | Total amount of vault baseAsset value to spend over the lifetime of the DCA
`period` | number | Period (in seconds) between each DCA purchase swap

#### DCAAssetDefinition

##### Properties:

Name | Type | Description
--- | --- | ---
`inputAssetSymbol` | string | Input asset symbol
`outputAssetSymbol` | string | Output asset symbol
`outputAssetIconUrl` | string | Output asset icon URL
`routerName` | string | Name of swap router
`router` | string | Address of swap router
`priceFeed` | string | Address of asset price oracle
`path` | Array.<string> | Asset swap path
`chainId` | number | Chain ID

#### DCADetail

##### Properties:

Name | Type | Description
--- | --- | ---
`dcaId` | string | DCA ID
`status` | number | DCA status
`to` | string | Address which receives purchased asset
`swapProtocol` | number | Swap protocol used for DCA
`swapData` | string | Extra calldata associated with DCA used by swap protocol
`router` | string | Router used to perform swaps
`priceFeed` | string | Address of oracle price feed for the purchasing asset
`path` | Array.<string> | Asset path for DCA swap
`amount` | number | Amount of vault baseAsset to spend on each DCA swap
`period` | number | Period (in seconds) between each asset purchase
`maxSlippageBps` | number | Maximum slippage (in BPS) allowed during a purchase swap attempt
`createdAt` | number | Unix timestamp of DCA creation time
`processAt` | number | Unit timestamp of next DCA purchase
`totalAmount` | number | Total amount of vault baseAsset value to spend across the lifetime of the DCA
`currentAmount` | number | Current amount of vault baseAsset value spent while the DCA has been active
`numBuys` | number | Number of swap purchases performed to date while the DCA has been active
`numSkips` | number | Number of skips due to an issue with the DCA
`minPrice` | number | Minimum price (in vault baseAssset value) the asset must be for the purchase swap to be attempted
`maxPrice` | number | Maximum price (in vault baseAssset value) the asset must be for the purchase swap to be attempted

#### Event

##### Properties:

Name | Type | Description
--- | --- | ---
`txnId` | string | On-chain transaction ID of event
`timestamp` | number | Unix timestamp of event
`user.id` | string | Address of user for event
`type` | string | Event type
`assetAddress` | string | Address of asset
`amount` | number | Amount of vault baseAsset involved in the event
`fee` | number | Amount of vault baseAsset fee involved in the event
`buyQty` | number | Amount of the purchased asset
`skipReason` | number | Reason why the purchase attempt was skipped

#### ServiceParameters

##### Properties:

Name | Type | Description
--- | --- | ---
`assetsMerkleRoot` | string | Merkleroot of the approved assets
`minAmount` | number | Minimum amount of value for a new DCA
`minPeriod` | number | Minimum period (in seconds) for a new DCA
`minSlippage` | number | Minimum slippage (in BPS) allowed for a new DCA
`maxSkips` | number | Max number of skips allowed on an DCA before it is canceled
`dcaFeeBps` | number | Fee (in BPS) charged for processing an DCA
`dcaFeeMin` | number | Minimum fee (in vault baseAsset units) charged for processing an DCA
`dcaMinValue` | number | Minimum amount of value for a new DCA