1+ // Effect-TS imports
2+ import { Data , type Effect } from "effect"
3+
4+ import type * as AssetName from "../../core/AssetName.js"
5+ import type * as Coin from "../../core/Coin.js"
6+ import type * as PolicyId from "../../core/PolicyId.js"
7+ import type * as Transaction from "../../core/Transaction.js"
8+ import type * as TransactionMetadatum from "../../core/TransactionMetadatum.js"
9+ import type * as TransactionWitnessSet from "../../core/TransactionWitnessSet.js"
10+ import type * as Value from "../../core/Value.js"
11+ import type * as Address from "../Address.js"
12+ import type * as Script from "../Script.js"
13+ import type { EffectToPromiseAPI } from "../Type.js"
14+ import type * as UTxO from "../UTxO.js"
15+ import type { CoinSelectionAlgorithm , CoinSelectionFunction , CoinSelectionOptions } from "./CoinSelection.js"
16+ import type { CollectFromParams , MintTokensParams , PayToAddressParams , ScriptHash } from "./operations/Operations.js"
17+
18+ // ============================================================================
19+ // Error Types
20+ // ============================================================================
21+
22+ /**
23+ * Error class for TransactionBuilder related operations.
24+ *
25+ * @since 2.0.0
26+ * @category errors
27+ */
28+ export class TransactionBuilderError extends Data . TaggedError ( "TransactionBuilderError" ) < {
29+ message ?: string
30+ cause ?: unknown
31+ } > { }
32+
33+ // ============================================================================
34+ // Transaction Types
35+ // ============================================================================
36+
37+ export type MetadataLabel = string | number
38+
39+ export type Slot = number
40+
41+ export interface ChainResult {
42+ readonly transaction : Transaction . Transaction
43+ readonly newOutputs : ReadonlyArray < UTxO . UTxO > // UTxOs created by this transaction
44+ readonly updatedUtxos : ReadonlyArray < UTxO . UTxO > // Available UTxOs for next transaction (original - spent + new)
45+ readonly spentUtxos : ReadonlyArray < UTxO . UTxO > // UTxOs consumed by this transaction
46+ }
47+
48+ export interface UplcEvaluationOptions {
49+ readonly type : "wasm" | "provider"
50+ readonly wasmModule ?: any // TODO: Define WASM UPLC module interface
51+ readonly timeout ?: number
52+ readonly maxMemory ?: number
53+ readonly maxCpu ?: number
54+ }
55+
56+ // TODO: To be defined - transaction optimization flags
57+ export interface TransactionOptimizations {
58+ readonly mergeOutputs ?: boolean
59+ readonly consolidateInputs ?: boolean
60+ readonly minimizeFee ?: boolean
61+ }
62+
63+ // Transaction cost estimation
64+ export interface TransactionEstimate {
65+ readonly fee : Coin . Coin
66+ readonly size : number
67+ readonly exUnits ?: {
68+ readonly mem : bigint
69+ readonly steps : bigint
70+ }
71+ }
72+
73+ // Build Options - Comprehensive configuration for transaction building
74+ export interface BuildOptions {
75+ // Coin selection strategy
76+ readonly coinSelection ?: CoinSelectionAlgorithm | CoinSelectionFunction
77+ readonly coinSelectionOptions ?: CoinSelectionOptions
78+
79+ // Script evaluation options
80+ readonly uplcEval ?: UplcEvaluationOptions
81+
82+ // Collateral handling
83+ readonly collateral ?: ReadonlyArray < UTxO . UTxO > // Manual collateral (max 3)
84+ readonly autoCollateral ?: boolean // Default: true if Plutus scripts present
85+
86+ // Fee and optimization
87+ readonly minFee ?: Coin . Coin
88+ readonly feeMultiplier ?: number
89+
90+ // TODO: To be defined - optimization flags, debug options
91+ readonly debug ?: boolean
92+ readonly optimizations ?: TransactionOptimizations
93+ }
94+
95+ // ============================================================================
96+ // Transaction Builder Interface
97+ // ============================================================================
98+
99+ export interface TransactionBuilderEffect {
100+ // Basic transaction operations
101+ readonly payToAddress : ( params : PayToAddressParams ) => TransactionBuilderEffect
102+ readonly payToScript : (
103+ scriptHash : ScriptHash . ScriptHash ,
104+ value : Value . Value ,
105+ datum : string
106+ ) => TransactionBuilderEffect
107+
108+ // Native token operations
109+ readonly mintTokens : ( params : MintTokensParams ) => TransactionBuilderEffect
110+ readonly burnTokens : (
111+ policyId : PolicyId . PolicyId ,
112+ assets : Map < AssetName . AssetName , bigint > ,
113+ redeemer ?: string
114+ ) => TransactionBuilderEffect
115+
116+ // Staking operations
117+ readonly delegateStake : ( poolId : string ) => TransactionBuilderEffect
118+ readonly withdrawRewards : ( amount ?: Coin . Coin ) => TransactionBuilderEffect
119+ readonly registerStakeKey : ( ) => TransactionBuilderEffect
120+ readonly deregisterStakeKey : ( ) => TransactionBuilderEffect
121+
122+ // Governance operations
123+ readonly vote : ( governanceActionId : string , vote : any ) => TransactionBuilderEffect
124+ readonly proposeGovernanceAction : ( proposal : any ) => TransactionBuilderEffect
125+
126+ // Transaction metadata and configuration
127+ readonly addMetadata : (
128+ label : MetadataLabel ,
129+ metadata : TransactionMetadatum . TransactionMetadatum
130+ ) => TransactionBuilderEffect
131+ readonly setValidityInterval : ( start ?: Slot , end ?: Slot ) => TransactionBuilderEffect
132+ readonly addRequiredSigner : ( keyHash : string ) => TransactionBuilderEffect
133+ readonly addCollateral : ( utxo : UTxO . UTxO ) => TransactionBuilderEffect
134+
135+ // Manual input/output management
136+ readonly collectFrom : ( params : CollectFromParams ) => TransactionBuilderEffect
137+ readonly addChangeOutput : ( address : Address . Address ) => TransactionBuilderEffect
138+
139+ // Script operations
140+ readonly attachScript : ( script : Script . Script ) => TransactionBuilderEffect
141+
142+ // Transaction finalization and execution
143+ readonly build : ( options ?: BuildOptions ) => Effect . Effect < any , TransactionBuilderError > // SignBuilder defined in SignBuilder.ts
144+ readonly buildAndSign : (
145+ options ?: BuildOptions
146+ ) => Effect . Effect < TransactionWitnessSet . TransactionWitnessSet , TransactionBuilderError >
147+ readonly buildSignAndSubmit : ( options ?: BuildOptions ) => Effect . Effect < string , TransactionBuilderError >
148+
149+ // Transaction chaining
150+ readonly chain : ( options ?: BuildOptions ) => Effect . Effect < ChainResult , TransactionBuilderError >
151+
152+ // Fee estimation and draft transaction
153+ readonly estimateFee : ( options ?: BuildOptions ) => Effect . Effect < TransactionEstimate , TransactionBuilderError >
154+ readonly draftTx : ( ) => Effect . Effect < Transaction . Transaction , TransactionBuilderError >
155+ }
156+
157+ export interface TransactionBuilder extends EffectToPromiseAPI < TransactionBuilderEffect > {
158+ readonly Effect : TransactionBuilderEffect
159+ }
0 commit comments