From 28bace8d21c5477be262a2edb63dac5b2167e091 Mon Sep 17 00:00:00 2001 From: Nishant Ghodke Date: Tue, 3 Oct 2023 20:57:10 +0530 Subject: [PATCH] refactor: set `~` as root and update all imports --- packages/sdk/src/addresses/index.ts | 5 ++- .../src/browser-wallets/metamask/addresses.ts | 6 ++- .../browser-wallets/metamask/signatures.ts | 5 ++- .../src/browser-wallets/unisat/addresses.ts | 5 ++- .../src/browser-wallets/xverse/addresses.ts | 5 ++- .../src/browser-wallets/xverse/signatures.ts | 5 ++- packages/sdk/src/config/index.ts | 4 -- packages/sdk/src/constants/index.ts | 4 ++ packages/sdk/src/fee/FeeEstimator.ts | 10 +++-- packages/sdk/src/fee/types.ts | 2 +- packages/sdk/src/index.ts | 1 + .../{transactions => inscriber}/Inscriber.ts | 38 ++++--------------- packages/sdk/src/inscriber/index.ts | 2 + packages/sdk/src/inscriber/types.ts | 21 ++++++++++ packages/sdk/src/inscription/collection.ts | 13 +++++-- .../src/instant-trade/InstantTradeBuilder.ts | 9 +++-- .../InstantTradeBuyerTxBuilder.ts | 11 +++--- .../InstantTradeSellerTxBuilder.ts | 11 +++--- packages/sdk/src/instant-trade/index.ts | 6 +-- packages/sdk/src/instant-trade/types.ts | 2 +- packages/sdk/src/keys/index.ts | 4 +- packages/sdk/src/modules/BaseDatasource.ts | 8 ++-- packages/sdk/src/modules/DatasourceUtility.ts | 7 ++-- packages/sdk/src/modules/JsonRpcDatasource.ts | 13 ++++--- packages/sdk/src/psbt-builder/PSBTBuilder.ts | 22 ++++------- packages/sdk/src/psbt-builder/types.ts | 7 ++-- packages/sdk/src/signatures/message.ts | 6 +-- packages/sdk/src/signatures/psbt.ts | 4 +- packages/sdk/src/transactions/index.ts | 1 - packages/sdk/src/transactions/psbt.ts | 7 ++-- packages/sdk/src/transactions/types.ts | 7 ++-- packages/sdk/src/utils/constants.ts | 2 +- packages/sdk/src/utils/index.ts | 7 ++-- packages/sdk/src/utils/types.ts | 2 +- packages/sdk/src/utxos/UTXOManager.ts | 6 ++- packages/sdk/src/utxos/types.ts | 2 +- packages/sdk/src/wallet/Ordit.ts | 12 +++--- packages/sdk/src/wallet/index.ts | 4 +- packages/sdk/tsconfig.json | 6 ++- 39 files changed, 156 insertions(+), 136 deletions(-) rename packages/sdk/src/{transactions => inscriber}/Inscriber.ts (90%) create mode 100644 packages/sdk/src/inscriber/index.ts create mode 100644 packages/sdk/src/inscriber/types.ts diff --git a/packages/sdk/src/addresses/index.ts b/packages/sdk/src/addresses/index.ts index af8ed53f..327579ae 100644 --- a/packages/sdk/src/addresses/index.ts +++ b/packages/sdk/src/addresses/index.ts @@ -1,8 +1,9 @@ import * as ecc from "@bitcoinerlab/secp256k1" import BIP32Factory, { BIP32Interface } from "bip32" -import { Network } from "../config/types" -import { createTransaction, getDerivationPath, getNetwork, toXOnly } from "../utils" +import { Network } from "~/config/types" +import { createTransaction, getDerivationPath, getNetwork, toXOnly } from "~/utils" + import { AddressFormats, addressFormats, addressNameToType, AddressTypes, addressTypeToName } from "./formats" export function getAddressFormat(address: string, network: Network) { diff --git a/packages/sdk/src/browser-wallets/metamask/addresses.ts b/packages/sdk/src/browser-wallets/metamask/addresses.ts index 02914862..e1713408 100644 --- a/packages/sdk/src/browser-wallets/metamask/addresses.ts +++ b/packages/sdk/src/browser-wallets/metamask/addresses.ts @@ -1,7 +1,9 @@ import { ethers } from "ethers" -import { getAddressesFromPublicKey, getDerivedNode } from "../.." -import { Network } from "../../config/types" +import { getAddressesFromPublicKey } from "~/addresses" +import { Network } from "~/config/types" +import { getDerivedNode } from "~/keys" + import { isMetaMaskInstalled } from "./utils" export async function getAddresses({ path, network = "testnet" }: GetMetaMaskAddressesOptions) { if (!isMetaMaskInstalled()) { diff --git a/packages/sdk/src/browser-wallets/metamask/signatures.ts b/packages/sdk/src/browser-wallets/metamask/signatures.ts index c6087675..07c68d2d 100644 --- a/packages/sdk/src/browser-wallets/metamask/signatures.ts +++ b/packages/sdk/src/browser-wallets/metamask/signatures.ts @@ -2,8 +2,9 @@ import { Psbt } from "bitcoinjs-lib" import { sign } from "bitcoinjs-message" import { ethers } from "ethers" -import { createTransaction } from "../.." -import { Network } from "../../config/types" +import { Network } from "~/config/types" +import { createTransaction } from "~/utils" + import { getDerivedNodeFromMetaMaskSignature } from "./addresses" import { isMetaMaskInstalled } from "./utils" diff --git a/packages/sdk/src/browser-wallets/unisat/addresses.ts b/packages/sdk/src/browser-wallets/unisat/addresses.ts index 6693be22..960a5418 100644 --- a/packages/sdk/src/browser-wallets/unisat/addresses.ts +++ b/packages/sdk/src/browser-wallets/unisat/addresses.ts @@ -1,5 +1,6 @@ -import { getAddressFormat } from "../.." -import { Network } from "../../config/types" +import { getAddressFormat } from "~/addresses" +import { Network } from "~/config/types" + import { isUnisatInstalled, UnisatNetwork } from "./utils" export async function getAddresses(network: Network) { diff --git a/packages/sdk/src/browser-wallets/xverse/addresses.ts b/packages/sdk/src/browser-wallets/xverse/addresses.ts index f8a3f898..767ab681 100644 --- a/packages/sdk/src/browser-wallets/xverse/addresses.ts +++ b/packages/sdk/src/browser-wallets/xverse/addresses.ts @@ -1,7 +1,8 @@ import { AddressPurposes, getAddress } from "sats-connect" -import { getAddressFormat } from "../../addresses" -import { Network } from "../../config/types" +import { getAddressFormat } from "~/addresses" +import { Network } from "~/config/types" + import { fromXOnlyToFullPubkey, isXverseInstalled, XverseNetwork } from "./utils" export async function getAddresses(options: XverseGetAddressOptions) { options.network = options.network ?? "testnet" diff --git a/packages/sdk/src/browser-wallets/xverse/signatures.ts b/packages/sdk/src/browser-wallets/xverse/signatures.ts index d4bf60af..39fa7d27 100644 --- a/packages/sdk/src/browser-wallets/xverse/signatures.ts +++ b/packages/sdk/src/browser-wallets/xverse/signatures.ts @@ -1,8 +1,9 @@ import { Psbt } from "bitcoinjs-lib" import { signMessage as _signMessage, signTransaction } from "sats-connect" -import { Network } from "../../config/types" -import { InputsToSign } from "../../inscription/types" +import { Network } from "~/config/types" +import { InputsToSign } from "~/inscription/types" + import { BrowserWalletSignPSBTResponse } from "../types" import { isXverseInstalled, XverseNetwork } from "./utils" diff --git a/packages/sdk/src/config/index.ts b/packages/sdk/src/config/index.ts index 83702d68..e3f71d06 100644 --- a/packages/sdk/src/config/index.ts +++ b/packages/sdk/src/config/index.ts @@ -19,8 +19,4 @@ export const apiConfig = { } } -// Input from seller PSBT when unwrapped & merged, -// is placed on the 2nd index in instant-buy-sell flow -export const INSTANT_BUY_SELLER_INPUT_INDEX = 2 - export type * from "./types" diff --git a/packages/sdk/src/constants/index.ts b/packages/sdk/src/constants/index.ts index a9618db1..18959d20 100644 --- a/packages/sdk/src/constants/index.ts +++ b/packages/sdk/src/constants/index.ts @@ -4,3 +4,7 @@ export const MINIMUM_AMOUNT_IN_SATS = 600 // Fee calculated by the fee estimator cannot be greater than 0.05 BTC in any case export const MAXIMUM_FEE = 5000000 + +// Input from seller PSBT when unwrapped & merged, +// is placed on the 2nd index in instant-buy-sell flow +export const INSTANT_BUY_SELLER_INPUT_INDEX = 2 diff --git a/packages/sdk/src/fee/FeeEstimator.ts b/packages/sdk/src/fee/FeeEstimator.ts index b15b697c..4fe03f79 100644 --- a/packages/sdk/src/fee/FeeEstimator.ts +++ b/packages/sdk/src/fee/FeeEstimator.ts @@ -1,11 +1,13 @@ import { Psbt } from "bitcoinjs-lib" -import { AddressFormats, getNetwork, getScriptType } from ".." -import { Network } from "../config/types" -import { MAXIMUM_FEE } from "../constants" +import { AddressFormats } from "~/addresses" +import { Network } from "~/config/types" +import { MAXIMUM_FEE } from "~/constants" +import { getNetwork, getScriptType } from "~/utils" + import { FeeEstimatorOptions } from "./types" -export default class FeeEstimator { +export class FeeEstimator { protected fee = 0 protected feeRate: number protected network: Network diff --git a/packages/sdk/src/fee/types.ts b/packages/sdk/src/fee/types.ts index 66559302..36b8e22c 100644 --- a/packages/sdk/src/fee/types.ts +++ b/packages/sdk/src/fee/types.ts @@ -1,6 +1,6 @@ import { Psbt } from "bitcoinjs-lib" -import { Network } from "../config/types" +import { Network } from "~/config/types" export interface FeeEstimatorOptions { feeRate: number diff --git a/packages/sdk/src/index.ts b/packages/sdk/src/index.ts index 489deea5..5dddd262 100644 --- a/packages/sdk/src/index.ts +++ b/packages/sdk/src/index.ts @@ -32,6 +32,7 @@ export * as metamask from "./browser-wallets/metamask" export * as unisat from "./browser-wallets/unisat" export * as xverse from "./browser-wallets/xverse" export * from "./config" +export * from "./fee" export * from "./inscription" export * from "./instant-trade" export * from "./keys" diff --git a/packages/sdk/src/transactions/Inscriber.ts b/packages/sdk/src/inscriber/Inscriber.ts similarity index 90% rename from packages/sdk/src/transactions/Inscriber.ts rename to packages/sdk/src/inscriber/Inscriber.ts index ab34368e..68574a47 100644 --- a/packages/sdk/src/transactions/Inscriber.ts +++ b/packages/sdk/src/inscriber/Inscriber.ts @@ -2,19 +2,14 @@ import * as ecc from "@bitcoinerlab/secp256k1" import * as bitcoin from "bitcoinjs-lib" import { Tapleaf } from "bitcoinjs-lib/src/types" -import { - buildWitnessScript, - createTransaction, - encodeObject, - getDummyP2TRInput, - getNetwork, - GetWalletOptions, - OnOffUnion -} from ".." -import { Network } from "../config/types" -import { PSBTBuilder } from "../psbt-builder" -import { NestedObject } from "../utils/types" -import { SkipStrictSatsCheckOptions, UTXOLimited } from "./types" +import { buildWitnessScript } from "~/inscription" +import { PSBTBuilder } from "~/psbt-builder" +import { SkipStrictSatsCheckOptions, UTXOLimited } from "~/transactions/types" +import { createTransaction, encodeObject, getDummyP2TRInput, getNetwork } from "~/utils" +import { NestedObject } from "~/utils/types" +import { OnOffUnion } from "~/wallet" + +import { InscriberArgOptions } from "./types" bitcoin.initEccLib(ecc) @@ -276,20 +271,3 @@ export class Inscriber extends PSBTBuilder { return this.suitableUnspent } } - -export type InscriberArgOptions = Pick & { - network: Network - address: string - destinationAddress: string - publicKey: string - feeRate: number - postage: number - mediaType: string - mediaContent: string - changeAddress: string - meta?: NestedObject - outputs?: Outputs - encodeMetadata?: boolean -} - -type Outputs = Array<{ address: string; value: number }> diff --git a/packages/sdk/src/inscriber/index.ts b/packages/sdk/src/inscriber/index.ts new file mode 100644 index 00000000..c6ebd839 --- /dev/null +++ b/packages/sdk/src/inscriber/index.ts @@ -0,0 +1,2 @@ +export * from "./Inscriber" +export * from "./types" diff --git a/packages/sdk/src/inscriber/types.ts b/packages/sdk/src/inscriber/types.ts new file mode 100644 index 00000000..a52673d4 --- /dev/null +++ b/packages/sdk/src/inscriber/types.ts @@ -0,0 +1,21 @@ +import { Network } from "~/config/types" +import { NestedObject } from "~/utils/types" +import { OnOffUnion } from "~/wallet" + +export type InscriberArgOptions = { + network: Network + address: string + destinationAddress: string + publicKey: string + feeRate: number + postage: number + mediaType: string + mediaContent: string + changeAddress: string + meta?: NestedObject + outputs?: Outputs + encodeMetadata?: boolean + safeMode?: OnOffUnion +} + +type Outputs = Array<{ address: string; value: number }> diff --git a/packages/sdk/src/inscription/collection.ts b/packages/sdk/src/inscription/collection.ts index ddf44d44..9923b76f 100644 --- a/packages/sdk/src/inscription/collection.ts +++ b/packages/sdk/src/inscription/collection.ts @@ -1,5 +1,8 @@ -import { BaseDatasource, GetWalletOptions, Inscriber, JsonRpcDatasource, verifyMessage } from ".." -import { Network } from "../config/types" +import { Network } from "~/config/types" +import { Inscriber } from "~/inscriber" +import { BaseDatasource, JsonRpcDatasource } from "~/modules" +import { verifyMessage } from "~/signatures/message" +import { OnOffUnion } from "~/wallet" export async function publishCollection({ title, @@ -120,7 +123,7 @@ function validateInscriptions(inscriptions: CollectionInscription[] = []) { return true } -export type PublishCollectionOptions = Pick & { +export type PublishCollectionOptions = { address: string feeRate: number postage: number @@ -148,6 +151,7 @@ export type PublishCollectionOptions = Pick & { outputs?: Outputs encodeMetadata?: boolean enableRBF?: boolean + safeMode?: OnOffUnion } export type CollectionInscription = { @@ -156,7 +160,7 @@ export type CollectionInscription = { sri?: string } -export type MintFromCollectionOptions = Pick & { +export type MintFromCollectionOptions = { address: string feeRate: number postage: number @@ -176,6 +180,7 @@ export type MintFromCollectionOptions = Pick & { encodeMetadata?: boolean enableRBF?: boolean datasource?: BaseDatasource + safeMode?: OnOffUnion } type Outputs = Array<{ address: string; value: number }> diff --git a/packages/sdk/src/instant-trade/InstantTradeBuilder.ts b/packages/sdk/src/instant-trade/InstantTradeBuilder.ts index fe13b7c8..7f6d7eed 100644 --- a/packages/sdk/src/instant-trade/InstantTradeBuilder.ts +++ b/packages/sdk/src/instant-trade/InstantTradeBuilder.ts @@ -1,9 +1,10 @@ -import { Inscription } from ".." -import { MINIMUM_AMOUNT_IN_SATS } from "../constants" -import { PSBTBuilder } from "../psbt-builder" +import { MINIMUM_AMOUNT_IN_SATS } from "~/constants" +import { Inscription } from "~/inscription" +import { PSBTBuilder } from "~/psbt-builder" + import { InstantTradeBuilderArgOptions } from "./types" -export default class InstantTradeBuilder extends PSBTBuilder { +export class InstantTradeBuilder extends PSBTBuilder { protected inscriptionOutpoint?: string protected inscription?: Inscription protected price = 0 diff --git a/packages/sdk/src/instant-trade/InstantTradeBuyerTxBuilder.ts b/packages/sdk/src/instant-trade/InstantTradeBuyerTxBuilder.ts index c2000090..8205029c 100644 --- a/packages/sdk/src/instant-trade/InstantTradeBuyerTxBuilder.ts +++ b/packages/sdk/src/instant-trade/InstantTradeBuyerTxBuilder.ts @@ -1,13 +1,14 @@ import { Psbt } from "bitcoinjs-lib" import reverseBuffer from "buffer-reverse" -import { decodePSBT, generateTxUniqueIdentifier, getScriptType, INSTANT_BUY_SELLER_INPUT_INDEX } from ".." -import { MINIMUM_AMOUNT_IN_SATS } from "../constants" -import { InjectableInput, InjectableOutput } from "../psbt-builder/types" -import InstantTradeBuilder from "./InstantTradeBuilder" +import { INSTANT_BUY_SELLER_INPUT_INDEX, MINIMUM_AMOUNT_IN_SATS } from "~/constants" +import { InjectableInput, InjectableOutput } from "~/psbt-builder/types" +import { decodePSBT, generateTxUniqueIdentifier, getScriptType } from "~/utils" + +import { InstantTradeBuilder } from "./InstantTradeBuilder" import { InstantTradeBuyerTxBuilderArgOptions } from "./types" -export default class InstantTradeBuyerTxBuilder extends InstantTradeBuilder { +export class InstantTradeBuyerTxBuilder extends InstantTradeBuilder { private receiveAddress?: string private sellerPSBT!: Psbt private sellerAddress?: string diff --git a/packages/sdk/src/instant-trade/InstantTradeSellerTxBuilder.ts b/packages/sdk/src/instant-trade/InstantTradeSellerTxBuilder.ts index 76c5949a..04a26608 100644 --- a/packages/sdk/src/instant-trade/InstantTradeSellerTxBuilder.ts +++ b/packages/sdk/src/instant-trade/InstantTradeSellerTxBuilder.ts @@ -1,12 +1,13 @@ import * as bitcoin from "bitcoinjs-lib" -import { processInput } from ".." -import { MINIMUM_AMOUNT_IN_SATS } from "../constants" -import { UTXO } from "../transactions/types" -import InstantTradeBuilder from "./InstantTradeBuilder" +import { MINIMUM_AMOUNT_IN_SATS } from "~/constants" +import { processInput } from "~/transactions" +import { UTXO } from "~/transactions/types" + +import { InstantTradeBuilder } from "./InstantTradeBuilder" import { InstantTradeSellerTxBuilderArgOptions } from "./types" -export default class InstantTradeSellerTxBuilder extends InstantTradeBuilder { +export class InstantTradeSellerTxBuilder extends InstantTradeBuilder { private receiveAddress?: string private utxo?: UTXO diff --git a/packages/sdk/src/instant-trade/index.ts b/packages/sdk/src/instant-trade/index.ts index a3345d33..f2395be3 100644 --- a/packages/sdk/src/instant-trade/index.ts +++ b/packages/sdk/src/instant-trade/index.ts @@ -1,4 +1,4 @@ -export { default as InstantTradeBuilder } from "./InstantTradeBuilder" -export { default as InstantTradeBuyerTxBuilder } from "./InstantTradeBuyerTxBuilder" -export { default as InstantTradeSellerTxBuilder } from "./InstantTradeSellerTxBuilder" +export * from "./InstantTradeBuilder" +export * from "./InstantTradeBuyerTxBuilder" +export * from "./InstantTradeSellerTxBuilder" export * from "./types" diff --git a/packages/sdk/src/instant-trade/types.ts b/packages/sdk/src/instant-trade/types.ts index f72d086a..620df8c5 100644 --- a/packages/sdk/src/instant-trade/types.ts +++ b/packages/sdk/src/instant-trade/types.ts @@ -1,4 +1,4 @@ -import { PSBTBuilderOptions } from "../psbt-builder/types" +import { PSBTBuilderOptions } from "~/psbt-builder/types" export interface InstantTradeBuilderArgOptions extends Pick { diff --git a/packages/sdk/src/keys/index.ts b/packages/sdk/src/keys/index.ts index 6c2b5ede..3dcc9614 100644 --- a/packages/sdk/src/keys/index.ts +++ b/packages/sdk/src/keys/index.ts @@ -2,8 +2,8 @@ import * as ecc from "@bitcoinerlab/secp256k1" import BIP32Factory from "bip32" import { entropyToMnemonic, mnemonicToSeed, validateMnemonic, wordlists } from "bip39" -import { Network } from "../config/types" -import { getNetwork } from "../utils" +import { Network } from "~/config/types" +import { getNetwork } from "~/utils" export async function getWalletKeys(seedValue: string, network: Network = "testnet", path: string) { const { parent, mnemonic } = await getDerivedNode(seedValue, network, path) diff --git a/packages/sdk/src/modules/BaseDatasource.ts b/packages/sdk/src/modules/BaseDatasource.ts index 2d39637f..6daa5d3c 100644 --- a/packages/sdk/src/modules/BaseDatasource.ts +++ b/packages/sdk/src/modules/BaseDatasource.ts @@ -1,6 +1,5 @@ import { Transaction as BTCTransaction } from "bitcoinjs-lib" -import { Inscription } from ".." import { GetBalanceOptions, GetInscriptionOptions, @@ -11,9 +10,10 @@ import { GetUnspentsOptions, GetUnspentsResponse, RelayOptions -} from "../api/types" -import { Network } from "../config/types" -import { Transaction, UTXO, UTXOLimited } from "../transactions/types" +} from "~/api/types" +import { Network } from "~/config/types" +import { Inscription } from "~/inscription" +import { Transaction, UTXO, UTXOLimited } from "~/transactions/types" interface BaseDatasourceOptions { network: Network diff --git a/packages/sdk/src/modules/DatasourceUtility.ts b/packages/sdk/src/modules/DatasourceUtility.ts index ab255f48..6902e4fb 100644 --- a/packages/sdk/src/modules/DatasourceUtility.ts +++ b/packages/sdk/src/modules/DatasourceUtility.ts @@ -1,6 +1,7 @@ -import { decodeObject, Inscription } from ".." -import { GetUnspentsResponse } from "../api/types" -import { UTXO } from "../transactions/types" +import { GetUnspentsResponse } from "~/api/types" +import { Inscription } from "~/inscription" +import { UTXO } from "~/transactions/types" +import { decodeObject } from "~/utils" interface SegregateUTXOsBySpendStatusArgOptions { utxos: UTXO[] diff --git a/packages/sdk/src/modules/JsonRpcDatasource.ts b/packages/sdk/src/modules/JsonRpcDatasource.ts index d4f08951..4805d3e2 100644 --- a/packages/sdk/src/modules/JsonRpcDatasource.ts +++ b/packages/sdk/src/modules/JsonRpcDatasource.ts @@ -1,7 +1,6 @@ import { Transaction as BTCTransaction } from "bitcoinjs-lib" -import { Inscription } from ".." -import { rpc } from "../api/jsonrpc" +import { rpc } from "~/api/jsonrpc" import { GetBalanceOptions, GetInscriptionOptions, @@ -12,11 +11,13 @@ import { GetUnspentsOptions, GetUnspentsResponse, RelayOptions -} from "../api/types" -import { Network } from "../config/types" -import { Transaction, UTXO, UTXOLimited } from "../transactions/types" -import { DatasourceUtility } from "." +} from "~/api/types" +import { Network } from "~/config/types" +import { Inscription } from "~/inscription" +import { Transaction, UTXO, UTXOLimited } from "~/transactions/types" + import { BaseDatasource } from "./BaseDatasource" +import { DatasourceUtility } from "./DatasourceUtility" import { JsonRpcPagination } from "./types" interface JsonRpcDatasourceOptions { diff --git a/packages/sdk/src/psbt-builder/PSBTBuilder.ts b/packages/sdk/src/psbt-builder/PSBTBuilder.ts index 88c812e8..1aa73222 100644 --- a/packages/sdk/src/psbt-builder/PSBTBuilder.ts +++ b/packages/sdk/src/psbt-builder/PSBTBuilder.ts @@ -2,20 +2,14 @@ import { networks, Psbt, Transaction } from "bitcoinjs-lib" import reverseBuffer from "buffer-reverse" -import { - convertSatoshisToBTC, - generateTxUniqueIdentifier, - getNetwork, - InputsToSign, - INSTANT_BUY_SELLER_INPUT_INDEX, - JsonRpcDatasource, - toXOnly -} from ".." -import { MINIMUM_AMOUNT_IN_SATS } from "../constants" -import FeeEstimator from "../fee/FeeEstimator" -import { BaseDatasource } from "../modules/BaseDatasource" -import { InputType, processInput } from "../transactions" -import { Output, UTXOLimited } from "../transactions/types" +import { INSTANT_BUY_SELLER_INPUT_INDEX, MINIMUM_AMOUNT_IN_SATS } from "~/constants" +import { FeeEstimator } from "~/fee" +import { InputsToSign } from "~/inscription" +import { BaseDatasource, JsonRpcDatasource } from "~/modules" +import { InputType, processInput } from "~/transactions" +import { Output, UTXOLimited } from "~/transactions/types" +import { convertSatoshisToBTC, generateTxUniqueIdentifier, getNetwork, toXOnly } from "~/utils" + import { InjectableInput, InjectableOutput, PSBTBuilderOptions } from "./types" export class PSBTBuilder extends FeeEstimator { diff --git a/packages/sdk/src/psbt-builder/types.ts b/packages/sdk/src/psbt-builder/types.ts index c151673b..26185951 100644 --- a/packages/sdk/src/psbt-builder/types.ts +++ b/packages/sdk/src/psbt-builder/types.ts @@ -1,7 +1,6 @@ -import { InputType } from ".." -import { Network } from "../config/types" -import { BaseDatasource } from "../modules/BaseDatasource" -import { Output } from "../transactions/types" +import { Network } from "~/config/types" +import { BaseDatasource } from "~/modules/BaseDatasource" +import { InputType, Output } from "~/transactions" export interface PSBTBuilderOptions { address: string diff --git a/packages/sdk/src/signatures/message.ts b/packages/sdk/src/signatures/message.ts index b4db0d29..8a4826d0 100644 --- a/packages/sdk/src/signatures/message.ts +++ b/packages/sdk/src/signatures/message.ts @@ -1,8 +1,8 @@ import { sign, verify } from "bitcoinjs-message" -import { Network } from "../config/types" -import { getDerivedNode } from "../keys" -import { createTransaction, getNetwork } from "../utils" +import { Network } from "~/config/types" +import { getDerivedNode } from "~/keys" +import { createTransaction, getNetwork } from "~/utils" export async function signMessage(options: SignMessageOptions) { const network = getNetwork(options.network) diff --git a/packages/sdk/src/signatures/psbt.ts b/packages/sdk/src/signatures/psbt.ts index 0a61558f..bf3238db 100644 --- a/packages/sdk/src/signatures/psbt.ts +++ b/packages/sdk/src/signatures/psbt.ts @@ -1,8 +1,8 @@ import * as ecc from "@bitcoinerlab/secp256k1" import * as bitcoin from "bitcoinjs-lib" -import { Network } from "../config/types" -import { getDerivedNode } from "../keys" +import { Network } from "~/config/types" +import { getDerivedNode } from "~/keys" export async function signPsbt(options: SignPsbtOptions) { bitcoin.initEccLib(ecc) diff --git a/packages/sdk/src/transactions/index.ts b/packages/sdk/src/transactions/index.ts index ffd98016..c6145566 100644 --- a/packages/sdk/src/transactions/index.ts +++ b/packages/sdk/src/transactions/index.ts @@ -1,3 +1,2 @@ -export * from "./Inscriber" export * from "./psbt" export * from "./types" diff --git a/packages/sdk/src/transactions/psbt.ts b/packages/sdk/src/transactions/psbt.ts index 8553bb02..073f8539 100644 --- a/packages/sdk/src/transactions/psbt.ts +++ b/packages/sdk/src/transactions/psbt.ts @@ -1,9 +1,10 @@ import * as ecc from "@bitcoinerlab/secp256k1" import { BIP32Factory } from "bip32" -import { JsonRpcDatasource } from "../modules" -import { PSBTBuilder } from "../psbt-builder" -import { createTransaction, getNetwork, toXOnly } from "../utils" +import { JsonRpcDatasource } from "~/modules" +import { PSBTBuilder } from "~/psbt-builder" +import { createTransaction, getNetwork, toXOnly } from "~/utils" + import { CreatePsbtOptions, InputType, diff --git a/packages/sdk/src/transactions/types.ts b/packages/sdk/src/transactions/types.ts index 7b05389a..00d186b4 100644 --- a/packages/sdk/src/transactions/types.ts +++ b/packages/sdk/src/transactions/types.ts @@ -1,6 +1,7 @@ -import { Network, OnOffUnion } from ".." -import { Inscription, Ordinal } from "../inscription/types" -import { BaseDatasource } from "../modules/BaseDatasource" +import { Network } from "~/config/types" +import { Inscription, Ordinal } from "~/inscription/types" +import { BaseDatasource } from "~/modules" +import { OnOffUnion } from "~/wallet" export type Vout = { value: number diff --git a/packages/sdk/src/utils/constants.ts b/packages/sdk/src/utils/constants.ts index 8504ee39..f04f6c33 100644 --- a/packages/sdk/src/utils/constants.ts +++ b/packages/sdk/src/utils/constants.ts @@ -1,4 +1,4 @@ -import { AddressFormats } from ".." +import { AddressFormats } from "~/addresses" export const DERIVATION_PATHS_WITHOUT_INDEX: Record = { legacy: `m/44'/0'/0'/0/`, diff --git a/packages/sdk/src/utils/index.ts b/packages/sdk/src/utils/index.ts index ffa87e8d..34b161ed 100644 --- a/packages/sdk/src/utils/index.ts +++ b/packages/sdk/src/utils/index.ts @@ -3,9 +3,10 @@ import { BIP32Interface } from "bip32" import * as bitcoin from "bitcoinjs-lib" import ECPairFactory from "ecpair" -import { AddressFormats, AddressTypes, addressTypeToName } from "../addresses/formats" -import { Network } from "../config/types" -import { UTXO } from "../transactions/types" +import { AddressFormats, AddressTypes, addressTypeToName } from "~/addresses" +import { Network } from "~/config/types" +import { UTXO } from "~/transactions/types" + import { BufferOrHex, EncodeDecodeObjectOptions, diff --git a/packages/sdk/src/utils/types.ts b/packages/sdk/src/utils/types.ts index 53a4cc7b..15ff6856 100644 --- a/packages/sdk/src/utils/types.ts +++ b/packages/sdk/src/utils/types.ts @@ -1,6 +1,6 @@ import { payments } from "bitcoinjs-lib" -import { AddressFormats, AddressTypes } from ".." +import { AddressFormats, AddressTypes } from "~/addresses" export interface NestedObject { [key: string]: NestedObject | any diff --git a/packages/sdk/src/utxos/UTXOManager.ts b/packages/sdk/src/utxos/UTXOManager.ts index 97504bdb..f50a2ae8 100644 --- a/packages/sdk/src/utxos/UTXOManager.ts +++ b/packages/sdk/src/utxos/UTXOManager.ts @@ -1,5 +1,7 @@ -import { processInput, PSBTBuilder } from ".." -import { MINIMUM_AMOUNT_IN_SATS } from "../constants" +import { MINIMUM_AMOUNT_IN_SATS } from "~/constants" +import { PSBTBuilder } from "~/psbt-builder" +import { processInput } from "~/transactions" + import { UTXOManagerOptions } from "./types" export class UTXOManager extends PSBTBuilder { diff --git a/packages/sdk/src/utxos/types.ts b/packages/sdk/src/utxos/types.ts index b587abfd..7e7c57fd 100644 --- a/packages/sdk/src/utxos/types.ts +++ b/packages/sdk/src/utxos/types.ts @@ -1,4 +1,4 @@ -import { PSBTBuilderOptions } from "../psbt-builder/types" +import { PSBTBuilderOptions } from "~/psbt-builder/types" export type UTXOManagerOptions = Pick< PSBTBuilderOptions, diff --git a/packages/sdk/src/wallet/Ordit.ts b/packages/sdk/src/wallet/Ordit.ts index 91066ad8..af2a2f23 100644 --- a/packages/sdk/src/wallet/Ordit.ts +++ b/packages/sdk/src/wallet/Ordit.ts @@ -12,13 +12,11 @@ import { addressNameToType, getAccountDataFromHdNode, getAddressesFromPublicKey, - getAllAccountsFromHdNode, - getNetwork, - mintFromCollection, - publishCollection, - tweakSigner -} from ".." -import { Network } from "../config/types" + getAllAccountsFromHdNode +} from "~/addresses" +import { Network } from "~/config/types" +import { mintFromCollection, publishCollection } from "~/inscription" +import { getNetwork, tweakSigner } from "~/utils" bitcoin.initEccLib(ecc) const ECPair = ECPairFactory(ecc) diff --git a/packages/sdk/src/wallet/index.ts b/packages/sdk/src/wallet/index.ts index 8006dcf6..2723fa7b 100644 --- a/packages/sdk/src/wallet/index.ts +++ b/packages/sdk/src/wallet/index.ts @@ -1,5 +1,5 @@ -import { AddressTypes } from "../addresses/formats" -import { Network } from "../config/types" +import { AddressTypes } from "~/addresses/formats" +import { Network } from "~/config/types" export type OnOffUnion = "on" | "off" diff --git a/packages/sdk/tsconfig.json b/packages/sdk/tsconfig.json index a5b38310..4eea74eb 100644 --- a/packages/sdk/tsconfig.json +++ b/packages/sdk/tsconfig.json @@ -1,7 +1,11 @@ { "extends": "@sadoprotocol/typescript", "compilerOptions": { - "rootDir": "./", + "rootDir": ".", + "baseUrl": ".", + "paths": { + "~/*": ["./src/*"] + }, "outDir": "./dist", "sourceMap": true },