Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgeantonio21 committed Dec 23, 2024
1 parent 6f20fb6 commit 46c7ad1
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 43 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
64 changes: 32 additions & 32 deletions atoma-sui/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ObjectID>,
usdc_wallet_id: Option<ObjectID>,
}

impl AtomaSuiClient {
Expand All @@ -88,7 +88,7 @@ impl AtomaSuiClient {
config,
wallet_ctx,
node_badge,
toma_wallet_id: None,
usdc_wallet_id: None,
})
}

Expand Down Expand Up @@ -166,7 +166,7 @@ impl AtomaSuiClient {
) -> Result<String> {
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(
Expand All @@ -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),
Expand Down Expand Up @@ -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<ObjectID> {
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<ObjectID> {
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),
}
Expand All @@ -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")]
Expand Down Expand Up @@ -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<ObjectID> {
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,
)
Expand All @@ -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)
}
}
16 changes: 8 additions & 8 deletions atoma-sui/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Duration>,
limit: Option<usize>,
node_small_ids: Option<Vec<u64>>,
Expand All @@ -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,
Expand All @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 46c7ad1

Please sign in to comment.