@ocap/tx-protocols 1.28.8 → 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,275 @@
|
|
|
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 lodash_pick = require("lodash/pick");
|
|
9
|
+
lodash_pick = require_rolldown_runtime.__toESM(lodash_pick);
|
|
10
|
+
let _arcblock_did_util = require("@arcblock/did-util");
|
|
11
|
+
let _ocap_state = require("@ocap/state");
|
|
12
|
+
let _ocap_util = require("@ocap/util");
|
|
13
|
+
let debug = require("debug");
|
|
14
|
+
debug = require_rolldown_runtime.__toESM(debug);
|
|
15
|
+
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
16
|
+
let _arcblock_validator = require("@arcblock/validator");
|
|
17
|
+
let node_util = require("node:util");
|
|
18
|
+
let lodash_isEmpty = require("lodash/isEmpty");
|
|
19
|
+
lodash_isEmpty = require_rolldown_runtime.__toESM(lodash_isEmpty);
|
|
20
|
+
|
|
21
|
+
//#region src/protocols/governance/stake.ts
|
|
22
|
+
const debug$1 = (0, debug.default)("@ocap/tx-protocols:stake");
|
|
23
|
+
const verifyAssetOwner = (0, node_util.promisify)(_ocap_tx_pipeline.pipes.VerifyUpdater({
|
|
24
|
+
assetKey: "assets",
|
|
25
|
+
ownerKey: "owner"
|
|
26
|
+
}));
|
|
27
|
+
const runner = new _ocap_tx_pipeline.Runner("stake");
|
|
28
|
+
const schema = _arcblock_validator.Joi.object({
|
|
29
|
+
address: _arcblock_validator.Joi.DID().prefix().role("ROLE_STAKE").required(),
|
|
30
|
+
receiver: _arcblock_validator.Joi.DID().prefix().required(),
|
|
31
|
+
slashersList: _arcblock_validator.Joi.array().items(_arcblock_validator.Joi.DID().prefix()).default([]),
|
|
32
|
+
locked: _arcblock_validator.Joi.boolean().default(false),
|
|
33
|
+
inputsList: _arcblock_validator.schemas.multiInput.min(1).required(),
|
|
34
|
+
message: _arcblock_validator.Joi.string().trim().min(1).max(256).required(),
|
|
35
|
+
revokeWaitingPeriod: _arcblock_validator.Joi.number().integer().min(0).default(0),
|
|
36
|
+
data: _arcblock_validator.Joi.any().optional().allow(null),
|
|
37
|
+
nonce: _arcblock_validator.Joi.string().trim().min(1).max(256).allow("").optional().allow(null)
|
|
38
|
+
}).options({
|
|
39
|
+
stripUnknown: true,
|
|
40
|
+
noDefaults: false
|
|
41
|
+
});
|
|
42
|
+
runner.use(({ itx }, next) => {
|
|
43
|
+
const { error } = schema.validate(itx);
|
|
44
|
+
return next(error ? new _ocap_util_lib_error.CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
|
|
45
|
+
});
|
|
46
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyTxInput({
|
|
47
|
+
fieldKey: "itx.inputs",
|
|
48
|
+
inputsKey: "inputs",
|
|
49
|
+
sendersKey: "senders",
|
|
50
|
+
tokensKey: "tokens",
|
|
51
|
+
assetsKey: "assets"
|
|
52
|
+
}));
|
|
53
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyInfo([
|
|
54
|
+
{
|
|
55
|
+
error: "INVALID_TX",
|
|
56
|
+
message: "Invalid staking address",
|
|
57
|
+
fn: (ctx) => {
|
|
58
|
+
const context = ctx;
|
|
59
|
+
return (0, _arcblock_did_util.toStakeAddress)(context.tx.from, context.itx.receiver, context.itx.nonce) === context.itx.address;
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
error: "INVALID_TX",
|
|
64
|
+
message: "Tx sender can not be slasher",
|
|
65
|
+
fn: (ctx) => {
|
|
66
|
+
const context = ctx;
|
|
67
|
+
const slashers = (0, _ocap_util_lib_get_list_field.getListField)(context.itx, "slashers");
|
|
68
|
+
return slashers.length === 0 || slashers.includes(context.tx.from) === false;
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
error: "INSUFFICIENT_DATA",
|
|
73
|
+
message: "Can not stake without any token or asset",
|
|
74
|
+
fn: (ctx) => {
|
|
75
|
+
const context = ctx;
|
|
76
|
+
return !((0, lodash_isEmpty.default)(context.tokens) && (0, lodash_isEmpty.default)(context.assets));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
]));
|
|
80
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyListSize({ listKey: [
|
|
81
|
+
"inputs",
|
|
82
|
+
"senders",
|
|
83
|
+
"tokens",
|
|
84
|
+
"assets"
|
|
85
|
+
] }));
|
|
86
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyMultiSigV2({ signersKey: "senders" }));
|
|
87
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
88
|
+
from: "itx.address",
|
|
89
|
+
to: "stakeState",
|
|
90
|
+
status: "OK",
|
|
91
|
+
table: "stake"
|
|
92
|
+
}));
|
|
93
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
94
|
+
from: "tx.from",
|
|
95
|
+
to: "senderState",
|
|
96
|
+
status: "OK",
|
|
97
|
+
table: "account"
|
|
98
|
+
}));
|
|
99
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
100
|
+
from: "senders",
|
|
101
|
+
to: "signerStates",
|
|
102
|
+
status: "INVALID_SIGNER_STATE",
|
|
103
|
+
table: "account"
|
|
104
|
+
}));
|
|
105
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
106
|
+
signerKey: "signerStates",
|
|
107
|
+
stateKey: "senderState",
|
|
108
|
+
addressKey: "tx.from"
|
|
109
|
+
}));
|
|
110
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
111
|
+
from: "itx.receiver",
|
|
112
|
+
to: "receiverState",
|
|
113
|
+
status: "INVALID_RECEIVER_STATE"
|
|
114
|
+
}));
|
|
115
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyBlocked({ stateKeys: ["signerStates", "receiverState"] }));
|
|
116
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
117
|
+
stateKey: "receiverState",
|
|
118
|
+
addressKey: "itx.receiver"
|
|
119
|
+
}));
|
|
120
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
121
|
+
from: "tokens",
|
|
122
|
+
to: "tokenStates",
|
|
123
|
+
status: "INVALID_TOKEN",
|
|
124
|
+
table: "token"
|
|
125
|
+
}));
|
|
126
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyTokenBalance({
|
|
127
|
+
ownerKey: "signerStates",
|
|
128
|
+
conditionKey: "inputs"
|
|
129
|
+
}));
|
|
130
|
+
runner.use(_ocap_tx_pipeline.pipes.verifyTokenAccess({
|
|
131
|
+
statesKey: "tokenStates",
|
|
132
|
+
listFieldKey: "spenders",
|
|
133
|
+
accountKeys: ["senderState"],
|
|
134
|
+
errorMessage: "Account {address} is not allowed to stake token {tokenAddress}"
|
|
135
|
+
}));
|
|
136
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
137
|
+
from: "assets",
|
|
138
|
+
to: "assetStates",
|
|
139
|
+
status: "OK",
|
|
140
|
+
table: "asset"
|
|
141
|
+
}));
|
|
142
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyTransferrable({ assets: "assetStates" }));
|
|
143
|
+
runner.use(async (context, next) => {
|
|
144
|
+
const { inputs = [], assetStates = [], signerStates = [] } = context;
|
|
145
|
+
for (const input of inputs) {
|
|
146
|
+
const { owner } = input;
|
|
147
|
+
const assetsList = (0, _ocap_util_lib_get_list_field.getListField)(input, "assets");
|
|
148
|
+
const states = assetStates.filter((x) => assetsList.includes(x.address));
|
|
149
|
+
const signer = signerStates.find((x) => x.address === owner);
|
|
150
|
+
try {
|
|
151
|
+
await verifyAssetOwner({
|
|
152
|
+
assets: states,
|
|
153
|
+
owner: signer
|
|
154
|
+
});
|
|
155
|
+
} catch (err) {
|
|
156
|
+
return next(err);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return next();
|
|
160
|
+
});
|
|
161
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
162
|
+
from: "itx.slashersList",
|
|
163
|
+
to: "slasherStates",
|
|
164
|
+
status: "INVALID_SLASHER_STATE",
|
|
165
|
+
table: "account"
|
|
166
|
+
}));
|
|
167
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
168
|
+
stateKey: "slasherStates",
|
|
169
|
+
addressKey: "itx.slashersList"
|
|
170
|
+
}));
|
|
171
|
+
runner.use((context, next) => {
|
|
172
|
+
const { tx, itx, inputs = [] } = context;
|
|
173
|
+
const { config } = context;
|
|
174
|
+
const { token, transaction } = config;
|
|
175
|
+
const { minStake, maxStake } = transaction.txGas;
|
|
176
|
+
context.isGasStake = require_util.isGasStakeAddress(tx.from, itx.address) && require_util.isGasStakeInput(inputs, token.address);
|
|
177
|
+
if (context.isGasStake) {
|
|
178
|
+
const [tokenInput] = (0, _ocap_util_lib_get_list_field.getListField)(inputs[0], "tokens");
|
|
179
|
+
const actualStake = new _ocap_util.BN(tokenInput.value);
|
|
180
|
+
const expectedMinStake = (0, _ocap_util.fromTokenToUnit)(minStake, token.decimal);
|
|
181
|
+
const expectedMaxStake = (0, _ocap_util.fromTokenToUnit)(maxStake, token.decimal);
|
|
182
|
+
if (actualStake.lt(expectedMinStake)) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Stake for gas should be greater than: ${minStake}`));
|
|
183
|
+
if (actualStake.gt(expectedMaxStake)) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Stake for gas should be less than: ${maxStake}`));
|
|
184
|
+
}
|
|
185
|
+
if (context.isGasStake) {
|
|
186
|
+
context.revokeWaitingPeriod = transaction.txGas.stakeLockPeriod;
|
|
187
|
+
context.slashers = [config.moderator.address];
|
|
188
|
+
} else {
|
|
189
|
+
context.revokeWaitingPeriod = itx.revokeWaitingPeriod;
|
|
190
|
+
context.slashers = (0, _ocap_util_lib_get_list_field.getListField)(itx, "slashers");
|
|
191
|
+
}
|
|
192
|
+
return next();
|
|
193
|
+
});
|
|
194
|
+
runner.use(require_pipes_ensure_gas.default((context) => {
|
|
195
|
+
const result = {
|
|
196
|
+
create: 0,
|
|
197
|
+
update: 0,
|
|
198
|
+
payment: 0
|
|
199
|
+
};
|
|
200
|
+
if ((context.senderState ? context.senderState.address : context.tx.from) === (context.receiverState ? context.receiverState.address : context.itx.receiver)) {
|
|
201
|
+
Object.defineProperty(context, "txBaseGas", { value: false });
|
|
202
|
+
return result;
|
|
203
|
+
}
|
|
204
|
+
if (context.senderState) result.update += 1;
|
|
205
|
+
else result.create += 1;
|
|
206
|
+
if (context.stakeState) result.update += 1;
|
|
207
|
+
else result.create += 1;
|
|
208
|
+
if (context.signerStates) result.update += context.signerStates.length;
|
|
209
|
+
if (context.assetStates) result.update += context.assetStates.length;
|
|
210
|
+
return result;
|
|
211
|
+
}));
|
|
212
|
+
runner.use(require_pipes_ensure_cost.default({ attachSenderChanges: true }));
|
|
213
|
+
runner.use(_ocap_tx_pipeline.pipes.TakeStateSnapshot());
|
|
214
|
+
runner.use(async (context, next) => {
|
|
215
|
+
const { tx, itx, inputs = [], statedb, senderState, senderChange, stakeState, signerStates = [], updateVaults, assetStates = [] } = context;
|
|
216
|
+
const signerUpdates = {};
|
|
217
|
+
const stakeUpdates = stakeState ? {
|
|
218
|
+
tokens: stakeState.tokens,
|
|
219
|
+
assets: stakeState.assets || [],
|
|
220
|
+
data: itx.data
|
|
221
|
+
} : {
|
|
222
|
+
tokens: {},
|
|
223
|
+
assets: [],
|
|
224
|
+
data: itx.data
|
|
225
|
+
};
|
|
226
|
+
inputs.forEach((x) => {
|
|
227
|
+
const { owner } = x;
|
|
228
|
+
const tokensList = (0, _ocap_util_lib_get_list_field.getListField)(x, "tokens");
|
|
229
|
+
const assetsList = (0, _ocap_util_lib_get_list_field.getListField)(x, "assets");
|
|
230
|
+
signerUpdates[owner] = require_util.applyTokenUpdates(tokensList, signerStates.find((s) => s.address === owner), "sub");
|
|
231
|
+
if (senderChange && owner === senderChange.address) signerUpdates[owner] = require_util.applyTokenChange(signerUpdates[owner], senderChange);
|
|
232
|
+
Object.assign(stakeUpdates, require_util.applyTokenUpdates(tokensList, stakeUpdates, "add"));
|
|
233
|
+
stakeUpdates.assets.push(...assetsList);
|
|
234
|
+
});
|
|
235
|
+
const isAlsoSigner = !!signerUpdates[tx.from];
|
|
236
|
+
const [newSenderState, newSignerStates, newStakeState, newAssetStates] = await Promise.all([
|
|
237
|
+
statedb.account.updateOrCreate(senderState ?? null, _ocap_state.account.updateOrCreate(senderState ?? null, Object.assign({
|
|
238
|
+
address: tx.from,
|
|
239
|
+
nonce: tx.nonce,
|
|
240
|
+
pk: tx.pk
|
|
241
|
+
}, signerUpdates[tx.from] || (senderChange ? require_util.applyTokenChange(senderState ?? {}, senderChange) : {})), context), context),
|
|
242
|
+
Promise.all(signerStates.filter((x) => x.address !== tx.from).map((x) => statedb.account.update(x.address, _ocap_state.account.update(x, signerUpdates[x.address], context), context))),
|
|
243
|
+
stakeState ? statedb.stake.update(stakeState.address, _ocap_state.stake.update(stakeState, stakeUpdates, context), context) : statedb.stake.create(itx.address, _ocap_state.stake.create({
|
|
244
|
+
sender: tx.from,
|
|
245
|
+
revocable: !itx.locked,
|
|
246
|
+
slashers: context.slashers,
|
|
247
|
+
revokeWaitingPeriod: context.revokeWaitingPeriod,
|
|
248
|
+
...(0, lodash_pick.default)(itx, [
|
|
249
|
+
"address",
|
|
250
|
+
"receiver",
|
|
251
|
+
"message",
|
|
252
|
+
"data",
|
|
253
|
+
"nonce"
|
|
254
|
+
]),
|
|
255
|
+
...stakeUpdates
|
|
256
|
+
}, context), context),
|
|
257
|
+
Promise.all(assetStates.map((x) => statedb.asset.update(x.address, _ocap_state.asset.update(x, { owner: itx.address }, context), context)))
|
|
258
|
+
]);
|
|
259
|
+
if (updateVaults) await updateVaults();
|
|
260
|
+
context.senderState = newSenderState;
|
|
261
|
+
context.signerStates = isAlsoSigner ? newSignerStates.concat(newSenderState) : newSignerStates;
|
|
262
|
+
context.stakeState = newStakeState;
|
|
263
|
+
context.assetStates = newAssetStates;
|
|
264
|
+
debug$1("stake", {
|
|
265
|
+
address: itx.address,
|
|
266
|
+
stakeUpdates,
|
|
267
|
+
signerUpdates
|
|
268
|
+
});
|
|
269
|
+
next();
|
|
270
|
+
}, { persistError: true });
|
|
271
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyStateDiff());
|
|
272
|
+
var stake_default = runner;
|
|
273
|
+
|
|
274
|
+
//#endregion
|
|
275
|
+
exports.default = stake_default;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/protocols/governance/stake.d.ts
|
|
2
|
+
/** Token input type */
|
|
3
|
+
interface TokenInput {
|
|
4
|
+
address: string;
|
|
5
|
+
value: string;
|
|
6
|
+
}
|
|
7
|
+
/** Multi-input type - uses List suffix in proto but runtime has both */
|
|
8
|
+
interface MultiInput {
|
|
9
|
+
owner: string;
|
|
10
|
+
tokensList?: TokenInput[];
|
|
11
|
+
assetsList?: string[];
|
|
12
|
+
}
|
|
13
|
+
declare const runner: any;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { MultiInput, TokenInput, runner as default };
|
|
@@ -0,0 +1,328 @@
|
|
|
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
|
+
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
10
|
+
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
11
|
+
let _arcblock_did_util = require("@arcblock/did-util");
|
|
12
|
+
let _ocap_state = require("@ocap/state");
|
|
13
|
+
let _ocap_util = require("@ocap/util");
|
|
14
|
+
let debug = require("debug");
|
|
15
|
+
debug = require_rolldown_runtime.__toESM(debug);
|
|
16
|
+
let lodash_cloneDeep = require("lodash/cloneDeep");
|
|
17
|
+
lodash_cloneDeep = require_rolldown_runtime.__toESM(lodash_cloneDeep);
|
|
18
|
+
let lodash_groupBy = require("lodash/groupBy");
|
|
19
|
+
lodash_groupBy = require_rolldown_runtime.__toESM(lodash_groupBy);
|
|
20
|
+
let _arcblock_validator = require("@arcblock/validator");
|
|
21
|
+
let lodash_uniqBy = require("lodash/uniqBy");
|
|
22
|
+
lodash_uniqBy = require_rolldown_runtime.__toESM(lodash_uniqBy);
|
|
23
|
+
|
|
24
|
+
//#region src/protocols/rollup/claim-reward.ts
|
|
25
|
+
const debug$1 = (0, debug.default)("@ocap/tx-protocols:claim-block-reward");
|
|
26
|
+
const runner = new _ocap_tx_pipeline.Runner("claim_block_reward");
|
|
27
|
+
const schema = _arcblock_validator.Joi.object({
|
|
28
|
+
rollup: _arcblock_validator.Joi.DID().prefix().role("ROLE_ROLLUP").required(),
|
|
29
|
+
blockHeight: _arcblock_validator.Joi.number().integer().greater(0).required(),
|
|
30
|
+
blockHash: _arcblock_validator.Joi.string().regex(_arcblock_validator.patterns.txHash).required(),
|
|
31
|
+
evidence: _arcblock_validator.Joi.object({ hash: _arcblock_validator.Joi.string().regex(_arcblock_validator.patterns.txHash).required() }).required(),
|
|
32
|
+
publisher: _arcblock_validator.Joi.DID().prefix().wallet("ethereum").required(),
|
|
33
|
+
data: _arcblock_validator.Joi.any().optional().allow(null)
|
|
34
|
+
}).options({
|
|
35
|
+
stripUnknown: true,
|
|
36
|
+
noDefaults: false
|
|
37
|
+
});
|
|
38
|
+
runner.use((context, next) => {
|
|
39
|
+
const { tx, itx } = context;
|
|
40
|
+
const { error } = schema.validate(itx);
|
|
41
|
+
if (error) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", error.message));
|
|
42
|
+
if (tx.from !== itx.publisher) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "itx.publisher must be same with tx.from"));
|
|
43
|
+
context.lockerAddress = require_util.getRewardLocker(itx.rollup);
|
|
44
|
+
return next();
|
|
45
|
+
});
|
|
46
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
47
|
+
from: "itx.evidence.hash",
|
|
48
|
+
to: "evidenceSeen",
|
|
49
|
+
status: "OK",
|
|
50
|
+
table: "evidence"
|
|
51
|
+
}));
|
|
52
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
53
|
+
from: "itx.blockHash",
|
|
54
|
+
to: "blockClaimed",
|
|
55
|
+
status: "OK",
|
|
56
|
+
table: "evidence"
|
|
57
|
+
}));
|
|
58
|
+
runner.use(({ evidenceSeen, blockClaimed }, next) => {
|
|
59
|
+
if (evidenceSeen) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "Claim evidence already seen on this chain"));
|
|
60
|
+
if (blockClaimed) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "Block reward already claimed before this tx"));
|
|
61
|
+
return next();
|
|
62
|
+
});
|
|
63
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
64
|
+
from: "itx.rollup",
|
|
65
|
+
to: "rollupState",
|
|
66
|
+
status: "INVALID_ROLLUP",
|
|
67
|
+
table: "rollup"
|
|
68
|
+
}));
|
|
69
|
+
runner.use(require_protocols_rollup_pipes_ensure_validator.default(false));
|
|
70
|
+
runner.use(require_protocols_rollup_pipes_verify_status.default({ closed: false }));
|
|
71
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
72
|
+
from: "itx.blockHash",
|
|
73
|
+
to: "blockState",
|
|
74
|
+
status: "INVALID_ROLLUP_BLOCK",
|
|
75
|
+
table: "rollupBlock"
|
|
76
|
+
}));
|
|
77
|
+
runner.use((context, next) => {
|
|
78
|
+
const { blockState, rollupState, itx } = context;
|
|
79
|
+
if (blockState.rollup !== rollupState.address) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "Rollup block belonging does not match"));
|
|
80
|
+
if (blockState.height !== itx.blockHeight) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "Rollup block height does not match"));
|
|
81
|
+
if (blockState.proposer !== itx.publisher) {
|
|
82
|
+
const proposedAt = +new Date(blockState.context.genesisTime);
|
|
83
|
+
const publishedAt = +new Date(context.txTime);
|
|
84
|
+
if (proposedAt + rollupState.publishWaitingPeriod * 1e3 > publishedAt) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "Rollup block can only be published by producer during waiting period"));
|
|
85
|
+
}
|
|
86
|
+
context.producerStakeAddress = (0, _arcblock_did_util.toStakeAddress)(blockState.proposer, itx.rollup);
|
|
87
|
+
return next();
|
|
88
|
+
});
|
|
89
|
+
runner.use(require_protocols_rollup_pipes_verify_signers.default({
|
|
90
|
+
signersKey: "tx.signaturesList",
|
|
91
|
+
allowSender: true
|
|
92
|
+
}));
|
|
93
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyMultiSigV2({ signersKey: "signers" }));
|
|
94
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
95
|
+
from: "lockerAddress",
|
|
96
|
+
to: "lockerState",
|
|
97
|
+
status: "INVALID_LOCKER_STATE",
|
|
98
|
+
table: "stake"
|
|
99
|
+
}));
|
|
100
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
101
|
+
from: "producerStakeAddress",
|
|
102
|
+
to: "stakeState",
|
|
103
|
+
status: "INVALID_STAKE_STATE",
|
|
104
|
+
table: "stake"
|
|
105
|
+
}));
|
|
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: "rollupState.tokenAddress",
|
|
125
|
+
to: "tokenState",
|
|
126
|
+
status: "INVALID_TOKEN",
|
|
127
|
+
table: "token"
|
|
128
|
+
}));
|
|
129
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
130
|
+
from: "blockState.txs",
|
|
131
|
+
to: "txs",
|
|
132
|
+
status: "INVALID_TX",
|
|
133
|
+
table: "tx"
|
|
134
|
+
}));
|
|
135
|
+
runner.use((context, next) => {
|
|
136
|
+
const { itx, txs, rollupState, blockState, lockerState, tokenState, stakeState } = context;
|
|
137
|
+
const { proposerFeeShare, publisherFeeShare } = rollupState;
|
|
138
|
+
const shares = {
|
|
139
|
+
publisher: publisherFeeShare,
|
|
140
|
+
proposer: proposerFeeShare,
|
|
141
|
+
validator: 1e4 - publisherFeeShare - proposerFeeShare
|
|
142
|
+
};
|
|
143
|
+
const changes = {
|
|
144
|
+
account: [],
|
|
145
|
+
stake: []
|
|
146
|
+
};
|
|
147
|
+
if (blockState.proposer !== itx.publisher) {
|
|
148
|
+
const slashAmount = new _ocap_util.BN(rollupState.minStakeAmount).mul(new _ocap_util.BN(rollupState.publishSlashRate)).div(require_util.RATE_BASE);
|
|
149
|
+
const slashShare = slashAmount.div(new _ocap_util.BN(2));
|
|
150
|
+
changes.stake.push({
|
|
151
|
+
address: stakeState.address,
|
|
152
|
+
delta: `-${slashAmount.toString(10)}`,
|
|
153
|
+
action: "slash"
|
|
154
|
+
});
|
|
155
|
+
changes.stake.push({
|
|
156
|
+
address: lockerState.address,
|
|
157
|
+
delta: slashShare.toString(10),
|
|
158
|
+
action: "slash"
|
|
159
|
+
});
|
|
160
|
+
changes.account.push({
|
|
161
|
+
address: itx.publisher,
|
|
162
|
+
delta: slashShare.toString(10),
|
|
163
|
+
action: "reward"
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
(txs || []).forEach((x) => {
|
|
167
|
+
const txData = x.tx;
|
|
168
|
+
const { actualFee } = txData.itxJson;
|
|
169
|
+
const { publisher, proposer, validator } = require_util.splitTxFee({
|
|
170
|
+
total: actualFee,
|
|
171
|
+
shares,
|
|
172
|
+
stringify: false
|
|
173
|
+
});
|
|
174
|
+
changes.stake.push({
|
|
175
|
+
address: lockerState.address,
|
|
176
|
+
delta: `-${actualFee}`,
|
|
177
|
+
action: "claim"
|
|
178
|
+
});
|
|
179
|
+
changes.account.push({
|
|
180
|
+
address: itx.publisher,
|
|
181
|
+
delta: publisher.toString(10),
|
|
182
|
+
action: "fee"
|
|
183
|
+
});
|
|
184
|
+
if (x.type === "deposit_token_v2") {
|
|
185
|
+
const txItxJson = txData.itxJson;
|
|
186
|
+
changes.account.push({
|
|
187
|
+
address: txItxJson.proposer,
|
|
188
|
+
delta: proposer.toString(10),
|
|
189
|
+
action: "fee"
|
|
190
|
+
});
|
|
191
|
+
const txSignatures = txData.signatures;
|
|
192
|
+
const blockSignatures = blockState.signatures;
|
|
193
|
+
const validators = txSignatures.map((s) => s.signer).concat(blockSignatures.map((s) => s.signer));
|
|
194
|
+
const validatorShare = validator.div(new _ocap_util.BN(validators.length));
|
|
195
|
+
validators.forEach((v) => changes.account.push({
|
|
196
|
+
address: v,
|
|
197
|
+
delta: validatorShare.toString(10),
|
|
198
|
+
action: "fee"
|
|
199
|
+
}));
|
|
200
|
+
} else if (x.type === "withdraw_token_v2") {
|
|
201
|
+
changes.account.push({
|
|
202
|
+
address: blockState.proposer,
|
|
203
|
+
delta: proposer.toString(10),
|
|
204
|
+
action: "fee"
|
|
205
|
+
});
|
|
206
|
+
const validators = blockState.signatures.map((s) => s.signer);
|
|
207
|
+
const validatorShares = require_util.splitTxFee({
|
|
208
|
+
total: validator.toString(10),
|
|
209
|
+
shares: validators.reduce((acc, signer) => {
|
|
210
|
+
acc[signer] = 1;
|
|
211
|
+
return acc;
|
|
212
|
+
}, {}),
|
|
213
|
+
rateBase: new _ocap_util.BN(validators.length)
|
|
214
|
+
});
|
|
215
|
+
Object.keys(validatorShares).forEach((v) => changes.account.push({
|
|
216
|
+
address: v,
|
|
217
|
+
delta: validatorShares[v],
|
|
218
|
+
action: "fee"
|
|
219
|
+
}));
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
const grouped = {
|
|
223
|
+
account: (0, lodash_groupBy.default)(changes.account, "address"),
|
|
224
|
+
stake: (0, lodash_groupBy.default)(changes.stake, "address")
|
|
225
|
+
};
|
|
226
|
+
const updates = {
|
|
227
|
+
stake: Object.keys(grouped.stake).reduce((acc, x) => {
|
|
228
|
+
acc[x] = {
|
|
229
|
+
address: x,
|
|
230
|
+
token: tokenState.address,
|
|
231
|
+
delta: require_util.getBNSum(...grouped.stake[x].map((c) => c.delta)),
|
|
232
|
+
action: grouped.stake[x][grouped.stake[x].length - 1].action
|
|
233
|
+
};
|
|
234
|
+
return acc;
|
|
235
|
+
}, {}),
|
|
236
|
+
account: Object.keys(grouped.account).reduce((acc, x) => {
|
|
237
|
+
acc[x] = {
|
|
238
|
+
address: x,
|
|
239
|
+
token: tokenState.address,
|
|
240
|
+
delta: require_util.getBNSum(...grouped.account[x].map((c) => c.delta)),
|
|
241
|
+
action: grouped.account[x][grouped.account[x].length - 1].action
|
|
242
|
+
};
|
|
243
|
+
return acc;
|
|
244
|
+
}, {})
|
|
245
|
+
};
|
|
246
|
+
context.changes = changes;
|
|
247
|
+
context.updates = updates;
|
|
248
|
+
return next();
|
|
249
|
+
});
|
|
250
|
+
runner.use((context, next) => {
|
|
251
|
+
const { updates, senderState, signerStates } = context;
|
|
252
|
+
const requiredAccounts = Object.keys(updates.account);
|
|
253
|
+
const knownAccounts = { [senderState.address]: senderState };
|
|
254
|
+
(signerStates || []).forEach((x) => knownAccounts[x.address] = x);
|
|
255
|
+
context.missingAccounts = requiredAccounts.filter((x) => !knownAccounts[x]);
|
|
256
|
+
return next();
|
|
257
|
+
});
|
|
258
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
259
|
+
from: "missingAccounts",
|
|
260
|
+
to: "missingAccountStates",
|
|
261
|
+
status: "INVALID_SIGNER_STATE",
|
|
262
|
+
table: "account"
|
|
263
|
+
}));
|
|
264
|
+
runner.use((context, next) => {
|
|
265
|
+
const { senderState, signerStates, missingAccountStates } = context;
|
|
266
|
+
context.accountStates = (0, lodash_uniqBy.default)([
|
|
267
|
+
senderState,
|
|
268
|
+
...signerStates || [],
|
|
269
|
+
...missingAccountStates || []
|
|
270
|
+
], "address");
|
|
271
|
+
return next();
|
|
272
|
+
});
|
|
273
|
+
runner.use(require_pipes_ensure_gas.default((context) => {
|
|
274
|
+
const result = {
|
|
275
|
+
create: 2,
|
|
276
|
+
update: 1,
|
|
277
|
+
payment: 0
|
|
278
|
+
};
|
|
279
|
+
result.update += context.accountStates?.length || 0;
|
|
280
|
+
if (context.updates?.stake[context.lockerState.address]) result.update += 1;
|
|
281
|
+
if (context.updates?.stake[context.stakeState.address]) result.update += 1;
|
|
282
|
+
return result;
|
|
283
|
+
}));
|
|
284
|
+
runner.use(require_pipes_ensure_cost.default({ attachSenderChanges: true }));
|
|
285
|
+
runner.use(_ocap_tx_pipeline.pipes.TakeStateSnapshot());
|
|
286
|
+
runner.use(async (context, next) => {
|
|
287
|
+
const { tx, itx, updates, statedb, senderState, blockState, lockerState, stakeState, accountStates, senderChange, updateVaults } = context;
|
|
288
|
+
const stakeUpdates = updates.stake;
|
|
289
|
+
const accountUpdates = updates.account;
|
|
290
|
+
const [newStakeStates, newAccountStates, newBlockState] = await Promise.all([
|
|
291
|
+
Promise.all([lockerState, stakeState].map((x) => stakeUpdates[x.address] ? statedb.stake.update(x.address, _ocap_state.stake.update(x, require_util.applyTokenChange(x, stakeUpdates[x.address]), context), context) : x)),
|
|
292
|
+
Promise.all((accountStates || []).map((x) => {
|
|
293
|
+
if (accountUpdates[x.address]) {
|
|
294
|
+
let updateSet = require_util.applyTokenChange(x, accountUpdates[x.address]);
|
|
295
|
+
if (x.address === senderState.address) {
|
|
296
|
+
updateSet.nonce = tx.nonce;
|
|
297
|
+
updateSet = Object.assign(updateSet, senderChange ? require_util.applyTokenChange(updateSet, senderChange) : {});
|
|
298
|
+
}
|
|
299
|
+
return statedb.account.update(x.address, _ocap_state.account.update(x, updateSet, context), context);
|
|
300
|
+
}
|
|
301
|
+
return x;
|
|
302
|
+
})),
|
|
303
|
+
statedb.rollupBlock.update(blockState.hash, _ocap_state.rollupBlock.update(blockState, context), context),
|
|
304
|
+
statedb.evidence.create(itx.evidence.hash, _ocap_state.evidence.create({
|
|
305
|
+
hash: itx.evidence.hash,
|
|
306
|
+
data: "rollup-claim-block-reward"
|
|
307
|
+
}, context), context),
|
|
308
|
+
statedb.evidence.create(itx.blockHash, _ocap_state.evidence.create({
|
|
309
|
+
hash: itx.blockHash,
|
|
310
|
+
data: "rollup-claim-block-reward"
|
|
311
|
+
}, context), context)
|
|
312
|
+
]);
|
|
313
|
+
if (updateVaults) await updateVaults();
|
|
314
|
+
delete context.stakeState;
|
|
315
|
+
context.stakeStates = newStakeStates.filter((x) => stakeUpdates[x.address]);
|
|
316
|
+
context.accountStates = newAccountStates;
|
|
317
|
+
context.blockState = newBlockState;
|
|
318
|
+
context.updatedAccounts = context.updatedAccounts || [];
|
|
319
|
+
context.updatedAccounts.push(...(0, lodash_cloneDeep.default)(Object.values(accountUpdates)));
|
|
320
|
+
context.updatedAccounts.push(...(0, lodash_cloneDeep.default)(Object.values(stakeUpdates)));
|
|
321
|
+
debug$1("claim-block-reward", itx);
|
|
322
|
+
next();
|
|
323
|
+
}, { persistError: true });
|
|
324
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyStateDiff());
|
|
325
|
+
var claim_reward_default = runner;
|
|
326
|
+
|
|
327
|
+
//#endregion
|
|
328
|
+
exports.default = claim_reward_default;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/protocols/rollup/claim-reward.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 };
|