Skip to content

EnsoBuild/enso-looping-front

Repository files navigation

aHYPER Leverage Frontend

A single-page DeFi app for leveraged aHYPER positions on Monad, powered by Enso Finance bundle API and Morpho flashloans.

How It Works

Users deposit USDC or aHYPER and select a leverage multiplier (1.5x - 3x). The app builds an atomic bundle that:

  1. Flashloan USDC from Morpho
  2. Deposit flashloaned USDC into the Hyperithm vault to mint aHYPER
  3. Deposit all aHYPER (user's + newly minted) as collateral into Morpho
  4. Borrow USDC from Morpho to repay the flashloan

All steps execute in a single transaction via the Enso bundle API.

USDC Mode

When depositing USDC, a preliminary step converts the user's USDC into aHYPER via the Hyperithm vault before entering the flashloan loop.

Health Factor

Since totalCollateral = leverage * deposit and debt = (leverage - 1) * deposit, the deposit amount cancels out:

HF = (leverage * LLTV) / (leverage - 1)

HF depends only on the leverage multiplier and LLTV (0.77), not on the deposit size:

Leverage Health Factor
1.5x 2.31
2x 1.54
2.5x 1.28
3x 1.16

Positions with HF <= 1.0 are liquidatable.

Constraints

  • The Hyperithm aHYPER vault requires a minimum deposit of 100 USDC (or equivalent aHYPER). Transactions below this threshold will revert on-chain.
  • The bundle response includes an approval transaction that the EOA must execute to call setAuthorization on the Morpho contract, granting the ensowallet-v2 contract permission to act on behalf of the user. This is a one-time operation per wallet. See example tx.

Transaction Flow

On "Execute Leverage", the app checks which transactions are needed and batches them via EIP-5792 (wallet_sendCalls). Wallets without 5792 support (e.g. Rabby) receive sequential eth_sendTransaction calls as fallback.

User clicks "Execute Leverage"
            |
            v
   Build bundle via Enso API
   (returns: tx, approvals[])
            |
            v
+--[ Check Morpho setAuthorization ]--+
|   isAuthorized(user, ensowallet)?   |
|                                     |
|   YES --> skip          NO --> add  |
+-------------------------------------+
            |
            v
+--[ Check ERC-20 token allowance ]---+
|   allowance(user, spender)          |
|   >= amountIn?                      |
|                                     |
|   YES --> skip          NO --> add  |
+-------------------------------------+
            |
            v
   Always add main leverage tx
            |
            v
+--[ Batch via EIP-5792 ]------------+
|                                     |
|   5792 supported?                   |
|   YES --> single batch prompt       |
|   NO  --> sequential fallback       |
+-------------------------------------+

UX Cases

Case 1: First-time user (3 txs)
  [setAuthorization] -> [approve USDC] -> [leverage tx]

Case 2: Authorized, new token amount (2 txs)
  [approve USDC] -> [leverage tx]

Case 3: Authorized + sufficient allowance (1 tx)
  [leverage tx]

Case 4: Returning user, same token, higher amount (2 txs)
  [approve USDC] -> [leverage tx]

Case 5: aHYPER mode, first time (3 txs)
  [setAuthorization] -> [approve aHYPER] -> [leverage tx]

Case 5b: aHYPER mode, authorized + sufficient allowance (1 tx)
  [leverage tx]

Case 6: Insufficient balance
  Button greyed out, "Insufficient {token} balance" shown

Case 7: Health factor <= 1
  Button greyed out

Enso APIs Used

Endpoint Purpose
POST /api/v1/shortcuts/bundle Build and simulate the flashloan bundle
GET /api/v1/wallet/approve Check/build ERC-20 approval for the Enso router
GET /api/v1/wallet/balances Fetch wallet token balances
GET /api/v1/tokens Token metadata (symbol, name, logo)
GET /api/v1/prices/{chainId}/{token} Token USD pricing

Contracts

Contract Address
aHYPER (Hyperithm Vault) 0x7Cd231120a60F500887444a9bAF5e1BD753A5e59
USDC 0x754704Bc059F8C67012fEd69BC8A327a5aafb603
Morpho Primary 0xD5D960E8C380B724a48AC59E2DfF1b2CB4a1eAee

Chain: Monad (chainId: 143)

Setup

npm install
cp .env.example .env
# Edit .env with your API key and RPC URL
npm run dev

Environment Variables

Variable Description
NEXT_PUBLIC_ENSO_API_KEY Enso Finance API key (get one here)
NEXT_PUBLIC_RPC_URL Monad RPC endpoint

Tech Stack

  • Next.js 14 (App Router)
  • wagmi v2 + viem for wallet interaction
  • Tailwind CSS for styling
  • Enso Finance bundle API for DeFi transaction composition

Deploy

Deployed on Vercel. Set the environment variables in your Vercel project settings, then:

npx vercel --prod

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages