@ocap/tx-protocols 1.30.26 → 1.31.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 +7 -0
- package/esm/execute.mjs +196 -71
- package/esm/gas-security-guard.d.mts +374 -0
- package/esm/gas-security-guard.mjs +1101 -0
- package/esm/index.d.mts +35 -5
- package/esm/index.mjs +3 -1
- package/esm/pipes/ensure-cost.mjs +314 -58
- package/esm/protocols/account/delegate.mjs +64 -16
- package/esm/protocols/account/migrate.d.mts +3 -0
- package/esm/protocols/account/migrate.mjs +235 -35
- package/esm/protocols/account/revoke-delegate.d.mts +3 -3
- package/esm/protocols/account/revoke-delegate.mjs +70 -38
- package/esm/protocols/asset/acquire-v2.mjs +29 -12
- package/esm/protocols/asset/acquire-v3.mjs +78 -22
- package/esm/protocols/asset/calls/transfer-token.mjs +2 -1
- package/esm/protocols/asset/calls/transfer.mjs +1 -0
- package/esm/protocols/asset/consume.mjs +12 -4
- package/esm/protocols/asset/create.mjs +18 -5
- package/esm/protocols/asset/mint.mjs +23 -1
- package/esm/protocols/asset/pipes/exec-mint-hook.d.mts +21 -1
- package/esm/protocols/asset/pipes/exec-mint-hook.mjs +115 -1
- package/esm/protocols/asset/pipes/extract-factory-tokens.mjs +14 -8
- package/esm/protocols/asset/pipes/verify-itx-address.mjs +9 -0
- package/esm/protocols/asset/pipes/verify-itx-assets.mjs +21 -5
- package/esm/protocols/asset/update.d.mts +13 -2
- package/esm/protocols/asset/update.mjs +133 -14
- package/esm/protocols/factory/create.mjs +14 -6
- package/esm/protocols/governance/claim-stake.mjs +92 -10
- package/esm/protocols/governance/return-stake.mjs +44 -12
- package/esm/protocols/governance/revoke-stake.mjs +17 -5
- package/esm/protocols/governance/slash-stake.mjs +64 -25
- package/esm/protocols/governance/stake.mjs +63 -13
- package/esm/protocols/rollup/claim-reward.mjs +39 -20
- package/esm/protocols/rollup/close.mjs +1 -1
- package/esm/protocols/rollup/create-block.mjs +8 -7
- package/esm/protocols/rollup/create.mjs +17 -6
- package/esm/protocols/rollup/join.mjs +3 -3
- package/esm/protocols/rollup/leave.mjs +1 -1
- package/esm/protocols/rollup/migrate.mjs +7 -4
- package/esm/protocols/rollup/pipes/verify-evidence.mjs +12 -4
- package/esm/protocols/rollup/update.mjs +6 -1
- package/esm/protocols/token/create.mjs +23 -12
- package/esm/protocols/token/deposit-v2.d.mts +5 -1
- package/esm/protocols/token/deposit-v2.mjs +81 -29
- package/esm/protocols/token/withdraw-v2.mjs +33 -16
- package/esm/protocols/token-factory/burn.mjs +43 -10
- package/esm/protocols/token-factory/create.mjs +23 -14
- package/esm/protocols/token-factory/mint.mjs +54 -21
- package/esm/protocols/token-factory/pipes/verify-icon.mjs +1 -1
- package/esm/protocols/token-factory/update.mjs +16 -6
- package/esm/protocols/trade/exchange-v2.d.mts +4 -0
- package/esm/protocols/trade/exchange-v2.mjs +78 -22
- package/esm/protocols/trade/transfer-v2.mjs +44 -13
- package/esm/protocols/trade/transfer-v3.mjs +72 -31
- package/esm/util.d.mts +3 -1
- package/esm/util.mjs +26 -17
- package/lib/execute.cjs +193 -67
- package/lib/execute.d.cts +7 -0
- package/lib/gas-security-guard.cjs +1140 -0
- package/lib/gas-security-guard.d.cts +374 -0
- package/lib/index.cjs +122 -1
- package/lib/index.d.cts +36 -6
- package/lib/pipes/ensure-cost.cjs +313 -57
- package/lib/protocols/account/delegate.cjs +64 -16
- package/lib/protocols/account/migrate.cjs +235 -35
- package/lib/protocols/account/migrate.d.cts +3 -0
- package/lib/protocols/account/revoke-delegate.cjs +71 -39
- package/lib/protocols/account/revoke-delegate.d.cts +3 -3
- package/lib/protocols/asset/acquire-v2.cjs +28 -11
- package/lib/protocols/asset/acquire-v3.cjs +77 -20
- package/lib/protocols/asset/calls/transfer-token.cjs +3 -2
- package/lib/protocols/asset/calls/transfer.cjs +1 -0
- package/lib/protocols/asset/consume.cjs +11 -3
- package/lib/protocols/asset/create.cjs +19 -6
- package/lib/protocols/asset/mint.cjs +23 -1
- package/lib/protocols/asset/pipes/exec-mint-hook.cjs +117 -1
- package/lib/protocols/asset/pipes/exec-mint-hook.d.cts +21 -1
- package/lib/protocols/asset/pipes/extract-factory-tokens.cjs +14 -9
- package/lib/protocols/asset/pipes/verify-itx-address.cjs +9 -0
- package/lib/protocols/asset/pipes/verify-itx-assets.cjs +21 -5
- package/lib/protocols/asset/update.cjs +131 -12
- package/lib/protocols/asset/update.d.cts +13 -2
- package/lib/protocols/factory/create.cjs +14 -6
- package/lib/protocols/governance/claim-stake.cjs +92 -9
- package/lib/protocols/governance/claim-stake.d.cts +1 -1
- package/lib/protocols/governance/return-stake.cjs +44 -11
- package/lib/protocols/governance/return-stake.d.cts +1 -1
- package/lib/protocols/governance/revoke-stake.cjs +17 -5
- package/lib/protocols/governance/revoke-stake.d.cts +1 -1
- package/lib/protocols/governance/slash-stake.cjs +64 -24
- package/lib/protocols/governance/slash-stake.d.cts +1 -1
- package/lib/protocols/governance/stake.cjs +65 -14
- package/lib/protocols/rollup/claim-reward.cjs +39 -20
- package/lib/protocols/rollup/close.cjs +1 -1
- package/lib/protocols/rollup/create-block.cjs +9 -8
- package/lib/protocols/rollup/create-block.d.cts +1 -1
- package/lib/protocols/rollup/create.cjs +18 -7
- package/lib/protocols/rollup/join.cjs +3 -3
- package/lib/protocols/rollup/leave.cjs +1 -1
- package/lib/protocols/rollup/migrate.cjs +7 -4
- package/lib/protocols/rollup/pipes/verify-evidence.cjs +11 -3
- package/lib/protocols/rollup/update.cjs +6 -1
- package/lib/protocols/token/create.cjs +24 -13
- package/lib/protocols/token/deposit-v2.cjs +80 -28
- package/lib/protocols/token/deposit-v2.d.cts +5 -1
- package/lib/protocols/token/withdraw-v2.cjs +32 -15
- package/lib/protocols/token-factory/burn.cjs +42 -9
- package/lib/protocols/token-factory/create.cjs +24 -15
- package/lib/protocols/token-factory/mint.cjs +53 -20
- package/lib/protocols/token-factory/pipes/verify-icon.cjs +1 -1
- package/lib/protocols/token-factory/update.cjs +16 -6
- package/lib/protocols/trade/exchange-v2.cjs +76 -20
- package/lib/protocols/trade/exchange-v2.d.cts +4 -0
- package/lib/protocols/trade/transfer-v2.cjs +45 -14
- package/lib/protocols/trade/transfer-v3.cjs +72 -30
- package/lib/util.cjs +26 -17
- package/lib/util.d.cts +4 -2
- package/package.json +16 -16
|
@@ -3,15 +3,19 @@ const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
|
3
3
|
const require_util = require('../../util.cjs');
|
|
4
4
|
const require_pipes_ensure_cost = require('../../pipes/ensure-cost.cjs');
|
|
5
5
|
const require_pipes_ensure_gas = require('../../pipes/ensure-gas.cjs');
|
|
6
|
+
let _arcblock_did = require("@arcblock/did");
|
|
7
|
+
let _ocap_mcrypto = require("@ocap/mcrypto");
|
|
6
8
|
let _ocap_state = require("@ocap/state");
|
|
7
9
|
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
8
10
|
let _ocap_util = require("@ocap/util");
|
|
9
11
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
12
|
+
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
13
|
+
let _ocap_util_lib_get_related_addr = require("@ocap/util/lib/get-related-addr");
|
|
10
14
|
let debug = require("debug");
|
|
11
15
|
debug = require_rolldown_runtime.__toESM(debug);
|
|
12
|
-
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
13
16
|
let _arcblock_validator = require("@arcblock/validator");
|
|
14
|
-
let
|
|
17
|
+
let lodash_uniqBy = require("lodash/uniqBy");
|
|
18
|
+
lodash_uniqBy = require_rolldown_runtime.__toESM(lodash_uniqBy);
|
|
15
19
|
let lodash_isEmpty = require("lodash/isEmpty");
|
|
16
20
|
lodash_isEmpty = require_rolldown_runtime.__toESM(lodash_isEmpty);
|
|
17
21
|
|
|
@@ -65,7 +69,11 @@ runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
|
65
69
|
status: "INVALID_RECEIVER_STATE",
|
|
66
70
|
table: "account"
|
|
67
71
|
}));
|
|
68
|
-
runner.use(_ocap_tx_pipeline.pipes.VerifyBlocked({ stateKeys: [
|
|
72
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyBlocked({ stateKeys: [
|
|
73
|
+
"senderState",
|
|
74
|
+
"delegatorState",
|
|
75
|
+
"receiverStates"
|
|
76
|
+
] }));
|
|
69
77
|
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
70
78
|
stateKey: "senderState",
|
|
71
79
|
addressKey: "tx.from"
|
|
@@ -82,23 +90,39 @@ runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
|
82
90
|
status: "INVALID_SLASH_STATE",
|
|
83
91
|
table: "account"
|
|
84
92
|
}));
|
|
85
|
-
runner.use(_ocap_tx_pipeline.pipes.VerifyInfo([
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
93
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyInfo([
|
|
94
|
+
{
|
|
95
|
+
error: "INVALID_STAKE_STATE",
|
|
96
|
+
message: "Cannot slash permanently locked protocol token stake",
|
|
97
|
+
fn: (ctx) => {
|
|
98
|
+
const context = ctx;
|
|
99
|
+
if (!context.stakeState.revocable) {
|
|
100
|
+
const receiverRole = (0, _arcblock_did.toTypeInfo)(context.stakeState.receiver).role;
|
|
101
|
+
if (context.stakeState.receiver === context.config.token.address || receiverRole === _ocap_mcrypto.types.RoleType.ROLE_TOKEN || receiverRole === _ocap_mcrypto.types.RoleType.ROLE_TOKEN_FACTORY || receiverRole === _ocap_mcrypto.types.RoleType.ROLE_ASSET) return false;
|
|
102
|
+
}
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
error: "INVALID_TX",
|
|
108
|
+
message: "You are not allowed to slash from this stake",
|
|
109
|
+
fn: (ctx) => {
|
|
110
|
+
const context = ctx;
|
|
111
|
+
const slasherStates = context.slasherStates || [];
|
|
112
|
+
const senderAddresses = (0, _ocap_util_lib_get_related_addr.getRelatedAddresses)(context.senderState);
|
|
113
|
+
return ((0, lodash_isEmpty.default)(slasherStates) ? context.stakeState.revocable ? [context.stakeState.receiver] : [] : slasherStates.map((x) => x.address)).some((addr) => senderAddresses.includes(addr));
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
error: "INVALID_TX",
|
|
118
|
+
message: "Can only send slashed token/assets to vault or specified slasher",
|
|
119
|
+
fn: (ctx) => {
|
|
120
|
+
const context = ctx;
|
|
121
|
+
const slasherStates = context.slasherStates || [];
|
|
122
|
+
return (context.receivers || []).every((x) => x === context.config.vaults.slashedStake || slasherStates.some((s) => s.address === x));
|
|
123
|
+
}
|
|
92
124
|
}
|
|
93
|
-
|
|
94
|
-
error: "INVALID_TX",
|
|
95
|
-
message: "Can only send slashed token/assets to vault or specified slasher",
|
|
96
|
-
fn: (ctx) => {
|
|
97
|
-
const context = ctx;
|
|
98
|
-
const slasherStates = context.slasherStates || [];
|
|
99
|
-
return (context.receivers || []).every((x) => x === context.config.vaults.slashedStake || slasherStates.some((s) => s.address === x));
|
|
100
|
-
}
|
|
101
|
-
}]));
|
|
125
|
+
]));
|
|
102
126
|
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
103
127
|
from: "tokens",
|
|
104
128
|
to: "tokenStates",
|
|
@@ -187,17 +211,33 @@ runner.use(async (context, next) => {
|
|
|
187
211
|
stakeUpdates.tokens = newTokens.tokens;
|
|
188
212
|
stakeUpdates.revokedTokens = newRevoked.tokens;
|
|
189
213
|
const ownerState = receiverStates.find((s) => (0, _ocap_util_lib_get_related_addr.getRelatedAddresses)(s).includes(owner));
|
|
190
|
-
receiverUpdates[ownerState.address]
|
|
191
|
-
|
|
214
|
+
const alreadyUpdated = Boolean(receiverUpdates[ownerState.address]);
|
|
215
|
+
const baseState = receiverUpdates[ownerState.address] || ownerState;
|
|
216
|
+
receiverUpdates[ownerState.address] = require_util.applyTokenUpdates(tokensList, baseState, "add");
|
|
217
|
+
if (!alreadyUpdated && senderChange && ownerState.address === senderChange.address) receiverUpdates[ownerState.address] = require_util.applyTokenChange(receiverUpdates[ownerState.address], senderChange);
|
|
192
218
|
assetsList.forEach((a) => {
|
|
193
219
|
assetUpdates[a] = { owner: ownerState.address };
|
|
194
220
|
});
|
|
195
221
|
});
|
|
196
222
|
const [newSenderState, newReceiverStates, newStakeState, newAssetStates] = await Promise.all([
|
|
197
223
|
statedb.account.update(senderState.address, _ocap_state.account.update(senderState, Object.assign({ nonce: tx.nonce }, receiverUpdates[senderState.address] || (senderChange ? require_util.applyTokenChange(senderState, senderChange) : {})), context), context),
|
|
198
|
-
Promise.all(receiverStates.filter((x) => x.address !== senderState.address).map((x) => statedb.account.update(x.address, _ocap_state.account.update(x, receiverUpdates[x.address], context), context))),
|
|
199
|
-
|
|
200
|
-
|
|
224
|
+
Promise.all((0, lodash_uniqBy.default)(receiverStates, "address").filter((x) => x.address !== senderState.address).map((x) => statedb.account.update(x.address, _ocap_state.account.update(x, receiverUpdates[x.address], context), context))),
|
|
225
|
+
(() => {
|
|
226
|
+
const prevRevoked = stakeState.revokedTokens || {};
|
|
227
|
+
const nextRevoked = stakeUpdates.revokedTokens || {};
|
|
228
|
+
const poolShrunk = Object.keys(prevRevoked).some((k) => new _ocap_util.BN(prevRevoked[k] || "0").gt(new _ocap_util.BN(nextRevoked[k] || "0"))) || (stakeUpdates.revokedAssets || []).length < (stakeState.revokedAssets || []).length;
|
|
229
|
+
const hasPending = Object.values(nextRevoked).some((v$1) => new _ocap_util.BN(v$1 || "0").gt(new _ocap_util.BN(0))) || (stakeUpdates.revokedAssets || []).length > 0;
|
|
230
|
+
return statedb.stake.update(stakeState.address, _ocap_state.stake.update(stakeState, stakeUpdates, hasPending && !poolShrunk ? {
|
|
231
|
+
...context,
|
|
232
|
+
txTime: stakeState.context?.renaissanceTime || context.txTime
|
|
233
|
+
} : context), context);
|
|
234
|
+
})(),
|
|
235
|
+
Promise.all(assetStates.map(async (x) => {
|
|
236
|
+
const nextOwner = assetUpdates[x.address]?.owner;
|
|
237
|
+
const updatedAsset = await statedb.asset.update(x.address, _ocap_state.asset.update(x, assetUpdates[x.address], context), context);
|
|
238
|
+
if (nextOwner && _ocap_state.token.isTokenCharterAsset(x)) await _ocap_state.token.syncTokenCharterOwnership(x, nextOwner, statedb, context);
|
|
239
|
+
return updatedAsset;
|
|
240
|
+
}))
|
|
201
241
|
]);
|
|
202
242
|
if (updateVaults) await updateVaults();
|
|
203
243
|
context.senderState = newSenderState;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IAccountState, IReadyContext, IWithAssets, IWithLocked, IWithReceivers, IWithSender, IWithStake, IWithTokens, TSlashStakeTx } from "@ocap/types";
|
|
2
|
-
import { Runner } from "@ocap/tx-pipeline";
|
|
3
2
|
import { BN } from "@ocap/util";
|
|
3
|
+
import { Runner } from "@ocap/tx-pipeline";
|
|
4
4
|
|
|
5
5
|
//#region src/protocols/governance/slash-stake.d.ts
|
|
6
6
|
/** Token input type */
|
|
@@ -3,18 +3,22 @@ const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
|
3
3
|
const require_util = require('../../util.cjs');
|
|
4
4
|
const require_pipes_ensure_cost = require('../../pipes/ensure-cost.cjs');
|
|
5
5
|
const require_pipes_ensure_gas = require('../../pipes/ensure-gas.cjs');
|
|
6
|
+
let _arcblock_did = require("@arcblock/did");
|
|
7
|
+
let _arcblock_did_util = require("@arcblock/did-util");
|
|
8
|
+
let _ocap_mcrypto = require("@ocap/mcrypto");
|
|
6
9
|
let _ocap_state = require("@ocap/state");
|
|
7
10
|
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
8
11
|
let _ocap_util = require("@ocap/util");
|
|
9
12
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
13
|
+
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
10
14
|
let lodash_pick = require("lodash/pick");
|
|
11
15
|
lodash_pick = require_rolldown_runtime.__toESM(lodash_pick);
|
|
12
|
-
let _arcblock_did_util = require("@arcblock/did-util");
|
|
13
16
|
let debug = require("debug");
|
|
14
17
|
debug = require_rolldown_runtime.__toESM(debug);
|
|
15
|
-
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
16
18
|
let _arcblock_validator = require("@arcblock/validator");
|
|
17
19
|
let node_util = require("node:util");
|
|
20
|
+
let lodash_uniqBy = require("lodash/uniqBy");
|
|
21
|
+
lodash_uniqBy = require_rolldown_runtime.__toESM(lodash_uniqBy);
|
|
18
22
|
let lodash_isEmpty = require("lodash/isEmpty");
|
|
19
23
|
lodash_isEmpty = require_rolldown_runtime.__toESM(lodash_isEmpty);
|
|
20
24
|
|
|
@@ -75,6 +79,18 @@ runner.use(_ocap_tx_pipeline.pipes.VerifyInfo([
|
|
|
75
79
|
const context = ctx;
|
|
76
80
|
return !((0, lodash_isEmpty.default)(context.tokens) && (0, lodash_isEmpty.default)(context.assets));
|
|
77
81
|
}
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
error: "INVALID_TX",
|
|
85
|
+
message: "Permanently locked token stake cannot have slashers",
|
|
86
|
+
fn: (ctx) => {
|
|
87
|
+
const context = ctx;
|
|
88
|
+
if (context.itx.locked) {
|
|
89
|
+
const receiverRole = (0, _arcblock_did.toTypeInfo)(context.itx.receiver).role;
|
|
90
|
+
if (context.itx.receiver === context.config.token.address || receiverRole === _ocap_mcrypto.types.RoleType.ROLE_TOKEN || receiverRole === _ocap_mcrypto.types.RoleType.ROLE_TOKEN_FACTORY || receiverRole === _ocap_mcrypto.types.RoleType.ROLE_ASSET) return (0, _ocap_util_lib_get_list_field.getListField)(context.itx, "slashers").length === 0;
|
|
91
|
+
}
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
78
94
|
}
|
|
79
95
|
]));
|
|
80
96
|
runner.use(_ocap_tx_pipeline.pipes.VerifyListSize({ listKey: [
|
|
@@ -112,7 +128,12 @@ runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
|
112
128
|
to: "receiverState",
|
|
113
129
|
status: "INVALID_RECEIVER_STATE"
|
|
114
130
|
}));
|
|
115
|
-
runner.use(_ocap_tx_pipeline.pipes.VerifyBlocked({ stateKeys: [
|
|
131
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyBlocked({ stateKeys: [
|
|
132
|
+
"senderState",
|
|
133
|
+
"delegatorState",
|
|
134
|
+
"signerStates",
|
|
135
|
+
"receiverState"
|
|
136
|
+
] }));
|
|
116
137
|
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
117
138
|
stateKey: "receiverState",
|
|
118
139
|
addressKey: "itx.receiver"
|
|
@@ -136,16 +157,18 @@ runner.use(_ocap_tx_pipeline.pipes.verifyTokenAccess({
|
|
|
136
157
|
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
137
158
|
from: "assets",
|
|
138
159
|
to: "assetStates",
|
|
139
|
-
status: "
|
|
160
|
+
status: "INVALID_ASSET_STATE",
|
|
140
161
|
table: "asset"
|
|
141
162
|
}));
|
|
142
163
|
runner.use(_ocap_tx_pipeline.pipes.VerifyTransferrable({ assets: "assetStates" }));
|
|
143
164
|
runner.use(async (context, next) => {
|
|
144
165
|
const { inputs = [], assetStates = [], signerStates = [] } = context;
|
|
166
|
+
if (assetStates.some((x) => _ocap_state.token.isTokenCharterAsset(x))) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "Token charter asset cannot be staked"));
|
|
145
167
|
for (const input of inputs) {
|
|
146
168
|
const { owner } = input;
|
|
147
169
|
const assetsList = (0, _ocap_util_lib_get_list_field.getListField)(input, "assets");
|
|
148
170
|
const states = assetStates.filter((x) => assetsList.includes(x.address));
|
|
171
|
+
if (states.length !== new Set(assetsList).size) return next(new _ocap_util_lib_error.CustomError("INVALID_ASSET_STATE", "Input asset does not exist on chain"));
|
|
149
172
|
const signer = signerStates.find((x) => x.address === owner);
|
|
150
173
|
try {
|
|
151
174
|
await verifyAssetOwner({
|
|
@@ -171,16 +194,20 @@ runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
|
171
194
|
runner.use((context, next) => {
|
|
172
195
|
const { tx, itx, inputs = [] } = context;
|
|
173
196
|
const { config } = context;
|
|
174
|
-
const { token, transaction } = config;
|
|
197
|
+
const { token: token$1, transaction } = config;
|
|
175
198
|
const { minStake, maxStake } = transaction.txGas;
|
|
176
|
-
|
|
199
|
+
const isGasAddress = require_util.isGasStakeAddress(tx.from, itx.address);
|
|
200
|
+
const isValidGasInput = require_util.isGasStakeInput(inputs, token$1.address);
|
|
201
|
+
if (isGasAddress && !isValidGasInput) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "Invalid input for gas stake"));
|
|
202
|
+
context.isGasStake = isGasAddress && isValidGasInput;
|
|
177
203
|
if (context.isGasStake) {
|
|
178
204
|
const [tokenInput] = (0, _ocap_util_lib_get_list_field.getListField)(inputs[0], "tokens");
|
|
179
205
|
const actualStake = new _ocap_util.BN(tokenInput.value);
|
|
180
|
-
const
|
|
181
|
-
const
|
|
206
|
+
const cumulativeStake = new _ocap_util.BN(context.stakeState?.tokens?.[token$1.address] || 0).add(actualStake);
|
|
207
|
+
const expectedMinStake = (0, _ocap_util.fromTokenToUnit)(minStake, token$1.decimal);
|
|
208
|
+
const expectedMaxStake = (0, _ocap_util.fromTokenToUnit)(maxStake, token$1.decimal);
|
|
182
209
|
if (actualStake.lt(expectedMinStake)) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Stake for gas should be greater than: ${minStake}`));
|
|
183
|
-
if (
|
|
210
|
+
if (cumulativeStake.gt(expectedMaxStake)) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Stake for gas should be less than: ${maxStake}`));
|
|
184
211
|
}
|
|
185
212
|
if (context.isGasStake) {
|
|
186
213
|
context.revokeWaitingPeriod = transaction.txGas.stakeLockPeriod;
|
|
@@ -197,7 +224,7 @@ runner.use(require_pipes_ensure_gas.default((context) => {
|
|
|
197
224
|
update: 0,
|
|
198
225
|
payment: 0
|
|
199
226
|
};
|
|
200
|
-
if (
|
|
227
|
+
if (context.isGasStake) {
|
|
201
228
|
Object.defineProperty(context, "txBaseGas", { value: false });
|
|
202
229
|
return result;
|
|
203
230
|
}
|
|
@@ -214,10 +241,26 @@ runner.use(_ocap_tx_pipeline.pipes.TakeStateSnapshot());
|
|
|
214
241
|
runner.use(async (context, next) => {
|
|
215
242
|
const { tx, itx, inputs = [], statedb, senderState, senderChange, stakeState, signerStates = [], updateVaults, assetStates = [] } = context;
|
|
216
243
|
const signerUpdates = {};
|
|
244
|
+
const hasNonEmptyItxData = itx.data !== void 0 && itx.data !== null && Boolean(itx.data.typeUrl || itx.data.type || itx.data.value);
|
|
245
|
+
const hasProtectedStakeData = (() => {
|
|
246
|
+
if (!stakeState?.data) return false;
|
|
247
|
+
try {
|
|
248
|
+
const rawVal = require_util.decodeAnySafe(stakeState.data)?.value ?? stakeState.data.value;
|
|
249
|
+
if (!rawVal) return false;
|
|
250
|
+
const parsed = typeof rawVal === "string" ? JSON.parse(rawVal) : rawVal;
|
|
251
|
+
if (parsed && typeof parsed === "object") return [
|
|
252
|
+
"creditPool",
|
|
253
|
+
"cardReserve",
|
|
254
|
+
"distributorRebate",
|
|
255
|
+
"unmaturedRebate"
|
|
256
|
+
].some((k) => k in parsed);
|
|
257
|
+
} catch {}
|
|
258
|
+
return false;
|
|
259
|
+
})();
|
|
217
260
|
const stakeUpdates = stakeState ? {
|
|
218
261
|
tokens: stakeState.tokens,
|
|
219
262
|
assets: stakeState.assets || [],
|
|
220
|
-
data: itx.data
|
|
263
|
+
...stakeState.revocable && !hasProtectedStakeData && hasNonEmptyItxData ? { data: itx.data } : {}
|
|
221
264
|
} : {
|
|
222
265
|
tokens: {},
|
|
223
266
|
assets: [],
|
|
@@ -237,10 +280,18 @@ runner.use(async (context, next) => {
|
|
|
237
280
|
statedb.account.updateOrCreate(senderState ?? null, _ocap_state.account.updateOrCreate(senderState ?? null, Object.assign({
|
|
238
281
|
address: tx.from,
|
|
239
282
|
nonce: tx.nonce,
|
|
240
|
-
pk: tx.pk
|
|
283
|
+
pk: tx.delegator ? senderState?.pk || tx.pk : tx.pk
|
|
241
284
|
}, 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 ?
|
|
285
|
+
Promise.all((0, lodash_uniqBy.default)(signerStates, "address").filter((x) => x.address !== tx.from).map((x) => statedb.account.update(x.address, _ocap_state.account.update(x, signerUpdates[x.address], context), context))),
|
|
286
|
+
stakeState ? (() => {
|
|
287
|
+
const hasPendingRevokedTokens = Object.values(stakeState.revokedTokens || {}).some((v$1) => new _ocap_util.BN(String(v$1 || "0")).gt(new _ocap_util.BN(0)));
|
|
288
|
+
const hasPendingRevokedAssets = Array.isArray(stakeState.revokedAssets) && stakeState.revokedAssets.length > 0;
|
|
289
|
+
const preserveRenaissanceTime = (hasPendingRevokedTokens || hasPendingRevokedAssets) && stakeState?.context?.renaissanceTime;
|
|
290
|
+
return statedb.stake.update(stakeState.address, _ocap_state.stake.update(stakeState, stakeUpdates, preserveRenaissanceTime ? {
|
|
291
|
+
...context,
|
|
292
|
+
txTime: preserveRenaissanceTime
|
|
293
|
+
} : context), context);
|
|
294
|
+
})() : statedb.stake.create(itx.address, _ocap_state.stake.create({
|
|
244
295
|
sender: tx.from,
|
|
245
296
|
revocable: !itx.locked,
|
|
246
297
|
slashers: context.slashers,
|
|
@@ -6,15 +6,15 @@ const require_pipes_ensure_gas = require('../../pipes/ensure-gas.cjs');
|
|
|
6
6
|
const require_protocols_rollup_pipes_ensure_validator = require('./pipes/ensure-validator.cjs');
|
|
7
7
|
const require_protocols_rollup_pipes_verify_signers = require('./pipes/verify-signers.cjs');
|
|
8
8
|
const require_protocols_rollup_pipes_verify_status = require('./pipes/verify-status.cjs');
|
|
9
|
+
let _arcblock_did_util = require("@arcblock/did-util");
|
|
9
10
|
let _ocap_state = require("@ocap/state");
|
|
10
11
|
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
11
12
|
let _ocap_util = require("@ocap/util");
|
|
12
13
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
13
|
-
let _arcblock_did_util = require("@arcblock/did-util");
|
|
14
|
-
let debug = require("debug");
|
|
15
|
-
debug = require_rolldown_runtime.__toESM(debug);
|
|
16
14
|
let lodash_cloneDeep = require("lodash/cloneDeep");
|
|
17
15
|
lodash_cloneDeep = require_rolldown_runtime.__toESM(lodash_cloneDeep);
|
|
16
|
+
let debug = require("debug");
|
|
17
|
+
debug = require_rolldown_runtime.__toESM(debug);
|
|
18
18
|
let lodash_groupBy = require("lodash/groupBy");
|
|
19
19
|
lodash_groupBy = require_rolldown_runtime.__toESM(lodash_groupBy);
|
|
20
20
|
let _arcblock_validator = require("@arcblock/validator");
|
|
@@ -32,10 +32,7 @@ const schema = _arcblock_validator.v.pipe(_arcblock_validator.v.object({
|
|
|
32
32
|
blockHeight: _arcblock_validator.v.pipe(_arcblock_validator.v.number(), _arcblock_validator.v.integer(), _arcblock_validator.v.check((n) => n > 0, "Must be > 0")),
|
|
33
33
|
blockHash: _arcblock_validator.v.pipe(_arcblock_validator.v.string(), _arcblock_validator.v.regex(_arcblock_validator.patterns.txHash)),
|
|
34
34
|
evidence: _arcblock_validator.v.object({ hash: _arcblock_validator.v.pipe(_arcblock_validator.v.string(), _arcblock_validator.v.regex(_arcblock_validator.patterns.txHash)) }),
|
|
35
|
-
publisher: (0, _arcblock_validator.vDID)({
|
|
36
|
-
prefix: true,
|
|
37
|
-
wallet: "ethereum"
|
|
38
|
-
}),
|
|
35
|
+
publisher: (0, _arcblock_validator.vDID)({ prefix: true }),
|
|
39
36
|
data: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_arcblock_validator.v.any()))
|
|
40
37
|
}), (0, _arcblock_validator.vStripUnknown)());
|
|
41
38
|
runner.use((context, next) => {
|
|
@@ -69,6 +66,14 @@ runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
|
69
66
|
status: "INVALID_ROLLUP",
|
|
70
67
|
table: "rollup"
|
|
71
68
|
}));
|
|
69
|
+
runner.use((context, next) => {
|
|
70
|
+
const { itx, rollupState } = context;
|
|
71
|
+
if (_ocap_state.rollup.getRollupTargetType(rollupState) === "EVM" && (0, _arcblock_validator.vValidate)((0, _arcblock_validator.vDID)({
|
|
72
|
+
prefix: true,
|
|
73
|
+
wallet: "ethereum"
|
|
74
|
+
}), itx.publisher).error) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "\"publisher\" Expected wallet type to be \"ethereum\""));
|
|
75
|
+
return next();
|
|
76
|
+
});
|
|
72
77
|
runner.use(require_protocols_rollup_pipes_ensure_validator.default(false));
|
|
73
78
|
runner.use(require_protocols_rollup_pipes_verify_status.default({ closed: false }));
|
|
74
79
|
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
@@ -152,23 +157,27 @@ runner.use((context, next) => {
|
|
|
152
157
|
const slashShare = slashAmount.div(new _ocap_util.BN(2));
|
|
153
158
|
changes.stake.push({
|
|
154
159
|
address: stakeState.address,
|
|
160
|
+
token: tokenState.address,
|
|
155
161
|
delta: `-${slashAmount.toString(10)}`,
|
|
156
162
|
action: "slash"
|
|
157
163
|
});
|
|
158
164
|
changes.stake.push({
|
|
159
165
|
address: lockerState.address,
|
|
166
|
+
token: tokenState.address,
|
|
160
167
|
delta: slashShare.toString(10),
|
|
161
168
|
action: "slash"
|
|
162
169
|
});
|
|
163
170
|
changes.account.push({
|
|
164
171
|
address: itx.publisher,
|
|
172
|
+
token: tokenState.address,
|
|
165
173
|
delta: slashShare.toString(10),
|
|
166
174
|
action: "reward"
|
|
167
175
|
});
|
|
168
176
|
}
|
|
169
177
|
(txs || []).forEach((x) => {
|
|
170
178
|
const txData = x.tx;
|
|
171
|
-
const { actualFee } = txData.itxJson;
|
|
179
|
+
const { actualFee, token: txTokenObj } = txData.itxJson;
|
|
180
|
+
const txToken = txTokenObj?.address || tokenState.address;
|
|
172
181
|
const { publisher, proposer, validator } = require_util.splitTxFee({
|
|
173
182
|
total: actualFee,
|
|
174
183
|
shares,
|
|
@@ -176,11 +185,13 @@ runner.use((context, next) => {
|
|
|
176
185
|
});
|
|
177
186
|
changes.stake.push({
|
|
178
187
|
address: lockerState.address,
|
|
188
|
+
token: txToken,
|
|
179
189
|
delta: `-${actualFee}`,
|
|
180
190
|
action: "claim"
|
|
181
191
|
});
|
|
182
192
|
changes.account.push({
|
|
183
193
|
address: itx.publisher,
|
|
194
|
+
token: txToken,
|
|
184
195
|
delta: publisher.toString(10),
|
|
185
196
|
action: "fee"
|
|
186
197
|
});
|
|
@@ -188,6 +199,7 @@ runner.use((context, next) => {
|
|
|
188
199
|
const txItxJson = txData.itxJson;
|
|
189
200
|
changes.account.push({
|
|
190
201
|
address: txItxJson.proposer,
|
|
202
|
+
token: txToken,
|
|
191
203
|
delta: proposer.toString(10),
|
|
192
204
|
action: "fee"
|
|
193
205
|
});
|
|
@@ -197,12 +209,14 @@ runner.use((context, next) => {
|
|
|
197
209
|
const validatorShare = validator.div(new _ocap_util.BN(validators.length));
|
|
198
210
|
validators.forEach((v$1) => changes.account.push({
|
|
199
211
|
address: v$1,
|
|
212
|
+
token: txToken,
|
|
200
213
|
delta: validatorShare.toString(10),
|
|
201
214
|
action: "fee"
|
|
202
215
|
}));
|
|
203
216
|
} else if (x.type === "withdraw_token_v2") {
|
|
204
217
|
changes.account.push({
|
|
205
218
|
address: blockState.proposer,
|
|
219
|
+
token: txToken,
|
|
206
220
|
delta: proposer.toString(10),
|
|
207
221
|
action: "fee"
|
|
208
222
|
});
|
|
@@ -218,6 +232,7 @@ runner.use((context, next) => {
|
|
|
218
232
|
});
|
|
219
233
|
Object.keys(validatorShares).forEach((v$1) => changes.account.push({
|
|
220
234
|
address: v$1,
|
|
235
|
+
token: txToken,
|
|
221
236
|
delta: validatorShares[v$1],
|
|
222
237
|
action: "fee"
|
|
223
238
|
}));
|
|
@@ -227,23 +242,27 @@ runner.use((context, next) => {
|
|
|
227
242
|
account: (0, lodash_groupBy.default)(changes.account, "address"),
|
|
228
243
|
stake: (0, lodash_groupBy.default)(changes.stake, "address")
|
|
229
244
|
};
|
|
245
|
+
const aggregateChanges = (items, addr) => {
|
|
246
|
+
const byToken = (0, lodash_groupBy.default)(items, (c) => c.token || tokenState.address);
|
|
247
|
+
const perToken = Object.keys(byToken).map((tok) => ({
|
|
248
|
+
address: addr,
|
|
249
|
+
token: tok,
|
|
250
|
+
delta: require_util.getBNSum(...byToken[tok].map((c) => c.delta)),
|
|
251
|
+
action: byToken[tok][byToken[tok].length - 1].action
|
|
252
|
+
}));
|
|
253
|
+
if (perToken.length === 1) return perToken[0];
|
|
254
|
+
return {
|
|
255
|
+
...perToken[perToken.length - 1],
|
|
256
|
+
changes: perToken
|
|
257
|
+
};
|
|
258
|
+
};
|
|
230
259
|
const updates = {
|
|
231
260
|
stake: Object.keys(grouped.stake).reduce((acc, x) => {
|
|
232
|
-
acc[x] =
|
|
233
|
-
address: x,
|
|
234
|
-
token: tokenState.address,
|
|
235
|
-
delta: require_util.getBNSum(...grouped.stake[x].map((c) => c.delta)),
|
|
236
|
-
action: grouped.stake[x][grouped.stake[x].length - 1].action
|
|
237
|
-
};
|
|
261
|
+
acc[x] = aggregateChanges(grouped.stake[x], x);
|
|
238
262
|
return acc;
|
|
239
263
|
}, {}),
|
|
240
264
|
account: Object.keys(grouped.account).reduce((acc, x) => {
|
|
241
|
-
acc[x] =
|
|
242
|
-
address: x,
|
|
243
|
-
token: tokenState.address,
|
|
244
|
-
delta: require_util.getBNSum(...grouped.account[x].map((c) => c.delta)),
|
|
245
|
-
action: grouped.account[x][grouped.account[x].length - 1].action
|
|
246
|
-
};
|
|
265
|
+
acc[x] = aggregateChanges(grouped.account[x], x);
|
|
247
266
|
return acc;
|
|
248
267
|
}, {})
|
|
249
268
|
};
|
|
@@ -5,10 +5,10 @@ const require_pipes_ensure_gas = require('../../pipes/ensure-gas.cjs');
|
|
|
5
5
|
const require_protocols_rollup_pipes_ensure_validator = require('./pipes/ensure-validator.cjs');
|
|
6
6
|
const require_protocols_rollup_pipes_verify_signers = require('./pipes/verify-signers.cjs');
|
|
7
7
|
const require_protocols_rollup_pipes_verify_status = require('./pipes/verify-status.cjs');
|
|
8
|
+
let _arcblock_did_util = require("@arcblock/did-util");
|
|
8
9
|
let _ocap_state = require("@ocap/state");
|
|
9
10
|
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
10
11
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
11
|
-
let _arcblock_did_util = require("@arcblock/did-util");
|
|
12
12
|
let _arcblock_validator = require("@arcblock/validator");
|
|
13
13
|
|
|
14
14
|
//#region src/protocols/rollup/close.ts
|
|
@@ -7,18 +7,18 @@ const require_protocols_rollup_pipes_ensure_validator = require('./pipes/ensure-
|
|
|
7
7
|
const require_protocols_rollup_pipes_verify_signers = require('./pipes/verify-signers.cjs');
|
|
8
8
|
const require_protocols_rollup_pipes_verify_status = require('./pipes/verify-status.cjs');
|
|
9
9
|
const require_protocols_rollup_pipes_verify_evidence = require('./pipes/verify-evidence.cjs');
|
|
10
|
+
let _arcblock_did_util = require("@arcblock/did-util");
|
|
10
11
|
let _ocap_state = require("@ocap/state");
|
|
11
12
|
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
12
13
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
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);
|
|
13
17
|
let lodash_pick = require("lodash/pick");
|
|
14
18
|
lodash_pick = require_rolldown_runtime.__toESM(lodash_pick);
|
|
15
|
-
let _arcblock_did_util = require("@arcblock/did-util");
|
|
16
19
|
let debug = require("debug");
|
|
17
20
|
debug = require_rolldown_runtime.__toESM(debug);
|
|
18
21
|
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
22
|
let _arcblock_validator = require("@arcblock/validator");
|
|
23
23
|
let _ocap_merkle_tree = require("@ocap/merkle-tree");
|
|
24
24
|
_ocap_merkle_tree = require_rolldown_runtime.__toESM(_ocap_merkle_tree);
|
|
@@ -34,10 +34,7 @@ const schema = _arcblock_validator.v.pipe(_arcblock_validator.v.object({
|
|
|
34
34
|
previousHash: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_arcblock_validator.v.string())),
|
|
35
35
|
txsHash: txHashString,
|
|
36
36
|
txsList: _arcblock_validator.v.pipe(_arcblock_validator.v.array(txHashString), _arcblock_validator.v.minLength(1)),
|
|
37
|
-
proposer: (0, _arcblock_validator.vDID)({
|
|
38
|
-
prefix: true,
|
|
39
|
-
wallet: "ethereum"
|
|
40
|
-
}),
|
|
37
|
+
proposer: (0, _arcblock_validator.vDID)({ prefix: true }),
|
|
41
38
|
signaturesList: _arcblock_validator.v.pipe(_arcblock_validator.schemas.multiSig, _arcblock_validator.v.minLength(1)),
|
|
42
39
|
rollup: (0, _arcblock_validator.vDID)({
|
|
43
40
|
prefix: true,
|
|
@@ -79,6 +76,10 @@ runner.use(require_protocols_rollup_pipes_ensure_validator.default(false));
|
|
|
79
76
|
runner.use(require_protocols_rollup_pipes_verify_status.default({ closed: false }));
|
|
80
77
|
runner.use((context, next) => {
|
|
81
78
|
const { itx, rollupState } = context;
|
|
79
|
+
if (_ocap_state.rollup.getRollupTargetType(rollupState) === "EVM" && (0, _arcblock_validator.vValidate)((0, _arcblock_validator.vDID)({
|
|
80
|
+
prefix: true,
|
|
81
|
+
wallet: "ethereum"
|
|
82
|
+
}), itx.proposer).error) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "\"proposer\" Expected wallet type to be \"ethereum\""));
|
|
82
83
|
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}`));
|
|
83
84
|
const itxTxsList = (0, _ocap_util_lib_get_list_field.getListField)(itx, "txs");
|
|
84
85
|
if (itx.governance) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IAccountState, IReadyContext, IRollupBlock, ITokenState, ITxState, IWithRollup, IWithSender, IWithSigners, IWithStakes, TCreateRollupBlockTx } from "@ocap/types";
|
|
2
|
-
import { Runner } from "@ocap/tx-pipeline";
|
|
3
2
|
import { BN } from "@ocap/util";
|
|
3
|
+
import { Runner } from "@ocap/tx-pipeline";
|
|
4
4
|
|
|
5
5
|
//#region src/protocols/rollup/create-block.d.ts
|
|
6
6
|
/** Token change for updates */
|
|
@@ -3,17 +3,17 @@ const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
|
3
3
|
const require_util = require('../../util.cjs');
|
|
4
4
|
const require_pipes_ensure_cost = require('../../pipes/ensure-cost.cjs');
|
|
5
5
|
const require_pipes_ensure_gas = require('../../pipes/ensure-gas.cjs');
|
|
6
|
+
let _arcblock_did = require("@arcblock/did");
|
|
7
|
+
let _arcblock_did_util = require("@arcblock/did-util");
|
|
6
8
|
let _ocap_state = require("@ocap/state");
|
|
7
9
|
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
8
10
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
9
|
-
let _arcblock_did = require("@arcblock/did");
|
|
10
|
-
let _arcblock_did_util = require("@arcblock/did-util");
|
|
11
|
-
let debug = require("debug");
|
|
12
|
-
debug = require_rolldown_runtime.__toESM(debug);
|
|
13
|
-
let _ocap_message = require("@ocap/message");
|
|
14
11
|
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
15
12
|
let lodash_cloneDeep = require("lodash/cloneDeep");
|
|
16
13
|
lodash_cloneDeep = require_rolldown_runtime.__toESM(lodash_cloneDeep);
|
|
14
|
+
let debug = require("debug");
|
|
15
|
+
debug = require_rolldown_runtime.__toESM(debug);
|
|
16
|
+
let _ocap_message = require("@ocap/message");
|
|
17
17
|
let lodash_isEmpty = require("lodash/isEmpty");
|
|
18
18
|
lodash_isEmpty = require_rolldown_runtime.__toESM(lodash_isEmpty);
|
|
19
19
|
|
|
@@ -24,8 +24,13 @@ runner.use(_ocap_tx_pipeline.pipes.VerifyMultiSig(0));
|
|
|
24
24
|
runner.use((context, next) => {
|
|
25
25
|
const { itx } = context;
|
|
26
26
|
context.formattedItx = (0, _ocap_message.formatMessage)("CreateRollupTx", itx);
|
|
27
|
+
const decodedData = require_util.decodeAnySafe(itx.data ?? null);
|
|
28
|
+
context.rollupData = decodedData;
|
|
27
29
|
try {
|
|
28
|
-
_ocap_state.rollup.create(
|
|
30
|
+
_ocap_state.rollup.create({
|
|
31
|
+
...context.formattedItx,
|
|
32
|
+
data: decodedData
|
|
33
|
+
}, context);
|
|
29
34
|
} catch (err) {
|
|
30
35
|
return next(new _ocap_util_lib_error.CustomError("INVALID_TX", err.message));
|
|
31
36
|
}
|
|
@@ -51,7 +56,13 @@ runner.use(_ocap_tx_pipeline.pipes.VerifyInfo([
|
|
|
51
56
|
error: "INVALID_TX",
|
|
52
57
|
message: "Seed validator must use ethereum compatible address",
|
|
53
58
|
fn: (ctx) => {
|
|
54
|
-
|
|
59
|
+
const context = ctx;
|
|
60
|
+
const targetType = _ocap_state.rollup.getRollupTargetType({
|
|
61
|
+
...context.formattedItx,
|
|
62
|
+
data: context.rollupData
|
|
63
|
+
});
|
|
64
|
+
const seedValidators = context.formattedItx?.seedValidators || [];
|
|
65
|
+
return targetType === "EVM" ? seedValidators.every(({ address }) => (0, _arcblock_did.isEthereumDid)(address)) : true;
|
|
55
66
|
}
|
|
56
67
|
},
|
|
57
68
|
{
|
|
@@ -7,12 +7,12 @@ const require_protocols_rollup_pipes_verify_signers = require('./pipes/verify-si
|
|
|
7
7
|
const require_protocols_rollup_pipes_verify_status = require('./pipes/verify-status.cjs');
|
|
8
8
|
const require_protocols_rollup_pipes_verify_evidence = require('./pipes/verify-evidence.cjs');
|
|
9
9
|
const require_index = require('../../node_modules/valibot/dist/index.cjs');
|
|
10
|
+
let _arcblock_did = require("@arcblock/did");
|
|
11
|
+
let _arcblock_did_util = require("@arcblock/did-util");
|
|
10
12
|
let _ocap_state = require("@ocap/state");
|
|
11
13
|
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
12
14
|
let _ocap_util = require("@ocap/util");
|
|
13
15
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
14
|
-
let _arcblock_did = require("@arcblock/did");
|
|
15
|
-
let _arcblock_did_util = require("@arcblock/did-util");
|
|
16
16
|
let debug = require("debug");
|
|
17
17
|
debug = require_rolldown_runtime.__toESM(debug);
|
|
18
18
|
let _arcblock_validator = require("@arcblock/validator");
|
|
@@ -52,7 +52,7 @@ runner.use((context, next) => {
|
|
|
52
52
|
address: tx.from,
|
|
53
53
|
endpoint: itx.endpoint
|
|
54
54
|
};
|
|
55
|
-
if ((0, _arcblock_did.isEthereumDid)(tx.from) === false) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "Invalid tx.from: only ethereum compatible address can join rollup"));
|
|
55
|
+
if (_ocap_state.rollup.getRollupTargetType(rollupState) === "EVM" && (0, _arcblock_did.isEthereumDid)(tx.from) === false) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "Invalid tx.from: only ethereum compatible address can join rollup"));
|
|
56
56
|
if (rollupState?.validators.some((x) => x.address === validator.address)) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Address ${validator.address} already exist in validators`));
|
|
57
57
|
if (rollupState?.validators.some((x) => (0, url_join.default)(x.endpoint, "/") === (0, url_join.default)(validator.endpoint, "/"))) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Endpoint ${validator.endpoint} already exist in validators`));
|
|
58
58
|
context.newValidator = validator;
|
|
@@ -7,10 +7,10 @@ const require_protocols_rollup_pipes_verify_signers = require('./pipes/verify-si
|
|
|
7
7
|
const require_protocols_rollup_pipes_verify_status = require('./pipes/verify-status.cjs');
|
|
8
8
|
const require_protocols_rollup_pipes_verify_evidence = require('./pipes/verify-evidence.cjs');
|
|
9
9
|
const require_index = require('../../node_modules/valibot/dist/index.cjs');
|
|
10
|
+
let _arcblock_did_util = require("@arcblock/did-util");
|
|
10
11
|
let _ocap_state = require("@ocap/state");
|
|
11
12
|
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
12
13
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
13
|
-
let _arcblock_did_util = require("@arcblock/did-util");
|
|
14
14
|
let debug = require("debug");
|
|
15
15
|
debug = require_rolldown_runtime.__toESM(debug);
|
|
16
16
|
let _arcblock_validator = require("@arcblock/validator");
|
|
@@ -17,10 +17,7 @@ const schema = _arcblock_validator.v.pipe(_arcblock_validator.v.object({
|
|
|
17
17
|
prefix: true,
|
|
18
18
|
role: "ROLE_ROLLUP"
|
|
19
19
|
}),
|
|
20
|
-
to: (
|
|
21
|
-
prefix: true,
|
|
22
|
-
wallet: "ethereum"
|
|
23
|
-
}),
|
|
20
|
+
to: _arcblock_validator.v.pipe(_arcblock_validator.v.string(), _arcblock_validator.v.minLength(1)),
|
|
24
21
|
type: _arcblock_validator.v.pipe(_arcblock_validator.v.string(), _arcblock_validator.v.trim(), _arcblock_validator.v.check((s) => s === "vault" || s === "contract", "Must be vault or contract")),
|
|
25
22
|
message: _arcblock_validator.v.pipe(_arcblock_validator.v.string(), _arcblock_validator.v.trim(), _arcblock_validator.v.minLength(1), _arcblock_validator.v.maxLength(512)),
|
|
26
23
|
data: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_arcblock_validator.v.any()))
|
|
@@ -35,6 +32,12 @@ runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
|
35
32
|
status: "INVALID_ROLLUP",
|
|
36
33
|
table: "rollup"
|
|
37
34
|
}));
|
|
35
|
+
runner.use((context, next) => {
|
|
36
|
+
const { itx, rollupState } = context;
|
|
37
|
+
const targetType = _ocap_state.rollup.getRollupTargetType(rollupState);
|
|
38
|
+
if (!(itx.type === "vault" ? Boolean(itx.to) && _ocap_state.rollup.isValidRollupVaultAddress(itx.to, targetType) : _ocap_state.rollup.isValidRollupContractAddress(itx.to, targetType))) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "Invalid itx: \"to\" Expected wallet type to be \"ethereum\""));
|
|
39
|
+
return next();
|
|
40
|
+
});
|
|
38
41
|
runner.use(require_protocols_rollup_pipes_ensure_validator.default(true));
|
|
39
42
|
runner.use(require_protocols_rollup_pipes_verify_status.default({
|
|
40
43
|
paused: true,
|