Skip to content

Commit

Permalink
Updated config file definition
Browse files Browse the repository at this point in the history
  • Loading branch information
mstrug committed Jan 9, 2025
1 parent 028b28a commit 5a6e1b6
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 20 deletions.
28 changes: 28 additions & 0 deletions config/example.okx.toml
Original file line number Diff line number Diff line change
@@ -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"
42 changes: 31 additions & 11 deletions src/infra/config/dex/okx/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<okx::OkxCredentialsConfig> 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()
Expand All @@ -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,
Expand Down
12 changes: 4 additions & 8 deletions src/infra/dex/okx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
2 changes: 1 addition & 1 deletion src/tests/okx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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'
",
))
}

0 comments on commit 5a6e1b6

Please sign in to comment.