Skip to content

Commit

Permalink
refactor: override functions to extract params from LSP7 calldata
Browse files Browse the repository at this point in the history
  • Loading branch information
CJ42 committed Sep 24, 2024
1 parent 8e024e8 commit 73eb4cc
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

## Architecture & Workflow

The flow for bridging tokens is generally as follow:

- if the token is originally from ETH, the token is locked on ETHEREUM, and minted on LUKSO.
- if the token is originally from LUKSO, the token is burnt on LUKSO, minted on ETHEREUM.

### Ethereum -> LUKSO

![Ethereum to LUKSO bridge flow](./assets/flow-ethereum-lukso-hashi-bridge.png)
Expand Down Expand Up @@ -79,8 +84,8 @@

### Relevant links & resources

- [Architecture diagrams](https://hackmd.io/WXwzLS5TS4q_G3C7w2DkiA)
- [Cross Chain Alliance - Hashi](https://crosschain-alliance.gitbook.io/hashi)
- [Hyperlane smart contracts monorepo](https://github.com/hyperlane-xyz/hyperlane-monorepo)

## Getting Started

Expand Down
24 changes: 24 additions & 0 deletions src/HypLSP7.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { LSP7DigitalAssetInitAbstract } from "@lukso/lsp7-contracts/contracts/LS
import { TokenRouter } from "@hyperlane-xyz/core/contracts/token/libs/TokenRouter.sol";
import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

// libraries
import { TokenMessageForLSP7 } from "./TokenMessageForLSP7.sol";

/**
* @title LSP7 version of the Hyperlane ERC20 Token Router
* @dev https://github.com/hyperlane-xyz/hyperlane-monorepo/blob/main/solidity/contracts/token/HypERC20.sol
Expand Down Expand Up @@ -90,4 +93,25 @@ contract HypLSP7 is LSP7DigitalAssetInitAbstract, TokenRouter {
{
LSP7DigitalAssetInitAbstract._mint(_recipient, _amount, true, "");
}

function _transferRemote(
uint32 _destination,
bytes32 _recipient,
uint256 _amountOrId,
uint256 _value,
bytes memory _hookMetadata,
address _hook
)
internal
virtual
override(TokenRouter)
returns (bytes32 messageId)
{
bytes memory _tokenMetadata = _transferFromSender(_amountOrId);
bytes memory _tokenMessage = TokenMessageForLSP7.format(_recipient, _amountOrId, _tokenMetadata);

messageId = _Router_dispatch(_destination, _value, _tokenMessage, _hookMetadata, _hook);

emit SentTransferRemote(_destination, _recipient, _amountOrId);
}
}
25 changes: 25 additions & 0 deletions src/TokenMessageForLSP7.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.8.0;

/// @dev Adjusted version of the TokenMessage library from Hyperlane
/// to extract parameters from the calldata of an LSP7 transfer
/// according to the `transfer(address,address,uint256,bool,bytes)` signature.
library TokenMessageForLSP7 {
function format(bytes32 _recipient, uint256 _amount, bytes memory _metadata) internal view returns (bytes memory) {
return abi.encodePacked(
msg.sender, // TODO: which sender should be specified here? Should we add an extra parameter?
_recipient,
_amount,
true, // force param set to `true` by default
_metadata
);
}

function recipient(bytes calldata message) internal pure returns (bytes32) {
return bytes32(message[32:64]);
}

function amount(bytes calldata message) internal pure returns (uint256) {
return uint256(bytes32(message[64:96]));
}
}

0 comments on commit 73eb4cc

Please sign in to comment.