> For the complete documentation index, see [llms.txt](https://boringity.gitbook.io/wsup-mvp-draft/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boringity.gitbook.io/wsup-mvp-draft/wsup-cli-sdk.md).

# wSup CLI / SDK

<figure><img src="/files/ibUvNPEp8IidpbcA0pbe" alt=""><figcaption></figcaption></figure>

Below is a **comprehensive list** of the **key Supra CLI commands** (`supra move tool run` or `view`) that interact with your **price oracle**, **lending\_market**, and **obligation** modules. For each command, we detail:

1. **Function ID**: Fully qualified entry/view function.
2. **Type Arguments**: The coin type or other generics.
3. **Arguments**: Exact syntax and expected values.
4. **Description**: What it does and how it affects the protocol state.
5. **Example CLI**: A sample command you can paste into your terminal.

By the end, you’ll have a **one-stop reference** for all major RPC calls needed to use or debug the wSup lending protocol.

***

## **1. `price_oracle.move` RPC Calls**

#### **1.1 Initialize Pair**

* **Function ID**:

  ```php
  0x<CONTRACT>::price_oracle::initialize_pair
  ```
* **Type Args**:\
  `<CoinType>`
* **Arguments**:
  * `u32: pair_id` (the Supra Oracle pair ID to map)
  * `u8: decimals` (the coin’s decimal precision, e.g., 6 for USDC)
* **Description**:\
  Sets up a coin’s **pair ID** and **decimals** in the oracle. Only an admin can call this. This ensures the protocol knows how to scale the token and which ID to reference in `supra_oracle_storage`.
* **Example**:

  ```bash
  supra move tool run \
    --function-id 0x<CONTRACT>::price_oracle::initialize_pair \
    --type-args 0x6c4a3aa30f7b1f40e5e5e9c0091b0897775afc8076ebe5d63e2d3dcca48c994f::hyper_coin::HyperUsdcCoin \
    --args u32:47 u8:6 \
    --profile admin \
    --url https://rpc-testnet.supra.com
  ```

#### **1.2 Update Average Price**

* **Function ID**:

  ```php
  0x<CONTRACT>::price_oracle::update_average_price
  ```
* **Type Args**:\
  `<CoinType>`
* **Arguments**:\
  \&#xNAN;*No direct arguments besides the type arg.*
* **Description**:\
  Pulls the latest price from `supra_oracle_storage`, checks if it’s fresh, and updates the internal average price.\
  Typically called **before** borrowing or depositing to ensure the protocol sees correct data.
* **Example**:

  ```bash
  supra move tool run \
    --function-id 0x<CONTRACT>::price_oracle::update_average_price \
    --type-args 0x6c4a3aa30f7b1f40e5e5e9c0091b0897775afc8076ebe5d63e2d3dcca48c994f::hyper_coin::HyperUsdcCoin \
    --profile admin \
    --url https://rpc-testnet.supra.com
  ```

#### **1.3 View Stored Price (Read-Only)**

* **Function ID**:

  ```php
  0x<CONTRACT>::price_oracle::get_stored_price
  ```
* **Type Args**:\
  `<CoinType>`
* **Arguments**:\
  \&#xNAN;*None*
* **Description**:\
  Returns the **current averaged price** for a coin, as stored by the oracle.\
  This is a **view** function, so it doesn’t cost gas or change state.
* **Example**:

  ```bash
  supra move tool view \
    --function-id 0x<CONTRACT>::price_oracle::get_stored_price \
    --type-args 0x<SOME_COIN>::hyper_coin::HyperUsdcCoin \
    --url https://rpc-testnet.supra.com
  ```

***

## **2. `lending_market.move` RPC Calls**

#### **2.1 Initialize Lending Market**

* **Function ID**:

  ```php
  0x<CONTRACT>::lending_market::initialize_lending_market
  ```
* **Type Args**:\
  `<CoinType>`
* **Arguments**:\
  \&#xNAN;*No direct arguments aside from the admin signer.*
* **Description**:\
  Deploys/initializes a **LendingMarket** resource for a particular coin. Verifies the **price oracle** is configured (i.e., `is_pair_configured<CoinType>()`) and ensures a nonzero price.
* **Example**:

  ```bash
  supra move tool run \
    --function-id 0x<CONTRACT>::lending_market::initialize_lending_market \
    --type-args 0x6c4a3aa30f7b1f40e5e5e9c0091b0897775afc8076ebe5d63e2d3dcca48c994f::hyper_coin::HyperUsdcCoin \
    --profile admin \
    --url https://rpc-testnet.supra.com
  ```

#### **2.2 Deposit**

* **Function ID**:

  ```php
  0x<CONTRACT>::lending_market::deposit
  ```
* **Type Args**:\
  `<CoinType>`
* **Arguments**:
  * `u64: amount` (in base units; e.g., `1000000` for 1.0 if 6 decimals)
* **Description**:\
  Moves **`amount`** of tokens from your wallet into the lending protocol as collateral. Updates `total_supplied_usd` and calls `obligation::deposit_collateral` under the hood.
* **Example**:

  ```bash
  supra move tool run \
    --function-id 0x<CONTRACT>::lending_market::deposit \
    --type-args 0x6c4a3aa30f7b1f40e5e5e9c0091b0897775afc8076ebe5d63e2d3dcca48c994f::hyper_coin::HyperUsdcCoin \
    --args u64:1000000 \
    --profile user \
    --url https://rpc-testnet.supra.com
  ```

#### **2.3 Borrow**

* **Function ID**:

  ```php
  phpCopyEdit0x<CONTRACT>::lending_market::borrow
  ```
* **Type Args**:\
  `<CoinType>`
* **Arguments**:
  * `u64: amount` (base units again)
* **Description**:\
  Lets you **borrow** `amount` of the token from the pool, increasing both your debt and `total_borrowed_usd`.\
  The protocol calls `obligation::borrow` to check if you remain healthy post-borrow.
* **Example**:

  ```bash
  supra move tool run \
    --function-id 0x<CONTRACT>::lending_market::borrow \
    --type-args 0x6c4a3aa30f7b1f40e5e5e9c0091b0897775afc8076ebe5d63e2d3dcca48c994f::hyper_coin::HyperUsdcCoin \
    --args u64:500000 \
    --profile user \
    --url https://rpc-testnet.supra.com
  ```

#### **2.4 Repay**

* **Function ID**:

  ```php
  0x<CONTRACT>::lending_market::repay
  ```
* **Type Args**:\
  `<CoinType>`
* **Arguments**:
  * `u64: amount` (how many tokens to repay)
* **Description**:\
  Sends tokens from your wallet to **repay** some or all of your debt. Decreases the market’s `total_borrowed_usd` and calls `obligation::repay` to adjust your obligation.
* **Example**:

  ```bash
  bashCopyEditsupra move tool run \
    --function-id 0x<CONTRACT>::lending_market::repay \
    --type-args 0x6c4a3aa30f7b1f40e5e5e9c0091b0897775afc8076ebe5d63e2d3dcca48c994f::hyper_coin::HyperUsdcCoin \
    --args u64:250000 \
    --profile user \
    --url https://rpc-testnet.supra.com
  ```

#### **2.5 Withdraw Collateral**

* **Function ID**:

  ```php
  0x<CONTRACT>::lending_market::withdraw_collateral
  ```
* **Type Args**:\
  `<CoinType>`
* **Arguments**:
  * `u64: amount` (how many tokens to withdraw)
* **Description**:\
  Pulls `amount` of your **collateral** out of the protocol and back to your wallet, assuming you remain healthy (above liquidation threshold) after withdrawal.
* **Example**:

  ```bash
  bashCopyEditsupra move tool run \
    --function-id 0x<CONTRACT>::lending_market::withdraw_collateral \
    --type-args 0x6c4a3aa30f7b1f40e5e5e9c0091b0897775afc8076ebe5d63e2d3dcca48c994f::hyper_coin::HyperUsdcCoin \
    --args u64:1000000 \
    --profile user \
    --url https://rpc-testnet.supra.com
  ```

#### **2.6 Liquidate**

* **Function ID**:

  ```php
  phpCopyEdit0x<CONTRACT>::lending_market::liquidate
  ```
* **Type Args**:\
  `<CoinType>`
* **Arguments**:
  * `address: user_addr` (the user whose debt is being partially liquidated)
  * `u64: repay_amount` (how many tokens you intend to repay on their behalf)
* **Description**:\
  If the user is undercollateralized (health factor < 1), you can **liquidate** them by paying off some of their debt in exchange for a portion of their collateral.\
  This updates the market’s `total_borrowed_usd` and `total_supplied_usd` accordingly.
* **Example**:

  ```bash
  bashCopyEditsupra move tool run \
    --function-id 0x<CONTRACT>::lending_market::liquidate \
    --type-args 0x6c4a3aa30f7b1f40e5e5e9c0091b0897775afc8076ebe5d63e2d3dcca48c994f::hyper_coin::HyperUsdcCoin \
    --args address:0xUSER_ADDRESS u64:500000 \
    --profile liquidator \
    --url https://rpc-testnet.supra.com
  ```

***

## **3. `obligation.move` RPC Calls**

Most “obligation” calls are done **internally** by `lending_market.move`. However, there are a few direct entry functions or view functions you might need:

#### **3.1 Create Obligation**

* **Function ID**:

  ```php
  phpCopyEdit0x<CONTRACT>::obligation::create_obligation
  ```
* **Type Args**:\
  `<CoinType>`
* **Arguments**:\
  \&#xNAN;*None, just the user signer*
* **Description**:\
  Initializes a **UserObligation\<CoinType>** resource in your account if one doesn’t exist.\
  Called automatically by `deposit` if you have no existing obligation, but you can also call it manually.
* **Example**:

  ```bash
  bashCopyEditsupra move tool run \
    --function-id 0x<CONTRACT>::obligation::create_obligation \
    --type-args 0x6c4a3aa30f7b1f40e5e5e9c0091b0897775afc8076ebe5d63e2d3dcca48c994f::hyper_coin::HyperUsdcCoin \
    --profile user \
    --url https://rpc-testnet.supra.com
  ```

#### **3.2 View Obligation (Read-Only)**

* **Function ID**:

  ```php
  0x<CONTRACT>::obligation::view_obligation
  ```
* **Type Args**:\
  `<CoinType>`
* **Arguments**:
  * `address: user_addr`
* **Description**:\
  Returns a tuple with `(collateral, debt, deposited_value_usd, allowed_borrow_value_usd, unhealthy_borrowed_value_usd, weighted_borrowed_value_usd)`.\
  Great for dashboards or checking your own collateral–debt ratio.
* **Example**:

  ```bash
  supra move tool view \
    --function-id 0x<CONTRACT>::obligation::view_obligation \
    --type-args 0x6c4a3aa30f7b1f40e5e5e9c0091b0897775afc8076ebe5d63e2d3dcca48c994f::hyper_coin::HyperUsdcCoin \
    --args address:0xUSER_ADDRESS \
    --url https://rpc-testnet.supra.com
  ```

#### **3.3 Get Health Factor (Read-Only)**

* **Function ID**:

  ```php
  0x<CONTRACT>::obligation::get_health_factor
  ```
* **Type Args**:\
  `<CoinType>`
* **Arguments**:
  * `address: user_addr`
* **Description**:\
  Returns the user’s health factor (scaled to 1e18). If it’s above 1.0, they’re safe; below 1.0, they’re open to liquidation.
* **Example**:

  ```bash
  supra move tool view \
    --function-id 0x<CONTRACT>::obligation::get_health_factor \
    --type-args 0x6c4a3aa30f7b1f40e5e5e9c0091b0897775afc8076ebe5d63e2d3dcca48c994f::hyper_coin::HyperUsdcCoin \
    --args address:0xUSER_ADDRESS \
    --url https://rpc-testnet.supra.com
  ```

***

## **4. Utility & Notes**

#### **4.1 Decimal Module**

You typically **don’t** call `decimal.move` directly via CLI. It’s just a helper for arithmetic and scaling. But know it’s there to standardize decimals.

#### **4.2 Profile vs. Admin**

* Some commands (like `initialize_lending_market` or `initialize_pair`) require an **admin** or special signer.
* For user actions (deposit, borrow, repay, etc.), use your **personal** profile.

#### **4.3 Argument Conversions**

* If a coin has **6 decimals**, then `1.0` token = `u64: 1000000`.
* If your coin has **8 decimals**, then `1.0` token = `u64: 100000000`.

#### **4.4 Checking Balances**

To confirm your current coin balance (outside the lending protocol), you can do:

```bash
curl https://rpc-testnet.supra.com/rpc/v1/accounts/<YOUR_ADDRESS>/resources/0x1::coin::CoinStore<0x<SOME_COIN>::hyper_coin::HyperUsdcCoin>
```

This returns how many tokens you hold natively in your wallet.

***

### **Final Words**

With these **Supra CLI** commands, you can:

1. **Initialize** your price oracle and lending market.
2. **Deposit**, **borrow**, **repay**, and **withdraw** on the protocol.
3. **View** obligations, health factors, and store balances.
4. **Liquidate** risky positions if necessary.


---

# 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 dynamically by asking a question.

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

```
GET https://boringity.gitbook.io/wsup-mvp-draft/wsup-cli-sdk.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.
