@ocap/tx-protocols 1.31.1 → 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.
Files changed (161) hide show
  1. package/esm/bridge-release-crypto.d.mts +39 -0
  2. package/esm/bridge-release-crypto.mjs +88 -0
  3. package/esm/bridge-release-window.d.mts +47 -0
  4. package/esm/bridge-release-window.mjs +62 -0
  5. package/esm/bridge-reserve.d.mts +24 -0
  6. package/esm/bridge-reserve.mjs +41 -0
  7. package/esm/execute.d.mts +1 -1
  8. package/esm/execute.mjs +58 -5
  9. package/esm/gas-security-guard.d.mts +6 -2
  10. package/esm/gas-security-guard.mjs +16 -9
  11. package/esm/index.d.mts +37 -18
  12. package/esm/index.mjs +6 -2
  13. package/esm/pipes/ensure-cost.mjs +7 -1
  14. package/esm/pipes/write-ledger.d.mts +2 -2
  15. package/esm/pipes/write-ledger.mjs +6 -3
  16. package/esm/protocols/account/delegate.mjs +6 -4
  17. package/esm/protocols/account/migrate.mjs +5 -3
  18. package/esm/protocols/account/revoke-delegate.mjs +5 -3
  19. package/esm/protocols/asset/acquire-v2.mjs +3 -1
  20. package/esm/protocols/asset/acquire-v3.mjs +4 -2
  21. package/esm/protocols/asset/consume.mjs +3 -1
  22. package/esm/protocols/asset/create.mjs +4 -2
  23. package/esm/protocols/asset/mint.mjs +4 -2
  24. package/esm/protocols/asset/pipes/exec-mint-hook.mjs +1 -1
  25. package/esm/protocols/asset/pipes/verify-itx-address.mjs +1 -1
  26. package/esm/protocols/asset/pipes/verify-itx-assets.mjs +1 -1
  27. package/esm/protocols/asset/update.mjs +4 -2
  28. package/esm/protocols/bridge/release.d.mts +34 -0
  29. package/esm/protocols/bridge/release.mjs +385 -0
  30. package/esm/protocols/factory/create.mjs +4 -2
  31. package/esm/protocols/governance/claim-stake.mjs +4 -2
  32. package/esm/protocols/governance/return-stake.mjs +4 -2
  33. package/esm/protocols/governance/revoke-ledger.mjs +1 -1
  34. package/esm/protocols/governance/revoke-stake.d.mts +7 -2
  35. package/esm/protocols/governance/revoke-stake.mjs +49 -28
  36. package/esm/protocols/governance/slash-stake.mjs +5 -3
  37. package/esm/protocols/governance/stake.mjs +6 -4
  38. package/esm/protocols/rollup/bridge-create.d.mts +13 -0
  39. package/esm/protocols/rollup/bridge-create.mjs +206 -0
  40. package/esm/protocols/rollup/bridge-membership.d.mts +10 -0
  41. package/esm/protocols/rollup/bridge-membership.mjs +154 -0
  42. package/esm/protocols/rollup/bridge-migrate.d.mts +10 -0
  43. package/esm/protocols/rollup/bridge-migrate.mjs +208 -0
  44. package/esm/protocols/rollup/bridge-v2.d.mts +113 -0
  45. package/esm/protocols/rollup/bridge-v2.mjs +219 -0
  46. package/esm/protocols/rollup/claim-reward.mjs +4 -2
  47. package/esm/protocols/rollup/close.d.mts +2 -1
  48. package/esm/protocols/rollup/close.mjs +59 -6
  49. package/esm/protocols/rollup/create-block.mjs +4 -2
  50. package/esm/protocols/rollup/create.d.mts +3 -0
  51. package/esm/protocols/rollup/create.mjs +45 -6
  52. package/esm/protocols/rollup/join.d.mts +2 -1
  53. package/esm/protocols/rollup/join.mjs +31 -23
  54. package/esm/protocols/rollup/leave.d.mts +2 -1
  55. package/esm/protocols/rollup/leave.mjs +32 -24
  56. package/esm/protocols/rollup/migrate.d.mts +2 -1
  57. package/esm/protocols/rollup/migrate.mjs +19 -10
  58. package/esm/protocols/rollup/pause.d.mts +4 -1
  59. package/esm/protocols/rollup/pause.mjs +50 -6
  60. package/esm/protocols/rollup/pipes/verify-evidence.mjs +2 -2
  61. package/esm/protocols/rollup/resume.d.mts +2 -1
  62. package/esm/protocols/rollup/resume.mjs +26 -6
  63. package/esm/protocols/rollup/update.d.mts +5 -1
  64. package/esm/protocols/rollup/update.mjs +56 -9
  65. package/esm/protocols/token/create.mjs +4 -2
  66. package/esm/protocols/token/deposit-v2.mjs +5 -3
  67. package/esm/protocols/token/withdraw-v2.mjs +5 -3
  68. package/esm/protocols/token-factory/burn.mjs +4 -2
  69. package/esm/protocols/token-factory/create.mjs +8 -4
  70. package/esm/protocols/token-factory/mint.mjs +4 -2
  71. package/esm/protocols/token-factory/update.mjs +20 -5
  72. package/esm/protocols/trade/exchange-v2.d.mts +5 -1
  73. package/esm/protocols/trade/exchange-v2.mjs +89 -4
  74. package/esm/protocols/trade/transfer-v2.mjs +15 -4
  75. package/esm/protocols/trade/transfer-v3.mjs +5 -3
  76. package/esm/stateless-prefix.d.mts +16 -0
  77. package/esm/stateless-prefix.mjs +82 -0
  78. package/esm/tx-timer.d.mts +1 -1
  79. package/esm/tx-timer.mjs +1 -1
  80. package/esm/util.mjs +2 -2
  81. package/lib/bridge-release-crypto.cjs +93 -0
  82. package/lib/bridge-release-crypto.d.cts +39 -0
  83. package/lib/bridge-release-window.cjs +69 -0
  84. package/lib/bridge-release-window.d.cts +47 -0
  85. package/lib/bridge-reserve.cjs +45 -0
  86. package/lib/bridge-reserve.d.cts +24 -0
  87. package/lib/execute.cjs +58 -5
  88. package/lib/gas-security-guard.cjs +16 -9
  89. package/lib/gas-security-guard.d.cts +6 -2
  90. package/lib/index.cjs +8 -1
  91. package/lib/index.d.cts +36 -17
  92. package/lib/pipes/ensure-cost.cjs +7 -1
  93. package/lib/pipes/write-ledger.cjs +6 -3
  94. package/lib/pipes/write-ledger.d.cts +2 -2
  95. package/lib/protocols/account/delegate.cjs +6 -4
  96. package/lib/protocols/account/migrate.cjs +5 -3
  97. package/lib/protocols/account/revoke-delegate.cjs +5 -3
  98. package/lib/protocols/asset/acquire-v2.cjs +3 -1
  99. package/lib/protocols/asset/acquire-v3.cjs +4 -2
  100. package/lib/protocols/asset/consume.cjs +3 -1
  101. package/lib/protocols/asset/create.cjs +4 -2
  102. package/lib/protocols/asset/mint.cjs +4 -2
  103. package/lib/protocols/asset/pipes/exec-mint-hook.cjs +1 -1
  104. package/lib/protocols/asset/pipes/verify-itx-address.cjs +1 -1
  105. package/lib/protocols/asset/pipes/verify-itx-assets.cjs +1 -1
  106. package/lib/protocols/asset/update.cjs +4 -2
  107. package/lib/protocols/bridge/release.cjs +390 -0
  108. package/lib/protocols/bridge/release.d.cts +34 -0
  109. package/lib/protocols/factory/create.cjs +4 -2
  110. package/lib/protocols/governance/claim-stake.cjs +4 -2
  111. package/lib/protocols/governance/return-stake.cjs +4 -2
  112. package/lib/protocols/governance/revoke-ledger.cjs +1 -1
  113. package/lib/protocols/governance/revoke-stake.cjs +49 -28
  114. package/lib/protocols/governance/revoke-stake.d.cts +7 -2
  115. package/lib/protocols/governance/slash-stake.cjs +5 -3
  116. package/lib/protocols/governance/stake.cjs +6 -4
  117. package/lib/protocols/rollup/bridge-create.cjs +209 -0
  118. package/lib/protocols/rollup/bridge-create.d.cts +13 -0
  119. package/lib/protocols/rollup/bridge-membership.cjs +157 -0
  120. package/lib/protocols/rollup/bridge-membership.d.cts +10 -0
  121. package/lib/protocols/rollup/bridge-migrate.cjs +212 -0
  122. package/lib/protocols/rollup/bridge-migrate.d.cts +10 -0
  123. package/lib/protocols/rollup/bridge-v2.cjs +244 -0
  124. package/lib/protocols/rollup/bridge-v2.d.cts +113 -0
  125. package/lib/protocols/rollup/claim-reward.cjs +4 -2
  126. package/lib/protocols/rollup/close.cjs +59 -6
  127. package/lib/protocols/rollup/close.d.cts +2 -1
  128. package/lib/protocols/rollup/create-block.cjs +4 -2
  129. package/lib/protocols/rollup/create.cjs +45 -6
  130. package/lib/protocols/rollup/create.d.cts +3 -0
  131. package/lib/protocols/rollup/join.cjs +31 -23
  132. package/lib/protocols/rollup/join.d.cts +2 -1
  133. package/lib/protocols/rollup/leave.cjs +32 -24
  134. package/lib/protocols/rollup/leave.d.cts +2 -1
  135. package/lib/protocols/rollup/migrate.cjs +19 -10
  136. package/lib/protocols/rollup/migrate.d.cts +2 -1
  137. package/lib/protocols/rollup/pause.cjs +50 -6
  138. package/lib/protocols/rollup/pause.d.cts +4 -1
  139. package/lib/protocols/rollup/pipes/verify-evidence.cjs +2 -2
  140. package/lib/protocols/rollup/resume.cjs +26 -6
  141. package/lib/protocols/rollup/resume.d.cts +2 -1
  142. package/lib/protocols/rollup/update.cjs +56 -9
  143. package/lib/protocols/rollup/update.d.cts +5 -1
  144. package/lib/protocols/token/create.cjs +4 -2
  145. package/lib/protocols/token/deposit-v2.cjs +5 -3
  146. package/lib/protocols/token/withdraw-v2.cjs +5 -3
  147. package/lib/protocols/token-factory/burn.cjs +4 -2
  148. package/lib/protocols/token-factory/create.cjs +8 -4
  149. package/lib/protocols/token-factory/mint.cjs +4 -2
  150. package/lib/protocols/token-factory/update.cjs +20 -5
  151. package/lib/protocols/trade/exchange-v2.cjs +90 -3
  152. package/lib/protocols/trade/exchange-v2.d.cts +5 -1
  153. package/lib/protocols/trade/transfer-v2.cjs +15 -4
  154. package/lib/protocols/trade/transfer-v3.cjs +5 -3
  155. package/lib/stateless-prefix.cjs +88 -0
  156. package/lib/stateless-prefix.d.cts +16 -0
  157. package/lib/tx-timer.cjs +1 -1
  158. package/lib/tx-timer.d.cts +1 -1
  159. package/lib/util.cjs +2 -2
  160. package/package.json +16 -16
  161. package/tools/fixtures.ts +9 -4
@@ -1,16 +1,18 @@
1
1
  import { isHttpUrl } from "../../util.mjs";
2
2
  import ensure_cost_default from "../../pipes/ensure-cost.mjs";
3
3
  import ensure_gas_default from "../../pipes/ensure-gas.mjs";
4
+ import { ifV1, loadBridge, peekBridge, rejectRollupV1IfDisabled } from "./bridge-v2.mjs";
4
5
  import verify_signers_default from "./pipes/verify-signers.mjs";
5
6
  import verify_status_default from "./pipes/verify-status.mjs";
6
7
  import verify_evidence_default from "./pipes/verify-evidence.mjs";
7
8
  import { any, check, minLength, nullable, object, optional, pipe, regex, string } from "../../node_modules/valibot/dist/index.mjs";
9
+ import { membershipChecks, membershipSchemaV2, membershipStep } from "./bridge-membership.mjs";
10
+ import { Runner, pipes } from "@ocap/tx-pipeline";
11
+ import { CustomError } from "@ocap/util/lib/error";
8
12
  import { isEthereumDid } from "@arcblock/did";
9
13
  import { toStakeAddress } from "@arcblock/did-util";
10
14
  import { account, evidence, rollup, stake } from "@ocap/state";
11
- import { Runner, pipes } from "@ocap/tx-pipeline";
12
15
  import { BN, toHex } from "@ocap/util";
13
- import { CustomError } from "@ocap/util/lib/error";
14
16
  import Debug from "debug";
15
17
  import { patterns, schemas, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
16
18
  import MerkleTree from "@ocap/merkle-tree";
@@ -29,18 +31,22 @@ const schema = pipe(object({
29
31
  signaturesList: pipe(schemas.multiSig, minLength(1)),
30
32
  data: optional(nullable(any()))
31
33
  }), vStripUnknown());
32
- runner.use(({ itx }, next) => {
34
+ runner.use(peekBridge("itx.rollup", { rejectV1IfDisabled: "join_rollup" }));
35
+ runner.use(ifV1(({ itx }, next) => {
33
36
  const { error } = vValidate(schema, itx);
34
37
  return next(error ? new CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
35
- });
38
+ }));
39
+ runner.use(membershipSchemaV2("join"));
36
40
  runner.use(pipes.ExtractState({
37
41
  from: "itx.rollup",
38
42
  to: "rollupState",
39
43
  status: "INVALID_ROLLUP",
40
44
  table: "rollup"
41
45
  }));
42
- runner.use(verify_status_default({ paused: false }));
43
- runner.use((context, next) => {
46
+ runner.use(loadBridge);
47
+ runner.use(rejectRollupV1IfDisabled("join_rollup"));
48
+ runner.use(ifV1(verify_status_default({ paused: false })));
49
+ runner.use(ifV1((context, next) => {
44
50
  const { tx: tx$1, itx, rollupState } = context;
45
51
  const validator = {
46
52
  pk: toHex(tx$1.pk),
@@ -53,50 +59,51 @@ runner.use((context, next) => {
53
59
  context.newValidator = validator;
54
60
  context.validatorsHash = MerkleTree.getListHash([validator.address]);
55
61
  return next();
56
- });
57
- runner.use(verify_signers_default({
62
+ }));
63
+ runner.use(ifV1(verify_signers_default({
58
64
  signersKey: "itx.signaturesList",
59
65
  allowSender: false
60
- }));
61
- runner.use(verify_evidence_default({
66
+ })));
67
+ runner.use(ifV1(verify_evidence_default({
62
68
  evidenceKey: "validatorsHash",
63
69
  signaturesKey: "itx.signaturesList",
64
70
  verifyMethod: "ethVerify"
65
- }));
66
- runner.use(pipes.ExtractState({
71
+ })));
72
+ runner.use(ifV1(pipes.ExtractState({
67
73
  from: "itx.evidence.hash",
68
74
  to: "evidenceState",
69
75
  status: "OK",
70
76
  table: "evidence"
71
- }));
72
- runner.use(({ evidenceState }, next) => {
77
+ })));
78
+ runner.use(ifV1(({ evidenceState }, next) => {
73
79
  if (evidenceState) return next(new CustomError("INVALID_TX", "Join evidence already seen on this chain"));
74
80
  return next();
75
- });
76
- runner.use(verify_signers_default({
81
+ }));
82
+ runner.use(ifV1(verify_signers_default({
77
83
  signersKey: "tx.signaturesList",
78
84
  allowSender: false
79
- }));
85
+ })));
86
+ runner.use(membershipChecks("join"));
80
87
  runner.use(pipes.VerifyMultiSigV2({ signersKey: "signers" }));
81
- runner.use((context, next) => {
88
+ runner.use(ifV1((context, next) => {
82
89
  const { tx: tx$1, itx } = context;
83
90
  context.stakeAddress = toStakeAddress(tx$1.from, itx.rollup);
84
91
  return next();
85
- });
86
- runner.use(pipes.ExtractState({
92
+ }));
93
+ runner.use(ifV1(pipes.ExtractState({
87
94
  from: "stakeAddress",
88
95
  to: "stakeState",
89
96
  status: "INVALID_STAKE_STATE",
90
97
  table: "stake"
91
- }));
92
- runner.use((context, next) => {
98
+ })));
99
+ runner.use(ifV1((context, next) => {
93
100
  const { stakeState, rollupState } = context;
94
101
  if (stakeState?.revocable === false) return next(new CustomError("INVALID_STAKE_STATE", `Staking already locked: ${stakeState.address}`));
95
102
  const actualStake = new BN(stakeState?.tokens[rollupState?.tokenAddress || ""] || 0);
96
103
  const requiredStake = new BN(rollupState?.minStakeAmount || 0);
97
104
  if (actualStake.lt(requiredStake)) return next(new CustomError("INVALID_STAKE_STATE", `Staking does not match min stake amount: ${requiredStake}`));
98
105
  return next();
99
- });
106
+ }));
100
107
  runner.use(pipes.ExtractState({
101
108
  from: "tx.from",
102
109
  to: "senderState",
@@ -122,6 +129,7 @@ runner.use(ensure_gas_default(() => ({
122
129
  runner.use(ensure_cost_default({ attachSenderChanges: true }));
123
130
  runner.use(pipes.TakeStateSnapshot());
124
131
  runner.use(async (context, next) => {
132
+ if (context.isBridgeV2) return membershipStep("join")(context, next);
125
133
  const { tx: tx$1, itx, rollupState, statedb, senderState, stakeState, newValidator, stakeAddress, senderUpdates, updateVaults } = context;
126
134
  const newValidators = rollupState.validators.concat([newValidator]);
127
135
  const [newSenderState, newRollupState, newStakeState, newEvidenceState] = await Promise.all([
@@ -1,3 +1,4 @@
1
+ import { BridgeCtxMixin } from "./bridge-v2.mjs";
1
2
  import { Runner } from "@ocap/tx-pipeline";
2
3
  import { IEvidenceState, IReadyContext, IWithRollup, IWithSender, IWithSigners, IWithStake, TLeaveRollupTx } from "@ocap/types";
3
4
 
@@ -8,7 +9,7 @@ import { IEvidenceState, IReadyContext, IWithRollup, IWithSender, IWithSigners,
8
9
  * Phase: IReadyContext (after TakeStateSnapshot)
9
10
  * Mixins: IWithRollup (required), IWithSender (required), IWithSigners (required), IWithStake (required)
10
11
  */
11
- type Context = IReadyContext<TLeaveRollupTx> & IWithRollup & IWithSender & IWithSigners & IWithStake & {
12
+ type Context = IReadyContext<TLeaveRollupTx> & IWithRollup & IWithSender & IWithSigners & IWithStake & BridgeCtxMixin & {
12
13
  /** Hash of validators being removed */
13
14
  validatorsHash?: string;
14
15
  /** Evidence state (null if not seen before) */
@@ -1,14 +1,16 @@
1
1
  import ensure_cost_default from "../../pipes/ensure-cost.mjs";
2
2
  import ensure_gas_default from "../../pipes/ensure-gas.mjs";
3
+ import { ifV1, loadBridge, peekBridge, rejectRollupV1IfDisabled } from "./bridge-v2.mjs";
3
4
  import ensure_validator_default from "./pipes/ensure-validator.mjs";
4
5
  import verify_signers_default from "./pipes/verify-signers.mjs";
5
6
  import verify_status_default from "./pipes/verify-status.mjs";
6
7
  import verify_evidence_default from "./pipes/verify-evidence.mjs";
7
8
  import { any, minLength, nullable, object, optional, pipe, regex, string } from "../../node_modules/valibot/dist/index.mjs";
8
- import { toStakeAddress } from "@arcblock/did-util";
9
- import { account, evidence, rollup, stake } from "@ocap/state";
9
+ import { membershipChecks, membershipSchemaV2, membershipStep } from "./bridge-membership.mjs";
10
10
  import { Runner, pipes } from "@ocap/tx-pipeline";
11
11
  import { CustomError } from "@ocap/util/lib/error";
12
+ import { toStakeAddress } from "@arcblock/did-util";
13
+ import { account, evidence, rollup, stake } from "@ocap/state";
12
14
  import Debug from "debug";
13
15
  import { patterns, schemas, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
14
16
  import MerkleTree from "@ocap/merkle-tree";
@@ -25,65 +27,70 @@ const schema = pipe(object({
25
27
  signaturesList: pipe(schemas.multiSig, minLength(1)),
26
28
  data: optional(nullable(any()))
27
29
  }), vStripUnknown());
28
- runner.use(({ itx }, next) => {
30
+ runner.use(peekBridge("itx.rollup", { rejectV1IfDisabled: "leave_rollup" }));
31
+ runner.use(ifV1(({ itx }, next) => {
29
32
  const { error } = vValidate(schema, itx);
30
33
  return next(error ? new CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
31
- });
34
+ }));
35
+ runner.use(membershipSchemaV2("leave"));
32
36
  runner.use(pipes.ExtractState({
33
37
  from: "itx.rollup",
34
38
  to: "rollupState",
35
39
  status: "INVALID_ROLLUP",
36
40
  table: "rollup"
37
41
  }));
38
- runner.use(ensure_validator_default(false));
39
- runner.use(verify_status_default({ paused: false }));
40
- runner.use((context, next) => {
42
+ runner.use(loadBridge);
43
+ runner.use(rejectRollupV1IfDisabled("leave_rollup"));
44
+ runner.use(ifV1(ensure_validator_default(false)));
45
+ runner.use(ifV1(verify_status_default({ paused: false })));
46
+ runner.use(ifV1((context, next) => {
41
47
  context.validatorsHash = MerkleTree.getListHash([context.tx.from]);
42
48
  return next();
43
- });
44
- runner.use(verify_signers_default({
49
+ }));
50
+ runner.use(ifV1(verify_signers_default({
45
51
  signersKey: "itx.signaturesList",
46
52
  allowSender: false,
47
53
  allowShrink: true
48
- }));
49
- runner.use(verify_evidence_default({
54
+ })));
55
+ runner.use(ifV1(verify_evidence_default({
50
56
  evidenceKey: "validatorsHash",
51
57
  signaturesKey: "itx.signaturesList",
52
58
  verifyMethod: "ethVerify"
53
- }));
54
- runner.use(pipes.ExtractState({
59
+ })));
60
+ runner.use(ifV1(pipes.ExtractState({
55
61
  from: "itx.evidence.hash",
56
62
  to: "evidenceState",
57
63
  status: "OK",
58
64
  table: "evidence"
59
- }));
60
- runner.use((context, next) => {
65
+ })));
66
+ runner.use(ifV1((context, next) => {
61
67
  if (context.evidenceState) return next(new CustomError("INVALID_TX", "Leave evidence already seen on this chain"));
62
68
  return next();
63
- });
64
- runner.use(verify_signers_default({
69
+ }));
70
+ runner.use(ifV1(verify_signers_default({
65
71
  signersKey: "tx.signaturesList",
66
72
  allowSender: false,
67
73
  allowShrink: true
68
- }));
74
+ })));
75
+ runner.use(membershipChecks("leave"));
69
76
  runner.use(pipes.VerifyMultiSigV2({ signersKey: "signers" }));
70
- runner.use((context, next) => {
77
+ runner.use(ifV1((context, next) => {
71
78
  const { tx: tx$1, rollupState } = context;
72
79
  if (rollupState?.seedValidators.some((x) => x.address === tx$1.from)) return next(new CustomError("INVALID_TX", `Address ${tx$1.from} can not leave since it's seed validator`));
73
80
  if (rollupState?.validators.some((x) => x.address === tx$1.from) === false) return next(new CustomError("INVALID_TX", `Address ${tx$1.from} not exist in validator whitelist`));
74
81
  return next();
75
- });
76
- runner.use((context, next) => {
82
+ }));
83
+ runner.use(ifV1((context, next) => {
77
84
  const { tx: tx$1, itx } = context;
78
85
  context.stakeAddress = toStakeAddress(tx$1.from, itx.rollup);
79
86
  return next();
80
- });
81
- runner.use(pipes.ExtractState({
87
+ }));
88
+ runner.use(ifV1(pipes.ExtractState({
82
89
  from: "stakeAddress",
83
90
  to: "stakeState",
84
91
  status: "INVALID_STAKE_STATE",
85
92
  table: "stake"
86
- }));
93
+ })));
87
94
  runner.use(pipes.ExtractState({
88
95
  from: "tx.from",
89
96
  to: "senderState",
@@ -109,6 +116,7 @@ runner.use(ensure_gas_default(() => ({
109
116
  runner.use(ensure_cost_default({ attachSenderChanges: true }));
110
117
  runner.use(pipes.TakeStateSnapshot());
111
118
  runner.use(async (context, next) => {
119
+ if (context.isBridgeV2) return membershipStep("leave")(context, next);
112
120
  const { tx: tx$1, itx, rollupState, statedb, senderState, stakeState, stakeAddress, senderUpdates, updateVaults } = context;
113
121
  const newValidators = rollupState.validators.filter((x) => x.address !== tx$1.from);
114
122
  const [newSenderState, newRollupState, newStakeState, newEvidenceState] = await Promise.all([
@@ -1,3 +1,4 @@
1
+ import { BridgeCtxMixin } from "./bridge-v2.mjs";
1
2
  import { Runner } from "@ocap/tx-pipeline";
2
3
  import { IReadyContext, IWithRollup, IWithSender, IWithSigners, TMigrateRollupTx } from "@ocap/types";
3
4
 
@@ -8,7 +9,7 @@ import { IReadyContext, IWithRollup, IWithSender, IWithSigners, TMigrateRollupTx
8
9
  * Phase: IReadyContext (after TakeStateSnapshot)
9
10
  * Mixins: IWithRollup (required), IWithSender (required), IWithSigners (required)
10
11
  */
11
- type Context = IReadyContext<TMigrateRollupTx> & IWithRollup & IWithSender & IWithSigners;
12
+ type Context = IReadyContext<TMigrateRollupTx> & IWithRollup & IWithSender & IWithSigners & BridgeCtxMixin;
12
13
  declare const runner: Runner<Context>;
13
14
  //#endregion
14
15
  export { runner as default };
@@ -1,11 +1,13 @@
1
1
  import ensure_cost_default from "../../pipes/ensure-cost.mjs";
2
2
  import ensure_gas_default from "../../pipes/ensure-gas.mjs";
3
+ import { ifV1, loadBridge, peekBridge, rejectRollupV1IfDisabled } from "./bridge-v2.mjs";
3
4
  import ensure_validator_default from "./pipes/ensure-validator.mjs";
4
5
  import verify_signers_default from "./pipes/verify-signers.mjs";
5
6
  import verify_status_default from "./pipes/verify-status.mjs";
6
- import { account, rollup } from "@ocap/state";
7
+ import { migrateBridgeAuth, migrateBridgeChecks, migrateBridgeStep, migrateSchemaV2 } from "./bridge-migrate.mjs";
7
8
  import { Runner, pipes } from "@ocap/tx-pipeline";
8
9
  import { CustomError } from "@ocap/util/lib/error";
10
+ import { account, rollup } from "@ocap/state";
9
11
  import { v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
10
12
 
11
13
  //#region src/protocols/rollup/migrate.ts
@@ -20,31 +22,37 @@ const schema = v.pipe(v.object({
20
22
  message: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(512)),
21
23
  data: v.optional(v.nullable(v.any()))
22
24
  }), vStripUnknown());
23
- runner.use(({ itx }, next) => {
25
+ runner.use(peekBridge("itx.rollup", { rejectV1IfDisabled: "migrate_rollup" }));
26
+ runner.use(ifV1(({ itx }, next) => {
24
27
  const { error } = vValidate(schema, itx);
25
28
  return next(error ? new CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
26
- });
29
+ }));
30
+ runner.use(migrateSchemaV2);
27
31
  runner.use(pipes.ExtractState({
28
32
  from: "itx.rollup",
29
33
  to: "rollupState",
30
34
  status: "INVALID_ROLLUP",
31
35
  table: "rollup"
32
36
  }));
33
- runner.use((context, next) => {
37
+ runner.use(loadBridge);
38
+ runner.use(rejectRollupV1IfDisabled("migrate_rollup"));
39
+ runner.use(ifV1((context, next) => {
34
40
  const { itx, rollupState } = context;
35
41
  const targetType = rollup.getRollupTargetType(rollupState);
36
42
  if (!(itx.type === "vault" ? Boolean(itx.to) && rollup.isValidRollupVaultAddress(itx.to, targetType) : rollup.isValidRollupContractAddress(itx.to, targetType))) return next(new CustomError("INVALID_TX", "Invalid itx: \"to\" Expected wallet type to be \"ethereum\""));
37
43
  return next();
38
- });
39
- runner.use(ensure_validator_default(true));
40
- runner.use(verify_status_default({
44
+ }));
45
+ runner.use(ifV1(ensure_validator_default(true)));
46
+ runner.use(ifV1(verify_status_default({
41
47
  paused: true,
42
48
  closed: false
43
- }));
44
- runner.use(verify_signers_default({
49
+ })));
50
+ runner.use(migrateBridgeChecks);
51
+ runner.use(ifV1(verify_signers_default({
45
52
  signersKey: "tx.signaturesList",
46
53
  allowSender: true
47
- }));
54
+ })));
55
+ runner.use(migrateBridgeAuth);
48
56
  runner.use(pipes.VerifyMultiSigV2({ signersKey: "signers" }));
49
57
  runner.use(pipes.ExtractState({
50
58
  from: "tx.from",
@@ -72,6 +80,7 @@ runner.use(ensure_cost_default({ attachSenderChanges: true }));
72
80
  runner.use(pipes.TakeStateSnapshot());
73
81
  runner.use(async (context, next) => {
74
82
  const { tx: tx$1, itx, statedb, rollupState, senderState, senderUpdates, updateVaults } = context;
83
+ if (context.isBridgeV2) return migrateBridgeStep(context, next);
75
84
  let updates = {};
76
85
  if (itx.type === "vault") updates = rollup.migrateVault(rollupState, itx.to, context);
77
86
  if (itx.type === "contract") updates = rollup.migrateContract(rollupState, itx.to, context);
@@ -1,3 +1,4 @@
1
+ import { BridgeCtxMixin } from "./bridge-v2.mjs";
1
2
  import { Runner } from "@ocap/tx-pipeline";
2
3
  import { IReadyContext, IWithRollup, IWithSender, IWithSigners, TPauseRollupTx } from "@ocap/types";
3
4
 
@@ -8,7 +9,9 @@ import { IReadyContext, IWithRollup, IWithSender, IWithSigners, TPauseRollupTx }
8
9
  * Phase: IReadyContext (after TakeStateSnapshot)
9
10
  * Mixins: IWithRollup (required), IWithSender (required), IWithSigners (required)
10
11
  */
11
- type Context = IReadyContext<TPauseRollupTx> & IWithRollup & IWithSender & IWithSigners;
12
+ type Context = IReadyContext<TPauseRollupTx> & IWithRollup & IWithSender & IWithSigners & BridgeCtxMixin & {
13
+ pauseKind?: 'quorum' | 'lone';
14
+ };
12
15
  declare const runner: Runner<Context>;
13
16
  //#endregion
14
17
  export { runner as default };
@@ -1,11 +1,13 @@
1
1
  import ensure_cost_default from "../../pipes/ensure-cost.mjs";
2
2
  import ensure_gas_default from "../../pipes/ensure-gas.mjs";
3
+ import { VerifyBridgeAuthority, bridgeUpdates, ifV1, loadBridge, peekBridge } from "./bridge-v2.mjs";
3
4
  import ensure_validator_default from "./pipes/ensure-validator.mjs";
4
5
  import verify_signers_default from "./pipes/verify-signers.mjs";
5
6
  import verify_status_default from "./pipes/verify-status.mjs";
6
- import { account, rollup } from "@ocap/state";
7
7
  import { Runner, pipes } from "@ocap/tx-pipeline";
8
8
  import { CustomError } from "@ocap/util/lib/error";
9
+ import { getListField } from "@ocap/util/lib/get-list-field";
10
+ import { account, rollup } from "@ocap/state";
9
11
  import { v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
10
12
 
11
13
  //#region src/protocols/rollup/pause.ts
@@ -17,6 +19,7 @@ const schema = v.pipe(v.object({
17
19
  }),
18
20
  data: v.optional(v.nullable(v.any()))
19
21
  }), vStripUnknown());
22
+ runner.use(peekBridge("itx.rollup"));
20
23
  runner.use(({ itx }, next) => {
21
24
  const { error } = vValidate(schema, itx);
22
25
  return next(error ? new CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
@@ -27,12 +30,44 @@ runner.use(pipes.ExtractState({
27
30
  status: "INVALID_ROLLUP",
28
31
  table: "rollup"
29
32
  }));
30
- runner.use(ensure_validator_default(true));
31
- runner.use(verify_status_default({ paused: false }));
32
- runner.use(verify_signers_default({
33
+ runner.use(loadBridge);
34
+ runner.use(ifV1(ensure_validator_default(true)));
35
+ runner.use(ifV1(verify_status_default({ paused: false })));
36
+ runner.use(ifV1(verify_signers_default({
33
37
  signersKey: "tx.signaturesList",
34
38
  allowSender: true
35
- }));
39
+ })));
40
+ runner.use((context, next) => {
41
+ if (!context.isBridgeV2) return next();
42
+ const state = context.rollupState;
43
+ const body = context.bridgeBody;
44
+ if (state.closed) return next(new CustomError("INVALID_TX", "The rollup is closed"));
45
+ const pausedNow = rollup.isBridgePausedAt(state, context.txSec);
46
+ const asLone = () => {
47
+ if (getListField(context, "tx.signaturesList").length > 0 || !body.pausers.some((p) => rollup.sameAddress(p, context.tx.from))) return false;
48
+ return true;
49
+ };
50
+ return VerifyBridgeAuthority({
51
+ owner: "required",
52
+ quorum: "threshold"
53
+ })(context, (err) => {
54
+ if (!err) {
55
+ if (pausedNow && state.paused && body.lonePause === null) return next(new CustomError("INVALID_TX", "The rollup is already paused"));
56
+ context.pauseKind = "quorum";
57
+ return next();
58
+ }
59
+ if (!asLone()) return next(err);
60
+ if (pausedNow) return next(new CustomError("INVALID_TX", "The rollup is already paused"));
61
+ try {
62
+ context.nextBody = rollup.applyLonePause(body, context.tx.from, context.txSec);
63
+ } catch (e) {
64
+ return next(new CustomError("INVALID_TX", e.message));
65
+ }
66
+ context.pauseKind = "lone";
67
+ context.signers = [];
68
+ return next();
69
+ });
70
+ });
36
71
  runner.use(pipes.VerifyMultiSigV2({ signersKey: "signers" }));
37
72
  runner.use(pipes.ExtractState({
38
73
  from: "tx.from",
@@ -60,10 +95,19 @@ runner.use(ensure_cost_default({ attachSenderChanges: true }));
60
95
  runner.use(pipes.TakeStateSnapshot());
61
96
  runner.use(async (context, next) => {
62
97
  const { tx: tx$1, itx, rollupState, statedb, senderState, senderUpdates, updateVaults } = context;
98
+ let nextRollup;
99
+ if (context.isBridgeV2) {
100
+ const body = context.pauseKind === "lone" ? context.nextBody : {
101
+ ...context.bridgeBody,
102
+ lonePause: null,
103
+ lastLonePause: {}
104
+ };
105
+ nextRollup = rollup.updateBridge(context.rollupStateOrig, bridgeUpdates(context, body, { paused: true }), context);
106
+ } else nextRollup = rollup.pause(rollupState, context);
63
107
  const [newSenderState, newRollupState] = await Promise.all([statedb.account.update(senderState.address, account.update(senderState, {
64
108
  nonce: tx$1.nonce,
65
109
  ...senderUpdates
66
- }, context), context), statedb.rollup.update(itx.rollup, rollup.pause(rollupState, context), context)]);
110
+ }, context), context), statedb.rollup.update(itx.rollup, nextRollup, context)]);
67
111
  if (updateVaults) await updateVaults();
68
112
  context.senderState = newSenderState;
69
113
  context.rollupState = newRollupState;
@@ -1,8 +1,8 @@
1
+ import { CustomError } from "@ocap/util/lib/error";
2
+ import { getListField } from "@ocap/util/lib/get-list-field";
1
3
  import { isEthereumDid, isFromPublicKey, toTypeInfo } from "@arcblock/did";
2
4
  import { rollup } from "@ocap/state";
3
5
  import { toHex } from "@ocap/util";
4
- import { CustomError } from "@ocap/util/lib/error";
5
- import { getListField } from "@ocap/util/lib/get-list-field";
6
6
  import get from "lodash/get.js";
7
7
  import { fromPublicKey as fromPublicKey$1 } from "@ocap/wallet";
8
8
 
@@ -1,3 +1,4 @@
1
+ import { BridgeCtxMixin } from "./bridge-v2.mjs";
1
2
  import { Runner } from "@ocap/tx-pipeline";
2
3
  import { IReadyContext, IWithRollup, IWithSender, IWithSigners, TResumeRollupTx } from "@ocap/types";
3
4
 
@@ -8,7 +9,7 @@ import { IReadyContext, IWithRollup, IWithSender, IWithSigners, TResumeRollupTx
8
9
  * Phase: IReadyContext (after TakeStateSnapshot)
9
10
  * Mixins: IWithRollup (required), IWithSender (required), IWithSigners (required)
10
11
  */
11
- type Context = IReadyContext<TResumeRollupTx> & IWithRollup & IWithSender & IWithSigners;
12
+ type Context = IReadyContext<TResumeRollupTx> & IWithRollup & IWithSender & IWithSigners & BridgeCtxMixin;
12
13
  declare const runner: Runner<Context>;
13
14
  //#endregion
14
15
  export { runner as default };
@@ -1,11 +1,12 @@
1
1
  import ensure_cost_default from "../../pipes/ensure-cost.mjs";
2
2
  import ensure_gas_default from "../../pipes/ensure-gas.mjs";
3
+ import { VerifyBridgeAuthority, bridgeUpdates, ifV1, loadBridge, peekBridge, rejectRollupV1IfDisabled } from "./bridge-v2.mjs";
3
4
  import ensure_validator_default from "./pipes/ensure-validator.mjs";
4
5
  import verify_signers_default from "./pipes/verify-signers.mjs";
5
6
  import verify_status_default from "./pipes/verify-status.mjs";
6
- import { account, rollup } from "@ocap/state";
7
7
  import { Runner, pipes } from "@ocap/tx-pipeline";
8
8
  import { CustomError } from "@ocap/util/lib/error";
9
+ import { account, rollup } from "@ocap/state";
9
10
  import { v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
10
11
 
11
12
  //#region src/protocols/rollup/resume.ts
@@ -17,6 +18,7 @@ const schema = v.pipe(v.object({
17
18
  }),
18
19
  data: v.optional(v.nullable(v.any()))
19
20
  }), vStripUnknown());
21
+ runner.use(peekBridge("itx.rollup", { rejectV1IfDisabled: "resume_rollup" }));
20
22
  runner.use(({ itx }, next) => {
21
23
  const { error } = vValidate(schema, itx);
22
24
  return next(error ? new CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
@@ -27,14 +29,27 @@ runner.use(pipes.ExtractState({
27
29
  status: "INVALID_ROLLUP",
28
30
  table: "rollup"
29
31
  }));
30
- runner.use(ensure_validator_default(true));
31
- runner.use(verify_status_default({
32
+ runner.use(loadBridge);
33
+ runner.use(rejectRollupV1IfDisabled("resume_rollup"));
34
+ runner.use(ifV1(ensure_validator_default(true)));
35
+ runner.use(ifV1(verify_status_default({
32
36
  paused: true,
33
37
  closed: false
34
- }));
35
- runner.use(verify_signers_default({
38
+ })));
39
+ runner.use((context, next) => {
40
+ if (!context.isBridgeV2) return next();
41
+ const state = context.rollupState;
42
+ if (state.closed) return next(new CustomError("INVALID_TX", "The rollup is closed"));
43
+ if (!rollup.isBridgePausedAt(state, context.txSec)) return next(new CustomError("INVALID_TX", "The rollup is not paused"));
44
+ return next();
45
+ });
46
+ runner.use(ifV1(verify_signers_default({
36
47
  signersKey: "tx.signaturesList",
37
48
  allowSender: true
49
+ })));
50
+ runner.use(VerifyBridgeAuthority({
51
+ owner: "required",
52
+ quorum: "threshold"
38
53
  }));
39
54
  runner.use(pipes.VerifyMultiSigV2({ signersKey: "signers" }));
40
55
  runner.use(pipes.ExtractState({
@@ -63,10 +78,15 @@ runner.use(ensure_cost_default({ attachSenderChanges: true }));
63
78
  runner.use(pipes.TakeStateSnapshot());
64
79
  runner.use(async (context, next) => {
65
80
  const { tx: tx$1, itx, rollupState, statedb, senderState, senderUpdates, updateVaults } = context;
81
+ const nextRollup = context.isBridgeV2 ? rollup.updateBridge(context.rollupStateOrig, bridgeUpdates(context, {
82
+ ...context.bridgeBody,
83
+ lonePause: null,
84
+ lastLonePause: {}
85
+ }, { paused: false }), context) : rollup.resume(rollupState, context);
66
86
  const [newSenderState, newRollupState] = await Promise.all([statedb.account.update(senderState.address, account.update(senderState, {
67
87
  nonce: tx$1.nonce,
68
88
  ...senderUpdates
69
- }, context), context), statedb.rollup.update(itx.rollup, rollup.resume(rollupState, context), context)]);
89
+ }, context), context), statedb.rollup.update(itx.rollup, nextRollup, context)]);
70
90
  if (updateVaults) await updateVaults();
71
91
  context.senderState = newSenderState;
72
92
  context.rollupState = newRollupState;
@@ -1,4 +1,6 @@
1
+ import { BridgeCtxMixin } from "./bridge-v2.mjs";
1
2
  import { Runner } from "@ocap/tx-pipeline";
3
+ import { rollup } from "@ocap/state";
2
4
  import { IReadyContext, IWithRollup, IWithSender, IWithSigners, TUpdateRollupTx } from "@ocap/types";
3
5
 
4
6
  //#region src/protocols/rollup/update.d.ts
@@ -8,7 +10,9 @@ import { IReadyContext, IWithRollup, IWithSender, IWithSigners, TUpdateRollupTx
8
10
  * Phase: IReadyContext (after TakeStateSnapshot)
9
11
  * Mixins: IWithRollup (required), IWithSender (required), IWithSigners (required)
10
12
  */
11
- type Context = IReadyContext<TUpdateRollupTx> & IWithRollup & IWithSender & IWithSigners;
13
+ type Context = IReadyContext<TUpdateRollupTx> & IWithRollup & IWithSender & IWithSigners & BridgeCtxMixin & {
14
+ bridgePlan?: rollup.BridgePatchPlan;
15
+ };
12
16
  declare const runner: Runner<Context>;
13
17
  //#endregion
14
18
  export { runner as default };