ethereum: whitespace + docs

This commit is contained in:
Csongor Kiss 2022-05-27 12:56:25 +02:00 committed by Evan Gray
parent fe687783c0
commit 5a4ce6ab51
1 changed files with 178 additions and 49 deletions

View File

@ -42,16 +42,11 @@ contract Bridge is BridgeGovernance, ReentrancyGuard {
BridgeStructs.AssetMeta memory meta = BridgeStructs.AssetMeta({
payloadID : 2,
// Address of the token. Left-zero-padded if shorter than 32 bytes
tokenAddress : bytes32(uint256(uint160(tokenAddress))),
// Chain ID of the token
tokenChain : chainId(),
// Number of decimals of the token (big-endian uint8)
decimals : decimals,
// Symbol of the token (UTF-8)
symbol : symbol,
// Name of the token (UTF-8)
name : name
tokenAddress : bytes32(uint256(uint160(tokenAddress))), // Address of the token. Left-zero-padded if shorter than 32 bytes
tokenChain : chainId(), // Chain ID of the token
decimals : decimals, // Number of decimals of the token (big-endian uint8)
symbol : symbol, // Symbol of the token (UTF-8)
name : name // Name of the token (UTF-8)
});
bytes memory encoded = encodeAssetMeta(meta);
@ -61,14 +56,61 @@ contract Bridge is BridgeGovernance, ReentrancyGuard {
}(nonce, encoded, 15);
}
function wrapAndTransferETH(uint16 recipientChain, bytes32 recipient, uint256 arbiterFee, uint32 nonce) public payable returns (uint64 sequence) {
BridgeStructs.TransferResult memory transferResult = _wrapAndTransferETH(arbiterFee);
sequence = logTransfer(transferResult.tokenChain, transferResult.tokenAddress, transferResult.normalizedAmount, recipientChain, recipient, transferResult.normalizedArbiterFee, transferResult.wormholeFee, nonce);
/*
* @notice Send eth through portal by first wrapping it to WETH.
*/
function wrapAndTransferETH(
uint16 recipientChain,
bytes32 recipient,
uint256 arbiterFee,
uint32 nonce
) public payable returns (uint64 sequence) {
BridgeStructs.TransferResult
memory transferResult = _wrapAndTransferETH(arbiterFee);
sequence = logTransfer(
transferResult.tokenChain,
transferResult.tokenAddress,
transferResult.normalizedAmount,
recipientChain,
recipient,
transferResult.normalizedArbiterFee,
transferResult.wormholeFee,
nonce
);
}
function wrapAndTransferETHWithPayload(uint16 recipientChain, bytes32 recipient, uint256 arbiterFee, uint32 nonce, bytes memory payload) public payable returns (uint64 sequence) {
BridgeStructs.TransferResult memory transferResult = _wrapAndTransferETH(arbiterFee);
sequence = logTransferWithPayload(transferResult.tokenChain, transferResult.tokenAddress, transferResult.normalizedAmount, recipientChain, recipient, transferResult.normalizedArbiterFee, transferResult.wormholeFee, nonce, payload);
/*
* @notice Send eth through portal by first wrapping it.
*
* @dev This type of transfer is called a "contract-controlled transfer".
* There are three differences from a regular token transfer:
* 1) Additional arbitrary payload can be attached to the message
* 2) Only the recipient (typically a contract) can redeem the transaction
* 3) The sender's address (msg.sender) is also included in the transaction payload
*
* With these three additional components, xDapps can implement cross-chain
* composable interactions.
*/
function wrapAndTransferETHWithPayload(
uint16 recipientChain,
bytes32 recipient,
uint256 arbiterFee,
uint32 nonce,
bytes memory payload
) public payable returns (uint64 sequence) {
BridgeStructs.TransferResult
memory transferResult = _wrapAndTransferETH(arbiterFee);
sequence = logTransferWithPayload(
transferResult.tokenChain,
transferResult.tokenAddress,
transferResult.normalizedAmount,
recipientChain,
recipient,
transferResult.normalizedArbiterFee,
transferResult.wormholeFee,
nonce,
payload
);
}
function _wrapAndTransferETH(uint256 arbiterFee) internal returns (BridgeStructs.TransferResult memory transferResult) {
@ -106,17 +148,76 @@ contract Bridge is BridgeGovernance, ReentrancyGuard {
});
}
function transferTokens(address token, uint256 amount, uint16 recipientChain, bytes32 recipient, uint256 arbiterFee, uint32 nonce) public payable nonReentrant returns (uint64 sequence) {
BridgeStructs.TransferResult memory transferResult = _transferTokens(token, amount, arbiterFee);
sequence = logTransfer(transferResult.tokenChain, transferResult.tokenAddress, transferResult.normalizedAmount, recipientChain, recipient, transferResult.normalizedArbiterFee, transferResult.wormholeFee, nonce);
/*
* @notice Send ERC20 token through portal.
*/
function transferTokens(
address token,
uint256 amount,
uint16 recipientChain,
bytes32 recipient,
uint256 arbiterFee,
uint32 nonce
) public payable nonReentrant returns (uint64 sequence) {
BridgeStructs.TransferResult memory transferResult = _transferTokens(
token,
amount,
arbiterFee
);
sequence = logTransfer(
transferResult.tokenChain,
transferResult.tokenAddress,
transferResult.normalizedAmount,
recipientChain,
recipient,
transferResult.normalizedArbiterFee,
transferResult.wormholeFee,
nonce
);
}
function transferTokensWithPayload(address token, uint256 amount, uint16 recipientChain, bytes32 recipient, uint256 arbiterFee, uint32 nonce, bytes memory payload) public payable nonReentrant returns (uint64 sequence) {
BridgeStructs.TransferResult memory transferResult = _transferTokens(token, amount, arbiterFee);
sequence = logTransferWithPayload(transferResult.tokenChain, transferResult.tokenAddress, transferResult.normalizedAmount, recipientChain, recipient, transferResult.normalizedArbiterFee, transferResult.wormholeFee, nonce, payload);
/*
* @notice Send ERC20 token through portal.
*
* @dev This type of transfer is called a "contract-controlled transfer".
* There are three differences from a regular token transfer:
* 1) Additional arbitrary payload can be attached to the message
* 2) Only the recipient (typically a contract) can redeem the transaction
* 3) The sender's address (msg.sender) is also included in the transaction payload
*
* With these three additional components, xDapps can implement cross-chain
* composable interactions.
*/
function transferTokensWithPayload(
address token,
uint256 amount,
uint16 recipientChain,
bytes32 recipient,
uint256 arbiterFee,
uint32 nonce,
bytes memory payload
) public payable nonReentrant returns (uint64 sequence) {
BridgeStructs.TransferResult memory transferResult = _transferTokens(
token,
amount,
arbiterFee
);
sequence = logTransferWithPayload(
transferResult.tokenChain,
transferResult.tokenAddress,
transferResult.normalizedAmount,
recipientChain,
recipient,
transferResult.normalizedArbiterFee,
transferResult.wormholeFee,
nonce,
payload
);
}
// Initiate a Transfer
/*
* @notice Initiate a transfer
*/
function _transferTokens(address token, uint256 amount, uint256 arbiterFee) internal returns (BridgeStructs.TransferResult memory transferResult) {
// determine token parameters
uint16 tokenChain;
@ -188,47 +289,75 @@ contract Bridge is BridgeGovernance, ReentrancyGuard {
return amount;
}
function logTransfer(uint16 tokenChain, bytes32 tokenAddress, uint256 amount, uint16 recipientChain, bytes32 recipient, uint256 fee, uint256 callValue, uint32 nonce) internal returns (uint64 sequence) {
function logTransfer(
uint16 tokenChain,
bytes32 tokenAddress,
uint256 amount,
uint16 recipientChain,
bytes32 recipient,
uint256 fee,
uint256 callValue,
uint32 nonce
) internal returns (uint64 sequence) {
require(fee <= amount, "fee exceeds amount");
BridgeStructs.Transfer memory transfer = BridgeStructs.Transfer({
payloadID : 1,
amount : amount,
tokenAddress : tokenAddress,
tokenChain : tokenChain,
to : recipient,
toChain : recipientChain,
fee : fee
payloadID: 1,
amount: amount,
tokenAddress: tokenAddress,
tokenChain: tokenChain,
to: recipient,
toChain: recipientChain,
fee: fee
});
bytes memory encoded = encodeTransfer(transfer);
sequence = wormhole().publishMessage{
value : callValue
}(nonce, encoded, 15);
sequence = wormhole().publishMessage{value: callValue}(
nonce,
encoded,
15
);
}
function logTransferWithPayload(uint16 tokenChain, bytes32 tokenAddress, uint256 amount, uint16 recipientChain, bytes32 recipient, uint256 fee, uint256 callValue, uint32 nonce, bytes memory payload) internal returns (uint64 sequence) {
/*
* @dev Publish a token transfer message with payload.
*
* @return The sequence number of the published message.
*/
function logTransferWithPayload(
uint16 tokenChain,
bytes32 tokenAddress,
uint256 amount,
uint16 recipientChain,
bytes32 recipient,
uint256 fee,
uint256 callValue,
uint32 nonce,
bytes memory payload
) internal returns (uint64 sequence) {
require(fee <= amount, "fee exceeds amount");
BridgeStructs.TransferWithPayload memory transfer = BridgeStructs.TransferWithPayload({
payloadID : 3,
amount : amount,
tokenAddress : tokenAddress,
tokenChain : tokenChain,
to : recipient,
toChain : recipientChain,
fee : fee,
payload : payload
});
BridgeStructs.TransferWithPayload memory transfer = BridgeStructs
.TransferWithPayload({
payloadID: 3,
amount: amount,
tokenAddress: tokenAddress,
tokenChain: tokenChain,
to: recipient,
toChain: recipientChain,
fee: fee,
payload: payload
});
bytes memory encoded = encodeTransferWithPayload(transfer);
sequence = wormhole().publishMessage{
value : callValue
}(nonce, encoded, 15);
sequence = wormhole().publishMessage{value: callValue}(
nonce,
encoded,
15
);
}
function updateWrapped(bytes memory encodedVm) external returns (address token) {
(IWormhole.VM memory vm, bool valid, string memory reason) = wormhole().parseAndVerifyVM(encodedVm);