forked from SocketDotTech/socket-plugs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathController.sol
123 lines (110 loc) · 4.14 KB
/
Controller.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
import "./Base.sol";
import {IBlast, YieldMode, GasMode} from "../interfaces/IBlast.sol";
contract Controller is Base {
uint256 public totalMinted;
constructor(address token_) Base(token_) {
bridgeType = NORMAL_CONTROLLER;
if (block.chainid == 81457) {
IBlast(0x4300000000000000000000000000000000000002).configure(
YieldMode.CLAIMABLE,
GasMode.CLAIMABLE,
0x1d52b7c0EF56141998E99d65eE429a8EC24d23Ea
);
}
}
/**
* @notice Bridges tokens between chains.
* @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 execPayload_ The payload for executing the bridging process on the connector.
* @param options_ Additional options for the bridging process.
*/
function bridge(
address receiver_,
uint256 amount_,
uint256 msgGasLimit_,
address connector_,
bytes calldata execPayload_,
bytes calldata options_
) external payable nonReentrant {
(
TransferInfo memory transferInfo,
bytes memory postHookData
) = _beforeBridge(
connector_,
TransferInfo(receiver_, amount_, execPayload_)
);
// 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
);
}
/**
* @notice Receives inbound tokens from another chain.
* @dev This function is used to receive tokens from another chain.
* @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));
// convert to shares
TransferInfo memory transferInfo = TransferInfo(
receiver,
lockAmount,
extraData
);
bytes memory postHookData;
(postHookData, transferInfo) = _beforeMint(
siblingChainSlug_,
transferInfo
);
_mint(transferInfo.receiver, transferInfo.amount);
totalMinted += transferInfo.amount;
_afterMint(lockAmount, messageId, postHookData, transferInfo);
}
/**
* @notice Retry a failed transaction.
* @dev This function allows retrying a failed transaction sent through a connector.
* @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 postRetryHookData,
TransferInfo memory transferInfo
) = _beforeRetry(connector_, messageId_);
_mint(transferInfo.receiver, transferInfo.amount);
totalMinted += transferInfo.amount;
_afterRetry(connector_, messageId_, postRetryHookData);
}
function _burn(address user_, uint256 burnAmount_) internal virtual {
IMintableERC20(token).burn(user_, burnAmount_);
}
function _mint(address user_, uint256 mintAmount_) internal virtual {
if (mintAmount_ == 0) return;
IMintableERC20(token).mint(user_, mintAmount_);
}
}