@@ -11,28 +11,35 @@ abstract contract IntraBlockTokenTracking {
1111 /// @dev last block interaction
1212 uint256 lastUsedBlock;
1313
14- /// @dev trowed at invalid amount
15- error IBTT_InvalidAmount ();
16-
1714 /// @dev throwed if the balance is not enough
1815 error IBTT_InsufficientBalance ();
1916
2017 /// @dev throwed when tries to send zero amount
2118 error IBTT_ZeroAmount ();
2219
23- function getBalance () external view returns (uint64 ) {
24- return _getBalance ();
20+ /**
21+ * @notice Get the available balance at the current block state
22+ */
23+ function getAvailableBalance () external view returns (uint64 ) {
24+ return _getAvailableBalance ();
2525 }
2626
27- function _getBalance () internal view returns (uint64 balance ) {
27+ /**
28+ * @notice Get the available balance at the current block state
29+ */
30+ function _getAvailableBalance () internal view returns (uint64 balance ) {
2831 PrecompileLib.SpotBalance memory spotBalance = PrecompileLib.spotBalance (address (this ), 0 );
2932 uint64 total = spotBalance.total;
3033 uint64 usedAmount = _getUsedAmount ();
3134
32- if (usedAmount > total) return 0 ;
35+ // total can't be > usedAmount
36+ // check on that in the _spotSend()
3337 return total - usedAmount;
3438 }
3539
40+ /**
41+ * @notice Add amount used in the current block
42+ */
3643 function _addUsedAmount (uint64 amount ) internal {
3744 if (lastUsedBlock != block .number ) {
3845 usedTokenAmounts = amount;
@@ -42,6 +49,9 @@ abstract contract IntraBlockTokenTracking {
4249 }
4350 }
4451
52+ /**
53+ * @notice Get used amount
54+ */
4555 function _getUsedAmount () internal view returns (uint64 ) {
4656 return lastUsedBlock == block .number ? usedTokenAmounts : 0 ;
4757 }
@@ -54,17 +64,14 @@ abstract contract IntraBlockTokenTracking {
5464 function _spotSend (address to , uint64 amount ) internal {
5565 if (amount == 0 ) revert IBTT_ZeroAmount ();
5666
57- bool activated;
58- uint64 balance = _getBalance ();
59-
60- if (PrecompileLib.coreUserExists (to)) {
61- activated = true ;
62- }
63-
67+ // enabler fees not included
6468 CoreWriterLib.spotSend (to, 0 , amount);
6569
70+ // get the balance - used amount in the same block
71+ uint64 balance = _getAvailableBalance ();
72+
6673 // add 1USDC as fee to enable the recipient at core spot
67- amount = activated ? amount : amount + 1e8 ;
74+ amount = PrecompileLib. coreUserExists (to) ? amount : amount + 1e8 ;
6875
6976 if (amount > balance) revert IBTT_InsufficientBalance ();
7077
0 commit comments