@atomiqlabs/chain-solana 7.3.8 → 8.0.0-beta.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 (57) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +1 -0
  3. package/dist/solana/SolanaChains.d.ts +14 -0
  4. package/dist/solana/SolanaChains.js +18 -0
  5. package/dist/solana/SolanaInitializer.d.ts +18 -0
  6. package/dist/solana/SolanaInitializer.js +59 -0
  7. package/dist/solana/base/SolanaAction.js +25 -38
  8. package/dist/solana/base/modules/SolanaBlocks.js +18 -29
  9. package/dist/solana/base/modules/SolanaEvents.js +15 -26
  10. package/dist/solana/base/modules/SolanaFees.d.ts +4 -5
  11. package/dist/solana/base/modules/SolanaFees.js +168 -182
  12. package/dist/solana/base/modules/SolanaSlots.js +16 -29
  13. package/dist/solana/base/modules/SolanaTokens.d.ts +6 -7
  14. package/dist/solana/base/modules/SolanaTokens.js +63 -84
  15. package/dist/solana/base/modules/SolanaTransactions.d.ts +2 -2
  16. package/dist/solana/base/modules/SolanaTransactions.js +143 -165
  17. package/dist/solana/btcrelay/SolanaBtcRelay.d.ts +2 -3
  18. package/dist/solana/btcrelay/SolanaBtcRelay.js +185 -221
  19. package/dist/solana/events/SolanaChainEvents.js +113 -138
  20. package/dist/solana/events/SolanaChainEventsBrowser.js +56 -65
  21. package/dist/solana/program/modules/SolanaProgramEvents.js +13 -24
  22. package/dist/solana/swaps/SolanaSwapData.d.ts +15 -11
  23. package/dist/solana/swaps/SolanaSwapData.js +29 -13
  24. package/dist/solana/swaps/SolanaSwapProgram.d.ts +40 -41
  25. package/dist/solana/swaps/SolanaSwapProgram.js +212 -221
  26. package/dist/solana/swaps/modules/SolanaDataAccount.d.ts +2 -3
  27. package/dist/solana/swaps/modules/SolanaDataAccount.js +117 -141
  28. package/dist/solana/swaps/modules/SolanaLpVault.d.ts +4 -5
  29. package/dist/solana/swaps/modules/SolanaLpVault.js +87 -110
  30. package/dist/solana/swaps/modules/SwapClaim.d.ts +4 -4
  31. package/dist/solana/swaps/modules/SwapClaim.js +122 -134
  32. package/dist/solana/swaps/modules/SwapInit.d.ts +2 -3
  33. package/dist/solana/swaps/modules/SwapInit.js +254 -285
  34. package/dist/solana/swaps/modules/SwapRefund.d.ts +2 -3
  35. package/dist/solana/swaps/modules/SwapRefund.js +103 -113
  36. package/dist/utils/Utils.d.ts +10 -0
  37. package/dist/utils/Utils.js +62 -35
  38. package/package.json +9 -6
  39. package/src/index.ts +1 -0
  40. package/src/solana/SolanaChains.ts +16 -0
  41. package/src/solana/SolanaInitializer.ts +98 -0
  42. package/src/solana/base/SolanaBase.ts +1 -2
  43. package/src/solana/base/modules/SolanaEvents.ts +0 -1
  44. package/src/solana/base/modules/SolanaFees.ts +35 -31
  45. package/src/solana/base/modules/SolanaTokens.ts +26 -27
  46. package/src/solana/base/modules/SolanaTransactions.ts +33 -28
  47. package/src/solana/btcrelay/SolanaBtcRelay.ts +6 -10
  48. package/src/solana/events/SolanaChainEventsBrowser.ts +14 -10
  49. package/src/solana/program/modules/SolanaProgramEvents.ts +1 -1
  50. package/src/solana/swaps/SolanaSwapData.ts +38 -19
  51. package/src/solana/swaps/SolanaSwapProgram.ts +133 -105
  52. package/src/solana/swaps/modules/SolanaDataAccount.ts +4 -6
  53. package/src/solana/swaps/modules/SolanaLpVault.ts +18 -18
  54. package/src/solana/swaps/modules/SwapClaim.ts +14 -17
  55. package/src/solana/swaps/modules/SwapInit.ts +35 -38
  56. package/src/solana/swaps/modules/SwapRefund.ts +20 -23
  57. package/src/utils/Utils.ts +35 -0
@@ -7,6 +7,8 @@ const base_1 = require("@atomiqlabs/base");
7
7
  const SwapTypeEnum_1 = require("./SwapTypeEnum");
8
8
  const buffer_1 = require("buffer");
9
9
  const spl_token_1 = require("@solana/spl-token");
10
+ const Utils_1 = require("../../utils/Utils");
11
+ const SolanaTokens_1 = require("../base/modules/SolanaTokens");
10
12
  const EXPIRY_BLOCKHEIGHT_THRESHOLD = new BN("1000000000");
11
13
  class SolanaSwapData extends base_1.SwapData {
12
14
  constructor(offererOrData, claimer, token, amount, paymentHash, sequence, expiry, nonce, confirmations, payOut, kind, payIn, offererAta, claimerAta, securityDeposit, claimerBounty, txoHash) {
@@ -91,7 +93,7 @@ class SolanaSwapData extends base_1.SwapData {
91
93
  };
92
94
  }
93
95
  getAmount() {
94
- return this.amount;
96
+ return (0, Utils_1.toBigInt)(this.amount);
95
97
  }
96
98
  getToken() {
97
99
  return this.token.toString();
@@ -105,13 +107,13 @@ class SolanaSwapData extends base_1.SwapData {
105
107
  getExpiry() {
106
108
  if (this.expiry.lt(EXPIRY_BLOCKHEIGHT_THRESHOLD))
107
109
  return null;
108
- return this.expiry;
110
+ return (0, Utils_1.toBigInt)(this.expiry);
109
111
  }
110
- getConfirmations() {
112
+ getConfirmationsHint() {
111
113
  return this.confirmations;
112
114
  }
113
- getEscrowNonce() {
114
- return this.nonce;
115
+ getNonceHint() {
116
+ return (0, Utils_1.toBigInt)(this.nonce);
115
117
  }
116
118
  isPayIn() {
117
119
  return this.payIn;
@@ -119,26 +121,34 @@ class SolanaSwapData extends base_1.SwapData {
119
121
  isPayOut() {
120
122
  return this.payOut;
121
123
  }
122
- getHash() {
123
- return this.paymentHash;
124
+ getClaimHash() {
125
+ return (0, Utils_1.toClaimHash)(this.paymentHash, (0, Utils_1.toBigInt)(this.nonce), this.confirmations);
126
+ }
127
+ getEscrowHash() {
128
+ return (0, Utils_1.toEscrowHash)(this.paymentHash, this.sequence);
124
129
  }
125
130
  getSequence() {
126
- return this.sequence;
131
+ return (0, Utils_1.toBigInt)(this.sequence);
132
+ }
133
+ getTxoHashHint() {
134
+ if (this.txoHash === "0000000000000000000000000000000000000000000000000000000000000000")
135
+ return null; //Txo hash opt-out flag
136
+ return this.txoHash;
127
137
  }
128
- getTxoHash() {
138
+ getExtraData() {
129
139
  return this.txoHash;
130
140
  }
131
- setTxoHash(txoHash) {
141
+ setExtraData(txoHash) {
132
142
  this.txoHash = txoHash;
133
143
  }
134
144
  getSecurityDeposit() {
135
- return this.securityDeposit;
145
+ return (0, Utils_1.toBigInt)(this.securityDeposit);
136
146
  }
137
147
  getClaimerBounty() {
138
- return this.claimerBounty;
148
+ return (0, Utils_1.toBigInt)(this.claimerBounty);
139
149
  }
140
150
  getTotalDeposit() {
141
- return this.claimerBounty.lt(this.securityDeposit) ? this.securityDeposit : this.claimerBounty;
151
+ return (0, Utils_1.toBigInt)(this.claimerBounty.lt(this.securityDeposit) ? this.securityDeposit : this.claimerBounty);
142
152
  }
143
153
  toSwapDataStruct() {
144
154
  return {
@@ -246,6 +256,12 @@ class SolanaSwapData extends base_1.SwapData {
246
256
  isOfferer(address) {
247
257
  return this.offerer.equals(new web3_js_1.PublicKey(address));
248
258
  }
259
+ getDepositToken() {
260
+ return SolanaTokens_1.SolanaTokens.WSOL_ADDRESS.toString();
261
+ }
262
+ isDepositToken(token) {
263
+ return SolanaTokens_1.SolanaTokens.WSOL_ADDRESS.equals(new web3_js_1.PublicKey(token));
264
+ }
249
265
  }
250
266
  exports.SolanaSwapData = SolanaSwapData;
251
267
  base_1.SwapData.deserializers["sol"] = SolanaSwapData;
@@ -1,6 +1,5 @@
1
1
  /// <reference types="node" />
2
2
  import { SolanaSwapData } from "./SolanaSwapData";
3
- import * as BN from "bn.js";
4
3
  import { Connection, PublicKey, SendOptions } from "@solana/web3.js";
5
4
  import { SolanaBtcRelay } from "../btcrelay/SolanaBtcRelay";
6
5
  import { IStorageManager, SwapContract, ChainSwapType, IntermediaryReputationType, SwapCommitStatus, TransactionConfirmationOptions, SignatureData, RelaySynchronizer } from "@atomiqlabs/base";
@@ -39,12 +38,12 @@ export declare class SolanaSwapProgram extends SolanaProgramBase<SwapProgram> im
39
38
  start(): Promise<void>;
40
39
  getClaimableDeposits(signer: string): Promise<{
41
40
  count: number;
42
- totalValue: BN;
41
+ totalValue: bigint;
43
42
  }>;
44
43
  claimDeposits(signer: SolanaSigner): Promise<{
45
44
  txIds: string[];
46
45
  count: number;
47
- totalValue: BN;
46
+ totalValue: bigint;
48
47
  }>;
49
48
  preFetchForInitSignatureVerification(data: SolanaPreFetchData): Promise<SolanaPreFetchVerification>;
50
49
  preFetchBlockDataForSignatures(): Promise<SolanaPreFetchData>;
@@ -92,7 +91,7 @@ export declare class SolanaSwapProgram extends SolanaProgramBase<SwapProgram> im
92
91
  * @param signer
93
92
  * @param data
94
93
  */
95
- isExpired(signer: string, data: SolanaSwapData): boolean;
94
+ isExpired(signer: string, data: SolanaSwapData): Promise<boolean>;
96
95
  /**
97
96
  * Checks if the swap is refundable by us, checks if we are offerer, if the swap is already expired & if the swap
98
97
  * is still commited
@@ -106,9 +105,12 @@ export declare class SolanaSwapProgram extends SolanaProgramBase<SwapProgram> im
106
105
  *
107
106
  * @param outputScript output script required to claim the swap
108
107
  * @param amount sats sent required to claim the swap
108
+ * @param confirmations
109
109
  * @param nonce swap nonce uniquely identifying the transaction to prevent replay attacks
110
110
  */
111
- getHashForOnchain(outputScript: Buffer, amount: BN, nonce: BN): Buffer;
111
+ getHashForOnchain(outputScript: Buffer, amount: bigint, confirmations: number, nonce?: bigint): Buffer;
112
+ getHashForHtlc(swapHash: Buffer): Buffer;
113
+ getHashForTxId(txId: string, confirmations: number): Buffer;
112
114
  /**
113
115
  * Gets the status of the specific swap, this also checks if we are offerer/claimer & checks for expiry (to see
114
116
  * if swap is refundable)
@@ -120,96 +122,92 @@ export declare class SolanaSwapProgram extends SolanaProgramBase<SwapProgram> im
120
122
  /**
121
123
  * Checks the status of the specific payment hash
122
124
  *
123
- * @param paymentHash
125
+ * @param claimHash
124
126
  */
125
- getPaymentHashStatus(paymentHash: string): Promise<SwapCommitStatus>;
127
+ getClaimHashStatus(claimHash: string): Promise<SwapCommitStatus>;
126
128
  /**
127
129
  * Returns the data committed for a specific payment hash, or null if no data is currently commited for
128
130
  * the specific swap
129
131
  *
130
- * @param paymentHashHex
132
+ * @param claimHashHex
131
133
  */
132
- getCommitedData(paymentHashHex: string): Promise<SolanaSwapData>;
133
- createSwapData(type: ChainSwapType, offerer: string, claimer: string, token: string, amount: BN, paymentHash: string, sequence: BN, expiry: BN, escrowNonce: BN, confirmations: number, payIn: boolean, payOut: boolean, securityDeposit: BN, claimerBounty: BN): Promise<SolanaSwapData>;
134
- getBalance(signer: string, tokenAddress: string, inContract: boolean): Promise<BN>;
134
+ getCommitedData(claimHashHex: string): Promise<SolanaSwapData>;
135
+ createSwapData(type: ChainSwapType, offerer: string, claimer: string, token: string, amount: bigint, claimHash: string, sequence: bigint, expiry: bigint, payIn: boolean, payOut: boolean, securityDeposit: bigint, claimerBounty: bigint, depositToken?: string): Promise<SolanaSwapData>;
136
+ getBalance(signer: string, tokenAddress: string, inContract: boolean): Promise<bigint>;
135
137
  getIntermediaryData(address: string, token: string): Promise<{
136
- balance: BN;
138
+ balance: bigint;
137
139
  reputation: IntermediaryReputationType;
138
140
  }>;
139
141
  getIntermediaryReputation(address: string, token: string): Promise<IntermediaryReputationType>;
140
- getIntermediaryBalance(address: PublicKey, token: PublicKey): Promise<BN>;
142
+ getIntermediaryBalance(address: PublicKey, token: PublicKey): Promise<bigint>;
141
143
  isValidAddress(address: string): boolean;
142
144
  getNativeCurrencyAddress(): string;
143
145
  txsClaimWithSecret(signer: string | SolanaSigner, swapData: SolanaSwapData, secret: string, checkExpiry?: boolean, initAta?: boolean, feeRate?: string, skipAtaCheck?: boolean): Promise<SolanaTx[]>;
144
- txsClaimWithTxData(signer: string | SolanaSigner, swapData: SolanaSwapData, blockheight: number, tx: {
146
+ txsClaimWithTxData(signer: string | SolanaSigner, swapData: SolanaSwapData, tx: {
145
147
  blockhash: string;
146
148
  confirmations: number;
147
149
  txid: string;
148
150
  hex: string;
149
- }, vout: number, commitedHeader?: SolanaBtcStoredHeader, synchronizer?: RelaySynchronizer<any, SolanaTx, any>, initAta?: boolean, feeRate?: string, storageAccHolder?: {
151
+ height: number;
152
+ }, requiredConfirmations: number, vout: number, commitedHeader?: SolanaBtcStoredHeader, synchronizer?: RelaySynchronizer<any, SolanaTx, any>, initAta?: boolean, feeRate?: string, storageAccHolder?: {
150
153
  storageAcc: PublicKey;
151
154
  }): Promise<SolanaTx[] | null>;
152
- txsRefund(swapData: SolanaSwapData, check?: boolean, initAta?: boolean, feeRate?: string): Promise<SolanaTx[]>;
153
- txsRefundWithAuthorization(swapData: SolanaSwapData, { timeout, prefix, signature }: {
155
+ txsRefund(signer: string, swapData: SolanaSwapData, check?: boolean, initAta?: boolean, feeRate?: string): Promise<SolanaTx[]>;
156
+ txsRefundWithAuthorization(signer: string, swapData: SolanaSwapData, { timeout, prefix, signature }: {
154
157
  timeout: any;
155
158
  prefix: any;
156
159
  signature: any;
157
160
  }, check?: boolean, initAta?: boolean, feeRate?: string): Promise<SolanaTx[]>;
158
- txsInitPayIn(swapData: SolanaSwapData, { timeout, prefix, signature }: {
159
- timeout: any;
160
- prefix: any;
161
- signature: any;
162
- }, skipChecks?: boolean, feeRate?: string): Promise<SolanaTx[]>;
163
161
  txsInit(swapData: SolanaSwapData, { timeout, prefix, signature }: {
164
162
  timeout: any;
165
163
  prefix: any;
166
164
  signature: any;
167
- }, txoHash?: Buffer, skipChecks?: boolean, feeRate?: string): Promise<SolanaTx[]>;
168
- txsWithdraw(signer: string, token: string, amount: BN, feeRate?: string): Promise<SolanaTx[]>;
169
- txsDeposit(signer: string, token: string, amount: BN, feeRate?: string): Promise<SolanaTx[]>;
170
- txsTransfer(signer: string, token: string, amount: BN, dstAddress: string, feeRate?: string): Promise<SolanaTx[]>;
165
+ }, skipChecks?: boolean, feeRate?: string): Promise<SolanaTx[]>;
166
+ txsWithdraw(signer: string, token: string, amount: bigint, feeRate?: string): Promise<SolanaTx[]>;
167
+ txsDeposit(signer: string, token: string, amount: bigint, feeRate?: string): Promise<SolanaTx[]>;
168
+ txsTransfer(signer: string, token: string, amount: bigint, dstAddress: string, feeRate?: string): Promise<SolanaTx[]>;
171
169
  claimWithSecret(signer: SolanaSigner, swapData: SolanaSwapData, secret: string, checkExpiry?: boolean, initAta?: boolean, txOptions?: TransactionConfirmationOptions): Promise<string>;
172
- claimWithTxData(signer: SolanaSigner, swapData: SolanaSwapData, blockheight: number, tx: {
170
+ claimWithTxData(signer: SolanaSigner, swapData: SolanaSwapData, tx: {
173
171
  blockhash: string;
174
172
  confirmations: number;
175
173
  txid: string;
176
174
  hex: string;
177
- }, vout: number, commitedHeader?: SolanaBtcStoredHeader, synchronizer?: RelaySynchronizer<any, SolanaTx, any>, initAta?: boolean, txOptions?: TransactionConfirmationOptions): Promise<string>;
175
+ height: number;
176
+ }, requiredConfirmations: number, vout: number, commitedHeader?: SolanaBtcStoredHeader, synchronizer?: RelaySynchronizer<any, SolanaTx, any>, initAta?: boolean, txOptions?: TransactionConfirmationOptions): Promise<string>;
178
177
  refund(signer: SolanaSigner, swapData: SolanaSwapData, check?: boolean, initAta?: boolean, txOptions?: TransactionConfirmationOptions): Promise<string>;
179
178
  refundWithAuthorization(signer: SolanaSigner, swapData: SolanaSwapData, signature: SignatureData, check?: boolean, initAta?: boolean, txOptions?: TransactionConfirmationOptions): Promise<string>;
180
- initPayIn(signer: SolanaSigner, swapData: SolanaSwapData, signature: SignatureData, skipChecks?: boolean, txOptions?: TransactionConfirmationOptions): Promise<string>;
181
- init(signer: SolanaSigner, swapData: SolanaSwapData, signature: SignatureData, txoHash?: Buffer, skipChecks?: boolean, txOptions?: TransactionConfirmationOptions): Promise<string>;
179
+ init(signer: SolanaSigner, swapData: SolanaSwapData, signature: SignatureData, skipChecks?: boolean, txOptions?: TransactionConfirmationOptions): Promise<string>;
182
180
  initAndClaimWithSecret(signer: SolanaSigner, swapData: SolanaSwapData, signature: SignatureData, secret: string, skipChecks?: boolean, txOptions?: TransactionConfirmationOptions): Promise<string[]>;
183
- withdraw(signer: SolanaSigner, token: string, amount: BN, txOptions?: TransactionConfirmationOptions): Promise<string>;
184
- deposit(signer: SolanaSigner, token: string, amount: BN, txOptions?: TransactionConfirmationOptions): Promise<string>;
185
- transfer(signer: SolanaSigner, token: string, amount: BN, dstAddress: string, txOptions?: TransactionConfirmationOptions): Promise<string>;
181
+ withdraw(signer: SolanaSigner, token: string, amount: bigint, txOptions?: TransactionConfirmationOptions): Promise<string>;
182
+ deposit(signer: SolanaSigner, token: string, amount: bigint, txOptions?: TransactionConfirmationOptions): Promise<string>;
183
+ transfer(signer: SolanaSigner, token: string, amount: bigint, dstAddress: string, txOptions?: TransactionConfirmationOptions): Promise<string>;
186
184
  sendAndConfirm(signer: SolanaSigner, txs: SolanaTx[], waitForConfirmation?: boolean, abortSignal?: AbortSignal, parallel?: boolean, onBeforePublish?: (txId: string, rawTx: string) => Promise<void>): Promise<string[]>;
187
185
  serializeTx(tx: SolanaTx): Promise<string>;
188
186
  deserializeTx(txData: string): Promise<SolanaTx>;
189
187
  getTxIdStatus(txId: string): Promise<"not_found" | "pending" | "success" | "reverted">;
190
188
  getTxStatus(tx: string): Promise<"not_found" | "pending" | "success" | "reverted">;
191
- getInitPayInFeeRate(offerer?: string, claimer?: string, token?: string, paymentHash?: string): Promise<string>;
192
- getInitFeeRate(offerer?: string, claimer?: string, token?: string, paymentHash?: string): Promise<string>;
189
+ getInitPayInFeeRate(offerer?: string, claimer?: string, token?: string, claimHash?: string): Promise<string>;
190
+ getInitFeeRate(offerer?: string, claimer?: string, token?: string, claimHash?: string): Promise<string>;
193
191
  getRefundFeeRate(swapData: SolanaSwapData): Promise<string>;
194
192
  getClaimFeeRate(signer: string, swapData: SolanaSwapData): Promise<string>;
195
- getClaimFee(signer: string, swapData: SolanaSwapData, feeRate?: string): Promise<BN>;
196
- getRawClaimFee(signer: string, swapData: SolanaSwapData, feeRate?: string): Promise<BN>;
193
+ getClaimFee(signer: string, swapData: SolanaSwapData, feeRate?: string): Promise<bigint>;
194
+ getRawClaimFee(signer: string, swapData: SolanaSwapData, feeRate?: string): Promise<bigint>;
197
195
  /**
198
196
  * Get the estimated solana fee of the commit transaction
199
197
  */
200
- getCommitFee(swapData: SolanaSwapData, feeRate?: string): Promise<BN>;
198
+ getCommitFee(swapData: SolanaSwapData, feeRate?: string): Promise<bigint>;
201
199
  /**
202
200
  * Get the estimated solana fee of the commit transaction, without any deposits
203
201
  */
204
- getRawCommitFee(swapData: SolanaSwapData, feeRate?: string): Promise<BN>;
202
+ getRawCommitFee(swapData: SolanaSwapData, feeRate?: string): Promise<bigint>;
205
203
  /**
206
204
  * Get the estimated solana transaction fee of the refund transaction
207
205
  */
208
- getRefundFee(swapData: SolanaSwapData, feeRate?: string): Promise<BN>;
206
+ getRefundFee(swapData: SolanaSwapData, feeRate?: string): Promise<bigint>;
209
207
  /**
210
208
  * Get the estimated solana transaction fee of the refund transaction
211
209
  */
212
- getRawRefundFee(swapData: SolanaSwapData, feeRate?: string): Promise<BN>;
210
+ getRawRefundFee(swapData: SolanaSwapData, feeRate?: string): Promise<bigint>;
213
211
  offBeforeTxReplace(callback: (oldTx: string, oldTxId: string, newTx: string, newTxId: string) => Promise<void>): boolean;
214
212
  onBeforeTxReplace(callback: (oldTx: string, oldTxId: string, newTx: string, newTxId: string) => Promise<void>): void;
215
213
  onBeforeTxSigned(callback: (tx: SolanaTx) => Promise<void>): void;
@@ -219,4 +217,5 @@ export declare class SolanaSwapProgram extends SolanaProgramBase<SwapProgram> im
219
217
  isValidToken(tokenIdentifier: string): boolean;
220
218
  randomAddress(): string;
221
219
  randomSigner(): SolanaSigner;
220
+ getExtraData(outputScript: Buffer, amount: bigint, confirmations: number, nonce?: bigint): Buffer;
222
221
  }