Sepolia Testnet

Contract

0x1F64078E323c37B3Aca709FB9146A73c3f3c4617

Overview

ETH Balance

0 ETH

Multichain Info

N/A
Transaction Hash
Method
Block
From
To
0x61062a6162877792024-07-11 5:31:009 days ago1720675860IN
 Create: MathHelper
0 ETH0.0087908822.31255963

Advanced mode:
Parent Transaction Hash Block From To
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
MathHelper

Compiler Version
v0.8.24+commit.e11b9ed9

Optimization Enabled:
Yes with 200 runs

Other Settings:
paris EvmVersion

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 1 : MathHelper.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

library MathHelper {
    /// @dev default decimals for now to calculate price ratio
    uint8 internal constant DEFAULT_DECIMAL = 18;

    /**
     * @dev calculate the amount of ra and ct needed to provide AMM with liquidity in respect to the price ratio
     *
     * @param amountra the total amount of liquidity user provide(e.g 2 ra)
     * @param priceRatio the price ratio of the pair, should be retrieved from the AMM as sqrtx96 and be converted to ratio
     * @return ra the amount of ra needed to provide AMM with liquidity
     * @return ct the amount of ct needed to provide AMM with liquidity, also the amount of how much ra should be converted to ct
     */
    function calculateAmounts(
        uint256 amountra,
        uint256 priceRatio
    ) external pure returns (uint256 ra, uint256 ct) {
        ct = (amountra * 1e18) / (priceRatio + 1e18);
        ra = (amountra - ct);

        assert((ct + ra) == amountra);
    }

    // TODO: add support for 2 different decimals token? but since we're
    // using ra and ct, which both has 18 decimals so will default into that one for now
    /// @dev should only pass ERC20.decimals() onto the decimal field
    /// @dev will output price ratio in 18 decimal precision.
    function calculatePriceRatio(
        uint160 sqrtPriceX96,
        uint8 decimal
    ) external pure returns (uint256) {
        uint256 numerator1 = uint256(sqrtPriceX96) * uint256(sqrtPriceX96);
        uint256 numerator2 = 10 ** decimal;
        uint256 denominator = 1 << 192;

        return (numerator1 * numerator2) / denominator;
    }

    /**
     *  @dev calculate the base withdrawal amount of ra and pa in respect of given amount
     * @param totalLv the total amount of lv in the pool
     * @param accruedRa the total amount of ra accrued in the pool
     * @param accruedPa the total amount of pa accrued in the pool
     * @param amount the amount of lv user want to withdraw
     * @return ra the amount of ra user will receive
     * @return pa the amount of pa user will receive
     */
    function calculateBaseWithdrawal(
        uint256 totalLv,
        uint256 accruedRa,
        uint256 accruedPa,
        uint256 amount
    ) external pure returns (uint256 ra, uint256 pa) {
        ra = (amount * ((accruedRa * 1e18) / totalLv)) / 1e18;
        pa = (amount * ((accruedPa * 1e18) / totalLv)) / 1e18;
    }

    /**
     * calculate the early lv rate in respect to the amount given
     * @param lvRaBalance the total amount of ra in the lv
     * @param totalLv the total amount of lv in the pool
     * @param amount the amount of lv user want to withdraw
     */
    function calculateEarlyLvRate(
        uint256 lvRaBalance,
        uint256 totalLv,
        uint256 amount
    ) external pure returns (uint256 received) {
        received = (amount * ((lvRaBalance * 1e18) / totalLv)) / 1e18;
    }

    /**
     * @dev calculate the fee in respect to the amount given
     * @param fee1e8 the fee in 1e8
     * @param amount the amount of lv user want to withdraw
     */
    function calculatePrecentageFee(
        uint256 fee1e8,
        uint256 amount
    ) external pure returns (uint256 precentage) {
        precentage = (((amount * 1e18) * fee1e8) / (100 * 1e18)) / 1e18;
    }

    /**
     * @dev calcualte how much ct + ds user will receive based on the amount of the current exchange rate
     * @param amount  the amount of user  deposit
     * @param exchangeRate the current exchange rate between RA:(CT+DS)
     */
    function calculateDepositAmountWithExchangeRate(
        uint256 amount,
        uint256 exchangeRate
    ) external pure returns (uint256 _amount) {
        _amount = (amount * 1e18) / exchangeRate;
    }

    /**
     * @dev caclulcate how much ra user will receive based on an exchange rate
     * @param amount the amount of ds user want to redeem
     * @param exchangeRate the current exchange rate between RA:(CT+DS)
     */
    function calculateRedeemAmountWithExchangeRate(
        uint256 amount,
        uint256 exchangeRate
    ) external pure returns (uint256 _amount) {
        _amount = (amount * exchangeRate) / 1e18;
    }

    // TODO : unit test this, just move here from psm
    /// @notice calculate the accrued PA & RA
    /// @dev this function follow below equation :
    /// '#' refers to the total circulation supply of that token.
    /// '&' refers to the total amount of token in the PSM.
    ///
    /// amount * (&PA or &RA/#CT)
    function calculateAccrued(
        uint256 amount,
        uint256 available,
        uint256 totalCtIssued
    ) internal pure returns (uint256 accrued) {
        accrued = (amount * ((available * 1e18) / totalCtIssued)) / 1e18;
    }

    function separateLiquidity(
        uint256 totalAmount,
        uint256 totalLvIssued,
        uint256 totalLvWithdrawn
    )
        external
        pure
        returns (
            uint256 attributedWithdrawal,
            uint256 attributedAmm,
            uint256 ratePerLv
        )
    {
        // with 1e18 precision
        ratePerLv = ((totalAmount * 1e18) / totalLvIssued);
        attributedWithdrawal = (ratePerLv * totalLvWithdrawn) / 1e18;
        attributedAmm = totalAmount - attributedWithdrawal;

        assert((attributedWithdrawal + attributedAmm) == totalAmount);
    }
}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "evmVersion": "paris",
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  }
}

Contract ABI

[{"inputs":[{"internalType":"uint256","name":"amountra","type":"uint256"},{"internalType":"uint256","name":"priceRatio","type":"uint256"}],"name":"calculateAmounts","outputs":[{"internalType":"uint256","name":"ra","type":"uint256"},{"internalType":"uint256","name":"ct","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"totalLv","type":"uint256"},{"internalType":"uint256","name":"accruedRa","type":"uint256"},{"internalType":"uint256","name":"accruedPa","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"calculateBaseWithdrawal","outputs":[{"internalType":"uint256","name":"ra","type":"uint256"},{"internalType":"uint256","name":"pa","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"exchangeRate","type":"uint256"}],"name":"calculateDepositAmountWithExchangeRate","outputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"lvRaBalance","type":"uint256"},{"internalType":"uint256","name":"totalLv","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"calculateEarlyLvRate","outputs":[{"internalType":"uint256","name":"received","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"fee1e8","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"calculatePrecentageFee","outputs":[{"internalType":"uint256","name":"precentage","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint160","name":"sqrtPriceX96","type":"uint160"},{"internalType":"uint8","name":"decimal","type":"uint8"}],"name":"calculatePriceRatio","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"exchangeRate","type":"uint256"}],"name":"calculateRedeemAmountWithExchangeRate","outputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"totalAmount","type":"uint256"},{"internalType":"uint256","name":"totalLvIssued","type":"uint256"},{"internalType":"uint256","name":"totalLvWithdrawn","type":"uint256"}],"name":"separateLiquidity","outputs":[{"internalType":"uint256","name":"attributedWithdrawal","type":"uint256"},{"internalType":"uint256","name":"attributedAmm","type":"uint256"},{"internalType":"uint256","name":"ratePerLv","type":"uint256"}],"stateMutability":"pure","type":"function"}]

61062a61003a600b82828239805160001a60731461002d57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600436106100925760003560e01c80638d3d803d116100655780638d3d803d14610126578063b5b4115f14610139578063f2a5e9701461014c578063ff65a2e11461015f57600080fd5b80630712af29146100975780630e042cec146100c45780633d6690db146100e55780637b7ddb3b14610113575b600080fd5b6100aa6100a53660046103ab565b610172565b604080519283526020830191909152015b60405180910390f35b6100d76100d23660046103dd565b6101e6565b6040519081526020016100bb565b6100f86100f33660046103ff565b61020c565b604080519384526020840192909252908201526060016100bb565b6100d76101213660046103ff565b61027b565b6100d76101343660046103dd565b6102b7565b6100d76101473660046103dd565b6102cc565b6100d761015a36600461042b565b610300565b6100aa61016d3660046103dd565b61034d565b600080670de0b6b3a764000086610189878361048c565b61019391906104a3565b61019d908561048c565b6101a791906104a3565b9150670de0b6b3a7640000866101bd868361048c565b6101c791906104a3565b6101d1908561048c565b6101db91906104a3565b905094509492505050565b6000816101fb84670de0b6b3a764000061048c565b61020591906104a3565b9392505050565b600080808461022387670de0b6b3a764000061048c565b61022d91906104a3565b9050670de0b6b3a7640000610242858361048c565b61024c91906104a3565b925061025883876104c5565b91508561026583856104d8565b14610272576102726104eb565b93509350939050565b6000670de0b6b3a764000083610291868361048c565b61029b91906104a3565b6102a5908461048c565b6102af91906104a3565b949350505050565b6000670de0b6b3a76400006101fb838561048c565b6000670de0b6b3a764000068056bc75e2d63100000846102ec858461048c565b6102f6919061048c565b6101fb91906104a3565b6000806103166001600160a01b0385168061048c565b9050600061032584600a6105e5565b9050600160c01b80610337838561048c565b61034191906104a3565b93505050505b92915050565b60008061036283670de0b6b3a76400006104d8565b61037485670de0b6b3a764000061048c565b61037e91906104a3565b905061038a81856104c5565b91508361039783836104d8565b146103a4576103a46104eb565b9250929050565b600080600080608085870312156103c157600080fd5b5050823594602084013594506040840135936060013592509050565b600080604083850312156103f057600080fd5b50508035926020909101359150565b60008060006060848603121561041457600080fd5b505081359360208301359350604090920135919050565b6000806040838503121561043e57600080fd5b82356001600160a01b038116811461045557600080fd5b9150602083013560ff8116811461046b57600080fd5b809150509250929050565b634e487b7160e01b600052601160045260246000fd5b808202811582820484141761034757610347610476565b6000826104c057634e487b7160e01b600052601260045260246000fd5b500490565b8181038181111561034757610347610476565b8082018082111561034757610347610476565b634e487b7160e01b600052600160045260246000fd5b600181815b8085111561053c57816000190482111561052257610522610476565b8085161561052f57918102915b93841c9390800290610506565b509250929050565b60008261055357506001610347565b8161056057506000610347565b816001811461057657600281146105805761059c565b6001915050610347565b60ff84111561059157610591610476565b50506001821b610347565b5060208310610133831016604e8410600b84101617156105bf575081810a610347565b6105c98383610501565b80600019048211156105dd576105dd610476565b029392505050565b600061020560ff84168361054456fea2646970667358221220d480eedac4e6d6e8eb1bc19061d55c68f3d70d8d5682d07623a369c62c631ba064736f6c63430008180033

Deployed Bytecode

0x731f64078e323c37b3aca709fb9146a73c3f3c461730146080604052600436106100925760003560e01c80638d3d803d116100655780638d3d803d14610126578063b5b4115f14610139578063f2a5e9701461014c578063ff65a2e11461015f57600080fd5b80630712af29146100975780630e042cec146100c45780633d6690db146100e55780637b7ddb3b14610113575b600080fd5b6100aa6100a53660046103ab565b610172565b604080519283526020830191909152015b60405180910390f35b6100d76100d23660046103dd565b6101e6565b6040519081526020016100bb565b6100f86100f33660046103ff565b61020c565b604080519384526020840192909252908201526060016100bb565b6100d76101213660046103ff565b61027b565b6100d76101343660046103dd565b6102b7565b6100d76101473660046103dd565b6102cc565b6100d761015a36600461042b565b610300565b6100aa61016d3660046103dd565b61034d565b600080670de0b6b3a764000086610189878361048c565b61019391906104a3565b61019d908561048c565b6101a791906104a3565b9150670de0b6b3a7640000866101bd868361048c565b6101c791906104a3565b6101d1908561048c565b6101db91906104a3565b905094509492505050565b6000816101fb84670de0b6b3a764000061048c565b61020591906104a3565b9392505050565b600080808461022387670de0b6b3a764000061048c565b61022d91906104a3565b9050670de0b6b3a7640000610242858361048c565b61024c91906104a3565b925061025883876104c5565b91508561026583856104d8565b14610272576102726104eb565b93509350939050565b6000670de0b6b3a764000083610291868361048c565b61029b91906104a3565b6102a5908461048c565b6102af91906104a3565b949350505050565b6000670de0b6b3a76400006101fb838561048c565b6000670de0b6b3a764000068056bc75e2d63100000846102ec858461048c565b6102f6919061048c565b6101fb91906104a3565b6000806103166001600160a01b0385168061048c565b9050600061032584600a6105e5565b9050600160c01b80610337838561048c565b61034191906104a3565b93505050505b92915050565b60008061036283670de0b6b3a76400006104d8565b61037485670de0b6b3a764000061048c565b61037e91906104a3565b905061038a81856104c5565b91508361039783836104d8565b146103a4576103a46104eb565b9250929050565b600080600080608085870312156103c157600080fd5b5050823594602084013594506040840135936060013592509050565b600080604083850312156103f057600080fd5b50508035926020909101359150565b60008060006060848603121561041457600080fd5b505081359360208301359350604090920135919050565b6000806040838503121561043e57600080fd5b82356001600160a01b038116811461045557600080fd5b9150602083013560ff8116811461046b57600080fd5b809150509250929050565b634e487b7160e01b600052601160045260246000fd5b808202811582820484141761034757610347610476565b6000826104c057634e487b7160e01b600052601260045260246000fd5b500490565b8181038181111561034757610347610476565b8082018082111561034757610347610476565b634e487b7160e01b600052600160045260246000fd5b600181815b8085111561053c57816000190482111561052257610522610476565b8085161561052f57918102915b93841c9390800290610506565b509250929050565b60008261055357506001610347565b8161056057506000610347565b816001811461057657600281146105805761059c565b6001915050610347565b60ff84111561059157610591610476565b50506001821b610347565b5060208310610133831016604e8410600b84101617156105bf575081810a610347565b6105c98383610501565b80600019048211156105dd576105dd610476565b029392505050565b600061020560ff84168361054456fea2646970667358221220d480eedac4e6d6e8eb1bc19061d55c68f3d70d8d5682d07623a369c62c631ba064736f6c63430008180033

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
[ Download: CSV Export  ]

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.