@ocap/tx-protocols 1.28.9 → 1.29.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 +53 -0
- package/esm/execute.mjs +225 -0
- package/esm/index.d.mts +95 -0
- package/esm/index.mjs +100 -0
- package/esm/pipes/ensure-cost.d.mts +18 -0
- package/esm/pipes/ensure-cost.mjs +136 -0
- package/esm/pipes/ensure-gas.d.mts +14 -0
- package/esm/pipes/ensure-gas.mjs +38 -0
- package/esm/protocols/account/delegate.d.mts +4 -0
- package/esm/protocols/account/delegate.mjs +195 -0
- package/esm/protocols/account/migrate.d.mts +4 -0
- package/esm/protocols/account/migrate.mjs +130 -0
- package/esm/protocols/account/revoke-delegate.d.mts +4 -0
- package/esm/protocols/account/revoke-delegate.mjs +102 -0
- package/esm/protocols/asset/acquire-v2.d.mts +9 -0
- package/esm/protocols/asset/acquire-v2.mjs +213 -0
- package/esm/protocols/asset/acquire-v3.d.mts +17 -0
- package/esm/protocols/asset/acquire-v3.mjs +265 -0
- package/esm/protocols/asset/calls/transfer-token.d.mts +4 -0
- package/esm/protocols/asset/calls/transfer-token.mjs +36 -0
- package/esm/protocols/asset/calls/transfer.d.mts +4 -0
- package/esm/protocols/asset/calls/transfer.mjs +32 -0
- package/esm/protocols/asset/consume.d.mts +4 -0
- package/esm/protocols/asset/consume.mjs +92 -0
- package/esm/protocols/asset/create.d.mts +4 -0
- package/esm/protocols/asset/create.mjs +136 -0
- package/esm/protocols/asset/mint.d.mts +4 -0
- package/esm/protocols/asset/mint.mjs +156 -0
- package/esm/protocols/asset/pipes/exec-mint-hook.d.mts +24 -0
- package/esm/protocols/asset/pipes/exec-mint-hook.mjs +54 -0
- package/esm/protocols/asset/pipes/extract-factory-tokens.d.mts +21 -0
- package/esm/protocols/asset/pipes/extract-factory-tokens.mjs +22 -0
- package/esm/protocols/asset/pipes/verify-itx-address.d.mts +32 -0
- package/esm/protocols/asset/pipes/verify-itx-address.mjs +56 -0
- package/esm/protocols/asset/pipes/verify-itx-assets.d.mts +18 -0
- package/esm/protocols/asset/pipes/verify-itx-assets.mjs +27 -0
- package/esm/protocols/asset/pipes/verify-itx-variables.d.mts +17 -0
- package/esm/protocols/asset/pipes/verify-itx-variables.mjs +20 -0
- package/esm/protocols/asset/pipes/verify-mint-limit.d.mts +15 -0
- package/esm/protocols/asset/pipes/verify-mint-limit.mjs +14 -0
- package/esm/protocols/asset/update.d.mts +4 -0
- package/esm/protocols/asset/update.mjs +111 -0
- package/esm/protocols/factory/create.d.mts +29 -0
- package/esm/protocols/factory/create.mjs +155 -0
- package/esm/protocols/governance/claim-stake.d.mts +27 -0
- package/esm/protocols/governance/claim-stake.mjs +220 -0
- package/esm/protocols/governance/return-stake.d.mts +27 -0
- package/esm/protocols/governance/return-stake.mjs +211 -0
- package/esm/protocols/governance/revoke-stake.d.mts +27 -0
- package/esm/protocols/governance/revoke-stake.mjs +178 -0
- package/esm/protocols/governance/slash-stake.d.mts +17 -0
- package/esm/protocols/governance/slash-stake.mjs +213 -0
- package/esm/protocols/governance/stake.d.mts +15 -0
- package/esm/protocols/governance/stake.mjs +270 -0
- package/esm/protocols/rollup/claim-reward.d.mts +11 -0
- package/esm/protocols/rollup/claim-reward.mjs +322 -0
- package/esm/protocols/rollup/close.d.mts +4 -0
- package/esm/protocols/rollup/close.mjs +105 -0
- package/esm/protocols/rollup/create-block.d.mts +11 -0
- package/esm/protocols/rollup/create-block.mjs +303 -0
- package/esm/protocols/rollup/create.d.mts +4 -0
- package/esm/protocols/rollup/create.mjs +164 -0
- package/esm/protocols/rollup/join.d.mts +4 -0
- package/esm/protocols/rollup/join.mjs +152 -0
- package/esm/protocols/rollup/leave.d.mts +4 -0
- package/esm/protocols/rollup/leave.mjs +137 -0
- package/esm/protocols/rollup/migrate.d.mts +4 -0
- package/esm/protocols/rollup/migrate.mjs +85 -0
- package/esm/protocols/rollup/pause.d.mts +4 -0
- package/esm/protocols/rollup/pause.mjs +76 -0
- package/esm/protocols/rollup/pipes/ensure-validator.d.mts +6 -0
- package/esm/protocols/rollup/pipes/ensure-validator.mjs +12 -0
- package/esm/protocols/rollup/pipes/verify-evidence.d.mts +15 -0
- package/esm/protocols/rollup/pipes/verify-evidence.mjs +29 -0
- package/esm/protocols/rollup/pipes/verify-signers.d.mts +15 -0
- package/esm/protocols/rollup/pipes/verify-signers.mjs +36 -0
- package/esm/protocols/rollup/pipes/verify-status.d.mts +13 -0
- package/esm/protocols/rollup/pipes/verify-status.mjs +26 -0
- package/esm/protocols/rollup/resume.d.mts +4 -0
- package/esm/protocols/rollup/resume.mjs +79 -0
- package/esm/protocols/rollup/update.d.mts +4 -0
- package/esm/protocols/rollup/update.mjs +111 -0
- package/esm/protocols/token/create.d.mts +4 -0
- package/esm/protocols/token/create.mjs +150 -0
- package/esm/protocols/token/deposit-v2.d.mts +11 -0
- package/esm/protocols/token/deposit-v2.mjs +216 -0
- package/esm/protocols/token/withdraw-v2.d.mts +9 -0
- package/esm/protocols/token/withdraw-v2.mjs +222 -0
- package/esm/protocols/token-factory/burn.d.mts +15 -0
- package/esm/protocols/token-factory/burn.mjs +233 -0
- package/esm/protocols/token-factory/create.d.mts +4 -0
- package/esm/protocols/token-factory/create.mjs +254 -0
- package/esm/protocols/token-factory/mint.d.mts +15 -0
- package/esm/protocols/token-factory/mint.mjs +234 -0
- package/esm/protocols/token-factory/pipes/calc-reserve.d.mts +21 -0
- package/esm/protocols/token-factory/pipes/calc-reserve.mjs +34 -0
- package/esm/protocols/token-factory/pipes/verify-icon.d.mts +14 -0
- package/esm/protocols/token-factory/pipes/verify-icon.mjs +18 -0
- package/esm/protocols/token-factory/pipes/verify-ownership.d.mts +12 -0
- package/esm/protocols/token-factory/pipes/verify-ownership.mjs +63 -0
- package/esm/protocols/token-factory/pipes/verify-url.d.mts +12 -0
- package/esm/protocols/token-factory/pipes/verify-url.mjs +26 -0
- package/esm/protocols/token-factory/update.d.mts +10 -0
- package/esm/protocols/token-factory/update.mjs +152 -0
- package/esm/protocols/trade/exchange-v2.d.mts +9 -0
- package/esm/protocols/trade/exchange-v2.mjs +239 -0
- package/esm/protocols/trade/transfer-v2.d.mts +9 -0
- package/esm/protocols/trade/transfer-v2.mjs +226 -0
- package/esm/protocols/trade/transfer-v3.d.mts +17 -0
- package/esm/protocols/trade/transfer-v3.mjs +270 -0
- package/esm/util.d.mts +141 -0
- package/esm/util.mjs +278 -0
- package/lib/_virtual/rolldown_runtime.cjs +29 -0
- package/lib/execute.cjs +231 -0
- package/lib/execute.d.cts +53 -0
- package/lib/index.cjs +105 -0
- package/lib/index.d.cts +95 -0
- package/lib/pipes/ensure-cost.cjs +141 -0
- package/lib/pipes/ensure-cost.d.cts +18 -0
- package/lib/pipes/ensure-gas.cjs +41 -0
- package/lib/pipes/ensure-gas.d.cts +14 -0
- package/lib/protocols/account/delegate.cjs +201 -0
- package/lib/protocols/account/delegate.d.cts +4 -0
- package/lib/protocols/account/migrate.cjs +135 -0
- package/lib/protocols/account/migrate.d.cts +4 -0
- package/lib/protocols/account/revoke-delegate.cjs +107 -0
- package/lib/protocols/account/revoke-delegate.d.cts +4 -0
- package/lib/protocols/asset/acquire-v2.cjs +216 -0
- package/lib/protocols/asset/acquire-v2.d.cts +9 -0
- package/lib/protocols/asset/acquire-v3.cjs +269 -0
- package/lib/protocols/asset/acquire-v3.d.cts +17 -0
- package/lib/protocols/asset/calls/transfer-token.cjs +40 -0
- package/lib/protocols/asset/calls/transfer-token.d.cts +4 -0
- package/lib/protocols/asset/calls/transfer.cjs +35 -0
- package/lib/protocols/asset/calls/transfer.d.cts +4 -0
- package/lib/protocols/asset/consume.cjs +95 -0
- package/lib/protocols/asset/consume.d.cts +4 -0
- package/lib/protocols/asset/create.cjs +140 -0
- package/lib/protocols/asset/create.d.cts +4 -0
- package/lib/protocols/asset/mint.cjs +159 -0
- package/lib/protocols/asset/mint.d.cts +4 -0
- package/lib/protocols/asset/pipes/exec-mint-hook.cjs +57 -0
- package/lib/protocols/asset/pipes/exec-mint-hook.d.cts +24 -0
- package/lib/protocols/asset/pipes/extract-factory-tokens.cjs +25 -0
- package/lib/protocols/asset/pipes/extract-factory-tokens.d.cts +21 -0
- package/lib/protocols/asset/pipes/verify-itx-address.cjs +59 -0
- package/lib/protocols/asset/pipes/verify-itx-address.d.cts +32 -0
- package/lib/protocols/asset/pipes/verify-itx-assets.cjs +29 -0
- package/lib/protocols/asset/pipes/verify-itx-assets.d.cts +18 -0
- package/lib/protocols/asset/pipes/verify-itx-variables.cjs +22 -0
- package/lib/protocols/asset/pipes/verify-itx-variables.d.cts +17 -0
- package/lib/protocols/asset/pipes/verify-mint-limit.cjs +16 -0
- package/lib/protocols/asset/pipes/verify-mint-limit.d.cts +15 -0
- package/lib/protocols/asset/update.cjs +114 -0
- package/lib/protocols/asset/update.d.cts +4 -0
- package/lib/protocols/factory/create.cjs +161 -0
- package/lib/protocols/factory/create.d.cts +29 -0
- package/lib/protocols/governance/claim-stake.cjs +223 -0
- package/lib/protocols/governance/claim-stake.d.cts +27 -0
- package/lib/protocols/governance/return-stake.cjs +215 -0
- package/lib/protocols/governance/return-stake.d.cts +27 -0
- package/lib/protocols/governance/revoke-stake.cjs +182 -0
- package/lib/protocols/governance/revoke-stake.d.cts +27 -0
- package/lib/protocols/governance/slash-stake.cjs +217 -0
- package/lib/protocols/governance/slash-stake.d.cts +17 -0
- package/lib/protocols/governance/stake.cjs +275 -0
- package/lib/protocols/governance/stake.d.cts +15 -0
- package/lib/protocols/rollup/claim-reward.cjs +328 -0
- package/lib/protocols/rollup/claim-reward.d.cts +11 -0
- package/lib/protocols/rollup/close.cjs +107 -0
- package/lib/protocols/rollup/close.d.cts +4 -0
- package/lib/protocols/rollup/create-block.cjs +309 -0
- package/lib/protocols/rollup/create-block.d.cts +11 -0
- package/lib/protocols/rollup/create.cjs +169 -0
- package/lib/protocols/rollup/create.d.cts +4 -0
- package/lib/protocols/rollup/join.cjs +157 -0
- package/lib/protocols/rollup/join.d.cts +4 -0
- package/lib/protocols/rollup/leave.cjs +141 -0
- package/lib/protocols/rollup/leave.d.cts +4 -0
- package/lib/protocols/rollup/migrate.cjs +87 -0
- package/lib/protocols/rollup/migrate.d.cts +4 -0
- package/lib/protocols/rollup/pause.cjs +78 -0
- package/lib/protocols/rollup/pause.d.cts +4 -0
- package/lib/protocols/rollup/pipes/ensure-validator.cjs +14 -0
- package/lib/protocols/rollup/pipes/ensure-validator.d.cts +6 -0
- package/lib/protocols/rollup/pipes/verify-evidence.cjs +32 -0
- package/lib/protocols/rollup/pipes/verify-evidence.d.cts +15 -0
- package/lib/protocols/rollup/pipes/verify-signers.cjs +39 -0
- package/lib/protocols/rollup/pipes/verify-signers.d.cts +15 -0
- package/lib/protocols/rollup/pipes/verify-status.cjs +28 -0
- package/lib/protocols/rollup/pipes/verify-status.d.cts +13 -0
- package/lib/protocols/rollup/resume.cjs +81 -0
- package/lib/protocols/rollup/resume.d.cts +4 -0
- package/lib/protocols/rollup/update.cjs +114 -0
- package/lib/protocols/rollup/update.d.cts +4 -0
- package/lib/protocols/token/create.cjs +156 -0
- package/lib/protocols/token/create.d.cts +4 -0
- package/lib/protocols/token/deposit-v2.cjs +219 -0
- package/lib/protocols/token/deposit-v2.d.cts +11 -0
- package/lib/protocols/token/withdraw-v2.cjs +225 -0
- package/lib/protocols/token/withdraw-v2.d.cts +9 -0
- package/lib/protocols/token-factory/burn.cjs +236 -0
- package/lib/protocols/token-factory/burn.d.cts +15 -0
- package/lib/protocols/token-factory/create.cjs +260 -0
- package/lib/protocols/token-factory/create.d.cts +4 -0
- package/lib/protocols/token-factory/mint.cjs +237 -0
- package/lib/protocols/token-factory/mint.d.cts +15 -0
- package/lib/protocols/token-factory/pipes/calc-reserve.cjs +38 -0
- package/lib/protocols/token-factory/pipes/calc-reserve.d.cts +21 -0
- package/lib/protocols/token-factory/pipes/verify-icon.cjs +22 -0
- package/lib/protocols/token-factory/pipes/verify-icon.d.cts +14 -0
- package/lib/protocols/token-factory/pipes/verify-ownership.cjs +66 -0
- package/lib/protocols/token-factory/pipes/verify-ownership.d.cts +12 -0
- package/lib/protocols/token-factory/pipes/verify-url.cjs +29 -0
- package/lib/protocols/token-factory/pipes/verify-url.d.cts +12 -0
- package/lib/protocols/token-factory/update.cjs +155 -0
- package/lib/protocols/token-factory/update.d.cts +10 -0
- package/lib/protocols/trade/exchange-v2.cjs +243 -0
- package/lib/protocols/trade/exchange-v2.d.cts +9 -0
- package/lib/protocols/trade/transfer-v2.cjs +229 -0
- package/lib/protocols/trade/transfer-v2.d.cts +9 -0
- package/lib/protocols/trade/transfer-v3.cjs +274 -0
- package/lib/protocols/trade/transfer-v3.d.cts +17 -0
- package/lib/util.cjs +296 -0
- package/lib/util.d.cts +141 -0
- package/package.json +49 -22
- package/tools/fixtures.ts +564 -0
- package/lib/execute.js +0 -254
- package/lib/index.js +0 -117
- package/lib/pipes/ensure-cost.js +0 -193
- package/lib/pipes/ensure-gas.js +0 -48
- package/lib/protocols/account/delegate.js +0 -223
- package/lib/protocols/account/migrate.js +0 -153
- package/lib/protocols/account/revoke-delegate.js +0 -110
- package/lib/protocols/asset/acquire-v2.js +0 -262
- package/lib/protocols/asset/acquire-v3.js +0 -330
- package/lib/protocols/asset/calls/README.md +0 -5
- package/lib/protocols/asset/calls/transfer-token.js +0 -36
- package/lib/protocols/asset/calls/transfer.js +0 -28
- package/lib/protocols/asset/consume.js +0 -105
- package/lib/protocols/asset/create.js +0 -151
- package/lib/protocols/asset/mint.js +0 -199
- package/lib/protocols/asset/pipes/exec-mint-hook.js +0 -62
- package/lib/protocols/asset/pipes/extract-factory-tokens.js +0 -18
- package/lib/protocols/asset/pipes/verify-itx-address.js +0 -54
- package/lib/protocols/asset/pipes/verify-itx-assets.js +0 -51
- package/lib/protocols/asset/pipes/verify-itx-variables.js +0 -26
- package/lib/protocols/asset/pipes/verify-mint-limit.js +0 -13
- package/lib/protocols/asset/update.js +0 -131
- package/lib/protocols/factory/create.js +0 -191
- package/lib/protocols/governance/claim-stake.js +0 -266
- package/lib/protocols/governance/return-stake.js +0 -248
- package/lib/protocols/governance/revoke-stake.js +0 -172
- package/lib/protocols/governance/slash-stake.js +0 -271
- package/lib/protocols/governance/stake.js +0 -303
- package/lib/protocols/rollup/claim-reward.js +0 -342
- package/lib/protocols/rollup/close.js +0 -104
- package/lib/protocols/rollup/create-block.js +0 -413
- package/lib/protocols/rollup/create.js +0 -197
- package/lib/protocols/rollup/join.js +0 -182
- package/lib/protocols/rollup/leave.js +0 -145
- package/lib/protocols/rollup/migrate.js +0 -85
- package/lib/protocols/rollup/pause.js +0 -75
- package/lib/protocols/rollup/pipes/ensure-validator.js +0 -12
- package/lib/protocols/rollup/pipes/verify-evidence.js +0 -37
- package/lib/protocols/rollup/pipes/verify-signers.js +0 -87
- package/lib/protocols/rollup/pipes/verify-status.js +0 -30
- package/lib/protocols/rollup/resume.js +0 -75
- package/lib/protocols/rollup/update.js +0 -122
- package/lib/protocols/token/create.js +0 -199
- package/lib/protocols/token/deposit-v2.js +0 -290
- package/lib/protocols/token/withdraw-v2.js +0 -305
- package/lib/protocols/token-factory/burn.js +0 -371
- package/lib/protocols/token-factory/create.js +0 -342
- package/lib/protocols/token-factory/mint.js +0 -385
- package/lib/protocols/token-factory/pipes/calc-reserve.js +0 -37
- package/lib/protocols/token-factory/pipes/verify-icon.js +0 -27
- package/lib/protocols/token-factory/pipes/verify-ownership.js +0 -93
- package/lib/protocols/token-factory/pipes/verify-url.js +0 -32
- package/lib/protocols/token-factory/update.js +0 -208
- package/lib/protocols/trade/exchange-v2.js +0 -239
- package/lib/protocols/trade/transfer-v2.js +0 -233
- package/lib/protocols/trade/transfer-v3.js +0 -333
- package/lib/util.js +0 -442
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
3
|
+
const require_util = require('../../util.cjs');
|
|
4
|
+
const require_pipes_ensure_cost = require('../../pipes/ensure-cost.cjs');
|
|
5
|
+
const require_pipes_ensure_gas = require('../../pipes/ensure-gas.cjs');
|
|
6
|
+
const require_protocols_rollup_pipes_verify_status = require('../rollup/pipes/verify-status.cjs');
|
|
7
|
+
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
8
|
+
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
9
|
+
let _arcblock_did_util = require("@arcblock/did-util");
|
|
10
|
+
let _ocap_state = require("@ocap/state");
|
|
11
|
+
let _ocap_util = require("@ocap/util");
|
|
12
|
+
let debug = require("debug");
|
|
13
|
+
debug = require_rolldown_runtime.__toESM(debug);
|
|
14
|
+
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
15
|
+
let _arcblock_validator = require("@arcblock/validator");
|
|
16
|
+
|
|
17
|
+
//#region src/protocols/token/withdraw-v2.ts
|
|
18
|
+
const debug$1 = (0, debug.default)("@ocap/tx-protocols:withdraw-token");
|
|
19
|
+
const verifyMultiSigV2 = _ocap_tx_pipeline.pipes.VerifyMultiSigV2({ signersKey: "signers" });
|
|
20
|
+
const schema = _arcblock_validator.Joi.object({
|
|
21
|
+
token: _arcblock_validator.schemas.tokenInput.required(),
|
|
22
|
+
to: _arcblock_validator.Joi.DID().prefix().wallet("ethereum").required(),
|
|
23
|
+
rollup: _arcblock_validator.Joi.DID().prefix().role("ROLE_ROLLUP").required(),
|
|
24
|
+
proposer: _arcblock_validator.Joi.DID().prefix().wallet("ethereum").optional().allow(null).allow("").default(""),
|
|
25
|
+
actualFee: _arcblock_validator.Joi.BN().min(0).required(),
|
|
26
|
+
maxFee: _arcblock_validator.Joi.BN().min(0).required(),
|
|
27
|
+
data: _arcblock_validator.Joi.any().optional().allow(null)
|
|
28
|
+
}).options({
|
|
29
|
+
stripUnknown: true,
|
|
30
|
+
noDefaults: false
|
|
31
|
+
});
|
|
32
|
+
const runner = new _ocap_tx_pipeline.Runner("withdraw_token_v2");
|
|
33
|
+
runner.use(({ tx, itx }, next) => {
|
|
34
|
+
const { error } = schema.validate(itx);
|
|
35
|
+
if (error) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
|
|
36
|
+
if (itx.to !== tx.from) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "You can only withdraw to tx sender account"));
|
|
37
|
+
return next();
|
|
38
|
+
});
|
|
39
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
40
|
+
from: "itx.rollup",
|
|
41
|
+
to: "rollupState",
|
|
42
|
+
status: "INVALID_ROLLUP",
|
|
43
|
+
table: "rollup"
|
|
44
|
+
}));
|
|
45
|
+
runner.use(require_protocols_rollup_pipes_verify_status.default({ paused: false }));
|
|
46
|
+
runner.use((context, next) => {
|
|
47
|
+
const { itx, rollupState } = context;
|
|
48
|
+
if (rollupState.tokenAddress !== itx.token.address) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "Withdraw token address does not match with rollup"));
|
|
49
|
+
return next();
|
|
50
|
+
});
|
|
51
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
52
|
+
from: "itx.token.address",
|
|
53
|
+
to: "tokenState",
|
|
54
|
+
status: "INVALID_TOKEN",
|
|
55
|
+
table: "token"
|
|
56
|
+
}));
|
|
57
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
58
|
+
from: "tx.from",
|
|
59
|
+
to: "senderState",
|
|
60
|
+
status: "INVALID_SENDER_STATE",
|
|
61
|
+
table: "account"
|
|
62
|
+
}));
|
|
63
|
+
runner.use((context, next) => {
|
|
64
|
+
const { tx, itx, tokenState, rollupState } = context;
|
|
65
|
+
const withdrawAmount = new _ocap_util.BN(itx.token.value);
|
|
66
|
+
const minWithdrawAmount = new _ocap_util.BN(rollupState.minWithdrawAmount);
|
|
67
|
+
const maxWithdrawAmount = new _ocap_util.BN(rollupState.maxWithdrawAmount);
|
|
68
|
+
if (withdrawAmount.lt(minWithdrawAmount)) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Withdraw amount must be greater than: ${(0, _ocap_util.fromUnitToToken)(minWithdrawAmount, tokenState.decimal)}`));
|
|
69
|
+
if (withdrawAmount.gt(maxWithdrawAmount)) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Withdraw amount must be less than maxWithdrawAmount: ${(0, _ocap_util.fromUnitToToken)(maxWithdrawAmount, tokenState.decimal)}`));
|
|
70
|
+
const maxAmount = require_util.getBNSum(itx.token.value, itx.actualFee, itx.maxFee);
|
|
71
|
+
context.tokenConditions = {
|
|
72
|
+
owner: tx.from,
|
|
73
|
+
tokens: [{
|
|
74
|
+
address: itx.token.address,
|
|
75
|
+
value: maxAmount
|
|
76
|
+
}]
|
|
77
|
+
};
|
|
78
|
+
return next();
|
|
79
|
+
});
|
|
80
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyTokenBalance({
|
|
81
|
+
ownerKey: "senderState",
|
|
82
|
+
conditionKey: "tokenConditions"
|
|
83
|
+
}));
|
|
84
|
+
runner.use((context, next) => {
|
|
85
|
+
const { itx, rollupState, tokenState } = context;
|
|
86
|
+
const { withdrawFeeRate, maxWithdrawFee, minWithdrawFee } = rollupState;
|
|
87
|
+
if (new _ocap_util.BN(itx.maxFee).isZero()) {
|
|
88
|
+
const { reward } = require_util.getTxFee({
|
|
89
|
+
amount: itx.token.value,
|
|
90
|
+
feeRate: withdrawFeeRate,
|
|
91
|
+
maxFee: maxWithdrawFee,
|
|
92
|
+
minFee: minWithdrawFee
|
|
93
|
+
});
|
|
94
|
+
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)}`));
|
|
95
|
+
}
|
|
96
|
+
return next();
|
|
97
|
+
});
|
|
98
|
+
runner.use((context, next) => {
|
|
99
|
+
const { tx, itx } = context;
|
|
100
|
+
if (new _ocap_util.BN(itx.maxFee).isZero()) return next();
|
|
101
|
+
const signatures = (0, _ocap_util_lib_get_list_field.getListField)(tx, "signatures");
|
|
102
|
+
if (signatures.length !== 1) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "Withdraw with maxFee should have one multi-sig"));
|
|
103
|
+
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"));
|
|
104
|
+
context.signers = signatures.map((x) => x.signer);
|
|
105
|
+
verifyMultiSigV2(context, next);
|
|
106
|
+
});
|
|
107
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
108
|
+
from: "signers",
|
|
109
|
+
to: "signerStates",
|
|
110
|
+
status: "INVALID_SIGNER_STATE",
|
|
111
|
+
table: "account"
|
|
112
|
+
}));
|
|
113
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
114
|
+
signerKey: "signerStates",
|
|
115
|
+
stateKey: "senderState",
|
|
116
|
+
addressKey: "tx.from"
|
|
117
|
+
}));
|
|
118
|
+
runner.use((context, next) => {
|
|
119
|
+
const { itx, senderState } = context;
|
|
120
|
+
context.stakeAddress = (0, _arcblock_did_util.toStakeAddress)(senderState.address, itx.rollup);
|
|
121
|
+
context.lockerAddress = require_util.getRewardLocker(itx.rollup);
|
|
122
|
+
return next();
|
|
123
|
+
});
|
|
124
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
125
|
+
from: "lockerAddress",
|
|
126
|
+
to: "lockerState",
|
|
127
|
+
status: "OK",
|
|
128
|
+
table: "stake"
|
|
129
|
+
}));
|
|
130
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
131
|
+
from: "stakeAddress",
|
|
132
|
+
to: "stakeState",
|
|
133
|
+
status: "OK",
|
|
134
|
+
table: "stake"
|
|
135
|
+
}));
|
|
136
|
+
runner.use((context, next) => {
|
|
137
|
+
const { stakeState } = context;
|
|
138
|
+
if (stakeState && stakeState.revocable === true) return next(new _ocap_util_lib_error.CustomError("INVALID_STAKE_STATE", `Staking not locked for withdraw: ${stakeState.address}`));
|
|
139
|
+
return next();
|
|
140
|
+
});
|
|
141
|
+
runner.use(require_pipes_ensure_gas.default((context) => {
|
|
142
|
+
const result = {
|
|
143
|
+
create: 0,
|
|
144
|
+
update: 1,
|
|
145
|
+
payment: 0
|
|
146
|
+
};
|
|
147
|
+
if (context.stakeState) result.update += 1;
|
|
148
|
+
else result.create += 1;
|
|
149
|
+
if (context.lockerState) result.update += 1;
|
|
150
|
+
else result.create += 1;
|
|
151
|
+
return result;
|
|
152
|
+
}));
|
|
153
|
+
runner.use(require_pipes_ensure_cost.default({ attachSenderChanges: true }));
|
|
154
|
+
runner.use(_ocap_tx_pipeline.pipes.TakeStateSnapshot());
|
|
155
|
+
runner.use(async (context, next) => {
|
|
156
|
+
const { tx, itx, statedb, stakeState, senderState, lockerState, lockerAddress, stakeAddress, senderChange, updateVaults } = context;
|
|
157
|
+
const total = require_util.getBNSum(itx.token.value, itx.actualFee, itx.maxFee);
|
|
158
|
+
const fee = require_util.getBNSum(itx.actualFee, itx.maxFee);
|
|
159
|
+
let senderUpdates = require_util.applyTokenUpdates([{
|
|
160
|
+
address: itx.token.address,
|
|
161
|
+
value: total
|
|
162
|
+
}], senderState, "sub");
|
|
163
|
+
if (senderChange) senderUpdates = require_util.applyTokenChange(senderUpdates, senderChange);
|
|
164
|
+
const stakeUpdates = require_util.applyTokenUpdates([{
|
|
165
|
+
address: itx.token.address,
|
|
166
|
+
value: itx.token.value
|
|
167
|
+
}], stakeState || {}, "add");
|
|
168
|
+
const lockerUpdates = require_util.applyTokenUpdates([{
|
|
169
|
+
address: itx.token.address,
|
|
170
|
+
value: fee
|
|
171
|
+
}], lockerState || { tokens: {} }, "add");
|
|
172
|
+
const [newSenderState, newStakeState, newLockerState] = await Promise.all([
|
|
173
|
+
statedb.account.update(senderState.address, _ocap_state.account.update(senderState, {
|
|
174
|
+
nonce: tx.nonce,
|
|
175
|
+
...senderUpdates
|
|
176
|
+
}, context), context),
|
|
177
|
+
stakeState ? statedb.stake.update(stakeAddress, _ocap_state.stake.update(stakeState, stakeUpdates, context), context) : statedb.stake.create(stakeAddress, _ocap_state.stake.create({
|
|
178
|
+
address: stakeAddress,
|
|
179
|
+
sender: senderState.address,
|
|
180
|
+
receiver: itx.rollup,
|
|
181
|
+
revocable: false,
|
|
182
|
+
tokens: stakeUpdates.tokens,
|
|
183
|
+
message: "withdraw-locker",
|
|
184
|
+
assets: []
|
|
185
|
+
}, context), context),
|
|
186
|
+
lockerState ? statedb.stake.update(lockerState.address, _ocap_state.stake.update(lockerState, lockerUpdates, context), context) : statedb.stake.create(lockerAddress, _ocap_state.stake.create({
|
|
187
|
+
address: lockerAddress,
|
|
188
|
+
sender: itx.rollup,
|
|
189
|
+
receiver: itx.rollup,
|
|
190
|
+
revocable: false,
|
|
191
|
+
message: "pending-block-reward",
|
|
192
|
+
revokeWaitingPeriod: 0,
|
|
193
|
+
...lockerUpdates
|
|
194
|
+
}, context), context)
|
|
195
|
+
]);
|
|
196
|
+
if (updateVaults) await updateVaults();
|
|
197
|
+
context.senderState = newSenderState;
|
|
198
|
+
context.stakeState = newStakeState;
|
|
199
|
+
context.lockerState = newLockerState;
|
|
200
|
+
context.stakeStates = [newStakeState, newLockerState];
|
|
201
|
+
context.updatedAccounts = context.updatedAccounts || [];
|
|
202
|
+
context.updatedAccounts.push({
|
|
203
|
+
address: senderState.address,
|
|
204
|
+
token: itx.token.address,
|
|
205
|
+
delta: `-${total}`,
|
|
206
|
+
action: "lock"
|
|
207
|
+
}, {
|
|
208
|
+
address: stakeAddress,
|
|
209
|
+
token: itx.token.address,
|
|
210
|
+
delta: itx.token.value,
|
|
211
|
+
action: "lock"
|
|
212
|
+
}, {
|
|
213
|
+
address: lockerAddress,
|
|
214
|
+
token: itx.token.address,
|
|
215
|
+
delta: fee,
|
|
216
|
+
action: "pending"
|
|
217
|
+
});
|
|
218
|
+
debug$1("withdraw-token-v2", itx);
|
|
219
|
+
next();
|
|
220
|
+
}, { persistError: true });
|
|
221
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyStateDiff());
|
|
222
|
+
var withdraw_v2_default = runner;
|
|
223
|
+
|
|
224
|
+
//#endregion
|
|
225
|
+
exports.default = withdraw_v2_default;
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
3
|
+
const require_util = require('../../util.cjs');
|
|
4
|
+
const require_pipes_ensure_cost = require('../../pipes/ensure-cost.cjs');
|
|
5
|
+
const require_pipes_ensure_gas = require('../../pipes/ensure-gas.cjs');
|
|
6
|
+
const require_protocols_token_factory_pipes_calc_reserve = require('./pipes/calc-reserve.cjs');
|
|
7
|
+
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
8
|
+
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
9
|
+
let lodash_pick = require("lodash/pick");
|
|
10
|
+
lodash_pick = require_rolldown_runtime.__toESM(lodash_pick);
|
|
11
|
+
let _ocap_state = require("@ocap/state");
|
|
12
|
+
let _ocap_util = require("@ocap/util");
|
|
13
|
+
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
14
|
+
let _arcblock_validator = require("@arcblock/validator");
|
|
15
|
+
|
|
16
|
+
//#region src/protocols/token-factory/burn.ts
|
|
17
|
+
const runner = new _ocap_tx_pipeline.Runner("burn_token");
|
|
18
|
+
const schema = _arcblock_validator.Joi.object({
|
|
19
|
+
tokenFactory: _arcblock_validator.Joi.DID().prefix().role("ROLE_TOKEN_FACTORY").required(),
|
|
20
|
+
receiver: _arcblock_validator.schemas.tokenHolder.required(),
|
|
21
|
+
minReserve: _arcblock_validator.Joi.alternatives().try(_arcblock_validator.Joi.BN().greater(0), _arcblock_validator.Joi.equal("")).optional(),
|
|
22
|
+
inputsList: _arcblock_validator.schemas.multiInput.min(1).required(),
|
|
23
|
+
data: _arcblock_validator.Joi.any().optional().allow(null)
|
|
24
|
+
}).options({
|
|
25
|
+
stripUnknown: true,
|
|
26
|
+
noDefaults: false
|
|
27
|
+
});
|
|
28
|
+
runner.use(({ itx }, next) => {
|
|
29
|
+
const { error } = schema.validate(itx);
|
|
30
|
+
if (error) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
|
|
31
|
+
return next();
|
|
32
|
+
});
|
|
33
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
34
|
+
from: "itx.tokenFactory",
|
|
35
|
+
to: "tokenFactoryState",
|
|
36
|
+
status: "INVALID_TOKEN_FACTORY",
|
|
37
|
+
table: "tokenFactory"
|
|
38
|
+
}));
|
|
39
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
40
|
+
from: "tokenFactoryState.tokenAddress",
|
|
41
|
+
to: "tokenState",
|
|
42
|
+
status: "INVALID_TOKEN",
|
|
43
|
+
table: "token"
|
|
44
|
+
}));
|
|
45
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyTxInput({
|
|
46
|
+
fieldKey: "itx.inputs",
|
|
47
|
+
inputsKey: "inputs",
|
|
48
|
+
sendersKey: "senders",
|
|
49
|
+
tokensKey: "tokens",
|
|
50
|
+
assetsKey: null
|
|
51
|
+
}));
|
|
52
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyListSize({ listKey: [
|
|
53
|
+
"inputs",
|
|
54
|
+
"senders",
|
|
55
|
+
"tokens",
|
|
56
|
+
"assets"
|
|
57
|
+
] }));
|
|
58
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyMultiSigV2({ signersKey: "senders" }));
|
|
59
|
+
runner.use((context, next) => {
|
|
60
|
+
const { tokenFactoryState, inputs } = context;
|
|
61
|
+
if (!(inputs || []).every((input) => {
|
|
62
|
+
const tokensList = (0, _ocap_util_lib_get_list_field.getListField)(input, "tokens");
|
|
63
|
+
const assetsList = (0, _ocap_util_lib_get_list_field.getListField)(input, "assets");
|
|
64
|
+
return tokensList.length && tokensList.every((x) => x.address === tokenFactoryState.tokenAddress) && !assetsList.length;
|
|
65
|
+
})) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Inputs only accept ${tokenFactoryState.tokenAddress}`));
|
|
66
|
+
return next();
|
|
67
|
+
});
|
|
68
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
69
|
+
from: "tx.from",
|
|
70
|
+
to: "senderState",
|
|
71
|
+
status: "OK",
|
|
72
|
+
table: "account"
|
|
73
|
+
}));
|
|
74
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
75
|
+
stateKey: "senderState",
|
|
76
|
+
addressKey: "tx.from"
|
|
77
|
+
}));
|
|
78
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
79
|
+
from: "senders",
|
|
80
|
+
to: "signerStates",
|
|
81
|
+
status: "INVALID_SIGNER_STATE",
|
|
82
|
+
table: "account"
|
|
83
|
+
}));
|
|
84
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
85
|
+
signerKey: "signerStates",
|
|
86
|
+
stateKey: "senderState",
|
|
87
|
+
addressKey: "tx.from"
|
|
88
|
+
}));
|
|
89
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
90
|
+
from: "itx.receiver",
|
|
91
|
+
to: "receiverState",
|
|
92
|
+
status: "OK",
|
|
93
|
+
table: "account"
|
|
94
|
+
}));
|
|
95
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
96
|
+
stateKey: "receiverState",
|
|
97
|
+
addressKey: "itx.receiver"
|
|
98
|
+
}));
|
|
99
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyBlocked({ stateKeys: ["signerStates", "receiverState"] }));
|
|
100
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
101
|
+
from: "tokenFactoryState.owner",
|
|
102
|
+
to: "ownerState",
|
|
103
|
+
status: "INVALID_OWNER_STATE",
|
|
104
|
+
table: "account"
|
|
105
|
+
}));
|
|
106
|
+
runner.use(_ocap_tx_pipeline.pipes.verifyTokenAccess({
|
|
107
|
+
statesKey: "tokenState",
|
|
108
|
+
listFieldKey: "minters",
|
|
109
|
+
accountKeys: ["senderState"],
|
|
110
|
+
errorMessage: "Account {address} is not allowed to burn token {tokenAddress}"
|
|
111
|
+
}));
|
|
112
|
+
runner.use((context, next) => {
|
|
113
|
+
const { inputs = [], tokenFactoryState } = context;
|
|
114
|
+
let amount = new _ocap_util.BN("0");
|
|
115
|
+
for (const { tokensList } of inputs) {
|
|
116
|
+
const delta = tokensList.find((x) => x.address === tokenFactoryState.tokenAddress)?.value;
|
|
117
|
+
if (!delta) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "Invalid inputs"));
|
|
118
|
+
amount = amount.add(new _ocap_util.BN(delta));
|
|
119
|
+
}
|
|
120
|
+
context.burnAmount = amount.toString();
|
|
121
|
+
return next();
|
|
122
|
+
});
|
|
123
|
+
runner.use(require_protocols_token_factory_pipes_calc_reserve.default({
|
|
124
|
+
tokenFactoryKey: "tokenFactoryState",
|
|
125
|
+
tokenStateKey: "tokenState",
|
|
126
|
+
reserveKey: "reserveAmount",
|
|
127
|
+
feeKey: "reserveFee",
|
|
128
|
+
amountKey: "burnAmount",
|
|
129
|
+
direction: "burn"
|
|
130
|
+
}), { shouldSkip: (ctx) => !ctx.tokenFactoryState?.curve });
|
|
131
|
+
runner.use((context, next) => {
|
|
132
|
+
const { reserveAmount = "0", reserveFee } = context;
|
|
133
|
+
const { minReserve } = context.itx;
|
|
134
|
+
if (minReserve && new _ocap_util.BN(reserveAmount).lt(new _ocap_util.BN(minReserve).add(new _ocap_util.BN(reserveFee || "0")))) return next(new _ocap_util_lib_error.CustomError("SLIPPAGE_EXCEEDED", `Burn token failed due to price movement. Expected minimum: ${(0, _ocap_util.fromUnitToToken)(minReserve)}, actual: ${(0, _ocap_util.fromUnitToToken)(reserveAmount)}. Try reducing your minReserve.`));
|
|
135
|
+
return next();
|
|
136
|
+
}, { shouldSkip: (ctx) => !ctx.tokenFactoryState?.curve });
|
|
137
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
138
|
+
from: "tokens",
|
|
139
|
+
to: "tokenStates",
|
|
140
|
+
status: "INVALID_TOKEN",
|
|
141
|
+
table: "token"
|
|
142
|
+
}));
|
|
143
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyTokenBalance({
|
|
144
|
+
ownerKey: "signerStates",
|
|
145
|
+
conditionKey: "inputs"
|
|
146
|
+
}));
|
|
147
|
+
runner.use((context, next) => {
|
|
148
|
+
const { tokenFactoryState, burnAmount = "0", reserveAmount = "0" } = context;
|
|
149
|
+
if (new _ocap_util.BN(tokenFactoryState.currentSupply).lt(new _ocap_util.BN(burnAmount))) return next(new _ocap_util_lib_error.CustomError("INSUFFICIENT_FUND", "Token factory supply is not enough"));
|
|
150
|
+
if (new _ocap_util.BN(tokenFactoryState.reserveBalance).lt(new _ocap_util.BN(reserveAmount))) return next(new _ocap_util_lib_error.CustomError("INSUFFICIENT_FUND", "Token factory reserve balance is not enough"));
|
|
151
|
+
return next();
|
|
152
|
+
});
|
|
153
|
+
runner.use(require_pipes_ensure_gas.default((context) => {
|
|
154
|
+
const result = {
|
|
155
|
+
create: 0,
|
|
156
|
+
update: 2,
|
|
157
|
+
payment: 0
|
|
158
|
+
};
|
|
159
|
+
if (context.senderState) result.update += 1;
|
|
160
|
+
else result.create += 1;
|
|
161
|
+
if (context.tokenFactoryState?.curve) if (context.receiverState) result.update += 1;
|
|
162
|
+
else result.create += 1;
|
|
163
|
+
if (context.reserveFee) result.update += 1;
|
|
164
|
+
if (context.signerStates) result.update += context.signerStates.length;
|
|
165
|
+
return result;
|
|
166
|
+
}));
|
|
167
|
+
runner.use(require_pipes_ensure_cost.default({ attachSenderChanges: true }));
|
|
168
|
+
runner.use(_ocap_tx_pipeline.pipes.TakeStateSnapshot());
|
|
169
|
+
runner.use(async (context, next) => {
|
|
170
|
+
const { tx, senderState, receiverState, ownerState, statedb, senderChange, updateVaults, tokenFactoryState, tokenState, reserveAmount = "0", reserveFee, itx, inputs = [], signerStates = [], burnAmount = "0" } = context;
|
|
171
|
+
const { receiver } = itx;
|
|
172
|
+
const { reserveAddress, tokenAddress } = tokenFactoryState;
|
|
173
|
+
const accountUpdates = {};
|
|
174
|
+
const inputChanges = [];
|
|
175
|
+
inputs.forEach((input) => {
|
|
176
|
+
const { owner } = input;
|
|
177
|
+
const tokenChange = (0, _ocap_util_lib_get_list_field.getListField)(input, "tokens").find((item) => item.address === tokenAddress);
|
|
178
|
+
accountUpdates[owner] = require_util.applyTokenUpdates([tokenChange], signerStates.find((s) => s.address === owner), "sub");
|
|
179
|
+
inputChanges.push({
|
|
180
|
+
address: owner,
|
|
181
|
+
token: tokenAddress,
|
|
182
|
+
delta: new _ocap_util.BN(tokenChange.value).neg().toString()
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
if (!accountUpdates[tx.from]) accountUpdates[tx.from] = senderState || {};
|
|
186
|
+
if (reserveFee && new _ocap_util.BN(reserveFee).gt(new _ocap_util.BN(0))) accountUpdates[ownerState.address] = require_util.applyTokenChange(accountUpdates[ownerState.address] || ownerState, {
|
|
187
|
+
token: reserveAddress,
|
|
188
|
+
delta: reserveFee
|
|
189
|
+
});
|
|
190
|
+
if (tokenFactoryState.curve) accountUpdates[receiver] = require_util.applyTokenChange(accountUpdates[receiver] || receiverState || {
|
|
191
|
+
address: receiver,
|
|
192
|
+
tokens: {}
|
|
193
|
+
}, {
|
|
194
|
+
token: reserveAddress,
|
|
195
|
+
delta: new _ocap_util.BN(reserveAmount).sub(new _ocap_util.BN(reserveFee || "0")).toString()
|
|
196
|
+
});
|
|
197
|
+
if (senderChange) accountUpdates[senderChange.address] = require_util.applyTokenChange(accountUpdates[senderChange.address] || senderState, senderChange);
|
|
198
|
+
const [newAccountStates, newTokenFactoryState, newTokenState] = await Promise.all([
|
|
199
|
+
Promise.all(Object.entries(accountUpdates).map(([address, updates]) => {
|
|
200
|
+
const state = [
|
|
201
|
+
senderState,
|
|
202
|
+
receiverState,
|
|
203
|
+
ownerState,
|
|
204
|
+
...signerStates
|
|
205
|
+
].find((x) => x?.address === address);
|
|
206
|
+
const actualUpdates = state ? (0, lodash_pick.default)(updates, ["tokens"]) : {
|
|
207
|
+
...updates,
|
|
208
|
+
address
|
|
209
|
+
};
|
|
210
|
+
if (address === tx.from) {
|
|
211
|
+
actualUpdates.pk = tx.pk;
|
|
212
|
+
actualUpdates.nonce = tx.nonce;
|
|
213
|
+
}
|
|
214
|
+
return statedb.account.updateOrCreate(state ?? null, _ocap_state.account.updateOrCreate(state ?? null, actualUpdates, context), context);
|
|
215
|
+
})),
|
|
216
|
+
statedb.tokenFactory.update(tokenFactoryState.address, _ocap_state.tokenFactory.update(tokenFactoryState, {
|
|
217
|
+
currentSupply: new _ocap_util.BN(tokenFactoryState.currentSupply).sub(new _ocap_util.BN(burnAmount)).toString(),
|
|
218
|
+
reserveBalance: new _ocap_util.BN(tokenFactoryState.reserveBalance).sub(new _ocap_util.BN(reserveAmount)).toString()
|
|
219
|
+
}, context), context),
|
|
220
|
+
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
|
+
]);
|
|
222
|
+
context.senderState = newAccountStates.find((x) => x.address === tx.from);
|
|
223
|
+
context.receiverState = newAccountStates.find((x) => x.address === receiver);
|
|
224
|
+
context.ownerState = newAccountStates.find((x) => x.address === ownerState.address) || ownerState;
|
|
225
|
+
context.signerStates = newAccountStates.filter((x) => signerStates.find((s) => s.address === x.address));
|
|
226
|
+
context.tokenFactoryState = newTokenFactoryState;
|
|
227
|
+
context.tokenState = newTokenState;
|
|
228
|
+
context.inputChanges = inputChanges;
|
|
229
|
+
if (updateVaults) await updateVaults();
|
|
230
|
+
next();
|
|
231
|
+
}, { persistError: true });
|
|
232
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyStateDiff());
|
|
233
|
+
var burn_default = runner;
|
|
234
|
+
|
|
235
|
+
//#endregion
|
|
236
|
+
exports.default = burn_default;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/protocols/token-factory/burn.d.ts
|
|
2
|
+
/** Token input type */
|
|
3
|
+
interface TokenInput {
|
|
4
|
+
address: string;
|
|
5
|
+
value: string;
|
|
6
|
+
}
|
|
7
|
+
/** Multi-input type */
|
|
8
|
+
interface MultiInput {
|
|
9
|
+
owner: string;
|
|
10
|
+
tokensList: TokenInput[];
|
|
11
|
+
assetsList: string[];
|
|
12
|
+
}
|
|
13
|
+
declare const runner: any;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { MultiInput, TokenInput, runner as default };
|