Skip to content

Commit

Permalink
Merge pull request #229 from skalenetwork/develop
Browse files Browse the repository at this point in the history
New beta version - 2.0.1
  • Loading branch information
dmytrotkk authored Nov 13, 2023
2 parents 2eab246 + aae8074 commit 8cc96e4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 29 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@skalenetwork/metaport",
"version": "2.0.0",
"version": "2.0.1",
"description": "SKALE Metaport Widget",
"keywords": [
"skale",
Expand Down
53 changes: 28 additions & 25 deletions src/core/community_pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { Chain } from '@wagmi/core'
import { CommunityPoolData } from './interfaces'
import { fromWei, toWei } from './convertation'
import { walletClientToSigner } from './ethers'
import { enforceNetwork, getMainnetAbi } from './network'
import {
MAINNET_CHAIN_NAME,
DEFAULT_ERC20_DECIMALS,
Expand All @@ -41,7 +42,6 @@ import {
BALANCE_UPDATE_INTERVAL_MS
} from './constants'
import { delay } from './helper'
import { CHAIN_IDS, getMainnetAbi } from './network'
import MetaportCore from './metaport'

import * as dataclasses from '../core/dataclasses'
Expand Down Expand Up @@ -104,25 +104,6 @@ export async function getCommunityPoolData(
return communityPoolData
}

export async function connectedMainnetChain(
mpc: MetaportCore,
walletClient: WalletClient,
switchNetwork: (chainId: number | bigint) => Promise<Chain | undefined>
): Promise<MainnetChain> {
const currentChainId = walletClient.chain.id
const chainId = CHAIN_IDS[mpc.config.skaleNetwork]
log(`Current chainId: ${currentChainId}, required chainId: ${chainId} `)
if (currentChainId !== Number(chainId)) {
log(`Switching network to ${chainId}...`)
const chain = await switchNetwork(Number(chainId))
if (!chain) {
throw new Error(`Failed to switch from ${currentChainId} to ${chainId} `)
}
log(`Network switched to ${chainId}...`)
}
const signer = walletClientToSigner(walletClient)
return new MainnetChain(signer.provider, getMainnetAbi(mpc.config.skaleNetwork))
}

export async function withdraw(
mpc: MetaportCore,
Expand All @@ -138,8 +119,19 @@ export async function withdraw(
setLoading('withdraw')
try {
log(`Withdrawing from community pool: ${chainName}, amount: ${amount}`)
const mainnetMetamask = await connectedMainnetChain(mpc, walletClient, switchNetwork)
await mainnetMetamask.communityPool.withdraw(chainName, amount, {
await enforceNetwork(
mpc.mainnet().provider,
walletClient,
switchNetwork,
mpc.config.skaleNetwork,
MAINNET_CHAIN_NAME
)
const signer = walletClientToSigner(walletClient)
const connectedMainnet = new MainnetChain(
signer.provider,
getMainnetAbi(mpc.config.skaleNetwork)
)
await connectedMainnet.communityPool.withdraw(chainName, amount, {
address: address,
customGasLimit: COMMUNITY_POOL_WITHDRAW_GAS_LIMIT
})
Expand Down Expand Up @@ -167,8 +159,19 @@ export async function recharge(
log(`Recharging community pool: ${chainName}, amount: ${amount}`)

const sChain = mpc.schain(chainName)
const mainnetMetamask = await connectedMainnetChain(mpc, walletClient, switchNetwork)
await mainnetMetamask.communityPool.recharge(chainName, address, {
await enforceNetwork(
mpc.mainnet().provider,
walletClient,
switchNetwork,
mpc.config.skaleNetwork,
MAINNET_CHAIN_NAME
)
const signer = walletClientToSigner(walletClient)
const connectedMainnet = new MainnetChain(
signer.provider,
getMainnetAbi(mpc.config.skaleNetwork)
)
await connectedMainnet.communityPool.recharge(chainName, address, {
address: address,
value: toWei(amount, DEFAULT_ERC20_DECIMALS)
})
Expand All @@ -178,7 +181,7 @@ export async function recharge(
let counter = 0
while (!active) {
log('Waiting for account activation...')
let activeM = await mainnetMetamask.communityPool.contract.activeUsers(address, chainHash)
let activeM = await connectedMainnet.communityPool.contract.activeUsers(address, chainHash)
let activeS = await sChain.communityLocker.contract.activeUsers(address)
active = activeS && activeM
await delay(BALANCE_UPDATE_INTERVAL_MS)
Expand Down
4 changes: 2 additions & 2 deletions src/core/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ export const FAUCET_DATA = faucetJson

export const RECHARGE_MULTIPLIER = 1.2
export const MINIMUM_RECHARGE_AMOUNT = 0.005
export const COMMUNITY_POOL_WITHDRAW_GAS_LIMIT = 1500000n
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 SFUEL_RESERVE_AMOUNT = 0.02
export const SFUEL_RESERVE_AMOUNT = 0.01

export const SUCCESS_EMOJIS = ['πŸŽ‰', 'πŸ‘Œ', 'βœ…', 'πŸ™Œ', '🎊']

Expand Down
2 changes: 1 addition & 1 deletion src/core/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const CHAIN_IDS: { [network in SkaleNetwork]: number } = {
staging: 5,
legacy: 5,
regression: 5,
mainnet: 5
mainnet: 1
}

export function isMainnetChainId(chainId: number | BigInt, skaleNetwork: SkaleNetwork): boolean {
Expand Down

0 comments on commit 8cc96e4

Please sign in to comment.