@ocap/tx-protocols 1.28.9 → 1.29.0
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/execute.d.mts +53 -0
- package/esm/execute.mjs +225 -0
- package/esm/index.d.mts +95 -0
- package/esm/index.mjs +100 -0
- package/esm/pipes/ensure-cost.d.mts +18 -0
- package/esm/pipes/ensure-cost.mjs +136 -0
- package/esm/pipes/ensure-gas.d.mts +14 -0
- package/esm/pipes/ensure-gas.mjs +38 -0
- package/esm/protocols/account/delegate.d.mts +4 -0
- package/esm/protocols/account/delegate.mjs +195 -0
- package/esm/protocols/account/migrate.d.mts +4 -0
- package/esm/protocols/account/migrate.mjs +130 -0
- package/esm/protocols/account/revoke-delegate.d.mts +4 -0
- package/esm/protocols/account/revoke-delegate.mjs +102 -0
- package/esm/protocols/asset/acquire-v2.d.mts +9 -0
- package/esm/protocols/asset/acquire-v2.mjs +213 -0
- package/esm/protocols/asset/acquire-v3.d.mts +17 -0
- package/esm/protocols/asset/acquire-v3.mjs +265 -0
- package/esm/protocols/asset/calls/transfer-token.d.mts +4 -0
- package/esm/protocols/asset/calls/transfer-token.mjs +36 -0
- package/esm/protocols/asset/calls/transfer.d.mts +4 -0
- package/esm/protocols/asset/calls/transfer.mjs +32 -0
- package/esm/protocols/asset/consume.d.mts +4 -0
- package/esm/protocols/asset/consume.mjs +92 -0
- package/esm/protocols/asset/create.d.mts +4 -0
- package/esm/protocols/asset/create.mjs +136 -0
- package/esm/protocols/asset/mint.d.mts +4 -0
- package/esm/protocols/asset/mint.mjs +156 -0
- package/esm/protocols/asset/pipes/exec-mint-hook.d.mts +24 -0
- package/esm/protocols/asset/pipes/exec-mint-hook.mjs +54 -0
- package/esm/protocols/asset/pipes/extract-factory-tokens.d.mts +21 -0
- package/esm/protocols/asset/pipes/extract-factory-tokens.mjs +22 -0
- package/esm/protocols/asset/pipes/verify-itx-address.d.mts +32 -0
- package/esm/protocols/asset/pipes/verify-itx-address.mjs +56 -0
- package/esm/protocols/asset/pipes/verify-itx-assets.d.mts +18 -0
- package/esm/protocols/asset/pipes/verify-itx-assets.mjs +27 -0
- package/esm/protocols/asset/pipes/verify-itx-variables.d.mts +17 -0
- package/esm/protocols/asset/pipes/verify-itx-variables.mjs +20 -0
- package/esm/protocols/asset/pipes/verify-mint-limit.d.mts +15 -0
- package/esm/protocols/asset/pipes/verify-mint-limit.mjs +14 -0
- package/esm/protocols/asset/update.d.mts +4 -0
- package/esm/protocols/asset/update.mjs +111 -0
- package/esm/protocols/factory/create.d.mts +29 -0
- package/esm/protocols/factory/create.mjs +155 -0
- package/esm/protocols/governance/claim-stake.d.mts +27 -0
- package/esm/protocols/governance/claim-stake.mjs +220 -0
- package/esm/protocols/governance/return-stake.d.mts +27 -0
- package/esm/protocols/governance/return-stake.mjs +211 -0
- package/esm/protocols/governance/revoke-stake.d.mts +27 -0
- package/esm/protocols/governance/revoke-stake.mjs +178 -0
- package/esm/protocols/governance/slash-stake.d.mts +17 -0
- package/esm/protocols/governance/slash-stake.mjs +213 -0
- package/esm/protocols/governance/stake.d.mts +15 -0
- package/esm/protocols/governance/stake.mjs +270 -0
- package/esm/protocols/rollup/claim-reward.d.mts +11 -0
- package/esm/protocols/rollup/claim-reward.mjs +322 -0
- package/esm/protocols/rollup/close.d.mts +4 -0
- package/esm/protocols/rollup/close.mjs +105 -0
- package/esm/protocols/rollup/create-block.d.mts +11 -0
- package/esm/protocols/rollup/create-block.mjs +303 -0
- package/esm/protocols/rollup/create.d.mts +4 -0
- package/esm/protocols/rollup/create.mjs +164 -0
- package/esm/protocols/rollup/join.d.mts +4 -0
- package/esm/protocols/rollup/join.mjs +152 -0
- package/esm/protocols/rollup/leave.d.mts +4 -0
- package/esm/protocols/rollup/leave.mjs +137 -0
- package/esm/protocols/rollup/migrate.d.mts +4 -0
- package/esm/protocols/rollup/migrate.mjs +85 -0
- package/esm/protocols/rollup/pause.d.mts +4 -0
- package/esm/protocols/rollup/pause.mjs +76 -0
- package/esm/protocols/rollup/pipes/ensure-validator.d.mts +6 -0
- package/esm/protocols/rollup/pipes/ensure-validator.mjs +12 -0
- package/esm/protocols/rollup/pipes/verify-evidence.d.mts +15 -0
- package/esm/protocols/rollup/pipes/verify-evidence.mjs +29 -0
- package/esm/protocols/rollup/pipes/verify-signers.d.mts +15 -0
- package/esm/protocols/rollup/pipes/verify-signers.mjs +36 -0
- package/esm/protocols/rollup/pipes/verify-status.d.mts +13 -0
- package/esm/protocols/rollup/pipes/verify-status.mjs +26 -0
- package/esm/protocols/rollup/resume.d.mts +4 -0
- package/esm/protocols/rollup/resume.mjs +79 -0
- package/esm/protocols/rollup/update.d.mts +4 -0
- package/esm/protocols/rollup/update.mjs +111 -0
- package/esm/protocols/token/create.d.mts +4 -0
- package/esm/protocols/token/create.mjs +150 -0
- package/esm/protocols/token/deposit-v2.d.mts +11 -0
- package/esm/protocols/token/deposit-v2.mjs +216 -0
- package/esm/protocols/token/withdraw-v2.d.mts +9 -0
- package/esm/protocols/token/withdraw-v2.mjs +222 -0
- package/esm/protocols/token-factory/burn.d.mts +15 -0
- package/esm/protocols/token-factory/burn.mjs +233 -0
- package/esm/protocols/token-factory/create.d.mts +4 -0
- package/esm/protocols/token-factory/create.mjs +254 -0
- package/esm/protocols/token-factory/mint.d.mts +15 -0
- package/esm/protocols/token-factory/mint.mjs +234 -0
- package/esm/protocols/token-factory/pipes/calc-reserve.d.mts +21 -0
- package/esm/protocols/token-factory/pipes/calc-reserve.mjs +34 -0
- package/esm/protocols/token-factory/pipes/verify-icon.d.mts +14 -0
- package/esm/protocols/token-factory/pipes/verify-icon.mjs +18 -0
- package/esm/protocols/token-factory/pipes/verify-ownership.d.mts +12 -0
- package/esm/protocols/token-factory/pipes/verify-ownership.mjs +63 -0
- package/esm/protocols/token-factory/pipes/verify-url.d.mts +12 -0
- package/esm/protocols/token-factory/pipes/verify-url.mjs +26 -0
- package/esm/protocols/token-factory/update.d.mts +10 -0
- package/esm/protocols/token-factory/update.mjs +152 -0
- package/esm/protocols/trade/exchange-v2.d.mts +9 -0
- package/esm/protocols/trade/exchange-v2.mjs +239 -0
- package/esm/protocols/trade/transfer-v2.d.mts +9 -0
- package/esm/protocols/trade/transfer-v2.mjs +226 -0
- package/esm/protocols/trade/transfer-v3.d.mts +17 -0
- package/esm/protocols/trade/transfer-v3.mjs +270 -0
- package/esm/util.d.mts +141 -0
- package/esm/util.mjs +278 -0
- package/lib/_virtual/rolldown_runtime.cjs +29 -0
- package/lib/execute.cjs +231 -0
- package/lib/execute.d.cts +53 -0
- package/lib/index.cjs +105 -0
- package/lib/index.d.cts +95 -0
- package/lib/pipes/ensure-cost.cjs +141 -0
- package/lib/pipes/ensure-cost.d.cts +18 -0
- package/lib/pipes/ensure-gas.cjs +41 -0
- package/lib/pipes/ensure-gas.d.cts +14 -0
- package/lib/protocols/account/delegate.cjs +201 -0
- package/lib/protocols/account/delegate.d.cts +4 -0
- package/lib/protocols/account/migrate.cjs +135 -0
- package/lib/protocols/account/migrate.d.cts +4 -0
- package/lib/protocols/account/revoke-delegate.cjs +107 -0
- package/lib/protocols/account/revoke-delegate.d.cts +4 -0
- package/lib/protocols/asset/acquire-v2.cjs +216 -0
- package/lib/protocols/asset/acquire-v2.d.cts +9 -0
- package/lib/protocols/asset/acquire-v3.cjs +269 -0
- package/lib/protocols/asset/acquire-v3.d.cts +17 -0
- package/lib/protocols/asset/calls/transfer-token.cjs +40 -0
- package/lib/protocols/asset/calls/transfer-token.d.cts +4 -0
- package/lib/protocols/asset/calls/transfer.cjs +35 -0
- package/lib/protocols/asset/calls/transfer.d.cts +4 -0
- package/lib/protocols/asset/consume.cjs +95 -0
- package/lib/protocols/asset/consume.d.cts +4 -0
- package/lib/protocols/asset/create.cjs +140 -0
- package/lib/protocols/asset/create.d.cts +4 -0
- package/lib/protocols/asset/mint.cjs +159 -0
- package/lib/protocols/asset/mint.d.cts +4 -0
- package/lib/protocols/asset/pipes/exec-mint-hook.cjs +57 -0
- package/lib/protocols/asset/pipes/exec-mint-hook.d.cts +24 -0
- package/lib/protocols/asset/pipes/extract-factory-tokens.cjs +25 -0
- package/lib/protocols/asset/pipes/extract-factory-tokens.d.cts +21 -0
- package/lib/protocols/asset/pipes/verify-itx-address.cjs +59 -0
- package/lib/protocols/asset/pipes/verify-itx-address.d.cts +32 -0
- package/lib/protocols/asset/pipes/verify-itx-assets.cjs +29 -0
- package/lib/protocols/asset/pipes/verify-itx-assets.d.cts +18 -0
- package/lib/protocols/asset/pipes/verify-itx-variables.cjs +22 -0
- package/lib/protocols/asset/pipes/verify-itx-variables.d.cts +17 -0
- package/lib/protocols/asset/pipes/verify-mint-limit.cjs +16 -0
- package/lib/protocols/asset/pipes/verify-mint-limit.d.cts +15 -0
- package/lib/protocols/asset/update.cjs +114 -0
- package/lib/protocols/asset/update.d.cts +4 -0
- package/lib/protocols/factory/create.cjs +161 -0
- package/lib/protocols/factory/create.d.cts +29 -0
- package/lib/protocols/governance/claim-stake.cjs +223 -0
- package/lib/protocols/governance/claim-stake.d.cts +27 -0
- package/lib/protocols/governance/return-stake.cjs +215 -0
- package/lib/protocols/governance/return-stake.d.cts +27 -0
- package/lib/protocols/governance/revoke-stake.cjs +182 -0
- package/lib/protocols/governance/revoke-stake.d.cts +27 -0
- package/lib/protocols/governance/slash-stake.cjs +217 -0
- package/lib/protocols/governance/slash-stake.d.cts +17 -0
- package/lib/protocols/governance/stake.cjs +275 -0
- package/lib/protocols/governance/stake.d.cts +15 -0
- package/lib/protocols/rollup/claim-reward.cjs +328 -0
- package/lib/protocols/rollup/claim-reward.d.cts +11 -0
- package/lib/protocols/rollup/close.cjs +107 -0
- package/lib/protocols/rollup/close.d.cts +4 -0
- package/lib/protocols/rollup/create-block.cjs +309 -0
- package/lib/protocols/rollup/create-block.d.cts +11 -0
- package/lib/protocols/rollup/create.cjs +169 -0
- package/lib/protocols/rollup/create.d.cts +4 -0
- package/lib/protocols/rollup/join.cjs +157 -0
- package/lib/protocols/rollup/join.d.cts +4 -0
- package/lib/protocols/rollup/leave.cjs +141 -0
- package/lib/protocols/rollup/leave.d.cts +4 -0
- package/lib/protocols/rollup/migrate.cjs +87 -0
- package/lib/protocols/rollup/migrate.d.cts +4 -0
- package/lib/protocols/rollup/pause.cjs +78 -0
- package/lib/protocols/rollup/pause.d.cts +4 -0
- package/lib/protocols/rollup/pipes/ensure-validator.cjs +14 -0
- package/lib/protocols/rollup/pipes/ensure-validator.d.cts +6 -0
- package/lib/protocols/rollup/pipes/verify-evidence.cjs +32 -0
- package/lib/protocols/rollup/pipes/verify-evidence.d.cts +15 -0
- package/lib/protocols/rollup/pipes/verify-signers.cjs +39 -0
- package/lib/protocols/rollup/pipes/verify-signers.d.cts +15 -0
- package/lib/protocols/rollup/pipes/verify-status.cjs +28 -0
- package/lib/protocols/rollup/pipes/verify-status.d.cts +13 -0
- package/lib/protocols/rollup/resume.cjs +81 -0
- package/lib/protocols/rollup/resume.d.cts +4 -0
- package/lib/protocols/rollup/update.cjs +114 -0
- package/lib/protocols/rollup/update.d.cts +4 -0
- package/lib/protocols/token/create.cjs +156 -0
- package/lib/protocols/token/create.d.cts +4 -0
- package/lib/protocols/token/deposit-v2.cjs +219 -0
- package/lib/protocols/token/deposit-v2.d.cts +11 -0
- package/lib/protocols/token/withdraw-v2.cjs +225 -0
- package/lib/protocols/token/withdraw-v2.d.cts +9 -0
- package/lib/protocols/token-factory/burn.cjs +236 -0
- package/lib/protocols/token-factory/burn.d.cts +15 -0
- package/lib/protocols/token-factory/create.cjs +260 -0
- package/lib/protocols/token-factory/create.d.cts +4 -0
- package/lib/protocols/token-factory/mint.cjs +237 -0
- package/lib/protocols/token-factory/mint.d.cts +15 -0
- package/lib/protocols/token-factory/pipes/calc-reserve.cjs +38 -0
- package/lib/protocols/token-factory/pipes/calc-reserve.d.cts +21 -0
- package/lib/protocols/token-factory/pipes/verify-icon.cjs +22 -0
- package/lib/protocols/token-factory/pipes/verify-icon.d.cts +14 -0
- package/lib/protocols/token-factory/pipes/verify-ownership.cjs +66 -0
- package/lib/protocols/token-factory/pipes/verify-ownership.d.cts +12 -0
- package/lib/protocols/token-factory/pipes/verify-url.cjs +29 -0
- package/lib/protocols/token-factory/pipes/verify-url.d.cts +12 -0
- package/lib/protocols/token-factory/update.cjs +155 -0
- package/lib/protocols/token-factory/update.d.cts +10 -0
- package/lib/protocols/trade/exchange-v2.cjs +243 -0
- package/lib/protocols/trade/exchange-v2.d.cts +9 -0
- package/lib/protocols/trade/transfer-v2.cjs +229 -0
- package/lib/protocols/trade/transfer-v2.d.cts +9 -0
- package/lib/protocols/trade/transfer-v3.cjs +274 -0
- package/lib/protocols/trade/transfer-v3.d.cts +17 -0
- package/lib/util.cjs +296 -0
- package/lib/util.d.cts +141 -0
- package/package.json +49 -22
- package/tools/fixtures.ts +564 -0
- package/lib/execute.js +0 -254
- package/lib/index.js +0 -117
- package/lib/pipes/ensure-cost.js +0 -193
- package/lib/pipes/ensure-gas.js +0 -48
- package/lib/protocols/account/delegate.js +0 -223
- package/lib/protocols/account/migrate.js +0 -153
- package/lib/protocols/account/revoke-delegate.js +0 -110
- package/lib/protocols/asset/acquire-v2.js +0 -262
- package/lib/protocols/asset/acquire-v3.js +0 -330
- package/lib/protocols/asset/calls/README.md +0 -5
- package/lib/protocols/asset/calls/transfer-token.js +0 -36
- package/lib/protocols/asset/calls/transfer.js +0 -28
- package/lib/protocols/asset/consume.js +0 -105
- package/lib/protocols/asset/create.js +0 -151
- package/lib/protocols/asset/mint.js +0 -199
- package/lib/protocols/asset/pipes/exec-mint-hook.js +0 -62
- package/lib/protocols/asset/pipes/extract-factory-tokens.js +0 -18
- package/lib/protocols/asset/pipes/verify-itx-address.js +0 -54
- package/lib/protocols/asset/pipes/verify-itx-assets.js +0 -51
- package/lib/protocols/asset/pipes/verify-itx-variables.js +0 -26
- package/lib/protocols/asset/pipes/verify-mint-limit.js +0 -13
- package/lib/protocols/asset/update.js +0 -131
- package/lib/protocols/factory/create.js +0 -191
- package/lib/protocols/governance/claim-stake.js +0 -266
- package/lib/protocols/governance/return-stake.js +0 -248
- package/lib/protocols/governance/revoke-stake.js +0 -172
- package/lib/protocols/governance/slash-stake.js +0 -271
- package/lib/protocols/governance/stake.js +0 -303
- package/lib/protocols/rollup/claim-reward.js +0 -342
- package/lib/protocols/rollup/close.js +0 -104
- package/lib/protocols/rollup/create-block.js +0 -413
- package/lib/protocols/rollup/create.js +0 -197
- package/lib/protocols/rollup/join.js +0 -182
- package/lib/protocols/rollup/leave.js +0 -145
- package/lib/protocols/rollup/migrate.js +0 -85
- package/lib/protocols/rollup/pause.js +0 -75
- package/lib/protocols/rollup/pipes/ensure-validator.js +0 -12
- package/lib/protocols/rollup/pipes/verify-evidence.js +0 -37
- package/lib/protocols/rollup/pipes/verify-signers.js +0 -87
- package/lib/protocols/rollup/pipes/verify-status.js +0 -30
- package/lib/protocols/rollup/resume.js +0 -75
- package/lib/protocols/rollup/update.js +0 -122
- package/lib/protocols/token/create.js +0 -199
- package/lib/protocols/token/deposit-v2.js +0 -290
- package/lib/protocols/token/withdraw-v2.js +0 -305
- package/lib/protocols/token-factory/burn.js +0 -371
- package/lib/protocols/token-factory/create.js +0 -342
- package/lib/protocols/token-factory/mint.js +0 -385
- package/lib/protocols/token-factory/pipes/calc-reserve.js +0 -37
- package/lib/protocols/token-factory/pipes/verify-icon.js +0 -27
- package/lib/protocols/token-factory/pipes/verify-ownership.js +0 -93
- package/lib/protocols/token-factory/pipes/verify-url.js +0 -32
- package/lib/protocols/token-factory/update.js +0 -208
- package/lib/protocols/trade/exchange-v2.js +0 -239
- package/lib/protocols/trade/transfer-v2.js +0 -233
- package/lib/protocols/trade/transfer-v3.js +0 -333
- package/lib/util.js +0 -442
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
3
|
+
const require_pipes_ensure_cost = require('../../pipes/ensure-cost.cjs');
|
|
4
|
+
const require_pipes_ensure_gas = require('../../pipes/ensure-gas.cjs');
|
|
5
|
+
const require_protocols_rollup_pipes_ensure_validator = require('./pipes/ensure-validator.cjs');
|
|
6
|
+
const require_protocols_rollup_pipes_verify_signers = require('./pipes/verify-signers.cjs');
|
|
7
|
+
const require_protocols_rollup_pipes_verify_status = require('./pipes/verify-status.cjs');
|
|
8
|
+
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
9
|
+
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
10
|
+
let _arcblock_did_util = require("@arcblock/did-util");
|
|
11
|
+
let _ocap_state = require("@ocap/state");
|
|
12
|
+
let _arcblock_validator = require("@arcblock/validator");
|
|
13
|
+
|
|
14
|
+
//#region src/protocols/rollup/close.ts
|
|
15
|
+
const runner = new _ocap_tx_pipeline.Runner("close_rollup");
|
|
16
|
+
const schema = _arcblock_validator.Joi.object({
|
|
17
|
+
rollup: _arcblock_validator.Joi.DID().prefix().role("ROLE_ROLLUP").required(),
|
|
18
|
+
message: _arcblock_validator.Joi.string().trim().min(1).max(512).required(),
|
|
19
|
+
token: _arcblock_validator.Joi.object({
|
|
20
|
+
address: _arcblock_validator.Joi.DID().prefix().wallet("ethereum").required(),
|
|
21
|
+
value: _arcblock_validator.Joi.BN().positive().required()
|
|
22
|
+
}),
|
|
23
|
+
data: _arcblock_validator.Joi.any().optional().allow(null)
|
|
24
|
+
}).options({
|
|
25
|
+
stripUnknown: true,
|
|
26
|
+
noDefaults: false
|
|
27
|
+
});
|
|
28
|
+
runner.use(({ itx }, next) => {
|
|
29
|
+
const { error } = schema.validate(itx);
|
|
30
|
+
return next(error ? new _ocap_util_lib_error.CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
|
|
31
|
+
});
|
|
32
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
33
|
+
from: "itx.rollup",
|
|
34
|
+
to: "rollupState",
|
|
35
|
+
status: "INVALID_ROLLUP",
|
|
36
|
+
table: "rollup"
|
|
37
|
+
}));
|
|
38
|
+
runner.use(require_protocols_rollup_pipes_ensure_validator.default(true));
|
|
39
|
+
runner.use(require_protocols_rollup_pipes_verify_status.default({
|
|
40
|
+
paused: true,
|
|
41
|
+
closed: false
|
|
42
|
+
}));
|
|
43
|
+
runner.use(require_protocols_rollup_pipes_verify_signers.default({
|
|
44
|
+
signersKey: "tx.signaturesList",
|
|
45
|
+
allowSender: true
|
|
46
|
+
}));
|
|
47
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyMultiSigV2({ signersKey: "signers" }));
|
|
48
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
49
|
+
from: "tx.from",
|
|
50
|
+
to: "senderState",
|
|
51
|
+
status: "INVALID_SENDER_STATE",
|
|
52
|
+
table: "account"
|
|
53
|
+
}));
|
|
54
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
55
|
+
from: "signers",
|
|
56
|
+
to: "signerStates",
|
|
57
|
+
status: "INVALID_SIGNER_STATE",
|
|
58
|
+
table: "account"
|
|
59
|
+
}));
|
|
60
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
61
|
+
signerKey: "signerStates",
|
|
62
|
+
stateKey: "senderState",
|
|
63
|
+
addressKey: "tx.from"
|
|
64
|
+
}));
|
|
65
|
+
runner.use((context, next) => {
|
|
66
|
+
const { validators, address } = context.rollupState;
|
|
67
|
+
context.stakeAddresses = validators.map((x) => (0, _arcblock_did_util.toStakeAddress)(x.address, address));
|
|
68
|
+
return next();
|
|
69
|
+
});
|
|
70
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
71
|
+
from: "stakeAddresses",
|
|
72
|
+
to: "stakeStates",
|
|
73
|
+
status: "INVALID_STAKE_STATE",
|
|
74
|
+
table: "stake"
|
|
75
|
+
}));
|
|
76
|
+
runner.use(require_pipes_ensure_gas.default((context) => ({
|
|
77
|
+
create: 0,
|
|
78
|
+
update: (context.stakeStates || []).length + 2,
|
|
79
|
+
payment: 0
|
|
80
|
+
})));
|
|
81
|
+
runner.use(require_pipes_ensure_cost.default({ attachSenderChanges: true }));
|
|
82
|
+
runner.use(_ocap_tx_pipeline.pipes.TakeStateSnapshot());
|
|
83
|
+
runner.use(async (context, next) => {
|
|
84
|
+
const { tx, itx, statedb, senderUpdates, updateVaults, rollupState, senderState } = context;
|
|
85
|
+
const stakeStates = context.stakeStates || [];
|
|
86
|
+
const [newSenderState, newRollupState, newStakeStates] = await Promise.all([
|
|
87
|
+
statedb.account.update(senderState.address, _ocap_state.account.update(senderState, {
|
|
88
|
+
nonce: tx.nonce,
|
|
89
|
+
...senderUpdates
|
|
90
|
+
}, context), context),
|
|
91
|
+
statedb.rollup.update(itx.rollup, _ocap_state.rollup.close(rollupState, context), context),
|
|
92
|
+
Promise.all(stakeStates.map((x) => statedb.stake.update(x.address, _ocap_state.stake.update(x, {
|
|
93
|
+
revocable: true,
|
|
94
|
+
revokeWaitingPeriod: rollupState.leaveWaitingPeriod
|
|
95
|
+
}, context), context)))
|
|
96
|
+
]);
|
|
97
|
+
if (updateVaults) await updateVaults();
|
|
98
|
+
context.senderState = newSenderState;
|
|
99
|
+
context.rollupState = newRollupState;
|
|
100
|
+
context.stakeStates = newStakeStates;
|
|
101
|
+
next();
|
|
102
|
+
}, { persistError: true });
|
|
103
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyStateDiff());
|
|
104
|
+
var close_default = runner;
|
|
105
|
+
|
|
106
|
+
//#endregion
|
|
107
|
+
exports.default = close_default;
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
3
|
+
const require_util = require('../../util.cjs');
|
|
4
|
+
const require_pipes_ensure_cost = require('../../pipes/ensure-cost.cjs');
|
|
5
|
+
const require_pipes_ensure_gas = require('../../pipes/ensure-gas.cjs');
|
|
6
|
+
const require_protocols_rollup_pipes_ensure_validator = require('./pipes/ensure-validator.cjs');
|
|
7
|
+
const require_protocols_rollup_pipes_verify_signers = require('./pipes/verify-signers.cjs');
|
|
8
|
+
const require_protocols_rollup_pipes_verify_status = require('./pipes/verify-status.cjs');
|
|
9
|
+
const require_protocols_rollup_pipes_verify_evidence = require('./pipes/verify-evidence.cjs');
|
|
10
|
+
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
11
|
+
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
12
|
+
let lodash_pick = require("lodash/pick");
|
|
13
|
+
lodash_pick = require_rolldown_runtime.__toESM(lodash_pick);
|
|
14
|
+
let _arcblock_did_util = require("@arcblock/did-util");
|
|
15
|
+
let _ocap_state = require("@ocap/state");
|
|
16
|
+
let debug = require("debug");
|
|
17
|
+
debug = require_rolldown_runtime.__toESM(debug);
|
|
18
|
+
let _ocap_message = require("@ocap/message");
|
|
19
|
+
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
20
|
+
let lodash_cloneDeep = require("lodash/cloneDeep");
|
|
21
|
+
lodash_cloneDeep = require_rolldown_runtime.__toESM(lodash_cloneDeep);
|
|
22
|
+
let _arcblock_validator = require("@arcblock/validator");
|
|
23
|
+
let _ocap_merkle_tree = require("@ocap/merkle-tree");
|
|
24
|
+
_ocap_merkle_tree = require_rolldown_runtime.__toESM(_ocap_merkle_tree);
|
|
25
|
+
|
|
26
|
+
//#region src/protocols/rollup/create-block.ts
|
|
27
|
+
const debug$1 = (0, debug.default)("@ocap/tx-protocols:create-rollup-block");
|
|
28
|
+
const runner = new _ocap_tx_pipeline.Runner("create_rollup_block");
|
|
29
|
+
const schema = _arcblock_validator.Joi.object({
|
|
30
|
+
hash: _arcblock_validator.Joi.string().regex(_arcblock_validator.patterns.txHash).required(),
|
|
31
|
+
height: _arcblock_validator.Joi.number().integer().greater(0).required(),
|
|
32
|
+
merkleRoot: _arcblock_validator.Joi.string().regex(_arcblock_validator.patterns.txHash).required(),
|
|
33
|
+
previousHash: _arcblock_validator.Joi.string().when("height", {
|
|
34
|
+
is: 1,
|
|
35
|
+
then: _arcblock_validator.Joi.string().optional().allow(null).allow(""),
|
|
36
|
+
otherwise: _arcblock_validator.Joi.string().regex(_arcblock_validator.patterns.txHash).required()
|
|
37
|
+
}),
|
|
38
|
+
txsHash: _arcblock_validator.Joi.string().regex(_arcblock_validator.patterns.txHash).required(),
|
|
39
|
+
txsList: _arcblock_validator.Joi.array().items(_arcblock_validator.Joi.string().regex(_arcblock_validator.patterns.txHash).required()).min(1).unique().required(),
|
|
40
|
+
proposer: _arcblock_validator.Joi.DID().prefix().wallet("ethereum").required(),
|
|
41
|
+
signaturesList: _arcblock_validator.schemas.multiSig.min(1).required(),
|
|
42
|
+
rollup: _arcblock_validator.Joi.DID().prefix().role("ROLE_ROLLUP").required(),
|
|
43
|
+
minReward: _arcblock_validator.Joi.BN().min(0).required(),
|
|
44
|
+
governance: _arcblock_validator.Joi.boolean().default(false),
|
|
45
|
+
data: _arcblock_validator.Joi.any().optional().allow(null)
|
|
46
|
+
}).options({
|
|
47
|
+
stripUnknown: true,
|
|
48
|
+
noDefaults: false
|
|
49
|
+
});
|
|
50
|
+
runner.use((context, next) => {
|
|
51
|
+
const { tx, itx } = context;
|
|
52
|
+
context.formattedItx = (0, _ocap_message.formatMessage)("CreateRollupBlockTx", itx);
|
|
53
|
+
const { error } = schema.validate(itx);
|
|
54
|
+
if (error) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", error.message));
|
|
55
|
+
if (tx.from !== itx.proposer) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "itx.proposer must be same with tx.from"));
|
|
56
|
+
if ((0, _ocap_util_lib_get_list_field.getListField)(tx, "signatures").some((x) => x.signer === itx.proposer) === false) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "itx.proposer must exist in signatures"));
|
|
57
|
+
const txsList = (0, _ocap_util_lib_get_list_field.getListField)(itx, "txs");
|
|
58
|
+
if (_ocap_merkle_tree.default.getListHash(txsList) !== itx.txsHash) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "itx.txsHash does not match with itx.txs"));
|
|
59
|
+
if (_ocap_merkle_tree.default.getBlockHash({
|
|
60
|
+
...(0, lodash_pick.default)(itx, [
|
|
61
|
+
"height",
|
|
62
|
+
"merkleRoot",
|
|
63
|
+
"txsHash"
|
|
64
|
+
]),
|
|
65
|
+
previousHash: itx.height === 1 ? "" : itx.previousHash
|
|
66
|
+
}) !== itx.hash) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "itx.hash invalid"));
|
|
67
|
+
return next();
|
|
68
|
+
});
|
|
69
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
70
|
+
from: "itx.rollup",
|
|
71
|
+
to: "rollupState",
|
|
72
|
+
status: "INVALID_ROLLUP",
|
|
73
|
+
table: "rollup"
|
|
74
|
+
}));
|
|
75
|
+
runner.use(require_protocols_rollup_pipes_ensure_validator.default(false));
|
|
76
|
+
runner.use(require_protocols_rollup_pipes_verify_status.default({ closed: false }));
|
|
77
|
+
runner.use((context, next) => {
|
|
78
|
+
const { itx, rollupState } = context;
|
|
79
|
+
if (itx.height !== (rollupState?.blockHeight || 0) + 1) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Expect new block height to be ${(rollupState?.blockHeight || 0) + 1}, got ${itx.height}`));
|
|
80
|
+
const itxTxsList = (0, _ocap_util_lib_get_list_field.getListField)(itx, "txs");
|
|
81
|
+
if (itx.governance) {
|
|
82
|
+
if (itx.minReward !== "0") return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "itx.minReward should be 0 for governance block"));
|
|
83
|
+
if (itxTxsList.length !== 1) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "itx.txs should contain only 1 tx for governance block"));
|
|
84
|
+
} else {
|
|
85
|
+
if (rollupState?.paused) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "Normal block is only allowed when rollup is not paused"));
|
|
86
|
+
const blockSize = itxTxsList.length;
|
|
87
|
+
if (blockSize < (rollupState?.minBlockSize || 0)) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Expect at least ${rollupState?.minBlockSize || 0} tx in the block, got ${blockSize}`));
|
|
88
|
+
if (blockSize > (rollupState?.maxBlockSize || 0)) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Expect at most ${rollupState?.maxBlockSize || 0} tx in the block, got ${blockSize}`));
|
|
89
|
+
}
|
|
90
|
+
return next();
|
|
91
|
+
});
|
|
92
|
+
runner.use(require_protocols_rollup_pipes_verify_signers.default({
|
|
93
|
+
signersKey: "itx.signaturesList",
|
|
94
|
+
allowSender: true
|
|
95
|
+
}));
|
|
96
|
+
runner.use(require_protocols_rollup_pipes_verify_evidence.default({
|
|
97
|
+
evidenceKey: "itx.hash",
|
|
98
|
+
signaturesKey: "itx.signaturesList",
|
|
99
|
+
verifyMethod: "ethVerify"
|
|
100
|
+
}));
|
|
101
|
+
runner.use(require_protocols_rollup_pipes_verify_signers.default({
|
|
102
|
+
signersKey: "tx.signaturesList",
|
|
103
|
+
allowSender: true
|
|
104
|
+
}));
|
|
105
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyMultiSigV2({ signersKey: "signers" }));
|
|
106
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
107
|
+
from: "tx.from",
|
|
108
|
+
to: "senderState",
|
|
109
|
+
status: "INVALID_SENDER_STATE",
|
|
110
|
+
table: "account"
|
|
111
|
+
}));
|
|
112
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
113
|
+
from: "signers",
|
|
114
|
+
to: "signerStates",
|
|
115
|
+
status: "INVALID_SIGNER_STATE",
|
|
116
|
+
table: "account"
|
|
117
|
+
}));
|
|
118
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
119
|
+
signerKey: "signerStates",
|
|
120
|
+
stateKey: "senderState",
|
|
121
|
+
addressKey: "tx.from"
|
|
122
|
+
}));
|
|
123
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
124
|
+
from: "itx.previousHash",
|
|
125
|
+
to: "previousBlock",
|
|
126
|
+
status: "OK",
|
|
127
|
+
table: "rollupBlock"
|
|
128
|
+
}));
|
|
129
|
+
runner.use((context, next) => {
|
|
130
|
+
const { txTime, itx, previousBlock, rollupState } = context;
|
|
131
|
+
if (itx.height > 1) {
|
|
132
|
+
if (!previousBlock) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Rollup block with height ${itx.height} does not exist`));
|
|
133
|
+
if (itx.height !== previousBlock.height + 1) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Unexpected previous block height, expected ${itx.height - 1}, got ${previousBlock.height}`));
|
|
134
|
+
if (itx.governance === false) {
|
|
135
|
+
const minBlockTime = +new Date(previousBlock.context.genesisTime) + (rollupState?.minBlockInterval || 0) * 1e3;
|
|
136
|
+
if (+new Date(txTime) < minBlockTime) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Block does not comply with minBlockInterval: ${new Date(minBlockTime).toISOString()}`));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return next();
|
|
140
|
+
});
|
|
141
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
142
|
+
from: "itx.hash",
|
|
143
|
+
to: "newBlock",
|
|
144
|
+
status: "OK",
|
|
145
|
+
table: "rollupBlock"
|
|
146
|
+
}));
|
|
147
|
+
runner.use((context, next) => {
|
|
148
|
+
if (context.newBlock) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Rollup block with height ${context.itx.height} already exists`));
|
|
149
|
+
return next();
|
|
150
|
+
});
|
|
151
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
152
|
+
from: "rollupState.tokenAddress",
|
|
153
|
+
to: "tokenState",
|
|
154
|
+
status: "INVALID_TOKEN",
|
|
155
|
+
table: "token"
|
|
156
|
+
}));
|
|
157
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
158
|
+
from: "itx.txsList",
|
|
159
|
+
to: "txStates",
|
|
160
|
+
status: "INVALID_TX",
|
|
161
|
+
table: "tx"
|
|
162
|
+
}));
|
|
163
|
+
runner.use(({ itx, txStates }, next) => {
|
|
164
|
+
const normalTxTypes = ["deposit_token_v2", "withdraw_token_v2"];
|
|
165
|
+
const governanceTxTypes = [
|
|
166
|
+
"pause_rollup",
|
|
167
|
+
"resume_rollup",
|
|
168
|
+
"migrate_rollup"
|
|
169
|
+
];
|
|
170
|
+
const txList = txStates || [];
|
|
171
|
+
if (txList.some((x) => x.finalized)) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "Should not include finalized tx in later block"));
|
|
172
|
+
if (txList.some((x) => x.code !== "OK")) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "Rollup block can only include successful executed transactions"));
|
|
173
|
+
if (itx.governance) {
|
|
174
|
+
if (txList.some((x) => governanceTxTypes.includes(x.type) === false)) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Governance block can only include governance txs: ${governanceTxTypes.join(",")}`));
|
|
175
|
+
} else if (txList.some((x) => normalTxTypes.includes(x.type) === false)) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Rollup block can only include normal txs: ${normalTxTypes.join(",")}`));
|
|
176
|
+
if (txList.some((x) => {
|
|
177
|
+
return (x.tx?.itxJson)?.rollup !== itx.rollup;
|
|
178
|
+
})) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Rollup block can only include tx from rollup ${itx.rollup}`));
|
|
179
|
+
if (_ocap_merkle_tree.default.getBlockMerkleTree(txList.map((x) => {
|
|
180
|
+
const txItxJson = x.tx?.itxJson;
|
|
181
|
+
if (x.type === "withdraw_token_v2") return {
|
|
182
|
+
hash: x.hash,
|
|
183
|
+
to: txItxJson?.to,
|
|
184
|
+
amount: txItxJson?.token?.value
|
|
185
|
+
};
|
|
186
|
+
if (x.type === "pause_rollup") return {
|
|
187
|
+
hash: x.hash,
|
|
188
|
+
to: _ocap_merkle_tree.default.BLACK_HOLE,
|
|
189
|
+
amount: "0"
|
|
190
|
+
};
|
|
191
|
+
if (x.type === "resume_rollup") return {
|
|
192
|
+
hash: x.hash,
|
|
193
|
+
to: _ocap_merkle_tree.default.BLACK_HOLE,
|
|
194
|
+
amount: "0"
|
|
195
|
+
};
|
|
196
|
+
if (x.type === "migrate_rollup") return {
|
|
197
|
+
hash: x.hash,
|
|
198
|
+
to: txItxJson?.to,
|
|
199
|
+
amount: "0"
|
|
200
|
+
};
|
|
201
|
+
return null;
|
|
202
|
+
}).filter(Boolean)).getHexRoot() !== itx.merkleRoot) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "Invalid rollup block merkle root"));
|
|
203
|
+
return next();
|
|
204
|
+
});
|
|
205
|
+
runner.use((context, next) => {
|
|
206
|
+
const { itx, txStates } = context;
|
|
207
|
+
const txList = txStates || [];
|
|
208
|
+
const depositProposerStakeAddr = txList.filter((x) => x.type === "deposit_token_v2").map((x) => {
|
|
209
|
+
const txItxJson = x.tx?.itxJson;
|
|
210
|
+
return (0, _arcblock_did_util.toStakeAddress)(txItxJson.proposer, itx.rollup);
|
|
211
|
+
});
|
|
212
|
+
const withdrawLockerStakeAddr = txList.filter((x) => x.type === "withdraw_token_v2").map((x) => (0, _arcblock_did_util.toStakeAddress)(x.tx.from, itx.rollup));
|
|
213
|
+
context.stakeAddresses = [
|
|
214
|
+
...depositProposerStakeAddr,
|
|
215
|
+
...withdrawLockerStakeAddr,
|
|
216
|
+
require_util.getRewardLocker(itx.rollup)
|
|
217
|
+
];
|
|
218
|
+
return next();
|
|
219
|
+
});
|
|
220
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
221
|
+
from: "stakeAddresses",
|
|
222
|
+
to: "stakeStates",
|
|
223
|
+
status: "INVALID_STAKE_STATE",
|
|
224
|
+
table: "stake"
|
|
225
|
+
}));
|
|
226
|
+
runner.use((context, next) => {
|
|
227
|
+
const { itx, txStates, rollupState } = context;
|
|
228
|
+
try {
|
|
229
|
+
const txStatesForReward = txStates || [];
|
|
230
|
+
const result = require_util.ensureBlockReward(rollupState, itx.minReward, txStatesForReward);
|
|
231
|
+
context.senders = Object.keys(result.accountUpdates);
|
|
232
|
+
Object.assign(context, result);
|
|
233
|
+
return next();
|
|
234
|
+
} catch (err) {
|
|
235
|
+
return next(err);
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
239
|
+
from: "senders",
|
|
240
|
+
to: "senderStates",
|
|
241
|
+
status: "INVALID_SENDER_STATE",
|
|
242
|
+
table: "account"
|
|
243
|
+
}));
|
|
244
|
+
runner.use(require_pipes_ensure_gas.default((context) => {
|
|
245
|
+
const result = {
|
|
246
|
+
create: 1,
|
|
247
|
+
update: 2,
|
|
248
|
+
payment: 0
|
|
249
|
+
};
|
|
250
|
+
result.update += (context.stakeStates || []).filter((x) => context.stakeUpdates?.[x.address]).length;
|
|
251
|
+
result.update += (context.txStates || []).length;
|
|
252
|
+
result.update += (context.senderStates || []).length;
|
|
253
|
+
return result;
|
|
254
|
+
}));
|
|
255
|
+
runner.use(require_pipes_ensure_cost.default({ attachSenderChanges: true }));
|
|
256
|
+
runner.use(_ocap_tx_pipeline.pipes.TakeStateSnapshot());
|
|
257
|
+
runner.use(async (context, next) => {
|
|
258
|
+
const { tx, itx, statedb, rollupState, senderState, stakeStates, txStates, formattedItx, senderUpdates, updateVaults } = context;
|
|
259
|
+
const senderStatesList = context.senderStates || [];
|
|
260
|
+
const stakeStatesList = stakeStates || [];
|
|
261
|
+
const txStatesList = txStates || [];
|
|
262
|
+
const stakeUpdatesMap = context.stakeUpdates || {};
|
|
263
|
+
const accountUpdatesMap = context.accountUpdates || {};
|
|
264
|
+
const [newSenderState, newStakeStates, newSenderStates, newRollupState, rollupBlockState, newTxStates] = await Promise.all([
|
|
265
|
+
statedb.account.update(senderState.address, _ocap_state.account.update(senderState, {
|
|
266
|
+
nonce: tx.nonce,
|
|
267
|
+
...senderUpdates
|
|
268
|
+
}, context), context),
|
|
269
|
+
Promise.all(stakeStatesList.map((x) => stakeUpdatesMap[x.address] ? statedb.stake.update(x.address, _ocap_state.stake.update(x, require_util.applyTokenChange(x, stakeUpdatesMap[x.address]), context), context) : Promise.resolve(x))),
|
|
270
|
+
Promise.all(senderStatesList.map((x) => statedb.account.update(x.address, _ocap_state.account.update(x, require_util.applyTokenChange(x, accountUpdatesMap[x.address]), context), context))),
|
|
271
|
+
statedb.rollup.update(rollupState.address, _ocap_state.rollup.update(rollupState, {
|
|
272
|
+
blockHeight: itx.height,
|
|
273
|
+
blockHash: itx.hash
|
|
274
|
+
}, context), context),
|
|
275
|
+
statedb.rollupBlock.create(itx.hash, _ocap_state.rollupBlock.create({
|
|
276
|
+
...formattedItx,
|
|
277
|
+
...[
|
|
278
|
+
"rewardAmount",
|
|
279
|
+
"mintedAmount",
|
|
280
|
+
"burnedAmount"
|
|
281
|
+
].reduce((acc, x) => {
|
|
282
|
+
const val = context[x];
|
|
283
|
+
acc[x] = val ? val.toString(10) : "0";
|
|
284
|
+
return acc;
|
|
285
|
+
}, {})
|
|
286
|
+
}, context), context),
|
|
287
|
+
Promise.all(txStatesList.map((x) => statedb.tx.update(x.hash, _ocap_state.tx.update(x, { finalized: true }), context)))
|
|
288
|
+
]);
|
|
289
|
+
if (updateVaults) await updateVaults();
|
|
290
|
+
context.senderState = newSenderState;
|
|
291
|
+
context.stakeStates = newStakeStates.filter((x) => stakeUpdatesMap[x.address]);
|
|
292
|
+
context.newSenderStates = newSenderStates;
|
|
293
|
+
context.rollupState = newRollupState;
|
|
294
|
+
context.createdRollupBlock = rollupBlockState;
|
|
295
|
+
context.txStates = newTxStates;
|
|
296
|
+
context.updatedAccounts = context.updatedAccounts || [];
|
|
297
|
+
context.updatedAccounts.push(...(0, lodash_cloneDeep.default)(Object.values(stakeUpdatesMap)));
|
|
298
|
+
context.updatedAccounts.push(...(0, lodash_cloneDeep.default)(Object.values(accountUpdatesMap)));
|
|
299
|
+
debug$1("create-rollup-block", {
|
|
300
|
+
itx,
|
|
301
|
+
updatedAccounts: context.updatedAccounts
|
|
302
|
+
});
|
|
303
|
+
next();
|
|
304
|
+
}, { persistError: true });
|
|
305
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyStateDiff());
|
|
306
|
+
var create_block_default = runner;
|
|
307
|
+
|
|
308
|
+
//#endregion
|
|
309
|
+
exports.default = create_block_default;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/protocols/rollup/create-block.d.ts
|
|
2
|
+
/** Token change for updates */
|
|
3
|
+
interface TokenChange {
|
|
4
|
+
address: string;
|
|
5
|
+
token: string;
|
|
6
|
+
delta: string;
|
|
7
|
+
action?: string;
|
|
8
|
+
}
|
|
9
|
+
declare const runner: any;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { TokenChange, runner as default };
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
3
|
+
const require_util = require('../../util.cjs');
|
|
4
|
+
const require_pipes_ensure_cost = require('../../pipes/ensure-cost.cjs');
|
|
5
|
+
const require_pipes_ensure_gas = require('../../pipes/ensure-gas.cjs');
|
|
6
|
+
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
7
|
+
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
8
|
+
let _arcblock_did = require("@arcblock/did");
|
|
9
|
+
let _arcblock_did_util = require("@arcblock/did-util");
|
|
10
|
+
let _ocap_state = require("@ocap/state");
|
|
11
|
+
let debug = require("debug");
|
|
12
|
+
debug = require_rolldown_runtime.__toESM(debug);
|
|
13
|
+
let _ocap_message = require("@ocap/message");
|
|
14
|
+
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
15
|
+
let lodash_cloneDeep = require("lodash/cloneDeep");
|
|
16
|
+
lodash_cloneDeep = require_rolldown_runtime.__toESM(lodash_cloneDeep);
|
|
17
|
+
let lodash_isEmpty = require("lodash/isEmpty");
|
|
18
|
+
lodash_isEmpty = require_rolldown_runtime.__toESM(lodash_isEmpty);
|
|
19
|
+
|
|
20
|
+
//#region src/protocols/rollup/create.ts
|
|
21
|
+
const debug$1 = (0, debug.default)("@ocap/tx-protocols:create-rollup");
|
|
22
|
+
const runner = new _ocap_tx_pipeline.Runner("create_rollup");
|
|
23
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyMultiSig(0));
|
|
24
|
+
runner.use((context, next) => {
|
|
25
|
+
const { itx } = context;
|
|
26
|
+
context.formattedItx = (0, _ocap_message.formatMessage)("CreateRollupTx", itx);
|
|
27
|
+
try {
|
|
28
|
+
_ocap_state.rollup.create(context.formattedItx, context);
|
|
29
|
+
} catch (err) {
|
|
30
|
+
return next(new _ocap_util_lib_error.CustomError("INVALID_TX", err.message));
|
|
31
|
+
}
|
|
32
|
+
return next();
|
|
33
|
+
});
|
|
34
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyInfo([
|
|
35
|
+
{
|
|
36
|
+
error: "INVALID_TX",
|
|
37
|
+
message: "Sum of itx.proposerFeeShare and itx.publisherFeeShare must be less than 10000",
|
|
38
|
+
fn: (ctx) => {
|
|
39
|
+
const context = ctx;
|
|
40
|
+
return context.itx.proposerFeeShare + context.itx.publisherFeeShare < 1e4;
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
error: "INVALID_TX",
|
|
45
|
+
message: "Seed validator pk and address not match",
|
|
46
|
+
fn: (ctx) => {
|
|
47
|
+
return (ctx.formattedItx?.seedValidators || []).every(({ pk, address }) => (0, _arcblock_did.isFromPublicKey)(address, pk));
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
error: "INVALID_TX",
|
|
52
|
+
message: "Seed validator must use ethereum compatible address",
|
|
53
|
+
fn: (ctx) => {
|
|
54
|
+
return (ctx.formattedItx?.seedValidators || []).every(({ address }) => (0, _arcblock_did.isEthereumDid)(address));
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
error: "INVALID_TX",
|
|
59
|
+
message: "Rollup address is not valid",
|
|
60
|
+
fn: (ctx) => {
|
|
61
|
+
const context = ctx;
|
|
62
|
+
const itx = (0, lodash_cloneDeep.default)(context.itx);
|
|
63
|
+
itx.data = require_util.decodeAnySafe(itx.data);
|
|
64
|
+
itx.address = "";
|
|
65
|
+
context.rollupData = itx.data;
|
|
66
|
+
context.seedValidators = (0, _ocap_util_lib_get_list_field.getListField)(itx, "seedValidators").map((x) => x.address);
|
|
67
|
+
return (0, _arcblock_did_util.toRollupAddress)(itx) === context.itx.address;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
]));
|
|
71
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
72
|
+
from: "tx.from",
|
|
73
|
+
to: "senderState",
|
|
74
|
+
status: "INVALID_SENDER_STATE",
|
|
75
|
+
table: "account"
|
|
76
|
+
}));
|
|
77
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
78
|
+
from: "seedValidators",
|
|
79
|
+
to: "validatorStates",
|
|
80
|
+
status: "INVALID_VALIDATOR_STATE",
|
|
81
|
+
table: "account"
|
|
82
|
+
}));
|
|
83
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
84
|
+
signerKey: "validatorStates",
|
|
85
|
+
stateKey: "senderState",
|
|
86
|
+
addressKey: "tx.from"
|
|
87
|
+
}));
|
|
88
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
89
|
+
from: "tx.delegator",
|
|
90
|
+
to: "delegatorState",
|
|
91
|
+
status: "OK",
|
|
92
|
+
table: "account"
|
|
93
|
+
}));
|
|
94
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
95
|
+
stateKey: "delegatorState",
|
|
96
|
+
addressKey: "tx.delegator"
|
|
97
|
+
}));
|
|
98
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyDelegation({
|
|
99
|
+
type: "signature",
|
|
100
|
+
signerKey: "senderState",
|
|
101
|
+
delegatorKey: "delegatorState",
|
|
102
|
+
getRequirements: require_util.getDelegationRequirements
|
|
103
|
+
}));
|
|
104
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
105
|
+
from: "itx.tokenAddress",
|
|
106
|
+
to: "tokenState",
|
|
107
|
+
status: "INVALID_TOKEN",
|
|
108
|
+
table: "token"
|
|
109
|
+
}));
|
|
110
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyInfo([{
|
|
111
|
+
error: "INVALID_TOKEN",
|
|
112
|
+
message: "Token does not have foreignToken attached",
|
|
113
|
+
fn: (ctx) => {
|
|
114
|
+
return (0, lodash_isEmpty.default)(ctx.tokenState?.foreignToken) === false;
|
|
115
|
+
}
|
|
116
|
+
}]));
|
|
117
|
+
runner.use(async (context, next) => {
|
|
118
|
+
const { statedb, itx } = context;
|
|
119
|
+
if (await statedb.rollup.existByToken(itx.tokenAddress, context)) return next(new _ocap_util_lib_error.CustomError("DUPLICATE_ROLLUP", "Only 1 active rollup can be created for the token"));
|
|
120
|
+
return next();
|
|
121
|
+
});
|
|
122
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
123
|
+
from: "itx.address",
|
|
124
|
+
to: "rollupState",
|
|
125
|
+
status: "OK",
|
|
126
|
+
table: "rollup"
|
|
127
|
+
}));
|
|
128
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyInfo([{
|
|
129
|
+
error: "DUPLICATE_ROLLUP",
|
|
130
|
+
message: "This rollup already exist on chain",
|
|
131
|
+
fn: (ctx) => {
|
|
132
|
+
return (0, lodash_isEmpty.default)(ctx.rollupState);
|
|
133
|
+
}
|
|
134
|
+
}]));
|
|
135
|
+
runner.use(require_pipes_ensure_gas.default(() => ({
|
|
136
|
+
create: 1,
|
|
137
|
+
update: 2,
|
|
138
|
+
payment: 0
|
|
139
|
+
})));
|
|
140
|
+
runner.use(require_pipes_ensure_cost.default({ attachSenderChanges: true }));
|
|
141
|
+
runner.use(_ocap_tx_pipeline.pipes.TakeStateSnapshot());
|
|
142
|
+
runner.use(async (context, next) => {
|
|
143
|
+
const { tx, formattedItx, rollupData, statedb, senderState, delegatorState, delegationState, senderUpdates, updateVaults } = context;
|
|
144
|
+
const issuer = delegatorState ? delegatorState.address : senderState.address;
|
|
145
|
+
const [newSenderState, newRollupState, newDelegationState] = await Promise.all([
|
|
146
|
+
statedb.account.update(senderState.address, _ocap_state.account.update(senderState, {
|
|
147
|
+
nonce: tx.nonce,
|
|
148
|
+
...senderUpdates
|
|
149
|
+
}, context), context),
|
|
150
|
+
statedb.rollup.create(formattedItx.address, _ocap_state.rollup.create({
|
|
151
|
+
...formattedItx,
|
|
152
|
+
issuer,
|
|
153
|
+
validators: formattedItx.seedValidators || [],
|
|
154
|
+
data: rollupData
|
|
155
|
+
}, context), context),
|
|
156
|
+
context.isDelegationChanged && delegationState ? statedb.delegation.update(delegationState.address, _ocap_state.delegation.update(delegationState, {}, context), context) : Promise.resolve(delegationState)
|
|
157
|
+
]);
|
|
158
|
+
if (updateVaults) await updateVaults();
|
|
159
|
+
context.senderState = newSenderState;
|
|
160
|
+
context.rollupState = newRollupState;
|
|
161
|
+
context.delegationState = newDelegationState;
|
|
162
|
+
debug$1("create-rollup", newRollupState);
|
|
163
|
+
next();
|
|
164
|
+
}, { persistError: true });
|
|
165
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyStateDiff());
|
|
166
|
+
var create_default = runner;
|
|
167
|
+
|
|
168
|
+
//#endregion
|
|
169
|
+
exports.default = create_default;
|