diff --git a/config/example.okx.toml b/config/example.okx.toml new file mode 100644 index 0000000..e9b866e --- /dev/null +++ b/config/example.okx.toml @@ -0,0 +1,28 @@ +node-url = "http://localhost:8545" + +[dex] +# See here how to get a free key: https://0x.org/docs/introduction/getting-started +api-key = "$YOUR_API_KEY" + +# Specify which chain to use, 1 for Ethereum. +# More info here: https://www.okx.com/en-au/web3/build/docs/waas/walletapi-resources-supported-networks +chain-id = "1" + +# Optionally specify a custom OKX Swap API endpoint +# endpoint = "https://www.okx.com/api/v5/dex/aggregator/swap" + +# OKX Project ID. Instruction on how to create project: +# https://www.okx.com/en-au/web3/build/docs/waas/introduction-to-developer-portal-interface#create-project +api-project-id = "$OKX_PROJECT_ID" + +# OKX API Key. Instruction on how to generate API key: +# https://www.okx.com/en-au/web3/build/docs/waas/introduction-to-developer-portal-interface#generate-api-keys +api-key = "$OKX_API_KEY" + +# OKX Secret key used for signing request. Instruction on how to get security token: +# https://www.okx.com/en-au/web3/build/docs/waas/introduction-to-developer-portal-interface#view-the-secret-key +api-secret-key = "$OKX_SECRET_KEY" + +# OKX Secret key passphrase. Instruction on how to get passhprase: +# https://www.okx.com/en-au/web3/build/docs/waas/introduction-to-developer-portal-interface#generate-api-keys +api-passphrase = "$OKX_PASSPHRASE" diff --git a/src/infra/config/dex/okx/file.rs b/src/infra/config/dex/okx/file.rs index d7a3f53..ad5b27f 100644 --- a/src/infra/config/dex/okx/file.rs +++ b/src/infra/config/dex/okx/file.rs @@ -13,7 +13,7 @@ use { #[derive(Deserialize)] #[serde(rename_all = "kebab-case", deny_unknown_fields)] struct Config { - /// The versioned URL endpoint for the 0x swap API. + /// The versioned URL endpoint for the OKX swap API. #[serde(default = "default_endpoint")] #[serde_as(as = "serde_with::DisplayFromStr")] endpoint: reqwest::Url, @@ -22,19 +22,44 @@ struct Config { #[serde_as(as = "serialize::ChainId")] chain_id: eth::ChainId, - /// OKX Project ID. + /// OKX API credentials + #[serde(flatten)] + okx_credentials: OkxCredentialsConfig, +} + +#[derive(Deserialize)] +#[serde(rename_all = "kebab-case", deny_unknown_fields)] +struct OkxCredentialsConfig { + /// OKX Project ID. Instruction on how to create project: + /// https://www.okx.com/en-au/web3/build/docs/waas/introduction-to-developer-portal-interface#create-project api_project_id: String, - /// OKX API Key. + /// OKX API Key. Instruction on how to generate API key: + /// https://www.okx.com/en-au/web3/build/docs/waas/introduction-to-developer-portal-interface#generate-api-keys api_key: String, - /// OKX Secret key used for signing request. + /// OKX Secret key used for signing request. Instruction on how to get + /// security token: https://www.okx.com/en-au/web3/build/docs/waas/introduction-to-developer-portal-interface#view-the-secret-key api_secret_key: String, - /// OKX Secret key passphrase. + /// OKX Secret key passphrase. Instruction on how + /// to get passhprase: https://www.okx.com/en-au/web3/build/docs/waas/introduction-to-developer-portal-interface#generate-api-keys api_passphrase: String, } +// Implementing Into<> is enough as opposite conversion will never be used. +#[allow(clippy::from_over_into)] +impl Into for OkxCredentialsConfig { + fn into(self) -> okx::OkxCredentialsConfig { + okx::OkxCredentialsConfig { + project_id: self.api_project_id, + api_key: self.api_key, + api_secret_key: self.api_secret_key, + api_passphrase: self.api_passphrase, + } + } +} + fn default_endpoint() -> reqwest::Url { "https://www.okx.com/api/v5/dex/aggregator/swap" .parse() @@ -53,12 +78,7 @@ pub async fn load(path: &Path) -> super::Config { okx: okx::Config { endpoint: config.endpoint, chain_id: config.chain_id, - okx_credentials: okx::OkxCredentialsConfig { - project_id: config.api_project_id, - api_key: config.api_key, - api_secret_key: config.api_secret_key, - api_passphrase: config.api_passphrase, - }, + okx_credentials: config.okx_credentials.into(), block_stream: base.block_stream.clone(), }, base, diff --git a/src/infra/dex/okx/mod.rs b/src/infra/dex/okx/mod.rs index 0d1bc04..dd9232a 100644 --- a/src/infra/dex/okx/mod.rs +++ b/src/infra/dex/okx/mod.rs @@ -37,20 +37,16 @@ pub struct Config { } pub struct OkxCredentialsConfig { - /// OKX project ID to use. Instruction on how to create project: - /// https://www.okx.com/en-au/web3/build/docs/waas/introduction-to-developer-portal-interface#create-project + /// OKX project ID to use. pub project_id: String, - /// OKX API key. Instruction on how to generate API key: - /// https://www.okx.com/en-au/web3/build/docs/waas/introduction-to-developer-portal-interface#generate-api-keys + /// OKX API key. pub api_key: String, - /// OKX API key additional security token. Instruction on how to get - /// security token: https://www.okx.com/en-au/web3/build/docs/waas/introduction-to-developer-portal-interface#view-the-secret-key + /// OKX API key additional security token. pub api_secret_key: String, - /// OKX API key passphrase used to encrypt secrety key. Instruction on how - /// to get passhprase: https://www.okx.com/en-au/web3/build/docs/waas/introduction-to-developer-portal-interface#generate-api-keys + /// OKX API key passphrase used to encrypt secrety key. pub api_passphrase: String, } diff --git a/src/tests/okx/mod.rs b/src/tests/okx/mod.rs index ff928ef..463c98f 100644 --- a/src/tests/okx/mod.rs +++ b/src/tests/okx/mod.rs @@ -14,7 +14,7 @@ endpoint = 'http://{solver_addr}' api-project-id = '1' api-key = '1234' api-secret-key = '1234567890123456' -api-passphrase ='pass' +api-passphrase = 'pass' ", )) }