> For the complete documentation index, see [llms.txt](https://docs.mito.fi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mito.fi/integration/rewards.md).

# Rewards

This document aims to allow external developers to integrate with Mito's LP Staking Rewards from within their dApps. We will only show the message examples, how will you integrate them within your dApp is your own choice. Documentation on broadcasting the transactions containing these messages can be found [here](https://docs.ts.injective.network/transactions/msgbroadcaster#msgbroadcaster--wallet-strategy).

### Query

#### Fetch Staking Rewards

```typescript
import { IndexerGrpcMitoApi } from '@injectivelabs/sdk-ts'

const MITO_API_ENDPOINT = 'https://k8s.mainnet.mito.grpc-web.injective.network' /** for mainnet */
const mitoApi = new IndexerGrpcMitoApi(MITO_API_ENDPOINT)

const address = 'inj1..'
const STAKING_CONTRACT_ADDRESS = `inj1gtze7qm07nky47n7mwgj4zatf2s77xqvh3k2n8` /** staking contract address for mainnet */

const { rewards } = await mitoApi.fetchStakingRewardsByAccount({
    stakingContractAddress: STAKING_CONTRACT_ADDRESS,
    accountAddress: address
})

console.log(rewards)
```

#### Fetch Staking Pools

```typescript
import { IndexerGrpcMitoApi } from '@injectivelabs/sdk-ts'

const MITO_API_ENDPOINT = 'https://k8s.mainnet.mito.grpc-web.injective.network' /** for mainnet */
const mitoApi = new IndexerGrpcMitoApi(MITO_API_ENDPOINT)

const address = 'inj1..'
const STAKING_CONTRACT_ADDRESS = `inj1gtze7qm07nky47n7mwgj4zatf2s77xqvh3k2n8` /** staking contract address for mainnet */

const { pools } = await mitoApi.fetchStakingPools({
    stakingContractAddress: STAKING_CONTRACT_ADDRESS
})

console.log(pools)
```

### Transactions

#### Stake LP

```typescript
import { 
  MsgExecuteContractCompat,
  spotQuantityToChainQuantityToFixed 
} from '@injectivelabs/sdk-ts'

const sender = `inj1...`
const amount = 0.01 /** staking 0.01 QUNT/INJ LP */
const vaultLpDenom = 'factory...' /** Can be fetched from the vault's information */
const vaultTokenDecimals = 18
const STAKING_CONTRACT_ADDRESS = `inj1gtze7qm07nky47n7mwgj4zatf2s77xqvh3k2n8` /** staking contract address for mainnet */

const message = MsgExecuteContractCompat.fromJSON({
  sender,
  funds: [
    {
      denom: vaultLpDenom,
      amount: spotQuantityToChainQuantityToFixed({
        value: amount,
        baseDecimals: vaultTokenDecimals
      })
    }
  ],
  contractAddress: STAKING_CONTRACT_ADDRESS,
  exec: {
    action: 'stake',
    msg: {}
  }
})

/** (Prepare) Broadcast the transaction */
```

#### Unstake LP

*Note: The users need to* [*Claim Stake*](#claim-stake) *24 hours after they unstaked their LP.*

```typescript
import { 
  MsgExecuteContractCompat,
  spotQuantityToChainQuantityToFixed 
} from '@injectivelabs/sdk-ts'

const sender = `inj1...`
const amount = 0.01 /** unstaking 0.01 QUNT/INJ LP */
const vaultLpDenom = 'factory...' /** Can be fetched from the vault's information */
const vaultTokenDecimals = 18
const STAKING_CONTRACT_ADDRESS = `inj1gtze7qm07nky47n7mwgj4zatf2s77xqvh3k2n8` /** staking contract address for mainnet */

const message = MsgExecuteContractCompat.fromJSON({
  sender,
  contractAddress: STAKING_CONTRACT_ADDRESS,
  exec: {
    action: 'unstake',
    msg: {
      coin: {
        denom: vault.lpDenom,
        amount: spotQuantityToChainQuantityToFixed({
          value: amount,
          baseDecimals: vaultTokenDecimals
        })
      }
    }
  }
})

/** (Prepare) Broadcast the transaction */
```

#### Claim Stake

```typescript
import { 
  MsgExecuteContractCompat 
} from '@injectivelabs/sdk-ts'

const sender = `inj1...`
const vaultLpDenom = 'factory...' /** Can be fetched from the vault's information */
const STAKING_CONTRACT_ADDRESS = `inj1gtze7qm07nky47n7mwgj4zatf2s77xqvh3k2n8` /** staking contract address for mainnet */

const message = MsgExecuteContractCompat.fromJSON({
  sender,
  contractAddress: STAKING_CONTRACT_ADDRESS,
  exec: {
    action: 'claim_stake',
    msg: {
      lp_token: vaultLpDenom
    }
  }
})

/** (Prepare) Broadcast the transaction */
```

#### Claim Rewards

```typescript
import { 
  MsgExecuteContractCompat 
} from '@injectivelabs/sdk-ts'

const sender = `inj1...`
const vaultLpDenom = 'factory...' /** Can be fetched from the vault's information */
const STAKING_CONTRACT_ADDRESS = `inj1gtze7qm07nky47n7mwgj4zatf2s77xqvh3k2n8` /** staking contract address for mainnet */

const message = MsgExecuteContractCompat.fromJSON({
  sender,
  contractAddress: STAKING_CONTRACT_ADDRESS,
  exec: {
    action: 'claim_rewards',
    msg: {
      lp_token: vaultLpDenom
    }
  }
})
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.mito.fi/integration/rewards.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
