Skip to content

Commit

Permalink
refactor: set ~ as root and update all imports
Browse files Browse the repository at this point in the history
  • Loading branch information
iamcrazycoder committed Oct 3, 2023
1 parent bafee1e commit 28bace8
Show file tree
Hide file tree
Showing 39 changed files with 156 additions and 136 deletions.
5 changes: 3 additions & 2 deletions packages/sdk/src/addresses/index.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions packages/sdk/src/browser-wallets/metamask/addresses.ts
Original file line number Diff line number Diff line change
@@ -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()) {
Expand Down
5 changes: 3 additions & 2 deletions packages/sdk/src/browser-wallets/metamask/signatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
5 changes: 3 additions & 2 deletions packages/sdk/src/browser-wallets/unisat/addresses.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions packages/sdk/src/browser-wallets/xverse/addresses.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
5 changes: 3 additions & 2 deletions packages/sdk/src/browser-wallets/xverse/signatures.ts
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
4 changes: 0 additions & 4 deletions packages/sdk/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 4 additions & 0 deletions packages/sdk/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 6 additions & 4 deletions packages/sdk/src/fee/FeeEstimator.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/fee/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Psbt } from "bitcoinjs-lib"

import { Network } from "../config/types"
import { Network } from "~/config/types"

export interface FeeEstimatorOptions {
feeRate: number
Expand Down
1 change: 1 addition & 0 deletions packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -276,20 +271,3 @@ export class Inscriber extends PSBTBuilder {
return this.suitableUnspent
}
}

export type InscriberArgOptions = Pick<GetWalletOptions, "safeMode"> & {
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 }>
2 changes: 2 additions & 0 deletions packages/sdk/src/inscriber/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./Inscriber"
export * from "./types"
21 changes: 21 additions & 0 deletions packages/sdk/src/inscriber/types.ts
Original file line number Diff line number Diff line change
@@ -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 }>
13 changes: 9 additions & 4 deletions packages/sdk/src/inscription/collection.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -120,7 +123,7 @@ function validateInscriptions(inscriptions: CollectionInscription[] = []) {
return true
}

export type PublishCollectionOptions = Pick<GetWalletOptions, "safeMode"> & {
export type PublishCollectionOptions = {
address: string
feeRate: number
postage: number
Expand Down Expand Up @@ -148,6 +151,7 @@ export type PublishCollectionOptions = Pick<GetWalletOptions, "safeMode"> & {
outputs?: Outputs
encodeMetadata?: boolean
enableRBF?: boolean
safeMode?: OnOffUnion
}

export type CollectionInscription = {
Expand All @@ -156,7 +160,7 @@ export type CollectionInscription = {
sri?: string
}

export type MintFromCollectionOptions = Pick<GetWalletOptions, "safeMode"> & {
export type MintFromCollectionOptions = {
address: string
feeRate: number
postage: number
Expand All @@ -176,6 +180,7 @@ export type MintFromCollectionOptions = Pick<GetWalletOptions, "safeMode"> & {
encodeMetadata?: boolean
enableRBF?: boolean
datasource?: BaseDatasource
safeMode?: OnOffUnion
}

type Outputs = Array<{ address: string; value: number }>
9 changes: 5 additions & 4 deletions packages/sdk/src/instant-trade/InstantTradeBuilder.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 6 additions & 5 deletions packages/sdk/src/instant-trade/InstantTradeBuyerTxBuilder.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 6 additions & 5 deletions packages/sdk/src/instant-trade/InstantTradeSellerTxBuilder.ts
Original file line number Diff line number Diff line change
@@ -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

Expand Down
6 changes: 3 additions & 3 deletions packages/sdk/src/instant-trade/index.ts
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion packages/sdk/src/instant-trade/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PSBTBuilderOptions } from "../psbt-builder/types"
import { PSBTBuilderOptions } from "~/psbt-builder/types"

export interface InstantTradeBuilderArgOptions
extends Pick<PSBTBuilderOptions, "publicKey" | "network" | "address" | "autoAdjustment" | "feeRate" | "datasource"> {
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/src/keys/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions packages/sdk/src/modules/BaseDatasource.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Transaction as BTCTransaction } from "bitcoinjs-lib"

import { Inscription } from ".."
import {
GetBalanceOptions,
GetInscriptionOptions,
Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions packages/sdk/src/modules/DatasourceUtility.ts
Original file line number Diff line number Diff line change
@@ -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[]
Expand Down
13 changes: 7 additions & 6 deletions packages/sdk/src/modules/JsonRpcDatasource.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 {
Expand Down
Loading

0 comments on commit 28bace8

Please sign in to comment.