Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# StackIt Smart Contracts

Open-source smart contracts powering the StackIt treasury and liquidation protection system on Arbitrum.

---

## Contracts

### `Stack.sol`
The main registry contract. Creates and tracks user wallets, manages token allowlists, and controls the system's swapper and pool addresses.

- Deploys a new `Wallet` proxy for each user
- Maintains the list of supported tokens (BTC, ETH, USDC)
- Controls access roles (owner, operators)

### `Wallet.sol`
A minimal proxy contract created per user. Delegates all logic calls to `WalletImplementation.sol`. Each user owns exactly one wallet — nobody else can touch it.

### `WalletImplementation.sol`
The core logic contract. Handles all treasury operations:

- **Deposit** — accepts USDC and allocates to BTC/ETH via Aave
- **Borrow** — borrows USDC against BTC/ETH collateral, enforcing LTV safety limits
- **Repay** — repays outstanding debt to restore health factor
- **Liquidation protection** — automatically repays debt using collateral when health factor approaches unsafe levels, using flash loans to re-leverage as markets recover

**Key on-chain safety rules enforced by this contract:**
- Health factor cannot drop below the configured minimum after a borrow
- Per-transaction and daily borrow caps enforced on-chain
- Nonce replay prevention — transactions cannot be replayed
- Cooldown period between executions
- Only the wallet owner can authorize transactions — StackIt never holds or controls user keys

---

## Architecture

```
User Wallet (EOA)
└── Wallet.sol (proxy, per user)
└── WalletImplementation.sol (logic)
├── Aave (lending/borrowing)
├── Uniswap V2 (swaps)
└── Stack.sol (registry + access control)
```
Comment on lines +38 to +48
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Add a language tag to the architecture fence.

markdownlint will keep flagging this block until the fence is annotated. text is enough if you just want a plaintext diagram.

Suggested fix
-```
+```text
 User Wallet (EOA)
     │
     └── Wallet.sol (proxy, per user)
             │
             └── WalletImplementation.sol (logic)
                     │
                     ├── Aave (lending/borrowing)
                     ├── Uniswap V2 (swaps)
                     └── Stack.sol (registry + access control)
</details>

<!-- suggestion_start -->

<details>
<summary>📝 Committable suggestion</summary>

> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

```suggestion

🧰 Tools
🪛 markdownlint-cli2 (0.21.0)

[warning] 38-38: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@README.md` around lines 38 - 48, The fenced diagram block in README.md is
missing a language tag which triggers markdownlint; update the opening
triple-backtick for the architecture diagram to include a language tag (e.g.,
text) so the block starts with ```text, leaving the diagram content (lines like
"User Wallet (EOA)", "Wallet.sol (proxy, per user)", "WalletImplementation.sol
(logic)", "Aave", "Uniswap V2", "Stack.sol") unchanged.


**Custody model:** StackIt uses a wallet-sovereign architecture. The system constructs and simulates transactions, but returns them **unsigned** to the user (or agent). The user signs and submits. StackIt never holds private keys.

---

## Deployment

Deployed on **Arbitrum One**.

| Contract | Address |
|----------|---------|
| Stack.sol | *(add Arbiscan link)* |
| WalletImplementation.sol | *(add Arbiscan link)* |
Comment on lines +58 to +61
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Replace the deployment placeholders before merge.

This README frames the contracts as the trust layer, so shipping it without the actual Arbitrum addresses blocks readers from verifying what is deployed.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@README.md` around lines 58 - 61, Update the README table to replace the
placeholder entries for Stack.sol and WalletImplementation.sol with the actual
Arbiscan contract URLs; locate the table rows referencing "Stack.sol" and
"WalletImplementation.sol" and paste the correct Arbiscan links (or verified
contract addresses formatted as Arbiscan URLs) so readers can directly verify
the deployed trust-layer contracts.


---

## Open Source Scope

The smart contracts — where your funds actually move — are fully open source and auditable here.

The liquidation protection rules engine and backend orchestration are proprietary. This is by design: the on-chain contracts are the trust layer. You can verify that your funds only move with your wallet's authorization, health factor limits are enforced on-chain, and no transaction can be replayed or front-run by the system.

---

## Development

```bash
yarn install
yarn hardhat compile
yarn hardhat test
```

---

## License

GPL-3.0