From d32cb1f2292b99099ce3ddac9f8af7f518812a54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Ant=C3=B3nio?= Date: Mon, 23 Dec 2024 11:11:57 +0000 Subject: [PATCH] feat: change toma dependency to usdc (#300) * first commit * resolve unit tests --- README.md | 4 +-- atoma-sui/src/client.rs | 64 ++++++++++++++++++++--------------------- atoma-sui/src/config.rs | 18 ++++++------ config.example.toml | 2 +- 4 files changed, 44 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 546c4c1e..035f0565 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ service_bind_address = "0.0.0.0:3000" # Bind to all interfaces http_rpc_node_addr = "" atoma_db = "" atoma_package_id = "" -toma_package_id = "" +usdc_package_id = "" request_timeout = { secs = 300, nanos = 0 } max_concurrent_requests = 10 limit = 100 @@ -316,7 +316,7 @@ The application uses a TOML configuration file with the following sections: - `http_rpc_node_addr`: HTTP URL for a Sui RPC node, that the Atoma Sui's subscriber will use to listen to events on the Sui network. - `atoma_db`: ObjectID for Atoma's DB on the Sui network - `atoma_package_id`: ObjectID for Atoma's package on the Sui network -- `toma_package_id`: ObjectID for Atoma's TOMA token package +- `usdc_package_id`: ObjectID for USDC token package - `request_timeout` (optional): Duration for request timeouts - `max_concurrent_requests` (optional): Maximum number of concurrent Sui client requests - `limit` (optional): Limit for dynamic fields retrieval per event subscriber loop diff --git a/atoma-sui/src/client.rs b/atoma-sui/src/client.rs index 1161e792..3e572c19 100644 --- a/atoma-sui/src/client.rs +++ b/atoma-sui/src/client.rs @@ -63,9 +63,9 @@ pub struct AtomaSuiClient { /// which represents the node's registration in the Atoma network. node_badge: Option<(ObjectID, u64)>, - /// The ObjectID of the Toma wallet address + /// The ObjectID of the USDC wallet address /// for the current operator - toma_wallet_id: Option, + usdc_wallet_id: Option, } impl AtomaSuiClient { @@ -88,7 +88,7 @@ impl AtomaSuiClient { config, wallet_ctx, node_badge, - toma_wallet_id: None, + usdc_wallet_id: None, }) } @@ -166,7 +166,7 @@ impl AtomaSuiClient { ) -> Result { let client = self.wallet_ctx.get_client().await?; let active_address = self.wallet_ctx.active_address()?; - let toma_wallet_address = self.get_or_load_toma_wallet_object_id().await?; + let usdc_wallet_address = self.get_or_load_usdc_wallet_object_id().await?; let tx = client .transaction_builder() .move_call( @@ -177,7 +177,7 @@ impl AtomaSuiClient { vec![], vec![ SuiJsonValue::from_object_id(self.config.atoma_db()), - SuiJsonValue::from_object_id(toma_wallet_address), + SuiJsonValue::from_object_id(usdc_wallet_address), ], gas, gas_budget.unwrap_or(GAS_BUDGET), @@ -1144,44 +1144,44 @@ impl AtomaSuiClient { Err(AtomaSuiClientError::FailedToFindNewKeyRotationEvent) } - /// Get or load the TOMA wallet object ID + /// Get or load the USDC wallet object ID /// - /// This method checks if the TOMA wallet object ID is already loaded and returns it if so. - /// Otherwise, it loads the TOMA wallet object ID by finding the most balance TOMA coin for the active address. + /// This method checks if the USDC wallet object ID is already loaded and returns it if so. + /// Otherwise, it loads the USDC wallet object ID by finding the most balance USDC coin for the active address. /// /// # Returns /// - /// Returns the TOMA wallet object ID. + /// Returns the USDC wallet object ID. /// /// # Errors /// - /// Returns an error if no TOMA wallet is found for the active address. + /// Returns an error if no USDC wallet is found for the active address. /// /// # Examples /// /// ```rust,ignore /// let mut client = AtomaProxy::new(config).await?; - /// let toma_wallet_id = client.get_or_load_toma_wallet_object_id().await?; + /// let usdc_wallet_id = client.get_or_load_usdc_wallet_object_id().await?; /// ``` #[instrument(level = "info", skip_all, fields( - endpoint = "get_or_load_toma_wallet_object_id", + endpoint = "get_or_load_usdc_wallet_object_id", address = %self.wallet_ctx.active_address().unwrap() ))] - pub async fn get_or_load_toma_wallet_object_id(&mut self) -> Result { - if let Some(toma_wallet_id) = self.toma_wallet_id { - Ok(toma_wallet_id) + pub async fn get_or_load_usdc_wallet_object_id(&mut self) -> Result { + if let Some(usdc_wallet_id) = self.usdc_wallet_id { + Ok(usdc_wallet_id) } else { let active_address = self.wallet_ctx.active_address()?; - match utils::find_toma_token_wallet( + match utils::find_usdc_token_wallet( &self.wallet_ctx.get_client().await?, - self.config.toma_package_id(), + self.config.usdc_package_id(), active_address, ) .await { - Ok(toma_wallet) => { - self.toma_wallet_id = Some(toma_wallet); - Ok(toma_wallet) + Ok(usdc_wallet) => { + self.usdc_wallet_id = Some(usdc_wallet); + Ok(usdc_wallet) } Err(e) => Err(e), } @@ -1201,10 +1201,10 @@ pub enum AtomaSuiClientError { AtomaSuiClientError(#[from] sui_sdk::error::Error), #[error("Node is not subscribed to model {0}")] NodeNotSubscribedToModel(String), - #[error("No TOMA wallet found")] - NoTomaWalletFound, - #[error("No TOMA tokens found")] - NoTomaTokensFound, + #[error("No USDC wallet found")] + NoUsdcWalletFound, + #[error("No USDC tokens found")] + NoUsdcTokensFound, #[error("Failed to find new key rotation event")] FailedToFindNewKeyRotationEvent, #[error("Failed to parse event")] @@ -1344,29 +1344,29 @@ pub(crate) mod utils { None } - /// Find the TOMA token wallet for the given address + /// Find the USDC token wallet for the given address /// /// # Returns /// - /// Returns the TOMA token wallet object ID. + /// Returns the USDC token wallet object ID. /// /// # Errors /// - /// Returns an error if no TOMA wallet is found for the active address. + /// Returns an error if no USDC wallet is found for the active address. #[instrument(level = "info", skip_all, fields( - endpoint = "find_toma_token_wallet", + endpoint = "find_usdc_token_wallet", address = %active_address ))] - pub(crate) async fn find_toma_token_wallet( + pub(crate) async fn find_usdc_token_wallet( client: &SuiClient, - toma_package: ObjectID, + usdc_package: ObjectID, active_address: SuiAddress, ) -> Result { let Page { data: coins, .. } = client .coin_read_api() .get_coins( active_address, - Some(format!("{toma_package}::toma::TOMA")), + Some(format!("{usdc_package}::usdc::USDC")), None, None, ) @@ -1375,6 +1375,6 @@ pub(crate) mod utils { .into_iter() .max_by_key(|coin| coin.balance) .map(|coin| coin.coin_object_id) - .ok_or_else(|| AtomaSuiClientError::NoTomaTokensFound) + .ok_or_else(|| AtomaSuiClientError::NoUsdcTokensFound) } } diff --git a/atoma-sui/src/config.rs b/atoma-sui/src/config.rs index c436539a..d174b4ba 100644 --- a/atoma-sui/src/config.rs +++ b/atoma-sui/src/config.rs @@ -22,10 +22,10 @@ pub struct AtomaSuiConfig { /// This identifies the specific package (smart contract) to interact with atoma_package_id: ObjectID, - /// The Atoma's TOMA token package ID on the Sui network + /// The USDC token package ID on the Sui network /// This identifies the specific package (smart contract) to interact with - /// for TOMA token payments - toma_package_id: ObjectID, + /// for USDC token payments + usdc_package_id: ObjectID, /// The timeout duration for requests /// This sets the maximum time to wait for a response from the Sui network @@ -65,7 +65,7 @@ impl AtomaSuiConfig { http_rpc_node_addr: String, atoma_db: ObjectID, atoma_package_id: ObjectID, - toma_package_id: ObjectID, + usdc_package_id: ObjectID, request_timeout: Option, limit: Option, node_small_ids: Option>, @@ -79,7 +79,7 @@ impl AtomaSuiConfig { http_rpc_node_addr, atoma_db, atoma_package_id, - toma_package_id, + usdc_package_id, request_timeout, limit, node_small_ids, @@ -106,9 +106,9 @@ impl AtomaSuiConfig { self.atoma_package_id } - /// Getter for `toma_package_id` - pub fn toma_package_id(&self) -> ObjectID { - self.toma_package_id + /// Getter for `usdc_package_id` + pub fn usdc_package_id(&self) -> ObjectID { + self.usdc_package_id } /// Getter for `atoma_db` @@ -224,7 +224,7 @@ pub mod tests { ); let toml_str = toml::to_string(&config).unwrap(); - let should_be_toml_str = "http_rpc_node_addr = \"\"\natoma_db = \"0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e\"\natoma_package_id = \"0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e\"\ntoma_package_id = \"0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e\"\nmax_concurrent_requests = 10\nlimit = 10\nnode_small_ids = [0, 1, 2]\ntask_small_ids = [3, 4, 5]\nsui_config_path = \"\"\nsui_keystore_path = \"\"\ncursor_path = \"\"\n\n[request_timeout]\nsecs = 300\nnanos = 0\n"; + let should_be_toml_str = "http_rpc_node_addr = \"\"\natoma_db = \"0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e\"\natoma_package_id = \"0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e\"\nusdc_package_id = \"0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e\"\nmax_concurrent_requests = 10\nlimit = 10\nnode_small_ids = [0, 1, 2]\ntask_small_ids = [3, 4, 5]\nsui_config_path = \"\"\nsui_keystore_path = \"\"\ncursor_path = \"\"\n\n[request_timeout]\nsecs = 300\nnanos = 0\n"; assert_eq!(toml_str, should_be_toml_str); } } diff --git a/config.example.toml b/config.example.toml index 017fc469..3cf87dfd 100644 --- a/config.example.toml +++ b/config.example.toml @@ -11,7 +11,7 @@ service_bind_address = "0.0.0.0:3000" http_rpc_node_addr = "https://fullnode.testnet.sui.io:443" # Current RPC node address for testnet atoma_db = "0x7b8f40e38698deb650519a51f9c1a725bf8cfdc074d1552a4dc85976c2b414be" # Current ATOMA DB object ID for testnet atoma_package_id = "0xc05bae323433740c969d8cf938c48d7559490be5f8dde158792e7a0623787013" # Current ATOMA package ID for testnet -toma_package_id = "0xa1b2ce1a52abc52c5d21be9da0f752dbd587018bc666c5298f778f42de26df1d" # Current TOMA package ID for testnet +usdc_package_id = "0xa1ec7fc00a6f40db9693ad1415d0c193ad3906494428cf252621037bd7117e29" # Current USDC package ID for testnet request_timeout = { secs = 300, nanos = 0 } # Some reference value max_concurrent_requests = 10 # Some reference value limit = 100 # Some reference value