ethereum: whitespace + docs
This commit is contained in:
parent
fe687783c0
commit
5a4ce6ab51
|
@ -42,16 +42,11 @@ contract Bridge is BridgeGovernance, ReentrancyGuard {
|
||||||
|
|
||||||
BridgeStructs.AssetMeta memory meta = BridgeStructs.AssetMeta({
|
BridgeStructs.AssetMeta memory meta = BridgeStructs.AssetMeta({
|
||||||
payloadID : 2,
|
payloadID : 2,
|
||||||
// Address of the token. Left-zero-padded if shorter than 32 bytes
|
tokenAddress : bytes32(uint256(uint160(tokenAddress))), // Address of the token. Left-zero-padded if shorter than 32 bytes
|
||||||
tokenAddress : bytes32(uint256(uint160(tokenAddress))),
|
tokenChain : chainId(), // Chain ID of the token
|
||||||
// Chain ID of the token
|
decimals : decimals, // Number of decimals of the token (big-endian uint8)
|
||||||
tokenChain : chainId(),
|
symbol : symbol, // Symbol of the token (UTF-8)
|
||||||
// Number of decimals of the token (big-endian uint8)
|
name : name // Name of the token (UTF-8)
|
||||||
decimals : decimals,
|
|
||||||
// Symbol of the token (UTF-8)
|
|
||||||
symbol : symbol,
|
|
||||||
// Name of the token (UTF-8)
|
|
||||||
name : name
|
|
||||||
});
|
});
|
||||||
|
|
||||||
bytes memory encoded = encodeAssetMeta(meta);
|
bytes memory encoded = encodeAssetMeta(meta);
|
||||||
|
@ -61,14 +56,61 @@ contract Bridge is BridgeGovernance, ReentrancyGuard {
|
||||||
}(nonce, encoded, 15);
|
}(nonce, encoded, 15);
|
||||||
}
|
}
|
||||||
|
|
||||||
function wrapAndTransferETH(uint16 recipientChain, bytes32 recipient, uint256 arbiterFee, uint32 nonce) public payable returns (uint64 sequence) {
|
/*
|
||||||
BridgeStructs.TransferResult memory transferResult = _wrapAndTransferETH(arbiterFee);
|
* @notice Send eth through portal by first wrapping it to WETH.
|
||||||
sequence = logTransfer(transferResult.tokenChain, transferResult.tokenAddress, transferResult.normalizedAmount, recipientChain, recipient, transferResult.normalizedArbiterFee, transferResult.wormholeFee, nonce);
|
*/
|
||||||
|
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);
|
* @notice Send eth through portal by first wrapping it.
|
||||||
sequence = logTransferWithPayload(transferResult.tokenChain, transferResult.tokenAddress, transferResult.normalizedAmount, recipientChain, recipient, transferResult.normalizedArbiterFee, transferResult.wormholeFee, nonce, payload);
|
*
|
||||||
|
* @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) {
|
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);
|
* @notice Send ERC20 token through portal.
|
||||||
sequence = logTransfer(transferResult.tokenChain, transferResult.tokenAddress, transferResult.normalizedAmount, recipientChain, recipient, transferResult.normalizedArbiterFee, transferResult.wormholeFee, nonce);
|
*/
|
||||||
|
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);
|
* @notice Send ERC20 token through portal.
|
||||||
sequence = logTransferWithPayload(transferResult.tokenChain, transferResult.tokenAddress, transferResult.normalizedAmount, recipientChain, recipient, transferResult.normalizedArbiterFee, transferResult.wormholeFee, nonce, payload);
|
*
|
||||||
|
* @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) {
|
function _transferTokens(address token, uint256 amount, uint256 arbiterFee) internal returns (BridgeStructs.TransferResult memory transferResult) {
|
||||||
// determine token parameters
|
// determine token parameters
|
||||||
uint16 tokenChain;
|
uint16 tokenChain;
|
||||||
|
@ -188,47 +289,75 @@ contract Bridge is BridgeGovernance, ReentrancyGuard {
|
||||||
return amount;
|
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");
|
require(fee <= amount, "fee exceeds amount");
|
||||||
|
|
||||||
BridgeStructs.Transfer memory transfer = BridgeStructs.Transfer({
|
BridgeStructs.Transfer memory transfer = BridgeStructs.Transfer({
|
||||||
payloadID : 1,
|
payloadID: 1,
|
||||||
amount : amount,
|
amount: amount,
|
||||||
tokenAddress : tokenAddress,
|
tokenAddress: tokenAddress,
|
||||||
tokenChain : tokenChain,
|
tokenChain: tokenChain,
|
||||||
to : recipient,
|
to: recipient,
|
||||||
toChain : recipientChain,
|
toChain: recipientChain,
|
||||||
fee : fee
|
fee: fee
|
||||||
});
|
});
|
||||||
|
|
||||||
bytes memory encoded = encodeTransfer(transfer);
|
bytes memory encoded = encodeTransfer(transfer);
|
||||||
|
|
||||||
sequence = wormhole().publishMessage{
|
sequence = wormhole().publishMessage{value: callValue}(
|
||||||
value : callValue
|
nonce,
|
||||||
}(nonce, encoded, 15);
|
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");
|
require(fee <= amount, "fee exceeds amount");
|
||||||
|
|
||||||
BridgeStructs.TransferWithPayload memory transfer = BridgeStructs.TransferWithPayload({
|
BridgeStructs.TransferWithPayload memory transfer = BridgeStructs
|
||||||
payloadID : 3,
|
.TransferWithPayload({
|
||||||
amount : amount,
|
payloadID: 3,
|
||||||
tokenAddress : tokenAddress,
|
amount: amount,
|
||||||
tokenChain : tokenChain,
|
tokenAddress: tokenAddress,
|
||||||
to : recipient,
|
tokenChain: tokenChain,
|
||||||
toChain : recipientChain,
|
to: recipient,
|
||||||
fee : fee,
|
toChain: recipientChain,
|
||||||
payload : payload
|
fee: fee,
|
||||||
});
|
payload: payload
|
||||||
|
});
|
||||||
|
|
||||||
bytes memory encoded = encodeTransferWithPayload(transfer);
|
bytes memory encoded = encodeTransferWithPayload(transfer);
|
||||||
|
|
||||||
sequence = wormhole().publishMessage{
|
sequence = wormhole().publishMessage{value: callValue}(
|
||||||
value : callValue
|
nonce,
|
||||||
}(nonce, encoded, 15);
|
encoded,
|
||||||
|
15
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateWrapped(bytes memory encodedVm) external returns (address token) {
|
function updateWrapped(bytes memory encodedVm) external returns (address token) {
|
||||||
(IWormhole.VM memory vm, bool valid, string memory reason) = wormhole().parseAndVerifyVM(encodedVm);
|
(IWormhole.VM memory vm, bool valid, string memory reason) = wormhole().parseAndVerifyVM(encodedVm);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue