# Conviction Pool Management

### Creating Conviction Pool

#### 1. Set During Token Creation

```javascript
// Create conviction pool simultaneously when creating token
const createParams = {
  insurance_amt: 1000000000, // Conviction amount (lamports)
  insurance_px: 500000000, // Trigger price (lamports)
  name: "My Token",
  symbol: "MTK",
  uri: "ipfs://metadata_hash",
  user_pubkey: "user_wallet_public_key",
  network: "mainnet",
  platform: "meteora",
};
```

#### 2. Create Conviction Pool Separately

```javascript
// Create Conviction pool for existing token
const convictionParams = {
  mint: "token_address",
  insuranceAmt: 1000000000, // Conviction amount
  insurancePx: 500000000, // Trigger price
  userPubkey: "user_address",
};

// Call on-chain Conviction pool initialization
const convictionIx = await program.methods
  .initInsurance({
    amt: new BN(insuranceParams.insuranceAmt),
    startPrice: new BN(insuranceParams.insurancePx),
    creator: userPublicKey,
    mint: mintPubkey,
    name: tokenName,
    symbol: tokenSymbol,
    uri: "",
    poolId,
  })
  .instruction();
```

### Query Conviction Pool Information

**Endpoint**: `POST /api/token/conviction_pool/{token_address}`

**Request Headers**:

```
Authorization: Bearer your_jwt_token
Content-Type: application/json
```

**Response Example**:

```json
{
  "code": 200,
  "data": {
    "token_address": "token_address",
    "creator": "creator_address",
    "insurance_amt": 1000000000,
    "insurance_activation_price": 500000000,
    "insurance_status": "reserved",
    "has_deployed_insurance": true,
    "can_redeem_insurance": false,
    "deposit_time": "2024-01-01T00:00:00Z",
    "activation_time": null,
    "refund_time": null
  }
}
```

### Conviction Pool Status

#### Status Types

* **reserved**: Reserved, not triggered
* **deployed**: Triggered, tokens swapped
* **redeemed**: SOL redeemed

#### Status Determination Logic

```javascript
// Calculate Conviction pool status
const computeInsuranceStatus = (token) => {
  if (!token.has_deployed_insurance) {
    return "none";
  }

  if (token.can_redeem_insurance) {
    return "redeemable";
  }

  if (token.insurance_status === "deployed") {
    return "deployed";
  }

  return "reserved";
};
```

### Redeem Conviction Pool

#### Redemption Conditions

* Token price has not fallen below protection price
* Beyond lock period (usually a few days)
* User is the conviction pool creator

#### Redemption Process

```javascript
// Check redemption conditions
if (!tokenData.can_redeem_insurance) {
  throw new Error("Redemption conditions not met");
}

// Call redemption function
const refundParams = {
  mint: tokenAddress,
  userPubkey: userAddress,
};

const signature = await refundInsurance(connection, refundParams, wallet);
```

#### On-chain Redemption Transaction

```javascript
// Build redemption transaction
const refundIx = await program.methods
  .refundInsurance()
  .accounts({
    dish: dishPDA,
    insuranceVault: insuranceVaultPDA,
    user: userPublicKey,
    systemProgram: SystemProgram.programId,
  })
  .instruction();
```

### Conviction Pool Trigger Mechanism

#### Auto-trigger Conditions

* Current token price ≤ set protection price
* Meets minimum trigger time interval
* Pool has sufficient liquidity

#### Post-trigger Processing

* Automatically swap tokens for SOL
* Update conviction pool status to "deployed"
* User can no longer redeem original SOL

### Time Lock Mechanism

#### Lock Period Calculation

```javascript
// Check if redemption is possible (time lock)
const canRedeem = (depositTime, currentTime) => {
  const lockPeriod = 3 * 24 * 60 * 60 * 1000; // 3 days
  return currentTime - depositTime > lockPeriod;
};
```

#### Countdown Display

```javascript
// Calculate remaining lock time
const getRemainingTime = (depositTime) => {
  const lockPeriod = 3 * 24 * 60 * 60 * 1000;
  const elapsed = Date.now() - depositTime;
  const remaining = Math.max(0, lockPeriod - elapsed);

  return {
    days: Math.floor(remaining / (24 * 60 * 60 * 1000)),
    hours: Math.floor((remaining % (24 * 60 * 60 * 1000)) / (60 * 60 * 1000)),
    minutes: Math.floor((remaining % (60 * 60 * 1000)) / (60 * 1000)),
    seconds: Math.floor((remaining % (60 * 1000)) / 1000),
  };
};
```

### Key Points

* Conviction pool requires locking real SOL
* Protection price setting needs to be careful, too high easily triggers
* Time lock mechanism prevents frequent operations
* Cannot be reversed after triggering, SOL will be swapped
* Supports querying historical conviction pool records
* Each token can only have one conviction pool


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cooking-city-launchpad.gitbook.io/docs/api-documentation/conviction-pool-management.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
