@ercworldio/blockchain-shared 1.0.3-dev.4 → 1.0.3-dev.4-PROJ-1296.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.
Files changed (137) hide show
  1. package/build/chains/networks_dev copy.json +793 -0
  2. package/build/chains/networks_dev.json +12 -12
  3. package/build/chains/networks_prod-sh.json +40 -4
  4. package/build/chains/networks_prod-yb.json +40 -4
  5. package/build/contracts/Escrow.d.ts +66 -5
  6. package/build/contracts/Escrow.d.ts.map +1 -1
  7. package/build/contracts/Escrow.js +93 -2
  8. package/build/contracts/EscrowErrors.d.ts +85 -1
  9. package/build/contracts/EscrowErrors.d.ts.map +1 -1
  10. package/build/contracts/EscrowErrors.js +59 -14
  11. package/build/contracts/artifacts/Escrow.json +0 -12
  12. package/build/contracts/contract-events/AccessControlEvents.d.ts +12 -2
  13. package/build/contracts/contract-events/AccessControlEvents.d.ts.map +1 -1
  14. package/build/contracts/contract-events/AccessControlEvents.js +29 -5
  15. package/build/contracts/contract-events/EscrowEvents.d.ts +134 -2
  16. package/build/contracts/contract-events/EscrowEvents.d.ts.map +1 -1
  17. package/build/contracts/contract-events/EscrowEvents.js +67 -17
  18. package/build/contracts/contract-events/types/events.d.ts +35 -1
  19. package/build/contracts/contract-events/types/events.d.ts.map +1 -1
  20. package/build/contracts/typechain-types/contracts/escrow/Escrow.d.ts +1 -4
  21. package/build/contracts/typechain-types/contracts/escrow/Escrow.d.ts.map +1 -1
  22. package/build/contracts/typechain-types/contracts/lib/Events.d.ts +1 -4
  23. package/build/contracts/typechain-types/contracts/lib/Events.d.ts.map +1 -1
  24. package/build/contracts/typechain-types/factories/contracts/escrow/EscrowAccessControl__factory.d.ts +1 -1
  25. package/build/contracts/typechain-types/factories/contracts/escrow/EscrowAccessControl__factory.js +1 -1
  26. package/build/contracts/typechain-types/factories/contracts/escrow/Escrow__factory.d.ts +1 -6
  27. package/build/contracts/typechain-types/factories/contracts/escrow/Escrow__factory.d.ts.map +1 -1
  28. package/build/contracts/typechain-types/factories/contracts/escrow/Escrow__factory.js +1 -7
  29. package/build/contracts/typechain-types/factories/contracts/lib/Events__factory.d.ts +1 -6
  30. package/build/contracts/typechain-types/factories/contracts/lib/Events__factory.d.ts.map +1 -1
  31. package/build/contracts/typechain-types/factories/contracts/lib/Events__factory.js +1 -7
  32. package/build/contracts/types/escrow.d.ts +13 -1
  33. package/build/contracts/types/escrow.d.ts.map +1 -1
  34. package/build/contracts/types/escrow.js +4 -0
  35. package/build/entities/AdminOperationThresholds.d.ts +0 -1
  36. package/build/entities/AdminOperationThresholds.d.ts.map +1 -1
  37. package/build/entities/AdminOperationThresholds.js +1 -5
  38. package/build/entities/AdminWithdrawal.d.ts +20 -0
  39. package/build/entities/AdminWithdrawal.d.ts.map +1 -0
  40. package/build/entities/AdminWithdrawal.js +88 -0
  41. package/build/entities/ClaimJob.d.ts +1 -0
  42. package/build/entities/ClaimJob.d.ts.map +1 -1
  43. package/build/entities/ClaimJob.js +4 -0
  44. package/build/entities/CryptoOperationType.d.ts +18 -0
  45. package/build/entities/CryptoOperationType.d.ts.map +1 -0
  46. package/build/entities/CryptoOperationType.js +50 -0
  47. package/build/entities/EscrowRoles.js +1 -1
  48. package/build/entities/GlobalTimelock.d.ts +0 -1
  49. package/build/entities/GlobalTimelock.d.ts.map +1 -1
  50. package/build/entities/GlobalTimelock.js +1 -5
  51. package/build/entities/GranularTimelock .d.ts +0 -1
  52. package/build/entities/GranularTimelock .d.ts.map +1 -1
  53. package/build/entities/GranularTimelock .js +0 -4
  54. package/build/entities/GranularTimelock.d.ts +11 -0
  55. package/build/entities/GranularTimelock.d.ts.map +1 -0
  56. package/build/entities/GranularTimelock.js +52 -0
  57. package/build/entities/RoleHash.js +1 -1
  58. package/build/entities/ScheduleTransactionJob.d.ts +23 -0
  59. package/build/entities/ScheduleTransactionJob.d.ts.map +1 -0
  60. package/build/entities/ScheduleTransactionJob.js +89 -0
  61. package/build/entities/ScheduleTransactionJobHistory.d.ts +17 -0
  62. package/build/entities/ScheduleTransactionJobHistory.d.ts.map +1 -0
  63. package/build/entities/ScheduleTransactionJobHistory.js +66 -0
  64. package/build/entities/TokenExecutionThresholds.d.ts +0 -1
  65. package/build/entities/TokenExecutionThresholds.d.ts.map +1 -1
  66. package/build/entities/TokenExecutionThresholds.js +1 -5
  67. package/build/entities/WithdrawalCommitment.d.ts +15 -0
  68. package/build/entities/WithdrawalCommitment.d.ts.map +1 -0
  69. package/build/entities/WithdrawalCommitment.js +64 -0
  70. package/build/entities/index.d.ts +22 -0
  71. package/build/entities/index.d.ts.map +1 -0
  72. package/build/entities/index.js +37 -0
  73. package/build/errors/errors.d.ts +30 -0
  74. package/build/errors/errors.d.ts.map +1 -1
  75. package/build/errors/errors.js +64 -2
  76. package/build/index.d.ts +6 -9
  77. package/build/index.d.ts.map +1 -1
  78. package/build/index.js +22 -11
  79. package/build/interfaces.d.ts +2 -2
  80. package/build/interfaces.d.ts.map +1 -1
  81. package/build/services/AlchemyWebhooks.d.ts.map +1 -1
  82. package/build/services/AlchemyWebhooks.js +33 -29
  83. package/build/services/AzureEventHubHandler.d.ts.map +1 -1
  84. package/build/services/AzureEventHubHandler.js +17 -5
  85. package/build/services/ClaimJobService.d.ts +5 -2
  86. package/build/services/ClaimJobService.d.ts.map +1 -1
  87. package/build/services/ClaimJobService.js +135 -24
  88. package/build/services/ClaimJobServiceStatic.d.ts +9 -0
  89. package/build/services/ClaimJobServiceStatic.d.ts.map +1 -0
  90. package/build/services/ClaimJobServiceStatic.js +54 -0
  91. package/build/services/SweepJobService.d.ts +3 -3
  92. package/build/services/SweepJobService.d.ts.map +1 -1
  93. package/build/services/SweepJobService.js +7 -12
  94. package/build/services/WithdrawalService.d.ts +10 -0
  95. package/build/services/WithdrawalService.d.ts.map +1 -0
  96. package/build/services/WithdrawalService.js +36 -0
  97. package/build/services/db/multisig/MultisigService.d.ts +31 -0
  98. package/build/services/db/multisig/MultisigService.d.ts.map +1 -0
  99. package/build/services/db/multisig/MultisigService.js +134 -0
  100. package/build/services/db/roles/ContractRoles.d.ts +2 -2
  101. package/build/services/db/roles/ContractRoles.d.ts.map +1 -1
  102. package/build/services/db/roles/ContractRoles.js +18 -12
  103. package/build/services/db/timelock/ScheduleTransactionJobHistoryService.d.ts +14 -0
  104. package/build/services/db/timelock/ScheduleTransactionJobHistoryService.d.ts.map +1 -0
  105. package/build/services/db/timelock/ScheduleTransactionJobHistoryService.js +63 -0
  106. package/build/services/db/timelock/ScheduleTransactionService.d.ts +32 -0
  107. package/build/services/db/timelock/ScheduleTransactionService.d.ts.map +1 -0
  108. package/build/services/db/timelock/ScheduleTransactionService.js +212 -0
  109. package/build/services/types/azure_event_hub_handler.d.ts +9 -1
  110. package/build/services/types/azure_event_hub_handler.d.ts.map +1 -1
  111. package/build/services/types/azure_event_hub_handler.js +8 -0
  112. package/build/services/types/claim.d.ts +17 -1
  113. package/build/services/types/claim.d.ts.map +1 -1
  114. package/build/services/types/claim_job_service.d.ts +9 -1
  115. package/build/services/types/claim_job_service.d.ts.map +1 -1
  116. package/build/services/types/db/index.d.ts +3 -0
  117. package/build/services/types/db/index.d.ts.map +1 -0
  118. package/build/services/types/db/index.js +18 -0
  119. package/build/services/types/db/multisig_service.d.ts +154 -0
  120. package/build/services/types/db/multisig_service.d.ts.map +1 -0
  121. package/build/services/types/db/multisig_service.js +2 -0
  122. package/build/services/types/db/timelock.d.ts +28 -0
  123. package/build/services/types/db/timelock.d.ts.map +1 -0
  124. package/build/services/types/db/timelock.js +2 -0
  125. package/build/services/types/db/withdrawal_service.d.ts +16 -0
  126. package/build/services/types/db/withdrawal_service.d.ts.map +1 -0
  127. package/build/services/types/db/withdrawal_service.js +2 -0
  128. package/build/services/types/index.d.ts +1 -0
  129. package/build/services/types/index.d.ts.map +1 -1
  130. package/build/services/types/index.js +1 -0
  131. package/build/services/types/watchdog.d.ts +9 -0
  132. package/build/services/types/watchdog.d.ts.map +1 -0
  133. package/build/services/types/watchdog.js +2 -0
  134. package/build/utils/custodial.d.ts +8 -0
  135. package/build/utils/custodial.d.ts.map +1 -1
  136. package/build/utils/custodial.js +23 -2
  137. package/package.json +6 -3
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ /**
13
+ * Adapter class for interfacing the DB functions
14
+ * related to escrow multisig threshold execution settings
15
+ */
16
+ class MultisigService {
17
+ ///////////////////////////////////////////
18
+ /// Admin Operation Execution Thresholds
19
+ ///////////////////////////////////////////
20
+ /** Returns all admin operation signature thresholds for the given escrow. */
21
+ static fn_get_admin_operation_thresholds(pool, blockchain, chainId, escrow_address) {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ const result = yield pool.query(`SELECT multisig.fn_get_admin_operation_thresholds($1::text,$2::text,$3::text)`, [blockchain, chainId, escrow_address]);
24
+ if (!result)
25
+ throw new Error(`DB FN error: multisig.fn_get_admin_operation_thresholds()`);
26
+ return result.rows[0].fn_get_admin_operation_thresholds;
27
+ });
28
+ }
29
+ /** Inserts or updates the manager/executive signature thresholds for the given escrow. */
30
+ static fn_upsert_admin_operation_threshold(pool, blockchain, chainId, escrow_address, operation_type, sigs_manager, sigs_executive) {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ const result = yield pool.query(`SELECT multisig.fn_upsert_admin_operation_threshold($1::text,$2::text,$3::text,$4::integer,$5::integer,$6::integer)`, [blockchain, chainId, escrow_address, operation_type, sigs_manager, sigs_executive]);
33
+ if (!result)
34
+ throw new Error(`DB FN error: multisig.fn_upsert_admin_operation_threshold()`);
35
+ return result.rows[0].fn_upsert_admin_operation_threshold;
36
+ });
37
+ }
38
+ ///////////////////////////////////////////
39
+ /// Timelock Durations
40
+ ///////////////////////////////////////////
41
+ /** Returns all global timelock configs for the given escrow. */
42
+ static fn_get_global_timelock(pool, blockchain, chainId, escrow_address) {
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ const result = yield pool.query(`SELECT multisig.fn_get_global_timelock($1::text,$2::text,$3::text)`, [blockchain, chainId, escrow_address]);
45
+ if (!result)
46
+ throw new Error(`DB FN error: multisig.fn_get_global_timelock()`);
47
+ return result.rows[0].fn_get_global_timelock;
48
+ });
49
+ }
50
+ /** Inserts or updates the global timelock durations for a token/escrow pair. */
51
+ static fn_upsert_global_timelock(pool, blockchain, chainId, escrow_address, token_address, threshold_amount, duration_below_seconds, duration_above_seconds) {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ const result = yield pool.query(`SELECT multisig.fn_upsert_global_timelock($1::text,$2::text,$3::text,$4::text,$5::numeric,$6::bigint,$7::bigint)`, [blockchain, chainId, escrow_address, token_address, threshold_amount, duration_below_seconds, duration_above_seconds]);
54
+ if (!result)
55
+ throw new Error(`DB FN error: multisig.fn_upsert_global_timelock()`);
56
+ return result.rows[0].fn_upsert_global_timelock;
57
+ });
58
+ }
59
+ /** Returns all granular timelock configs for the given escrow. */
60
+ static fn_get_granular_timelock(pool, blockchain, chainId, escrow_address) {
61
+ return __awaiter(this, void 0, void 0, function* () {
62
+ const result = yield pool.query(`SELECT multisig.fn_get_granular_timelock($1::text,$2::text,$3::text)`, [blockchain, chainId, escrow_address]);
63
+ if (!result)
64
+ throw new Error(`DB FN error: multisig.fn_get_granular_timelock()`);
65
+ return result.rows[0].fn_get_granular_timelock;
66
+ });
67
+ }
68
+ /** Inserts or updates the timelock duration for a specific receiver address. */
69
+ static fn_upsert_granular_timelock(pool, blockchain, chainId, escrow_address, receiver_address, duration_seconds) {
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ const result = yield pool.query(`SELECT multisig.fn_upsert_granular_timelock($1::text,$2::text,$3::text,$4::text,$5::bigint)`, [blockchain, chainId, escrow_address, receiver_address, duration_seconds]);
72
+ if (!result)
73
+ throw new Error(`DB FN error: multisig.fn_upsert_granular_timelock()`);
74
+ return result.rows[0].fn_upsert_granular_timelock;
75
+ });
76
+ }
77
+ ///////////////////////////////////////////
78
+ /// Token Execution Thresholds
79
+ ///////////////////////////////////////////
80
+ /** Returns all per-token execution signature thresholds for the given escrow. */
81
+ static fn_get_token_execution_thresholds(pool, blockchain, chainId, escrow_address) {
82
+ return __awaiter(this, void 0, void 0, function* () {
83
+ const result = yield pool.query(`SELECT multisig.fn_get_token_execution_thresholds($1::text,$2::text,$3::text)`, [blockchain, chainId, escrow_address]);
84
+ if (!result)
85
+ throw new Error(`DB FN error: multisig.fn_get_token_execution_thresholds()`);
86
+ return result.rows[0].fn_get_token_execution_thresholds;
87
+ });
88
+ }
89
+ /** Inserts or updates the above/below signature thresholds for a token/escrow pair. */
90
+ static fn_upsert_token_execution_threshold(pool, blockchain, chainId, escrow_address, token_address, threshold_amount, sigs_executive_below, sigs_executive_above, sigs_manager_below, sigs_manager_above) {
91
+ return __awaiter(this, void 0, void 0, function* () {
92
+ const result = yield pool.query(`SELECT multisig.fn_upsert_token_execution_threshold($1::text,$2::text,$3::text,$4::text,$5::numeric,$6::bigint,$7::bigint,$8::bigint,$9::bigint)`, [blockchain, chainId, escrow_address, token_address, threshold_amount, sigs_executive_below, sigs_executive_above, sigs_manager_below, sigs_manager_above]);
93
+ if (!result)
94
+ throw new Error(`DB FN error: multisig.fn_upsert_token_execution_threshold()`);
95
+ return result.rows[0].fn_upsert_token_execution_threshold;
96
+ });
97
+ }
98
+ ///////////////////////////////////////////
99
+ /// Withdrawal Commitment
100
+ ///////////////////////////////////////////
101
+ static fn_get_withdrawal_commitments(pool, data) {
102
+ return __awaiter(this, void 0, void 0, function* () {
103
+ const result = yield pool.query(`SELECT multisig.fn_get_withdrawal_commitments($1::text,$2::text,$3::text,$4::text)`, [data.p_blockchain, data.p_chain_id, data.p_escrow_contract, data.p_status]);
104
+ if (!result)
105
+ throw new Error(`DB FN error: multisig.fn_get_withdrawal_commitments()`);
106
+ return result.rows[0].fn_get_withdrawal_commitments;
107
+ });
108
+ }
109
+ static fn_withdrawal_scheduled(pool, data) {
110
+ return __awaiter(this, void 0, void 0, function* () {
111
+ const result = yield pool.query(`SELECT multisig.fn_withdrawal_scheduled($1::text,$2::text,$3::text,$4::text,$5::bigint,$6::bigint,$7::numeric,$8::text,$9::text,$10::boolean,$11::text,$12::text,$13::text,$14::bigint,$15::bigint,$16::numeric)`, [data.p_blockchain, data.p_chain_id, data.p_escrow_contract, data.p_commitment_hash, data.p_request_id, data.p_execute_at, data.p_amount, data.p_token_address, data.p_receiver_address, data.p_confirmed, data.p_caller, data.p_sender, data.p_tx_hash, data.p_timestamp, data.p_block_number, data.p_gas_used]);
112
+ if (!result)
113
+ throw new Error(`DB FN error: multisig.fn_withdrawal_scheduled()`);
114
+ return result.rows[0].fn_withdrawal_scheduled;
115
+ });
116
+ }
117
+ static fn_withdrawal_executed(pool, data) {
118
+ return __awaiter(this, void 0, void 0, function* () {
119
+ const result = yield pool.query(`SELECT multisig.fn_withdrawal_executed($1::text,$2::text,$3::text,$4::text,$5::bigint,$6::boolean,$7::text,$8::text,$9::text,$10::bigint,$11::bigint,$12::numeric)`, [data.p_blockchain, data.p_chain_id, data.p_escrow_contract, data.p_commitment_hash, data.p_request_id, data.p_confirmed, data.p_caller, data.p_sender, data.p_tx_hash, data.p_timestamp, data.p_block_number, data.p_gas_used]);
120
+ if (!result)
121
+ throw new Error(`DB FN error: multisig.fn_withdrawal_executed()`);
122
+ return result.rows[0].fn_withdrawal_executed;
123
+ });
124
+ }
125
+ static fn_withdrawal_cancelled(pool, data) {
126
+ return __awaiter(this, void 0, void 0, function* () {
127
+ const result = yield pool.query(`SELECT multisig.fn_withdrawal_cancelled($1::text,$2::text,$3::text,$4::text,$5::bigint,$6::boolean,$7::text,$8::text,$9::text,$10::bigint,$11::bigint,$12::numeric)`, [data.p_blockchain, data.p_chain_id, data.p_escrow_contract, data.p_commitment_hash, data.p_request_id, data.p_confirmed, data.p_caller, data.p_sender, data.p_tx_hash, data.p_timestamp, data.p_block_number, data.p_gas_used]);
128
+ if (!result)
129
+ throw new Error(`DB FN error: multisig.fn_withdrawal_cancelled()`);
130
+ return result.rows[0].fn_withdrawal_cancelled;
131
+ });
132
+ }
133
+ }
134
+ exports.default = MultisigService;
@@ -46,9 +46,9 @@ declare class ContractRolesService {
46
46
  */
47
47
  static get_role_operation_types(pool: Pool, role_id: number): Promise<RoleOperationType[]>;
48
48
  /** Records an on-chain role grant for a wallet on an escrow contract. `confirmed` indicates whether the tx was finalised. */
49
- static fn_grant_escrow_role(pool: Pool, blockchain: BlockchainType, chain_id: ChainId, contract_address: string, wallet_address: string, role_hash: string, confirmed: boolean, p_caller: string, p_sender: string, p_tx_hash: string, p_timestamp: number, p_block_number: number, gas_used: number): Promise<any[]>;
49
+ static fn_grant_escrow_role(pool: Pool, blockchain: BlockchainType, chain_id: ChainId, contract_address: string, wallet_address: string, role_hash: string, p_user_id: number, confirmed: boolean, p_caller: string, p_sender: string, p_tx_hash: string, p_timestamp: number, p_block_number: number, gas_used: number): Promise<any>;
50
50
  /** Records an on-chain role revocation for a wallet on an escrow contract. `confirmed` indicates whether the tx was finalised. */
51
- static fn_revoke_escrow_role(pool: Pool, blockchain: BlockchainType, chain_id: ChainId, contract_address: string, wallet_address: string, role_hash: string, confirmed: boolean, p_caller: string, p_sender: string, p_tx_hash: string, p_timestamp: number, p_block_number: number, gas_used: number): Promise<any[]>;
51
+ static fn_revoke_escrow_role(pool: Pool, blockchain: BlockchainType, chain_id: ChainId, contract_address: string, wallet_address: string, role_hash: string, p_user_id: number, confirmed: boolean, p_caller: string, p_sender: string, p_tx_hash: string, p_timestamp: number, p_block_number: number, gas_used: number): Promise<any>;
52
52
  }
53
53
  export default ContractRolesService;
54
54
  //# sourceMappingURL=ContractRoles.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ContractRoles.d.ts","sourceRoot":"","sources":["../../../../src/services/db/roles/ContractRoles.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE9D,MAAM,WAAW,aAAa;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,YAAY;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,iBAAiB;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;CACvB;AAED;;;GAGG;AACH,cAAM,oBAAoB;IAEtB;;;;OAIG;WACU,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAU3D;;;;;OAKG;WACU,uBAAuB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAW1E;;;;OAIG;WACU,wBAAwB,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAahG,6HAA6H;WAChH,oBAAoB,CAC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WAAW,EAAE,MAAM,EACtC,cAAc,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;CAc/C;AAED,eAAe,oBAAoB,CAAC"}
@@ -26,7 +26,7 @@ class ContractRolesService {
26
26
  `);
27
27
  if (!result)
28
28
  throw new Error(`DB FN error: multisig.fn_get_roles()`);
29
- return result.rows;
29
+ return result.rows[0].fn_get_roles;
30
30
  });
31
31
  }
32
32
  /**
@@ -40,7 +40,9 @@ class ContractRolesService {
40
40
  const result = yield pool.query(`
41
41
  SELECT multisig.fn_get_all_operation_types()
42
42
  `);
43
- return result.rows;
43
+ if (!result.rows)
44
+ throw new Error(`DB FN Error: multisig.fn_get_all_operation_types`);
45
+ return result.rows[0].fn_get_all_operation_types;
44
46
  });
45
47
  }
46
48
  /**
@@ -53,27 +55,31 @@ class ContractRolesService {
53
55
  const result = yield pool.query(`
54
56
  SELECT multisig.fn_get_role_operation_types($1::bigint)
55
57
  `, [role_id]);
56
- if (!result)
58
+ if (!result || !result.rows)
57
59
  throw new Error(`DB FN error: multisig.gn_get_role_operation_types()`);
58
- return result.rows;
60
+ return result.rows[0].fn_get_role_operation_types;
59
61
  });
60
62
  }
61
63
  /** Records an on-chain role grant for a wallet on an escrow contract. `confirmed` indicates whether the tx was finalised. */
62
- static fn_grant_escrow_role(pool, blockchain, chain_id, contract_address, wallet_address, role_hash, confirmed, p_caller, p_sender, p_tx_hash, p_timestamp, p_block_number, gas_used) {
64
+ static fn_grant_escrow_role(pool, blockchain, chain_id, contract_address, wallet_address, role_hash, p_user_id, confirmed, p_caller, p_sender, p_tx_hash, p_timestamp, p_block_number, gas_used) {
63
65
  return __awaiter(this, void 0, void 0, function* () {
64
66
  const result = yield pool.query(`
65
- SELECT multisig.fn_grant_escrow_role($1::text,$2::text,$3::text,$4::text,$5::text,$6::boolean,$7::text,$8::text,$9::text,$10::bigint,$11::bigint,$12::numeric)
66
- `, [blockchain, chain_id, contract_address, wallet_address, role_hash, confirmed, p_caller, p_sender, p_tx_hash, p_timestamp, p_block_number, gas_used]);
67
- return result.rows;
67
+ SELECT multisig.fn_grant_escrow_role($1::text,$2::text,$3::text,$4::text,$5::text,$6::bigint,$7::boolean,$8::text,$9::text,$10::text,$11::bigint,$12::bigint,$13::numeric)
68
+ `, [blockchain, chain_id, contract_address, wallet_address, role_hash, p_user_id, confirmed, p_caller, p_sender, p_tx_hash, p_timestamp, p_block_number, gas_used]);
69
+ if (!result || !result.rows)
70
+ throw new Error(`DB FN Error: multisig.fn_grant_escrow_role`);
71
+ return result.rows[0].fn_grant_escrow_role;
68
72
  });
69
73
  }
70
74
  /** Records an on-chain role revocation for a wallet on an escrow contract. `confirmed` indicates whether the tx was finalised. */
71
- static fn_revoke_escrow_role(pool, blockchain, chain_id, contract_address, wallet_address, role_hash, confirmed, p_caller, p_sender, p_tx_hash, p_timestamp, p_block_number, gas_used) {
75
+ static fn_revoke_escrow_role(pool, blockchain, chain_id, contract_address, wallet_address, role_hash, p_user_id, confirmed, p_caller, p_sender, p_tx_hash, p_timestamp, p_block_number, gas_used) {
72
76
  return __awaiter(this, void 0, void 0, function* () {
73
77
  const result = yield pool.query(`
74
- SELECT multisig.fn_revoke_escrow_role($1::text,$2::text,$3::text,$4::text,$5::text,$6::boolean,$7::text,$8::text,$9::text,$10::bigint,$11::bigint,$12::numeric)
75
- `, [blockchain, chain_id, contract_address, wallet_address, role_hash, confirmed, p_caller, p_sender, p_tx_hash, p_timestamp, p_block_number, gas_used]);
76
- return result.rows;
78
+ SELECT multisig.fn_revoke_escrow_role($1::text,$2::text,$3::text,$4::text,$5::text,$6::bigint,$7::boolean,$8::text,$9::text,$10::text,$11::bigint,$12::bigint,$13::numeric)
79
+ `, [blockchain, chain_id, contract_address, wallet_address, role_hash, p_user_id, confirmed, p_caller, p_sender, p_tx_hash, p_timestamp, p_block_number, gas_used]);
80
+ if (!result || !result.rows)
81
+ throw new Error(`DB FN Error: multisig.fn_revoke_escrow_role`);
82
+ return result.rows[0].fn_revoke_escrow_role;
77
83
  });
78
84
  }
79
85
  }
@@ -0,0 +1,14 @@
1
+ import { Pool } from "pg";
2
+ import { OperationType } from "../../../contracts/types/escrow";
3
+ import { ScheduleTransactionJob } from "../../../entities/ScheduleTransactionJob";
4
+ import { ScheduleTransactionJobHistory } from "../../../entities/ScheduleTransactionJobHistory";
5
+ declare class ScheduleTransactionJobHistoryService {
6
+ /** Inserts a history snapshot for each job in the batch. */
7
+ static batch_insert: (pool: Pool, jobs: ScheduleTransactionJob[]) => Promise<void>;
8
+ /** Returns the full transition history for a job. */
9
+ static get_by_job_id: (pool: Pool, job_id: number) => Promise<ScheduleTransactionJobHistory[]>;
10
+ /** Returns the full transition history for a specific request and operation type. */
11
+ static get_by_request: (pool: Pool, request_id: number, operation_type: OperationType) => Promise<ScheduleTransactionJobHistory[]>;
12
+ }
13
+ export default ScheduleTransactionJobHistoryService;
14
+ //# sourceMappingURL=ScheduleTransactionJobHistoryService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ScheduleTransactionJobHistoryService.d.ts","sourceRoot":"","sources":["../../../../src/services/db/timelock/ScheduleTransactionJobHistoryService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,sBAAsB,EAAE,MAAM,0CAA0C,CAAC;AAClF,OAAO,EAAE,6BAA6B,EAAE,MAAM,iDAAiD,CAAC;AAEhG,cAAM,oCAAoC;IAEtC,4DAA4D;IAC5D,MAAM,CAAC,YAAY,GAAU,MAAM,IAAI,EAAE,MAAM,sBAAsB,EAAE,KAAG,OAAO,CAAC,IAAI,CAAC,CA2BrF;IAEF,qDAAqD;IACrD,MAAM,CAAC,aAAa,GAAU,MAAM,IAAI,EAAE,QAAQ,MAAM,KAAG,OAAO,CAAC,6BAA6B,EAAE,CAAC,CAQjG;IAEF,qFAAqF;IACrF,MAAM,CAAC,cAAc,GAAU,MAAM,IAAI,EAAE,YAAY,MAAM,EAAE,gBAAgB,aAAa,KAAG,OAAO,CAAC,6BAA6B,EAAE,CAAC,CASrI;CAEL;AAED,eAAe,oCAAoC,CAAC"}
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var _a;
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ class ScheduleTransactionJobHistoryService {
14
+ }
15
+ _a = ScheduleTransactionJobHistoryService;
16
+ /** Inserts a history snapshot for each job in the batch. */
17
+ ScheduleTransactionJobHistoryService.batch_insert = (pool, jobs) => __awaiter(void 0, void 0, void 0, function* () {
18
+ if (jobs.length === 0)
19
+ return;
20
+ const jobIds = jobs.map(j => j.id);
21
+ const requestIds = jobs.map(j => j.request_id);
22
+ const opTypes = jobs.map(j => j.operation_type);
23
+ const blockchains = jobs.map(j => j.blockchain);
24
+ const chainIds = jobs.map(j => j.chain_id);
25
+ const statuses = jobs.map(j => j.status);
26
+ const txHashes = jobs.map(j => { var _b; return (_b = j.tx_hash) !== null && _b !== void 0 ? _b : null; });
27
+ const retryCounts = jobs.map(j => j.retry_count);
28
+ const errorMessages = jobs.map(j => { var _b; return (_b = j.error_message) !== null && _b !== void 0 ? _b : null; });
29
+ yield pool.query(`
30
+ INSERT INTO multisig.schedule_transaction_jobs_history
31
+ (job_id, request_id, operation_type, blockchain, chain_id, status, tx_hash, retry_count, error_message)
32
+ SELECT
33
+ UNNEST($1::bigint[]),
34
+ UNNEST($2::int[]),
35
+ UNNEST($3::int[]),
36
+ UNNEST($4::text[]),
37
+ UNNEST($5::text[]),
38
+ UNNEST($6::text[]),
39
+ UNNEST($7::text[]),
40
+ UNNEST($8::int[]),
41
+ UNNEST($9::text[])
42
+ `, [jobIds, requestIds, opTypes, blockchains, chainIds, statuses, txHashes, retryCounts, errorMessages]);
43
+ });
44
+ /** Returns the full transition history for a job. */
45
+ ScheduleTransactionJobHistoryService.get_by_job_id = (pool, job_id) => __awaiter(void 0, void 0, void 0, function* () {
46
+ const res = yield pool.query(`
47
+ SELECT * FROM multisig.schedule_transaction_jobs_history
48
+ WHERE job_id = $1
49
+ ORDER BY created_at ASC
50
+ `, [job_id]);
51
+ return res.rows;
52
+ });
53
+ /** Returns the full transition history for a specific request and operation type. */
54
+ ScheduleTransactionJobHistoryService.get_by_request = (pool, request_id, operation_type) => __awaiter(void 0, void 0, void 0, function* () {
55
+ const res = yield pool.query(`
56
+ SELECT * FROM multisig.schedule_transaction_jobs_history
57
+ WHERE request_id = $1
58
+ AND operation_type = $2
59
+ ORDER BY created_at ASC
60
+ `, [request_id, operation_type]);
61
+ return res.rows;
62
+ });
63
+ exports.default = ScheduleTransactionJobHistoryService;
@@ -0,0 +1,32 @@
1
+ import { ScheduleJobStatus, ScheduleTransactionJob } from "../../../entities/ScheduleTransactionJob";
2
+ import { ClaimJobLockMetadata } from "../../types";
3
+ import { Pool } from "pg";
4
+ import { OperationType } from "../../../contracts/types/escrow";
5
+ import { MarkCompleteScheduleJob, ScheduleTransactionJobWithDetails } from "../../types/db";
6
+ import { RequeueJobConfiguration } from "../../types/watchdog";
7
+ declare class ScheduleTransactionService {
8
+ 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
+ static get_and_lock_available_jobs_with_details: (pool: Pool, limit?: number, job_ttl_s?: number, lock_metadata?: ClaimJobLockMetadata) => Promise<ScheduleTransactionJobWithDetails[]>;
11
+ /**
12
+ * Requeues all jobs in the given status to "queued"
13
+ */
14
+ static requeue_expired_jobs: (pool: Pool, data: RequeueJobConfiguration<ScheduleJobStatus>) => Promise<ScheduleTransactionJob[]>;
15
+ static batch_update_status: (pool: Pool, operation_type: OperationType, request_ids: number[], new_status: ScheduleJobStatus) => Promise<void>;
16
+ static batch_update_failed_jobs: (pool: Pool, operation_type: OperationType, request_ids: number[], new_status: ScheduleJobStatus, error_message?: string, retryable?: boolean) => Promise<void>;
17
+ static batch_update_failed_jobs_custom_error: (pool: Pool, operation_type: OperationType, jobs: {
18
+ request_id: number;
19
+ new_status: ScheduleJobStatus;
20
+ error_message: string;
21
+ retryable: boolean;
22
+ }[]) => Promise<void>;
23
+ static batch_update_executed_jobs: (pool: Pool, data: {
24
+ operation_type: OperationType;
25
+ request_id: number;
26
+ tx_hash: string;
27
+ sent_at: Date;
28
+ }[]) => Promise<void>;
29
+ static mark_complete: (pool: Pool, payloads: MarkCompleteScheduleJob[]) => Promise<void>;
30
+ }
31
+ export default ScheduleTransactionService;
32
+ //# sourceMappingURL=ScheduleTransactionService.d.ts.map
@@ -0,0 +1 @@
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,EAAE,uBAAuB,EAAE,iCAAiC,EAAE,MAAM,gBAAgB,CAAC;AAC5F,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAE/D,cAAM,0BAA0B;IAE5B,MAAM,CAAC,2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AAI,CAAC,CAwBd;IAGF,MAAM,CAAC,aAAa,GAAU,MAAM,IAAI,EAAE,UAAU,uBAAuB,EAAE,KAAG,OAAO,CAAC,IAAI,CAAC,CAmB5F;CAEJ;AAED,eAAe,0BAA0B,CAAC"}
@@ -0,0 +1,212 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var _a;
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ class ScheduleTransactionService {
14
+ }
15
+ _a = ScheduleTransactionService;
16
+ ScheduleTransactionService.get_and_lock_available_jobs = (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" }) {
17
+ const ttlSeconds = job_ttl_s;
18
+ const res = yield pool.query(`
19
+ WITH status_ids AS (
20
+ SELECT
21
+ MAX(CASE WHEN status = 'queued' THEN id END) AS queued_id,
22
+ MAX(CASE WHEN status = 'processing' THEN id END) AS processing_id
23
+ FROM multisig.schedule_job_statuses
24
+ ),
25
+ candidates AS (
26
+ SELECT cj.id
27
+ FROM multisig.schedule_transaction_jobs cj, status_ids
28
+ WHERE cj.status_id = status_ids.queued_id
29
+ AND (cj.lock_expires_at IS NULL OR cj.lock_expires_at < now())
30
+ ORDER BY cj.blockchain, cj.chain_id ASC
31
+ LIMIT $1
32
+ FOR UPDATE SKIP LOCKED
33
+ )
34
+ UPDATE multisig.schedule_transaction_jobs cj
35
+ SET
36
+ status_id = si.processing_id,
37
+ locked_at = now(),
38
+ lock_expires_at = now() + ($2 || ' seconds')::interval,
39
+ metadata = jsonb_set(
40
+ jsonb_set(
41
+ coalesce(cj.metadata, '{}'::jsonb),
42
+ '{lock_owner}',
43
+ to_jsonb($3::text)
44
+ ),
45
+ '{lock_reason}',
46
+ to_jsonb($4::text)
47
+ ),
48
+ updated_at = now()
49
+ FROM candidates c, status_ids si
50
+ WHERE cj.id = c.id
51
+ RETURNING cj.*;
52
+ `, [limit, ttlSeconds, lock_metadata.lock_owner, lock_metadata.lock_reason]);
53
+ return res.rows;
54
+ });
55
+ /** Locks and returns available jobs with full withdrawal details via DB function. */
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;
58
+ 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
+ return (_b = result.rows[0].fn_get_available_schedule_jobs_with_details) !== null && _b !== void 0 ? _b : [];
60
+ });
61
+ /**
62
+ * Requeues all jobs in the given status to "queued"
63
+ */
64
+ ScheduleTransactionService.requeue_expired_jobs = (pool, data) => __awaiter(void 0, void 0, void 0, function* () {
65
+ const res = yield pool.query(`
66
+ WITH status_ids AS (
67
+ SELECT
68
+ MAX(CASE WHEN status = $4::text THEN id END) AS current_status_id,
69
+ MAX(CASE WHEN status = 'queued' THEN id END) AS queued_id
70
+ FROM multisig.schedule_job_statuses
71
+ ),
72
+ expired AS (
73
+ SELECT sj.id
74
+ FROM multisig.schedule_transaction_jobs sj, status_ids
75
+ WHERE sj.status_id = status_ids.current_status_id
76
+ AND (
77
+ sj.lock_expires_at IS NULL
78
+ OR sj.lock_expires_at < now()
79
+ )
80
+ AND sj.retry_count < $5
81
+ ORDER BY sj.lock_expires_at ASC
82
+ LIMIT $1
83
+ FOR UPDATE SKIP LOCKED
84
+ )
85
+ UPDATE multisig.schedule_transaction_jobs cj
86
+ SET
87
+ status_id = si.queued_id,
88
+ locked_at = NULL,
89
+ lock_expires_at = NULL,
90
+ metadata = jsonb_set(
91
+ jsonb_set(
92
+ coalesce(metadata, '{}'::jsonb),
93
+ '{requeued_by}',
94
+ to_jsonb($2::text),
95
+ true
96
+ ),
97
+ '{requeue_reason}',
98
+ to_jsonb($3::text),
99
+ true
100
+ ),
101
+ updated_at = now()
102
+ FROM expired e, status_ids si
103
+ WHERE cj.id = e.id
104
+ RETURNING cj.*;
105
+ `, [data.limit, data.lock_owner, data.lock_reason, data.watch_status, data.max_retries]);
106
+ return res.rows;
107
+ });
108
+ ScheduleTransactionService.batch_update_status = (pool, operation_type, request_ids, new_status) => __awaiter(void 0, void 0, void 0, function* () {
109
+ yield pool.query(`
110
+ UPDATE multisig.schedule_transaction_jobs
111
+ SET
112
+ status_id = (SELECT id FROM multisig.schedule_job_statuses WHERE status = $1),
113
+ updated_at = CURRENT_TIMESTAMP
114
+ WHERE operation_type = $2::int
115
+ AND request_id = ANY($3)
116
+ `, [new_status, operation_type, request_ids]);
117
+ });
118
+ ScheduleTransactionService.batch_update_failed_jobs = (pool, operation_type, request_ids, new_status, error_message, retryable) => __awaiter(void 0, void 0, void 0, function* () {
119
+ yield pool.query(`
120
+ UPDATE multisig.schedule_transaction_jobs
121
+ SET
122
+ status_id = (SELECT id FROM multisig.schedule_job_statuses WHERE status = $1),
123
+ updated_at = CURRENT_TIMESTAMP,
124
+ error_message = COALESCE($2, error_message),
125
+ last_error_at = CASE
126
+ WHEN $2 IS NOT NULL THEN CURRENT_TIMESTAMP
127
+ ELSE last_error_at
128
+ END,
129
+ retry_count = CASE
130
+ WHEN $3 = true THEN retry_count + 1
131
+ ELSE retry_count
132
+ END
133
+ WHERE operation_type = $5
134
+ AND request_id = ANY($4)
135
+ `, [
136
+ new_status,
137
+ error_message || null,
138
+ retryable === true,
139
+ request_ids,
140
+ operation_type,
141
+ ]);
142
+ });
143
+ ScheduleTransactionService.batch_update_failed_jobs_custom_error = (pool, operation_type, jobs) => __awaiter(void 0, void 0, void 0, function* () {
144
+ const operationTypes = jobs.map(() => operation_type);
145
+ const requestIds = jobs.map(j => j.request_id);
146
+ const newStatuses = jobs.map(j => j.new_status);
147
+ const errorMessages = jobs.map(j => j.error_message);
148
+ const retryables = jobs.map(j => j.retryable);
149
+ yield pool.query(`
150
+ UPDATE multisig.schedule_transaction_jobs AS t
151
+ SET
152
+ status_id = sjs.id,
153
+ error_message = c.error_message,
154
+ last_error_at = CURRENT_TIMESTAMP,
155
+ retry_count = CASE WHEN c.retryable THEN t.retry_count + 1 ELSE t.retry_count END,
156
+ updated_at = CURRENT_TIMESTAMP
157
+ FROM (
158
+ SELECT
159
+ UNNEST($1::int[]) AS operation_type,
160
+ UNNEST($2::int[]) AS request_id,
161
+ UNNEST($3::text[]) AS status,
162
+ UNNEST($4::text[]) AS error_message,
163
+ UNNEST($5::boolean[]) AS retryable
164
+ ) AS c
165
+ JOIN multisig.schedule_job_statuses sjs ON sjs.status = c.status
166
+ WHERE t.operation_type = c.operation_type
167
+ AND t.request_id = c.request_id
168
+ `, [operationTypes, requestIds, newStatuses, errorMessages, retryables]);
169
+ });
170
+ ScheduleTransactionService.batch_update_executed_jobs = (pool, data) => __awaiter(void 0, void 0, void 0, function* () {
171
+ const requestIds = data.map(d => d.request_id);
172
+ const operationTypes = data.map(d => d.operation_type);
173
+ const txHashes = data.map(d => d.tx_hash);
174
+ const sentAts = data.map(d => d.sent_at);
175
+ yield pool.query(`
176
+ UPDATE multisig.schedule_transaction_jobs AS t
177
+ SET
178
+ tx_hash = c.tx_hash,
179
+ sent_at = c.sent_at,
180
+ status_id = (SELECT id FROM multisig.schedule_job_statuses WHERE status = 'confirming'),
181
+ updated_at = CURRENT_TIMESTAMP
182
+ FROM (
183
+ SELECT
184
+ UNNEST($1::int[]) AS operation_type,
185
+ UNNEST($2::int[]) AS request_id,
186
+ UNNEST($3::text[]) AS tx_hash,
187
+ UNNEST($4::timestamptz[]) AS sent_at
188
+ ) AS c
189
+ WHERE t.request_id = c.request_id
190
+ AND t.operation_type = c.operation_type
191
+ `, [operationTypes, requestIds, txHashes, sentAts]);
192
+ });
193
+ ScheduleTransactionService.mark_complete = (pool, payloads) => __awaiter(void 0, void 0, void 0, function* () {
194
+ if (payloads.length === 0)
195
+ return;
196
+ const requestIds = payloads.map(d => d.requestId);
197
+ const operationTypes = payloads.map(d => d.operationType);
198
+ yield pool.query(`
199
+ UPDATE multisig.schedule_transaction_jobs AS t
200
+ SET
201
+ status_id = (SELECT id FROM multisig.schedule_job_statuses WHERE status = 'completed'),
202
+ updated_at = CURRENT_TIMESTAMP
203
+ FROM (
204
+ SELECT
205
+ UNNEST($1::int[]) AS request_id,
206
+ UNNEST($2::int[]) AS operation_type
207
+ ) AS c
208
+ WHERE t.request_id = c.request_id
209
+ AND t.operation_type = c.operation_type
210
+ `, [requestIds, operationTypes]);
211
+ });
212
+ exports.default = ScheduleTransactionService;
@@ -7,7 +7,15 @@ export declare enum EventHubEventNames {
7
7
  ROLEREVOKED = "RoleRevoked",
8
8
  LOWRESERVES = "LowReserves",
9
9
  COVERAGEINFO = "CoverageInfo",
10
- TRANSFERLOGSRAW = "TransferLogsRaw"
10
+ TRANSFERLOGSRAW = "TransferLogsRaw",
11
+ SET_TOKEN_TIMELOCK = "SetTokenTimelock",
12
+ SET_TIMELOCK_GRANULAR = "SetTimelockGranular",
13
+ CONFIGURE_TOKEN_MULTISIG = "ConfigureTokenMultisig",
14
+ CONFIGURE_ADMIN_MULTISIG = "ConfigureAdminMultisig",
15
+ WITHDRAWAL_SCHEDUELED = "WithdrawalScheduled",
16
+ WITHDRAWAL_EXECUTED = "WithdrawalExecuted",
17
+ WITHDRAWAL_CANCELLED = "WithdrawalCancelled",
18
+ ADMIN_WITHDRAW = "AdminWithdraw"
11
19
  }
12
20
  export declare enum AzureEventHubNames {
13
21
  DEPOSIT = "deposits",
@@ -1 +1 @@
1
- {"version":3,"file":"azure_event_hub_handler.d.ts","sourceRoot":"","sources":["../../../src/services/types/azure_event_hub_handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,MAAM,CAAC,kBAAkB,EAAE,GAAG,CAAC,EAAE,kBAAkB,CAAC,CAAA;AACxF,oBAAY,kBAAkB;IAC1B,OAAO,YAAY;IACnB,UAAU,eAAe;IACzB,WAAW,gBAAgB;IAC3B,WAAW,gBAAgB;IAC3B,WAAW,gBAAgB;IAC3B,YAAY,iBAAiB;IAC7B,eAAe,oBAAoB;CACtC;AAED,oBAAY,kBAAkB;IAC1B,OAAO,aAAa;IACpB,UAAU,gBAAgB;IAC1B,YAAY,iBAAiB;IAC7B,eAAe,oBAAoB;CACtC"}
1
+ {"version":3,"file":"azure_event_hub_handler.d.ts","sourceRoot":"","sources":["../../../src/services/types/azure_event_hub_handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,MAAM,CAAC,kBAAkB,EAAE,GAAG,CAAC,EAAE,kBAAkB,CAAC,CAAA;AACxF,oBAAY,kBAAkB;IAC1B,OAAO,YAAY;IACnB,UAAU,eAAe;IACzB,WAAW,gBAAgB;IAC3B,WAAW,gBAAgB;IAC3B,WAAW,gBAAgB;IAC3B,YAAY,iBAAiB;IAC7B,eAAe,oBAAoB;IACnC,kBAAkB,qBAAqB;IACvC,qBAAqB,wBAAwB;IAC7C,wBAAwB,2BAA2B;IACnD,wBAAwB,2BAA2B;IACnD,qBAAqB,wBAAwB;IAC7C,mBAAmB,uBAAuB;IAC1C,oBAAoB,wBAAwB;IAC5C,cAAc,kBAAkB;CACnC;AAED,oBAAY,kBAAkB;IAC1B,OAAO,aAAa;IACpB,UAAU,gBAAgB;IAC1B,YAAY,iBAAiB;IAC7B,eAAe,oBAAoB;CACtC"}
@@ -10,6 +10,14 @@ var EventHubEventNames;
10
10
  EventHubEventNames["LOWRESERVES"] = "LowReserves";
11
11
  EventHubEventNames["COVERAGEINFO"] = "CoverageInfo";
12
12
  EventHubEventNames["TRANSFERLOGSRAW"] = "TransferLogsRaw";
13
+ EventHubEventNames["SET_TOKEN_TIMELOCK"] = "SetTokenTimelock";
14
+ EventHubEventNames["SET_TIMELOCK_GRANULAR"] = "SetTimelockGranular";
15
+ EventHubEventNames["CONFIGURE_TOKEN_MULTISIG"] = "ConfigureTokenMultisig";
16
+ EventHubEventNames["CONFIGURE_ADMIN_MULTISIG"] = "ConfigureAdminMultisig";
17
+ EventHubEventNames["WITHDRAWAL_SCHEDUELED"] = "WithdrawalScheduled";
18
+ EventHubEventNames["WITHDRAWAL_EXECUTED"] = "WithdrawalExecuted";
19
+ EventHubEventNames["WITHDRAWAL_CANCELLED"] = "WithdrawalCancelled";
20
+ EventHubEventNames["ADMIN_WITHDRAW"] = "AdminWithdraw";
13
21
  })(EventHubEventNames || (exports.EventHubEventNames = EventHubEventNames = {}));
14
22
  var AzureEventHubNames;
15
23
  (function (AzureEventHubNames) {
@@ -19,9 +19,25 @@ export interface WithdrawRequestDetails {
19
19
  blockchain: BlockchainType;
20
20
  receiver: string;
21
21
  paymentType: PaymentType;
22
- destinationBlockchain?: BLOCKCHAINS.EVM | BLOCKCHAINS.SOLANA;
22
+ destinationBlockchain?: BLOCKCHAINS.EVM | BLOCKCHAINS.SOLANA | BLOCKCHAINS.TRON;
23
23
  destinationChainId?: number;
24
24
  destinationToken?: string;
25
+ sigsExecutiveRequired?: number;
26
+ sigsManagerRequired?: number;
27
+ multisigSignatures: MultisigSignatureEntry[];
28
+ receiverAddress: string;
29
+ timeLockSeconds: number;
30
+ }
31
+ export interface MultisigSignatureEntry {
32
+ name: string;
33
+ signerAddress: string;
34
+ contractAddress: string;
35
+ createdAt: string;
36
+ updatedAt: string;
37
+ operationType: number;
38
+ v?: number;
39
+ r?: string;
40
+ s?: string;
25
41
  }
26
42
  export interface ClaimJobSuccessResult extends ClaimJobs {
27
43
  tx_hash: string;
@@ -1 +1 @@
1
- {"version":3,"file":"claim.d.ts","sourceRoot":"","sources":["../../../src/services/types/claim.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,UAAU,CAAC;AAEhD,MAAM,WAAW,mBAAmB;IAChC,UAAU,EAAE,cAAc,CAAC;IAC3B,YAAY,EAAE,WAAW,CAAC;CAC7B;AACD,MAAM,MAAM,aAAa,GACnB,SAAS,GACT,YAAY,GACZ,UAAU,GACV,UAAU,GACV,UAAU,GACV,MAAM,GACN,aAAa,CAAC;AAEpB,MAAM,MAAM,SAAS,GACf,QAAQ,GACR,YAAY,GACZ,WAAW,GACX,YAAY,GACZ,aAAa,GACb,kBAAkB,GAClB,QAAQ,CAAC;AAEf,MAAM,WAAW,sBAAsB;IACnC,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,aAAa,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IAGd,UAAU,EAAE,cAAc,CAAC;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,WAAW,CAAC;IAEzB,qBAAqB,CAAC,EAAE,WAAW,CAAC,GAAG,GAAG,WAAW,CAAC,MAAM,CAAC;IAC7D,kBAAkB,CAAC,EAA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