@ocap/tx-protocols 1.29.27 → 1.30.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/_virtual/rolldown_runtime.mjs +32 -0
- package/esm/node_modules/bn.js/lib/bn.mjs +2551 -0
- package/esm/node_modules/valibot/dist/index.mjs +663 -0
- package/esm/protocols/account/delegate.mjs +42 -36
- package/esm/protocols/account/migrate.mjs +7 -10
- package/esm/protocols/account/revoke-delegate.mjs +11 -11
- package/esm/protocols/asset/acquire-v2.mjs +19 -13
- package/esm/protocols/asset/acquire-v3.mjs +17 -14
- package/esm/protocols/asset/consume.mjs +9 -9
- package/esm/protocols/asset/create.mjs +2 -1
- package/esm/protocols/asset/mint.mjs +19 -13
- package/esm/protocols/asset/update.mjs +11 -11
- package/esm/protocols/governance/claim-stake.mjs +10 -10
- package/esm/protocols/governance/return-stake.mjs +11 -11
- package/esm/protocols/governance/revoke-stake.mjs +10 -10
- package/esm/protocols/governance/slash-stake.mjs +11 -11
- package/esm/protocols/governance/stake.mjs +16 -16
- package/esm/protocols/rollup/claim-reward.mjs +21 -18
- package/esm/protocols/rollup/close.mjs +16 -13
- package/esm/protocols/rollup/create-block.mjs +25 -22
- package/esm/protocols/rollup/join.mjs +14 -12
- package/esm/protocols/rollup/leave.mjs +12 -11
- package/esm/protocols/rollup/migrate.mjs +15 -12
- package/esm/protocols/rollup/pause.mjs +9 -9
- package/esm/protocols/rollup/resume.mjs +9 -9
- package/esm/protocols/rollup/update.mjs +31 -28
- package/esm/protocols/token/create.mjs +25 -22
- package/esm/protocols/token/deposit-v2.mjs +20 -14
- package/esm/protocols/token/withdraw-v2.mjs +20 -14
- package/esm/protocols/token-factory/burn.mjs +12 -12
- package/esm/protocols/token-factory/create.mjs +45 -37
- package/esm/protocols/token-factory/mint.mjs +13 -12
- package/esm/protocols/token-factory/update.mjs +21 -21
- package/esm/protocols/trade/exchange-v2.mjs +15 -15
- package/esm/protocols/trade/transfer-v2.mjs +12 -12
- package/esm/protocols/trade/transfer-v3.mjs +7 -10
- package/esm/util.d.mts +3 -1
- package/esm/util.mjs +16 -1
- package/lib/_virtual/rolldown_runtime.cjs +2 -0
- package/lib/node_modules/bn.js/lib/bn.cjs +2554 -0
- package/lib/node_modules/valibot/dist/index.cjs +683 -0
- package/lib/protocols/account/delegate.cjs +41 -35
- package/lib/protocols/account/migrate.cjs +6 -9
- package/lib/protocols/account/revoke-delegate.cjs +10 -10
- package/lib/protocols/asset/acquire-v2.cjs +18 -12
- package/lib/protocols/asset/acquire-v3.cjs +16 -13
- package/lib/protocols/asset/consume.cjs +8 -8
- package/lib/protocols/asset/create.cjs +2 -1
- package/lib/protocols/asset/mint.cjs +18 -12
- package/lib/protocols/asset/update.cjs +10 -10
- package/lib/protocols/governance/claim-stake.cjs +9 -9
- package/lib/protocols/governance/return-stake.cjs +10 -10
- package/lib/protocols/governance/revoke-stake.cjs +9 -9
- package/lib/protocols/governance/slash-stake.cjs +10 -10
- package/lib/protocols/governance/stake.cjs +15 -15
- package/lib/protocols/rollup/claim-reward.cjs +20 -17
- package/lib/protocols/rollup/close.cjs +15 -12
- package/lib/protocols/rollup/create-block.cjs +24 -21
- package/lib/protocols/rollup/join.cjs +13 -11
- package/lib/protocols/rollup/leave.cjs +11 -10
- package/lib/protocols/rollup/migrate.cjs +14 -11
- package/lib/protocols/rollup/pause.cjs +8 -8
- package/lib/protocols/rollup/resume.cjs +8 -8
- package/lib/protocols/rollup/update.cjs +29 -27
- package/lib/protocols/token/create.cjs +23 -20
- package/lib/protocols/token/deposit-v2.cjs +19 -13
- package/lib/protocols/token/withdraw-v2.cjs +19 -13
- package/lib/protocols/token-factory/burn.cjs +11 -11
- package/lib/protocols/token-factory/create.cjs +43 -35
- package/lib/protocols/token-factory/mint.cjs +12 -11
- package/lib/protocols/token-factory/update.cjs +19 -19
- package/lib/protocols/trade/exchange-v2.cjs +14 -14
- package/lib/protocols/trade/transfer-v2.cjs +11 -11
- package/lib/protocols/trade/transfer-v3.cjs +6 -9
- package/lib/util.cjs +17 -0
- package/lib/util.d.cts +3 -1
- package/package.json +16 -18
- package/tools/fixtures.ts +2 -1
|
@@ -12,26 +12,29 @@ import { BN } from "@ocap/util";
|
|
|
12
12
|
import Debug from "debug";
|
|
13
13
|
import cloneDeep from "lodash/cloneDeep.js";
|
|
14
14
|
import groupBy from "lodash/groupBy.js";
|
|
15
|
-
import {
|
|
15
|
+
import { patterns, v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
16
16
|
import uniqBy from "lodash/uniqBy.js";
|
|
17
17
|
|
|
18
18
|
//#region src/protocols/rollup/claim-reward.ts
|
|
19
19
|
const debug = Debug("@ocap/tx-protocols:claim-block-reward");
|
|
20
20
|
const runner = new Runner("claim_block_reward");
|
|
21
|
-
const schema =
|
|
22
|
-
rollup:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
21
|
+
const schema = v.pipe(v.object({
|
|
22
|
+
rollup: vDID({
|
|
23
|
+
prefix: true,
|
|
24
|
+
role: "ROLE_ROLLUP"
|
|
25
|
+
}),
|
|
26
|
+
blockHeight: v.pipe(v.number(), v.integer(), v.check((n) => n > 0, "Must be > 0")),
|
|
27
|
+
blockHash: v.pipe(v.string(), v.regex(patterns.txHash)),
|
|
28
|
+
evidence: v.object({ hash: v.pipe(v.string(), v.regex(patterns.txHash)) }),
|
|
29
|
+
publisher: vDID({
|
|
30
|
+
prefix: true,
|
|
31
|
+
wallet: "ethereum"
|
|
32
|
+
}),
|
|
33
|
+
data: v.optional(v.nullable(v.any()))
|
|
34
|
+
}), vStripUnknown());
|
|
32
35
|
runner.use((context, next) => {
|
|
33
36
|
const { tx: tx$1, itx } = context;
|
|
34
|
-
const { error } = schema
|
|
37
|
+
const { error } = vValidate(schema, itx);
|
|
35
38
|
if (error) return next(new CustomError("INVALID_TX", error.message));
|
|
36
39
|
if (tx$1.from !== itx.publisher) return next(new CustomError("INVALID_TX", "itx.publisher must be same with tx.from"));
|
|
37
40
|
context.lockerAddress = getRewardLocker(itx.rollup);
|
|
@@ -186,8 +189,8 @@ runner.use((context, next) => {
|
|
|
186
189
|
const blockSignatures = blockState.signatures;
|
|
187
190
|
const validators = txSignatures.map((s) => s.signer).concat(blockSignatures.map((s) => s.signer));
|
|
188
191
|
const validatorShare = validator.div(new BN(validators.length));
|
|
189
|
-
validators.forEach((v) => changes.account.push({
|
|
190
|
-
address: v,
|
|
192
|
+
validators.forEach((v$1) => changes.account.push({
|
|
193
|
+
address: v$1,
|
|
191
194
|
delta: validatorShare.toString(10),
|
|
192
195
|
action: "fee"
|
|
193
196
|
}));
|
|
@@ -206,9 +209,9 @@ runner.use((context, next) => {
|
|
|
206
209
|
}, {}),
|
|
207
210
|
rateBase: new BN(validators.length)
|
|
208
211
|
});
|
|
209
|
-
Object.keys(validatorShares).forEach((v) => changes.account.push({
|
|
210
|
-
address: v,
|
|
211
|
-
delta: validatorShares[v],
|
|
212
|
+
Object.keys(validatorShares).forEach((v$1) => changes.account.push({
|
|
213
|
+
address: v$1,
|
|
214
|
+
delta: validatorShares[v$1],
|
|
212
215
|
action: "fee"
|
|
213
216
|
}));
|
|
214
217
|
}
|
|
@@ -7,24 +7,27 @@ import { Runner, pipes } from "@ocap/tx-pipeline";
|
|
|
7
7
|
import { CustomError } from "@ocap/util/lib/error";
|
|
8
8
|
import { toStakeAddress } from "@arcblock/did-util";
|
|
9
9
|
import { account, rollup, stake } from "@ocap/state";
|
|
10
|
-
import {
|
|
10
|
+
import { v, vBN, vBNPositive, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
11
11
|
|
|
12
12
|
//#region src/protocols/rollup/close.ts
|
|
13
13
|
const runner = new Runner("close_rollup");
|
|
14
|
-
const schema =
|
|
15
|
-
rollup:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
address: Joi.DID().prefix().wallet("ethereum").required(),
|
|
19
|
-
value: Joi.BN().positive().required()
|
|
14
|
+
const schema = v.pipe(v.object({
|
|
15
|
+
rollup: vDID({
|
|
16
|
+
prefix: true,
|
|
17
|
+
role: "ROLE_ROLLUP"
|
|
20
18
|
}),
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
message: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(512)),
|
|
20
|
+
token: v.optional(v.object({
|
|
21
|
+
address: vDID({
|
|
22
|
+
prefix: true,
|
|
23
|
+
wallet: "ethereum"
|
|
24
|
+
}),
|
|
25
|
+
value: vBN(vBNPositive())
|
|
26
|
+
})),
|
|
27
|
+
data: v.optional(v.nullable(v.any()))
|
|
28
|
+
}), vStripUnknown());
|
|
26
29
|
runner.use(({ itx }, next) => {
|
|
27
|
-
const { error } = schema
|
|
30
|
+
const { error } = vValidate(schema, itx);
|
|
28
31
|
return next(error ? new CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
|
|
29
32
|
});
|
|
30
33
|
runner.use(pipes.ExtractState({
|
|
@@ -14,37 +14,40 @@ import Debug from "debug";
|
|
|
14
14
|
import { formatMessage } from "@ocap/message";
|
|
15
15
|
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
16
16
|
import cloneDeep from "lodash/cloneDeep.js";
|
|
17
|
-
import {
|
|
17
|
+
import { patterns, schemas, v, vBN, vBNMin, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
18
18
|
import MerkleTree from "@ocap/merkle-tree";
|
|
19
19
|
|
|
20
20
|
//#region src/protocols/rollup/create-block.ts
|
|
21
21
|
const debug = Debug("@ocap/tx-protocols:create-rollup-block");
|
|
22
22
|
const runner = new Runner("create_rollup_block");
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
const txHashString = v.pipe(v.string(), v.regex(patterns.txHash));
|
|
24
|
+
const schema = v.pipe(v.object({
|
|
25
|
+
hash: txHashString,
|
|
26
|
+
height: v.pipe(v.number(), v.integer(), v.check((n) => n > 0, "Must be greater than 0")),
|
|
27
|
+
merkleRoot: txHashString,
|
|
28
|
+
previousHash: v.optional(v.nullable(v.string())),
|
|
29
|
+
txsHash: txHashString,
|
|
30
|
+
txsList: v.pipe(v.array(txHashString), v.minLength(1)),
|
|
31
|
+
proposer: vDID({
|
|
32
|
+
prefix: true,
|
|
33
|
+
wallet: "ethereum"
|
|
31
34
|
}),
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
minReward:
|
|
38
|
-
governance:
|
|
39
|
-
data:
|
|
40
|
-
}).
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
});
|
|
35
|
+
signaturesList: v.pipe(schemas.multiSig, v.minLength(1)),
|
|
36
|
+
rollup: vDID({
|
|
37
|
+
prefix: true,
|
|
38
|
+
role: "ROLE_ROLLUP"
|
|
39
|
+
}),
|
|
40
|
+
minReward: vBN(vBNMin(0)),
|
|
41
|
+
governance: v.optional(v.boolean(), false),
|
|
42
|
+
data: v.optional(v.nullable(v.any()))
|
|
43
|
+
}), v.forward(v.check((input) => {
|
|
44
|
+
if (input.height === 1) return true;
|
|
45
|
+
return typeof input.previousHash === "string" && patterns.txHash.test(input.previousHash);
|
|
46
|
+
}, "previousHash must match txHash pattern when height > 1"), ["previousHash"]), vStripUnknown());
|
|
44
47
|
runner.use((context, next) => {
|
|
45
48
|
const { tx: tx$1, itx } = context;
|
|
46
49
|
context.formattedItx = formatMessage("CreateRollupBlockTx", itx);
|
|
47
|
-
const { error } = schema
|
|
50
|
+
const { error } = vValidate(schema, itx);
|
|
48
51
|
if (error) return next(new CustomError("INVALID_TX", error.message));
|
|
49
52
|
if (tx$1.from !== itx.proposer) return next(new CustomError("INVALID_TX", "itx.proposer must be same with tx.from"));
|
|
50
53
|
if (getListField(tx$1, "signatures").some((x) => x.signer === itx.proposer) === false) return next(new CustomError("INVALID_TX", "itx.proposer must exist in signatures"));
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { isHttpUrl } from "../../util.mjs";
|
|
1
2
|
import ensure_cost_default from "../../pipes/ensure-cost.mjs";
|
|
2
3
|
import ensure_gas_default from "../../pipes/ensure-gas.mjs";
|
|
3
4
|
import verify_signers_default from "./pipes/verify-signers.mjs";
|
|
4
5
|
import verify_status_default from "./pipes/verify-status.mjs";
|
|
5
6
|
import verify_evidence_default from "./pipes/verify-evidence.mjs";
|
|
7
|
+
import { any, check, minLength, nullable, object, optional, pipe, regex, string } from "../../node_modules/valibot/dist/index.mjs";
|
|
6
8
|
import { Runner, pipes } from "@ocap/tx-pipeline";
|
|
7
9
|
import { CustomError } from "@ocap/util/lib/error";
|
|
8
10
|
import { isEthereumDid } from "@arcblock/did";
|
|
@@ -10,25 +12,25 @@ import { toStakeAddress } from "@arcblock/did-util";
|
|
|
10
12
|
import { account, evidence, rollup, stake } from "@ocap/state";
|
|
11
13
|
import { BN, toHex } from "@ocap/util";
|
|
12
14
|
import Debug from "debug";
|
|
13
|
-
import {
|
|
15
|
+
import { patterns, schemas, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
14
16
|
import MerkleTree from "@ocap/merkle-tree";
|
|
15
17
|
import joinUrl from "url-join";
|
|
16
18
|
|
|
17
19
|
//#region src/protocols/rollup/join.ts
|
|
18
20
|
const debug = Debug("@ocap/tx-protocols:join-rollup");
|
|
19
21
|
const runner = new Runner("join_rollup");
|
|
20
|
-
const schema =
|
|
21
|
-
rollup:
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
});
|
|
22
|
+
const schema = pipe(object({
|
|
23
|
+
rollup: vDID({
|
|
24
|
+
prefix: true,
|
|
25
|
+
role: "ROLE_ROLLUP"
|
|
26
|
+
}),
|
|
27
|
+
endpoint: pipe(string(), check(isHttpUrl, "Must be a valid HTTP/HTTPS URL")),
|
|
28
|
+
evidence: object({ hash: pipe(string(), regex(patterns.txHash)) }),
|
|
29
|
+
signaturesList: pipe(schemas.multiSig, minLength(1)),
|
|
30
|
+
data: optional(nullable(any()))
|
|
31
|
+
}), vStripUnknown());
|
|
30
32
|
runner.use(({ itx }, next) => {
|
|
31
|
-
const { error } = schema
|
|
33
|
+
const { error } = vValidate(schema, itx);
|
|
32
34
|
return next(error ? new CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
|
|
33
35
|
});
|
|
34
36
|
runner.use(pipes.ExtractState({
|
|
@@ -4,28 +4,29 @@ import ensure_validator_default from "./pipes/ensure-validator.mjs";
|
|
|
4
4
|
import verify_signers_default from "./pipes/verify-signers.mjs";
|
|
5
5
|
import verify_status_default from "./pipes/verify-status.mjs";
|
|
6
6
|
import verify_evidence_default from "./pipes/verify-evidence.mjs";
|
|
7
|
+
import { any, minLength, nullable, object, optional, pipe, regex, string } from "../../node_modules/valibot/dist/index.mjs";
|
|
7
8
|
import { Runner, pipes } from "@ocap/tx-pipeline";
|
|
8
9
|
import { CustomError } from "@ocap/util/lib/error";
|
|
9
10
|
import { toStakeAddress } from "@arcblock/did-util";
|
|
10
11
|
import { account, evidence, rollup, stake } from "@ocap/state";
|
|
11
12
|
import Debug from "debug";
|
|
12
|
-
import {
|
|
13
|
+
import { patterns, schemas, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
13
14
|
import MerkleTree from "@ocap/merkle-tree";
|
|
14
15
|
|
|
15
16
|
//#region src/protocols/rollup/leave.ts
|
|
16
17
|
const debug = Debug("@ocap/tx-protocols:leave-rollup");
|
|
17
18
|
const runner = new Runner("leave_rollup");
|
|
18
|
-
const schema =
|
|
19
|
-
rollup:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
});
|
|
19
|
+
const schema = pipe(object({
|
|
20
|
+
rollup: vDID({
|
|
21
|
+
prefix: true,
|
|
22
|
+
role: "ROLE_ROLLUP"
|
|
23
|
+
}),
|
|
24
|
+
evidence: object({ hash: pipe(string(), regex(patterns.txHash)) }),
|
|
25
|
+
signaturesList: pipe(schemas.multiSig, minLength(1)),
|
|
26
|
+
data: optional(nullable(any()))
|
|
27
|
+
}), vStripUnknown());
|
|
27
28
|
runner.use(({ itx }, next) => {
|
|
28
|
-
const { error } = schema
|
|
29
|
+
const { error } = vValidate(schema, itx);
|
|
29
30
|
return next(error ? new CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
|
|
30
31
|
});
|
|
31
32
|
runner.use(pipes.ExtractState({
|
|
@@ -6,22 +6,25 @@ import verify_status_default from "./pipes/verify-status.mjs";
|
|
|
6
6
|
import { Runner, pipes } from "@ocap/tx-pipeline";
|
|
7
7
|
import { CustomError } from "@ocap/util/lib/error";
|
|
8
8
|
import { account, rollup } from "@ocap/state";
|
|
9
|
-
import {
|
|
9
|
+
import { v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
10
10
|
|
|
11
11
|
//#region src/protocols/rollup/migrate.ts
|
|
12
12
|
const runner = new Runner("migrate_rollup");
|
|
13
|
-
const schema =
|
|
14
|
-
rollup:
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
13
|
+
const schema = v.pipe(v.object({
|
|
14
|
+
rollup: vDID({
|
|
15
|
+
prefix: true,
|
|
16
|
+
role: "ROLE_ROLLUP"
|
|
17
|
+
}),
|
|
18
|
+
to: vDID({
|
|
19
|
+
prefix: true,
|
|
20
|
+
wallet: "ethereum"
|
|
21
|
+
}),
|
|
22
|
+
type: v.pipe(v.string(), v.trim(), v.check((s) => s === "vault" || s === "contract", "Must be vault or contract")),
|
|
23
|
+
message: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(512)),
|
|
24
|
+
data: v.optional(v.nullable(v.any()))
|
|
25
|
+
}), vStripUnknown());
|
|
23
26
|
runner.use(({ itx }, next) => {
|
|
24
|
-
const { error } = schema
|
|
27
|
+
const { error } = vValidate(schema, itx);
|
|
25
28
|
return next(error ? new CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
|
|
26
29
|
});
|
|
27
30
|
runner.use(pipes.ExtractState({
|
|
@@ -6,19 +6,19 @@ import verify_status_default from "./pipes/verify-status.mjs";
|
|
|
6
6
|
import { Runner, pipes } from "@ocap/tx-pipeline";
|
|
7
7
|
import { CustomError } from "@ocap/util/lib/error";
|
|
8
8
|
import { account, rollup } from "@ocap/state";
|
|
9
|
-
import {
|
|
9
|
+
import { v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
10
10
|
|
|
11
11
|
//#region src/protocols/rollup/pause.ts
|
|
12
12
|
const runner = new Runner("pause_rollup");
|
|
13
|
-
const schema =
|
|
14
|
-
rollup:
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
});
|
|
13
|
+
const schema = v.pipe(v.object({
|
|
14
|
+
rollup: vDID({
|
|
15
|
+
prefix: true,
|
|
16
|
+
role: "ROLE_ROLLUP"
|
|
17
|
+
}),
|
|
18
|
+
data: v.optional(v.nullable(v.any()))
|
|
19
|
+
}), vStripUnknown());
|
|
20
20
|
runner.use(({ itx }, next) => {
|
|
21
|
-
const { error } = schema
|
|
21
|
+
const { error } = vValidate(schema, itx);
|
|
22
22
|
return next(error ? new CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
|
|
23
23
|
});
|
|
24
24
|
runner.use(pipes.ExtractState({
|
|
@@ -6,19 +6,19 @@ import verify_status_default from "./pipes/verify-status.mjs";
|
|
|
6
6
|
import { Runner, pipes } from "@ocap/tx-pipeline";
|
|
7
7
|
import { CustomError } from "@ocap/util/lib/error";
|
|
8
8
|
import { account, rollup } from "@ocap/state";
|
|
9
|
-
import {
|
|
9
|
+
import { v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
10
10
|
|
|
11
11
|
//#region src/protocols/rollup/resume.ts
|
|
12
12
|
const runner = new Runner("resume_rollup");
|
|
13
|
-
const schema =
|
|
14
|
-
rollup:
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
});
|
|
13
|
+
const schema = v.pipe(v.object({
|
|
14
|
+
rollup: vDID({
|
|
15
|
+
prefix: true,
|
|
16
|
+
role: "ROLE_ROLLUP"
|
|
17
|
+
}),
|
|
18
|
+
data: v.optional(v.nullable(v.any()))
|
|
19
|
+
}), vStripUnknown());
|
|
20
20
|
runner.use(({ itx }, next) => {
|
|
21
|
-
const { error } = schema
|
|
21
|
+
const { error } = vValidate(schema, itx);
|
|
22
22
|
return next(error ? new CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
|
|
23
23
|
});
|
|
24
24
|
runner.use(pipes.ExtractState({
|
|
@@ -1,46 +1,49 @@
|
|
|
1
|
+
import { __toESM } from "../../_virtual/rolldown_runtime.mjs";
|
|
1
2
|
import { decodeAnySafe } from "../../util.mjs";
|
|
2
3
|
import ensure_cost_default from "../../pipes/ensure-cost.mjs";
|
|
3
4
|
import ensure_gas_default from "../../pipes/ensure-gas.mjs";
|
|
4
5
|
import ensure_validator_default from "./pipes/ensure-validator.mjs";
|
|
5
6
|
import verify_signers_default from "./pipes/verify-signers.mjs";
|
|
6
7
|
import verify_status_default from "./pipes/verify-status.mjs";
|
|
8
|
+
import { require_bn } from "../../node_modules/bn.js/lib/bn.mjs";
|
|
7
9
|
import { Runner, pipes } from "@ocap/tx-pipeline";
|
|
8
10
|
import { CustomError } from "@ocap/util/lib/error";
|
|
9
11
|
import { account, rollup } from "@ocap/state";
|
|
10
12
|
import Debug from "debug";
|
|
11
|
-
import {
|
|
13
|
+
import { v, vBN, vBNGreater, vBNPositive, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
12
14
|
|
|
13
15
|
//#region src/protocols/rollup/update.ts
|
|
16
|
+
var import_bn = /* @__PURE__ */ __toESM(require_bn(), 1);
|
|
14
17
|
const debug = Debug("@ocap/tx-protocols:update-rollup");
|
|
15
18
|
const runner = new Runner("update_rollup");
|
|
16
|
-
const schema =
|
|
17
|
-
rollup:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
});
|
|
19
|
+
const schema = v.pipe(v.object({
|
|
20
|
+
rollup: vDID({
|
|
21
|
+
prefix: true,
|
|
22
|
+
role: "ROLE_ROLLUP"
|
|
23
|
+
}),
|
|
24
|
+
minStakeAmount: vBN(vBNGreater(0)),
|
|
25
|
+
maxStakeAmount: vBN(vBNGreater(0)),
|
|
26
|
+
minSignerCount: v.pipe(v.number(), v.integer()),
|
|
27
|
+
maxSignerCount: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(8)),
|
|
28
|
+
minBlockSize: v.pipe(v.number(), v.integer(), v.minValue(1)),
|
|
29
|
+
maxBlockSize: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(10)),
|
|
30
|
+
minBlockInterval: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(3600)),
|
|
31
|
+
minBlockConfirmation: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(100)),
|
|
32
|
+
minDepositAmount: vBN(vBNPositive()),
|
|
33
|
+
maxDepositAmount: vBN(vBNPositive()),
|
|
34
|
+
minWithdrawAmount: vBN(vBNPositive()),
|
|
35
|
+
maxWithdrawAmount: vBN(vBNPositive()),
|
|
36
|
+
depositFeeRate: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(1e4)),
|
|
37
|
+
withdrawFeeRate: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(1e4)),
|
|
38
|
+
publisherFeeShare: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(1e4)),
|
|
39
|
+
minDepositFee: vBN(vBNPositive()),
|
|
40
|
+
maxDepositFee: vBN(vBNPositive()),
|
|
41
|
+
minWithdrawFee: vBN(vBNPositive()),
|
|
42
|
+
maxWithdrawFee: vBN(vBNPositive()),
|
|
43
|
+
data: v.optional(v.nullable(v.any()))
|
|
44
|
+
}), v.forward(v.check((input) => new import_bn.default(input.maxStakeAmount).gt(new import_bn.default(input.minStakeAmount)), "maxStakeAmount must be > minStakeAmount"), ["maxStakeAmount"]), v.forward(v.check((input) => input.maxSignerCount > input.minSignerCount, "maxSignerCount must be > minSignerCount"), ["maxSignerCount"]), v.forward(v.check((input) => input.maxBlockSize > input.minBlockSize, "maxBlockSize must be > minBlockSize"), ["maxBlockSize"]), v.forward(v.check((input) => new import_bn.default(input.maxDepositAmount).gt(new import_bn.default(input.minDepositAmount)), "maxDepositAmount must be > minDepositAmount"), ["maxDepositAmount"]), v.forward(v.check((input) => new import_bn.default(input.maxWithdrawAmount).gt(new import_bn.default(input.minWithdrawAmount)), "maxWithdrawAmount must be > minWithdrawAmount"), ["maxWithdrawAmount"]), v.forward(v.check((input) => new import_bn.default(input.maxDepositFee).gt(new import_bn.default(input.minDepositFee)), "maxDepositFee must be > minDepositFee"), ["maxDepositFee"]), v.forward(v.check((input) => new import_bn.default(input.maxWithdrawFee).gt(new import_bn.default(input.minWithdrawFee)), "maxWithdrawFee must be > minWithdrawFee"), ["maxWithdrawFee"]), vStripUnknown());
|
|
42
45
|
runner.use(({ itx }, next) => {
|
|
43
|
-
const { error } = schema
|
|
46
|
+
const { error } = vValidate(schema, itx);
|
|
44
47
|
return next(error ? new CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
|
|
45
48
|
});
|
|
46
49
|
runner.use(pipes.VerifyInfo([{
|
|
@@ -5,10 +5,10 @@ import { Runner, pipes } from "@ocap/tx-pipeline";
|
|
|
5
5
|
import { CustomError } from "@ocap/util/lib/error";
|
|
6
6
|
import { toTokenAddress } from "@arcblock/did-util";
|
|
7
7
|
import { account, delegation, token } from "@ocap/state";
|
|
8
|
-
import { fromTokenToUnit } from "@ocap/util";
|
|
8
|
+
import { BN, fromTokenToUnit } from "@ocap/util";
|
|
9
9
|
import Debug from "debug";
|
|
10
10
|
import cloneDeep from "lodash/cloneDeep.js";
|
|
11
|
-
import {
|
|
11
|
+
import { schemas, v, vBN, vBNGreater, vBNMax, vDID, vForbidden, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
12
12
|
import uniq from "lodash/uniq.js";
|
|
13
13
|
import isEmpty from "lodash/isEmpty.js";
|
|
14
14
|
|
|
@@ -17,27 +17,30 @@ const debug = Debug("@ocap/tx-protocols:create-token");
|
|
|
17
17
|
const MAX_TOTAL_SUPPLY = fromTokenToUnit(1e4 * 1e8, 18);
|
|
18
18
|
const runner = new Runner("create_token");
|
|
19
19
|
runner.use(pipes.VerifyMultiSig(0));
|
|
20
|
-
const schema =
|
|
21
|
-
address:
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}).
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
})
|
|
20
|
+
const schema = v.pipe(v.object({
|
|
21
|
+
address: vDID({
|
|
22
|
+
prefix: true,
|
|
23
|
+
role: "ROLE_TOKEN"
|
|
24
|
+
}),
|
|
25
|
+
name: v.pipe(v.string(), v.minLength(1), v.maxLength(32)),
|
|
26
|
+
description: v.pipe(v.string(), v.minLength(16), v.maxLength(128)),
|
|
27
|
+
symbol: v.pipe(v.string(), v.minLength(2), v.maxLength(6), v.toUpperCase()),
|
|
28
|
+
unit: v.pipe(v.string(), v.minLength(1), v.maxLength(6), v.toLowerCase()),
|
|
29
|
+
decimal: v.pipe(v.number(), v.minValue(2), v.maxValue(18)),
|
|
30
|
+
icon: v.optional(v.nullable(v.literal(""))),
|
|
31
|
+
totalSupply: vBN(vBNGreater(0), vBNMax(MAX_TOTAL_SUPPLY)),
|
|
32
|
+
initialSupply: vBN(vBNGreater(0)),
|
|
33
|
+
maxTotalSupply: v.optional(v.nullable(v.union([vBN(vBNGreater(0)), v.literal("")]))),
|
|
34
|
+
foreignToken: v.optional(v.nullable(schemas.foreignToken)),
|
|
35
|
+
spendersList: v.optional(v.nullable(v.pipe(v.array(vDID({ prefix: true })), v.maxLength(30)))),
|
|
36
|
+
tokenFactoryAddress: v.optional(vForbidden("tokenFactoryAddress is forbidden")),
|
|
37
|
+
data: v.optional(v.nullable(v.any()))
|
|
38
|
+
}), v.forward(v.check((input) => new BN(input.initialSupply).lte(new BN(input.totalSupply)), "initialSupply must be <= totalSupply"), ["initialSupply"]), v.forward(v.check((input) => {
|
|
39
|
+
if (!input.maxTotalSupply || input.maxTotalSupply === "") return true;
|
|
40
|
+
return new BN(input.maxTotalSupply).lte(new BN(input.totalSupply));
|
|
41
|
+
}, "maxTotalSupply must be <= totalSupply"), ["maxTotalSupply"]), vStripUnknown());
|
|
39
42
|
runner.use(({ itx }, next) => {
|
|
40
|
-
const { error, value } = schema
|
|
43
|
+
const { error, value } = vValidate(schema, itx);
|
|
41
44
|
if (error) return next(new CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
|
|
42
45
|
const spendersList = value.spendersList;
|
|
43
46
|
itx.spenders = spendersList?.length ? uniq(spendersList) : null;
|
|
@@ -10,25 +10,31 @@ import { account, evidence, stake } from "@ocap/state";
|
|
|
10
10
|
import { BN, fromUnitToToken } from "@ocap/util";
|
|
11
11
|
import Debug from "debug";
|
|
12
12
|
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
13
|
-
import {
|
|
13
|
+
import { patterns, schemas, v, vBN, vBNMin, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
14
14
|
|
|
15
15
|
//#region src/protocols/token/deposit-v2.ts
|
|
16
16
|
const debug = Debug("@ocap/tx-protocols:deposit-token");
|
|
17
|
-
const schema =
|
|
18
|
-
token: schemas.tokenInput
|
|
19
|
-
to:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
17
|
+
const schema = v.pipe(v.object({
|
|
18
|
+
token: schemas.tokenInput,
|
|
19
|
+
to: vDID({
|
|
20
|
+
prefix: true,
|
|
21
|
+
wallet: "ethereum"
|
|
22
|
+
}),
|
|
23
|
+
proposer: vDID({
|
|
24
|
+
prefix: true,
|
|
25
|
+
wallet: "ethereum"
|
|
26
|
+
}),
|
|
27
|
+
evidence: v.object({ hash: v.pipe(v.string(), v.regex(patterns.txHash)) }),
|
|
28
|
+
rollup: vDID({
|
|
29
|
+
prefix: true,
|
|
30
|
+
role: "ROLE_ROLLUP"
|
|
31
|
+
}),
|
|
32
|
+
actualFee: vBN(vBNMin(0)),
|
|
33
|
+
data: v.optional(v.nullable(v.any()))
|
|
34
|
+
}), vStripUnknown());
|
|
29
35
|
const runner = new Runner("deposit_token_v2");
|
|
30
36
|
runner.use(({ tx: tx$1, itx }, next) => {
|
|
31
|
-
const { error } = schema
|
|
37
|
+
const { error } = vValidate(schema, itx);
|
|
32
38
|
if (error) return next(new CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
|
|
33
39
|
if (itx.to !== tx$1.from) return next(new CustomError("INVALID_TX", "You can only deposit to tx sender account"));
|
|
34
40
|
const signatures = getListField(tx$1, "signatures");
|
|
@@ -9,26 +9,32 @@ import { account, stake } from "@ocap/state";
|
|
|
9
9
|
import { BN, fromUnitToToken } from "@ocap/util";
|
|
10
10
|
import Debug from "debug";
|
|
11
11
|
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
12
|
-
import {
|
|
12
|
+
import { schemas, v, vBN, vBNMin, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
13
13
|
|
|
14
14
|
//#region src/protocols/token/withdraw-v2.ts
|
|
15
15
|
const debug = Debug("@ocap/tx-protocols:withdraw-token");
|
|
16
16
|
const verifyMultiSigV2 = pipes.VerifyMultiSigV2({ signersKey: "signers" });
|
|
17
|
-
const schema =
|
|
18
|
-
token: schemas.tokenInput
|
|
19
|
-
to:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
17
|
+
const schema = v.pipe(v.object({
|
|
18
|
+
token: schemas.tokenInput,
|
|
19
|
+
to: vDID({
|
|
20
|
+
prefix: true,
|
|
21
|
+
wallet: "ethereum"
|
|
22
|
+
}),
|
|
23
|
+
rollup: vDID({
|
|
24
|
+
prefix: true,
|
|
25
|
+
role: "ROLE_ROLLUP"
|
|
26
|
+
}),
|
|
27
|
+
proposer: v.optional(v.nullable(v.union([v.literal(""), vDID({
|
|
28
|
+
prefix: true,
|
|
29
|
+
wallet: "ethereum"
|
|
30
|
+
})])), ""),
|
|
31
|
+
actualFee: vBN(vBNMin(0)),
|
|
32
|
+
maxFee: vBN(vBNMin(0)),
|
|
33
|
+
data: v.optional(v.nullable(v.any()))
|
|
34
|
+
}), vStripUnknown());
|
|
29
35
|
const runner = new Runner("withdraw_token_v2");
|
|
30
36
|
runner.use(({ tx: tx$1, itx }, next) => {
|
|
31
|
-
const { error } = schema
|
|
37
|
+
const { error } = vValidate(schema, itx);
|
|
32
38
|
if (error) return next(new CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
|
|
33
39
|
if (itx.to !== tx$1.from) return next(new CustomError("INVALID_TX", "You can only withdraw to tx sender account"));
|
|
34
40
|
return next();
|