> For the complete documentation index, see [llms.txt](https://docs.tensorusd.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tensorusd.com/components/smart-contract.md).

# Smart Contract

The TUSDT protocol is a collateralized debt position (CDP) system built on ink! smart contracts. It allows users to lock native token collateral in vaults, borrow a synthetic stablecoin (TUSDT), and participate in liquidation auctions when vaults become undercollateralized. The system is composed of three interdependent contracts deployed together: TusdtVault, TusdtAuction, and TusdtErc20.&#x20;

## Contract Architecture

The three contracts have a strict ownership hierarchy. TusdtVault is the entry point for end users and is the owner of both TusdtErc20 and TusdtAuction. Neither the token nor the auction contract should be called directly by external integrators for write operations — all state-changing flows are orchestrated through the vault.

<figure><img src="https://2800809789-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCUTQy9XCNtZbiGWrE6nM%2Fuploads%2FrxB9LyaNHXck5QvzoRuE%2FScreenshot%202026-03-16%20at%2011.56.58.png?alt=media&amp;token=a239a32b-6104-41f4-9798-12a1e05e0bf3" alt=""><figcaption></figcaption></figure>

&#x20;                                                         Figure : Contract Architecture&#x20;

TusdtVault instantiates both child contracts at construction time using their code hashes and retains references to their on-chain addresses. Their addresses can be retrieved at any time via get\_token\_address() and get\_auction\_address().

## TusdtVault

The core contract. Handles everything related to creating vaults, borrowing, repaying, and liquidations.

### Key Parameters

<table data-header-hidden><thead><tr><th></th><th width="175.14453125"></th><th></th></tr></thead><tbody><tr><td><strong>Parameter</strong></td><td><strong>Default</strong></td><td><strong>Description</strong></td></tr><tr><td>Collateral Ratio</td><td>150%</td><td>Minimum collateral required to borrow</td></tr><tr><td>Liquidation Ratio</td><td>120%</td><td>Threshold where vault can be liquidated</td></tr><tr><td>Interest Rate</td><td>10% p.a</td><td>Compounded hourly</td></tr><tr><td>Liquidation Fee</td><td>upto 11%</td><td>Extra collateral added when liquidating</td></tr><tr><td>Auction Duration</td><td>15 Minute</td><td>How long liquidation auctions run</td></tr></tbody></table>

### Key Functions

<table data-header-hidden><thead><tr><th width="396.69921875"></th><th></th></tr></thead><tbody><tr><td><strong>Function</strong></td><td><strong>Description</strong></td></tr><tr><td><code>create_vault()</code></td><td>Opens a new vault with attached native tokens as collateral</td></tr><tr><td><code>add_collateral(vault_id)</code></td><td>Tops up collateral in an existing vault</td></tr><tr><td><code>borrow_token(vault_id, amount)</code></td><td>Mints TUSDT to the caller against their collateral</td></tr><tr><td><code>repay_token(vault_id, amount)</code></td><td>Burns TUSDT from the caller to reduce vault debt</td></tr><tr><td><code>release_collateral(vault_id, amount)</code></td><td>Withdraws collateral back to the caller</td></tr><tr><td><code>trigger_liquidation_auction(owner, vault_id)</code></td><td>Starts a liquidation auction on an unsafe vault</td></tr><tr><td><code>settle_liquidation_auction(owner, vault_id)</code></td><td>Completes a finalized auction and clears vault debt</td></tr><tr><td><code>get_vault(owner, vault_id)</code></td><td>Returns full vault state</td></tr><tr><td><code>get_max_borrow(owner, vault_id)</code></td><td>Returns how much TUSDT can still be borrowed</td></tr><tr><td><code>set_contract_params(params)</code></td><td>Owner only — updates protocol parameter</td></tr></tbody></table>

<br>

## TusdtErc20

Standard token contract for TUSDT. Mint and burn are restricted to the Vault contract. Users interact with it for transfers and approvals.

<br>

### Key Functions

<table data-header-hidden><thead><tr><th width="304.87890625"></th><th></th></tr></thead><tbody><tr><td>Function</td><td>Description</td></tr><tr><td><code>transfer(to, value)</code></td><td>Sends TUSDT to another account</td></tr><tr><td><code>approve(spender, value)</code></td><td>Approves another contract or account to spend TUSDT</td></tr><tr><td><code>transfer_from(from, to, value)</code></td><td>Transfers on behalf of another account using allowance</td></tr><tr><td><code>balance_of(owner)</code></td><td>Returns TUSDT balance of an account</td></tr><tr><td><code>mint(to, value)</code></td><td>Owner only — creates new TUSDT tokens</td></tr><tr><td><code>burn(from, value)</code></td><td>Owner only — destroys TUSDT tokens</td></tr></tbody></table>

## TusdtAuction

Manages liquidation auctions. Created and settled by the Vault. Bidders interact with it directly to place bids and withdraw refunds.

### Key Functions

<table data-header-hidden><thead><tr><th width="353.26171875"></th><th></th></tr></thead><tbody><tr><td>Function</td><td>Description</td></tr><tr><td><code>place_bid(auction_id, amount, metadata)</code></td><td>Places or increases a bid using TUSDT</td></tr><tr><td><code>finalize_auction(auction_id)</code></td><td>Closes an expired auction and records the winner</td></tr><tr><td><code>withdraw_refund(auction_id, bid_id)</code></td><td>Returns TUSDT to losing bidders after finalization</td></tr><tr><td><code>get_active_auctions(page)</code></td><td>Lists all currently running auctions</td></tr><tr><td><code>get_auction(auction_id)</code></td><td>Returns full details of a specific auction</td></tr></tbody></table>


---

# 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.tensorusd.com/components/smart-contract.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.
