KomodoPlatform / komodo-docs-mdx

Komodo Platform Docs
https://komodoplatform.com/en/docs/
2 stars 8 forks source link

EVM custom tokens import #385

Open shamardy opened 1 week ago

shamardy commented 1 week ago

KDF PR: https://github.com/KomodoPlatform/komodo-defi-framework/pull/2141

Adds support for enabling custom EVM (ERC20, PLG20, etc..) tokens without requiring them to be in the coins config. This allows users to interact with any ERC20 token by providing the contract address.

New RPC: get_token_info

Retrieves token information (symbol/ticker, decimals) from the contract. This RPC should be used before enabling a token to:

Request

{
  "userpass": "**********",
  "mmrpc": "2.0",
  "method": "get_token_info",
  "params": {
    // Protocol information required for custom tokens, same format as protocol info used in config
    "protocol": {
      "type": "ERC20",
      "protocol_data": {
        "platform": "ETH",
        "contract_address": "0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9"
      }
    }
  }
}

Response (Success)

{
  "mmrpc": "2.0",
  "result": {
    "type": "ERC20",
    "info": {
      "symbol": "QTC", // The ticker to populate for the GUI user.
      "decimals": 8 // The decimals to populate for GUI user.
    }
  }
}

Response (Success) - Case for if the same contract address is used for a coin in configuration

{
  "mmrpc": "2.0",
  "result": {
    "config_ticker": "ERC20DEV", // This will show the ticker used in config, we should populate this to the user and use it to enable the token from config in the activation request. If we can show the user the contract ticker it would be good as well.
    "type": "ERC20",
    "info": {
      "symbol": "QTC",
      "decimals": 8
    }
  }
}

Updated RPC: task::enable_erc20::init/enable_erc20

Both should work for custom tokens, but we should be moving to task manager ones for trezor support.

Request (Enable a custom token)

{
  "userpass": "**********",
  "mmrpc": "2.0",
  "method": "task::enable_erc20::init",
  "params": {
    "ticker": "QTC", // 
    // New Field: protocol field required for custom tokens, same format as protocol info used in config
    "protocol": {
      "type": "ERC20",
      "protocol_data": {
        "platform": "ETH",
        "contract_address": "0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9"
      }
    }
    // Other fields are the same
}

Success Response should be the same as response for non custom tokens but should be shown as wallet only in GUIs

Response (Error) - Token with this contract is already activated

{
  "error_type": "CustomTokenError",
  "error_data": {
    "TokenWithSameContractAlreadyActivated": {
      "ticker": "QTC",
      "contract_address": "0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9"
    }
  }
}

This error indicates the contract is already activated with ticker "QTC".

Response (Error) - Token with this contract is in coin config

{
  "error_type": "CustomTokenError",
  "error_data": {
    "DuplicateContractInConfig": {
      "ticker_in_config": "ERC20DEV"
    }
  }
}

This error indicates the token should be enabled using the config ticker "ERC20DEV".

Important notes: