@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
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { applyTokenChange, applyTokenUpdates } from "../../util.mjs";
|
|
2
2
|
import ensure_cost_default from "../../pipes/ensure-cost.mjs";
|
|
3
3
|
import ensure_gas_default from "../../pipes/ensure-gas.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { LEGACY_REVOKE_KEY, consumeStakeRevoke, normalizeStakeRevokes } from "./revoke-ledger.mjs";
|
|
5
|
+
import { account, asset, evidence, stake, token } from "@ocap/state";
|
|
5
6
|
import { Runner, pipes } from "@ocap/tx-pipeline";
|
|
6
7
|
import { BN } from "@ocap/util";
|
|
7
8
|
import { CustomError } from "@ocap/util/lib/error";
|
|
9
|
+
import { getRelatedAddresses } from "@ocap/util/lib/get-related-addr";
|
|
8
10
|
import Debug from "debug";
|
|
9
11
|
import { patterns, v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
10
|
-
import
|
|
12
|
+
import uniqBy from "lodash/uniqBy.js";
|
|
11
13
|
|
|
12
14
|
//#region src/protocols/governance/claim-stake.ts
|
|
13
15
|
const debug = Debug("@ocap/tx-protocols:claim-stake");
|
|
@@ -41,6 +43,7 @@ runner.use(pipes.VerifyAccountMigration({
|
|
|
41
43
|
stateKey: "senderState",
|
|
42
44
|
addressKey: "tx.from"
|
|
43
45
|
}));
|
|
46
|
+
runner.use(pipes.VerifyBlocked({ stateKeys: ["senderState", "delegatorState"] }));
|
|
44
47
|
runner.use(pipes.VerifyInfo([{
|
|
45
48
|
error: "SENDER_NOT_MATCH",
|
|
46
49
|
message: "You are not allowed to claim stake from this address",
|
|
@@ -98,8 +101,16 @@ runner.use(pipes.VerifyInfo([
|
|
|
98
101
|
error: "WITHIN_WAITING_PERIOD",
|
|
99
102
|
message: "You can not claim stake before waiting period ends",
|
|
100
103
|
fn: (ctx) => {
|
|
101
|
-
const { txState, stakeState, txTime } = ctx;
|
|
102
|
-
const
|
|
104
|
+
const { itx, txState, stakeState, txTime } = ctx;
|
|
105
|
+
const waitingMs = (stakeState.revokeWaitingPeriod || 0) * 1e3;
|
|
106
|
+
const txEnd = +new Date(txState.time) + waitingMs;
|
|
107
|
+
const revokes = normalizeStakeRevokes(stakeState);
|
|
108
|
+
const evidenceHash = itx.evidence?.hash || "";
|
|
109
|
+
const trackedEntry = Object.hasOwn(revokes, evidenceHash) ? revokes[evidenceHash] : void 0;
|
|
110
|
+
const legacyEntry = Object.hasOwn(revokes, LEGACY_REVOKE_KEY) ? revokes[LEGACY_REVOKE_KEY] : void 0;
|
|
111
|
+
const baseTime = trackedEntry ? trackedEntry.txTime : legacyEntry?.txTime || stakeState.context?.renaissanceTime;
|
|
112
|
+
const stateEnd = baseTime ? +new Date(baseTime) + waitingMs : 0;
|
|
113
|
+
const end = Math.max(txEnd, stateEnd);
|
|
103
114
|
return +new Date(txTime) > end;
|
|
104
115
|
}
|
|
105
116
|
}
|
|
@@ -111,12 +122,69 @@ runner.use(pipes.VerifyTxInput({
|
|
|
111
122
|
tokensKey: "tokens",
|
|
112
123
|
assetsKey: "assets"
|
|
113
124
|
}));
|
|
125
|
+
runner.use((context, next) => {
|
|
126
|
+
const { itx, outputs = [], stakeState } = context;
|
|
127
|
+
const ZERO = new BN(0);
|
|
128
|
+
const revokes = normalizeStakeRevokes(stakeState);
|
|
129
|
+
const evidenceHash = itx.evidence?.hash || "";
|
|
130
|
+
const targetBucket = Object.hasOwn(revokes, evidenceHash) ? revokes[evidenceHash] : Object.hasOwn(revokes, LEGACY_REVOKE_KEY) ? revokes[LEGACY_REVOKE_KEY] : void 0;
|
|
131
|
+
const bucketTokens = targetBucket?.tokens || {};
|
|
132
|
+
const bucketAssets = new Set(targetBucket?.assets || []);
|
|
133
|
+
const availableRevokedTokens = {};
|
|
134
|
+
Object.entries(stakeState.revokedTokens || {}).forEach(([addr, val]) => {
|
|
135
|
+
const totalAvail = new BN(val || "0");
|
|
136
|
+
const bucketAvail = new BN(bucketTokens[addr] || "0");
|
|
137
|
+
availableRevokedTokens[addr] = BN.min(totalAvail, bucketAvail);
|
|
138
|
+
});
|
|
139
|
+
const availableRevokedAssets = new Set((stakeState.revokedAssets || []).filter((a) => bucketAssets.has(a)));
|
|
140
|
+
let hasClaimable = false;
|
|
141
|
+
const clampedOutputs = [];
|
|
142
|
+
outputs.forEach((output) => {
|
|
143
|
+
const rawTokens = output.tokens || output.tokensList || [];
|
|
144
|
+
const clampedTokens = [];
|
|
145
|
+
rawTokens.forEach(({ address, value }) => {
|
|
146
|
+
const requested = new BN(value || "0");
|
|
147
|
+
const available = availableRevokedTokens[address] || ZERO;
|
|
148
|
+
const actual = BN.min(requested, available);
|
|
149
|
+
if (actual.gt(ZERO)) {
|
|
150
|
+
clampedTokens.push({
|
|
151
|
+
address,
|
|
152
|
+
value: actual.toString(10)
|
|
153
|
+
});
|
|
154
|
+
availableRevokedTokens[address] = available.sub(actual);
|
|
155
|
+
hasClaimable = true;
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
const clampedAssets = (output.assets || output.assetsList || []).filter((assetAddr) => {
|
|
159
|
+
if (availableRevokedAssets.has(assetAddr)) {
|
|
160
|
+
availableRevokedAssets.delete(assetAddr);
|
|
161
|
+
hasClaimable = true;
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
return false;
|
|
165
|
+
});
|
|
166
|
+
if (clampedTokens.length > 0 || clampedAssets.length > 0) clampedOutputs.push({
|
|
167
|
+
...output,
|
|
168
|
+
tokens: clampedTokens,
|
|
169
|
+
tokensList: clampedTokens,
|
|
170
|
+
assets: clampedAssets,
|
|
171
|
+
assetsList: clampedAssets
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
if (!hasClaimable) return next(new CustomError("INSUFFICIENT_FUND", "Account does not have enough token balance"));
|
|
175
|
+
context.outputs = clampedOutputs;
|
|
176
|
+
context.receivers = Array.from(new Set(clampedOutputs.map((o) => o.owner)));
|
|
177
|
+
context.tokens = Array.from(new Set(clampedOutputs.flatMap((o) => o.tokens.map((t) => t.address))));
|
|
178
|
+
context.assets = Array.from(new Set(clampedOutputs.flatMap((o) => o.assets)));
|
|
179
|
+
return next();
|
|
180
|
+
});
|
|
114
181
|
runner.use(pipes.ExtractState({
|
|
115
182
|
from: "receivers",
|
|
116
183
|
to: "receiverStates",
|
|
117
184
|
status: "INVALID_RECEIVER_STATE",
|
|
118
185
|
table: "account"
|
|
119
186
|
}));
|
|
187
|
+
runner.use(pipes.VerifyBlocked({ stateKeys: ["receiverStates"] }));
|
|
120
188
|
runner.use(pipes.ExtractState({
|
|
121
189
|
from: "tokens",
|
|
122
190
|
to: "tokenStates",
|
|
@@ -149,10 +217,27 @@ runner.use(pipes.VerifyTokenBalance({
|
|
|
149
217
|
runner.use(pipes.ExtractState({
|
|
150
218
|
from: "assets",
|
|
151
219
|
to: "assetStates",
|
|
152
|
-
status: "
|
|
220
|
+
status: "INVALID_ASSET_STATE",
|
|
153
221
|
table: "asset"
|
|
154
222
|
}));
|
|
155
|
-
runner.use(pipes.VerifyTransferrable({
|
|
223
|
+
runner.use(pipes.VerifyTransferrable({
|
|
224
|
+
assets: "assetStates",
|
|
225
|
+
allowConsumed: true
|
|
226
|
+
}));
|
|
227
|
+
runner.use(pipes.VerifyInfo([{
|
|
228
|
+
error: "UNTRANSFERRABLE_ASSET",
|
|
229
|
+
message: "Consumed assets can only be claimed back to the stake sender",
|
|
230
|
+
fn: (ctx) => {
|
|
231
|
+
const { outputs = [], assetStates = [], receiverStates = [], stakeState } = ctx;
|
|
232
|
+
const consumed = new Set(assetStates.filter((a) => a.consumedTime).map((a) => a.address));
|
|
233
|
+
if (consumed.size === 0) return true;
|
|
234
|
+
return outputs.every((o) => {
|
|
235
|
+
if (!(o.assets || o.assetsList || []).some((a) => consumed.has(a))) return true;
|
|
236
|
+
const rs = receiverStates.find((s) => getRelatedAddresses(s).includes(o.owner));
|
|
237
|
+
return !!rs && getRelatedAddresses(rs).includes(stakeState.sender);
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
}]));
|
|
156
241
|
runner.use(pipes.VerifyUpdater({
|
|
157
242
|
assetKey: "assetStates",
|
|
158
243
|
ownerKey: "stakeState"
|
|
@@ -180,8 +265,10 @@ runner.use(async (context, next) => {
|
|
|
180
265
|
outputs.forEach((x) => {
|
|
181
266
|
const { owner, tokens, assets } = x;
|
|
182
267
|
const ownerState = receiverStates.find((s) => getRelatedAddresses(s).includes(owner));
|
|
183
|
-
receiverUpdates[ownerState.address]
|
|
184
|
-
|
|
268
|
+
const alreadyUpdated = Boolean(receiverUpdates[ownerState.address]);
|
|
269
|
+
const baseState = receiverUpdates[ownerState.address] || ownerState;
|
|
270
|
+
receiverUpdates[ownerState.address] = applyTokenUpdates(tokens || [], baseState, "add");
|
|
271
|
+
if (!alreadyUpdated && senderChange && ownerState.address === senderChange.address) receiverUpdates[ownerState.address] = applyTokenChange(receiverUpdates[ownerState.address], senderChange);
|
|
185
272
|
(assets || []).forEach((a) => {
|
|
186
273
|
assetUpdates[a] = { owner: ownerState.address };
|
|
187
274
|
});
|
|
@@ -191,9 +278,26 @@ runner.use(async (context, next) => {
|
|
|
191
278
|
const isAlsoSigner = !!receiverUpdates[senderState.address];
|
|
192
279
|
const [newSenderState, newReceiverStates, newStakeState, newAssetStates, newEvidenceState] = await Promise.all([
|
|
193
280
|
statedb.account.update(senderState.address, account.update(senderState, Object.assign({ nonce: tx$1.nonce }, receiverUpdates[senderState.address] || (senderChange ? applyTokenChange(senderState, senderChange) : {})), context), context),
|
|
194
|
-
Promise.all(receiverStates.filter((x) => x.address !== senderState.address).map((x) => statedb.account.update(x.address, account.update(x, receiverUpdates[x.address], context), context))),
|
|
195
|
-
|
|
196
|
-
|
|
281
|
+
Promise.all(uniqBy(receiverStates, "address").filter((x) => x.address !== senderState.address).map((x) => statedb.account.update(x.address, account.update(x, receiverUpdates[x.address], context), context))),
|
|
282
|
+
(() => {
|
|
283
|
+
const nextRevokes = consumeStakeRevoke(stakeState, itx.evidence.hash, outputs);
|
|
284
|
+
return statedb.stake.update(stakeState.address, stake.update(stakeState, {
|
|
285
|
+
...stakeUpdates,
|
|
286
|
+
context: {
|
|
287
|
+
...stakeState.context,
|
|
288
|
+
revokes: nextRevokes
|
|
289
|
+
}
|
|
290
|
+
}, Object.values(stakeUpdates.revokedTokens || {}).some((v$1) => new BN(v$1 || "0").gt(new BN(0))) || (stakeUpdates.revokedAssets || []).length > 0 ? {
|
|
291
|
+
...context,
|
|
292
|
+
txTime: stakeState.context?.renaissanceTime || context.txTime
|
|
293
|
+
} : context), context);
|
|
294
|
+
})(),
|
|
295
|
+
Promise.all(assetStates.map(async (x) => {
|
|
296
|
+
const nextOwner = assetUpdates[x.address]?.owner;
|
|
297
|
+
const updatedAsset = await statedb.asset.update(x.address, asset.update(x, assetUpdates[x.address], context), context);
|
|
298
|
+
if (nextOwner && token.isTokenCharterAsset(x)) await token.syncTokenCharterOwnership(x, nextOwner, statedb, context);
|
|
299
|
+
return updatedAsset;
|
|
300
|
+
})),
|
|
197
301
|
statedb.evidence.create(itx.evidence.hash, evidence.create({
|
|
198
302
|
hash: itx.evidence.hash,
|
|
199
303
|
data: "claim-stake"
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { applyTokenChange, applyTokenUpdates } from "../../util.mjs";
|
|
2
2
|
import ensure_cost_default from "../../pipes/ensure-cost.mjs";
|
|
3
3
|
import ensure_gas_default from "../../pipes/ensure-gas.mjs";
|
|
4
|
-
import { account, asset, stake } from "@ocap/state";
|
|
4
|
+
import { account, asset, stake, token } from "@ocap/state";
|
|
5
5
|
import { Runner, pipes } from "@ocap/tx-pipeline";
|
|
6
6
|
import { BN } from "@ocap/util";
|
|
7
7
|
import { CustomError } from "@ocap/util/lib/error";
|
|
8
|
-
import Debug from "debug";
|
|
9
8
|
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
10
|
-
import { schemas, v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
11
9
|
import { getRelatedAddresses } from "@ocap/util/lib/get-related-addr";
|
|
10
|
+
import Debug from "debug";
|
|
11
|
+
import { schemas, v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
12
|
+
import uniqBy from "lodash/uniqBy.js";
|
|
12
13
|
import isEmpty from "lodash/isEmpty.js";
|
|
13
14
|
|
|
14
15
|
//#region src/protocols/governance/return-stake.ts
|
|
@@ -61,7 +62,11 @@ runner.use(pipes.ExtractState({
|
|
|
61
62
|
status: "INVALID_RECEIVER_STATE",
|
|
62
63
|
table: "account"
|
|
63
64
|
}));
|
|
64
|
-
runner.use(pipes.VerifyBlocked({ stateKeys: [
|
|
65
|
+
runner.use(pipes.VerifyBlocked({ stateKeys: [
|
|
66
|
+
"senderState",
|
|
67
|
+
"delegatorState",
|
|
68
|
+
"receiverStates"
|
|
69
|
+
] }));
|
|
65
70
|
runner.use(pipes.VerifyAccountMigration({
|
|
66
71
|
stateKey: "senderState",
|
|
67
72
|
addressKey: "tx.from"
|
|
@@ -73,6 +78,14 @@ runner.use(pipes.ExtractState({
|
|
|
73
78
|
table: "stake"
|
|
74
79
|
}));
|
|
75
80
|
runner.use(pipes.VerifyInfo([
|
|
81
|
+
{
|
|
82
|
+
error: "STAKE_NOT_REVOCABLE",
|
|
83
|
+
message: "This stake address is not revocable",
|
|
84
|
+
fn: (ctx) => {
|
|
85
|
+
const context = ctx;
|
|
86
|
+
return Boolean(context.stakeState.revocable);
|
|
87
|
+
}
|
|
88
|
+
},
|
|
76
89
|
{
|
|
77
90
|
error: "INVALID_TX",
|
|
78
91
|
message: "Can only return from none-self staking",
|
|
@@ -146,7 +159,10 @@ runner.use(pipes.ExtractState({
|
|
|
146
159
|
status: "INVALID_ASSET_STATE",
|
|
147
160
|
table: "asset"
|
|
148
161
|
}));
|
|
149
|
-
runner.use(pipes.VerifyTransferrable({
|
|
162
|
+
runner.use(pipes.VerifyTransferrable({
|
|
163
|
+
assets: "assetStates",
|
|
164
|
+
allowConsumed: true
|
|
165
|
+
}));
|
|
150
166
|
runner.use(pipes.VerifyUpdater({
|
|
151
167
|
assetKey: "assetStates",
|
|
152
168
|
ownerKey: "stakeState"
|
|
@@ -178,21 +194,37 @@ runner.use(async (context, next) => {
|
|
|
178
194
|
stakeUpdates.assets = stakeUpdates.assets.filter((a) => assetsList.includes(a) === false);
|
|
179
195
|
stakeUpdates.tokens = applyTokenUpdates(tokensList, { tokens: stakeUpdates.tokens }, "sub").tokens;
|
|
180
196
|
const ownerState = receiverStates.find((s) => getRelatedAddresses(s).includes(owner));
|
|
181
|
-
receiverUpdates[ownerState.address]
|
|
182
|
-
|
|
197
|
+
const alreadyUpdated = Boolean(receiverUpdates[ownerState.address]);
|
|
198
|
+
const baseState = receiverUpdates[ownerState.address] || ownerState;
|
|
199
|
+
receiverUpdates[ownerState.address] = applyTokenUpdates(tokensList, baseState, "add");
|
|
200
|
+
if (!alreadyUpdated && senderChange && ownerState.address === senderChange.address) receiverUpdates[ownerState.address] = applyTokenChange(receiverUpdates[ownerState.address], senderChange);
|
|
183
201
|
assetsList.forEach((a) => {
|
|
184
202
|
assetUpdates[a] = { owner: ownerState.address };
|
|
185
203
|
});
|
|
186
204
|
});
|
|
205
|
+
const isAlsoSigner = !!receiverUpdates[senderState.address];
|
|
187
206
|
const [newSenderState, newReceiverStates, newStakeState, newAssetStates] = await Promise.all([
|
|
188
|
-
statedb.account.update(senderState.address, account.update(senderState, Object.assign({ nonce: tx$1.nonce }, senderChange ? applyTokenChange(senderState, senderChange) : {}), context), context),
|
|
189
|
-
Promise.all(receiverStates.map((x) => statedb.account.update(x.address, account.update(x, receiverUpdates[x.address], context), context))),
|
|
190
|
-
|
|
191
|
-
|
|
207
|
+
statedb.account.update(senderState.address, account.update(senderState, Object.assign({ nonce: tx$1.nonce }, receiverUpdates[senderState.address] || (senderChange ? applyTokenChange(senderState, senderChange) : {})), context), context),
|
|
208
|
+
Promise.all(uniqBy(receiverStates, "address").filter((x) => x.address !== senderState.address).map((x) => statedb.account.update(x.address, account.update(x, receiverUpdates[x.address], context), context))),
|
|
209
|
+
(() => {
|
|
210
|
+
const hasPendingRevokedTokens = Object.values(stakeState.revokedTokens || {}).some((v$1) => new BN(String(v$1 || "0")).gt(new BN(0)));
|
|
211
|
+
const hasPendingRevokedAssets = Array.isArray(stakeState.revokedAssets) && stakeState.revokedAssets.length > 0;
|
|
212
|
+
const preserveRenaissanceTime = (hasPendingRevokedTokens || hasPendingRevokedAssets) && stakeState?.context?.renaissanceTime;
|
|
213
|
+
return statedb.stake.update(stakeState.address, stake.update(stakeState, stakeUpdates, preserveRenaissanceTime ? {
|
|
214
|
+
...context,
|
|
215
|
+
txTime: preserveRenaissanceTime
|
|
216
|
+
} : context), context);
|
|
217
|
+
})(),
|
|
218
|
+
Promise.all(assetStates.map(async (x) => {
|
|
219
|
+
const nextOwner = assetUpdates[x.address]?.owner;
|
|
220
|
+
const updatedAsset = await statedb.asset.update(x.address, asset.update(x, assetUpdates[x.address], context), context);
|
|
221
|
+
if (nextOwner && token.isTokenCharterAsset(x)) await token.syncTokenCharterOwnership(x, nextOwner, statedb, context);
|
|
222
|
+
return updatedAsset;
|
|
223
|
+
}))
|
|
192
224
|
]);
|
|
193
225
|
if (updateVaults) await updateVaults();
|
|
194
226
|
context.senderState = newSenderState;
|
|
195
|
-
context.receiverStates = newReceiverStates;
|
|
227
|
+
context.receiverStates = isAlsoSigner ? newReceiverStates.concat(newSenderState) : newReceiverStates;
|
|
196
228
|
context.stakeState = newStakeState;
|
|
197
229
|
context.assetStates = newAssetStates;
|
|
198
230
|
debug("return-stake", {
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { IStakeRevokeEntry, IStakeState } from "@ocap/types";
|
|
2
|
+
|
|
3
|
+
//#region src/protocols/governance/revoke-ledger.d.ts
|
|
4
|
+
declare const LEGACY_REVOKE_KEY = "__legacy__";
|
|
5
|
+
interface TokenInputLike {
|
|
6
|
+
address: string;
|
|
7
|
+
value: string;
|
|
8
|
+
}
|
|
9
|
+
interface OutputLike {
|
|
10
|
+
tokensList?: TokenInputLike[];
|
|
11
|
+
tokens?: TokenInputLike[];
|
|
12
|
+
assetsList?: string[];
|
|
13
|
+
assets?: string[];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Normalizes `stakeState.context?.revokes` against aggregate `stakeState.revokedTokens` and `stakeState.revokedAssets`.
|
|
17
|
+
* Any unattributed aggregate revoked tokens/assets (e.g. from pre-upgrade legacy stakes) are placed into
|
|
18
|
+
* `revokes[LEGACY_REVOKE_KEY]` at the head of the FIFO queue with `renaissanceTime` as their unlock base.
|
|
19
|
+
*/
|
|
20
|
+
declare function normalizeStakeRevokes(stakeState: IStakeState): Record<string, IStakeRevokeEntry>;
|
|
21
|
+
/**
|
|
22
|
+
* Records a new `revoke_stake` transaction's outputs into the per-revoke ledger under `txHash`.
|
|
23
|
+
*/
|
|
24
|
+
declare function recordStakeRevoke(stakeState: IStakeState, txHash: string, txTime: string, outputs: OutputLike[]): Record<string, IStakeRevokeEntry>;
|
|
25
|
+
/**
|
|
26
|
+
* Deducts slashed revoked tokens and assets from the per-revoke ledger in FIFO order (oldest first).
|
|
27
|
+
*/
|
|
28
|
+
declare function slashStakeRevokes(stakeState: IStakeState, nextRevokedTokens: Record<string, string>, nextRevokedAssets: string[], slashTxTime: string): Record<string, IStakeRevokeEntry>;
|
|
29
|
+
/**
|
|
30
|
+
* Consumes claimed tokens and assets from the target revoke entry (`evidenceHash` or `LEGACY_REVOKE_KEY`).
|
|
31
|
+
*/
|
|
32
|
+
declare function consumeStakeRevoke(stakeState: IStakeState, evidenceHash: string, claimedOutputs: OutputLike[]): Record<string, IStakeRevokeEntry>;
|
|
33
|
+
//#endregion
|
|
34
|
+
export { LEGACY_REVOKE_KEY, consumeStakeRevoke, normalizeStakeRevokes, recordStakeRevoke, slashStakeRevokes };
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { BN } from "@ocap/util";
|
|
2
|
+
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
3
|
+
|
|
4
|
+
//#region src/protocols/governance/revoke-ledger.ts
|
|
5
|
+
const LEGACY_REVOKE_KEY = "__legacy__";
|
|
6
|
+
const ZERO = new BN(0);
|
|
7
|
+
function hasPositiveEntry(entry) {
|
|
8
|
+
if (!entry) return false;
|
|
9
|
+
const hasTokens = Object.values(entry.tokens || {}).some((v) => new BN(String(v || "0")).gt(ZERO));
|
|
10
|
+
const hasAssets = Array.isArray(entry.assets) && entry.assets.length > 0;
|
|
11
|
+
return hasTokens || hasAssets;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Normalizes `stakeState.context?.revokes` against aggregate `stakeState.revokedTokens` and `stakeState.revokedAssets`.
|
|
15
|
+
* Any unattributed aggregate revoked tokens/assets (e.g. from pre-upgrade legacy stakes) are placed into
|
|
16
|
+
* `revokes[LEGACY_REVOKE_KEY]` at the head of the FIFO queue with `renaissanceTime` as their unlock base.
|
|
17
|
+
*/
|
|
18
|
+
function normalizeStakeRevokes(stakeState) {
|
|
19
|
+
const aggTokens = stakeState.revokedTokens || {};
|
|
20
|
+
const aggAssets = Array.isArray(stakeState.revokedAssets) ? stakeState.revokedAssets : [];
|
|
21
|
+
const rawRevokes = stakeState.context?.revokes || {};
|
|
22
|
+
const orderedKeys = [...Object.hasOwn(rawRevokes, LEGACY_REVOKE_KEY) ? [LEGACY_REVOKE_KEY] : [], ...Object.keys(rawRevokes).filter((k) => k !== LEGACY_REVOKE_KEY)];
|
|
23
|
+
const remainingTokenCap = {};
|
|
24
|
+
for (const [tok, val] of Object.entries(aggTokens)) {
|
|
25
|
+
const bnVal = new BN(String(val || "0"));
|
|
26
|
+
if (bnVal.gt(ZERO)) remainingTokenCap[tok] = bnVal;
|
|
27
|
+
}
|
|
28
|
+
const aggAssetSet = new Set(aggAssets);
|
|
29
|
+
const seenAssets = /* @__PURE__ */ new Set();
|
|
30
|
+
const normalized = {};
|
|
31
|
+
for (const key of orderedKeys) {
|
|
32
|
+
const raw = rawRevokes[key];
|
|
33
|
+
if (!raw || typeof raw !== "object") continue;
|
|
34
|
+
const clampedTokens = {};
|
|
35
|
+
for (const [tok, val] of Object.entries(raw.tokens || {})) {
|
|
36
|
+
const cap = remainingTokenCap[tok] || ZERO;
|
|
37
|
+
const entryBn = new BN(String(val || "0"));
|
|
38
|
+
const actual = BN.min(entryBn, cap);
|
|
39
|
+
if (actual.gt(ZERO)) {
|
|
40
|
+
clampedTokens[tok] = actual.toString(10);
|
|
41
|
+
remainingTokenCap[tok] = cap.sub(actual);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const clampedAssets = (Array.isArray(raw.assets) ? raw.assets : []).filter((a) => {
|
|
45
|
+
if (aggAssetSet.has(a) && !seenAssets.has(a)) {
|
|
46
|
+
seenAssets.add(a);
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
});
|
|
51
|
+
normalized[key] = {
|
|
52
|
+
txTime: typeof raw.txTime === "string" ? raw.txTime : "",
|
|
53
|
+
tokens: clampedTokens,
|
|
54
|
+
assets: clampedAssets
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const unattributedTokens = {};
|
|
58
|
+
for (const [tok, rem] of Object.entries(remainingTokenCap)) if (rem.gt(ZERO)) unattributedTokens[tok] = rem.toString(10);
|
|
59
|
+
const unattributedAssets = aggAssets.filter((a) => !seenAssets.has(a));
|
|
60
|
+
if (Object.keys(unattributedTokens).length > 0 || unattributedAssets.length > 0) {
|
|
61
|
+
const existingLegacy = normalized[LEGACY_REVOKE_KEY];
|
|
62
|
+
const mergedLegacyTokens = { ...existingLegacy?.tokens || {} };
|
|
63
|
+
for (const [tok, val] of Object.entries(unattributedTokens)) mergedLegacyTokens[tok] = new BN(mergedLegacyTokens[tok] || "0").add(new BN(val)).toString(10);
|
|
64
|
+
const mergedLegacyAssets = Array.from(new Set([...existingLegacy?.assets || [], ...unattributedAssets]));
|
|
65
|
+
const legacyEntry = {
|
|
66
|
+
txTime: existingLegacy?.txTime || stakeState.context?.renaissanceTime || stakeState.context?.genesisTime || "",
|
|
67
|
+
tokens: mergedLegacyTokens,
|
|
68
|
+
assets: mergedLegacyAssets
|
|
69
|
+
};
|
|
70
|
+
const reordered = { [LEGACY_REVOKE_KEY]: legacyEntry };
|
|
71
|
+
for (const [k, v] of Object.entries(normalized)) if (k !== LEGACY_REVOKE_KEY && hasPositiveEntry(v)) reordered[k] = v;
|
|
72
|
+
return reordered;
|
|
73
|
+
}
|
|
74
|
+
const result = {};
|
|
75
|
+
for (const [k, v] of Object.entries(normalized)) if (hasPositiveEntry(v)) result[k] = v;
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Records a new `revoke_stake` transaction's outputs into the per-revoke ledger under `txHash`.
|
|
80
|
+
*/
|
|
81
|
+
function recordStakeRevoke(stakeState, txHash, txTime, outputs) {
|
|
82
|
+
const revokes = normalizeStakeRevokes(stakeState);
|
|
83
|
+
const prev = Object.hasOwn(revokes, txHash) ? revokes[txHash] : void 0;
|
|
84
|
+
const mergedTokens = { ...prev?.tokens || {} };
|
|
85
|
+
const mergedAssets = new Set(prev?.assets || []);
|
|
86
|
+
for (const out of outputs || []) {
|
|
87
|
+
const tokensList = getListField(out, "tokens") || [];
|
|
88
|
+
const assetsList = getListField(out, "assets") || [];
|
|
89
|
+
for (const { address, value } of tokensList) {
|
|
90
|
+
const addBn = new BN(String(value || "0"));
|
|
91
|
+
if (addBn.gt(ZERO)) mergedTokens[address] = new BN(mergedTokens[address] || "0").add(addBn).toString(10);
|
|
92
|
+
}
|
|
93
|
+
for (const assetAddr of assetsList) mergedAssets.add(assetAddr);
|
|
94
|
+
}
|
|
95
|
+
const nextEntry = {
|
|
96
|
+
txTime: txTime || prev?.txTime || "",
|
|
97
|
+
tokens: mergedTokens,
|
|
98
|
+
assets: Array.from(mergedAssets)
|
|
99
|
+
};
|
|
100
|
+
if (hasPositiveEntry(nextEntry)) revokes[txHash] = nextEntry;
|
|
101
|
+
return revokes;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Deducts slashed revoked tokens and assets from the per-revoke ledger in FIFO order (oldest first).
|
|
105
|
+
*/
|
|
106
|
+
function slashStakeRevokes(stakeState, nextRevokedTokens, nextRevokedAssets, slashTxTime) {
|
|
107
|
+
const revokes = normalizeStakeRevokes(stakeState);
|
|
108
|
+
const prevRevokedTokens = stakeState.revokedTokens || {};
|
|
109
|
+
const slashedTokens = {};
|
|
110
|
+
for (const [tok, prevVal] of Object.entries(prevRevokedTokens)) {
|
|
111
|
+
const prevBn = new BN(String(prevVal || "0"));
|
|
112
|
+
const nextBn = new BN(String(nextRevokedTokens?.[tok] || "0"));
|
|
113
|
+
const diff = prevBn.sub(nextBn);
|
|
114
|
+
if (diff.gt(ZERO)) slashedTokens[tok] = diff;
|
|
115
|
+
}
|
|
116
|
+
const nextAssetSet = new Set(nextRevokedAssets || []);
|
|
117
|
+
const result = {};
|
|
118
|
+
for (const [key, entry] of Object.entries(revokes)) {
|
|
119
|
+
let shrunk = false;
|
|
120
|
+
const updatedTokens = {};
|
|
121
|
+
for (const [tok, val] of Object.entries(entry.tokens || {})) {
|
|
122
|
+
const avail = new BN(String(val || "0"));
|
|
123
|
+
const toSlash = slashedTokens[tok] || ZERO;
|
|
124
|
+
const deduct = BN.min(avail, toSlash);
|
|
125
|
+
if (deduct.gt(ZERO)) {
|
|
126
|
+
shrunk = true;
|
|
127
|
+
slashedTokens[tok] = toSlash.sub(deduct);
|
|
128
|
+
}
|
|
129
|
+
const rem = avail.sub(deduct);
|
|
130
|
+
if (rem.gt(ZERO)) updatedTokens[tok] = rem.toString(10);
|
|
131
|
+
}
|
|
132
|
+
const prevAssets = entry.assets || [];
|
|
133
|
+
const updatedAssets = prevAssets.filter((a) => nextAssetSet.has(a));
|
|
134
|
+
if (updatedAssets.length < prevAssets.length) shrunk = true;
|
|
135
|
+
const updatedEntry = {
|
|
136
|
+
txTime: key === LEGACY_REVOKE_KEY && shrunk && slashTxTime ? slashTxTime : entry.txTime,
|
|
137
|
+
tokens: updatedTokens,
|
|
138
|
+
assets: updatedAssets
|
|
139
|
+
};
|
|
140
|
+
if (hasPositiveEntry(updatedEntry)) result[key] = updatedEntry;
|
|
141
|
+
}
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Consumes claimed tokens and assets from the target revoke entry (`evidenceHash` or `LEGACY_REVOKE_KEY`).
|
|
146
|
+
*/
|
|
147
|
+
function consumeStakeRevoke(stakeState, evidenceHash, claimedOutputs) {
|
|
148
|
+
const revokes = normalizeStakeRevokes(stakeState);
|
|
149
|
+
const targetKey = evidenceHash && Object.hasOwn(revokes, evidenceHash) ? evidenceHash : LEGACY_REVOKE_KEY;
|
|
150
|
+
const target = Object.hasOwn(revokes, targetKey) ? revokes[targetKey] : void 0;
|
|
151
|
+
if (!target) return revokes;
|
|
152
|
+
const claimedTokens = {};
|
|
153
|
+
const claimedAssets = /* @__PURE__ */ new Set();
|
|
154
|
+
for (const out of claimedOutputs || []) {
|
|
155
|
+
const tokensList = out.tokens || out.tokensList || [];
|
|
156
|
+
const assetsList = out.assets || out.assetsList || [];
|
|
157
|
+
for (const { address, value } of tokensList) claimedTokens[address] = (claimedTokens[address] || ZERO).add(new BN(String(value || "0")));
|
|
158
|
+
for (const assetAddr of assetsList) claimedAssets.add(assetAddr);
|
|
159
|
+
}
|
|
160
|
+
const remainingTokens = {};
|
|
161
|
+
for (const [tok, val] of Object.entries(target.tokens || {})) {
|
|
162
|
+
const avail = new BN(String(val || "0"));
|
|
163
|
+
const deduct = BN.min(avail, claimedTokens[tok] || ZERO);
|
|
164
|
+
const rem = avail.sub(deduct);
|
|
165
|
+
if (rem.gt(ZERO)) remainingTokens[tok] = rem.toString(10);
|
|
166
|
+
}
|
|
167
|
+
const remainingAssets = (target.assets || []).filter((a) => !claimedAssets.has(a));
|
|
168
|
+
const updatedTarget = {
|
|
169
|
+
txTime: target.txTime,
|
|
170
|
+
tokens: remainingTokens,
|
|
171
|
+
assets: remainingAssets
|
|
172
|
+
};
|
|
173
|
+
if (hasPositiveEntry(updatedTarget)) revokes[targetKey] = updatedTarget;
|
|
174
|
+
else delete revokes[targetKey];
|
|
175
|
+
return revokes;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
//#endregion
|
|
179
|
+
export { LEGACY_REVOKE_KEY, consumeStakeRevoke, normalizeStakeRevokes, recordStakeRevoke, slashStakeRevokes };
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { applyTokenUpdates } from "../../util.mjs";
|
|
2
2
|
import ensure_cost_default from "../../pipes/ensure-cost.mjs";
|
|
3
3
|
import ensure_gas_default from "../../pipes/ensure-gas.mjs";
|
|
4
|
+
import { recordStakeRevoke } from "./revoke-ledger.mjs";
|
|
4
5
|
import { account, stake } from "@ocap/state";
|
|
5
6
|
import { Runner, pipes } from "@ocap/tx-pipeline";
|
|
6
7
|
import { BN } from "@ocap/util";
|
|
7
8
|
import { CustomError } from "@ocap/util/lib/error";
|
|
8
|
-
import Debug from "debug";
|
|
9
9
|
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
10
|
-
import { schemas, v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
11
10
|
import { getRelatedAddresses } from "@ocap/util/lib/get-related-addr";
|
|
11
|
+
import Debug from "debug";
|
|
12
|
+
import { schemas, v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
12
13
|
import isEmpty from "lodash/isEmpty.js";
|
|
13
14
|
|
|
14
15
|
//#region src/protocols/governance/revoke-stake.ts
|
|
@@ -60,7 +61,11 @@ runner.use(pipes.ExtractState({
|
|
|
60
61
|
status: "INVALID_RECEIVER_STATE",
|
|
61
62
|
table: "account"
|
|
62
63
|
}));
|
|
63
|
-
runner.use(pipes.VerifyBlocked({ stateKeys: [
|
|
64
|
+
runner.use(pipes.VerifyBlocked({ stateKeys: [
|
|
65
|
+
"senderState",
|
|
66
|
+
"delegatorState",
|
|
67
|
+
"receiverStates"
|
|
68
|
+
] }));
|
|
64
69
|
runner.use(pipes.VerifyAccountMigration({
|
|
65
70
|
stateKey: "senderState",
|
|
66
71
|
addressKey: "tx.from"
|
|
@@ -127,7 +132,7 @@ runner.use(pipes.VerifyTokenBalance({
|
|
|
127
132
|
runner.use(pipes.ExtractState({
|
|
128
133
|
from: "assets",
|
|
129
134
|
to: "assetStates",
|
|
130
|
-
status: "
|
|
135
|
+
status: "INVALID_ASSET_STATE",
|
|
131
136
|
table: "asset"
|
|
132
137
|
}));
|
|
133
138
|
runner.use(pipes.VerifyTransferrable({ assets: "assetStates" }));
|
|
@@ -161,7 +166,22 @@ runner.use(async (context, next) => {
|
|
|
161
166
|
const [newSenderState, newStakeState] = await Promise.all([statedb.account.update(senderState.address, account.update(senderState, {
|
|
162
167
|
nonce: tx$1.nonce,
|
|
163
168
|
...senderUpdates
|
|
164
|
-
}, context), context),
|
|
169
|
+
}, context), context), (() => {
|
|
170
|
+
const nextRevokes = recordStakeRevoke(stakeState, context.txHash, context.txTime, outputs);
|
|
171
|
+
const hasPendingRevokedTokens = Object.values(stakeState.revokedTokens || {}).some((v$1) => new BN(String(v$1 || "0")).gt(new BN(0)));
|
|
172
|
+
const hasPendingRevokedAssets = Array.isArray(stakeState.revokedAssets) && stakeState.revokedAssets.length > 0;
|
|
173
|
+
const preserveRenaissanceTime = (hasPendingRevokedTokens || hasPendingRevokedAssets) && stakeState.context?.renaissanceTime;
|
|
174
|
+
return statedb.stake.update(stakeState.address, stake.update(stakeState, {
|
|
175
|
+
...stakeUpdates,
|
|
176
|
+
context: {
|
|
177
|
+
...stakeState.context,
|
|
178
|
+
revokes: nextRevokes
|
|
179
|
+
}
|
|
180
|
+
}, preserveRenaissanceTime ? {
|
|
181
|
+
...context,
|
|
182
|
+
txTime: preserveRenaissanceTime
|
|
183
|
+
} : context), context);
|
|
184
|
+
})()]);
|
|
165
185
|
if (updateVaults) await updateVaults();
|
|
166
186
|
context.senderState = newSenderState;
|
|
167
187
|
context.stakeState = newStakeState;
|