Skip to content

Commit

Permalink
fix: add token uri and memoir to release key
Browse files Browse the repository at this point in the history
  • Loading branch information
0xdcota committed Feb 6, 2024
1 parent 9fe4d95 commit 9cb16d9
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 22 deletions.
44 changes: 31 additions & 13 deletions src/MgdL2NFTEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -140,24 +140,27 @@ contract MgdL2NFTEscrow is Initializable, IERC721Receiver, IERC1155Receiver {
/// @param nft token address to redeem
/// @param tokenId to redeeem
/// @param amount to redeem
/// @param owner who will receive nft
/// @param receiver who will receive nft
/// @param blockHash of tx in L2 where {MgdL2NFTVoucher.redeemVoucherToL1(...)} was called
/// @param marketData status of voucher when redeem call was initiated in L2
function getRedeemClearanceKey(
uint256 voucherId,
address nft,
uint256 tokenId,
uint256 amount,
address owner,
address receiver,
bytes32 blockHash,
MgdL1MarketData calldata marketData
MgdL1MarketData calldata marketData,
string memory tokenURI,
bytes memory tokenIdMemoir
)
external
view
returns (bool)
{
uint256 key =
_generateL1RedeemKey(voucherId, nft, tokenId, amount, owner, blockHash, marketData);
uint256 key = _generateL1RedeemKey(
voucherId, nft, tokenId, amount, receiver, blockHash, marketData, tokenURI, tokenIdMemoir
);
return redeemClearance[key];
}

Expand All @@ -180,13 +183,14 @@ contract MgdL2NFTEscrow is Initializable, IERC721Receiver, IERC1155Receiver {
address receiver,
bytes32 blockHash,
MgdL1MarketData calldata marketData,
string calldata tokenURI,
bytes calldata memoir
string memory tokenURI,
bytes memory memoir
)
external
{
uint256 key =
_generateL1RedeemKey(voucherId, nft, tokenId, amount, receiver, blockHash, marketData);
uint256 key = _generateL1RedeemKey(
voucherId, nft, tokenId, amount, receiver, blockHash, marketData, tokenURI, memoir
);
if (!redeemClearance[key]) {
revert MgdL2NFTEscrow__releaseFromEscrow_notClearedOrAlreadyReleased();
}
Expand Down Expand Up @@ -326,16 +330,30 @@ contract MgdL2NFTEscrow is Initializable, IERC721Receiver, IERC1155Receiver {
address nft,
uint256 tokenId,
uint256 amount,
address owner,
address receiver,
bytes32 blockHash,
MgdL1MarketData calldata marketData
MgdL1MarketData calldata marketData,
string memory tokenURI,
bytes memory tokenIdMemoir
)
internal
pure
returns (uint256 key)
{
key =
uint256(keccak256(abi.encode(voucherId, nft, tokenId, amount, owner, blockHash, marketData)));
if (tokenId == _REF_NUMBER) {
bytes32 hashedUriMemoir = keccak256(abi.encode(tokenURI, tokenIdMemoir));
key = uint256(
keccak256(
abi.encode(
voucherId, nft, tokenId, amount, receiver, blockHash, marketData, hashedUriMemoir
)
)
);
} else {
key = uint256(
keccak256(abi.encode(voucherId, nft, tokenId, amount, receiver, blockHash, marketData))
);
}
}

function _sendEscrowNoticeToL2(uint256 voucherId, bool state, TypeNFT nftType) internal {
Expand Down
7 changes: 4 additions & 3 deletions src/voucher/Mgd1155L2Voucher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,12 @@ contract Mgd1155L2Voucher is MgdL2BaseVoucher, ERC1155Permit, Almost1155Upgradea
_mint(owner, voucherId, representedAmount, "");

_voucherMarketData[voucherId] = marketData;
if (memoir.length > 0) {
_tokenIdMemoir[voucherId] = memoir;
}

if (generatedL1VoucherId == 0) {
_tokenURIs[voucherId] = tokenURI;
if (memoir.length > 0) {
_tokenIdMemoir[voucherId] = memoir;
}
emit MintGoldDustNFTMinted(
voucherId,
tokenURI,
Expand Down
7 changes: 4 additions & 3 deletions src/voucher/Mgd721L2Voucher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,12 @@ contract Mgd721L2Voucher is MgdL2BaseVoucher, ERC721Permit, Almost721Upgradeable
_safeMint(owner, voucherId);

_voucherMarketData[voucherId] = marketData;
if (memoir.length > 0) {
_tokenIdMemoir[voucherId] = memoir;
}

if (generatedL1VoucherId == 0) {
_tokenURIs[voucherId] = tokenURI;
if (memoir.length > 0) {
_tokenIdMemoir[voucherId] = memoir;
}
emit MintGoldDustNFTMinted(
voucherId,
tokenURI,
Expand Down
2 changes: 1 addition & 1 deletion src/voucher/MgdL2BaseNFT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ abstract contract MgdL2BaseNFT is Initializable, PausableUpgradeable, Reentrancy

// voucherId => struct MgdL1MarketData
mapping(uint256 => MgdL1MarketData) internal _voucherMarketData;

mapping(uint256 => string) internal _tokenURIs;
mapping(uint256 => bytes) internal _tokenIdMemoir;

/**
Expand Down
15 changes: 13 additions & 2 deletions src/voucher/MgdL2BaseVoucher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,19 @@ abstract contract MgdL2BaseVoucher is MgdL2BaseNFT {
returns (uint256 key, bytes32 blockHash)
{
blockHash = blockhash(block.number);
key =
uint256(keccak256(abi.encode(voucherId, nft, tokenId, amount, owner, blockHash, marketData)));
if (tokenId == _REF_NUMBER) {
bytes32 hashedUriMemoir =
keccak256(abi.encode(_tokenURIs[voucherId], _tokenIdMemoir[voucherId]));
key = uint256(
keccak256(
abi.encode(voucherId, nft, tokenId, amount, owner, blockHash, marketData, hashedUriMemoir)
)
);
} else {
key = uint256(
keccak256(abi.encode(voucherId, nft, tokenId, amount, owner, blockHash, marketData))
);
}
}

function _clearVoucherData(uint256 voucherId) internal {
Expand Down

0 comments on commit 9cb16d9

Please sign in to comment.