@ocap/state 1.31.0 → 1.31.2

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.
@@ -0,0 +1,188 @@
1
+ //#region src/states/rollup-v2.d.ts
2
+ declare const BRIDGE_MIN_EPOCH_LEAD = 3600;
3
+ declare const BRIDGE_MAX_EPOCH_LEAD: number;
4
+ declare const BRIDGE_OWNER_TIMELOCK: number;
5
+ declare const BRIDGE_LONE_PAUSE_TTL: number;
6
+ declare const BRIDGE_LONE_PAUSE_COOLDOWN: number;
7
+ declare const BRIDGE_RESERVE_MIGRATION_WINDOW: number;
8
+ declare const BRIDGE_MAX_PAUSERS = 3;
9
+ declare const BRIDGE_MIN_VALIDATORS = 3;
10
+ declare const BRIDGE_MAX_VALIDATORS = 16;
11
+ declare const BRIDGE_MAX_DELAY: number;
12
+ declare const BRIDGE_VERSION = 2;
13
+ /** Keys a creator may put in `itx.data.value` of a v2 `create_rollup`. Everything else is derived by the chain. */
14
+ declare const BRIDGE_CREATE_KEYS: readonly ["version", "ethChainId", "gateway", "minDeposit", "minWithdraw", "maxWithdraw", "withdrawFee", "releaseDailyCap", "refundDailyCap", "releaseGrace", "refundDelay", "transitionPeriod", "epochs", "salt", "pausers", "ethOwnerAttestation", "consents", "initialReserve"];
15
+ /** Keys `update_rollup` may patch. `proposeOwner` / `cancelOwnerProposal` / `cancelPendingEpoch` are actions. */
16
+ declare const BRIDGE_PATCH_VALUE_KEYS: readonly ["minDeposit", "minWithdraw", "maxWithdraw", "releaseDailyCap", "refundDailyCap", "releaseGrace", "refundDelay", "pausers"];
17
+ declare const BRIDGE_PATCH_ACTION_KEYS: readonly ["cancelPendingEpoch", "proposeOwner", "cancelOwnerProposal"];
18
+ interface BridgeEpoch {
19
+ epoch: number;
20
+ activeFrom: number;
21
+ threshold: number;
22
+ /** lowercase Ethereum addresses, strictly ascending */
23
+ validators: string[];
24
+ voucherValidity: number;
25
+ }
26
+ interface BridgeMember {
27
+ address: string;
28
+ pk: string;
29
+ endpoint: string;
30
+ }
31
+ interface BridgeBodyV2 {
32
+ version: 2;
33
+ owner: string;
34
+ ethChainId: string;
35
+ gateway: string;
36
+ /** informational: loaders recompute `toBridgeReserveAddress(bridge)` */
37
+ reserve: string;
38
+ minDeposit: string;
39
+ minWithdraw: string;
40
+ maxWithdraw: string;
41
+ withdrawFee: string;
42
+ releaseDailyCap: string;
43
+ refundDailyCap: string;
44
+ releaseGrace: number;
45
+ refundDelay: number;
46
+ transitionPeriod: number;
47
+ epochs: BridgeEpoch[];
48
+ members: Record<string, BridgeMember>;
49
+ salt: string;
50
+ pausers: string[];
51
+ lonePause: {
52
+ by: string;
53
+ until: number;
54
+ } | null;
55
+ /** txTime (s) of the last lone pause by the owner / by any other pauser: two independent cooldown tracks */
56
+ lastLonePause: {
57
+ owner?: number;
58
+ others?: number;
59
+ };
60
+ pendingOwner: {
61
+ address: string;
62
+ pk: string;
63
+ endpoint: string;
64
+ proposedAt: number;
65
+ effectiveAt: number;
66
+ } | null;
67
+ pendingMigration: {
68
+ to: string;
69
+ announcedAt: number;
70
+ effectiveAt: number;
71
+ } | null;
72
+ closingAt: number | null;
73
+ depositCutoffEthBlock: string | null;
74
+ /** closingAt + maxVoucherValidity + refundDelay, fixed at close */
75
+ finalAt: number | null;
76
+ migratedTo: string | null;
77
+ /**
78
+ * Refund ledger (#1505, for #1466): the amount of the bridge token that `migrate_rollup { reserve }` moved to the
79
+ * successor's reserve, written together with `migratedTo`. A REFUND of the migrated source debits the successor's reserve
80
+ * and MUST be capped by this ledger and decrement it, or the source's validators could drain the successor's own funds.
81
+ * Absent on bodies written before #1505 (read as null).
82
+ */
83
+ migratedAmount?: string | null;
84
+ ethOwnerAttestation: {
85
+ address: string;
86
+ signature: string;
87
+ };
88
+ }
89
+ type AnyState = Record<string, any>;
90
+ /** Whether a rollup `data` field (`{ type, value }`) is a v2 body. */
91
+ declare function isBridgeV2Data(data: unknown): boolean;
92
+ /** Whether the rollup row is a v2 bridge. Rows without `data.value.version == 2` are v1 and keep today's behaviour. */
93
+ declare function isBridgeV2(state: unknown): boolean;
94
+ declare function getBridgeBody(state: unknown): BridgeBodyV2 | null;
95
+ declare const toSeconds: (iso: string | number | Date | undefined | null) => number;
96
+ declare const lc: (address: string) => string;
97
+ /** Ethereum addresses compare case-insensitively; OCAP addresses may carry a DID prefix. */
98
+ declare const sameAddress: (a: unknown, b: unknown) => boolean;
99
+ /** `epochAt(t) = max{ e : activeFrom(e) <= t }`, undefined (null) before the first epoch. */
100
+ declare function activeEpochAt(body: BridgeBodyV2, t: number): BridgeEpoch | null;
101
+ /** The epoch whose `activeFrom` is still in the future at `t` (there is at most one). */
102
+ declare function pendingEpochAt(body: BridgeBodyV2, t: number): BridgeEpoch | null;
103
+ declare function maxVoucherValidity(body: BridgeBodyV2): number;
104
+ /**
105
+ * Effective pause at `t`. A lone pause expires 24h after it was issued, purely by time: the persisted `paused` flag
106
+ * stays true, so every reader MUST use this function instead of reading `paused`.
107
+ */
108
+ declare function isBridgePausedAt(state: AnyState, t: number): boolean;
109
+ /** Quorum pause = paused with no running (or expired) lone pause marker. */
110
+ declare function isQuorumPaused(state: AnyState): boolean;
111
+ /** Whether the bridge is final at `t` (closed and `closingAt + maxVoucherValidity + refundDelay` has passed). */
112
+ declare function isBridgeFinalAt(body: BridgeBodyV2, t: number): boolean;
113
+ /** The owner at `t`: a pending replacement takes effect `effectiveAt` after it was proposed. */
114
+ declare function effectiveOwnerAt(body: BridgeBodyV2, t: number): string;
115
+ /**
116
+ * Whether a proposed owner can be written into `owner` / `seed_validators`: a bare (no DID prefix), checksummed,
117
+ * non-zero Ethereum address, the public key of that address, and an http(s) endpoint.
118
+ */
119
+ declare function isValidOwnerCandidate(p: AnyState | null | undefined): boolean;
120
+ /**
121
+ * Re-derive the informational mirrors (`validators`, `min/maxSignerCount`) from the active epoch. Called on every v2
122
+ * state write, so they are exact as of the last governance tx. Authority checks never read them; they read `epochs`.
123
+ */
124
+ declare function syncBridgeView(state: AnyState, txSec: number): AnyState;
125
+ /**
126
+ * Apply every time-driven transition that is due at `txSec` to the state: a pending owner replacement whose timelock
127
+ * has run out rewrites BOTH `owner` and `seedValidators`. Returns the (possibly new) state; never mutates its input.
128
+ */
129
+ declare function materializeBridgeAt(state: AnyState, txSec: number): AnyState;
130
+ /** Full structural validation of a stored v2 body. */
131
+ declare function validateBridgeBody(body: BridgeBodyV2): BridgeBodyV2;
132
+ /** Whether a v1 numeric field is "zero or empty" (the v2 requirement for unused v1 fields). */
133
+ declare function isZeroish(v: unknown): boolean;
134
+ /** v1 fields a v2 bridge must leave at zero / empty (stake, block size / interval, fees, block height / hash, waits). */
135
+ declare const BRIDGE_V1_ZERO_FIELDS: readonly string[];
136
+ declare function assertV1FieldsUnused(attrs: AnyState, errorCode: 'INVALID_ROLLUP_PROPS' | 'INVALID_ROLLUP_UPDATE'): void;
137
+ /**
138
+ * Structural rules for any transition of a v2 row, enforced by the state layer on every `update`:
139
+ * `version`, `gateway`, `ethChainId`, `reserve`, `salt`, `withdrawFee`, `transitionPeriod`, `ethOwnerAttestation`,
140
+ * `issuer` and the token fields are immutable; epochs are append-only (one new epoch, or the last pending one removed);
141
+ * `members` only grows; the owner changes only through a due `pendingOwner`; `migratedTo` is written once.
142
+ */
143
+ declare function assertBridgeTransition(prev: AnyState, next: AnyState, txSec: number | null): void;
144
+ interface BridgeConsent {
145
+ address: string;
146
+ endpoint: string;
147
+ signature: string;
148
+ }
149
+ interface BridgeCreateInput {
150
+ body: Omit<BridgeBodyV2, 'owner' | 'reserve' | 'members' | 'lonePause' | 'lastLonePause' | 'pendingOwner' | 'pendingMigration' | 'closingAt' | 'depositCutoffEthBlock' | 'finalAt' | 'migratedTo' | 'migratedAmount'>;
151
+ consents: BridgeConsent[];
152
+ initialReserve: string;
153
+ }
154
+ /** Parse and validate `itx.data.value` of a v2 `create_rollup` (pure shape checks; signatures are checked by the protocol). */
155
+ declare function parseBridgeCreateData(value: AnyState): BridgeCreateInput;
156
+ type BridgePatchKind = 'owner-quorum' | 'propose-owner' | 'cancel-owner-proposal';
157
+ interface BridgePatchPlan {
158
+ kind: BridgePatchKind;
159
+ /** the body after the patch */
160
+ body: BridgeBodyV2;
161
+ /** a pending epoch was removed */
162
+ cancelledEpoch: BridgeEpoch | null;
163
+ }
164
+ /**
165
+ * Validate an `update_rollup` patch (`itx.data.value`) against the allow-list and compute the resulting body.
166
+ * `proposeOwner` is its own transaction kind (2/3 quorum), `cancelOwnerProposal` needs the current owner alone, anything
167
+ * else needs owner + quorum. Frozen keys (version, epochs, reserve, gateway, ethChainId, token fields...) are rejected.
168
+ */
169
+ declare function planBridgePatch(body: BridgeBodyV2, patch: AnyState, txSec: number): BridgePatchPlan;
170
+ interface MembershipRequest {
171
+ action: 'join' | 'leave';
172
+ validator: string;
173
+ threshold: number;
174
+ activeFrom: number;
175
+ voucherValidity: number;
176
+ }
177
+ interface MembershipPlan {
178
+ epoch: BridgeEpoch;
179
+ /** the epoch whose quorum must sign: the active epoch at txTime */
180
+ signingEpoch: BridgeEpoch;
181
+ }
182
+ /** Epoch rules of §v2.2: `epoch = last + 1`, lead window, `2*threshold > n`, `n >= 3`, at most one pending epoch. */
183
+ declare function planMembership(body: BridgeBodyV2, req: MembershipRequest, txSec: number): MembershipPlan;
184
+ declare function lonePauseTrack(body: BridgeBodyV2, by: string): 'owner' | 'others';
185
+ /** Validate and apply a lone pause by `by` (a member of `pausers`) at `txSec`. */
186
+ declare function applyLonePause(body: BridgeBodyV2, by: string, txSec: number): BridgeBodyV2;
187
+ //#endregion
188
+ export { BRIDGE_CREATE_KEYS, BRIDGE_LONE_PAUSE_COOLDOWN, BRIDGE_LONE_PAUSE_TTL, BRIDGE_MAX_DELAY, BRIDGE_MAX_EPOCH_LEAD, BRIDGE_MAX_PAUSERS, BRIDGE_MAX_VALIDATORS, BRIDGE_MIN_EPOCH_LEAD, BRIDGE_MIN_VALIDATORS, BRIDGE_OWNER_TIMELOCK, BRIDGE_PATCH_ACTION_KEYS, BRIDGE_PATCH_VALUE_KEYS, BRIDGE_RESERVE_MIGRATION_WINDOW, BRIDGE_V1_ZERO_FIELDS, BRIDGE_VERSION, BridgeBodyV2, BridgeConsent, BridgeCreateInput, BridgeEpoch, BridgeMember, BridgePatchKind, BridgePatchPlan, MembershipPlan, MembershipRequest, activeEpochAt, applyLonePause, assertBridgeTransition, assertV1FieldsUnused, effectiveOwnerAt, getBridgeBody, isBridgeFinalAt, isBridgePausedAt, isBridgeV2, isBridgeV2Data, isQuorumPaused, isValidOwnerCandidate, isZeroish, lc, lonePauseTrack, materializeBridgeAt, maxVoucherValidity, parseBridgeCreateData, pendingEpochAt, planBridgePatch, planMembership, sameAddress, syncBridgeView, toSeconds, validateBridgeBody };
@@ -1,5 +1,7 @@
1
1
  const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
2
  const require_contexts_state = require('../contexts/state.cjs');
3
+ const require_states_rollup_v2 = require('./rollup-v2.cjs');
4
+ const require_states_rollup_bridge = require('./rollup-bridge.cjs');
3
5
  let _ocap_util = require("@ocap/util");
4
6
  let _ocap_util_lib_error = require("@ocap/util/lib/error");
5
7
  let lodash_pick = require("lodash/pick");
@@ -10,28 +12,72 @@ let _arcblock_validator = require("@arcblock/validator");
10
12
 
11
13
  //#region src/states/rollup.ts
12
14
  var rollup_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
15
+ BRIDGE_CREATE_KEYS: () => require_states_rollup_v2.BRIDGE_CREATE_KEYS,
16
+ BRIDGE_LONE_PAUSE_COOLDOWN: () => require_states_rollup_v2.BRIDGE_LONE_PAUSE_COOLDOWN,
17
+ BRIDGE_LONE_PAUSE_TTL: () => require_states_rollup_v2.BRIDGE_LONE_PAUSE_TTL,
18
+ BRIDGE_MAX_DELAY: () => require_states_rollup_v2.BRIDGE_MAX_DELAY,
19
+ BRIDGE_MAX_EPOCH_LEAD: () => require_states_rollup_v2.BRIDGE_MAX_EPOCH_LEAD,
20
+ BRIDGE_MAX_PAUSERS: () => require_states_rollup_v2.BRIDGE_MAX_PAUSERS,
21
+ BRIDGE_MAX_VALIDATORS: () => require_states_rollup_v2.BRIDGE_MAX_VALIDATORS,
22
+ BRIDGE_MIN_EPOCH_LEAD: () => require_states_rollup_v2.BRIDGE_MIN_EPOCH_LEAD,
23
+ BRIDGE_MIN_VALIDATORS: () => require_states_rollup_v2.BRIDGE_MIN_VALIDATORS,
24
+ BRIDGE_OWNER_TIMELOCK: () => require_states_rollup_v2.BRIDGE_OWNER_TIMELOCK,
25
+ BRIDGE_PATCH_ACTION_KEYS: () => require_states_rollup_v2.BRIDGE_PATCH_ACTION_KEYS,
26
+ BRIDGE_PATCH_VALUE_KEYS: () => require_states_rollup_v2.BRIDGE_PATCH_VALUE_KEYS,
27
+ BRIDGE_RESERVE_MIGRATION_WINDOW: () => require_states_rollup_v2.BRIDGE_RESERVE_MIGRATION_WINDOW,
28
+ BRIDGE_V1_ZERO_FIELDS: () => require_states_rollup_v2.BRIDGE_V1_ZERO_FIELDS,
29
+ BRIDGE_VERSION: () => require_states_rollup_v2.BRIDGE_VERSION,
13
30
  VALID_ROLLUP_TARGET_TYPES: () => VALID_ROLLUP_TARGET_TYPES,
31
+ activeEpochAt: () => require_states_rollup_v2.activeEpochAt,
32
+ applyLonePause: () => require_states_rollup_v2.applyLonePause,
33
+ assertBridgeTransition: () => require_states_rollup_v2.assertBridgeTransition,
34
+ assertV1FieldsUnused: () => require_states_rollup_v2.assertV1FieldsUnused,
35
+ bridgeSchema: () => require_states_rollup_bridge.bridgeSchema,
14
36
  close: () => close,
15
37
  create: () => create,
38
+ createBridge: () => require_states_rollup_bridge.createBridge,
39
+ effectiveOwnerAt: () => require_states_rollup_v2.effectiveOwnerAt,
40
+ getBridgeBody: () => require_states_rollup_v2.getBridgeBody,
16
41
  getRollupSupportedTokens: () => getRollupSupportedTokens,
17
42
  getRollupTargetType: () => getRollupTargetType,
18
43
  getRollupTokenReserve: () => getRollupTokenReserve,
19
44
  hasRollupReserveTracking: () => hasRollupReserveTracking,
45
+ isBridgeFinalAt: () => require_states_rollup_v2.isBridgeFinalAt,
46
+ isBridgePausedAt: () => require_states_rollup_v2.isBridgePausedAt,
47
+ isBridgeV2: () => require_states_rollup_v2.isBridgeV2,
48
+ isBridgeV2Data: () => require_states_rollup_v2.isBridgeV2Data,
20
49
  isProposerSponsoredDepositAllowed: () => isProposerSponsoredDepositAllowed,
50
+ isQuorumPaused: () => require_states_rollup_v2.isQuorumPaused,
21
51
  isTokenSupportedByRollup: () => isTokenSupportedByRollup,
52
+ isValidOwnerCandidate: () => require_states_rollup_v2.isValidOwnerCandidate,
22
53
  isValidRollupContractAddress: () => isValidRollupContractAddress,
23
54
  isValidRollupTargetType: () => isValidRollupTargetType,
24
55
  isValidRollupValidatorAddress: () => isValidRollupValidatorAddress,
25
56
  isValidRollupVaultAddress: () => isValidRollupVaultAddress,
57
+ isZeroish: () => require_states_rollup_v2.isZeroish,
58
+ lc: () => require_states_rollup_v2.lc,
59
+ lonePauseTrack: () => require_states_rollup_v2.lonePauseTrack,
60
+ materializeBridgeAt: () => require_states_rollup_v2.materializeBridgeAt,
61
+ maxVoucherValidity: () => require_states_rollup_v2.maxVoucherValidity,
26
62
  migrateContract: () => migrateContract,
27
63
  migrateVault: () => migrateVault,
64
+ parseBridgeCreateData: () => require_states_rollup_v2.parseBridgeCreateData,
28
65
  pause: () => pause,
66
+ pendingEpochAt: () => require_states_rollup_v2.pendingEpochAt,
67
+ planBridgePatch: () => require_states_rollup_v2.planBridgePatch,
68
+ planMembership: () => require_states_rollup_v2.planMembership,
29
69
  recordRollupDeposit: () => recordRollupDeposit,
30
70
  recordRollupWithdraw: () => recordRollupWithdraw,
31
71
  resume: () => resume,
72
+ sameAddress: () => require_states_rollup_v2.sameAddress,
32
73
  schema: () => schema,
74
+ syncBridgeView: () => require_states_rollup_v2.syncBridgeView,
75
+ toSeconds: () => require_states_rollup_v2.toSeconds,
33
76
  update: () => update,
34
- validate: () => validate
77
+ updateBridge: () => require_states_rollup_bridge.updateBridge,
78
+ validate: () => validate,
79
+ validateBridge: () => require_states_rollup_bridge.validateBridge,
80
+ validateBridgeBody: () => require_states_rollup_v2.validateBridgeBody
35
81
  });
36
82
  const VALID_ROLLUP_TARGET_TYPES = ["EVM", "OCAP_ISOMORPHIC"];
37
83
  const ethDidSchema = (0, _arcblock_validator.vDID)({
@@ -183,6 +229,7 @@ const create = (attrs, context) => {
183
229
  if (attrs?.reserves && typeof attrs.reserves === "object") {
184
230
  for (const [tokenAddr, reserve] of Object.entries(attrs.reserves)) if (new _ocap_util.BN(reserve?.totalDeposited || "0").gt(new _ocap_util.BN(0)) || new _ocap_util.BN(reserve?.totalWithdrawn || "0").gt(new _ocap_util.BN(0))) throw new _ocap_util_lib_error.CustomError("INVALID_ROLLUP_PROPS", `Cannot pre-seed non-zero reserve watermark for token ${tokenAddr} on rollup creation`);
185
231
  }
232
+ if (require_states_rollup_v2.isBridgeV2Data(attrs?.data)) return require_states_rollup_bridge.createBridge(attrs, context);
186
233
  const dataValue = attrs?.data?.value && typeof attrs.data.value === "object" ? attrs.data.value : void 0;
187
234
  const rollup = {
188
235
  context: require_contexts_state.create(context),
@@ -243,6 +290,8 @@ const create = (attrs, context) => {
243
290
  return validate(rollup);
244
291
  };
245
292
  const update = (state, updates, context) => {
293
+ if (updates.data !== void 0 && updates.data !== null && require_states_rollup_v2.isBridgeV2Data(updates.data) !== require_states_rollup_v2.isBridgeV2(state)) throw new _ocap_util_lib_error.CustomError("INVALID_ROLLUP_UPDATE", "data.version is immutable: v1 and v2 rollups can not be converted");
294
+ if (require_states_rollup_v2.isBridgeV2(state)) return require_states_rollup_bridge.updateBridge(state, updates, context);
246
295
  if (updates.blockHeight && !updates.blockHash) throw new _ocap_util_lib_error.CustomError("INVALID_ROLLUP_UPDATE", "blockHash must be updated together with blockHeight");
247
296
  if (updates.blockHash && !updates.blockHeight) throw new _ocap_util_lib_error.CustomError("INVALID_ROLLUP_UPDATE", "blockHeight must be updated together with blockHash");
248
297
  if (updates.blockHeight && updates.blockHash) {
@@ -399,6 +448,7 @@ const recordRollupWithdraw = (state, tokenAddress, amount, context) => {
399
448
  };
400
449
  const validate = (state) => {
401
450
  if (state?.data?.value?.reserves !== void 0) throw new _ocap_util_lib_error.CustomError("INVALID_ROLLUP_PROPS", "reserves cannot be defined inside data.value");
451
+ if (require_states_rollup_v2.isBridgeV2Data(state?.data)) return require_states_rollup_bridge.validateBridge(state);
402
452
  const { value, error } = (0, _arcblock_validator.vValidate)(schema, state);
403
453
  if (error) throw new _ocap_util_lib_error.CustomError("INVALID_ROLLUP_PROPS", error.details.map((x) => x.message).join(", "));
404
454
  if (value.reserves && typeof value.reserves === "object") for (const [tokenAddr, reserve] of Object.entries(value.reserves)) {
@@ -410,22 +460,60 @@ const validate = (state) => {
410
460
  };
411
461
 
412
462
  //#endregion
463
+ exports.BRIDGE_CREATE_KEYS = require_states_rollup_v2.BRIDGE_CREATE_KEYS;
464
+ exports.BRIDGE_LONE_PAUSE_COOLDOWN = require_states_rollup_v2.BRIDGE_LONE_PAUSE_COOLDOWN;
465
+ exports.BRIDGE_LONE_PAUSE_TTL = require_states_rollup_v2.BRIDGE_LONE_PAUSE_TTL;
466
+ exports.BRIDGE_MAX_DELAY = require_states_rollup_v2.BRIDGE_MAX_DELAY;
467
+ exports.BRIDGE_MAX_EPOCH_LEAD = require_states_rollup_v2.BRIDGE_MAX_EPOCH_LEAD;
468
+ exports.BRIDGE_MAX_PAUSERS = require_states_rollup_v2.BRIDGE_MAX_PAUSERS;
469
+ exports.BRIDGE_MAX_VALIDATORS = require_states_rollup_v2.BRIDGE_MAX_VALIDATORS;
470
+ exports.BRIDGE_MIN_EPOCH_LEAD = require_states_rollup_v2.BRIDGE_MIN_EPOCH_LEAD;
471
+ exports.BRIDGE_MIN_VALIDATORS = require_states_rollup_v2.BRIDGE_MIN_VALIDATORS;
472
+ exports.BRIDGE_OWNER_TIMELOCK = require_states_rollup_v2.BRIDGE_OWNER_TIMELOCK;
473
+ exports.BRIDGE_PATCH_ACTION_KEYS = require_states_rollup_v2.BRIDGE_PATCH_ACTION_KEYS;
474
+ exports.BRIDGE_PATCH_VALUE_KEYS = require_states_rollup_v2.BRIDGE_PATCH_VALUE_KEYS;
475
+ exports.BRIDGE_RESERVE_MIGRATION_WINDOW = require_states_rollup_v2.BRIDGE_RESERVE_MIGRATION_WINDOW;
476
+ exports.BRIDGE_V1_ZERO_FIELDS = require_states_rollup_v2.BRIDGE_V1_ZERO_FIELDS;
477
+ exports.BRIDGE_VERSION = require_states_rollup_v2.BRIDGE_VERSION;
413
478
  exports.VALID_ROLLUP_TARGET_TYPES = VALID_ROLLUP_TARGET_TYPES;
479
+ exports.activeEpochAt = require_states_rollup_v2.activeEpochAt;
480
+ exports.applyLonePause = require_states_rollup_v2.applyLonePause;
481
+ exports.assertBridgeTransition = require_states_rollup_v2.assertBridgeTransition;
482
+ exports.assertV1FieldsUnused = require_states_rollup_v2.assertV1FieldsUnused;
483
+ exports.bridgeSchema = require_states_rollup_bridge.bridgeSchema;
414
484
  exports.close = close;
415
485
  exports.create = create;
486
+ exports.createBridge = require_states_rollup_bridge.createBridge;
487
+ exports.effectiveOwnerAt = require_states_rollup_v2.effectiveOwnerAt;
488
+ exports.getBridgeBody = require_states_rollup_v2.getBridgeBody;
416
489
  exports.getRollupSupportedTokens = getRollupSupportedTokens;
417
490
  exports.getRollupTargetType = getRollupTargetType;
418
491
  exports.getRollupTokenReserve = getRollupTokenReserve;
419
492
  exports.hasRollupReserveTracking = hasRollupReserveTracking;
493
+ exports.isBridgeFinalAt = require_states_rollup_v2.isBridgeFinalAt;
494
+ exports.isBridgePausedAt = require_states_rollup_v2.isBridgePausedAt;
495
+ exports.isBridgeV2 = require_states_rollup_v2.isBridgeV2;
496
+ exports.isBridgeV2Data = require_states_rollup_v2.isBridgeV2Data;
420
497
  exports.isProposerSponsoredDepositAllowed = isProposerSponsoredDepositAllowed;
498
+ exports.isQuorumPaused = require_states_rollup_v2.isQuorumPaused;
421
499
  exports.isTokenSupportedByRollup = isTokenSupportedByRollup;
500
+ exports.isValidOwnerCandidate = require_states_rollup_v2.isValidOwnerCandidate;
422
501
  exports.isValidRollupContractAddress = isValidRollupContractAddress;
423
502
  exports.isValidRollupTargetType = isValidRollupTargetType;
424
503
  exports.isValidRollupValidatorAddress = isValidRollupValidatorAddress;
425
504
  exports.isValidRollupVaultAddress = isValidRollupVaultAddress;
505
+ exports.isZeroish = require_states_rollup_v2.isZeroish;
506
+ exports.lc = require_states_rollup_v2.lc;
507
+ exports.lonePauseTrack = require_states_rollup_v2.lonePauseTrack;
508
+ exports.materializeBridgeAt = require_states_rollup_v2.materializeBridgeAt;
509
+ exports.maxVoucherValidity = require_states_rollup_v2.maxVoucherValidity;
426
510
  exports.migrateContract = migrateContract;
427
511
  exports.migrateVault = migrateVault;
512
+ exports.parseBridgeCreateData = require_states_rollup_v2.parseBridgeCreateData;
428
513
  exports.pause = pause;
514
+ exports.pendingEpochAt = require_states_rollup_v2.pendingEpochAt;
515
+ exports.planBridgePatch = require_states_rollup_v2.planBridgePatch;
516
+ exports.planMembership = require_states_rollup_v2.planMembership;
429
517
  exports.recordRollupDeposit = recordRollupDeposit;
430
518
  exports.recordRollupWithdraw = recordRollupWithdraw;
431
519
  exports.resume = resume;
@@ -435,6 +523,12 @@ Object.defineProperty(exports, 'rollup_exports', {
435
523
  return rollup_exports;
436
524
  }
437
525
  });
526
+ exports.sameAddress = require_states_rollup_v2.sameAddress;
438
527
  exports.schema = schema;
528
+ exports.syncBridgeView = require_states_rollup_v2.syncBridgeView;
529
+ exports.toSeconds = require_states_rollup_v2.toSeconds;
439
530
  exports.update = update;
440
- exports.validate = validate;
531
+ exports.updateBridge = require_states_rollup_bridge.updateBridge;
532
+ exports.validate = validate;
533
+ exports.validateBridge = require_states_rollup_bridge.validateBridge;
534
+ exports.validateBridgeBody = require_states_rollup_v2.validateBridgeBody;
@@ -1,10 +1,12 @@
1
1
  import { StateContextInput } from "../contexts/state.cjs";
2
+ import { BRIDGE_CREATE_KEYS, BRIDGE_LONE_PAUSE_COOLDOWN, BRIDGE_LONE_PAUSE_TTL, BRIDGE_MAX_DELAY, BRIDGE_MAX_EPOCH_LEAD, BRIDGE_MAX_PAUSERS, BRIDGE_MAX_VALIDATORS, BRIDGE_MIN_EPOCH_LEAD, BRIDGE_MIN_VALIDATORS, BRIDGE_OWNER_TIMELOCK, BRIDGE_PATCH_ACTION_KEYS, BRIDGE_PATCH_VALUE_KEYS, BRIDGE_RESERVE_MIGRATION_WINDOW, BRIDGE_V1_ZERO_FIELDS, BRIDGE_VERSION, BridgeBodyV2, BridgeConsent, BridgeCreateInput, BridgeEpoch, BridgeMember, BridgePatchKind, BridgePatchPlan, MembershipPlan, MembershipRequest, activeEpochAt, applyLonePause, assertBridgeTransition, assertV1FieldsUnused, effectiveOwnerAt, getBridgeBody, isBridgeFinalAt, isBridgePausedAt, isBridgeV2, isBridgeV2Data, isQuorumPaused, isValidOwnerCandidate, isZeroish, lc, lonePauseTrack, materializeBridgeAt, maxVoucherValidity, parseBridgeCreateData, pendingEpochAt, planBridgePatch, planMembership, sameAddress, syncBridgeView, toSeconds, validateBridgeBody } from "./rollup-v2.cjs";
3
+ import { bridgeSchema, createBridge, updateBridge, validateBridge } from "./rollup-bridge.cjs";
2
4
  import { IRollupState } from "@ocap/types";
3
5
  import { v } from "@arcblock/validator";
4
6
 
5
7
  //#region src/states/rollup.d.ts
6
8
  declare namespace rollup_d_exports {
7
- export { RollupTargetType, RollupTokenReserve, VALID_ROLLUP_TARGET_TYPES, close, create, getRollupSupportedTokens, getRollupTargetType, getRollupTokenReserve, hasRollupReserveTracking, isProposerSponsoredDepositAllowed, isTokenSupportedByRollup, isValidRollupContractAddress, isValidRollupTargetType, isValidRollupValidatorAddress, isValidRollupVaultAddress, migrateContract, migrateVault, pause, recordRollupDeposit, recordRollupWithdraw, resume, schema, update, validate };
9
+ export { BRIDGE_CREATE_KEYS, BRIDGE_LONE_PAUSE_COOLDOWN, BRIDGE_LONE_PAUSE_TTL, BRIDGE_MAX_DELAY, BRIDGE_MAX_EPOCH_LEAD, BRIDGE_MAX_PAUSERS, BRIDGE_MAX_VALIDATORS, BRIDGE_MIN_EPOCH_LEAD, BRIDGE_MIN_VALIDATORS, BRIDGE_OWNER_TIMELOCK, BRIDGE_PATCH_ACTION_KEYS, BRIDGE_PATCH_VALUE_KEYS, BRIDGE_RESERVE_MIGRATION_WINDOW, BRIDGE_V1_ZERO_FIELDS, BRIDGE_VERSION, BridgeBodyV2, BridgeConsent, BridgeCreateInput, BridgeEpoch, BridgeMember, BridgePatchKind, BridgePatchPlan, MembershipPlan, MembershipRequest, RollupTargetType, RollupTokenReserve, VALID_ROLLUP_TARGET_TYPES, activeEpochAt, applyLonePause, assertBridgeTransition, assertV1FieldsUnused, bridgeSchema, close, create, createBridge, effectiveOwnerAt, getBridgeBody, getRollupSupportedTokens, getRollupTargetType, getRollupTokenReserve, hasRollupReserveTracking, isBridgeFinalAt, isBridgePausedAt, isBridgeV2, isBridgeV2Data, isProposerSponsoredDepositAllowed, isQuorumPaused, isTokenSupportedByRollup, isValidOwnerCandidate, isValidRollupContractAddress, isValidRollupTargetType, isValidRollupValidatorAddress, isValidRollupVaultAddress, isZeroish, lc, lonePauseTrack, materializeBridgeAt, maxVoucherValidity, migrateContract, migrateVault, parseBridgeCreateData, pause, pendingEpochAt, planBridgePatch, planMembership, recordRollupDeposit, recordRollupWithdraw, resume, sameAddress, schema, syncBridgeView, toSeconds, update, updateBridge, validate, validateBridge, validateBridgeBody };
8
10
  }
9
11
  type RollupTargetType = 'EVM' | 'OCAP_ISOMORPHIC';
10
12
  interface RollupTokenReserve {
@@ -103,4 +105,4 @@ declare const recordRollupDeposit: (state: IRollupState & Record<string, any>, t
103
105
  declare const recordRollupWithdraw: (state: IRollupState & Record<string, any>, tokenAddress: string, amount: string, context: StateContextInput) => IRollupState;
104
106
  declare const validate: (state: IRollupState & Record<string, any>) => IRollupState;
105
107
  //#endregion
106
- export { RollupTargetType, RollupTokenReserve, VALID_ROLLUP_TARGET_TYPES, close, create, getRollupSupportedTokens, getRollupTargetType, getRollupTokenReserve, hasRollupReserveTracking, isProposerSponsoredDepositAllowed, isTokenSupportedByRollup, isValidRollupContractAddress, isValidRollupTargetType, isValidRollupValidatorAddress, isValidRollupVaultAddress, migrateContract, migrateVault, pause, recordRollupDeposit, recordRollupWithdraw, resume, rollup_d_exports, schema, update, validate };
108
+ export { BRIDGE_CREATE_KEYS, BRIDGE_LONE_PAUSE_COOLDOWN, BRIDGE_LONE_PAUSE_TTL, BRIDGE_MAX_DELAY, BRIDGE_MAX_EPOCH_LEAD, BRIDGE_MAX_PAUSERS, BRIDGE_MAX_VALIDATORS, BRIDGE_MIN_EPOCH_LEAD, BRIDGE_MIN_VALIDATORS, BRIDGE_OWNER_TIMELOCK, BRIDGE_PATCH_ACTION_KEYS, BRIDGE_PATCH_VALUE_KEYS, BRIDGE_RESERVE_MIGRATION_WINDOW, BRIDGE_V1_ZERO_FIELDS, BRIDGE_VERSION, BridgeBodyV2, BridgeConsent, BridgeCreateInput, BridgeEpoch, BridgeMember, BridgePatchKind, BridgePatchPlan, MembershipPlan, MembershipRequest, RollupTargetType, RollupTokenReserve, VALID_ROLLUP_TARGET_TYPES, activeEpochAt, applyLonePause, assertBridgeTransition, assertV1FieldsUnused, bridgeSchema, close, create, createBridge, effectiveOwnerAt, getBridgeBody, getRollupSupportedTokens, getRollupTargetType, getRollupTokenReserve, hasRollupReserveTracking, isBridgeFinalAt, isBridgePausedAt, isBridgeV2, isBridgeV2Data, isProposerSponsoredDepositAllowed, isQuorumPaused, isTokenSupportedByRollup, isValidOwnerCandidate, isValidRollupContractAddress, isValidRollupTargetType, isValidRollupValidatorAddress, isValidRollupVaultAddress, isZeroish, lc, lonePauseTrack, materializeBridgeAt, maxVoucherValidity, migrateContract, migrateVault, parseBridgeCreateData, pause, pendingEpochAt, planBridgePatch, planMembership, recordRollupDeposit, recordRollupWithdraw, resume, rollup_d_exports, sameAddress, schema, syncBridgeView, toSeconds, update, updateBridge, validate, validateBridge, validateBridgeBody };
@@ -13,6 +13,21 @@ var stake_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
13
13
  update: () => update,
14
14
  validate: () => validate
15
15
  });
16
+ const stakeRevokeEntrySchema = _arcblock_validator.v.object({
17
+ txTime: _arcblock_validator.v.optional(_arcblock_validator.v.string(), ""),
18
+ tokens: _arcblock_validator.v.optional((0, _arcblock_validator.vFilteredRecord)((0, _arcblock_validator.vDID)({
19
+ prefix: true,
20
+ role: "ROLE_TOKEN"
21
+ }), (0, _arcblock_validator.vBN)((0, _arcblock_validator.vBNMin)(0))), {}),
22
+ assets: _arcblock_validator.v.optional(_arcblock_validator.v.array((0, _arcblock_validator.vDID)({
23
+ prefix: true,
24
+ role: "ROLE_ASSET"
25
+ })), [])
26
+ });
27
+ const stakeContextSchema = _arcblock_validator.v.object({
28
+ ..._arcblock_validator.schemas.context.entries,
29
+ revokes: _arcblock_validator.v.optional(_arcblock_validator.v.record(_arcblock_validator.v.string(), stakeRevokeEntrySchema))
30
+ });
16
31
  const schema = _arcblock_validator.v.pipe(_arcblock_validator.v.object({
17
32
  address: (0, _arcblock_validator.vDID)({
18
33
  prefix: true,
@@ -40,7 +55,7 @@ const schema = _arcblock_validator.v.pipe(_arcblock_validator.v.object({
40
55
  prefix: true,
41
56
  role: "ROLE_ASSET"
42
57
  })), []),
43
- context: _arcblock_validator.schemas.context,
58
+ context: stakeContextSchema,
44
59
  data: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_arcblock_validator.v.any())),
45
60
  nonce: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_arcblock_validator.v.pipe(_arcblock_validator.v.string(), _arcblock_validator.v.trim(), _arcblock_validator.v.check((s) => s === "" || s.length >= 1 && s.length <= 256, "Must be 1-256 chars or empty"))))
46
61
  }), (0, _arcblock_validator.vStripUnknown)());
@@ -73,6 +88,9 @@ const create = (attrs, context) => {
73
88
  return validate(stake);
74
89
  };
75
90
  const update = (state, attrs, context) => {
91
+ const nextContext = require_contexts_state.update(state.context, context);
92
+ if (attrs.context && "revokes" in attrs.context) if (attrs.context.revokes && Object.keys(attrs.context.revokes).length > 0) nextContext.revokes = attrs.context.revokes;
93
+ else delete nextContext.revokes;
76
94
  return validate({
77
95
  ...state,
78
96
  revokedTokens: state.revokedTokens ?? {},
@@ -89,13 +107,16 @@ const update = (state, attrs, context) => {
89
107
  ]),
90
108
  ...attrs.data !== void 0 ? { data: attrs.data } : {},
91
109
  message: state.message || "empty",
92
- context: require_contexts_state.update(state.context, context)
110
+ context: nextContext
93
111
  });
94
112
  };
95
113
  const validate = (state) => {
96
114
  const { value, error } = (0, _arcblock_validator.vValidate)(schema, state);
97
115
  if (error) throw new _ocap_util_lib_error.CustomError("INVALID_STAKE", `Invalid stake state: ${error.details.map((x) => x.message).join(", ")}`);
98
116
  if (!value.data) value.data = null;
117
+ const hasRevokedTokens = Object.values(value.revokedTokens || {}).some((v$1) => new _ocap_util.BN(String(v$1 || "0")).gt(new _ocap_util.BN(0)));
118
+ const hasRevokedAssets = Array.isArray(value.revokedAssets) && value.revokedAssets.length > 0;
119
+ if (value.context && (!hasRevokedTokens && !hasRevokedAssets ? true : !value.context.revokes || Object.keys(value.context.revokes).length === 0)) delete value.context.revokes;
99
120
  return value;
100
121
  };
101
122
 
@@ -19,6 +19,11 @@ declare const schema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
19
19
  readonly revokedTokens: v.OptionalSchema<any, {}>;
20
20
  readonly revokedAssets: v.OptionalSchema<v.ArraySchema<any, undefined>, readonly []>;
21
21
  readonly context: v.ObjectSchema<{
22
+ readonly revokes: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
23
+ readonly txTime: v.OptionalSchema<v.StringSchema<undefined>, "">;
24
+ readonly tokens: v.OptionalSchema<any, {}>;
25
+ readonly assets: v.OptionalSchema<v.ArraySchema<any, undefined>, readonly []>;
26
+ }, undefined>, undefined>, undefined>;
22
27
  readonly genesisTime: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must be valid ISO date">]>;
23
28
  readonly genesisTx: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must match tx hash pattern or be empty">]>;
24
29
  readonly renaissanceTime: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must be valid ISO date">]>;
@@ -63,7 +63,8 @@ const stateSchema = _arcblock_validator.v.pipe(_arcblock_validator.v.object({
63
63
  status: _arcblock_validator.v.picklist([
64
64
  "ACTIVE",
65
65
  "PAUSED",
66
- "GRADUATED"
66
+ "GRADUATED",
67
+ "RETIRED"
67
68
  ]),
68
69
  feeRate: _arcblock_validator.v.pipe(_arcblock_validator.v.number(), _arcblock_validator.v.minValue(0), _arcblock_validator.v.maxValue(2e3)),
69
70
  curve: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(vCurveSchema)),
package/lib/states/tx.cjs CHANGED
@@ -58,7 +58,8 @@ const getTxReceiver = ({ tx, itx, typeUrl }) => {
58
58
  case "TransferTx":
59
59
  case "ExchangeTx":
60
60
  case "TransferV2Tx":
61
- case "ExchangeV2Tx": return itx.to;
61
+ case "ExchangeV2Tx":
62
+ case "ReleaseBridgeTokenTx": return itx.to;
62
63
  case "MintAssetTx": return itx.owner;
63
64
  case "CreateTokenTx":
64
65
  case "CreateAssetTx":
@@ -199,6 +200,33 @@ const getReceiptsFromGasPaid = (tx, { config, typeUrl }) => {
199
200
  }]
200
201
  }];
201
202
  };
203
+ /**
204
+ * `release_bridge_token` (#1466): the reserve pays `amount` of the official token to `itx.to`. The reserve address is
205
+ * not part of the itx (the protocol derives it from `itx.bridge`), so the protocol hands the paying reserve over as
206
+ * `ctx.bridgeReserve` and the bridge token as `ctx.bridgeToken`.
207
+ */
208
+ const getReleaseBridgeTokenReceipts = (tx, ctx) => {
209
+ const reserve = ctx.bridgeReserve;
210
+ const tokenAddress = ctx.bridgeToken || ctx.config?.token?.address;
211
+ const amount = tx.itxJson?.amount;
212
+ const to = tx.itxJson?.to;
213
+ if (!reserve || !tokenAddress || !amount || !to) return [];
214
+ return [{
215
+ address: reserve,
216
+ changes: [{
217
+ target: tokenAddress,
218
+ action: "transfer",
219
+ value: `-${amount}`
220
+ }]
221
+ }, {
222
+ address: to,
223
+ changes: [{
224
+ target: tokenAddress,
225
+ action: "transfer",
226
+ value: amount
227
+ }]
228
+ }];
229
+ };
202
230
  const getTransferV3Receipts = (tx) => [...getReceiptsFromTxInput(tx.itxJson.inputs || [], "-", "transfer"), ...getReceiptsFromTxInput(tx.itxJson.outputs || [], "", "transfer")];
203
231
  const getExchangeReceipts = (tx, ctx) => {
204
232
  const { senderState, receiverState } = ctx;
@@ -768,6 +796,7 @@ const getTxReceipts = ({ tx, code }, ctx = {}) => {
768
796
  let receipts = Array.isArray(ctx.receipts) ? ctx.receipts : [];
769
797
  if (["TransferTx", "TransferV2Tx"].includes(typeUrl)) receipts = receipts.concat(getTransferReceipts(tx));
770
798
  else if (["TransferV3Tx"].includes(typeUrl)) receipts = receipts.concat(getTransferV3Receipts(tx));
799
+ else if (["ReleaseBridgeTokenTx"].includes(typeUrl)) receipts = receipts.concat(getReleaseBridgeTokenReceipts(tx, ctx));
771
800
  else if (["ExchangeTx", "ExchangeV2Tx"].includes(typeUrl)) receipts = receipts.concat(getExchangeReceipts(tx, ctx));
772
801
  else if (["CreateAssetTx"].includes(typeUrl)) receipts = receipts.concat(getCreateAssetReceipts(tx));
773
802
  else if (["MintAssetTx"].includes(typeUrl)) receipts = receipts.concat(getMintAssetReceipts(tx, ctx));
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.31.0",
6
+ "version": "1.31.2",
7
7
  "description": "State management utilities for OCAP blockchain",
8
8
  "type": "module",
9
9
  "main": "./lib/index.cjs",
@@ -40,14 +40,14 @@
40
40
  "clean": "rm -rf lib esm"
41
41
  },
42
42
  "dependencies": {
43
- "@arcblock/did": "1.31.0",
44
- "@arcblock/validator": "1.31.0",
45
- "@ocap/contract": "1.31.0",
46
- "@ocap/mcrypto": "1.31.0",
47
- "@ocap/message": "1.31.0",
48
- "@ocap/types": "1.31.0",
49
- "@ocap/util": "1.31.0",
50
- "@ocap/wallet": "1.31.0",
43
+ "@arcblock/did": "1.31.2",
44
+ "@arcblock/validator": "1.31.2",
45
+ "@ocap/contract": "1.31.2",
46
+ "@ocap/mcrypto": "1.31.2",
47
+ "@ocap/message": "1.31.2",
48
+ "@ocap/types": "1.31.2",
49
+ "@ocap/util": "1.31.2",
50
+ "@ocap/wallet": "1.31.2",
51
51
  "bloom-filters": "^1.3.9",
52
52
  "lodash": "^4.17.23"
53
53
  },