generated from PaulRBerg/hardhat-template
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from gnosis/feat/v0.2.0-adapters
feat: Adapters - v0.2.0
- Loading branch information
Showing
80 changed files
with
813 additions
and
3,188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
pragma solidity ^0.8.17; | ||
|
||
import { Reporter } from "../Reporter.sol"; | ||
import { AMBAdapter } from "./AMBAdapter.sol"; | ||
import { IOracleAdapter } from "../../interfaces/IOracleAdapter.sol"; | ||
import { IAMB } from "./IAMB.sol"; | ||
|
||
contract AMBReporter is Reporter { | ||
string public constant PROVIDER = "amb"; | ||
|
||
address public immutable AMB; | ||
uint256 public immutable GAS; | ||
uint256 public immutable TO_CHAIN_ID; | ||
|
||
error InvalidToChainId(uint256 chainId, uint256 expectedChainId); | ||
|
||
constructor( | ||
address headerStorage, | ||
address yaho, | ||
address amb, | ||
uint256 toChainId, | ||
uint256 gas | ||
) Reporter(headerStorage, yaho) { | ||
AMB = amb; | ||
TO_CHAIN_ID = toChainId; | ||
GAS = gas; | ||
} | ||
|
||
function _dispatch( | ||
uint256 toChainId, | ||
address adapter, | ||
uint256[] memory ids, | ||
bytes32[] memory hashes | ||
) internal override returns (bytes32) { | ||
if (toChainId != TO_CHAIN_ID) revert InvalidToChainId(toChainId, TO_CHAIN_ID); | ||
bytes memory payload = abi.encodeCall(AMBAdapter.storeHashes, (ids, hashes)); | ||
return IAMB(AMB).requireToPassMessage(adapter, payload, GAS); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 0 additions & 19 deletions
19
packages/evm/contracts/adapters/Axelar/AxelarHeaderReporter.sol
This file was deleted.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
packages/evm/contracts/adapters/Axelar/AxelarMessageRelay.sol
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,64 @@ | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
pragma solidity ^0.8.17; | ||
|
||
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; | ||
import { Strings } from "@openzeppelin/contracts/utils/Strings.sol"; | ||
import { IAxelarGateway } from "@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarGateway.sol"; | ||
import { IAxelarGasService } from "@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarGasService.sol"; | ||
import { Strings } from "@openzeppelin/contracts/utils/Strings.sol"; | ||
import { Reporter } from "../Reporter.sol"; | ||
|
||
abstract contract AxelarReporter { | ||
contract AxelarReporter is Reporter, Ownable { | ||
using Strings for uint256; | ||
|
||
string public constant PROVIDER = "axelar"; | ||
bytes32 private constant NULL_STRING = keccak256(""); | ||
IAxelarGateway public immutable AXELAR_GATEWAY; | ||
IAxelarGasService public immutable AXELAR_GAS_SERVICE; | ||
string public AXELAR_ADAPTER_CHAIN; // Immutable | ||
|
||
constructor(address axelarGateway, address axelarGasService, string memory axelarAdapterChain) { | ||
mapping(uint256 => string) public chainNames; | ||
|
||
error ChainIdNotSupported(uint256 chainId); | ||
|
||
event ChainNameSet(uint256 indexed chainId, string indexed chainName); | ||
|
||
constructor( | ||
address headerStorage, | ||
address yaho, | ||
address axelarGateway, | ||
address axelarGasService | ||
) Reporter(headerStorage, yaho) { | ||
AXELAR_GATEWAY = IAxelarGateway(axelarGateway); | ||
AXELAR_GAS_SERVICE = IAxelarGasService(axelarGasService); | ||
AXELAR_ADAPTER_CHAIN = axelarAdapterChain; | ||
} | ||
|
||
function _axelarSend(bytes memory payload, address adapter) internal { | ||
function setChainNameByChainId(uint256 chainId, string calldata chainName) external onlyOwner { | ||
chainNames[chainId] = chainName; | ||
emit ChainNameSet(chainId, chainName); | ||
} | ||
|
||
function _dispatch( | ||
uint256 toChainId, | ||
address adapter, | ||
uint256[] memory ids, | ||
bytes32[] memory hashes | ||
) internal override returns (bytes32) { | ||
string memory chainName = chainNames[toChainId]; | ||
if (keccak256(abi.encode(chainName)) == NULL_STRING) revert ChainIdNotSupported(toChainId); | ||
|
||
string memory sAdapter = uint256(uint160(adapter)).toHexString(20); | ||
bytes memory payload = abi.encode(ids, hashes); | ||
|
||
if (msg.value > 0) { | ||
AXELAR_GAS_SERVICE.payNativeGasForContractCall{ value: msg.value }( | ||
address(this), | ||
AXELAR_ADAPTER_CHAIN, | ||
chainName, | ||
sAdapter, | ||
payload, | ||
msg.sender | ||
); | ||
} | ||
|
||
AXELAR_GATEWAY.callContract(AXELAR_ADAPTER_CHAIN, sAdapter, payload); | ||
AXELAR_GATEWAY.callContract(chainName, sAdapter, payload); | ||
return bytes32(0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.