Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactored code to work both on mainnet/rinkeby networks. #218

Open
wants to merge 8 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/classes/farming_simulator/Calculator.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { CoinGecko } from '../../stores/coingecko.js';
import smartcontracts from '../../config/smartcontracts.json';
import { environment } from '../../stores/eth/connection.js';
import { fetchTreasuryBalance } from '../../helpers/zapper.js';

export default class Calculator {
constructor() {
// default treasury address, just a placeholder for now
// TODO: change it for real address before go live...
this.treasury_address = '0x4efD8CEad66bb0fA64C8d53eBE65f31663199C6d';
this.treasury_address = smartcontracts[environment].treasury;

// default empty markets object, to be filled dynamically...
this.markets = {
Expand Down
3 changes: 2 additions & 1 deletion src/components/Liquidity.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import displayNotification from "../notifications.js";
import TokenSelectModal from "./modals/TokenSelectModal.svelte";
import { environment } from '../stores/eth/connection.js';

import {
allowances,
Expand Down Expand Up @@ -149,7 +150,7 @@
return;
}

const recipe = await contract({ address: smartcontracts.recipe, abi: recipeAbi });
const recipe = await contract({ address: smartcontracts[environment].recipe, abi: recipeAbi });
const amountWei = requestedAmount.multipliedBy(10 ** 18).toFixed(0);

let overrides = {
Expand Down
3 changes: 2 additions & 1 deletion src/components/Migration.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import displayNotification from "../notifications.js";
import TokenSelectModal from "./modals/TokenSelectModal.svelte";
import { environment } from '../stores/eth/connection.js';

import {
allowances,
Expand Down Expand Up @@ -241,7 +242,7 @@
return;
}

const recipe = await contract({ address: smartcontracts.recipe, abi: recipeAbi });
const recipe = await contract({ address: smartcontracts[environment].recipe, abi: recipeAbi });
const amountWei = requestedAmount.multipliedBy(10 ** 18).toFixed(0);

let overrides = {
Expand Down
1 change: 0 additions & 1 deletion src/components/Tvl.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@

if( p.id == 3 || p.id == 4 ) {
const pieStaked = $farming[p.addressUniPoll].doughStaked;
console.log(p.containing[0].address, marketData)
partialTotal -= pieStaked * marketData[ p.containing[0].address ].market_data.current_price;
}

Expand Down
3 changes: 2 additions & 1 deletion src/components/elements/BoostedModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { formatFiat } from '../helpers.js';
import confetti from '../Confetti.js';
import { toNum, calculateVeDough, AVG_SECONDS_MONTH } from '../../helpers/staking.js';
import { environment } from '../../stores/eth/connection.js';

let bindedModal;

Expand Down Expand Up @@ -59,7 +60,7 @@
params: {
type: 'ERC20',
options: {
address: smartcontracts.reward,
address: smartcontracts[environment].reward,
symbol: 'SLICE',
decimals: 18,
image: images.rewardsPie,
Expand Down
9 changes: 7 additions & 2 deletions src/components/elements/ClaimModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import smartcontracts from '../../config/smartcontracts.json';
import isEmpty from 'lodash/isEmpty';
import BigNumber from 'bignumber.js';
import { prodProvider } from '../../stores/eth/connection.js';
import { stakingData } from '../../stores/eth/writables.js';

let _stakingData = $stakingData;
Expand All @@ -29,8 +30,12 @@

async function initialize() {
try {
rewardPie = new Experipie(smartcontracts.reward, $eth.provider);
await rewardPie.initialize($piesMarketDataStore);
rewardPie = new Experipie(
smartcontracts['prod'].reward,
prodProvider
);
await rewardPie.initialize($piesMarketDataStore);
console.log("rewardPie", rewardPie);
} catch(error) {
console.error(error);
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/elements/StakedModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
params: {
type: 'ERC20',
options: {
address: smartcontracts.veDOUGH,
address: smartcontracts[environment].veDOUGH,
symbol: 'veDOUGH',
decimals: 18,
image: images.simulator_veDough,
Expand Down
3 changes: 2 additions & 1 deletion src/components/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import unipoolAbi from '../config/unipoolABI.json';
import geyserABI from '../config/geyser.json';
import uniswapPair from '../config/uniswapPair.json';
import BALANCER_POOL_ABI from '../config/balancerPoolABI.json';
import { environment } from '../stores/eth/connection.js';

import {
allowances,
Expand Down Expand Up @@ -374,7 +375,7 @@ export const fetchCalcToPie = async (pieAddress, poolAmount) => {

const { provider } = get(eth);

const recipe = new ethers.Contract(smartcontracts.recipe, recipeAbi, provider);
const recipe = new ethers.Contract(smartcontracts[environment].recipe, recipeAbi, provider);

const amount = ethers.BigNumber.from(
BigNumber(poolAmount)
Expand Down
4 changes: 3 additions & 1 deletion src/components/modals/ExperiPieLiquidityModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import displayNotification from "../../notifications.js";
import TokenSelectModal from "./TokenSelectModal.svelte";

import { environment } from '../../stores/eth/connection.js';

import {
allowances,
approveMax,
Expand Down Expand Up @@ -161,7 +163,7 @@
return;
}

const recipe = await contract({ address: smartcontracts.recipe, abi: recipeAbi });
const recipe = await contract({ address: smartcontracts[environment].recipe, abi: recipeAbi });
const amountWei = requestedAmount.multipliedBy(10 ** 18).toFixed(0);


Expand Down
4 changes: 3 additions & 1 deletion src/components/modals/LiquidityModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import displayNotification from "../../notifications.js";
import TokenSelectModal from "./TokenSelectModal.svelte";

import { environment } from '../../stores/eth/connection.js';

import {
allowances,
approveMax,
Expand Down Expand Up @@ -149,7 +151,7 @@
return;
}

const recipe = await contract({ address: smartcontracts.recipe, abi: recipeAbi });
const recipe = await contract({ address: smartcontracts[environment].recipe, abi: recipeAbi });
const amountWei = requestedAmount.multipliedBy(10 ** 18).toFixed(0);

let overrides = {
Expand Down
3 changes: 2 additions & 1 deletion src/components/staking/Rewards.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import images from '../../config/images.json';
import { formatFiat } from '../../components/helpers.js';
import { toNum } from '../../helpers/staking.js';
import { etherscanUrl } from '../../stores/eth/connection.js';
import { stakingData } from '../../stores/eth/writables.js';
import { eth } from '../../stores/eth.js';
import Modal from '../../components/elements/Modal.svelte';
Expand Down Expand Up @@ -56,7 +57,7 @@
<div class="flex nowrap intems-center p-1 font-thin">
{new Date(reward.timestamp * 1000).toDateString()}
</div>
<a class="" href="https://etherscan.io/tx/{reward.id}" target="_blank"
<a class="" href="{etherscanUrl}/tx/{reward.id}" target="_blank"
><img
width="20px"
height="20px"
Expand Down
3 changes: 2 additions & 1 deletion src/components/staking/Summary.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script>
import { _ } from 'svelte-i18n';
import { formatFiat } from '../../components/helpers.js';
import { environment } from '../../stores/eth/connection.js';
import { toNum } from '../../helpers/staking.js';
import images from '../../config/images.json';
import smartcontracts from '../../config/smartcontracts.json';
Expand Down Expand Up @@ -85,7 +86,7 @@
params: {
type: 'ERC20',
options: {
address: smartcontracts.reward,
address: smartcontracts[environment].reward,
symbol: 'SLICE',
decimals: 18,
image: images.rewardsPie,
Expand Down
18 changes: 18 additions & 0 deletions src/config/smartcontracts.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"prod": {
"recipe": "0x2984F02e0Bf6cc21419b7f1D5081e53BA00fe458",
"recipe_old": "0xE1F9E100cbF4aD6D546b196Af33E1129Dd0866b3",
"recipev1": "0x6cb4b8669e23295563d3b34df4a760c0cee993c7",
Expand All @@ -13,4 +14,21 @@
"merkleTreeDistributor": "0xbaB795479bfF02c6ef52a10a54a95a42A1afa456",
"kpi_options": "0xdfD82bF0e1CEEC9740B9004A0921a5DE61D3557E",
"wkpi": "0xC67C620074440C15683acE78c1EfA38A4569969b"
},
"dev": {
"recipe": "0x2984F02e0Bf6cc21419b7f1D5081e53BA00fe458",
"recipe_old": "0xE1F9E100cbF4aD6D546b196Af33E1129Dd0866b3",
"recipev1": "0x6cb4b8669e23295563d3b34df4a760c0cee993c7",
"stakingPools": "0x6de77A304609472A4811a0BFD47d8682Aebc29df",
"eDOUGH": "0x63cbd1858bd79de1a06c3c26462db360b834912d",
"treasury": "0x4efd8cead66bb0fa64c8d53ebe65f31663199c6d",
"multisig": "0x3bfda5285416eb06ebc8bc0abf7d105813af06d0",
"doughStaking": "0x441658De8ebCB25d8D320Bd5C1Abb314b0CE195E",
"veDOUGH": "0xA4D4587480a61809Cbdee20F8E0d9a5c4A031d72",
"dough": "0x6503e51056C881Ebf463207f8E969fA45A1E0747",
"reward": "0xaf498e2391e7cf7a4c1ed2ea14a8c74136313e09",
"merkleTreeDistributor": "0x046B9C3A8a02A802FBA7e61054B79E28E0928F01",
"kpi_options": "0xdfD82bF0e1CEEC9740B9004A0921a5DE61D3557E",
"wkpi": "0xC67C620074440C15683acE78c1EfA38A4569969b"
}
}
33 changes: 20 additions & 13 deletions src/helpers/staking.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import MerkleTreeDistributorABI from '../abis/MerkleTreeDistributorABI.json';
import smartcontracts from '../config/smartcontracts.json';
import { subgraphRequest } from './subgraph.js';
import { subject, approve, approveMax, connectWeb3 } from '../stores/eth.js';
import { AverageSecondsMonth, veDoughSubgraphUrl, environment } from '../stores/eth/connection.js';
import displayNotification from '../notifications';
import EpochJson from '../config/rewards/distribution.json';
import { stakingDataInterval, stakingData } from '../stores/eth/writables.js';
Expand All @@ -24,8 +25,7 @@ export let sharesTimeLock = false;
export let veDOUGH = false;
export let merkleTreeDistributor = false;
export const minLockAmount = 1;
export const AVG_SECONDS_MONTH = 2628000;

export const AVG_SECONDS_MONTH = AverageSecondsMonth;
let ETH = null;
let _stakingData = get(stakingData);
let observer = null;
Expand Down Expand Up @@ -166,19 +166,19 @@ export function calculateVeDough(stakedDough, commitment) {

export function initContracts(eth) {
sharesTimeLock = new ethers.Contract(
smartcontracts.doughStaking,
smartcontracts[environment].doughStaking,
sharesTimeLockABI,
eth.signer || eth.provider,
);

veDOUGH = new ethers.Contract(
smartcontracts.veDOUGH,
smartcontracts[environment].veDOUGH,
veDoughABI,
eth.signer || eth.provider,
);

merkleTreeDistributor = new ethers.Contract(
smartcontracts.merkleTreeDistributor,
smartcontracts[environment].merkleTreeDistributor,
MerkleTreeDistributorABI,
eth.signer || eth.provider,
);
Expand Down Expand Up @@ -229,17 +229,17 @@ export async function getLastLockForAddress(eth) {
export async function calculateDoughTotalSupply(provider) {
try {
const dough = new ethers.Contract(
smartcontracts.dough,
smartcontracts[environment].dough,
DoughABI,
provider,
);

const totalSupply = await dough.totalSupply();

const treasury = await dough.balanceOf(smartcontracts.treasury);
const multisig = await dough.balanceOf(smartcontracts.multisig);
const eDough = await dough.balanceOf(smartcontracts.eDOUGH);
const kpi = await dough.balanceOf(smartcontracts.kpi_options);
const treasury = await dough.balanceOf(smartcontracts[environment].treasury);
const multisig = await dough.balanceOf(smartcontracts[environment].multisig);
const eDough = await dough.balanceOf(smartcontracts[environment].eDOUGH);
const kpi = await dough.balanceOf(smartcontracts[environment].kpi_options);

return totalSupply - treasury - multisig - eDough - kpi;
} catch (error) {
Expand Down Expand Up @@ -327,7 +327,7 @@ export async function fetchStakingStats(provider, limit, fromId) {
export async function fetchStakingDataGraph(address) {
try {
const response = await subgraphRequest(
'https://api.thegraph.com/subgraphs/name/pie-dao/vedough',
veDoughSubgraphUrl,
{
stakers: {
__args: {
Expand Down Expand Up @@ -739,10 +739,17 @@ export function approveToken(eth) {
!_stakingData.accountDepositTokenAllowance.isEqualTo(0)
&& !_stakingData.accountDepositTokenAllowance.isEqualTo(ethers.constants.MaxUint256)
) {
await approve(smartcontracts.dough, smartcontracts.doughStaking, 0);
await approve(
smartcontracts[environment].dough,
smartcontracts[environment].doughStaking, 0,
);
}

await approveMax(smartcontracts.dough, smartcontracts.doughStaking, { gasLimit: 100000 });
await approveMax(
smartcontracts[environment].dough,
smartcontracts[environment].doughStaking, { gasLimit: 100000 },
);

_stakingData.accountDepositTokenAllowance = ethers.constants.MaxUint256;
resolve(_stakingData);
} catch (error) {
Expand Down
7 changes: 4 additions & 3 deletions src/pages/DoughStaking.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import StakingSummary from '../components/staking/Summary.svelte';
import StakingStats from '../components/staking/Stats.svelte';
import StakedModal from '../components/elements/StakedModal.svelte';
import { environment } from '../stores/eth/connection.js';

let veDOUGH = 0;

Expand All @@ -41,8 +42,8 @@
let stakedModal;

$: if ($eth.address) {
subscribeToBalance(smartcontracts.dough, $eth.address);
keyDoughBalance = balanceKey(smartcontracts.dough, $eth.address);
subscribeToBalance(smartcontracts[environment].dough, $eth.address);
keyDoughBalance = balanceKey(smartcontracts[environment].dough, $eth.address);

// if address is first setup, or is changed...
if (currentAddress !== $eth.address) {
Expand All @@ -59,7 +60,7 @@
params: {
type: 'ERC20',
options: {
address: smartcontracts.veDOUGH,
address: smartcontracts[environment].veDOUGH,
symbol: 'veDOUGH',
decimals: 18,
image: images.veDough,
Expand Down
8 changes: 4 additions & 4 deletions src/pages/LPStakingV2.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import Accordion from '../components/elements/Accordion.svelte';
import AccordionGroup from '../components/elements/AccordionGroup.svelte';
import Meta from '../components/elements/meta.svelte';

import { environment } from '../stores/eth/connection.js';

let doughInEscrow = "n/a";
let escrowEntries = "n/a";
Expand All @@ -38,21 +38,21 @@
}

const { provider, signer } = get(eth);
const rewardEscrow = new ethers.Contract(smartcontracts.eDOUGH, rewardEscrowABI, signer || provider);
const rewardEscrow = new ethers.Contract(smartcontracts[environment].eDOUGH, rewardEscrowABI, signer || provider);

doughInEscrow = Number(formatEther(await rewardEscrow.totalEscrowedAccountBalance(address))).toFixed(4);
escrowEntries = (await rewardEscrow.numVestingEntries(address)).toString();
}

const getEscrowPercentages = async (poolId) => {
const { provider, signer } = get(eth);
const stakingContract = new ethers.Contract(smartcontracts.stakingPools, stakingPoolsABI, signer || provider);
const stakingContract = new ethers.Contract(smartcontracts[environment].stakingPools, stakingPoolsABI, signer || provider);
return Number(formatEther(await stakingContract.getPoolEscrowPercentage(poolId))) * 100;
}

const getPoolsUser = async () => {
const { provider, signer } = get(eth);
const stakingContract = new ethers.Contract(smartcontracts.stakingPools, stakingPoolsABI, signer || provider);
const stakingContract = new ethers.Contract(smartcontracts[environment].stakingPools, stakingPoolsABI, signer || provider);
let pools = await stakingContract.getPools($eth.address);
const res = [];

Expand Down
3 changes: 2 additions & 1 deletion src/pages/StakingPageSingle.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import { get } from "svelte/store";
import { formatEther, parseEther } from '@ethersproject/units';
import { environment } from '../stores/eth/connection.js';

export let params;

Expand Down Expand Up @@ -50,7 +51,7 @@
const getStakingPoolData = async () => {
// put address in config
const { provider, signer } = get(eth);
stakingContract = new ethers.Contract(smartcontracts.stakingPools, stakingPoolsABI, signer || provider);
stakingContract = new ethers.Contract(smartcontracts[environment].stakingPools, stakingPoolsABI, signer || provider);
let res = (await stakingContract.getPools($eth.address))[poolId] || data;

const percentage = Number(formatEther(data.escrowPercentage)) * 100;;
Expand Down
Loading