@ercworldio/blockchain-shared 1.0.5-dev.8-PLAT300.7 → 1.0.6

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 (35) hide show
  1. package/build/chains/networks_dev.json +2 -1
  2. package/build/chains/networks_prod-ab120.json +644 -0
  3. package/build/chains/networks_prod-dz.json +2 -2
  4. package/build/chains/networks_stg-ab120-mainnet.json +681 -0
  5. package/build/chains/networks_stg-ab120.json +597 -0
  6. package/build/contracts/typechain-types/factories/contracts/escrow/Escrow__factory.d.ts +1 -1
  7. package/build/contracts/typechain-types/factories/contracts/escrow/Escrow__factory.d.ts.map +1 -1
  8. package/build/contracts/typechain-types/factories/contracts/escrow/Escrow__factory.js +1 -1
  9. package/build/index.d.ts +1 -0
  10. package/build/index.d.ts.map +1 -1
  11. package/build/index.js +4 -2
  12. package/build/services/AzureEventHubHandler.d.ts.map +1 -1
  13. package/build/services/AzureEventHubHandler.js +4 -1
  14. package/build/services/db/multisig/MultisigService.d.ts +26 -1
  15. package/build/services/db/multisig/MultisigService.d.ts.map +1 -1
  16. package/build/services/db/multisig/MultisigService.js +70 -0
  17. package/build/services/db/timelock/ScheduleTransactionService.d.ts +16 -2
  18. package/build/services/db/timelock/ScheduleTransactionService.d.ts.map +1 -1
  19. package/build/services/db/timelock/ScheduleTransactionService.js +265 -1
  20. package/build/services/solana/escrow/idl/escrow.json +528 -17
  21. package/build/services/solana/escrow/services/EscrowAdminUtility.d.ts +8 -0
  22. package/build/services/solana/escrow/services/EscrowAdminUtility.d.ts.map +1 -1
  23. package/build/services/solana/escrow/services/EscrowAdminUtility.js +46 -5
  24. package/build/services/solana/escrow/types/escrow.d.ts +528 -17
  25. package/build/services/solana/escrow/types/escrow.d.ts.map +1 -1
  26. package/build/services/types/azure_event_hub_handler.d.ts +3 -1
  27. package/build/services/types/azure_event_hub_handler.d.ts.map +1 -1
  28. package/build/services/types/azure_event_hub_handler.js +3 -0
  29. package/build/services/types/claim.d.ts +1 -0
  30. package/build/services/types/claim.d.ts.map +1 -1
  31. package/build/services/types/db/multisig_service.d.ts +70 -0
  32. package/build/services/types/db/multisig_service.d.ts.map +1 -1
  33. package/build/services/types/db/timelock.d.ts +56 -0
  34. package/build/services/types/db/timelock.d.ts.map +1 -1
  35. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  import { Pool } from "pg";
2
- import { GetAdminOperationThreshold, UpsertAdminOperationThreshold, GetGlobalTimelock, UpsertGlobalTimelock, GetGranularTimelock, UpsertGranularTimelock, GetTokenExecutionThreshold, UpsertTokenExecutionThreshold, FnWithdrawalScheduledPayload, FnWithdrawalScheduledResult, FnWithdrawalExecutedResult, FnWithdrawalExecutedPayload, FnWithdrawalCancelledPayload, FnWithdrawalCancelledResult, FnGetWithdrawalCommitmentsResult, FnGetWithdrawalCommitmentsPayload, ConfigChangeRequestRow, ConfigChangeStatus, ConfigChangeTarget, CreateConfigChangeResult, UpsertConfigChangeSignatureResult, CancelConfigChangeResult, SetConfigChangeTxHashResult, ConfigChangeAppliedResult } from "../../types";
2
+ import { GetAdminOperationThreshold, UpsertAdminOperationThreshold, GetGlobalTimelock, UpsertGlobalTimelock, GetGranularTimelock, UpsertGranularTimelock, GetTokenExecutionThreshold, UpsertTokenExecutionThreshold, FnWithdrawalScheduledPayload, FnWithdrawalScheduledResult, FnWithdrawalExecutedResult, FnWithdrawalExecutedPayload, FnWithdrawalCancelledPayload, FnWithdrawalCancelledResult, FnGetWithdrawalCommitmentsResult, FnGetWithdrawalCommitmentsPayload, ConfigChangeRequestRow, ConfigChangeStatus, ConfigChangeTarget, CreateConfigChangeResult, UpsertConfigChangeSignatureResult, CancelConfigChangeResult, SetConfigChangeTxHashResult, ConfigChangeAppliedResult, AdminWithdrawalStatus, AdminWithdrawalRequestRow, CreateAdminWithdrawalResult, UpsertAdminWithdrawalSignatureResult, CancelAdminWithdrawalResult, SetAdminWithdrawalTxHashResult, AdminWithdrawalCompletedResult } from "../../types";
3
3
  import { OperationType } from "../../../contracts/types/escrow";
4
4
  /**
5
5
  * Adapter class for interfacing the DB functions
@@ -44,6 +44,31 @@ declare class MultisigService {
44
44
  * op type (MANAGE_MULTISIG=4 / CONFIG_TIMELOCK=5), not the configured operation's op type.
45
45
  */
46
46
  static fn_config_change_applied(pool: Pool, blockchain: string, chainId: string, escrowAddress: string, operationType: number, tx_hash: string): Promise<ConfigChangeAppliedResult>;
47
+ /**
48
+ * Creates an admin-withdrawal request; snapshots the op=3 threshold and pre-seeds signature
49
+ * placeholders. Returns the request `pending`, or `approved` when no signatures are required.
50
+ * `amount`/`amountDecimals` are numeric strings (raw base-unit + human-readable). `adminUserId`
51
+ * is the requesting admin's user id from the JWT.
52
+ */
53
+ static fn_create_admin_withdrawal_request(pool: Pool, blockchain: string, chainId: string, escrow_address: string, amount: string, amount_decimals: string, token_address: string, receiver_address: string, admin_user_id: number): Promise<CreateAdminWithdrawalResult>;
54
+ /**
55
+ * Upserts a collected approver signature onto a pre-seeded placeholder — v/r/s (EVM) or the base58
56
+ * `signature` (Solana). Auto-promotes to `approved` once the ADMIN_TREASURY manager+executive quota
57
+ * is met. Op type 3 is implied (no p_operation_type arg).
58
+ */
59
+ static fn_upsert_admin_withdrawal_signature(pool: Pool, blockchain: string, chainId: string, escrow_address: string, request_id: number, signer_address: string, v?: number | null, r?: string | null, s?: string | null, signature?: string | null, type_data_hash?: string | null): Promise<UpsertAdminWithdrawalSignatureResult>;
60
+ /** Lists admin-withdrawal requests (all filters optional), each with its embedded signatures array. */
61
+ static fn_get_admin_withdrawal_requests(pool: Pool, blockchain?: string | null, chainId?: string | null, status?: AdminWithdrawalStatus | null): Promise<AdminWithdrawalRequestRow[]>;
62
+ /** Cancels a pending/approved request — only while it has not been broadcast (tx_hash IS NULL). */
63
+ static fn_cancel_admin_withdrawal_request(pool: Pool, request_id: number): Promise<CancelAdminWithdrawalResult>;
64
+ /** Records the broadcast tx hash on an approved request (status stays approved until the event completes it). */
65
+ static fn_set_admin_withdrawal_tx_hash(pool: Pool, request_id: number, tx_hash: string): Promise<SetAdminWithdrawalTxHashResult>;
66
+ /**
67
+ * Worker-side: flips an approved admin-withdrawal request to `completed` when the confirming on-chain
68
+ * event lands. Matches by `request_id` identity (the AdminWithdraw / AdminPullWithdrawEvent carries it),
69
+ * backfilling tx_hash/block/timestamp. Idempotent.
70
+ */
71
+ static fn_admin_withdrawal_completed(pool: Pool, blockchain: string, chainId: string, escrow_address: string, request_id: number, tx_hash: string, block_number: number, timestamp: number): Promise<AdminWithdrawalCompletedResult>;
47
72
  }
48
73
  export default MultisigService;
49
74
  //# sourceMappingURL=MultisigService.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"MultisigService.d.ts","sourceRoot":"","sources":["../../../../src/services/db/multisig/MultisigService.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAE1B,OAAO,EACH,0BAA0B,EAC1B,6BAA6B,EAC7B,iBAAiB,EACjB,oBAAoB,EACpB,mBAAmB,EACnB,sBAAsB,EACtB,0BAA0B,EAC1B,6BAA6B,EAC7B,4BAA4B,EAC5B,2BAA2B,EAC3B,0BAA0B,EAC1B,2BAA2B,EAC3B,4BAA4B,EAC5B,2BAA2B,EAC3B,gCAAgC,EAChC,iCAAiC,EACjC,sBAAsB,EACtB,kBAAkB,EAClB,kBAAkB,EAClB,wBAAwB,EACxB,iCAAiC,EACjC,wBAAwB,EACxB,2BAA2B,EAC3B,yBAAyB,EAC5B,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAGhE;;;GAGG;AACH,cAAM,eAAe;IAMjB,6EAA6E;WAChE,iCAAiC,CAAC,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,0BAA0B,EAAE,CAAC;IAS9J,0FAA0F;WAC7E,mCAAmC,C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AG,IAAW,EACvB,CAAC,GAAE,MAAM,GAAG,IAAW,EACvB,SAAS,GAAE,MAAM,GAAG,IAAW,EAC/B,eAAe,GAAE,MAAM,GAAG,IAAW,EACrC,cAAc,GAAE,MAAM,GAAG,IAAW,GACrC,OAAO,CAAC,iCAAiC,CAAC;IAS7C,oGAAoG;WACvF,6BAA6B,CACtC,IAAI,EAAE,IAAI,EACV,UAAU,GAAE,MAAM,GAAG,IAAW,EAChC,OAAO,GAAE,MAAM,GAAG,IAAW,EAC7B,MAAM,GAAE,kBAAkB,GAAG,IAAW,EACxC,aAAa,GAAE,kBAAkB,GAAG,IAAW,GAChD,OAAO,CAAC,sBAAsB,EAAE,CAAC;IASpC,0CAA0C;WAC7B,+BAA+B,CAAC,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,wBAAwB,CAAC;IAS/G,+GAA+G;WAClG,4BAA4B,CAAC,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,2BAA2B,CAAC;IAShI;;;;;;OAMG;WACU,wBAAwB,CAAC,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,yBAAyB,CAAC;CAS5L;AAED,eAAe,eAAe,CAAC"}
1
+ {"version":3,"file":"MultisigService.d.ts","sourceRoot":"","sources":["../../../../src/services/db/multisig/MultisigService.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAE1B,OAAO,EACH,0BAA0B,EAC1B,6BAA6B,EAC7B,iBAAiB,EACjB,oBAAoB,EACpB,mBAAmB,EACnB,sBAAsB,EACtB,0BAA0B,EAC1B,6BAA6B,EAC7B,4BAA4B,EAC5B,2BAA2B,EAC3B,0BAA0B,EA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ASrH,iHAAiH;WACpG,+BAA+B,CAAC,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,8BAA8B,CAAC;IAStI;;;;OAIG;WACU,6BAA6B,CACtC,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,MAAM,GAClB,OAAO,CAAC,8BAA8B,CAAC;CAS7C;AAED,eAAe,eAAe,CAAC"}
@@ -193,5 +193,75 @@ class MultisigService {
193
193
  return result.rows[0].fn_config_change_applied;
194
194
  });
195
195
  }
196
+ ///////////////////////////////////////////
197
+ /// Admin-withdrawal requests (PLAN5)
198
+ ///////////////////////////////////////////
199
+ /**
200
+ * Creates an admin-withdrawal request; snapshots the op=3 threshold and pre-seeds signature
201
+ * placeholders. Returns the request `pending`, or `approved` when no signatures are required.
202
+ * `amount`/`amountDecimals` are numeric strings (raw base-unit + human-readable). `adminUserId`
203
+ * is the requesting admin's user id from the JWT.
204
+ */
205
+ static fn_create_admin_withdrawal_request(pool, blockchain, chainId, escrow_address, amount, amount_decimals, token_address, receiver_address, admin_user_id) {
206
+ return __awaiter(this, void 0, void 0, function* () {
207
+ const result = yield pool.query(`SELECT multisig.fn_create_admin_withdrawal_request($1::varchar,$2::varchar,$3::varchar,$4::numeric,$5::numeric,$6::varchar,$7::varchar,$8::varchar)`, [blockchain, chainId, escrow_address, amount, amount_decimals, token_address, receiver_address, admin_user_id.toString()]);
208
+ if (!result)
209
+ throw new Error(`DB FN error: multisig.fn_create_admin_withdrawal_request()`);
210
+ return result.rows[0].fn_create_admin_withdrawal_request;
211
+ });
212
+ }
213
+ /**
214
+ * Upserts a collected approver signature onto a pre-seeded placeholder — v/r/s (EVM) or the base58
215
+ * `signature` (Solana). Auto-promotes to `approved` once the ADMIN_TREASURY manager+executive quota
216
+ * is met. Op type 3 is implied (no p_operation_type arg).
217
+ */
218
+ static fn_upsert_admin_withdrawal_signature(pool_1, blockchain_1, chainId_1, escrow_address_1, request_id_1, signer_address_1) {
219
+ return __awaiter(this, arguments, void 0, function* (pool, blockchain, chainId, escrow_address, request_id, signer_address, v = null, r = null, s = null, signature = null, type_data_hash = null) {
220
+ const result = yield pool.query(`SELECT multisig.fn_upsert_admin_withdrawal_signature($1::varchar,$2::varchar,$3::varchar,$4::bigint,$5::varchar,$6::integer,$7::varchar,$8::varchar,$9::varchar,$10::varchar)`, [blockchain, chainId, escrow_address, request_id, signer_address, v, r, s, signature, type_data_hash]);
221
+ if (!result)
222
+ throw new Error(`DB FN error: multisig.fn_upsert_admin_withdrawal_signature()`);
223
+ return result.rows[0].fn_upsert_admin_withdrawal_signature;
224
+ });
225
+ }
226
+ /** Lists admin-withdrawal requests (all filters optional), each with its embedded signatures array. */
227
+ static fn_get_admin_withdrawal_requests(pool_1) {
228
+ return __awaiter(this, arguments, void 0, function* (pool, blockchain = null, chainId = null, status = null) {
229
+ const result = yield pool.query(`SELECT multisig.fn_get_admin_withdrawal_requests($1::varchar,$2::varchar,$3::varchar)`, [blockchain, chainId, status]);
230
+ if (!result)
231
+ throw new Error(`DB FN error: multisig.fn_get_admin_withdrawal_requests()`);
232
+ return result.rows[0].fn_get_admin_withdrawal_requests;
233
+ });
234
+ }
235
+ /** Cancels a pending/approved request — only while it has not been broadcast (tx_hash IS NULL). */
236
+ static fn_cancel_admin_withdrawal_request(pool, request_id) {
237
+ return __awaiter(this, void 0, void 0, function* () {
238
+ const result = yield pool.query(`SELECT multisig.fn_cancel_admin_withdrawal_request($1::bigint)`, [request_id]);
239
+ if (!result)
240
+ throw new Error(`DB FN error: multisig.fn_cancel_admin_withdrawal_request()`);
241
+ return result.rows[0].fn_cancel_admin_withdrawal_request;
242
+ });
243
+ }
244
+ /** Records the broadcast tx hash on an approved request (status stays approved until the event completes it). */
245
+ static fn_set_admin_withdrawal_tx_hash(pool, request_id, tx_hash) {
246
+ return __awaiter(this, void 0, void 0, function* () {
247
+ const result = yield pool.query(`SELECT multisig.fn_set_admin_withdrawal_tx_hash($1::bigint,$2::varchar)`, [request_id, tx_hash]);
248
+ if (!result)
249
+ throw new Error(`DB FN error: multisig.fn_set_admin_withdrawal_tx_hash()`);
250
+ return result.rows[0].fn_set_admin_withdrawal_tx_hash;
251
+ });
252
+ }
253
+ /**
254
+ * Worker-side: flips an approved admin-withdrawal request to `completed` when the confirming on-chain
255
+ * event lands. Matches by `request_id` identity (the AdminWithdraw / AdminPullWithdrawEvent carries it),
256
+ * backfilling tx_hash/block/timestamp. Idempotent.
257
+ */
258
+ static fn_admin_withdrawal_completed(pool, blockchain, chainId, escrow_address, request_id, tx_hash, block_number, timestamp) {
259
+ return __awaiter(this, void 0, void 0, function* () {
260
+ const result = yield pool.query(`SELECT multisig.fn_admin_withdrawal_completed($1::varchar,$2::varchar,$3::varchar,$4::bigint,$5::varchar,$6::bigint,$7::bigint)`, [blockchain, chainId, escrow_address, request_id, tx_hash, block_number, timestamp]);
261
+ if (!result)
262
+ throw new Error(`DB FN error: multisig.fn_admin_withdrawal_completed()`);
263
+ return result.rows[0].fn_admin_withdrawal_completed;
264
+ });
265
+ }
196
266
  }
197
267
  exports.default = MultisigService;
@@ -2,12 +2,15 @@ import { ScheduleJobStatus, ScheduleTransactionJob } from "../../../entities/Sch
2
2
  import { ClaimJobLockMetadata } from "../../types";
3
3
  import { Pool } from "pg";
4
4
  import { OperationType } from "../../../contracts/types/escrow";
5
- import { MarkCompleteScheduleJob, ScheduleTransactionJobWithDetails } from "../../types/db";
5
+ import { MarkCompleteScheduleJob, ScheduleTransactionJobWithDetails, ScheduleJobFilters, ScheduleJobListItem, ScheduleJobHistoryFilters, ScheduleJobHistoryItem } from "../../types/db";
6
+ import { Paginated } from "../../types/claim_job_service";
6
7
  import { RequeueJobConfiguration } from "../../types/watchdog";
7
8
  declare class ScheduleTransactionService {
8
9
  static get_and_lock_available_jobs: (pool: Pool, limit?: number, job_ttl_s?: number, lock_metadata?: ClaimJobLockMetadata) => Promise<ScheduleTransactionJob[]>;
9
- /** Locks and returns available jobs with full withdrawal details via DB function. */
10
+ /** Locks and returns available jobs with full withdrawal details via inline SQL (bypasses DB function). */
10
11
  static get_and_lock_available_jobs_with_details: (pool: Pool, limit?: number, job_ttl_s?: number, lock_metadata?: ClaimJobLockMetadata) => Promise<ScheduleTransactionJobWithDetails[]>;
12
+ /** Locks and returns available jobs with full withdrawal details via DB function. */
13
+ static get_and_lock_available_jobs_with_details_depr: (pool: Pool, limit?: number, job_ttl_s?: number, lock_metadata?: ClaimJobLockMetadata) => Promise<ScheduleTransactionJobWithDetails[]>;
11
14
  /**
12
15
  * Requeues all jobs in the given status to "queued"
13
16
  */
@@ -27,6 +30,17 @@ declare class ScheduleTransactionService {
27
30
  sent_at: Date;
28
31
  }[]) => Promise<void>;
29
32
  static mark_complete: (pool: Pool, payloads: MarkCompleteScheduleJob[]) => Promise<void>;
33
+ /**
34
+ * Paginated list of current schedule-transaction jobs, newest first, with the
35
+ * status resolved to text and (for withdrawal operation types) the receiver/token/
36
+ * amount joined in. All filters are optional and combine with AND.
37
+ */
38
+ static list_jobs_paginated: (pool: Pool, page: number, page_size?: number, filters?: ScheduleJobFilters) => Promise<Paginated<ScheduleJobListItem[]>>;
39
+ /**
40
+ * Paginated schedule-transaction job history (append-only status transitions),
41
+ * newest first. All filters are optional and combine with AND.
42
+ */
43
+ static list_history_paginated: (pool: Pool, page: number, page_size?: number, filters?: ScheduleJobHistoryFilters) => Promise<Paginated<ScheduleJobHistoryItem[]>>;
30
44
  }
31
45
  export default ScheduleTransactionService;
32
46
  //# sourceMappingURL=ScheduleTransactionService.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ScheduleTransactionService.d.ts","sourceRoot":"","sources":["../../../../src/services/db/timelock/ScheduleTransactionService.ts"],"names":[],"mappings":"AACA,OAAO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EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,iBAAiB,CAAC;QAAC,aAAa,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,OAAO,CAAA;KAAE,EAAE,KACzG,OAAO,CAAC,IAAI,CAAC,CA8Bf;IAGD,MAAM,CAAC,0BAA0B,GAC7B,MAAM,IAAI,EACV,MAAM;QAAE,cAAc,EAAE,aAAa,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,IAAI,CAAA;KAAE,EAAE,KAC9F,OAAO,CAAC,IAAI,CAAC,CAwBd;IAGF,MAAM,CAAC,aAAa,GAAU,MAAM,IAAI,EAAE,UAAU,uBAAuB,EAAE,KAAG,OAAO,CAAC,IAAI,CAAC,CAmB5F;CAEJ;AAED,eAAe,0BAA0B,CAAC"}
1
+ {"version":3,"file":"ScheduleTransactionService.d.ts","sourceRoot":"","sources":["../../../../src/services/db/timelock/ScheduleTransactionService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,0CAA0C,CAAC;AACrG,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EACH,uBAAuB,EACvB,iCAAiC,EACjC,kBAAkB,EAClB,mBAAmB,EACnB,yBAAyB,EACzB,sBAAsB,EACzB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAE/D,cAAM,0BAA0B;IAE5B,MAAM,CAAC,2BAA2B,GAAU,MAAM,IAAI,EAAE,QAAO,MAAW,EAAE,YAAW,MAAY,EAAE,gBAAe,oBAA0F,KAAG,OAAO,CAAC,sBAAsB,EAAE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EAAE,IAAI,CAAA;KAAE,EAAE,KAC9F,OAAO,CAAC,IAAI,CAAC,CAwBd;IAGF,MAAM,CAAC,aAAa,GAAU,MAAM,IAAI,EAAE,UAAU,uBAAuB,EAAE,KAAG,OAAO,CAAC,IAAI,CAAC,CAmB5F;IAKD;;;;OAIG;IACH,MAAM,CAAC,mBAAmB,GACtB,MAAM,IAAI,EACV,MAAM,MAAM,EACZ,YAAW,MAAW,EACtB,UAAS,kBAAuB,KACjC,OAAO,CAAC,SAAS,CAAC,mBAAmB,EAAE,CAAC,CAAC,CAgE1C;IAGF;;;OAGG;IACH,MAAM,CAAC,sBAAsB,GACzB,MAAM,IAAI,EACV,MAAM,MAAM,EACZ,YAAW,MAAW,EACtB,UAAS,yBAA8B,KACxC,OAAO,CAAC,SAAS,CAAC,sBAAsB,EAAE,CAAC,CAAC,CAqD7C;CAEL;AAED,eAAe,0BAA0B,CAAC"}
@@ -52,8 +52,123 @@ ScheduleTransactionService.get_and_lock_available_jobs = (pool_1, ...args_1) =>
52
52
  `, [limit, ttlSeconds, lock_metadata.lock_owner, lock_metadata.lock_reason]);
53
53
  return res.rows;
54
54
  });
55
- /** Locks and returns available jobs with full withdrawal details via DB function. */
55
+ /** Locks and returns available jobs with full withdrawal details via inline SQL (bypasses DB function). */
56
56
  ScheduleTransactionService.get_and_lock_available_jobs_with_details = (pool_1, ...args_1) => __awaiter(void 0, [pool_1, ...args_1], void 0, function* (pool, limit = 10, job_ttl_s = 120, lock_metadata = { lock_owner: "schedule-tx-worker", lock_reason: "process_queued" }) {
57
+ var _b, _c;
58
+ const result = yield pool.query(`
59
+ WITH status_ids AS (
60
+ SELECT
61
+ MAX(CASE WHEN status = 'queued' THEN id END) AS queued_id,
62
+ MAX(CASE WHEN status = 'processing' THEN id END) AS processing_id
63
+ FROM multisig.schedule_job_statuses
64
+ ),
65
+ candidates AS (
66
+ SELECT id
67
+ FROM multisig.schedule_transaction_jobs, status_ids
68
+ WHERE status_id = status_ids.queued_id
69
+ AND (lock_expires_at IS NULL OR lock_expires_at < NOW())
70
+ ORDER BY blockchain, chain_id ASC
71
+ LIMIT $1
72
+ FOR UPDATE SKIP LOCKED
73
+ ),
74
+ updated AS (
75
+ UPDATE multisig.schedule_transaction_jobs j
76
+ SET status_id = si.processing_id,
77
+ locked_at = NOW(),
78
+ lock_expires_at = NOW() + ($2 || ' seconds')::INTERVAL,
79
+ batch_group_id = gen_random_uuid(),
80
+ metadata = jsonb_set(
81
+ jsonb_set(
82
+ COALESCE(j.metadata, '{}'::jsonb),
83
+ '{lock_owner}', to_jsonb($3::text)
84
+ ),
85
+ '{lock_reason}', to_jsonb($4::text)
86
+ ),
87
+ updated_at = NOW()
88
+ FROM candidates c, status_ids si
89
+ WHERE j.id = c.id
90
+ RETURNING j.*
91
+ )
92
+ SELECT COALESCE(json_agg(json_build_object(
93
+ 'id', u.id,
94
+ 'requestId', u.request_id,
95
+ 'operationType', u.operation_type,
96
+ 'status', sjs.status,
97
+ 'blockchain', u.blockchain,
98
+ 'chainId', u.chain_id,
99
+ 'batchGroupId', u.batch_group_id,
100
+ 'lockExpiresAt', u.lock_expires_at,
101
+ 'lockedAt', u.locked_at,
102
+ 'txHash', u.tx_hash,
103
+ 'sentAt', u.sent_at,
104
+ 'confirmedAt', u.confirmed_at,
105
+ 'retryCount', u.retry_count,
106
+ 'errorMessage', u.error_message,
107
+ 'lastErrorAt', u.last_error_at,
108
+ 'metadata', u.metadata,
109
+ 'createdAt', u.created_at,
110
+ 'updatedAt', u.updated_at,
111
+ 'withdrawalDetails', json_build_object(
112
+ 'id', cw.id,
113
+ 'userId', cw.user_id,
114
+ 'status', LOWER(cws.status),
115
+ 'blockchain', LOWER(cwbt.blockchain),
116
+ 'receiver', cw.receiver_address,
117
+ 'receiverAddress', cw.receiver_address,
118
+ 'paymentType', LOWER(cwpt.type),
119
+ 'chainId', cw.chain_id,
120
+ 'token', cw.token_address,
121
+ 'amount', cw.amount,
122
+ 'amountInUsd', cw.amount * cr.rate,
123
+ 'destinationChainId', cw.destination_chain_id,
124
+ 'destinationToken', cw.destination_token_address,
125
+ 'destinationBlockchain', cw.destination_blockchain,
126
+ 'sigsExecutiveRequired', cw.sigs_executive_required,
127
+ 'sigsManagerRequired', cw.sigs_manager_required,
128
+ 'timeLockSeconds', cw.timelock_seconds,
129
+ 'multisigSignatures', (
130
+ SELECT COALESCE(json_agg(json_build_object(
131
+ 'name', COALESCE(role.role_alias, ''),
132
+ 'signerAddress', cs.signer_address,
133
+ 'contractAddress', cs.contract_address,
134
+ 'createdAt', cs.created_at,
135
+ 'updatedAt', cs.updated_at,
136
+ 'operationType', cs.operation_type,
137
+ 'v', cs.v,
138
+ 'r', cs.r,
139
+ 's', cs.s,
140
+ 'signature', cs.signature
141
+ )), '[]'::json)
142
+ FROM multisig.crypto_signatures cs
143
+ LEFT JOIN multisig.crypto_escrow_roles cer
144
+ ON LOWER(cer.wallet_address) = LOWER(cs.signer_address)
145
+ AND LOWER(cer.blockchain) = LOWER(cs.blockchain)
146
+ AND cer.chain_id = cs.chain_id
147
+ AND LOWER(cer.contract_address) = LOWER(cs.contract_address)
148
+ LEFT JOIN multisig.crypto_role role ON role.id = cer.role_id
149
+ WHERE cs.reference_id = cw.id
150
+ AND cs.operation_type = 1
151
+ AND (
152
+ (cs.v IS NOT NULL AND cs.r IS NOT NULL AND cs.s IS NOT NULL)
153
+ OR cs.signature IS NOT NULL
154
+ )
155
+ )
156
+ )
157
+ )), '[]'::json) AS result
158
+ FROM updated u
159
+ JOIN multisig.schedule_job_statuses sjs ON sjs.id = u.status_id
160
+ JOIN accounting.crypto_withdrawals cw ON cw.id = u.request_id
161
+ LEFT JOIN accounting.crypto_withdrawal_status cws ON cws.id = cw.status_id
162
+ LEFT JOIN accounting.crypto_withdrawal_blockchain_types cwbt ON cwbt.id = cw.blockchain_id
163
+ LEFT JOIN accounting.crypto_withdrawal_payment_types cwpt ON cwpt.id = cw.payment_type_id
164
+ LEFT JOIN usersmanagement.user_currency_mappings ucm ON ucm.currency_specific_user_id = cw.currency_specific_user_id
165
+ LEFT JOIN public.currencies cur ON cur.currencyid = ucm.currency_id
166
+ LEFT JOIN accounting.currencyrates cr ON cr.symbol = UPPER(cur.currency_code || 'USD')
167
+ `, [limit, job_ttl_s, lock_metadata.lock_owner, lock_metadata.lock_reason]);
168
+ return (_c = (_b = result.rows[0]) === null || _b === void 0 ? void 0 : _b.result) !== null && _c !== void 0 ? _c : [];
169
+ });
170
+ /** Locks and returns available jobs with full withdrawal details via DB function. */
171
+ ScheduleTransactionService.get_and_lock_available_jobs_with_details_depr = (pool_1, ...args_1) => __awaiter(void 0, [pool_1, ...args_1], void 0, function* (pool, limit = 10, job_ttl_s = 120, lock_metadata = { lock_owner: "schedule-tx-worker", lock_reason: "process_queued" }) {
57
172
  var _b;
58
173
  const result = yield pool.query(`SELECT multisig.fn_get_available_schedule_jobs_with_details($1::int, $2::int, $3::text, $4::text)`, [limit, job_ttl_s, lock_metadata.lock_owner, lock_metadata.lock_reason]);
59
174
  return (_b = result.rows[0].fn_get_available_schedule_jobs_with_details) !== null && _b !== void 0 ? _b : [];
@@ -209,4 +324,153 @@ ScheduleTransactionService.mark_complete = (pool, payloads) => __awaiter(void 0,
209
324
  AND t.operation_type = c.operation_type
210
325
  `, [requestIds, operationTypes]);
211
326
  });
327
+ // ── BO read views ────────────────────────────────────────────────────────
328
+ /**
329
+ * Paginated list of current schedule-transaction jobs, newest first, with the
330
+ * status resolved to text and (for withdrawal operation types) the receiver/token/
331
+ * amount joined in. All filters are optional and combine with AND.
332
+ */
333
+ ScheduleTransactionService.list_jobs_paginated = (pool_1, page_1, ...args_1) => __awaiter(void 0, [pool_1, page_1, ...args_1], void 0, function* (pool, page, page_size = 20, filters = {}) {
334
+ var _b, _c;
335
+ if (page < 1)
336
+ page = 1;
337
+ const clauses = [];
338
+ const params = [];
339
+ let i = 1;
340
+ if (filters.status) {
341
+ clauses.push(`sjs.status = $${i++}`);
342
+ params.push(filters.status);
343
+ }
344
+ if (filters.blockchain) {
345
+ clauses.push(`j.blockchain = $${i++}`);
346
+ params.push(filters.blockchain);
347
+ }
348
+ if (filters.chainId) {
349
+ clauses.push(`j.chain_id = $${i++}`);
350
+ params.push(filters.chainId);
351
+ }
352
+ if (filters.operationType !== undefined) {
353
+ clauses.push(`j.operation_type = $${i++}`);
354
+ params.push(filters.operationType);
355
+ }
356
+ if (filters.requestId !== undefined) {
357
+ clauses.push(`j.request_id = $${i++}`);
358
+ params.push(filters.requestId);
359
+ }
360
+ if (filters.txHash) {
361
+ clauses.push(`j.tx_hash = $${i++}`);
362
+ params.push(filters.txHash);
363
+ }
364
+ const where = clauses.length ? `WHERE ${clauses.join(" AND ")}` : "";
365
+ const countRes = yield pool.query(`SELECT COUNT(*)::bigint AS count
366
+ FROM multisig.schedule_transaction_jobs j
367
+ JOIN multisig.schedule_job_statuses sjs ON sjs.id = j.status_id
368
+ ${where}`, params);
369
+ const total_count = Number((_c = (_b = countRes.rows[0]) === null || _b === void 0 ? void 0 : _b.count) !== null && _c !== void 0 ? _c : 0);
370
+ const limitParam = i++;
371
+ const offsetParam = i++;
372
+ const rowsRes = yield pool.query(`SELECT
373
+ j.id,
374
+ j.request_id AS "requestId",
375
+ j.operation_type AS "operationType",
376
+ sjs.status AS status,
377
+ j.blockchain,
378
+ j.chain_id AS "chainId",
379
+ j.tx_hash AS "txHash",
380
+ j.locked_at AS "lockedAt",
381
+ j.lock_expires_at AS "lockExpiresAt",
382
+ j.sent_at AS "sentAt",
383
+ j.confirmed_at AS "confirmedAt",
384
+ j.retry_count AS "retryCount",
385
+ j.error_message AS "errorMessage",
386
+ j.last_error_at AS "lastErrorAt",
387
+ j.metadata,
388
+ j.created_at AS "createdAt",
389
+ j.updated_at AS "updatedAt",
390
+ cw.receiver_address AS "receiverAddress",
391
+ cw.token_address AS "tokenAddress",
392
+ cw.amount AS "amount"
393
+ FROM multisig.schedule_transaction_jobs j
394
+ JOIN multisig.schedule_job_statuses sjs ON sjs.id = j.status_id
395
+ LEFT JOIN accounting.crypto_withdrawals cw
396
+ ON cw.id = j.request_id AND j.operation_type IN (1, 3)
397
+ ${where}
398
+ ORDER BY j.created_at DESC
399
+ LIMIT $${limitParam} OFFSET $${offsetParam}`, [...params, page_size, (page - 1) * page_size]);
400
+ return {
401
+ total_count,
402
+ pages_count: Math.ceil(total_count / page_size),
403
+ current_page: page,
404
+ has_next: total_count > page * page_size,
405
+ items: rowsRes.rows
406
+ };
407
+ });
408
+ /**
409
+ * Paginated schedule-transaction job history (append-only status transitions),
410
+ * newest first. All filters are optional and combine with AND.
411
+ */
412
+ ScheduleTransactionService.list_history_paginated = (pool_1, page_1, ...args_1) => __awaiter(void 0, [pool_1, page_1, ...args_1], void 0, function* (pool, page, page_size = 20, filters = {}) {
413
+ var _b, _c;
414
+ if (page < 1)
415
+ page = 1;
416
+ const clauses = [];
417
+ const params = [];
418
+ let i = 1;
419
+ if (filters.jobId !== undefined) {
420
+ clauses.push(`h.job_id = $${i++}`);
421
+ params.push(filters.jobId);
422
+ }
423
+ if (filters.requestId !== undefined) {
424
+ clauses.push(`h.request_id = $${i++}`);
425
+ params.push(filters.requestId);
426
+ }
427
+ if (filters.operationType !== undefined) {
428
+ clauses.push(`h.operation_type = $${i++}`);
429
+ params.push(filters.operationType);
430
+ }
431
+ if (filters.status) {
432
+ clauses.push(`sjs.status = $${i++}`);
433
+ params.push(filters.status);
434
+ }
435
+ if (filters.blockchain) {
436
+ clauses.push(`h.blockchain = $${i++}`);
437
+ params.push(filters.blockchain);
438
+ }
439
+ if (filters.chainId) {
440
+ clauses.push(`h.chain_id = $${i++}`);
441
+ params.push(filters.chainId);
442
+ }
443
+ const where = clauses.length ? `WHERE ${clauses.join(" AND ")}` : "";
444
+ const countRes = yield pool.query(`SELECT COUNT(*)::bigint AS count
445
+ FROM multisig.schedule_transaction_jobs_history h
446
+ JOIN multisig.schedule_job_statuses sjs ON sjs.id = h.status_id
447
+ ${where}`, params);
448
+ const total_count = Number((_c = (_b = countRes.rows[0]) === null || _b === void 0 ? void 0 : _b.count) !== null && _c !== void 0 ? _c : 0);
449
+ const limitParam = i++;
450
+ const offsetParam = i++;
451
+ const rowsRes = yield pool.query(`SELECT
452
+ h.id,
453
+ h.job_id AS "jobId",
454
+ h.request_id AS "requestId",
455
+ h.operation_type AS "operationType",
456
+ sjs.status AS status,
457
+ h.blockchain,
458
+ h.chain_id AS "chainId",
459
+ h.tx_hash AS "txHash",
460
+ h.retry_count AS "retryCount",
461
+ h.error_message AS "errorMessage",
462
+ h.created_at AS "createdAt"
463
+ FROM multisig.schedule_transaction_jobs_history h
464
+ JOIN multisig.schedule_job_statuses sjs ON sjs.id = h.status_id
465
+ ${where}
466
+ ORDER BY h.created_at DESC
467
+ LIMIT $${limitParam} OFFSET $${offsetParam}`, [...params, page_size, (page - 1) * page_size]);
468
+ return {
469
+ total_count,
470
+ pages_count: Math.ceil(total_count / page_size),
471
+ current_page: page,
472
+ has_next: total_count > page * page_size,
473
+ items: rowsRes.rows
474
+ };
475
+ });
212
476
  exports.default = ScheduleTransactionService;