diff --git a/package.json b/package.json index 78bd7d8..6fec199 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "prettier": "^2.2.1", "pretty-quick": "^3.1.0", "ts-node": "^9.1.1", - "typescript": "^4.1.5" + "typescript": "^5.1.6" }, "dependencies": { "debug": "^4.3.4", diff --git a/src/contracts/BaseContract.ts b/src/contracts/BaseContract.ts index d0d0272..6989ab9 100644 --- a/src/contracts/BaseContract.ts +++ b/src/contracts/BaseContract.ts @@ -22,10 +22,6 @@ */ import { ethers, Provider } from "ethers"; -import debug from 'debug'; - - -const log = debug('ima:contracts:BaseContract'); export class BaseContract { @@ -35,7 +31,6 @@ export class BaseContract { name: string; constructor(provider: Provider, address: string, abi: any, name: string) { - log('Initing contract ' + this.constructor.name + ' at ' + address); this.provider = provider; this.address = address; this.contract = new ethers.Contract(address, abi, provider); diff --git a/src/helper.ts b/src/helper.ts index c527cad..b176a91 100644 --- a/src/helper.ts +++ b/src/helper.ts @@ -21,7 +21,6 @@ * @copyright SKALE Labs 2021-Present */ -import fs from 'fs'; import * as constants from './constants'; import InvalidCredentialsException from './exceptions/InvalidCredentialsException'; @@ -39,24 +38,6 @@ export function remove0x(s: any) { return s.slice(2); } -export function jsonFileLoad(path: string) { - if (!fileExists(path)) { - return {} - } - const s = fs.readFileSync(path); - const jo = JSON.parse(s.toString()); - return jo; -} - -export function fileExists(strPath: string) { - if (fs.existsSync(strPath)) { - const stats = fs.statSync(strPath); - if (stats.isFile()) - return true; - } - return false; -} - export function validatePrivateKey(privateKey: string) { if (!constants.PRIVATE_KEY_REGEX.test(privateKey)) { throw new InvalidCredentialsException(constants.errorMessages.INVALID_PRIVATEKEY); diff --git a/src/transactions.ts b/src/transactions.ts index aec7ef8..6935c2d 100644 --- a/src/transactions.ts +++ b/src/transactions.ts @@ -44,8 +44,9 @@ export async function send( if (opts.value) transaction.value = opts.value; if (opts.address) transaction.from = opts.address; - const gasLimit = await provider.estimateGas(transaction); - log('💡 ' + name + ' estimated gasLimit: ' + gasLimit); + const gasLimit = opts.customGasLimit ?? await provider.estimateGas(transaction); + transaction.gasLimit = gasLimit; + log('💡 ' + name + ' gasLimit: ' + gasLimit); const signer = await getSigner(provider, opts); @@ -56,6 +57,7 @@ export async function send( log('⏳ ' + name + ' mining - tx: ' + txResponse.hash + ', nonce: ' + txResponse.nonce + ', gasLimit: ' + txResponse.gasLimit); if (wait) await provider.waitForTransaction(txResponse.hash); + // todo: handle failed tx! log('✅ ' + name + ' mined - tx: ' + txResponse.hash); return txResponse; } diff --git a/test/helper.ts b/test/helper.ts new file mode 100644 index 0000000..e69de29 diff --git a/test/test_utils.ts b/test/test_utils.ts index 25996ac..451d7b6 100644 --- a/test/test_utils.ts +++ b/test/test_utils.ts @@ -1,5 +1,6 @@ // import Web3 from 'web3'; // import {AbiItem} from 'web3-utils'; +import fs from 'fs'; import { Wallet, Contract, Provider, JsonRpcProvider } from "ethers"; @@ -42,25 +43,44 @@ const NETWORKS = ['mainnet', 'schain']; const TOKEN_NAME = 'TEST'; + +export function jsonFileLoad(path: string) { + if (!fileExists(path)) { + return {} + } + const s = fs.readFileSync(path); + const jo = JSON.parse(s.toString()); + return jo; +} + +export function fileExists(strPath: string) { + if (fs.existsSync(strPath)) { + const stats = fs.statSync(strPath); + if (stats.isFile()) + return true; + } + return false; +} + export function initTestIMA() { const providerMainnet = new JsonRpcProvider(MAINNET_ENDPOINT); const providerSchain = new JsonRpcProvider(SCHAIN_ENDPOINT); - const mainnetAbi = helper.jsonFileLoad(MAINNET_ABI_FILEPATH); - const sChainAbi = helper.jsonFileLoad(SCHAIN_ABI_FILEPATH); + const mainnetAbi = jsonFileLoad(MAINNET_ABI_FILEPATH); + const sChainAbi = jsonFileLoad(SCHAIN_ABI_FILEPATH); return new IMA(providerMainnet, providerSchain, mainnetAbi, sChainAbi) } export function initTestSChain() { const provider = new JsonRpcProvider(SCHAIN_ENDPOINT); - const abi = helper.jsonFileLoad(SCHAIN_ABI_FILEPATH); + const abi = jsonFileLoad(SCHAIN_ABI_FILEPATH); return new SChain(provider, abi); } export function initTestMainnet() { const provider = new JsonRpcProvider(MAINNET_ENDPOINT); - const abi = helper.jsonFileLoad(MAINNET_ABI_FILEPATH); + const abi = jsonFileLoad(MAINNET_ABI_FILEPATH); return new MainnetChain(provider, abi); } @@ -118,7 +138,7 @@ export function initTestTokens( for (let i in NETWORKS) { let network = NETWORKS[i]; let filepath = TOKENS_ABI_FOLDER + tokenName + 'Example-' + TOKEN_NAME + '-' + network + '.json'; - let tokenMeta = helper.jsonFileLoad(filepath); + let tokenMeta = jsonFileLoad(filepath); let keyName = network + tokenName; let abiKey = tokenName.toLowerCase() + '_abi'; diff --git a/tsconfig.json b/tsconfig.json index 5db033a..3d8aabf 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,7 +4,7 @@ /* Basic Options */ // "incremental": true, /* Enable incremental compilation */ - "target": "ES2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ + "target": "esnext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ // "lib": [], /* Specify library files to be included in the compilation. */ // "allowJs": true, /* Allow javascript files to be compiled. */ @@ -42,8 +42,8 @@ // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ /* Module Resolution Options */ - // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ - "baseUrl": "src", /* Base directory to resolve non-absolute module names. */ + "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ + // "baseUrl": "src", /* Base directory to resolve non-absolute module names. */ // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ // "typeRoots": [], /* List of folders to include type definitions from. */ @@ -66,8 +66,6 @@ /* Advanced Options */ "skipLibCheck": true, /* Skip type checking of declaration files. */ "forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */ - - "resolveJsonModule": true }, "exclude": [ "build", diff --git a/yarn.lock b/yarn.lock index d5e0df3..144d6cf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3486,10 +3486,10 @@ type-fest@^0.21.3: resolved "https://registry.npmjs.org/type-fest/-/type-fest-0.21.3.tgz" integrity sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w== -typescript@^4.1.5: - version "4.6.4" - resolved "https://registry.npmjs.org/typescript/-/typescript-4.6.4.tgz" - integrity sha512-9ia/jWHIEbo49HfjrLGfKbZSuWo9iTMwXO+Ca3pRsSpbsMbc7/IU8NKdCZVRRBafVPGnoJeFL76ZOAA84I9fEg== +typescript@^5.1.6: + version "5.1.6" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.1.6.tgz#02f8ac202b6dad2c0dd5e0913745b47a37998274" + integrity sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA== unbox-primitive@^1.0.1: version "1.0.2"