Skip to content

Commit 8d48ef8

Browse files
kiselnolga24912
andauthored
Update bitcoin deposits to a safe version (#207)
* Update bitcoin deposits to a safe version * fix safe deposit msg * fix deposit method * fix clippy --------- Co-authored-by: Olga Kunyavskaya <olga.kunyavskaya@aurora.dev>
1 parent da15272 commit 8d48ef8

File tree

8 files changed

+36
-39
lines changed

8 files changed

+36
-39
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bridge-cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bridge-cli"
3-
version = "0.3.14"
3+
version = "0.3.15"
44
edition = "2021"
55
repository = "https://github.com/Near-One/bridge-sdk-rs"
66

bridge-cli/src/omni_connector_command.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -337,13 +337,6 @@ pub enum OmniConnectorSubCommand {
337337
vout: usize,
338338
#[clap(short, long, help = "The BTC recipient on NEAR")]
339339
recipient_id: OmniAddress,
340-
#[clap(
341-
short,
342-
long,
343-
help = "The amount to be transferred, in satoshis",
344-
default_value = "0"
345-
)]
346-
amount: u128,
347340
#[clap(
348341
short,
349342
long,
@@ -867,7 +860,6 @@ pub async fn match_subcommand(cmd: OmniConnectorSubCommand, network: Network) {
867860
btc_tx_hash,
868861
vout,
869862
recipient_id,
870-
amount,
871863
fee,
872864
config_cli,
873865
} => {
@@ -878,7 +870,6 @@ pub async fn match_subcommand(cmd: OmniConnectorSubCommand, network: Network) {
878870
vout,
879871
BtcDepositArgs::OmniDepositArgs {
880872
recipient_id,
881-
amount,
882873
fee,
883874
},
884875
TransactionOptions::default(),
@@ -963,7 +954,7 @@ pub async fn match_subcommand(cmd: OmniConnectorSubCommand, network: Network) {
963954
} => {
964955
let omni_connector = omni_connector(network, config_cli);
965956
let btc_address = omni_connector
966-
.get_btc_address(chain.into(), recipient_id, amount, fee)
957+
.get_btc_address(chain.into(), recipient_id, fee)
967958
.await
968959
.unwrap();
969960

bridge-sdk/bridge-clients/near-bridge-client/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "near-bridge-client"
3-
version = "0.2.2"
3+
version = "0.2.3"
44
edition = "2021"
55

66
[dependencies]

bridge-sdk/bridge-clients/near-bridge-client/src/btc.rs

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const SUBMIT_BTC_TRANSFER_GAS: u64 = 300_000_000_000_000;
2929
const INIT_BTC_TRANSFER_DEPOSIT: u128 = 1;
3030
const ACTIVE_UTXO_MANAGEMENT_DEPOSIT: u128 = 1;
3131
const SIGN_BTC_TRANSACTION_DEPOSIT: u128 = 250_000_000_000_000_000_000_000;
32+
const BTC_SAFE_VERIFY_DEPOSIT_DEPOSIT: u128 = 1_200_000_000_000_000_000_000;
3233
const BTC_VERIFY_DEPOSIT_DEPOSIT: u128 = 0;
3334
const BTC_VERIFY_WITHDRAW_DEPOSIT: u128 = 0;
3435
const BTC_CANCEL_WITHDRAW_DEPOSIT: u128 = 1;
@@ -75,13 +76,20 @@ pub struct PostAction {
7576
pub gas: Option<Gas>,
7677
}
7778

79+
#[derive(Clone, serde::Serialize, serde::Deserialize)]
80+
pub struct SafeDepositMsg {
81+
pub msg: String,
82+
}
83+
7884
#[derive(Clone, serde::Serialize, serde::Deserialize)]
7985
pub struct DepositMsg {
8086
pub recipient_id: AccountId,
8187
#[serde(skip_serializing_if = "Option::is_none")]
8288
pub post_actions: Option<Vec<PostAction>>,
8389
#[serde(skip_serializing_if = "Option::is_none")]
8490
pub extra_msg: Option<String>,
91+
#[serde(skip_serializing_if = "Option::is_none")]
92+
pub safe_deposit: Option<SafeDepositMsg>,
8593
}
8694

8795
#[derive(Clone, serde::Serialize, serde::Deserialize)]
@@ -365,16 +373,24 @@ impl NearBridgeClient {
365373
) -> Result<CryptoHash> {
366374
let endpoint = self.endpoint()?;
367375
let btc_connector = self.utxo_chain_connector(chain)?;
376+
let (method_name, deposit) = if args.deposit_msg.safe_deposit.is_some() {
377+
(
378+
"safe_verify_deposit".to_string(),
379+
BTC_SAFE_VERIFY_DEPOSIT_DEPOSIT,
380+
)
381+
} else {
382+
("verify_deposit".to_string(), BTC_VERIFY_DEPOSIT_DEPOSIT)
383+
};
368384
let tx_hash = near_rpc_client::change_and_wait(
369385
endpoint,
370386
ChangeRequest {
371387
signer: self.signer()?,
372388
nonce: transaction_options.nonce,
373389
receiver_id: btc_connector,
374-
method_name: "verify_deposit".to_string(),
390+
method_name,
375391
args: serde_json::json!(args).to_string().into_bytes(),
376392
gas: BTC_VERIFY_DEPOSIT_GAS,
377-
deposit: BTC_VERIFY_DEPOSIT_DEPOSIT,
393+
deposit,
378394
},
379395
transaction_options.wait_until,
380396
transaction_options.wait_final_outcome_timeout_sec,
@@ -567,10 +583,9 @@ impl NearBridgeClient {
567583
&self,
568584
chain: ChainKind,
569585
recipient_id: OmniAddress,
570-
amount: u128,
571586
fee: u128,
572587
) -> Result<String> {
573-
let deposit_msg = self.get_deposit_msg_for_omni_bridge(recipient_id, amount, fee)?;
588+
let deposit_msg = self.get_deposit_msg_for_omni_bridge(recipient_id, fee)?;
574589
let endpoint = self.endpoint()?;
575590
let btc_connector = self.utxo_chain_connector(chain)?;
576591

@@ -699,7 +714,6 @@ impl NearBridgeClient {
699714
pub fn get_deposit_msg_for_omni_bridge(
700715
&self,
701716
recipient_id: OmniAddress,
702-
amount: u128,
703717
fee: u128,
704718
) -> Result<DepositMsg> {
705719
if recipient_id.is_utxo_chain() {
@@ -713,25 +727,22 @@ impl NearBridgeClient {
713727
recipient_id,
714728
post_actions: None,
715729
extra_msg: None,
730+
safe_deposit: None,
716731
})
717732
} else {
718733
let omni_bridge_id = self.omni_bridge_id()?;
719-
let account_id = self.account_id()?;
720734
Ok(DepositMsg {
721-
recipient_id: account_id,
722-
post_actions: Some(vec![PostAction {
723-
receiver_id: omni_bridge_id,
724-
amount,
725-
memo: None,
735+
recipient_id: omni_bridge_id,
736+
post_actions: None,
737+
extra_msg: None,
738+
safe_deposit: Some(SafeDepositMsg {
726739
msg: json!({
727740
"recipient": recipient_id.to_string(),
728741
"fee": fee.to_string(),
729742
"native_token_fee": "0",
730743
})
731744
.to_string(),
732-
gas: None,
733-
}]),
734-
extra_msg: None,
745+
}),
735746
})
736747
}
737748
}

bridge-sdk/bridge-clients/near-bridge-client/src/near_bridge_client.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,8 @@ impl NearBridgeClient {
613613
let endpoint = self.endpoint()?;
614614
let omni_bridge_id = self.omni_bridge_id()?;
615615

616-
let required_balance = self.get_required_balance_for_init_transfer().await?;
616+
let required_balance = self.get_required_balance_for_init_transfer().await?
617+
.saturating_add(native_fee);
617618

618619
let nonce = if self
619620
.deposit_storage_if_required(required_balance, transaction_options.clone())

bridge-sdk/connectors/omni-connector/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "omni-connector"
3-
version = "0.2.13"
3+
version = "0.2.14"
44
edition = "2021"
55

66
[dependencies]

bridge-sdk/connectors/omni-connector/src/omni_connector.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ pub enum FinTransferArgs {
190190
btc_tx_hash: String,
191191
vout: usize,
192192
recipient_id: OmniAddress,
193-
amount: u128,
194193
fee: u128,
195194
transaction_options: TransactionOptions,
196195
},
@@ -223,7 +222,6 @@ pub enum FinTransferArgs {
223222
pub enum BtcDepositArgs {
224223
OmniDepositArgs {
225224
recipient_id: OmniAddress,
226-
amount: u128,
227225
fee: u128,
228226
},
229227
DepositMsg {
@@ -488,9 +486,8 @@ impl OmniConnector {
488486
BtcDepositArgs::DepositMsg { msg } => msg,
489487
BtcDepositArgs::OmniDepositArgs {
490488
recipient_id,
491-
amount,
492489
fee,
493-
} => near_bridge_client.get_deposit_msg_for_omni_bridge(recipient_id, amount, fee)?,
490+
} => near_bridge_client.get_deposit_msg_for_omni_bridge(recipient_id, fee)?,
494491
};
495492

496493
let args = FinBtcTransferArgs {
@@ -586,12 +583,11 @@ impl OmniConnector {
586583
&self,
587584
chain: ChainKind,
588585
recipient_id: OmniAddress,
589-
amount: u128,
590586
fee: u128,
591587
) -> Result<String> {
592588
let near_bridge_client = self.near_bridge_client()?;
593589
near_bridge_client
594-
.get_btc_address(chain, recipient_id, amount, fee)
590+
.get_btc_address(chain, recipient_id, fee)
595591
.await
596592
}
597593

@@ -1715,7 +1711,6 @@ impl OmniConnector {
17151711
btc_tx_hash,
17161712
vout,
17171713
recipient_id,
1718-
amount,
17191714
fee,
17201715
transaction_options,
17211716
} => self
@@ -1725,7 +1720,6 @@ impl OmniConnector {
17251720
vout,
17261721
BtcDepositArgs::OmniDepositArgs {
17271722
recipient_id,
1728-
amount,
17291723
fee,
17301724
},
17311725
transaction_options,

0 commit comments

Comments
 (0)