Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usual deployment #151

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 45 additions & 42 deletions contracts/bridge/Controller.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,49 @@ contract Controller is Base {
address connector_,
bytes calldata extraData_,
bytes calldata options_
) external payable nonReentrant {
(
TransferInfo memory transferInfo,
bytes memory postHookData
) = _beforeBridge(
connector_,
TransferInfo(receiver_, amount_, extraData_)
);
) public payable nonReentrant {
(TransferInfo memory transferInfo, bytes memory postHookData) =
_beforeBridge(connector_, TransferInfo(receiver_, amount_, extraData_));

// to maintain socket dl specific accounting for super token
// re check this logic for mint and mint use cases and if other minter involved
totalMinted -= transferInfo.amount;
_burn(msg.sender, transferInfo.amount);
_afterBridge(
msgGasLimit_,
connector_,
options_,
postHookData,
transferInfo
);
_afterBridge(msgGasLimit_, connector_, options_, postHookData, transferInfo);
}

/**
* @notice Bridges tokens between chains with permit.
* @dev This function allows bridging tokens between different chains.
* @param receiver_ The address to receive the bridged tokens.
* @param amount_ The amount of tokens to bridge.
* @param msgGasLimit_ The gas limit for the execution of the bridging process.
* @param connector_ The address of the connector contract responsible for the bridge.
* @param extraData_ The extra data passed to hook functions.
* @param options_ Additional options for the bridging process.
* @param deadline_ The deadline for the permit signature.
* @param v_ The recovery id of the permit signature.
* @param r_ The r value of the permit signature.
* @param s_ The s value of the permit signature.
*/
function bridgeWithPermit(
address receiver_,
uint256 amount_,
uint256 msgGasLimit_,
address connector_,
bytes calldata execPayload_,
bytes calldata options_,
uint256 deadline_,
uint8 v_,
bytes32 r_,
bytes32 s_
) external payable {

try ERC20(token).permit(msg.sender, address(this), amount_, deadline_, v_, r_, s_) {
bridge(receiver_, amount_, msgGasLimit_, connector_, execPayload_, options_);
} catch {
bridge(receiver_, amount_, msgGasLimit_, connector_, extraData_, options_);
}
}

/**
Expand All @@ -55,28 +78,14 @@ contract Controller is Base {
* @param siblingChainSlug_ The identifier of the sibling chain.
* @param payload_ The payload containing the inbound tokens.
*/
function receiveInbound(
uint32 siblingChainSlug_,
bytes memory payload_
) external payable override nonReentrant {
(
address receiver,
uint256 lockAmount,
bytes32 messageId,
bytes memory extraData
) = abi.decode(payload_, (address, uint256, bytes32, bytes));
function receiveInbound(uint32 siblingChainSlug_, bytes memory payload_) external payable override nonReentrant {
(address receiver, uint256 lockAmount, bytes32 messageId, bytes memory extraData) =
abi.decode(payload_, (address, uint256, bytes32, bytes));

// convert to shares
TransferInfo memory transferInfo = TransferInfo(
receiver,
lockAmount,
extraData
);
TransferInfo memory transferInfo = TransferInfo(receiver, lockAmount, extraData);
bytes memory postHookData;
(postHookData, transferInfo) = _beforeMint(
siblingChainSlug_,
transferInfo
);
(postHookData, transferInfo) = _beforeMint(siblingChainSlug_, transferInfo);

_mint(transferInfo.receiver, transferInfo.amount);
totalMinted += transferInfo.amount;
Expand All @@ -90,14 +99,8 @@ contract Controller is Base {
* @param connector_ The address of the connector contract responsible for the failed transaction.
* @param messageId_ The unique identifier of the failed transaction.
*/
function retry(
address connector_,
bytes32 messageId_
) external nonReentrant {
(
bytes memory postHookData,
TransferInfo memory transferInfo
) = _beforeRetry(connector_, messageId_);
function retry(address connector_, bytes32 messageId_) external nonReentrant {
(bytes memory postHookData, TransferInfo memory transferInfo) = _beforeRetry(connector_, messageId_);
_mint(transferInfo.receiver, transferInfo.amount);
totalMinted += transferInfo.amount;

Expand Down
49 changes: 48 additions & 1 deletion contracts/bridge/Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ contract Vault is Base {
address connector_,
bytes calldata extraData_,
bytes calldata options_
) external payable nonReentrant {
) public payable nonReentrant {
(
TransferInfo memory transferInfo,
bytes memory postHookData
Expand All @@ -59,6 +59,40 @@ contract Vault is Base {
);
}

/**
* @notice Bridges tokens between chains with permit.
* @dev This function allows bridging tokens between different chains.
* @param receiver_ The address to receive the bridged tokens.
* @param amount_ The amount of tokens to bridge.
* @param msgGasLimit_ The gas limit for the execution of the bridging process.
* @param connector_ The address of the connector contract responsible for the bridge.
* @param extraData_ The extra data passed to hook functions.
* @param options_ Additional options for the bridging process.
* @param deadline_ The deadline for the permit signature.
* @param v_ The recovery id of the permit signature.
* @param r_ The r value of the permit signature.
* @param s_ The s value of the permit signature.
*/
function bridgeWithPermit(
address receiver_,
uint256 amount_,
uint256 msgGasLimit_,
address connector_,
bytes calldata execPayload_,
bytes calldata options_,
uint256 deadline_,
uint8 v_,
bytes32 r_,
bytes32 s_
) external payable {

try ERC20(token).permit(msg.sender, address(this), amount_, deadline_, v_, r_, s_) {
bridge(receiver_, amount_, msgGasLimit_, connector_, execPayload_, options_);
} catch {
bridge(receiver_, amount_, msgGasLimit_, connector_, extraData_, options_);
}
}

/**
* @notice Receives inbound tokens from another chain.
* @dev This function is used to receive tokens from another chain.
Expand Down Expand Up @@ -112,6 +146,19 @@ contract Vault is Base {
_afterRetry(connector_, messageId_, postHookData);
}

/**
* @notice Disperse rewards, will be used for dispersing rewards in the future.
* @dev reward token can not be locked token.
* @param receiver_ The address to receive the rewards.
* @param amount_ The amount of rewards to disperse.
* @param rewardToken_ The address of the reward token.
*/
function disperseRewards(address receiver_, uint256 amount_, address rewardToken_) external onlyOwner {
if (rewardToken_ == token) revert("Vault: reward token is same as token");
ERC20(rewardToken_).safeTransfer(receiver_, amount_);
}


function _transferTokens(address receiver_, uint256 amount_) internal {
if (amount_ == 0) return;
if (address(token) == ETH_ADDRESS) {
Expand Down