@ocap/state 1.30.25 → 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/index.d.mts +4 -4
- package/esm/index.mjs +4 -4
- package/esm/states/account.d.mts +2 -8
- package/esm/states/account.mjs +2 -64
- package/esm/states/asset.mjs +5 -1
- package/esm/states/chain.mjs +1 -3
- package/esm/states/delegation.mjs +2 -0
- package/esm/states/rollup-block.mjs +1 -4
- package/esm/states/rollup.d.mts +37 -10
- package/esm/states/rollup.mjs +193 -19
- package/esm/states/stake.mjs +2 -1
- package/esm/states/token-factory.mjs +28 -9
- package/esm/states/token.d.mts +111 -7
- package/esm/states/token.mjs +365 -6
- package/esm/states/tx.mjs +1 -1
- package/lib/index.cjs +28 -8
- package/lib/index.d.cts +4 -4
- package/lib/states/account.cjs +1 -70
- package/lib/states/account.d.cts +2 -8
- package/lib/states/asset.cjs +5 -1
- package/lib/states/chain.cjs +2 -4
- package/lib/states/delegation.cjs +2 -0
- package/lib/states/rollup-block.cjs +1 -4
- package/lib/states/rollup.cjs +205 -17
- package/lib/states/rollup.d.cts +37 -10
- package/lib/states/stake.cjs +2 -1
- package/lib/states/token-factory.cjs +28 -9
- package/lib/states/token.cjs +380 -6
- package/lib/states/token.d.cts +111 -7
- package/lib/states/tx.cjs +2 -2
- package/package.json +9 -9
package/lib/states/account.cjs
CHANGED
|
@@ -6,8 +6,6 @@ let _ocap_util = require("@ocap/util");
|
|
|
6
6
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
7
7
|
let lodash_flatten = require("lodash/flatten");
|
|
8
8
|
lodash_flatten = require_rolldown_runtime.__toESM(lodash_flatten);
|
|
9
|
-
let lodash_get = require("lodash/get");
|
|
10
|
-
lodash_get = require_rolldown_runtime.__toESM(lodash_get);
|
|
11
9
|
let lodash_pick = require("lodash/pick");
|
|
12
10
|
lodash_pick = require_rolldown_runtime.__toESM(lodash_pick);
|
|
13
11
|
let lodash_uniq = require("lodash/uniq");
|
|
@@ -16,16 +14,10 @@ let _arcblock_validator = require("@arcblock/validator");
|
|
|
16
14
|
|
|
17
15
|
//#region src/states/account.ts
|
|
18
16
|
var account_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
|
|
19
|
-
CHAIN_UNSIGNED_TX_DEDUP_HEIGHTS: () => CHAIN_UNSIGNED_TX_DEDUP_HEIGHTS,
|
|
20
|
-
EXPLICIT_HEIGHT_PATHS: () => EXPLICIT_HEIGHT_PATHS,
|
|
21
|
-
PENDING_DEDUP_ACTIVATION_HEIGHT: () => PENDING_DEDUP_ACTIVATION_HEIGHT,
|
|
22
17
|
create: () => create,
|
|
23
18
|
ensureChecksumAddress: () => ensureChecksumAddress,
|
|
24
|
-
isExplicitlyPreActivation: () => isExplicitlyPreActivation,
|
|
25
19
|
isMigrated: () => isMigrated,
|
|
26
20
|
parseNonceBn: () => parseNonceBn,
|
|
27
|
-
readExplicitHeight: () => readExplicitHeight,
|
|
28
|
-
resolveDedupActivationHeight: () => resolveDedupActivationHeight,
|
|
29
21
|
schema: () => schema,
|
|
30
22
|
update: () => update,
|
|
31
23
|
updateOrCreate: () => updateOrCreate,
|
|
@@ -71,57 +63,6 @@ const create = (attrs, context) => {
|
|
|
71
63
|
if (!account.moniker) account.moniker = [account.address.slice(0, 6), account.address.slice(-5)].join("-");
|
|
72
64
|
return validate(account);
|
|
73
65
|
};
|
|
74
|
-
const PENDING_DEDUP_ACTIVATION_HEIGHT = Number.MAX_SAFE_INTEGER;
|
|
75
|
-
const CHAIN_UNSIGNED_TX_DEDUP_HEIGHTS = Object.freeze({
|
|
76
|
-
main: PENDING_DEDUP_ACTIVATION_HEIGHT,
|
|
77
|
-
"xenon-2020-01-15": PENDING_DEDUP_ACTIVATION_HEIGHT,
|
|
78
|
-
xenon: PENDING_DEDUP_ACTIVATION_HEIGHT,
|
|
79
|
-
beta: 1,
|
|
80
|
-
"test-chain": 1,
|
|
81
|
-
test: 1
|
|
82
|
-
});
|
|
83
|
-
const EXPLICIT_HEIGHT_PATHS = [
|
|
84
|
-
"height",
|
|
85
|
-
"blockHeight",
|
|
86
|
-
"sequence",
|
|
87
|
-
"ledgerSequence",
|
|
88
|
-
"expectedLedgerSequence",
|
|
89
|
-
"extra.height",
|
|
90
|
-
"extra.blockHeight",
|
|
91
|
-
"extra.sequence",
|
|
92
|
-
"tx.height"
|
|
93
|
-
];
|
|
94
|
-
const readExplicitHeight = (context) => {
|
|
95
|
-
for (const path of EXPLICIT_HEIGHT_PATHS) {
|
|
96
|
-
const val = (0, lodash_get.default)(context, path);
|
|
97
|
-
if (val !== void 0 && val !== null && val !== "") {
|
|
98
|
-
const parsed = Number(val);
|
|
99
|
-
if (Number.isFinite(parsed) && parsed >= 0) return Math.floor(parsed);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
const resolveDedupActivationHeight = (context) => {
|
|
104
|
-
const rawChainId = (0, lodash_get.default)(context, "config.chainId") ?? (0, lodash_get.default)(context, "tx.chainId") ?? (0, lodash_get.default)(context, "chainId");
|
|
105
|
-
const chainId = typeof rawChainId === "string" ? rawChainId.trim() : "";
|
|
106
|
-
const registryHeight = chainId && Object.prototype.hasOwnProperty.call(CHAIN_UNSIGNED_TX_DEDUP_HEIGHTS, chainId) ? CHAIN_UNSIGNED_TX_DEDUP_HEIGHTS[chainId] : void 0;
|
|
107
|
-
if (typeof registryHeight === "number" && Number.isFinite(registryHeight) && registryHeight > 1 && registryHeight < PENDING_DEDUP_ACTIVATION_HEIGHT) return Math.floor(registryHeight);
|
|
108
|
-
const rawConfig = (0, lodash_get.default)(context, "config.transaction.unsignedTxHashDedupHeight", 0);
|
|
109
|
-
const parsedConfig = Number(rawConfig);
|
|
110
|
-
if (Number.isFinite(parsedConfig) && parsedConfig > 0) return Math.floor(parsedConfig);
|
|
111
|
-
if (typeof registryHeight === "number" && Number.isFinite(registryHeight) && registryHeight > 0) return Math.floor(registryHeight);
|
|
112
|
-
if (chainId) return PENDING_DEDUP_ACTIVATION_HEIGHT;
|
|
113
|
-
return 0;
|
|
114
|
-
};
|
|
115
|
-
const isExplicitlyPreActivation = (context) => {
|
|
116
|
-
const explicitFlag = (0, lodash_get.default)(context, "dedupActive");
|
|
117
|
-
if (typeof explicitFlag === "boolean") return !explicitFlag;
|
|
118
|
-
const dedupHeight = resolveDedupActivationHeight(context);
|
|
119
|
-
if (!Number.isFinite(dedupHeight) || dedupHeight <= 0) return false;
|
|
120
|
-
const explicitHeight = readExplicitHeight(context);
|
|
121
|
-
if (explicitHeight !== void 0) return explicitHeight < dedupHeight;
|
|
122
|
-
if (dedupHeight >= PENDING_DEDUP_ACTIVATION_HEIGHT) return true;
|
|
123
|
-
return false;
|
|
124
|
-
};
|
|
125
66
|
const parseNonceBn = (rawNonce) => {
|
|
126
67
|
if (typeof rawNonce === "number") {
|
|
127
68
|
if (!Number.isFinite(rawNonce) || !Number.isInteger(rawNonce)) return null;
|
|
@@ -138,11 +79,7 @@ const update = (state, attrs, context) => {
|
|
|
138
79
|
const hasExplicitNonce = attrs.nonce !== void 0 && attrs.nonce !== null;
|
|
139
80
|
let shouldUpdateNonce = false;
|
|
140
81
|
let normalizedNonce;
|
|
141
|
-
if (hasExplicitNonce)
|
|
142
|
-
if (attrs.nonce && Number(attrs.nonce) <= Number(state.nonce)) throw new _ocap_util_lib_error.CustomError("INVALID_NONCE", "nonce must be greater in newer transactions");
|
|
143
|
-
shouldUpdateNonce = true;
|
|
144
|
-
normalizedNonce = attrs.nonce;
|
|
145
|
-
} else {
|
|
82
|
+
if (hasExplicitNonce) {
|
|
146
83
|
const incomingNonceBn = parseNonceBn(attrs.nonce);
|
|
147
84
|
const currentNonceBn = parseNonceBn(state.nonce) ?? new _ocap_util.BN(0);
|
|
148
85
|
if (!incomingNonceBn || incomingNonceBn.lte(currentNonceBn) || incomingNonceBn.lte(new _ocap_util.BN(0))) throw new _ocap_util_lib_error.CustomError("INVALID_NONCE", "nonce must be greater in newer transactions");
|
|
@@ -187,9 +124,6 @@ const isMigrated = (state) => (state.migratedTo || []).length > 0;
|
|
|
187
124
|
const ensureChecksumAddress = (address) => (0, _arcblock_did_lib_type.isEthereumDid)(address) ? (0, _arcblock_did_lib_type.toChecksumAddress)(address) : address;
|
|
188
125
|
|
|
189
126
|
//#endregion
|
|
190
|
-
exports.CHAIN_UNSIGNED_TX_DEDUP_HEIGHTS = CHAIN_UNSIGNED_TX_DEDUP_HEIGHTS;
|
|
191
|
-
exports.EXPLICIT_HEIGHT_PATHS = EXPLICIT_HEIGHT_PATHS;
|
|
192
|
-
exports.PENDING_DEDUP_ACTIVATION_HEIGHT = PENDING_DEDUP_ACTIVATION_HEIGHT;
|
|
193
127
|
Object.defineProperty(exports, 'account_exports', {
|
|
194
128
|
enumerable: true,
|
|
195
129
|
get: function () {
|
|
@@ -198,11 +132,8 @@ Object.defineProperty(exports, 'account_exports', {
|
|
|
198
132
|
});
|
|
199
133
|
exports.create = create;
|
|
200
134
|
exports.ensureChecksumAddress = ensureChecksumAddress;
|
|
201
|
-
exports.isExplicitlyPreActivation = isExplicitlyPreActivation;
|
|
202
135
|
exports.isMigrated = isMigrated;
|
|
203
136
|
exports.parseNonceBn = parseNonceBn;
|
|
204
|
-
exports.readExplicitHeight = readExplicitHeight;
|
|
205
|
-
exports.resolveDedupActivationHeight = resolveDedupActivationHeight;
|
|
206
137
|
exports.schema = schema;
|
|
207
138
|
exports.update = update;
|
|
208
139
|
exports.updateOrCreate = updateOrCreate;
|
package/lib/states/account.d.cts
CHANGED
|
@@ -5,7 +5,7 @@ import { v } from "@arcblock/validator";
|
|
|
5
5
|
|
|
6
6
|
//#region src/states/account.d.ts
|
|
7
7
|
declare namespace account_d_exports {
|
|
8
|
-
export {
|
|
8
|
+
export { create, ensureChecksumAddress, isMigrated, parseNonceBn, schema, update, updateOrCreate, validate };
|
|
9
9
|
}
|
|
10
10
|
declare const schema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
11
11
|
readonly address: any;
|
|
@@ -25,12 +25,6 @@ declare const schema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
|
25
25
|
readonly data: v.OptionalSchema<v.NullableSchema<v.AnySchema, undefined>, undefined>;
|
|
26
26
|
}, undefined>, any]>;
|
|
27
27
|
declare const create: (attrs: Partial<IAccountState>, context: StateContextInput) => IAccountState;
|
|
28
|
-
declare const PENDING_DEDUP_ACTIVATION_HEIGHT: number;
|
|
29
|
-
declare const CHAIN_UNSIGNED_TX_DEDUP_HEIGHTS: Readonly<Record<string, number>>;
|
|
30
|
-
declare const EXPLICIT_HEIGHT_PATHS: readonly ["height", "blockHeight", "sequence", "ledgerSequence", "expectedLedgerSequence", "extra.height", "extra.blockHeight", "extra.sequence", "tx.height"];
|
|
31
|
-
declare const readExplicitHeight: (context: unknown) => number | undefined;
|
|
32
|
-
declare const resolveDedupActivationHeight: (context: unknown) => number;
|
|
33
|
-
declare const isExplicitlyPreActivation: (context: unknown) => boolean;
|
|
34
28
|
declare const parseNonceBn: (rawNonce: unknown) => InstanceType<typeof BN> | null;
|
|
35
29
|
declare const update: (state: IAccountState, attrs: Partial<IAccountState>, context: StateContextInput) => IAccountState;
|
|
36
30
|
declare const updateOrCreate: (state: IAccountState | null, attrs: Partial<IAccountState>, context: StateContextInput) => IAccountState;
|
|
@@ -40,4 +34,4 @@ declare const isMigrated: (state: {
|
|
|
40
34
|
}) => boolean;
|
|
41
35
|
declare const ensureChecksumAddress: (address: string) => string;
|
|
42
36
|
//#endregion
|
|
43
|
-
export {
|
|
37
|
+
export { account_d_exports, create, ensureChecksumAddress, isMigrated, parseNonceBn, schema, update, updateOrCreate, validate };
|
package/lib/states/asset.cjs
CHANGED
package/lib/states/chain.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_contexts_state = require('../contexts/state.cjs');
|
|
3
3
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
4
|
-
let lodash_get = require("lodash/get");
|
|
5
|
-
lodash_get = require_rolldown_runtime.__toESM(lodash_get);
|
|
6
4
|
let lodash_pick = require("lodash/pick");
|
|
7
5
|
lodash_pick = require_rolldown_runtime.__toESM(lodash_pick);
|
|
6
|
+
let lodash_get = require("lodash/get");
|
|
7
|
+
lodash_get = require_rolldown_runtime.__toESM(lodash_get);
|
|
8
8
|
let lodash_isEqual = require("lodash/isEqual");
|
|
9
9
|
lodash_isEqual = require_rolldown_runtime.__toESM(lodash_isEqual);
|
|
10
10
|
|
|
@@ -37,8 +37,6 @@ const update = (state, updates) => {
|
|
|
37
37
|
];
|
|
38
38
|
if (!process.env.CHAIN_TOKEN_ADDRESS) immutableAttrs.push("token.name", "token.description", "token.unit", "token.totalSupply", "token.initialSupply", "token.foreignToken");
|
|
39
39
|
for (const attr of immutableAttrs) if ((0, lodash_get.default)(updates, attr) && !(0, lodash_isEqual.default)((0, lodash_get.default)(updates, attr), (0, lodash_get.default)(state, attr))) throw new _ocap_util_lib_error.CustomError("FORBIDDEN", `Cannot update ${attr} field on chain state`);
|
|
40
|
-
const prevDedupHeight = Number((0, lodash_get.default)(state, "transaction.unsignedTxHashDedupHeight", 0));
|
|
41
|
-
if (prevDedupHeight > 0 && updates.transaction !== void 0 && Number((0, lodash_get.default)(updates, "transaction.unsignedTxHashDedupHeight", 0)) !== prevDedupHeight) throw new _ocap_util_lib_error.CustomError("FORBIDDEN", "Cannot update transaction.unsignedTxHashDedupHeight field on chain state");
|
|
42
40
|
const context = { txTime: (/* @__PURE__ */ new Date()).toISOString() };
|
|
43
41
|
return {
|
|
44
42
|
...state,
|
|
@@ -47,6 +47,8 @@ const create = (attrs, context) => {
|
|
|
47
47
|
if (delegation.deny === void 0 || delegation.deny === null) delegation.deny = [];
|
|
48
48
|
if (delegation.validUntil === void 0 || delegation.validUntil === null) delegation.validUntil = 0;
|
|
49
49
|
if (typeof delegation.address === "string") delegation.address = (0, _ocap_util.toAddress)(delegation.address);
|
|
50
|
+
if (typeof delegation.to === "string" && delegation.to) delegation.to = (0, _ocap_util.toAddress)(delegation.to);
|
|
51
|
+
if (typeof delegation.from === "string" && delegation.from) delegation.from = (0, _ocap_util.toAddress)(delegation.from);
|
|
50
52
|
if (Array.isArray(delegation.ops)) delegation.ops = require_util.nullify(delegation.ops);
|
|
51
53
|
return validate(delegation);
|
|
52
54
|
};
|
|
@@ -19,10 +19,7 @@ const schema = _arcblock_validator.v.pipe(_arcblock_validator.v.object({
|
|
|
19
19
|
previousHash: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_arcblock_validator.v.string())),
|
|
20
20
|
txsHash: _arcblock_validator.v.pipe(_arcblock_validator.v.string(), _arcblock_validator.v.regex(_arcblock_validator.patterns.txHash)),
|
|
21
21
|
txs: _arcblock_validator.v.pipe(_arcblock_validator.v.array(_arcblock_validator.v.pipe(_arcblock_validator.v.string(), _arcblock_validator.v.regex(_arcblock_validator.patterns.txHash))), _arcblock_validator.v.minLength(1), _arcblock_validator.v.check((arr) => new Set(arr).size === arr.length, "Must contain unique values")),
|
|
22
|
-
proposer: (0, _arcblock_validator.vDID)({
|
|
23
|
-
prefix: true,
|
|
24
|
-
wallet: "ethereum"
|
|
25
|
-
}),
|
|
22
|
+
proposer: (0, _arcblock_validator.vDID)({ prefix: true }),
|
|
26
23
|
signatures: _arcblock_validator.v.pipe(_arcblock_validator.schemas.multiSig, _arcblock_validator.v.minLength(1)),
|
|
27
24
|
rollup: (0, _arcblock_validator.vDID)({
|
|
28
25
|
prefix: true,
|
package/lib/states/rollup.cjs
CHANGED
|
@@ -4,20 +4,98 @@ let _ocap_util = require("@ocap/util");
|
|
|
4
4
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
5
5
|
let lodash_pick = require("lodash/pick");
|
|
6
6
|
lodash_pick = require_rolldown_runtime.__toESM(lodash_pick);
|
|
7
|
+
let lodash_uniq = require("lodash/uniq");
|
|
8
|
+
lodash_uniq = require_rolldown_runtime.__toESM(lodash_uniq);
|
|
7
9
|
let _arcblock_validator = require("@arcblock/validator");
|
|
8
10
|
|
|
9
11
|
//#region src/states/rollup.ts
|
|
10
12
|
var rollup_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
|
|
13
|
+
VALID_ROLLUP_TARGET_TYPES: () => VALID_ROLLUP_TARGET_TYPES,
|
|
11
14
|
close: () => close,
|
|
12
15
|
create: () => create,
|
|
16
|
+
getRollupSupportedTokens: () => getRollupSupportedTokens,
|
|
17
|
+
getRollupTargetType: () => getRollupTargetType,
|
|
18
|
+
getRollupTokenReserve: () => getRollupTokenReserve,
|
|
19
|
+
hasRollupReserveTracking: () => hasRollupReserveTracking,
|
|
20
|
+
isProposerSponsoredDepositAllowed: () => isProposerSponsoredDepositAllowed,
|
|
21
|
+
isTokenSupportedByRollup: () => isTokenSupportedByRollup,
|
|
22
|
+
isValidRollupContractAddress: () => isValidRollupContractAddress,
|
|
23
|
+
isValidRollupTargetType: () => isValidRollupTargetType,
|
|
24
|
+
isValidRollupValidatorAddress: () => isValidRollupValidatorAddress,
|
|
25
|
+
isValidRollupVaultAddress: () => isValidRollupVaultAddress,
|
|
13
26
|
migrateContract: () => migrateContract,
|
|
14
27
|
migrateVault: () => migrateVault,
|
|
15
28
|
pause: () => pause,
|
|
29
|
+
recordRollupDeposit: () => recordRollupDeposit,
|
|
30
|
+
recordRollupWithdraw: () => recordRollupWithdraw,
|
|
16
31
|
resume: () => resume,
|
|
17
32
|
schema: () => schema,
|
|
18
33
|
update: () => update,
|
|
19
34
|
validate: () => validate
|
|
20
35
|
});
|
|
36
|
+
const VALID_ROLLUP_TARGET_TYPES = ["EVM", "OCAP_ISOMORPHIC"];
|
|
37
|
+
const ethDidSchema = (0, _arcblock_validator.vDID)({
|
|
38
|
+
prefix: true,
|
|
39
|
+
wallet: "ethereum"
|
|
40
|
+
});
|
|
41
|
+
const ethVaultDidSchema = (0, _arcblock_validator.vDID)({ wallet: "ethereum" });
|
|
42
|
+
const anyDidSchema = (0, _arcblock_validator.vDID)({ prefix: true });
|
|
43
|
+
function isValidRollupTargetType(value) {
|
|
44
|
+
return typeof value === "string" && VALID_ROLLUP_TARGET_TYPES.includes(value);
|
|
45
|
+
}
|
|
46
|
+
function getRollupTargetType(state) {
|
|
47
|
+
const raw = state?.targetType ?? state?.data?.value?.targetType;
|
|
48
|
+
if (isValidRollupTargetType(raw)) return raw;
|
|
49
|
+
return "EVM";
|
|
50
|
+
}
|
|
51
|
+
function isValidRollupContractAddress(address, targetType = "EVM") {
|
|
52
|
+
if (typeof address !== "string" || address.length === 0) return false;
|
|
53
|
+
if (targetType === "EVM") return !(0, _arcblock_validator.vValidate)(ethDidSchema, address).error;
|
|
54
|
+
if (targetType === "OCAP_ISOMORPHIC") return !(0, _arcblock_validator.vValidate)(anyDidSchema, address).error;
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
function isValidRollupVaultAddress(address, targetType = "EVM") {
|
|
58
|
+
if (address === void 0 || address === null || address === "") return true;
|
|
59
|
+
if (typeof address !== "string") return false;
|
|
60
|
+
if (targetType === "EVM") return !(0, _arcblock_validator.vValidate)(ethVaultDidSchema, address).error;
|
|
61
|
+
if (targetType === "OCAP_ISOMORPHIC") return !(0, _arcblock_validator.vValidate)(anyDidSchema, address).error;
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
function isValidRollupValidatorAddress(address, targetType = "EVM") {
|
|
65
|
+
if (typeof address !== "string" || address.length === 0) return false;
|
|
66
|
+
if (targetType === "EVM") return !(0, _arcblock_validator.vValidate)(ethDidSchema, address).error;
|
|
67
|
+
return !(0, _arcblock_validator.vValidate)(anyDidSchema, address).error;
|
|
68
|
+
}
|
|
69
|
+
function getRollupSupportedTokens(state) {
|
|
70
|
+
const primary = typeof state?.tokenAddress === "string" && state.tokenAddress ? [state.tokenAddress] : [];
|
|
71
|
+
const extra = state?.supportedTokens ?? state?.data?.value?.supportedTokens;
|
|
72
|
+
if (!Array.isArray(extra)) return primary;
|
|
73
|
+
return (0, lodash_uniq.default)([...primary, ...extra.filter((x) => typeof x === "string" && x.length > 0)]);
|
|
74
|
+
}
|
|
75
|
+
function isTokenSupportedByRollup(state, tokenAddress) {
|
|
76
|
+
if (!state || !tokenAddress) return false;
|
|
77
|
+
if (state.tokenAddress === tokenAddress) return true;
|
|
78
|
+
return getRollupSupportedTokens(state).includes(tokenAddress);
|
|
79
|
+
}
|
|
80
|
+
function isProposerSponsoredDepositAllowed(state) {
|
|
81
|
+
const explicit = state?.allowProposerSponsor ?? state?.data?.value?.allowProposerSponsor;
|
|
82
|
+
if (typeof explicit === "boolean") return explicit;
|
|
83
|
+
return getRollupTargetType(state) !== "EVM";
|
|
84
|
+
}
|
|
85
|
+
function hasRollupReserveTracking(state) {
|
|
86
|
+
if (!state) return false;
|
|
87
|
+
if (state.reserves !== void 0) return true;
|
|
88
|
+
if (state.enforceReserveWatermark === true || state.data?.value?.enforceReserveWatermark === true) return true;
|
|
89
|
+
return getRollupTargetType(state) !== "EVM";
|
|
90
|
+
}
|
|
91
|
+
function getRollupTokenReserve(state, tokenAddress) {
|
|
92
|
+
const map = state?.reserves;
|
|
93
|
+
const entry = map && typeof map === "object" ? map[tokenAddress] : void 0;
|
|
94
|
+
return {
|
|
95
|
+
totalDeposited: typeof entry?.totalDeposited === "string" ? entry.totalDeposited : "0",
|
|
96
|
+
totalWithdrawn: typeof entry?.totalWithdrawn === "string" ? entry.totalWithdrawn : "0"
|
|
97
|
+
};
|
|
98
|
+
}
|
|
21
99
|
const isHttpOrHttpsUrl = (s) => {
|
|
22
100
|
try {
|
|
23
101
|
return ["http:", "https:"].includes(new URL(s).protocol);
|
|
@@ -30,6 +108,10 @@ const validatorSchema = _arcblock_validator.v.object({
|
|
|
30
108
|
address: (0, _arcblock_validator.vDID)({ prefix: true }),
|
|
31
109
|
endpoint: _arcblock_validator.v.pipe(_arcblock_validator.v.string(), _arcblock_validator.v.check(isHttpOrHttpsUrl, "Must be a valid HTTP/HTTPS URL"))
|
|
32
110
|
});
|
|
111
|
+
const reserveItemSchema = _arcblock_validator.v.object({
|
|
112
|
+
totalDeposited: (0, _arcblock_validator.vBN)((0, _arcblock_validator.vBNMin)(0)),
|
|
113
|
+
totalWithdrawn: (0, _arcblock_validator.vBN)((0, _arcblock_validator.vBNMin)(0))
|
|
114
|
+
});
|
|
33
115
|
const schema = _arcblock_validator.v.pipe(_arcblock_validator.v.object({
|
|
34
116
|
address: (0, _arcblock_validator.vDID)({
|
|
35
117
|
prefix: true,
|
|
@@ -39,19 +121,10 @@ const schema = _arcblock_validator.v.pipe(_arcblock_validator.v.object({
|
|
|
39
121
|
prefix: true,
|
|
40
122
|
role: "ROLE_TOKEN"
|
|
41
123
|
}),
|
|
42
|
-
contractAddress: (
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
vaultAddress: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_arcblock_validator.v.union([_arcblock_validator.v.literal(""), (0, _arcblock_validator.vDID)({ wallet: "ethereum" })]))),
|
|
47
|
-
migrateHistory: _arcblock_validator.v.optional(_arcblock_validator.v.array((0, _arcblock_validator.vDID)({
|
|
48
|
-
prefix: true,
|
|
49
|
-
wallet: "ethereum"
|
|
50
|
-
})), []),
|
|
51
|
-
vaultHistory: _arcblock_validator.v.optional(_arcblock_validator.v.array((0, _arcblock_validator.vDID)({
|
|
52
|
-
prefix: true,
|
|
53
|
-
wallet: "ethereum"
|
|
54
|
-
})), []),
|
|
124
|
+
contractAddress: _arcblock_validator.v.pipe(_arcblock_validator.v.string(), _arcblock_validator.v.minLength(1)),
|
|
125
|
+
vaultAddress: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_arcblock_validator.v.string())),
|
|
126
|
+
migrateHistory: _arcblock_validator.v.optional(_arcblock_validator.v.array(_arcblock_validator.v.pipe(_arcblock_validator.v.string(), _arcblock_validator.v.minLength(1))), []),
|
|
127
|
+
vaultHistory: _arcblock_validator.v.optional(_arcblock_validator.v.array(_arcblock_validator.v.pipe(_arcblock_validator.v.string(), _arcblock_validator.v.minLength(1))), []),
|
|
55
128
|
paused: _arcblock_validator.v.optional(_arcblock_validator.v.boolean(), false),
|
|
56
129
|
closed: _arcblock_validator.v.optional(_arcblock_validator.v.boolean(), false),
|
|
57
130
|
seedValidators: _arcblock_validator.v.pipe(_arcblock_validator.v.array(validatorSchema), _arcblock_validator.v.minLength(1)),
|
|
@@ -82,13 +155,35 @@ const schema = _arcblock_validator.v.pipe(_arcblock_validator.v.object({
|
|
|
82
155
|
leaveWaitingPeriod: _arcblock_validator.v.optional(_arcblock_validator.v.pipe(_arcblock_validator.v.number(), _arcblock_validator.v.integer()), 0),
|
|
83
156
|
publishWaitingPeriod: _arcblock_validator.v.optional(_arcblock_validator.v.pipe(_arcblock_validator.v.number(), _arcblock_validator.v.integer()), 0),
|
|
84
157
|
publishSlashRate: _arcblock_validator.v.pipe(_arcblock_validator.v.number(), _arcblock_validator.v.integer(), _arcblock_validator.v.minValue(1), _arcblock_validator.v.maxValue(1e4)),
|
|
158
|
+
targetType: _arcblock_validator.v.optional(_arcblock_validator.v.picklist(["EVM", "OCAP_ISOMORPHIC"])),
|
|
159
|
+
targetChainId: _arcblock_validator.v.optional(_arcblock_validator.v.pipe(_arcblock_validator.v.string(), _arcblock_validator.v.minLength(1), _arcblock_validator.v.maxLength(128))),
|
|
160
|
+
supportedTokens: _arcblock_validator.v.optional(_arcblock_validator.v.array((0, _arcblock_validator.vDID)({
|
|
161
|
+
prefix: true,
|
|
162
|
+
role: "ROLE_TOKEN"
|
|
163
|
+
}))),
|
|
164
|
+
reserves: _arcblock_validator.v.optional(_arcblock_validator.v.record((0, _arcblock_validator.vDID)({
|
|
165
|
+
prefix: true,
|
|
166
|
+
role: "ROLE_TOKEN"
|
|
167
|
+
}), reserveItemSchema)),
|
|
168
|
+
allowProposerSponsor: _arcblock_validator.v.optional(_arcblock_validator.v.boolean()),
|
|
169
|
+
enforceReserveWatermark: _arcblock_validator.v.optional(_arcblock_validator.v.boolean()),
|
|
85
170
|
context: _arcblock_validator.schemas.context,
|
|
86
171
|
data: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_arcblock_validator.v.any()))
|
|
87
|
-
}), _arcblock_validator.v.forward(_arcblock_validator.v.check((d) =>
|
|
172
|
+
}), _arcblock_validator.v.forward(_arcblock_validator.v.check((d) => {
|
|
173
|
+
const dataTargetType = d.data?.value?.targetType;
|
|
174
|
+
if (dataTargetType !== void 0 && !isValidRollupTargetType(dataTargetType)) return false;
|
|
175
|
+
if (d.targetType !== void 0 && dataTargetType !== void 0 && d.targetType !== dataTargetType) return false;
|
|
176
|
+
return true;
|
|
177
|
+
}, "Invalid targetType in rollup state"), ["targetType"]), _arcblock_validator.v.forward(_arcblock_validator.v.check((d) => isValidRollupContractAddress(d.contractAddress, getRollupTargetType(d)), "Expected wallet type to be \"ethereum\" or valid target chain contract address"), ["contractAddress"]), _arcblock_validator.v.forward(_arcblock_validator.v.check((d) => isValidRollupVaultAddress(d.vaultAddress, getRollupTargetType(d)), "Expected wallet type to be \"ethereum\" or valid target chain vault address"), ["vaultAddress"]), _arcblock_validator.v.forward(_arcblock_validator.v.check((d) => Array.isArray(d.migrateHistory) && d.migrateHistory.every((addr) => isValidRollupContractAddress(addr, getRollupTargetType(d))), "Expected wallet type to be \"ethereum\" or valid target chain contract address in migrateHistory"), ["migrateHistory"]), _arcblock_validator.v.forward(_arcblock_validator.v.check((d) => Array.isArray(d.vaultHistory) && d.vaultHistory.every((addr) => Boolean(addr) && isValidRollupVaultAddress(addr, getRollupTargetType(d))), "Expected wallet type to be \"ethereum\" or valid target chain vault address in vaultHistory"), ["vaultHistory"]), _arcblock_validator.v.forward(_arcblock_validator.v.check((d) => Array.isArray(d.seedValidators) && d.seedValidators.every((val) => isValidRollupValidatorAddress(val?.address, getRollupTargetType(d))), "Seed validator must use ethereum compatible keypair and address"), ["seedValidators"]), _arcblock_validator.v.forward(_arcblock_validator.v.check((d) => Array.isArray(d.validators) && d.validators.every((val) => isValidRollupValidatorAddress(val?.address, getRollupTargetType(d))), "Expected wallet type to be \"ethereum\" or valid target chain validator address in validators"), ["validators"]), _arcblock_validator.v.forward(_arcblock_validator.v.check((d) => new _ocap_util.BN(d.maxStakeAmount).gte(new _ocap_util.BN(d.minStakeAmount)), "maxStakeAmount must be >= minStakeAmount"), ["maxStakeAmount"]), _arcblock_validator.v.forward(_arcblock_validator.v.check((d) => d.minSignerCount >= d.seedValidators.length, "minSignerCount must be >= seedValidators count"), ["minSignerCount"]), _arcblock_validator.v.forward(_arcblock_validator.v.check((d) => d.maxSignerCount >= d.minSignerCount, "maxSignerCount must be >= minSignerCount"), ["maxSignerCount"]), _arcblock_validator.v.forward(_arcblock_validator.v.check((d) => d.maxBlockSize >= d.minBlockSize, "maxBlockSize must be >= minBlockSize"), ["maxBlockSize"]), _arcblock_validator.v.forward(_arcblock_validator.v.check((d) => new _ocap_util.BN(d.minDepositAmount).lt(new _ocap_util.BN(d.minStakeAmount)), "minDepositAmount must be < minStakeAmount"), ["minDepositAmount"]), _arcblock_validator.v.forward(_arcblock_validator.v.check((d) => {
|
|
88
178
|
const max = new _ocap_util.BN(d.maxDepositAmount);
|
|
89
179
|
return max.gt(new _ocap_util.BN(d.minDepositAmount)) && max.lt(new _ocap_util.BN(d.minStakeAmount));
|
|
90
180
|
}, "maxDepositAmount must be > minDepositAmount and < minStakeAmount"), ["maxDepositAmount"]), _arcblock_validator.v.forward(_arcblock_validator.v.check((d) => new _ocap_util.BN(d.maxWithdrawAmount).gt(new _ocap_util.BN(d.minWithdrawAmount)), "maxWithdrawAmount must be > minWithdrawAmount"), ["maxWithdrawAmount"]), _arcblock_validator.v.forward(_arcblock_validator.v.check((d) => new _ocap_util.BN(d.maxDepositFee).gte(new _ocap_util.BN(d.minDepositFee)), "maxDepositFee must be >= minDepositFee"), ["maxDepositFee"]), _arcblock_validator.v.forward(_arcblock_validator.v.check((d) => new _ocap_util.BN(d.maxWithdrawFee).gte(new _ocap_util.BN(d.minWithdrawFee)), "maxWithdrawFee must be >= minWithdrawFee"), ["maxWithdrawFee"]), _arcblock_validator.v.forward(_arcblock_validator.v.check((d) => d.leaveWaitingPeriod >= d.minBlockInterval, "leaveWaitingPeriod must be >= minBlockInterval"), ["leaveWaitingPeriod"]), _arcblock_validator.v.forward(_arcblock_validator.v.check((d) => d.publishWaitingPeriod >= d.minBlockInterval, "publishWaitingPeriod must be >= minBlockInterval"), ["publishWaitingPeriod"]), (0, _arcblock_validator.vStripUnknown)());
|
|
91
181
|
const create = (attrs, context) => {
|
|
182
|
+
if (attrs?.data?.value?.reserves !== void 0) throw new _ocap_util_lib_error.CustomError("INVALID_ROLLUP_PROPS", "reserves cannot be defined inside data.value");
|
|
183
|
+
if (attrs?.reserves && typeof attrs.reserves === "object") {
|
|
184
|
+
for (const [tokenAddr, reserve] of Object.entries(attrs.reserves)) if (new _ocap_util.BN(reserve?.totalDeposited || "0").gt(new _ocap_util.BN(0)) || new _ocap_util.BN(reserve?.totalWithdrawn || "0").gt(new _ocap_util.BN(0))) throw new _ocap_util_lib_error.CustomError("INVALID_ROLLUP_PROPS", `Cannot pre-seed non-zero reserve watermark for token ${tokenAddr} on rollup creation`);
|
|
185
|
+
}
|
|
186
|
+
const dataValue = attrs?.data?.value && typeof attrs.data.value === "object" ? attrs.data.value : void 0;
|
|
92
187
|
const rollup = {
|
|
93
188
|
context: require_contexts_state.create(context),
|
|
94
189
|
paused: false,
|
|
@@ -128,9 +223,22 @@ const create = (attrs, context) => {
|
|
|
128
223
|
"publishWaitingPeriod",
|
|
129
224
|
"publishSlashRate",
|
|
130
225
|
"issuer",
|
|
226
|
+
"targetType",
|
|
227
|
+
"targetChainId",
|
|
228
|
+
"supportedTokens",
|
|
229
|
+
"reserves",
|
|
230
|
+
"allowProposerSponsor",
|
|
231
|
+
"enforceReserveWatermark",
|
|
131
232
|
"data"
|
|
132
233
|
])
|
|
133
234
|
};
|
|
235
|
+
if (dataValue) {
|
|
236
|
+
if (rollup.targetType === void 0 && dataValue.targetType !== void 0) rollup.targetType = dataValue.targetType;
|
|
237
|
+
if (rollup.targetChainId === void 0 && typeof dataValue.targetChainId === "string") rollup.targetChainId = dataValue.targetChainId;
|
|
238
|
+
if (rollup.supportedTokens === void 0 && Array.isArray(dataValue.supportedTokens)) rollup.supportedTokens = dataValue.supportedTokens;
|
|
239
|
+
if (rollup.allowProposerSponsor === void 0 && typeof dataValue.allowProposerSponsor === "boolean") rollup.allowProposerSponsor = dataValue.allowProposerSponsor;
|
|
240
|
+
if (rollup.enforceReserveWatermark === void 0 && typeof dataValue.enforceReserveWatermark === "boolean") rollup.enforceReserveWatermark = dataValue.enforceReserveWatermark;
|
|
241
|
+
}
|
|
134
242
|
rollup.address = (0, _ocap_util.toAddress)(rollup.address);
|
|
135
243
|
return validate(rollup);
|
|
136
244
|
};
|
|
@@ -143,7 +251,16 @@ const update = (state, updates, context) => {
|
|
|
143
251
|
}
|
|
144
252
|
if (typeof updates.blockHeight !== "undefined" && !updates.blockHeight) throw new _ocap_util_lib_error.CustomError("INVALID_ROLLUP_UPDATE", "blockHeight can not be unset");
|
|
145
253
|
if (typeof updates.blockHash !== "undefined" && !updates.blockHash) throw new _ocap_util_lib_error.CustomError("INVALID_ROLLUP_UPDATE", "blockHash can not be unset");
|
|
146
|
-
|
|
254
|
+
if (updates?.data?.value?.reserves !== void 0) throw new _ocap_util_lib_error.CustomError("INVALID_ROLLUP_UPDATE", "reserves cannot be updated inside data.value");
|
|
255
|
+
const currentTargetType = getRollupTargetType(state);
|
|
256
|
+
const nextTargetType = updates.targetType ?? updates.data?.value?.targetType;
|
|
257
|
+
if (nextTargetType !== void 0 && nextTargetType !== currentTargetType) throw new _ocap_util_lib_error.CustomError("INVALID_ROLLUP_UPDATE", "targetType cannot be changed after rollup creation");
|
|
258
|
+
const currentChainId = state.targetChainId ?? state.data?.value?.targetChainId;
|
|
259
|
+
const nextChainId = updates.targetChainId ?? updates.data?.value?.targetChainId;
|
|
260
|
+
if (currentChainId && nextChainId !== void 0 && nextChainId !== currentChainId) throw new _ocap_util_lib_error.CustomError("INVALID_ROLLUP_UPDATE", "targetChainId cannot be changed after rollup creation");
|
|
261
|
+
const wasEnforcingWatermark = state.enforceReserveWatermark === true || state.data?.value?.enforceReserveWatermark === true;
|
|
262
|
+
if (wasEnforcingWatermark && (updates.enforceReserveWatermark === false || updates.data?.value?.enforceReserveWatermark === false)) throw new _ocap_util_lib_error.CustomError("INVALID_ROLLUP_UPDATE", "enforceReserveWatermark cannot be disabled once enabled");
|
|
263
|
+
const rollup = {
|
|
147
264
|
...state,
|
|
148
265
|
...(0, lodash_pick.default)(updates, [
|
|
149
266
|
"validators",
|
|
@@ -171,10 +288,18 @@ const update = (state, updates, context) => {
|
|
|
171
288
|
"leaveWaitingPeriod",
|
|
172
289
|
"publishWaitingPeriod",
|
|
173
290
|
"publishSlashRate",
|
|
291
|
+
"targetType",
|
|
292
|
+
"targetChainId",
|
|
293
|
+
"supportedTokens",
|
|
294
|
+
"reserves",
|
|
295
|
+
"allowProposerSponsor",
|
|
296
|
+
"enforceReserveWatermark",
|
|
174
297
|
"data"
|
|
175
298
|
]),
|
|
176
299
|
context: require_contexts_state.update(state.context, context)
|
|
177
|
-
}
|
|
300
|
+
};
|
|
301
|
+
if (wasEnforcingWatermark) rollup.enforceReserveWatermark = true;
|
|
302
|
+
return validate(rollup);
|
|
178
303
|
};
|
|
179
304
|
const pause = (state, context) => {
|
|
180
305
|
if (state.closed) throw new _ocap_util_lib_error.CustomError("INVALID_PAUSE_ATTEMPT", "rollup already closed");
|
|
@@ -206,6 +331,7 @@ const resume = (state, context) => {
|
|
|
206
331
|
const migrateContract = (state, to, context) => {
|
|
207
332
|
if (state.closed) throw new _ocap_util_lib_error.CustomError("INVALID_MIGRATE_ATTEMPT", "rollup is closed");
|
|
208
333
|
if (state.paused === false) throw new _ocap_util_lib_error.CustomError("INVALID_MIGRATE_ATTEMPT", "rollup not paused");
|
|
334
|
+
if (!to || typeof to !== "string") throw new _ocap_util_lib_error.CustomError("INVALID_MIGRATE_ATTEMPT", "invalid contract address");
|
|
209
335
|
if (state.contractAddress === to) throw new _ocap_util_lib_error.CustomError("INVALID_MIGRATE_ATTEMPT", "can not migrate contract to self");
|
|
210
336
|
if (state.migrateHistory.includes(to)) throw new _ocap_util_lib_error.CustomError("INVALID_MIGRATE_ATTEMPT", "can not migrate contract to history contracts");
|
|
211
337
|
return validate({
|
|
@@ -218,28 +344,90 @@ const migrateContract = (state, to, context) => {
|
|
|
218
344
|
const migrateVault = (state, to, context) => {
|
|
219
345
|
if (state.closed) throw new _ocap_util_lib_error.CustomError("INVALID_MIGRATE_ATTEMPT", "rollup is closed");
|
|
220
346
|
if (state.paused === false) throw new _ocap_util_lib_error.CustomError("INVALID_MIGRATE_ATTEMPT", "rollup not paused");
|
|
347
|
+
if (!to || typeof to !== "string") throw new _ocap_util_lib_error.CustomError("INVALID_MIGRATE_ATTEMPT", "invalid vault address");
|
|
221
348
|
if (state.vaultAddress === to) throw new _ocap_util_lib_error.CustomError("INVALID_MIGRATE_ATTEMPT", "can not migrate vault to self");
|
|
222
349
|
if (state.vaultHistory.includes(to)) throw new _ocap_util_lib_error.CustomError("INVALID_MIGRATE_ATTEMPT", "can not migrate vault to history vaults");
|
|
223
350
|
return validate({
|
|
224
351
|
...state,
|
|
225
352
|
vaultAddress: to,
|
|
226
|
-
vaultHistory: [...state.vaultHistory, state.vaultAddress],
|
|
353
|
+
vaultHistory: state.vaultAddress ? [...state.vaultHistory, state.vaultAddress] : [...state.vaultHistory],
|
|
227
354
|
context: require_contexts_state.update(state.context, context)
|
|
228
355
|
});
|
|
229
356
|
};
|
|
357
|
+
const recordRollupDeposit = (state, tokenAddress, amount, context) => {
|
|
358
|
+
if (!isTokenSupportedByRollup(state, tokenAddress)) throw new _ocap_util_lib_error.CustomError("INVALID_ROLLUP_TOKEN", `Token ${tokenAddress} is not supported by rollup ${state.address}`);
|
|
359
|
+
let amountBn;
|
|
360
|
+
try {
|
|
361
|
+
amountBn = new _ocap_util.BN(amount);
|
|
362
|
+
} catch {
|
|
363
|
+
throw new _ocap_util_lib_error.CustomError("INVALID_DEPOSIT_AMOUNT", `Invalid deposit amount: ${amount}`);
|
|
364
|
+
}
|
|
365
|
+
if (amountBn.lte(new _ocap_util.BN(0))) throw new _ocap_util_lib_error.CustomError("INVALID_DEPOSIT_AMOUNT", `Deposit amount must be positive: ${amount}`);
|
|
366
|
+
const currentReserves = state.reserves ?? {};
|
|
367
|
+
const prev = getRollupTokenReserve(state, tokenAddress);
|
|
368
|
+
const nextReserve = {
|
|
369
|
+
totalDeposited: new _ocap_util.BN(prev.totalDeposited).add(amountBn).toString(10),
|
|
370
|
+
totalWithdrawn: prev.totalWithdrawn
|
|
371
|
+
};
|
|
372
|
+
return update(state, { reserves: {
|
|
373
|
+
...currentReserves,
|
|
374
|
+
[tokenAddress]: nextReserve
|
|
375
|
+
} }, context);
|
|
376
|
+
};
|
|
377
|
+
const recordRollupWithdraw = (state, tokenAddress, amount, context) => {
|
|
378
|
+
if (!isTokenSupportedByRollup(state, tokenAddress)) throw new _ocap_util_lib_error.CustomError("INVALID_ROLLUP_TOKEN", `Token ${tokenAddress} is not supported by rollup ${state.address}`);
|
|
379
|
+
let amountBn;
|
|
380
|
+
try {
|
|
381
|
+
amountBn = new _ocap_util.BN(amount);
|
|
382
|
+
} catch {
|
|
383
|
+
throw new _ocap_util_lib_error.CustomError("INVALID_WITHDRAW_AMOUNT", `Invalid withdraw amount: ${amount}`);
|
|
384
|
+
}
|
|
385
|
+
if (amountBn.lte(new _ocap_util.BN(0))) throw new _ocap_util_lib_error.CustomError("INVALID_WITHDRAW_AMOUNT", `Withdraw amount must be positive: ${amount}`);
|
|
386
|
+
const currentReserves = state.reserves ?? {};
|
|
387
|
+
const prev = getRollupTokenReserve(state, tokenAddress);
|
|
388
|
+
const nextWithdrawn = new _ocap_util.BN(prev.totalWithdrawn).add(amountBn);
|
|
389
|
+
const totalDeposited = new _ocap_util.BN(prev.totalDeposited);
|
|
390
|
+
if (nextWithdrawn.gt(totalDeposited)) throw new _ocap_util_lib_error.CustomError("INSUFFICIENT_ROLLUP_RESERVE", `Withdraw amount (${amount}) exceeds rollup net inflow reserve watermark for token ${tokenAddress}: cumulativeWithdrawn (${nextWithdrawn.toString(10)}) > cumulativeDeposited (${totalDeposited.toString(10)})`);
|
|
391
|
+
const nextReserve = {
|
|
392
|
+
totalDeposited: prev.totalDeposited,
|
|
393
|
+
totalWithdrawn: nextWithdrawn.toString(10)
|
|
394
|
+
};
|
|
395
|
+
return update(state, { reserves: {
|
|
396
|
+
...currentReserves,
|
|
397
|
+
[tokenAddress]: nextReserve
|
|
398
|
+
} }, context);
|
|
399
|
+
};
|
|
230
400
|
const validate = (state) => {
|
|
401
|
+
if (state?.data?.value?.reserves !== void 0) throw new _ocap_util_lib_error.CustomError("INVALID_ROLLUP_PROPS", "reserves cannot be defined inside data.value");
|
|
231
402
|
const { value, error } = (0, _arcblock_validator.vValidate)(schema, state);
|
|
232
403
|
if (error) throw new _ocap_util_lib_error.CustomError("INVALID_ROLLUP_PROPS", error.details.map((x) => x.message).join(", "));
|
|
404
|
+
if (value.reserves && typeof value.reserves === "object") for (const [tokenAddr, reserve] of Object.entries(value.reserves)) {
|
|
405
|
+
if (!isTokenSupportedByRollup(value, tokenAddr)) throw new _ocap_util_lib_error.CustomError("INVALID_ROLLUP_PROPS", `Reserve token ${tokenAddr} is not supported by rollup`);
|
|
406
|
+
if (new _ocap_util.BN(reserve.totalWithdrawn).gt(new _ocap_util.BN(reserve.totalDeposited))) throw new _ocap_util_lib_error.CustomError("INVALID_ROLLUP_PROPS", `Cumulative withdrawn (${reserve.totalWithdrawn}) exceeds cumulative deposited (${reserve.totalDeposited}) for token ${tokenAddr}`);
|
|
407
|
+
}
|
|
233
408
|
if (!value.data) value.data = null;
|
|
234
409
|
return value;
|
|
235
410
|
};
|
|
236
411
|
|
|
237
412
|
//#endregion
|
|
413
|
+
exports.VALID_ROLLUP_TARGET_TYPES = VALID_ROLLUP_TARGET_TYPES;
|
|
238
414
|
exports.close = close;
|
|
239
415
|
exports.create = create;
|
|
416
|
+
exports.getRollupSupportedTokens = getRollupSupportedTokens;
|
|
417
|
+
exports.getRollupTargetType = getRollupTargetType;
|
|
418
|
+
exports.getRollupTokenReserve = getRollupTokenReserve;
|
|
419
|
+
exports.hasRollupReserveTracking = hasRollupReserveTracking;
|
|
420
|
+
exports.isProposerSponsoredDepositAllowed = isProposerSponsoredDepositAllowed;
|
|
421
|
+
exports.isTokenSupportedByRollup = isTokenSupportedByRollup;
|
|
422
|
+
exports.isValidRollupContractAddress = isValidRollupContractAddress;
|
|
423
|
+
exports.isValidRollupTargetType = isValidRollupTargetType;
|
|
424
|
+
exports.isValidRollupValidatorAddress = isValidRollupValidatorAddress;
|
|
425
|
+
exports.isValidRollupVaultAddress = isValidRollupVaultAddress;
|
|
240
426
|
exports.migrateContract = migrateContract;
|
|
241
427
|
exports.migrateVault = migrateVault;
|
|
242
428
|
exports.pause = pause;
|
|
429
|
+
exports.recordRollupDeposit = recordRollupDeposit;
|
|
430
|
+
exports.recordRollupWithdraw = recordRollupWithdraw;
|
|
243
431
|
exports.resume = resume;
|
|
244
432
|
Object.defineProperty(exports, 'rollup_exports', {
|
|
245
433
|
enumerable: true,
|
package/lib/states/rollup.d.cts
CHANGED
|
@@ -4,15 +4,31 @@ import { v } from "@arcblock/validator";
|
|
|
4
4
|
|
|
5
5
|
//#region src/states/rollup.d.ts
|
|
6
6
|
declare namespace rollup_d_exports {
|
|
7
|
-
export { close, create, migrateContract, migrateVault, pause, resume, schema, update, validate };
|
|
7
|
+
export { RollupTargetType, RollupTokenReserve, VALID_ROLLUP_TARGET_TYPES, close, create, getRollupSupportedTokens, getRollupTargetType, getRollupTokenReserve, hasRollupReserveTracking, isProposerSponsoredDepositAllowed, isTokenSupportedByRollup, isValidRollupContractAddress, isValidRollupTargetType, isValidRollupValidatorAddress, isValidRollupVaultAddress, migrateContract, migrateVault, pause, recordRollupDeposit, recordRollupWithdraw, resume, schema, update, validate };
|
|
8
8
|
}
|
|
9
|
+
type RollupTargetType = 'EVM' | 'OCAP_ISOMORPHIC';
|
|
10
|
+
interface RollupTokenReserve {
|
|
11
|
+
totalDeposited: string;
|
|
12
|
+
totalWithdrawn: string;
|
|
13
|
+
}
|
|
14
|
+
declare const VALID_ROLLUP_TARGET_TYPES: readonly RollupTargetType[];
|
|
15
|
+
declare function isValidRollupTargetType(value: unknown): value is RollupTargetType;
|
|
16
|
+
declare function getRollupTargetType(state?: Record<string, any> | null): RollupTargetType;
|
|
17
|
+
declare function isValidRollupContractAddress(address: unknown, targetType?: RollupTargetType): boolean;
|
|
18
|
+
declare function isValidRollupVaultAddress(address: unknown, targetType?: RollupTargetType): boolean;
|
|
19
|
+
declare function isValidRollupValidatorAddress(address: unknown, targetType?: RollupTargetType): boolean;
|
|
20
|
+
declare function getRollupSupportedTokens(state?: Record<string, any> | null): string[];
|
|
21
|
+
declare function isTokenSupportedByRollup(state: Record<string, any> | null | undefined, tokenAddress: string): boolean;
|
|
22
|
+
declare function isProposerSponsoredDepositAllowed(state?: Record<string, any> | null): boolean;
|
|
23
|
+
declare function hasRollupReserveTracking(state?: Record<string, any> | null): boolean;
|
|
24
|
+
declare function getRollupTokenReserve(state: Record<string, any> | null | undefined, tokenAddress: string): RollupTokenReserve;
|
|
9
25
|
declare const schema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
10
26
|
readonly address: any;
|
|
11
27
|
readonly tokenAddress: any;
|
|
12
|
-
readonly contractAddress:
|
|
13
|
-
readonly vaultAddress: v.OptionalSchema<v.NullableSchema<v.
|
|
14
|
-
readonly migrateHistory: v.OptionalSchema<v.ArraySchema<
|
|
15
|
-
readonly vaultHistory: v.OptionalSchema<v.ArraySchema<
|
|
28
|
+
readonly contractAddress: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
29
|
+
readonly vaultAddress: v.OptionalSchema<v.NullableSchema<v.StringSchema<undefined>, undefined>, undefined>;
|
|
30
|
+
readonly migrateHistory: v.OptionalSchema<v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>, undefined>, readonly []>;
|
|
31
|
+
readonly vaultHistory: v.OptionalSchema<v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>, undefined>, readonly []>;
|
|
16
32
|
readonly paused: v.OptionalSchema<v.BooleanSchema<undefined>, false>;
|
|
17
33
|
readonly closed: v.OptionalSchema<v.BooleanSchema<undefined>, false>;
|
|
18
34
|
readonly seedValidators: v.SchemaWithPipe<readonly [v.ArraySchema<v.ObjectSchema<{
|
|
@@ -59,6 +75,15 @@ declare const schema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
|
59
75
|
readonly leaveWaitingPeriod: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>, 0>;
|
|
60
76
|
readonly publishWaitingPeriod: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>, 0>;
|
|
61
77
|
readonly publishSlashRate: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>, v.MaxValueAction<number, 10000, undefined>]>;
|
|
78
|
+
readonly targetType: v.OptionalSchema<v.PicklistSchema<["EVM", "OCAP_ISOMORPHIC"], undefined>, undefined>;
|
|
79
|
+
readonly targetChainId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 128, undefined>]>, undefined>;
|
|
80
|
+
readonly supportedTokens: v.OptionalSchema<v.ArraySchema<any, undefined>, undefined>;
|
|
81
|
+
readonly reserves: v.OptionalSchema<v.RecordSchema<any, v.ObjectSchema<{
|
|
82
|
+
readonly totalDeposited: any;
|
|
83
|
+
readonly totalWithdrawn: any;
|
|
84
|
+
}, undefined>, undefined>, undefined>;
|
|
85
|
+
readonly allowProposerSponsor: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
86
|
+
readonly enforceReserveWatermark: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
62
87
|
readonly context: v.ObjectSchema<{
|
|
63
88
|
readonly genesisTime: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must be valid ISO date">]>;
|
|
64
89
|
readonly genesisTx: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must match tx hash pattern or be empty">]>;
|
|
@@ -66,14 +91,16 @@ declare const schema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
|
66
91
|
readonly renaissanceTx: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must match tx hash pattern or be empty">]>;
|
|
67
92
|
}, undefined>;
|
|
68
93
|
readonly data: v.OptionalSchema<v.NullableSchema<v.AnySchema, undefined>, undefined>;
|
|
69
|
-
}, undefined>, v.BaseValidation<any, any, v.CheckIssue<any>>, v.BaseValidation<any, any, v.CheckIssue<any>>, v.BaseValidation<any, any, v.CheckIssue<any>>, v.BaseValidation<any, any, v.CheckIssue<any>>, v.BaseValidation<any, any, v.CheckIssue<any>>, v.BaseValidation<any, any, v.CheckIssue<any>>, v.BaseValidation<any, any, v.CheckIssue<any>>, v.BaseValidation<any, any, v.CheckIssue<any>>, v.BaseValidation<any, any, v.CheckIssue<any>>, v.BaseValidation<any, any, v.CheckIssue<any>>, v.BaseValidation<any, any, v.CheckIssue<any>>, any]>;
|
|
70
|
-
declare const create: (attrs: Partial<IRollupState>, context: StateContextInput) => IRollupState;
|
|
71
|
-
declare const update: (state: IRollupState, updates: Partial<IRollupState>, context: StateContextInput) => IRollupState;
|
|
94
|
+
}, undefined>, v.BaseValidation<any, any, v.CheckIssue<any>>, v.BaseValidation<any, any, v.CheckIssue<any>>, v.BaseValidation<any, any, v.CheckIssue<any>>, v.BaseValidation<any, any, v.CheckIssue<any>>, v.BaseValidation<any, any, v.CheckIssue<any>>, v.BaseValidation<any, any, v.CheckIssue<any>>, v.BaseValidation<any, any, v.CheckIssue<any>>, v.BaseValidation<any, any, v.CheckIssue<any>>, v.BaseValidation<any, any, v.CheckIssue<any>>, v.BaseValidation<any, any, v.CheckIssue<any>>, v.BaseValidation<any, any, v.CheckIssue<any>>, v.BaseValidation<any, any, v.CheckIssue<any>>, v.BaseValidation<any, any, v.CheckIssue<any>>, v.BaseValidation<any, any, v.CheckIssue<any>>, v.BaseValidation<any, any, v.CheckIssue<any>>, v.BaseValidation<any, any, v.CheckIssue<any>>, v.BaseValidation<any, any, v.CheckIssue<any>>, v.BaseValidation<any, any, v.CheckIssue<any>>, any]>;
|
|
95
|
+
declare const create: (attrs: Partial<IRollupState> & Record<string, any>, context: StateContextInput) => IRollupState;
|
|
96
|
+
declare const update: (state: IRollupState, updates: Partial<IRollupState> & Record<string, any>, context: StateContextInput) => IRollupState;
|
|
72
97
|
declare const pause: (state: IRollupState, context: StateContextInput) => IRollupState;
|
|
73
98
|
declare const close: (state: IRollupState, context: StateContextInput) => IRollupState;
|
|
74
99
|
declare const resume: (state: IRollupState, context: StateContextInput) => IRollupState;
|
|
75
100
|
declare const migrateContract: (state: IRollupState, to: string, context: StateContextInput) => IRollupState;
|
|
76
101
|
declare const migrateVault: (state: IRollupState, to: string, context: StateContextInput) => IRollupState;
|
|
77
|
-
declare const
|
|
102
|
+
declare const recordRollupDeposit: (state: IRollupState & Record<string, any>, tokenAddress: string, amount: string, context: StateContextInput) => IRollupState;
|
|
103
|
+
declare const recordRollupWithdraw: (state: IRollupState & Record<string, any>, tokenAddress: string, amount: string, context: StateContextInput) => IRollupState;
|
|
104
|
+
declare const validate: (state: IRollupState & Record<string, any>) => IRollupState;
|
|
78
105
|
//#endregion
|
|
79
|
-
export { close, create, migrateContract, migrateVault, pause, resume, rollup_d_exports, schema, update, validate };
|
|
106
|
+
export { RollupTargetType, RollupTokenReserve, VALID_ROLLUP_TARGET_TYPES, close, create, getRollupSupportedTokens, getRollupTargetType, getRollupTokenReserve, hasRollupReserveTracking, isProposerSponsoredDepositAllowed, isTokenSupportedByRollup, isValidRollupContractAddress, isValidRollupTargetType, isValidRollupValidatorAddress, isValidRollupVaultAddress, migrateContract, migrateVault, pause, recordRollupDeposit, recordRollupWithdraw, resume, rollup_d_exports, schema, update, validate };
|