Skip to content

Conversation

@dmax10
Copy link
Contributor

@dmax10 dmax10 commented Sep 16, 2025

Archi Finance distribution calculations into a unified end-to-end script

Files:

  • ARCHI_DISTRIBUTIONS.md - Distribution results and tables
  • archiDistributions.ts - Unified calculation script
  • archiUnaccountedFsGLP.ts - Investigation script for CreditAggregator balance

What archiDistributions.ts does:

Step 1: Verify fsGLP Holdings

Queries on-chain balances from 3 key contracts

  • GMXExecutor: 1,606,694.32 fsGLP (active farmer positions)
  • CreditUser#2: 8,478.67 fsGLP (liquidator fees)
  • CreditAggregator: 99.81 fsGLP (unaccounted)
  • Total: 1,615,272.79 fsGLP

Step 2: Extract Active Positions

  • Queries CreateUserLendCredit and CreateUserBorrowed events from CreditUser#2
  • Filters via isTerminated() on-chain calls
  • Result: 47 active positions (65 terminated out of 112 total)
  • Extracts complete position data: collateral, borrowed amounts, credit managers, fsGLP breakdown
  • Queries historical GLP prices at position opening for IL adjustment calculations

Step 3: Calculate Farmer Distributions

  • Aggregates 47 positions by farmer → 4 unique farmers
  • Calculates: collateral fsGLP + proportional liquidator fee share
  • Liquidator fees: 5% of collateral (8,478.67 fsGLP total in CreditUser#2)
  • IL Adjustment Capping: Caps farmer distributions based on weighted average GLP price at position opening vs $1.45 incident price
    • Formula: capped_fsGLP = total_fsGLP × avg_price_at_open / 1.45
  • Total farmer distributions (original): 169,573.39 fsGLP (10.50% of protocol)

Step 4: Calculate Vault Borrowing

  • Maps credit manager addresses to vault tokens (WETH/WBTC/USDT/USDC)
  • Aggregates borrowed fsGLP by vault
  • Total borrowed: 1,445,599.59 fsGLP (89.50% of protocol)
  • Breakdown:
    • WBTC: 848,962.09 (58.72%)
    • WETH: 248,165.92 (17.16%)
    • USDT: 190,986.02 (13.21%)
    • USDC: 157,485.56 (10.89%)

Step 5: Calculate LP Distributions

  • Discovery method: Queries StakeFor events from BaseReward contracts
    • 100% accurate (vs 99.52% with AddLiquidity/RemoveLiquidity events)
    • Discovers all LPs who ever staked in each vault
  • Balance queries: Gets current vsToken balances for each LP
  • Calculation: LP_fsGLP = (LP_vsTokens / total_vsTokens) × vault_borrowed_fsGLP
  • Result: 405 unique LPs with current balances (888 total discovered via StakeFor, 483 with zero balance)

Step 6: Apply Stablecoin Capping and Redistribute Excess

  • USDC/USDT LP Capping: Caps stablecoin LP distributions so their fsGLP value at $1.45 doesn't exceed their original deposit value ($1 per USDC/USDT)
    • Formula: capped_fsGLP = min(original_fsGLP, deposit_usd / 1.45)
  • Excess Redistribution: Total excess from farmer IL adjustment + stablecoin LP capping is redistributed proportionally to WBTC/WETH LPs based on their volatile asset holdings
  • Final LP distributions: Same total fsGLP (1,445,599.59), but redistributed from stablecoin LPs to volatile asset LPs

Outputs

CSV Files

  • out/archi-farmer-positions.csv - All 47 active positions with complete borrowing details, historical GLP prices, and opening dates
  • out/archi-farmer-distributions.csv - Final distributions for 4 farmers (includes original, capped, and recovery % columns)
  • out/archi-lp-distributions.csv - LP distributions with per-vault vsToken balances, original amounts, capped amounts, and final distributions (405 LPs)

Markdown

ARCHI_DISTRIBUTIONS.md - Auto-updated with distribution tables:

  • Vault borrowing summary
  • Farmers table (with capping details)
  • All farmer positions (with historical prices)
  • Top 20 LPs table (or all with PREVIEW_ALL_LPS=true)

Distribution Summary (Before Capping)

Category Amount (fsGLP) % of Total Recipients
Farmers 169,573.39 10.50% 4 farmers (47 positions)
LPs 1,445,599.59 89.50% 405 unique LPs
TOTAL 1,615,172.98 100% 409 unique addresses

Not Distributed: CreditAggregator 99.81 fsGLP (1 tx initiated by archi deployer)

Distribution Summary (After Capping & Redistribution)

Category Original Capped/Final Excess Recipients
Farmers 169,573.39 fsGLP [Calculated at runtime] [Redistributed to LPs] 4 farmers
LPs - Stablecoins (USDC/USDT) [Original amount] [Capped at deposit value] [Redistributed to volatile LPs] Stablecoin LPs
LPs - Volatile (WBTC/WETH) 1,097,128.01 fsGLP [Original + excess] - Volatile asset LPs
Total LPs 1,445,599.59 fsGLP 1,445,599.59 fsGLP + farmer excess - 405 unique LPs
GRAND TOTAL 1,615,172.98 fsGLP [Farmer capped + LP final] 0 409 unique addresses

Capping Methodology

  1. Farmer IL Adjustment Capping:

    • Each farmer's distribution is capped based on the weighted average GLP price when they opened their positions vs the $1.45 price at the time of the incident
    • Formula: capped_total = total_fsGLP × (avg_GLP_price_at_open / 1.45)
    • Excess from farmers is added to the redistribution pool for volatile LPs
  2. Stablecoin LP Capping:

    • USDC and USDT LP distributions are capped so that their fsGLP value at $1.45 does not exceed their original stablecoin deposit value
    • Formula: capped_fsGLP = min(original_fsGLP, (vsTokens / 1e6 × $1.00) / 1.45)
    • Assumes $1.00 per USDC/USDT at deposit time
    • Excess from stablecoin LPs is added to the redistribution pool
  3. Excess Redistribution to Volatile LPs:

    • Total excess = Farmer excess + USDC excess + USDT excess
    • Redistributed proportionally to WBTC and WETH LPs based on their volatile asset value
    • Each LP's excess share is split between WBTC and WETH based on their individual holdings ratio
    • WBTC and WETH LPs receive their original distribution + their share of the excess

Result: Farmers and stablecoin LPs are protected from receiving more value than they deposited, while volatile asset LPs (WBTC/WETH) absorb the excess to maintain 100% distribution of available fsGLP.

@dmax10 dmax10 changed the base branch from main to updates September 16, 2025 19:46
3 accounts have negative outflows
- LPs (adding / removing liquidity) for all vaults: wbtc, weth, usdc, usdt
- and remove individual vault queries
- addresses are consistent with archi-GMXExecutor-fsGLP-unique-users query, which has just 3 additional addresses
-- 0x02b72485ecdaabd5f9af68d9a5d2b2ca54d5339b
-- 0x60a3d336c39e8fac40647142d3068780b4bc4c93 --> archi deployer
-- 0x61cd1eb8434aabdd38a0abd62dc8665e958e41d1
Mostly closed / liquidated positions, but must be confirmed
…ract

This CreditUser was the one used by farmers to mint the 1.6M fsGLP from GMXExecutor, and it holds the records for these farmers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants