### Initialize Git and Install Foundry Dependencies Source: https://github.com/gmx-io/gmx-synthetics/blob/main/forked-env-example/QUICKSTART.md Initializes a git repository and installs the forge-std dependency for Foundry. ```bash cd forked-env-example # Initialize git (required for forge install if setting up as standalone repo) git init # Install dependencies (just forge-std) forge install foundry-rs/forge-std --no-commit ``` -------------------------------- ### Set Arbitrum RPC URL for Foundry Source: https://github.com/gmx-io/gmx-synthetics/blob/main/forked-env-example/QUICKSTART.md Copies the example environment file and sources it to set the Arbitrum RPC URL. ```bash # Set Arbitrum RPC URL cp .env.example .env # Edit .env and set your ARBITRUM_RPC_URL source .env ``` -------------------------------- ### Start Anvil Fork with npm Script Source: https://github.com/gmx-io/gmx-synthetics/blob/main/forked-env-example/QUICKSTART.md Starts the Anvil development blockchain, forked from Arbitrum mainnet, using an npm script. ```bash # Using npm script (automatically sources .env) npm run anvil:start ``` -------------------------------- ### Set Arbitrum RPC URL for Anvil Source: https://github.com/gmx-io/gmx-synthetics/blob/main/forked-env-example/QUICKSTART.md Copies the example environment file to .env. npm scripts will automatically source this file. ```bash # Set Arbitrum RPC URL cp .env.example .env # Edit .env and set your ARBITRUM_RPC_URL # Note: npm scripts automatically source .env, so you don't need to run 'source .env' ``` -------------------------------- ### Funding Fee Calculation Example 3 Source: https://github.com/gmx-io/gmx-synthetics/blob/main/README.md Demonstrates a funding fee calculation where `longShortImbalance` is below `thresholdForDecreaseFunding`, leading to a decrease in `savedFundingFactorPerSecond`. ```plaintext Since longShortImbalance < thresholdForDecreaseFunding, savedFundingFactorPerSecond should decrease by `0.000002% * 600 = 0.0012%` ``` -------------------------------- ### Real-tx Example: Opening Position Source: https://github.com/gmx-io/gmx-synthetics/blob/main/scripts/distributions/ARCHI_DISTRIBUTIONS.md Details a real transaction where a farmer opened a leveraged position by depositing collateral and borrowing from WETH and USDC vaults. ```text Total borrowed: 1.71 WETH + 4,081.23 USDC (~$11,000 combined) ├── Collateral: 0.4275 ETH (after 10% fee) → 826.23 fsGLP ├── Liquidator fee: 0.0225 ETH → held in escrow (returned to farmer on normal close, or to liquidator if liquidated) ├── From WETH vault: 1.71 WETH → 3,304.93 fsGLP └── From USDC vault: 4,081.23 USDC → 4,128.68 fsGLP Total position: 8,259.84 fsGLP (~10x leverage) ``` -------------------------------- ### Funding Fee Calculation Example 2 Source: https://github.com/gmx-io/gmx-synthetics/blob/main/README.md Shows a funding fee calculation where the `longShortImbalance` is between `thresholdForDecreaseFunding` and `thresholdForStableFunding`, and the funding rate remains unchanged. ```plaintext Since longs are already paying shorts, the skew is the same, and the longShortImbalance < thresholdForStableFunding, savedFundingFactorPerSecond should not change ``` -------------------------------- ### Install npm Dependencies for Anvil Source: https://github.com/gmx-io/gmx-synthetics/blob/main/forked-env-example/QUICKSTART.md Installs the necessary npm dependencies for running TypeScript scripts with Anvil. ```bash cd forked-env-example # Install npm dependencies npm install ``` -------------------------------- ### Run Archi Distribution Calculation Source: https://github.com/gmx-io/gmx-synthetics/blob/main/scripts/distributions/ARCHI_DISTRIBUTIONS.md Execute the script to calculate and preview LP distributions. Set PREVIEW_ALL_LPS to true to show all LPs instead of the default top 20. ```bash PREVIEW_ALL_LPS=true npx hardhat run --network arbitrum scripts/distributions/archi/calculateDistributions.ts ``` -------------------------------- ### Solidity Callback Function Overloading for Backward Compatibility Source: https://github.com/gmx-io/gmx-synthetics/blob/main/changelogs/v2.2.md Demonstrates how to support both old and new callback function signatures during a transition period. This allows integrations to update their contracts gradually without breaking existing functionality. ```solidity contract Callback { function afterDepositExecution( bytes32 key, Deposit.Props memory deposit, EventUtils.EventLogData memory eventData ) external { ... } function afterDepositExecution( bytes32 key, EventUtils.EventLogData memory depositData, EventUtils.EventLogData memory eventData ) external { ... } } ``` -------------------------------- ### Funding Fee Calculation Example 1 Source: https://github.com/gmx-io/gmx-synthetics/blob/main/README.md Illustrates a funding fee calculation scenario where `longShortImbalance` exceeds `thresholdForStableFunding`, resulting in an increase in `savedFundingFactorPerSecond`. ```plaintext Since longShortImbalance > thresholdForStableFunding, savedFundingFactorPerSecond should increase by `0.0001% * 6% * 600 = 0.0036%` ``` -------------------------------- ### Compile Contracts with Hardhat Source: https://github.com/gmx-io/gmx-synthetics/blob/main/README.md Use this command to compile all smart contracts in the project. ```sh npx hardhat compile ``` -------------------------------- ### Run Archi Distribution Calculation Source: https://github.com/gmx-io/gmx-synthetics/blob/main/scripts/distributions/ARCHI_DISTRIBUTIONS.md Execute the Archi Finance distribution calculation script. Use a public RPC for basic usage or a paid RPC for faster execution. ```bash # Use public RPC (slower with rate limiting) npx hardhat run --network arbitrum scripts/distributions/archi/calculateDistributions.ts # Or use fast RPC (paid Alchemy/Infura) FAST_RPC=true npx hardhat run --network arbitrum scripts/distributions/archi/calculateDistributions.ts ``` -------------------------------- ### Check Contract Sizes with Hardhat Source: https://github.com/gmx-io/gmx-synthetics/blob/main/README.md This command helps in measuring the deployment size of your smart contracts. ```sh npx hardhat measure-contract-sizes ``` -------------------------------- ### Check Contract Dependencies with Hardhat Source: https://github.com/gmx-io/gmx-synthetics/blob/main/README.md Analyze and display the dependencies of a specified contract file. ```sh npx hardhat dependencies ```