@ocap/tx-protocols 1.30.26 → 1.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/execute.d.mts +7 -0
- package/esm/execute.mjs +196 -71
- package/esm/gas-security-guard.d.mts +374 -0
- package/esm/gas-security-guard.mjs +1101 -0
- package/esm/index.d.mts +35 -5
- package/esm/index.mjs +3 -1
- package/esm/pipes/ensure-cost.mjs +314 -58
- package/esm/protocols/account/delegate.mjs +64 -16
- package/esm/protocols/account/migrate.d.mts +3 -0
- package/esm/protocols/account/migrate.mjs +235 -35
- package/esm/protocols/account/revoke-delegate.d.mts +3 -3
- package/esm/protocols/account/revoke-delegate.mjs +70 -38
- package/esm/protocols/asset/acquire-v2.mjs +29 -12
- package/esm/protocols/asset/acquire-v3.mjs +78 -22
- package/esm/protocols/asset/calls/transfer-token.mjs +2 -1
- package/esm/protocols/asset/calls/transfer.mjs +1 -0
- package/esm/protocols/asset/consume.mjs +12 -4
- package/esm/protocols/asset/create.mjs +18 -5
- package/esm/protocols/asset/mint.mjs +23 -1
- package/esm/protocols/asset/pipes/exec-mint-hook.d.mts +21 -1
- package/esm/protocols/asset/pipes/exec-mint-hook.mjs +115 -1
- package/esm/protocols/asset/pipes/extract-factory-tokens.mjs +14 -8
- package/esm/protocols/asset/pipes/verify-itx-address.mjs +9 -0
- package/esm/protocols/asset/pipes/verify-itx-assets.mjs +21 -5
- package/esm/protocols/asset/update.d.mts +13 -2
- package/esm/protocols/asset/update.mjs +133 -14
- package/esm/protocols/factory/create.mjs +14 -6
- package/esm/protocols/governance/claim-stake.mjs +92 -10
- package/esm/protocols/governance/return-stake.mjs +44 -12
- package/esm/protocols/governance/revoke-stake.mjs +17 -5
- package/esm/protocols/governance/slash-stake.mjs +64 -25
- package/esm/protocols/governance/stake.mjs +63 -13
- package/esm/protocols/rollup/claim-reward.mjs +39 -20
- package/esm/protocols/rollup/close.mjs +1 -1
- package/esm/protocols/rollup/create-block.mjs +8 -7
- package/esm/protocols/rollup/create.mjs +17 -6
- package/esm/protocols/rollup/join.mjs +3 -3
- package/esm/protocols/rollup/leave.mjs +1 -1
- package/esm/protocols/rollup/migrate.mjs +7 -4
- package/esm/protocols/rollup/pipes/verify-evidence.mjs +12 -4
- package/esm/protocols/rollup/update.mjs +6 -1
- package/esm/protocols/token/create.mjs +23 -12
- package/esm/protocols/token/deposit-v2.d.mts +5 -1
- package/esm/protocols/token/deposit-v2.mjs +81 -29
- package/esm/protocols/token/withdraw-v2.mjs +33 -16
- package/esm/protocols/token-factory/burn.mjs +43 -10
- package/esm/protocols/token-factory/create.mjs +23 -14
- package/esm/protocols/token-factory/mint.mjs +54 -21
- package/esm/protocols/token-factory/pipes/verify-icon.mjs +1 -1
- package/esm/protocols/token-factory/update.mjs +16 -6
- package/esm/protocols/trade/exchange-v2.d.mts +4 -0
- package/esm/protocols/trade/exchange-v2.mjs +78 -22
- package/esm/protocols/trade/transfer-v2.mjs +44 -13
- package/esm/protocols/trade/transfer-v3.mjs +72 -31
- package/esm/util.d.mts +3 -1
- package/esm/util.mjs +26 -17
- package/lib/execute.cjs +193 -67
- package/lib/execute.d.cts +7 -0
- package/lib/gas-security-guard.cjs +1140 -0
- package/lib/gas-security-guard.d.cts +374 -0
- package/lib/index.cjs +122 -1
- package/lib/index.d.cts +36 -6
- package/lib/pipes/ensure-cost.cjs +313 -57
- package/lib/protocols/account/delegate.cjs +64 -16
- package/lib/protocols/account/migrate.cjs +235 -35
- package/lib/protocols/account/migrate.d.cts +3 -0
- package/lib/protocols/account/revoke-delegate.cjs +71 -39
- package/lib/protocols/account/revoke-delegate.d.cts +3 -3
- package/lib/protocols/asset/acquire-v2.cjs +28 -11
- package/lib/protocols/asset/acquire-v3.cjs +77 -20
- package/lib/protocols/asset/calls/transfer-token.cjs +3 -2
- package/lib/protocols/asset/calls/transfer.cjs +1 -0
- package/lib/protocols/asset/consume.cjs +11 -3
- package/lib/protocols/asset/create.cjs +19 -6
- package/lib/protocols/asset/mint.cjs +23 -1
- package/lib/protocols/asset/pipes/exec-mint-hook.cjs +117 -1
- package/lib/protocols/asset/pipes/exec-mint-hook.d.cts +21 -1
- package/lib/protocols/asset/pipes/extract-factory-tokens.cjs +14 -9
- package/lib/protocols/asset/pipes/verify-itx-address.cjs +9 -0
- package/lib/protocols/asset/pipes/verify-itx-assets.cjs +21 -5
- package/lib/protocols/asset/update.cjs +131 -12
- package/lib/protocols/asset/update.d.cts +13 -2
- package/lib/protocols/factory/create.cjs +14 -6
- package/lib/protocols/governance/claim-stake.cjs +92 -9
- package/lib/protocols/governance/claim-stake.d.cts +1 -1
- package/lib/protocols/governance/return-stake.cjs +44 -11
- package/lib/protocols/governance/return-stake.d.cts +1 -1
- package/lib/protocols/governance/revoke-stake.cjs +17 -5
- package/lib/protocols/governance/revoke-stake.d.cts +1 -1
- package/lib/protocols/governance/slash-stake.cjs +64 -24
- package/lib/protocols/governance/slash-stake.d.cts +1 -1
- package/lib/protocols/governance/stake.cjs +65 -14
- package/lib/protocols/rollup/claim-reward.cjs +39 -20
- package/lib/protocols/rollup/close.cjs +1 -1
- package/lib/protocols/rollup/create-block.cjs +9 -8
- package/lib/protocols/rollup/create-block.d.cts +1 -1
- package/lib/protocols/rollup/create.cjs +18 -7
- package/lib/protocols/rollup/join.cjs +3 -3
- package/lib/protocols/rollup/leave.cjs +1 -1
- package/lib/protocols/rollup/migrate.cjs +7 -4
- package/lib/protocols/rollup/pipes/verify-evidence.cjs +11 -3
- package/lib/protocols/rollup/update.cjs +6 -1
- package/lib/protocols/token/create.cjs +24 -13
- package/lib/protocols/token/deposit-v2.cjs +80 -28
- package/lib/protocols/token/deposit-v2.d.cts +5 -1
- package/lib/protocols/token/withdraw-v2.cjs +32 -15
- package/lib/protocols/token-factory/burn.cjs +42 -9
- package/lib/protocols/token-factory/create.cjs +24 -15
- package/lib/protocols/token-factory/mint.cjs +53 -20
- package/lib/protocols/token-factory/pipes/verify-icon.cjs +1 -1
- package/lib/protocols/token-factory/update.cjs +16 -6
- package/lib/protocols/trade/exchange-v2.cjs +76 -20
- package/lib/protocols/trade/exchange-v2.d.cts +4 -0
- package/lib/protocols/trade/transfer-v2.cjs +45 -14
- package/lib/protocols/trade/transfer-v3.cjs +72 -30
- package/lib/util.cjs +26 -17
- package/lib/util.d.cts +4 -2
- package/package.json +16 -16
|
@@ -5,10 +5,11 @@ import { any, nullable, object, optional, pipe } from "../../node_modules/valibo
|
|
|
5
5
|
import calc_reserve_default from "./pipes/calc-reserve.mjs";
|
|
6
6
|
import { account, token, tokenFactory } from "@ocap/state";
|
|
7
7
|
import { Runner, pipes } from "@ocap/tx-pipeline";
|
|
8
|
-
import { BN, fromUnitToToken } from "@ocap/util";
|
|
8
|
+
import { BN, fromUnitToToken, isSameDid, toAddress } from "@ocap/util";
|
|
9
9
|
import { CustomError } from "@ocap/util/lib/error";
|
|
10
|
-
import pick from "lodash/pick.js";
|
|
11
10
|
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
11
|
+
import { getRelatedAddresses } from "@ocap/util/lib/get-related-addr";
|
|
12
|
+
import pick from "lodash/pick.js";
|
|
12
13
|
import { schemas, vBN, vBNGreater, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
13
14
|
|
|
14
15
|
//#region src/protocols/token-factory/mint.ts
|
|
@@ -34,12 +35,22 @@ runner.use(pipes.ExtractState({
|
|
|
34
35
|
status: "INVALID_TOKEN_FACTORY",
|
|
35
36
|
table: "tokenFactory"
|
|
36
37
|
}));
|
|
38
|
+
runner.use((context, next) => {
|
|
39
|
+
const { tokenFactoryState } = context;
|
|
40
|
+
if (tokenFactoryState?.status && tokenFactoryState.status !== "ACTIVE") return next(new CustomError("INVALID_TOKEN_FACTORY", `Token factory is ${tokenFactoryState.status} and cannot mint tokens`));
|
|
41
|
+
return next();
|
|
42
|
+
});
|
|
37
43
|
runner.use(pipes.ExtractState({
|
|
38
44
|
from: "tokenFactoryState.tokenAddress",
|
|
39
45
|
to: "tokenState",
|
|
40
46
|
status: "INVALID_TOKEN",
|
|
41
47
|
table: "token"
|
|
42
48
|
}));
|
|
49
|
+
runner.use((context, next) => {
|
|
50
|
+
const sigs = getListField(context.tx, "signatures");
|
|
51
|
+
if (sigs && sigs.length > 0) context.senders = [context.tx.from];
|
|
52
|
+
return next();
|
|
53
|
+
}, { shouldSkip: (ctx) => Boolean(ctx.tokenFactoryState?.curve) });
|
|
43
54
|
runner.use(pipes.VerifyTxInput({
|
|
44
55
|
fieldKey: "itx.inputs",
|
|
45
56
|
inputsKey: "inputs",
|
|
@@ -53,7 +64,7 @@ runner.use(pipes.VerifyListSize({ listKey: [
|
|
|
53
64
|
"tokens",
|
|
54
65
|
"assets"
|
|
55
66
|
] }), { shouldSkip: (ctx) => !ctx.tokenFactoryState?.curve });
|
|
56
|
-
runner.use(pipes.VerifyMultiSigV2({ signersKey: "senders" }), { shouldSkip: (ctx) => !ctx.tokenFactoryState?.curve });
|
|
67
|
+
runner.use(pipes.VerifyMultiSigV2({ signersKey: "senders" }), { shouldSkip: (ctx) => !ctx.tokenFactoryState?.curve && !ctx.senders?.length });
|
|
57
68
|
runner.use((context, next) => {
|
|
58
69
|
const { tokenFactoryState, inputs = [] } = context;
|
|
59
70
|
if (!inputs.every((input) => {
|
|
@@ -69,6 +80,10 @@ runner.use(pipes.ExtractState({
|
|
|
69
80
|
status: "OK",
|
|
70
81
|
table: "account"
|
|
71
82
|
}));
|
|
83
|
+
runner.use(pipes.VerifyAccountMigration({
|
|
84
|
+
stateKey: "senderState",
|
|
85
|
+
addressKey: "tx.from"
|
|
86
|
+
}));
|
|
72
87
|
runner.use(pipes.ExtractState({
|
|
73
88
|
from: "senders",
|
|
74
89
|
to: "signerStates",
|
|
@@ -90,7 +105,11 @@ runner.use(pipes.VerifyAccountMigration({
|
|
|
90
105
|
stateKey: "receiverState",
|
|
91
106
|
addressKey: "itx.receiver"
|
|
92
107
|
}));
|
|
93
|
-
runner.use(pipes.VerifyBlocked({ stateKeys: [
|
|
108
|
+
runner.use(pipes.VerifyBlocked({ stateKeys: [
|
|
109
|
+
"senderState",
|
|
110
|
+
"signerStates",
|
|
111
|
+
"receiverState"
|
|
112
|
+
] }));
|
|
94
113
|
runner.use(pipes.ExtractState({
|
|
95
114
|
from: "tokenFactoryState.owner",
|
|
96
115
|
to: "ownerState",
|
|
@@ -103,6 +122,15 @@ runner.use(pipes.verifyTokenAccess({
|
|
|
103
122
|
accountKeys: ["senderState"],
|
|
104
123
|
errorMessage: "Account {address} is not allowed to mint token {tokenAddress}"
|
|
105
124
|
}));
|
|
125
|
+
runner.use((context, next) => {
|
|
126
|
+
const { tokenFactoryState, tokenState, senderState, ownerState, tx: tx$1 } = context;
|
|
127
|
+
if (!tokenFactoryState?.curve && (!tokenState?.minters || tokenState.minters.length === 0)) {
|
|
128
|
+
const senderAddrs = senderState ? getRelatedAddresses(senderState) : [tx$1.from];
|
|
129
|
+
const ownerAddrs = ownerState ? getRelatedAddresses(ownerState) : [tokenFactoryState.owner];
|
|
130
|
+
if (!senderAddrs.some((s) => ownerAddrs.some((o) => isSameDid(s, o)))) return next(new CustomError("FORBIDDEN", `verify-token-access: Account ${senderState?.address || tx$1.from} is not allowed to mint token ${tokenState.address}`, { persist: true }));
|
|
131
|
+
}
|
|
132
|
+
return next();
|
|
133
|
+
});
|
|
106
134
|
runner.use(calc_reserve_default({
|
|
107
135
|
tokenFactoryKey: "tokenFactoryState",
|
|
108
136
|
tokenStateKey: "tokenState",
|
|
@@ -110,9 +138,12 @@ runner.use(calc_reserve_default({
|
|
|
110
138
|
amountKey: "itx.amount"
|
|
111
139
|
}), { shouldSkip: (ctx) => !ctx.tokenFactoryState?.curve });
|
|
112
140
|
runner.use((context, next) => {
|
|
113
|
-
const { tokenState, itx } = context;
|
|
141
|
+
const { tokenState, tokenFactoryState, itx } = context;
|
|
114
142
|
if (tokenState.maxTotalSupply) {
|
|
115
|
-
const
|
|
143
|
+
const factoryData = tokenFactoryState?.data || {};
|
|
144
|
+
const rawLpReserve = factoryData.lpReserveSupply ?? (factoryData.value && typeof factoryData.value === "object" ? factoryData.value.lpReserveSupply : void 0);
|
|
145
|
+
const lpReserveSupply = rawLpReserve ? new BN(String(rawLpReserve)) : new BN(0);
|
|
146
|
+
const availableSupply = new BN(tokenState.maxTotalSupply).sub(lpReserveSupply).sub(new BN(tokenState.totalSupply));
|
|
116
147
|
if (new BN(itx.amount).gt(availableSupply)) return next(new CustomError("INVALID_TOKEN", `Maximum mintable tokens are ${fromUnitToToken(availableSupply, tokenState.decimal)} ${tokenState.symbol}`));
|
|
117
148
|
}
|
|
118
149
|
next();
|
|
@@ -168,17 +199,18 @@ runner.use(async (context, next) => {
|
|
|
168
199
|
const { owner } = input;
|
|
169
200
|
const reserveTokenChange = getListField(input, "tokens").find((item) => item.address === reserveAddress);
|
|
170
201
|
if (!reserveTokenChange) return;
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
202
|
+
const reserveValue = new BN(reserveTokenChange.value);
|
|
203
|
+
const remainingCost = BN.max(new BN(0), totalReserveCost.sub(currentReserveCost));
|
|
204
|
+
const actualSpend = reserveValue.gt(remainingCost) ? remainingCost : BN.max(new BN(0), reserveValue);
|
|
205
|
+
currentReserveCost = currentReserveCost.add(actualSpend);
|
|
206
|
+
accountUpdates[owner] = applyTokenUpdates([{
|
|
207
|
+
address: reserveAddress,
|
|
208
|
+
value: actualSpend.toString()
|
|
209
|
+
}], signerStates.find((s) => s.address === owner), "sub");
|
|
178
210
|
inputChanges.push({
|
|
179
211
|
address: owner,
|
|
180
212
|
token: reserveAddress,
|
|
181
|
-
delta:
|
|
213
|
+
delta: actualSpend.neg().toString()
|
|
182
214
|
});
|
|
183
215
|
});
|
|
184
216
|
if (!accountUpdates[tx$1.from]) accountUpdates[tx$1.from] = senderState || {};
|
|
@@ -194,6 +226,7 @@ runner.use(async (context, next) => {
|
|
|
194
226
|
delta: String(amount)
|
|
195
227
|
});
|
|
196
228
|
if (senderChange) accountUpdates[senderChange.address] = applyTokenChange(accountUpdates[senderChange.address] || senderState, senderChange);
|
|
229
|
+
const isSameAddr = (a, b) => Boolean(a && b && (a === b || toAddress(a) === toAddress(b)));
|
|
197
230
|
const [newAccountStates, newTokenFactoryState, newTokenState] = await Promise.all([
|
|
198
231
|
Promise.all(Object.entries(accountUpdates).map(([address, updates]) => {
|
|
199
232
|
const state = [
|
|
@@ -201,13 +234,13 @@ runner.use(async (context, next) => {
|
|
|
201
234
|
receiverState,
|
|
202
235
|
ownerState,
|
|
203
236
|
...signerStates
|
|
204
|
-
].find((x) => x?.address
|
|
237
|
+
].find((x) => isSameAddr(x?.address, address));
|
|
205
238
|
const actualUpdates = state ? pick(updates, ["tokens"]) : {
|
|
206
239
|
...updates,
|
|
207
240
|
address
|
|
208
241
|
};
|
|
209
|
-
if (address
|
|
210
|
-
actualUpdates.pk = tx$1.pk;
|
|
242
|
+
if (isSameAddr(address, tx$1.from)) {
|
|
243
|
+
actualUpdates.pk = tx$1.delegator ? state?.pk || tx$1.pk : tx$1.pk;
|
|
211
244
|
actualUpdates.nonce = tx$1.nonce;
|
|
212
245
|
}
|
|
213
246
|
return statedb.account.updateOrCreate(state ?? null, account.updateOrCreate(state ?? null, actualUpdates, context), context);
|
|
@@ -218,10 +251,10 @@ runner.use(async (context, next) => {
|
|
|
218
251
|
}, context), context),
|
|
219
252
|
statedb.token.update(tokenAddress, token.update(tokenState, { totalSupply: new BN(tokenState.totalSupply).add(new BN(amount)).toString() }), context)
|
|
220
253
|
]);
|
|
221
|
-
context.senderState = newAccountStates.find((x) => x.address
|
|
222
|
-
context.receiverState = newAccountStates.find((x) => x.address
|
|
223
|
-
context.ownerState = newAccountStates.find((x) => x.address
|
|
224
|
-
context.signerStates = newAccountStates.filter((x) => signerStates.find((s) => s.address
|
|
254
|
+
context.senderState = newAccountStates.find((x) => isSameAddr(x.address, tx$1.from));
|
|
255
|
+
context.receiverState = newAccountStates.find((x) => isSameAddr(x.address, receiver));
|
|
256
|
+
context.ownerState = newAccountStates.find((x) => isSameAddr(x.address, ownerState.address)) || ownerState;
|
|
257
|
+
context.signerStates = newAccountStates.filter((x) => signerStates.find((s) => isSameAddr(s.address, x.address)));
|
|
225
258
|
context.tokenFactoryState = newTokenFactoryState;
|
|
226
259
|
context.tokenState = newTokenState;
|
|
227
260
|
context.inputChanges = inputChanges;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CustomError } from "@ocap/util/lib/error";
|
|
2
2
|
import get from "lodash/get.js";
|
|
3
|
-
import set from "lodash/set.js";
|
|
4
3
|
import { isSvgFile, sanitizeSvg } from "@blocklet/xss";
|
|
4
|
+
import set from "lodash/set.js";
|
|
5
5
|
|
|
6
6
|
//#region src/protocols/token-factory/pipes/verify-icon.ts
|
|
7
7
|
const verifyIcon = ({ iconKey = "itx.token.icon", size = 16 * 1024 } = {}) => (context, next) => {
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { applyTokenChange, decodeAnySafe, getDelegationRequirements, isHttpUrl, isHttpsUrl } 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 verify_icon_default from "./pipes/verify-icon.mjs";
|
|
5
4
|
import verify_ownership_default from "./pipes/verify-ownership.mjs";
|
|
6
5
|
import verify_url_default from "./pipes/verify-url.mjs";
|
|
6
|
+
import verify_icon_default from "./pipes/verify-icon.mjs";
|
|
7
7
|
import { account, delegation, token, tokenFactory } from "@ocap/state";
|
|
8
8
|
import { Runner, pipes } from "@ocap/tx-pipeline";
|
|
9
|
+
import { isSameDid } from "@ocap/util";
|
|
9
10
|
import { CustomError } from "@ocap/util/lib/error";
|
|
11
|
+
import { getRelatedAddresses } from "@ocap/util/lib/get-related-addr";
|
|
10
12
|
import Debug from "debug";
|
|
11
13
|
import { v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
12
14
|
|
|
@@ -92,6 +94,7 @@ runner.use(pipes.VerifyAccountMigration({
|
|
|
92
94
|
stateKey: "delegatorState",
|
|
93
95
|
addressKey: "tx.delegator"
|
|
94
96
|
}));
|
|
97
|
+
runner.use(pipes.VerifyBlocked({ stateKeys: ["delegatorState"] }));
|
|
95
98
|
runner.use(pipes.VerifyDelegation({
|
|
96
99
|
type: "signature",
|
|
97
100
|
signerKey: "senderState",
|
|
@@ -99,8 +102,8 @@ runner.use(pipes.VerifyDelegation({
|
|
|
99
102
|
getRequirements: getDelegationRequirements
|
|
100
103
|
}));
|
|
101
104
|
runner.use((context, next) => {
|
|
102
|
-
const { tokenFactoryState, delegatorState, senderState } = context;
|
|
103
|
-
if ((delegatorState ? delegatorState.
|
|
105
|
+
const { tx: tx$1, tokenFactoryState, delegatorState, senderState } = context;
|
|
106
|
+
if (!(delegatorState ? getRelatedAddresses(delegatorState) : tx$1.delegator ? [tx$1.delegator] : getRelatedAddresses(senderState)).some((addr) => isSameDid(addr, tokenFactoryState.owner))) return next(new CustomError("FORBIDDEN", "Token factory can only be updated by owner"));
|
|
104
107
|
return next();
|
|
105
108
|
});
|
|
106
109
|
runner.use(ensure_gas_default((context) => {
|
|
@@ -129,15 +132,22 @@ runner.use(async (context, next) => {
|
|
|
129
132
|
website: itx.token.website || tokenStateValue.website,
|
|
130
133
|
metadata: itx.token.metadata || tokenStateValue.metadata
|
|
131
134
|
} : null;
|
|
135
|
+
const nextTokenState = tokenUpdates ? token.update(token.normalizeLegacyTokenStateForUpdate(tokenStateValue), tokenUpdates) : tokenStateValue;
|
|
136
|
+
const charterAddress = tokenUpdates ? token.toTokenCharterAssetAddress(tokenStateValue.address) : "";
|
|
132
137
|
const [newSenderState, newTokenFactoryState, newTokenState, newDelegationState] = await Promise.all([
|
|
133
138
|
statedb.account.update(senderStateValue.address, account.update(senderStateValue, {
|
|
134
139
|
nonce: tx$1.nonce,
|
|
135
|
-
pk: tx$1.pk,
|
|
140
|
+
pk: tx$1.delegator ? senderStateValue.pk : tx$1.pk,
|
|
136
141
|
...senderUpdates
|
|
137
142
|
}, context), context),
|
|
138
143
|
statedb.tokenFactory.update(tokenFactoryStateValue.address, tokenFactory.update(tokenFactoryStateValue, factoryUpdates, context), context),
|
|
139
|
-
tokenUpdates ? statedb.token.update(tokenStateValue.address,
|
|
140
|
-
context.isDelegationChanged && delegationState ? statedb.delegation.update(delegationState.address, delegation.update(delegationState, {}, context), context) : delegationState
|
|
144
|
+
tokenUpdates ? statedb.token.update(tokenStateValue.address, nextTokenState, context) : tokenStateValue,
|
|
145
|
+
context.isDelegationChanged && delegationState ? statedb.delegation.update(delegationState.address, delegation.update(delegationState, {}, context), context) : delegationState,
|
|
146
|
+
tokenUpdates && statedb.asset?.get ? Promise.resolve(statedb.asset.get(charterAddress, context)).then((existingCharter) => {
|
|
147
|
+
if (existingCharter && statedb.asset.update) return statedb.asset.update(charterAddress, token.syncCharterAssetWithToken(existingCharter, nextTokenState, context, tokenFactoryStateValue.owner), context);
|
|
148
|
+
if (statedb.asset.create) return statedb.asset.create(charterAddress, token.buildTokenCharterAssetState(nextTokenState, context, tokenFactoryStateValue.owner), context);
|
|
149
|
+
return null;
|
|
150
|
+
}) : null
|
|
141
151
|
]);
|
|
142
152
|
if (updateVaults) await updateVaults();
|
|
143
153
|
context.senderState = newSenderState;
|
|
@@ -35,6 +35,10 @@ type Context = IReadyContext<TExchangeV2Tx> & IWithSender & IWithReceiver & Part
|
|
|
35
35
|
};
|
|
36
36
|
/** Token states for exchanged tokens */
|
|
37
37
|
tokenStates?: ITokenState[];
|
|
38
|
+
/** Token states for sender's exchanged tokens */
|
|
39
|
+
senderTokenStates?: ITokenState[];
|
|
40
|
+
/** Token states for receiver's exchanged tokens */
|
|
41
|
+
receiverTokenStates?: ITokenState[];
|
|
38
42
|
/** Receiver address extracted from tx signatures or itx.to */
|
|
39
43
|
receiver?: string;
|
|
40
44
|
/** Multisig delegation states */
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { applyTokenChange } 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 { toTypeInfo } from "@arcblock/did";
|
|
5
|
+
import { types } from "@ocap/mcrypto";
|
|
6
|
+
import { account, delegation, token } from "@ocap/state";
|
|
5
7
|
import { Runner, pipes, verifyAssetHierarchy } from "@ocap/tx-pipeline";
|
|
6
|
-
import { BN } from "@ocap/util";
|
|
8
|
+
import { BN, isSameDid } from "@ocap/util";
|
|
7
9
|
import { CustomError } from "@ocap/util/lib/error";
|
|
10
|
+
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
11
|
+
import { getRelatedAddresses } from "@ocap/util/lib/get-related-addr";
|
|
8
12
|
import Debug from "debug";
|
|
9
13
|
import { decodeBigInt } from "@ocap/message";
|
|
10
|
-
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
11
14
|
import { schemas, v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
12
15
|
import { createSortedList } from "@ocap/util/lib/create-sorted-list";
|
|
13
16
|
import isEmpty from "lodash/isEmpty.js";
|
|
@@ -40,6 +43,24 @@ runner.use(pipes.ExtractReceiver({ from: [
|
|
|
40
43
|
"itx.to"
|
|
41
44
|
] }));
|
|
42
45
|
runner.use(pipes.VerifyInfo([{
|
|
46
|
+
error: "INVALID_TX",
|
|
47
|
+
message: "Can not exchange duplicate tokens or assets",
|
|
48
|
+
fn: (ctx) => {
|
|
49
|
+
const { itx } = ctx;
|
|
50
|
+
const senderAssets = getListField(itx, "sender.assets");
|
|
51
|
+
const receiverAssets = getListField(itx, "receiver.assets");
|
|
52
|
+
const senderTokens = getListField(itx, "sender.tokens");
|
|
53
|
+
const receiverTokens = getListField(itx, "receiver.tokens");
|
|
54
|
+
const senderTokenAddrs = senderTokens.map((x) => x.address);
|
|
55
|
+
const receiverTokenAddrs = receiverTokens.map((x) => x.address);
|
|
56
|
+
if (new Set(senderTokenAddrs).size !== senderTokenAddrs.length) return false;
|
|
57
|
+
if (new Set(receiverTokenAddrs).size !== receiverTokenAddrs.length) return false;
|
|
58
|
+
if (new Set(senderAssets).size !== senderAssets.length) return false;
|
|
59
|
+
if (new Set(receiverAssets).size !== receiverAssets.length) return false;
|
|
60
|
+
if (senderAssets.some((x) => receiverAssets.includes(x))) return false;
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
}, {
|
|
43
64
|
error: "INVALID_TX",
|
|
44
65
|
message: "Can not exchange without any token or assets",
|
|
45
66
|
fn: (ctx) => {
|
|
@@ -53,8 +74,11 @@ runner.use(pipes.VerifyInfo([{
|
|
|
53
74
|
const senderValue = itx.sender?.value;
|
|
54
75
|
const senderAmount = senderValue ? decodeBigInt(senderValue) : 0;
|
|
55
76
|
if (new BN(senderAmount).gt(zero)) {
|
|
56
|
-
|
|
57
|
-
|
|
77
|
+
const primaryTokenAddress = config.token.address;
|
|
78
|
+
const existing = senderTokensLocal.find((x) => x.address === primaryTokenAddress);
|
|
79
|
+
if (existing) existing.value = new BN(existing.value).add(new BN(senderAmount)).toString(10);
|
|
80
|
+
else senderTokensLocal.push({
|
|
81
|
+
address: primaryTokenAddress,
|
|
58
82
|
value: senderAmount
|
|
59
83
|
});
|
|
60
84
|
itx.sender.value = "0";
|
|
@@ -62,8 +86,11 @@ runner.use(pipes.VerifyInfo([{
|
|
|
62
86
|
const receiverValue = itx.receiver?.value;
|
|
63
87
|
const receiverAmount = receiverValue ? decodeBigInt(receiverValue) : 0;
|
|
64
88
|
if (new BN(receiverAmount).gt(zero)) {
|
|
65
|
-
|
|
66
|
-
|
|
89
|
+
const primaryTokenAddress = config.token.address;
|
|
90
|
+
const existing = receiverTokensLocal.find((x) => x.address === primaryTokenAddress);
|
|
91
|
+
if (existing) existing.value = new BN(existing.value).add(new BN(receiverAmount)).toString(10);
|
|
92
|
+
else receiverTokensLocal.push({
|
|
93
|
+
address: primaryTokenAddress,
|
|
67
94
|
value: receiverAmount
|
|
68
95
|
});
|
|
69
96
|
itx.receiver.value = "0";
|
|
@@ -85,12 +112,22 @@ runner.use(pipes.ExtractState({
|
|
|
85
112
|
status: "INVALID_SENDER_STATE",
|
|
86
113
|
table: "account"
|
|
87
114
|
}));
|
|
115
|
+
runner.use(pipes.ExtractState({
|
|
116
|
+
from: "receiver",
|
|
117
|
+
to: "receiverState",
|
|
118
|
+
status: "INVALID_RECEIVER_STATE",
|
|
119
|
+
table: "account"
|
|
120
|
+
}));
|
|
88
121
|
runner.use(pipes.ExtractState({
|
|
89
122
|
from: "tx.delegator",
|
|
90
123
|
to: "delegatorState",
|
|
91
124
|
status: "OK",
|
|
92
125
|
table: "account"
|
|
93
126
|
}));
|
|
127
|
+
runner.use(pipes.VerifyAccountMigration({
|
|
128
|
+
stateKey: "delegatorState",
|
|
129
|
+
addressKey: "tx.delegator"
|
|
130
|
+
}));
|
|
94
131
|
runner.use(pipes.VerifyDelegation({
|
|
95
132
|
type: "signature",
|
|
96
133
|
signerKey: "senderState",
|
|
@@ -99,7 +136,7 @@ runner.use(pipes.VerifyDelegation({
|
|
|
99
136
|
const context = ctx;
|
|
100
137
|
const tokens = context.senderTokens || [];
|
|
101
138
|
const assets = context.senderAssets || [];
|
|
102
|
-
const toAddresses = context.receiver ? [context.receiver] : [context.itx.to];
|
|
139
|
+
const toAddresses = context.receiverState ? getRelatedAddresses(context.receiverState) : context.receiver ? [context.receiver] : [context.itx.to];
|
|
103
140
|
return [...tokens.map((x) => ({
|
|
104
141
|
type: "token",
|
|
105
142
|
address: x.address,
|
|
@@ -125,7 +162,7 @@ runner.use(pipes.VerifyDelegation({
|
|
|
125
162
|
const context = ctx;
|
|
126
163
|
const tokens = context.receiverTokens || [];
|
|
127
164
|
const assets = context.receiverAssets || [];
|
|
128
|
-
const toAddresses = context.senderState ?
|
|
165
|
+
const toAddresses = context.senderState ? getRelatedAddresses(context.senderState) : [context.tx.from];
|
|
129
166
|
return [...tokens.map((x) => ({
|
|
130
167
|
type: "token",
|
|
131
168
|
address: x.address,
|
|
@@ -144,17 +181,15 @@ runner.use(pipes.ExtractState({
|
|
|
144
181
|
status: "INVALID_TOKEN",
|
|
145
182
|
table: "token"
|
|
146
183
|
}));
|
|
147
|
-
runner.use(pipes.ExtractState({
|
|
148
|
-
from: "receiver",
|
|
149
|
-
to: "receiverState",
|
|
150
|
-
status: "INVALID_RECEIVER_STATE",
|
|
151
|
-
table: "account"
|
|
152
|
-
}));
|
|
153
184
|
runner.use(pipes.VerifyAccountMigration({
|
|
154
185
|
signerKey: "signerStates",
|
|
155
186
|
stateKey: "senderState",
|
|
156
187
|
addressKey: "tx.from"
|
|
157
188
|
}));
|
|
189
|
+
runner.use(pipes.VerifyAccountMigration({
|
|
190
|
+
stateKey: "receiverState",
|
|
191
|
+
addressKey: "receiver"
|
|
192
|
+
}));
|
|
158
193
|
runner.use((context, next) => {
|
|
159
194
|
context.senderTokenConditions = {
|
|
160
195
|
owner: context.senderState.address,
|
|
@@ -164,6 +199,8 @@ runner.use((context, next) => {
|
|
|
164
199
|
owner: context.receiverState.address,
|
|
165
200
|
tokens: context.receiverTokens || []
|
|
166
201
|
};
|
|
202
|
+
context.senderTokenStates = (context.tokenStates || []).filter((t) => (context.senderTokens || []).some((st) => st.address === t.address));
|
|
203
|
+
context.receiverTokenStates = (context.tokenStates || []).filter((t) => (context.receiverTokens || []).some((rt) => rt.address === t.address));
|
|
167
204
|
next();
|
|
168
205
|
});
|
|
169
206
|
runner.use(pipes.VerifyTokenBalance({
|
|
@@ -178,13 +215,25 @@ runner.use(pipes.AntiLandAttack({
|
|
|
178
215
|
senderState: "senderState",
|
|
179
216
|
receiverState: "receiverState"
|
|
180
217
|
}));
|
|
181
|
-
runner.use(pipes.VerifyBlocked({ stateKeys: [
|
|
218
|
+
runner.use(pipes.VerifyBlocked({ stateKeys: [
|
|
219
|
+
"senderState",
|
|
220
|
+
"receiverState",
|
|
221
|
+
"delegatorState",
|
|
222
|
+
"signerStates",
|
|
223
|
+
"delegatorStates"
|
|
224
|
+
] }));
|
|
182
225
|
runner.use(pipes.verifyTokenAccess({
|
|
183
|
-
statesKey: "
|
|
226
|
+
statesKey: "senderTokenStates",
|
|
184
227
|
listFieldKey: "spenders",
|
|
185
228
|
accountKeys: ["senderState"],
|
|
186
229
|
errorMessage: "Account {address} is not allowed to exchange token {tokenAddress}"
|
|
187
230
|
}));
|
|
231
|
+
runner.use(pipes.verifyTokenAccess({
|
|
232
|
+
statesKey: "receiverTokenStates",
|
|
233
|
+
listFieldKey: "spenders",
|
|
234
|
+
accountKeys: ["receiverState"],
|
|
235
|
+
errorMessage: "Account {address} is not allowed to exchange token {tokenAddress}"
|
|
236
|
+
}));
|
|
188
237
|
runner.use(pipes.ExtractState({
|
|
189
238
|
from: "senderAssets",
|
|
190
239
|
to: "priv.senderAssets",
|
|
@@ -208,10 +257,16 @@ runner.use(pipes.VerifyUpdater({
|
|
|
208
257
|
ownerKey: "receiverState"
|
|
209
258
|
}));
|
|
210
259
|
runner.use(async (context, next) => {
|
|
211
|
-
const { senderAssets = [], receiverAssets = [], senderState, receiverState } = context;
|
|
260
|
+
const { senderAssets = [], receiverAssets = [], senderState, receiverState, priv } = context;
|
|
212
261
|
const pendingOwners = {};
|
|
213
|
-
if (receiverState?.address)
|
|
214
|
-
|
|
262
|
+
if (receiverState?.address) {
|
|
263
|
+
if (toTypeInfo(receiverState.address).role === types.RoleType.ROLE_ASSET && (priv?.senderAssets || []).some((st) => token.isTokenCharterAsset(st))) return next(new CustomError("INVALID_OWNER", "Token Charter NFT cannot be owned by an asset", { persist: true }));
|
|
264
|
+
for (const addr of senderAssets) pendingOwners[addr] = receiverState.address;
|
|
265
|
+
}
|
|
266
|
+
if (senderState?.address) {
|
|
267
|
+
if (toTypeInfo(senderState.address).role === types.RoleType.ROLE_ASSET && (priv?.receiverAssets || []).some((st) => token.isTokenCharterAsset(st))) return next(new CustomError("INVALID_OWNER", "Token Charter NFT cannot be owned by an asset", { persist: true }));
|
|
268
|
+
for (const addr of receiverAssets) pendingOwners[addr] = senderState.address;
|
|
269
|
+
}
|
|
215
270
|
if (senderAssets.length && receiverState?.address) {
|
|
216
271
|
const err = await verifyAssetHierarchy(senderAssets, receiverState.address, context, pendingOwners);
|
|
217
272
|
if (err) return next(err);
|
|
@@ -233,6 +288,7 @@ runner.use(ensure_gas_default((context) => {
|
|
|
233
288
|
return ops;
|
|
234
289
|
}));
|
|
235
290
|
runner.use(ensure_cost_default({ attachSenderChanges: true }));
|
|
291
|
+
runner.use(pipes.TakeStateSnapshot());
|
|
236
292
|
runner.use(pipes.UpdateOwner({
|
|
237
293
|
assets: "priv.senderAssets",
|
|
238
294
|
owner: "receiverState"
|
|
@@ -241,7 +297,6 @@ runner.use(pipes.UpdateOwner({
|
|
|
241
297
|
assets: "priv.receiverAssets",
|
|
242
298
|
owner: "senderState"
|
|
243
299
|
}));
|
|
244
|
-
runner.use(pipes.TakeStateSnapshot());
|
|
245
300
|
runner.use(async (context, next) => {
|
|
246
301
|
const { tx: tx$1, itx, senderAssets = [], receiverAssets = [], senderTokens = [], receiverTokens = [], senderState, receiverState, senderChange, delegationState, delegationStates = [], updateVaults, statedb } = context;
|
|
247
302
|
const senderStateTokens = senderState?.tokens || {};
|
|
@@ -262,6 +317,7 @@ runner.use(async (context, next) => {
|
|
|
262
317
|
statedb.account.updateOrCreate(existingSenderState ?? null, account.updateOrCreate(existingSenderState ?? null, {
|
|
263
318
|
address: senderState.address,
|
|
264
319
|
nonce: tx$1.nonce,
|
|
320
|
+
pk: tx$1.delegator ? senderState.pk : tx$1.pk,
|
|
265
321
|
...senderUpdates
|
|
266
322
|
}, context), context),
|
|
267
323
|
statedb.account.updateOrCreate(existingReceiverState ?? null, account.updateOrCreate(existingReceiverState ?? null, {
|
|
@@ -269,7 +325,7 @@ runner.use(async (context, next) => {
|
|
|
269
325
|
tokens: receiverStateTokens
|
|
270
326
|
}, context), context),
|
|
271
327
|
context.isDelegationChanged && delegationState ? statedb.delegation.update(delegationState.address, delegation.update(delegationState, {}, context), context) : delegationState,
|
|
272
|
-
context.isDelegationChanged && delegationStates.length ? Promise.all(delegationStates.map((d) => statedb.delegation.update(d.address, delegation.update(d, {}, context), context))) : delegationStates
|
|
328
|
+
context.isDelegationChanged && delegationStates.length ? Promise.all(delegationStates.filter((d) => !delegationState || !isSameDid(d.address, delegationState.address)).map((d) => statedb.delegation.update(d.address, delegation.update(d, {}, context), context))) : delegationStates
|
|
273
329
|
]);
|
|
274
330
|
if (updateVaults) await updateVaults();
|
|
275
331
|
context.senderState = newSenderState;
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { applyTokenChange } 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 {
|
|
5
|
-
import { Runner, pipes } from "@ocap/tx-pipeline";
|
|
6
|
-
import { BN } from "@ocap/util";
|
|
7
|
-
import { CustomError } from "@ocap/util/lib/error";
|
|
4
|
+
import { toTypeInfo } from "@arcblock/did";
|
|
8
5
|
import { toStakeAddress } from "@arcblock/did-util";
|
|
9
|
-
import {
|
|
6
|
+
import { types } from "@ocap/mcrypto";
|
|
7
|
+
import { account, delegation, token } from "@ocap/state";
|
|
8
|
+
import { Runner, pipes, verifyAssetHierarchy } from "@ocap/tx-pipeline";
|
|
9
|
+
import { BN, isSameDid } from "@ocap/util";
|
|
10
|
+
import { CustomError } from "@ocap/util/lib/error";
|
|
10
11
|
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
11
|
-
import { schemas, v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
12
12
|
import { getRelatedAddresses } from "@ocap/util/lib/get-related-addr";
|
|
13
|
+
import { decodeBigInt } from "@ocap/message";
|
|
14
|
+
import { schemas, v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
13
15
|
import isEmpty from "lodash/isEmpty.js";
|
|
14
16
|
|
|
15
17
|
//#region src/protocols/trade/transfer-v2.ts
|
|
@@ -64,6 +66,22 @@ runner.use(pipes.VerifyInfo([
|
|
|
64
66
|
const addresses = (ctx.tokens || []).map((x) => x.address);
|
|
65
67
|
return new Set(addresses).size === addresses.length;
|
|
66
68
|
}
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
error: "INVALID_TX",
|
|
72
|
+
message: "Can not transfer duplicate assets in itx.assets",
|
|
73
|
+
fn: (ctx) => {
|
|
74
|
+
const addresses = ctx.assets || [];
|
|
75
|
+
return new Set(addresses).size === addresses.length;
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
error: "INVALID_TX",
|
|
80
|
+
message: "Sender should not exist in receiver list",
|
|
81
|
+
fn: (ctx) => {
|
|
82
|
+
const context = ctx;
|
|
83
|
+
return !isSameDid(context.tx.from, context.itx.to);
|
|
84
|
+
}
|
|
67
85
|
}
|
|
68
86
|
]));
|
|
69
87
|
runner.use(pipes.VerifyListSize({ listKey: ["assets", "tokens"] }));
|
|
@@ -92,7 +110,7 @@ runner.use(ensure_gas_default((context) => {
|
|
|
92
110
|
update: 2,
|
|
93
111
|
payment: 0
|
|
94
112
|
};
|
|
95
|
-
result.update += context.assetStates?.length || 0;
|
|
113
|
+
result.update += context.assetStates?.length || context.assets?.length || 0;
|
|
96
114
|
if (context.receiverState) result.update += 1;
|
|
97
115
|
else result.create += 1;
|
|
98
116
|
return result;
|
|
@@ -179,7 +197,11 @@ runner.use(pipes.AntiLandAttack({
|
|
|
179
197
|
senderState: "senderState",
|
|
180
198
|
receiverState: "receiverState"
|
|
181
199
|
}));
|
|
182
|
-
runner.use(pipes.VerifyBlocked({ stateKeys: [
|
|
200
|
+
runner.use(pipes.VerifyBlocked({ stateKeys: [
|
|
201
|
+
"senderState",
|
|
202
|
+
"delegatorState",
|
|
203
|
+
"receiverState"
|
|
204
|
+
] }));
|
|
183
205
|
runner.use(pipes.verifyTokenAccess({
|
|
184
206
|
statesKey: "tokenStates",
|
|
185
207
|
listFieldKey: "spenders",
|
|
@@ -197,17 +219,26 @@ runner.use(pipes.VerifyUpdater({
|
|
|
197
219
|
assetKey: "assetStates",
|
|
198
220
|
ownerKey: "senderState"
|
|
199
221
|
}));
|
|
200
|
-
runner.use(
|
|
201
|
-
|
|
202
|
-
const
|
|
203
|
-
context.receiverAddr =
|
|
222
|
+
runner.use(async (context, next) => {
|
|
223
|
+
const { itx, receiverState, senderState, assets = [], assetStates = [] } = context;
|
|
224
|
+
const receiverAddr = receiverState ? receiverState.address : itx.to;
|
|
225
|
+
context.receiverAddr = receiverAddr;
|
|
226
|
+
if (senderState && isSameDid(senderState.address, receiverAddr)) return next(new CustomError("INVALID_TX", `Sender should not exist in receiver list: ${senderState.address}`));
|
|
227
|
+
if (assets.length > 0) {
|
|
228
|
+
if (toTypeInfo(receiverAddr).role === types.RoleType.ROLE_ASSET && assetStates.some((st) => token.isTokenCharterAsset(st))) return next(new CustomError("INVALID_OWNER", "Token Charter NFT cannot be owned by an asset", { persist: true }));
|
|
229
|
+
const pendingOwners = {};
|
|
230
|
+
for (const addr of assets) pendingOwners[addr] = receiverAddr;
|
|
231
|
+
const err = await verifyAssetHierarchy(assets, receiverAddr, context, pendingOwners);
|
|
232
|
+
if (err) return next(err);
|
|
233
|
+
}
|
|
204
234
|
return next();
|
|
205
235
|
});
|
|
236
|
+
runner.use(ensure_cost_default({ attachSenderChanges: true }));
|
|
237
|
+
runner.use(pipes.TakeStateSnapshot());
|
|
206
238
|
runner.use(pipes.UpdateOwner({
|
|
207
239
|
assets: "assetStates",
|
|
208
240
|
owner: "receiverAddr"
|
|
209
241
|
}));
|
|
210
|
-
runner.use(pipes.TakeStateSnapshot());
|
|
211
242
|
runner.use(async (context, next) => {
|
|
212
243
|
const { tx: tx$1, tokens, senderState, receiverAddr, receiverState, statedb, senderChange, delegationState, updateVaults } = context;
|
|
213
244
|
const senderTokens = senderState?.tokens || {};
|