-
Notifications
You must be signed in to change notification settings - Fork 7
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
2.0.2 Hotifx Beta #232
2.0.2 Hotifx Beta #232
Changes from all commits
775c381
eaa7046
88f590f
236fb43
8179128
231c72a
f2cfb26
61f2f53
4e47f41
0b3b88a
36fe873
0f81c22
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* @license | ||
* SKALE Metaport | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/** | ||
* @file Transactions.ts | ||
* @copyright SKALE Labs 2023-Present | ||
*/ | ||
|
||
import { type TransactionResponse } from 'ethers'; | ||
|
||
export interface TxResponse { | ||
status: boolean | ||
err: TxResponseError | undefined | ||
response: TransactionResponse | undefined | ||
} | ||
|
||
export interface TxResponseError { | ||
name: string | ||
msg: string | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ | |
|
||
import debug from 'debug' | ||
import { MainnetChain, SChain, TimeoutException } from '@skalenetwork/ima-js' | ||
import { JsonRpcProvider, Provider } from 'ethers' | ||
import { JsonRpcProvider } from 'ethers' | ||
|
||
import { WalletClient } from 'viem' | ||
import { Chain } from '@wagmi/core' | ||
|
@@ -138,7 +138,7 @@ async function waitForNetworkChange( | |
async function _networkSwitch( | ||
chainId: number | bigint, | ||
currentChainId: number | bigint, | ||
switchNetwork: (chainId: number | bigint) => Promise<Chain | undefined> | ||
switchNetwork: (chainId: number | undefined) => Promise<Chain | undefined> | ||
): Promise<void> { | ||
const chain = await switchNetwork(Number(chainId)) | ||
if (!chain) { | ||
|
@@ -147,21 +147,21 @@ async function _networkSwitch( | |
} | ||
|
||
export async function enforceNetwork( | ||
provider: Provider, | ||
walletClient: WalletClient, | ||
switchNetwork: (chainId: number | bigint) => Promise<Chain | undefined>, | ||
chainId: bigint, | ||
walletClient: any, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Usage of cast to WalletClient to create local instance _walletClient on line 156 starts here. Ideal Cleanup
|
||
switchNetwork: (chainId: number | undefined) => Promise<Chain | undefined>, | ||
skaleNetwork: SkaleNetwork, | ||
chainName: string | ||
): Promise<bigint> { | ||
const currentChainId = walletClient.chain.id | ||
const { chainId } = await provider.getNetwork() | ||
const _walletClient = walletClient as WalletClient | ||
const currentChainId = await _walletClient.getChainId() | ||
log( | ||
`Current chainId: ${currentChainId}, required chainId: ${chainId}, required network: ${chainName} ` | ||
) | ||
if (currentChainId !== Number(chainId)) { | ||
log(`Switching network to ${chainId}...`) | ||
if (chainId !== 1n && chainId !== 5n) { | ||
await walletClient.addChain({ chain: constructWagmiChain(skaleNetwork, chainName) }) | ||
await _walletClient.addChain({ chain: constructWagmiChain(skaleNetwork, chainName) }) | ||
} | ||
try { | ||
// tmp fix for coinbase wallet | ||
|
@@ -170,7 +170,7 @@ export async function enforceNetwork( | |
await sleep(DEFAULT_SLEEP) | ||
_networkSwitch(chainId, currentChainId, switchNetwork) | ||
} | ||
await waitForNetworkChange(walletClient, currentChainId, chainId) | ||
await waitForNetworkChange(_walletClient, currentChainId, chainId) | ||
log(`Network switched to ${chainId}...`) | ||
} | ||
return chainId | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* @license | ||
* SKALE Metaport | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/** | ||
* @file transactions.ts | ||
* @copyright SKALE Labs 2023-Present | ||
*/ | ||
|
||
import { type TransactionResponse } from 'ethers'; | ||
import { TRANSFER_ERROR_MSG } from './constants' | ||
import { TxResponse } from './interfaces' | ||
|
||
|
||
export async function sendTransaction(func: any, args: any[]): Promise<TxResponse> { | ||
try { | ||
const response: TransactionResponse = await func(...args) | ||
await response.wait() | ||
return { status: true, err: undefined, response: response } | ||
} catch (err) { | ||
console.error(err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally should not print errors in production unless via different debug channel. |
||
const msg = err.message | ||
let name | ||
if (err.code && err.code === 'ACTION_REJECTED') { | ||
name = 'Transaction signing was rejected' | ||
} else { | ||
name = TRANSFER_ERROR_MSG | ||
} | ||
if (err.info && err.info.error && err.info.error.data && err.info.error.data.message) { | ||
name = err.info.error.data.message | ||
} | ||
if (err.shortMessage) { | ||
name = err.shortMessage | ||
} | ||
return { status: false, err: { name, msg }, response: undefined } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"mainnet": "mainnet.skalenodes.com", | ||
"staging": "staging-v3.skalenodes.com", | ||
"legacy": "legacy-proxy.skalenodes.com/", | ||
"regression": "https://regression-proxy.skalenodes.com/", | ||
"legacy": "legacy-proxy.skalenodes.com", | ||
"regression": "regression-proxy.skalenodes.com", | ||
"qatestnet": "new-testnet-proxy.skalenodes.com" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note -> Skipped 2.0.2