### Start Native Midgard Source: https://gitlab.com/thorchain/midgard/-/blob/develop/README.md One-time setup for PostgreSQL and running Midgard with multiple configuration files. ```sh # One time setup: docker-compose up -d pg mkdir -p ./tmp/blockstore # run midgard go run ./cmd/midgard/ config/ex/base.json:config/ex/pg.json:config/ex/bs-m.json:config/ex/net-main-9r.json ``` -------------------------------- ### Start Midgard with Docker Compose Source: https://gitlab.com/thorchain/midgard/-/blob/develop/README.md One-time setup for PostgreSQL and running Midgard using Docker Compose. ```sh # One time setup: docker-compose up -d pg docker-compose up --build midgard ``` -------------------------------- ### Midgard Configuration Source: https://context7.com/thorchain/midgard/llms.txt Example JSON configuration file for Midgard deployment. ```json { "listen_port": 8080, "shutdown_timeout": "20s", "read_timeout": "20s", "write_timeout": "20s", "max_block_age": "60s", "thorchain": { "tendermint_url": "http://localhost:26657/websocket", "thornode_url": "http://localhost:1317/thorchain", "fetch_batch_size": 1, "parallelism": 1, "read_timeout": "8s" }, "timescale": { "host": "localhost", "port": 5432, "user_name": "midgard", "password": "password", "database": "midgard", "max_open_conns": 80 }, "blockstore": { "local": "./tmp/blockstore", "remote": "https://storage.googleapis.com/public-snapshots-ninerealms/midgard-blockstore/mainnet/v2/", "blocks_per_chunk": 10000 }, "websockets": { "enable": true, "connection_limit": 100 }, "usdpools": [ "BNB.BUSD-BD1", "ETH.USDT-0XDAC17F958D2EE523A2206206994597C13D831EC7", "ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48" ] } ``` -------------------------------- ### Run Multiple Midgard Instances Source: https://gitlab.com/thorchain/midgard/-/blob/develop/README.md Run multiple Midgard instances against different chains (e.g., mainnet and testnet) by configuring separate listen ports, Thorchain/Tendermint URLs, and timescale/ports. This example shows starting PostgreSQL instances and then running Midgard with different config files. ```bash docker-compose up -d pg docker-compose up -d pg2 go run ./cmd/midgard tmp/mainnet.json go run ./cmd/midgard tmp/testnet.json ``` -------------------------------- ### Install PostgreSQL Client Source: https://gitlab.com/thorchain/midgard/-/blob/develop/README.md Installs the PostgreSQL client tools on Debian-based systems. This is necessary for connecting to Midgard's PostgreSQL database. ```bash sudo apt install postgres-client ``` -------------------------------- ### Run Midgard Locally Source: https://context7.com/thorchain/midgard/llms.txt Commands for starting the Midgard service, running tests, and accessing the database. ```bash docker-compose up -d pg mkdir -p ./tmp/blockstore go run ./cmd/midgard/ config/ex/base.json:config/ex/pg.json:config/ex/bs-m.json:config/ex/net-main-9r.json docker-compose up --build midgard docker-compose up -d pgtest go test -p 1 ./... psql -h localhost -U midgard midgard -p 5432 ``` -------------------------------- ### Configure Midgard with Genesis Files Source: https://gitlab.com/thorchain/midgard/-/blob/develop/README.md Example JSON configuration for Midgard to bootstrap from a THORNode genesis file. ```json ... "genesis": { "local": "your-genesis-file-location", "initial_block_height": 123, "initial_block_hash": "genesis-first-block-hash" }, ... ``` -------------------------------- ### Prepare ThorChain Environment Source: https://gitlab.com/thorchain/midgard/-/blob/develop/docs/smoke/README.md Copies the smoke setup script to the working directory and executes it to prepare the environment. ```shell cd $SMOKEPATH cp midgard/docs/smoke/smoke-setup.sh . ./smoke-setup.sh ``` -------------------------------- ### Run Local ThorNode Mainnet Source: https://gitlab.com/thorchain/midgard/-/blob/develop/README.md Starts a local ThorNode mainnet instance using Docker Compose. ```sh cd docs/fullnode docker-compose up -d mainnet ``` -------------------------------- ### Regenerate OpenApi Files Source: https://gitlab.com/thorchain/midgard/-/blob/develop/README.md Regenerate OpenApi files using the 'make generated' command. This requires installing 'redoc-cli' via npm and 'oapi-codegen' via go get. ```bash make generated ``` -------------------------------- ### Get Affiliate History Source: https://context7.com/thorchain/midgard/llms.txt Retrieve historical earnings data for affiliates, optionally filtered by THORName. ```bash curl -X GET "https://midgard.thorchain.info/v2/history/affiliate?interval=day&count=30" ``` ```bash curl -X GET "https://midgard.thorchain.info/v2/history/affiliate?thorname=myaffiliate&interval=week&count=4" ``` -------------------------------- ### Run Local ThorNode Testnet Source: https://gitlab.com/thorchain/midgard/-/blob/develop/README.md Starts a local ThorNode testnet instance using Docker Compose. Note the API port difference. ```sh cd docs/fullnode docker-compose up -d testnet ``` -------------------------------- ### GET /members Source: https://context7.com/thorchain/midgard/llms.txt Returns an array of all liquidity provider addresses across all pools. ```APIDOC ## GET /members ### Description Returns an array of all liquidity provider addresses across all pools. ### Method GET ### Endpoint /v2/members ### Parameters #### Query Parameters - **pool** (string) - Optional - Filter members by a specific pool (e.g., BTC.BTC). ### Response #### Success Response (200) - **addresses** (array) - List of liquidity provider addresses. ``` -------------------------------- ### Get Top Asset Holders Source: https://context7.com/thorchain/midgard/llms.txt Retrieve a list of the top holders for a specific asset, ordered by balance. ```bash curl -X GET "https://midgard.thorchain.info/v2/holders?asset=THOR.RUNE&limit=100" ``` -------------------------------- ### GET /v2/thorname/lookup/{name} Source: https://context7.com/thorchain/midgard/llms.txt Returns chain addresses and ownership information for a registered THORName. ```APIDOC ## GET /v2/thorname/lookup/{name} ### Description Returns chain addresses and ownership information for a registered THORName. ### Method GET ### Endpoint https://midgard.thorchain.info/v2/thorname/lookup/{name} ### Parameters #### Path Parameters - **name** (string) - Required - The THORName to look up ### Response #### Success Response (200) - **owner** (string) - Address of the owner - **expire** (string) - Expiration block height - **entries** (array) - List of chain addresses #### Response Example { "owner": "thor102y0m3uptg0vvudeyh00r2fnz70wq7d8y7mu2g", "expire": "15500000", "entries": [ { "chain": "THOR", "address": "thor102y0m3uptg0vvudeyh00r2fnz70wq7d8y7mu2g" } ] } ``` -------------------------------- ### Get Single Pool Details Source: https://context7.com/thorchain/midgard/llms.txt Retrieves detailed metrics for a specific liquidity pool, supporting custom APY period configurations. ```bash # Get details for BTC pool curl -X GET "https://midgard.thorchain.info/v2/pool/BTC.BTC" # Get ETH pool with 100-day APY period curl -X GET "https://midgard.thorchain.info/v2/pool/ETH.ETH?period=100d" ``` -------------------------------- ### Get Bonder Details Source: https://context7.com/thorchain/midgard/llms.txt Retrieve bond information for a specific address, including associated nodes and their statuses. ```bash curl -X GET "https://midgard.thorchain.info/v2/bonds/thor102y0m3uptg0vvudeyh00r2fnz70wq7d8y7mu2g" ``` -------------------------------- ### GET /v2/stats Source: https://context7.com/thorchain/midgard/llms.txt Returns global statistics for all pools and transactions since the beginning of the chain. ```APIDOC ## GET /v2/stats ### Description Returns global statistics for all pools and transactions since the beginning of the chain. ### Method GET ### Endpoint https://midgard.thorchain.info/v2/stats ### Response #### Success Response (200) - **runeDepth** (string) - Total RUNE depth - **swapVolume** (string) - Total swap volume - **swapCount** (string) - Total swap count #### Response Example { "runeDepth": "250000000000000000", "swapVolume": "500000000000000000000", "swapCount": "10000000" } ``` -------------------------------- ### List All Member Addresses Source: https://context7.com/thorchain/midgard/llms.txt Retrieves a list of all liquidity provider addresses across all pools. This is useful for getting an overview of all participants. ```bash # Get all member addresses curl -X GET "https://midgard.thorchain.info/v2/members" ``` ```bash # Get members for specific pool only curl -X GET "https://midgard.thorchain.info/v2/members?pool=BTC.BTC" ``` ```json [ "thor1abc123...", "thor1def456...", "thor1ghi789..." ] ``` -------------------------------- ### Get Borrower Details Source: https://context7.com/thorchain/midgard/llms.txt Fetches loan statistics for a specific borrower address, including collateral and debt information. This endpoint is crucial for monitoring loan positions. ```bash # Get borrower details curl -X GET "https://midgard.thorchain.info/v2/borrower/bc1qabc123..." ``` ```json { "pools": [ { "collateral_asset": "BTC.BTC", "target_assets": ["ETH.ETH", "THOR.RUNE"], "debt_issued_tor": "500000000000", "debt_repaid_tor": "100000000000", "collateral_deposited": "100000000", "collateral_withdrawn": "0", "last_open_loan_timestamp": "1699000000", "last_repay_loan_timestamp": "1699500000" } ] } ``` -------------------------------- ### GET /v2/history/swaps Source: https://context7.com/thorchain/midgard/llms.txt Retrieves historical swap statistics including count, volume, fees, and slippage metrics for pools. ```APIDOC ## GET /v2/history/swaps ### Description Returns historical swap statistics including count, volume, fees, and slippage metrics. ### Method GET ### Endpoint /v2/history/swaps ### Parameters #### Query Parameters - **pool** (string) - Optional - Filter by specific pool - **interval** (string) - Required - Time interval (e.g., day, hour) - **count** (integer) - Optional - Number of intervals to return ### Response #### Success Response (200) - **meta** (object) - Aggregate swap statistics for the requested period - **intervals** (array) - List of interval data points including counts, volumes, and fees ``` -------------------------------- ### Connect via Dockerized PostgreSQL Source: https://gitlab.com/thorchain/midgard/-/blob/develop/README.md Connect to the Midgard PostgreSQL database from within its Docker container, avoiding the need to install the client locally. Use the container name 'midgard_pg_1'. ```bash docker exec -it midgard_pg_1 psql -h localhost -U midgard midgard ``` -------------------------------- ### GET /borrower/{address} Source: https://context7.com/thorchain/midgard/llms.txt Returns loan statistics for a specific borrower address showing collateral and debt information. ```APIDOC ## GET /borrower/{address} ### Description Returns loan statistics for a specific borrower address showing collateral and debt information. ### Method GET ### Endpoint /v2/borrower/{address} ### Parameters #### Path Parameters - **address** (string) - Required - The borrower address to query. ### Response #### Success Response (200) - **pools** (array) - List of loan positions for the borrower. ``` -------------------------------- ### GET /network Source: https://context7.com/thorchain/midgard/llms.txt Returns comprehensive network statistics including bond metrics, block rewards, and node counts. ```APIDOC ## GET /network ### Description Returns comprehensive network statistics including bond metrics, block rewards, and node counts. ### Method GET ### Endpoint /v2/network ``` -------------------------------- ### Get Pool Statistics Source: https://context7.com/thorchain/midgard/llms.txt Retrieves comprehensive performance statistics for a specific pool over a defined time period. ```bash # Get pool statistics for BTC curl -X GET "https://midgard.thorchain.info/v2/pool/BTC.BTC/stats?period=24h" ``` -------------------------------- ### GET /v2/history/depths/{pool} Source: https://context7.com/thorchain/midgard/llms.txt Retrieves historical asset and rune depths with price data for a specific pool over specified time intervals. ```APIDOC ## GET /v2/history/depths/{pool} ### Description Returns historical asset and rune depths with price data for a pool over specified time intervals. ### Method GET ### Endpoint /v2/history/depths/{pool} ### Parameters #### Path Parameters - **pool** (string) - Required - The pool identifier (e.g., BTC.BTC) #### Query Parameters - **interval** (string) - Required - Time interval (e.g., day, hour) - **count** (integer) - Optional - Number of intervals to return - **from** (integer) - Optional - Start timestamp - **to** (integer) - Optional - End timestamp ### Response #### Success Response (200) - **meta** (object) - Metadata containing start/end times and aggregate depth/unit changes - **intervals** (array) - List of interval data points including depths, prices, and units ``` -------------------------------- ### Get Address Balance Source: https://context7.com/thorchain/midgard/llms.txt Retrieve coin balances for a specific RUNE address, optionally filtered by timestamp or block height. ```bash curl -X GET "https://midgard.thorchain.info/v2/balance/thor102y0m3uptg0vvudeyh00r2fnz70wq7d8y7mu2g" ``` ```bash curl -X GET "https://midgard.thorchain.info/v2/balance/thor102y0m3uptg0vvudeyh00r2fnz70wq7d8y7mu2g?timestamp=1699800000" ``` ```bash curl -X GET "https://midgard.thorchain.info/v2/balance/thor102y0m3uptg0vvudeyh00r2fnz70wq7d8y7mu2g?height=15000000" ``` -------------------------------- ### Get Single Pool Details Source: https://context7.com/thorchain/midgard/llms.txt Returns detailed information about a specific liquidity pool including depths, price, volume, and APY metrics. ```APIDOC ## GET /v2/pool/{asset} ### Description Returns detailed information about a specific liquidity pool including depths, price, volume, and APY metrics. ### Method GET ### Endpoint /v2/pool/{asset} ### Path Parameters - **asset** (string) - Required - The asset ticker of the pool (e.g., 'BTC.BTC'). ### Query Parameters - **period** (string) - Optional - Specify the period for APY calculation (e.g., '30d', '100d'). ### Response #### Success Response (200) - **asset** (string) - The asset ticker (e.g., 'BTC.BTC'). - **volume24h** (string) - Trading volume in the last 24 hours. - **assetDepth** (string) - The depth of the asset in the pool. - **runeDepth** (string) - The depth of RUNE in the pool. - **assetPrice** (string) - The current price of the asset in RUNE. - **assetPriceUSD** (string) - The current price of the asset in USD. - **liquidityInUSD** (string) - The total liquidity of the pool in USD. - **annualPercentageRate** (string) - The annual percentage rate for the pool. - **poolAPY** (string) - The annual percentage yield for the pool. - **status** (string) - The status of the pool (e.g., 'available'). - **liquidityUnits** (string) - Total liquidity units in the pool. - **synthUnits** (string) - Units of synthetic assets in the pool. - **synthSupply** (string) - Supply of synthetic assets. - **units** (string) - Total units in the pool. - **nativeDecimal** (string) - The native decimal precision of the asset. - **saversUnits** (string) - Units in the savers module. - **saversDepth** (string) - Depth of savers in the pool. - **saversAPR** (string) - Annual Percentage Rate for savers. - **lpLuvi** (string) - Liquidity Provider Unit Liquidity Index. ### Request Example ```bash # Get details for BTC pool curl -X GET "https://midgard.thorchain.info/v2/pool/BTC.BTC" # Get ETH pool with 100-day APY period curl -X GET "https://midgard.thorchain.info/v2/pool/ETH.ETH?period=100d" ``` ### Response Example ```json { "asset": "BTC.BTC", "volume24h": "1500000000000", "assetDepth": "50000000000", "runeDepth": "2000000000000000", "assetPrice": "40000.0", "assetPriceUSD": "40000.0", "liquidityInUSD": "4000000000", "annualPercentageRate": "0.15", "poolAPY": "0.15", "status": "available", "liquidityUnits": "1000000000000", "synthUnits": "100000000000", "synthSupply": "5000000000", "units": "1100000000000", "nativeDecimal": "8", "saversUnits": "200000000000", "saversDepth": "10000000000", "saversAPR": "0.08", "lpLuvi": "0.12" } ``` ``` -------------------------------- ### Get Member Details for Single Address Source: https://context7.com/thorchain/midgard/llms.txt Retrieves liquidity provider statistics for a specific address across all pools. Use this to understand an individual's participation in liquidity pools. ```bash # Get member details for single address curl -X GET "https://midgard.thorchain.info/v2/member/thor1abc123..." ``` ```bash # Get member details for multiple addresses (comma-separated) curl -X GET "https://midgard.thorchain.info/v2/member/thor1abc123...,bc1q..." ``` ```bash # Include savers vault membership curl -X GET "https://midgard.thorchain.info/v2/member/thor1abc123...?showSavers=true" ``` ```json { "pools": [ { "pool": "BTC.BTC", "runeAddress": "thor1abc123...", "assetAddress": "bc1q...", "liquidityUnits": "50000000000", "runeDeposit": "1000000000000", "assetDeposit": "25000000", "runeAdded": "1200000000000", "assetAdded": "30000000", "runePending": "0", "assetPending": "0", "runeWithdrawn": "200000000000", "assetWithdrawn": "5000000", "dateFirstAdded": "1680000000", "dateLastAdded": "1699800000" } ] } ``` -------------------------------- ### GET /member/{address} Source: https://context7.com/thorchain/midgard/llms.txt Returns liquidity provider statistics for a specific address or multiple addresses across all pools they participate in. ```APIDOC ## GET /member/{address} ### Description Returns liquidity provider statistics for a specific address across all pools they participate in. ### Method GET ### Endpoint /v2/member/{address} ### Parameters #### Path Parameters - **address** (string) - Required - The address or comma-separated list of addresses to query. #### Query Parameters - **showSavers** (boolean) - Optional - Include savers vault membership in the response. ### Response #### Success Response (200) - **pools** (array) - List of pool participation details for the member. ``` -------------------------------- ### Get Current Votes Source: https://context7.com/thorchain/midgard/llms.txt Retrieves all current votes from the network. ```APIDOC ## GET /v2/votes ### Description Retrieves all current votes from the network. ### Method GET ### Endpoint https://midgard.thorchain.info/v2/votes ### Response #### Success Response (200) - **value** (string) - The identifier for the vote. - **votes** (array) - An array of vote objects. - **address** (string) - The address that cast the vote. - **key** (string) - The type of vote (e.g., "VOTE"). - **date** (string) - The timestamp of the vote in nanoseconds. ### Response Example ```json [ { "value": "prop6", "votes": [ { "address": "thor1abc123...", "key": "VOTE", "date": "1699800000000000000" } ] } ] ``` ``` -------------------------------- ### Run Midgard Tests Source: https://gitlab.com/thorchain/midgard/-/blob/develop/README.md Sets up a test PostgreSQL instance and runs all Go tests for Midgard. ```sh docker-compose up -d pgtest go test -p 1 ./... ``` -------------------------------- ### Running Midgard Locally Source: https://context7.com/thorchain/midgard/llms.txt Instructions for setting up and running Midgard locally using Docker Compose or natively. ```APIDOC ## Running Midgard Locally ### Description Start Midgard with Docker Compose or natively with Go for local development and testing. ### Commands #### Start PostgreSQL database ```bash docker-compose up -d pg ``` #### Create local blockstore directory ```bash mkdir -p ./tmp/blockstore ``` #### Run Midgard natively connecting to mainnet ```bash go run ./cmd/midgard/ config/ex/base.json:config/ex/pg.json:config/ex/bs-m.json:config/ex/net-main-9r.json ``` #### Run with Docker Compose (Requires `config/local.json` with `timescale.host="pg"`) ```bash docker-compose up --build midgard ``` #### Run tests ```bash docker-compose up -d pgtest go test -p 1 ./... ``` #### Connect to PostgreSQL for manual queries ```bash psql -h localhost -U midgard midgard -p 5432 ``` ``` -------------------------------- ### GET /v2/nodes Source: https://context7.com/thorchain/midgard/llms.txt Returns a list of all THORChain nodes with their public keys and addresses. ```APIDOC ## GET /v2/nodes ### Description Returns a list of all THORChain nodes with their public keys and addresses. ### Method GET ### Endpoint https://midgard.thorchain.info/v2/nodes ### Response #### Success Response (200) - **nodeAddress** (string) - The address of the node - **secp256k1** (string) - The secp256k1 public key - **ed25519** (string) - The ed25519 public key #### Response Example [ { "nodeAddress": "thor102y0m3uptg0vvudeyh00r2fnz70wq7d8y7mu2g", "secp256k1": "thorpub1addwnpepqgxwdf3ure0pg5fwnpeux3ym9n06267lkres54zwjh4c8048ezhj5024qyr", "ed25519": "thorpub1addwnpepqgxwdf3ure0pg5fwnpeux3ym9n06267lkres54zwjh4c8048ezhj5024qyr" } ] ``` -------------------------------- ### Get Votes from Specific Period Source: https://context7.com/thorchain/midgard/llms.txt Retrieves votes within a specified historical period. ```APIDOC ## GET /v2/votes?period={period} ### Description Retrieves votes within a specified historical period. ### Method GET ### Endpoint https://midgard.thorchain.info/v2/votes ### Query Parameters - **period** (string) - Required - The time period for which to retrieve votes (e.g., "30d"). ### Response #### Success Response (200) - **value** (string) - The identifier for the vote. - **votes** (array) - An array of vote objects. - **address** (string) - The address that cast the vote. - **key** (string) - The type of vote (e.g., "VOTE"). - **date** (string) - The timestamp of the vote in nanoseconds. ### Response Example ```json [ { "value": "prop6", "votes": [ { "address": "thor1abc123...", "key": "VOTE", "date": "1699800000000000000" } ] } ] ``` ``` -------------------------------- ### Run Balance Check Tool Source: https://gitlab.com/thorchain/midgard/-/blob/develop/cmd/checks/balance/README.md Executes the balance comparison utility using a PostgreSQL configuration and a genesis file. ```console $ go run ./cmd/checks/balance postgres_config_json genesis_json ``` -------------------------------- ### Create temporary export directory Source: https://gitlab.com/thorchain/midgard/-/blob/develop/docs/synthluvi/README.md Prepare the filesystem for data export. ```bash mkdir tmp/export ``` -------------------------------- ### Configuration Source: https://context7.com/thorchain/midgard/llms.txt Details on how to configure Midgard using JSON config files or environment variables. ```APIDOC ## Configuration ### Description Configure Midgard using JSON config files or environment variables for flexible deployment options. ### Configuration Example (JSON) ```json { "listen_port": 8080, "shutdown_timeout": "20s", "read_timeout": "20s", "write_timeout": "20s", "max_block_age": "60s", "thorchain": { "tendermint_url": "http://localhost:26657/websocket", "thornode_url": "http://localhost:1317/thorchain", "fetch_batch_size": 1, "parallelism": 1, "read_timeout": "8s" }, "timescale": { "host": "localhost", "port": 5432, "user_name": "midgard", "password": "password", "database": "midgard", "max_open_conns": 80 }, "blockstore": { "local": "./tmp/blockstore", "remote": "https://storage.googleapis.com/public-snapshots-ninerealms/midgard-blockstore/mainnet/v2/", "blocks_per_chunk": 10000 }, "websockets": { "enable": true, "connection_limit": 100 }, "usdpools": [ "BNB.BUSD-BD1", "ETH.USDT-0XDAC17F958D2EE523A2206206994597C13D831EC7", "ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48" ] } ``` ``` -------------------------------- ### Run code formatting and linting Source: https://gitlab.com/thorchain/midgard/-/blob/develop/README.md Execute these commands to ensure code style compliance and static analysis pass before submission. ```bash gofmt -l -s -w ./ docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint golangci-lint run -v ``` -------------------------------- ### Retrieve Actions List Source: https://context7.com/thorchain/midgard/llms.txt Fetches a paginated list of network actions like swaps, adds, and withdraws with filtering options. ```bash curl -X GET "https://midgard.thorchain.info/v2/actions?limit=50" ``` ```bash curl -X GET "https://midgard.thorchain.info/v2/actions?address=thor1abc123...&limit=20" ``` ```bash curl -X GET "https://midgard.thorchain.info/v2/actions?type=swap&limit=50" ``` ```bash curl -X GET "https://midgard.thorchain.info/v2/actions?txid=2F624637DE179665BA3322B864DB9F30001FD37B4E0D22A0B6ECE6A5B078DAB4" ``` ```bash curl -X GET "https://midgard.thorchain.info/v2/actions?asset=BTC.BTC,ETH.ETH&type=swap" ``` ```bash curl -X GET "https://midgard.thorchain.info/v2/actions?asset=nosynth,norune&type=swap" ``` ```bash curl -X GET "https://midgard.thorchain.info/v2/actions?nextPageToken=123456789" ``` -------------------------------- ### GET /history/savers/{pool} Source: https://context7.com/thorchain/midgard/llms.txt Returns historical savers vault depth and unit data for a specific pool. ```APIDOC ## GET /history/savers/{pool} ### Description Returns historical savers vault depth and unit data for a specific pool. ### Method GET ### Endpoint /v2/history/savers/{pool} ### Parameters #### Path Parameters - **pool** (string) - Required - The pool identifier (e.g., BTC.BTC). #### Query Parameters - **interval** (string) - Optional - Time interval (e.g., day). - **count** (integer) - Optional - Number of intervals to return. ### Response #### Success Response (200) - **meta** (object) - Historical metadata. - **intervals** (array) - Historical data points. ``` -------------------------------- ### Clone Repositories for Smoke Testing Source: https://gitlab.com/thorchain/midgard/-/blob/develop/docs/smoke/README.md Initializes the directory structure and clones the required repositories for the smoke test environment. ```shell mkdir smoke cd smoke SMOKEPATH=`pwd` git clone git@gitlab.com:thorchain/thornode.git git clone git@gitlab.com:thorchain/heimdall.git # If you don't have it yet clone midgard and go to the branch you want git clone git@gitlab.com:delphidigital/midgard.git ``` -------------------------------- ### Update Go dependencies Source: https://gitlab.com/thorchain/midgard/-/blob/develop/README.md Use these commands to update a library version and synchronize the go.mod file. ```bash go get github.com/team/repo@version go mod tidy ``` -------------------------------- ### Midgard Configuration File Source: https://gitlab.com/thorchain/midgard/-/blob/develop/docs/smoke/README.md JSON configuration for Midgard, specifying the listen port, ThorChain node URLs, and Timescale database connection details. ```json { "listen_port": 8080, "thorchain": { "url": "http://localhost:26657/websocket", "node_url": "http://localhost:1317/thorchain", "last_chain_backoff": "7s" }, "timescale": { "host": "localhost", "port": 5433, "user_name": "midgard", "password": "password", "database": "midgard", "sslmode": "disable" } } ``` -------------------------------- ### Upgrade Local ThorNode Source: https://gitlab.com/thorchain/midgard/-/blob/develop/README.md Instructions to upgrade a local ThorNode by updating the Docker image and restarting. ```sh docker-compose up -d ... ``` -------------------------------- ### List All Liquidity Pools Source: https://context7.com/thorchain/midgard/llms.txt Fetches an array of all liquidity pools with optional filtering by status and APY period. ```bash # Get all available pools curl -X GET "https://midgard.thorchain.info/v2/pools" # Get only available pools with 30-day APY period curl -X GET "https://midgard.thorchain.info/v2/pools?status=available&period=30d" ``` -------------------------------- ### Execute SQL export script Source: https://gitlab.com/thorchain/midgard/-/blob/develop/docs/synthluvi/README.md Run the SQL script to generate raw data files. ```sql \i docs/synthluvi/export.sql ``` -------------------------------- ### Calculate Swap Metrics Source: https://gitlab.com/thorchain/midgard/-/blob/develop/docs/slip_explained.txt Mathematical formulas for calculating expected amounts, slippage, and fees for swaps. ```javascript t0 = 1612415387742639681 priceA0 = 8000000000 / 104000000000 = 0.07692307692307693 priceR = 1/pricaA = 13.0 Trade1, first swap (1612420911125838092) ============================ from_e8=100000000 to_e8=1268099375 swap_slip_bp = 123 liq_fee_e8 = 15851242 // (from:) a=100000000 -> (to:) b=? a = 100000000 // X: from_depth_before, Y: to_depth_before X1 = 8000000000 Y1 = 104000000000 // Expected to (ratio only, without fees) bE = (a * Y1) / X1 = 1300000000.0 // Actual to (without fees) bA = (a * Y1) / (a + X1) = 1283950617.2839506 bDiffEA = bE - bA = 16049382.716049433 // Expected/Actual Ratio R1Formula1 = bA / bE = 0.9876543209876543 R1 = X1 / (a+X1) = 0.9876543209876543 // slip = diffEA / bE ( == 1 - ear), formulas are the same, except loat rounding errors slip1Formula1 = diffEA / bE = 0.012345679012345718 ( ~= 123 * 1e4) slip1Formula2 = 1 - R1 = 0.012345679012345734 slip1 = a / (a + X1) = 0.012345679012345678 // Fee = (actual to)*slip fee1 = slip1 * bA = 15851242.188690798 ~= 15851242 // Final to = (actual to) - fee bFormula1 = bA - fee1 = 1268099375.09526 bF = bE*R1*R1 = 1268099375.0952597 ~= 1268099375 Trade1, second swap ==================== from_e8=1268099375 to_e8=35970313 swap_slip_bp = 36 liq_fee_e8 = 130312 X2 = 350035000000 Y2 = 10001000000 b = 1268099375 cE = b*Y2 / X2 = 36231410.71428572 cA = b*Y2 / (b + X2) = 36100626.13150266 R2 = X2 / (b + X2) = 0.996390298357014 cAFormula2 = ce*R2 slip2 = 1 - R2 = 0.0036097016429860185 ( ~= 36*1e4) fee2 = slip2 * cE*R2 = 130312.48945970729 ~= 130312 cFFormula1 = cA - fee2 = 35970313.64204295 = 35970313 cF = cE*R2*R2 Doubleswap formula: =================== X->Y->Z a->b->c c = (a*Z/X)*R1*R1*R2*R2 = expectedPrice * (1-slip1)^2 * (1-slip2)^2 slipTotal = slip1 + slip2 - slip1*slip2 c = expectedPrice * (1-slipTotal)^2 slipTotalBP = slip1BP + slip2BP - slip1BP*slip2BP/1e4 ``` -------------------------------- ### GET /v2/history/earnings Source: https://context7.com/thorchain/midgard/llms.txt Retrieves historical earnings data including liquidity fees, block rewards, and pool-specific earnings. ```APIDOC ## GET /v2/history/earnings ### Description Returns historical earnings data including liquidity fees, block rewards, and pool-specific earnings. ### Method GET ### Endpoint /v2/history/earnings ### Parameters #### Query Parameters - **interval** (string) - Required - Time interval (e.g., day, hour) - **count** (integer) - Optional - Number of intervals to return ``` -------------------------------- ### Dump Blocks for Blockstore Source: https://gitlab.com/thorchain/midgard/-/blob/develop/README.md Dump all blocks from ThorNode to be used for generating blockstore hashes. Stop Midgard before running this command. ```bash # Stop midgard first. go run ./cmd/blockstore/dump config ``` -------------------------------- ### Add binary-only dependency Source: https://gitlab.com/thorchain/midgard/-/blob/develop/README.md Add a dependency used for build tools. Ensure it is imported in a .go file to prevent removal by go mod tidy. ```bash go get github.com/deepmap/oapi-codegen@latest ``` -------------------------------- ### Get Current and Historical Votes Source: https://context7.com/thorchain/midgard/llms.txt Retrieve voting data from the Midgard API, optionally filtered by a specific time period. ```bash curl -X GET "https://midgard.thorchain.info/v2/votes" ``` ```bash curl -X GET "https://midgard.thorchain.info/v2/votes?period=30d" ``` -------------------------------- ### GET /saver/{address} Source: https://context7.com/thorchain/midgard/llms.txt Returns saver vault statistics for a specific address, showing deposited assets and redeemable amounts. ```APIDOC ## GET /saver/{address} ### Description Returns saver vault statistics for a specific address, showing deposited assets and redeemable amounts. ### Method GET ### Endpoint /v2/saver/{address} ### Parameters #### Path Parameters - **address** (string) - Required - The saver address to query. ### Response #### Success Response (200) - **pools** (array) - List of saver vault positions for the address. ``` -------------------------------- ### Actions List Source: https://context7.com/thorchain/midgard/llms.txt Returns a paginated list of actions (swaps, adds, withdraws, refunds, etc.) with their related transactions. ```APIDOC ## GET /v2/actions ### Description Returns a paginated list of actions (swaps, adds, withdraws, refunds, etc.) with their related transactions. ### Method GET ### Endpoint /v2/actions ### Query Parameters - **limit** (integer) - Optional - The maximum number of actions to return per page. Default is 50. - **address** (string) - Optional - Filter actions by a specific THORChain address. - **type** (string) - Optional - Filter actions by type (e.g., 'swap', 'addLiquidity', 'withdraw'). - **txid** (string) - Optional - Filter actions by a specific transaction ID. - **asset** (string) - Optional - Filter actions by asset(s). Can be a single asset (e.g., 'BTC.BTC') or a comma-separated list. Special filters like 'nosynth' or 'norune' can also be used. - **nextPageToken** (string) - Optional - Token for retrieving the next page of results. ### Response #### Success Response (200) - **actions** (array) - An array of action objects, each containing details about a specific transaction. - **nextPageToken** (string) - Token for retrieving the next page of results, if available. ### Response Example (for a swap action) ```json { "actions": [ { "type": "swap", "height": "1234567", "txid": "2F624637DE179665BA3322B864DB9F30001FD37B4E0D22A0B6ECE6A5B078DAB4", "fromAsset": "BNB.BNB", "toAsset": "BTC.BTC", "fromAmount": "100000000", "toAmount": "5000", "effectivePrice": "0.00005", "priceImpact": "0.001", "fee": { "asset": "BNB.BNB", "amount": "100000", "decimals": 8 }, "date": "1699900800", "thorchainAddress": "thor1...", "fromAddress": "bnb1...", "toAddress": "bc1..." } ], "nextPageToken": "abcdef12345" } ``` ``` -------------------------------- ### List All Pools Source: https://context7.com/thorchain/midgard/llms.txt Returns an array of all liquidity pools with their current depths, prices, APY, and volume statistics. ```APIDOC ## GET /v2/pools ### Description Returns an array of all liquidity pools with their current depths, prices, APY, and volume statistics. ### Method GET ### Endpoint /v2/pools ### Query Parameters - **status** (string) - Optional - Filter pools by status (e.g., 'available'). - **period** (string) - Optional - Specify the period for APY calculation (e.g., '30d', '100d'). ### Response #### Success Response (200) - **asset** (string) - The asset ticker (e.g., 'BTC.BTC'). - **volume24h** (string) - Trading volume in the last 24 hours. - **assetDepth** (string) - The depth of the asset in the pool. - **runeDepth** (string) - The depth of RUNE in the pool. - **assetPrice** (string) - The current price of the asset in RUNE. - **assetPriceUSD** (string) - The current price of the asset in USD. - **liquidityInUSD** (string) - The total liquidity of the pool in USD. - **annualPercentageRate** (string) - The annual percentage rate for the pool. - **poolAPY** (string) - The annual percentage yield for the pool. - **earnings** (string) - Accumulated earnings for the pool. - **earningsAnnualAsPercentOfDepth** (string) - Annual earnings as a percentage of depth. - **status** (string) - The status of the pool (e.g., 'available'). - **liquidityUnits** (string) - Total liquidity units in the pool. - **synthUnits** (string) - Units of synthetic assets in the pool. - **synthSupply** (string) - Supply of synthetic assets. - **units** (string) - Total units in the pool. - **nativeDecimal** (string) - The native decimal precision of the asset. - **saversUnits** (string) - Units in the savers module. - **saversDepth** (string) - Depth of savers in the pool. - **saversAPR** (string) - Annual Percentage Rate for savers. - **totalCollateral** (string) - Total collateral in the pool. - **totalDebtTor** (string) - Total debt in RUNE for the pool. - **lpLuvi** (string) - Liquidity Provider Unit Liquidity Index. ### Request Example ```bash # Get all available pools curl -X GET "https://midgard.thorchain.info/v2/pools" # Get only available pools with 30-day APY period curl -X GET "https://midgard.thorchain.info/v2/pools?status=available&period=30d" ``` ### Response Example ```json [ { "asset": "BTC.BTC", "volume24h": "1500000000000", "assetDepth": "50000000000", "runeDepth": "2000000000000000", "assetPrice": "40000.0", "assetPriceUSD": "40000.0", "liquidityInUSD": "4000000000", "annualPercentageRate": "0.15", "poolAPY": "0.15", "earnings": "500000000000", "earningsAnnualAsPercentOfDepth": "0.12", "status": "available", "liquidityUnits": "1000000000000", "synthUnits": "100000000000", "synthSupply": "5000000000", "units": "1100000000000", "nativeDecimal": "8", "saversUnits": "200000000000", "saversDepth": "10000000000", "saversAPR": "0.08", "totalCollateral": "1000000000", "totalDebtTor": "500000000000", "lpLuvi": "0.12" } ] ``` ``` -------------------------------- ### Configure PostgreSQL Password Source: https://gitlab.com/thorchain/midgard/-/blob/develop/README.md Avoid repeatedly entering the PostgreSQL password by adding it to the ~/.pgpass file. Ensure the file has correct permissions (0600). ```bash echo '*:*:midgard:*:password' >> ~/.pgpass && chmod 0600 ~/.pgpass ``` -------------------------------- ### Execute Smoke Test Source: https://gitlab.com/thorchain/midgard/-/blob/develop/docs/smoke/README.md Runs the smoke test suite using the Makefile in the Heimdall directory. ```shell cd $SMOKEPATH/heimdall make smoke ``` -------------------------------- ### Override Midgard Config with Environment Variables Source: https://context7.com/thorchain/midgard/llms.txt Set environment variables to customize Midgard's configuration, such as listen port, timescale port, and specific pool settings. Ensure variables are exported before running Midgard. ```bash export MIDGARD_LISTEN_PORT=8081 export MIDGARD_TIMESCALE_PORT=5433 export MIDGARD_USD_POOLS="A,B,C" export MIDGARD_POOLS_DECIMAL="A.A:8,B.B:18" ``` -------------------------------- ### Retrieve Depth and Price History Source: https://context7.com/thorchain/midgard/llms.txt Fetches historical asset and rune depths with price data for a specific pool. Use interval parameters to define the granularity of the returned data. ```bash curl -X GET "https://midgard.thorchain.info/v2/history/depths/BTC.BTC?interval=day&count=30" ``` ```bash curl -X GET "https://midgard.thorchain.info/v2/history/depths/ETH.ETH?interval=hour&from=1699800000&to=1699900000" ``` -------------------------------- ### Define Pool Variables Source: https://gitlab.com/thorchain/midgard/-/blob/develop/docs/earnings.md Initial and final state variables for pool assets, rune, and units. ```text A0 = total amount of Asset in the pool at the beginning of the time interval R0 = total amount of Rune in the pool at the beginning of the time interval U0 = total Pool units of pool at the beginning of the time interval A1 = total amount of Asset in the pool at the end of the time interval R1 = total amount of Rune in the pool at the end of the time interval U1 = total Pool units of pool at the end of the time interval ```