@@ -17,6 +17,13 @@ access(all) contract TidalProtocol {
1717 /// The canonical PublicPath where the primary TidalProtocol Pool can be accessed publicly
1818 access (all ) let PoolPublicPath : PublicPath
1919
20+ /* --- EVENTS ---- */
21+
22+ access (all ) event Opened (pid : UInt64 , poolUUID : UInt64 )
23+ access (all ) event Deposited (pid : UInt64 , poolUUID : UInt64 , type : String , amount : UFix64 , depositedUUID : UInt64 )
24+ access (all ) event Withdrawn (pid : UInt64 , poolUUID : UInt64 , type : String , amount : UFix64 , withdrawnUUID : UInt64 )
25+ access (all ) event Rebalanced (pid : UInt64 , poolUUID : UInt64 , atHealth : UFix64 , amount : UFix64 , fromUnder : Bool )
26+
2027 /* --- PUBLIC METHODS ---- */
2128
2229 /// Takes out a TidalProtocol loan with the provided collateral, returning a Position that can be used to manage
@@ -552,6 +559,8 @@ access(all) contract TidalProtocol {
552559
553560 // Get a reference to the user's position and global token state for the affected token.
554561 let type = from .getType ()
562+ let amount = from .balance
563+ let depositedUUID = from .uuid
555564 let position = (&self .positions [pid ] as auth (EImplementation ) &InternalPosition ? )!
556565 let tokenState = self .tokenState (type : type )
557566
@@ -596,6 +605,8 @@ access(all) contract TidalProtocol {
596605 self .rebalancePosition (pid : pid , force : true )
597606 }
598607
608+ emit Deposited (pid : pid , poolUUID : self .uuid , type : type .identifier , amount : amount , depositedUUID : depositedUUID )
609+
599610 self .queuePositionForUpdateIfNecessary (pid : pid )
600611 }
601612
@@ -700,7 +711,11 @@ access(all) contract TidalProtocol {
700711 // Queue for update if necessary
701712 self .queuePositionForUpdateIfNecessary (pid : pid )
702713
703- return <- reserveVault .withdraw (amount : amount )
714+ let withdrawn <- reserveVault .withdraw (amount : amount )
715+
716+ emit Withdrawn (pid : pid , poolUUID : self .uuid , type : type .identifier , amount : withdrawn .balance , withdrawnUUID : withdrawn .uuid )
717+
718+ return <- withdrawn
704719 }
705720
706721 // RESTORED: Position queue management from Dieter's implementation
@@ -752,6 +767,9 @@ access(all) contract TidalProtocol {
752767 )
753768
754769 let pulledVault <- topUpSource .withdrawAvailable (maxAmount : idealDeposit )
770+
771+ emit Rebalanced (pid : pid , poolUUID : self .uuid , atHealth : balanceSheet .health , amount : pulledVault .balance , fromUnder : true )
772+
755773 self .depositAndPush (pid : pid , from : <- pulledVault , pushToDrawDownSink : false )
756774 }
757775 } else if balanceSheet .health > position .targetHealth {
@@ -786,9 +804,11 @@ access(all) contract TidalProtocol {
786804 }
787805 position .balances [self .defaultToken ]! .recordWithdrawal (amount : sinkAmount , tokenState : tokenState )
788806 let sinkVault <- TidalProtocol .borrowMOETMinter ().mintTokens (amount : sinkAmount )
807+
808+ emit Rebalanced (pid : pid , poolUUID : self .uuid , atHealth : balanceSheet .health , amount : sinkVault .balance , fromUnder : false )
809+
789810 // Push what we can into the sink, and redeposit the rest
790811 drawDownSink .depositCapacity (from : &sinkVault as auth (FungibleToken.Withdraw ) &{FungibleToken .Vault })
791-
792812 if sinkVault .balance > 0.0 {
793813 self .depositAndPush (pid : pid , from : <- sinkVault , pushToDrawDownSink : false )
794814 } else {
@@ -922,6 +942,7 @@ access(all) contract TidalProtocol {
922942 self .nextPositionID = self .nextPositionID + 1
923943 self .positions [id ] <- ! create InternalPosition ()
924944
945+ emit Opened (pid : id , poolUUID : self .uuid )
925946
926947 // assign issuance & repayment connectors within the InternalPosition
927948 let iPos = (&self .positions [id ] as auth (EImplementation ) &InternalPosition ? )!
@@ -1645,19 +1666,19 @@ access(all) contract TidalProtocol {
16451666 access (all ) struct DummyPriceOracle : DFB .PriceOracle {
16461667 access (self ) var prices : {Type : UFix64 }
16471668 access (self ) let defaultToken : Type
1648-
1669+
16491670 access (all ) view fun unitOfAccount (): Type {
16501671 return self .defaultToken
16511672 }
1652-
1673+
16531674 access (all ) fun price (ofToken : Type ): UFix64 {
16541675 return self .prices [ofToken ] ?? 1.0
16551676 }
1656-
1677+
16571678 access (all ) fun setPrice (ofToken : Type , price : UFix64 ) {
16581679 self .prices [ofToken ] = price
16591680 }
1660-
1681+
16611682 init (defaultToken : Type ) {
16621683 self .defaultToken = defaultToken
16631684 self .prices = {defaultToken : 1.0 }
0 commit comments