Skip to content

Commit

Permalink
Merge pull request #283 from skalenetwork/update-community-pool-logic
Browse files Browse the repository at this point in the history
Update community pool logic, remove legacy components
  • Loading branch information
dmytrotkk authored Oct 30, 2024
2 parents 87792c5 + 2da4a8d commit e803061
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 121 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@skalenetwork/metaport",
"version": "3.0.1",
"version": "3.1.0",
"description": "SKALE Metaport Widget",
"keywords": [
"skale",
Expand Down Expand Up @@ -101,4 +101,4 @@
"prettier -w"
]
}
}
}
2 changes: 1 addition & 1 deletion skale-network
Submodule skale-network updated 330 files
7 changes: 4 additions & 3 deletions src/components/CommunityPool.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { fromWei } from '../core/convertation'
import { withdraw, recharge } from '../core/community_pool'
import {
BALANCE_UPDATE_INTERVAL_MS,
COMMUNITY_POOL_DECIMALS,
DEFAULT_ERC20_DECIMALS,
MINIMUM_RECHARGE_AMOUNT
} from '../core/constants'
Expand Down Expand Up @@ -126,9 +127,9 @@ export default function CommunityPool() {
if (loading === 'recharge') return 'Recharging...'
if (loading === 'activate') return 'Activating account...'
if (Number(amount) > Number(accountBalanceEther)) return 'Insufficient ETH balance'
if (amount === '' || amount === '0' || !amount) return 'Enter an amount'
if (Number(amount) < MINIMUM_RECHARGE_AMOUNT)
return `Recharge amount should be bigger than ${MINIMUM_RECHARGE_AMOUNT}`
if (amount === '' || amount === '0' || !amount) return 'Enter an amount'
return 'Recharge exit gas wallet'
}

Expand Down Expand Up @@ -210,7 +211,7 @@ export default function CommunityPool() {
<TokenBalance
balance={cpData.accountBalance}
symbol="ETH"
truncate={4}
truncate={COMMUNITY_POOL_DECIMALS}
size="sm"
primary
/>
Expand All @@ -224,7 +225,7 @@ export default function CommunityPool() {
<TokenBalance
balance={cpData.balance}
symbol="ETH"
truncate={4}
truncate={COMMUNITY_POOL_DECIMALS}
size="sm"
primary
/>
Expand Down
53 changes: 0 additions & 53 deletions src/components/TransferETA.tsx

This file was deleted.

50 changes: 0 additions & 50 deletions src/components/TransferETF.tsx

This file was deleted.

16 changes: 12 additions & 4 deletions src/core/community_pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ import {
RECHARGE_MULTIPLIER,
MINIMUM_RECHARGE_AMOUNT,
COMMUNITY_POOL_WITHDRAW_GAS_LIMIT,
COMMUNITY_POOL_ESTIMATE_GAS_LIMIT,
DEFAULT_ERROR_MSG,
BALANCE_UPDATE_INTERVAL_MS
} from './constants'
import { delay } from './helper'
import { delay, roundUp } from './helper'
import MetaportCore from './metaport'

import * as dataclasses from '../core/dataclasses'
Expand Down Expand Up @@ -83,14 +84,21 @@ export async function getCommunityPoolData(
const chainHash = ethers.id(chainName1)
const activeM = await mainnet.communityPool.contract.activeUsers(address, chainHash)

const feeData = await mainnet.communityPool.contract.runner.provider.getFeeData()
const rraWei = await mainnet.communityPool.contract.getRecommendedRechargeAmount(
chainHash,
address
address,
{
gasPrice: feeData.gasPrice,
gasLimit: COMMUNITY_POOL_ESTIMATE_GAS_LIMIT
}
)
const rraEther = fromWei(rraWei as string, DEFAULT_ERC20_DECIMALS)

let recommendedAmount = parseFloat(rraEther as string) * RECHARGE_MULTIPLIER
if (recommendedAmount < MINIMUM_RECHARGE_AMOUNT) recommendedAmount = MINIMUM_RECHARGE_AMOUNT
let recommendedAmount = roundUp(parseFloat(rraEther as string) * RECHARGE_MULTIPLIER)
if (recommendedAmount < MINIMUM_RECHARGE_AMOUNT && recommendedAmount !== 0) {
recommendedAmount = MINIMUM_RECHARGE_AMOUNT
}

const communityPoolData = {
exitGasOk: activeM && activeS && rraWei === 0n,
Expand Down
6 changes: 4 additions & 2 deletions src/core/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,13 @@ export const FAUCET_DATA = faucetJson

// community pool

export const RECHARGE_MULTIPLIER = 1.2
export const MINIMUM_RECHARGE_AMOUNT = 0.005
export const RECHARGE_MULTIPLIER = 1.1
export const MINIMUM_RECHARGE_AMOUNT = 0.000005
export const COMMUNITY_POOL_ESTIMATE_GAS_LIMIT = 1000000n
export const COMMUNITY_POOL_WITHDRAW_GAS_LIMIT = 150000n
export const _BALANCE_UPDATE_INTERVAL_SECONDS = 10
export const BALANCE_UPDATE_INTERVAL_MS = _BALANCE_UPDATE_INTERVAL_SECONDS * 1000
export const COMMUNITY_POOL_DECIMALS = 6

export const SFUEL_RESERVE_AMOUNT = 0.01

Expand Down
12 changes: 11 additions & 1 deletion src/core/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import { getAddress } from 'ethers'

import { MAINNET_CHAIN_NAME } from './constants'
import { COMMUNITY_POOL_DECIMALS, MAINNET_CHAIN_NAME } from './constants'
import { TransferRequestStatus } from './dataclasses'

export function eqArrays(arr1, arr2) {
Expand Down Expand Up @@ -67,3 +67,13 @@ export function sortObjectByKeys(obj: { [key: string]: any }): { [key: string]:

return sortedObject
}

export function roundDown(num: number, decimals: number = COMMUNITY_POOL_DECIMALS): number {
decimals = decimals || 0
return Math.floor(num * Math.pow(10, decimals)) / Math.pow(10, decimals)
}

export function roundUp(num: number, decimals: number = COMMUNITY_POOL_DECIMALS): number {
const factor = Math.pow(10, decimals)
return Math.round(num * factor) / factor
}
5 changes: 0 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import TokenBalance from './components/TokenBalance'
import AmountInput from './components/AmountInput'
import SwitchDirection from './components/SwitchDirection'
import SkStepper from './components/Stepper'
import TransferETF from './components/TransferETF'
import TransferETA from './components/TransferETA'
import AmountErrorMessage from './components/AmountErrorMessage'
import DestTokenBalance from './components/DestTokenBalance'
import ErrorMessage from './components/ErrorMessage'
Expand All @@ -45,7 +43,6 @@ import { ERC_ABIS } from './core/contracts'
import { sendTransaction } from './core/transactions'
import { Station, StationData } from './core/sfuel'


import { getWidgetTheme as getMetaportTheme } from './core/themes'

import {
Expand Down Expand Up @@ -78,8 +75,6 @@ export {
AmountInput,
SwitchDirection,
SkStepper,
TransferETF,
TransferETA,
AmountErrorMessage,
TokenBalance,
DestTokenBalance,
Expand Down

0 comments on commit e803061

Please sign in to comment.