Skip to content

Commit

Permalink
Docs (#156)
Browse files Browse the repository at this point in the history
* docs

* Fix review
  • Loading branch information
jiguantong authored Oct 31, 2023
1 parent 881609f commit e9a80d5
Show file tree
Hide file tree
Showing 19 changed files with 300 additions and 20 deletions.
21 changes: 19 additions & 2 deletions src/Application.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
// SPDX-License-Identifier: MIT
// This file is part of Darwinia.
// Copyright (C) 2018-2023 Darwinia Network
// SPDX-License-Identifier: GPL-3.0
//
// Darwinia is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Darwinia is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Darwinia. If not, see <https://www.gnu.org/licenses/>.

pragma solidity ^0.8.17;

Expand All @@ -7,15 +22,17 @@ abstract contract Application {
_line = payable(msg.sender);
}

/// @notice The cross-chain message source chainId
function _fromChainId() internal pure returns (uint256 _msgDataFromChainId) {
require(msg.data.length >= 52, "!fromChainId");
assembly {
_msgDataFromChainId := calldataload(sub(calldatasize(), 52))
}
}

/// @notice Get the source chain fromDapp address.
function _xmsgSender() internal pure returns (address payable _from) {
require(msg.data.length >= 20, "!line");
require(msg.data.length >= 20, "!fromDapp");
assembly {
_from := shr(96, calldataload(sub(calldatasize(), 20)))
}
Expand Down
20 changes: 19 additions & 1 deletion src/LineRegistry.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
// SPDX-License-Identifier: MIT
// This file is part of Darwinia.
// Copyright (C) 2018-2023 Darwinia Network
// SPDX-License-Identifier: GPL-3.0
//
// Darwinia is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Darwinia is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Darwinia. If not, see <https://www.gnu.org/licenses/>.

pragma solidity ^0.8.17;

import "@openzeppelin/contracts/access/Ownable2Step.sol";
import "./interfaces/ILineMetadata.sol";

/// @title LineRegistry
/// @notice LineRegistry will be deployed on each chain.
/// It is the registry of messageLine and can be used to verify whether the line has been registered.
contract LineRegistry is Ownable2Step {
// lineName => lineAddress
mapping(string => address) private _lineLookup;
Expand Down
2 changes: 1 addition & 1 deletion src/chain-id-mappings/AxelarChainIdMapping.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file is part of Darwinia.
// Copyright (C) 2018-2022 Darwinia Network
// Copyright (C) 2018-2023 Darwinia Network
// SPDX-License-Identifier: GPL-3.0
//
// Darwinia is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion src/chain-id-mappings/CelerChainIdMapping.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file is part of Darwinia.
// Copyright (C) 2018-2022 Darwinia Network
// Copyright (C) 2018-2023 Darwinia Network
// SPDX-License-Identifier: GPL-3.0
//
// Darwinia is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion src/chain-id-mappings/LayerZeroChainIdMapping.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file is part of Darwinia.
// Copyright (C) 2018-2022 Darwinia Network
// Copyright (C) 2018-2023 Darwinia Network
// SPDX-License-Identifier: GPL-3.0
//
// Darwinia is free software: you can redistribute it and/or modify
Expand Down
18 changes: 17 additions & 1 deletion src/examples/ExampleReceiverDapp.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
// SPDX-License-Identifier: MIT
// This file is part of Darwinia.
// Copyright (C) 2018-2023 Darwinia Network
// SPDX-License-Identifier: GPL-3.0
//
// Darwinia is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Darwinia is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Darwinia. If not, see <https://www.gnu.org/licenses/>.

pragma solidity ^0.8.17;

Expand All @@ -17,6 +32,7 @@ contract ExampleReceiverDapp is Application {
DAPP = dapp;
}

/// @notice You could check the fromDapp address or messageLine address.
function xxx(bytes calldata message) external {
uint256 fromChainId = _fromChainId();
address fromDapp = _xmsgSender();
Expand Down
22 changes: 21 additions & 1 deletion src/interfaces/ILineMetadata.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
// SPDX-License-Identifier: MIT
// This file is part of Darwinia.
// Copyright (C) 2018-2023 Darwinia Network
// SPDX-License-Identifier: GPL-3.0
//
// Darwinia is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Darwinia is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Darwinia. If not, see <https://www.gnu.org/licenses/>.

pragma solidity ^0.8.0;

interface ILineMetadata {
/// @notice Get the line name, it's globally unique and immutable.
/// @return The MessageLine name.
function name() external view returns (string memory);

/// @return The line metadata uri.
function uri() external view returns (string memory);
}
31 changes: 30 additions & 1 deletion src/interfaces/IMessageLine.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,40 @@
// SPDX-License-Identifier: MIT
// This file is part of Darwinia.
// Copyright (C) 2018-2023 Darwinia Network
// SPDX-License-Identifier: GPL-3.0
//
// Darwinia is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Darwinia is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Darwinia. If not, see <https://www.gnu.org/licenses/>.

pragma solidity ^0.8.0;

interface IMessageLine {
error MessageFailure(bytes errorData);

/// @dev Send a cross-chain message over the MessageLine.
/// @notice Send a cross-chain message over the MessageLine.
/// @param toChainId The message destination chain id. <https://eips.ethereum.org/EIPS/eip-155>
/// @param toDapp The user application contract address which receive the message.
/// @param message The calldata which encoded by ABI Encoding.
/// @param params Extend parameters to adapt to different message protocols.
function send(uint256 toChainId, address toDapp, bytes calldata message, bytes calldata params) external payable;

/// @notice Get a quote in source native gas, for the amount that send() requires to pay for message delivery.
/// It should be noted that not all lines will implement this interface.
/// @dev If the messaging protocol does not support on-chain fetch fee, then revert with "Unimplemented!".
/// @param toChainId The message destination chain id. <https://eips.ethereum.org/EIPS/eip-155>
/// @param toDapp The user application contract address which receive the message.
/// @param message The calldata which encoded by ABI Encoding.
/// @param params Extend parameters to adapt to different message protocols.
function fee(uint256 toChainId, address toDapp, bytes calldata message, bytes calldata params)
external
view
Expand Down
17 changes: 16 additions & 1 deletion src/lines/AxelarLine.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
// SPDX-License-Identifier: MIT
// This file is part of Darwinia.
// Copyright (C) 2018-2023 Darwinia Network
// SPDX-License-Identifier: GPL-3.0
//
// Darwinia is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Darwinia is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Darwinia. If not, see <https://www.gnu.org/licenses/>.

pragma solidity ^0.8.17;

Expand Down
17 changes: 16 additions & 1 deletion src/lines/CelerLine.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
// SPDX-License-Identifier: MIT
// This file is part of Darwinia.
// Copyright (C) 2018-2023 Darwinia Network
// SPDX-License-Identifier: GPL-3.0
//
// Darwinia is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Darwinia is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Darwinia. If not, see <https://www.gnu.org/licenses/>.

pragma solidity 0.8.9;

Expand Down
17 changes: 16 additions & 1 deletion src/lines/DarwiniaLine.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
// SPDX-License-Identifier: MIT
// This file is part of Darwinia.
// Copyright (C) 2018-2023 Darwinia Network
// SPDX-License-Identifier: GPL-3.0
//
// Darwinia is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Darwinia is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Darwinia. If not, see <https://www.gnu.org/licenses/>.

pragma solidity ^0.8.17;

Expand Down
18 changes: 17 additions & 1 deletion src/lines/DarwiniaS2SLine.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
// SPDX-License-Identifier: MIT
// This file is part of Darwinia.
// Copyright (C) 2018-2023 Darwinia Network
// SPDX-License-Identifier: GPL-3.0
//
// Darwinia is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Darwinia is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Darwinia. If not, see <https://www.gnu.org/licenses/>.

pragma solidity ^0.8.17;

import "./base/BaseMessageLine.sol";
Expand Down
17 changes: 16 additions & 1 deletion src/lines/LayerZeroLine.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
// SPDX-License-Identifier: MIT
// This file is part of Darwinia.
// Copyright (C) 2018-2023 Darwinia Network
// SPDX-License-Identifier: GPL-3.0
//
// Darwinia is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Darwinia is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Darwinia. If not, see <https://www.gnu.org/licenses/>.

pragma solidity ^0.8.17;

Expand Down
18 changes: 17 additions & 1 deletion src/lines/ORMPLine.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
// SPDX-License-Identifier: MIT
// This file is part of Darwinia.
// Copyright (C) 2018-2023 Darwinia Network
// SPDX-License-Identifier: GPL-3.0
//
// Darwinia is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Darwinia is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Darwinia. If not, see <https://www.gnu.org/licenses/>.

pragma solidity ^0.8.17;

import "./base/BaseMessageLine.sol";
Expand Down
30 changes: 29 additions & 1 deletion src/lines/base/BaseMessageLine.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
// SPDX-License-Identifier: MIT
// This file is part of Darwinia.
// Copyright (C) 2018-2023 Darwinia Network
// SPDX-License-Identifier: GPL-3.0
//
// Darwinia is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Darwinia is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Darwinia. If not, see <https://www.gnu.org/licenses/>.

pragma solidity ^0.8.0;

Expand All @@ -12,6 +27,13 @@ abstract contract BaseMessageLine is IMessageLine, LineMetadata {
return block.chainid;
}

/// @dev Send a cross-chain message over the MessageLine.
/// Line developer should implement this, then it will be called by `send`.
/// @param fromDapp The real sender account who send the message.
/// @param toChainId The message destination chain id. <https://eips.ethereum.org/EIPS/eip-155>
/// @param toDapp The user application contract address which receive the message.
/// @param message The calldata which encoded by ABI Encoding.
/// @param params Extend parameters to adapt to different message protocols.
function _send(address fromDapp, uint256 toChainId, address toDapp, bytes calldata message, bytes calldata params)
internal
virtual;
Expand All @@ -20,6 +42,12 @@ abstract contract BaseMessageLine is IMessageLine, LineMetadata {
_send(msg.sender, toChainId, toDapp, message, params);
}

/// @dev Make toDapp accept messages.
/// This should be called by message line when a message is received.
/// @param fromChainId The source chainId, standard evm chainId.
/// @param fromDapp The message sender in source chain.
/// @param toDapp The message receiver in dest chain.
/// @param message The message body.
function _recv(uint256 fromChainId, address fromDapp, address toDapp, bytes memory message)
internal
returns (bytes memory)
Expand Down
17 changes: 16 additions & 1 deletion src/lines/base/FromLineLookup.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
// SPDX-License-Identifier: MIT
// This file is part of Darwinia.
// Copyright (C) 2018-2023 Darwinia Network
// SPDX-License-Identifier: GPL-3.0
//
// Darwinia is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Darwinia is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Darwinia. If not, see <https://www.gnu.org/licenses/>.

pragma solidity ^0.8.0;

Expand Down
Loading

0 comments on commit e9a80d5

Please sign in to comment.