11use near_sdk:: { env, json_types:: U64 , near} ;
22
33use crate :: {
4- asset:: BorrowAssetAmount , asset_op, interest_rate_strategy:: InterestRateStrategy ,
5- number:: Decimal , time_chunk:: TimeChunk ,
4+ asset:: { BorrowAssetAmount , CollateralAssetAmount } ,
5+ asset_op,
6+ interest_rate_strategy:: InterestRateStrategy ,
7+ number:: Decimal ,
8+ time_chunk:: TimeChunk ,
69} ;
710
811#[ derive( Clone , Debug , PartialEq , Eq , PartialOrd , Ord ) ]
912#[ near( serializers = [ borsh, json] ) ]
1013pub struct Snapshot {
11- pub time_chunk : TimeChunk ,
12- pub end_timestamp_ms : U64 ,
13- deposited_active : BorrowAssetAmount ,
14- pub deposited_incoming : BorrowAssetAmount ,
15- borrowed : BorrowAssetAmount ,
16- pub yield_distribution : BorrowAssetAmount ,
14+ pub ( crate ) time_chunk : TimeChunk ,
15+ pub ( crate ) end_timestamp_ms : U64 ,
16+ pub ( crate ) borrow_asset_deposited_active : BorrowAssetAmount ,
17+ borrow_asset_deposited_incoming : BorrowAssetAmount ,
18+ borrow_asset_borrowed : BorrowAssetAmount ,
19+ collateral_asset_deposited : CollateralAssetAmount ,
20+ yield_distribution : BorrowAssetAmount ,
1721 interest_rate : Decimal ,
1822}
1923
2024impl Snapshot {
2125 pub fn new ( time_chunk : TimeChunk ) -> Self {
2226 Self {
2327 time_chunk,
24- end_timestamp_ms : near_sdk:: env:: block_timestamp_ms ( ) . into ( ) ,
25- deposited_active : 0 . into ( ) ,
26- deposited_incoming : 0 . into ( ) ,
27- borrowed : 0 . into ( ) ,
28+ end_timestamp_ms : env:: block_timestamp_ms ( ) . into ( ) ,
29+ borrow_asset_deposited_active : 0 . into ( ) ,
30+ borrow_asset_deposited_incoming : 0 . into ( ) ,
31+ borrow_asset_borrowed : 0 . into ( ) ,
32+ collateral_asset_deposited : 0 . into ( ) ,
2833 yield_distribution : BorrowAssetAmount :: zero ( ) ,
2934 interest_rate : Decimal :: ZERO ,
3035 }
@@ -36,35 +41,70 @@ impl Snapshot {
3641
3742 pub fn update_active (
3843 & mut self ,
39- deposited_active : BorrowAssetAmount ,
40- borrowed : BorrowAssetAmount ,
44+ borrow_asset_deposited_active : BorrowAssetAmount ,
45+ borrow_asset_borrowed : BorrowAssetAmount ,
46+ collateral_asset_deposited : CollateralAssetAmount ,
4147 interest_rate_strategy : & InterestRateStrategy ,
4248 ) {
4349 self . end_timestamp_ms = env:: block_timestamp_ms ( ) . into ( ) ;
44- self . deposited_active = deposited_active;
45- self . borrowed = borrowed;
50+ self . borrow_asset_deposited_active = borrow_asset_deposited_active;
51+ self . borrow_asset_borrowed = borrow_asset_borrowed;
52+ self . collateral_asset_deposited = collateral_asset_deposited;
4653 self . interest_rate = interest_rate_strategy. at ( self . usage_ratio ( ) ) ;
4754 }
4855
4956 pub fn usage_ratio ( & self ) -> Decimal {
50- if self . deposited_active . is_zero ( ) || self . borrowed . is_zero ( ) {
57+ if self . borrow_asset_deposited_active . is_zero ( ) || self . borrow_asset_borrowed . is_zero ( ) {
5158 Decimal :: ZERO
52- } else if self . borrowed >= self . deposited_active {
59+ } else if self . borrow_asset_borrowed >= self . borrow_asset_deposited_active {
5360 Decimal :: ONE
5461 } else {
55- Decimal :: from ( self . borrowed ) / Decimal :: from ( self . deposited_active )
62+ Decimal :: from ( self . borrow_asset_borrowed )
63+ / Decimal :: from ( self . borrow_asset_deposited_active )
5664 }
5765 }
5866
67+ pub fn set_time_chunk ( & mut self , time_chunk : TimeChunk ) {
68+ self . time_chunk = time_chunk;
69+ }
70+
71+ pub fn set_borrow_asset_deposited_incoming ( & mut self , amount : BorrowAssetAmount ) {
72+ self . borrow_asset_deposited_incoming = amount;
73+ }
74+
75+ pub fn set_yield_distribution ( & mut self , amount : BorrowAssetAmount ) {
76+ self . yield_distribution = amount;
77+ }
78+
79+ pub fn time_chunk ( & self ) -> & TimeChunk {
80+ & self . time_chunk
81+ }
82+
83+ pub fn end_timestamp_ms ( & self ) -> U64 {
84+ self . end_timestamp_ms
85+ }
86+
87+ pub fn borrow_asset_deposited_incoming ( & self ) -> BorrowAssetAmount {
88+ self . borrow_asset_deposited_incoming
89+ }
90+
91+ pub fn collateral_asset_deposited ( & self ) -> CollateralAssetAmount {
92+ self . collateral_asset_deposited
93+ }
94+
95+ pub fn yield_distribution ( & self ) -> BorrowAssetAmount {
96+ self . yield_distribution
97+ }
98+
5999 pub fn interest_rate ( & self ) -> Decimal {
60100 self . interest_rate
61101 }
62102
63- pub fn deposited_active ( & self ) -> BorrowAssetAmount {
64- self . deposited_active
103+ pub fn borrow_asset_deposited_active ( & self ) -> BorrowAssetAmount {
104+ self . borrow_asset_deposited_active
65105 }
66106
67- pub fn borrowed ( & self ) -> BorrowAssetAmount {
68- self . borrowed
107+ pub fn borrow_asset_borrowed ( & self ) -> BorrowAssetAmount {
108+ self . borrow_asset_borrowed
69109 }
70110}
0 commit comments