From 9f1a8713959ee716964aed03f0b5c6dcd7016a8a Mon Sep 17 00:00:00 2001 From: Dhaiwat Pandya Date: Thu, 21 Oct 2021 23:29:48 +0530 Subject: [PATCH 1/7] Setup rinkeby --- packages/hardhat/hardhat.config.js | 22 +- .../src/contracts/hardhat_contracts.json | 266 +++------------- packages/react-app/src/views/TokenSwap.jsx | 1 + packages/subgraph/abis/rinkeby_MoonSwap.json | 290 ++++++++++++++++++ packages/subgraph/abis/rinkeby_dETH.json | 290 ++++++++++++++++++ packages/subgraph/abis/rinkeby_dGTC.json | 290 ++++++++++++++++++ packages/subgraph/config/config.json | 5 +- yarn.lock | 76 ++++- 8 files changed, 1005 insertions(+), 235 deletions(-) create mode 100644 packages/subgraph/abis/rinkeby_MoonSwap.json create mode 100644 packages/subgraph/abis/rinkeby_dETH.json create mode 100644 packages/subgraph/abis/rinkeby_dGTC.json diff --git a/packages/hardhat/hardhat.config.js b/packages/hardhat/hardhat.config.js index 8decf05..c133eb0 100644 --- a/packages/hardhat/hardhat.config.js +++ b/packages/hardhat/hardhat.config.js @@ -26,7 +26,7 @@ const { isAddress, getAddress, formatUnits, parseUnits } = utils; // // Select the network you want to deploy to here: // -const defaultNetwork = "hardhat"; +const defaultNetwork = "rinkeby"; const mainnetGwei = 21; @@ -63,10 +63,10 @@ module.exports = { */ }, - // rinkeby: { - // url: `https://rinkeby.infura.io/v3/${process.env.RINKEBY_INFURA_KEY}`, - // accounts: [`${process.env.RINKEBY_DEPLOYER_PRIV_KEY}`], - // }, + rinkeby: { + url: `https://rinkeby.infura.io/v3/${process.env.RINKEBY_INFURA_KEY}`, + accounts: [`${process.env.RINKEBY_DEPLOYER_PRIV_KEY}`], + }, // kovan: { // url: `https://rinkeby.infura.io/v3/${process.env.KOVAN_INFURA_KEY}`, // accounts: [`${process.env.KOVAN_DEPLOYER_PRIV_KEY}`], @@ -89,14 +89,14 @@ module.exports = { // accounts: [`${process.env.XDAI_DEPLOYER_PRIV_KEY}`], // }, - rinkeby: { - url: "https://rinkeby.infura.io/v3/460f40a260564ac4a4f4b3fffb032dad", // <---- YOUR INFURA ID! (or it won't work) + // rinkeby: { + // url: "https://rinkeby.infura.io/v3/460f40a260564ac4a4f4b3fffb032dad", // <---- YOUR INFURA ID! (or it won't work) - // url: "https://speedy-nodes-nyc.moralis.io/XXXXXXXXXXXXXXXXXXXXXXX/eth/rinkeby", // <---- YOUR MORALIS ID! (not limited to infura) + // // url: "https://speedy-nodes-nyc.moralis.io/XXXXXXXXXXXXXXXXXXXXXXX/eth/rinkeby", // <---- YOUR MORALIS ID! (not limited to infura) - accounts: - process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [], - }, + // accounts: + // process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [], + // }, mainnet: { url: "https://mainnet.infura.io/v3/460f40a260564ac4a4f4b3fffb032dad", // <---- YOUR INFURA ID! (or it won't work) diff --git a/packages/react-app/src/contracts/hardhat_contracts.json b/packages/react-app/src/contracts/hardhat_contracts.json index d01ac62..df164bb 100644 --- a/packages/react-app/src/contracts/hardhat_contracts.json +++ b/packages/react-app/src/contracts/hardhat_contracts.json @@ -1,32 +1,18 @@ { - "31337": { - "localhost": { - "name": "localhost", - "chainId": "31337", + "4": { + "rinkeby": { + "name": "rinkeby", + "chainId": "4", "contracts": { "MoonSwap": { - "address": "0x5FbDB2315678afecb367f032d93F642f64180aa3", + "address": "0x8719168f2d330e389429aBB23E71F2D0CCff34DA", "abi": [ - { - "inputs": [], - "stateMutability": "nonpayable", - "type": "constructor" - }, + { "inputs": [], "stateMutability": "nonpayable", "type": "constructor" }, { "anonymous": false, "inputs": [ - { - "indexed": true, - "internalType": "uint256", - "name": "id", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "address", - "name": "outTokenParty", - "type": "address" - } + { "indexed": true, "internalType": "uint256", "name": "id", "type": "uint256" }, + { "indexed": false, "internalType": "address", "name": "outTokenParty", "type": "address" } ], "name": "CloseSwap", "type": "event" @@ -34,263 +20,99 @@ { "anonymous": false, "inputs": [ - { - "indexed": true, - "internalType": "uint256", - "name": "id", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "address", - "name": "inToken", - "type": "address" - }, - { - "indexed": false, - "internalType": "address", - "name": "outToken", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "inTokens", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "outTokens", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "address", - "name": "inTokenParty", - "type": "address" - }, - { - "indexed": false, - "internalType": "address", - "name": "outTokenParty", - "type": "address" - } + { "indexed": true, "internalType": "uint256", "name": "id", "type": "uint256" }, + { "indexed": false, "internalType": "address", "name": "inToken", "type": "address" }, + { "indexed": false, "internalType": "address", "name": "outToken", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "inTokens", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "outTokens", "type": "uint256" }, + { "indexed": false, "internalType": "address", "name": "inTokenParty", "type": "address" }, + { "indexed": false, "internalType": "address", "name": "outTokenParty", "type": "address" } ], "name": "NewSwap", "type": "event" }, { "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "uint256", - "name": "id", - "type": "uint256" - } - ], + "inputs": [{ "indexed": true, "internalType": "uint256", "name": "id", "type": "uint256" }], "name": "RevokeSwap", "type": "event" }, { "inputs": [], "name": "admin", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { - "inputs": [ - { - "internalType": "contract IERC20", - "name": "_token", - "type": "address" - } - ], + "inputs": [{ "internalType": "contract IERC20", "name": "_token", "type": "address" }], "name": "claimFees", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], + "inputs": [{ "internalType": "address", "name": "", "type": "address" }], "name": "claimableFees", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [ - { - "internalType": "uint256", - "name": "_swapId", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "_outTokens", - "type": "uint256" - } + { "internalType": "uint256", "name": "_swapId", "type": "uint256" }, + { "internalType": "uint256", "name": "_outTokens", "type": "uint256" } ], "name": "commitToSwap", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ - { - "internalType": "contract IERC20", - "name": "_inToken", - "type": "address" - }, - { - "internalType": "contract IERC20", - "name": "_outToken", - "type": "address" - }, - { - "internalType": "uint256", - "name": "_inTokens", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "_outTokens", - "type": "uint256" - }, - { - "internalType": "address", - "name": "_tokenOutParty", - "type": "address" - } + { "internalType": "contract IERC20", "name": "_inToken", "type": "address" }, + { "internalType": "contract IERC20", "name": "_outToken", "type": "address" }, + { "internalType": "uint256", "name": "_inTokens", "type": "uint256" }, + { "internalType": "uint256", "name": "_outTokens", "type": "uint256" }, + { "internalType": "address", "name": "_tokenOutParty", "type": "address" } ], "name": "createNewSwap", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "getActiveSwaps", - "outputs": [ - { - "internalType": "uint256[]", - "name": "", - "type": "uint256[]" - } - ], + "outputs": [{ "internalType": "uint256[]", "name": "", "type": "uint256[]" }], "stateMutability": "view", "type": "function" }, { - "inputs": [ - { - "internalType": "uint256", - "name": "_swapId", - "type": "uint256" - } - ], + "inputs": [{ "internalType": "uint256", "name": "_swapId", "type": "uint256" }], "name": "revokeSwap", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "swapId", - "outputs": [ - { - "internalType": "uint256", - "name": "_value", - "type": "uint256" - } - ], + "outputs": [{ "internalType": "uint256", "name": "_value", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { - "inputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], + "inputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "name": "swaps", "outputs": [ - { - "internalType": "contract IERC20", - "name": "inToken", - "type": "address" - }, - { - "internalType": "contract IERC20", - "name": "outToken", - "type": "address" - }, - { - "internalType": "uint256", - "name": "tokensIn", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "tokensOut", - "type": "uint256" - }, - { - "internalType": "address", - "name": "inTokenParty", - "type": "address" - }, - { - "internalType": "address", - "name": "outTokenParty", - "type": "address" - }, - { - "internalType": "bool", - "name": "status", - "type": "bool" - } + { "internalType": "contract IERC20", "name": "inToken", "type": "address" }, + { "internalType": "contract IERC20", "name": "outToken", "type": "address" }, + { "internalType": "uint256", "name": "tokensIn", "type": "uint256" }, + { "internalType": "uint256", "name": "tokensOut", "type": "uint256" }, + { "internalType": "address", "name": "inTokenParty", "type": "address" }, + { "internalType": "address", "name": "outTokenParty", "type": "address" }, + { "internalType": "bool", "name": "status", "type": "bool" } ], "stateMutability": "view", "type": "function" @@ -298,7 +120,7 @@ ] }, "dGTC": { - "address": "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", + "address": "0xE0F028C08852D70243BD7c6EF030bCf6049e6d98", "abi": [ { "inputs": [], @@ -591,7 +413,7 @@ ] }, "dETH": { - "address": "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0", + "address": "0x1d269Cf95A2732ce98fAaF909642D756b59Af0aF", "abi": [ { "inputs": [], @@ -886,4 +708,4 @@ } } } -} \ No newline at end of file +} diff --git a/packages/react-app/src/views/TokenSwap.jsx b/packages/react-app/src/views/TokenSwap.jsx index b1800b2..42d7a92 100644 --- a/packages/react-app/src/views/TokenSwap.jsx +++ b/packages/react-app/src/views/TokenSwap.jsx @@ -92,6 +92,7 @@ export default function TokenSwap({ let swapId = null; if (readContracts?.MoonSwap) { swapId = await readContracts.MoonSwap.swapId(); + tokenOut = await readContracts.MoonSwap.tokenOut(); } const result = tx(writeContracts.MoonSwap.commitToSwap({ swapId, tokenOut }), update => { console.log("📡 Swap Committed:", update); diff --git a/packages/subgraph/abis/rinkeby_MoonSwap.json b/packages/subgraph/abis/rinkeby_MoonSwap.json new file mode 100644 index 0000000..ea0ab9b --- /dev/null +++ b/packages/subgraph/abis/rinkeby_MoonSwap.json @@ -0,0 +1,290 @@ +[ + { + "inputs": [], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "id", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "address", + "name": "outTokenParty", + "type": "address" + } + ], + "name": "CloseSwap", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "id", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "address", + "name": "inToken", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "outToken", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "inTokens", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "outTokens", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "address", + "name": "inTokenParty", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "outTokenParty", + "type": "address" + } + ], + "name": "NewSwap", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "id", + "type": "uint256" + } + ], + "name": "RevokeSwap", + "type": "event" + }, + { + "inputs": [], + "name": "admin", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "contract IERC20", + "name": "_token", + "type": "address" + } + ], + "name": "claimFees", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "claimableFees", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_swapId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_outTokens", + "type": "uint256" + } + ], + "name": "commitToSwap", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "contract IERC20", + "name": "_inToken", + "type": "address" + }, + { + "internalType": "contract IERC20", + "name": "_outToken", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_inTokens", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_outTokens", + "type": "uint256" + }, + { + "internalType": "address", + "name": "_tokenOutParty", + "type": "address" + } + ], + "name": "createNewSwap", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "getActiveSwaps", + "outputs": [ + { + "internalType": "uint256[]", + "name": "", + "type": "uint256[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_swapId", + "type": "uint256" + } + ], + "name": "revokeSwap", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "swapId", + "outputs": [ + { + "internalType": "uint256", + "name": "_value", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "swaps", + "outputs": [ + { + "internalType": "contract IERC20", + "name": "inToken", + "type": "address" + }, + { + "internalType": "contract IERC20", + "name": "outToken", + "type": "address" + }, + { + "internalType": "uint256", + "name": "tokensIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokensOut", + "type": "uint256" + }, + { + "internalType": "address", + "name": "inTokenParty", + "type": "address" + }, + { + "internalType": "address", + "name": "outTokenParty", + "type": "address" + }, + { + "internalType": "bool", + "name": "status", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + } +] \ No newline at end of file diff --git a/packages/subgraph/abis/rinkeby_dETH.json b/packages/subgraph/abis/rinkeby_dETH.json new file mode 100644 index 0000000..d106e81 --- /dev/null +++ b/packages/subgraph/abis/rinkeby_dETH.json @@ -0,0 +1,290 @@ +[ + { + "inputs": [], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "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": "amount", + "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": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "subtractedValue", + "type": "uint256" + } + ], + "name": "decreaseAllowance", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "addedValue", + "type": "uint256" + } + ], + "name": "increaseAllowance", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "mint4Me", + "outputs": [], + "stateMutability": "nonpayable", + "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": "recipient", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "transfer", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "transferFrom", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + } +] \ No newline at end of file diff --git a/packages/subgraph/abis/rinkeby_dGTC.json b/packages/subgraph/abis/rinkeby_dGTC.json new file mode 100644 index 0000000..d106e81 --- /dev/null +++ b/packages/subgraph/abis/rinkeby_dGTC.json @@ -0,0 +1,290 @@ +[ + { + "inputs": [], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "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": "amount", + "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": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "subtractedValue", + "type": "uint256" + } + ], + "name": "decreaseAllowance", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "addedValue", + "type": "uint256" + } + ], + "name": "increaseAllowance", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "mint4Me", + "outputs": [], + "stateMutability": "nonpayable", + "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": "recipient", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "transfer", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "transferFrom", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + } +] \ No newline at end of file diff --git a/packages/subgraph/config/config.json b/packages/subgraph/config/config.json index 5988447..b80f886 100644 --- a/packages/subgraph/config/config.json +++ b/packages/subgraph/config/config.json @@ -1,5 +1,8 @@ { "localhost_MoonSwapAddress": "0x5FbDB2315678afecb367f032d93F642f64180aa3", "localhost_dGTCAddress": "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", - "localhost_dETHAddress": "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0" + "localhost_dETHAddress": "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0", + "rinkeby_MoonSwapAddress": "0x28D480c56eE7064aed894E8ABbaa15F01DB30ebA", + "rinkeby_dETHAddress": "0x1d269Cf95A2732ce98fAaF909642D756b59Af0aF", + "rinkeby_dGTCAddress": "0xE0F028C08852D70243BD7c6EF030bCf6049e6d98" } \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index e71b273..f3e57b0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1544,6 +1544,17 @@ "@ethersproject/logger" "^5.4.0" "@ethersproject/rlp" "^5.4.0" +"@ethersproject/address@^5.0.2": + version "5.5.0" + resolved "https://registry.yarnpkg.com/@ethersproject/address/-/address-5.5.0.tgz#bcc6f576a553f21f3dd7ba17248f81b473c9c78f" + integrity sha512-l4Nj0eWlTUh6ro5IbPTgbpT4wRbdH5l8CQf7icF7sb/SI3Nhd9Y9HzhonTSTi6CefI0necIw7LJqQPopPLZyWw== + dependencies: + "@ethersproject/bignumber" "^5.5.0" + "@ethersproject/bytes" "^5.5.0" + "@ethersproject/keccak256" "^5.5.0" + "@ethersproject/logger" "^5.5.0" + "@ethersproject/rlp" "^5.5.0" + "@ethersproject/base64@5.4.0", "@ethersproject/base64@^5.4.0": version "5.4.0" resolved "https://registry.yarnpkg.com/@ethersproject/base64/-/base64-5.4.0.tgz#7252bf65295954c9048c7ca5f43e5c86441b2a9a" @@ -1568,6 +1579,15 @@ "@ethersproject/logger" "^5.4.0" bn.js "^4.11.9" +"@ethersproject/bignumber@^5.5.0": + version "5.5.0" + resolved "https://registry.yarnpkg.com/@ethersproject/bignumber/-/bignumber-5.5.0.tgz#875b143f04a216f4f8b96245bde942d42d279527" + integrity sha512-6Xytlwvy6Rn3U3gKEc1vP7nR92frHkv6wtVr95LFR3jREXiCPzdWxKQ1cx4JGQBXxcguAwjA8murlYN2TSiEbg== + dependencies: + "@ethersproject/bytes" "^5.5.0" + "@ethersproject/logger" "^5.5.0" + bn.js "^4.11.9" + "@ethersproject/bytes@5.4.0", "@ethersproject/bytes@>=5.0.0-beta.129", "@ethersproject/bytes@^5.0.8", "@ethersproject/bytes@^5.4.0": version "5.4.0" resolved "https://registry.yarnpkg.com/@ethersproject/bytes/-/bytes-5.4.0.tgz#56fa32ce3bf67153756dbaefda921d1d4774404e" @@ -1575,6 +1595,13 @@ dependencies: "@ethersproject/logger" "^5.4.0" +"@ethersproject/bytes@^5.5.0": + version "5.5.0" + resolved "https://registry.yarnpkg.com/@ethersproject/bytes/-/bytes-5.5.0.tgz#cb11c526de657e7b45d2e0f0246fb3b9d29a601c" + integrity sha512-ABvc7BHWhZU9PNM/tANm/Qx4ostPGadAuQzWTr3doklZOhDlmcBqclrQe/ZXUIj3K8wC28oYeuRa+A37tX9kog== + dependencies: + "@ethersproject/logger" "^5.5.0" + "@ethersproject/constants@5.4.0", "@ethersproject/constants@>=5.0.0-beta.128", "@ethersproject/constants@^5.4.0": version "5.4.0" resolved "https://registry.yarnpkg.com/@ethersproject/constants/-/constants-5.4.0.tgz#ee0bdcb30bf1b532d2353c977bf2ef1ee117958a" @@ -1657,11 +1684,24 @@ "@ethersproject/bytes" "^5.4.0" js-sha3 "0.5.7" +"@ethersproject/keccak256@^5.5.0": + version "5.5.0" + resolved "https://registry.yarnpkg.com/@ethersproject/keccak256/-/keccak256-5.5.0.tgz#e4b1f9d7701da87c564ffe336f86dcee82983492" + integrity sha512-5VoFCTjo2rYbBe1l2f4mccaRFN/4VQEYFwwn04aJV2h7qf4ZvI2wFxUE1XOX+snbwCLRzIeikOqtAoPwMza9kg== + dependencies: + "@ethersproject/bytes" "^5.5.0" + js-sha3 "0.8.0" + "@ethersproject/logger@5.4.1", "@ethersproject/logger@>=5.0.0-beta.129", "@ethersproject/logger@^5.4.0": version "5.4.1" resolved "https://registry.yarnpkg.com/@ethersproject/logger/-/logger-5.4.1.tgz#503bd33683538b923c578c07d1c2c0dd18672054" integrity sha512-DZ+bRinnYLPw1yAC64oRl0QyVZj43QeHIhVKfD/+YwSz4wsv1pfwb5SOFjz+r710YEWzU6LrhuSjpSO+6PeE4A== +"@ethersproject/logger@^5.5.0": + version "5.5.0" + resolved "https://registry.yarnpkg.com/@ethersproject/logger/-/logger-5.5.0.tgz#0c2caebeff98e10aefa5aef27d7441c7fd18cf5d" + integrity sha512-rIY/6WPm7T8n3qS2vuHTUBPdXHl+rGxWxW5okDfo9J4Z0+gRRZT0msvUdIJkE4/HS29GUMziwGaaKO2bWONBrg== + "@ethersproject/networks@5.4.2", "@ethersproject/networks@^5.4.0", "@ethersproject/networks@^5.4.1": version "5.4.2" resolved "https://registry.yarnpkg.com/@ethersproject/networks/-/networks-5.4.2.tgz#2247d977626e97e2c3b8ee73cd2457babde0ce35" @@ -1725,6 +1765,14 @@ "@ethersproject/bytes" "^5.4.0" "@ethersproject/logger" "^5.4.0" +"@ethersproject/rlp@^5.5.0": + version "5.5.0" + resolved "https://registry.yarnpkg.com/@ethersproject/rlp/-/rlp-5.5.0.tgz#530f4f608f9ca9d4f89c24ab95db58ab56ab99a0" + integrity sha512-hLv8XaQ8PTI9g2RHoQGf/WSxBfTB/NudRacbzdxmst5VHAqd1sMibWG7SENzT5Dj3yZ3kJYx+WiRYEcQTAkcYA== + dependencies: + "@ethersproject/bytes" "^5.5.0" + "@ethersproject/logger" "^5.5.0" + "@ethersproject/sha2@5.4.0", "@ethersproject/sha2@^5.4.0": version "5.4.0" resolved "https://registry.yarnpkg.com/@ethersproject/sha2/-/sha2-5.4.0.tgz#c9a8db1037014cbc4e9482bd662f86c090440371" @@ -2189,6 +2237,19 @@ resolved "https://registry.yarnpkg.com/hardhat-deploy-ethers/-/hardhat-deploy-ethers-0.3.0-beta.11.tgz#7f9122301853b01cb85b5ac85ba84dd764c98b07" integrity sha512-HnniBGBYsFRQDXBy3bQ27i86pQQnHkN0Mxdwiu869jZURY2gDQ4OEZxcXItnWQqBjYiEaavVyw/Xle7qwKOBAg== +"@nomiclabs/hardhat-etherscan@^2.1.6": + version "2.1.6" + resolved "https://registry.yarnpkg.com/@nomiclabs/hardhat-etherscan/-/hardhat-etherscan-2.1.6.tgz#8d1502f42adc6f7b8ef16fb917c0b5a8780cb83a" + integrity sha512-gCvT5fj8GbXS9+ACS3BzrX0pzYHHZqAHCb+NcipOkl2cy48FakUXlzrCf4P4sTH+Y7W10OgT62ezD1sJ+/NikQ== + dependencies: + "@ethersproject/abi" "^5.1.2" + "@ethersproject/address" "^5.0.2" + cbor "^5.0.2" + debug "^4.1.1" + fs-extra "^7.0.1" + node-fetch "^2.6.0" + semver "^6.3.0" + "@nomiclabs/hardhat-waffle@^2.0.0": version "2.0.1" resolved "https://registry.yarnpkg.com/@nomiclabs/hardhat-waffle/-/hardhat-waffle-2.0.1.tgz#5d43654fba780720c5033dea240fe14f70ef4bd2" @@ -5333,7 +5394,7 @@ big.js@^5.2.2: resolved "https://registry.yarnpkg.com/big.js/-/big.js-5.2.2.tgz#65f0af382f578bcdc742bd9c281e9cb2d7768328" integrity sha512-vyL2OymJxmarO8gxMr0mhChsO9QGwhynfuu4+MHTAW6czfq9humCB7rKpUjDd9YUiDPU4mzpyupFSvOClAwbmQ== -bignumber.js@^9.0.0: +bignumber.js@^9.0.0, bignumber.js@^9.0.1: version "9.0.1" resolved "https://registry.yarnpkg.com/bignumber.js/-/bignumber.js-9.0.1.tgz#8d7ba124c882bfd8e43260c67475518d0689e4e5" integrity sha512-IdZR9mh6ahOBv/hYGiXyVuyCetmGJhtYkqLBpTStdhEGjegpPlUawydyaF3pbIOFynJTpllEs+NP+CS9jKFLjA== @@ -6044,6 +6105,14 @@ caseless@~0.12.0: resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc" integrity sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw= +cbor@^5.0.2: + version "5.2.0" + resolved "https://registry.yarnpkg.com/cbor/-/cbor-5.2.0.tgz#4cca67783ccd6de7b50ab4ed62636712f287a67c" + integrity sha512-5IMhi9e1QU76ppa5/ajP1BmMWZ2FHkhAhjeVKQ/EFCgYSEaeVaoGtL7cxJskf9oCCk+XjzaIdc3IuU/dbA/o2A== + dependencies: + bignumber.js "^9.0.1" + nofilter "^1.0.4" + center-align@^0.1.1: version "0.1.3" resolved "https://registry.yarnpkg.com/center-align/-/center-align-0.1.3.tgz#aa0d32629b6ee972200411cbd4461c907bc2b7ad" @@ -14776,6 +14845,11 @@ nodeify@^1.0.1: is-promise "~1.0.0" promise "~1.3.0" +nofilter@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/nofilter/-/nofilter-1.0.4.tgz#78d6f4b6a613e7ced8b015cec534625f7667006e" + integrity sha512-N8lidFp+fCz+TD51+haYdbDGrcBWwuHX40F5+z0qkUjMJ5Tp+rdSuAkMJ9N9eoolDlEVTf6u5icM+cNKkKW2mA== + normalize-hex@0.0.2: version "0.0.2" resolved "https://registry.yarnpkg.com/normalize-hex/-/normalize-hex-0.0.2.tgz#5491c43759db2f06b7168d8419f4925c271ab27e" From 9735f3bd048201dbfa7903e07047de5479c7f2f7 Mon Sep 17 00:00:00 2001 From: farque65 Date: Thu, 21 Oct 2021 18:20:23 -0400 Subject: [PATCH 2/7] Created Swap List --- packages/hardhat/hardhat.config.js | 15 ++- packages/react-app/src/App.jsx | 122 ++++++------------ .../{ClaimFees.jsx => SwapItem.jsx} | 8 +- packages/react-app/src/components/index.js | 2 +- packages/react-app/src/views/ClaimFees.jsx | 45 ------- packages/react-app/src/views/SwapList.jsx | 62 +++++++++ packages/react-app/src/views/index.js | 2 +- 7 files changed, 119 insertions(+), 137 deletions(-) rename packages/react-app/src/components/{ClaimFees.jsx => SwapItem.jsx} (81%) delete mode 100644 packages/react-app/src/views/ClaimFees.jsx create mode 100644 packages/react-app/src/views/SwapList.jsx diff --git a/packages/hardhat/hardhat.config.js b/packages/hardhat/hardhat.config.js index c133eb0..a69a5e5 100644 --- a/packages/hardhat/hardhat.config.js +++ b/packages/hardhat/hardhat.config.js @@ -43,6 +43,16 @@ function mnemonic() { return ""; } +function getRpc(network) { + const infuraKey = process.env[`${network}_INFURA_KEY`] || null; + + // Add environment variable NETWORK_RPC. For example RINKEBY_RPC + + return process.env[`${network}_RPC`] + ? process.env[`${network}_RPC`] + : `https://${network}.infura.io/v3/${infuraKey}`; +} + module.exports = { defaultNetwork, @@ -64,8 +74,9 @@ module.exports = { }, rinkeby: { - url: `https://rinkeby.infura.io/v3/${process.env.RINKEBY_INFURA_KEY}`, - accounts: [`${process.env.RINKEBY_DEPLOYER_PRIV_KEY}`], + // url: `https://rinkeby.infura.io/v3/${process.env.RINKEBY_INFURA_KEY}`, + // accounts: [`${process.env.RINKEBY_DEPLOYER_PRIV_KEY}`], + url: getRpc("RINKEBY"), }, // kovan: { // url: `https://rinkeby.infura.io/v3/${process.env.KOVAN_INFURA_KEY}`, diff --git a/packages/react-app/src/App.jsx b/packages/react-app/src/App.jsx index c121c11..599f3ec 100644 --- a/packages/react-app/src/App.jsx +++ b/packages/react-app/src/App.jsx @@ -4,7 +4,7 @@ import WalletLink from "walletlink"; import { Alert, Button, Col, Menu, Row } from "antd"; import "antd/dist/antd.css"; import React, { useCallback, useEffect, useState } from "react"; -import { HomeOutlined, ContainerOutlined, QuestionCircleOutlined, DatabaseOutlined } from "@ant-design/icons"; +import { HomeOutlined, ContainerOutlined, InteractionOutlined } from "@ant-design/icons"; import { BrowserRouter, Link, Route, Switch } from "react-router-dom"; import Web3Modal from "web3modal"; import "./App.css"; @@ -22,7 +22,7 @@ import { import { useEventListener } from "eth-hooks/events/useEventListener"; import { useExchangeEthPrice } from "eth-hooks/dapps/dex"; // import Hints from "./Hints"; -import { ExampleUI, Hints, TokenSwap, ClaimFees } from "./views"; +import { TokenSwap, SwapList } from "./views"; import { useContractConfig } from "./hooks"; @@ -453,26 +453,6 @@ function App(props) {
- - { - setRoute("/swap"); - }} - to="/swap" - > - Home - - - - { - setRoute("/claimfees"); - }} - to="/claimfees" - > - Claim Fees - - { @@ -480,27 +460,27 @@ function App(props) { }} to="/" > - Contracts + Home - + { - setRoute("/hints"); + setRoute("/swap"); }} - to="/hints" + to="/swap" > - Hints + Swap - + { - setRoute("/exampleui"); + setRoute("/contracts"); }} - to="/exampleui" + to="/contracts" > - ExampleUI + Contracts @@ -517,43 +497,7 @@ function App(props) { - -
- -
- -
- - - - - - + - - + +
+ +
+
- + - {loading ? ( -
In Progress...
- ) : ( -
Completed
- )} + {loading ?
Loading...
: } ); diff --git a/packages/react-app/src/components/index.js b/packages/react-app/src/components/index.js index 0ec7851..de323f8 100644 --- a/packages/react-app/src/components/index.js +++ b/packages/react-app/src/components/index.js @@ -17,4 +17,4 @@ export { default as Timeline } from "./Timeline"; export { default as TokenBalance } from "./TokenBalance"; export { default as Wallet } from "./Wallet"; export { default as L2Bridge } from "./L2Bridge"; -export { default as ClaimFees } from "./ClaimFees"; +export { default as SwapItem } from "./SwapItem"; diff --git a/packages/react-app/src/views/ClaimFees.jsx b/packages/react-app/src/views/ClaimFees.jsx deleted file mode 100644 index 3e8dabf..0000000 --- a/packages/react-app/src/views/ClaimFees.jsx +++ /dev/null @@ -1,45 +0,0 @@ -import { SyncOutlined, SettingOutlined, ArrowDownOutlined } from "@ant-design/icons"; -import { utils } from "ethers"; -import { Button, Divider, Input, List, Row, Col, Tabs, Card, Form, Checkbox } from "antd"; -import React, { useState } from "react"; -import { Address, Balance, ClaimFees, AddressInput } from "../components"; - -export default function Swap({ - purpose, - setPurposeEvents, - address, - mainnetProvider, - localProvider, - yourLocalBalance, - price, - tx, - readContracts, - writeContracts, -}) { - const [newPurpose, setNewPurpose] = useState("loading..."); - const [openToSwap, setOpenToSwap] = useState(); - - return ( -
-
- - ( - -
- -
-
- )} - /> -
-
-
- ); -} diff --git a/packages/react-app/src/views/SwapList.jsx b/packages/react-app/src/views/SwapList.jsx new file mode 100644 index 0000000..3d994b8 --- /dev/null +++ b/packages/react-app/src/views/SwapList.jsx @@ -0,0 +1,62 @@ +import React, { useCallback, useEffect, useState } from "react"; +import { SyncOutlined, SettingOutlined, ArrowDownOutlined } from "@ant-design/icons"; +import { utils, BigNumber } from "ethers"; +import { Button, Divider, Input, List, Row, Col, Tabs, Card, Form, Checkbox } from "antd"; +import { Address, Balance, SwapItem, AddressInput } from "../components"; + +export default function SwapList({ + purpose, + setPurposeEvents, + address, + mainnetProvider, + localProvider, + yourLocalBalance, + price, + tx, + readContracts, + writeContracts, + chainId, +}) { + const [activeSwaps, setActiveSwaps] = useState([]); + + const getActiveSwaps = async () => { + let swaps = null; + let temp = []; + if (readContracts?.MoonSwap) { + swaps = await readContracts.MoonSwap.getActiveSwaps(); + swaps.forEach(swap => { + temp.push(utils.keccak256(swap)); + }); + console.log("viewswap ", swaps, temp); + setActiveSwaps(temp); + } + }; + + useEffect(async () => { + getActiveSwaps(); + }, [activeSwaps]); + + return ( +
+
+ + ( + +
+ +
+
+ )} + /> +
+
+
+ ); +} diff --git a/packages/react-app/src/views/index.js b/packages/react-app/src/views/index.js index 9e2489c..d4a9669 100644 --- a/packages/react-app/src/views/index.js +++ b/packages/react-app/src/views/index.js @@ -2,4 +2,4 @@ export { default as ExampleUI } from "./ExampleUI"; export { default as Hints } from "./Hints"; export { default as Subgraph } from "./Subgraph"; export { default as TokenSwap } from "./TokenSwap"; -export { default as ClaimFees } from "./ClaimFees"; +export { default as SwapList } from "./SwapList"; From 5aa8c8b19c8c79f8824f67b080f7a37c7d53255b Mon Sep 17 00:00:00 2001 From: farque65 Date: Fri, 22 Oct 2021 02:21:16 -0400 Subject: [PATCH 3/7] Commit Swap --- packages/react-app/src/App.jsx | 1 + .../react-app/src/components/SwapItem.jsx | 2 +- packages/react-app/src/views/TokenSwap.jsx | 230 +++++++++++------- 3 files changed, 141 insertions(+), 92 deletions(-) diff --git a/packages/react-app/src/App.jsx b/packages/react-app/src/App.jsx index 599f3ec..f2efa3c 100644 --- a/packages/react-app/src/App.jsx +++ b/packages/react-app/src/App.jsx @@ -527,6 +527,7 @@ function App(props) { setPurposeEvents={setPurposeEvents} isWalletConnected={isWalletConnected} userSigner={userSigner} + chainId={selectedChainId} />
diff --git a/packages/react-app/src/components/SwapItem.jsx b/packages/react-app/src/components/SwapItem.jsx index c174dcd..dab0748 100644 --- a/packages/react-app/src/components/SwapItem.jsx +++ b/packages/react-app/src/components/SwapItem.jsx @@ -44,7 +44,7 @@ export default function SwapItem({ hash, localProvider, chainId, ...props }) { href={`${explorer}tx/${hash}`} rel="noopener noreferrer" > - {hash.substr(0, 10)} + {hash} diff --git a/packages/react-app/src/views/TokenSwap.jsx b/packages/react-app/src/views/TokenSwap.jsx index 42d7a92..21f14dc 100644 --- a/packages/react-app/src/views/TokenSwap.jsx +++ b/packages/react-app/src/views/TokenSwap.jsx @@ -20,11 +20,15 @@ export default function TokenSwap({ writeContracts, isWalletConnected, userSigner, + chainId, }) { const [readyToSwap, setReadyToSwap] = useState(); const [addressIn, setAddressIn] = useState(); const [addressOut, setAddressOut] = useState(address); const [token, setTokenOut] = useState(); + const [numTokensOut, setNumTokensOut] = useState(); + const [commitSwapId, setCommitSwapId] = useState(); + const [activeSwaps, setActiveSwaps] = useState(); const [tokenInContract, setTokenInContract] = useState(); const [tokenOutContract, setTokenOutContract] = useState(); @@ -34,6 +38,15 @@ export default function TokenSwap({ return { decimals }; }; + const getLatestSwapId = async () => { + let swaps = null; + if (readContracts?.MoonSwap) { + swaps = await readContracts.MoonSwap.getActiveSwaps(); + const latestSwap = swaps[swaps.length - 1]; + setCommitSwapId(utils.keccak256(latestSwap)); + } + }; + const approveTokenAllowance = async ({ maxApproval, token, tokenInContract, tokenOutContract }) => { // const decimals = await getTokenDetails({ token }); // FIX: Harcoded decimals value @@ -73,11 +86,12 @@ export default function TokenSwap({ const result = tx( writeContracts.MoonSwap.createNewSwap(tokenIn, tokenOut, swapValueIn, swapValueOut, addressOut), - update => { - console.log("📡 New Swap Created:", update); + (update, error) => { + console.log("result check ", update, error); if (update && (update.status === "confirmed" || update.status === 1)) { + console.log("📡 New Swap Created:", update); setReadyToSwap(true); - setTokenOut(tokenOut); + setNumTokensOut(swapValueOut); notification.success({ message: "Ready to Commit To Swap", description: "successful", @@ -85,17 +99,18 @@ export default function TokenSwap({ }); } }, - ); + ).then(result => { + console.log("result finished ", result); + getLatestSwapId(); + }); }; - const commitToSwap = async () => { - let swapId = null; - if (readContracts?.MoonSwap) { - swapId = await readContracts.MoonSwap.swapId(); - tokenOut = await readContracts.MoonSwap.tokenOut(); - } - const result = tx(writeContracts.MoonSwap.commitToSwap({ swapId, tokenOut }), update => { - console.log("📡 Swap Committed:", update); + const commitToSwap = async ({ currentSwapId, tokenOut }) => { + currentSwapId = commitSwapId; + tokenOut = numTokensOut; + + const result = tx(writeContracts.MoonSwap.commitToSwap(currentSwapId, tokenOut), update => { + console.log("📡 Swap Complete:", update); if (update && (update.status === "confirmed" || update.status === 1)) { setReadyToSwap(false); console.log(" 🍾 Swap finished!"); @@ -113,7 +128,7 @@ export default function TokenSwap({ style={{ border: "1px solid #cccccc", padding: 30, - width: 600, + width: 700, margin: "auto", marginTop: 64, borderRadius: 25, @@ -121,16 +136,20 @@ export default function TokenSwap({ }} >
-
-
- - -

IN

- - - - - - - - - - -
-
- -
- - -

OUT

- - - - - - - - - - -
-
- - - - - + {!readyToSwap && ( +
+
+ + +

IN

+ + + + + + + + + + +
+
+ +
+ + +

OUT

+ + + + + + + + + + +
+
+ + + + + )} + {readyToSwap && commitSwapId && numTokensOut && ( +
+
+ + + +

{commitSwapId}

+
+ +

{numTokensOut}

+
+ +
+
+ + + +
+ )}
); From bee831e84475d66cc481d25d80caf422a340c9c0 Mon Sep 17 00:00:00 2001 From: Nazeeh21 Date: Fri, 22 Oct 2021 13:53:24 +0530 Subject: [PATCH 4/7] Add commit Swap functionality --- packages/react-app/src/views/TokenSwap.jsx | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/react-app/src/views/TokenSwap.jsx b/packages/react-app/src/views/TokenSwap.jsx index 21f14dc..3f752af 100644 --- a/packages/react-app/src/views/TokenSwap.jsx +++ b/packages/react-app/src/views/TokenSwap.jsx @@ -29,6 +29,8 @@ export default function TokenSwap({ const [numTokensOut, setNumTokensOut] = useState(); const [commitSwapId, setCommitSwapId] = useState(); const [activeSwaps, setActiveSwaps] = useState(); + const [tokenInAddress, setTokenInAddress] = useState(); + const [tokenOutAddress, setTokenOutAddress] = useState(); const [tokenInContract, setTokenInContract] = useState(); const [tokenOutContract, setTokenOutContract] = useState(); @@ -43,11 +45,12 @@ export default function TokenSwap({ if (readContracts?.MoonSwap) { swaps = await readContracts.MoonSwap.getActiveSwaps(); const latestSwap = swaps[swaps.length - 1]; - setCommitSwapId(utils.keccak256(latestSwap)); + console.log("latestSwap: ", latestSwap.toNumber()); + setCommitSwapId(latestSwap.toNumber()); } }; - const approveTokenAllowance = async ({ maxApproval, token, tokenInContract, tokenOutContract }) => { + const approveTokenAllowance = async ({ maxApproval, tokenInContract }) => { // const decimals = await getTokenDetails({ token }); // FIX: Harcoded decimals value const newAllowance = ethers.utils.parseUnits(maxApproval, await tokenInContract.decimals()); @@ -56,6 +59,8 @@ export default function TokenSwap({ }; const createNewSwap = async ({ tokenIn, swapValueIn, tokenOut, swapValueOut }) => { + setTokenInAddress(tokenIn); + setTokenOutAddress(tokenOut); if (!isWalletConnected) { return notification.error({ message: "Access request failed", @@ -79,9 +84,7 @@ export default function TokenSwap({ // Approve the token allowance await approveTokenAllowance({ maxApproval: swapValueIn, - token: tokenIn, tokenInContract: inContract, - tokenOutContract: outContract, }); const result = tx( @@ -109,6 +112,11 @@ export default function TokenSwap({ currentSwapId = commitSwapId; tokenOut = numTokensOut; + const signer = userSigner; + const outContract = new ethers.Contract(tokenOutAddress, ERC20ABI, signer); + + await approveTokenAllowance({ maxApproval: tokenOut, tokenInContract: outContract }); + const result = tx(writeContracts.MoonSwap.commitToSwap(currentSwapId, tokenOut), update => { console.log("📡 Swap Complete:", update); if (update && (update.status === "confirmed" || update.status === 1)) { @@ -246,7 +254,7 @@ export default function TokenSwap({ -

{commitSwapId}

+ {/*

{commitSwapId}

*/}

{numTokensOut}

From 5be0ac587d053d060592e7cbd2d82b52be56ff2f Mon Sep 17 00:00:00 2001 From: Nazeeh21 Date: Fri, 22 Oct 2021 14:15:04 +0530 Subject: [PATCH 5/7] Implement commit swap --- packages/react-app/src/App.jsx | 20 ++++++++++++++++- packages/react-app/src/views/TokenSwap.jsx | 25 ++++++++++++++++++++-- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/packages/react-app/src/App.jsx b/packages/react-app/src/App.jsx index f2efa3c..6d9ddef 100644 --- a/packages/react-app/src/App.jsx +++ b/packages/react-app/src/App.jsx @@ -55,7 +55,7 @@ const { ethers } = require("ethers"); const targetNetwork = process.env.REACT_APP_NETWORK ? NETWORKS[process.env.REACT_APP_NETWORK] : NETWORKS.localhost; // <------- select your target frontend network (localhost, rinkeby, xdai, mainnet) // 😬 Sorry for all the console logging -const DEBUG = true; +const DEBUG = false; const NETWORKCHECK = true; // 🛰 providers @@ -530,6 +530,24 @@ function App(props) { chainId={selectedChainId} />
+ + + { + if (id) { + console.log("id: ", id); + setReadyToSwap(true); + setCommitSwapId(id); + + getSwapData(id); + } + }, [id, readContracts]); + + const getSwapData = async id => { + if (readContracts && readContracts.MoonSwap) { + const swapData = await readContracts.MoonSwap.swaps(id); + setNumTokensOut(swapData.tokensOut.toNumber()); + setTokenOutAddress(swapData.outToken.toString()); + console.log("swapData: ", swapData); + } + }; + const getTokenDetails = async ({ token }) => { const decimals = await readContracts[token].decimals; return { decimals }; @@ -115,7 +136,7 @@ export default function TokenSwap({ const signer = userSigner; const outContract = new ethers.Contract(tokenOutAddress, ERC20ABI, signer); - await approveTokenAllowance({ maxApproval: tokenOut, tokenInContract: outContract }); + await approveTokenAllowance({ maxApproval: tokenOut.toString(), tokenInContract: outContract }); const result = tx(writeContracts.MoonSwap.commitToSwap(currentSwapId, tokenOut), update => { console.log("📡 Swap Complete:", update); @@ -254,7 +275,7 @@ export default function TokenSwap({ - {/*

{commitSwapId}

*/} +

{commitSwapId}

{numTokensOut}

From 0e02ed62a7843e6351027c8c74ec7e712a6bb711 Mon Sep 17 00:00:00 2001 From: Dhaiwat Pandya Date: Fri, 22 Oct 2021 14:56:25 +0530 Subject: [PATCH 6/7] Add auto re-route after createSwap, add support for inactive swaps --- packages/react-app/src/views/TokenSwap.jsx | 31 ++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/packages/react-app/src/views/TokenSwap.jsx b/packages/react-app/src/views/TokenSwap.jsx index 7f31e66..617df91 100644 --- a/packages/react-app/src/views/TokenSwap.jsx +++ b/packages/react-app/src/views/TokenSwap.jsx @@ -4,7 +4,7 @@ import { Button, Divider, Input, List, Row, Col, Tabs, Card, Form, Checkbox, not import React, { useState, useEffect } from "react"; import { Address, Balance, ClaimFees, AddressInput } from "../components"; import externalContracts from "../contracts/external_contracts"; -import { useParams } from "react-router-dom"; +import { useParams, useHistory } from "react-router-dom"; const ERC20ABI = externalContracts[1].contracts.UNI.abi; @@ -24,6 +24,7 @@ export default function TokenSwap({ chainId, }) { const { id } = useParams(); + const history = useHistory(); const [readyToSwap, setReadyToSwap] = useState(); const [addressIn, setAddressIn] = useState(); const [addressOut, setAddressOut] = useState(address); @@ -37,6 +38,8 @@ export default function TokenSwap({ const [tokenInContract, setTokenInContract] = useState(); const [tokenOutContract, setTokenOutContract] = useState(); + const [notFound, setNotFound] = useState(false); + useEffect(() => { if (id) { console.log("id: ", id); @@ -50,6 +53,10 @@ export default function TokenSwap({ const getSwapData = async id => { if (readContracts && readContracts.MoonSwap) { const swapData = await readContracts.MoonSwap.swaps(id); + const status = swapData.status; + if (!status) { + setNotFound(true); + } setNumTokensOut(swapData.tokensOut.toNumber()); setTokenOutAddress(swapData.outToken.toString()); console.log("swapData: ", swapData); @@ -67,6 +74,7 @@ export default function TokenSwap({ swaps = await readContracts.MoonSwap.getActiveSwaps(); const latestSwap = swaps[swaps.length - 1]; console.log("latestSwap: ", latestSwap.toNumber()); + history.push(`/swap/${latestSwap.toNumber()}`); setCommitSwapId(latestSwap.toNumber()); } }; @@ -152,6 +160,24 @@ export default function TokenSwap({ }); }; + if (notFound) { + return ( +
+ Swap not found or inactive. Please check the swap id and try again. +
+ ); + } + return (
)} - {readyToSwap && commitSwapId && numTokensOut && ( + {notFound &&
Swap already completed or inactive.
} + {!notFound && readyToSwap && commitSwapId && numTokensOut && (
Date: Fri, 22 Oct 2021 19:01:54 +0530 Subject: [PATCH 7/7] add redirect button in swaplist --- .../react-app/src/components/SwapItem.jsx | 5 +++-- packages/react-app/src/views/SwapList.jsx | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/packages/react-app/src/components/SwapItem.jsx b/packages/react-app/src/components/SwapItem.jsx index dab0748..a7e5f1c 100644 --- a/packages/react-app/src/components/SwapItem.jsx +++ b/packages/react-app/src/components/SwapItem.jsx @@ -1,9 +1,9 @@ import React, { useEffect, useState } from "react"; import { useThemeSwitcher } from "react-css-theme-switcher"; -import { Typography } from "antd"; +import { Typography, Button } from "antd"; import { NETWORK } from "../constants"; -export default function SwapItem({ hash, localProvider, chainId, ...props }) { +export default function SwapItem({ onClick, hash, localProvider, chainId, ...props }) { const { currentTheme } = useThemeSwitcher(); const [loading, updateLoading] = useState(true); const [txData, updateTxData] = useState({}); @@ -47,6 +47,7 @@ export default function SwapItem({ hash, localProvider, chainId, ...props }) { {hash} +
{loading ?
Loading...
: }
diff --git a/packages/react-app/src/views/SwapList.jsx b/packages/react-app/src/views/SwapList.jsx index 3d994b8..fea34d8 100644 --- a/packages/react-app/src/views/SwapList.jsx +++ b/packages/react-app/src/views/SwapList.jsx @@ -3,6 +3,8 @@ import { SyncOutlined, SettingOutlined, ArrowDownOutlined } from "@ant-design/ic import { utils, BigNumber } from "ethers"; import { Button, Divider, Input, List, Row, Col, Tabs, Card, Form, Checkbox } from "antd"; import { Address, Balance, SwapItem, AddressInput } from "../components"; +import { useParams, useHistory } from "react-router-dom"; +import { Router } from "@uniswap/sdk"; export default function SwapList({ purpose, @@ -17,18 +19,25 @@ export default function SwapList({ writeContracts, chainId, }) { + const history = useHistory(); + const { id } = useParams(); const [activeSwaps, setActiveSwaps] = useState([]); + const [swapIds, setSwapIds] = useState([]); const getActiveSwaps = async () => { let swaps = null; let temp = []; + let tempIds = []; if (readContracts?.MoonSwap) { swaps = await readContracts.MoonSwap.getActiveSwaps(); + swaps.forEach(swap => { temp.push(utils.keccak256(swap)); + tempIds.push(swap.toNumber()); }); console.log("viewswap ", swaps, temp); setActiveSwaps(temp); + setSwapIds(tempIds); } }; @@ -50,7 +59,15 @@ export default function SwapList({ width: "80%", }} > - + { + history.push(`/swap/${swapIds[index]}`); + }} + hash={item} + localProvider={localProvider} + chainId={chainId} + fontSize={14} + /> )}