### Install Dependencies Source: https://github.com/liquity/bold/blob/main/frontend/app/README.md Clone the repository and install all project dependencies using pnpm. ```sh git clone git@github.com:liquity/bold.git cd bold pnpm install # install dependencies for all packages ``` -------------------------------- ### Start Development Server Source: https://github.com/liquity/bold/blob/main/INSTRUCTIONS.md Start the development server for the Liquity V2 frontend. The app will be accessible at https://localhost:3000. ```bash pnpm dev ``` -------------------------------- ### Run Development Server Source: https://github.com/liquity/bold/blob/main/frontend/app/README.md Build necessary dependencies and start the local development server for the frontend application. ```sh cd bold/frontend/app pnpm build-deps # only needed once pnpm dev ``` -------------------------------- ### Install and Use Solidity Compiler Source: https://github.com/liquity/bold/blob/main/contracts/README.md Manages Solidity compiler versions using solc-select. Installs version 0.8.18 and sets it as the active version. ```shell solc-select install 0.8.18 solc-select use 0.8.18 ``` -------------------------------- ### Install npm Dependencies Source: https://github.com/liquity/bold/blob/main/INSTRUCTIONS.md Install all npm dependencies for the project packages using pnpm. ```bash pnpm install ``` -------------------------------- ### Install Slither Source: https://github.com/liquity/bold/blob/main/contracts/README.md Installs Slither using pip, assuming requirements.txt is present. ```shell pip3 install -r requirements.txt ``` -------------------------------- ### Build App Dependencies and Production Build Source: https://github.com/liquity/bold/blob/main/INSTRUCTIONS.md Install build dependencies if it's the first time, then build the app for production. The output will be in the 'out/' directory. ```bash cd frontend/app pnpm build-deps # only needed the first time pnpm build ``` -------------------------------- ### Sequential Redistribution Example Source: https://github.com/liquity/bold/blob/main/README.md Illustrates the step-by-step process of sequential liquidations and redistributions in Liquity v1. This shows how debt and collateral are 'rolled' forward to subsequent Troves before final distribution. ```text batchLiquidateTroves(A) -> B,C,D,E receive A’s debt and coll proportionally batchLiquidateTroves(B) -> C,D,E receive B’s debt and coll proportionally batchLiquidateTroves(C) -> D,E receive C’s debt and coll proportionally ``` -------------------------------- ### Set up Python Environment for Slither Source: https://github.com/liquity/bold/blob/main/contracts/README.md Creates and activates a local Python virtual environment for installing Slither. ```shell python3 -m venv .venv source .venv/bin/activate ``` -------------------------------- ### Copy Environment File Source: https://github.com/liquity/bold/blob/main/INSTRUCTIONS.md Copy the example .env file to .env.local for local configuration. Ensure to set environment variables, including NEXT_PUBLIC_SUBGRAPH_URL. ```bash cd frontend/app cp .env .env.local ``` -------------------------------- ### Trove Operation With Hints Source: https://github.com/liquity/bold/blob/main/README.md This outlines the process of performing a Trove operation using hints. It involves calling HintHelpers.getApproxHint to get an approximate hint, then SortedTroves.findInsertPosition to get exact hints, and finally passing these exact hints to the Trove operation. This method results in a gas cost of O(1) for the final operation. ```Solidity _lowerHint = _nextId, _upperHint = _prevId ``` -------------------------------- ### Start Graph Node Locally Source: https://github.com/liquity/bold/blob/main/subgraph/README.md Navigates to the subgraph directory and starts the Graph node. The `--reset` flag can be used to clear the existing state. ```shell cd subgraph ./start-graph # use --reset to clear the state: # ./start-graph --reset ``` -------------------------------- ### Install Foundry Dependencies for Contracts Source: https://github.com/liquity/bold/blob/main/INSTRUCTIONS.md Install Foundry dependencies specifically for contract development. ```bash cd contracts forge install ``` -------------------------------- ### Run Anvil Local Blockchain Source: https://github.com/liquity/bold/blob/main/subgraph/README.md Starts a local Anvil blockchain instance with a high gas limit and a base fee of 1. This is the first step in the local subgraph setup. ```shell anvil --host 0.0.0.0 --gas-limit 100000000000 --base-fee 1 ``` -------------------------------- ### Run Local Ethereum Node with Anvil Source: https://github.com/liquity/bold/blob/main/contracts/README.md Starts a local Ethereum node using Anvil, a tool from the Foundry suite. ```shell anvil ``` -------------------------------- ### Generate ABI Definitions Source: https://github.com/liquity/bold/blob/main/contracts/abi/README.md Run these commands to generate ABI definitions. Ensure you have forge and pnpm installed. ```bash forge build pnpm extract-abi ``` -------------------------------- ### Stability Pool Overflow Calculation Example Source: https://github.com/liquity/bold/blob/main/README.md This example illustrates a potential overflow scenario in the Stability Pool's `getCompoundedDeposit` calculation due to high precision and large deposit amounts. It highlights the magnitude of intermediate values that can exceed `uint256` limits. ```Solidity https://github.com/liquity/bold/blob/b2ff26c5f09e72eaa5ad7eb24210aded4e80f00e/contracts/src/StabilityPool.sol#L530 ``` ```Solidity https://github.com/liquity/bold/blob/b2ff26c5f09e72eaa5ad7eb24210aded4e80f00e/contracts/src/StabilityPool.sol#L372 ``` -------------------------------- ### Get Contract Addresses for Local Development Source: https://github.com/liquity/bold/blob/main/INSTRUCTIONS.md Retrieve contract addresses from the deployment manifest for use in local development configuration. Save the output for the next step. ```bash pnpm tsx utils/deployment-manifest-to-app-env.ts deployment-manifest.json ``` -------------------------------- ### Create Local Environment File Source: https://github.com/liquity/bold/blob/main/frontend/app/README.md Copy the default environment file to create a local configuration for development. ```sh cp .env .env.local ``` -------------------------------- ### Open Trove Transaction with Hints Source: https://github.com/liquity/bold/blob/main/README.md Demonstrates how to open a trove by calculating approximate and exact hints for the transaction. Ensure you have the necessary contracts and helper functions like toBN, toWei, and sortedTroves, hintHelpers, borrowerOperations are available. ```javascript const BOLDAmount = toBN(toWei('2500')) // borrower wants to withdraw 2500 BOLD const colll = toBN(toWei('5')) // borrower wants to lock 5 collateral tokens const interestRate = toBn(toWei(‘7’) // Borrower wants a 7% annual interest rate // Get an approximate address hint from the deployed HintHelper contract. Use (15 * sqrt(number of troves)) trials // to get an approx. hint that is close to the right position. let numTroves = await sortedTroves.getSize() let numTrials = numTroves.mul(toBN('15')) let { 0: approxHint } = await hintHelpers.getApproxHint(interestRate, numTrials, 42) // random seed of 42 // Use the approximate hint to get the exact upper and lower hints from the deployed SortedTroves contract let { 0: upperHint, 1: lowerHint } = await sortedTroves.findInsertPosition(interestRate, approxHint, approxHint) // Finally, call openTrove with the exact upperHint and lowerHint const maxFee = '5'.concat('0'.repeat(16)) // Slippage protection: 5% await borrowerOperations.openTrove({otherParams}, upperHint, upperHint) ``` -------------------------------- ### Build Project with Forge Source: https://github.com/liquity/bold/blob/main/contracts/README.md Compiles the smart contracts in your project using Forge. ```shell forge build ``` -------------------------------- ### Deploy Contracts Locally Source: https://github.com/liquity/bold/blob/main/subgraph/README.md Navigates to the contracts directory and deploys the contracts locally. An optional flag `--open-demo-troves` can be used to initialize with demo data. ```shell cd contracts ./deploy local # use --open-demo-troves to start with some demo data: # ./deploy local --open-demo-troves ``` -------------------------------- ### Build App with Trailing Slash Configuration Source: https://github.com/liquity/bold/blob/main/INSTRUCTIONS.md Build the app with a separate directory for each route by setting NEXT_TRAILING_SLASH=1. This is useful if your server does not serve .html files by default. ```bash NEXT_TRAILING_SLASH=1 pnpm build ``` -------------------------------- ### Run Slither Static Analysis Source: https://github.com/liquity/bold/blob/main/contracts/README.md Analyzes Solidity code in the 'src' directory using Slither. ```shell slither src ``` -------------------------------- ### Configure Network Currency Details Source: https://github.com/liquity/bold/blob/main/frontend/app/README.md Set the currency name, symbol, and decimals for the Ethereum network using NEXT_PUBLIC_CHAIN_CURRENCY. ```dosini # Format NEXT_PUBLIC_CHAIN_CURRENCY=name|symbol|decimals # Example NEXT_PUBLIC_CHAIN_CURRENCY=Ether|ETH|18 ``` -------------------------------- ### Generating Approximate Hint Source: https://github.com/liquity/bold/blob/main/README.md The HintHelpers.getApproxHint function generates a useful hint for Trove operations. It randomly selects a number of Troves and returns the one closest to the target insertion position for a given annual interest rate. This function can be called with a random seed for better approximations through multiple runs. ```Solidity HintHelpers.getApproxHint(uint256 _collIndex, uint256 _interestRate, uint256 _numTrials, uint256 _inputRandomSeed) ``` -------------------------------- ### Configure Block Explorer Details Source: https://github.com/liquity/bold/blob/main/frontend/app/README.md Set the name and URL of the block explorer for the Ethereum network using NEXT_PUBLIC_CHAIN_BLOCK_EXPLORER. This is optional. ```dosini # Format NEXT_PUBLIC_CHAIN_BLOCK_EXPLORER=name|url # Example NEXT_PUBLIC_CHAIN_BLOCK_EXPLORER=Etherscan|https://etherscan.io ``` -------------------------------- ### Deployment Flavor Source: https://github.com/liquity/bold/blob/main/frontend/app/README.md Indicates a specific deployment variant, such as 'preview', which will be displayed in the app header. ```dosini # Example NEXT_PUBLIC_DEPLOYMENT_FLAVOR=preview ``` -------------------------------- ### Generate Contract Addresses for .env.local Source: https://github.com/liquity/bold/blob/main/INSTRUCTIONS.md Generate contract addresses for the .env.local file by converting a deployment manifest. Replace the address file with the desired one. ```bash cd contracts pnpm tsx ./utils/deployment-manifest-to-app-env.ts ./addresses/11155111.json ``` -------------------------------- ### Format Code with Forge Source: https://github.com/liquity/bold/blob/main/contracts/README.md Formats your Solidity code according to standard conventions using Forge. ```shell forge fmt ``` -------------------------------- ### Deploy Smart Contracts with Forge Source: https://github.com/liquity/bold/blob/main/contracts/README.md Deploys a smart contract using Forge's script functionality. Requires RPC URL and private key. ```shell forge script script/Counter.s.sol:CounterScript --rpc-url --private-key ``` -------------------------------- ### Liquity Bold Folder Structure Source: https://github.com/liquity/bold/blob/main/frontend/app/README.md Directory structure for the Liquity Bold project. Organizes smart contracts, UI components, services, and transaction flows. ```bash src/ abi/ # ABIs of the Liquity contracts app/ # The Next.js app (mostly routing only) comps/ # UI Components screens/ # App Screens (used by /app routing components) services/ # Service Components tx-flows/ # Transaction Flows ``` -------------------------------- ### Configure App Version URL Template Source: https://github.com/liquity/bold/blob/main/frontend/app/README.md Define the URL template for linking to specific app version releases using NEXT_PUBLIC_APP_VERSION_URL. Set to false to disable. ```dosini # Format NEXT_PUBLIC_APP_VERSION_URL=https://url_template_with_{version} # Example (default) NEXT_PUBLIC_APP_VERSION_URL=https://github.com/liquity/bold/releases/tag/%40liquity2%2Fapp-v{version} ``` -------------------------------- ### Clone Liquity V2 Repository Source: https://github.com/liquity/bold/blob/main/INSTRUCTIONS.md Clone the Liquity V2 repository and navigate into the project directory. ```bash git clone git@github.com:liquity/bold.git cd bold ``` -------------------------------- ### Release Workflow Commands Source: https://github.com/liquity/bold/blob/main/frontend/app/RELEASING.md Commands to switch to the main branch, pull latest changes, build the app, update version, commit, tag, and push. ```bash git switch main git pull origin main pnpm build pnpm version [version] git add package.json git commit -m "App: v[version]" git tag -s @liquity2/app-v[version] -m '@liquity2/app-v[version]' git push origin main git push origin @liquity2/app-v[version] ``` -------------------------------- ### Common npm Scripts Source: https://github.com/liquity/bold/blob/main/frontend/app/README.md A list of frequently used npm scripts for building, testing, and maintaining the application. ```sh pnpm build # build the static app in out/ pnpm build-deps # build all the dependencies needed by the app pnpm build-graphql # update the code generated from the GraphQL queries pnpm build-panda # update the code generated from the Panda CSS config pnpm build-uikit # builds the UI kit in ../uikit pnpm dev # run the development server pnpm fmt # format the code pnpm lint # lint the code pnpm test # run the tests pnpm update-liquity-abis # build the contracts and update the ABIs ``` -------------------------------- ### Deploy Subgraph Locally Source: https://github.com/liquity/bold/blob/main/subgraph/README.md Navigates to the subgraph directory and deploys the subgraph. This script automatically updates contract addresses in `subgraph.yaml` if new versions are detected. Use `--create` to initialize the subgraph. ```shell cd subgraph # Note: this script detects if new versions of the contract it needs # have been deployed, and will automatically update their addresses in the # subgraph.yaml file (after confirmation). ./deploy-subgraph local --version v1 --create ``` -------------------------------- ### provideToSP Source: https://github.com/liquity/bold/blob/main/README.md Deposits a specified amount of BOLD to the Stability Pool, with an option to claim existing gains. ```APIDOC ## provideToSP ### Description Allows the caller to deposit a specified amount of BOLD into the Stability Pool. The `_doClaim` parameter dictates how existing collateral and BOLD yield gains are handled: if true, they are transferred to the caller; otherwise, collateral is stashed and BOLD gains are added to the deposit. ### Method `provideToSP(uint256 _amount, bool _doClaim)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### Enable/Disable Account Screen Source: https://github.com/liquity/bold/blob/main/frontend/app/README.md Configure the NEXT_PUBLIC_ACCOUNT_SCREEN environment variable to enable or disable the account screen for testing purposes. ```dosini # Example NEXT_PUBLIC_ACCOUNT_SCREEN=false ``` -------------------------------- ### Test Smart Contracts with Forge Source: https://github.com/liquity/bold/blob/main/contracts/README.md Executes the tests for your smart contracts using Forge. Use -vvv flag to see console logs. ```shell forge test ``` -------------------------------- ### Deploy Contracts Locally Source: https://github.com/liquity/bold/blob/main/INSTRUCTIONS.md Deploy contracts to the local Anvil node. The --open-demo-troves flag creates test troves for the first 8 Anvil accounts. ```bash cd contracts ./deploy local --open-demo-troves ``` -------------------------------- ### Open Trove and Join Interest Batch Manager Source: https://github.com/liquity/bold/blob/main/README.md This function is used to open a Trove and join an interest batch. It incurs an upfront fee, and the branch's debt-weighted average interest rate is calculated incorporating the Trove's debt and the batch's interest rate. This is part of a strategy to potentially reduce upfront fees. ```solidity openTroveAndJoinInterestBatchManager ``` -------------------------------- ### Generate Gas Snapshots with Forge Source: https://github.com/liquity/bold/blob/main/contracts/README.md Generates gas snapshots for your smart contracts using Forge. ```shell forge snapshot ``` -------------------------------- ### Interact with EVM using Cast Source: https://github.com/liquity/bold/blob/main/contracts/README.md Provides a command-line interface for interacting with EVM contracts and chain data using Cast. ```shell cast ``` -------------------------------- ### Known Initiatives URL Source: https://github.com/liquity/bold/blob/main/frontend/app/README.md Provides the URL for fetching known initiatives data. This is an optional configuration. ```dosini # Example NEXT_PUBLIC_KNOWN_INITIATIVES_URL=https://api.liquity.org/v2/known-initiatives/ethereum.json ``` -------------------------------- ### V1 Staking Check Feature Flag Source: https://github.com/liquity/bold/blob/main/frontend/app/README.md Enables or disables a banner warning users about any LQTY remaining staked in v1. Defaults to true. ```dosini # Example NEXT_PUBLIC_V1_STAKING_CHECK=false ``` -------------------------------- ### Trove Operation Without Hints Source: https://github.com/liquity/bold/blob/main/README.md When performing a Trove operation without hints, both _lowerHint and _upperHint are set to the user's address. This results in a worst-case gas cost of O(n), where n is the size of the SortedTroves list. ```Solidity userAddress, _lowerHint = userAddress, _upperHint = userAddress ``` -------------------------------- ### Set Ethereum Network RPC URL Source: https://github.com/liquity/bold/blob/main/frontend/app/README.md Provide the RPC URL for the Ethereum network using NEXT_PUBLIC_CHAIN_RPC_URL. ```dosini # Example NEXT_PUBLIC_CHAIN_RPC_URL=https://cloudflare-eth.com ``` -------------------------------- ### Configure App Commit URL Template Source: https://github.com/liquity/bold/blob/main/frontend/app/README.md Define the URL template for linking to specific app commits in the repository using NEXT_PUBLIC_APP_COMMIT_URL. Set to false to disable. ```dosini # Format NEXT_PUBLIC_APP_COMMIT_URL=https://url_template_with_{commit} # Example (default) NEXT_PUBLIC_APP_COMMIT_URL=https://github.com/liquity/bold/tree/{commit} ``` -------------------------------- ### VPN API Configuration Source: https://github.com/liquity/bold/blob/main/frontend/app/README.md Configures VPNAPI.io detection to filter by country codes. The format is `key|countryCodes`. ```dosini # Format NEXT_PUBLIC_BLOCKING_VPNAPI=key|countryCodes # Example NEXT_PUBLIC_BLOCKING_VPNAPI=1234|US,CA ``` -------------------------------- ### openTrove Source: https://github.com/liquity/bold/blob/main/README.md Creates a new Trove for the caller. This function transfers collateral from the caller to the system, mints BOLD debt, and mints a Trove NFT. It includes parameters for managing collateral and debt, setting hints for efficient operation, and defining optional managers for collateral and debt adjustments. An upfront fee is charged, and the caller can specify a maximum acceptable fee to mitigate slippage. ```APIDOC ## openTrove( address _owner, uint256 _ownerIndex, uint256 _collAmount, uint256 _boldAmount, uint256 _upperHint, uint256 _lowerHint, uint256 _annualInterestRate, uint256 _maxUpfrontFee, address _addManager, address _removeManager, address _receiver ) ### Description Creates a Trove for the caller that is not part of a batch. Transfers `_collAmount` from the caller to the system, mints `_boldAmount` of BOLD to their address. Mints the Trove NFT to their address. The `ETH_GAS_COMPENSATION` of 0.0375 WETH is transferred from the caller to the GasPool. Opening a Trove must result in the Trove’s ICR > MCR, and also the system’s TCR > CCR. An `upfrontFee` is charged, based on the system’s _average_ interest rate, the BOLD debt drawn and the `UPFRONT_INTEREST_PERIOD`. The borrower chooses a `_maxUpfrontFee` that he/she is willing to accept in case of a fee slippage, i.e. when the system’s average interest rate increases and in turn increases the fee they’d pay. The optional `_addManager` permits that address to improve the collateral ratio of the Trove - i.e. to add collateral or to repay debt. The optional `_removeManager` is permitted to reduce the collateral ratio of the Trove, that is to remove collateral or draw new debt, and also to close it. The `_receiver` is the address the `_removeManager` can send funds to. ### Method N/A (Function Signature) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body - **_owner** (address) - Required - The owner of the Trove. - **_ownerIndex** (uint256) - Required - The index of the owner. - **_collAmount** (uint256) - Required - The amount of collateral to deposit. - **_boldAmount** (uint256) - Required - The amount of BOLD debt to mint. - **_upperHint** (uint256) - Required - Hint for upper bound. - **_lowerHint** (uint256) - Required - Hint for lower bound. - **_annualInterestRate** (uint256) - Required - The annual interest rate. - **_maxUpfrontFee** (uint256) - Required - The maximum upfront fee the caller is willing to accept. - **_addManager** (address) - Optional - Address permitted to improve the collateral ratio. - **_removeManager** (address) - Optional - Address permitted to reduce the collateral ratio. - **_receiver** (address) - Optional - The address to which the remove manager can send funds. ``` -------------------------------- ### applyPendingDebt Source: https://github.com/liquity/bold/blob/main/README.md Applies all pending debt to the Trove - i.e. adds its accrued interest and any redistribution debt gain, to its recorded debt and updates its lastDebtUpdateTime to now. The purpose is to make sure all Troves can have their interest and gains applied with sufficient regularity even if their owner doesn’t touch them. Also makes Zombie Troves that have reached debt > MIN_DEBT (e.g. from interest or redistribution gains) become redeemable again, by reinserting them to the SortedList and previous batch (if they were in one). If the Trove is in a batch, it applies all of the batch's accrued interest and accrued management fee to the batch's recorded debt, as well as the _individual_ Trove's redistribution debt gain. ```APIDOC ## applyPendingDebt(uint256 _troveId, uint256 _lowerHint, uint256 _upperHint) ### Description Applies all pending debt to the Trove - i.e. adds its accrued interest and any redistribution debt gain, to its recorded debt and updates its lastDebtUpdateTime to now. The purpose is to make sure all Troves can have their interest and gains applied with sufficient regularity even if their owner doesn’t touch them. Also makes Zombie Troves that have reached debt > MIN_DEBT (e.g. from interest or redistribution gains) become redeemable again, by reinserting them to the SortedList and previous batch (if they were in one). If the Trove is in a batch, it applies all of the batch's accrued interest and accrued management fee to the batch's recorded debt, as well as the _individual_ Trove's redistribution debt gain. ### Method (Not specified, likely a contract function call) ### Parameters #### Path Parameters - **_troveId** (uint256) - Required - The ID of the trove to apply pending debt to. - **_lowerHint** (uint256) - Required - Hint for lower bound. - **_upperHint** (uint256) - Required - Hint for upper bound. ``` -------------------------------- ### V1 Stability Pool Check Feature Flag Source: https://github.com/liquity/bold/blob/main/frontend/app/README.md Enables or disables a banner warning users about unclaimed LQTY in the V1 Stability Pool. Defaults to true. ```dosini # Example NEXT_PUBLIC_V1_STABILITY_POOL_CHECK=false ``` -------------------------------- ### Liquity Contract Addresses Source: https://github.com/liquity/bold/blob/main/frontend/app/README.md Environment variable for contract addresses. Used to configure the application with the correct contract endpoints. ```bash NEXT_PUBLIC_CONTRACT_… ```