@atomiqlabs/base 10.0.0-dev.2 → 10.0.0-dev.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/LICENSE +201 -201
  2. package/dist/btc/BitcoinNetwork.d.ts +6 -6
  3. package/dist/btc/BitcoinNetwork.js +10 -10
  4. package/dist/btc/rpc/BitcoinRpc.d.ts +68 -68
  5. package/dist/btc/rpc/BitcoinRpc.js +2 -2
  6. package/dist/btcrelay/BtcRelay.d.ts +61 -61
  7. package/dist/btcrelay/BtcRelay.js +2 -2
  8. package/dist/btcrelay/synchronizer/RelaySynchronizer.d.ts +18 -18
  9. package/dist/btcrelay/synchronizer/RelaySynchronizer.js +2 -2
  10. package/dist/btcrelay/types/BtcBlock.d.ts +13 -13
  11. package/dist/btcrelay/types/BtcBlock.js +2 -2
  12. package/dist/btcrelay/types/BtcHeader.d.ts +10 -10
  13. package/dist/btcrelay/types/BtcHeader.js +2 -2
  14. package/dist/btcrelay/types/BtcStoredHeader.d.ts +11 -11
  15. package/dist/btcrelay/types/BtcStoredHeader.js +2 -2
  16. package/dist/btcrelay/utils/StatePredictorUtils.d.ts +11 -11
  17. package/dist/btcrelay/utils/StatePredictorUtils.js +80 -80
  18. package/dist/chains/ChainData.d.ts +31 -31
  19. package/dist/chains/ChainData.js +2 -2
  20. package/dist/chains/ChainInterface.d.ts +110 -110
  21. package/dist/chains/ChainInterface.js +2 -2
  22. package/dist/chains/ChainType.d.ts +23 -23
  23. package/dist/chains/ChainType.js +2 -2
  24. package/dist/errors/CannotInitializeATAError.d.ts +3 -3
  25. package/dist/errors/CannotInitializeATAError.js +11 -11
  26. package/dist/errors/SignatureVerificationError.d.ts +3 -3
  27. package/dist/errors/SignatureVerificationError.js +11 -11
  28. package/dist/errors/SwapDataVerificationError.d.ts +3 -3
  29. package/dist/errors/SwapDataVerificationError.js +11 -11
  30. package/dist/events/ChainEvents.d.ts +9 -9
  31. package/dist/events/ChainEvents.js +2 -2
  32. package/dist/events/types/ChainEvent.d.ts +7 -7
  33. package/dist/events/types/ChainEvent.js +6 -6
  34. package/dist/events/types/spv_vault/SpvVaultClaimEvent.d.ts +12 -12
  35. package/dist/events/types/spv_vault/SpvVaultClaimEvent.js +18 -18
  36. package/dist/events/types/spv_vault/SpvVaultCloseEvent.d.ts +7 -7
  37. package/dist/events/types/spv_vault/SpvVaultCloseEvent.js +13 -13
  38. package/dist/events/types/spv_vault/SpvVaultDepositEvent.d.ts +7 -7
  39. package/dist/events/types/spv_vault/SpvVaultDepositEvent.js +13 -13
  40. package/dist/events/types/spv_vault/SpvVaultEvent.d.ts +15 -15
  41. package/dist/events/types/spv_vault/SpvVaultEvent.js +20 -20
  42. package/dist/events/types/spv_vault/SpvVaultFrontEvent.d.ts +10 -10
  43. package/dist/events/types/spv_vault/SpvVaultFrontEvent.js +16 -16
  44. package/dist/events/types/spv_vault/SpvVaultOpenEvent.d.ts +7 -7
  45. package/dist/events/types/spv_vault/SpvVaultOpenEvent.js +13 -13
  46. package/dist/events/types/swap/ClaimEvent.d.ts +7 -7
  47. package/dist/events/types/swap/ClaimEvent.js +11 -11
  48. package/dist/events/types/swap/InitializeEvent.d.ts +9 -9
  49. package/dist/events/types/swap/InitializeEvent.js +12 -12
  50. package/dist/events/types/swap/RefundEvent.d.ts +5 -5
  51. package/dist/events/types/swap/RefundEvent.js +7 -7
  52. package/dist/events/types/swap/SwapEvent.d.ts +12 -12
  53. package/dist/events/types/swap/SwapEvent.js +17 -17
  54. package/dist/index.d.ts +41 -38
  55. package/dist/index.js +57 -54
  56. package/dist/lockable/Lockable.d.ts +6 -6
  57. package/dist/lockable/Lockable.js +28 -28
  58. package/dist/messaging/EventMessaging.d.ts +8 -0
  59. package/dist/messaging/EventMessaging.js +2 -0
  60. package/dist/messaging/Messenger.d.ts +8 -0
  61. package/dist/messaging/Messenger.js +2 -0
  62. package/dist/messaging/messages/Message.d.ts +8 -0
  63. package/dist/messaging/messages/Message.js +24 -0
  64. package/dist/messaging/messages/SwapClaimWitnessMessage.d.ts +13 -0
  65. package/dist/messaging/messages/SwapClaimWitnessMessage.js +26 -0
  66. package/dist/spv_swap/SpvVaultContract.d.ts +199 -199
  67. package/dist/spv_swap/SpvVaultContract.js +2 -2
  68. package/dist/spv_swap/SpvVaultData.d.ts +35 -35
  69. package/dist/spv_swap/SpvVaultData.js +37 -37
  70. package/dist/spv_swap/SpvWithdrawalState.d.ts +31 -31
  71. package/dist/spv_swap/SpvWithdrawalState.js +10 -10
  72. package/dist/spv_swap/SpvWithdrawalTransactionData.d.ts +43 -43
  73. package/dist/spv_swap/SpvWithdrawalTransactionData.js +143 -143
  74. package/dist/storage/IStorageManager.d.ts +15 -15
  75. package/dist/storage/IStorageManager.js +2 -2
  76. package/dist/storage/StorageObject.d.ts +3 -3
  77. package/dist/storage/StorageObject.js +2 -2
  78. package/dist/swaps/ChainSwapType.d.ts +6 -6
  79. package/dist/swaps/ChainSwapType.js +10 -10
  80. package/dist/swaps/SwapCommitState.d.ts +38 -38
  81. package/dist/swaps/SwapCommitState.js +11 -11
  82. package/dist/swaps/SwapContract.d.ts +467 -467
  83. package/dist/swaps/SwapContract.js +2 -2
  84. package/dist/swaps/SwapData.d.ts +36 -36
  85. package/dist/swaps/SwapData.js +14 -14
  86. package/dist/utils/BigIntBufferUtils.d.ts +6 -6
  87. package/dist/utils/BigIntBufferUtils.js +31 -31
  88. package/package.json +31 -31
  89. package/src/btc/BitcoinNetwork.ts +6 -6
  90. package/src/btc/rpc/BitcoinRpc.ts +77 -77
  91. package/src/btcrelay/BtcRelay.ts +70 -70
  92. package/src/btcrelay/synchronizer/RelaySynchronizer.ts +17 -17
  93. package/src/btcrelay/types/BtcBlock.ts +15 -15
  94. package/src/btcrelay/types/BtcHeader.ts +11 -11
  95. package/src/btcrelay/types/BtcStoredHeader.ts +12 -12
  96. package/src/btcrelay/utils/StatePredictorUtils.ts +108 -108
  97. package/src/chains/ChainData.ts +40 -40
  98. package/src/chains/ChainInterface.ts +132 -132
  99. package/src/chains/ChainType.ts +38 -38
  100. package/src/errors/CannotInitializeATAError.ts +11 -11
  101. package/src/errors/SignatureVerificationError.ts +11 -11
  102. package/src/errors/SwapDataVerificationError.ts +11 -11
  103. package/src/events/ChainEvents.ts +13 -13
  104. package/src/events/types/ChainEvent.ts +10 -10
  105. package/src/events/types/spv_vault/SpvVaultClaimEvent.ts +31 -31
  106. package/src/events/types/spv_vault/SpvVaultCloseEvent.ts +17 -17
  107. package/src/events/types/spv_vault/SpvVaultDepositEvent.ts +17 -17
  108. package/src/events/types/spv_vault/SpvVaultEvent.ts +25 -25
  109. package/src/events/types/spv_vault/SpvVaultFrontEvent.ts +27 -27
  110. package/src/events/types/spv_vault/SpvVaultOpenEvent.ts +16 -16
  111. package/src/events/types/swap/ClaimEvent.ts +15 -15
  112. package/src/events/types/swap/InitializeEvent.ts +18 -18
  113. package/src/events/types/swap/RefundEvent.ts +6 -6
  114. package/src/events/types/swap/SwapEvent.ts +21 -21
  115. package/src/index.ts +50 -46
  116. package/src/lockable/Lockable.ts +30 -30
  117. package/src/messaging/Messenger.ts +11 -0
  118. package/src/messaging/messages/Message.ts +27 -0
  119. package/src/messaging/messages/SwapClaimWitnessMessage.ts +31 -0
  120. package/src/spv_swap/SpvVaultContract.ts +230 -230
  121. package/src/spv_swap/SpvVaultData.ts +70 -70
  122. package/src/spv_swap/SpvWithdrawalState.ts +40 -40
  123. package/src/spv_swap/SpvWithdrawalTransactionData.ts +169 -169
  124. package/src/storage/IStorageManager.ts +16 -16
  125. package/src/storage/StorageObject.ts +6 -6
  126. package/src/swaps/ChainSwapType.ts +6 -6
  127. package/src/swaps/SwapCommitState.ts +39 -39
  128. package/src/swaps/SwapContract.ts +556 -556
  129. package/src/swaps/SwapData.ts +65 -65
  130. package/src/utils/BigIntBufferUtils.ts +31 -31
@@ -1,30 +1,30 @@
1
-
2
-
3
- export class Lockable {
4
-
5
- private lockedTill = 0;
6
- private lockNonce = 0;
7
-
8
- lock(timeoutSeconds: number): (() => boolean) | null {
9
- if(this.isLocked()) {
10
- return null;
11
- }
12
-
13
- this.lockedTill = Date.now()+(timeoutSeconds*1000);
14
-
15
- this.lockNonce++;
16
- const lockNonce = this.lockNonce;
17
- return () => {
18
- if(this.lockNonce!==lockNonce) {
19
- return false;
20
- }
21
- this.lockedTill = 0;
22
- return true;
23
- };
24
- }
25
-
26
- isLocked(): boolean {
27
- return this.lockedTill>Date.now();
28
- }
29
-
30
- }
1
+
2
+
3
+ export class Lockable {
4
+
5
+ private lockedTill = 0;
6
+ private lockNonce = 0;
7
+
8
+ lock(timeoutSeconds: number): (() => boolean) | null {
9
+ if(this.isLocked()) {
10
+ return null;
11
+ }
12
+
13
+ this.lockedTill = Date.now()+(timeoutSeconds*1000);
14
+
15
+ this.lockNonce++;
16
+ const lockNonce = this.lockNonce;
17
+ return () => {
18
+ if(this.lockNonce!==lockNonce) {
19
+ return false;
20
+ }
21
+ this.lockedTill = 0;
22
+ return true;
23
+ };
24
+ }
25
+
26
+ isLocked(): boolean {
27
+ return this.lockedTill>Date.now();
28
+ }
29
+
30
+ }
@@ -0,0 +1,11 @@
1
+ import {Message} from "./messages/Message";
2
+
3
+ export interface Messenger {
4
+
5
+ init(): Promise<void>;
6
+ broadcast(msg: Message): Promise<void>;
7
+ subscribe(callback: (msg: Message) => void): Promise<void>;
8
+ unsubscribe(callback: (msg: Message) => void): Promise<boolean>;
9
+ stop(): Promise<void>;
10
+
11
+ }
@@ -0,0 +1,27 @@
1
+ import {SwapClaimWitnessMessage} from "./SwapClaimWitnessMessage";
2
+
3
+ export enum MessageType {
4
+ SWAP_CLAIM_WITNESS = 0,
5
+
6
+ }
7
+
8
+ export abstract class Message {
9
+
10
+ abstract type: MessageType;
11
+
12
+ serialize(): any {
13
+ return {
14
+ type: this.type
15
+ }
16
+ }
17
+
18
+ static deserialize(message: any): any {
19
+ switch(message.type) {
20
+ case MessageType.SWAP_CLAIM_WITNESS:
21
+ return SwapClaimWitnessMessage.deserialize(message);
22
+ default:
23
+ throw new Error("Unknown message type " + message.type);
24
+ }
25
+ }
26
+
27
+ }
@@ -0,0 +1,31 @@
1
+ import {SwapData} from "../../swaps/SwapData";
2
+ import {Message, MessageType} from "./Message";
3
+
4
+
5
+ export class SwapClaimWitnessMessage<T extends SwapData> extends Message {
6
+
7
+ type = MessageType.SWAP_CLAIM_WITNESS;
8
+ swapData: T;
9
+ witness: string;
10
+
11
+ constructor(swapData: T, witness: string) {
12
+ super();
13
+ this.swapData = swapData;
14
+ this.witness = witness;
15
+ }
16
+
17
+ serialize() {
18
+ return {
19
+ swapData: this.swapData.serialize(),
20
+ witness: this.witness
21
+ }
22
+ }
23
+
24
+ static deserialize(obj: any) {
25
+ if(obj==null || typeof(obj.witness)!=="string" || typeof(obj.swapData)!=="object") {
26
+ throw new Error("Invalid format!");
27
+ }
28
+ return new SwapClaimWitnessMessage(SwapData.deserialize(obj.swapData), obj.witness);
29
+ }
30
+
31
+ }
@@ -1,231 +1,231 @@
1
- import {AbstractSigner, TransactionConfirmationOptions} from "../chains/ChainInterface";
2
- import {SpvVaultData, SpvVaultTokenData} from "./SpvVaultData";
3
- import {SpvWithdrawalTransactionData} from "./SpvWithdrawalTransactionData";
4
- import {BtcStoredHeader} from "../btcrelay/types/BtcStoredHeader";
5
- import {RelaySynchronizer} from "../btcrelay/synchronizer/RelaySynchronizer";
6
- import {SpvWithdrawalState} from "./SpvWithdrawalState";
7
- import {Buffer} from "buffer";
8
- import {BtcTx} from "../btc/rpc/BitcoinRpc";
9
-
10
-
11
- export interface SpvVaultContract<
12
- TX = any,
13
- Signer extends AbstractSigner = AbstractSigner,
14
- ChainId extends string = string,
15
- Data extends SpvVaultData = SpvVaultData,
16
- WithdrawalTX extends SpvWithdrawalTransactionData = SpvWithdrawalTransactionData
17
- > {
18
-
19
- readonly chainId: ChainId;
20
-
21
- /**
22
- * Signs & sends transactions for opening a specific spv vault
23
- *
24
- * @param signer Signer to use for the transaction (must match owner in vault)
25
- * @param vault Vault to init
26
- * @param txOptions Transaction options
27
- */
28
- open(signer: Signer, vault: Data, txOptions?: TransactionConfirmationOptions): Promise<string>;
29
-
30
- /**
31
- * Returns the unsigned transactions for opening a specific spv vault
32
- *
33
- * @param signer Signer to use for the transaction (must match owner in vault)
34
- * @param vault Vault to init
35
- * @param feeRate Fee rate to use for the transaction
36
- */
37
- txsOpen(signer: string, vault: Data, feeRate?: string): Promise<TX[]>;
38
-
39
- /**
40
- * Signs & sends transactions for depositing funds to a specific spv vault
41
- *
42
- * @param signer Signer to use for the transaction (can be any)
43
- * @param vault Vault to deposit to
44
- * @param rawAmounts Raw amounts to deposit (these are unscaled)
45
- * @param txOptions Transaction options
46
- */
47
- deposit(signer: Signer, vault: Data, rawAmounts: bigint[], txOptions?: TransactionConfirmationOptions): Promise<string>;
48
-
49
- /**
50
- * Returns the unsigned transactions for depositing funds to a specific spv vault
51
- *
52
- * @param signer Signer to use for the transaction (can be any)
53
- * @param vault Vault to deposit to
54
- * @param rawAmounts Raw amounts to deposit (these are unscaled)
55
- * @param feeRate Fee rate to use for the transaction
56
- */
57
- txsDeposit(signer: string, vault: Data, rawAmounts: bigint[], feeRate?: string): Promise<TX[]>;
58
-
59
- /**
60
- * Signs & sends transactions for fronting liquidity for a specific withdrawal btc transaction
61
- *
62
- * @param signer Signer to use for the transaction (payer of the fronted liquidity)
63
- * @param vault Vault to deposit to
64
- * @param realWithdrawalTx Real withdrawal transaction data
65
- * @param withdrawSequence Sequence number of the withdrawal that is being fronted, this used as race condition
66
- * prevention, such that fronting will not happen if the withdrawal tx is already used in claim()
67
- * @param txOptions Transaction options
68
- */
69
- frontLiquidity(signer: Signer, vault: Data, realWithdrawalTx: WithdrawalTX, withdrawSequence: number, txOptions?: TransactionConfirmationOptions): Promise<string>;
70
-
71
- /**
72
- * Returns the unsigned transactions for fronting liquidity for a specific withdrawal btc transaction
73
- *
74
- * @param signer Signer to use for the transaction (payer of the fronted liquidity)
75
- * @param vault Vault to deposit to
76
- * @param realWithdrawalTx Real withdrawal transaction data
77
- * @param withdrawSequence Sequence number of the withdrawal that is being fronted, this used as race condition
78
- * prevention, such that fronting will not happen if the withdrawal tx is already used in claim()
79
- * @param feeRate Fee rate to use for the transaction
80
- */
81
- txsFrontLiquidity(signer: string, vault: Data, realWithdrawalTx: WithdrawalTX, withdrawSequence: number, feeRate?: string): Promise<TX[]>;
82
-
83
- /**
84
- * Signs & sends transactions for claiming the funds from a specific vault
85
- *
86
- * @param signer Signer to use for the transaction
87
- * @param vault Vault to claim from
88
- * @param txs
89
- * @param synchronizer Optiona synchronizer to be used if BTC relay contract is not synced up to the required blockheight
90
- * @param initAta Whether to initialize a token account if it doesn't exist (applies to e.g. Solana, with token specific ATAs)
91
- * @param txOptions Transaction options
92
- */
93
- claim(
94
- signer: Signer, vault: Data, txs: {
95
- tx: WithdrawalTX,
96
- storedHeader?: BtcStoredHeader<any>
97
- }[], synchronizer?: RelaySynchronizer<any, TX, any>,
98
- initAta?: boolean, txOptions?: TransactionConfirmationOptions
99
- ): Promise<string>;
100
-
101
- /**
102
- * Returns the unsigned transactions for claiming the funds from a specific vault
103
- *
104
- * @param signer Signer to use for the transaction
105
- * @param vault Vault to claim from
106
- * @param txs
107
- * @param synchronizer Optiona synchronizer to be used if BTC relay contract is not synced up to the required blockheight
108
- * @param initAta Whether to initialize a token account if it doesn't exist (applies to e.g. Solana, with token specific ATAs)
109
- * @param feeRate Fee rate to use for the transaction
110
- */
111
- txsClaim(
112
- signer: string, vault: Data, txs: {
113
- tx: WithdrawalTX,
114
- storedHeader?: BtcStoredHeader<any>
115
- }[], synchronizer?: RelaySynchronizer<any, TX, any>,
116
- initAta?: boolean, feeRate?: string
117
- ): Promise<TX[]>;
118
-
119
- /**
120
- * Creates vault data for a new vault
121
- *
122
- * @param owner Vault owner
123
- * @param vaultId Vault ID
124
- * @param utxo Utxo on which to assign the vault initially
125
- * @param confirmations Required number of bitcoin confirmations to be able to withdraw funds from the vault
126
- * @param tokenData Data about the tokens in the vault
127
- */
128
- createVaultData(owner: string, vaultId: bigint, utxo: string, confirmations: number, tokenData: SpvVaultTokenData[]): Promise<Data>;
129
-
130
- /**
131
- * Returns the party which currently fronted the withdrawal transaction
132
- *
133
- * @param owner Owner of the vault
134
- * @param vaultId Vault ID
135
- * @param withdrawal Withdrawal transaction to check the fronting for
136
- */
137
- getFronterAddress(owner: string, vaultId: bigint, withdrawal: WithdrawalTX): Promise<string | null>;
138
-
139
- /**
140
- * Returns current vault data
141
- *
142
- * @param owner Owner of the vault
143
- * @param vaultId Vault ID
144
- */
145
- getVaultData(owner: string, vaultId: bigint): Promise<Data>;
146
-
147
- /**
148
- * Returns all currently opened vaults
149
- * NOTE: This will take a long time, since the implementation will have to go through all the prior events
150
- */
151
- getAllVaults(owner?: string): Promise<Data[]>;
152
-
153
- /**
154
- * Returns current state of the withdrawal as specified by the bitcoin transaction ID
155
- *
156
- * @param btcTxId
157
- */
158
- getWithdrawalState(btcTxId: string): Promise<SpvWithdrawalState>;
159
-
160
- /**
161
- * Parses withdrawal data from the parsed bitcoin transaction
162
- *
163
- * @param btcTx
164
- */
165
- getWithdrawalData(btcTx: BtcTx): Promise<WithdrawalTX>;
166
-
167
- /**
168
- * Checks if given withdrawal tx is valid and correctly parses on-chain, throws error when there is any issue with
169
- * the validation
170
- *
171
- * @param tx
172
- */
173
- checkWithdrawalTx(tx: WithdrawalTX): Promise<void>;
174
-
175
- /**
176
- * Serializes the withdrawal params to the OP_RETURN data
177
- *
178
- * @param recipient Recipient of the withdrawn tokens
179
- * @param rawAmounts Raw amount of tokens to withdraw
180
- * @param executionHash Optional execution hash of the actions to execute
181
- */
182
- toOpReturnData(recipient: string, rawAmounts: bigint[], executionHash?: string): Buffer;
183
-
184
- /**
185
- * Parses withdrawal params from OP_RETURN data
186
- *
187
- * @param data data as specified in the OP_RETURN output of the transaction
188
- */
189
- fromOpReturnData(data: Buffer): {recipient: string, rawAmounts: bigint[], executionHash: string};
190
-
191
- /**
192
- * Returns the fee in native token base units to claim the swap
193
- *
194
- * @param signer Signer claiming the swap
195
- * @param vault
196
- * @param withdrawalData Withdrawal to claim
197
- * @param feeRate Optional fee rate (fetched on-demand if not provided)
198
- */
199
- getClaimFee(signer: string, vault: Data, withdrawalData: WithdrawalTX, feeRate?: string): Promise<bigint>;
200
-
201
- /**
202
- * Returns raw fee (not including any refunds we might get that would make the getClaimFee negative) for claiming the swap
203
- *
204
- * @param signer Signer claiming the swap
205
- * @param vault
206
- * @param withdrawalData Withdrawal to claim
207
- * @param feeRate Optional fee rate (fetched on-demand if not provided)
208
- */
209
- getRawClaimFee?(signer: string, vault: Data, withdrawalData: WithdrawalTX, feeRate?: string): Promise<bigint>;
210
-
211
- /**
212
- * Returns the fee in native token base units to claim the swap
213
- *
214
- * @param signer Signer claiming the swap
215
- * @param vault
216
- * @param withdrawalData Withdrawal to claim
217
- * @param feeRate Optional fee rate (fetched on-demand if not provided)
218
- */
219
- getFrontFee(signer: string, vault: Data, withdrawalData: WithdrawalTX, feeRate?: string): Promise<bigint>;
220
-
221
- /**
222
- * Returns raw fee (not including any refunds we might get that would make the getClaimFee negative) for claiming the swap
223
- *
224
- * @param signer Signer claiming the swap
225
- * @param vault
226
- * @param withdrawalData Withdrawal to claim
227
- * @param feeRate Optional fee rate (fetched on-demand if not provided)
228
- */
229
- getRawFrontFee?(signer: string, vault: Data, withdrawalData: WithdrawalTX, feeRate?: string): Promise<bigint>;
230
-
1
+ import {AbstractSigner, TransactionConfirmationOptions} from "../chains/ChainInterface";
2
+ import {SpvVaultData, SpvVaultTokenData} from "./SpvVaultData";
3
+ import {SpvWithdrawalTransactionData} from "./SpvWithdrawalTransactionData";
4
+ import {BtcStoredHeader} from "../btcrelay/types/BtcStoredHeader";
5
+ import {RelaySynchronizer} from "../btcrelay/synchronizer/RelaySynchronizer";
6
+ import {SpvWithdrawalState} from "./SpvWithdrawalState";
7
+ import {Buffer} from "buffer";
8
+ import {BtcTx} from "../btc/rpc/BitcoinRpc";
9
+
10
+
11
+ export interface SpvVaultContract<
12
+ TX = any,
13
+ Signer extends AbstractSigner = AbstractSigner,
14
+ ChainId extends string = string,
15
+ Data extends SpvVaultData = SpvVaultData,
16
+ WithdrawalTX extends SpvWithdrawalTransactionData = SpvWithdrawalTransactionData
17
+ > {
18
+
19
+ readonly chainId: ChainId;
20
+
21
+ /**
22
+ * Signs & sends transactions for opening a specific spv vault
23
+ *
24
+ * @param signer Signer to use for the transaction (must match owner in vault)
25
+ * @param vault Vault to init
26
+ * @param txOptions Transaction options
27
+ */
28
+ open(signer: Signer, vault: Data, txOptions?: TransactionConfirmationOptions): Promise<string>;
29
+
30
+ /**
31
+ * Returns the unsigned transactions for opening a specific spv vault
32
+ *
33
+ * @param signer Signer to use for the transaction (must match owner in vault)
34
+ * @param vault Vault to init
35
+ * @param feeRate Fee rate to use for the transaction
36
+ */
37
+ txsOpen(signer: string, vault: Data, feeRate?: string): Promise<TX[]>;
38
+
39
+ /**
40
+ * Signs & sends transactions for depositing funds to a specific spv vault
41
+ *
42
+ * @param signer Signer to use for the transaction (can be any)
43
+ * @param vault Vault to deposit to
44
+ * @param rawAmounts Raw amounts to deposit (these are unscaled)
45
+ * @param txOptions Transaction options
46
+ */
47
+ deposit(signer: Signer, vault: Data, rawAmounts: bigint[], txOptions?: TransactionConfirmationOptions): Promise<string>;
48
+
49
+ /**
50
+ * Returns the unsigned transactions for depositing funds to a specific spv vault
51
+ *
52
+ * @param signer Signer to use for the transaction (can be any)
53
+ * @param vault Vault to deposit to
54
+ * @param rawAmounts Raw amounts to deposit (these are unscaled)
55
+ * @param feeRate Fee rate to use for the transaction
56
+ */
57
+ txsDeposit(signer: string, vault: Data, rawAmounts: bigint[], feeRate?: string): Promise<TX[]>;
58
+
59
+ /**
60
+ * Signs & sends transactions for fronting liquidity for a specific withdrawal btc transaction
61
+ *
62
+ * @param signer Signer to use for the transaction (payer of the fronted liquidity)
63
+ * @param vault Vault to deposit to
64
+ * @param realWithdrawalTx Real withdrawal transaction data
65
+ * @param withdrawSequence Sequence number of the withdrawal that is being fronted, this used as race condition
66
+ * prevention, such that fronting will not happen if the withdrawal tx is already used in claim()
67
+ * @param txOptions Transaction options
68
+ */
69
+ frontLiquidity(signer: Signer, vault: Data, realWithdrawalTx: WithdrawalTX, withdrawSequence: number, txOptions?: TransactionConfirmationOptions): Promise<string>;
70
+
71
+ /**
72
+ * Returns the unsigned transactions for fronting liquidity for a specific withdrawal btc transaction
73
+ *
74
+ * @param signer Signer to use for the transaction (payer of the fronted liquidity)
75
+ * @param vault Vault to deposit to
76
+ * @param realWithdrawalTx Real withdrawal transaction data
77
+ * @param withdrawSequence Sequence number of the withdrawal that is being fronted, this used as race condition
78
+ * prevention, such that fronting will not happen if the withdrawal tx is already used in claim()
79
+ * @param feeRate Fee rate to use for the transaction
80
+ */
81
+ txsFrontLiquidity(signer: string, vault: Data, realWithdrawalTx: WithdrawalTX, withdrawSequence: number, feeRate?: string): Promise<TX[]>;
82
+
83
+ /**
84
+ * Signs & sends transactions for claiming the funds from a specific vault
85
+ *
86
+ * @param signer Signer to use for the transaction
87
+ * @param vault Vault to claim from
88
+ * @param txs
89
+ * @param synchronizer Optiona synchronizer to be used if BTC relay contract is not synced up to the required blockheight
90
+ * @param initAta Whether to initialize a token account if it doesn't exist (applies to e.g. Solana, with token specific ATAs)
91
+ * @param txOptions Transaction options
92
+ */
93
+ claim(
94
+ signer: Signer, vault: Data, txs: {
95
+ tx: WithdrawalTX,
96
+ storedHeader?: BtcStoredHeader<any>
97
+ }[], synchronizer?: RelaySynchronizer<any, TX, any>,
98
+ initAta?: boolean, txOptions?: TransactionConfirmationOptions
99
+ ): Promise<string>;
100
+
101
+ /**
102
+ * Returns the unsigned transactions for claiming the funds from a specific vault
103
+ *
104
+ * @param signer Signer to use for the transaction
105
+ * @param vault Vault to claim from
106
+ * @param txs
107
+ * @param synchronizer Optiona synchronizer to be used if BTC relay contract is not synced up to the required blockheight
108
+ * @param initAta Whether to initialize a token account if it doesn't exist (applies to e.g. Solana, with token specific ATAs)
109
+ * @param feeRate Fee rate to use for the transaction
110
+ */
111
+ txsClaim(
112
+ signer: string, vault: Data, txs: {
113
+ tx: WithdrawalTX,
114
+ storedHeader?: BtcStoredHeader<any>
115
+ }[], synchronizer?: RelaySynchronizer<any, TX, any>,
116
+ initAta?: boolean, feeRate?: string
117
+ ): Promise<TX[]>;
118
+
119
+ /**
120
+ * Creates vault data for a new vault
121
+ *
122
+ * @param owner Vault owner
123
+ * @param vaultId Vault ID
124
+ * @param utxo Utxo on which to assign the vault initially
125
+ * @param confirmations Required number of bitcoin confirmations to be able to withdraw funds from the vault
126
+ * @param tokenData Data about the tokens in the vault
127
+ */
128
+ createVaultData(owner: string, vaultId: bigint, utxo: string, confirmations: number, tokenData: SpvVaultTokenData[]): Promise<Data>;
129
+
130
+ /**
131
+ * Returns the party which currently fronted the withdrawal transaction
132
+ *
133
+ * @param owner Owner of the vault
134
+ * @param vaultId Vault ID
135
+ * @param withdrawal Withdrawal transaction to check the fronting for
136
+ */
137
+ getFronterAddress(owner: string, vaultId: bigint, withdrawal: WithdrawalTX): Promise<string | null>;
138
+
139
+ /**
140
+ * Returns current vault data
141
+ *
142
+ * @param owner Owner of the vault
143
+ * @param vaultId Vault ID
144
+ */
145
+ getVaultData(owner: string, vaultId: bigint): Promise<Data>;
146
+
147
+ /**
148
+ * Returns all currently opened vaults
149
+ * NOTE: This will take a long time, since the implementation will have to go through all the prior events
150
+ */
151
+ getAllVaults(owner?: string): Promise<Data[]>;
152
+
153
+ /**
154
+ * Returns current state of the withdrawal as specified by the bitcoin transaction ID
155
+ *
156
+ * @param btcTxId
157
+ */
158
+ getWithdrawalState(btcTxId: string): Promise<SpvWithdrawalState>;
159
+
160
+ /**
161
+ * Parses withdrawal data from the parsed bitcoin transaction
162
+ *
163
+ * @param btcTx
164
+ */
165
+ getWithdrawalData(btcTx: BtcTx): Promise<WithdrawalTX>;
166
+
167
+ /**
168
+ * Checks if given withdrawal tx is valid and correctly parses on-chain, throws error when there is any issue with
169
+ * the validation
170
+ *
171
+ * @param tx
172
+ */
173
+ checkWithdrawalTx(tx: WithdrawalTX): Promise<void>;
174
+
175
+ /**
176
+ * Serializes the withdrawal params to the OP_RETURN data
177
+ *
178
+ * @param recipient Recipient of the withdrawn tokens
179
+ * @param rawAmounts Raw amount of tokens to withdraw
180
+ * @param executionHash Optional execution hash of the actions to execute
181
+ */
182
+ toOpReturnData(recipient: string, rawAmounts: bigint[], executionHash?: string): Buffer;
183
+
184
+ /**
185
+ * Parses withdrawal params from OP_RETURN data
186
+ *
187
+ * @param data data as specified in the OP_RETURN output of the transaction
188
+ */
189
+ fromOpReturnData(data: Buffer): {recipient: string, rawAmounts: bigint[], executionHash: string};
190
+
191
+ /**
192
+ * Returns the fee in native token base units to claim the swap
193
+ *
194
+ * @param signer Signer claiming the swap
195
+ * @param vault
196
+ * @param withdrawalData Withdrawal to claim
197
+ * @param feeRate Optional fee rate (fetched on-demand if not provided)
198
+ */
199
+ getClaimFee(signer: string, vault: Data, withdrawalData: WithdrawalTX, feeRate?: string): Promise<bigint>;
200
+
201
+ /**
202
+ * Returns raw fee (not including any refunds we might get that would make the getClaimFee negative) for claiming the swap
203
+ *
204
+ * @param signer Signer claiming the swap
205
+ * @param vault
206
+ * @param withdrawalData Withdrawal to claim
207
+ * @param feeRate Optional fee rate (fetched on-demand if not provided)
208
+ */
209
+ getRawClaimFee?(signer: string, vault: Data, withdrawalData: WithdrawalTX, feeRate?: string): Promise<bigint>;
210
+
211
+ /**
212
+ * Returns the fee in native token base units to claim the swap
213
+ *
214
+ * @param signer Signer claiming the swap
215
+ * @param vault
216
+ * @param withdrawalData Withdrawal to claim
217
+ * @param feeRate Optional fee rate (fetched on-demand if not provided)
218
+ */
219
+ getFrontFee(signer: string, vault: Data, withdrawalData: WithdrawalTX, feeRate?: string): Promise<bigint>;
220
+
221
+ /**
222
+ * Returns raw fee (not including any refunds we might get that would make the getClaimFee negative) for claiming the swap
223
+ *
224
+ * @param signer Signer claiming the swap
225
+ * @param vault
226
+ * @param withdrawalData Withdrawal to claim
227
+ * @param feeRate Optional fee rate (fetched on-demand if not provided)
228
+ */
229
+ getRawFrontFee?(signer: string, vault: Data, withdrawalData: WithdrawalTX, feeRate?: string): Promise<bigint>;
230
+
231
231
  }