Allow governance to update asset conversion buffer, and also remove t… (#44)
* Allow governance to update asset conversion buffer, and also remove the dependency on source chain for asset conversion buffer * forge fmt
This commit is contained in:
parent
7357f20f64
commit
177862cd78
|
@ -716,7 +716,7 @@ contract CoreRelayer is CoreRelayerGovernance {
|
|||
returns (uint256 nativeQuote)
|
||||
{
|
||||
uint256 sourceAmount = quoteAssetConversion(targetChain, targetAmount, chainId(), provider);
|
||||
(uint16 buffer, uint16 denominator) = provider.assetConversionBuffer(chainId(), targetChain);
|
||||
(uint16 buffer, uint16 denominator) = provider.getAssetConversionBuffer(targetChain);
|
||||
nativeQuote = (sourceAmount * (denominator + buffer) + denominator - 1) / denominator;
|
||||
}
|
||||
|
||||
|
@ -728,7 +728,7 @@ contract CoreRelayer is CoreRelayerGovernance {
|
|||
returns (uint256 targetAmount)
|
||||
{
|
||||
uint256 amount = quoteAssetConversion(chainId(), sourceAmount, targetChain, provider);
|
||||
(uint16 buffer, uint16 denominator) = provider.assetConversionBuffer(chainId(), targetChain);
|
||||
(uint16 buffer, uint16 denominator) = provider.getAssetConversionBuffer(targetChain);
|
||||
targetAmount = amount * denominator / (denominator + buffer);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ interface IRelayProvider {
|
|||
function quoteAssetPrice(uint16 chainId) external view returns (uint256 usdPrice);
|
||||
|
||||
// should this have source chain as a parameter, or default to current chain id?
|
||||
function assetConversionBuffer(uint16 sourceChain, uint16 targetChain)
|
||||
function getAssetConversionBuffer(uint16 targetChain)
|
||||
external
|
||||
view
|
||||
returns (uint16 tolerance, uint16 toleranceDenominator);
|
||||
|
|
|
@ -58,13 +58,13 @@ contract RelayProvider is RelayProviderGovernance, IRelayProvider {
|
|||
|
||||
//Returns a a buffer amount, and a buffer denominator, whereby the bufferAmount / bufferDenominator will be reduced from
|
||||
//applicationBudget conversions, giving an overhead to the provider on each conversion
|
||||
function assetConversionBuffer(uint16 sourceChain, uint16 targetChain)
|
||||
function getAssetConversionBuffer(uint16 targetChain)
|
||||
public
|
||||
view
|
||||
override
|
||||
returns (uint16 tolerance, uint16 toleranceDenominator)
|
||||
{
|
||||
return (5, 100);
|
||||
return assetConversionBuffer(targetChain);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -59,4 +59,12 @@ contract RelayProviderGetters is RelayProviderState {
|
|||
function deliveryAddress(uint16 targetChain) public view returns (bytes32 whFormatAddress) {
|
||||
return _state.deliveryAddressMap[targetChain];
|
||||
}
|
||||
|
||||
function assetConversionBuffer(uint16 targetChain)
|
||||
public
|
||||
view
|
||||
returns (uint16 tolerance, uint16 toleranceDenominator)
|
||||
{
|
||||
return (_state.assetConversionBuffer[targetChain], _state.assetConversionBufferDenominator[targetChain]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ abstract contract RelayProviderGovernance is RelayProviderGetters, RelayProvider
|
|||
event DeliverGasOverheadUpdated(uint32 indexed oldGasOverhead, uint32 indexed newGasOverhead);
|
||||
event CoreRelayerUpdated(address coreRelayer);
|
||||
event ApprovedSenderUpdated(address sender, bool approved);
|
||||
event AssetConversionBufferUpdated(uint16 targetChain, uint16 buffer, uint16 bufferDenominator);
|
||||
|
||||
function updateCoreRelayer(address payable newAddress) public onlyOwner {
|
||||
setCoreRelayer(newAddress);
|
||||
|
@ -74,6 +75,14 @@ abstract contract RelayProviderGovernance is RelayProviderGetters, RelayProvider
|
|||
setMaximumBudget(targetChainId, maximumTotalBudget);
|
||||
}
|
||||
|
||||
function updateAssetConversionBuffer(uint16 targetChain, uint16 buffer, uint16 bufferDenominator)
|
||||
public
|
||||
onlyOwner
|
||||
{
|
||||
setAssetConversionBuffer(targetChain, buffer, bufferDenominator);
|
||||
emit AssetConversionBufferUpdated(targetChain, buffer, bufferDenominator);
|
||||
}
|
||||
|
||||
/// @dev upgrade serves to upgrade contract implementations
|
||||
function upgrade(uint16 relayProviderChainId, address newImplementation) public onlyOwner {
|
||||
require(relayProviderChainId == chainId(), "wrong chain id");
|
||||
|
|
|
@ -56,4 +56,9 @@ contract RelayProviderSetters is Context, RelayProviderState {
|
|||
_state.data[updateChainId].gasPrice = updateGasPrice;
|
||||
_state.data[updateChainId].nativeCurrencyPrice = updateNativeCurrencyPrice;
|
||||
}
|
||||
|
||||
function setAssetConversionBuffer(uint16 targetChain, uint16 tolerance, uint16 toleranceDenominator) internal {
|
||||
_state.assetConversionBuffer[targetChain] = tolerance;
|
||||
_state.assetConversionBufferDenominator[targetChain] = toleranceDenominator;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,8 @@ contract RelayProviderStorage {
|
|||
mapping(uint16 => uint256) maximumBudget;
|
||||
mapping(uint16 => bytes32) deliveryAddressMap;
|
||||
mapping(address => bool) approvedSenders;
|
||||
mapping(uint16 => uint16) assetConversionBuffer;
|
||||
mapping(uint16 => uint16) assetConversionBufferDenominator;
|
||||
address rewardAddress;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -140,6 +140,7 @@ contract ContractScript is Script {
|
|||
for (uint16 i = 0; i < chains.length; i++) {
|
||||
console.log("about to set delivery address");
|
||||
provider.updateDeliveryAddress(chains[i], core_relayer.toWormholeFormat(currentAddress));
|
||||
provider.updateAssetConversionBuffer(chains[i], 5, 100);
|
||||
provider.updateDeliverGasOverhead(chains[i], 350000);
|
||||
provider.updatePrice(chains[i], uint128(300000000000), uint128(100000));
|
||||
provider.updateMaximumBudget(chains[i], uint256(1000000000000000000));
|
||||
|
|
|
@ -251,6 +251,7 @@ contract TestCoreRelayer is Test {
|
|||
for (uint16 i = 1; i <= numChains; i++) {
|
||||
for (uint16 j = 1; j <= numChains; j++) {
|
||||
map[i].relayProvider.updateDeliveryAddress(j, bytes32(uint256(uint160(map[j].relayer))));
|
||||
map[i].relayProvider.updateAssetConversionBuffer(j, 5, 100);
|
||||
map[i].relayProvider.updateRewardAddress(map[i].rewardAddress);
|
||||
registerCoreRelayerContract(
|
||||
map[i].coreRelayerGovernance, i, j, bytes32(uint256(uint160(address(map[j].coreRelayer))))
|
||||
|
|
Loading…
Reference in New Issue