@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
|
@@ -5,28 +5,22 @@ 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_signers = require('../rollup/pipes/verify-signers.cjs');
|
|
7
7
|
const require_protocols_rollup_pipes_verify_status = require('../rollup/pipes/verify-status.cjs');
|
|
8
|
+
let _arcblock_did_util = require("@arcblock/did-util");
|
|
8
9
|
let _ocap_state = require("@ocap/state");
|
|
9
10
|
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
10
11
|
let _ocap_util = require("@ocap/util");
|
|
11
12
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
12
|
-
let
|
|
13
|
+
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
13
14
|
let debug = require("debug");
|
|
14
15
|
debug = require_rolldown_runtime.__toESM(debug);
|
|
15
|
-
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
16
16
|
let _arcblock_validator = require("@arcblock/validator");
|
|
17
17
|
|
|
18
18
|
//#region src/protocols/token/deposit-v2.ts
|
|
19
19
|
const debug$1 = (0, debug.default)("@ocap/tx-protocols:deposit-token");
|
|
20
20
|
const schema = _arcblock_validator.v.pipe(_arcblock_validator.v.object({
|
|
21
21
|
token: _arcblock_validator.schemas.tokenInput,
|
|
22
|
-
to: (0, _arcblock_validator.vDID)({
|
|
23
|
-
|
|
24
|
-
wallet: "ethereum"
|
|
25
|
-
}),
|
|
26
|
-
proposer: (0, _arcblock_validator.vDID)({
|
|
27
|
-
prefix: true,
|
|
28
|
-
wallet: "ethereum"
|
|
29
|
-
}),
|
|
22
|
+
to: (0, _arcblock_validator.vDID)({ prefix: true }),
|
|
23
|
+
proposer: (0, _arcblock_validator.vDID)({ prefix: true }),
|
|
30
24
|
evidence: _arcblock_validator.v.object({ hash: _arcblock_validator.v.pipe(_arcblock_validator.v.string(), _arcblock_validator.v.regex(_arcblock_validator.patterns.txHash)) }),
|
|
31
25
|
rollup: (0, _arcblock_validator.vDID)({
|
|
32
26
|
prefix: true,
|
|
@@ -36,13 +30,9 @@ const schema = _arcblock_validator.v.pipe(_arcblock_validator.v.object({
|
|
|
36
30
|
data: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_arcblock_validator.v.any()))
|
|
37
31
|
}), (0, _arcblock_validator.vStripUnknown)());
|
|
38
32
|
const runner = new _ocap_tx_pipeline.Runner("deposit_token_v2");
|
|
39
|
-
runner.use(({
|
|
33
|
+
runner.use(({ itx }, next) => {
|
|
40
34
|
const { error } = (0, _arcblock_validator.vValidate)(schema, itx);
|
|
41
35
|
if (error) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
|
|
42
|
-
if (itx.to !== tx.from) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "You can only deposit to tx sender account"));
|
|
43
|
-
const signatures = (0, _ocap_util_lib_get_list_field.getListField)(tx, "signatures");
|
|
44
|
-
if (signatures.some((x) => x.signer === itx.proposer) === false) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "itx.proposer must exist in signatures"));
|
|
45
|
-
if (signatures.some((x) => x.signer === tx.from)) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "tx.from should not exist in signatures"));
|
|
46
36
|
return next();
|
|
47
37
|
});
|
|
48
38
|
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
@@ -51,10 +41,31 @@ runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
|
51
41
|
status: "INVALID_ROLLUP",
|
|
52
42
|
table: "rollup"
|
|
53
43
|
}));
|
|
44
|
+
runner.use((context, next) => {
|
|
45
|
+
const { tx, itx, rollupState } = context;
|
|
46
|
+
if (_ocap_state.rollup.getRollupTargetType(rollupState) === "EVM") {
|
|
47
|
+
if ((0, _arcblock_validator.vValidate)((0, _arcblock_validator.vDID)({
|
|
48
|
+
prefix: true,
|
|
49
|
+
wallet: "ethereum"
|
|
50
|
+
}), itx.to).error) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "Invalid itx: \"to\" Expected wallet type to be \"ethereum\""));
|
|
51
|
+
if ((0, _arcblock_validator.vValidate)((0, _arcblock_validator.vDID)({
|
|
52
|
+
prefix: true,
|
|
53
|
+
wallet: "ethereum"
|
|
54
|
+
}), itx.proposer).error) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "Invalid itx: \"proposer\" Expected wallet type to be \"ethereum\""));
|
|
55
|
+
}
|
|
56
|
+
const isProposerSponsor = _ocap_state.rollup.isProposerSponsoredDepositAllowed(rollupState) && tx.from === itx.proposer && itx.to !== tx.from;
|
|
57
|
+
context.isProposerSponsor = isProposerSponsor;
|
|
58
|
+
if (itx.to !== tx.from && !isProposerSponsor) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "You can only deposit to tx sender account"));
|
|
59
|
+
const signatures = (0, _ocap_util_lib_get_list_field.getListField)(tx, "signatures");
|
|
60
|
+
if (signatures.some((x) => x.signer === itx.proposer) === false) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "itx.proposer must exist in signatures"));
|
|
61
|
+
if (!isProposerSponsor && signatures.some((x) => x.signer === tx.from)) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "tx.from should not exist in signatures"));
|
|
62
|
+
if (isProposerSponsor && signatures.some((x) => x.signer === itx.to)) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "itx.to should not exist in signatures"));
|
|
63
|
+
return next();
|
|
64
|
+
});
|
|
54
65
|
runner.use(require_protocols_rollup_pipes_verify_status.default({ paused: false }));
|
|
55
66
|
runner.use((context, next) => {
|
|
56
67
|
const { itx, rollupState } = context;
|
|
57
|
-
if (rollupState
|
|
68
|
+
if (!_ocap_state.rollup.isTokenSupportedByRollup(rollupState, itx.token.address)) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "Deposit token address does not match with rollup state"));
|
|
58
69
|
if (rollupState.validators.some((x) => x.address === itx.proposer) === false) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "itx.proposer does not exist in validators"));
|
|
59
70
|
return next();
|
|
60
71
|
});
|
|
@@ -105,7 +116,7 @@ runner.use((context, next) => {
|
|
|
105
116
|
const maxDepositAmount = new _ocap_util.BN(rollupState.maxDepositAmount);
|
|
106
117
|
if (depositAmount.lt(minDepositAmount)) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Deposit amount must be greater than minDepositAmount: ${(0, _ocap_util.fromUnitToToken)(minDepositAmount, tokenState.decimal)}`));
|
|
107
118
|
if (depositAmount.gt(maxDepositAmount)) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Deposit amount must be less than maxDepositAmount: ${(0, _ocap_util.fromUnitToToken)(maxDepositAmount, tokenState.decimal)}`));
|
|
108
|
-
const stakedAmount = new _ocap_util.BN(stakeState.tokens[
|
|
119
|
+
const stakedAmount = new _ocap_util.BN(stakeState.tokens[itx.token.address] || 0);
|
|
109
120
|
if (depositAmount.gt(stakedAmount)) return next(new _ocap_util_lib_error.CustomError("INSUFFICIENT_STAKE", `Deposit amount must be less than available stake: ${(0, _ocap_util.fromUnitToToken)(stakedAmount, tokenState.decimal)}`));
|
|
110
121
|
return next();
|
|
111
122
|
});
|
|
@@ -127,6 +138,13 @@ runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
|
127
138
|
status: "OK",
|
|
128
139
|
table: "account"
|
|
129
140
|
}));
|
|
141
|
+
runner.use(async (context, next) => {
|
|
142
|
+
if (context.isProposerSponsor) {
|
|
143
|
+
context.receiverState = await context.statedb.account.get(context.itx.to, context);
|
|
144
|
+
if (context.receiverState && (context.receiverState.address !== context.itx.to || _ocap_state.account.isMigrated(context.receiverState))) return next(new _ocap_util_lib_error.CustomError("ACCOUNT_MIGRATED", `Recipient account is already migrated: ${context.itx.to}`));
|
|
145
|
+
}
|
|
146
|
+
return next();
|
|
147
|
+
});
|
|
130
148
|
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
131
149
|
from: "signers",
|
|
132
150
|
to: "signerStates",
|
|
@@ -138,6 +156,11 @@ runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
|
138
156
|
stateKey: "senderState",
|
|
139
157
|
addressKey: "tx.from"
|
|
140
158
|
}));
|
|
159
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyBlocked({ stateKeys: [
|
|
160
|
+
"senderState",
|
|
161
|
+
"receiverState",
|
|
162
|
+
"signerStates"
|
|
163
|
+
] }));
|
|
141
164
|
runner.use(require_pipes_ensure_gas.default((context) => {
|
|
142
165
|
const result = {
|
|
143
166
|
create: 1,
|
|
@@ -146,6 +169,8 @@ runner.use(require_pipes_ensure_gas.default((context) => {
|
|
|
146
169
|
};
|
|
147
170
|
if (context.senderState) result.update += 1;
|
|
148
171
|
else result.create += 1;
|
|
172
|
+
if (context.isProposerSponsor) if (context.receiverState) result.update += 1;
|
|
173
|
+
else result.create += 1;
|
|
149
174
|
if (context.lockerState) result.update += 1;
|
|
150
175
|
else result.create += 1;
|
|
151
176
|
return result;
|
|
@@ -153,7 +178,7 @@ runner.use(require_pipes_ensure_gas.default((context) => {
|
|
|
153
178
|
runner.use(require_pipes_ensure_cost.default({ attachSenderChanges: true }));
|
|
154
179
|
runner.use(_ocap_tx_pipeline.pipes.TakeStateSnapshot());
|
|
155
180
|
runner.use(async (context, next) => {
|
|
156
|
-
const { tx, itx, statedb, senderState, stakeState, stakeAddress, lockerState, lockerAddress, senderChange, updateVaults } = context;
|
|
181
|
+
const { tx, itx, statedb, rollupState, senderState, receiverState, isProposerSponsor, stakeState, stakeAddress, lockerState, lockerAddress, senderChange, updateVaults } = context;
|
|
157
182
|
const user = itx.token.value;
|
|
158
183
|
const fee = itx.actualFee;
|
|
159
184
|
const total = require_util.getBNSum(user, fee);
|
|
@@ -161,23 +186,43 @@ runner.use(async (context, next) => {
|
|
|
161
186
|
address: itx.token.address,
|
|
162
187
|
value: total
|
|
163
188
|
}], stakeState, "sub");
|
|
164
|
-
let senderUpdates = require_util.applyTokenUpdates([{
|
|
165
|
-
address: itx.token.address,
|
|
166
|
-
value: user
|
|
167
|
-
}], senderState || {}, "add");
|
|
168
189
|
const lockerUpdates = require_util.applyTokenUpdates([{
|
|
169
190
|
address: itx.token.address,
|
|
170
191
|
value: fee
|
|
171
192
|
}], lockerState || { tokens: {} }, "add");
|
|
172
|
-
if (senderChange && senderState) senderUpdates = require_util.applyTokenChange(senderUpdates, senderChange);
|
|
173
193
|
const sender = senderState ? senderState.address : tx.from;
|
|
174
|
-
|
|
175
|
-
|
|
194
|
+
let newSenderState;
|
|
195
|
+
let newReceiverState;
|
|
196
|
+
if (isProposerSponsor) {
|
|
197
|
+
let proposerUpdates = {};
|
|
198
|
+
if (senderChange && senderState) proposerUpdates = require_util.applyTokenChange(senderState, senderChange);
|
|
199
|
+
const recipientUpdates = require_util.applyTokenUpdates([{
|
|
200
|
+
address: itx.token.address,
|
|
201
|
+
value: user
|
|
202
|
+
}], receiverState || {}, "add");
|
|
203
|
+
[newSenderState, newReceiverState] = await Promise.all([statedb.account.updateOrCreate(senderState ?? null, _ocap_state.account.updateOrCreate(senderState ?? null, {
|
|
204
|
+
address: sender,
|
|
205
|
+
nonce: tx.nonce,
|
|
206
|
+
pk: tx.pk,
|
|
207
|
+
...proposerUpdates
|
|
208
|
+
}, context), context), statedb.account.updateOrCreate(receiverState ?? null, _ocap_state.account.updateOrCreate(receiverState ?? null, {
|
|
209
|
+
address: itx.to,
|
|
210
|
+
...recipientUpdates
|
|
211
|
+
}, context), context)]);
|
|
212
|
+
} else {
|
|
213
|
+
let senderUpdates = require_util.applyTokenUpdates([{
|
|
214
|
+
address: itx.token.address,
|
|
215
|
+
value: user
|
|
216
|
+
}], senderState || {}, "add");
|
|
217
|
+
if (senderChange && senderState) senderUpdates = require_util.applyTokenChange(senderUpdates, senderChange);
|
|
218
|
+
newSenderState = await statedb.account.updateOrCreate(senderState ?? null, _ocap_state.account.updateOrCreate(senderState ?? null, {
|
|
176
219
|
address: sender,
|
|
177
220
|
nonce: tx.nonce,
|
|
178
221
|
pk: tx.pk,
|
|
179
222
|
...senderUpdates
|
|
180
|
-
}, context), context)
|
|
223
|
+
}, context), context);
|
|
224
|
+
}
|
|
225
|
+
const [newStakeState, newLockerState, evidenceState, newRollupState] = await Promise.all([
|
|
181
226
|
statedb.stake.update(stakeAddress, _ocap_state.stake.update(stakeState, stakeUpdates, context), context),
|
|
182
227
|
lockerState ? statedb.stake.update(lockerState.address, _ocap_state.stake.update(lockerState, lockerUpdates, context), context) : statedb.stake.create(lockerAddress, _ocap_state.stake.create({
|
|
183
228
|
address: lockerAddress,
|
|
@@ -191,13 +236,20 @@ runner.use(async (context, next) => {
|
|
|
191
236
|
statedb.evidence.create(itx.evidence.hash, _ocap_state.evidence.create({
|
|
192
237
|
hash: itx.evidence.hash,
|
|
193
238
|
data: "rollup-deposit"
|
|
194
|
-
}, context), context)
|
|
239
|
+
}, context), context),
|
|
240
|
+
_ocap_state.rollup.hasRollupReserveTracking(rollupState) ? statedb.rollup.update(itx.rollup, _ocap_state.rollup.recordRollupDeposit(rollupState, itx.token.address, itx.token.value, context), context) : Promise.resolve(rollupState)
|
|
195
241
|
]);
|
|
196
242
|
if (updateVaults) await updateVaults();
|
|
197
243
|
context.senderState = newSenderState;
|
|
244
|
+
if (isProposerSponsor && newReceiverState) {
|
|
245
|
+
context.receiverState = newReceiverState;
|
|
246
|
+
context.signerStates = (context.signerStates || []).map((s) => s.address === newSenderState.address ? newSenderState : s);
|
|
247
|
+
}
|
|
248
|
+
context.rollupState = newRollupState;
|
|
198
249
|
context.stakeState = newStakeState;
|
|
199
250
|
context.evidenceState = evidenceState;
|
|
200
251
|
context.stakeStates = [newStakeState, newLockerState];
|
|
252
|
+
const recipientAddress = isProposerSponsor ? itx.to : sender;
|
|
201
253
|
context.updatedAccounts = context.updatedAccounts || [];
|
|
202
254
|
context.updatedAccounts.push({
|
|
203
255
|
address: stakeAddress,
|
|
@@ -205,7 +257,7 @@ runner.use(async (context, next) => {
|
|
|
205
257
|
delta: `-${total}`,
|
|
206
258
|
action: "unlock"
|
|
207
259
|
}, {
|
|
208
|
-
address:
|
|
260
|
+
address: recipientAddress,
|
|
209
261
|
token: itx.token.address,
|
|
210
262
|
delta: user,
|
|
211
263
|
action: "unlock"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IReadyContext, IStakeState, IWithEvidence, IWithRollup, IWithSender, IWithSigners, IWithStake, IWithToken, TDepositTokenV2Tx } from "@ocap/types";
|
|
1
|
+
import { IAccountState, IReadyContext, IStakeState, IWithEvidence, IWithRollup, IWithSender, IWithSigners, IWithStake, IWithToken, TDepositTokenV2Tx } from "@ocap/types";
|
|
2
2
|
import { Runner } from "@ocap/tx-pipeline";
|
|
3
3
|
|
|
4
4
|
//#region src/protocols/token/deposit-v2.d.ts
|
|
@@ -21,6 +21,10 @@ type Context = IReadyContext<TDepositTokenV2Tx> & Partial<IWithSender> & Partial
|
|
|
21
21
|
lockerAddress?: string;
|
|
22
22
|
/** Locker stake state */
|
|
23
23
|
lockerState?: IStakeState;
|
|
24
|
+
/** Recipient account state when proposer-sponsored (itx.to !== tx.from) */
|
|
25
|
+
receiverState?: IAccountState | null;
|
|
26
|
+
/** Whether deposit is submitted by proposer on behalf of itx.to */
|
|
27
|
+
isProposerSponsor?: boolean;
|
|
24
28
|
/** Signer addresses */
|
|
25
29
|
signers?: string[];
|
|
26
30
|
/** All updated stake states */
|
|
@@ -4,14 +4,14 @@ 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 _arcblock_did_util = require("@arcblock/did-util");
|
|
7
8
|
let _ocap_state = require("@ocap/state");
|
|
8
9
|
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
9
10
|
let _ocap_util = require("@ocap/util");
|
|
10
11
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
11
|
-
let
|
|
12
|
+
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
12
13
|
let debug = require("debug");
|
|
13
14
|
debug = require_rolldown_runtime.__toESM(debug);
|
|
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
|
|
|
17
17
|
//#region src/protocols/token/withdraw-v2.ts
|
|
@@ -19,27 +19,20 @@ const debug$1 = (0, debug.default)("@ocap/tx-protocols:withdraw-token");
|
|
|
19
19
|
const verifyMultiSigV2 = _ocap_tx_pipeline.pipes.VerifyMultiSigV2({ signersKey: "signers" });
|
|
20
20
|
const schema = _arcblock_validator.v.pipe(_arcblock_validator.v.object({
|
|
21
21
|
token: _arcblock_validator.schemas.tokenInput,
|
|
22
|
-
to: (0, _arcblock_validator.vDID)({
|
|
23
|
-
prefix: true,
|
|
24
|
-
wallet: "ethereum"
|
|
25
|
-
}),
|
|
22
|
+
to: (0, _arcblock_validator.vDID)({ prefix: true }),
|
|
26
23
|
rollup: (0, _arcblock_validator.vDID)({
|
|
27
24
|
prefix: true,
|
|
28
25
|
role: "ROLE_ROLLUP"
|
|
29
26
|
}),
|
|
30
|
-
proposer: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_arcblock_validator.v.union([_arcblock_validator.v.literal(""), (0, _arcblock_validator.vDID)({
|
|
31
|
-
prefix: true,
|
|
32
|
-
wallet: "ethereum"
|
|
33
|
-
})])), ""),
|
|
27
|
+
proposer: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_arcblock_validator.v.union([_arcblock_validator.v.literal(""), (0, _arcblock_validator.vDID)({ prefix: true })])), ""),
|
|
34
28
|
actualFee: (0, _arcblock_validator.vBN)((0, _arcblock_validator.vBNMin)(0)),
|
|
35
29
|
maxFee: (0, _arcblock_validator.vBN)((0, _arcblock_validator.vBNMin)(0)),
|
|
36
30
|
data: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_arcblock_validator.v.any()))
|
|
37
31
|
}), (0, _arcblock_validator.vStripUnknown)());
|
|
38
32
|
const runner = new _ocap_tx_pipeline.Runner("withdraw_token_v2");
|
|
39
|
-
runner.use(({
|
|
33
|
+
runner.use(({ itx }, next) => {
|
|
40
34
|
const { error } = (0, _arcblock_validator.vValidate)(schema, itx);
|
|
41
35
|
if (error) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
|
|
42
|
-
if (itx.to !== tx.from) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "You can only withdraw to tx sender account"));
|
|
43
36
|
return next();
|
|
44
37
|
});
|
|
45
38
|
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
@@ -48,10 +41,31 @@ runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
|
48
41
|
status: "INVALID_ROLLUP",
|
|
49
42
|
table: "rollup"
|
|
50
43
|
}));
|
|
44
|
+
runner.use((context, next) => {
|
|
45
|
+
const { tx, itx, rollupState } = context;
|
|
46
|
+
if (_ocap_state.rollup.getRollupTargetType(rollupState) === "EVM") {
|
|
47
|
+
if ((0, _arcblock_validator.vValidate)((0, _arcblock_validator.vDID)({
|
|
48
|
+
prefix: true,
|
|
49
|
+
wallet: "ethereum"
|
|
50
|
+
}), itx.to).error) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "Invalid itx: \"to\" Expected wallet type to be \"ethereum\""));
|
|
51
|
+
if (itx.proposer && (0, _arcblock_validator.vValidate)((0, _arcblock_validator.vDID)({
|
|
52
|
+
prefix: true,
|
|
53
|
+
wallet: "ethereum"
|
|
54
|
+
}), itx.proposer).error) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "Invalid itx: \"proposer\" Expected wallet type to be \"ethereum\""));
|
|
55
|
+
}
|
|
56
|
+
if (itx.to !== tx.from) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "You can only withdraw to tx sender account"));
|
|
57
|
+
return next();
|
|
58
|
+
});
|
|
51
59
|
runner.use(require_protocols_rollup_pipes_verify_status.default({ paused: false }));
|
|
52
60
|
runner.use((context, next) => {
|
|
53
61
|
const { itx, rollupState } = context;
|
|
54
|
-
if (rollupState
|
|
62
|
+
if (!_ocap_state.rollup.isTokenSupportedByRollup(rollupState, itx.token.address)) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "Withdraw token address does not match with rollup"));
|
|
63
|
+
if (_ocap_state.rollup.hasRollupReserveTracking(rollupState)) {
|
|
64
|
+
const reserve = _ocap_state.rollup.getRollupTokenReserve(rollupState, itx.token.address);
|
|
65
|
+
const nextWithdrawn = new _ocap_util.BN(reserve.totalWithdrawn).add(new _ocap_util.BN(itx.token.value));
|
|
66
|
+
const totalDeposited = new _ocap_util.BN(reserve.totalDeposited);
|
|
67
|
+
if (nextWithdrawn.gt(totalDeposited)) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Withdraw amount (${itx.token.value}) exceeds rollup net inflow reserve watermark: cumulativeWithdrawn (${nextWithdrawn.toString(10)}) > cumulativeDeposited (${totalDeposited.toString(10)})`));
|
|
68
|
+
}
|
|
55
69
|
return next();
|
|
56
70
|
});
|
|
57
71
|
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
@@ -125,6 +139,7 @@ runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
|
125
139
|
stateKey: "senderState",
|
|
126
140
|
addressKey: "tx.from"
|
|
127
141
|
}));
|
|
142
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyBlocked({ stateKeys: ["senderState", "signerStates"] }));
|
|
128
143
|
runner.use((context, next) => {
|
|
129
144
|
const { itx, senderState } = context;
|
|
130
145
|
context.stakeAddress = (0, _arcblock_did_util.toStakeAddress)(senderState.address, itx.rollup);
|
|
@@ -179,7 +194,7 @@ runner.use(async (context, next) => {
|
|
|
179
194
|
address: itx.token.address,
|
|
180
195
|
value: fee
|
|
181
196
|
}], lockerState || { tokens: {} }, "add");
|
|
182
|
-
const [newSenderState, newStakeState, newLockerState] = await Promise.all([
|
|
197
|
+
const [newSenderState, newStakeState, newLockerState, newRollupState] = await Promise.all([
|
|
183
198
|
statedb.account.update(senderState.address, _ocap_state.account.update(senderState, {
|
|
184
199
|
nonce: tx.nonce,
|
|
185
200
|
...senderUpdates
|
|
@@ -201,10 +216,12 @@ runner.use(async (context, next) => {
|
|
|
201
216
|
message: "pending-block-reward",
|
|
202
217
|
revokeWaitingPeriod: 0,
|
|
203
218
|
...lockerUpdates
|
|
204
|
-
}, context), context)
|
|
219
|
+
}, context), context),
|
|
220
|
+
_ocap_state.rollup.hasRollupReserveTracking(context.rollupState) ? statedb.rollup.update(itx.rollup, _ocap_state.rollup.recordRollupWithdraw(context.rollupState, itx.token.address, itx.token.value, context), context) : Promise.resolve(context.rollupState)
|
|
205
221
|
]);
|
|
206
222
|
if (updateVaults) await updateVaults();
|
|
207
223
|
context.senderState = newSenderState;
|
|
224
|
+
context.rollupState = newRollupState;
|
|
208
225
|
context.stakeState = newStakeState;
|
|
209
226
|
context.lockerState = newLockerState;
|
|
210
227
|
context.stakeStates = [newStakeState, newLockerState];
|
|
@@ -8,10 +8,12 @@ let _ocap_state = require("@ocap/state");
|
|
|
8
8
|
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
9
9
|
let _ocap_util = require("@ocap/util");
|
|
10
10
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
11
|
+
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
12
|
+
let _ocap_util_lib_get_related_addr = require("@ocap/util/lib/get-related-addr");
|
|
11
13
|
let lodash_pick = require("lodash/pick");
|
|
12
14
|
lodash_pick = require_rolldown_runtime.__toESM(lodash_pick);
|
|
13
|
-
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
14
15
|
let _arcblock_validator = require("@arcblock/validator");
|
|
16
|
+
let _ocap_util_lib_curve = require("@ocap/util/lib/curve");
|
|
15
17
|
|
|
16
18
|
//#region src/protocols/token-factory/burn.ts
|
|
17
19
|
const runner = new _ocap_tx_pipeline.Runner("burn_token");
|
|
@@ -36,6 +38,11 @@ runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
|
36
38
|
status: "INVALID_TOKEN_FACTORY",
|
|
37
39
|
table: "tokenFactory"
|
|
38
40
|
}));
|
|
41
|
+
runner.use((context, next) => {
|
|
42
|
+
const { tokenFactoryState } = context;
|
|
43
|
+
if (tokenFactoryState?.status && tokenFactoryState.status !== "ACTIVE") return next(new _ocap_util_lib_error.CustomError("INVALID_TOKEN_FACTORY", `Token factory is ${tokenFactoryState.status} and cannot burn tokens`));
|
|
44
|
+
return next();
|
|
45
|
+
});
|
|
39
46
|
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
40
47
|
from: "tokenFactoryState.tokenAddress",
|
|
41
48
|
to: "tokenState",
|
|
@@ -96,7 +103,11 @@ runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
|
96
103
|
stateKey: "receiverState",
|
|
97
104
|
addressKey: "itx.receiver"
|
|
98
105
|
}));
|
|
99
|
-
runner.use(_ocap_tx_pipeline.pipes.VerifyBlocked({ stateKeys: [
|
|
106
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyBlocked({ stateKeys: [
|
|
107
|
+
"senderState",
|
|
108
|
+
"signerStates",
|
|
109
|
+
"receiverState"
|
|
110
|
+
] }));
|
|
100
111
|
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
101
112
|
from: "tokenFactoryState.owner",
|
|
102
113
|
to: "ownerState",
|
|
@@ -109,6 +120,15 @@ runner.use(_ocap_tx_pipeline.pipes.verifyTokenAccess({
|
|
|
109
120
|
accountKeys: ["senderState"],
|
|
110
121
|
errorMessage: "Account {address} is not allowed to burn token {tokenAddress}"
|
|
111
122
|
}));
|
|
123
|
+
runner.use((context, next) => {
|
|
124
|
+
const { tokenFactoryState, tokenState, senderState, ownerState, tx } = context;
|
|
125
|
+
if (!tokenFactoryState?.curve && (!tokenState?.minters || tokenState.minters.length === 0)) {
|
|
126
|
+
const senderAddrs = senderState ? (0, _ocap_util_lib_get_related_addr.getRelatedAddresses)(senderState) : [tx.from];
|
|
127
|
+
const ownerAddrs = ownerState ? (0, _ocap_util_lib_get_related_addr.getRelatedAddresses)(ownerState) : [tokenFactoryState.owner];
|
|
128
|
+
if (!senderAddrs.some((s) => ownerAddrs.some((o) => (0, _ocap_util.isSameDid)(s, o)))) return next(new _ocap_util_lib_error.CustomError("FORBIDDEN", `verify-token-access: Account ${senderState?.address || tx.from} is not allowed to burn token ${tokenState.address}`, { persist: true }));
|
|
129
|
+
}
|
|
130
|
+
return next();
|
|
131
|
+
});
|
|
112
132
|
runner.use((context, next) => {
|
|
113
133
|
const { inputs = [], tokenFactoryState } = context;
|
|
114
134
|
let amount = new _ocap_util.BN("0");
|
|
@@ -128,6 +148,18 @@ runner.use(require_protocols_token_factory_pipes_calc_reserve.default({
|
|
|
128
148
|
amountKey: "burnAmount",
|
|
129
149
|
direction: "burn"
|
|
130
150
|
}), { shouldSkip: (ctx) => !ctx.tokenFactoryState?.curve });
|
|
151
|
+
runner.use((context, next) => {
|
|
152
|
+
const { tokenFactoryState, burnAmount = "0", reserveAmount = "0" } = context;
|
|
153
|
+
const reserveBalance = new _ocap_util.BN(tokenFactoryState.reserveBalance || "0");
|
|
154
|
+
if (new _ocap_util.BN(burnAmount).eq(new _ocap_util.BN(tokenFactoryState.currentSupply)) && new _ocap_util.BN(reserveAmount).gt(reserveBalance)) {
|
|
155
|
+
context.reserveAmount = reserveBalance.toString(10);
|
|
156
|
+
context.reserveFee = (0, _ocap_util_lib_curve.calcFee)({
|
|
157
|
+
reserveAmount: context.reserveAmount,
|
|
158
|
+
feeRate: String(tokenFactoryState.feeRate)
|
|
159
|
+
})?.toString();
|
|
160
|
+
}
|
|
161
|
+
return next();
|
|
162
|
+
}, { shouldSkip: (ctx) => !ctx.tokenFactoryState?.curve });
|
|
131
163
|
runner.use((context, next) => {
|
|
132
164
|
const { reserveAmount = "0", reserveFee } = context;
|
|
133
165
|
const { minReserve } = context.itx;
|
|
@@ -195,6 +227,7 @@ runner.use(async (context, next) => {
|
|
|
195
227
|
delta: new _ocap_util.BN(reserveAmount).sub(new _ocap_util.BN(reserveFee || "0")).toString()
|
|
196
228
|
});
|
|
197
229
|
if (senderChange) accountUpdates[senderChange.address] = require_util.applyTokenChange(accountUpdates[senderChange.address] || senderState, senderChange);
|
|
230
|
+
const isSameAddr = (a, b) => Boolean(a && b && (a === b || (0, _ocap_util.toAddress)(a) === (0, _ocap_util.toAddress)(b)));
|
|
198
231
|
const [newAccountStates, newTokenFactoryState, newTokenState] = await Promise.all([
|
|
199
232
|
Promise.all(Object.entries(accountUpdates).map(([address, updates]) => {
|
|
200
233
|
const state = [
|
|
@@ -202,13 +235,13 @@ runner.use(async (context, next) => {
|
|
|
202
235
|
receiverState,
|
|
203
236
|
ownerState,
|
|
204
237
|
...signerStates
|
|
205
|
-
].find((x) => x?.address
|
|
238
|
+
].find((x) => isSameAddr(x?.address, address));
|
|
206
239
|
const actualUpdates = state ? (0, lodash_pick.default)(updates, ["tokens"]) : {
|
|
207
240
|
...updates,
|
|
208
241
|
address
|
|
209
242
|
};
|
|
210
|
-
if (address
|
|
211
|
-
actualUpdates.pk = tx.pk;
|
|
243
|
+
if (isSameAddr(address, tx.from)) {
|
|
244
|
+
actualUpdates.pk = tx.delegator ? state?.pk || tx.pk : tx.pk;
|
|
212
245
|
actualUpdates.nonce = tx.nonce;
|
|
213
246
|
}
|
|
214
247
|
return statedb.account.updateOrCreate(state ?? null, _ocap_state.account.updateOrCreate(state ?? null, actualUpdates, context), context);
|
|
@@ -219,10 +252,10 @@ runner.use(async (context, next) => {
|
|
|
219
252
|
}, context), context),
|
|
220
253
|
statedb.token.update(tokenAddress, _ocap_state.token.update(tokenState, { totalSupply: new _ocap_util.BN(tokenState.totalSupply).sub(new _ocap_util.BN(burnAmount)).toString() }), context)
|
|
221
254
|
]);
|
|
222
|
-
context.senderState = newAccountStates.find((x) => x.address
|
|
223
|
-
context.receiverState = newAccountStates.find((x) => x.address
|
|
224
|
-
context.ownerState = newAccountStates.find((x) => x.address
|
|
225
|
-
context.signerStates = newAccountStates.filter((x) => signerStates.find((s) => s.address
|
|
255
|
+
context.senderState = newAccountStates.find((x) => isSameAddr(x.address, tx.from));
|
|
256
|
+
context.receiverState = newAccountStates.find((x) => isSameAddr(x.address, receiver));
|
|
257
|
+
context.ownerState = newAccountStates.find((x) => isSameAddr(x.address, ownerState.address)) || ownerState;
|
|
258
|
+
context.signerStates = newAccountStates.filter((x) => signerStates.find((s) => isSameAddr(s.address, x.address)));
|
|
226
259
|
context.tokenFactoryState = newTokenFactoryState;
|
|
227
260
|
context.tokenState = newTokenState;
|
|
228
261
|
context.inputChanges = inputChanges;
|
|
@@ -3,20 +3,20 @@ 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
|
-
const require_index = require('../../node_modules/valibot/dist/index.cjs');
|
|
7
|
-
const require_protocols_token_factory_pipes_verify_icon = require('./pipes/verify-icon.cjs');
|
|
8
6
|
const require_protocols_token_factory_pipes_verify_ownership = require('./pipes/verify-ownership.cjs');
|
|
9
7
|
const require_protocols_token_factory_pipes_verify_url = require('./pipes/verify-url.cjs');
|
|
8
|
+
const require_index = require('../../node_modules/valibot/dist/index.cjs');
|
|
9
|
+
const require_protocols_token_factory_pipes_verify_icon = require('./pipes/verify-icon.cjs');
|
|
10
|
+
let _arcblock_did_util = require("@arcblock/did-util");
|
|
10
11
|
let _ocap_state = require("@ocap/state");
|
|
11
12
|
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
12
13
|
let _ocap_util = require("@ocap/util");
|
|
13
14
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
14
|
-
let _arcblock_did_util = require("@arcblock/did-util");
|
|
15
|
-
let debug = require("debug");
|
|
16
|
-
debug = require_rolldown_runtime.__toESM(debug);
|
|
17
15
|
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
18
16
|
let lodash_cloneDeep = require("lodash/cloneDeep");
|
|
19
17
|
lodash_cloneDeep = require_rolldown_runtime.__toESM(lodash_cloneDeep);
|
|
18
|
+
let debug = require("debug");
|
|
19
|
+
debug = require_rolldown_runtime.__toESM(debug);
|
|
20
20
|
let _arcblock_validator = require("@arcblock/validator");
|
|
21
21
|
let lodash_uniq = require("lodash/uniq");
|
|
22
22
|
lodash_uniq = require_rolldown_runtime.__toESM(lodash_uniq);
|
|
@@ -44,7 +44,7 @@ const schema = require_index.pipe(require_index.object({
|
|
|
44
44
|
description: require_index.pipe(require_index.string(), require_index.minLength(16), require_index.maxLength(128)),
|
|
45
45
|
symbol: require_index.pipe(require_index.string(), require_index.minLength(2), require_index.maxLength(6), require_index.toUpperCase()),
|
|
46
46
|
unit: require_index.pipe(require_index.string(), require_index.minLength(1), require_index.maxLength(6), require_index.toLowerCase()),
|
|
47
|
-
decimal: require_index.pipe(require_index.number(), require_index.minValue(2), require_index.maxValue(18)),
|
|
47
|
+
decimal: require_index.union([require_index.literal(0), require_index.pipe(require_index.number(), require_index.minValue(2), require_index.maxValue(18))]),
|
|
48
48
|
icon: require_index.optional(require_index.nullable(require_index.string())),
|
|
49
49
|
maxTotalSupply: require_index.optional(require_index.nullable(require_index.union([(0, _arcblock_validator.vBN)((0, _arcblock_validator.vBNGreater)(0)), require_index.literal("")]))),
|
|
50
50
|
website: require_index.optional(require_index.nullable(require_index.union([require_index.literal(""), require_index.pipe(require_index.string(), require_index.maxLength(256), require_index.check(isValidUrl, "Must be a valid URL"))]))),
|
|
@@ -59,6 +59,7 @@ runner.use((context, next) => {
|
|
|
59
59
|
const { error, value } = (0, _arcblock_validator.vValidate)(schema, context.itx);
|
|
60
60
|
if (error) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
|
|
61
61
|
if (context.itx.token?.type === "CreditToken") {
|
|
62
|
+
if (context.itx.token?.decimal === 0) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "Invalid itx: CreditToken decimal must be between 2 and 18"));
|
|
62
63
|
if (context.itx.curve != null) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "Invalid itx: Should not provide curve for CreditToken"));
|
|
63
64
|
context.itx.curve = value.curve;
|
|
64
65
|
} else {
|
|
@@ -184,6 +185,9 @@ runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
|
184
185
|
runner.use((context, next) => {
|
|
185
186
|
const { stakeState, config, itx } = context;
|
|
186
187
|
if (stakeState.revocable === false) return next(new _ocap_util_lib_error.CustomError("INVALID_STAKE_STATE", `Staking for token creating already locked: ${stakeState.address}`));
|
|
188
|
+
if (Array.isArray(stakeState.slashers) && stakeState.slashers.length > 0) return next(new _ocap_util_lib_error.CustomError("INVALID_STAKE_STATE", "Staking for token creation cannot have slashers"));
|
|
189
|
+
if (stakeState.revokedTokens && Object.values(stakeState.revokedTokens).some((v) => new _ocap_util.BN(String(v || "0")).gt(new _ocap_util.BN(0)))) return next(new _ocap_util_lib_error.CustomError("INVALID_STAKE_STATE", "Staking for token creation cannot have pending revoked tokens"));
|
|
190
|
+
if (Array.isArray(stakeState.assets) && stakeState.assets.length > 0 || Array.isArray(stakeState.revokedAssets) && stakeState.revokedAssets.length > 0) return next(new _ocap_util_lib_error.CustomError("INVALID_STAKE_STATE", "Staking for token creation cannot contain assets"));
|
|
187
191
|
const actualStake = new _ocap_util.BN(stakeState.tokens[config.token.address] || 0);
|
|
188
192
|
const requiredStake = (0, _ocap_util.fromTokenToUnit)(itx.token.type === "CreditToken" ? config.transaction.txStake.createCreditToken : config.transaction.txStake.createToken, config.token.decimal);
|
|
189
193
|
if (actualStake.lt(requiredStake)) return next(new _ocap_util_lib_error.CustomError("INVALID_STAKE_STATE", `Insufficient stake amount: required ${(0, _ocap_util.fromUnitToToken)(requiredStake, config.token.decimal)} ${config.token.symbol}`));
|
|
@@ -199,6 +203,7 @@ runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
|
199
203
|
stateKey: "delegatorState",
|
|
200
204
|
addressKey: "tx.delegator"
|
|
201
205
|
}));
|
|
206
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyBlocked({ stateKeys: ["delegatorState"] }));
|
|
202
207
|
runner.use(_ocap_tx_pipeline.pipes.VerifyDelegation({
|
|
203
208
|
type: "signature",
|
|
204
209
|
signerKey: "senderState",
|
|
@@ -228,19 +233,21 @@ runner.use(async (context, next) => {
|
|
|
228
233
|
const itxToken = itx.token;
|
|
229
234
|
const { tokens: senderTokens = {} } = senderState;
|
|
230
235
|
const senderUpdates = senderChange ? require_util.applyTokenChange({ tokens: senderTokens }, senderChange) : { tokens: senderTokens };
|
|
236
|
+
const initialTokenState = _ocap_state.token.create({
|
|
237
|
+
...(0, lodash_cloneDeep.default)(itxToken),
|
|
238
|
+
totalSupply: "0",
|
|
239
|
+
initialSupply: "0",
|
|
240
|
+
issuer: owner,
|
|
241
|
+
tokenFactoryAddress: itx.address
|
|
242
|
+
}, context);
|
|
243
|
+
const charterAsset = _ocap_state.token.buildTokenCharterAssetState(initialTokenState, context, owner);
|
|
231
244
|
const [newSenderState, newTokenState, newTokenFactoryState, newDelegationState, newStakeState] = await Promise.all([
|
|
232
245
|
statedb.account.update(senderState.address, _ocap_state.account.update(senderState, {
|
|
233
246
|
nonce: tx.nonce,
|
|
234
|
-
pk: tx.pk,
|
|
247
|
+
pk: tx.delegator ? senderState.pk : tx.pk,
|
|
235
248
|
...senderUpdates
|
|
236
249
|
}, context), context),
|
|
237
|
-
statedb.token.create(itxToken.address,
|
|
238
|
-
...(0, lodash_cloneDeep.default)(itxToken),
|
|
239
|
-
totalSupply: "0",
|
|
240
|
-
initialSupply: "0",
|
|
241
|
-
issuer: owner,
|
|
242
|
-
tokenFactoryAddress: itx.address
|
|
243
|
-
}, context), context),
|
|
250
|
+
statedb.token.create(itxToken.address, initialTokenState, context),
|
|
244
251
|
statedb.tokenFactory.create(itx.address, _ocap_state.tokenFactory.create({
|
|
245
252
|
...(0, lodash_cloneDeep.default)(itx),
|
|
246
253
|
owner,
|
|
@@ -250,8 +257,10 @@ runner.use(async (context, next) => {
|
|
|
250
257
|
context.isDelegationChanged ? statedb.delegation.update(delegationState.address, _ocap_state.delegation.update(delegationState, {}, context), context) : delegationState,
|
|
251
258
|
statedb.stake.update(stakeAddress, _ocap_state.stake.update(stakeState, {
|
|
252
259
|
revocable: false,
|
|
260
|
+
slashers: [],
|
|
253
261
|
revokeWaitingPeriod: config.transaction.txStake.createTokenLockPeriod
|
|
254
|
-
}, context), context)
|
|
262
|
+
}, context), context),
|
|
263
|
+
statedb.asset?.create ? Promise.resolve(statedb.asset.get?.(charterAsset.address, context)).then((existing) => existing && statedb.asset.update ? statedb.asset.update(charterAsset.address, charterAsset, context) : statedb.asset.create(charterAsset.address, charterAsset, context)) : null
|
|
255
264
|
]);
|
|
256
265
|
if (updateVaults) await updateVaults();
|
|
257
266
|
context.senderState = newSenderState;
|