Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit b6f04df

Browse files
authored
token-cli: Set a compute unit limit for set_interest_rate (#6514)
1 parent 7a021d6 commit b6f04df

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

token/cli/src/command.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,19 +134,24 @@ async fn check_wallet_balance(
134134
}
135135
}
136136

137-
fn token_client_from_config(
137+
fn base_token_client(
138138
config: &Config<'_>,
139139
token_pubkey: &Pubkey,
140140
decimals: Option<u8>,
141141
) -> Result<Token<ProgramRpcClientSendTransaction>, Error> {
142-
let token = Token::new(
142+
Ok(Token::new(
143143
config.program_client.clone(),
144144
&config.program_id,
145145
token_pubkey,
146146
decimals,
147147
config.fee_payer()?.clone(),
148-
);
148+
))
149+
}
149150

151+
fn config_token_client(
152+
token: Token<ProgramRpcClientSendTransaction>,
153+
config: &Config<'_>,
154+
) -> Result<Token<ProgramRpcClientSendTransaction>, Error> {
150155
let token = if let Some(compute_unit_limit) = config.compute_unit_limit {
151156
token.with_compute_unit_limit(compute_unit_limit)
152157
} else {
@@ -174,6 +179,15 @@ fn token_client_from_config(
174179
}
175180
}
176181

182+
fn token_client_from_config(
183+
config: &Config<'_>,
184+
token_pubkey: &Pubkey,
185+
decimals: Option<u8>,
186+
) -> Result<Token<ProgramRpcClientSendTransaction>, Error> {
187+
let token = base_token_client(config, token_pubkey, decimals)?;
188+
config_token_client(token, config)
189+
}
190+
177191
fn native_token_client_from_config(
178192
config: &Config<'_>,
179193
) -> Result<Token<ProgramRpcClientSendTransaction>, Error> {
@@ -418,7 +432,10 @@ async fn command_set_interest_rate(
418432
rate_bps: i16,
419433
bulk_signers: Vec<Arc<dyn Signer>>,
420434
) -> CommandResult {
421-
let token = token_client_from_config(config, &token_pubkey, None)?;
435+
// Because set_interest_rate depends on the time, it can cost more between
436+
// simulation and execution. To help that, just set a static compute limit
437+
let token = base_token_client(config, &token_pubkey, None)?.with_compute_unit_limit(2_500);
438+
let token = config_token_client(token, config)?;
422439

423440
if !config.sign_only {
424441
let mint_account = config.get_account_checked(&token_pubkey).await?;

0 commit comments

Comments
 (0)