Skip to content

Commit

Permalink
chore: fix forge transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
cinnabarhorse committed May 8, 2024
1 parent e5444a0 commit 4dd4e92
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 50 deletions.
59 changes: 9 additions & 50 deletions contracts/Aavegotchi/ForgeDiamond/facets/ForgeTokenFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,7 @@ contract ForgeTokenFacet is Modifiers {
/**
* @dev See {IERC1155-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
) public {
function safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes memory data) public {
require(from == msg.sender || isApprovedForAll(from, msg.sender), "ForgeTokenFacet: caller is not token owner or approved");
_safeTransferFrom(from, to, id, amount, data);
}
Expand All @@ -141,18 +135,12 @@ contract ForgeTokenFacet is Modifiers {
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
* acceptance magic value.
*/
function _safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
) internal {
function _safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes memory data) internal {
require(to != address(0), "ForgeTokenFacet: transfer to the zero address");

LibToken.removeFromOwner(from, id, amount);
LibToken.addToOwner(to, id, amount);
IERC1155Marketplace(s.aavegotchiDiamond).updateERC1155Listing(s.aavegotchiDiamond, id, from);
IERC1155Marketplace(s.aavegotchiDiamond).updateERC1155Listing(address(this), id, from);

emit TransferSingle(LibMeta.msgSender(), from, to, id, amount);

Expand All @@ -169,13 +157,7 @@ contract ForgeTokenFacet is Modifiers {
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
* acceptance magic value.
*/
function _safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal {
function _safeBatchTransferFrom(address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data) internal {
require(ids.length == amounts.length, "ForgeTokenFacet: ids and amounts length mismatch");
require(to != address(0), "ForgeTokenFacet: transfer to the zero address");

Expand All @@ -185,7 +167,7 @@ contract ForgeTokenFacet is Modifiers {

LibToken.removeFromOwner(from, id, amount);
LibToken.addToOwner(to, id, amount);
IERC1155Marketplace(s.aavegotchiDiamond).updateERC1155Listing(s.aavegotchiDiamond, id, from);
IERC1155Marketplace(s.aavegotchiDiamond).updateERC1155Listing(address(this), id, from);
}

emit TransferBatch(LibMeta.msgSender(), from, to, ids, amounts);
Expand All @@ -198,24 +180,13 @@ contract ForgeTokenFacet is Modifiers {
*
* Emits an {ApprovalForAll} event.
*/
function _setApprovalForAll(
address owner,
address operator,
bool approved
) internal virtual {
function _setApprovalForAll(address owner, address operator, bool approved) internal virtual {
require(owner != operator, "ForgeTokenFacet: setting approval status for self");
s._operatorApprovals[owner][operator] = approved;
emit ApprovalForAll(owner, operator, approved);
}

function _doSafeTransferAcceptanceCheck(
address operator,
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
) private {
function _doSafeTransferAcceptanceCheck(address operator, address from, address to, uint256 id, uint256 amount, bytes memory data) private {
if (isContract(to)) {
try IERC1155Receiver(to).onERC1155Received(operator, from, id, amount, data) returns (bytes4 response) {
if (response != IERC1155Receiver.onERC1155Received.selector) {
Expand Down Expand Up @@ -260,23 +231,11 @@ contract ForgeTokenFacet is Modifiers {
}

// @dev Add support for receiving ERC1155 tokens.
function onERC1155Received(
address,
address,
uint256,
uint256,
bytes memory
) external returns (bytes4) {
function onERC1155Received(address, address, uint256, uint256, bytes memory) external returns (bytes4) {
return this.onERC1155Received.selector;
}

function onERC1155BatchReceived(
address,
address,
uint256[] memory,
uint256[] memory,
bytes memory
) external returns (bytes4) {
function onERC1155BatchReceived(address, address, uint256[] memory, uint256[] memory, bytes memory) external returns (bytes4) {
return this.onERC1155BatchReceived.selector;
}
}
40 changes: 40 additions & 0 deletions scripts/upgrades/forge/upgrade-forgeSafeTransfer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { run } from "hardhat";
import {
convertFacetAndSelectorsToString,
DeployUpgradeTaskArgs,
FacetsAndAddSelectors,
} from "../../../tasks/deployUpgrade";

import { maticDiamondUpgrader, maticForgeDiamond } from "../../helperFunctions";

export async function upgradeForgeListingsFix() {
console.log("Upgrading ForgeFacet to fix safe transfer");

const facets: FacetsAndAddSelectors[] = [
{
facetName: "ForgeTokenFacet",
addSelectors: [],
removeSelectors: [],
},
];
const joined = convertFacetAndSelectorsToString(facets);

const args: DeployUpgradeTaskArgs = {
diamondUpgrader: maticDiamondUpgrader,
diamondAddress: maticForgeDiamond,
facetsAndAddSelectors: joined,
useLedger: true,
useMultisig: false,
};

await run("deployUpgrade", args);
}

if (require.main === module) {
upgradeForgeListingsFix()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
}

0 comments on commit 4dd4e92

Please sign in to comment.