@clonegod/ttd-sui-common 2.0.4 → 2.0.5

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.
@@ -53,6 +53,8 @@ export declare abstract class AbstractDexQuote<C extends SuiChainOps = SuiChainO
53
53
  private registerEventHandlers;
54
54
  private assertValidBlockNumber;
55
55
  private isStaleUpdate;
56
+ private appliedSwapWatermark;
57
+ private shouldApplySwapState;
56
58
  private handleBlockUpdateEvent;
57
59
  private calculateQuote;
58
60
  private calculateQuoteForPool;
@@ -12,6 +12,7 @@ class AbstractDexQuote {
12
12
  this.lastPublished = new Map();
13
13
  this.quotePriceVerify = new quote_price_verify_1.QuotePriceVerify();
14
14
  this.MIN_QUOTE_INTERVAL_MS = Math.max(3000, parseInt(process.env.MIN_QUOTE_INTERVAL_MS || '10000', 10) || 10000);
15
+ this.appliedSwapWatermark = new Map();
15
16
  this.appConfig = appConfig;
16
17
  this.chain = chain;
17
18
  }
@@ -58,8 +59,15 @@ class AbstractDexQuote {
58
59
  const last = this.lastPublished.get(poolAddr);
59
60
  return !!last && (block < last.block || (block === last.block && txIndex <= last.txIndex));
60
61
  }
62
+ shouldApplySwapState(poolAddr, block, txIndex) {
63
+ const last = this.appliedSwapWatermark.get(poolAddr);
64
+ if (last && (block < last.block || (block === last.block && txIndex <= last.txIndex)))
65
+ return false;
66
+ this.appliedSwapWatermark.set(poolAddr, { block, txIndex });
67
+ return true;
68
+ }
61
69
  async handleBlockUpdateEvent(eventData) {
62
- const { blockNumber, blockTime } = JSON.parse(eventData);
70
+ const { blockNumber, blockTimestampMs: blockTime } = JSON.parse(eventData);
63
71
  this.assertValidBlockNumber(blockNumber, `${this.dexId} block-event`);
64
72
  for (const poolInfo of this.poolInfoMap.values()) {
65
73
  const poolAddress = poolInfo.pool_address;
@@ -87,7 +95,11 @@ class AbstractDexQuote {
87
95
  return { bundle: null, verifyLog };
88
96
  }
89
97
  this.assertValidBlockNumber(evt.blockNumber, `${this.dexId} ${poolInfo.pool_name} ${eventType}`);
90
- await this.refreshStateFromEvent(poolInfo, evt);
98
+ const skipApply = eventType === 'swap'
99
+ && Number.isInteger(evt.txIndex)
100
+ && !this.shouldApplySwapState(poolInfo.pool_address, evt.blockNumber, evt.txIndex);
101
+ if (!skipApply)
102
+ await this.refreshStateFromEvent(poolInfo, evt);
91
103
  if (Number.isInteger(evt.txIndex) && this.isStaleUpdate(poolInfo.pool_address, evt.blockNumber, evt.txIndex))
92
104
  return { bundle: null, verifyLog };
93
105
  const bundle = await this.calculateQuoteForPool(poolInfo, evt.blockTime, evt.blockNumber, evt);
@@ -19,7 +19,7 @@ class ExecutorWsClient {
19
19
  });
20
20
  this.ws.onMessage((data) => {
21
21
  try {
22
- const env = JSON.parse(typeof data === 'string' ? data : data.toString());
22
+ const env = (typeof data === 'string' ? JSON.parse(data) : data);
23
23
  const p = this.pending.get(env.reqId);
24
24
  if (!p)
25
25
  return;
@@ -1,8 +1,9 @@
1
1
  export interface BlockUpdateEvent {
2
- blockHash: string;
3
2
  blockNumber: number;
4
- blockTime: number;
5
- transactions: TransactionData[];
3
+ blockTimestamp: number;
4
+ blockTimestampMs: number;
5
+ recvBlockTime: number;
6
+ blockHash?: string;
6
7
  }
7
8
  export interface TransactionData {
8
9
  txHash: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-sui-common",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "description": "Sui common library",
5
5
  "license": "UNLICENSED",
6
6
  "main": "dist/index.js",