From 7a8d6ebf8734a852c0a281c9cbebdad3483f9805 Mon Sep 17 00:00:00 2001 From: Chanchal Delson Date: Sat, 7 Sep 2024 15:36:37 +0530 Subject: [PATCH] escrowMapping contract update --- packages/backend/ninja/.dockerignore | 10 + packages/backend/ninja/deployment.json | 4 +- packages/hardhat/contracts/EscrowMapping.sol | 46 + .../deploy/03_deploy_escrow_mapping.ts | 31 + .../{03_deploy_nft.ts => 04_deploy_nft.ts} | 0 .../nextjs/contracts/deployedContracts.ts | 1073 ++--------------- 6 files changed, 206 insertions(+), 958 deletions(-) create mode 100644 packages/backend/ninja/.dockerignore create mode 100644 packages/hardhat/contracts/EscrowMapping.sol create mode 100644 packages/hardhat/deploy/03_deploy_escrow_mapping.ts rename packages/hardhat/deploy/{03_deploy_nft.ts => 04_deploy_nft.ts} (100%) diff --git a/packages/backend/ninja/.dockerignore b/packages/backend/ninja/.dockerignore new file mode 100644 index 0000000..dcfb092 --- /dev/null +++ b/packages/backend/ninja/.dockerignore @@ -0,0 +1,10 @@ +# flyctl launch added from .gitignore +**/*.sqlite +**/node_modules +**/build +**/bun.lockb +**/stackr_build +**/.env +**/dist +**/.vercel +fly.toml diff --git a/packages/backend/ninja/deployment.json b/packages/backend/ninja/deployment.json index b1ab991..25c7075 100644 --- a/packages/backend/ninja/deployment.json +++ b/packages/backend/ninja/deployment.json @@ -1,5 +1,5 @@ { - "appId": 101, - "appInbox": "0xaf4a15008892e5Ca30B04A70891834c38d4b88b6", + "appId": 110, + "appInbox": "0x0d5aFA71F688B480469D9686C9C946910C804535", "chainId": 11155111 } \ No newline at end of file diff --git a/packages/hardhat/contracts/EscrowMapping.sol b/packages/hardhat/contracts/EscrowMapping.sol new file mode 100644 index 0000000..52c8163 --- /dev/null +++ b/packages/hardhat/contracts/EscrowMapping.sol @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +contract EscrowGameMapping { + address public owner; + + // Mapping from EscrowId (uint256) to GameId (bytes32) + mapping(uint256 => bytes32) public escrowToGame; + + // Event to log the mapping creation + event MappingCreated(uint256 indexed escrowId, bytes32 indexed gameId); + + // Modifier to restrict function access to the owner + modifier onlyOwner() { + require(msg.sender == owner, "Caller is not the owner"); + _; + } + + // Constructor to set the contract deployer as the initial owner + constructor() { + owner = msg.sender; + } + + // Function to transfer ownership to a new address (only callable by the current owner) + function transferOwnership(address newOwner) public onlyOwner { + require(newOwner != address(0), "New owner is the zero address"); + owner = newOwner; + } + + // Function to create a new mapping between EscrowId and GameId + function createMapping(uint256 escrowId, bytes32 gameId) public onlyOwner { + // Ensure that the EscrowId is not already mapped + require(escrowToGame[escrowId] == bytes32(0), "EscrowId is already mapped to a GameId."); + + // Create the mapping + escrowToGame[escrowId] = gameId; + + // Emit the event + emit MappingCreated(escrowId, gameId); + } + + // Function to retrieve the GameId for a given EscrowId + function getGameId(uint256 escrowId) public view returns (bytes32) { + return escrowToGame[escrowId]; + } +} diff --git a/packages/hardhat/deploy/03_deploy_escrow_mapping.ts b/packages/hardhat/deploy/03_deploy_escrow_mapping.ts new file mode 100644 index 0000000..d1927d2 --- /dev/null +++ b/packages/hardhat/deploy/03_deploy_escrow_mapping.ts @@ -0,0 +1,31 @@ +import { HardhatRuntimeEnvironment } from "hardhat/types"; +import { DeployFunction } from "hardhat-deploy/types"; +import { Contract } from "ethers"; + +/** + * Deploys a contract named "EscrowGameMapping" using the deployer account + * + * @param hre HardhatRuntimeEnvironment object. + */ +const deployEscrowGameMapping: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { + const { deployer } = await hre.getNamedAccounts(); + const { deploy } = hre.deployments; + + // Deploy the contract + await deploy("EscrowGameMapping", { + from: deployer, + args: [], // No constructor arguments + log: true, + autoMine: true, + }); + + // Get the deployed contract to interact with it after deploying. + const escrowGameMapping: Contract = await hre.ethers.getContract("EscrowGameMapping", deployer); + console.log("🥷🏻 Deployed", await escrowGameMapping.getAddress()); +}; + +export default deployEscrowGameMapping; + +// Tags are useful if you have multiple deploy files and only want to run one of them. +// e.g. yarn deploy --tags EscrowGameMapping +deployEscrowGameMapping.tags = ["EscrowGameMapping"]; diff --git a/packages/hardhat/deploy/03_deploy_nft.ts b/packages/hardhat/deploy/04_deploy_nft.ts similarity index 100% rename from packages/hardhat/deploy/03_deploy_nft.ts rename to packages/hardhat/deploy/04_deploy_nft.ts diff --git a/packages/nextjs/contracts/deployedContracts.ts b/packages/nextjs/contracts/deployedContracts.ts index 123300d..b933eb7 100644 --- a/packages/nextjs/contracts/deployedContracts.ts +++ b/packages/nextjs/contracts/deployedContracts.ts @@ -7,7 +7,7 @@ import { GenericContractsDeclaration } from "~~/utils/scaffold-eth/contract"; const deployedContracts = { 31337: { Escrow: { - address: "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0", + address: "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9", abi: [ { inputs: [ @@ -430,8 +430,120 @@ const deployedContracts = { transferOwnership: "@openzeppelin/contracts/access/Ownable.sol", }, }, + EscrowGameMapping: { + address: "0x0165878A594ca255338adfa4d48449f69242Eb8F", + abi: [ + { + inputs: [], + stateMutability: "nonpayable", + type: "constructor", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "uint256", + name: "escrowId", + type: "uint256", + }, + { + indexed: true, + internalType: "bytes32", + name: "gameId", + type: "bytes32", + }, + ], + name: "MappingCreated", + type: "event", + }, + { + inputs: [ + { + internalType: "uint256", + name: "escrowId", + type: "uint256", + }, + { + internalType: "bytes32", + name: "gameId", + type: "bytes32", + }, + ], + name: "createMapping", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + name: "escrowToGame", + outputs: [ + { + internalType: "bytes32", + name: "", + type: "bytes32", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "escrowId", + type: "uint256", + }, + ], + name: "getGameId", + outputs: [ + { + internalType: "bytes32", + name: "", + type: "bytes32", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "owner", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "newOwner", + type: "address", + }, + ], + name: "transferOwnership", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + ], + inheritedFunctions: {}, + }, NFT: { - address: "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9", + address: "0x5FC8d32690cc91D4c39d9d3abcBD16989F875707", abi: [ { inputs: [], @@ -1151,7 +1263,7 @@ const deployedContracts = { }, }, Token: { - address: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", + address: "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9", abi: [ { inputs: [], @@ -1444,959 +1556,7 @@ const deployedContracts = { }, }, YourContract: { - address: "0x5FbDB2315678afecb367f032d93F642f64180aa3", - abi: [ - { - inputs: [ - { - internalType: "address", - name: "_owner", - type: "address", - }, - ], - stateMutability: "nonpayable", - type: "constructor", - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: "address", - name: "greetingSetter", - type: "address", - }, - { - indexed: false, - internalType: "string", - name: "newGreeting", - type: "string", - }, - { - indexed: false, - internalType: "bool", - name: "premium", - type: "bool", - }, - { - indexed: false, - internalType: "uint256", - name: "value", - type: "uint256", - }, - ], - name: "GreetingChange", - type: "event", - }, - { - inputs: [], - name: "greeting", - outputs: [ - { - internalType: "string", - name: "", - type: "string", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "owner", - outputs: [ - { - internalType: "address", - name: "", - type: "address", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "premium", - outputs: [ - { - internalType: "bool", - name: "", - type: "bool", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "string", - name: "_newGreeting", - type: "string", - }, - ], - name: "setGreeting", - outputs: [], - stateMutability: "payable", - type: "function", - }, - { - inputs: [], - name: "totalCounter", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "", - type: "address", - }, - ], - name: "userGreetingCounter", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "withdraw", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - stateMutability: "payable", - type: "receive", - }, - ], - inheritedFunctions: {}, - }, - }, - 11155111: { - Escrow: { - address: "0x9C32b71d0555522EC692D3f9ceF15B88f6400E95", - abi: [ - { - inputs: [ - { - internalType: "contract IERC20", - name: "_escrowToken", - type: "address", - }, - { - internalType: "uint256", - name: "_fee", - type: "uint256", - }, - { - internalType: "uint256", - name: "_minEthRequired", - type: "uint256", - }, - { - internalType: "address", - name: "_owner", - type: "address", - }, - ], - stateMutability: "nonpayable", - type: "constructor", - }, - { - inputs: [ - { - internalType: "address", - name: "target", - type: "address", - }, - ], - name: "AddressEmptyCode", - type: "error", - }, - { - inputs: [ - { - internalType: "address", - name: "account", - type: "address", - }, - ], - name: "AddressInsufficientBalance", - type: "error", - }, - { - inputs: [], - name: "FailedInnerCall", - type: "error", - }, - { - inputs: [ - { - internalType: "address", - name: "owner", - type: "address", - }, - ], - name: "OwnableInvalidOwner", - type: "error", - }, - { - inputs: [ - { - internalType: "address", - name: "account", - type: "address", - }, - ], - name: "OwnableUnauthorizedAccount", - type: "error", - }, - { - inputs: [ - { - internalType: "address", - name: "token", - type: "address", - }, - ], - name: "SafeERC20FailedOperation", - type: "error", - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: "address", - name: "user", - type: "address", - }, - { - indexed: false, - internalType: "uint256", - name: "amount", - type: "uint256", - }, - { - indexed: false, - internalType: "enum Escrow.EscrowType", - name: "escrowType", - type: "uint8", - }, - { - indexed: false, - internalType: "uint256", - name: "escrowId", - type: "uint256", - }, - ], - name: "Deposited", - type: "event", - }, - { - anonymous: false, - inputs: [ - { - indexed: false, - internalType: "uint256", - name: "oldMinEthRequired", - type: "uint256", - }, - { - indexed: false, - internalType: "uint256", - name: "newMinEthRequired", - type: "uint256", - }, - ], - name: "MinEthRequiredUpdated", - type: "event", - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: "address", - name: "previousOwner", - type: "address", - }, - { - indexed: true, - internalType: "address", - name: "newOwner", - type: "address", - }, - ], - name: "OwnershipTransferred", - type: "event", - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: "address", - name: "winner", - type: "address", - }, - { - indexed: false, - internalType: "uint256", - name: "amount", - type: "uint256", - }, - { - indexed: false, - internalType: "uint256", - name: "escrowId", - type: "uint256", - }, - ], - name: "Released", - type: "event", - }, - { - stateMutability: "payable", - type: "fallback", - }, - { - inputs: [], - name: "depositEth", - outputs: [], - stateMutability: "payable", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "amount", - type: "uint256", - }, - ], - name: "depositToken", - outputs: [], - stateMutability: "payable", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - name: "escrowIds", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "escrowToken", - outputs: [ - { - internalType: "contract IERC20", - name: "", - type: "address", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - name: "escrows", - outputs: [ - { - internalType: "uint256", - name: "id", - type: "uint256", - }, - { - internalType: "enum Escrow.EscrowType", - name: "escrowType", - type: "uint8", - }, - { - internalType: "address", - name: "depositor1", - type: "address", - }, - { - internalType: "address", - name: "depositor2", - type: "address", - }, - { - internalType: "uint256", - name: "amount", - type: "uint256", - }, - { - internalType: "bool", - name: "isReleased", - type: "bool", - }, - { - internalType: "string", - name: "gameData", - type: "string", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "fee", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "getAllEscrows", - outputs: [ - { - internalType: "uint256[]", - name: "", - type: "uint256[]", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "userAddress", - type: "address", - }, - ], - name: "getAllUserEscrows", - outputs: [ - { - internalType: "uint256[]", - name: "", - type: "uint256[]", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "escrowId", - type: "uint256", - }, - ], - name: "joinEscrow", - outputs: [], - stateMutability: "payable", - type: "function", - }, - { - inputs: [], - name: "minEthRequired", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "owner", - outputs: [ - { - internalType: "address", - name: "", - type: "address", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "address payable", - name: "recipient", - type: "address", - }, - ], - name: "recoverFunds", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "escrowId", - type: "uint256", - }, - { - internalType: "address payable", - name: "winner", - type: "address", - }, - { - internalType: "string", - name: "gameData", - type: "string", - }, - ], - name: "releaseFunds", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [], - name: "renounceOwnership", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "newOwner", - type: "address", - }, - ], - name: "transferOwnership", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "_minEthRequired", - type: "uint256", - }, - ], - name: "updateMinEthRequired", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "", - type: "address", - }, - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - name: "userEscrows", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - stateMutability: "payable", - type: "receive", - }, - ], - inheritedFunctions: { - owner: "@openzeppelin/contracts/access/Ownable.sol", - renounceOwnership: "@openzeppelin/contracts/access/Ownable.sol", - transferOwnership: "@openzeppelin/contracts/access/Ownable.sol", - }, - }, - Token: { - address: "0x4f3396dA82b9919AA4e13D76c04F6F2551a7b929", - abi: [ - { - inputs: [], - stateMutability: "nonpayable", - type: "constructor", - }, - { - inputs: [ - { - internalType: "address", - name: "spender", - type: "address", - }, - { - internalType: "uint256", - name: "allowance", - type: "uint256", - }, - { - internalType: "uint256", - name: "needed", - type: "uint256", - }, - ], - name: "ERC20InsufficientAllowance", - type: "error", - }, - { - inputs: [ - { - internalType: "address", - name: "sender", - type: "address", - }, - { - internalType: "uint256", - name: "balance", - type: "uint256", - }, - { - internalType: "uint256", - name: "needed", - type: "uint256", - }, - ], - name: "ERC20InsufficientBalance", - type: "error", - }, - { - inputs: [ - { - internalType: "address", - name: "approver", - type: "address", - }, - ], - name: "ERC20InvalidApprover", - type: "error", - }, - { - inputs: [ - { - internalType: "address", - name: "receiver", - type: "address", - }, - ], - name: "ERC20InvalidReceiver", - type: "error", - }, - { - inputs: [ - { - internalType: "address", - name: "sender", - type: "address", - }, - ], - name: "ERC20InvalidSender", - type: "error", - }, - { - inputs: [ - { - internalType: "address", - name: "spender", - type: "address", - }, - ], - name: "ERC20InvalidSpender", - type: "error", - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: "address", - name: "owner", - type: "address", - }, - { - indexed: true, - internalType: "address", - name: "spender", - type: "address", - }, - { - indexed: false, - internalType: "uint256", - name: "value", - type: "uint256", - }, - ], - name: "Approval", - type: "event", - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: "address", - name: "from", - type: "address", - }, - { - indexed: true, - internalType: "address", - name: "to", - type: "address", - }, - { - indexed: false, - internalType: "uint256", - name: "value", - type: "uint256", - }, - ], - name: "Transfer", - type: "event", - }, - { - inputs: [ - { - internalType: "address", - name: "owner", - type: "address", - }, - { - internalType: "address", - name: "spender", - type: "address", - }, - ], - name: "allowance", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "spender", - type: "address", - }, - { - internalType: "uint256", - name: "value", - type: "uint256", - }, - ], - name: "approve", - outputs: [ - { - internalType: "bool", - name: "", - type: "bool", - }, - ], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "account", - type: "address", - }, - ], - name: "balanceOf", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "decimals", - outputs: [ - { - internalType: "uint8", - name: "", - type: "uint8", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "name", - outputs: [ - { - internalType: "string", - name: "", - type: "string", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "symbol", - outputs: [ - { - internalType: "string", - name: "", - type: "string", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "totalSupply", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "to", - type: "address", - }, - { - internalType: "uint256", - name: "value", - type: "uint256", - }, - ], - name: "transfer", - outputs: [ - { - internalType: "bool", - name: "", - type: "bool", - }, - ], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "from", - type: "address", - }, - { - internalType: "address", - name: "to", - type: "address", - }, - { - internalType: "uint256", - name: "value", - type: "uint256", - }, - ], - name: "transferFrom", - outputs: [ - { - internalType: "bool", - name: "", - type: "bool", - }, - ], - stateMutability: "nonpayable", - type: "function", - }, - ], - inheritedFunctions: { - allowance: "@openzeppelin/contracts/token/ERC20/ERC20.sol", - approve: "@openzeppelin/contracts/token/ERC20/ERC20.sol", - balanceOf: "@openzeppelin/contracts/token/ERC20/ERC20.sol", - decimals: "@openzeppelin/contracts/token/ERC20/ERC20.sol", - decreaseAllowance: "@openzeppelin/contracts/token/ERC20/ERC20.sol", - increaseAllowance: "@openzeppelin/contracts/token/ERC20/ERC20.sol", - name: "@openzeppelin/contracts/token/ERC20/ERC20.sol", - symbol: "@openzeppelin/contracts/token/ERC20/ERC20.sol", - totalSupply: "@openzeppelin/contracts/token/ERC20/ERC20.sol", - transfer: "@openzeppelin/contracts/token/ERC20/ERC20.sol", - transferFrom: "@openzeppelin/contracts/token/ERC20/ERC20.sol", - }, - }, - YourContract: { - address: "0x9fd95f5701708529edf55C38BCa5cD0f6cD1FEc5", + address: "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0", abi: [ { inputs: [ @@ -2539,6 +1699,7 @@ const deployedContracts = { inheritedFunctions: {}, }, }, + 11155111: {}, } as const; export default deployedContracts satisfies GenericContractsDeclaration;