@arkade-os/swap 0.0.12 → 0.1.0-rc.1

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.
@@ -1,10 +1,11 @@
1
1
  import {
2
2
  marketsCacheKey
3
- } from "../../chunk-6ZUS47GA.js";
3
+ } from "../../chunk-U7VWWTL6.js";
4
4
 
5
5
  // src/repositories/realm/repository.ts
6
6
  var SWAPS = "ArkadeAssetSwap";
7
7
  var RFQ_SWAPS = "ArkadeRfqSwap";
8
+ var SWAP_RECORDS = "ArkadeSwapRecord";
8
9
  var SCANNED = "ArkadeAssetSwapScannedTxid";
9
10
  var MARKETS = "ArkadeAssetSwapMarketsCache";
10
11
  var RealmAssetSwapRepository = class {
@@ -12,7 +13,7 @@ var RealmAssetSwapRepository = class {
12
13
  this.realm = realm;
13
14
  }
14
15
  realm;
15
- version = 4;
16
+ version = 5;
16
17
  async saveSwap(swap) {
17
18
  this.realm.write(() => {
18
19
  this.realm.create(
@@ -64,6 +65,38 @@ var RealmAssetSwapRepository = class {
64
65
  );
65
66
  });
66
67
  }
68
+ async saveSwapRecord(record) {
69
+ this.realm.write(() => {
70
+ this.realm.create(
71
+ SWAP_RECORDS,
72
+ {
73
+ id: record.id,
74
+ family: record.family,
75
+ updatedAt: record.updatedAt,
76
+ data: JSON.stringify(record)
77
+ },
78
+ "modified"
79
+ );
80
+ });
81
+ }
82
+ async getSwapRecord(id) {
83
+ const [found] = [
84
+ ...this.realm.objects(SWAP_RECORDS).filtered("id == $0", id)
85
+ ];
86
+ return found ? JSON.parse(found.data) : void 0;
87
+ }
88
+ async getAllSwapRecords() {
89
+ return [...this.realm.objects(SWAP_RECORDS)].map(
90
+ (o) => JSON.parse(o.data)
91
+ );
92
+ }
93
+ async removeSwapRecord(id) {
94
+ this.realm.write(() => {
95
+ this.realm.delete(
96
+ this.realm.objects(SWAP_RECORDS).filtered("id == $0", id)
97
+ );
98
+ });
99
+ }
67
100
  async getScannedTxids() {
68
101
  return new Set([...this.realm.objects(SCANNED)].map((o) => o.txid));
69
102
  }
@@ -92,7 +125,7 @@ var RealmAssetSwapRepository = class {
92
125
  * partial clear must not be observable. */
93
126
  async clear() {
94
127
  this.realm.write(() => {
95
- for (const name of [SWAPS, RFQ_SWAPS, SCANNED, MARKETS]) {
128
+ for (const name of [SWAPS, RFQ_SWAPS, SWAP_RECORDS, SCANNED, MARKETS]) {
96
129
  this.realm.delete(this.realm.objects(name));
97
130
  }
98
131
  });
@@ -137,8 +170,19 @@ var ArkadeRfqSwapSchema = {
137
170
  data: "string"
138
171
  }
139
172
  };
173
+ var ArkadeSwapRecordSchema = {
174
+ name: "ArkadeSwapRecord",
175
+ primaryKey: "id",
176
+ properties: {
177
+ id: "string",
178
+ family: "string",
179
+ updatedAt: "int",
180
+ data: "string"
181
+ }
182
+ };
140
183
  var AssetSwapRealmSchemas = [
141
184
  ArkadeRfqSwapSchema,
185
+ ArkadeSwapRecordSchema,
142
186
  ArkadeAssetSwapSchema,
143
187
  ArkadeAssetSwapScannedTxidSchema,
144
188
  ArkadeAssetSwapMarketsCacheSchema
@@ -147,6 +191,8 @@ export {
147
191
  ArkadeAssetSwapMarketsCacheSchema,
148
192
  ArkadeAssetSwapScannedTxidSchema,
149
193
  ArkadeAssetSwapSchema,
194
+ ArkadeRfqSwapSchema,
195
+ ArkadeSwapRecordSchema,
150
196
  AssetSwapRealmSchemas,
151
197
  RealmAssetSwapRepository
152
198
  };
@@ -39,15 +39,17 @@ var SQLiteAssetSwapRepository = class {
39
39
  this.prefix = (0, import_sqlite.sanitizeTablePrefix)(options?.prefix ?? DEFAULT_PREFIX);
40
40
  this.swaps = `${this.prefix}asset_swaps`;
41
41
  this.rfqSwaps = `${this.prefix}rfq_swaps`;
42
+ this.swapRecords = `${this.prefix}swap_records`;
42
43
  this.scanned = `${this.prefix}asset_swap_scanned_txids`;
43
44
  this.markets = `${this.prefix}asset_swap_markets`;
44
45
  }
45
46
  db;
46
- version = 4;
47
+ version = 5;
47
48
  initPromise = null;
48
49
  prefix;
49
50
  swaps;
50
51
  rfqSwaps;
52
+ swapRecords;
51
53
  scanned;
52
54
  markets;
53
55
  /** A rejected init is not cached. The DDL runs in a transaction on a shared
@@ -88,6 +90,15 @@ var SQLiteAssetSwapRepository = class {
88
90
  await this.db.run(
89
91
  `CREATE INDEX IF NOT EXISTS idx_${this.prefix}rfq_swaps_state ON ${this.rfqSwaps} (state)`
90
92
  );
93
+ await this.db.run(`CREATE TABLE IF NOT EXISTS ${this.swapRecords} (
94
+ id TEXT PRIMARY KEY,
95
+ family TEXT NOT NULL,
96
+ updated_at INTEGER NOT NULL,
97
+ data TEXT NOT NULL
98
+ )`);
99
+ await this.db.run(
100
+ `CREATE INDEX IF NOT EXISTS idx_${this.prefix}swap_records_family ON ${this.swapRecords} (family)`
101
+ );
91
102
  await this.db.run(`CREATE TABLE IF NOT EXISTS ${this.scanned} (txid TEXT PRIMARY KEY)`);
92
103
  await this.db.run(
93
104
  `CREATE TABLE IF NOT EXISTS ${this.markets} (cache_key TEXT PRIMARY KEY, data TEXT NOT NULL)`
@@ -147,6 +158,35 @@ var SQLiteAssetSwapRepository = class {
147
158
  await this.db.run(`DELETE FROM ${this.rfqSwaps} WHERE rfq_id = ?`, [rfqId]);
148
159
  });
149
160
  }
161
+ async saveSwapRecord(record) {
162
+ await this.ensureInit();
163
+ await this.withTx(async () => {
164
+ await this.db.run(
165
+ `INSERT OR REPLACE INTO ${this.swapRecords} (id, family, updated_at, data)
166
+ VALUES (?, ?, ?, ?)`,
167
+ [record.id, record.family, record.updatedAt, JSON.stringify(record)]
168
+ );
169
+ });
170
+ }
171
+ async getSwapRecord(id) {
172
+ await this.ensureInit();
173
+ const row = await this.db.get(
174
+ `SELECT data FROM ${this.swapRecords} WHERE id = ?`,
175
+ [id]
176
+ );
177
+ return row ? JSON.parse(row.data) : void 0;
178
+ }
179
+ async getAllSwapRecords() {
180
+ await this.ensureInit();
181
+ const rows = await this.db.all(`SELECT data FROM ${this.swapRecords}`);
182
+ return rows.map((r) => JSON.parse(r.data));
183
+ }
184
+ async removeSwapRecord(id) {
185
+ await this.ensureInit();
186
+ await this.withTx(async () => {
187
+ await this.db.run(`DELETE FROM ${this.swapRecords} WHERE id = ?`, [id]);
188
+ });
189
+ }
150
190
  async getScannedTxids() {
151
191
  await this.ensureInit();
152
192
  const rows = await this.db.all(`SELECT txid FROM ${this.scanned}`);
@@ -191,6 +231,7 @@ var SQLiteAssetSwapRepository = class {
191
231
  await this.withTx(async () => {
192
232
  await this.db.run(`DELETE FROM ${this.swaps}`);
193
233
  await this.db.run(`DELETE FROM ${this.rfqSwaps}`);
234
+ await this.db.run(`DELETE FROM ${this.swapRecords}`);
194
235
  await this.db.run(`DELETE FROM ${this.scanned}`);
195
236
  await this.db.run(`DELETE FROM ${this.markets}`);
196
237
  });
@@ -1,8 +1,8 @@
1
1
  import { SQLExecutor } from '@arkade-os/sdk/repositories/sqlite';
2
- import { A as AssetSwapRepository, a as AssetSwap, R as RfqSwapRecord, M as MarketsCacheEntry } from '../../repository-DaK1RzRq.cjs';
2
+ import { A as AssetSwapRepository, a as AssetSwap, R as RfqSwapRecord, b as SwapRecord, M as MarketsCacheEntry } from '../../repository-oeW8KZo1.cjs';
3
3
  import '@arkade-os/solver-discovery';
4
4
  import '@arkade-os/sdk';
5
- import '../../rfq-DzsmhXX3.cjs';
5
+ import '../../rfq-D0KGjmnn.cjs';
6
6
 
7
7
  /**
8
8
  * SQLite backend over the SDK's `SQLExecutor`, so any driver plugs in
@@ -28,11 +28,12 @@ import '../../rfq-DzsmhXX3.cjs';
28
28
  */
29
29
  declare class SQLiteAssetSwapRepository implements AssetSwapRepository {
30
30
  private readonly db;
31
- readonly version: 4;
31
+ readonly version: 5;
32
32
  private initPromise;
33
33
  private readonly prefix;
34
34
  private readonly swaps;
35
35
  private readonly rfqSwaps;
36
+ private readonly swapRecords;
36
37
  private readonly scanned;
37
38
  private readonly markets;
38
39
  constructor(db: SQLExecutor, options?: {
@@ -62,6 +63,10 @@ declare class SQLiteAssetSwapRepository implements AssetSwapRepository {
62
63
  getRfqSwap(rfqId: string): Promise<RfqSwapRecord | undefined>;
63
64
  getAllRfqSwaps(): Promise<RfqSwapRecord[]>;
64
65
  removeRfqSwap(rfqId: string): Promise<void>;
66
+ saveSwapRecord(record: SwapRecord): Promise<void>;
67
+ getSwapRecord(id: string): Promise<SwapRecord | undefined>;
68
+ getAllSwapRecords(): Promise<SwapRecord[]>;
69
+ removeSwapRecord(id: string): Promise<void>;
65
70
  getScannedTxids(): Promise<Set<string>>;
66
71
  markTxidsScanned(txids: Iterable<string>): Promise<void>;
67
72
  getCachedMarkets(network: string, registry: string): Promise<MarketsCacheEntry | undefined>;
@@ -1,8 +1,8 @@
1
1
  import { SQLExecutor } from '@arkade-os/sdk/repositories/sqlite';
2
- import { A as AssetSwapRepository, a as AssetSwap, R as RfqSwapRecord, M as MarketsCacheEntry } from '../../repository-DlLvj_y6.js';
2
+ import { A as AssetSwapRepository, a as AssetSwap, R as RfqSwapRecord, b as SwapRecord, M as MarketsCacheEntry } from '../../repository-DoR-ahHc.js';
3
3
  import '@arkade-os/solver-discovery';
4
4
  import '@arkade-os/sdk';
5
- import '../../rfq-DzsmhXX3.js';
5
+ import '../../rfq-D0KGjmnn.js';
6
6
 
7
7
  /**
8
8
  * SQLite backend over the SDK's `SQLExecutor`, so any driver plugs in
@@ -28,11 +28,12 @@ import '../../rfq-DzsmhXX3.js';
28
28
  */
29
29
  declare class SQLiteAssetSwapRepository implements AssetSwapRepository {
30
30
  private readonly db;
31
- readonly version: 4;
31
+ readonly version: 5;
32
32
  private initPromise;
33
33
  private readonly prefix;
34
34
  private readonly swaps;
35
35
  private readonly rfqSwaps;
36
+ private readonly swapRecords;
36
37
  private readonly scanned;
37
38
  private readonly markets;
38
39
  constructor(db: SQLExecutor, options?: {
@@ -62,6 +63,10 @@ declare class SQLiteAssetSwapRepository implements AssetSwapRepository {
62
63
  getRfqSwap(rfqId: string): Promise<RfqSwapRecord | undefined>;
63
64
  getAllRfqSwaps(): Promise<RfqSwapRecord[]>;
64
65
  removeRfqSwap(rfqId: string): Promise<void>;
66
+ saveSwapRecord(record: SwapRecord): Promise<void>;
67
+ getSwapRecord(id: string): Promise<SwapRecord | undefined>;
68
+ getAllSwapRecords(): Promise<SwapRecord[]>;
69
+ removeSwapRecord(id: string): Promise<void>;
65
70
  getScannedTxids(): Promise<Set<string>>;
66
71
  markTxidsScanned(txids: Iterable<string>): Promise<void>;
67
72
  getCachedMarkets(network: string, registry: string): Promise<MarketsCacheEntry | undefined>;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  marketsCacheKey
3
- } from "../../chunk-6ZUS47GA.js";
3
+ } from "../../chunk-U7VWWTL6.js";
4
4
 
5
5
  // src/repositories/sqlite/repository.ts
6
6
  import {
@@ -15,15 +15,17 @@ var SQLiteAssetSwapRepository = class {
15
15
  this.prefix = sanitizeTablePrefix(options?.prefix ?? DEFAULT_PREFIX);
16
16
  this.swaps = `${this.prefix}asset_swaps`;
17
17
  this.rfqSwaps = `${this.prefix}rfq_swaps`;
18
+ this.swapRecords = `${this.prefix}swap_records`;
18
19
  this.scanned = `${this.prefix}asset_swap_scanned_txids`;
19
20
  this.markets = `${this.prefix}asset_swap_markets`;
20
21
  }
21
22
  db;
22
- version = 4;
23
+ version = 5;
23
24
  initPromise = null;
24
25
  prefix;
25
26
  swaps;
26
27
  rfqSwaps;
28
+ swapRecords;
27
29
  scanned;
28
30
  markets;
29
31
  /** A rejected init is not cached. The DDL runs in a transaction on a shared
@@ -64,6 +66,15 @@ var SQLiteAssetSwapRepository = class {
64
66
  await this.db.run(
65
67
  `CREATE INDEX IF NOT EXISTS idx_${this.prefix}rfq_swaps_state ON ${this.rfqSwaps} (state)`
66
68
  );
69
+ await this.db.run(`CREATE TABLE IF NOT EXISTS ${this.swapRecords} (
70
+ id TEXT PRIMARY KEY,
71
+ family TEXT NOT NULL,
72
+ updated_at INTEGER NOT NULL,
73
+ data TEXT NOT NULL
74
+ )`);
75
+ await this.db.run(
76
+ `CREATE INDEX IF NOT EXISTS idx_${this.prefix}swap_records_family ON ${this.swapRecords} (family)`
77
+ );
67
78
  await this.db.run(`CREATE TABLE IF NOT EXISTS ${this.scanned} (txid TEXT PRIMARY KEY)`);
68
79
  await this.db.run(
69
80
  `CREATE TABLE IF NOT EXISTS ${this.markets} (cache_key TEXT PRIMARY KEY, data TEXT NOT NULL)`
@@ -123,6 +134,35 @@ var SQLiteAssetSwapRepository = class {
123
134
  await this.db.run(`DELETE FROM ${this.rfqSwaps} WHERE rfq_id = ?`, [rfqId]);
124
135
  });
125
136
  }
137
+ async saveSwapRecord(record) {
138
+ await this.ensureInit();
139
+ await this.withTx(async () => {
140
+ await this.db.run(
141
+ `INSERT OR REPLACE INTO ${this.swapRecords} (id, family, updated_at, data)
142
+ VALUES (?, ?, ?, ?)`,
143
+ [record.id, record.family, record.updatedAt, JSON.stringify(record)]
144
+ );
145
+ });
146
+ }
147
+ async getSwapRecord(id) {
148
+ await this.ensureInit();
149
+ const row = await this.db.get(
150
+ `SELECT data FROM ${this.swapRecords} WHERE id = ?`,
151
+ [id]
152
+ );
153
+ return row ? JSON.parse(row.data) : void 0;
154
+ }
155
+ async getAllSwapRecords() {
156
+ await this.ensureInit();
157
+ const rows = await this.db.all(`SELECT data FROM ${this.swapRecords}`);
158
+ return rows.map((r) => JSON.parse(r.data));
159
+ }
160
+ async removeSwapRecord(id) {
161
+ await this.ensureInit();
162
+ await this.withTx(async () => {
163
+ await this.db.run(`DELETE FROM ${this.swapRecords} WHERE id = ?`, [id]);
164
+ });
165
+ }
126
166
  async getScannedTxids() {
127
167
  await this.ensureInit();
128
168
  const rows = await this.db.all(`SELECT txid FROM ${this.scanned}`);
@@ -167,6 +207,7 @@ var SQLiteAssetSwapRepository = class {
167
207
  await this.withTx(async () => {
168
208
  await this.db.run(`DELETE FROM ${this.swaps}`);
169
209
  await this.db.run(`DELETE FROM ${this.rfqSwaps}`);
210
+ await this.db.run(`DELETE FROM ${this.swapRecords}`);
170
211
  await this.db.run(`DELETE FROM ${this.scanned}`);
171
212
  await this.db.run(`DELETE FROM ${this.markets}`);
172
213
  });