diff --git a/package.json b/package.json index 775ddc6..074ce02 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@skalenetwork/metaport", - "version": "2.0.0", + "version": "2.0.1", "description": "SKALE Metaport Widget", "keywords": [ "skale", diff --git a/src/core/community_pool.ts b/src/core/community_pool.ts index 04cbfcd..8a1a461 100644 --- a/src/core/community_pool.ts +++ b/src/core/community_pool.ts @@ -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, @@ -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' @@ -104,25 +104,6 @@ export async function getCommunityPoolData( return communityPoolData } -export async function connectedMainnetChain( - mpc: MetaportCore, - walletClient: WalletClient, - switchNetwork: (chainId: number | bigint) => Promise -): Promise { - 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, @@ -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 }) @@ -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) }) @@ -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) diff --git a/src/core/constants.ts b/src/core/constants.ts index ec1e8ac..0b8214f 100644 --- a/src/core/constants.ts +++ b/src/core/constants.ts @@ -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 = ['🎉', '👌', '✅', '🙌', '🎊'] diff --git a/src/core/network.ts b/src/core/network.ts index 2df301b..7461f8b 100644 --- a/src/core/network.ts +++ b/src/core/network.ts @@ -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 {