@atomiqlabs/chain-solana 10.0.0-dev.3 → 11.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 (114) hide show
  1. package/LICENSE +201 -201
  2. package/dist/index.d.ts +29 -29
  3. package/dist/index.js +45 -45
  4. package/dist/solana/SolanaChainType.d.ts +10 -10
  5. package/dist/solana/SolanaChainType.js +2 -2
  6. package/dist/solana/SolanaChains.d.ts +20 -20
  7. package/dist/solana/SolanaChains.js +25 -25
  8. package/dist/solana/SolanaInitializer.d.ts +18 -18
  9. package/dist/solana/SolanaInitializer.js +63 -63
  10. package/dist/solana/btcrelay/SolanaBtcRelay.d.ts +228 -228
  11. package/dist/solana/btcrelay/SolanaBtcRelay.js +441 -441
  12. package/dist/solana/btcrelay/headers/SolanaBtcHeader.d.ts +29 -29
  13. package/dist/solana/btcrelay/headers/SolanaBtcHeader.js +34 -34
  14. package/dist/solana/btcrelay/headers/SolanaBtcStoredHeader.d.ts +46 -46
  15. package/dist/solana/btcrelay/headers/SolanaBtcStoredHeader.js +78 -78
  16. package/dist/solana/btcrelay/program/programIdl.json +671 -671
  17. package/dist/solana/chain/SolanaAction.d.ts +26 -26
  18. package/dist/solana/chain/SolanaAction.js +86 -86
  19. package/dist/solana/chain/SolanaChainInterface.d.ts +58 -58
  20. package/dist/solana/chain/SolanaChainInterface.js +112 -112
  21. package/dist/solana/chain/SolanaModule.d.ts +14 -14
  22. package/dist/solana/chain/SolanaModule.js +13 -13
  23. package/dist/solana/chain/modules/SolanaAddresses.d.ts +8 -8
  24. package/dist/solana/chain/modules/SolanaAddresses.js +22 -22
  25. package/dist/solana/chain/modules/SolanaBlocks.d.ts +28 -28
  26. package/dist/solana/chain/modules/SolanaBlocks.js +72 -72
  27. package/dist/solana/chain/modules/SolanaEvents.d.ts +25 -25
  28. package/dist/solana/chain/modules/SolanaEvents.js +58 -58
  29. package/dist/solana/chain/modules/SolanaFees.d.ts +121 -121
  30. package/dist/solana/chain/modules/SolanaFees.js +379 -379
  31. package/dist/solana/chain/modules/SolanaSignatures.d.ts +23 -23
  32. package/dist/solana/chain/modules/SolanaSignatures.js +39 -39
  33. package/dist/solana/chain/modules/SolanaSlots.d.ts +31 -31
  34. package/dist/solana/chain/modules/SolanaSlots.js +68 -68
  35. package/dist/solana/chain/modules/SolanaTokens.d.ts +136 -136
  36. package/dist/solana/chain/modules/SolanaTokens.js +248 -248
  37. package/dist/solana/chain/modules/SolanaTransactions.d.ts +124 -124
  38. package/dist/solana/chain/modules/SolanaTransactions.js +332 -332
  39. package/dist/solana/events/SolanaChainEvents.d.ts +88 -88
  40. package/dist/solana/events/SolanaChainEvents.js +256 -256
  41. package/dist/solana/events/SolanaChainEventsBrowser.d.ts +85 -85
  42. package/dist/solana/events/SolanaChainEventsBrowser.js +194 -194
  43. package/dist/solana/program/SolanaProgramBase.d.ts +40 -40
  44. package/dist/solana/program/SolanaProgramBase.js +43 -43
  45. package/dist/solana/program/SolanaProgramModule.d.ts +8 -8
  46. package/dist/solana/program/SolanaProgramModule.js +11 -11
  47. package/dist/solana/program/modules/SolanaProgramEvents.d.ts +59 -59
  48. package/dist/solana/program/modules/SolanaProgramEvents.js +103 -103
  49. package/dist/solana/swaps/SolanaSwapData.d.ts +59 -59
  50. package/dist/solana/swaps/SolanaSwapData.js +267 -267
  51. package/dist/solana/swaps/SolanaSwapModule.d.ts +10 -10
  52. package/dist/solana/swaps/SolanaSwapModule.js +11 -11
  53. package/dist/solana/swaps/SolanaSwapProgram.d.ts +202 -202
  54. package/dist/solana/swaps/SolanaSwapProgram.js +470 -463
  55. package/dist/solana/swaps/SwapTypeEnum.d.ts +11 -11
  56. package/dist/solana/swaps/SwapTypeEnum.js +42 -42
  57. package/dist/solana/swaps/modules/SolanaDataAccount.d.ts +94 -94
  58. package/dist/solana/swaps/modules/SolanaDataAccount.js +231 -231
  59. package/dist/solana/swaps/modules/SolanaLpVault.d.ts +71 -71
  60. package/dist/solana/swaps/modules/SolanaLpVault.js +173 -173
  61. package/dist/solana/swaps/modules/SwapClaim.d.ts +129 -129
  62. package/dist/solana/swaps/modules/SwapClaim.js +291 -291
  63. package/dist/solana/swaps/modules/SwapInit.d.ts +217 -217
  64. package/dist/solana/swaps/modules/SwapInit.js +519 -519
  65. package/dist/solana/swaps/modules/SwapRefund.d.ts +82 -82
  66. package/dist/solana/swaps/modules/SwapRefund.js +252 -252
  67. package/dist/solana/swaps/programIdl.json +945 -945
  68. package/dist/solana/swaps/programTypes.d.ts +943 -943
  69. package/dist/solana/swaps/programTypes.js +945 -945
  70. package/dist/solana/wallet/SolanaKeypairWallet.d.ts +9 -9
  71. package/dist/solana/wallet/SolanaKeypairWallet.js +33 -33
  72. package/dist/solana/wallet/SolanaSigner.d.ts +10 -10
  73. package/dist/solana/wallet/SolanaSigner.js +16 -16
  74. package/dist/utils/Utils.d.ts +53 -53
  75. package/dist/utils/Utils.js +170 -170
  76. package/package.json +41 -41
  77. package/src/index.ts +36 -36
  78. package/src/solana/SolanaChainType.ts +25 -25
  79. package/src/solana/SolanaChains.ts +23 -23
  80. package/src/solana/SolanaInitializer.ts +102 -102
  81. package/src/solana/btcrelay/SolanaBtcRelay.ts +589 -588
  82. package/src/solana/btcrelay/headers/SolanaBtcHeader.ts +57 -57
  83. package/src/solana/btcrelay/headers/SolanaBtcStoredHeader.ts +102 -102
  84. package/src/solana/btcrelay/program/programIdl.json +670 -670
  85. package/src/solana/chain/SolanaAction.ts +108 -108
  86. package/src/solana/chain/SolanaChainInterface.ts +174 -174
  87. package/src/solana/chain/SolanaModule.ts +20 -20
  88. package/src/solana/chain/modules/SolanaAddresses.ts +20 -20
  89. package/src/solana/chain/modules/SolanaBlocks.ts +78 -78
  90. package/src/solana/chain/modules/SolanaEvents.ts +56 -56
  91. package/src/solana/chain/modules/SolanaFees.ts +450 -450
  92. package/src/solana/chain/modules/SolanaSignatures.ts +39 -39
  93. package/src/solana/chain/modules/SolanaSlots.ts +82 -82
  94. package/src/solana/chain/modules/SolanaTokens.ts +307 -307
  95. package/src/solana/chain/modules/SolanaTransactions.ts +370 -370
  96. package/src/solana/events/SolanaChainEvents.ts +299 -299
  97. package/src/solana/events/SolanaChainEventsBrowser.ts +256 -256
  98. package/src/solana/program/SolanaProgramBase.ts +79 -79
  99. package/src/solana/program/SolanaProgramModule.ts +15 -15
  100. package/src/solana/program/modules/SolanaProgramEvents.ts +140 -140
  101. package/src/solana/swaps/SolanaSwapData.ts +379 -379
  102. package/src/solana/swaps/SolanaSwapModule.ts +16 -16
  103. package/src/solana/swaps/SolanaSwapProgram.ts +697 -692
  104. package/src/solana/swaps/SwapTypeEnum.ts +29 -29
  105. package/src/solana/swaps/modules/SolanaDataAccount.ts +307 -307
  106. package/src/solana/swaps/modules/SolanaLpVault.ts +215 -215
  107. package/src/solana/swaps/modules/SwapClaim.ts +389 -389
  108. package/src/solana/swaps/modules/SwapInit.ts +663 -663
  109. package/src/solana/swaps/modules/SwapRefund.ts +312 -312
  110. package/src/solana/swaps/programIdl.json +944 -944
  111. package/src/solana/swaps/programTypes.ts +1885 -1885
  112. package/src/solana/wallet/SolanaKeypairWallet.ts +36 -36
  113. package/src/solana/wallet/SolanaSigner.ts +23 -23
  114. package/src/utils/Utils.ts +180 -180
@@ -1,267 +1,267 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SolanaSwapData = void 0;
4
- const web3_js_1 = require("@solana/web3.js");
5
- const BN = require("bn.js");
6
- const base_1 = require("@atomiqlabs/base");
7
- const SwapTypeEnum_1 = require("./SwapTypeEnum");
8
- const buffer_1 = require("buffer");
9
- const spl_token_1 = require("@solana/spl-token");
10
- const Utils_1 = require("../../utils/Utils");
11
- const SolanaTokens_1 = require("../chain/modules/SolanaTokens");
12
- const EXPIRY_BLOCKHEIGHT_THRESHOLD = new BN("1000000000");
13
- class SolanaSwapData extends base_1.SwapData {
14
- constructor(offererOrData, claimer, token, amount, paymentHash, sequence, expiry, nonce, confirmations, payOut, kind, payIn, offererAta, claimerAta, securityDeposit, claimerBounty, txoHash) {
15
- super();
16
- if (claimer != null || token != null || amount != null || paymentHash != null || expiry != null ||
17
- nonce != null || confirmations != null || payOut != null || kind != null || payIn != null || claimerAta != null) {
18
- this.offerer = offererOrData;
19
- this.claimer = claimer;
20
- this.token = token;
21
- this.amount = amount;
22
- this.paymentHash = paymentHash;
23
- this.sequence = sequence;
24
- this.expiry = expiry;
25
- this.nonce = nonce;
26
- this.confirmations = confirmations;
27
- this.payOut = payOut;
28
- this.kind = kind;
29
- this.payIn = payIn;
30
- this.claimerAta = claimerAta;
31
- this.offererAta = offererAta;
32
- this.securityDeposit = securityDeposit;
33
- this.claimerBounty = claimerBounty;
34
- this.txoHash = txoHash;
35
- }
36
- else {
37
- this.offerer = offererOrData.offerer == null ? null : new web3_js_1.PublicKey(offererOrData.offerer);
38
- this.claimer = offererOrData.claimer == null ? null : new web3_js_1.PublicKey(offererOrData.claimer);
39
- this.token = offererOrData.token == null ? null : new web3_js_1.PublicKey(offererOrData.token);
40
- this.amount = offererOrData.amount == null ? null : new BN(offererOrData.amount);
41
- this.paymentHash = offererOrData.paymentHash;
42
- this.sequence = offererOrData.sequence == null ? null : new BN(offererOrData.sequence);
43
- this.expiry = offererOrData.expiry == null ? null : new BN(offererOrData.expiry);
44
- this.nonce = offererOrData.nonce == null ? null : new BN(offererOrData.nonce);
45
- this.confirmations = offererOrData.confirmations;
46
- this.payOut = offererOrData.payOut;
47
- this.kind = offererOrData.kind;
48
- this.payIn = offererOrData.payIn;
49
- this.claimerAta = offererOrData.claimerAta == null ? null : new web3_js_1.PublicKey(offererOrData.claimerAta);
50
- this.offererAta = offererOrData.offererAta == null ? null : new web3_js_1.PublicKey(offererOrData.offererAta);
51
- this.securityDeposit = offererOrData.securityDeposit == null ? null : new BN(offererOrData.securityDeposit);
52
- this.claimerBounty = offererOrData.claimerBounty == null ? null : new BN(offererOrData.claimerBounty);
53
- this.txoHash = offererOrData.txoHash;
54
- }
55
- }
56
- getOfferer() {
57
- return this.offerer.toBase58();
58
- }
59
- setOfferer(newOfferer) {
60
- this.offerer = new web3_js_1.PublicKey(newOfferer);
61
- this.offererAta = (0, spl_token_1.getAssociatedTokenAddressSync)(this.token, this.offerer);
62
- this.payIn = true;
63
- }
64
- getClaimer() {
65
- return this.claimer.toBase58();
66
- }
67
- setClaimer(newClaimer) {
68
- this.claimer = new web3_js_1.PublicKey(newClaimer);
69
- this.payIn = false;
70
- this.payOut = true;
71
- this.claimerAta = (0, spl_token_1.getAssociatedTokenAddressSync)(this.token, this.claimer);
72
- }
73
- serialize() {
74
- return {
75
- type: "sol",
76
- offerer: this.offerer == null ? null : this.offerer.toBase58(),
77
- claimer: this.claimer == null ? null : this.claimer.toBase58(),
78
- token: this.token == null ? null : this.token.toBase58(),
79
- amount: this.amount == null ? null : this.amount.toString(10),
80
- paymentHash: this.paymentHash,
81
- sequence: this.sequence == null ? null : this.sequence.toString(10),
82
- expiry: this.expiry == null ? null : this.expiry.toString(10),
83
- nonce: this.nonce == null ? null : this.nonce.toString(10),
84
- confirmations: this.confirmations,
85
- payOut: this.payOut,
86
- kind: this.kind,
87
- payIn: this.payIn,
88
- offererAta: this.offererAta == null ? null : this.offererAta.toBase58(),
89
- claimerAta: this.claimerAta == null ? null : this.claimerAta.toBase58(),
90
- securityDeposit: this.securityDeposit == null ? null : this.securityDeposit.toString(10),
91
- claimerBounty: this.claimerBounty == null ? null : this.claimerBounty.toString(10),
92
- txoHash: this.txoHash
93
- };
94
- }
95
- getAmount() {
96
- return (0, Utils_1.toBigInt)(this.amount);
97
- }
98
- getToken() {
99
- return this.token.toString();
100
- }
101
- isToken(token) {
102
- return this.token.equals(new web3_js_1.PublicKey(token));
103
- }
104
- getType() {
105
- return SolanaSwapData.kindToType(this.kind);
106
- }
107
- getExpiry() {
108
- if (this.expiry.lt(EXPIRY_BLOCKHEIGHT_THRESHOLD))
109
- return null;
110
- return (0, Utils_1.toBigInt)(this.expiry);
111
- }
112
- getConfirmationsHint() {
113
- return this.confirmations;
114
- }
115
- getNonceHint() {
116
- return (0, Utils_1.toBigInt)(this.nonce);
117
- }
118
- isPayIn() {
119
- return this.payIn;
120
- }
121
- isPayOut() {
122
- return this.payOut;
123
- }
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);
129
- }
130
- getSequence() {
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;
137
- }
138
- getExtraData() {
139
- return this.txoHash;
140
- }
141
- setExtraData(txoHash) {
142
- this.txoHash = txoHash;
143
- }
144
- getSecurityDeposit() {
145
- return (0, Utils_1.toBigInt)(this.securityDeposit);
146
- }
147
- getClaimerBounty() {
148
- return (0, Utils_1.toBigInt)(this.claimerBounty);
149
- }
150
- getTotalDeposit() {
151
- return (0, Utils_1.toBigInt)(this.claimerBounty.lt(this.securityDeposit) ? this.securityDeposit : this.claimerBounty);
152
- }
153
- toSwapDataStruct() {
154
- return {
155
- kind: SwapTypeEnum_1.SwapTypeEnum.fromNumber(this.kind),
156
- confirmations: this.confirmations,
157
- nonce: this.nonce,
158
- hash: [...buffer_1.Buffer.from(this.paymentHash, "hex")],
159
- payIn: this.payIn,
160
- payOut: this.payOut,
161
- amount: this.amount,
162
- expiry: this.expiry,
163
- sequence: this.sequence
164
- };
165
- }
166
- correctPDA(account) {
167
- return SwapTypeEnum_1.SwapTypeEnum.toNumber(account.data.kind) === this.kind &&
168
- account.data.confirmations === this.confirmations &&
169
- this.nonce.eq(account.data.nonce) &&
170
- buffer_1.Buffer.from(account.data.hash).toString("hex") === this.paymentHash &&
171
- account.data.payIn === this.payIn &&
172
- account.data.payOut === this.payOut &&
173
- this.amount.eq(account.data.amount) &&
174
- this.expiry.eq(account.data.expiry) &&
175
- this.sequence.eq(account.data.sequence) &&
176
- account.offerer.equals(this.offerer) &&
177
- (this.offererAta == null || account.offererAta.equals(this.offererAta)) &&
178
- account.claimer.equals(this.claimer) &&
179
- (this.claimerAta == null || account.claimerAta.equals(this.claimerAta)) &&
180
- account.mint.equals(this.token) &&
181
- this.claimerBounty.eq(account.claimerBounty) &&
182
- this.securityDeposit.eq(account.securityDeposit);
183
- }
184
- equals(other) {
185
- if (this.claimerAta == null && other.claimerAta != null)
186
- return false;
187
- if (this.claimerAta != null && other.claimerAta == null)
188
- return false;
189
- if (this.claimerAta != null && other.claimerAta != null) {
190
- if (!this.claimerAta.equals(other.claimerAta))
191
- return false;
192
- }
193
- if (this.offererAta == null && other.offererAta != null)
194
- return false;
195
- if (this.offererAta != null && other.offererAta == null)
196
- return false;
197
- if (this.offererAta != null && other.offererAta != null) {
198
- if (!this.offererAta.equals(other.offererAta))
199
- return false;
200
- }
201
- return other.kind === this.kind &&
202
- other.confirmations === this.confirmations &&
203
- this.nonce.eq(other.nonce) &&
204
- other.paymentHash === this.paymentHash &&
205
- this.sequence.eq(other.sequence) &&
206
- other.payIn === this.payIn &&
207
- other.payOut === this.payOut &&
208
- other.offerer.equals(this.offerer) &&
209
- other.claimer.equals(this.claimer) &&
210
- other.expiry.eq(this.expiry) &&
211
- other.amount.eq(this.amount) &&
212
- other.securityDeposit.eq(this.securityDeposit) &&
213
- other.claimerBounty.eq(this.claimerBounty) &&
214
- other.token.equals(this.token);
215
- }
216
- static fromEscrowState(account) {
217
- const data = account.data;
218
- return new SolanaSwapData(account.offerer, account.claimer, account.mint, data.amount, buffer_1.Buffer.from(data.hash).toString("hex"), data.sequence, data.expiry, data.nonce, data.confirmations, data.payOut, SwapTypeEnum_1.SwapTypeEnum.toNumber(data.kind), data.payIn, account.offererAta, account.claimerAta, account.securityDeposit, account.claimerBounty, null);
219
- }
220
- static typeToKind(type) {
221
- switch (type) {
222
- case base_1.ChainSwapType.HTLC:
223
- return 0;
224
- case base_1.ChainSwapType.CHAIN:
225
- return 1;
226
- case base_1.ChainSwapType.CHAIN_NONCED:
227
- return 2;
228
- case base_1.ChainSwapType.CHAIN_TXID:
229
- return 3;
230
- }
231
- return null;
232
- }
233
- static kindToType(value) {
234
- switch (value) {
235
- case 0:
236
- return base_1.ChainSwapType.HTLC;
237
- case 1:
238
- return base_1.ChainSwapType.CHAIN;
239
- case 2:
240
- return base_1.ChainSwapType.CHAIN_NONCED;
241
- case 3:
242
- return base_1.ChainSwapType.CHAIN_TXID;
243
- }
244
- return null;
245
- }
246
- isClaimer(address) {
247
- const _address = new web3_js_1.PublicKey(address);
248
- if (this.isPayOut()) {
249
- //Also check that swapData's ATA is correct
250
- const ourAta = (0, spl_token_1.getAssociatedTokenAddressSync)(this.token, _address);
251
- if (!this.claimerAta.equals(ourAta))
252
- return false;
253
- }
254
- return this.claimer.equals(new web3_js_1.PublicKey(address));
255
- }
256
- isOfferer(address) {
257
- return this.offerer.equals(new web3_js_1.PublicKey(address));
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
- }
265
- }
266
- exports.SolanaSwapData = SolanaSwapData;
267
- base_1.SwapData.deserializers["sol"] = SolanaSwapData;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SolanaSwapData = void 0;
4
+ const web3_js_1 = require("@solana/web3.js");
5
+ const BN = require("bn.js");
6
+ const base_1 = require("@atomiqlabs/base");
7
+ const SwapTypeEnum_1 = require("./SwapTypeEnum");
8
+ const buffer_1 = require("buffer");
9
+ const spl_token_1 = require("@solana/spl-token");
10
+ const Utils_1 = require("../../utils/Utils");
11
+ const SolanaTokens_1 = require("../chain/modules/SolanaTokens");
12
+ const EXPIRY_BLOCKHEIGHT_THRESHOLD = new BN("1000000000");
13
+ class SolanaSwapData extends base_1.SwapData {
14
+ constructor(offererOrData, claimer, token, amount, paymentHash, sequence, expiry, nonce, confirmations, payOut, kind, payIn, offererAta, claimerAta, securityDeposit, claimerBounty, txoHash) {
15
+ super();
16
+ if (claimer != null || token != null || amount != null || paymentHash != null || expiry != null ||
17
+ nonce != null || confirmations != null || payOut != null || kind != null || payIn != null || claimerAta != null) {
18
+ this.offerer = offererOrData;
19
+ this.claimer = claimer;
20
+ this.token = token;
21
+ this.amount = amount;
22
+ this.paymentHash = paymentHash;
23
+ this.sequence = sequence;
24
+ this.expiry = expiry;
25
+ this.nonce = nonce;
26
+ this.confirmations = confirmations;
27
+ this.payOut = payOut;
28
+ this.kind = kind;
29
+ this.payIn = payIn;
30
+ this.claimerAta = claimerAta;
31
+ this.offererAta = offererAta;
32
+ this.securityDeposit = securityDeposit;
33
+ this.claimerBounty = claimerBounty;
34
+ this.txoHash = txoHash;
35
+ }
36
+ else {
37
+ this.offerer = offererOrData.offerer == null ? null : new web3_js_1.PublicKey(offererOrData.offerer);
38
+ this.claimer = offererOrData.claimer == null ? null : new web3_js_1.PublicKey(offererOrData.claimer);
39
+ this.token = offererOrData.token == null ? null : new web3_js_1.PublicKey(offererOrData.token);
40
+ this.amount = offererOrData.amount == null ? null : new BN(offererOrData.amount);
41
+ this.paymentHash = offererOrData.paymentHash;
42
+ this.sequence = offererOrData.sequence == null ? null : new BN(offererOrData.sequence);
43
+ this.expiry = offererOrData.expiry == null ? null : new BN(offererOrData.expiry);
44
+ this.nonce = offererOrData.nonce == null ? null : new BN(offererOrData.nonce);
45
+ this.confirmations = offererOrData.confirmations;
46
+ this.payOut = offererOrData.payOut;
47
+ this.kind = offererOrData.kind;
48
+ this.payIn = offererOrData.payIn;
49
+ this.claimerAta = offererOrData.claimerAta == null ? null : new web3_js_1.PublicKey(offererOrData.claimerAta);
50
+ this.offererAta = offererOrData.offererAta == null ? null : new web3_js_1.PublicKey(offererOrData.offererAta);
51
+ this.securityDeposit = offererOrData.securityDeposit == null ? null : new BN(offererOrData.securityDeposit);
52
+ this.claimerBounty = offererOrData.claimerBounty == null ? null : new BN(offererOrData.claimerBounty);
53
+ this.txoHash = offererOrData.txoHash;
54
+ }
55
+ }
56
+ getOfferer() {
57
+ return this.offerer.toBase58();
58
+ }
59
+ setOfferer(newOfferer) {
60
+ this.offerer = new web3_js_1.PublicKey(newOfferer);
61
+ this.offererAta = (0, spl_token_1.getAssociatedTokenAddressSync)(this.token, this.offerer);
62
+ this.payIn = true;
63
+ }
64
+ getClaimer() {
65
+ return this.claimer.toBase58();
66
+ }
67
+ setClaimer(newClaimer) {
68
+ this.claimer = new web3_js_1.PublicKey(newClaimer);
69
+ this.payIn = false;
70
+ this.payOut = true;
71
+ this.claimerAta = (0, spl_token_1.getAssociatedTokenAddressSync)(this.token, this.claimer);
72
+ }
73
+ serialize() {
74
+ return {
75
+ type: "sol",
76
+ offerer: this.offerer == null ? null : this.offerer.toBase58(),
77
+ claimer: this.claimer == null ? null : this.claimer.toBase58(),
78
+ token: this.token == null ? null : this.token.toBase58(),
79
+ amount: this.amount == null ? null : this.amount.toString(10),
80
+ paymentHash: this.paymentHash,
81
+ sequence: this.sequence == null ? null : this.sequence.toString(10),
82
+ expiry: this.expiry == null ? null : this.expiry.toString(10),
83
+ nonce: this.nonce == null ? null : this.nonce.toString(10),
84
+ confirmations: this.confirmations,
85
+ payOut: this.payOut,
86
+ kind: this.kind,
87
+ payIn: this.payIn,
88
+ offererAta: this.offererAta == null ? null : this.offererAta.toBase58(),
89
+ claimerAta: this.claimerAta == null ? null : this.claimerAta.toBase58(),
90
+ securityDeposit: this.securityDeposit == null ? null : this.securityDeposit.toString(10),
91
+ claimerBounty: this.claimerBounty == null ? null : this.claimerBounty.toString(10),
92
+ txoHash: this.txoHash
93
+ };
94
+ }
95
+ getAmount() {
96
+ return (0, Utils_1.toBigInt)(this.amount);
97
+ }
98
+ getToken() {
99
+ return this.token.toString();
100
+ }
101
+ isToken(token) {
102
+ return this.token.equals(new web3_js_1.PublicKey(token));
103
+ }
104
+ getType() {
105
+ return SolanaSwapData.kindToType(this.kind);
106
+ }
107
+ getExpiry() {
108
+ if (this.expiry.lt(EXPIRY_BLOCKHEIGHT_THRESHOLD))
109
+ return null;
110
+ return (0, Utils_1.toBigInt)(this.expiry);
111
+ }
112
+ getConfirmationsHint() {
113
+ return this.confirmations;
114
+ }
115
+ getNonceHint() {
116
+ return (0, Utils_1.toBigInt)(this.nonce);
117
+ }
118
+ isPayIn() {
119
+ return this.payIn;
120
+ }
121
+ isPayOut() {
122
+ return this.payOut;
123
+ }
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);
129
+ }
130
+ getSequence() {
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;
137
+ }
138
+ getExtraData() {
139
+ return this.txoHash;
140
+ }
141
+ setExtraData(txoHash) {
142
+ this.txoHash = txoHash;
143
+ }
144
+ getSecurityDeposit() {
145
+ return (0, Utils_1.toBigInt)(this.securityDeposit);
146
+ }
147
+ getClaimerBounty() {
148
+ return (0, Utils_1.toBigInt)(this.claimerBounty);
149
+ }
150
+ getTotalDeposit() {
151
+ return (0, Utils_1.toBigInt)(this.claimerBounty.lt(this.securityDeposit) ? this.securityDeposit : this.claimerBounty);
152
+ }
153
+ toSwapDataStruct() {
154
+ return {
155
+ kind: SwapTypeEnum_1.SwapTypeEnum.fromNumber(this.kind),
156
+ confirmations: this.confirmations,
157
+ nonce: this.nonce,
158
+ hash: [...buffer_1.Buffer.from(this.paymentHash, "hex")],
159
+ payIn: this.payIn,
160
+ payOut: this.payOut,
161
+ amount: this.amount,
162
+ expiry: this.expiry,
163
+ sequence: this.sequence
164
+ };
165
+ }
166
+ correctPDA(account) {
167
+ return SwapTypeEnum_1.SwapTypeEnum.toNumber(account.data.kind) === this.kind &&
168
+ account.data.confirmations === this.confirmations &&
169
+ this.nonce.eq(account.data.nonce) &&
170
+ buffer_1.Buffer.from(account.data.hash).toString("hex") === this.paymentHash &&
171
+ account.data.payIn === this.payIn &&
172
+ account.data.payOut === this.payOut &&
173
+ this.amount.eq(account.data.amount) &&
174
+ this.expiry.eq(account.data.expiry) &&
175
+ this.sequence.eq(account.data.sequence) &&
176
+ account.offerer.equals(this.offerer) &&
177
+ (this.offererAta == null || account.offererAta.equals(this.offererAta)) &&
178
+ account.claimer.equals(this.claimer) &&
179
+ (this.claimerAta == null || account.claimerAta.equals(this.claimerAta)) &&
180
+ account.mint.equals(this.token) &&
181
+ this.claimerBounty.eq(account.claimerBounty) &&
182
+ this.securityDeposit.eq(account.securityDeposit);
183
+ }
184
+ equals(other) {
185
+ if (this.claimerAta == null && other.claimerAta != null)
186
+ return false;
187
+ if (this.claimerAta != null && other.claimerAta == null)
188
+ return false;
189
+ if (this.claimerAta != null && other.claimerAta != null) {
190
+ if (!this.claimerAta.equals(other.claimerAta))
191
+ return false;
192
+ }
193
+ if (this.offererAta == null && other.offererAta != null)
194
+ return false;
195
+ if (this.offererAta != null && other.offererAta == null)
196
+ return false;
197
+ if (this.offererAta != null && other.offererAta != null) {
198
+ if (!this.offererAta.equals(other.offererAta))
199
+ return false;
200
+ }
201
+ return other.kind === this.kind &&
202
+ other.confirmations === this.confirmations &&
203
+ this.nonce.eq(other.nonce) &&
204
+ other.paymentHash === this.paymentHash &&
205
+ this.sequence.eq(other.sequence) &&
206
+ other.payIn === this.payIn &&
207
+ other.payOut === this.payOut &&
208
+ other.offerer.equals(this.offerer) &&
209
+ other.claimer.equals(this.claimer) &&
210
+ other.expiry.eq(this.expiry) &&
211
+ other.amount.eq(this.amount) &&
212
+ other.securityDeposit.eq(this.securityDeposit) &&
213
+ other.claimerBounty.eq(this.claimerBounty) &&
214
+ other.token.equals(this.token);
215
+ }
216
+ static fromEscrowState(account) {
217
+ const data = account.data;
218
+ return new SolanaSwapData(account.offerer, account.claimer, account.mint, data.amount, buffer_1.Buffer.from(data.hash).toString("hex"), data.sequence, data.expiry, data.nonce, data.confirmations, data.payOut, SwapTypeEnum_1.SwapTypeEnum.toNumber(data.kind), data.payIn, account.offererAta, account.claimerAta, account.securityDeposit, account.claimerBounty, null);
219
+ }
220
+ static typeToKind(type) {
221
+ switch (type) {
222
+ case base_1.ChainSwapType.HTLC:
223
+ return 0;
224
+ case base_1.ChainSwapType.CHAIN:
225
+ return 1;
226
+ case base_1.ChainSwapType.CHAIN_NONCED:
227
+ return 2;
228
+ case base_1.ChainSwapType.CHAIN_TXID:
229
+ return 3;
230
+ }
231
+ return null;
232
+ }
233
+ static kindToType(value) {
234
+ switch (value) {
235
+ case 0:
236
+ return base_1.ChainSwapType.HTLC;
237
+ case 1:
238
+ return base_1.ChainSwapType.CHAIN;
239
+ case 2:
240
+ return base_1.ChainSwapType.CHAIN_NONCED;
241
+ case 3:
242
+ return base_1.ChainSwapType.CHAIN_TXID;
243
+ }
244
+ return null;
245
+ }
246
+ isClaimer(address) {
247
+ const _address = new web3_js_1.PublicKey(address);
248
+ if (this.isPayOut()) {
249
+ //Also check that swapData's ATA is correct
250
+ const ourAta = (0, spl_token_1.getAssociatedTokenAddressSync)(this.token, _address);
251
+ if (!this.claimerAta.equals(ourAta))
252
+ return false;
253
+ }
254
+ return this.claimer.equals(new web3_js_1.PublicKey(address));
255
+ }
256
+ isOfferer(address) {
257
+ return this.offerer.equals(new web3_js_1.PublicKey(address));
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
+ }
265
+ }
266
+ exports.SolanaSwapData = SolanaSwapData;
267
+ base_1.SwapData.deserializers["sol"] = SolanaSwapData;
@@ -1,10 +1,10 @@
1
- import { SolanaSwapProgram } from "./SolanaSwapProgram";
2
- import { Program } from "@coral-xyz/anchor";
3
- import { SwapProgram } from "./programTypes";
4
- import { SolanaProgramModule } from "../program/SolanaProgramModule";
5
- import { SolanaChainInterface } from "../chain/SolanaChainInterface";
6
- export declare class SolanaSwapModule extends SolanaProgramModule<SwapProgram> {
7
- protected readonly program: SolanaSwapProgram;
8
- protected readonly swapProgram: Program<SwapProgram>;
9
- constructor(chainInterface: SolanaChainInterface, program: SolanaSwapProgram);
10
- }
1
+ import { SolanaSwapProgram } from "./SolanaSwapProgram";
2
+ import { Program } from "@coral-xyz/anchor";
3
+ import { SwapProgram } from "./programTypes";
4
+ import { SolanaProgramModule } from "../program/SolanaProgramModule";
5
+ import { SolanaChainInterface } from "../chain/SolanaChainInterface";
6
+ export declare class SolanaSwapModule extends SolanaProgramModule<SwapProgram> {
7
+ protected readonly program: SolanaSwapProgram;
8
+ protected readonly swapProgram: Program<SwapProgram>;
9
+ constructor(chainInterface: SolanaChainInterface, program: SolanaSwapProgram);
10
+ }
@@ -1,11 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SolanaSwapModule = void 0;
4
- const SolanaProgramModule_1 = require("../program/SolanaProgramModule");
5
- class SolanaSwapModule extends SolanaProgramModule_1.SolanaProgramModule {
6
- constructor(chainInterface, program) {
7
- super(chainInterface, program);
8
- this.swapProgram = program.program;
9
- }
10
- }
11
- exports.SolanaSwapModule = SolanaSwapModule;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SolanaSwapModule = void 0;
4
+ const SolanaProgramModule_1 = require("../program/SolanaProgramModule");
5
+ class SolanaSwapModule extends SolanaProgramModule_1.SolanaProgramModule {
6
+ constructor(chainInterface, program) {
7
+ super(chainInterface, program);
8
+ this.swapProgram = program.program;
9
+ }
10
+ }
11
+ exports.SolanaSwapModule = SolanaSwapModule;