@ocap/tx-protocols 1.30.24 → 1.30.25
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 +6 -2
- package/esm/execute.mjs +214 -25
- package/esm/index.d.mts +25 -2
- package/esm/index.mjs +2 -2
- package/esm/pipes/ensure-cost.mjs +2 -2
- package/esm/pipes/write-ledger.mjs +7 -0
- package/esm/protocols/account/delegate.mjs +7 -6
- package/esm/protocols/account/migrate.mjs +2 -2
- package/esm/protocols/account/revoke-delegate.mjs +1 -1
- package/esm/protocols/asset/acquire-v2.mjs +25 -6
- package/esm/protocols/asset/acquire-v3.d.mts +11 -1
- package/esm/protocols/asset/acquire-v3.mjs +78 -9
- package/esm/protocols/asset/consume.mjs +1 -1
- package/esm/protocols/asset/create.mjs +1 -1
- package/esm/protocols/asset/mint.mjs +8 -2
- package/esm/protocols/asset/pipes/verify-itx-address.mjs +1 -1
- package/esm/protocols/asset/update.mjs +1 -1
- package/esm/protocols/factory/create.mjs +4 -3
- package/esm/protocols/governance/claim-stake.mjs +2 -2
- package/esm/protocols/governance/return-stake.mjs +2 -2
- package/esm/protocols/governance/revoke-stake.mjs +2 -2
- package/esm/protocols/governance/slash-stake.mjs +2 -2
- package/esm/protocols/governance/stake.mjs +2 -2
- package/esm/protocols/rollup/claim-reward.mjs +5 -4
- package/esm/protocols/rollup/close.mjs +1 -1
- package/esm/protocols/rollup/create-block.mjs +1 -1
- package/esm/protocols/rollup/create.mjs +1 -1
- package/esm/protocols/rollup/join.mjs +2 -2
- package/esm/protocols/rollup/leave.mjs +1 -1
- package/esm/protocols/rollup/migrate.mjs +1 -1
- package/esm/protocols/rollup/pause.mjs +1 -1
- package/esm/protocols/rollup/pipes/verify-evidence.mjs +5 -2
- package/esm/protocols/rollup/pipes/verify-signers.mjs +5 -3
- package/esm/protocols/rollup/resume.mjs +1 -1
- package/esm/protocols/rollup/update.mjs +4 -4
- package/esm/protocols/token/create.mjs +2 -2
- package/esm/protocols/token/deposit-v2.mjs +2 -2
- package/esm/protocols/token/withdraw-v2.mjs +13 -9
- package/esm/protocols/token-factory/burn.mjs +4 -4
- package/esm/protocols/token-factory/create.mjs +2 -2
- package/esm/protocols/token-factory/mint.mjs +2 -2
- package/esm/protocols/token-factory/update.mjs +7 -5
- package/esm/protocols/trade/exchange-v2.d.mts +3 -1
- package/esm/protocols/trade/exchange-v2.mjs +69 -11
- package/esm/protocols/trade/transfer-v2.mjs +39 -23
- package/esm/protocols/trade/transfer-v3.d.mts +11 -1
- package/esm/protocols/trade/transfer-v3.mjs +102 -11
- package/esm/tx-timer.d.mts +5 -0
- package/esm/tx-timer.mjs +13 -0
- package/esm/util.mjs +2 -1
- package/lib/execute.cjs +211 -20
- package/lib/execute.d.cts +6 -2
- package/lib/index.cjs +3 -1
- package/lib/index.d.cts +25 -2
- package/lib/pipes/ensure-cost.cjs +2 -2
- package/lib/pipes/write-ledger.cjs +7 -0
- package/lib/protocols/account/delegate.cjs +7 -6
- package/lib/protocols/account/migrate.cjs +2 -2
- package/lib/protocols/account/revoke-delegate.cjs +1 -1
- package/lib/protocols/asset/acquire-v2.cjs +24 -5
- package/lib/protocols/asset/acquire-v3.cjs +77 -8
- package/lib/protocols/asset/acquire-v3.d.cts +11 -1
- package/lib/protocols/asset/consume.cjs +1 -1
- package/lib/protocols/asset/create.cjs +1 -1
- package/lib/protocols/asset/mint.cjs +7 -1
- package/lib/protocols/asset/pipes/verify-itx-address.cjs +1 -1
- package/lib/protocols/asset/update.cjs +1 -1
- package/lib/protocols/factory/create.cjs +4 -3
- package/lib/protocols/governance/claim-stake.cjs +2 -2
- package/lib/protocols/governance/return-stake.cjs +2 -2
- package/lib/protocols/governance/revoke-stake.cjs +2 -2
- package/lib/protocols/governance/slash-stake.cjs +2 -2
- package/lib/protocols/governance/stake.cjs +2 -2
- package/lib/protocols/rollup/claim-reward.cjs +5 -4
- package/lib/protocols/rollup/close.cjs +1 -1
- package/lib/protocols/rollup/create-block.cjs +1 -1
- package/lib/protocols/rollup/create.cjs +1 -1
- package/lib/protocols/rollup/join.cjs +2 -2
- package/lib/protocols/rollup/leave.cjs +1 -1
- package/lib/protocols/rollup/migrate.cjs +1 -1
- package/lib/protocols/rollup/pause.cjs +1 -1
- package/lib/protocols/rollup/pipes/verify-evidence.cjs +5 -2
- package/lib/protocols/rollup/pipes/verify-signers.cjs +5 -4
- package/lib/protocols/rollup/resume.cjs +1 -1
- package/lib/protocols/rollup/update.cjs +4 -4
- package/lib/protocols/token/create.cjs +2 -2
- package/lib/protocols/token/deposit-v2.cjs +2 -2
- package/lib/protocols/token/withdraw-v2.cjs +13 -9
- package/lib/protocols/token-factory/burn.cjs +4 -4
- package/lib/protocols/token-factory/create.cjs +2 -2
- package/lib/protocols/token-factory/mint.cjs +2 -2
- package/lib/protocols/token-factory/update.cjs +7 -5
- package/lib/protocols/trade/exchange-v2.cjs +68 -10
- package/lib/protocols/trade/exchange-v2.d.cts +3 -1
- package/lib/protocols/trade/transfer-v2.cjs +39 -23
- package/lib/protocols/trade/transfer-v3.cjs +101 -10
- package/lib/protocols/trade/transfer-v3.d.cts +11 -1
- package/lib/tx-timer.cjs +13 -0
- package/lib/tx-timer.d.cts +5 -0
- package/lib/util.cjs +2 -1
- package/package.json +16 -16
|
@@ -4,11 +4,11 @@ const require_util = require('../../util.cjs');
|
|
|
4
4
|
const require_pipes_ensure_cost = require('../../pipes/ensure-cost.cjs');
|
|
5
5
|
const require_pipes_ensure_gas = require('../../pipes/ensure-gas.cjs');
|
|
6
6
|
const require_protocols_rollup_pipes_verify_status = require('../rollup/pipes/verify-status.cjs');
|
|
7
|
+
let _ocap_state = require("@ocap/state");
|
|
7
8
|
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
9
|
+
let _ocap_util = require("@ocap/util");
|
|
8
10
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
9
11
|
let _arcblock_did_util = require("@arcblock/did-util");
|
|
10
|
-
let _ocap_state = require("@ocap/state");
|
|
11
|
-
let _ocap_util = require("@ocap/util");
|
|
12
12
|
let debug = require("debug");
|
|
13
13
|
debug = require_rolldown_runtime.__toESM(debug);
|
|
14
14
|
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
@@ -90,20 +90,24 @@ runner.use(_ocap_tx_pipeline.pipes.VerifyTokenBalance({
|
|
|
90
90
|
runner.use((context, next) => {
|
|
91
91
|
const { itx, rollupState, tokenState } = context;
|
|
92
92
|
const { withdrawFeeRate, maxWithdrawFee, minWithdrawFee } = rollupState;
|
|
93
|
+
const { reward } = require_util.getTxFee({
|
|
94
|
+
amount: itx.token.value,
|
|
95
|
+
feeRate: withdrawFeeRate,
|
|
96
|
+
maxFee: maxWithdrawFee,
|
|
97
|
+
minFee: minWithdrawFee
|
|
98
|
+
});
|
|
93
99
|
if (new _ocap_util.BN(itx.maxFee).isZero()) {
|
|
94
|
-
const { reward } = require_util.getTxFee({
|
|
95
|
-
amount: itx.token.value,
|
|
96
|
-
feeRate: withdrawFeeRate,
|
|
97
|
-
maxFee: maxWithdrawFee,
|
|
98
|
-
minFee: minWithdrawFee
|
|
99
|
-
});
|
|
100
100
|
if (new _ocap_util.BN(itx.actualFee).lt(new _ocap_util.BN(reward))) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `itx.actualFee too low, expect at least ${(0, _ocap_util.fromUnitToToken)(reward, tokenState.decimal)}, got ${(0, _ocap_util.fromUnitToToken)(itx.actualFee, tokenState.decimal)}`));
|
|
101
|
+
} else {
|
|
102
|
+
if (!new _ocap_util.BN(itx.actualFee || 0).isZero()) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "itx.actualFee must be 0 when itx.maxFee is specified"));
|
|
103
|
+
if (new _ocap_util.BN(itx.maxFee).lt(new _ocap_util.BN(reward))) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `itx.maxFee too low, expect at least ${(0, _ocap_util.fromUnitToToken)(reward, tokenState.decimal)}, got ${(0, _ocap_util.fromUnitToToken)(itx.maxFee, tokenState.decimal)}`));
|
|
101
104
|
}
|
|
102
105
|
return next();
|
|
103
106
|
});
|
|
104
107
|
runner.use((context, next) => {
|
|
105
|
-
const { tx, itx } = context;
|
|
108
|
+
const { tx, itx, rollupState } = context;
|
|
106
109
|
if (new _ocap_util.BN(itx.maxFee).isZero()) return next();
|
|
110
|
+
if ((rollupState.validators ?? []).map((x) => x.address).includes(itx.proposer) === false) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `itx.proposer ${itx.proposer} does not exist in validator whitelist`));
|
|
107
111
|
const signatures = (0, _ocap_util_lib_get_list_field.getListField)(tx, "signatures");
|
|
108
112
|
if (signatures.length !== 1) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "Withdraw with maxFee should have one multi-sig"));
|
|
109
113
|
if (signatures.some((x) => x.signer === itx.proposer) === false) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "itx.proposer must exist in tx.signatures"));
|
|
@@ -4,12 +4,12 @@ const require_util = require('../../util.cjs');
|
|
|
4
4
|
const require_pipes_ensure_cost = require('../../pipes/ensure-cost.cjs');
|
|
5
5
|
const require_pipes_ensure_gas = require('../../pipes/ensure-gas.cjs');
|
|
6
6
|
const require_protocols_token_factory_pipes_calc_reserve = require('./pipes/calc-reserve.cjs');
|
|
7
|
+
let _ocap_state = require("@ocap/state");
|
|
7
8
|
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
9
|
+
let _ocap_util = require("@ocap/util");
|
|
8
10
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
9
11
|
let lodash_pick = require("lodash/pick");
|
|
10
12
|
lodash_pick = require_rolldown_runtime.__toESM(lodash_pick);
|
|
11
|
-
let _ocap_state = require("@ocap/state");
|
|
12
|
-
let _ocap_util = require("@ocap/util");
|
|
13
13
|
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
14
14
|
let _arcblock_validator = require("@arcblock/validator");
|
|
15
15
|
|
|
@@ -112,8 +112,8 @@ runner.use(_ocap_tx_pipeline.pipes.verifyTokenAccess({
|
|
|
112
112
|
runner.use((context, next) => {
|
|
113
113
|
const { inputs = [], tokenFactoryState } = context;
|
|
114
114
|
let amount = new _ocap_util.BN("0");
|
|
115
|
-
for (const
|
|
116
|
-
const delta =
|
|
115
|
+
for (const input of inputs) {
|
|
116
|
+
const delta = (0, _ocap_util_lib_get_list_field.getListField)(input, "tokens").find((x) => x.address === tokenFactoryState.tokenAddress)?.value;
|
|
117
117
|
if (!delta) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "Invalid inputs"));
|
|
118
118
|
amount = amount.add(new _ocap_util.BN(delta));
|
|
119
119
|
}
|
|
@@ -7,11 +7,11 @@ const require_index = require('../../node_modules/valibot/dist/index.cjs');
|
|
|
7
7
|
const require_protocols_token_factory_pipes_verify_icon = require('./pipes/verify-icon.cjs');
|
|
8
8
|
const require_protocols_token_factory_pipes_verify_ownership = require('./pipes/verify-ownership.cjs');
|
|
9
9
|
const require_protocols_token_factory_pipes_verify_url = require('./pipes/verify-url.cjs');
|
|
10
|
+
let _ocap_state = require("@ocap/state");
|
|
10
11
|
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
12
|
+
let _ocap_util = require("@ocap/util");
|
|
11
13
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
12
14
|
let _arcblock_did_util = require("@arcblock/did-util");
|
|
13
|
-
let _ocap_state = require("@ocap/state");
|
|
14
|
-
let _ocap_util = require("@ocap/util");
|
|
15
15
|
let debug = require("debug");
|
|
16
16
|
debug = require_rolldown_runtime.__toESM(debug);
|
|
17
17
|
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
@@ -5,12 +5,12 @@ const require_pipes_ensure_cost = require('../../pipes/ensure-cost.cjs');
|
|
|
5
5
|
const require_pipes_ensure_gas = require('../../pipes/ensure-gas.cjs');
|
|
6
6
|
const require_index = require('../../node_modules/valibot/dist/index.cjs');
|
|
7
7
|
const require_protocols_token_factory_pipes_calc_reserve = require('./pipes/calc-reserve.cjs');
|
|
8
|
+
let _ocap_state = require("@ocap/state");
|
|
8
9
|
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
10
|
+
let _ocap_util = require("@ocap/util");
|
|
9
11
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
10
12
|
let lodash_pick = require("lodash/pick");
|
|
11
13
|
lodash_pick = require_rolldown_runtime.__toESM(lodash_pick);
|
|
12
|
-
let _ocap_state = require("@ocap/state");
|
|
13
|
-
let _ocap_util = require("@ocap/util");
|
|
14
14
|
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
15
15
|
let _arcblock_validator = require("@arcblock/validator");
|
|
16
16
|
|
|
@@ -6,9 +6,9 @@ const require_pipes_ensure_gas = require('../../pipes/ensure-gas.cjs');
|
|
|
6
6
|
const require_protocols_token_factory_pipes_verify_icon = require('./pipes/verify-icon.cjs');
|
|
7
7
|
const require_protocols_token_factory_pipes_verify_ownership = require('./pipes/verify-ownership.cjs');
|
|
8
8
|
const require_protocols_token_factory_pipes_verify_url = require('./pipes/verify-url.cjs');
|
|
9
|
+
let _ocap_state = require("@ocap/state");
|
|
9
10
|
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
10
11
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
11
|
-
let _ocap_state = require("@ocap/state");
|
|
12
12
|
let debug = require("debug");
|
|
13
13
|
debug = require_rolldown_runtime.__toESM(debug);
|
|
14
14
|
let _arcblock_validator = require("@arcblock/validator");
|
|
@@ -124,11 +124,13 @@ runner.use(async (context, next) => {
|
|
|
124
124
|
const tokenStateValue = tokenState;
|
|
125
125
|
const { tokens: senderTokens = {} } = senderStateValue;
|
|
126
126
|
const senderUpdates = senderChange ? require_util.applyTokenChange({ tokens: senderTokens }, senderChange) : { tokens: senderTokens };
|
|
127
|
-
const
|
|
127
|
+
const rawItx = tx?.itx || {};
|
|
128
|
+
const hasExplicitFeeRate = typeof rawItx.feeRate === "number" || rawItx.value && typeof rawItx.value === "object" && typeof rawItx.value.feeRate === "number" || !rawItx.typeUrl && !rawItx.type && typeof itx.feeRate === "number";
|
|
129
|
+
const factoryUpdates = Boolean(itx.feeRate) || itx.feeRate === 0 && (hasExplicitFeeRate || !itx.token && !itx.data) ? { feeRate: itx.feeRate } : {};
|
|
128
130
|
const tokenUpdates = itx.token ? {
|
|
129
|
-
icon: itx.token
|
|
130
|
-
website: itx.token
|
|
131
|
-
metadata: itx.token
|
|
131
|
+
icon: itx.token.icon || tokenStateValue.icon,
|
|
132
|
+
website: itx.token.website || tokenStateValue.website,
|
|
133
|
+
metadata: itx.token.metadata || tokenStateValue.metadata
|
|
132
134
|
} : null;
|
|
133
135
|
const [newSenderState, newTokenFactoryState, newTokenState, newDelegationState] = await Promise.all([
|
|
134
136
|
statedb.account.update(senderStateValue.address, _ocap_state.account.update(senderStateValue, {
|
|
@@ -3,10 +3,10 @@ const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
|
3
3
|
const require_util = require('../../util.cjs');
|
|
4
4
|
const require_pipes_ensure_cost = require('../../pipes/ensure-cost.cjs');
|
|
5
5
|
const require_pipes_ensure_gas = require('../../pipes/ensure-gas.cjs');
|
|
6
|
-
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
7
|
-
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
8
6
|
let _ocap_state = require("@ocap/state");
|
|
7
|
+
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
9
8
|
let _ocap_util = require("@ocap/util");
|
|
9
|
+
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
10
10
|
let debug = require("debug");
|
|
11
11
|
debug = require_rolldown_runtime.__toESM(debug);
|
|
12
12
|
let _ocap_message = require("@ocap/message");
|
|
@@ -98,7 +98,23 @@ runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
|
98
98
|
runner.use(_ocap_tx_pipeline.pipes.VerifyDelegation({
|
|
99
99
|
type: "signature",
|
|
100
100
|
signerKey: "senderState",
|
|
101
|
-
delegatorKey: "delegatorState"
|
|
101
|
+
delegatorKey: "delegatorState",
|
|
102
|
+
getRequirements: (ctx) => {
|
|
103
|
+
const context = ctx;
|
|
104
|
+
const tokens = context.senderTokens || [];
|
|
105
|
+
const assets = context.senderAssets || [];
|
|
106
|
+
const toAddresses = context.receiver ? [context.receiver] : [context.itx.to];
|
|
107
|
+
return [...tokens.map((x) => ({
|
|
108
|
+
type: "token",
|
|
109
|
+
address: x.address,
|
|
110
|
+
value: String(x.value),
|
|
111
|
+
to: toAddresses
|
|
112
|
+
})), ...assets.map((x) => ({
|
|
113
|
+
type: "asset",
|
|
114
|
+
address: x,
|
|
115
|
+
to: toAddresses
|
|
116
|
+
}))];
|
|
117
|
+
}
|
|
102
118
|
}));
|
|
103
119
|
runner.use(_ocap_tx_pipeline.pipes.ExtractSigner({
|
|
104
120
|
signerKey: "signerStates",
|
|
@@ -109,7 +125,22 @@ runner.use(_ocap_tx_pipeline.pipes.VerifyDelegation({
|
|
|
109
125
|
signerKey: "signerStates",
|
|
110
126
|
delegatorKey: "delegatorStates",
|
|
111
127
|
delegationKey: "delegationStates",
|
|
112
|
-
getRequirements: () =>
|
|
128
|
+
getRequirements: (ctx) => {
|
|
129
|
+
const context = ctx;
|
|
130
|
+
const tokens = context.receiverTokens || [];
|
|
131
|
+
const assets = context.receiverAssets || [];
|
|
132
|
+
const toAddresses = context.senderState ? [context.senderState.address] : [context.tx.from];
|
|
133
|
+
return [...tokens.map((x) => ({
|
|
134
|
+
type: "token",
|
|
135
|
+
address: x.address,
|
|
136
|
+
value: String(x.value),
|
|
137
|
+
to: toAddresses
|
|
138
|
+
})), ...assets.map((x) => ({
|
|
139
|
+
type: "asset",
|
|
140
|
+
address: x,
|
|
141
|
+
to: toAddresses
|
|
142
|
+
}))];
|
|
143
|
+
}
|
|
113
144
|
}));
|
|
114
145
|
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
115
146
|
from: "tokenAddress",
|
|
@@ -180,6 +211,21 @@ runner.use(_ocap_tx_pipeline.pipes.VerifyUpdater({
|
|
|
180
211
|
assetKey: "priv.receiverAssets",
|
|
181
212
|
ownerKey: "receiverState"
|
|
182
213
|
}));
|
|
214
|
+
runner.use(async (context, next) => {
|
|
215
|
+
const { senderAssets = [], receiverAssets = [], senderState, receiverState } = context;
|
|
216
|
+
const pendingOwners = {};
|
|
217
|
+
if (receiverState?.address) for (const addr of senderAssets) pendingOwners[addr] = receiverState.address;
|
|
218
|
+
if (senderState?.address) for (const addr of receiverAssets) pendingOwners[addr] = senderState.address;
|
|
219
|
+
if (senderAssets.length && receiverState?.address) {
|
|
220
|
+
const err = await (0, _ocap_tx_pipeline.verifyAssetHierarchy)(senderAssets, receiverState.address, context, pendingOwners);
|
|
221
|
+
if (err) return next(err);
|
|
222
|
+
}
|
|
223
|
+
if (receiverAssets.length && senderState?.address) {
|
|
224
|
+
const err = await (0, _ocap_tx_pipeline.verifyAssetHierarchy)(receiverAssets, senderState.address, context, pendingOwners);
|
|
225
|
+
if (err) return next(err);
|
|
226
|
+
}
|
|
227
|
+
return next();
|
|
228
|
+
});
|
|
183
229
|
runner.use(require_pipes_ensure_gas.default((context) => {
|
|
184
230
|
const ops = {
|
|
185
231
|
create: 0,
|
|
@@ -201,7 +247,7 @@ runner.use(_ocap_tx_pipeline.pipes.UpdateOwner({
|
|
|
201
247
|
}));
|
|
202
248
|
runner.use(_ocap_tx_pipeline.pipes.TakeStateSnapshot());
|
|
203
249
|
runner.use(async (context, next) => {
|
|
204
|
-
const { tx, itx, senderAssets = [], receiverAssets = [], senderTokens = [], receiverTokens = [], senderState, receiverState, senderChange, updateVaults, statedb } = context;
|
|
250
|
+
const { tx, itx, senderAssets = [], receiverAssets = [], senderTokens = [], receiverTokens = [], senderState, receiverState, senderChange, delegationState, delegationStates = [], updateVaults, statedb } = context;
|
|
205
251
|
const senderStateTokens = senderState?.tokens || {};
|
|
206
252
|
const receiverStateTokens = receiverState?.tokens || {};
|
|
207
253
|
for (const { address, value } of senderTokens) {
|
|
@@ -211,17 +257,29 @@ runner.use(async (context, next) => {
|
|
|
211
257
|
}
|
|
212
258
|
for (const { address, value } of receiverTokens) {
|
|
213
259
|
const delta = new _ocap_util.BN(value);
|
|
214
|
-
senderStateTokens[address] = new _ocap_util.BN(senderStateTokens[address]).add(delta).toString();
|
|
260
|
+
senderStateTokens[address] = new _ocap_util.BN(senderStateTokens[address] || "0").add(delta).toString();
|
|
215
261
|
receiverStateTokens[address] = new _ocap_util.BN(receiverStateTokens[address] || "0").sub(delta).toString();
|
|
216
262
|
}
|
|
217
263
|
const senderUpdates = senderChange ? require_util.applyTokenChange({ tokens: senderStateTokens }, senderChange) : { tokens: senderStateTokens };
|
|
218
|
-
const [
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
264
|
+
const [existingSenderState, existingReceiverState] = await Promise.all([statedb.account.get(senderState.address, context), statedb.account.get(receiverState.address, context)]);
|
|
265
|
+
const [newSenderState, newReceiverState, newDelegationState, newDelegationStates] = await Promise.all([
|
|
266
|
+
statedb.account.updateOrCreate(existingSenderState ?? null, _ocap_state.account.updateOrCreate(existingSenderState ?? null, {
|
|
267
|
+
address: senderState.address,
|
|
268
|
+
nonce: tx.nonce,
|
|
269
|
+
...senderUpdates
|
|
270
|
+
}, context), context),
|
|
271
|
+
statedb.account.updateOrCreate(existingReceiverState ?? null, _ocap_state.account.updateOrCreate(existingReceiverState ?? null, {
|
|
272
|
+
address: receiverState.address,
|
|
273
|
+
tokens: receiverStateTokens
|
|
274
|
+
}, context), context),
|
|
275
|
+
context.isDelegationChanged && delegationState ? statedb.delegation.update(delegationState.address, _ocap_state.delegation.update(delegationState, {}, context), context) : delegationState,
|
|
276
|
+
context.isDelegationChanged && delegationStates.length ? Promise.all(delegationStates.map((d) => statedb.delegation.update(d.address, _ocap_state.delegation.update(d, {}, context), context))) : delegationStates
|
|
277
|
+
]);
|
|
222
278
|
if (updateVaults) await updateVaults();
|
|
223
279
|
context.senderState = newSenderState;
|
|
224
280
|
context.receiverState = newReceiverState;
|
|
281
|
+
context.delegationState = newDelegationState;
|
|
282
|
+
context.delegationStates = newDelegationStates;
|
|
225
283
|
debug$1("exchange", {
|
|
226
284
|
from: tx.from,
|
|
227
285
|
to: itx.to,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IAssetState, IReadyContext, ITokenState, IWithDelegation, IWithDelegator, IWithReceiver, IWithSender, IWithSigners, TExchangeV2Tx } from "@ocap/types";
|
|
1
|
+
import { IAssetState, IDelegateState, IReadyContext, ITokenState, IWithDelegation, IWithDelegator, IWithReceiver, IWithSender, IWithSigners, TExchangeV2Tx } from "@ocap/types";
|
|
2
2
|
import { Runner } from "@ocap/tx-pipeline";
|
|
3
3
|
|
|
4
4
|
//#region src/protocols/trade/exchange-v2.d.ts
|
|
@@ -37,6 +37,8 @@ type Context = IReadyContext<TExchangeV2Tx> & IWithSender & IWithReceiver & Part
|
|
|
37
37
|
tokenStates?: ITokenState[];
|
|
38
38
|
/** Receiver address extracted from tx signatures or itx.to */
|
|
39
39
|
receiver?: string;
|
|
40
|
+
/** Multisig delegation states */
|
|
41
|
+
delegationStates?: IDelegateState[];
|
|
40
42
|
/** Private state for asset states */
|
|
41
43
|
priv?: {
|
|
42
44
|
senderAssets?: IAssetState[];
|
|
@@ -3,11 +3,11 @@ const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
|
3
3
|
const require_util = require('../../util.cjs');
|
|
4
4
|
const require_pipes_ensure_cost = require('../../pipes/ensure-cost.cjs');
|
|
5
5
|
const require_pipes_ensure_gas = require('../../pipes/ensure-gas.cjs');
|
|
6
|
+
let _ocap_state = require("@ocap/state");
|
|
6
7
|
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
8
|
+
let _ocap_util = require("@ocap/util");
|
|
7
9
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
8
10
|
let _arcblock_did_util = require("@arcblock/did-util");
|
|
9
|
-
let _ocap_state = require("@ocap/state");
|
|
10
|
-
let _ocap_util = require("@ocap/util");
|
|
11
11
|
let _ocap_message = require("@ocap/message");
|
|
12
12
|
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
13
13
|
let _arcblock_validator = require("@arcblock/validator");
|
|
@@ -39,33 +39,47 @@ runner.use((context, next) => {
|
|
|
39
39
|
context.tokenAddress = (context.tokens || []).map((x) => x.address);
|
|
40
40
|
next();
|
|
41
41
|
});
|
|
42
|
-
runner.use(_ocap_tx_pipeline.pipes.VerifyInfo([
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
42
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyInfo([
|
|
43
|
+
{
|
|
44
|
+
error: "INSUFFICIENT_DATA",
|
|
45
|
+
message: "Can not transfer without any primary token or assets or secondary tokens",
|
|
46
|
+
fn: (ctx) => {
|
|
47
|
+
const { itx, assets, tokens } = ctx;
|
|
48
|
+
if (itx.to && (itx.value || (0, lodash_isEmpty.default)(assets) === false || (0, lodash_isEmpty.default)(tokens) === false)) return true;
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
error: "INVALID_TX",
|
|
54
|
+
message: "Can not transfer primary token smaller than 0",
|
|
55
|
+
fn: (ctx) => {
|
|
56
|
+
const { itx, assets, tokens } = ctx;
|
|
57
|
+
if ((0, lodash_isEmpty.default)(tokens) && (0, lodash_isEmpty.default)(assets)) {
|
|
58
|
+
if (new _ocap_util.BN(itx.value ? (0, _ocap_message.decodeBigInt)(itx.value) : 0).lte(new _ocap_util.BN(0))) return false;
|
|
59
|
+
}
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
error: "INVALID_TX",
|
|
65
|
+
message: "Can not transfer duplicate tokens in itx.tokens",
|
|
66
|
+
fn: (ctx) => {
|
|
67
|
+
const addresses = (ctx.tokens || []).map((x) => x.address);
|
|
68
|
+
return new Set(addresses).size === addresses.length;
|
|
57
69
|
}
|
|
58
|
-
return true;
|
|
59
70
|
}
|
|
60
|
-
|
|
71
|
+
]));
|
|
61
72
|
runner.use(_ocap_tx_pipeline.pipes.VerifyListSize({ listKey: ["assets", "tokens"] }));
|
|
62
73
|
runner.use((context, next) => {
|
|
63
74
|
if (context.itx.value) {
|
|
64
75
|
const amount = new _ocap_util.BN((0, _ocap_message.decodeBigInt)(context.itx.value));
|
|
65
76
|
if (amount.gt(new _ocap_util.BN(0))) {
|
|
66
77
|
const tokens = context.tokens || [];
|
|
67
|
-
|
|
68
|
-
|
|
78
|
+
const primaryTokenAddress = context.config.token.address;
|
|
79
|
+
const existing = tokens.find((x) => x.address === primaryTokenAddress);
|
|
80
|
+
if (existing) existing.value = new _ocap_util.BN(existing.value).add(amount).toString();
|
|
81
|
+
else tokens.push({
|
|
82
|
+
address: primaryTokenAddress,
|
|
69
83
|
value: amount.toString()
|
|
70
84
|
});
|
|
71
85
|
context.tokens = tokens;
|
|
@@ -207,10 +221,12 @@ runner.use(async (context, next) => {
|
|
|
207
221
|
receiverTokens[token.address] = new _ocap_util.BN(receiverTokens[token.address] || "0").add(delta).toString();
|
|
208
222
|
}
|
|
209
223
|
const senderUpdates = senderChange ? require_util.applyTokenChange({ tokens: senderTokens }, senderChange) : { tokens: senderTokens };
|
|
224
|
+
const existingSenderState = await statedb.account.get(senderState.address, context);
|
|
210
225
|
const [newSenderState, newReceiverState, newDelegationState] = await Promise.all([
|
|
211
|
-
statedb.account.
|
|
226
|
+
statedb.account.updateOrCreate(existingSenderState ?? null, _ocap_state.account.updateOrCreate(existingSenderState ?? null, {
|
|
227
|
+
address: senderState.address,
|
|
212
228
|
nonce: tx.nonce,
|
|
213
|
-
pk: tx.pk,
|
|
229
|
+
pk: tx.delegator ? senderState.pk : tx.pk,
|
|
214
230
|
...senderUpdates
|
|
215
231
|
}, context), context),
|
|
216
232
|
statedb.account.updateOrCreate(receiverState ?? null, _ocap_state.account.updateOrCreate(receiverState ?? null, {
|
|
@@ -3,10 +3,10 @@ const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
|
3
3
|
const require_util = require('../../util.cjs');
|
|
4
4
|
const require_pipes_ensure_cost = require('../../pipes/ensure-cost.cjs');
|
|
5
5
|
const require_pipes_ensure_gas = require('../../pipes/ensure-gas.cjs');
|
|
6
|
-
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
7
|
-
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
8
6
|
let _ocap_state = require("@ocap/state");
|
|
7
|
+
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
9
8
|
let _ocap_util = require("@ocap/util");
|
|
9
|
+
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
10
10
|
let debug = require("debug");
|
|
11
11
|
debug = require_rolldown_runtime.__toESM(debug);
|
|
12
12
|
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
@@ -150,6 +150,69 @@ runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
|
150
150
|
stateKey: "senderState",
|
|
151
151
|
addressKey: "tx.from"
|
|
152
152
|
}));
|
|
153
|
+
const getTransferV3Requirements = (ctx, index, signature) => {
|
|
154
|
+
const { tx, inputs = [], outputs = [], receiverStates = [] } = ctx;
|
|
155
|
+
const signatures = (0, _ocap_util_lib_get_list_field.getListField)(tx, "signatures");
|
|
156
|
+
const targetOwner = signature?.signer || (typeof index === "number" ? signatures?.[index]?.signer : tx?.from);
|
|
157
|
+
if (!targetOwner) return [];
|
|
158
|
+
const input = inputs.find((x) => (0, _ocap_util.isSameDid)(x.owner, targetOwner));
|
|
159
|
+
if (!input) return [];
|
|
160
|
+
const tokensList = (0, _ocap_util_lib_get_list_field.getListField)(input, "tokens");
|
|
161
|
+
const assetsList = (0, _ocap_util_lib_get_list_field.getListField)(input, "assets");
|
|
162
|
+
const getReceiverAddresses = (owner) => {
|
|
163
|
+
if (!owner) return [];
|
|
164
|
+
const state = receiverStates.find((s) => (0, _ocap_util_lib_get_related_addr.getRelatedAddresses)(s).some((addr) => (0, _ocap_util.isSameDid)(addr, owner)));
|
|
165
|
+
return state ? (0, _ocap_util_lib_get_related_addr.getRelatedAddresses)(state) : [owner];
|
|
166
|
+
};
|
|
167
|
+
return [...tokensList.flatMap((t) => {
|
|
168
|
+
const tokenOutputs = outputs.filter((o) => (0, _ocap_util_lib_get_list_field.getListField)(o, "tokens").some((ot) => (0, _ocap_util.isSameDid)(ot.address, t.address)));
|
|
169
|
+
if (tokenOutputs.length === 0) return [{
|
|
170
|
+
type: "token",
|
|
171
|
+
address: t.address,
|
|
172
|
+
value: t.value,
|
|
173
|
+
to: []
|
|
174
|
+
}];
|
|
175
|
+
return tokenOutputs.map((o, i) => ({
|
|
176
|
+
type: "token",
|
|
177
|
+
address: t.address,
|
|
178
|
+
value: i === 0 ? t.value : "0",
|
|
179
|
+
to: getReceiverAddresses(o.owner)
|
|
180
|
+
}));
|
|
181
|
+
}), ...assetsList.map((a) => {
|
|
182
|
+
return {
|
|
183
|
+
type: "asset",
|
|
184
|
+
address: a,
|
|
185
|
+
to: getReceiverAddresses(outputs.find((o) => (0, _ocap_util_lib_get_list_field.getListField)(o, "assets").some((oa) => (0, _ocap_util.isSameDid)(oa, a)))?.owner)
|
|
186
|
+
};
|
|
187
|
+
})];
|
|
188
|
+
};
|
|
189
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
190
|
+
from: "tx.delegator",
|
|
191
|
+
to: "delegatorState",
|
|
192
|
+
status: "OK",
|
|
193
|
+
table: "account"
|
|
194
|
+
}));
|
|
195
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
196
|
+
stateKey: "delegatorState",
|
|
197
|
+
addressKey: "tx.delegator"
|
|
198
|
+
}));
|
|
199
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyDelegation({
|
|
200
|
+
type: "signature",
|
|
201
|
+
signerKey: "senderState",
|
|
202
|
+
delegatorKey: "delegatorState",
|
|
203
|
+
getRequirements: (ctx) => getTransferV3Requirements(ctx)
|
|
204
|
+
}));
|
|
205
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractSigner({
|
|
206
|
+
signerKey: "msSignerStates",
|
|
207
|
+
delegatorKey: "delegatorStates"
|
|
208
|
+
}));
|
|
209
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyDelegation({
|
|
210
|
+
type: "multisig",
|
|
211
|
+
signerKey: "msSignerStates",
|
|
212
|
+
delegatorKey: "delegatorStates",
|
|
213
|
+
delegationKey: "delegationStates",
|
|
214
|
+
getRequirements: (ctx, index, sig) => getTransferV3Requirements(ctx, index, sig)
|
|
215
|
+
}));
|
|
153
216
|
runner.use(_ocap_tx_pipeline.pipes.VerifyTokenBalance({
|
|
154
217
|
ownerKey: "signerStates",
|
|
155
218
|
conditionKey: "inputs"
|
|
@@ -157,7 +220,7 @@ runner.use(_ocap_tx_pipeline.pipes.VerifyTokenBalance({
|
|
|
157
220
|
runner.use(_ocap_tx_pipeline.pipes.verifyTokenAccess({
|
|
158
221
|
statesKey: "tokenStates",
|
|
159
222
|
listFieldKey: "spenders",
|
|
160
|
-
accountKeys: ["
|
|
223
|
+
accountKeys: ["signerStates"],
|
|
161
224
|
errorMessage: "Account {address} is not allowed to transfer token {tokenAddress}"
|
|
162
225
|
}));
|
|
163
226
|
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
@@ -168,7 +231,7 @@ runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
|
168
231
|
}));
|
|
169
232
|
runner.use(_ocap_tx_pipeline.pipes.VerifyTransferrable({ assets: "assetStates" }));
|
|
170
233
|
runner.use(async (context, next) => {
|
|
171
|
-
const { inputs = [], assetStates = [], signerStates = [] } = context;
|
|
234
|
+
const { inputs = [], outputs = [], assetStates = [], signerStates = [], receiverStates = [] } = context;
|
|
172
235
|
for (const input of inputs) {
|
|
173
236
|
const { owner } = input;
|
|
174
237
|
const assetsList = (0, _ocap_util_lib_get_list_field.getListField)(input, "assets");
|
|
@@ -183,6 +246,23 @@ runner.use(async (context, next) => {
|
|
|
183
246
|
return next(err);
|
|
184
247
|
}
|
|
185
248
|
}
|
|
249
|
+
const pendingOwners = {};
|
|
250
|
+
for (const output of outputs) {
|
|
251
|
+
const { owner } = output;
|
|
252
|
+
const assetsList = (0, _ocap_util_lib_get_list_field.getListField)(output, "assets");
|
|
253
|
+
if (assetsList.length) {
|
|
254
|
+
const ownerState = receiverStates.find((s) => (0, _ocap_util_lib_get_related_addr.getRelatedAddresses)(s).includes(owner)) || { address: owner };
|
|
255
|
+
for (const assetAddr of assetsList) pendingOwners[assetAddr] = ownerState.address;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
for (const output of outputs) {
|
|
259
|
+
const { owner } = output;
|
|
260
|
+
const assetsList = (0, _ocap_util_lib_get_list_field.getListField)(output, "assets");
|
|
261
|
+
if (assetsList.length) {
|
|
262
|
+
const err = await (0, _ocap_tx_pipeline.verifyAssetHierarchy)(assetsList, (receiverStates.find((s) => (0, _ocap_util_lib_get_related_addr.getRelatedAddresses)(s).includes(owner)) || { address: owner }).address, context, pendingOwners);
|
|
263
|
+
if (err) return next(err);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
186
266
|
return next();
|
|
187
267
|
});
|
|
188
268
|
runner.use(require_pipes_ensure_gas.default((context) => {
|
|
@@ -204,7 +284,7 @@ runner.use(require_pipes_ensure_gas.default((context) => {
|
|
|
204
284
|
runner.use(require_pipes_ensure_cost.default({ attachSenderChanges: true }));
|
|
205
285
|
runner.use(_ocap_tx_pipeline.pipes.TakeStateSnapshot());
|
|
206
286
|
runner.use(async (context, next) => {
|
|
207
|
-
const { tx, inputs = [], outputs = [], receivers = [], senderState, signerStates = [], senderChange, updateVaults, receiverStates = [], assetStates = [], statedb } = context;
|
|
287
|
+
const { tx, inputs = [], outputs = [], receivers = [], senderState, signerStates = [], senderChange, updateVaults, receiverStates = [], assetStates = [], delegationState, delegationStates = [], statedb } = context;
|
|
208
288
|
const signerUpdates = {};
|
|
209
289
|
inputs.forEach((x) => {
|
|
210
290
|
const { owner } = x;
|
|
@@ -236,13 +316,20 @@ runner.use(async (context, next) => {
|
|
|
236
316
|
isAlsoSigner,
|
|
237
317
|
isAlsoReceiver
|
|
238
318
|
});
|
|
239
|
-
const
|
|
240
|
-
|
|
319
|
+
const existingSenderState = senderState ? await statedb.account.get(senderState.address, context) : null;
|
|
320
|
+
const [newSenderState, newSignerStates, newReceiverStates, newAssetStates, newDelegationState, newDelegationStates] = await Promise.all([
|
|
321
|
+
statedb.account.updateOrCreate(existingSenderState ?? null, _ocap_state.account.updateOrCreate(existingSenderState ?? null, Object.assign({
|
|
241
322
|
address: sender,
|
|
242
323
|
nonce: tx.nonce,
|
|
243
|
-
pk: tx.pk
|
|
324
|
+
pk: tx.delegator ? senderState?.pk : tx.pk
|
|
244
325
|
}, signerUpdates[sender] || {}, receiverUpdates[sender] || {}, senderUpdatesLocal[sender] || {}), context), context),
|
|
245
|
-
Promise.all(signerStates.filter((x) => x.address !== sender).map((x) =>
|
|
326
|
+
Promise.all(signerStates.filter((x) => x.address !== sender).map(async (x) => {
|
|
327
|
+
const existing = await statedb.account.get(x.address, context);
|
|
328
|
+
return statedb.account.updateOrCreate(existing ?? null, _ocap_state.account.updateOrCreate(existing ?? null, {
|
|
329
|
+
address: x.address,
|
|
330
|
+
...signerUpdates[x.address]
|
|
331
|
+
}, context), context);
|
|
332
|
+
})),
|
|
246
333
|
Promise.all(receivers.filter((x) => x !== sender).map((x) => {
|
|
247
334
|
const receiverState = receiverStates.find((s) => (0, _ocap_util_lib_get_related_addr.getRelatedAddresses)(s).includes(x));
|
|
248
335
|
const owner = receiverState ? receiverState.address : x;
|
|
@@ -252,13 +339,17 @@ runner.use(async (context, next) => {
|
|
|
252
339
|
address: owner
|
|
253
340
|
}, context), context);
|
|
254
341
|
})),
|
|
255
|
-
Promise.all(assetStates.map((x) => statedb.asset.update(x.address, _ocap_state.asset.update(x, assetUpdates[x.address], context), context)))
|
|
342
|
+
Promise.all(assetStates.map((x) => statedb.asset.update(x.address, _ocap_state.asset.update(x, assetUpdates[x.address], context), context))),
|
|
343
|
+
context.isDelegationChanged && delegationState ? statedb.delegation.update(delegationState.address, _ocap_state.delegation.update(delegationState, {}, context), context) : delegationState,
|
|
344
|
+
context.isDelegationChanged && delegationStates.length ? Promise.all(delegationStates.map((x) => statedb.delegation.update(x.address, _ocap_state.delegation.update(x, {}, context), context))) : delegationStates
|
|
256
345
|
]);
|
|
257
346
|
if (updateVaults) await updateVaults();
|
|
258
347
|
context.senderState = newSenderState;
|
|
259
348
|
context.signerStates = isAlsoSigner ? newSignerStates.concat(newSenderState) : newSignerStates;
|
|
260
349
|
context.receiverStates = isAlsoReceiver ? newReceiverStates.concat(newSenderState) : newReceiverStates;
|
|
261
350
|
context.assetStates = newAssetStates;
|
|
351
|
+
context.delegationState = newDelegationState ?? void 0;
|
|
352
|
+
context.delegationStates = newDelegationStates;
|
|
262
353
|
debug$1("transfer-v3", {
|
|
263
354
|
inputs,
|
|
264
355
|
outputs
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IAssetState, IReadyContext, ITokenState, IWithReceivers, IWithSender, IWithSigners, TTransferV3Tx } from "@ocap/types";
|
|
1
|
+
import { IAccountState, IAssetState, IDelegateState, IReadyContext, ITokenState, IWithReceivers, IWithSender, IWithSigners, TTransferV3Tx } from "@ocap/types";
|
|
2
2
|
import { Runner } from "@ocap/tx-pipeline";
|
|
3
3
|
|
|
4
4
|
//#region src/protocols/trade/transfer-v3.d.ts
|
|
@@ -41,6 +41,16 @@ type Context = IReadyContext<TTransferV3Tx> & Partial<IWithSender> & Partial<IWi
|
|
|
41
41
|
tokenStates?: ITokenState[];
|
|
42
42
|
/** Asset states for transferred assets */
|
|
43
43
|
assetStates?: IAssetState[];
|
|
44
|
+
/** Delegator account state for tx.delegator */
|
|
45
|
+
delegatorState?: IAccountState;
|
|
46
|
+
/** Explicit delegation state for tx.delegator */
|
|
47
|
+
delegationState?: IDelegateState;
|
|
48
|
+
/** Signer states extracted from tx.signatures */
|
|
49
|
+
msSignerStates?: IAccountState[];
|
|
50
|
+
/** Delegator states extracted from tx.signatures */
|
|
51
|
+
delegatorStates?: (IAccountState | null)[];
|
|
52
|
+
/** Explicit delegation states for tx.signatures */
|
|
53
|
+
delegationStates?: IDelegateState[];
|
|
44
54
|
};
|
|
45
55
|
declare const runner: Runner<Context>;
|
|
46
56
|
//#endregion
|
package/lib/tx-timer.cjs
CHANGED
|
@@ -65,6 +65,19 @@ var TxTimer = class {
|
|
|
65
65
|
this.marks.push([label, Date.now()]);
|
|
66
66
|
}
|
|
67
67
|
/**
|
|
68
|
+
* Read-only view of all recorded mark intervals in order: `[label, durationMs][]`.
|
|
69
|
+
* Unlike `summary()`, repeated labels are preserved without overwriting earlier marks.
|
|
70
|
+
*/
|
|
71
|
+
durations() {
|
|
72
|
+
const out = [];
|
|
73
|
+
let prev = this.origin;
|
|
74
|
+
for (const [label, time] of this.marks) {
|
|
75
|
+
out.push([label, time - prev]);
|
|
76
|
+
prev = time;
|
|
77
|
+
}
|
|
78
|
+
return out;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
68
81
|
* Compute per-stage durations (ms) between consecutive marks.
|
|
69
82
|
*
|
|
70
83
|
* Legacy schema: flat object `{ [label]: ms, total: ms }`. If the same label
|
package/lib/tx-timer.d.cts
CHANGED
|
@@ -75,6 +75,11 @@ declare class TxTimer {
|
|
|
75
75
|
private queueState;
|
|
76
76
|
/** Record a named timestamp. */
|
|
77
77
|
mark(label: string): void;
|
|
78
|
+
/**
|
|
79
|
+
* Read-only view of all recorded mark intervals in order: `[label, durationMs][]`.
|
|
80
|
+
* Unlike `summary()`, repeated labels are preserved without overwriting earlier marks.
|
|
81
|
+
*/
|
|
82
|
+
durations(): ReadonlyArray<readonly [label: string, duration: number]>;
|
|
78
83
|
/**
|
|
79
84
|
* Compute per-stage durations (ms) between consecutive marks.
|
|
80
85
|
*
|
package/lib/util.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let _ocap_util = require("@ocap/util");
|
|
2
3
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
3
4
|
let _arcblock_did_util = require("@arcblock/did-util");
|
|
4
|
-
let _ocap_util = require("@ocap/util");
|
|
5
5
|
let _ocap_message = require("@ocap/message");
|
|
6
6
|
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
7
7
|
let lodash_cloneDeep = require("lodash/cloneDeep");
|
|
@@ -187,6 +187,7 @@ const ensureBlockReward = (rollupState, minReward, txStates) => {
|
|
|
187
187
|
if (actualFee.isNeg()) throw new _ocap_util_lib_error.CustomError("NEGATIVE_ACTUAL_FEE", "Got negative actualFee for tx, abort!");
|
|
188
188
|
if (actualFee.lt(defaults.reward)) actualFee = defaults.reward;
|
|
189
189
|
if (actualFee.lt(minTxFee)) actualFee = minTxFee;
|
|
190
|
+
if (actualFee.gt(maxFee)) actualFee = maxFee;
|
|
190
191
|
if (actualFee.lt(maxFee)) {
|
|
191
192
|
const refundFee = maxFee.sub(actualFee).toString(10);
|
|
192
193
|
changes.account.push({
|