CLI tool for Diffuse Prime
npm install difcliA CLI tool for Diffuse Prime built with TypeScript and viem.
``bash`
npm install -g difclior
npx difcli
`bash`
difcli --help # Show help
difcli --version # Show version
#### Set Private Key
`bash`
difcli wallet set-private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
#### Show Wallet Information
`bash`
difcli wallet show
Displays wallet address and type.
#### Remove Wallet
`bash`
difcli wallet remove
Removes the stored private key from local storage.
#### Show Balance
`bash`
difcli balance
Displays wallet balance in native BERA tokens and configured token contract balance.
#### Display Contract Addresses
`bash`
difcli contracts
Displays all configured contract addresses including RPC endpoint, vault contract, and token contract.
#### Mint Tokens
`bash`
difcli token mint
Mints the specified amount of tokens to the configured wallet. Amount is in token units (will be multiplied by 1e18 for the transaction).
#### Burn Tokens
`bash`
difcli token burn
Burns the specified amount of tokens from the configured wallet. Amount is in token units (will be multiplied by 1e18 for the transaction).
Both commands will:
- Display transaction hash
- Wait for transaction confirmation
- Show success/failure status
- Display gas usage information
#### Deposit Tokens
`bash`
difcli lender deposit
Deposits tokens into the vault as a lender. Amount is in token units (will be multiplied by 1e18 for the transaction).
The command will:
- Check token balance to ensure sufficient funds
- Check token allowance for the vault contract
- Approve tokens if allowance is insufficient
- Execute deposit transaction to vault contract
- Display transaction hashes and confirmation status
- Show gas usage information
Validation: Command will fail with clear error message if token balance is insufficient.
#### Withdraw Tokens
`bash`
difcli lender withdraw
Withdraws tokens from the vault as a lender. Amount is in token units (will be multiplied by 1e18 for the transaction).
The command will:
- Check maximum withdrawable amount from vault
- Execute withdraw transaction from vault contract (if sufficient balance)
- Display transaction hash and confirmation status
- Show gas usage information
Note: Both receiver and owner addresses are set to the configured wallet address.
Validation: Command will fail with clear error message if requested amount exceeds maximum withdrawable balance.
#### Activate a pending position (unsafe SGX bypass)
`bash`
difcli borrower activate sgxActivateBorrowerPosition(positionId, liquidationPrice=getBorrowerPosition(id).liquidationPrice, blocksAndHashes=[], proof=0x, data)
Calls and simulates first.
⚠️ Warning: this only works on vaults where SGX proof checks are disabled. On normal vaults it will revert.
For Aegis strategies, the CLI will auto-fetch data via Prime API POST /mint (slippage is entered interactively).
#### Exit (unborrow) a position
`bash`
difcli borrower exit eth_call
Runs an simulation of unborrow and then submits the transaction.
If the preview shows Finished in one tx: No (async), the exit is intercepted by an async adapter and will require one or more follow-up calls:difcli borrower exit-status
- Use to see the intercepted adapter.difcli borrower exit-continue
- Use to continue until finished.
#### Check async-exit status
`bash`
difcli borrower exit-status hasUnfinishedSwap
Shows + getUnfinishedSwap (intercepted adapter + hop index best-effort).
#### Continue an unfinished async exit
`bash`
difcli borrower exit-continue minAssetsOut
Notes:
- The CLI derives per-hop from an eth_call simulation (returnedPerHop) and applies slippage per hop. Hops that output 0 keep minOut=0 automatically (required for unfinished async hops).instanceLocked
- Aegis async redeem is supported automatically if the intercepted adapter matches the expected interface (/getInfoForPosition), and will call Prime API POST /redeem to obtain encodedData.
Environment variables:
- PRIME_API_BASE_URL (default https://api.prime.diffuse.fi)
#### Aegis enter (mint yUSD) — preview integration
For strategies with Aegis in the strategy name, previewBorrow(..., data) requires Prime API POST /mint encodedData (used by AegisMintAdapter).
collateral_amount sent to /mint should match the exact amountIn that will go into AegisMintAdapter.buy(...):collateralType=OriginalAsset
- : collateralAmount + assetsToBorrowcollateralType=StrategyAsset
- : assetsToBorrow
In this CLI, this currently affects preview/simulation only (because borrowRequest(...) does not take a data argument). When you run difcli borrower preview or difcli borrower request, the CLI will auto-call /mint for Aegis strategies to make preview work.
Environment variables (mint):
- PRIME_API_BASE_URL (default https://api.prime.diffuse.fi)/mint
Slippage for Prime API ( and /redeem) is entered interactively as percent when needed.
#### Set Vault Address
`bash`
difcli vault set
Sets a custom vault contract address for a specific chain.
`bash`
difcli vault set berachain 0x1234567890123456789012345678901234567890
#### Show Vault Addresses
`bash`
difcli vault show
Displays current vault addresses for all chains, showing both default and custom addresses.
#### Reset Vault Address
`bash`
difcli vault reset
Resets the vault address for a specific chain back to the default.
`bash`
difcli vault reset berachain
Note: Custom vault addresses are stored per chain and persist across sessions.
#### Vault Status
`bash`
difcli lender status
Displays comprehensive vault status and lender-specific information:
Vault Statistics:
- Total assets in vault
- Assets currently utilized
- Base asset deficit
Lender Information:
- Maximum withdrawable amount
- Current vault balance (shares)
- Accrued yield information
Vault Status:
- Pause status and reason (if paused)
⚠️ WARNING: This CLI tool stores private keys locally with encryption. While the keys are encrypted, this is NOT suitable for production use with real funds.
For production use:
- Use hardware wallets
- Implement proper key management systems
- Never store private keys on disk
The current implementation uses a default encryption key. For better security, consider:
1. User-provided passwords for encryption
2. Hardware security modules
3. Secure key vaults
`bashInstall dependencies
npm install
- viem - Ethereum library for TypeScript
- commander - CLI framework
- crypto-js - Encryption utilities
- chalk - Terminal styling
MIT