From 63d774b85bcf9a53a5ed1bd47167eda7fbca9b7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toto=CC=80=20Volturno?= Date: Mon, 14 Jun 2021 17:04:29 +0200 Subject: [PATCH 01/13] first sketch for new dough staking page --- src/pages/DoughStaking.svelte | 364 ++++++++++++++++++++++++++++++++++ 1 file changed, 364 insertions(+) create mode 100644 src/pages/DoughStaking.svelte diff --git a/src/pages/DoughStaking.svelte b/src/pages/DoughStaking.svelte new file mode 100644 index 00000000..127caabf --- /dev/null +++ b/src/pages/DoughStaking.svelte @@ -0,0 +1,364 @@ + + +
+
DOUGH Staking
+
+ The new Stake, under development. +
+ +
+
+
+
Amount to Stake
+
+
{ + stake.amount = toNum(data.accountDepositTokenBalance); + }} + > + Max balance: {toNum(data.accountDepositTokenBalance)} +
+
+
+
+ { checkApproval(data.accountDepositTokenAllowance)}} + bind:value={stake.amount} + class="swap-input-from" + inputmode="decimal" + title="Token Amount" + autocomplete="off" + autocorrect="off" + type="number" + pattern="^[0-9]*[,]?[0-9]*$" + placeholder="0.0" + minlength="1" + maxlength="79" + spellcheck="false" + /> + + dough token + DOUGH + +
+
+ +
+
+
Stake Duration (Months)
+
+
{ + stake.duration = 36; + }} + > + Max 36 Months +
+
+
+
+ + + dough token + 3 Years + +
+
+ +
+
+
Receiver
+
+
+ +
+
+ + {#if needAllowance} + + {:else} + + {/if} +
+ +
+
+
+ + Total Staked: {toNum(data.totalStaked)} + dough token + DOUGH + +
+
Select the item you wish to unstake from the list.
+
+ +
    + {#each data.accountLocks as lock, id} +
  • + +
  • + {/each} +
+
+
From 87a9bc46c757346913ba4b9409632847e0d10ba0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toto=CC=80=20Volturno?= Date: Mon, 14 Jun 2021 17:22:57 +0200 Subject: [PATCH 02/13] added contract address, routes, and abis --- src/abis/sharesTimeLock.json | 1 + src/config/smartcontracts.json | 3 ++- src/pages/DoughStaking.svelte | 4 ++-- src/stores/routes.js | 3 +++ 4 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 src/abis/sharesTimeLock.json diff --git a/src/abis/sharesTimeLock.json b/src/abis/sharesTimeLock.json new file mode 100644 index 00000000..da9939dd --- /dev/null +++ b/src/abis/sharesTimeLock.json @@ -0,0 +1 @@ +[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":true,"internalType":"address","name":"owner","type":"address"}],"name":"BoostedToMax","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint32","name":"lockDuration","type":"uint32"},{"indexed":true,"internalType":"address","name":"owner","type":"address"}],"name":"Deposited","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":true,"internalType":"address","name":"owner","type":"address"}],"name":"Ejected","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"newLockAmount","type":"uint256"}],"name":"MinLockAmountChanged","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":"user","type":"address"},{"indexed":true,"internalType":"bool","name":"whitelisted","type":"bool"}],"name":"WhitelistedChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":true,"internalType":"address","name":"owner","type":"address"}],"name":"Withdrawn","type":"event"},{"inputs":[{"internalType":"uint256","name":"lockId","type":"uint256"}],"name":"boostToMax","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"lockId","type":"uint256"}],"name":"canEject","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"months","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"depositByMonths","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"depositToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"lockAccounts","type":"address[]"},{"internalType":"uint256[]","name":"lockIds","type":"uint256[]"}],"name":"eject","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getLocksOfLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"duration","type":"uint32"}],"name":"getRewardsMultiplier","outputs":[{"internalType":"uint256","name":"multiplier","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getStakingData","outputs":[{"components":[{"internalType":"uint256","name":"totalStaked","type":"uint256"},{"internalType":"uint256","name":"rewardTokenTotalSupply","type":"uint256"},{"internalType":"uint256","name":"accountRewardTokenBalance","type":"uint256"},{"internalType":"uint256","name":"accountWithdrawableRewards","type":"uint256"},{"internalType":"uint256","name":"accountWithdrawnRewards","type":"uint256"},{"internalType":"uint256","name":"accountDepositTokenBalance","type":"uint256"},{"internalType":"uint256","name":"accountDepositTokenAllowance","type":"uint256"},{"components":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint32","name":"lockedAt","type":"uint32"},{"internalType":"uint32","name":"lockDuration","type":"uint32"}],"internalType":"struct SharesTimeLock.Lock[]","name":"accountLocks","type":"tuple[]"}],"internalType":"struct SharesTimeLock.StakingData","name":"data","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"depositToken_","type":"address"},{"internalType":"contract ERC20NonTransferableRewardsOwned","name":"rewardsToken_","type":"address"},{"internalType":"uint32","name":"minLockDuration_","type":"uint32"},{"internalType":"uint32","name":"maxLockDuration_","type":"uint32"},{"internalType":"uint256","name":"minLockAmount_","type":"uint256"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"locksOf","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint32","name":"lockedAt","type":"uint32"},{"internalType":"uint32","name":"lockDuration","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxLockDuration","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minLockAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minLockDuration","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"rewardsToken","outputs":[{"internalType":"contract ERC20NonTransferableRewardsOwned","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"secPerMonth","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"minLockAmount_","type":"uint256"}],"name":"setMinLockAmount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"secondsPerMonth_","type":"uint256"}],"name":"setSecondsPerMonth","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"bool","name":"isWhitelisted","type":"bool"}],"name":"setWhitelisted","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"whitelisted","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"lockId","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file diff --git a/src/config/smartcontracts.json b/src/config/smartcontracts.json index 26760d92..d4efa689 100644 --- a/src/config/smartcontracts.json +++ b/src/config/smartcontracts.json @@ -3,5 +3,6 @@ "recipe_old": "0xE1F9E100cbF4aD6D546b196Af33E1129Dd0866b3", "recipev1": "0x6cb4b8669e23295563d3b34df4a760c0cee993c7", "stakingPools": "0x6de77A304609472A4811a0BFD47d8682Aebc29df", - "eDOUGH": "0x63cbd1858bd79de1a06c3c26462db360b834912d" + "eDOUGH": "0x63cbd1858bd79de1a06c3c26462db360b834912d", + "doughStaking": "0x44776A2C6368F85044123C79E49f03E914bb9a44" } \ No newline at end of file diff --git a/src/pages/DoughStaking.svelte b/src/pages/DoughStaking.svelte index 127caabf..92f3f45e 100644 --- a/src/pages/DoughStaking.svelte +++ b/src/pages/DoughStaking.svelte @@ -5,10 +5,9 @@ import { _ } from 'svelte-i18n'; import sharesTimeLockABI from '../abis/sharesTimeLock.json'; import smartcontracts from '../config/smartcontracts.json'; - import { get } from 'svelte/store'; import images from '../config/images.json'; import displayNotification from '../notifications'; - import { formatEther, parseEther } from '@ethersproject/units'; + import { parseEther } from '@ethersproject/units'; const toNum = (num) => BigNumber(num.toString()) @@ -195,6 +194,7 @@ }); } catch(error) { + console.log(error.message); if(error.message.includes('lock not expired')) { displayNotification({ message: 'can\'t unstake, lock not expired.', diff --git a/src/stores/routes.js b/src/stores/routes.js index 6a0a3e8a..1a13ca0c 100644 --- a/src/stores/routes.js +++ b/src/stores/routes.js @@ -22,6 +22,7 @@ import PiePageSwitch from '../pages/PiePageSwitch.svelte'; import Learn from '../pages/Learn.svelte'; import Integrations from '../pages/Integrations.svelte'; import Piefolio from '../pages/Piefolio.svelte'; +import DoughStaking from '../pages/DoughStaking.svelte'; import Farm from '../pages/Farm.svelte'; export const defaultRouteObj = { @@ -107,6 +108,8 @@ const formatRoute = (route) => { return { page: LPStakingV2 }; case 'farm': return { page: Farm }; + case 'new_staking': + return { page: DoughStaking }; case 'stake': referral = route[1] || null; From abe2172a0c9065178ad90b591bafe6e4cafcf20a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toto=CC=80=20Volturno?= Date: Tue, 15 Jun 2021 11:29:03 +0200 Subject: [PATCH 03/13] added return/resolve into approve async function --- src/stores/eth.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/stores/eth.js b/src/stores/eth.js index b81a4fd3..4746f5c6 100644 --- a/src/stores/eth.js +++ b/src/stores/eth.js @@ -134,6 +134,8 @@ export const approve = async (address, spender, amount) => { if (currentBlockNumber > lastBlock) { eth.set({ ...get(eth), currentBlockNumber }); } + + return true; }; export const approveMax = async (address, spender) => { From 13ec6072d281f22098a3b90d4713830673e18f14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toto=CC=80=20Volturno?= Date: Tue, 15 Jun 2021 14:48:54 +0200 Subject: [PATCH 04/13] updated doughStaking address --- src/config/smartcontracts.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/smartcontracts.json b/src/config/smartcontracts.json index d4efa689..81e59648 100644 --- a/src/config/smartcontracts.json +++ b/src/config/smartcontracts.json @@ -4,5 +4,5 @@ "recipev1": "0x6cb4b8669e23295563d3b34df4a760c0cee993c7", "stakingPools": "0x6de77A304609472A4811a0BFD47d8682Aebc29df", "eDOUGH": "0x63cbd1858bd79de1a06c3c26462db360b834912d", - "doughStaking": "0x44776A2C6368F85044123C79E49f03E914bb9a44" + "doughStaking": "0xf4a2BD807C817C41ae8689aAA655ECc1B6Ca6D06" } \ No newline at end of file From dc95db59dffede17b839c82774ed0da6711b645a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toto=CC=80=20Volturno?= Date: Thu, 17 Jun 2021 10:31:07 +0200 Subject: [PATCH 05/13] added missing dough address --- src/config/smartcontracts.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/config/smartcontracts.json b/src/config/smartcontracts.json index 81e59648..690bfde4 100644 --- a/src/config/smartcontracts.json +++ b/src/config/smartcontracts.json @@ -4,5 +4,6 @@ "recipev1": "0x6cb4b8669e23295563d3b34df4a760c0cee993c7", "stakingPools": "0x6de77A304609472A4811a0BFD47d8682Aebc29df", "eDOUGH": "0x63cbd1858bd79de1a06c3c26462db360b834912d", - "doughStaking": "0xf4a2BD807C817C41ae8689aAA655ECc1B6Ca6D06" + "doughStaking": "0xf4a2BD807C817C41ae8689aAA655ECc1B6Ca6D06", + "dough": "0x6503e51056C881Ebf463207f8E969fA45A1E0747" } \ No newline at end of file From 7ac378b6f465085fe9800ff35e7107ada74f7536 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toto=CC=80=20Volturno?= Date: Thu, 17 Jun 2021 11:24:58 +0200 Subject: [PATCH 06/13] added overrides on approve function --- src/config/env.json | 2 +- src/stores/eth.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/config/env.json b/src/config/env.json index 52d38c55..86c224d1 100644 --- a/src/config/env.json +++ b/src/config/env.json @@ -1,6 +1,6 @@ { "blocknative": { "dappId": "523b279d-0fe0-42e8-8977-e688c3686e57", - "networkId": 1 + "networkId": 4 } } diff --git a/src/stores/eth.js b/src/stores/eth.js index 4746f5c6..f3694880 100644 --- a/src/stores/eth.js +++ b/src/stores/eth.js @@ -108,9 +108,9 @@ export const trackGasPrice = async () => subject('gasPrice'); // Shortcuts -export const approve = async (address, spender, amount) => { +export const approve = async (address, spender, amount, overrides = {}) => { const erc20Contract = await contract({ address, abi: erc20 }); - const { hash } = await erc20Contract['approve(address,uint256)'](spender, amount); + const { hash } = await erc20Contract['approve(address,uint256)'](spender, amount, overrides); const { emitter } = displayNotification({ hash }); const symbol = await erc20Contract.symbol(); From ce2d32d8f0fa1a9a6feb3613cfbf09c1dc4b4b4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toto=CC=80=20Volturno?= Date: Thu, 17 Jun 2021 12:00:34 +0200 Subject: [PATCH 07/13] fixed staking contract address, owner bug fixed on smart contract --- src/config/env.json | 2 +- src/config/smartcontracts.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config/env.json b/src/config/env.json index 86c224d1..52d38c55 100644 --- a/src/config/env.json +++ b/src/config/env.json @@ -1,6 +1,6 @@ { "blocknative": { "dappId": "523b279d-0fe0-42e8-8977-e688c3686e57", - "networkId": 4 + "networkId": 1 } } diff --git a/src/config/smartcontracts.json b/src/config/smartcontracts.json index 690bfde4..6e012962 100644 --- a/src/config/smartcontracts.json +++ b/src/config/smartcontracts.json @@ -4,6 +4,6 @@ "recipev1": "0x6cb4b8669e23295563d3b34df4a760c0cee993c7", "stakingPools": "0x6de77A304609472A4811a0BFD47d8682Aebc29df", "eDOUGH": "0x63cbd1858bd79de1a06c3c26462db360b834912d", - "doughStaking": "0xf4a2BD807C817C41ae8689aAA655ECc1B6Ca6D06", + "doughStaking": "0xcc798c02C8D207AA309137C387db5195AAB7dDCd", "dough": "0x6503e51056C881Ebf463207f8E969fA45A1E0747" } \ No newline at end of file From 40ad10ec89bbfb8162c2ea5e886bf478a4cbd4a9 Mon Sep 17 00:00:00 2001 From: Alessio Delmonti Date: Wed, 23 Jun 2021 15:54:45 +0100 Subject: [PATCH 08/13] Adding sanity checks and reactivity to input responce --- src/config/env.json | 2 +- src/pages/DoughStaking.svelte | 216 ++++++++++++++++++++++------------ src/stores/eth.js | 5 +- 3 files changed, 142 insertions(+), 81 deletions(-) diff --git a/src/config/env.json b/src/config/env.json index 52d38c55..86c224d1 100644 --- a/src/config/env.json +++ b/src/config/env.json @@ -1,6 +1,6 @@ { "blocknative": { "dappId": "523b279d-0fe0-42e8-8977-e688c3686e57", - "networkId": 1 + "networkId": 4 } } diff --git a/src/pages/DoughStaking.svelte b/src/pages/DoughStaking.svelte index 92f3f45e..ce816f0d 100644 --- a/src/pages/DoughStaking.svelte +++ b/src/pages/DoughStaking.svelte @@ -1,5 +1,5 @@