File tree Expand file tree Collapse file tree 2 files changed +48
-17
lines changed
Expand file tree Collapse file tree 2 files changed +48
-17
lines changed Original file line number Diff line number Diff line change 11use std:: vec;
22
3+ use crate :: oracle_types:: BlockHeight ;
34use ergo_lib:: ergotree_ir:: chain:: ergo_box:: ErgoBox ;
45use ergo_lib:: ergotree_ir:: chain:: ergo_box:: ErgoBoxCandidate ;
6+ use ergo_lib:: ergotree_ir:: chain:: token:: Token ;
57use thiserror:: Error ;
68
79use crate :: spec_token:: RewardTokenId ;
@@ -42,24 +44,32 @@ impl BuybackBoxWrapper {
4244 } )
4345 }
4446
45- pub fn new_without_reward_token ( & self ) -> ErgoBoxCandidate {
46- // take only buyback nft
47- let tokens = vec ! [ self
48- . ergo_box
49- . tokens
50- . as_ref( )
51- . unwrap( )
52- . get( 0 )
53- . unwrap( )
54- . clone( ) ]
47+ pub fn new_with_one_reward_token ( & self , creation_height : BlockHeight ) -> ErgoBoxCandidate {
48+ let single_reward_token = Token {
49+ token_id : self . reward_token_id . token_id ( ) ,
50+ amount : 1 . try_into ( ) . unwrap ( ) ,
51+ } ;
52+
53+ // take buyback nft and at least one reward token
54+ let tokens = vec ! [
55+ self . ergo_box
56+ . tokens
57+ . as_ref( )
58+ . unwrap( )
59+ . get( 0 )
60+ . unwrap( )
61+ . clone( ) ,
62+ single_reward_token,
63+ ]
5564 . try_into ( )
5665 . unwrap ( ) ;
66+
5767 ErgoBoxCandidate {
5868 value : self . ergo_box . value ,
5969 ergo_tree : self . ergo_box . ergo_tree . clone ( ) ,
6070 tokens : Some ( tokens) ,
6171 additional_registers : self . ergo_box . additional_registers . clone ( ) ,
62- creation_height : self . ergo_box . creation_height ,
72+ creation_height : creation_height. 0 ,
6373 }
6474 }
6575}
Original file line number Diff line number Diff line change @@ -160,9 +160,13 @@ pub fn build_refresh_action(
160160 height,
161161 rate,
162162 reward_decrement,
163- Some ( buyback_reward_token. amount ) ,
163+ Some (
164+ ( buyback_reward_token. amount . as_u64 ( ) - 1 )
165+ . try_into ( )
166+ . unwrap ( ) ,
167+ ) ,
164168 ) ?;
165- let out_buyback_box = buyback_box. new_without_reward_token ( ) ;
169+ let out_buyback_box = buyback_box. new_with_one_reward_token ( height ) ;
166170 output_candidates. remove ( 0 ) ;
167171 output_candidates. insert ( 0 , out_pool_box_w_buyback_rewards) ;
168172 // should be at index 2 (checked in the contract of the buyback input box)
@@ -694,8 +698,8 @@ mod tests {
694698 . as_ref( )
695699 . unwrap( )
696700 . len( ) ,
697- 1 ,
698- "only one token should be in output buyback box"
701+ 2 ,
702+ "only two tokens should be in output buyback box"
699703 ) ;
700704 assert_eq ! (
701705 action_with_buyback
@@ -710,8 +714,25 @@ mod tests {
710714 . unwrap( )
711715 . token_id,
712716 buyback_token_id,
713- "only buyback nft should be in output buyback box"
717+ "buyback nft should be in output buyback box"
714718 ) ;
719+ assert_eq ! (
720+ action_with_buyback
721+ . tx
722+ . output_candidates
723+ . get( 2 )
724+ . unwrap( )
725+ . tokens
726+ . as_ref( )
727+ . unwrap( )
728+ . get( 1 )
729+ . unwrap( )
730+ . amount
731+ . as_u64( ) ,
732+ & 1 ,
733+ "one reward token should be in output buyback box"
734+ ) ;
735+
715736 assert_eq ! (
716737 action_with_buyback
717738 . tx
@@ -725,7 +746,7 @@ mod tests {
725746 . unwrap( )
726747 . amount
727748 . as_u64( ) ,
728- & 190 ,
749+ & 189 ,
729750 "reward tokens should be added to the pool box"
730751 )
731752 }
You can’t perform that action at this time.
0 commit comments