Adds `AssetConversion` struct to avoid multiple reads or stores.

This commit is contained in:
Sebastián Nale 2023-01-24 21:27:28 -03:00 committed by scnale
parent 7b384caadc
commit a292dc253d
3 changed files with 15 additions and 10 deletions

View File

@ -65,6 +65,7 @@ contract RelayProviderGetters is RelayProviderState {
view
returns (uint16 tolerance, uint16 toleranceDenominator)
{
return (_state.assetConversionBuffer[targetChain], _state.assetConversionBufferDenominator[targetChain]);
RelayProviderStorage.AssetConversion storage assetConversion = _state.assetConversion[targetChain];
return (assetConversion.buffer, assetConversion.denominator);
}
}

View File

@ -58,7 +58,8 @@ contract RelayProviderSetters is Context, RelayProviderState {
}
function setAssetConversionBuffer(uint16 targetChain, uint16 tolerance, uint16 toleranceDenominator) internal {
_state.assetConversionBuffer[targetChain] = tolerance;
_state.assetConversionBufferDenominator[targetChain] = toleranceDenominator;
RelayProviderStorage.AssetConversion storage assetConversion = _state.assetConversion[targetChain];
assetConversion.buffer = tolerance;
assetConversion.denominator = toleranceDenominator;
}
}

View File

@ -11,6 +11,14 @@ contract RelayProviderStorage {
uint128 nativeCurrencyPrice;
}
struct AssetConversion {
// The following two fields are a percentage buffer that is used to upcharge the user for the value attached to the message sent.
// The cost of getting targetAmount on targetChain for the receiverValue is
// (denominator + buffer) / (denominator) * (the converted amount in source chain currency using the quoteAssetPrice values)
uint16 buffer;
uint16 denominator;
}
struct State {
// Wormhole chain id of this blockchain.
uint16 chainId;
@ -34,13 +42,8 @@ contract RelayProviderStorage {
mapping(uint16 => bytes32) deliveryAddressMap;
// Set of relayer addresses used to deliver or redeliver wormhole messages.
mapping(address => bool) approvedSenders;
// The following two fields are a percentage buffer that is used to upcharge the user for the application budget.
// The cost of getting targetAmount on targetChain for the receiverValue is
// (denominator + buffer) / (denominator) * (the converted amount in source chain currency using the quoteAssetPrice values)
// Dictionary of wormhole chain id -> assetConversionBuffer buffer
mapping(uint16 => uint16) assetConversionBuffer;
// Dictionary of wormhole chain id -> assetConversionBufferDenominator
mapping(uint16 => uint16) assetConversionBufferDenominator;
// Dictionary of wormhole chain id -> assetConversion
mapping(uint16 => AssetConversion) assetConversion;
// Reward address for the relayer. The CoreRelayer contract transfers the reward for relaying messages here.
address payable rewardAddress;
}