# Charged State Contract

## Get State Data

> ***Get info on time locks, approvals, and permissions.***

### getDischargeTimelockExpiry

Gets unlock block for Discharge time lock.

```d
function getDischargeTimelockExpiry(
  address contractAddress,
  uint256 tokenId
) external view virtual override returns (uint256 lockExpiry);
```

| Parameter / Return Value | Description                                   |
| ------------------------ | --------------------------------------------- |
| contractAddress          | address of contract for Particle              |
| tokenId                  | id of Particle to check time lock for         |
| lockExpiry               | unlock block for Particle's Charge (interest) |

### getReleaseTimelockExpiry

Gets unlock block for Release time lock.

```d
function getReleaseTimelockExpiry(
  address contractAddress,
  uint256 tokenId
) external view virtual override returns (uint256 lockExpiry);
```

| Parameter / Return Value | Description                                  |
| ------------------------ | -------------------------------------------- |
| contractAddress          | address of contract for Particle             |
| tokenId                  | id of Particle to check time lock for        |
| lockExpiry               | unlock block for Particle's Mass (principal) |

### getBreakBondTimelockExpiry

Gets unlock block for restrictions on withdrawing NFTs from a Particle (covalent bonds).

```d
function getBreakBondTimelockExpiry(
  address contractAddress,
  uint256 tokenId
) external view virtual override returns (uint256 lockExpiry);
```

| Parameter / Return Value | Description                                       |
| ------------------------ | ------------------------------------------------- |
| contractAddress          | address of contract for Particle                  |
| tokenId                  | id of Particle to check time lock for             |
| lockExpiry               | unlock block for Particle's covalent bonds (NFTs) |

### isApprovedForDischarge

Checks if an operator is allowed to Discharge a specific Particle.

```d
function isApprovedForDischarge(
  address contractAddress,
  uint256 tokenId,
  address operator
) external virtual override view returns (bool);`
```

| Parameter / Return Value | Description                         |
| ------------------------ | ----------------------------------- |
| contractAddress          | address of contract for Particle    |
| tokenId                  | id of Particle to check approval of |
| operator                 | address of the operator to check    |
| return                   | True if operator approved           |

### isApprovedForRelease

Checks if an operator is allowed to Release a specific Particle.

```d
function isApprovedForRelease(
  address contractAddress,
  uint256 tokenId,
  address operator
) external virtual override view returns (bool);`
```

| Parameter / Return Value | Description                         |
| ------------------------ | ----------------------------------- |
| contractAddress          | address of contract for Particle    |
| tokenId                  | id of Particle to check approval of |
| operator                 | address of the operator to check    |
| return                   | True if operator approved           |

### isApprovedForBreakBond

Checks if an operator is allowed to Break Covalent Bonds on a specific Particle.

```d
function isApprovedForBreakBond(
  address contractAddress,
  uint256 tokenId,
  address operator
) external virtual override view returns (bool);`
```

| Parameter / Return Value | Description                         |
| ------------------------ | ----------------------------------- |
| contractAddress          | address of contract for Particle    |
| tokenId                  | id of Particle to check approval of |
| operator                 | address of the operator to check    |
| return                   | True if operator approved           |

### isApprovedForTimelock

Checks if an operator is allowed to Timelock a specific Particle.

```d
function isApprovedForTimelock(
  address contractAddress,
  uint256 tokenId,
  address operator
) external virtual override view returns (bool);`
```

| Parameter / Return Value | Description                         |
| ------------------------ | ----------------------------------- |
| contractAddress          | address of contract for Particle    |
| tokenId                  | id of Particle to check approval of |
| operator                 | address of the operator to check    |
| return                   | True if operator approved           |

### isEnergizeRestricted

Checks if energizing a specific Particle is restricted.

```d
function isEnergizeRestricted(
  address contractAddress,
  uint256 tokenId
) external virtual override view returns (bool);'
```

| Parameter / Return Value | Description                            |
| ------------------------ | -------------------------------------- |
| contractAddress          | address of contract for Particle       |
| tokenId                  | id of Particle to check restriction of |
| return                   | whether or not energizing restricted   |

### isCovalentBondRestricted

Checks if covalent bonding (depositing NFTs into a Particle) for a specific Particle is restricted.

```d
function isCovalentBondRestricted(
  address contractAddress,
  uint256 tokenId
) external virtual override view returns (bool);
```

| Parameter / Return Value | Description                            |
| ------------------------ | -------------------------------------- |
| contractAddress          | address of contract for Particle       |
| tokenId                  | id of Particle to check restriction of |
| return                   | whether or not bonding restricted      |

### getDischargeState

Gets state of discharge settings / permissions for a Particle.

```d
function getDischargeState(
  address contractAddress, 
  uint256 tokenId,
  address sender
) external view virtual override 
  returns (
    bool allowFromAll, 
    bool isApproved, 
    uint256 timelock, 
    uint256 tempLockExpiry
  );
```

| Parameter / Return Value | Description                                    |
| ------------------------ | ---------------------------------------------- |
| contractAddress          | address of contract for Particle               |
| tokenId                  | id of Particle to check state of               |
| sender                   | address of transaction sender                  |
| allowFromAll             | whether or not all can discharge from Particle |
| isApproved               | discharge approval status                      |
| timelock                 | unlock block for charge (interest)             |
| tempLockExpiry           | unlock block for temporary time lock           |

### getReleaseState

Gets state of release settings / permissions for a Particle.

```d
function getDischargeState(
  address contractAddress, 
  uint256 tokenId,
  address sender
) external view virtual override 
  returns (
    bool allowFromAll, 
    bool isApproved, 
    uint256 timelock, 
    uint256 tempLockExpiry
  );
```

| Parameter / Return Value | Description                               |
| ------------------------ | ----------------------------------------- |
| contractAddress          | address of contract for Particle          |
| tokenId                  | id of Particle to check state of          |
| sender                   | address of transaction sender             |
| allowFromAll             | whether or not all can release a Particle |
| isApproved               | discharge approval status                 |
| timelock                 | unlock block for mass (principal)         |
| tempLockExpiry           | unlock block for temporary time lock      |

### getBreakBondState

Gets state of covalent bond breaking (releasing an NFT) settings / permissions for a Particle.

```d
function getBreakBondState(
  address contractAddress,
  uint256 tokenId,
  address sender
) external view virtual override 
  returns (
    bool allowFromAll, 
    bool isApproved,
    uint256 timelock,
    uint256 tempLockExpiry
  );
```

| Parameter / Return Value | Description                                         |
| ------------------------ | --------------------------------------------------- |
| contractAddress          | address of contract for Particle                    |
| tokenId                  | id of Particle to check state of                    |
| sender                   | address of transaction sender                       |
| allowFromAll             | whether or not all can release an NFT from Particle |
| isApproved               | discharge approval status                           |
| timelock                 | unlock block for mass (principal)                   |
| tempLockExpiry           | unlock block for temporary time lock                |

## Set Permissions + Approvals

> ***Update a Particle's permissions and approvals***

### setDischargeApproval

Sets an Operator as Approved to Discharge a specific Token. This allows an operator to withdraw the interest-portion only.

```d
function setDischargeApproval(
  address contractAddress,
  uint256 tokenId,
  address operator
) external 
  virtual
  override
  onlyErc721OwnerOrOperator(contractAddress, tokenId, _msgSender());
```

| Parameter / Return Value | Description                        |
| ------------------------ | ---------------------------------- |
| contractAddress          | address of contract for Particle   |
| tokenId                  | id of Particle to set approval for |
| operator                 | address of Particle operator       |

### setReleaseApproval

Sets an Operator as Approved to Release a specific Token. This allows an operator to withdraw the principal + interest.

```d
function setReleaseApproval(
  address contractAddress,
  uint256 tokenId,
  address operator
) external
  virtual
  override
  onlyErc721OwnerOrOperator(contractAddress, tokenId, _msgSender());
```

| Parameter / Return Value | Description                      |
| ------------------------ | -------------------------------- |
| contractAddress          | address of contract for Particle |
| tokenId                  | id of Particle set approval for  |
| operator                 | address of Particle operator     |

### setBreakBondApproval

Sets an Operator as Approved to Break Covalent Bonds on a specific Token. This allows an operator to withdraw Basket NFTs.

```d
function setBreakBondApproval(
  address contractAddress,
  uint256 tokenId,
  address operator
) external
  virtual
  override
  onlyErc721OwnerOrOperator(contractAddress, tokenId, _msgSender());
```

| Parameter / Return Value | Description                        |
| ------------------------ | ---------------------------------- |
| contractAddress          | address of contract for Particle   |
| tokenId                  | id of Particle to set approval for |
| operator                 | address of Particle operator       |

### setTimelockApproval

Sets an Operator as Approved to Timelock a specific Token. This allows an operator to timelock the principal or interest.

```d
function setTimelockApproval(
  address contractAddress,
  uint256 tokenId,
  address operator
) external
  virtual
  override
  onlyErc721OwnerOrOperator(contractAddress, tokenId, _msgSender());
```

| Parameter / Return Value | Description                        |
| ------------------------ | ---------------------------------- |
| contractAddress          | address of contract for Particle   |
| tokenId                  | id of Particle to set approval for |
| operator                 | address of Particle operator       |

### setApprovalForAll

Sets an Operator as Approved to Discharge/Release/Timelock a specific Token.

```d
function setApprovalForAll(
  address contractAddress,
  uint256 tokenId,
  address operator
) external
  virtual
  override
  onlyErc721OwnerOrOperator(contractAddress, tokenId, _msgSender());
```

| Parameter / Return Value | Description                        |
| ------------------------ | ---------------------------------- |
| contractAddress          | address of contract for Particle   |
| tokenId                  | id of Particle to set approval for |
| operator                 | address of Particle operator       |

### setPermsForRestrictCharge

Updates Restrictions on Energizing an NFT.

```d
function setPermsForRestrictCharge(
  address contractAddress,
  uint256 tokenId,
  bool state
  ) external
    virtual
    override
    onlyErc721OwnerOrOperator(contractAddress, tokenId, _msgSender());
```

| Parameter / Return Value | Description                           |
| ------------------------ | ------------------------------------- |
| contractAddress          | address of contract for Particle      |
| tokenId                  | id of Particle to set permissions for |
| state                    | state of permissions for action       |

### setPermsForAllowDischarge

Updates Allowance on Discharging an NFT by Anyone.

```d
function setPermsForAllowDischarge(
  address contractAddress,
  uint256 tokenId,
  bool state
) external
  virtual
  override
  onlyErc721OwnerOrOperator(contractAddress, tokenId, _msgSender());
```

| Parameter / Return Value | Description                           |
| ------------------------ | ------------------------------------- |
| contractAddress          | address of contract for Particle      |
| tokenId                  | id of Particle to set permissions for |
| state                    | state of permissions for action       |

### setPermsForAllowRelease

Updates Allowance on Releasing an NFT by Anyone.

```d
function setPermsForAllowRelease(
  address contractAddress,
  uint256 tokenId,
  bool state
) external
  virtual
  override
  onlyErc721OwnerOrOperator(contractAddress, tokenId, _msgSender());
```

| Parameter / Return Value | Description                           |
| ------------------------ | ------------------------------------- |
| contractAddress          | address of contract for Particle      |
| tokenId                  | id of Particle to set permissions for |
| state                    | state of permissions for action       |

### setPermsForRestrictBond

Updates Restrictions on Covalent Bonds on an NFT.

```d
function setPermsForRestrictBreakBond(
  address contractAddress,
  uint256 tokenId,
  bool state
) external
  virtual
  override
  onlyErc721OwnerOrOperator(contractAddress, tokenId, _msgSender());
```

| Parameter / Return Value | Description                           |
| ------------------------ | ------------------------------------- |
| contractAddress          | address of contract for Particle      |
| tokenId                  | id of Particle to set permissions for |
| state                    | state of permissions for action       |

### setPermsForAllowBreakBond

Updates Allowance on Breaking Covalent Bonds on an NFT by Anyone.

```d
function setPermsForAllowBreakBond(
  address contractAddress,
  uint256 tokenId,
  bool state
) external
  virtual
  override
  onlyErc721OwnerOrOperator(contractAddress, tokenId, _msgSender());
```

| Parameter / Return Value | Description                           |
| ------------------------ | ------------------------------------- |
| contractAddress          | address of contract for Particle      |
| tokenId                  | id of Particle to set permissions for |
| state                    | state of permissions for action       |

## Set Timelocks

> ***Update time locks for a particles Mass (principal), Charge (interest), or Bonds (locked NFTs)***

### setDischargeTimelock

Sets a Timelock on the ability to Discharge the Interest of a Particle.

```d
function setDischargeTimelock(
  address contractAddress,
  uint256 tokenId,
  uint256 unlockBlock
) external override virtual;
```

| Parameter / Return Value | Description                             |
| ------------------------ | --------------------------------------- |
| contractAddress          | address of contract for Particle        |
| tokenId                  | id of Particle to set time lock for     |
| state                    | Ethereum Block-number to Timelock until |

### setReleaseTimelock

Sets a Timelock on the ability to Release the Assets of a Particle.

```d
function setReleaseTimelock(
  address contractAddress,
  uint256 tokenId,
  uint256 unlockBlock
) external override virtual;
```

| Parameter / Return Value | Description                             |
| ------------------------ | --------------------------------------- |
| contractAddress          | address of contract for Particle        |
| tokenId                  | id of Particle to set time lock for     |
| unlockBlock              | Ethereum Block-number to Timelock until |

### setBreakBondTimelock

Sets a Timelock on the ability to Break the Covalent Bond of a Particle.

```d
function setBreakBondTimelock(
  address contractAddress,
  uint256 tokenId,
  uint256 unlockBlock
) external override virtual;
```

| Parameter / Return Value | Description                             |
| ------------------------ | --------------------------------------- |
| contractAddress          | address of contract for Particle        |
| tokenId                  | id of Particle to set time lock for     |
| unlockBlock              | Ethereum Block-number to Timelock until |

## Other

### Events

**ChargedSettingsSet**

```erlang
event ChargedSettingsSet(address indexed settingsController);
```

**DischargeApproval**

```erlang
event DischargeApproval(
  address indexed contractAddress,
  uint256 indexed tokenId,
  address indexed owner,
  address operator
);
```

**ReleaseApproval**

```erlang
event ReleaseApproval(
  address indexed contractAddress,
  uint256 indexed tokenId,
  address indexed owner,
  address operator
);
```

**BreakBondApproval**

```erlang
event BreakBondApproval(
  address indexed contractAddress,
  uint256 indexed tokenId,
  address indexed owner,
  address operator
);
```

**TimelockApproval**

```erlang
event TimelockApproval(
  address indexed contractAddress,
  uint256 indexed tokenId,
  address indexed owner,
  address operator
);
```

**TokenDischargeTimelock**

```erlang
event TokenDischargeTimelock(
  address indexed contractAddress,
  uint256 indexed tokenId,
  address indexed operator,
  uint256 unlockBlock
);
```

**TokenReleaseTimelock**

```erlang
event TokenReleaseTimelock(
  address indexed contractAddress,
  uint256 indexed tokenId,
  address indexed operator,
  uint256 unlockBlock
);
```

**TokenBreakBondTimelock**

```erlang
event TokenBreakBondTimelock(
  address indexed contractAddress,
  uint256 indexed tokenId,
  address indexed operator, 
  uint256 unlockBlock
);
```

**TokenTempLock**

```erlang
event TokenTempLock(
  address indexed contractAddress,
  uint256 indexed tokenId,
  uint256 unlockBlock
);
```

**PermsSetForRestrictCharge**

```erlang
event PermsSetForRestrictCharge(
  address indexed contractAddress, 
  uint256 indexed tokenId, 
  bool state
);
```

**PermsSetForAllowDischarge**

```erlang
event PermsSetForAllowDischarge(
  address indexed contractAddress, 
  uint256 indexed tokenId, 
  bool state
);
```

**PermsSetForAllowRelease**

```erlang
event PermsSetForAllowRelease(
  address indexed contractAddress, 
  uint256 indexed tokenId, 
  bool state
);
```

**PermsSetForRestrictBond**

```erlang
event PermsSetForRestrictBond(
  address indexed contractAddress, 
  uint256 indexed tokenId, 
  bool state
);
```

**PermsSetForAllowBreakBond**

```erlang
event PermsSetForAllowBreakBond(
  address indexed contractAddress, 
  uint256 indexed tokenId, 
  bool state
);
```
