> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mystockline.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Emissions

> Emissions streams a fixed amount of STK to sUSDG stakers over a fixed schedule.

Emissions streams a fixed amount of STK to sUSDG stakers over a fixed schedule. The owner funds the contract with STK and calls `start` once; the rate is total divided by duration and never changes. Holders stake sUSDG here to earn, since reading raw balances would leak rewards on transfer. Seconds with no stake are skipped, not banked.

`Emissions` lets you:

* Stake sUSDG to earn streamed STK
* Unstake sUSDG at any time and harvest rewards
* Claim pending STK
* Read the schedule and pending rewards

Addresses per network. Every address is also on [Addresses](/resources/addresses).

| Network                 | Address                                                                                                                                       |
| ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| Robinhood Chain testnet | [0x34963d9b8C9168A9Cc9cA447B8FFba8eDaeF199A](https://explorer.testnet.chain.robinhood.com/address/0x34963d9b8C9168A9Cc9cA447B8FFba8eDaeF199A) |

The source code is [`src/token/Emissions.sol`](https://github.com/stockline-xyz/contracts/blob/main/src/token/Emissions.sol) on GitHub. The ABI is [`/abis/Emissions.json`](/abis/Emissions.json).

## Write methods

### start

```solidity theme={"system"}
function start(uint32 duration_) external
```

Locks the schedule using the STK already held by the contract. Owner only, once. Reverts with AlreadyStarted, InvalidDuration for 0, and ZeroAmount if the STK balance or the resulting per-second rate is 0.

<Warning>
  Owner only. Transfer the full STK allocation before calling; STK sent later is not streamed and cannot be withdrawn.
</Warning>

<Note>
  Floor(total / duration) is the rate. Remainder dust stays here forever.
</Note>

**Input parameters**

| Name       | Type     | Description                      |
| ---------- | -------- | -------------------------------- |
| duration\_ | `uint32` | Length of the stream in seconds. |

### stake

```solidity theme={"system"}
function stake(uint256 shares) external nonReentrant
```

Harvests any pending STK, then pulls `shares` sUSDG from the caller and adds them to the stake. Works before `start`; rewards begin when the stream starts. Reverts with ZeroAmount for 0.

<Warning>
  The caller must approve Emissions for the sUSDG shares.
</Warning>

<Note>
  Harvest first so a later stake cannot dilute an unpaid claim.
</Note>

**Input parameters**

| Name   | Type      | Description            |
| ------ | --------- | ---------------------- |
| shares | `uint256` | sUSDG shares to stake. |

### unstake

```solidity theme={"system"}
function unstake(uint256 shares) external nonReentrant
```

Harvests any pending STK, then returns `shares` sUSDG to the caller. Reverts with InsufficientStake above the staked balance and ZeroAmount for 0.

**Input parameters**

| Name   | Type      | Description               |
| ------ | --------- | ------------------------- |
| shares | `uint256` | sUSDG shares to withdraw. |

### claim

```solidity theme={"system"}
function claim() external nonReentrant
```

Transfers all pending STK to the caller. Reverts with NotStarted before `start` and ZeroAmount when nothing is pending.

## Read methods

### pending

```solidity theme={"system"}
function pending(address account) external view returns (uint256)
```

Returns the STK an account could claim right now, including the stream since the last accrual.

**Input parameters**

| Name    | Type      | Description |
| ------- | --------- | ----------- |
| account | `address` | The staker. |

**Return values**

| Type      | Description |
| --------- | ----------- |
| `uint256` | STK amount. |

## Events

### Started

```solidity theme={"system"}
event Started(
    uint256 total,
    uint32 duration,
    uint256 rewardPerSecond
)
```

Fires once when the schedule is locked, with the total, duration, and rate.

### Staked

```solidity theme={"system"}
event Staked(address indexed account, uint256 shares)
```

Fires when an account stakes sUSDG.

### Unstaked

```solidity theme={"system"}
event Unstaked(address indexed account, uint256 shares)
```

Fires when an account withdraws sUSDG.

### Claimed

```solidity theme={"system"}
event Claimed(address indexed account, uint256 amount)
```

Fires when STK is paid out, by claim or by the harvest inside stake and unstake.

## Errors

### ZeroAddress

```solidity theme={"system"}
error ZeroAddress()
```

A constructor address was zero.

### NotOwner

```solidity theme={"system"}
error NotOwner()
```

Only the owner can start the stream.

### AlreadyStarted

```solidity theme={"system"}
error AlreadyStarted()
```

start was called twice.

### NotStarted

```solidity theme={"system"}
error NotStarted()
```

claim was called before start.

### ZeroAmount

```solidity theme={"system"}
error ZeroAmount()
```

An amount was zero, no STK was held at start, or nothing was pending.

### InvalidDuration

```solidity theme={"system"}
error InvalidDuration()
```

The duration was 0.

### InsufficientStake

```solidity theme={"system"}
error InsufficientStake()
```

The unstake amount exceeds the staked balance.
