# Class: P2P

## P2P(options)

Service class to handle interacting with the Cask P2P system

## Constructor

#### new P2P(options)

Create an instance of the P2P service.

##### Parameters:

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

See:
  - CaskSDK

### Methods

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

Cancel a P2P.

##### Parameters:

Name | Type | Description
--- | --- | ---
`p2pId` | string | P2P ID

##### Returns:

Type
  Promise.<{tx: *}>

#### (async) create(args) → {P2P.CreateP2PResult}

Create a new P2P.

##### Parameters:

Name | Type | Description
--- | --- | ---
`args` | Object | Function arguments ###### Properties
Name | Type | Description
--- | --- | ---
`asset` | string | Address of asset to P2P

##### Returns:

Type
  P2P.CreateP2PResult

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

Get the estimated spend for a P2P 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(p2pId) → {Promise.<P2P.P2PDetail>}

Get the details of a specific P2P flow.

##### Parameters:

Name | Type | Description
--- | --- | ---
`p2pId` |  |

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

##### Returns:

Type
  Promise.<P2P.P2PDetail>

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

Get history for a P2P flow.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`p2pId` | string |  | P2P 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.<P2P.Event>>

#### (async) init(args)

Initialize the P2P service.

##### Parameters:

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

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

Pause an active P2P.

##### Parameters:

Name | Type | Description
--- | --- | ---
`p2pId` | string | P2P ID

##### Returns:

Type
  Promise.<{tx: *}>

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

Resume a paused P2P.

##### Parameters:

Name | Type | Description
--- | --- | ---
`p2pId` | string | P2P ID

##### Returns:

Type
  Promise.<{tx: *}>

#### serviceAvailable() → {boolean}

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

##### Returns:

Type
  boolean

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

Retrieve service configuration parameters for the P2P service.

##### Returns:

Type
  P2P.ServiceParameters

### Type Definitions

#### CreateP2PResult

##### Properties:

Name | Type | Description
--- | --- | ---
`tx` | Object | Create Transaction
`chainId` | number | Chain ID that the transaction took place on
`user` | string | Owner of P2P
`to` | string | Address which will receive the vault tokens on each transfer
`amount` | string | Amount (in vault baseAsset value) for each transfer
`totalAmount` | string | Total amount of vault baseAsset value to transfer over the lifetime of the P2P
`period` | number | Period (in seconds) between each P2P transfer

#### 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
`amount` | number | Amount of vault baseAsset involved in the event
`fee` | number | Amount of vault baseAsset fee involved in the event

#### P2PDetail

##### Properties:

Name | Type | Description
--- | --- | ---
`p2pId` | string | P2P ID
`status` | number | P2P status
`to` | string | Address which receives transferred value
`amount` | number | Amount of vault baseAsset to send on each transfer
`period` | number | Period (in seconds) between each transfer
`createdAt` | number | Unix timestmap of P2P creation time
`processAt` | number | Unit timestamp of next P2P transfer
`totalAmount` | number | Total amount of vault baseAsset value to send across the lifetime of the P2P
`currentAmount` | number | Current amount of vault baseAsset value sent while the P2P has been active
`numPayments` | number | Number of transfers performed to date while the P2P has been active
`numSkips` | number | Number of skips due to an issue with the P2P

#### ServiceParameters

##### Properties:

Name | Type | Description
--- | --- | ---
`minAmount` | number | Minimum amount of value for a new P2P
`minPeriod` | number | Minimum period (in seconds) for a new P2P
`maxSkips` | number | Max number of skips allowed on an P2P before it is canceled
`paymentFee` | number | Fee (in vault baseAsset value) charged for processing a P2P transfer