Browse Source

fix fee fields in state

Jayant Krishnamurthy 2 years ago
parent
commit
6362c1e7e4

+ 4 - 3
target_chains/ethereum/contracts/contracts/entropy/Entropy.sol

@@ -171,10 +171,11 @@ contract Entropy is IEntropy, EntropyState {
         providerInfo.sequenceNumber += 1;
 
         // Check that fees were paid and increment the pyth / provider balances.
-        uint requiredFee = getFee(provider);
+        uint128 requiredFee = getFee(provider);
         if (msg.value < requiredFee) revert EntropyErrors.InsufficientFee();
         providerInfo.accruedFeesInWei += providerInfo.feeInWei;
-        _state.accruedPythFeesInWei += (msg.value - providerInfo.feeInWei);
+        _state.accruedPythFeesInWei += (uint128(msg.value) -
+            providerInfo.feeInWei);
 
         // Store the user's commitment so that we can fulfill the request later.
         EntropyStructs.Request storage req = _state.requests[
@@ -270,7 +271,7 @@ contract Entropy is IEntropy, EntropyState {
 
     function getFee(
         address provider
-    ) public view override returns (uint feeAmount) {
+    ) public view override returns (uint128 feeAmount) {
         return _state.providers[provider].feeInWei + _state.pythFeeInWei;
     }
 

+ 2 - 2
target_chains/ethereum/contracts/contracts/entropy/EntropyState.sol

@@ -6,8 +6,8 @@ import "@pythnetwork/entropy-sdk-solidity/EntropyStructs.sol";
 
 contract EntropyInternalStructs {
     struct State {
-        uint pythFeeInWei;
-        uint accruedPythFeesInWei;
+        uint128 pythFeeInWei;
+        uint128 accruedPythFeesInWei;
         mapping(address => EntropyStructs.ProviderInfo) providers;
         mapping(bytes32 => EntropyStructs.Request) requests;
     }

+ 2 - 0
target_chains/ethereum/contracts/forge-test/Entropy.t.sol

@@ -378,6 +378,8 @@ contract EntropyTest is Test, EntropyTestUtils {
         random.register(MAX_UINT128, provider1Proofs[0], hex"0100", 100);
         vm.expectRevert();
         random.getFee(provider1);
+
+        // TODO: does casting in solidity fail if the value is too large?
     }
 
     function testFees() public {

+ 0 - 7
target_chains/ethereum/entropy_sdk/solidity/EntropyStructs.sol

@@ -3,13 +3,6 @@
 pragma solidity ^0.8.0;
 
 contract EntropyStructs {
-    struct State {
-        uint128 pythFeeInWei;
-        uint128 accruedPythFeesInWei;
-        mapping(address => ProviderInfo) providers;
-        mapping(bytes32 => Request) requests;
-    }
-
     struct ProviderInfo {
         uint128 feeInWei;
         uint128 accruedFeesInWei;

+ 1 - 1
target_chains/ethereum/entropy_sdk/solidity/IEntropy.sol

@@ -60,7 +60,7 @@ interface IEntropy is EntropyEvents {
         uint64 sequenceNumber
     ) external view returns (EntropyStructs.Request memory req);
 
-    function getFee(address provider) external view returns (uint feeAmount);
+    function getFee(address provider) external view returns (uint128 feeAmount);
 
     function getAccruedPythFees()
         external