Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions contracts/Token.sol
Original file line number Diff line number Diff line change
@@ -1,37 +1,41 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {ERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";

contract Nickle is ERC20 {
constructor() ERC20("Nickle", "NICKLE") {
contract Nickle is ERC20Upgradeable {
function initialize() public initializer {
__ERC20_init("Nickle", "NICKLE");
_mint(
msg.sender,
10000000000000000000000000000000000000000000000000000000000000000
);
}
}

contract BronzeCowry is ERC20 {
constructor() ERC20("Bronze Cowry", "SHELL") {
contract BronzeCowry is ERC20Upgradeable {
function initialize() public initializer {
__ERC20_init("Bronze Cowry", "SHELL");
_mint(
msg.sender,
10000000000000000000000000000000000000000000000000000000000000000
);
}
}

contract AthenianDrachma is ERC20 {
constructor() ERC20("Athenian Drachma", "ATH") {
contract AthenianDrachma is ERC20Upgradeable {
function initialize() public initializer {
__ERC20_init("Athenian Drachma", "ATH");
_mint(
msg.sender,
10000000000000000000000000000000000000000000000000000000000000000
);
}
}

contract DebasedTowerPoundSterling is ERC20 {
constructor() ERC20("DebasedTowerPoundSterling", "NEWTON") {
contract DebasedTowerPoundSterling is ERC20Upgradeable {
function initialize() public initializer {
__ERC20_init("DebasedTowerPoundSterling", "NEWTON");
_mint(
msg.sender,
10000000000000000000000000000000000000000000000000000000000000000
Expand Down
89 changes: 89 additions & 0 deletions contracts/axelar/AxelarExecutable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import {IAxelarGateway} from "@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarGateway.sol";
import {IAxelarExecutable} from "@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarExecutable.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

/**
* @title AxelarExecutable
* @dev Abstract contract to be inherited by contracts that need to execute cross-chain commands via Axelar's Gateway.
* It implements the IAxelarExecutable interface and is upgradeable.
*/
abstract contract AxelarExecutable is IAxelarExecutable, Initializable {
/// @dev Reference to the Axelar Gateway contract.
address internal gatewayAddress;

/**
* @dev Contract constructor that disables initializers.
*/
constructor() {
_disableInitializers();
}

/**
* @dev Initializes the contract with the Axelar Gateway address.
* Reverts if the provided address is the zero address.
* @param gateway_ The address of the Axelar Gateway contract.
*/
function __AxelarExecutable_init(
address gateway_
) internal onlyInitializing {
if (gateway_ == address(0)) revert InvalidAddress();
gatewayAddress = gateway_;
}

/**
* @notice Executes the cross-chain command after validating it with the Axelar Gateway.
* @dev This function ensures the call is approved by Axelar Gateway before execution.
* It uses a hash of the payload for validation and internally calls _execute for the actual command execution.
* Reverts if the validation fails.
* @param commandId The unique identifier of the cross-chain message being executed.
* @param sourceChain The name of the source chain from which the message originated.
* @param sourceAddress The address on the source chain that sent the message.
* @param payload The payload of the message payload.
*/
function execute(
bytes32 commandId,
string calldata sourceChain,
string calldata sourceAddress,
bytes calldata payload
) external virtual {
bytes32 payloadHash = keccak256(payload);

if (
!gateway().validateContractCall(
commandId,
sourceChain,
sourceAddress,
payloadHash
)
) revert NotApprovedByGateway();

_execute(commandId, sourceChain, sourceAddress, payload);
}

/**
* @dev Internal virtual function to be overridden by child contracts to execute the command.
* It allows child contracts to define their custom command execution logic.
* @param commandId The identifier of the command to execute.
* @param sourceChain The name of the source chain from which the command originated.
* @param sourceAddress The address on the source chain that sent the command.
* @param payload The payload of the command to be executed.
*/
function _execute(
bytes32 commandId,
string calldata sourceChain,
string calldata sourceAddress,
bytes calldata payload
) internal virtual;

/**
* @notice Returns the address of the AxelarGateway contract.
* @return The Axelar Gateway instance.
*/
function gateway() public view returns (IAxelarGateway) {
return IAxelarGateway(gatewayAddress);
}
}
110 changes: 69 additions & 41 deletions contracts/destChain/Prover-Axelar.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {Misc} from "filecoin-solidity-api/contracts/v0.8/utils/Misc.sol";
import {FilAddresses} from "filecoin-solidity-api/contracts/v0.8/utils/FilAddresses.sol";
import {DataAttestation, IBridgeContract, StringsEqual} from "../sourceChain/Oracles.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
import {AxelarExecutable} from "@axelar-network/axelar-gmp-sdk-solidity/contracts/executable/AxelarExecutable.sol";
import {AxelarExecutable} from "../axelar/AxelarExecutable.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";

Expand All @@ -25,7 +25,7 @@ contract DealClientAxl is AxelarExecutable {
using AccountCBOR for *;
using MarketCBOR for *;

IAxelarGasService public immutable gasService;
IAxelarGasService public gasService;
uint64 public constant AUTHENTICATE_MESSAGE_METHOD_NUM = 2643134072;
uint64 public constant DATACAP_RECEIVER_HOOK_METHOD_NUM = 3726118371;
uint64 public constant MARKET_NOTIFY_DEAL_METHOD_NUM = 4186741094;
Expand Down Expand Up @@ -94,19 +94,22 @@ contract DealClientAxl is AxelarExecutable {
uint256 price
);
event ReceivedDataCap(string received);
event DealNotify(
uint64 dealId,
bytes commP,
bytes chainId
);
event DealNotify(uint64 dealId, bytes commP, bytes chainId);
event XChainProveDataStored(
string destinationChain,
string destinationAddress);
string destinationChain,
string destinationAddress
);

constructor(
address _gateway,
address _gasReceiver
) AxelarExecutable(_gateway) {
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}

function initialize(
address _gateway,
address _gasReceiver
) public initializer {
__AxelarExecutable_init(_gateway);
gasService = IAxelarGasService(_gasReceiver);
}

Expand Down Expand Up @@ -134,42 +137,60 @@ contract DealClientAxl is AxelarExecutable {
}
}

function getSourceChain(uint256 chainId) public view returns (string memory, address) {
function getSourceChain(
uint256 chainId
) public view returns (string memory, address) {
SourceChain memory source = chainIdToSourceChain[chainId];
require(source.sourceOracleAddress != address(0), "chainId Chain is not configured in Prover Contract");
require(
source.sourceOracleAddress != address(0),
"chainId Chain is not configured in Prover Contract"
);
return (source.chainName, source.sourceOracleAddress);
}

function addGasFunds(bytes calldata providerAddrData) external payable {
providerGasFunds[providerAddrData] += msg.value;
}

function makeDealProposal(DealRequest calldata deal) public returns (bytes32){
function makeDealProposal(
DealRequest calldata deal
) public returns (bytes32) {
require(
pieceStatus[deal.piece_cid] != Status.DealActivated ||
pieceStatus[deal.piece_cid] != Status.DealPublished,
pieceStatus[deal.piece_cid] != Status.DealActivated ||
pieceStatus[deal.piece_cid] != Status.DealPublished,
"this deal is already active or published"
);

uint256 idx = dealRequests.length;
dealRequests.push(deal);

bytes32 proposalId = keccak256(abi.encodePacked(msg.sender, block.timestamp, idx));
bytes32 proposalId = keccak256(
abi.encodePacked(msg.sender, block.timestamp, idx)
);
dealIdToIndex[proposalId] = RequestIdx(idx, true);

pieceRequests[deal.piece_cid] = RequestId(proposalId, true);
pieceStatus[deal.piece_cid] = Status.DealPublished;

emit DealProposalCreate(proposalId, deal.piece_size, deal.verified_deal, deal.storage_price_per_epoch);
emit DealProposalCreate(
proposalId,
deal.piece_size,
deal.verified_deal,
deal.storage_price_per_epoch
);
return proposalId;
}

function getDealRequest(bytes32 proposalId) public view returns (DealRequest memory) {
function getDealRequest(
bytes32 proposalId
) public view returns (DealRequest memory) {
require(dealIdToIndex[proposalId].valid, "Deal does not exist");
return dealRequests[dealIdToIndex[proposalId].idx];
}

function getDealProposal(bytes32 proposalId) public view returns (bytes memory) {
function getDealProposal(
bytes32 proposalId
) public view returns (bytes memory) {
DealRequest memory deal = getDealRequest(proposalId);
MarketTypes.DealProposal memory proposal = MarketTypes.DealProposal(
CommonTypes.Cid(deal.piece_cid),
Expand All @@ -188,7 +209,9 @@ contract DealClientAxl is AxelarExecutable {
return MarketCBOR.serializeDealProposal(proposal);
}

function serializeExtraParams(ExtraParams memory params) internal pure returns (bytes memory) {
function serializeExtraParams(
ExtraParams memory params
) internal pure returns (bytes memory) {
CBOR.CBORBuffer memory buffer = CBOR.create(64);
buffer.startFixedArray(4);
buffer.writeString(params.location_ref);
Expand All @@ -199,20 +222,26 @@ contract DealClientAxl is AxelarExecutable {
return buffer.data();
}

function getExtraParams(bytes32 proposalId) public view returns (bytes memory extra_params) {
function getExtraParams(
bytes32 proposalId
) public view returns (bytes memory extra_params) {
DealRequest memory deal = getDealRequest(proposalId);
return serializeExtraParams(deal.extra_params);
}

function updateDealStatus(bytes memory pieceCid) public {

require(pieceDeals[pieceCid] > 0, "Deal does not exist for piece cid");

(int256 exit_code, MarketTypes.GetDealActivationReturn memory ret) = MarketAPI
.getDealActivation(pieceDeals[pieceCid]);

require(exit_code == 0, "Deal activation failed with non zero exit code");

(
int256 exit_code,
MarketTypes.GetDealActivationReturn memory ret
) = MarketAPI.getDealActivation(pieceDeals[pieceCid]);

require(
exit_code == 0,
"Deal activation failed with non zero exit code"
);

if (CommonTypes.ChainEpoch.unwrap(ret.terminated) > 0) {
pieceStatus[pieceCid] = Status.DealTerminated;
} else if (CommonTypes.ChainEpoch.unwrap(ret.activated) > 0) {
Expand Down Expand Up @@ -251,15 +280,15 @@ contract DealClientAxl is AxelarExecutable {
);
bytes memory payload = abi.encode(attest);

emit DealNotify(mdnp.dealId,
emit DealNotify(
mdnp.dealId,
proposal.piece_cid.data,
proposal.label.data
);

if (chainId == block.chainid) {
IBridgeContract(
chainIdToSourceChain[chainId].sourceOracleAddress
)._execute(
IBridgeContract(chainIdToSourceChain[chainId].sourceOracleAddress)
._execute(
chainIdToSourceChain[chainId].chainName,
addressToHexString(address(this)),
payload
Expand Down Expand Up @@ -290,8 +319,7 @@ contract DealClientAxl is AxelarExecutable {
// gasFunds = providerGasFunds[providerAddrData];
// providerGasFunds[providerAddrData] = 0;
// }
string memory sourceChain = chainIdToSourceChain[chainId]
.chainName;
string memory sourceChain = chainIdToSourceChain[chainId].chainName;
string memory sourceOracleAddress = addressToHexString(
chainIdToSourceChain[chainId].sourceOracleAddress
);
Expand All @@ -310,8 +338,9 @@ contract DealClientAxl is AxelarExecutable {
bytes32 commandId,
string calldata sourceChain,
string calldata sourceAddress,
bytes calldata payload) internal override{
//Do Nothing
bytes calldata payload
) internal override {
//Do Nothing
}

function debug_call(
Expand All @@ -328,9 +357,8 @@ contract DealClientAxl is AxelarExecutable {
);
bytes memory payload = abi.encode(attest);
if (chainId == block.chainid) {
IBridgeContract(
chainIdToSourceChain[chainId].sourceOracleAddress
)._execute(
IBridgeContract(chainIdToSourceChain[chainId].sourceOracleAddress)
._execute(
chainIdToSourceChain[chainId].chainName,
addressToHexString(address(this)),
payload
Expand Down
9 changes: 8 additions & 1 deletion contracts/destChain/Prover.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ import {Misc} from "filecoin-solidity-api/contracts/v0.8/utils/Misc.sol";
import {FilAddresses} from "filecoin-solidity-api/contracts/v0.8/utils/FilAddresses.sol";
import {DataAttestation, IBridgeContract, StringsEqual} from "../sourceChain/Oracles.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

using CBOR for CBOR.CBORBuffer;

contract DealClient {
contract DealClient is Initializable {
using AccountCBOR for *;
using MarketCBOR for *;

Expand All @@ -42,6 +43,12 @@ contract DealClient {

IBridgeContract public bridgeContract;

constructor() {
_disableInitializers();
}

function initialize() public initializer {}

function setBridgeContract(address _bridgeContract) external {
if (address(bridgeContract) == address(0)) {
bridgeContract = IBridgeContract(_bridgeContract);
Expand Down
Loading