@coinmasters/toolbox-utxo
Advanced tools
Comparing version 9.0.9 to 10.0.0
@@ -82,2 +82,3 @@ /// <reference types="node" /> | ||
createKeysForPath: (params: any) => Promise<ECPairInterface>; | ||
getInputsForPubkey: (pubkey: string) => Promise<any>; | ||
getPrivateKeyFromMnemonic: ({ phrase, derivationPath, }: { | ||
@@ -84,0 +85,0 @@ phrase: string; |
@@ -1,2 +0,2 @@ | ||
import { n as e, o as t, B as T, D as i, p as l, I as p, L as u, M as r, O as x, w as S, T as E, U as O, Z as b, u as d, y as c, v as g, t as n, z, C as A, A as C, x as D, G as H, q as m, E as B, H as R, F as _ } from "./index-9dbccddf.js"; | ||
import { n as e, o as t, B as T, D as i, p as l, I as p, L as u, M as r, O as x, w as S, T as E, U as O, Z as b, u as d, y as c, v as g, t as n, z, C as A, A as C, x as D, G as H, q as m, E as B, H as R, F as _ } from "./index-fdaf8008.js"; | ||
import "@coinmasters/helpers"; | ||
@@ -3,0 +3,0 @@ export { |
{ | ||
"author": "swapkit-oss-team", | ||
"dependencies": { | ||
"@pioneer-platform/pioneer-coins": "latest", | ||
"@psf/bitcoincashjs-lib": "4.0.3", | ||
@@ -14,3 +13,3 @@ "@scure/bip32": "1.3.2", | ||
"tiny-secp256k1": "1.1.6", | ||
"@coinmasters/types": "4.5.0" | ||
"@coinmasters/types": "4.6.0" | ||
}, | ||
@@ -26,4 +25,4 @@ "description": "THORSwap utxo", | ||
"vitest": "0.34.6", | ||
"@coinmasters/helpers": "9.0.9", | ||
"@internal/config": "2.5.0" | ||
"@internal/config": "2.6.0", | ||
"@coinmasters/helpers": "10.0.0" | ||
}, | ||
@@ -45,3 +44,3 @@ "eslintConfig": { | ||
"peerDependencies": { | ||
"@coinmasters/helpers": "9.0.9" | ||
"@coinmasters/helpers": "10.0.0" | ||
}, | ||
@@ -60,3 +59,3 @@ "homepage": "https://github.com/thorswap/SwapKit", | ||
"types": "./dist/index.d.ts", | ||
"version": "9.0.9", | ||
"version": "10.0.0", | ||
"scripts": { | ||
@@ -63,0 +62,0 @@ "build": "vite build", |
@@ -124,2 +124,3 @@ import { RequestClient } from '@coinmasters/helpers'; | ||
console.log('pubkey: ', pubkey); | ||
console.log('chain: ', chain); | ||
const url = `/utxo/getBalance/${chain}/${pubkey}`; | ||
@@ -129,7 +130,5 @@ //console.log('getXpubData URL: ', url); | ||
let response = await RequestClient.get<any>(`${baseUrlPioneer()}${url}`); | ||
//console.log('getXpubData: response: ', response); | ||
console.log('getXpubData: response: ', response); | ||
if (!response) { | ||
response = 0; | ||
} else { | ||
response = response / 100000000; | ||
} | ||
@@ -136,0 +135,0 @@ return response; |
@@ -57,3 +57,3 @@ import { AssetValue, SwapKitNumber } from '@coinmasters/helpers'; | ||
try { | ||
console.log(chain + ' validateAddress: ', address); | ||
//console.log(chain + ' validateAddress: ', address); | ||
//@TODO validate addresses! | ||
@@ -111,3 +111,3 @@ //btcLibAddress.toOutputScript(address, getNetwork(chain)); | ||
try { | ||
console.log('getPubkeyBalance pubkey: ', pubkey); | ||
//console.log('getPubkeyBalance pubkey: ', pubkey); | ||
//console.log('getPubkeyBalance type: ', type); | ||
@@ -123,3 +123,3 @@ switch (type) { | ||
); | ||
console.log(' | getPubkeyBalance | xpubBalance: ', xpubBalance); | ||
//console.log(' | getPubkeyBalance | xpubBalance: ', xpubBalance); | ||
return xpubBalance; | ||
@@ -143,3 +143,3 @@ case 'address': | ||
const getBalance = async ({ pubkeys, chain, apiClient }: { pubkeys: any[] } & any) => { | ||
console.log('getBalance pubkeys: ', pubkeys); | ||
//console.log('getBalance pubkeys: ', pubkeys); | ||
//legacy support | ||
@@ -156,12 +156,13 @@ if (typeof pubkeys === 'string') { | ||
type = 'pubkey'; | ||
console.log('pubkey: ', pubkey.pubkey); | ||
//console.log('pubkey: ', pubkey.pubkey); | ||
} else { | ||
type = 'address'; | ||
} | ||
console.log('type: ', type); | ||
//console.log('type: ', type); | ||
let balance = await getPubkeyBalance(pubkey, type, apiClient); | ||
if (typeof balance === 'object') balance = 0; | ||
console.log('BaseUTXO getPubkeyBalance balance: ', balance); | ||
//console.log('BaseUTXO getPubkeyBalance balance: ', balance); | ||
totalBalance = totalBalance + balance; | ||
} | ||
totalBalance = totalBalance / 100000000; | ||
//console.log(`BaseUTXO totalBalance:`, totalBalance); | ||
@@ -201,2 +202,3 @@ const asset = await AssetValue.fromChainOrSignature(chain, totalBalance); | ||
path, | ||
scriptType, | ||
hex: txHex, | ||
@@ -214,2 +216,3 @@ tx, | ||
height, | ||
scriptType, | ||
confirmations, | ||
@@ -248,48 +251,84 @@ path, | ||
//get inputs by xpub | ||
console.log('pubkeys: ', pubkeys); | ||
//console.log('pubkeys: ', pubkeys); | ||
//get balances for each pubkey | ||
for (let i = 0; i < pubkeys.length; i++) { | ||
let pubkey = pubkeys[i]; | ||
console.log('1 pubkey: ', pubkey); | ||
console.log('2 pubkey: ', pubkey.pubkey); | ||
let balance = await apiClient.getBalanceXpub(pubkey.pubkey || pubkey.xpub || pubkey); | ||
console.log('balance: ', balance); | ||
pubkeys[i].balance = balance.toString(); | ||
} | ||
//console.log('pubkeys: ', pubkeys); | ||
// for (let i = 0; i < pubkeys.length; i++) { | ||
// let pubkey = pubkeys[i]; | ||
// //console.log('1 pubkey: ', pubkey); | ||
// //console.log('2 pubkey: ', pubkey.pubkey); | ||
// let balance = await apiClient.getBalanceXpub(pubkey.pubkey || pubkey.xpub || pubkey); | ||
// //console.log('balance: ', balance); | ||
// pubkeys[i].balance = balance.toString(); | ||
// } | ||
// //console.log('pubkeys: ', pubkeys); | ||
// | ||
// // select a single pubkey | ||
// // choose largest balance | ||
// let largestBalance = -Infinity; // Initialize with a very small value | ||
// let pubkeyWithLargestBalance = null; // Initialize as null | ||
// | ||
// // eslint-disable-next-line @typescript-eslint/prefer-for-of | ||
// for (let i = 0; i < pubkeys.length; i++) { | ||
// const pubkey = pubkeys[i]; | ||
// const balance = parseFloat(pubkey.balance); | ||
// | ||
// if (!isNaN(balance) && balance > largestBalance) { | ||
// largestBalance = balance; | ||
// pubkeyWithLargestBalance = pubkey; | ||
// } | ||
// } | ||
// | ||
// //console.log('The pubkey with the highest balance is:', pubkeyWithLargestBalance); | ||
// | ||
// // pubkeyWithLargestBalance | ||
// //console.log('pubkeyWithLargestBalance: ', pubkeyWithLargestBalance); | ||
// let inputs = await apiClient.listUnspent({ | ||
// pubkey: | ||
// pubkeyWithLargestBalance?.pubkey || | ||
// pubkeyWithLargestBalance?.xpub || | ||
// pubkeyWithLargestBalance, | ||
// chain, | ||
// apiKey: apiClient.apiKey, | ||
// }); | ||
// //console.log('inputs total: ', inputs); | ||
// //console.log('inputs total: ', inputs.length); | ||
// select a single pubkey | ||
// choose largest balance | ||
let largestBalance = -Infinity; // Initialize with a very small value | ||
let pubkeyWithLargestBalance = null; // Initialize as null | ||
let allInputs: any[] = []; | ||
// eslint-disable-next-line @typescript-eslint/prefer-for-of | ||
for (let i = 0; i < pubkeys.length; i++) { | ||
const pubkey = pubkeys[i]; | ||
const balance = parseFloat(pubkey.balance); | ||
const pubkeyInfo = pubkeys[i]; | ||
const pubkey = pubkeyInfo.pubkey || pubkeyInfo.xpub || pubkeyInfo; | ||
if (!isNaN(balance) && balance > largestBalance) { | ||
largestBalance = balance; | ||
pubkeyWithLargestBalance = pubkey; | ||
// Assuming getBalance is a method of apiClient that returns a Promise<number> | ||
const balance: number = await apiClient.getBalanceXpub(pubkey.pubkey || pubkey.xpub || pubkey); | ||
if (balance > 0) { | ||
// Assuming listUnspent returns a Promise of an array | ||
// @ts-ignore | ||
let inputs = await apiClient.listUnspent({ | ||
pubkey: pubkey.pubkey || pubkey.xpub || pubkey, | ||
chain, | ||
apiKey: apiClient.apiKey, | ||
}); | ||
//console.log('getInputsAndTargetOutputs: pubkeyInfo: ', pubkeyInfo); | ||
//console.log('getInputsAndTargetOutputs: inputs: ', inputs); | ||
//add scriptType | ||
inputs = inputs.map((input) => { | ||
input.scriptType = pubkeyInfo.script_type; | ||
return input; | ||
}); | ||
//console.log('getInputsAndTargetOutputs: inputs: POST: ', inputs); | ||
if (inputs && inputs.length > 0) { | ||
allInputs = [...allInputs, ...inputs]; | ||
} | ||
} | ||
} | ||
//console.log('The pubkey with the highest balance is:', pubkeyWithLargestBalance); | ||
//console.log('Aggregated inputs total: ', allInputs.length); | ||
//console.log('Aggregated inputs: ', allInputs); | ||
// pubkeyWithLargestBalance | ||
console.log('pubkeyWithLargestBalance: ', pubkeyWithLargestBalance); | ||
let inputs = await apiClient.listUnspent({ | ||
pubkey: | ||
pubkeyWithLargestBalance?.pubkey || | ||
pubkeyWithLargestBalance?.xpub || | ||
pubkeyWithLargestBalance, | ||
chain, | ||
apiKey: apiClient.apiKey, | ||
}); | ||
console.log('inputs total: ', inputs); | ||
console.log('inputs total: ', inputs.length); | ||
console.log('inputs: ', inputs); | ||
//console.log('allInputs: ', allInputs); | ||
//Use the map function to transform each input | ||
inputs = inputs.map(transformInput); | ||
let inputs = allInputs.map(transformInput); | ||
//console.log('inputs: ', inputs); | ||
@@ -338,4 +377,4 @@ // //console.log('sender: ', sender); | ||
console.log('Checkpoint buildTx'); | ||
console.log('pubkeys: ', pubkeys); | ||
//console.log('Checkpoint buildTx'); | ||
//console.log('pubkeys: ', pubkeys); | ||
@@ -355,5 +394,5 @@ const inputsAndOutputs = await getInputsAndTargetOutputs({ | ||
if (chain === Chain.BitcoinCash) feeRate = 100; | ||
console.log('inputsAndOutputs: ', inputsAndOutputs); | ||
// console.log('coinSelect: ', coinSelect); | ||
console.log('feeRate: ', feeRate); | ||
//console.log('inputsAndOutputs: ', inputsAndOutputs); | ||
//console.log('coinSelect: ', coinSelect); | ||
//console.log('feeRate: ', feeRate); | ||
@@ -364,3 +403,3 @@ // Assuming inputsAndOutputs, feeRate, and isMax are defined elsewhere in your code | ||
if (isMax) { | ||
console.log('isMax: detected!'); | ||
//console.log('isMax: detected!'); | ||
inputsAndOutputs.outputs = inputsAndOutputs.outputs | ||
@@ -373,3 +412,3 @@ .filter((output) => output.address !== undefined) | ||
}); | ||
console.log('inputsAndOutputs: ', inputsAndOutputs); | ||
//console.log('inputsAndOutputs: ', inputsAndOutputs); | ||
({ inputs, outputs } = split.default( | ||
@@ -381,3 +420,3 @@ inputsAndOutputs.inputs, | ||
} else { | ||
console.log('isMax: not detected!'); | ||
//console.log('isMax: not detected!'); | ||
//const { inputs, outputs } = accumulative({ ...inputsAndOutputs, feeRate, chain }); | ||
@@ -393,4 +432,4 @@ //({ inputs, outputs } = accumulative({ ...inputsAndOutputs, feeRate, chain })); | ||
console.log('inputs: ', inputs); | ||
console.log('outputs: ', outputs); | ||
//console.log('inputs: ', inputs); | ||
//console.log('outputs: ', outputs); | ||
@@ -425,3 +464,4 @@ // .inputs and .outputs will be undefined if no solution was found | ||
console.log('buildTx Checkpoint 1.5:'); | ||
console.log('inputOptions: ',inputOptions); | ||
console.log('inputOptions: ', inputOptions); | ||
console.log('inputOptions: ', JSON.stringify(inputOptions)); | ||
psbt.addInput(inputOptions); | ||
@@ -485,2 +525,3 @@ console.log(' buildTx Checkpoint 2:'); | ||
const inputsAndOutputs = await getInputsAndTargetOutputs({ | ||
pubkeys, | ||
assetValue, | ||
@@ -492,3 +533,3 @@ recipient, | ||
apiClient, | ||
chain, | ||
chain | ||
}); | ||
@@ -501,2 +542,12 @@ | ||
export const getInputsForPubkey = async function (pubkey: string, chain: Chain, apiKey: any) { | ||
try { | ||
const utxos = await apiClient.listUnspent({ pubkey, chain, apiKey }); | ||
return utxos.map(transformInput); | ||
} catch (e) { | ||
console.error('Error getting inputs for pubkey', pubkey, e); | ||
throw e; | ||
} | ||
}; | ||
export const estimateMaxSendableAmount = async ({ | ||
@@ -570,129 +621,5 @@ pubkeys, | ||
return AssetValue.fromChainOrSignature(chain, maxSendableValue); | ||
return AssetValue.fromChainOrSignature(chain, maxSendableValue / 100000000); | ||
}; | ||
// export const estimateMaxSendableAmount = async ({ | ||
// pubkeys, | ||
// feeRate, | ||
// feeOptionKey = FeeOption.Fast, | ||
// recipient, | ||
// memo, | ||
// chain, | ||
// apiClient, | ||
// }: { | ||
// pubkeys: any[]; | ||
// feeRate?: number; | ||
// feeOptionKey?: FeeOption; | ||
// recipient: string; | ||
// memo?: string; | ||
// chain: Chain; | ||
// apiClient: any; | ||
// }): Promise<AssetValue> => { | ||
// console.log('pubkeys: ', pubkeys); | ||
// // Fetch the actual UTXOs for the provided pubkeys | ||
// let utxos = []; | ||
// for (let pubkey of pubkeys) { | ||
// const utxoSet = await apiClient.listUnspent({ | ||
// pubkey: pubkey.pubkey || pubkey.xpub || pubkey, | ||
// chain, | ||
// apiKey: apiClient.apiKey, | ||
// }); | ||
// console.log('utxoSet: ', utxoSet); | ||
// // Assuming transformInput is a function that formats each UTXO correctly | ||
// utxos = utxos.concat(utxoSet.map(transformInput)); | ||
// } | ||
// if(utxos.length === 0) throw new Error('No UTXOs found for the provided pubkeys'); | ||
// | ||
// // Calculate the total available balance from the UTXOs | ||
// const totalInputValue = utxos.reduce((acc, utxo) => acc + utxo.value, 0); | ||
// console.log('totalInputValue: ', totalInputValue); | ||
// | ||
// // Determine the effective fee rate | ||
// // const effectiveFeeRate = feeRate | ||
// // ? Math.ceil(feeRate) | ||
// // : (await getFeeRates(apiClient))[feeOptionKey]; | ||
// let effectiveFeeRate = getDefaultTxFeeByChain(chain); | ||
// console.log('totalInputValue: ', totalInputValue); | ||
// | ||
// | ||
// // Estimate the size of the transaction. Assuming 148 bytes per input and 34 bytes per output, plus 10 bytes overhead | ||
// const estimatedTxSize = utxos.length * 148 + 2 * 34 + 10; // Adjust based on your actual needs | ||
// | ||
// // Calculate the estimated fee for the transaction | ||
// const estimatedFee = estimatedTxSize * effectiveFeeRate; | ||
// | ||
// // Calculate the maximum sendable amount by subtracting the estimated fee from the total UTXO balance | ||
// const maxSendableValue = totalInputValue - estimatedFee; | ||
// | ||
// // Ensure maxSendableValue is not negative | ||
// if (maxSendableValue < 0) { | ||
// throw new Error('Insufficient funds for transaction after accounting for fees'); | ||
// } | ||
// | ||
// // Return the maximum sendable amount as an AssetValue | ||
// return AssetValue.fromChainOrSignature(chain, maxSendableValue); | ||
// }; | ||
// export const estimateMaxSendableAmount = async ({ | ||
// pubkeys, | ||
// feeRate, | ||
// feeOptionKey = FeeOption.Fast, | ||
// recipient, | ||
// memo, | ||
// chain, | ||
// apiClient, | ||
// }: { | ||
// pubkeys: any[]; | ||
// feeRate?: number; | ||
// feeOptionKey?: FeeOption; | ||
// recipient: string; | ||
// memo?: string; | ||
// chain: Chain; | ||
// apiClient: any; | ||
// }): Promise<AssetValue> => { | ||
// console.log('pubkeys: ', pubkeys); | ||
// | ||
// | ||
// const effectiveFeeRate = feeRate | ||
// ? Math.ceil(feeRate) | ||
// : (await getFeeRates(apiClient))[feeOptionKey]; | ||
// | ||
// console.log('effectiveFeeRate: ', effectiveFeeRate); | ||
// | ||
// // Simulate transaction to estimate size and fee | ||
// // Placeholder values for inputs and outputs since actual implementation may vary | ||
// const txSizeEstimation = calculateTxSize({ | ||
// inputs: [], // This would be based on actual UTXO selection logic | ||
// outputs: [ | ||
// { address: recipient, value: 0 }, // Placeholder, actual calculation needed | ||
// ...(memo ? [{ address: recipient, script: compileMemo(memo), value: 0 }] : []), | ||
// ], | ||
// feeRate: effectiveFeeRate, | ||
// }); | ||
// | ||
// console.log('txSizeEstimation: ', txSizeEstimation); | ||
// const fee = AssetValue.fromChainOrSignature( | ||
// chain, | ||
// (txSizeEstimation * effectiveFeeRate) / 10000000, | ||
// ); | ||
// | ||
// console.log('fee: ', fee); | ||
// console.log('totalBalance: ', totalBalance); | ||
// | ||
// console.log('fee: ', fee.toString()); | ||
// console.log('totalBalance: ', totalBalance.toString()); | ||
// | ||
// console.log('fee: ', fee.getValue('string')); | ||
// console.log('totalBalance: ', totalBalance[0].getValue('string')); | ||
// | ||
// // Adjusting for correct subtraction of BigInt values | ||
// const maxSendableValue = totalBalance[0].getValue('string') - fee.getValue('string'); | ||
// console.log('maxSendableValue: ', maxSendableValue); | ||
// | ||
// // Ensure the AssetValue is constructed correctly with bigIntValue | ||
// const maxSendableAmount = AssetValue.fromChainOrSignature(chain, maxSendableValue); | ||
// | ||
// return maxSendableAmount; | ||
// }; | ||
export const BaseUTXOToolbox = ( | ||
@@ -710,3 +637,3 @@ baseToolboxParams: UTXOBaseToolboxParams & { broadcastTx: (txHex: string) => Promise<string> }, | ||
createKeysForPath: (params: any) => createKeysForPath({ ...params, ...baseToolboxParams }), | ||
getInputsForPubkey: (pubkey: string) => getInputsForPubkey(pubkey, baseToolboxParams.chain, baseToolboxParams.apiClient), | ||
getPrivateKeyFromMnemonic: async ({ | ||
@@ -713,0 +640,0 @@ phrase, |
@@ -193,2 +193,3 @@ import type { UTXOChain } from '@coinmasters/types'; | ||
}); | ||
//console.log("inputs total: ",utxos) | ||
@@ -195,0 +196,0 @@ //console.log("inputs total: ",utxos.length) |
@@ -21,3 +21,3 @@ import { Chain, RPCUrl } from '@coinmasters/types'; | ||
broadcastTx: (txHash: string) => broadcastUTXOTx({ txHash, rpcUrl }), | ||
apiClient: apiClient || blockchairApi({ apiKey, chain: Chain.Dash }), | ||
apiClient: apiClient || blockchairApi({ apiKey, chain: Chain.Zcash }), | ||
}); |
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 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 1 instance in 1 package
11
2056927
44131
7
+ Added@coinmasters/helpers@10.0.0(transitive)
+ Added@coinmasters/tokens@3.6.0(transitive)
+ Added@coinmasters/types@4.6.0(transitive)
- Removed@coinmasters/helpers@9.0.9(transitive)
- Removed@coinmasters/tokens@3.5.9(transitive)
- Removed@coinmasters/types@4.5.0(transitive)
- Removed@cspotcode/source-map-support@0.8.1(transitive)
- Removed@jridgewell/resolve-uri@3.1.2(transitive)
- Removed@jridgewell/sourcemap-codec@1.5.0(transitive)
- Removed@jridgewell/trace-mapping@0.3.9(transitive)
- Removed@pioneer-platform/loggerdog@8.3.1(transitive)
- Removed@pioneer-platform/pioneer-coins@9.2.26(transitive)
- Removed@tsconfig/node10@1.0.11(transitive)
- Removed@tsconfig/node12@1.0.11(transitive)
- Removed@tsconfig/node14@1.0.3(transitive)
- Removed@tsconfig/node16@1.0.4(transitive)
- Removed@types/node@22.13.5(transitive)
- Removedacorn@8.14.0(transitive)
- Removedacorn-walk@8.3.4(transitive)
- Removedarg@4.1.3(transitive)
- Removedbignumber.js@9.1.2(transitive)
- Removedcreate-require@1.1.1(transitive)
- Removeddiff@4.0.2(transitive)
- Removedmake-error@1.3.6(transitive)
- Removedos@0.1.2(transitive)
- Removedts-node@10.9.2(transitive)
- Removedtypescript@5.7.3(transitive)
- Removedundici-types@6.20.0(transitive)
- Removedv8-compile-cache-lib@3.0.1(transitive)
- Removedyn@3.1.1(transitive)
Updated@coinmasters/types@4.6.0