@ercworldio/blockchain-shared 1.0.5-dev.7-PROJ-1469.13 → 1.0.5-dev.7-PROJ-1469.15
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.
- package/build/services/db/timelock/ScheduleTransactionService.d.ts +3 -1
- package/build/services/db/timelock/ScheduleTransactionService.d.ts.map +1 -1
- package/build/services/db/timelock/ScheduleTransactionService.js +116 -1
- package/build/services/solana/escrow/SolanaEscrowAdmin.d.ts +13 -0
- package/build/services/solana/escrow/SolanaEscrowAdmin.d.ts.map +1 -1
- package/build/services/solana/escrow/SolanaEscrowAdmin.js +8 -0
- package/build/services/solana/escrow/services/EscrowAdminUtility.d.ts +41 -0
- package/build/services/solana/escrow/services/EscrowAdminUtility.d.ts.map +1 -1
- package/build/services/solana/escrow/services/EscrowAdminUtility.js +121 -14
- package/package.json +1 -1
|
@@ -6,8 +6,10 @@ import { MarkCompleteScheduleJob, ScheduleTransactionJobWithDetails } from "../.
|
|
|
6
6
|
import { RequeueJobConfiguration } from "../../types/watchdog";
|
|
7
7
|
declare class ScheduleTransactionService {
|
|
8
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. */
|
|
9
|
+
/** Locks and returns available jobs with full withdrawal details via inline SQL (bypasses DB function). */
|
|
10
10
|
static get_and_lock_available_jobs_with_details: (pool: Pool, limit?: number, job_ttl_s?: number, lock_metadata?: ClaimJobLockMetadata) => Promise<ScheduleTransactionJobWithDetails[]>;
|
|
11
|
+
/** Locks and returns available jobs with full withdrawal details via DB function. */
|
|
12
|
+
static get_and_lock_available_jobs_with_details_depr: (pool: Pool, limit?: number, job_ttl_s?: number, lock_metadata?: ClaimJobLockMetadata) => Promise<ScheduleTransactionJobWithDetails[]>;
|
|
11
13
|
/**
|
|
12
14
|
* Requeues all jobs in the given status to "queued"
|
|
13
15
|
*/
|
|
@@ -1 +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,2BAA2B,GAAU,MAAM,IAAI,EAAE,QAAO,MAAW,EAAE,YAAW,MAAY,EAAE,gBAAe,oBAA0F,KAAG,OAAO,CAAC,sBAAsB,EAAE,CAAC,CA4CjP;IAGD,
|
|
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,2BAA2B,GAAU,MAAM,IAAI,EAAE,QAAO,MAAW,EAAE,YAAW,MAAY,EAAE,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AAC;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"}
|
|
@@ -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 : [];
|
|
@@ -97,6 +97,19 @@ declare class SolanaEscrowAdmin {
|
|
|
97
97
|
request_id: number;
|
|
98
98
|
receiver_pubkey: PublicKey | string;
|
|
99
99
|
}>) => Promise<string>;
|
|
100
|
+
/** Simulate a batch withdraw (schedule/immediate) to detect requests that would revert. */
|
|
101
|
+
simulate_withdraw_batch: (chain_id: ChainId, token_address: string, receivers: BatchReceiver[]) => Promise<{
|
|
102
|
+
ok: boolean;
|
|
103
|
+
error: string | null;
|
|
104
|
+
}>;
|
|
105
|
+
/** Simulate a batch execute to detect requests that would revert (timelock, already executed). */
|
|
106
|
+
simulate_batch_execute_withdrawal: (chain_id: ChainId, token_address: string, receivers: Array<{
|
|
107
|
+
request_id: number;
|
|
108
|
+
receiver_pubkey: PublicKey | string;
|
|
109
|
+
}>) => Promise<{
|
|
110
|
+
ok: boolean;
|
|
111
|
+
error: string | null;
|
|
112
|
+
}>;
|
|
100
113
|
/**
|
|
101
114
|
* Idempotently ensures the batch path's Address Lookup Table exists and covers `mints`.
|
|
102
115
|
* Safe to call on every startup: it discovers an existing table on-chain, extends it when
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolanaEscrowAdmin.d.ts","sourceRoot":"","sources":["../../../../src/services/solana/escrow/SolanaEscrowAdmin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS,EAAqC,MAAM,iBAAiB,CAAC;AAEpG,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAC;AAE5C,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC,OAAO,EAAE,aAAa,EAAE,4BAA4B,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACtG,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAkB9C,UAAU,2BAA2B;IACjC,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,EAAE,OAAO,CAAC;IAClB;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC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AG,MAAM,CAAA;KAAE,CAAC;;;OAGhF;IAED;;;;;;;;OAQG;IACI,mBAAmB,GAAU,OAAO,MAAM,EAAE,qBAGlD;IAED,8FAA8F;IACvF,mBAAmB,GAAU,OAAO,MAAM,EAAE,qBAElD;IAGD;;;;;;OAMG;IACI,QAAQ,GAAU,eAAe,MAAM,EAAE,oBAAoB,MAAM,EAAE,kBAAkB,MAAM,iCAEnG;IAED;;;;;OAKG;IACI,OAAO,GAAU,eAAe,MAAM,EAAE,oBAAoB,MAAM,qBAExE;CAKJ;AAED,eAAe,iBAAiB,CAAC"}
|
|
@@ -172,6 +172,14 @@ class SolanaEscrowAdmin {
|
|
|
172
172
|
this.batch_execute_withdrawal = (chain_id, token_address, receivers) => __awaiter(this, void 0, void 0, function* () {
|
|
173
173
|
return this.adminUtility.batch_execute_withdrawal(chain_id, token_address, receivers, this.signer);
|
|
174
174
|
});
|
|
175
|
+
/** Simulate a batch withdraw (schedule/immediate) to detect requests that would revert. */
|
|
176
|
+
this.simulate_withdraw_batch = (chain_id, token_address, receivers) => __awaiter(this, void 0, void 0, function* () {
|
|
177
|
+
return this.adminUtility.simulate_withdraw_batch(chain_id, token_address, receivers);
|
|
178
|
+
});
|
|
179
|
+
/** Simulate a batch execute to detect requests that would revert (timelock, already executed). */
|
|
180
|
+
this.simulate_batch_execute_withdrawal = (chain_id, token_address, receivers) => __awaiter(this, void 0, void 0, function* () {
|
|
181
|
+
return this.adminUtility.simulate_batch_execute_withdrawal(chain_id, token_address, receivers);
|
|
182
|
+
});
|
|
175
183
|
/**
|
|
176
184
|
* Idempotently ensures the batch path's Address Lookup Table exists and covers `mints`.
|
|
177
185
|
* Safe to call on every startup: it discovers an existing table on-chain, extends it when
|
|
@@ -141,8 +141,32 @@ export declare class EscrowAdminUtility {
|
|
|
141
141
|
request_id: number;
|
|
142
142
|
receiver_pubkey: PublicKey | string;
|
|
143
143
|
}>, signer?: Keypair): Promise<string>;
|
|
144
|
+
/** Builds the SOL batch-execute instruction. Shared by the send and simulate paths. */
|
|
145
|
+
private build_batch_execute_sol_ixs;
|
|
146
|
+
/** Builds the SPL batch-execute instruction. Shared by the send and simulate paths. */
|
|
147
|
+
private build_batch_execute_spl_ixs;
|
|
144
148
|
private batch_execute_withdrawal_sol;
|
|
145
149
|
private batch_execute_withdrawal_spl;
|
|
150
|
+
/**
|
|
151
|
+
* Simulates a batch execute without sending, returning `{ ok, error }`. The funding worker
|
|
152
|
+
* uses it to quarantine requests that would revert (timelock not elapsed, commitment already
|
|
153
|
+
* executed, …) before committing the real batch — the program reverts the whole transaction
|
|
154
|
+
* without naming the offending request, so callers simulate one request at a time.
|
|
155
|
+
*/
|
|
156
|
+
simulate_batch_execute_withdrawal(chain_id: ChainId, token_address: string, receivers: Array<{
|
|
157
|
+
request_id: number;
|
|
158
|
+
receiver_pubkey: PublicKey | string;
|
|
159
|
+
}>): Promise<{
|
|
160
|
+
ok: boolean;
|
|
161
|
+
error: string | null;
|
|
162
|
+
}>;
|
|
163
|
+
/**
|
|
164
|
+
* Builds an (unsigned) transaction from `ixs` and simulates it. Returns `{ ok:false, error }`
|
|
165
|
+
* with the revert reason from the program logs when it would fail. `sigVerify:false` skips the
|
|
166
|
+
* missing fee-payer signature; the Ed25519 program instruction still executes, so invalid or
|
|
167
|
+
* insufficient treasury signatures are caught here too.
|
|
168
|
+
*/
|
|
169
|
+
private simulateInstructions;
|
|
146
170
|
/** Per-request PDAs the folded batch path expects: receiver timelock override + commitment. */
|
|
147
171
|
private request_pdas;
|
|
148
172
|
/** Matches the program's IDS_PER_PAGE — the replay-bitmap page a request id maps to. */
|
|
@@ -160,9 +184,26 @@ export declare class EscrowAdminUtility {
|
|
|
160
184
|
* signatures, so plain batches send just the withdraw instruction.
|
|
161
185
|
*/
|
|
162
186
|
private buildBatchTreasuryEd25519;
|
|
187
|
+
/**
|
|
188
|
+
* Builds the instruction list for an SPL batch withdraw: an optional treasury Ed25519 proof
|
|
189
|
+
* followed by the batch instruction. Shared by the send and simulate paths so they never drift.
|
|
190
|
+
*/
|
|
191
|
+
private build_batch_withdraw_spl_ixs;
|
|
163
192
|
/** @dev this might fail if the recipient does not have an ATA - take care of it in funding worker task */
|
|
164
193
|
private batch_withdraw_spl;
|
|
194
|
+
/** Builds the instruction list for a SOL batch withdraw (optional treasury proof + batch ix). */
|
|
195
|
+
private build_batch_withdraw_sol_ixs;
|
|
165
196
|
private batch_withdraw_sol;
|
|
197
|
+
/**
|
|
198
|
+
* Simulates a batch withdraw without sending, returning `{ ok, error }`. Used by the funding
|
|
199
|
+
* worker to quarantine individual requests that would revert (bad/insufficient signatures,
|
|
200
|
+
* already scheduled, …) before committing the real batch — the program reverts the whole
|
|
201
|
+
* transaction without naming the offending request, so callers simulate one request at a time.
|
|
202
|
+
*/
|
|
203
|
+
simulate_withdraw_batch(chain_id: ChainId, token_address: string, recipients: BatchReceiver[]): Promise<{
|
|
204
|
+
ok: boolean;
|
|
205
|
+
error: string | null;
|
|
206
|
+
}>;
|
|
166
207
|
private withdraw_sol;
|
|
167
208
|
private withdraw_spl;
|
|
168
209
|
private deposit_sol;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EscrowAdminUtility.d.ts","sourceRoot":"","sources":["../../../../../src/services/solana/escrow/services/EscrowAdminUtility.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAwD,UAAU,EAAE,OAAO,EAAoB,SAAS,EAA0H,oBAAoB,EAAwB,MAAM,iBAAiB,CAAC;AAG7S,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAKzC,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAGjD,qBAAa,kBAAkB;IACpB,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;I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M,GAAG,kBAAkB;CAM5J;AAED,eAAe,kBAAkB,CAAC"}
|
|
@@ -595,7 +595,8 @@ class EscrowAdminUtility {
|
|
|
595
595
|
: this.batch_execute_withdrawal_spl(chain_id, token_pubkey, receivers, signer);
|
|
596
596
|
});
|
|
597
597
|
}
|
|
598
|
-
|
|
598
|
+
/** Builds the SOL batch-execute instruction. Shared by the send and simulate paths. */
|
|
599
|
+
build_batch_execute_sol_ixs(receivers) {
|
|
599
600
|
return __awaiter(this, void 0, void 0, function* () {
|
|
600
601
|
const escrowConfigPda = EscrowService.findEscrowConfigPda(this.program.programId);
|
|
601
602
|
const vaultAuthority = EscrowService.findVaultAuthorityPda(this.program.programId);
|
|
@@ -619,12 +620,11 @@ class EscrowAdminUtility {
|
|
|
619
620
|
})
|
|
620
621
|
.remainingAccounts(remaining)
|
|
621
622
|
.instruction();
|
|
622
|
-
|
|
623
|
-
yield this.waitForConfirmation(signature, "confirmed");
|
|
624
|
-
return signature;
|
|
623
|
+
return [ix];
|
|
625
624
|
});
|
|
626
625
|
}
|
|
627
|
-
|
|
626
|
+
/** Builds the SPL batch-execute instruction. Shared by the send and simulate paths. */
|
|
627
|
+
build_batch_execute_spl_ixs(mint, receivers) {
|
|
628
628
|
return __awaiter(this, void 0, void 0, function* () {
|
|
629
629
|
const escrowConfigPda = EscrowService.findEscrowConfigPda(this.program.programId);
|
|
630
630
|
const vaultAuthority = EscrowService.findVaultAuthorityPda(this.program.programId);
|
|
@@ -654,11 +654,80 @@ class EscrowAdminUtility {
|
|
|
654
654
|
})
|
|
655
655
|
.remainingAccounts(remaining)
|
|
656
656
|
.instruction();
|
|
657
|
-
|
|
657
|
+
return [ix];
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
batch_execute_withdrawal_sol(_chainId, receivers, signer) {
|
|
661
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
662
|
+
const ixs = yield this.build_batch_execute_sol_ixs(receivers);
|
|
663
|
+
const signature = yield this.sendTransaction(ixs, signer);
|
|
658
664
|
yield this.waitForConfirmation(signature, "confirmed");
|
|
659
665
|
return signature;
|
|
660
666
|
});
|
|
661
667
|
}
|
|
668
|
+
batch_execute_withdrawal_spl(_chainId, mint, receivers, signer) {
|
|
669
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
670
|
+
const ixs = yield this.build_batch_execute_spl_ixs(mint, receivers);
|
|
671
|
+
const signature = yield this.sendTransaction(ixs, signer);
|
|
672
|
+
yield this.waitForConfirmation(signature, "confirmed");
|
|
673
|
+
return signature;
|
|
674
|
+
});
|
|
675
|
+
}
|
|
676
|
+
/**
|
|
677
|
+
* Simulates a batch execute without sending, returning `{ ok, error }`. The funding worker
|
|
678
|
+
* uses it to quarantine requests that would revert (timelock not elapsed, commitment already
|
|
679
|
+
* executed, …) before committing the real batch — the program reverts the whole transaction
|
|
680
|
+
* without naming the offending request, so callers simulate one request at a time.
|
|
681
|
+
*/
|
|
682
|
+
simulate_batch_execute_withdrawal(chain_id, token_address, receivers) {
|
|
683
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
684
|
+
const token_pubkey = new web3_js_1.PublicKey(token_address);
|
|
685
|
+
try {
|
|
686
|
+
yield this.ensure_lookup_table([token_address]);
|
|
687
|
+
}
|
|
688
|
+
catch (_a) {
|
|
689
|
+
this.lookupTableAddress = undefined;
|
|
690
|
+
this.lookupTableCache = undefined;
|
|
691
|
+
}
|
|
692
|
+
const ixs = token_pubkey.equals(web3_js_1.SystemProgram.programId)
|
|
693
|
+
? yield this.build_batch_execute_sol_ixs(receivers)
|
|
694
|
+
: yield this.build_batch_execute_spl_ixs(token_pubkey, receivers);
|
|
695
|
+
return this.simulateInstructions(ixs);
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
/**
|
|
699
|
+
* Builds an (unsigned) transaction from `ixs` and simulates it. Returns `{ ok:false, error }`
|
|
700
|
+
* with the revert reason from the program logs when it would fail. `sigVerify:false` skips the
|
|
701
|
+
* missing fee-payer signature; the Ed25519 program instruction still executes, so invalid or
|
|
702
|
+
* insufficient treasury signatures are caught here too.
|
|
703
|
+
*/
|
|
704
|
+
simulateInstructions(ixs) {
|
|
705
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
706
|
+
var _a, _b, _c;
|
|
707
|
+
try {
|
|
708
|
+
const lookupTables = yield this.resolveLookupTables();
|
|
709
|
+
const message = new web3_js_1.TransactionMessage({
|
|
710
|
+
payerKey: this.provider.wallet.publicKey,
|
|
711
|
+
recentBlockhash: (yield this.provider.connection.getLatestBlockhash()).blockhash,
|
|
712
|
+
instructions: ixs,
|
|
713
|
+
}).compileToV0Message(lookupTables);
|
|
714
|
+
const tx = new web3_js_1.VersionedTransaction(message);
|
|
715
|
+
const sim = yield this.provider.connection.simulateTransaction(tx, {
|
|
716
|
+
sigVerify: false,
|
|
717
|
+
replaceRecentBlockhash: true,
|
|
718
|
+
});
|
|
719
|
+
if (sim.value.err) {
|
|
720
|
+
const logs = (_a = sim.value.logs) !== null && _a !== void 0 ? _a : [];
|
|
721
|
+
const reason = (_b = logs.find(l => l.includes("Error") || l.includes("failed"))) !== null && _b !== void 0 ? _b : JSON.stringify(sim.value.err);
|
|
722
|
+
return { ok: false, error: reason };
|
|
723
|
+
}
|
|
724
|
+
return { ok: true, error: null };
|
|
725
|
+
}
|
|
726
|
+
catch (error) {
|
|
727
|
+
return { ok: false, error: (_c = error === null || error === void 0 ? void 0 : error.message) !== null && _c !== void 0 ? _c : "simulation failed" };
|
|
728
|
+
}
|
|
729
|
+
});
|
|
730
|
+
}
|
|
662
731
|
/** Per-request PDAs the folded batch path expects: receiver timelock override + commitment. */
|
|
663
732
|
request_pdas(receiver, request_id) {
|
|
664
733
|
const ridBuf = Buffer.alloc(8);
|
|
@@ -717,8 +786,11 @@ class EscrowAdminUtility {
|
|
|
717
786
|
}
|
|
718
787
|
return entries.length ? (0, TreasuryWithdrawalSignature_1.buildTreasuryEd25519Instruction)(entries) : null;
|
|
719
788
|
}
|
|
720
|
-
/**
|
|
721
|
-
|
|
789
|
+
/**
|
|
790
|
+
* Builds the instruction list for an SPL batch withdraw: an optional treasury Ed25519 proof
|
|
791
|
+
* followed by the batch instruction. Shared by the send and simulate paths so they never drift.
|
|
792
|
+
*/
|
|
793
|
+
build_batch_withdraw_spl_ixs(chainId, mint, recipients) {
|
|
722
794
|
return __awaiter(this, void 0, void 0, function* () {
|
|
723
795
|
const escrowConfigPda = EscrowService.findEscrowConfigPda(this.program.programId);
|
|
724
796
|
const vaultAuthority = EscrowService.findVaultAuthorityPda(this.program.programId);
|
|
@@ -752,14 +824,21 @@ class EscrowAdminUtility {
|
|
|
752
824
|
})
|
|
753
825
|
.remainingAccounts(receivers)
|
|
754
826
|
.instruction();
|
|
755
|
-
// Prepend the treasury multisig proof when any request in the batch requires it.
|
|
756
827
|
const ed25519 = this.buildBatchTreasuryEd25519(chainId, mint, recipients);
|
|
757
|
-
|
|
828
|
+
return ed25519 ? [ed25519, ix] : [ix];
|
|
829
|
+
});
|
|
830
|
+
}
|
|
831
|
+
/** @dev this might fail if the recipient does not have an ATA - take care of it in funding worker task */
|
|
832
|
+
batch_withdraw_spl(chainId, mint, recipients, signer) {
|
|
833
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
834
|
+
const ixs = yield this.build_batch_withdraw_spl_ixs(chainId, mint, recipients);
|
|
835
|
+
const signature = yield this.sendTransaction(ixs, signer);
|
|
758
836
|
yield this.waitForConfirmation(signature, "confirmed");
|
|
759
837
|
return signature;
|
|
760
838
|
});
|
|
761
839
|
}
|
|
762
|
-
|
|
840
|
+
/** Builds the instruction list for a SOL batch withdraw (optional treasury proof + batch ix). */
|
|
841
|
+
build_batch_withdraw_sol_ixs(chainId, recipients) {
|
|
763
842
|
return __awaiter(this, void 0, void 0, function* () {
|
|
764
843
|
const escrowConfigPda = EscrowService.findEscrowConfigPda(this.program.programId);
|
|
765
844
|
const vaultAuthority = EscrowService.findVaultAuthorityPda(this.program.programId);
|
|
@@ -788,10 +867,38 @@ class EscrowAdminUtility {
|
|
|
788
867
|
})
|
|
789
868
|
.remainingAccounts(receivers)
|
|
790
869
|
.instruction();
|
|
791
|
-
// Prepend the treasury multisig proof when any request in the batch requires it.
|
|
792
870
|
const ed25519 = this.buildBatchTreasuryEd25519(chainId, web3_js_1.SystemProgram.programId, recipients);
|
|
793
|
-
|
|
794
|
-
|
|
871
|
+
return ed25519 ? [ed25519, ix] : [ix];
|
|
872
|
+
});
|
|
873
|
+
}
|
|
874
|
+
batch_withdraw_sol(chainId, recipients, signer) {
|
|
875
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
876
|
+
const ixs = yield this.build_batch_withdraw_sol_ixs(chainId, recipients);
|
|
877
|
+
return this.sendTransaction(ixs, signer);
|
|
878
|
+
});
|
|
879
|
+
}
|
|
880
|
+
/**
|
|
881
|
+
* Simulates a batch withdraw without sending, returning `{ ok, error }`. Used by the funding
|
|
882
|
+
* worker to quarantine individual requests that would revert (bad/insufficient signatures,
|
|
883
|
+
* already scheduled, …) before committing the real batch — the program reverts the whole
|
|
884
|
+
* transaction without naming the offending request, so callers simulate one request at a time.
|
|
885
|
+
*/
|
|
886
|
+
simulate_withdraw_batch(chain_id, token_address, recipients) {
|
|
887
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
888
|
+
const token_pubkey = new web3_js_1.PublicKey(token_address);
|
|
889
|
+
if (recipients.some(r => { var _a; return (_a = r.signatures) === null || _a === void 0 ? void 0 : _a.length; })) {
|
|
890
|
+
try {
|
|
891
|
+
yield this.ensure_lookup_table([token_address]);
|
|
892
|
+
}
|
|
893
|
+
catch (_a) {
|
|
894
|
+
this.lookupTableAddress = undefined;
|
|
895
|
+
this.lookupTableCache = undefined;
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
const ixs = token_pubkey.equals(web3_js_1.SystemProgram.programId)
|
|
899
|
+
? yield this.build_batch_withdraw_sol_ixs(chain_id, recipients)
|
|
900
|
+
: yield this.build_batch_withdraw_spl_ixs(chain_id, token_pubkey, recipients);
|
|
901
|
+
return this.simulateInstructions(ixs);
|
|
795
902
|
});
|
|
796
903
|
}
|
|
797
904
|
withdraw_sol(amount_in_decimals, receiver_pubkey, signer) {
|
package/package.json
CHANGED