-
Notifications
You must be signed in to change notification settings - Fork 3
Support BTC refund flow #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: omni-main
Are you sure you want to change the base?
Changes from 29 commits
fa6f5ec
eb63441
b5d9ed1
edf58ef
b2b65ee
bc73080
3113f71
c2a2cc9
211cfa0
c0ca652
71ae63b
f8324d4
106268e
8f4f045
bc3ae0b
e1fd99e
1753f3c
8d23beb
99206e4
710d7d3
181b003
afaa15c
fcb4f46
252f996
20a4767
0620f00
a1122b4
c294518
1c9c272
5339354
724da78
33a97aa
fea99fd
865019b
2b6d4b0
f1880ee
403ff11
28397dd
80027f9
532eb0f
22d199e
e764521
f1f3ed5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -426,6 +426,72 @@ impl Contract { | |
| } | ||
| } | ||
|
|
||
| #[cfg(not(feature = "zcash"))] | ||
| #[near] | ||
| impl Contract { | ||
| // ── Refund API (Bitcoin only) ── | ||
|
|
||
| #[pause(except(roles(Role::DAO)))] | ||
| pub fn request_refund( | ||
| &mut self, | ||
| deposit_msg: DepositMsg, | ||
| tx_bytes: Vec<u8>, | ||
| vout: usize, | ||
| tx_block_blockhash: String, | ||
| tx_index: u64, | ||
| merkle_proof: Vec<String>, | ||
olga24912 marked this conversation as resolved.
Show resolved
Hide resolved
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are we going to add coinbase proof here? |
||
| ) -> Promise { | ||
| self.internal_request_refund( | ||
| deposit_msg, | ||
| tx_bytes, | ||
| vout, | ||
| tx_block_blockhash, | ||
| tx_index, | ||
| merkle_proof, | ||
| ) | ||
| } | ||
|
|
||
| #[payable] | ||
| #[access_control_any(roles(Role::DAO, Role::Operator))] | ||
olga24912 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| pub fn reject_refund(&mut self, utxo_storage_key: String) { | ||
| assert_one_yocto(); | ||
| self.internal_reject_refund(utxo_storage_key); | ||
| } | ||
|
|
||
| #[payable] | ||
| #[pause(except(roles(Role::DAO)))] | ||
| pub fn execute_refund(&mut self, utxo_storage_key: String) { | ||
| require!( | ||
| env::attached_deposit() >= self.required_balance_for_execute_refund(), | ||
| "Insufficient deposit for storage" | ||
| ); | ||
| self.internal_execute_refund(utxo_storage_key); | ||
| } | ||
|
|
||
| #[pause(except(roles(Role::DAO)))] | ||
| pub fn verify_refund( | ||
olga24912 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| &mut self, | ||
| tx_id: String, | ||
| tx_block_blockhash: String, | ||
| tx_index: u64, | ||
| merkle_proof: Vec<String>, | ||
| ) -> Promise { | ||
| let btc_pending_info = self.internal_unwrap_btc_pending_info(&tx_id); | ||
| btc_pending_info.assert_refund_pending_verify_tx(); | ||
| require!( | ||
| btc_pending_info.tx_bytes_with_sign.is_some(), | ||
| "Missing tx_bytes_with_sign" | ||
| ); | ||
| self.internal_verify_refund( | ||
| tx_id, | ||
| tx_block_blockhash, | ||
| tx_index, | ||
| merkle_proof, | ||
| btc_pending_info, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| impl Contract { | ||
| pub fn create_active_utxo_management_pending_info( | ||
| &mut self, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -459,4 +459,11 @@ impl Contract { | |
| ); | ||
| self.internal_mut_config().unhealthy_utxo_amount = unhealthy_utxo_amount.0; | ||
| } | ||
|
|
||
| #[payable] | ||
| #[access_control_any(roles(Role::DAO))] | ||
| pub fn set_refund_timelock_sec(&mut self, refund_timelock_sec: u64) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The number of setters has become huge, can we combine some of them under one setter, eg set_config? |
||
| assert_one_yocto(); | ||
| self.internal_mut_config().refund_timelock_sec = refund_timelock_sec; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -284,4 +284,11 @@ impl Contract { | |
| pub fn required_balance_for_safe_deposit(&self) -> NearToken { | ||
| REQUIRED_BALANCE_FOR_DEPOSIT | ||
| } | ||
|
|
||
| #[cfg(not(feature = "zcash"))] | ||
| pub fn required_balance_for_execute_refund(&self) -> NearToken { | ||
| // execute_refund uses ~700 bytes of storage (BTCPendingInfo + Account + verified_deposit_utxo) | ||
| // At 0.00001 NEAR/byte, that's ~0.007 NEAR. We use 0.1 NEAR as a safe margin. | ||
|
||
| NearToken::from_millinear(100) | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.