@coinmasters/toolbox-evm
Advanced tools
Comparing version
@@ -1,2 +0,2 @@ | ||
import { aY as o, aZ as t, a_ as b, a$ as l, aS as r, aT as d, b0 as A, bj as i, b2 as T, aW as c, b3 as h, bc as n, b8 as x, b4 as g, bb as k, b5 as w, bh as p, aU as E, bd as M, bi as S, aV as W, b1 as m, ba as C, be as B, bf as V, b6 as u, b9 as N, aX as P, bg as f, b7 as D } from "./index-9b0d2426.js"; | ||
import { aY as o, aZ as t, a_ as b, a$ as l, aS as r, aT as d, b0 as A, bj as i, b2 as T, aW as c, b3 as h, bc as n, b8 as x, b4 as g, bb as k, b5 as w, bh as p, aU as E, bd as M, bi as S, aV as W, b1 as m, ba as C, be as B, bf as V, b6 as u, b9 as N, aX as P, bg as f, b7 as D } from "./index-385953a1.js"; | ||
import "@coinmasters/helpers"; | ||
@@ -3,0 +3,0 @@ export { |
@@ -18,3 +18,3 @@ { | ||
"@internal/config": "2.5.0", | ||
"@coinmasters/helpers": "9.0.0" | ||
"@coinmasters/helpers": "9.0.1" | ||
}, | ||
@@ -25,3 +25,3 @@ "eslintConfig": { | ||
"peerDependencies": { | ||
"@coinmasters/helpers": "9.0.0" | ||
"@coinmasters/helpers": "9.0.1" | ||
}, | ||
@@ -51,3 +51,3 @@ "exports": { | ||
"types": "./dist/index.d.ts", | ||
"version": "9.0.0", | ||
"version": "9.0.1", | ||
"scripts": { | ||
@@ -54,0 +54,0 @@ "build": "vite build", |
@@ -15,2 +15,3 @@ import { AssetValue, formatBigIntToSafeValue, SwapKitNumber } from '@coinmasters/helpers'; | ||
import { AVAXToolbox, BSCToolbox, ETHToolbox } from './index.ts'; | ||
const TAG = ' | EVM -helpers | '; | ||
@@ -163,3 +164,3 @@ type NetworkParams = { | ||
export const estimateMaxSendableAmount = async ({ | ||
export const estimateMaxSendableAmount = async function ({ | ||
toolbox, | ||
@@ -175,55 +176,133 @@ from, | ||
txOverrides, | ||
}: EVMMaxSendableAmountsParams): Promise<AssetValue> => { | ||
const balance = (await toolbox.getBalance(from)).find(({ symbol, chain }) => | ||
assetValue | ||
? symbol === assetValue.symbol | ||
: symbol === AssetValue.fromChainOrSignature(chain)?.symbol, | ||
); | ||
}: EVMMaxSendableAmountsParams) { | ||
let tag = TAG + ' | estimateMaxSendableAmount | '; | ||
try { | ||
console.log(tag, 'checkpoint '); | ||
const balance = (await toolbox.getBalance([{address:from}])).find(({ symbol, chain }) => | ||
assetValue | ||
? symbol === assetValue.symbol | ||
: symbol === AssetValue.fromChainOrSignature(chain)?.symbol, | ||
); | ||
console.log(tag, 'balance: ', balance); | ||
const fees = (await toolbox.estimateGasPrices())[feeOptionKey]; | ||
const fees = (await toolbox.estimateGasPrices())[feeOptionKey]; | ||
console.log(tag, 'fees: ', fees); | ||
if (!balance) return AssetValue.fromChainOrSignature(assetValue.chain, 0); | ||
if (!balance) return AssetValue.fromChainOrSignature(assetValue.chain, 0); | ||
if (assetValue && (balance.chain !== assetValue.chain || balance.symbol !== assetValue?.symbol)) { | ||
return balance; | ||
} | ||
if ( | ||
assetValue && | ||
(balance.chain !== assetValue.chain || balance.symbol !== assetValue?.symbol) | ||
) { | ||
return balance; | ||
} | ||
if ([abi, funcName, funcParams, contractAddress].some((param) => !param)) { | ||
throw new Error('Missing required parameters for smart contract estimateMaxSendableAmount'); | ||
} | ||
if ([abi, funcName, funcParams, contractAddress].some((param) => !param)) { | ||
throw new Error('Missing required parameters for smart contract estimateMaxSendableAmount'); | ||
} | ||
const gasLimit = | ||
abi && funcName && funcParams && contractAddress | ||
? await toolbox.estimateCall({ | ||
contractAddress, | ||
abi, | ||
funcName, | ||
funcParams, | ||
txOverrides, | ||
}) | ||
: await toolbox.estimateGasLimit({ | ||
from, | ||
recipient: from, | ||
memo, | ||
assetValue, | ||
}); | ||
const gasLimit = | ||
abi && funcName && funcParams && contractAddress | ||
? await toolbox.estimateCall({ | ||
contractAddress, | ||
abi, | ||
funcName, | ||
funcParams, | ||
txOverrides, | ||
}) | ||
: await toolbox.estimateGasLimit({ | ||
from, | ||
recipient: from, | ||
memo, | ||
assetValue, | ||
}); | ||
console.log(tag, 'gasLimit: ', gasLimit); | ||
const isFeeEIP1559Compatible = 'maxFeePerGas' in fees; | ||
const isFeeEVMLegacyCompatible = 'gasPrice' in fees; | ||
const isFeeEIP1559Compatible = 'maxFeePerGas' in fees; | ||
const isFeeEVMLegacyCompatible = 'gasPrice' in fees; | ||
if (!isFeeEVMLegacyCompatible && !isFeeEIP1559Compatible) | ||
throw new Error('Could not fetch fee data'); | ||
if (!isFeeEVMLegacyCompatible && !isFeeEIP1559Compatible) | ||
throw new Error('Could not fetch fee data'); | ||
const fee = | ||
gasLimit * | ||
(isFeeEIP1559Compatible | ||
? fees.maxFeePerGas! + (fees.maxPriorityFeePerGas! || 1n) | ||
: fees.gasPrice!); | ||
const maxSendableAmount = SwapKitNumber.fromBigInt(balance.getBaseValue('bigint')).sub( | ||
fee.toString(), | ||
); | ||
const fee = | ||
gasLimit * | ||
(isFeeEIP1559Compatible | ||
? fees.maxFeePerGas! + (fees.maxPriorityFeePerGas! || 1n) | ||
: fees.gasPrice!); | ||
const maxSendableAmount = SwapKitNumber.fromBigInt(balance.getBaseValue('bigint')).sub( | ||
fee.toString(), | ||
); | ||
console.log(tag, 'fee: ', fee); | ||
return AssetValue.fromChainOrSignature(balance.chain, maxSendableAmount.getValue('string')); | ||
return AssetValue.fromChainOrSignature(balance.chain, maxSendableAmount.getValue('string')); | ||
} catch (e) { | ||
console.error(tag,"e: ",e); | ||
throw e; | ||
} | ||
}; | ||
// export const estimateMaxSendableAmount = async ({ | ||
// toolbox, | ||
// from, | ||
// memo = '', | ||
// feeOptionKey = FeeOption.Fastest, | ||
// assetValue, | ||
// abi, | ||
// funcName, | ||
// funcParams, | ||
// contractAddress, | ||
// txOverrides, | ||
// }: EVMMaxSendableAmountsParams): Promise<AssetValue> => { | ||
// const balance = (await toolbox.getBalance(from)).find(({ symbol, chain }) => | ||
// assetValue | ||
// ? symbol === assetValue.symbol | ||
// : symbol === AssetValue.fromChainOrSignature(chain)?.symbol, | ||
// ); | ||
// | ||
// const fees = (await toolbox.estimateGasPrices())[feeOptionKey]; | ||
// | ||
// if (!balance) return AssetValue.fromChainOrSignature(assetValue.chain, 0); | ||
// | ||
// if (assetValue && (balance.chain !== assetValue.chain || balance.symbol !== assetValue?.symbol)) { | ||
// return balance; | ||
// } | ||
// | ||
// if ([abi, funcName, funcParams, contractAddress].some((param) => !param)) { | ||
// throw new Error('Missing required parameters for smart contract estimateMaxSendableAmount'); | ||
// } | ||
// | ||
// const gasLimit = | ||
// abi && funcName && funcParams && contractAddress | ||
// ? await toolbox.estimateCall({ | ||
// contractAddress, | ||
// abi, | ||
// funcName, | ||
// funcParams, | ||
// txOverrides, | ||
// }) | ||
// : await toolbox.estimateGasLimit({ | ||
// from, | ||
// recipient: from, | ||
// memo, | ||
// assetValue, | ||
// }); | ||
// | ||
// const isFeeEIP1559Compatible = 'maxFeePerGas' in fees; | ||
// const isFeeEVMLegacyCompatible = 'gasPrice' in fees; | ||
// | ||
// if (!isFeeEVMLegacyCompatible && !isFeeEIP1559Compatible) | ||
// throw new Error('Could not fetch fee data'); | ||
// | ||
// const fee = | ||
// gasLimit * | ||
// (isFeeEIP1559Compatible | ||
// ? fees.maxFeePerGas! + (fees.maxPriorityFeePerGas! || 1n) | ||
// : fees.gasPrice!); | ||
// const maxSendableAmount = SwapKitNumber.fromBigInt(balance.getBaseValue('bigint')).sub( | ||
// fee.toString(), | ||
// ); | ||
// | ||
// return AssetValue.fromChainOrSignature(balance.chain, maxSendableAmount.getValue('string')); | ||
// }; | ||
export const addAccountsChangedCallback = (callback: () => void) => { | ||
@@ -299,9 +378,15 @@ window.ethereum?.on('accountsChanged', () => callback()); | ||
let tokenBalance = tokenBalances[i]; | ||
let formatedBalance = AssetValue.fromIdentifierSync( | ||
//@ts-ignore | ||
tokenBalance.chain + '.' + tokenBalance.symbol.toUpperCase(), | ||
tokenBalance.value, | ||
); | ||
// formatedBalance.address = address[0].address; | ||
balances.push(formatedBalance); | ||
if (tokenBalance.symbol && tokenBalance.chain && tokenBalance.chain === chain) { | ||
let formatedBalance = AssetValue.fromIdentifierSync( | ||
//@ts-ignore | ||
tokenBalance.chain + '.' + tokenBalance.symbol.toUpperCase(), | ||
tokenBalance.value, | ||
); | ||
// formatedBalance.address = address[0].address; | ||
balances.push(formatedBalance); | ||
} else { | ||
console.log('chain: ', chain); | ||
console.log('tokenBalance.chain: ', tokenBalance.chain); | ||
console.error('invalid balance: ', tokenBalance); | ||
} | ||
} | ||
@@ -308,0 +393,0 @@ // return filteredBalances; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 2 instances in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 2 instances in 1 package
860144
0.45%18301
0.55%3
50%