@atomiqlabs/base 9.0.0-beta.3 → 9.0.0

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 (119) hide show
  1. package/LICENSE +201 -201
  2. package/dist/btc/BitcoinNetwork.d.ts +5 -5
  3. package/dist/btc/BitcoinNetwork.js +9 -9
  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 +38 -38
  55. package/dist/index.js +54 -54
  56. package/dist/lockable/Lockable.d.ts +6 -6
  57. package/dist/lockable/Lockable.js +28 -28
  58. package/dist/spv_swap/SpvVaultContract.d.ts +187 -187
  59. package/dist/spv_swap/SpvVaultContract.js +2 -2
  60. package/dist/spv_swap/SpvVaultData.d.ts +35 -35
  61. package/dist/spv_swap/SpvVaultData.js +37 -37
  62. package/dist/spv_swap/SpvWithdrawalState.d.ts +31 -31
  63. package/dist/spv_swap/SpvWithdrawalState.js +10 -10
  64. package/dist/spv_swap/SpvWithdrawalTransactionData.d.ts +42 -42
  65. package/dist/spv_swap/SpvWithdrawalTransactionData.js +143 -143
  66. package/dist/storage/IStorageManager.d.ts +15 -15
  67. package/dist/storage/IStorageManager.js +2 -2
  68. package/dist/storage/StorageObject.d.ts +3 -3
  69. package/dist/storage/StorageObject.js +2 -2
  70. package/dist/swaps/ChainSwapType.d.ts +6 -6
  71. package/dist/swaps/ChainSwapType.js +10 -10
  72. package/dist/swaps/SwapCommitStatus.d.ts +7 -7
  73. package/dist/swaps/SwapCommitStatus.js +11 -11
  74. package/dist/swaps/SwapContract.d.ts +461 -461
  75. package/dist/swaps/SwapContract.js +2 -2
  76. package/dist/swaps/SwapData.d.ts +36 -36
  77. package/dist/swaps/SwapData.js +12 -12
  78. package/dist/utils/BigIntBufferUtils.d.ts +6 -6
  79. package/dist/utils/BigIntBufferUtils.js +31 -31
  80. package/package.json +31 -31
  81. package/src/btc/BitcoinNetwork.ts +5 -5
  82. package/src/btc/rpc/BitcoinRpc.ts +77 -77
  83. package/src/btcrelay/BtcRelay.ts +70 -70
  84. package/src/btcrelay/synchronizer/RelaySynchronizer.ts +17 -17
  85. package/src/btcrelay/types/BtcBlock.ts +15 -15
  86. package/src/btcrelay/types/BtcHeader.ts +11 -11
  87. package/src/btcrelay/types/BtcStoredHeader.ts +12 -12
  88. package/src/btcrelay/utils/StatePredictorUtils.ts +108 -108
  89. package/src/chains/ChainData.ts +40 -40
  90. package/src/chains/ChainInterface.ts +132 -132
  91. package/src/chains/ChainType.ts +38 -38
  92. package/src/errors/CannotInitializeATAError.ts +11 -11
  93. package/src/errors/SignatureVerificationError.ts +11 -11
  94. package/src/errors/SwapDataVerificationError.ts +11 -11
  95. package/src/events/ChainEvents.ts +13 -13
  96. package/src/events/types/ChainEvent.ts +10 -10
  97. package/src/events/types/spv_vault/SpvVaultClaimEvent.ts +31 -31
  98. package/src/events/types/spv_vault/SpvVaultCloseEvent.ts +17 -17
  99. package/src/events/types/spv_vault/SpvVaultDepositEvent.ts +17 -17
  100. package/src/events/types/spv_vault/SpvVaultEvent.ts +25 -25
  101. package/src/events/types/spv_vault/SpvVaultFrontEvent.ts +27 -27
  102. package/src/events/types/spv_vault/SpvVaultOpenEvent.ts +16 -16
  103. package/src/events/types/swap/ClaimEvent.ts +15 -15
  104. package/src/events/types/swap/InitializeEvent.ts +18 -18
  105. package/src/events/types/swap/RefundEvent.ts +6 -6
  106. package/src/events/types/swap/SwapEvent.ts +21 -21
  107. package/src/index.ts +46 -46
  108. package/src/lockable/Lockable.ts +30 -30
  109. package/src/spv_swap/SpvVaultContract.ts +217 -217
  110. package/src/spv_swap/SpvVaultData.ts +70 -70
  111. package/src/spv_swap/SpvWithdrawalState.ts +40 -40
  112. package/src/spv_swap/SpvWithdrawalTransactionData.ts +167 -167
  113. package/src/storage/IStorageManager.ts +16 -16
  114. package/src/storage/StorageObject.ts +6 -6
  115. package/src/swaps/ChainSwapType.ts +6 -6
  116. package/src/swaps/SwapCommitStatus.ts +8 -8
  117. package/src/swaps/SwapContract.ts +550 -550
  118. package/src/swaps/SwapData.ts +64 -64
  119. package/src/utils/BigIntBufferUtils.ts +31 -31
@@ -1,187 +1,187 @@
1
- /// <reference types="node" />
2
- import { AbstractSigner, TransactionConfirmationOptions } from "../chains/ChainInterface";
3
- import { SpvVaultData, SpvVaultTokenData } from "./SpvVaultData";
4
- import { SpvWithdrawalTransactionData } from "./SpvWithdrawalTransactionData";
5
- import { BtcStoredHeader } from "../btcrelay/types/BtcStoredHeader";
6
- import { RelaySynchronizer } from "../btcrelay/synchronizer/RelaySynchronizer";
7
- import { SpvWithdrawalState } from "./SpvWithdrawalState";
8
- import { Buffer } from "buffer";
9
- import { BtcTx } from "../btc/rpc/BitcoinRpc";
10
- export interface SpvVaultContract<TX = any, Signer extends AbstractSigner = AbstractSigner, ChainId extends string = string, Data extends SpvVaultData = SpvVaultData, WithdrawalTX extends SpvWithdrawalTransactionData = SpvWithdrawalTransactionData> {
11
- readonly chainId: ChainId;
12
- /**
13
- * Signs & sends transactions for opening a specific spv vault
14
- *
15
- * @param signer Signer to use for the transaction (must match owner in vault)
16
- * @param vault Vault to init
17
- * @param txOptions Transaction options
18
- */
19
- open(signer: Signer, vault: Data, txOptions?: TransactionConfirmationOptions): Promise<string>;
20
- /**
21
- * Returns the unsigned transactions for opening a specific spv vault
22
- *
23
- * @param signer Signer to use for the transaction (must match owner in vault)
24
- * @param vault Vault to init
25
- * @param feeRate Fee rate to use for the transaction
26
- */
27
- txsOpen(signer: string, vault: Data, feeRate?: string): Promise<TX[]>;
28
- /**
29
- * Signs & sends transactions for depositing funds to a specific spv vault
30
- *
31
- * @param signer Signer to use for the transaction (can be any)
32
- * @param vault Vault to deposit to
33
- * @param rawAmounts Raw amounts to deposit (these are unscaled)
34
- * @param txOptions Transaction options
35
- */
36
- deposit(signer: Signer, vault: Data, rawAmounts: bigint[], txOptions?: TransactionConfirmationOptions): Promise<string>;
37
- /**
38
- * Returns the unsigned transactions for depositing funds to a specific spv vault
39
- *
40
- * @param signer Signer to use for the transaction (can be any)
41
- * @param vault Vault to deposit to
42
- * @param rawAmounts Raw amounts to deposit (these are unscaled)
43
- * @param feeRate Fee rate to use for the transaction
44
- */
45
- txsDeposit(signer: string, vault: Data, rawAmounts: bigint[], feeRate?: string): Promise<TX[]>;
46
- /**
47
- * Signs & sends transactions for fronting liquidity for a specific withdrawal btc transaction
48
- *
49
- * @param signer Signer to use for the transaction (payer of the fronted liquidity)
50
- * @param vault Vault to deposit to
51
- * @param realWithdrawalTx Real withdrawal transaction data
52
- * @param withdrawSequence Sequence number of the withdrawal that is being fronted, this used as race condition
53
- * prevention, such that fronting will not happen if the withdrawal tx is already used in claim()
54
- * @param txOptions Transaction options
55
- */
56
- frontLiquidity(signer: Signer, vault: Data, realWithdrawalTx: WithdrawalTX, withdrawSequence: number, txOptions?: TransactionConfirmationOptions): Promise<string>;
57
- /**
58
- * Returns the unsigned transactions for fronting liquidity for a specific withdrawal btc transaction
59
- *
60
- * @param signer Signer to use for the transaction (payer of the fronted liquidity)
61
- * @param vault Vault to deposit to
62
- * @param realWithdrawalTx Real withdrawal transaction data
63
- * @param withdrawSequence Sequence number of the withdrawal that is being fronted, this used as race condition
64
- * prevention, such that fronting will not happen if the withdrawal tx is already used in claim()
65
- * @param feeRate Fee rate to use for the transaction
66
- */
67
- txsFrontLiquidity(signer: string, vault: Data, realWithdrawalTx: WithdrawalTX, withdrawSequence: number, feeRate?: string): Promise<TX[]>;
68
- /**
69
- * Signs & sends transactions for claiming the funds from a specific vault
70
- *
71
- * @param signer Signer to use for the transaction
72
- * @param vault Vault to claim from
73
- * @param txs
74
- * @param synchronizer Optiona synchronizer to be used if BTC relay contract is not synced up to the required blockheight
75
- * @param initAta Whether to initialize a token account if it doesn't exist (applies to e.g. Solana, with token specific ATAs)
76
- * @param txOptions Transaction options
77
- */
78
- claim(signer: Signer, vault: Data, txs: {
79
- tx: WithdrawalTX;
80
- storedHeader?: BtcStoredHeader<any>;
81
- }[], synchronizer?: RelaySynchronizer<any, TX, any>, initAta?: boolean, txOptions?: TransactionConfirmationOptions): Promise<string>;
82
- /**
83
- * Returns the unsigned transactions for claiming the funds from a specific vault
84
- *
85
- * @param signer Signer to use for the transaction
86
- * @param vault Vault to claim from
87
- * @param txs
88
- * @param synchronizer Optiona synchronizer to be used if BTC relay contract is not synced up to the required blockheight
89
- * @param initAta Whether to initialize a token account if it doesn't exist (applies to e.g. Solana, with token specific ATAs)
90
- * @param feeRate Fee rate to use for the transaction
91
- */
92
- txsClaim(signer: string, vault: Data, txs: {
93
- tx: WithdrawalTX;
94
- storedHeader?: BtcStoredHeader<any>;
95
- }[], synchronizer?: RelaySynchronizer<any, TX, any>, initAta?: boolean, feeRate?: string): Promise<TX[]>;
96
- /**
97
- * Creates vault data for a new vault
98
- *
99
- * @param owner Vault owner
100
- * @param vaultId Vault ID
101
- * @param utxo Utxo on which to assign the vault initially
102
- * @param confirmations Required number of bitcoin confirmations to be able to withdraw funds from the vault
103
- * @param tokenData Data about the tokens in the vault
104
- */
105
- createVaultData(owner: string, vaultId: bigint, utxo: string, confirmations: number, tokenData: SpvVaultTokenData[]): Promise<Data>;
106
- /**
107
- * Returns current vault data
108
- *
109
- * @param owner Owner of the vault
110
- * @param vaultId Vault ID
111
- */
112
- getVaultData(owner: string, vaultId: bigint): Promise<Data>;
113
- /**
114
- * Returns all currently opened vaults
115
- * NOTE: This will take a long time, since the implementation will have to go through all the prior events
116
- */
117
- getAllVaults(owner?: string): Promise<Data[]>;
118
- /**
119
- * Returns current state of the withdrawal as specified by the bitcoin transaction ID
120
- *
121
- * @param btcTxId
122
- */
123
- getWithdrawalState(btcTxId: string): Promise<SpvWithdrawalState>;
124
- /**
125
- * Parses withdrawal data from the parsed bitcoin transaction
126
- *
127
- * @param btcTx
128
- */
129
- getWithdrawalData(btcTx: BtcTx): Promise<WithdrawalTX>;
130
- /**
131
- * Checks if given withdrawal tx is valid and correctly parses on-chain, throws error when there is any issue with
132
- * the validation
133
- *
134
- * @param tx
135
- */
136
- checkWithdrawalTx(tx: WithdrawalTX): Promise<void>;
137
- /**
138
- * Serializes the withdrawal params to the OP_RETURN data
139
- *
140
- * @param recipient Recipient of the withdrawn tokens
141
- * @param rawAmounts Raw amount of tokens to withdraw
142
- * @param executionHash Optional execution hash of the actions to execute
143
- */
144
- toOpReturnData(recipient: string, rawAmounts: bigint[], executionHash?: string): Buffer;
145
- /**
146
- * Parses withdrawal params from OP_RETURN data
147
- *
148
- * @param data data as specified in the OP_RETURN output of the transaction
149
- */
150
- fromOpReturnData(data: Buffer): {
151
- recipient: string;
152
- rawAmounts: bigint[];
153
- executionHash: string;
154
- };
155
- /**
156
- * Returns the fee in native token base units to claim the swap
157
- *
158
- * @param signer Signer claiming the swap
159
- * @param withdrawalData Withdrawal to claim
160
- * @param feeRate Optional fee rate (fetched on-demand if not provided)
161
- */
162
- getClaimFee(signer: string, withdrawalData: WithdrawalTX, feeRate?: string): Promise<bigint>;
163
- /**
164
- * Returns raw fee (not including any refunds we might get that would make the getClaimFee negative) for claiming the swap
165
- *
166
- * @param signer Signer claiming the swap
167
- * @param withdrawalData Withdrawal to claim
168
- * @param feeRate Optional fee rate (fetched on-demand if not provided)
169
- */
170
- getRawClaimFee?(signer: string, withdrawalData: WithdrawalTX, feeRate?: string): Promise<bigint>;
171
- /**
172
- * Returns the fee in native token base units to claim the swap
173
- *
174
- * @param signer Signer claiming the swap
175
- * @param withdrawalData Withdrawal to claim
176
- * @param feeRate Optional fee rate (fetched on-demand if not provided)
177
- */
178
- getFrontFee(signer: string, withdrawalData: WithdrawalTX, feeRate?: string): Promise<bigint>;
179
- /**
180
- * Returns raw fee (not including any refunds we might get that would make the getClaimFee negative) for claiming the swap
181
- *
182
- * @param signer Signer claiming the swap
183
- * @param withdrawalData Withdrawal to claim
184
- * @param feeRate Optional fee rate (fetched on-demand if not provided)
185
- */
186
- getRawFrontFee?(signer: string, withdrawalData: WithdrawalTX, feeRate?: string): Promise<bigint>;
187
- }
1
+ /// <reference types="node" />
2
+ import { AbstractSigner, TransactionConfirmationOptions } from "../chains/ChainInterface";
3
+ import { SpvVaultData, SpvVaultTokenData } from "./SpvVaultData";
4
+ import { SpvWithdrawalTransactionData } from "./SpvWithdrawalTransactionData";
5
+ import { BtcStoredHeader } from "../btcrelay/types/BtcStoredHeader";
6
+ import { RelaySynchronizer } from "../btcrelay/synchronizer/RelaySynchronizer";
7
+ import { SpvWithdrawalState } from "./SpvWithdrawalState";
8
+ import { Buffer } from "buffer";
9
+ import { BtcTx } from "../btc/rpc/BitcoinRpc";
10
+ export interface SpvVaultContract<TX = any, Signer extends AbstractSigner = AbstractSigner, ChainId extends string = string, Data extends SpvVaultData = SpvVaultData, WithdrawalTX extends SpvWithdrawalTransactionData = SpvWithdrawalTransactionData> {
11
+ readonly chainId: ChainId;
12
+ /**
13
+ * Signs & sends transactions for opening a specific spv vault
14
+ *
15
+ * @param signer Signer to use for the transaction (must match owner in vault)
16
+ * @param vault Vault to init
17
+ * @param txOptions Transaction options
18
+ */
19
+ open(signer: Signer, vault: Data, txOptions?: TransactionConfirmationOptions): Promise<string>;
20
+ /**
21
+ * Returns the unsigned transactions for opening a specific spv vault
22
+ *
23
+ * @param signer Signer to use for the transaction (must match owner in vault)
24
+ * @param vault Vault to init
25
+ * @param feeRate Fee rate to use for the transaction
26
+ */
27
+ txsOpen(signer: string, vault: Data, feeRate?: string): Promise<TX[]>;
28
+ /**
29
+ * Signs & sends transactions for depositing funds to a specific spv vault
30
+ *
31
+ * @param signer Signer to use for the transaction (can be any)
32
+ * @param vault Vault to deposit to
33
+ * @param rawAmounts Raw amounts to deposit (these are unscaled)
34
+ * @param txOptions Transaction options
35
+ */
36
+ deposit(signer: Signer, vault: Data, rawAmounts: bigint[], txOptions?: TransactionConfirmationOptions): Promise<string>;
37
+ /**
38
+ * Returns the unsigned transactions for depositing funds to a specific spv vault
39
+ *
40
+ * @param signer Signer to use for the transaction (can be any)
41
+ * @param vault Vault to deposit to
42
+ * @param rawAmounts Raw amounts to deposit (these are unscaled)
43
+ * @param feeRate Fee rate to use for the transaction
44
+ */
45
+ txsDeposit(signer: string, vault: Data, rawAmounts: bigint[], feeRate?: string): Promise<TX[]>;
46
+ /**
47
+ * Signs & sends transactions for fronting liquidity for a specific withdrawal btc transaction
48
+ *
49
+ * @param signer Signer to use for the transaction (payer of the fronted liquidity)
50
+ * @param vault Vault to deposit to
51
+ * @param realWithdrawalTx Real withdrawal transaction data
52
+ * @param withdrawSequence Sequence number of the withdrawal that is being fronted, this used as race condition
53
+ * prevention, such that fronting will not happen if the withdrawal tx is already used in claim()
54
+ * @param txOptions Transaction options
55
+ */
56
+ frontLiquidity(signer: Signer, vault: Data, realWithdrawalTx: WithdrawalTX, withdrawSequence: number, txOptions?: TransactionConfirmationOptions): Promise<string>;
57
+ /**
58
+ * Returns the unsigned transactions for fronting liquidity for a specific withdrawal btc transaction
59
+ *
60
+ * @param signer Signer to use for the transaction (payer of the fronted liquidity)
61
+ * @param vault Vault to deposit to
62
+ * @param realWithdrawalTx Real withdrawal transaction data
63
+ * @param withdrawSequence Sequence number of the withdrawal that is being fronted, this used as race condition
64
+ * prevention, such that fronting will not happen if the withdrawal tx is already used in claim()
65
+ * @param feeRate Fee rate to use for the transaction
66
+ */
67
+ txsFrontLiquidity(signer: string, vault: Data, realWithdrawalTx: WithdrawalTX, withdrawSequence: number, feeRate?: string): Promise<TX[]>;
68
+ /**
69
+ * Signs & sends transactions for claiming the funds from a specific vault
70
+ *
71
+ * @param signer Signer to use for the transaction
72
+ * @param vault Vault to claim from
73
+ * @param txs
74
+ * @param synchronizer Optiona synchronizer to be used if BTC relay contract is not synced up to the required blockheight
75
+ * @param initAta Whether to initialize a token account if it doesn't exist (applies to e.g. Solana, with token specific ATAs)
76
+ * @param txOptions Transaction options
77
+ */
78
+ claim(signer: Signer, vault: Data, txs: {
79
+ tx: WithdrawalTX;
80
+ storedHeader?: BtcStoredHeader<any>;
81
+ }[], synchronizer?: RelaySynchronizer<any, TX, any>, initAta?: boolean, txOptions?: TransactionConfirmationOptions): Promise<string>;
82
+ /**
83
+ * Returns the unsigned transactions for claiming the funds from a specific vault
84
+ *
85
+ * @param signer Signer to use for the transaction
86
+ * @param vault Vault to claim from
87
+ * @param txs
88
+ * @param synchronizer Optiona synchronizer to be used if BTC relay contract is not synced up to the required blockheight
89
+ * @param initAta Whether to initialize a token account if it doesn't exist (applies to e.g. Solana, with token specific ATAs)
90
+ * @param feeRate Fee rate to use for the transaction
91
+ */
92
+ txsClaim(signer: string, vault: Data, txs: {
93
+ tx: WithdrawalTX;
94
+ storedHeader?: BtcStoredHeader<any>;
95
+ }[], synchronizer?: RelaySynchronizer<any, TX, any>, initAta?: boolean, feeRate?: string): Promise<TX[]>;
96
+ /**
97
+ * Creates vault data for a new vault
98
+ *
99
+ * @param owner Vault owner
100
+ * @param vaultId Vault ID
101
+ * @param utxo Utxo on which to assign the vault initially
102
+ * @param confirmations Required number of bitcoin confirmations to be able to withdraw funds from the vault
103
+ * @param tokenData Data about the tokens in the vault
104
+ */
105
+ createVaultData(owner: string, vaultId: bigint, utxo: string, confirmations: number, tokenData: SpvVaultTokenData[]): Promise<Data>;
106
+ /**
107
+ * Returns current vault data
108
+ *
109
+ * @param owner Owner of the vault
110
+ * @param vaultId Vault ID
111
+ */
112
+ getVaultData(owner: string, vaultId: bigint): Promise<Data>;
113
+ /**
114
+ * Returns all currently opened vaults
115
+ * NOTE: This will take a long time, since the implementation will have to go through all the prior events
116
+ */
117
+ getAllVaults(owner?: string): Promise<Data[]>;
118
+ /**
119
+ * Returns current state of the withdrawal as specified by the bitcoin transaction ID
120
+ *
121
+ * @param btcTxId
122
+ */
123
+ getWithdrawalState(btcTxId: string): Promise<SpvWithdrawalState>;
124
+ /**
125
+ * Parses withdrawal data from the parsed bitcoin transaction
126
+ *
127
+ * @param btcTx
128
+ */
129
+ getWithdrawalData(btcTx: BtcTx): Promise<WithdrawalTX>;
130
+ /**
131
+ * Checks if given withdrawal tx is valid and correctly parses on-chain, throws error when there is any issue with
132
+ * the validation
133
+ *
134
+ * @param tx
135
+ */
136
+ checkWithdrawalTx(tx: WithdrawalTX): Promise<void>;
137
+ /**
138
+ * Serializes the withdrawal params to the OP_RETURN data
139
+ *
140
+ * @param recipient Recipient of the withdrawn tokens
141
+ * @param rawAmounts Raw amount of tokens to withdraw
142
+ * @param executionHash Optional execution hash of the actions to execute
143
+ */
144
+ toOpReturnData(recipient: string, rawAmounts: bigint[], executionHash?: string): Buffer;
145
+ /**
146
+ * Parses withdrawal params from OP_RETURN data
147
+ *
148
+ * @param data data as specified in the OP_RETURN output of the transaction
149
+ */
150
+ fromOpReturnData(data: Buffer): {
151
+ recipient: string;
152
+ rawAmounts: bigint[];
153
+ executionHash: string;
154
+ };
155
+ /**
156
+ * Returns the fee in native token base units to claim the swap
157
+ *
158
+ * @param signer Signer claiming the swap
159
+ * @param withdrawalData Withdrawal to claim
160
+ * @param feeRate Optional fee rate (fetched on-demand if not provided)
161
+ */
162
+ getClaimFee(signer: string, withdrawalData: WithdrawalTX, feeRate?: string): Promise<bigint>;
163
+ /**
164
+ * Returns raw fee (not including any refunds we might get that would make the getClaimFee negative) for claiming the swap
165
+ *
166
+ * @param signer Signer claiming the swap
167
+ * @param withdrawalData Withdrawal to claim
168
+ * @param feeRate Optional fee rate (fetched on-demand if not provided)
169
+ */
170
+ getRawClaimFee?(signer: string, withdrawalData: WithdrawalTX, feeRate?: string): Promise<bigint>;
171
+ /**
172
+ * Returns the fee in native token base units to claim the swap
173
+ *
174
+ * @param signer Signer claiming the swap
175
+ * @param withdrawalData Withdrawal to claim
176
+ * @param feeRate Optional fee rate (fetched on-demand if not provided)
177
+ */
178
+ getFrontFee(signer: string, withdrawalData: WithdrawalTX, feeRate?: string): Promise<bigint>;
179
+ /**
180
+ * Returns raw fee (not including any refunds we might get that would make the getClaimFee negative) for claiming the swap
181
+ *
182
+ * @param signer Signer claiming the swap
183
+ * @param withdrawalData Withdrawal to claim
184
+ * @param feeRate Optional fee rate (fetched on-demand if not provided)
185
+ */
186
+ getRawFrontFee?(signer: string, withdrawalData: WithdrawalTX, feeRate?: string): Promise<bigint>;
187
+ }
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,35 +1,35 @@
1
- import { StorageObject } from "../storage/StorageObject";
2
- import { SpvWithdrawalTransactionData } from "./SpvWithdrawalTransactionData";
3
- import { SpvVaultClaimEvent } from "../events/types/spv_vault/SpvVaultClaimEvent";
4
- import { SpvVaultCloseEvent } from "../events/types/spv_vault/SpvVaultCloseEvent";
5
- import { SpvVaultOpenEvent } from "../events/types/spv_vault/SpvVaultOpenEvent";
6
- import { SpvVaultDepositEvent } from "../events/types/spv_vault/SpvVaultDepositEvent";
7
- export type SpvVaultTokenBalance = SpvVaultTokenData & {
8
- rawAmount: bigint;
9
- scaledAmount: bigint;
10
- };
11
- export type SpvVaultTokenData = {
12
- token: string;
13
- multiplier: bigint;
14
- };
15
- export declare abstract class SpvVaultData<T extends SpvWithdrawalTransactionData = SpvWithdrawalTransactionData> implements StorageObject {
16
- static deserializers: {
17
- [type: string]: new (serialized: any) => any;
18
- };
19
- static deserialize<T extends SpvVaultData>(data: any): T;
20
- abstract serialize(): any;
21
- abstract getOwner(): string;
22
- abstract getVaultId(): bigint;
23
- abstract getTokenData(): SpvVaultTokenData[];
24
- abstract getBalances(): SpvVaultTokenBalance[];
25
- abstract getUtxo(): string;
26
- abstract getConfirmations(): number;
27
- abstract getWithdrawalCount(): number;
28
- abstract getDepositCount(): number;
29
- abstract isOpened(): boolean;
30
- abstract updateState(withdrawalTxOrEvent: T | SpvVaultClaimEvent | SpvVaultCloseEvent | SpvVaultOpenEvent | SpvVaultDepositEvent): void;
31
- calculateStateAfter(priorWithdrawalTxs: T[]): {
32
- withdrawalCount: number;
33
- balances: SpvVaultTokenBalance[];
34
- };
35
- }
1
+ import { StorageObject } from "../storage/StorageObject";
2
+ import { SpvWithdrawalTransactionData } from "./SpvWithdrawalTransactionData";
3
+ import { SpvVaultClaimEvent } from "../events/types/spv_vault/SpvVaultClaimEvent";
4
+ import { SpvVaultCloseEvent } from "../events/types/spv_vault/SpvVaultCloseEvent";
5
+ import { SpvVaultOpenEvent } from "../events/types/spv_vault/SpvVaultOpenEvent";
6
+ import { SpvVaultDepositEvent } from "../events/types/spv_vault/SpvVaultDepositEvent";
7
+ export type SpvVaultTokenBalance = SpvVaultTokenData & {
8
+ rawAmount: bigint;
9
+ scaledAmount: bigint;
10
+ };
11
+ export type SpvVaultTokenData = {
12
+ token: string;
13
+ multiplier: bigint;
14
+ };
15
+ export declare abstract class SpvVaultData<T extends SpvWithdrawalTransactionData = SpvWithdrawalTransactionData> implements StorageObject {
16
+ static deserializers: {
17
+ [type: string]: new (serialized: any) => any;
18
+ };
19
+ static deserialize<T extends SpvVaultData>(data: any): T;
20
+ abstract serialize(): any;
21
+ abstract getOwner(): string;
22
+ abstract getVaultId(): bigint;
23
+ abstract getTokenData(): SpvVaultTokenData[];
24
+ abstract getBalances(): SpvVaultTokenBalance[];
25
+ abstract getUtxo(): string;
26
+ abstract getConfirmations(): number;
27
+ abstract getWithdrawalCount(): number;
28
+ abstract getDepositCount(): number;
29
+ abstract isOpened(): boolean;
30
+ abstract updateState(withdrawalTxOrEvent: T | SpvVaultClaimEvent | SpvVaultCloseEvent | SpvVaultOpenEvent | SpvVaultDepositEvent): void;
31
+ calculateStateAfter(priorWithdrawalTxs: T[]): {
32
+ withdrawalCount: number;
33
+ balances: SpvVaultTokenBalance[];
34
+ };
35
+ }
@@ -1,37 +1,37 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SpvVaultData = void 0;
4
- class SpvVaultData {
5
- static deserialize(data) {
6
- if (SpvVaultData.deserializers[data.type] != null) {
7
- return new SpvVaultData.deserializers[data.type](data);
8
- }
9
- }
10
- calculateStateAfter(priorWithdrawalTxs) {
11
- const balances = [...this.getBalances()];
12
- let withdrawalCount = this.getWithdrawalCount();
13
- let utxo = this.getUtxo();
14
- for (let withdrawalTx of priorWithdrawalTxs) {
15
- if (withdrawalTx.getSpentVaultUtxo() !== utxo)
16
- throw new Error("Invalid transaction, doesn't spend prior vault UTXO!");
17
- withdrawalTx.getTotalOutput().forEach((value, i) => {
18
- if (balances[i] == null)
19
- throw new Error("Tried to withdraw non-existing token!");
20
- balances[i].rawAmount -= value;
21
- if (balances[i].rawAmount < 0n)
22
- throw new Error("Prior transaction withdrew more than available in vault");
23
- });
24
- utxo = withdrawalTx.getCreatedVaultUtxo();
25
- withdrawalCount++;
26
- }
27
- balances.forEach(balance => {
28
- balance.scaledAmount = balance.rawAmount * balance.multiplier;
29
- });
30
- return {
31
- withdrawalCount,
32
- balances
33
- };
34
- }
35
- }
36
- exports.SpvVaultData = SpvVaultData;
37
- SpvVaultData.deserializers = {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SpvVaultData = void 0;
4
+ class SpvVaultData {
5
+ static deserialize(data) {
6
+ if (SpvVaultData.deserializers[data.type] != null) {
7
+ return new SpvVaultData.deserializers[data.type](data);
8
+ }
9
+ }
10
+ calculateStateAfter(priorWithdrawalTxs) {
11
+ const balances = [...this.getBalances()];
12
+ let withdrawalCount = this.getWithdrawalCount();
13
+ let utxo = this.getUtxo();
14
+ for (let withdrawalTx of priorWithdrawalTxs) {
15
+ if (withdrawalTx.getSpentVaultUtxo() !== utxo)
16
+ throw new Error("Invalid transaction, doesn't spend prior vault UTXO!");
17
+ withdrawalTx.getTotalOutput().forEach((value, i) => {
18
+ if (balances[i] == null)
19
+ throw new Error("Tried to withdraw non-existing token!");
20
+ balances[i].rawAmount -= value;
21
+ if (balances[i].rawAmount < 0n)
22
+ throw new Error("Prior transaction withdrew more than available in vault");
23
+ });
24
+ utxo = withdrawalTx.getCreatedVaultUtxo();
25
+ withdrawalCount++;
26
+ }
27
+ balances.forEach(balance => {
28
+ balance.scaledAmount = balance.rawAmount * balance.multiplier;
29
+ });
30
+ return {
31
+ withdrawalCount,
32
+ balances
33
+ };
34
+ }
35
+ }
36
+ exports.SpvVaultData = SpvVaultData;
37
+ SpvVaultData.deserializers = {};
@@ -1,31 +1,31 @@
1
- export declare enum SpvWithdrawalStateType {
2
- CLOSED = -1,
3
- NOT_FOUND = 0,
4
- CLAIMED = 1,
5
- FRONTED = 2
6
- }
7
- export type SpvWithdrawalNotFoundState = {
8
- type: SpvWithdrawalStateType.NOT_FOUND;
9
- };
10
- type SpvWithdrawalStateCommon = {
11
- txId: string;
12
- owner: string;
13
- vaultId: bigint;
14
- };
15
- export type SpvWithdrawalClaimedState = {
16
- type: SpvWithdrawalStateType.CLAIMED;
17
- recipient: string;
18
- claimer: string;
19
- fronter: string;
20
- } & SpvWithdrawalStateCommon;
21
- export type SpvWithdrawalFrontedState = {
22
- type: SpvWithdrawalStateType.FRONTED;
23
- recipient: string;
24
- fronter: string;
25
- } & SpvWithdrawalStateCommon;
26
- export type SpvWithdrawalClosedState = {
27
- type: SpvWithdrawalStateType.CLOSED;
28
- error: string;
29
- } & SpvWithdrawalStateCommon;
30
- export type SpvWithdrawalState = SpvWithdrawalNotFoundState | SpvWithdrawalClaimedState | SpvWithdrawalFrontedState | SpvWithdrawalClosedState;
31
- export {};
1
+ export declare enum SpvWithdrawalStateType {
2
+ CLOSED = -1,
3
+ NOT_FOUND = 0,
4
+ CLAIMED = 1,
5
+ FRONTED = 2
6
+ }
7
+ export type SpvWithdrawalNotFoundState = {
8
+ type: SpvWithdrawalStateType.NOT_FOUND;
9
+ };
10
+ type SpvWithdrawalStateCommon = {
11
+ txId: string;
12
+ owner: string;
13
+ vaultId: bigint;
14
+ };
15
+ export type SpvWithdrawalClaimedState = {
16
+ type: SpvWithdrawalStateType.CLAIMED;
17
+ recipient: string;
18
+ claimer: string;
19
+ fronter: string;
20
+ } & SpvWithdrawalStateCommon;
21
+ export type SpvWithdrawalFrontedState = {
22
+ type: SpvWithdrawalStateType.FRONTED;
23
+ recipient: string;
24
+ fronter: string;
25
+ } & SpvWithdrawalStateCommon;
26
+ export type SpvWithdrawalClosedState = {
27
+ type: SpvWithdrawalStateType.CLOSED;
28
+ error: string;
29
+ } & SpvWithdrawalStateCommon;
30
+ export type SpvWithdrawalState = SpvWithdrawalNotFoundState | SpvWithdrawalClaimedState | SpvWithdrawalFrontedState | SpvWithdrawalClosedState;
31
+ export {};
@@ -1,10 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SpvWithdrawalStateType = void 0;
4
- var SpvWithdrawalStateType;
5
- (function (SpvWithdrawalStateType) {
6
- SpvWithdrawalStateType[SpvWithdrawalStateType["CLOSED"] = -1] = "CLOSED";
7
- SpvWithdrawalStateType[SpvWithdrawalStateType["NOT_FOUND"] = 0] = "NOT_FOUND";
8
- SpvWithdrawalStateType[SpvWithdrawalStateType["CLAIMED"] = 1] = "CLAIMED";
9
- SpvWithdrawalStateType[SpvWithdrawalStateType["FRONTED"] = 2] = "FRONTED";
10
- })(SpvWithdrawalStateType = exports.SpvWithdrawalStateType || (exports.SpvWithdrawalStateType = {}));
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SpvWithdrawalStateType = void 0;
4
+ var SpvWithdrawalStateType;
5
+ (function (SpvWithdrawalStateType) {
6
+ SpvWithdrawalStateType[SpvWithdrawalStateType["CLOSED"] = -1] = "CLOSED";
7
+ SpvWithdrawalStateType[SpvWithdrawalStateType["NOT_FOUND"] = 0] = "NOT_FOUND";
8
+ SpvWithdrawalStateType[SpvWithdrawalStateType["CLAIMED"] = 1] = "CLAIMED";
9
+ SpvWithdrawalStateType[SpvWithdrawalStateType["FRONTED"] = 2] = "FRONTED";
10
+ })(SpvWithdrawalStateType = exports.SpvWithdrawalStateType || (exports.SpvWithdrawalStateType = {}));