@atomiqlabs/lp-lib 17.1.1 → 17.1.2

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.
@@ -77,8 +77,8 @@ class SwapHandler {
77
77
  * @param ultimateState set the ultimate state of the swap before removing
78
78
  */
79
79
  async removeSwapData(swap, ultimateState) {
80
- this.inflightSwaps.delete(swap.getIdentifier());
81
- this.logger.debug("removeSwapData(): Removing in-flight swap, current in-flight swaps: " + this.inflightSwaps.size);
80
+ if (this.inflightSwaps.delete(swap.getIdentifier()))
81
+ this.logger.debug("removeSwapData(): Removing in-flight swap, current in-flight swaps: " + this.inflightSwaps.size);
82
82
  if (ultimateState != null)
83
83
  await swap.setState(ultimateState);
84
84
  if (swap != null)
@@ -87,13 +87,16 @@ class SwapHandler {
87
87
  await this.storageManager.removeData(swap.getIdentifierHash(), swap.getSequence());
88
88
  }
89
89
  async saveSwapData(swap) {
90
+ const identifier = swap.getIdentifier();
90
91
  if (this.inflightSwapStates.has(swap.state)) {
91
- this.inflightSwaps.add(swap.getIdentifier());
92
- this.logger.debug("removeSwapData(): Adding in-flight swap, current in-flight swaps: " + this.inflightSwaps.size);
92
+ if (!this.inflightSwaps.has(identifier)) {
93
+ this.inflightSwaps.add(identifier);
94
+ this.logger.debug("saveSwapData(): Adding in-flight swap, current in-flight swaps: " + this.inflightSwaps.size);
95
+ }
93
96
  }
94
97
  else {
95
- this.inflightSwaps.delete(swap.getIdentifier());
96
- this.logger.debug("removeSwapData(): Removing in-flight swap, current in-flight swaps: " + this.inflightSwaps.size);
98
+ if (this.inflightSwaps.delete(identifier))
99
+ this.logger.debug("saveSwapData(): Removing in-flight swap, current in-flight swaps: " + this.inflightSwaps.size);
97
100
  }
98
101
  await this.storageManager.saveData(swap.getIdentifierHash(), swap.getSequence(), swap);
99
102
  }
@@ -130,7 +133,12 @@ class SwapHandler {
130
133
  if (minNativeTokenReserve === 0n)
131
134
  return;
132
135
  const balance = await balancePrefetch;
133
- if (balance == null || balance < minNativeTokenReserve) {
136
+ if (signal != null)
137
+ signal.throwIfAborted();
138
+ if (balance == null) {
139
+ throw new Error("Failed to fetch native token balance!");
140
+ }
141
+ if (balance < minNativeTokenReserve) {
134
142
  throw {
135
143
  code: 20012,
136
144
  msg: "LP ran out of native token to cover gas fees"
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@atomiqlabs/lp-lib",
3
- "version": "17.1.1",
3
+ "version": "17.1.2",
4
4
  "description": "Main functionality implementation for atomiq LP node",
5
5
  "main": "./dist/index.js",
6
6
  "types:": "./dist/index.d.ts",
7
7
  "scripts": {
8
+ "build": "npx -y -p typescript@4.9 tsc",
8
9
  "test": "echo \"Error: no test specified\" && exit 1"
9
10
  },
10
11
  "files": [
@@ -179,8 +179,8 @@ export abstract class SwapHandler<V extends SwapHandlerSwap<S> = SwapHandlerSwap
179
179
  * @param ultimateState set the ultimate state of the swap before removing
180
180
  */
181
181
  protected async removeSwapData(swap: V, ultimateState?: S) {
182
- this.inflightSwaps.delete(swap.getIdentifier());
183
- this.logger.debug("removeSwapData(): Removing in-flight swap, current in-flight swaps: "+this.inflightSwaps.size);
182
+ if(this.inflightSwaps.delete(swap.getIdentifier()))
183
+ this.logger.debug("removeSwapData(): Removing in-flight swap, current in-flight swaps: "+this.inflightSwaps.size);
184
184
  if(ultimateState!=null) await swap.setState(ultimateState);
185
185
  if(swap!=null) await PluginManager.swapRemove(swap);
186
186
  this.swapLogger.debug(swap, "removeSwapData(): removing swap final state: "+swap.state);
@@ -188,12 +188,15 @@ export abstract class SwapHandler<V extends SwapHandlerSwap<S> = SwapHandlerSwap
188
188
  }
189
189
 
190
190
  protected async saveSwapData(swap: V) {
191
+ const identifier = swap.getIdentifier();
191
192
  if(this.inflightSwapStates.has(swap.state)) {
192
- this.inflightSwaps.add(swap.getIdentifier());
193
- this.logger.debug("removeSwapData(): Adding in-flight swap, current in-flight swaps: "+this.inflightSwaps.size);
193
+ if(!this.inflightSwaps.has(identifier)) {
194
+ this.inflightSwaps.add(identifier);
195
+ this.logger.debug("saveSwapData(): Adding in-flight swap, current in-flight swaps: "+this.inflightSwaps.size);
196
+ }
194
197
  } else {
195
- this.inflightSwaps.delete(swap.getIdentifier());
196
- this.logger.debug("removeSwapData(): Removing in-flight swap, current in-flight swaps: "+this.inflightSwaps.size);
198
+ if(this.inflightSwaps.delete(identifier))
199
+ this.logger.debug("saveSwapData(): Removing in-flight swap, current in-flight swaps: "+this.inflightSwaps.size);
197
200
  }
198
201
  await this.storageManager.saveData(swap.getIdentifierHash(), swap.getSequence(), swap);
199
202
  }
@@ -232,8 +235,13 @@ export abstract class SwapHandler<V extends SwapHandlerSwap<S> = SwapHandlerSwap
232
235
  const minNativeTokenReserve: bigint = this.config.minNativeBalances?.[chainIdentifier] ?? 0n;
233
236
  if(minNativeTokenReserve===0n) return;
234
237
  const balance = await balancePrefetch;
238
+ if(signal!=null) signal.throwIfAborted();
239
+
240
+ if(balance==null) {
241
+ throw new Error("Failed to fetch native token balance!");
242
+ }
235
243
 
236
- if(balance==null || balance < minNativeTokenReserve) {
244
+ if(balance < minNativeTokenReserve) {
237
245
  throw {
238
246
  code: 20012,
239
247
  msg: "LP ran out of native token to cover gas fees"