@ocap/tx-protocols 1.31.5 → 1.31.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.
- package/esm/bridge-release-crypto.mjs +1 -1
- package/esm/execute.mjs +24 -5
- package/esm/gas-security-guard.d.mts +2 -8
- package/esm/gas-security-guard.mjs +16 -1
- package/esm/index.d.mts +16 -3
- package/esm/index.mjs +0 -2
- package/esm/pipes/ensure-cost.mjs +3 -0
- package/esm/pipes/ensure-gas.d.mts +2 -1
- package/esm/pipes/write-ledger.mjs +2 -1
- package/esm/protocols/bridge/release-checks.d.mts +69 -0
- package/esm/protocols/bridge/{release.mjs → release-checks.mjs} +101 -100
- package/esm/protocols/rollup/bridge-create.mjs +2 -2
- package/esm/protocols/rollup/bridge-membership.mjs +10 -12
- package/esm/protocols/rollup/bridge-v2.d.mts +15 -5
- package/esm/protocols/rollup/bridge-v2.mjs +33 -8
- package/esm/protocols/token/deposit-v2.mjs +126 -25
- package/esm/protocols/token/withdraw-v2.d.mts +13 -1
- package/esm/protocols/token/withdraw-v2.mjs +158 -25
- package/esm/protocols/trade/transfer-v2.mjs +3 -8
- package/lib/bridge-release-crypto.cjs +1 -1
- package/lib/execute.cjs +24 -5
- package/lib/gas-security-guard.cjs +16 -1
- package/lib/gas-security-guard.d.cts +2 -8
- package/lib/index.cjs +0 -2
- package/lib/index.d.cts +16 -3
- package/lib/pipes/ensure-cost.cjs +3 -0
- package/lib/pipes/ensure-gas.d.cts +2 -1
- package/lib/pipes/write-ledger.cjs +2 -1
- package/lib/protocols/bridge/{release.cjs → release-checks.cjs} +115 -101
- package/lib/protocols/bridge/release-checks.d.cts +69 -0
- package/lib/protocols/rollup/bridge-create.cjs +1 -1
- package/lib/protocols/rollup/bridge-membership.cjs +9 -10
- package/lib/protocols/rollup/bridge-v2.cjs +32 -5
- package/lib/protocols/rollup/bridge-v2.d.cts +15 -5
- package/lib/protocols/token/deposit-v2.cjs +125 -24
- package/lib/protocols/token/withdraw-v2.cjs +155 -22
- package/lib/protocols/token/withdraw-v2.d.cts +13 -1
- package/lib/protocols/trade/transfer-v2.cjs +2 -7
- package/package.json +16 -16
- package/esm/protocols/bridge/release.d.mts +0 -34
- package/lib/protocols/bridge/release.d.cts +0 -34
|
@@ -2,7 +2,7 @@ import { Hasher, Signer } from "@ocap/mcrypto";
|
|
|
2
2
|
|
|
3
3
|
//#region src/bridge-release-crypto.ts
|
|
4
4
|
/**
|
|
5
|
-
* EIP-712 digests and signature recovery for `
|
|
5
|
+
* EIP-712 digests and signature recovery for the bridge release of `deposit_token_v2` (#1466, bridge/docs/ocap-protocols.md §3).
|
|
6
6
|
*
|
|
7
7
|
* The structs mirror `@arcblock/bridge-types` (`OcapRelease`, `DepositClaim`; domain `ArcBridge` v1). The chain can
|
|
8
8
|
* not depend on that package (it is private and pulls in viem), so the encoding is re-implemented here and pinned to
|
package/esm/execute.mjs
CHANGED
|
@@ -14,6 +14,7 @@ import { isFromPublicKey, toAddress, toTypeInfo } from "@arcblock/did";
|
|
|
14
14
|
import { toDelegateAddress, toStakeAddress } from "@arcblock/did-util";
|
|
15
15
|
import * as JWT from "@arcblock/jwt";
|
|
16
16
|
import { account, evidence, parseNonceBn } from "@ocap/state";
|
|
17
|
+
import { isBridgeRelease } from "@ocap/tx-pipeline/lib/bridge-reserves";
|
|
17
18
|
import { BN, fromTokenToUnit, isSameDid, toBase58, toBase64, toBuffer } from "@ocap/util";
|
|
18
19
|
import { getRelatedAddresses } from "@ocap/util/lib/get-related-addr";
|
|
19
20
|
import camelCase from "lodash/camelCase.js";
|
|
@@ -106,6 +107,12 @@ const NON_EXISTENT_SENDER_CAPABLE_TX_TYPES = new Set([
|
|
|
106
107
|
"deposit_token_v2",
|
|
107
108
|
"transfer_v3"
|
|
108
109
|
]);
|
|
110
|
+
/**
|
|
111
|
+
* #1692 (bridge/docs/deposit-withdraw-v2-unification.md §2.7 item 2): a `deposit_token_v2` with a bridge kind (1/2/3) is a
|
|
112
|
+
* bridge release, whose sender must exist and pay gas; only the v1 deposit (kind 0) keeps
|
|
113
|
+
* the non-existent sender capability. The kind is in the itx, so this needs no state.
|
|
114
|
+
*/
|
|
115
|
+
const isNonExistentSenderCapable = (shortTxType, itx) => NON_EXISTENT_SENDER_CAPABLE_TX_TYPES.has(shortTxType) && !isBridgeRelease(shortTxType, itx);
|
|
109
116
|
const shouldPersistTx = (err, context) => {
|
|
110
117
|
if (!err) return true;
|
|
111
118
|
if (!get(err, "props.persist")) return false;
|
|
@@ -261,6 +268,11 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
261
268
|
return result;
|
|
262
269
|
}
|
|
263
270
|
case "deposit_token_v2": {
|
|
271
|
+
if (isBridgeRelease(shortTxType, itx)) return {
|
|
272
|
+
create: 2,
|
|
273
|
+
update: 3,
|
|
274
|
+
isGasSelfStakeTx: false
|
|
275
|
+
};
|
|
264
276
|
const result = {
|
|
265
277
|
create: 2,
|
|
266
278
|
update: 1,
|
|
@@ -367,7 +379,7 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
367
379
|
const txType = context.txType;
|
|
368
380
|
const shortTxType = normalizeShortTxType(txType);
|
|
369
381
|
const assertProtocolAdmissibleWithoutSenderState = async () => {
|
|
370
|
-
if (!isExistingAssetSender && !
|
|
382
|
+
if (!isExistingAssetSender && !isNonExistentSenderCapable(shortTxType, context.itx)) throw new CustomError("INVALID_SENDER_STATE", `Invalid state extracted for ACCOUNT: ${from}`, { persist: false });
|
|
371
383
|
if (shortTxType === "transfer_v3" || shortTxType === "stake" || shortTxType === "burn_token" || shortTxType === "mint_token" || shortTxType === "acquire_asset_v3") {
|
|
372
384
|
const inputs = getListField(context.itx, "inputs") || [];
|
|
373
385
|
if ((shortTxType === "transfer_v3" || shortTxType === "stake" || shortTxType === "burn_token") && inputs.length === 0) throw new CustomError("INVALID_TX", "Invalid itx: inputs must not be empty", { persist: false });
|
|
@@ -375,7 +387,7 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
375
387
|
if (!inp?.owner) throw new CustomError("INVALID_TX", "Invalid itx: input owner is required", { persist: false });
|
|
376
388
|
if (!(Boolean(await accountStore.get(inp.owner, context)) || toTypeInfo(inp.owner).role === types.RoleType.ROLE_ASSET && typeof statedb?.asset?.get === "function" && Boolean(await statedb.asset.get(inp.owner, context)))) throw new CustomError("INVALID_SIGNER_STATE", `Invalid state extracted for ACCOUNT: ${inp.owner}`, { persist: false });
|
|
377
389
|
}
|
|
378
|
-
} else if (shortTxType === "deposit_token_v2") {
|
|
390
|
+
} else if (shortTxType === "deposit_token_v2" && !isBridgeRelease(shortTxType, context.itx)) {
|
|
379
391
|
const signatures = getListField(context.tx, "signatures") || [];
|
|
380
392
|
if (signatures.length === 0) throw new CustomError("INVALID_TX", "itx.proposer must exist in signatures", { persist: false });
|
|
381
393
|
for (const sig of signatures) if (!sig?.signer || !await accountStore.get(sig.signer, context)) throw new CustomError("INVALID_SIGNER_STATE", `Invalid state extracted for ACCOUNT: ${sig?.signer || ""}`, { persist: false });
|
|
@@ -458,6 +470,7 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
458
470
|
const selfStakeInfo = isThirdPartyGasPass ? await resolveSelfGasStake() : null;
|
|
459
471
|
const selfStakeEligible = Boolean(selfStakeInfo?.valid) && evaluateStakeForGasEligibility({
|
|
460
472
|
txType,
|
|
473
|
+
itx: context.itx,
|
|
461
474
|
txSize,
|
|
462
475
|
gasEstimate,
|
|
463
476
|
isFailedTxGasCharge: false,
|
|
@@ -466,12 +479,14 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
466
479
|
config
|
|
467
480
|
}).eligible;
|
|
468
481
|
const effectiveStakeState = selfStakeInfo?.valid && selfStakeEligible ? selfStakeInfo.state : passStakeState;
|
|
482
|
+
const effectiveThirdParty = selfStakeInfo?.valid && selfStakeEligible ? false : isThirdPartyGasPass;
|
|
469
483
|
const eligibility = evaluateStakeForGasEligibility({
|
|
470
484
|
txType,
|
|
485
|
+
itx: context.itx,
|
|
471
486
|
txSize,
|
|
472
487
|
gasEstimate,
|
|
473
488
|
isFailedTxGasCharge: false,
|
|
474
|
-
isThirdPartySponsor:
|
|
489
|
+
isThirdPartySponsor: effectiveThirdParty,
|
|
475
490
|
enforceSponsor3DEligibility: false,
|
|
476
491
|
config
|
|
477
492
|
});
|
|
@@ -578,6 +593,7 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
578
593
|
const selfStakeInfo = await resolveSelfGasStake();
|
|
579
594
|
const selfStakeEligible = Boolean(selfStakeInfo.valid) && evaluateStakeForGasEligibility({
|
|
580
595
|
txType,
|
|
596
|
+
itx: context.itx,
|
|
581
597
|
txSize,
|
|
582
598
|
gasEstimate,
|
|
583
599
|
isFailedTxGasCharge: false,
|
|
@@ -595,13 +611,15 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
595
611
|
return;
|
|
596
612
|
}
|
|
597
613
|
} else {
|
|
614
|
+
const enforceSponsor3DEligibility = decoded.enforce3DEligibility === true || (config?.transaction?.txGas)?.enforceSponsor3DEligibility === true;
|
|
598
615
|
const eligibility = evaluateStakeForGasEligibility({
|
|
599
616
|
txType,
|
|
617
|
+
itx: context.itx,
|
|
600
618
|
txSize,
|
|
601
619
|
gasEstimate,
|
|
602
620
|
isFailedTxGasCharge: false,
|
|
603
621
|
isThirdPartySponsor: true,
|
|
604
|
-
enforceSponsor3DEligibility
|
|
622
|
+
enforceSponsor3DEligibility,
|
|
605
623
|
config
|
|
606
624
|
});
|
|
607
625
|
if (isGasStakeValid(sponsorStakeState, config) && eligibility.eligible) {
|
|
@@ -618,6 +636,7 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
618
636
|
if (isGasStakeValid(await statedb.stake.get(directStakeId, context), config)) {
|
|
619
637
|
if (evaluateStakeForGasEligibility({
|
|
620
638
|
txType,
|
|
639
|
+
itx: context.itx,
|
|
621
640
|
txSize,
|
|
622
641
|
gasEstimate,
|
|
623
642
|
isFailedTxGasCharge: false,
|
|
@@ -633,7 +652,7 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
633
652
|
}
|
|
634
653
|
if (isExistingAssetSender) throw new CustomError("INSUFFICIENT_FUND", `Insufficient fund to pay for tx cost from ${from}`, { persist: false });
|
|
635
654
|
if (txType === "fg:t:account_migrate" || Boolean(token$1 || pk) || Boolean(rawGasPass)) throw new CustomError("INVALID_GAS_PAYER", `Gas payer ${from} does not exist on chain`, { persist: false });
|
|
636
|
-
if (!
|
|
655
|
+
if (!isNonExistentSenderCapable(shortTxType, context.itx)) throw new CustomError("INVALID_SENDER_STATE", `Invalid state extracted for ACCOUNT: ${from}`, { persist: false });
|
|
637
656
|
throw new CustomError("INVALID_SENDER_STATE", `Invalid state extracted for ACCOUNT: ${from}`, { persist: false });
|
|
638
657
|
};
|
|
639
658
|
const assertSenderNonceFresh = async (context) => {
|
|
@@ -161,6 +161,8 @@ interface IStakeForGasEligibilityResult {
|
|
|
161
161
|
*/
|
|
162
162
|
declare function evaluateStakeForGasEligibility(params: {
|
|
163
163
|
txType?: string;
|
|
164
|
+
/** the decoded itx: a `deposit_token_v2` with a bridge kind is a bridge release (#1692), never gas-free */
|
|
165
|
+
itx?: unknown;
|
|
164
166
|
txSize?: number;
|
|
165
167
|
gasEstimate?: {
|
|
166
168
|
create?: number;
|
|
@@ -177,14 +179,6 @@ declare function evaluateStakeForGasEligibility(params: {
|
|
|
177
179
|
* Paymaster `allowedTargets` scoping.
|
|
178
180
|
*/
|
|
179
181
|
declare function extractTransactionTargets(tx: Record<string, unknown> | undefined, decodedItx?: Record<string, unknown> | undefined, txType?: string): string[];
|
|
180
|
-
/**
|
|
181
|
-
* Verifies Merchant / DApp Paymaster (`extra.gasStakeHeaders` JWT) scope constraints:
|
|
182
|
-
* - `allowedTxTypes`: if present, transaction type must be in `allowedTxTypes`.
|
|
183
|
-
* - `allowedTargets`: if present, transaction must touch at least one target and EVERY target
|
|
184
|
-
* touched by the transaction (excluding the sender `tx.from` itself in multi-input change)
|
|
185
|
-
* must be in `allowedTargets`.
|
|
186
|
-
* - `maxGasPerTx`: if present, `totalGas` must not exceed `maxGasPerTx`.
|
|
187
|
-
*/
|
|
188
182
|
declare function verifyPaymasterConstraints(params: {
|
|
189
183
|
decoded: IPaymasterDecodedClaims;
|
|
190
184
|
tx?: Record<string, unknown>;
|
|
@@ -5,6 +5,7 @@ import { getListField } from "@ocap/util/lib/get-list-field";
|
|
|
5
5
|
import { isFromPublicKey, toTypeInfo } from "@arcblock/did";
|
|
6
6
|
import { toStakeAddress } from "@arcblock/did-util";
|
|
7
7
|
import { account, evidence, parseNonceBn, stake } from "@ocap/state";
|
|
8
|
+
import { isBridgeRelease } from "@ocap/tx-pipeline/lib/bridge-reserves";
|
|
8
9
|
import { BN, fromTokenToUnit, isSameDid, toAddress as toAddress$1 } from "@ocap/util";
|
|
9
10
|
import cloneDeep from "lodash/cloneDeep.js";
|
|
10
11
|
import { createHash } from "node:crypto";
|
|
@@ -206,8 +207,15 @@ function evaluateStakeForGasEligibility(params) {
|
|
|
206
207
|
};
|
|
207
208
|
const shortType = normalizeShortTxType(params.txType);
|
|
208
209
|
const customAllowlist = (params.config?.transaction?.txGas)?.freeGasAllowedTxTypes;
|
|
210
|
+
const isBridgeReleaseTx = isBridgeRelease(params.txType, params.itx);
|
|
211
|
+
if (isBridgeReleaseTx) {
|
|
212
|
+
if (!(Array.isArray(customAllowlist) && customAllowlist.some((t) => normalizeShortTxType(t) === BRIDGE_RELEASE_GAS_TYPE))) return {
|
|
213
|
+
eligible: false,
|
|
214
|
+
reason: "TX_TYPE_REQUIRES_DIRECT_GAS"
|
|
215
|
+
};
|
|
216
|
+
}
|
|
209
217
|
const enforceAllowlist = !params.isThirdPartySponsor || params.enforceSponsor3DEligibility === true;
|
|
210
|
-
if (shortType) {
|
|
218
|
+
if (shortType && !isBridgeReleaseTx) {
|
|
211
219
|
const requiresDirectGas = DIRECT_GAS_REQUIRED_TX_TYPES.has(shortType);
|
|
212
220
|
if (Array.isArray(customAllowlist) && customAllowlist.length > 0) {
|
|
213
221
|
if (!customAllowlist.some((t) => normalizeShortTxType(t) === shortType || t === params.txType) && (enforceAllowlist || requiresDirectGas)) return {
|
|
@@ -303,9 +311,16 @@ function extractTransactionTargets(tx$1, decodedItx, txType) {
|
|
|
303
311
|
* must be in `allowedTargets`.
|
|
304
312
|
* - `maxGasPerTx`: if present, `totalGas` must not exceed `maxGasPerTx`.
|
|
305
313
|
*/
|
|
314
|
+
/** Gas / resource name of a bridge release (`fg:t:deposit_token_v2_bridge` without the prefix). */
|
|
315
|
+
const BRIDGE_RELEASE_GAS_TYPE = "deposit_token_v2_bridge";
|
|
306
316
|
function verifyPaymasterConstraints(params) {
|
|
307
317
|
const { decoded, tx: tx$1, itx, txType, totalGas } = params;
|
|
308
318
|
const isPaymasterDirectCharge = decoded.mode === "paymaster" || decoded.chargeSponsorBalance === true;
|
|
319
|
+
if (isBridgeRelease(txType, itx)) return {
|
|
320
|
+
valid: false,
|
|
321
|
+
reason: "PAYMASTER_TX_TYPE_FORBIDDEN",
|
|
322
|
+
isPaymasterDirectCharge
|
|
323
|
+
};
|
|
309
324
|
if (Array.isArray(decoded.allowedTxTypes)) {
|
|
310
325
|
if (decoded.allowedTxTypes.length === 0) return {
|
|
311
326
|
valid: false,
|
package/esm/index.d.mts
CHANGED
|
@@ -12,7 +12,6 @@ import { TokenInput as TokenInput$4 } from "./protocols/token/withdraw-v2.mjs";
|
|
|
12
12
|
import { TokenInfoForVerification } from "./protocols/token-factory/update.mjs";
|
|
13
13
|
import { MultiInput as MultiInput$2 } from "./protocols/token-factory/mint.mjs";
|
|
14
14
|
import { MultiInput as MultiInput$3 } from "./protocols/token-factory/burn.mjs";
|
|
15
|
-
import { Context } from "./protocols/bridge/release.mjs";
|
|
16
15
|
import { MultiInput as MultiInput$4 } from "./protocols/governance/stake.mjs";
|
|
17
16
|
import { MultiOutput, TokenCondition } from "./protocols/governance/revoke-stake.mjs";
|
|
18
17
|
import { MultiOutput as MultiOutput$1, TokenCondition as TokenCondition$1, TokenInput as TokenInput$5 } from "./protocols/governance/claim-stake.mjs";
|
|
@@ -269,6 +268,14 @@ declare const createExecutor: ({
|
|
|
269
268
|
delta: string;
|
|
270
269
|
action: string;
|
|
271
270
|
}>;
|
|
271
|
+
isBridgeV2?: boolean;
|
|
272
|
+
bridge?: _ocap_tx_pipeline0.ResolvedBridge;
|
|
273
|
+
bridgeWithdraw?: {
|
|
274
|
+
amount: string;
|
|
275
|
+
ethRecipient: string;
|
|
276
|
+
};
|
|
277
|
+
reserveAddress?: string;
|
|
278
|
+
reserveState?: any;
|
|
272
279
|
}>;
|
|
273
280
|
createTokenFactory: _ocap_tx_pipeline0.Runner<_ocap_types0.IReadyContext<_ocap_types0.TCreateTokenFactoryTx> & Partial<_ocap_types0.IWithSender> & Partial<_ocap_types0.IWithDelegator> & Partial<_ocap_types0.IWithDelegation> & Partial<_ocap_types0.IWithStake> & Partial<_ocap_types0.IWithToken> & Partial<_ocap_types0.IWithTokenFactory> & {
|
|
274
281
|
stakeAddress?: string;
|
|
@@ -303,7 +310,6 @@ declare const createExecutor: ({
|
|
|
303
310
|
delta: string;
|
|
304
311
|
}[];
|
|
305
312
|
}>;
|
|
306
|
-
releaseBridgeToken: _ocap_tx_pipeline0.Runner<Context>;
|
|
307
313
|
stake: _ocap_tx_pipeline0.Runner<_ocap_types0.IReadyContext<_ocap_types0.TStakeTx> & Partial<_ocap_types0.IWithSender> & Partial<_ocap_types0.IWithSigners> & Partial<_ocap_types0.IWithReceiver> & Partial<_ocap_types0.IWithStake> & Partial<_ocap_types0.IWithTokens> & Partial<_ocap_types0.IWithAssets> & {
|
|
308
314
|
inputs?: MultiInput$4[];
|
|
309
315
|
senders?: string[];
|
|
@@ -661,6 +667,14 @@ declare const defaultExecutor: {
|
|
|
661
667
|
delta: string;
|
|
662
668
|
action: string;
|
|
663
669
|
}>;
|
|
670
|
+
isBridgeV2?: boolean;
|
|
671
|
+
bridge?: _ocap_tx_pipeline0.ResolvedBridge;
|
|
672
|
+
bridgeWithdraw?: {
|
|
673
|
+
amount: string;
|
|
674
|
+
ethRecipient: string;
|
|
675
|
+
};
|
|
676
|
+
reserveAddress?: string;
|
|
677
|
+
reserveState?: any;
|
|
664
678
|
}>;
|
|
665
679
|
createTokenFactory: _ocap_tx_pipeline0.Runner<_ocap_types0.IReadyContext<_ocap_types0.TCreateTokenFactoryTx> & Partial<_ocap_types0.IWithSender> & Partial<_ocap_types0.IWithDelegator> & Partial<_ocap_types0.IWithDelegation> & Partial<_ocap_types0.IWithStake> & Partial<_ocap_types0.IWithToken> & Partial<_ocap_types0.IWithTokenFactory> & {
|
|
666
680
|
stakeAddress?: string;
|
|
@@ -695,7 +709,6 @@ declare const defaultExecutor: {
|
|
|
695
709
|
delta: string;
|
|
696
710
|
}[];
|
|
697
711
|
}>;
|
|
698
|
-
releaseBridgeToken: _ocap_tx_pipeline0.Runner<Context>;
|
|
699
712
|
stake: _ocap_tx_pipeline0.Runner<_ocap_types0.IReadyContext<_ocap_types0.TStakeTx> & Partial<_ocap_types0.IWithSender> & Partial<_ocap_types0.IWithSigners> & Partial<_ocap_types0.IWithReceiver> & Partial<_ocap_types0.IWithStake> & Partial<_ocap_types0.IWithTokens> & Partial<_ocap_types0.IWithAssets> & {
|
|
700
713
|
inputs?: MultiInput$4[];
|
|
701
714
|
senders?: string[];
|
package/esm/index.mjs
CHANGED
|
@@ -12,7 +12,6 @@ import consume_default from "./protocols/asset/consume.mjs";
|
|
|
12
12
|
import create_default from "./protocols/asset/create.mjs";
|
|
13
13
|
import mint_default from "./protocols/asset/mint.mjs";
|
|
14
14
|
import update_default from "./protocols/asset/update.mjs";
|
|
15
|
-
import release_default from "./protocols/bridge/release.mjs";
|
|
16
15
|
import create_default$1 from "./protocols/factory/create.mjs";
|
|
17
16
|
import claim_stake_default from "./protocols/governance/claim-stake.mjs";
|
|
18
17
|
import return_stake_default from "./protocols/governance/return-stake.mjs";
|
|
@@ -66,7 +65,6 @@ const createExecutor = ({ filter, runAsLambda }) => {
|
|
|
66
65
|
updateTokenFactory: update_default$2,
|
|
67
66
|
mintToken: mint_default$1,
|
|
68
67
|
burnToken: burn_default,
|
|
69
|
-
releaseBridgeToken: release_default,
|
|
70
68
|
stake: stake_default,
|
|
71
69
|
revokeStake: revoke_stake_default,
|
|
72
70
|
claimStake: claim_stake_default,
|
|
@@ -88,6 +88,7 @@ function isMatchingAccountPublicKey(onChainPk, headerPk) {
|
|
|
88
88
|
const selfStakeInfo = isThirdPartyGasPass ? await resolveSignerSelfGasStake() : null;
|
|
89
89
|
const selfStakeEligible = Boolean(selfStakeInfo?.valid) && evaluateStakeForGasEligibility({
|
|
90
90
|
txType,
|
|
91
|
+
itx: context.itx,
|
|
91
92
|
txSize,
|
|
92
93
|
gasEstimate,
|
|
93
94
|
isFailedTxGasCharge: isFailedTxGasCharge && canChargeSenderDirectly,
|
|
@@ -192,6 +193,7 @@ function isMatchingAccountPublicKey(onChainPk, headerPk) {
|
|
|
192
193
|
const selfStakeInfo = await resolveSignerSelfGasStake();
|
|
193
194
|
const selfStakeEligible = Boolean(selfStakeInfo.valid) && evaluateStakeForGasEligibility({
|
|
194
195
|
txType,
|
|
196
|
+
itx: context.itx,
|
|
195
197
|
txSize,
|
|
196
198
|
gasEstimate,
|
|
197
199
|
isFailedTxGasCharge: isFailedTxGasCharge && canChargeSenderDirectly,
|
|
@@ -225,6 +227,7 @@ function isMatchingAccountPublicKey(onChainPk, headerPk) {
|
|
|
225
227
|
if (!gasStake.state && gasStake.stakeId) gasStake.state = await statedb.stake.get(gasStake.stakeId, context);
|
|
226
228
|
const eligibility = evaluateStakeForGasEligibility({
|
|
227
229
|
txType,
|
|
230
|
+
itx: context.itx,
|
|
228
231
|
txSize,
|
|
229
232
|
gasEstimate,
|
|
230
233
|
isFailedTxGasCharge: isFailedTxGasCharge && canChargeSenderDirectly,
|
|
@@ -5,7 +5,8 @@ import { PipeFunction } from "@ocap/tx-pipeline";
|
|
|
5
5
|
interface IGasEstimate {
|
|
6
6
|
create: number;
|
|
7
7
|
update: number;
|
|
8
|
-
payment
|
|
8
|
+
/** sender payment in the gas token on top of the tx cost (a decimal string for base-unit amounts) */
|
|
9
|
+
payment?: number | string;
|
|
9
10
|
}
|
|
10
11
|
/** Gas estimator function type - uses any for flexible context access */
|
|
11
12
|
type GasEstimatorFn = (context: any) => IGasEstimate;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Debug from "debug";
|
|
2
2
|
import { formatMessage } from "@ocap/message";
|
|
3
|
+
import { stripDefaultDepositV2BridgeFieldsInTx } from "@ocap/util/lib/deposit-v2-bridge-fields";
|
|
3
4
|
|
|
4
5
|
//#region src/pipes/write-ledger.ts
|
|
5
6
|
/**
|
|
@@ -66,7 +67,7 @@ const WriteLedger = async (context, next) => {
|
|
|
66
67
|
if (extra.txExtra) txExtra.txExtra = extra.txExtra;
|
|
67
68
|
if (extra.gasStakeHeaders) txExtra.gasStakeHeaders = extra.gasStakeHeaders;
|
|
68
69
|
}
|
|
69
|
-
const formattedTx = formatMessage("Transaction", tx);
|
|
70
|
+
const formattedTx = stripDefaultDepositV2BridgeFieldsInTx(formatMessage("Transaction", tx));
|
|
70
71
|
const txInput = {
|
|
71
72
|
txRaw: txBase64,
|
|
72
73
|
tx: formattedTx,
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { PipeFunction, ReleaseResolution } from "@ocap/tx-pipeline";
|
|
2
|
+
|
|
3
|
+
//#region src/protocols/bridge/release-checks.d.ts
|
|
4
|
+
declare const RELEASE_KIND: {
|
|
5
|
+
readonly DEPOSIT: 1;
|
|
6
|
+
readonly REFUND: 2;
|
|
7
|
+
readonly DEPOSIT_B: 3;
|
|
8
|
+
};
|
|
9
|
+
/** `resolveMigrated` follows at most this many `migratedTo` links of an ACCOUNT (check 6) */
|
|
10
|
+
declare const MAX_MIGRATION_HOPS = 8;
|
|
11
|
+
/** What a release says. */
|
|
12
|
+
interface ReleaseView {
|
|
13
|
+
kind: number;
|
|
14
|
+
/** the canonical bridge address: `itx.rollup` */
|
|
15
|
+
bridge: string;
|
|
16
|
+
/** lowercase `0x` bytes32: `itx.evidence.hash` */
|
|
17
|
+
evidence: string;
|
|
18
|
+
ordinal: number;
|
|
19
|
+
to: string;
|
|
20
|
+
/** base units, canonical decimal: `itx.token.value` */
|
|
21
|
+
amount: string;
|
|
22
|
+
epoch: number;
|
|
23
|
+
ethSender: string;
|
|
24
|
+
claimSignature: string;
|
|
25
|
+
/** `itx.validatorSignaturesList` */
|
|
26
|
+
signaturesList: string[];
|
|
27
|
+
}
|
|
28
|
+
type ReleaseContext = Record<string, any> & {
|
|
29
|
+
releaseItx: ReleaseView;
|
|
30
|
+
/** what `resolveBridgeForRelease` found: the bridge, its reserve and the reserves a refund may draw on */
|
|
31
|
+
release?: ReleaseResolution;
|
|
32
|
+
releaseAmount?: bigint;
|
|
33
|
+
releaseTimeMs?: number;
|
|
34
|
+
};
|
|
35
|
+
type Pipe = PipeFunction<any>;
|
|
36
|
+
declare const checkReleaseFields: Pipe;
|
|
37
|
+
declare const rejectReleaseDelegator: Pipe;
|
|
38
|
+
declare const resolveReleaseTime: Pipe;
|
|
39
|
+
/**
|
|
40
|
+
* 1. master switch, the bridge the release names, its lifecycle for this kind.
|
|
41
|
+
* `opts.token`: the release names the token (`itx.token.address`), which must be the bridge token (fail closed).
|
|
42
|
+
*/
|
|
43
|
+
declare const resolveReleaseBridge: (opts: {
|
|
44
|
+
token?: (context: ReleaseContext) => unknown;
|
|
45
|
+
}) => Pipe;
|
|
46
|
+
declare const checkReleaseMinimum: Pipe;
|
|
47
|
+
declare const checkReleaseRecipient: Pipe;
|
|
48
|
+
declare const checkReleaseTombstone: Pipe;
|
|
49
|
+
declare const verifyReleaseSignatures: Pipe;
|
|
50
|
+
declare const verifyReleaseClaim: Pipe;
|
|
51
|
+
declare function resolveMigrated(context: ReleaseContext, address: string): Promise<string | null>;
|
|
52
|
+
declare const checkReleaseRefund: Pipe;
|
|
53
|
+
declare const checkReleaseRecipientState: Pipe;
|
|
54
|
+
declare const checkReleaseCap: Pipe;
|
|
55
|
+
declare const checkReleaseReserve: Pipe;
|
|
56
|
+
/** Gas operations of a release (for `EnsureTxGas`). */
|
|
57
|
+
declare const releaseGasEstimate: (context: ReleaseContext) => {
|
|
58
|
+
create: number;
|
|
59
|
+
update: any;
|
|
60
|
+
payment: number;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* The state writes of a release: the tombstone (create only: a second release of the same evidence was refused above,
|
|
64
|
+
* and `create` fails on an existing key), the one bucket it uses, the refund ledger of the migrated bridges a REFUND
|
|
65
|
+
* draws through, the reserve debit, the recipient credit and the sender (nonce, gas).
|
|
66
|
+
*/
|
|
67
|
+
declare const writeRelease: Pipe;
|
|
68
|
+
//#endregion
|
|
69
|
+
export { MAX_MIGRATION_HOPS, RELEASE_KIND, ReleaseContext, ReleaseView, checkReleaseCap, checkReleaseFields, checkReleaseMinimum, checkReleaseRecipient, checkReleaseRecipientState, checkReleaseRefund, checkReleaseReserve, checkReleaseTombstone, rejectReleaseDelegator, releaseGasEstimate, resolveMigrated, resolveReleaseBridge, resolveReleaseTime, verifyReleaseClaim, verifyReleaseSignatures, writeRelease };
|