Relayer new delivery provider implementation (#3088)
* WIP * Pricing Wallet test * Give owner same permissions as price oracle
This commit is contained in:
parent
57562cc50e
commit
12b18d4ccc
|
@ -17,6 +17,10 @@ contract DeliveryProviderGetters is DeliveryProviderState {
|
||||||
return _state.pendingOwner;
|
return _state.pendingOwner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function pricingWallet() public view returns (address) {
|
||||||
|
return _state.pricingWallet;
|
||||||
|
}
|
||||||
|
|
||||||
function isInitialized(address impl) public view returns (bool) {
|
function isInitialized(address impl) public view returns (bool) {
|
||||||
return _state.initializedImplementations[impl];
|
return _state.initializedImplementations[impl];
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ abstract contract DeliveryProviderGovernance is
|
||||||
error AddressIsZero();
|
error AddressIsZero();
|
||||||
error CallerMustBePendingOwner();
|
error CallerMustBePendingOwner();
|
||||||
error CallerMustBeOwner();
|
error CallerMustBeOwner();
|
||||||
|
error CallerMustBeOwnerOrPricingWallet();
|
||||||
|
|
||||||
event ContractUpgraded(address indexed oldContract, address indexed newContract);
|
event ContractUpgraded(address indexed oldContract, address indexed newContract);
|
||||||
event ChainSupportUpdated(uint16 targetChain, bool isSupported);
|
event ChainSupportUpdated(uint16 targetChain, bool isSupported);
|
||||||
|
@ -69,6 +70,10 @@ abstract contract DeliveryProviderGovernance is
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updatePricingWallet(address newPricingWallet) external onlyOwner {
|
||||||
|
setPricingWallet(newPricingWallet);
|
||||||
|
}
|
||||||
|
|
||||||
function updateSupportedChainImpl(uint16 targetChain, bool isSupported) internal {
|
function updateSupportedChainImpl(uint16 targetChain, bool isSupported) internal {
|
||||||
setChainSupported(targetChain, isSupported);
|
setChainSupported(targetChain, isSupported);
|
||||||
emit ChainSupportUpdated(targetChain, isSupported);
|
emit ChainSupportUpdated(targetChain, isSupported);
|
||||||
|
@ -106,13 +111,13 @@ abstract contract DeliveryProviderGovernance is
|
||||||
emit TargetChainAddressUpdated(targetChain, newAddress);
|
emit TargetChainAddressUpdated(targetChain, newAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateDeliverGasOverhead(uint16 chainId, Gas newGasOverhead) external onlyOwner {
|
function updateDeliverGasOverhead(uint16 chainId, Gas newGasOverhead) external onlyOwnerOrPricingWallet {
|
||||||
updateDeliverGasOverheadImpl(chainId, newGasOverhead);
|
updateDeliverGasOverheadImpl(chainId, newGasOverhead);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateDeliverGasOverheads(
|
function updateDeliverGasOverheads(
|
||||||
DeliveryProviderStructs.DeliverGasOverheadUpdate[] memory overheadUpdates
|
DeliveryProviderStructs.DeliverGasOverheadUpdate[] memory overheadUpdates
|
||||||
) external onlyOwner {
|
) external onlyOwnerOrPricingWallet {
|
||||||
uint256 updatesLength = overheadUpdates.length;
|
uint256 updatesLength = overheadUpdates.length;
|
||||||
for (uint256 i = 0; i < updatesLength;) {
|
for (uint256 i = 0; i < updatesLength;) {
|
||||||
DeliveryProviderStructs.DeliverGasOverheadUpdate memory update = overheadUpdates[i];
|
DeliveryProviderStructs.DeliverGasOverheadUpdate memory update = overheadUpdates[i];
|
||||||
|
@ -133,13 +138,13 @@ abstract contract DeliveryProviderGovernance is
|
||||||
uint16 updateChainId,
|
uint16 updateChainId,
|
||||||
GasPrice updateGasPrice,
|
GasPrice updateGasPrice,
|
||||||
WeiPrice updateNativeCurrencyPrice
|
WeiPrice updateNativeCurrencyPrice
|
||||||
) external onlyOwner {
|
) external onlyOwnerOrPricingWallet {
|
||||||
updatePriceImpl(updateChainId, updateGasPrice, updateNativeCurrencyPrice);
|
updatePriceImpl(updateChainId, updateGasPrice, updateNativeCurrencyPrice);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updatePrices(DeliveryProviderStructs.UpdatePrice[] memory updates)
|
function updatePrices(DeliveryProviderStructs.UpdatePrice[] memory updates)
|
||||||
external
|
external
|
||||||
onlyOwner
|
onlyOwnerOrPricingWallet
|
||||||
{
|
{
|
||||||
uint256 pricesLength = updates.length;
|
uint256 pricesLength = updates.length;
|
||||||
for (uint256 i = 0; i < pricesLength;) {
|
for (uint256 i = 0; i < pricesLength;) {
|
||||||
|
@ -169,13 +174,13 @@ abstract contract DeliveryProviderGovernance is
|
||||||
setPriceInfo(updateChainId, updateGasPrice, updateNativeCurrencyPrice);
|
setPriceInfo(updateChainId, updateGasPrice, updateNativeCurrencyPrice);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateMaximumBudget(uint16 targetChain, Wei maximumTotalBudget) external onlyOwner {
|
function updateMaximumBudget(uint16 targetChain, Wei maximumTotalBudget) external onlyOwnerOrPricingWallet {
|
||||||
setMaximumBudget(targetChain, maximumTotalBudget);
|
setMaximumBudget(targetChain, maximumTotalBudget);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateMaximumBudgets(DeliveryProviderStructs.MaximumBudgetUpdate[] memory updates)
|
function updateMaximumBudgets(DeliveryProviderStructs.MaximumBudgetUpdate[] memory updates)
|
||||||
external
|
external
|
||||||
onlyOwner
|
onlyOwnerOrPricingWallet
|
||||||
{
|
{
|
||||||
uint256 updatesLength = updates.length;
|
uint256 updatesLength = updates.length;
|
||||||
for (uint256 i = 0; i < updatesLength;) {
|
for (uint256 i = 0; i < updatesLength;) {
|
||||||
|
@ -191,13 +196,13 @@ abstract contract DeliveryProviderGovernance is
|
||||||
uint16 targetChain,
|
uint16 targetChain,
|
||||||
uint16 buffer,
|
uint16 buffer,
|
||||||
uint16 bufferDenominator
|
uint16 bufferDenominator
|
||||||
) external onlyOwner {
|
) external onlyOwnerOrPricingWallet {
|
||||||
updateAssetConversionBufferImpl(targetChain, buffer, bufferDenominator);
|
updateAssetConversionBufferImpl(targetChain, buffer, bufferDenominator);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateAssetConversionBuffers(
|
function updateAssetConversionBuffers(
|
||||||
DeliveryProviderStructs.AssetConversionBufferUpdate[] memory updates
|
DeliveryProviderStructs.AssetConversionBufferUpdate[] memory updates
|
||||||
) external onlyOwner {
|
) external onlyOwnerOrPricingWallet {
|
||||||
uint256 updatesLength = updates.length;
|
uint256 updatesLength = updates.length;
|
||||||
for (uint256 i = 0; i < updatesLength;) {
|
for (uint256 i = 0; i < updatesLength;) {
|
||||||
DeliveryProviderStructs.AssetConversionBufferUpdate memory update = updates[i];
|
DeliveryProviderStructs.AssetConversionBufferUpdate memory update = updates[i];
|
||||||
|
@ -326,4 +331,11 @@ abstract contract DeliveryProviderGovernance is
|
||||||
}
|
}
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
modifier onlyOwnerOrPricingWallet() {
|
||||||
|
if ((pricingWallet() != _msgSender()) && (owner() != _msgSender())) {
|
||||||
|
revert CallerMustBeOwnerOrPricingWallet();
|
||||||
|
}
|
||||||
|
_;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,10 @@ contract DeliveryProviderSetters is Context, DeliveryProviderState {
|
||||||
_state.chainId = thisChain;
|
_state.chainId = thisChain;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setPricingWallet(address newPricingWallet) internal {
|
||||||
|
_state.pricingWallet = newPricingWallet;
|
||||||
|
}
|
||||||
|
|
||||||
function setWormholeRelayer(address payable coreRelayer) internal {
|
function setWormholeRelayer(address payable coreRelayer) internal {
|
||||||
_state.coreRelayer = coreRelayer;
|
_state.coreRelayer = coreRelayer;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,8 @@ contract DeliveryProviderStorage {
|
||||||
address owner;
|
address owner;
|
||||||
// Pending target of ownership transfer.
|
// Pending target of ownership transfer.
|
||||||
address pendingOwner;
|
address pendingOwner;
|
||||||
|
// Address that is allowed to modify pricing
|
||||||
|
address pricingWallet;
|
||||||
// Address of the core relayer contract.
|
// Address of the core relayer contract.
|
||||||
address coreRelayer;
|
address coreRelayer;
|
||||||
// Dictionary of implementation contract -> initialized flag
|
// Dictionary of implementation contract -> initialized flag
|
||||||
|
|
|
@ -100,23 +100,36 @@ contract TestDeliveryProvider is Test {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testCanUpdatePriceOnlyAsOwner(
|
function testCanUpdatePriceOnlyAsOwnerOrPriceWallet(
|
||||||
address oracleOwner,
|
address pricingWallet,
|
||||||
|
address maliciousUser,
|
||||||
uint16 updateChainId,
|
uint16 updateChainId,
|
||||||
GasPrice updateGasPrice,
|
GasPrice updateGasPrice,
|
||||||
WeiPrice updateNativeCurrencyPrice
|
WeiPrice updateNativeCurrencyPrice
|
||||||
) public {
|
) public {
|
||||||
vm.assume(oracleOwner != address(0));
|
vm.assume(maliciousUser != address(0));
|
||||||
vm.assume(oracleOwner != address(this));
|
vm.assume(pricingWallet != address(0));
|
||||||
|
vm.assume(maliciousUser != pricingWallet);
|
||||||
|
vm.assume(maliciousUser != address(this));
|
||||||
vm.assume(updateChainId > 0);
|
vm.assume(updateChainId > 0);
|
||||||
vm.assume(updateGasPrice.unwrap() > 0);
|
vm.assume(updateGasPrice.unwrap() > 0);
|
||||||
vm.assume(updateNativeCurrencyPrice.unwrap() > 0);
|
vm.assume(updateNativeCurrencyPrice.unwrap() > 0);
|
||||||
|
vm.assume(updateGasPrice.unwrap() < type(uint64).max);
|
||||||
|
vm.assume(updateNativeCurrencyPrice.unwrap() < type(uint128).max);
|
||||||
|
|
||||||
initializeDeliveryProvider();
|
initializeDeliveryProvider();
|
||||||
|
deliveryProvider.updatePricingWallet(pricingWallet);
|
||||||
|
|
||||||
// you shall not pass
|
// you shall not pass
|
||||||
vm.prank(oracleOwner);
|
vm.prank(maliciousUser);
|
||||||
vm.expectRevert(abi.encodeWithSignature("CallerMustBeOwner()"));
|
vm.expectRevert(abi.encodeWithSignature("CallerMustBeOwnerOrPricingWallet()"));
|
||||||
|
deliveryProvider.updatePrice(updateChainId, updateGasPrice, updateNativeCurrencyPrice);
|
||||||
|
|
||||||
|
// pricing wallet
|
||||||
|
vm.prank(pricingWallet);
|
||||||
|
deliveryProvider.updatePrice(updateChainId, updateGasPrice, updateNativeCurrencyPrice);
|
||||||
|
|
||||||
|
// owner
|
||||||
deliveryProvider.updatePrice(updateChainId, updateGasPrice, updateNativeCurrencyPrice);
|
deliveryProvider.updatePrice(updateChainId, updateGasPrice, updateNativeCurrencyPrice);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,6 +302,8 @@ contract TestDeliveryProvider is Test {
|
||||||
|
|
||||||
vm.assume(gasOverhead < uint256(2)**31);
|
vm.assume(gasOverhead < uint256(2)**31);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// update the prices with reasonable values
|
// update the prices with reasonable values
|
||||||
deliveryProvider.updatePrice(
|
deliveryProvider.updatePrice(
|
||||||
dstChainId, GasPrice.wrap(dstGasPrice), WeiPrice.wrap(dstNativeCurrencyPrice)
|
dstChainId, GasPrice.wrap(dstGasPrice), WeiPrice.wrap(dstNativeCurrencyPrice)
|
||||||
|
|
Loading…
Reference in New Issue