@ocap/tx-protocols 1.30.26 → 1.31.1
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 +11 -2
- package/esm/execute.mjs +724 -80
- package/esm/gas-security-guard.d.mts +375 -0
- package/esm/gas-security-guard.mjs +1103 -0
- package/esm/index.d.mts +36 -6
- package/esm/index.mjs +4 -2
- package/esm/pipes/ensure-cost.mjs +335 -59
- 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 +115 -11
- package/esm/protocols/governance/return-stake.mjs +44 -12
- package/esm/protocols/governance/revoke-ledger.d.mts +34 -0
- package/esm/protocols/governance/revoke-ledger.mjs +179 -0
- package/esm/protocols/governance/revoke-stake.mjs +25 -5
- package/esm/protocols/governance/slash-stake.mjs +72 -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 +724 -76
- package/lib/execute.d.cts +11 -2
- package/lib/gas-security-guard.cjs +1142 -0
- package/lib/gas-security-guard.d.cts +375 -0
- package/lib/index.cjs +124 -1
- package/lib/index.d.cts +37 -7
- package/lib/pipes/ensure-cost.cjs +334 -58
- 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 +115 -10
- 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-ledger.cjs +184 -0
- package/lib/protocols/governance/revoke-ledger.d.cts +34 -0
- package/lib/protocols/governance/revoke-stake.cjs +25 -5
- package/lib/protocols/governance/revoke-stake.d.cts +1 -1
- package/lib/protocols/governance/slash-stake.cjs +72 -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
|
@@ -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,
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
2
|
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
3
|
+
let _arcblock_did = require("@arcblock/did");
|
|
4
|
+
let _ocap_state = require("@ocap/state");
|
|
3
5
|
let _ocap_util = require("@ocap/util");
|
|
4
6
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
7
|
+
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
5
8
|
let lodash_get = require("lodash/get");
|
|
6
9
|
lodash_get = require_rolldown_runtime.__toESM(lodash_get);
|
|
7
|
-
let _arcblock_did = require("@arcblock/did");
|
|
8
|
-
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
9
10
|
let _ocap_wallet = require("@ocap/wallet");
|
|
10
11
|
|
|
11
12
|
//#region src/protocols/rollup/pipes/verify-evidence.ts
|
|
@@ -19,9 +20,16 @@ function CreateVerifyEvidencePipe({ evidenceKey, signaturesKey, verifyMethod = "
|
|
|
19
20
|
for (const sig of signatures) {
|
|
20
21
|
const { signer, pk, delegator, signature } = sig;
|
|
21
22
|
const address = delegator || signer;
|
|
23
|
+
if ((0, _arcblock_did.isFromPublicKey)(address, pk) === false) return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", `Signature for evidence signer ${address} and pk do not match`));
|
|
22
24
|
const wallet = (0, _ocap_wallet.fromPublicKey)(pk, (0, _arcblock_did.toTypeInfo)(address));
|
|
23
25
|
try {
|
|
24
|
-
|
|
26
|
+
const targetType = _ocap_state.rollup.getRollupTargetType(context.rollupState);
|
|
27
|
+
const effectiveMethod = verifyMethod === "ethVerify" && targetType !== "EVM" && !(0, _arcblock_did.isEthereumDid)(address) ? "verify" : verifyMethod;
|
|
28
|
+
const hexEvidence = (0, _ocap_util.toHex)(evidence);
|
|
29
|
+
const hexSig = (0, _ocap_util.toHex)(signature);
|
|
30
|
+
let verified = await wallet[effectiveMethod](hexEvidence, hexSig);
|
|
31
|
+
if (!verified && verifyMethod === "ethVerify" && targetType !== "EVM" && (0, _arcblock_did.isEthereumDid)(address)) verified = await wallet.verify(hexEvidence, hexSig);
|
|
32
|
+
if (verified === false) return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", `Signature for evidence from ${address} is not valid`));
|
|
25
33
|
} catch (err) {
|
|
26
34
|
return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", `Signature for evidence from ${address} verify failed: ${err.message}`));
|
|
27
35
|
}
|
|
@@ -95,11 +95,16 @@ runner.use(_ocap_tx_pipeline.pipes.TakeStateSnapshot());
|
|
|
95
95
|
runner.use(async (context, next) => {
|
|
96
96
|
const { tx, itx, rollupState, statedb, senderState, senderUpdates, updateVaults } = context;
|
|
97
97
|
const data = require_util.decodeAnySafe(itx.data ?? null);
|
|
98
|
+
const sanitizedItx = { ...itx };
|
|
99
|
+
delete sanitizedItx.reserves;
|
|
100
|
+
delete sanitizedItx.targetType;
|
|
101
|
+
delete sanitizedItx.targetChainId;
|
|
102
|
+
delete sanitizedItx.enforceReserveWatermark;
|
|
98
103
|
const [newSenderState, newRollupState] = await Promise.all([statedb.account.update(senderState.address, _ocap_state.account.update(senderState, {
|
|
99
104
|
nonce: tx.nonce,
|
|
100
105
|
...senderUpdates
|
|
101
106
|
}, context), context), statedb.rollup.update(itx.rollup, _ocap_state.rollup.update(rollupState, {
|
|
102
|
-
...
|
|
107
|
+
...sanitizedItx,
|
|
103
108
|
data
|
|
104
109
|
}, context), context)]);
|
|
105
110
|
if (updateVaults) await updateVaults();
|
|
@@ -3,15 +3,15 @@ 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_util = require("@arcblock/did-util");
|
|
6
7
|
let _ocap_state = require("@ocap/state");
|
|
7
8
|
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
8
9
|
let _ocap_util = require("@ocap/util");
|
|
9
10
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
10
|
-
let _arcblock_did_util = require("@arcblock/did-util");
|
|
11
|
-
let debug = require("debug");
|
|
12
|
-
debug = require_rolldown_runtime.__toESM(debug);
|
|
13
11
|
let lodash_cloneDeep = require("lodash/cloneDeep");
|
|
14
12
|
lodash_cloneDeep = require_rolldown_runtime.__toESM(lodash_cloneDeep);
|
|
13
|
+
let debug = require("debug");
|
|
14
|
+
debug = require_rolldown_runtime.__toESM(debug);
|
|
15
15
|
let _arcblock_validator = require("@arcblock/validator");
|
|
16
16
|
let lodash_uniq = require("lodash/uniq");
|
|
17
17
|
lodash_uniq = require_rolldown_runtime.__toESM(lodash_uniq);
|
|
@@ -33,11 +33,11 @@ const schema = _arcblock_validator.v.pipe(_arcblock_validator.v.object({
|
|
|
33
33
|
symbol: _arcblock_validator.v.pipe(_arcblock_validator.v.string(), _arcblock_validator.v.minLength(2), _arcblock_validator.v.maxLength(6), _arcblock_validator.v.toUpperCase()),
|
|
34
34
|
unit: _arcblock_validator.v.pipe(_arcblock_validator.v.string(), _arcblock_validator.v.minLength(1), _arcblock_validator.v.maxLength(6), _arcblock_validator.v.toLowerCase()),
|
|
35
35
|
decimal: _arcblock_validator.v.pipe(_arcblock_validator.v.number(), _arcblock_validator.v.minValue(2), _arcblock_validator.v.maxValue(18)),
|
|
36
|
-
icon: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_arcblock_validator.v.
|
|
36
|
+
icon: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_arcblock_validator.v.string())),
|
|
37
37
|
totalSupply: (0, _arcblock_validator.vBN)((0, _arcblock_validator.vBNGreater)(0), (0, _arcblock_validator.vBNMax)(MAX_TOTAL_SUPPLY)),
|
|
38
38
|
initialSupply: (0, _arcblock_validator.vBN)((0, _arcblock_validator.vBNGreater)(0)),
|
|
39
39
|
maxTotalSupply: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_arcblock_validator.v.union([(0, _arcblock_validator.vBN)((0, _arcblock_validator.vBNGreater)(0)), _arcblock_validator.v.literal("")]))),
|
|
40
|
-
foreignToken: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_arcblock_validator.schemas.foreignToken)),
|
|
40
|
+
foreignToken: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_ocap_state.token.multiChainForeignTokenSchema ?? _arcblock_validator.schemas.foreignToken)),
|
|
41
41
|
spendersList: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_arcblock_validator.v.pipe(_arcblock_validator.v.array((0, _arcblock_validator.vDID)({ prefix: true })), _arcblock_validator.v.maxLength(30)))),
|
|
42
42
|
tokenFactoryAddress: _arcblock_validator.v.optional((0, _arcblock_validator.vForbidden)("tokenFactoryAddress is forbidden")),
|
|
43
43
|
data: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_arcblock_validator.v.any()))
|
|
@@ -51,6 +51,13 @@ runner.use(({ itx }, next) => {
|
|
|
51
51
|
const spendersList = value.spendersList;
|
|
52
52
|
itx.spenders = spendersList?.length ? (0, lodash_uniq.default)(spendersList) : null;
|
|
53
53
|
delete itx.spendersList;
|
|
54
|
+
if (typeof itx.icon === "string" && itx.icon.trim()) {
|
|
55
|
+
const trimmedIcon = itx.icon.trim();
|
|
56
|
+
if (trimmedIcon.startsWith("<svg")) {
|
|
57
|
+
if (Buffer.byteLength(trimmedIcon, "utf8") > 16 * 1024) return next(new _ocap_util_lib_error.CustomError("INVALID_ICON", "Token Icon must be less than 16k"));
|
|
58
|
+
if (_ocap_state.token.sanitizeTokenSvg(trimmedIcon) !== trimmedIcon) return next(new _ocap_util_lib_error.CustomError("INVALID_ICON", "Token Icon contains unsafe SVG elements or attributes"));
|
|
59
|
+
} else if (/^data:/i.test(trimmedIcon) && !_ocap_state.token.iconToNftDisplay(trimmedIcon)) return next(new _ocap_util_lib_error.CustomError("INVALID_ICON", "Token Icon data URI must be a safe image format"));
|
|
60
|
+
}
|
|
54
61
|
return next();
|
|
55
62
|
});
|
|
56
63
|
runner.use(_ocap_tx_pipeline.pipes.VerifyInfo([{
|
|
@@ -84,6 +91,7 @@ runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
|
84
91
|
stateKey: "delegatorState",
|
|
85
92
|
addressKey: "tx.delegator"
|
|
86
93
|
}));
|
|
94
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyBlocked({ stateKeys: ["senderState", "delegatorState"] }));
|
|
87
95
|
runner.use(_ocap_tx_pipeline.pipes.VerifyDelegation({
|
|
88
96
|
type: "signature",
|
|
89
97
|
signerKey: "senderState",
|
|
@@ -129,20 +137,23 @@ runner.use(async (context, next) => {
|
|
|
129
137
|
delegatorUpdates.tokens = delegatorState.tokens || {};
|
|
130
138
|
delegatorUpdates.tokens[itx.address] = itx.initialSupply;
|
|
131
139
|
} else updates.tokens[itx.address] = itx.initialSupply;
|
|
140
|
+
const initialTokenState = _ocap_state.token.create({
|
|
141
|
+
...(0, lodash_cloneDeep.default)(itx),
|
|
142
|
+
data,
|
|
143
|
+
issuer: owner,
|
|
144
|
+
type: "Token"
|
|
145
|
+
}, context);
|
|
146
|
+
const charterAsset = _ocap_state.token.buildTokenCharterAssetState(initialTokenState, context, owner);
|
|
132
147
|
const [newSenderState, tokenState, newDelegatorState, newDelegationState] = await Promise.all([
|
|
133
148
|
statedb.account.update(senderState.address, _ocap_state.account.update(senderState, {
|
|
134
149
|
nonce: tx.nonce,
|
|
135
|
-
pk: tx.pk,
|
|
150
|
+
pk: tx.delegator ? senderState.pk : tx.pk,
|
|
136
151
|
...senderUpdates
|
|
137
152
|
}, context), context),
|
|
138
|
-
statedb.token.create(itx.address,
|
|
139
|
-
...(0, lodash_cloneDeep.default)(itx),
|
|
140
|
-
data,
|
|
141
|
-
issuer: owner,
|
|
142
|
-
type: "Token"
|
|
143
|
-
}, context), context),
|
|
153
|
+
statedb.token.create(itx.address, initialTokenState, context),
|
|
144
154
|
delegatorState ? statedb.account.update(delegatorState.address, _ocap_state.account.update(delegatorState, delegatorUpdates, context), context) : null,
|
|
145
|
-
context.isDelegationChanged ? statedb.delegation.update(delegationState.address, _ocap_state.delegation.update(delegationState, {}, context), context) : delegationState
|
|
155
|
+
context.isDelegationChanged ? statedb.delegation.update(delegationState.address, _ocap_state.delegation.update(delegationState, {}, context), context) : delegationState,
|
|
156
|
+
statedb.asset?.create ? Promise.resolve(statedb.asset.get?.(charterAsset.address, context)).then((existing) => existing && statedb.asset.update ? statedb.asset.update(charterAsset.address, charterAsset, context) : statedb.asset.create(charterAsset.address, charterAsset, context)) : null
|
|
146
157
|
]);
|
|
147
158
|
if (updateVaults) await updateVaults();
|
|
148
159
|
context.senderState = newSenderState;
|