Skip to content

Commit

Permalink
feat: added payload examples
Browse files Browse the repository at this point in the history
  • Loading branch information
sendra committed Jun 6, 2024
1 parent c9d89cf commit 8ae6a3b
Show file tree
Hide file tree
Showing 11 changed files with 780 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import 'forge-std/Script.sol';
import 'forge-std/console2.sol';

import {ICrossChainReceiver} from 'adi/interfaces/ICrossChainReceiver.sol';

/**
* @notice Deploys a payload with a single function that allows new receiver bridge adapters.
*
* @dev Remember to update the receiver address and allowAdapterInputs array length and members.
* An example is provided.
*
* Run with:
* forge script scripts/create_payloads/Payload_AllowReceiverBridgeAdapters.s.s.sol --tc CreateReceiverAllowBridgeAdaptersPayload
*/
contract ReceiverAllowBridgeAdaptersPayload {
/// @dev Replace with the address of the CrossChainReceiver contract.
ICrossChainReceiver constant RECEIVER = ICrossChainReceiver(address(0));

function execute() external {
/// @dev Replace with the adapters and associated chain IDs.
ICrossChainReceiver.ReceiverBridgeAdapterConfigInput[]
memory allowAdapterInputs = new ICrossChainReceiver.ReceiverBridgeAdapterConfigInput[](0);
// allowAdapterInputs[0] = ICrossChainReceiver.ReceiverBridgeAdapterConfigInput({
// bridgeAdapter: address(0),
// chainIds: new uint256[](0)
// });

RECEIVER.allowReceiverBridgeAdapters(allowAdapterInputs);
}
}

contract CreateReceiverAllowBridgeAdaptersPayload is Script {
function run() public {
vm.startBroadcast(vm.envUint('PRIVATE_KEY'));
ReceiverAllowBridgeAdaptersPayload receiverAllowBridgeAdaptersPayload = new ReceiverAllowBridgeAdaptersPayload();
console2.log(
'ReceiverAllowBridgeAdaptersPayload deployed at %s on chain with chain ID %s',
address(receiverAllowBridgeAdaptersPayload),
block.chainid
);
vm.stopBroadcast();
}
}
41 changes: 41 additions & 0 deletions scripts/payloads/examples/Payload_ApproveForwarderSenders.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import 'forge-std/Script.sol';
import 'forge-std/console2.sol';

import {ICrossChainForwarder} from 'adi/interfaces/ICrossChainForwarder.sol';

/**
* @notice Deploys a payload with a single function that approves forwarder senders.
*
* @dev Remember to update the sendersToApprove array length and members.
*
* Run with:
* forge script scripts/create_payloads/Payload_ApproveForwarderSenders.s.s.sol --tc CreateApproveForwarderSendersPayload
*/
contract ApproveForwarderSendersPayload {
/// @dev Replace with the address of the CrossChainForwarder contract.
ICrossChainForwarder constant FORWARDER = ICrossChainForwarder(address(0));

function execute() external {
/// @dev Replace with the senders to approve.
address[] memory sendersToApprove = new address[](0);
// sendersToApprove[0] = adress(0);

FORWARDER.approveSenders(sendersToApprove);
}
}

contract CreateApproveForwarderSendersPayload is Script {
function run() public {
vm.startBroadcast(vm.envUint('PRIVATE_KEY'));
ApproveForwarderSendersPayload approveForwarderSendersPayload = new ApproveForwarderSendersPayload();
console2.log(
'ApproveForwarderSendersPayload deployed at %s on chain with chain ID %s',
address(approveForwarderSendersPayload),
block.chainid
);
vm.stopBroadcast();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import 'forge-std/Script.sol';
import 'forge-std/console2.sol';

import {ICrossChainForwarder} from 'adi/interfaces/ICrossChainForwarder.sol';

/**
* @notice Deploys a payload with a single function that disables forwarder bridge adapters.
*
* @dev Remember to update the adaptersToDisable array length and members.
*
* Run with:
* forge script scripts/create_payloads/Payload_DisableForwarderBridgeAdapters.s.s.sol --tc CreateDisableForwarderBridgeAdaptersPayload
*/
contract DisableForwarderBridgeAdaptersPayload {
/// @dev Replace with the address of the CrossChainForwarder contract.
ICrossChainForwarder constant FORWARDER = ICrossChainForwarder(address(0));

function execute() external {
/// @dev Replace with the forwarder bridge adapters to disable.
ICrossChainForwarder.BridgeAdapterToDisable[]
memory adaptersToDisable = new ICrossChainForwarder.BridgeAdapterToDisable[](1);
// adaptersToDisable[0] = ICrossChainForwarder.BridgeAdapterToDisable({
// bridgeAdapter: address(0),
// chainIds: new uint256[](0)
// });

FORWARDER.disableBridgeAdapters(adaptersToDisable);
}
}

contract CreateDisableForwarderBridgeAdaptersPayload is Script {
function run() public {
vm.startBroadcast(vm.envUint('PRIVATE_KEY'));
DisableForwarderBridgeAdaptersPayload disableForwarderBridgeAdaptersPayload = new DisableForwarderBridgeAdaptersPayload();
console2.log(
'DisableForwarderBridgeAdaptersPayload deployed at %s on chain with chain ID %s',
address(disableForwarderBridgeAdaptersPayload),
block.chainid
);
vm.stopBroadcast();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import 'forge-std/Script.sol';
import 'forge-std/console2.sol';

import {ICrossChainReceiver} from 'adi/interfaces/ICrossChainReceiver.sol';

/**
* @notice Deploys a payload with a single function that disallows receiver bridge adapters.
*
* @dev Remember to update the receiver address and disallowAdapterInputs array length and members.
* An example is provided.
*
* Run with:
* forge script scripts/create_payloads/Payload_DisallowReceiverBridgeAdapters.s.s.sol --tc CreateReceiverDisallowBridgeAdaptersPayload
*/
contract ReceiverDisallowBridgeAdaptersPayload {
/// @dev Replace with the address of the CrossChainReceiver contract.
ICrossChainReceiver constant RECEIVER = ICrossChainReceiver(address(0));

function execute() external {
/// @dev Replace with the adapters and associated chain IDs.
ICrossChainReceiver.ReceiverBridgeAdapterConfigInput[]
memory disallowAdapterInputs = new ICrossChainReceiver.ReceiverBridgeAdapterConfigInput[](0);
// disallowAdapterInputs[0] = ICrossChainReceiver.ReceiverBridgeAdapterConfigInput({
// bridgeAdapter: address(0),
// chainIds: new uint256[](0)
// });

RECEIVER.disallowReceiverBridgeAdapters(disallowAdapterInputs);
}
}

contract CreateReceiverDisallowBridgeAdaptersPayload is Script {
function run() public {
vm.startBroadcast(vm.envUint('PRIVATE_KEY'));
ReceiverDisallowBridgeAdaptersPayload receiverDisallowBridgeAdaptersPayload = new ReceiverDisallowBridgeAdaptersPayload();
console2.log(
'ReceiverDisallowBridgeAdaptersPayload deployed at %s on chain with chain ID %s',
address(receiverDisallowBridgeAdaptersPayload),
block.chainid
);
vm.stopBroadcast();
}
}
44 changes: 44 additions & 0 deletions scripts/payloads/examples/Payload_Emergency.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import 'forge-std/Script.sol';
import 'forge-std/console2.sol';
import {IEmergencyRegistry} from 'adi/emergency/interfaces/IEmergencyRegistry.sol';

/**
* @notice Deploys a payload with a single `execute()` function that enables emergency mode
* on the given chains.
*
* @dev Remember to update the emergency registry address and the emergencyChains array length and members.
* Examples are provided.
*
* Run with:
* forge script scripts/create_payloads/Payload_Emergency.s.sol --tc CreateEmergencyPayload
*/
contract EmergencyPayload {
/// @dev Replace with the address of the EmergencyRegistry contract.
IEmergencyRegistry constant EMERGENCY_REGISTRY = IEmergencyRegistry(address(0));

function execute() external {
/// @dev Replace with the chains to enable emergency mode on.
// Replace the "0" with the number of chains, then set each one like in the comment.
uint256[] memory emergencyChains = new uint256[](0);
// emergencyChains[0] = 1;
// emergencyChains[1] = 2;

EMERGENCY_REGISTRY.setEmergency(emergencyChains);
}
}

contract CreateEmergencyPayload is Script {
function run() public {
vm.startBroadcast(vm.envUint('PRIVATE_KEY'));
EmergencyPayload emergencyPayload = new EmergencyPayload();
console2.log(
'EmergencyPayload deployed at %s on chain with chain ID %s',
address(emergencyPayload),
block.chainid
);
vm.stopBroadcast();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import 'forge-std/Script.sol';
import 'forge-std/console2.sol';

import {ICrossChainForwarder} from 'adi/interfaces/ICrossChainForwarder.sol';

/**
* @notice Deploys a payload with a single function that enables forwarder bridge adapters.
*
* @dev Remember to update the adaptersToEnable array length and members.
*
* Run with:
* forge script scripts/create_payloads/Payload_EnableForwarderBridgeAdapters.s.s.sol --tc CreateEnableForwarderBridgeAdaptersPayload
*/
contract EnableForwarderBridgeAdaptersPayload {
/// @dev Replace with the address of the CrossChainForwarder contract.
ICrossChainForwarder constant FORWARDER = ICrossChainForwarder(address(0));

function execute() external {
/// @dev Replace with the forwarder bridge adapters to enable.
ICrossChainForwarder.ForwarderBridgeAdapterConfigInput[]
memory adaptersToEnable = new ICrossChainForwarder.ForwarderBridgeAdapterConfigInput[](0);
// adaptersToEnable[0] = ICrossChainForwarder.ForwarderBridgeAdapterConfigInput({
// currentChainBridgeAdapter: address(0),
// destinationBridgeAdapter: address(0),
// destinationChainId: 0
// });

FORWARDER.enableBridgeAdapters(adaptersToEnable);
}
}

contract CreateEnableForwarderBridgeAdaptersPayload is Script {
function run() public {
vm.startBroadcast(vm.envUint('PRIVATE_KEY'));
EnableForwarderBridgeAdaptersPayload enableForwarderBridgeAdaptersPayload = new EnableForwarderBridgeAdaptersPayload();
console2.log(
'EnableForwarderBridgeAdaptersPayload deployed at %s on chain with chain ID %s',
address(enableForwarderBridgeAdaptersPayload),
block.chainid
);
vm.stopBroadcast();
}
}
45 changes: 45 additions & 0 deletions scripts/payloads/examples/Payload_MessageValidity.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import 'forge-std/Script.sol';
import 'forge-std/console2.sol';

import {ICrossChainReceiver} from 'adi/interfaces/ICrossChainReceiver.sol';

/**
* @notice Deploys a payload with a single function that updates receiver message validity timestamps.
*
* @dev Remember to update the receiver address and validityTimestampInputs array length and members.
* An example is provided.
*
* Run with:
* forge script scripts/create_payloads/Payload_MessageValidity.s.sol --tc CreateMessageValidityPayload
*/
contract MessageValidityPayload {
/// @dev Replace with the address of the CrossChainReceiver contract.
ICrossChainReceiver constant RECEIVER = ICrossChainReceiver(address(0));

function execute() external {
ICrossChainReceiver.ValidityTimestampInput[]
memory validityTimestampInputs = new ICrossChainReceiver.ValidityTimestampInput[](0);
// validityTimestampInputs[0] = ICrossChainReceiver.ValidityTimestampInput({
// chainId: 1,
// validityTimestamp: 1
// });

RECEIVER.updateMessagesValidityTimestamp(validityTimestampInputs);
}
}

contract CreateMessageValidityPayload is Script {
function run() public {
vm.startBroadcast(vm.envUint('PRIVATE_KEY'));
MessageValidityPayload messagesValidityPayload = new MessageValidityPayload();
console2.log(
'MessageValidityPayload deployed at %s on chain with chain ID %s',
address(messagesValidityPayload),
block.chainid
);
vm.stopBroadcast();
}
}
46 changes: 46 additions & 0 deletions scripts/payloads/examples/Payload_ReceiverConfirmations.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import 'forge-std/Script.sol';
import 'forge-std/console2.sol';

import {ICrossChainReceiver} from 'adi/interfaces/ICrossChainReceiver.sol';

/**
* @notice Deploys a payload with a single function that updates receiver confirmations.
*
* @dev Remember to update the receiver address and confirmationInputs array length and members.
* An example is provided.
*
* Run with:
* forge script scripts/create_payloads/Payload_ReceiverConfirmations.s.sol --tc CreateReceiverConfirmationsPayload
*/
contract ReceiverConfirmationsPayload {
/// @dev Replace with the address of the CrossChainReceiver contract.
ICrossChainReceiver constant RECEIVER = ICrossChainReceiver(address(0));

function execute() external {
/// @dev Replace with the chain IDs and required confirmations.
ICrossChainReceiver.ConfirmationInput[]
memory confirmationInputs = new ICrossChainReceiver.ConfirmationInput[](0);
// confirmationInputs[0] = ICrossChainReceiver.ConfirmationInput({
// chainId: 1,
// requiredConfirmations: 1
// });

RECEIVER.updateConfirmations(confirmationInputs);
}
}

contract CreateReceiverConfirmationsPayload is Script {
function run() public {
vm.startBroadcast(vm.envUint('PRIVATE_KEY'));
ReceiverConfirmationsPayload receiverConfirmationsPayload = new ReceiverConfirmationsPayload();
console2.log(
'ReceiverConfirmationsPayload deployed at %s on chain with chain ID %s',
address(receiverConfirmationsPayload),
block.chainid
);
vm.stopBroadcast();
}
}
Loading

0 comments on commit 8ae6a3b

Please sign in to comment.