Skip to content

Commit

Permalink
Merge branch 'master' into permissionless-deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
ameeshaagrawal committed Nov 7, 2023
2 parents 59bece9 + c2f67cb commit 88fb9cc
Show file tree
Hide file tree
Showing 8 changed files with 595 additions and 31 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ LYRA_TESTNET_RPC=''
LYRA_RPC=''

XAI_TESTNET_RPC=''
SX_NETWORK_TESTNET_RPC=''

# etherscan verification
ETHERSCAN_API_KEY=xxx
Expand Down
107 changes: 96 additions & 11 deletions contracts/socket/SocketBatcher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "openzeppelin-contracts/contracts/interfaces/IERC20.sol";
import "../libraries/RescueFundsLib.sol";
import "../utils/AccessControl.sol";
import "../interfaces/ISocket.sol";
import "../interfaces/ICapacitor.sol";
import "../switchboard/default-switchboards/FastSwitchboard.sol";
import "../interfaces/INativeRelay.sol";
import {RESCUE_ROLE} from "../utils/AccessRoles.sol";
Expand Down Expand Up @@ -265,10 +266,10 @@ contract SocketBatcher is AccessControl {
* @param socketAddress_ address of socket
* @param sealRequests_ the list of requests with packets to be sealed on sourceChain
*/
function sealBatch(
function _sealBatch(
address socketAddress_,
SealRequest[] calldata sealRequests_
) external {
) internal {
uint256 sealRequestLength = sealRequests_.length;
for (uint256 index = 0; index < sealRequestLength; ) {
ISocket(socketAddress_).seal(
Expand All @@ -282,15 +283,27 @@ contract SocketBatcher is AccessControl {
}
}

/**
* @notice seal a batch of packets from capacitor on sourceChain mentioned in sealRequests
* @param socketAddress_ address of socket
* @param sealRequests_ the list of requests with packets to be sealed on sourceChain
*/
function sealBatch(
address socketAddress_,
SealRequest[] calldata sealRequests_
) external {
_sealBatch(socketAddress_, sealRequests_);
}

/**
* @notice propose a batch of packets sequentially by socketDestination
* @param socketAddress_ address of socket
* @param proposeRequests_ the list of requests with packets to be proposed by socketDestination
*/
function proposeBatch(
function _proposeBatch(
address socketAddress_,
ProposeRequest[] calldata proposeRequests_
) external {
) internal {
uint256 proposeRequestLength = proposeRequests_.length;
for (uint256 index = 0; index < proposeRequestLength; ) {
ISocket(socketAddress_).proposeForSwitchboard(
Expand All @@ -305,17 +318,26 @@ contract SocketBatcher is AccessControl {
}
}

/**
* @notice propose a batch of packets sequentially by socketDestination
* @param socketAddress_ address of socket
* @param proposeRequests_ the list of requests with packets to be proposed by socketDestination
*/
function proposeBatch(
address socketAddress_,
ProposeRequest[] calldata proposeRequests_
) external {
_proposeBatch(socketAddress_, proposeRequests_);
}

/**
* @notice attests a batch of Packets
* @param attestRequests_ the list of requests with packets to be attested by switchboard in sequence
*/
function attestBatch(
address switchboardAddress_,
AttestRequest[] calldata attestRequests_
) external {
function _attestBatch(AttestRequest[] calldata attestRequests_) internal {
uint256 attestRequestLength = attestRequests_.length;
for (uint256 index = 0; index < attestRequestLength; ) {
FastSwitchboard(switchboardAddress_).attest(
FastSwitchboard(attestRequests_[index].switchboard).attest(
attestRequests_[index].packetId,
attestRequests_[index].proposalCount,
attestRequests_[index].root,
Expand All @@ -327,6 +349,34 @@ contract SocketBatcher is AccessControl {
}
}

/**
* @notice attests a batch of Packets
* @param attestRequests_ the list of requests with packets to be attested by switchboard in sequence
*/
function attestBatch(AttestRequest[] calldata attestRequests_) external {
_attestBatch(attestRequests_);
}

/**
* @notice send a batch of propose, attest and execute transactions
* @param socketAddress_ address of socket
* @param proposeRequests_ the list of requests with packets to be proposed
* @param attestRequests_ the list of requests with packets to be attested by switchboard
* @param executeRequests_ the list of requests with messages to be executed
*/
function sendBatch(
address socketAddress_,
SealRequest[] calldata sealRequests_,
ProposeRequest[] calldata proposeRequests_,
AttestRequest[] calldata attestRequests_,
ExecuteRequest[] calldata executeRequests_
) external payable {
_sealBatch(socketAddress_, sealRequests_);
_proposeBatch(socketAddress_, proposeRequests_);
_attestBatch(attestRequests_);
_executeBatch(socketAddress_, executeRequests_);
}

/**
* @notice trip a batch of Proposals
* @param proposalTripRequests_ the list of requests for tripping proposals
Expand Down Expand Up @@ -363,10 +413,10 @@ contract SocketBatcher is AccessControl {
* @param socketAddress_ address of socket
* @param executeRequests_ the list of requests with messages to be executed in sequence
*/
function executeBatch(
function _executeBatch(
address socketAddress_,
ExecuteRequest[] calldata executeRequests_
) external payable {
) internal {
uint256 executeRequestLength = executeRequests_.length;
uint256 totalMsgValue = msg.value;
for (uint256 index = 0; index < executeRequestLength; ) {
Expand Down Expand Up @@ -394,6 +444,18 @@ contract SocketBatcher is AccessControl {
}
}

/**
* @notice executes a batch of messages
* @param socketAddress_ address of socket
* @param executeRequests_ the list of requests with messages to be executed in sequence
*/
function executeBatch(
address socketAddress_,
ExecuteRequest[] calldata executeRequests_
) external payable {
_executeBatch(socketAddress_, executeRequests_);
}

/**
* @notice invoke receive Message on PolygonRootReceiver for a batch of messages in loop
* @param polygonRootReceiverAddress_ address of polygonRootReceiver
Expand Down Expand Up @@ -439,6 +501,29 @@ contract SocketBatcher is AccessControl {
return proposalCounts;
}

/**
* @notice returns root for capacitorAddress and count
* @param capacitorAddresses_ addresses of capacitor
* @param packetCounts_ the list of packetCounts
*/
function getPacketRootBatch(
address[] calldata capacitorAddresses_,
uint64[] calldata packetCounts_
) external view returns (bytes32[] memory) {
uint256 capacitorAddressesLength = capacitorAddresses_.length;

bytes32[] memory packetRoots = new bytes32[](capacitorAddressesLength);

for (uint256 index = 0; index < capacitorAddressesLength; ) {
packetRoots[index] = ICapacitor(capacitorAddresses_[index])
.getRootByCount(packetCounts_[index]);
unchecked {
++index;
}
}
return packetRoots;
}

/**
* @notice initiate NativeConfirmation on arbitrumChain for a batch of packets in loop
* @param switchboardAddress_ address of nativeArbitrumSwitchboard
Expand Down
Loading

0 comments on commit 88fb9cc

Please sign in to comment.