Skip to content

Commit

Permalink
calc rewards & roi
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita-Polyakov committed Jul 21, 2022
1 parent f50f6ce commit c55e6eb
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 76 deletions.
139 changes: 65 additions & 74 deletions public/env.json
Original file line number Diff line number Diff line change
@@ -1,95 +1,86 @@
{
"BASE_API_URL": "test.polkaswap.io",
"FAUCET_URL": "https://testfaucet.polkaswap.io/",
"SUBQUERY_ENDPOINT": "https://api.subquery.network/sq/sora-xor/sora-staging",
"API_KEYS": {
"BASE_API_URL": "",
"API_KEYS": {
"moonpay": "pk_test_4ASGxHKGpLPE6sdQq1V3QjtpUFSpWLk",
"nftStorage": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJkaWQ6ZXRocjoweDBmMzgwOTMyQTNDODM3ZDNiN2JEYzBBNTc0NmNkMDlBRGIyNUZGMzQiLCJpc3MiOiJuZnQtc3RvcmFnZSIsImlhdCI6MTY0MjU4OTQ2ODA4MSwibmFtZSI6Im5mdC1zdG9yYWdlLWRldiJ9.hkvzea9ltcriXXHKoYd3F2Iu1Y8X5H-zunAQboC_3vw",
"etherscan": "UPTTMBUBCE5FIE7XJZYAJ3YZGFE7DA6374"
},
"FEATURE_FLAGS": {
"moonpay": true
},
"DEFAULT_NETWORKS": [
"etherscan": "YBR7IWEBEXFICT8M7GRV77NBX4AXJ9T53H"
},
"FEATURE_FLAGS": {
"moonpay": true,
"charts": false
},
"FAUCET_URL": "https://faucet.dev.sora2.tachi.soramitsu.co.jp/",
"SUBQUERY_ENDPOINT": "https://api.subquery.network/sq/sora-xor/sora-dev",
"DEFAULT_NETWORKS": [
{
"chain": "SORA-staging Testnet",
"name": "SORA",
"address": "wss://ws.framenode-1.s1.stg1.sora2.soramitsu.co.jp"
"chain": "SORA-dev Testnet",
"name": "SORA",
"address": "wss://ws.framenode-1.s1.dev.sora2.soramitsu.co.jp"
},
{
"chain": "SORA-staging Testnet",
"name": "SORA",
"address": "wss://ws.framenode-2.s1.stg1.sora2.soramitsu.co.jp"
"chain": "SORA-dev Testnet",
"name": "SORA",
"address": "wss://ws.framenode-2.s2.dev.sora2.soramitsu.co.jp"
},
{
"chain": "SORA-staging Testnet",
"name": "SORA",
"address": "wss://ws.framenode-3.s2.stg1.sora2.soramitsu.co.jp"
"chain": "SORA-dev Testnet",
"name": "SORA",
"address": "wss://ws.framenode-3.s3.dev.sora2.soramitsu.co.jp"
},
{
"chain": "SORA-staging Testnet",
"name": "SORA",
"address": "wss://ws.framenode-4.s2.stg1.sora2.soramitsu.co.jp"
"chain": "SORA-dev Testnet",
"name": "SORA",
"address": "wss://ws.framenode-4.s3.dev.sora2.soramitsu.co.jp"
},
{
"chain": "SORA-staging Testnet",
"name": "SORA",
"address": "wss://ws.framenode-5.s3.stg1.sora2.soramitsu.co.jp"
"chain": "SORA-dev Testnet",
"name": "SORA",
"address": "wss://ws.framenode-5.s4.dev.sora2.soramitsu.co.jp"
},
{
"chain": "SORA-staging Testnet",
"name": "SORA",
"address": "wss://ws.framenode-6.s3.stg1.sora2.soramitsu.co.jp"
},
{
"chain": "SORA-staging Testnet",
"name": "SORA",
"address": "wss://ws.framenode-7.s4.stg1.sora2.soramitsu.co.jp"
},
{
"chain": "SORA-staging Testnet",
"name": "SORA",
"address": "wss://ws.framenode-8.s5.stg1.sora2.soramitsu.co.jp"
"chain": "SORA-dev Testnet",
"name": "SORA",
"address": "wss://ws.framenode-6.s4.dev.sora2.soramitsu.co.jp"
}
],
"NETWORK_TYPE": "Stage",
"CHAIN_GENESIS_HASH": "0x1a0983c6c9fd3178ae24656bcfca4510a439ab7b90c83e360a1671609752b09a",
"SUB_NETWORKS": [
],
"NETWORK_TYPE": "Dev",
"CHAIN_GENESIS_HASH": "",
"SUB_NETWORKS": [
{
"name": "ethereum",
"id": 0,
"symbol": "ETH",
"currency": "ETH",
"defaultType": "rinkeby",
"CONTRACTS": {
"XOR": {
"MASTER": "0xcceb41100aa2a9a6f144d7c1f876070b810bf7ae"
},
"VAL": {
"MASTER": "0xd7f81ed173cb3af28f983670164df30851fba678"
},
"OTHER": {
"MASTER": "0x077c2ec37d28709ce01ae740209bfbe185bd1eaa"
"name": "ethereum",
"id": 0,
"symbol": "ETH",
"currency": "ETH",
"defaultType": "rinkeby",
"CONTRACTS": {
"XOR": {
"MASTER": "0x12c6a709925783f49fcca0b398d13b0d597e6e1c"
},
"VAL": {
"MASTER": "0x47e229aa491763038f6a505b4f85d8eb463f0962"
},
"OTHER": {
"MASTER": "0x24390c8f6cbd5d152c30226f809f4e3f153b88d4"
}
}
}
},
{
"name": "energy",
"id": 1,
"symbol": "VT",
"currency": "VT",
"defaultType": "private",
"CONTRACTS": {
"XOR": {
"MASTER": ""
},
"VAL": {
"MASTER": ""
},
"OTHER": {
"MASTER": "0x906111a433731a563Aa0d0FA871FF93f9A3B3035"
"name": "energy",
"id": 1,
"symbol": "VT",
"currency": "VT",
"defaultType": "private",
"CONTRACTS": {
"XOR": {
"MASTER": ""
},
"VAL": {
"MASTER": ""
},
"OTHER": {
"MASTER": "0x1891b81AE0C5A81Ec84BC4f69322C6a01A3B3095"
}
}
}
}
]
}
]
}
62 changes: 60 additions & 2 deletions src/modules/demeterFarming/components/CalculatorDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
<div class="results">
<div class="results-title">APR Results</div>

<info-line label="ROI" />
<info-line :label="rewardsText" />
<info-line label="ROI" :value="calculatedRoiPercentFormatted" />
<info-line :label="rewardsText" :value="calculatedRewardsFormatted" :fiat-value="calculatedRewardsFiat" />
</div>
</div>
</dialog-base>
Expand Down Expand Up @@ -112,6 +112,64 @@ export default class CalculatorDialog extends Mixins(StakeDialogMixin) {
return isMaxButtonAvailable(true, this.poolAsset, this.poolAssetValue, this.networkFee, this.xor);
}
get userTokensDeposit(): FPNumber {
return this.isFarm
? this.liqudityLP
.mul(new FPNumber(this.poolAssetValue || 0))
.div(FPNumber.fromCodecValue(this.liquidity?.secondBalance ?? 0))
: new FPNumber(this.poolAssetValue || 0);
}
get userTokensDepositWithFee(): FPNumber {
const depositFee = new FPNumber(this.depositFee);
return this.userTokensDeposit.mul(FPNumber.ONE.sub(depositFee));
}
get calculatedRewards(): FPNumber {
if (!this.pool) return FPNumber.ZERO;
const totalDeposit = this.pool.totalTokensInPool.add(this.userTokensDepositWithFee);
const period = new FPNumber(this.interval);
const blocksPerDay = new FPNumber(14_400);
const blocksProduced = period.mul(blocksPerDay);
return this.emission.mul(blocksProduced).mul(this.userTokensDepositWithFee).div(totalDeposit);
}
get calculatedRewardsFormatted(): string {
return this.calculatedRewards.toLocaleString();
}
get calculatedRewardsFiat(): string {
return this.getFiatAmountByFPNumber(this.calculatedRewards, this.rewardAsset as AccountAsset);
}
get calculatedRoiPercent(): FPNumber {
const depositInPoolsAsset = new FPNumber(this.poolAssetValue || 0);
if (depositInPoolsAsset.isZero()) return FPNumber.ZERO;
// for liquidity pool we multiply deposit in pool asset by 2
const multiplier = this.isFarm ? 2 : 1;
const costOfDepositFeeUSD = depositInPoolsAsset
.mul(new FPNumber(multiplier))
.mul(new FPNumber(this.depositFee))
.mul(this.poolAssetPrice);
const costOfNetworkFeeUSD = FPNumber.fromCodecValue(this.networkFee, this.xor.decimals).mul(
FPNumber.fromCodecValue(this.getAssetFiatPrice(this.xor) ?? 0)
);
const costOfInvestmentUSD = costOfDepositFeeUSD.add(costOfNetworkFeeUSD);
const valueOfInvestmentUSD = this.calculatedRewards.mul(this.rewardAssetPrice);
return valueOfInvestmentUSD.sub(costOfInvestmentUSD).div(costOfInvestmentUSD).mul(FPNumber.HUNDRED);
}
get calculatedRoiPercentFormatted(): string {
return this.calculatedRoiPercent.dp(2).toLocaleString() + '%';
}
selectPeriod({ name }): void {
this.interval = Number(name);
}
Expand Down

0 comments on commit c55e6eb

Please sign in to comment.