diff --git a/filepathSlugs.json b/filepathSlugs.json index 1971babd..0d7e9965 100644 --- a/filepathSlugs.json +++ b/filepathSlugs.json @@ -2027,6 +2027,7 @@ "example-without-balances", "balance-infos", "derivation-method", + "event-stream-config", "numeric-formats-value", "fee-info", "examples", @@ -3800,6 +3801,7 @@ "utxo-coin-example", "antara-smartchain-example", "1c-evm-like-tokens-eth-erc-20-matic-plg-20-bnb-bep-20", + "gas-limit-options", "erc-20-token-example", "bep-20-token-example", "1d-qrc-20-tokens", diff --git a/src/pages/komodo-defi-framework/api/common_structures/index.mdx b/src/pages/komodo-defi-framework/api/common_structures/index.mdx index 22ddff47..0280395d 100644 --- a/src/pages/komodo-defi-framework/api/common_structures/index.mdx +++ b/src/pages/komodo-defi-framework/api/common_structures/index.mdx @@ -120,6 +120,46 @@ Where the value indicates: ``` +### EventStreamConfig + +The `EventStreamConfig` object defines which events will be streamed to the client: + +| Parameter | Type | Description | +| ------------------------------ | ------ | -------------------------------------------------------------------------------------- | +| access\_control\_allow\_origin | string | Defines CORS whitelist. Use "\*" to allow fromi any origin. | +| active\_events | object | Events to be streamed to the client, along with configuration defineing frequency etc. | +| worker\_path | string | WASM only. Path to a custom `worker.js` file. | + +Active events are defined as follows: + +* NETWORK: Network status changes. Requires `stream_interval_seconds` configuration. +* HEARTBEAT: Allows clients to easily determine whether channels are functioning. Requires `stream_interval_seconds` configuration. +* COIN\_BALANCE: Balance changes. Does not require `stream_interval_seconds` configuration, as the event is triggered by the balance change. + + + The `COIN_BALANCE` event may not be available for all coins or tokens. + + +An example of the event stream output can then be viewed in [https://github.com/KomodoPlatform/komodo-defi-framework/blob/main/examples/sse/index.html](https://github.com/KomodoPlatform/komodo-defi-framework/blob/main/examples/sse/index.html) + + + ```json + "event_stream_configuration": { + "access_control_allow_origin": "*", + "active_events": { + "NETWORK": { + "stream_interval_seconds": 1.5, + }, + "COIN_BALANCE": {}, + "HEATBEAT": { + "stream_interval_seconds": 2.4, + } + }, + "worker_path": "index.js" + } + ``` + + ### NumericFormatsValue The `NumericFormatsValue` returns a price or amount in three different formats: `fraction`, `rational`, and `decimal`. diff --git a/src/pages/komodo-defi-framework/api/v20/start_simple_market_maker_bot/index.mdx b/src/pages/komodo-defi-framework/api/v20/start_simple_market_maker_bot/index.mdx index 405e04d6..ba0e4203 100644 --- a/src/pages/komodo-defi-framework/api/v20/start_simple_market_maker_bot/index.mdx +++ b/src/pages/komodo-defi-framework/api/v20/start_simple_market_maker_bot/index.mdx @@ -1,5 +1,7 @@ -export const title = "Komodo DeFi Framework Method: Start Simple Market Maker Bot"; -export const description = "The Komodo DeFi Framework API allows for simple bot trading via the start_simple_market_maker_bot method."; +export const title = + "Komodo DeFi Framework Method: Start Simple Market Maker Bot"; +export const description = + "The Komodo DeFi Framework API allows for simple bot trading via the start_simple_market_maker_bot method."; # start\_simple\_market\_maker\_bot @@ -11,29 +13,29 @@ For convenience, an online [tool for generating configs](https://stats.kmd.io/at ## Arguments -| Structure | Type | Description | -| -------------------------------------------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| price\_url | string | Link to a price service API | -| bot\_refresh\_rate | float | Bot loop interval in seconds (optional, 30 sec default) | -| cfg.name | string | The name assigned to this configuration (e.g. the pair being configured) | -| cfg.name.base | string | Ticker of the coin you wish to sell | -| cfg.name.rel | string | Ticker of the coin you wish to buy | -| cfg.name.max | boolean | Set to `true` if you would like to trade your whole balance (optional) | -| cfg.name.max\_volume.percentage | string | Percentage of balance to trade (optional; can not use at same time as `max_volume.usd`; if greater than 1.0 `max=true` is implied) | -| cfg.name.max\_volume.usd | string | Maximum USD trade volume value to trade (optional; can not use at same time as `max_volume.percentage`; if greater than full balance `max=true` is implied) | -| cfg.name.min\_volume.percentage | string | Minimum percentage of balance to accept in trade (optional, can not use at same time as `min_volume.usd`) | -| cfg.name.min\_volume.usd | float | Minimum USD trade volume of trades accepted for order (optional, can not use at same time as `min_volume.percentage`) | -| cfg.name.min\_base\_price | float | Minimum USD price of base coin to accept in trade (optional) | -| cfg.name.min\_rel\_price | float | Minimum USD price of rel coin to accept in trade (optional) | -| cfg.name.min\_pair\_price | float | Minimum USD price of pair (base/rel) to accept in trade (optional) | -| cfg.name.spread\*\* | string | Target price in relation to prices API value | -| cfg.name.base\_confs | integer | number of required blockchain confirmations for base coin atomic swap transaction; default to base coin configuration if not set | -| cfg.name.base\_nota | boolean | whether dPoW notarization is required for base coin atomic swap transaction; default to base coin configuration if not set | -| cfg.name.rel\_confs | integer | number of required blockchain confirmations for rel coin atomic swap transaction; default to rel coin configuration if not set | -| cfg.name.rel\_nota | boolean | whether dPoW notarization is required for rel coin atomic swap transaction; default to base coin configuration if not set | -| cfg.name.enable | boolean | Bot will ignore this config entry if set to false | -| cfg.name.price\_elapsed\_validity | float | Will cancel current orders for this pair and not submit a new order if last price update time has been longer than this value in seconds (optional; defaults to 5 minutes) | -| cfg.name.check\_last\_bidirectional\_trade\_thresh\_hold | boolean | Will readjust the calculated cex price if a precedent trade exists for the pair (or reversed pair), applied via a [VWAP logic](https://www.investopedia.com/terms/v/vwap.asp) (optional; defaults to false) | +| Structure | Type | Description | +| -------------------------------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| price\_urls | list | Optional. A list of URLs serving price data in JSON format. During each update loop, price data will be sourced from the first working URL in the list. If not defined, a [default list](https://github.com/KomodoPlatform/komodo-defi-framework/blob/main/mm2src/coins/lp_price.rs#L13) will be used. | +| bot\_refresh\_rate | float | Bot loop interval in seconds (optional, 30 sec default) | +| cfg.name | string | The name assigned to this configuration (e.g. the pair being configured) | +| cfg.name.base | string | Ticker of the coin you wish to sell | +| cfg.name.rel | string | Ticker of the coin you wish to buy | +| cfg.name.max | boolean | Set to `true` if you would like to trade your whole balance (optional) | +| cfg.name.max\_volume.percentage | string | Percentage of balance to trade (optional; can not use at same time as `max_volume.usd`; if greater than 1.0 `max=true` is implied) | +| cfg.name.max\_volume.usd | string | Maximum USD trade volume value to trade (optional; can not use at same time as `max_volume.percentage`; if greater than full balance `max=true` is implied) | +| cfg.name.min\_volume.percentage | string | Minimum percentage of balance to accept in trade (optional, can not use at same time as `min_volume.usd`) | +| cfg.name.min\_volume.usd | float | Minimum USD trade volume of trades accepted for order (optional, can not use at same time as `min_volume.percentage`) | +| cfg.name.min\_base\_price | float | Minimum USD price of base coin to accept in trade (optional) | +| cfg.name.min\_rel\_price | float | Minimum USD price of rel coin to accept in trade (optional) | +| cfg.name.min\_pair\_price | float | Minimum USD price of pair (base/rel) to accept in trade (optional) | +| cfg.name.spread\*\* | string | Target price in relation to prices API value | +| cfg.name.base\_confs | integer | number of required blockchain confirmations for base coin atomic swap transaction; default to base coin configuration if not set | +| cfg.name.base\_nota | boolean | whether dPoW notarization is required for base coin atomic swap transaction; default to base coin configuration if not set | +| cfg.name.rel\_confs | integer | number of required blockchain confirmations for rel coin atomic swap transaction; default to rel coin configuration if not set | +| cfg.name.rel\_nota | boolean | whether dPoW notarization is required for rel coin atomic swap transaction; default to base coin configuration if not set | +| cfg.name.enable | boolean | Bot will ignore this config entry if set to false | +| cfg.name.price\_elapsed\_validity | float | Will cancel current orders for this pair and not submit a new order if last price update time has been longer than this value in seconds (optional; defaults to 5 minutes) | +| cfg.name.check\_last\_bidirectional\_trade\_thresh\_hold | boolean | Will readjust the calculated cex price if a precedent trade exists for the pair (or reversed pair), applied via a [VWAP logic](https://www.investopedia.com/terms/v/vwap.asp) (optional; defaults to false) | * Percentage values are within the range of 0-1, such that 0.25 = 25% * For spread, a value of 1.05 equates to 5% over the value returned from the prices API url. @@ -81,7 +83,11 @@ The third config tells the bot to: "mmrpc": "2.0", "method": "start_simple_market_maker_bot", "params": { - "price_url": "https://prices.komodo.earth/api/v2/tickers?expire_at=600", + "price_urls": [ + "https://prices.komodo.live:1313/api/v2/tickers?expire_at=600", + "https://prices.komodo.earth/api/v2/tickers?expire_at=600", + "https://prices.komodian.info/api/v2/tickers?expire_at=600" + ], "bot_refresh_rate": 60, "cfg": { "DASH/KMD": { diff --git a/src/pages/komodo-defi-framework/setup/configure-mm2-json/index.mdx b/src/pages/komodo-defi-framework/setup/configure-mm2-json/index.mdx index 5efa43f7..90c9c8c6 100644 --- a/src/pages/komodo-defi-framework/setup/configure-mm2-json/index.mdx +++ b/src/pages/komodo-defi-framework/setup/configure-mm2-json/index.mdx @@ -12,26 +12,27 @@ When running the Komodo DeFi API via commandline with the `mm2` binary, some bas ### Configuration Parameters -| Parameter | Type | Description | -| ----------------------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| gui | string | Information to identify which app, tool or product is using the API, e.g. `KomodoWallet iOS 1.0.1`. Helps developers identify if an issue is related to specific builds or operating systems etc. | -| netid | integer | Nework ID number, telling the Komodo DeFi Framework which network to join. 8762 is the current main network, though alternative netids can be used for testing or "private" trades as long as seed nodes exist to support it. | -| passphrase | string | Your passphrase; this is the source of each of your coins private keys. [**KEEP IT SAFE!**](https://www.youtube.com/watch?v=WFpxVbTqhB8) | -| rpc\_password | string | For RPC requests that need authentication, this will need to match the `userpass` value in the request body. | -| allow\_weak\_password | boolean | Optional, defaults to `false`. If `true`, will allow low entropy rpc\_password. If `false` rpc\_password must not have 3 of the same characters in a row, must be between 8-32 characters in length, must contain at least one of each of the following: numeric, uppercase, lowercase, special character (e.g. !#$\*). It also can not contain the word "password", or the chars `<`, `>`, or `&`. | -| dbdir | string | Optional, defaults to a subfolder named `DB` in the path of your `mm2` binary. This path will store the Komodo DeFi-API database data. | -| rpcip | string | Optional, defaults to `127.0.0.1`. IP address to bind to for RPC server. | -| rpcport | integer | Optional, defaults to `7783`. Port to use for RPC communication. | -| rpc\_local\_only | boolean | Optional, defaults to `true`. If `false` the Komodo DeFi Framework API will allow rpc methods sent from external IP addresses. **Warning:** Only use this if you know what you are doing, and have put the appropriate security measures in place. | -| i\_am\_seed | boolean | Optional, defaults to `false`. Runs Komodo DeFi Framework API as a seed node mode (acting as a relay for Komodo DeFi Framework API clients). Use of this mode is not reccomended on the main network (8762) as it could result in a pubkey ban if non-compliant. On alternative testing or private networks, at least one seed node is required to relay information to other Komodo DeFi Framework API clients using the same netID. | -| seednodes | list of strings | Optional. If operating on a test or private netID, the IP address of at least one seed node is required (on the main network, these are already hardcoded) | -| enable\_hd | boolean | Optional. If `true`, the Komodo DeFi-API will work in only the [HD mode](/komodo-defi-framework/api/v20-dev/hd_wallets_overview/), and coins will need to have a coin derivation path entry in the `coins` file for activation. Defaults to `false`. | -| message\_service\_cfg | object | Optional. This data is used to configure [Telegram](https://telegram.org/) messenger alerts for swap events when running using the [makerbot functionality](/komodo-defi-framework/api/v20/start_simple_market_maker_bot/). For more information check out the [telegram alerts guide](/komodo-defi-framework/api/v20/telegram_alerts/) | -| metrics | integer | Optional, defaults to `300`. The interval in seconds which metrics are logged. Set to `0` to disable metrics. | -| prometheusport | integer | Optional. Only used if you are logging metrics in [Prometheus](https://prometheus.io/) and [Grafana](https://grafana.com/). For more information check out the [Komodo DeFi metrics guide](/komodo-defi-framework/tutorials/api-metrics/) | -| prometheus\_credentials | integer | Optional. Only used if you are logging metrics in [Prometheus](https://prometheus.io/) and [Grafana](https://grafana.com/) with authentication. For more information check out the [Komodo DeFi metrics guide](/komodo-defi-framework/tutorials/api-metrics/) | -| https | boolean | Optional. Only used with wss. Defaults to `false`, set to `true` to allow TLS/SSL enabled RPC (e.g. remote queries to a domain with a valid SSL certificate). | -| wss\_certs | object | Optional. Contains fields for `server_priv_key` and `certificate` to allow RPC or P2P communications over TLS/SSL. | +| Parameter | Type | Description | +| ---------------------------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| gui | string | Information to identify which app, tool or product is using the API, e.g. `KomodoWallet iOS 1.0.1`. Helps developers identify if an issue is related to specific builds or operating systems etc. | +| netid | integer | Nework ID number, telling the Komodo DeFi Framework which network to join. 8762 is the current main network, though alternative netids can be used for testing or "private" trades as long as seed nodes exist to support it. | +| passphrase | string | Your passphrase; this is the source of each of your coins private keys. [**KEEP IT SAFE!**](https://www.youtube.com/watch?v=WFpxVbTqhB8) | +| rpc\_password | string | For RPC requests that need authentication, this will need to match the `userpass` value in the request body. | +| allow\_weak\_password | boolean | Optional, defaults to `false`. If `true`, will allow low entropy rpc\_password. If `false` rpc\_password must not have 3 of the same characters in a row, must be between 8-32 characters in length, must contain at least one of each of the following: numeric, uppercase, lowercase, special character (e.g. !#$\*). It also can not contain the word "password", or the chars `<`, `>`, or `&`. | +| dbdir | string | Optional, defaults to a subfolder named `DB` in the path of your `mm2` binary. This path will store the Komodo DeFi-API database data. | +| rpcip | string | Optional, defaults to `127.0.0.1`. IP address to bind to for RPC server. | +| rpcport | integer | Optional, defaults to `7783`. Port to use for RPC communication. | +| rpc\_local\_only | boolean | Optional, defaults to `true`. If `false` the Komodo DeFi Framework API will allow rpc methods sent from external IP addresses. **Warning:** Only use this if you know what you are doing, and have put the appropriate security measures in place. | +| i\_am\_seed | boolean | Optional, defaults to `false`. Runs Komodo DeFi Framework API as a seed node mode (acting as a relay for Komodo DeFi Framework API clients). Use of this mode is not reccomended on the main network (8762) as it could result in a pubkey ban if non-compliant. On alternative testing or private networks, at least one seed node is required to relay information to other Komodo DeFi Framework API clients using the same netID. | +| seednodes | list of strings | Optional. If operating on a test or private netID, the IP address of at least one seed node is required (on the main network, these are already hardcoded) | +| enable\_hd | boolean | Optional. If `true`, the Komodo DeFi-API will work in only the [HD mode](/komodo-defi-framework/api/v20-dev/hd_wallets_overview/), and coins will need to have a coin derivation path entry in the `coins` file for activation. Defaults to `false`. | +| message\_service\_cfg | object | Optional. This data is used to configure [Telegram](https://telegram.org/) messenger alerts for swap events when running using the [makerbot functionality](/komodo-defi-framework/api/v20/start_simple_market_maker_bot/). For more information check out the [telegram alerts guide](/komodo-defi-framework/api/v20/telegram_alerts/) | +| metrics | integer | Optional, defaults to `300`. The interval in seconds which metrics are logged. Set to `0` to disable metrics. | +| prometheusport | integer | Optional. Only used if you are logging metrics in [Prometheus](https://prometheus.io/) and [Grafana](https://grafana.com/). For more information check out the [Komodo DeFi metrics guide](/komodo-defi-framework/tutorials/api-metrics/) | +| prometheus\_credentials | integer | Optional. Only used if you are logging metrics in [Prometheus](https://prometheus.io/) and [Grafana](https://grafana.com/) with authentication. For more information check out the [Komodo DeFi metrics guide](/komodo-defi-framework/tutorials/api-metrics/) | +| https | boolean | Optional. Only used with wss. Defaults to `false`, set to `true` to allow TLS/SSL enabled RPC (e.g. remote queries to a domain with a valid SSL certificate). | +| wss\_certs | object | Optional. Contains fields for `server_priv_key` and `certificate` to allow RPC or P2P communications over TLS/SSL. | +| event\_stream\_configuration | object | Optional, a standard [EventStreamConfig](/komodo-defi-framework/api/v20/#derivation-method) object. Configuration for subscribing to events. | #### Example (allowing weak password): diff --git a/src/pages/komodo-defi-framework/tutorials/listing-a-new-coin/index.mdx b/src/pages/komodo-defi-framework/tutorials/listing-a-new-coin/index.mdx index 1263f976..554d85db 100644 --- a/src/pages/komodo-defi-framework/tutorials/listing-a-new-coin/index.mdx +++ b/src/pages/komodo-defi-framework/tutorials/listing-a-new-coin/index.mdx @@ -125,13 +125,28 @@ The token's contract **must** have `approve` and `transferFrom` methods. Additio * Protocol `"type"` field: `"ETH"` or `"ERC20"` * Protocol `"protocol_data"` field (ERC20 only): `"platform"` - `"ETH"`, `"ETC"` or other Ethereum forks. `"contract_address"` - ERC20 token [checksummed](https://coincodex.com/article/2078/ethereum-address-checksum-explained/) smart contract address. -| Parameter | Type | Description | -| ----------------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| chain\_id | integer | To find the EVM chain ID, see [Chainlist](https://chainlist.org/) | -| protocol.type | string | Platform / protocol - e.g `ETH` for Ethereum, `ERC20` for ERC20 tokens on the Ethereum network | -| protocol.protocol\_data | object | Required for tokens only. | -| protocol.protocol\_data.platform | string | The parent coin of the token's platform - e.g `MATIC` for PLG20 tokens | -| protocol.protocol\_data.contract\_address | string | **Must be mixed case** The indentifying hex string for the token's contract. Can be found on sites like [EthScan](https://etherscan.io/), [BscScan](https://bscscan.com/) & [PolygonScan](https://polygonscan.com/) | +| Parameter | Type | Description | +| ----------------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| chain\_id | integer | To find the EVM chain ID, see [Chainlist](https://chainlist.org/) | +| gas\_limit | object | Optional, required for tokens only. Defines more precise gas prices for swap or transaction operations. Some tokens are called over proxy contracts which often require more gas, though users may be able to choose higher/lower values than the default where required. See the `Gas Limit Options` table below for more information. | +| protocol.type | string | Platform / protocol - e.g `ETH` for Ethereum, `ERC20` for ERC20 tokens on the Ethereum network | +| protocol.protocol\_data | object | Required for tokens only. | +| protocol.protocol\_data.platform | string | The parent coin of the token's platform - e.g `MATIC` for PLG20 tokens | +| protocol.protocol\_data.contract\_address | string | **Must be mixed case** The identifying hex string for the token's contract. Can be found on sites like [EthScan](https://etherscan.io/), [BscScan](https://bscscan.com/) & [PolygonScan](https://polygonscan.com/) | + +### Gas Limit Options + +| Parameter | Type | Description | +| ---------------------- | ------- | ------------------------------------------------------- | +| eth\_send\_coins | integer | Gas limit for sending coins. | +| eth\_send\_erc20 | integer | Gas limit for sending ERC20 tokens. | +| eth\_payment | integer | Gas limit for swap payment tx with coins. | +| erc20\_payment | integer | Gas limit for swap payment tx with ERC20 tokens. | +| eth\_receiver\_spend | integer | Gas limit for swap receiver spend tx with coins. | +| erc20\_receiver\_spend | integer | Gas limit for swap receiver spend tx with ERC20 tokens. | +| eth\_sender\_refund | integer | Gas limit for swap refund tx with coins. | +| erc20\_sender\_refund | integer | Gas limit for swap refund tx with with ERC20 tokens. | +| eth\_max\_trade\_gas | integer | Gas limit for other operations. | ### ERC20 token example @@ -152,6 +167,17 @@ The token's contract **must** have `approve` and `transferFrom` methods. Additio "platform": "ETH", "contract_address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" } + }, + "gas_limit": { + "eth_send_coins": 21000, + "eth_send_erc20": 65000, + "eth_payment": 75000, + "erc20_payment": 120000, + "eth_receiver_spend": 55000, + "erc20_receiver_spend": 130000, + "eth_sender_refund": 110000, + "erc20_sender_refund": 110000, + "eth_max_trade_gas": 150000 } } ```