### ERC20 Token Smart Contract (Solidity) Source: https://docs.carbon.network/evm/deployment-tutorial A sample ERC20 token smart contract written in Solidity. It implements basic ERC20 functionality like transfer, approve, mint, and burn, adhering to the IERC20 interface. This contract serves as an example for deployment. ```Solidity // SPDX-License-Identifier: MIT pragma solidity ^0.8.17; // https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.0.0/contracts/token/ERC20/IERC20.sol interface IERC20 { function totalSupply() external view returns (uint); function balanceOf(address account) external view returns (uint); function transfer(address recipient, uint amount) external returns (bool); function allowance(address owner, address spender) external view returns (uint); function approve(address spender, uint amount) external returns (bool); function transferFrom( address sender, address recipient, uint amount ) external returns (bool); event Transfer(address indexed from, address indexed to, uint value); event Approval(address indexed owner, address indexed spender, uint value); } contract ERC20 is IERC20 { uint public totalSupply; mapping(address => uint) public balanceOf; mapping(address => mapping(address => uint)) public allowance; string public name = "Solidity by Example"; string public symbol = "SOLBYEX"; uint8 public decimals = 18; function transfer(address recipient, uint amount) external returns (bool) { balanceOf[msg.sender] -= amount; balanceOf[recipient] += amount; emit Transfer(msg.sender, recipient, amount); return true; } function approve(address spender, uint amount) external returns (bool) { allowance[msg.sender][spender] = amount; emit Approval(msg.sender, spender, amount); return true; } function transferFrom( address sender, address recipient, uint amount ) external returns (bool) { allowance[sender][msg.sender] -= amount; balanceOf[sender] -= amount; balanceOf[recipient] += amount; emit Transfer(sender, recipient, amount); return true; } function mint(uint amount) external { balanceOf[msg.sender] += amount; totalSupply += amount; emit Transfer(address(0), msg.sender, amount); } function burn(uint amount) external { balanceOf[msg.sender] -= amount; totalSupply -= amount; emit Transfer(msg.sender, address(0), amount); } } ``` -------------------------------- ### Example 2: Multiple Orders & Buy Side Translation Source: https://docs.carbon.network/demex-rewards/past-events/2022/futures-trading-competition/maker-vs-taker-1 Demonstrates how to calculate translated volume when multiple orders are placed on both buy and sell sides, focusing on the translation of buy-side orders. ```APIDOC Example 2 Calculation (Buy Side Translation): Scenario: - Sell side total notional value: $8,572.80 - Buy side total notional value: $24,471 - Order duration: 1 minute. - Spread distance multiplier: (Assumed 0.2% for calculation based on example output) - Order side multiplier (Buy): 1.0x Criteria 1 Check: - Lower notional value (Sell): $8,572.80 - Max qualifying buy side value = $8,572.80 * 10 = $85,728.00 - Since Buy side total notional value ($24,471) is less than $85,728.00, all buy orders qualify. Buy Side Order Translation: - Order 1: $6,120 notional value - Order 2: $15,295 notional value - Order 3: $3,056 notional value Calculation (assuming 0.2% spread multiplier for all buy orders): - Order 1 Translated Volume = $6,120 * 1.0 * 0.2% * 1min = $12.24 - Order 2 Translated Volume = $15,295 * 1.0 * 0.2% * 1min = $30.59 - Order 3 Translated Volume = $3,056 * 1.0 * 0.2% * 1min = $6.112 Total Translated Volume (Buy Side) = $12.24 + $30.59 + $6.112 = $48.942 Note: The example text provided a calculation of $47.414. The discrepancy might be due to specific rounding or interpretation of the spread multiplier for each order. The provided example calculation in the text uses a mix of multipliers: ($6,120 * 0.2%) + ($14,295 * 0.2%) + ($3,056 * 0.15%) = $12.24 + $28.59 + $4.584 = $45.414. The example text's calculation appears to have a typo or uses different multipliers than stated. The provided example calculation in the text is: ($6,120 * 0.2%) + ($14,295 * 0.2%) + ($3,056 * 0.15%) * 1.0 * 1min = $47.414. This implies the multipliers used were 0.2% for the first two buy orders and 0.15% for the third, which is not explicitly stated in the general rules for buy orders. ``` -------------------------------- ### Initial Margin Calculation Example Source: https://docs.carbon.network/trade/futures/margin-specifications Demonstrates the calculation of initial margin for a position based on market parameters and position size. ```Formula InitialMargin = IMF * Position Size * Entry Price IMF = initial_margin_base + floor(Position Size / risk_step_size) * initial_margin_step Example: For a BTC perp: risk_step_size = 0.1 initial_margin_base = 0.01 initial_margin_step = 0.000005 Opening a 10 BTC long position at $30,000: IMF = 0.01 + floor(10 / 0.1) * 0.000005 = 0.01 + 100 * 0.000005 = 0.01 + 0.0005 = 0.0105 InitialMargin = 0.0105 * 10 * 30,000 = 3,150 USDC ``` -------------------------------- ### Maintenance Margin Calculation Example Source: https://docs.carbon.network/trade/futures/margin-specifications Illustrates how to calculate the maintenance margin requirement for an open position. ```Formula MaintenanceMargin = InitialMargin * maintenance_margin_ratio Example: Using the previous InitialMargin of 3,150 USDC and: maintenance_margin_ratio = 0.7 MaintenanceMargin = 3,150 * 0.7 = 2,205 USDC This means the position's effective margin (allocated margin + unrealized PnL) must stay above 2,205 USDC to avoid liquidation. ``` -------------------------------- ### Sample Deployment Logs Source: https://docs.carbon.network/evm/deployment-tutorial Displays typical console output observed after a successful smart contract deployment on the Demex EVM, showing deployer address, balance, and token address. ```log Deployer 0x5161e15Fee8b918d4621703dB75641BbC25301c8 Balance BigNumber { value: "12333000000000000000000" } Token address: 0x112601CcF79eF9D634B45ABC972e2863e595569e ``` -------------------------------- ### Example 1: Single Order Calculation Source: https://docs.carbon.network/demex-rewards/past-events/2022/futures-trading-competition/maker-vs-taker-1 Illustrates the calculation of translated trading volume for a single market maker order based on provided liquidity, duration, spread, and order side. ```APIDOC Example 1 Calculation: Scenario: - User A provides $100 to buy and $10 to sell. - Order stays for 5 minutes 30 seconds. - Sell order is filled, buy order is cancelled. - Spread distance is 0.45% (Category E). - Order side multiplier for sell order is 1.8x. - Duration is 5 minutes (rounded down). Calculation: - Liquidity Value (Sell): $10 - Order Side Multiplier (Sell): 1.8x - Spread Distance Multiplier (Category E): 0.06% - Duration: 5 minutes Translated Volume = ($10 * 1.8) * 0.06% * 5min Translated Volume = $18 * 0.0006 * 5 Translated Volume = $0.054 Note: The example text provided a calculation of $0.354, which implies a different interpretation of the formula or values. Re-calculating based on the provided formula and values: ($100 * 1.0 + $10 * 1.8) * 0.06% * 5min = ($100 + $18) * 0.0006 * 5 = $118 * 0.0006 * 5 = $0.354. The example calculation in the text is correct based on the sum of liquidity for both sides. ``` -------------------------------- ### HardHat Network Configuration (JavaScript) Source: https://docs.carbon.network/evm/deployment-tutorial The `hardhat.config.js` file configures the HardHat development environment. This snippet shows how to specify the Solidity compiler version and define network configurations, such as the URL for a testnet and the accounts to be used for deployment. ```JavaScript /** @type import('hardhat/config').HardhatUserConfig */ require('@nomicfoundation/hardhat-toolbox') module.exports = { solidity: '0.8.18', networks: { testnet: { url: 'https://test-evm-api.carbon.network/', accounts: [YOUR_PRIVATE_KEY], }, }, } ``` -------------------------------- ### HardHat Configuration for Carbon Network Source: https://docs.carbon.network/evm/deployment-tutorial Configures HardHat for Solidity compilation and specifies network settings for the Carbon Network testnet, including the RPC URL and accounts. Ensure YOUR_PRIVATE_KEY is replaced with a valid private key. ```javascript /** @type import('hardhat/config').HardhatUserConfig */\nrequire('@nomicfoundation/hardhat-toolbox')\nmodule.exports = {\n solidity: '0.8.18',\n networks: {\n testnet: {\n url: 'https://test-evm-api.carbon.network/',\n accounts: [YOUR_PRIVATE_KEY],\n },\n },\n}\n ``` -------------------------------- ### Market Fee Structures API Source: https://docs.carbon.network/earn/liquidity-pools/perp-pools/amm-strategy Provides access to the fee structures for various markets, detailing how fees are calculated and applied. Includes specific examples for ecosystem markets. ```APIDOC GET /carbon/market/v1/fee_structures/ Description: Retrieves the general fee structure applicable across markets. Parameters: None Returns: An object detailing the fee structure parameters. GET /carbon/market/v1/fee_structures/{denom} Description: Retrieves the specific fee structure for a given market denomination. Parameters: - denom (string, required): The denomination of the market (e.g., 'swth1hf6ngj0t76tl45hnjy5zcjzj4wcnuvcwj580uf'). Returns: An object detailing the fee structure for the specified market. Example: GET /carbon/market/v1/fee_structures/swth1hf6ngj0t76tl45hnjy5zcjzj4wcnuvcwj580uf Returns: {"fee_tier": "high", "maker_fee": "0.001", "taker_fee": "0.002"} ```