Skip to content

Commit

Permalink
fix: use transaction request data
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov committed Sep 10, 2024
1 parent b57a1b6 commit f18ccc4
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 83 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@
"@noble/hashes": "^1.5.0",
"@solana/wallet-adapter-base": "^0.9.23",
"@solana/web3.js": "^1.95.3",
"@swapkit/helpers": "1.8.0",
"@swapkit/tokens": "1.5.0",
"@swapkit/toolbox-utxo": "1.1.11",
"@swapkit/types": "1.0.0-rc.46",
"@swapkit/helpers": "1.0.0-rc.83",
"@swapkit/tokens": "1.0.0-rc.34",
"@swapkit/toolbox-utxo": "1.0.0-rc.91",
"@swapkit/types": "1.0.0-rc.47",
"bech32": "^2.0.0",
"bitcoinjs-lib": "^7.0.0-rc.0",
"bs58": "^6.0.0",
Expand Down
33 changes: 15 additions & 18 deletions src/core/UTXO/UTXOStepExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
type ExtendedTransactionInfo,
type FullStatusData,
} from '@lifi/types'
import { getToolboxByChain } from '@swapkit/toolbox-utxo'
import { address, networks, Psbt } from 'bitcoinjs-lib'
import { withRetry, withTimeout, type Client } from 'viem'
import { config } from '../../config.js'
Expand All @@ -24,8 +23,6 @@ import type {
TransactionParameters,
} from '../types.js'
import { waitForReceivingTransaction } from '../waitForReceivingTransaction.js'
import { blockchairApi } from './blockchairApi.js'
import { Chain } from './blockchairApiTypes.js'
import { getUTXOPublicClient } from './getUTXOPublicClient.js'
import { parseUTXOErrors } from './parseUTXOErrors.js'
import { signPsbt } from './utxo-stack/actions/signPsbt.js'
Expand Down Expand Up @@ -149,24 +146,24 @@ export class UTXOStepExecutor extends BaseStepExecutor {

this.checkClient(step)

const toolbox = getToolboxByChain('BTC')({})
// const toolbox = getToolboxByChain('BTC')({})

const apiClient = blockchairApi({ chain: Chain.Bitcoin })
const txFeeRate = await apiClient.getSuggestedTxFee()
// const apiClient = blockchairApi({ chain: Chain.Bitcoin })
// const txFeeRate = await apiClient.getSuggestedTxFee()

const tx = await toolbox.buildTx({
assetValue: {
bigIntValue: step.transactionRequest.value,
},
recipient: step.transactionRequest.to,
memo: step.transactionRequest.data,
sender: this.client.account?.address,
chain: 'BTC',
apiClient: blockchairApi({ chain: Chain.Bitcoin }),
feeRate: txFeeRate,
})
// const tx = await toolbox.buildTx({
// assetValue: {
// bigIntValue: step.transactionRequest.value,
// },
// recipient: step.transactionRequest.to,
// memo: step.transactionRequest.data,
// sender: this.client.account?.address,
// chain: 'BTC',
// apiClient: blockchairApi({ chain: Chain.Bitcoin }),
// feeRate: txFeeRate,
// })

let psbtHex = tx.psbt.toHex()
let psbtHex = transactionRequest.data // tx.psbt.toHex()

const psbt = Psbt.fromHex(psbtHex, { network: networks.bitcoin })

Expand Down
2 changes: 1 addition & 1 deletion src/utils/withDedupe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class LruMap<value = unknown> extends Map<string, value> {
override set(key: string, value: value) {
super.set(key, value)
if (this.maxSize && this.size > this.maxSize) {
this.delete(this.keys().next().value)
this.delete(this.keys().next().value!)
}
return this
}
Expand Down
166 changes: 106 additions & 60 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -731,10 +731,10 @@ __metadata:
"@noble/hashes": "npm:^1.5.0"
"@solana/wallet-adapter-base": "npm:^0.9.23"
"@solana/web3.js": "npm:^1.95.3"
"@swapkit/helpers": "npm:1.8.0"
"@swapkit/tokens": "npm:1.5.0"
"@swapkit/toolbox-utxo": "npm:1.1.11"
"@swapkit/types": "npm:1.0.0-rc.46"
"@swapkit/helpers": "npm:1.0.0-rc.83"
"@swapkit/tokens": "npm:1.0.0-rc.34"
"@swapkit/toolbox-utxo": "npm:1.0.0-rc.91"
"@swapkit/types": "npm:1.0.0-rc.47"
"@types/fs-extra": "npm:^11.0.4"
"@types/ws": "npm:^8.5.12"
"@typescript-eslint/eslint-plugin": "npm:^7.18.0"
Expand Down Expand Up @@ -807,6 +807,15 @@ __metadata:
languageName: node
linkType: hard

"@noble/curves@npm:~1.3.0":
version: 1.3.0
resolution: "@noble/curves@npm:1.3.0"
dependencies:
"@noble/hashes": "npm:1.3.3"
checksum: 10/f3cbdd1af00179e30146eac5539e6df290228fb857a7a8ba36d1a772cbe59288a2ca83d06f175d3446ef00db3a80d7fd8b8347f7de9c2d4d5bf3865d8bb78252
languageName: node
linkType: hard

"@noble/curves@npm:~1.4.0":
version: 1.4.2
resolution: "@noble/curves@npm:1.4.2"
Expand All @@ -816,6 +825,13 @@ __metadata:
languageName: node
linkType: hard

"@noble/hashes@npm:1.3.3, @noble/hashes@npm:~1.3.2":
version: 1.3.3
resolution: "@noble/hashes@npm:1.3.3"
checksum: 10/1025ddde4d24630e95c0818e63d2d54ee131b980fe113312d17ed7468bc18f54486ac86c907685759f8a7e13c2f9b9e83ec7b67d1cc20836f36b5e4a65bb102d
languageName: node
linkType: hard

"@noble/hashes@npm:1.4.0, @noble/hashes@npm:~1.4.0":
version: 1.4.0
resolution: "@noble/hashes@npm:1.4.0"
Expand Down Expand Up @@ -1075,13 +1091,24 @@ __metadata:
languageName: node
linkType: hard

"@scure/base@npm:~1.1.6, @scure/base@npm:~1.1.8":
"@scure/base@npm:~1.1.4, @scure/base@npm:~1.1.6, @scure/base@npm:~1.1.8":
version: 1.1.8
resolution: "@scure/base@npm:1.1.8"
checksum: 10/5b764c0e98610bc4993479965db718457d91b68d3c6f1339e3cc74e53fc6b0ae0428d1d64d29a0de0cee9d966034674d4464fdbd2d1dbef27013927b2fe05c45
languageName: node
linkType: hard

"@scure/bip32@npm:1.3.3":
version: 1.3.3
resolution: "@scure/bip32@npm:1.3.3"
dependencies:
"@noble/curves": "npm:~1.3.0"
"@noble/hashes": "npm:~1.3.2"
"@scure/base": "npm:~1.1.4"
checksum: 10/4b8b75567866ff7d6b3ba154538add02d2951e9433e8dd7f0014331ac500cda5a88fe3d39b408fcc36e86b633682013f172b967af022c2e4e4ab07336801d688
languageName: node
linkType: hard

"@scure/bip32@npm:1.4.0":
version: 1.4.0
resolution: "@scure/bip32@npm:1.4.0"
Expand All @@ -1093,13 +1120,13 @@ __metadata:
languageName: node
linkType: hard

"@scure/bip39@npm:1.3.0":
version: 1.3.0
resolution: "@scure/bip39@npm:1.3.0"
"@scure/bip39@npm:1.2.2":
version: 1.2.2
resolution: "@scure/bip39@npm:1.2.2"
dependencies:
"@noble/hashes": "npm:~1.4.0"
"@scure/base": "npm:~1.1.6"
checksum: 10/7d71fd58153de22fe8cd65b525f6958a80487bc9d0fbc32c71c328aeafe41fa259f989d2f1e0fa4fdfeaf83b8fcf9310d52ed9862987e46c2f2bfb9dd8cf9fc1
"@noble/hashes": "npm:~1.3.2"
"@scure/base": "npm:~1.1.4"
checksum: 10/f71aceda10a7937bf3779fd2b4c4156c95ec9813269470ddca464cb8ab610d2451b173037f4b1e6dac45414e406e7adc7b5814c51279f4474d5d38140bbee542
languageName: node
linkType: hard

Expand Down Expand Up @@ -1169,53 +1196,72 @@ __metadata:
languageName: node
linkType: hard

"@swapkit/contracts@npm:1.0.4":
version: 1.0.4
resolution: "@swapkit/contracts@npm:1.0.4"
checksum: 10/a2689a05b6f47f2e31064ea618bfad5ea71b41e9ab502228254e0db75c2a6477e2f144df097fd760d7589b581c6fe8dfba9bc5a87880f283297db09c4c44733a
"@swapkit/api@npm:1.0.0-rc.48":
version: 1.0.0-rc.48
resolution: "@swapkit/api@npm:1.0.0-rc.48"
dependencies:
"@swapkit/types": "npm:1.0.0-rc.47"
ky: "npm:1.2.2"
peerDependencies:
"@swapkit/types": 1.0.0-rc.47
ky: ^1.2.2
checksum: 10/61033e6009aff852075adbc8b4e9ea2a78656b686a88d6ae263824519c49358fe1eb14b6c0f9fe7e7a9490c4130a545dde70b4fdeb595caa5c39b0de1c306038
languageName: node
linkType: hard

"@swapkit/helpers@npm:1.8.0":
version: 1.8.0
resolution: "@swapkit/helpers@npm:1.8.0"
"@swapkit/helpers@npm:1.0.0-rc.83":
version: 1.0.0-rc.83
resolution: "@swapkit/helpers@npm:1.0.0-rc.83"
dependencies:
"@swapkit/contracts": "npm:1.0.4"
"@swapkit/tokens": "npm:1.5.0"
picocolors: "npm:1.0.1"
checksum: 10/b6c90312b33731d56b0112d1258315fd4b6673717727b75b60e4c1104b44fe1b7fbb9dfd7bb48c2b27b0df77959338ac90d41de0b31715b142502f6def7d0c41
"@swapkit/api": "npm:1.0.0-rc.48"
peerDependencies:
"@swapkit/api": 1.0.0-rc.48
"@swapkit/tokens": 1.0.0-rc.44
"@swapkit/types": 1.0.0-rc.47
checksum: 10/b194de232f150d8688b1931b17b8a332e12282ea336e2be252a77d981e975c7e315253702ea444b666c6bbf9b160d9788e6850f53f9c05eaf543eb8864b78c00
languageName: node
linkType: hard

"@swapkit/tokens@npm:1.5.0":
version: 1.5.0
resolution: "@swapkit/tokens@npm:1.5.0"
checksum: 10/800b5abfd55927b0e344b9c9fcdc952b5d6e4fff90062c3618061a2d19d13782bf2e389f5377857350a0affa8e9870a50b58605ffe3059f31235aebb6999ff4c
"@swapkit/tokens@npm:1.0.0-rc.34":
version: 1.0.0-rc.34
resolution: "@swapkit/tokens@npm:1.0.0-rc.34"
checksum: 10/928be5be7ffbdb47365fffe207320becd3ab4b2179fa81ce0c8fdbd06ddb4e1f5c49d1c361949dccce73798718394d91aada2d348e000de71da4334c59a66d32
languageName: node
linkType: hard

"@swapkit/toolbox-utxo@npm:1.1.11":
version: 1.1.11
resolution: "@swapkit/toolbox-utxo@npm:1.1.11"
"@swapkit/toolbox-utxo@npm:1.0.0-rc.91":
version: 1.0.0-rc.91
resolution: "@swapkit/toolbox-utxo@npm:1.0.0-rc.91"
dependencies:
"@bitcoinerlab/secp256k1": "npm:1.1.1"
"@psf/bitcoincashjs-lib": "npm:4.0.3"
"@scure/bip32": "npm:1.4.0"
"@scure/bip39": "npm:1.3.0"
"@swapkit/helpers": "npm:1.8.0"
bitcoinjs-lib: "npm:6.1.6"
bs58check: "npm:4.0.0"
"@scure/bip32": "npm:1.3.3"
"@scure/bip39": "npm:1.2.2"
bitcoinjs-lib: "npm:6.1.5"
bs58check: "npm:3.0.1"
cashaddrjs: "npm:0.4.4"
coininfo: "npm:5.2.1"
ecpair: "npm:2.1.0"
checksum: 10/527170aa6b7fce3adb1d1a1219f94c1688cbce8a33ed6987bc53e6eb1029d57aa35ca92fbd69d77b34d818ff563dac0a94d5a25af5b9e4831da59f2a21657552
peerDependencies:
"@bitcoinerlab/secp256k1": 1.1.1
"@psf/bitcoincashjs-lib": 4.0.3
"@scure/bip32": 1.3.3
"@scure/bip39": 1.2.2
"@swapkit/helpers": 1.0.0-rc.83
"@swapkit/types": 1.0.0-rc.47
bitcoinjs-lib: 6.1.5
bs58check: 3.0.1
cashaddrjs: 0.4.4
coininfo: 5.2.1
ecpair: 2.1.0
checksum: 10/a7c36fcaeb1d033743c51de8febf2193aab3dc87f3f5f53c917a01c4bd8e6b65899606db309322ebadc1aedd8703e24fc1a6552eea5ae575b4b08eb2ee6faf9c
languageName: node
linkType: hard

"@swapkit/types@npm:1.0.0-rc.46":
version: 1.0.0-rc.46
resolution: "@swapkit/types@npm:1.0.0-rc.46"
checksum: 10/945073a7e610dcdad60851721f4dc28196f77b47b3640d6463b6ef0a335d60cfa758b9132f2601012b25dd19479a598e65a6f6349b55af16ae2774154328f603
"@swapkit/types@npm:1.0.0-rc.47":
version: 1.0.0-rc.47
resolution: "@swapkit/types@npm:1.0.0-rc.47"
checksum: 10/9bab31837b3dfd024813a76dcac532db6a5bc4d7f339691086def68aca3972e229c438ae62e04f18acb546f2e5853c516c99a7274ab5961c32322783e91bedfe
languageName: node
linkType: hard

Expand Down Expand Up @@ -2077,17 +2123,17 @@ __metadata:
languageName: node
linkType: hard

"bitcoinjs-lib@npm:6.1.6":
version: 6.1.6
resolution: "bitcoinjs-lib@npm:6.1.6"
"bitcoinjs-lib@npm:6.1.5":
version: 6.1.5
resolution: "bitcoinjs-lib@npm:6.1.5"
dependencies:
"@noble/hashes": "npm:^1.2.0"
bech32: "npm:^2.0.0"
bip174: "npm:^2.1.1"
bs58check: "npm:^3.0.1"
typeforce: "npm:^1.11.3"
varuint-bitcoin: "npm:^1.1.2"
checksum: 10/18057362e92756aacb3fdbb996beddb134406a998515fdab86d221a96fb203a9345e4c25e8151a788df169eae0cbb271c467d5669f40f2bc9fce487721061928
checksum: 10/9a4dc588cb989173e8631180078c141c7ca0456865490c2c1f052e86e87b92954556a10f516371a9d96bd294433c245961dba2ff8b1d70327c22a555dd201767
languageName: node
linkType: hard

Expand Down Expand Up @@ -2190,13 +2236,13 @@ __metadata:
languageName: node
linkType: hard

"bs58check@npm:4.0.0, bs58check@npm:^4.0.0":
version: 4.0.0
resolution: "bs58check@npm:4.0.0"
"bs58check@npm:3.0.1, bs58check@npm:^3.0.1":
version: 3.0.1
resolution: "bs58check@npm:3.0.1"
dependencies:
"@noble/hashes": "npm:^1.2.0"
bs58: "npm:^6.0.0"
checksum: 10/cf5691bdfdf317574f722582360a834f01a36e8f6c850bd5791f04e040b334a0800b7c322ad24c77979c3ed6ef6cf31a6373366b4018223e3005278d491d8799
bs58: "npm:^5.0.0"
checksum: 10/dbbecc7a09f3836e821149266c864c4bbd545539cea43c35f23f4c3c46b54c86c52b65d224b9ea2e916fa6d93bd2ce9fac5b6c6bfcf19621a9c209a5602f71c8
languageName: node
linkType: hard

Expand All @@ -2211,13 +2257,13 @@ __metadata:
languageName: node
linkType: hard

"bs58check@npm:^3.0.1":
version: 3.0.1
resolution: "bs58check@npm:3.0.1"
"bs58check@npm:^4.0.0":
version: 4.0.0
resolution: "bs58check@npm:4.0.0"
dependencies:
"@noble/hashes": "npm:^1.2.0"
bs58: "npm:^5.0.0"
checksum: 10/dbbecc7a09f3836e821149266c864c4bbd545539cea43c35f23f4c3c46b54c86c52b65d224b9ea2e916fa6d93bd2ce9fac5b6c6bfcf19621a9c209a5602f71c8
bs58: "npm:^6.0.0"
checksum: 10/cf5691bdfdf317574f722582360a834f01a36e8f6c850bd5791f04e040b334a0800b7c322ad24c77979c3ed6ef6cf31a6373366b4018223e3005278d491d8799
languageName: node
linkType: hard

Expand Down Expand Up @@ -4797,6 +4843,13 @@ __metadata:
languageName: node
linkType: hard

"ky@npm:1.2.2":
version: 1.2.2
resolution: "ky@npm:1.2.2"
checksum: 10/02705df3b6796bd75af64511df0e7d6a5a5e8af6cd6e726f91aee8ae3cb7cf5fa9dc35bd22f12a557d09d102167f8308cc02a95ddbcc71f08c410620ffe46ef9
languageName: node
linkType: hard

"levn@npm:^0.4.1":
version: 0.4.1
resolution: "levn@npm:0.4.1"
Expand Down Expand Up @@ -5897,13 +5950,6 @@ __metadata:
languageName: node
linkType: hard

"picocolors@npm:1.0.1":
version: 1.0.1
resolution: "picocolors@npm:1.0.1"
checksum: 10/fa68166d1f56009fc02a34cdfd112b0dd3cf1ef57667ac57281f714065558c01828cdf4f18600ad6851cbe0093952ed0660b1e0156bddf2184b6aaf5817553a5
languageName: node
linkType: hard

"picocolors@npm:^1.0.0, picocolors@npm:^1.0.1":
version: 1.1.0
resolution: "picocolors@npm:1.1.0"
Expand Down

0 comments on commit f18ccc4

Please sign in to comment.