@ocap/tx-protocols 1.28.9 → 1.29.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 +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,95 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
3
|
+
const require_pipes_ensure_cost = require('../../pipes/ensure-cost.cjs');
|
|
4
|
+
const require_pipes_ensure_gas = require('../../pipes/ensure-gas.cjs');
|
|
5
|
+
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
6
|
+
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
7
|
+
let _ocap_state = require("@ocap/state");
|
|
8
|
+
let debug = require("debug");
|
|
9
|
+
debug = require_rolldown_runtime.__toESM(debug);
|
|
10
|
+
let _arcblock_validator = require("@arcblock/validator");
|
|
11
|
+
|
|
12
|
+
//#region src/protocols/asset/consume.ts
|
|
13
|
+
const debug$1 = (0, debug.default)("@ocap/tx-protocols:consume-asset");
|
|
14
|
+
const runner = new _ocap_tx_pipeline.Runner("consume_asset");
|
|
15
|
+
const schema = _arcblock_validator.Joi.object({
|
|
16
|
+
address: _arcblock_validator.Joi.DID().prefix().role("ROLE_ASSET").required(),
|
|
17
|
+
data: _arcblock_validator.Joi.any().optional().allow(null)
|
|
18
|
+
}).options({
|
|
19
|
+
stripUnknown: true,
|
|
20
|
+
noDefaults: false
|
|
21
|
+
});
|
|
22
|
+
runner.use((context, next) => {
|
|
23
|
+
const { itx } = context;
|
|
24
|
+
const { error } = schema.validate(itx);
|
|
25
|
+
if (error) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
|
|
26
|
+
return next();
|
|
27
|
+
});
|
|
28
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
29
|
+
from: "itx.address",
|
|
30
|
+
to: "assetState",
|
|
31
|
+
status: "INVALID_ASSET",
|
|
32
|
+
table: "asset"
|
|
33
|
+
}));
|
|
34
|
+
runner.use((context, next) => {
|
|
35
|
+
const { assetState } = context;
|
|
36
|
+
if (!assetState) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "Asset state not found"));
|
|
37
|
+
const { issuer, consumedTime } = assetState;
|
|
38
|
+
if (!issuer) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "Asset without issuer can not be consumed"));
|
|
39
|
+
if (consumedTime) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Asset already consumed on ${consumedTime}`));
|
|
40
|
+
return next();
|
|
41
|
+
});
|
|
42
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
43
|
+
from: "tx.from",
|
|
44
|
+
to: "senderState",
|
|
45
|
+
status: "INVALID_SENDER_STATE",
|
|
46
|
+
table: "account"
|
|
47
|
+
}));
|
|
48
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
49
|
+
stateKey: "senderState",
|
|
50
|
+
addressKey: "tx.from"
|
|
51
|
+
}));
|
|
52
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
53
|
+
from: "assetState.issuer",
|
|
54
|
+
to: "issuerState",
|
|
55
|
+
status: "INVALID_ISSUER_STATE",
|
|
56
|
+
table: "account"
|
|
57
|
+
}));
|
|
58
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
59
|
+
from: "assetState.owner",
|
|
60
|
+
to: "ownerState",
|
|
61
|
+
status: "INVALID_OWNER_STATE",
|
|
62
|
+
table: "account"
|
|
63
|
+
}));
|
|
64
|
+
runner.use((context, next) => {
|
|
65
|
+
context.signerStates = [context.ownerState, context.issuerState];
|
|
66
|
+
context.signers = [context.ownerState.address, context.issuerState.address];
|
|
67
|
+
return next();
|
|
68
|
+
});
|
|
69
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyMultiSigV2({ signersKey: "signers" }));
|
|
70
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({ signerKey: "signerStates" }));
|
|
71
|
+
runner.use(require_pipes_ensure_gas.default(() => ({
|
|
72
|
+
create: 0,
|
|
73
|
+
update: 2,
|
|
74
|
+
payment: 0
|
|
75
|
+
})));
|
|
76
|
+
runner.use(require_pipes_ensure_cost.default({ attachSenderChanges: true }));
|
|
77
|
+
runner.use(_ocap_tx_pipeline.pipes.TakeStateSnapshot());
|
|
78
|
+
runner.use(async (context, next) => {
|
|
79
|
+
const { tx, itx, txTime, statedb, senderState, senderUpdates, assetState, updateVaults } = context;
|
|
80
|
+
const [newSenderState, newAssetState] = await Promise.all([statedb.account.update(senderState.address, _ocap_state.account.update(senderState, {
|
|
81
|
+
nonce: tx.nonce,
|
|
82
|
+
pk: tx.pk,
|
|
83
|
+
...senderUpdates
|
|
84
|
+
}, context), context), statedb.asset.update(itx.address, _ocap_state.asset.update(assetState, { consumedTime: txTime }, context), context)]);
|
|
85
|
+
if (updateVaults) await updateVaults();
|
|
86
|
+
context.senderState = newSenderState;
|
|
87
|
+
context.assetState = newAssetState;
|
|
88
|
+
debug$1("consume", newAssetState);
|
|
89
|
+
next();
|
|
90
|
+
}, { persistError: true });
|
|
91
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyStateDiff());
|
|
92
|
+
var consume_default = runner;
|
|
93
|
+
|
|
94
|
+
//#endregion
|
|
95
|
+
exports.default = consume_default;
|
|
@@ -0,0 +1,140 @@
|
|
|
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
|
+
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
7
|
+
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
8
|
+
let _arcblock_did_util = require("@arcblock/did-util");
|
|
9
|
+
let _ocap_state = require("@ocap/state");
|
|
10
|
+
let debug = require("debug");
|
|
11
|
+
debug = require_rolldown_runtime.__toESM(debug);
|
|
12
|
+
let _ocap_message = require("@ocap/message");
|
|
13
|
+
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
14
|
+
let lodash_cloneDeep = require("lodash/cloneDeep");
|
|
15
|
+
lodash_cloneDeep = require_rolldown_runtime.__toESM(lodash_cloneDeep);
|
|
16
|
+
|
|
17
|
+
//#region src/protocols/asset/create.ts
|
|
18
|
+
const debug$1 = (0, debug.default)("@ocap/tx-protocols:create-asset");
|
|
19
|
+
const runner = new _ocap_tx_pipeline.Runner("create_asset");
|
|
20
|
+
runner.use((context, next) => {
|
|
21
|
+
const itx = (0, _ocap_message.formatMessage)("CreateAssetTx", context.itx);
|
|
22
|
+
const { error } = _ocap_state.asset.schema.validate(itx);
|
|
23
|
+
if (error) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
|
|
24
|
+
return next();
|
|
25
|
+
});
|
|
26
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyInfo([{
|
|
27
|
+
error: "INVALID_ASSET",
|
|
28
|
+
message: "Asset address is not valid",
|
|
29
|
+
fn: (ctx) => {
|
|
30
|
+
const context = ctx;
|
|
31
|
+
const itx = (0, lodash_cloneDeep.default)(context.itx);
|
|
32
|
+
const decodedData = require_util.decodeAnySafe(itx.data ?? null);
|
|
33
|
+
itx.data = decodedData;
|
|
34
|
+
itx.address = "";
|
|
35
|
+
context.assetData = decodedData;
|
|
36
|
+
context.signers = [itx.issuer].filter(Boolean);
|
|
37
|
+
return (0, _arcblock_did_util.toAssetAddress)(itx) === context.itx.address;
|
|
38
|
+
}
|
|
39
|
+
}]));
|
|
40
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyMultiSigV2({ signersKey: "signers" }));
|
|
41
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
42
|
+
from: "itx.address",
|
|
43
|
+
to: "assetState",
|
|
44
|
+
status: "OK"
|
|
45
|
+
}));
|
|
46
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyInfo([{
|
|
47
|
+
error: "INVALID_ASSET",
|
|
48
|
+
message: "This asset already exist on chain",
|
|
49
|
+
fn: (ctx) => !ctx.assetState
|
|
50
|
+
}]));
|
|
51
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
52
|
+
from: "itx.issuer",
|
|
53
|
+
to: "issuerState",
|
|
54
|
+
status: "INVALID_ISSUER_STATE",
|
|
55
|
+
table: "account"
|
|
56
|
+
}));
|
|
57
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({ signerKey: "issuerState" }));
|
|
58
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
59
|
+
from: "tx.from",
|
|
60
|
+
to: "senderState",
|
|
61
|
+
status: "INVALID_SENDER_STATE",
|
|
62
|
+
table: "account"
|
|
63
|
+
}));
|
|
64
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
65
|
+
stateKey: "senderState",
|
|
66
|
+
addressKey: "tx.from"
|
|
67
|
+
}));
|
|
68
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
69
|
+
from: "tx.delegator",
|
|
70
|
+
to: "delegatorState",
|
|
71
|
+
status: "OK",
|
|
72
|
+
table: "account"
|
|
73
|
+
}));
|
|
74
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
75
|
+
stateKey: "delegatorState",
|
|
76
|
+
addressKey: "tx.delegator"
|
|
77
|
+
}));
|
|
78
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyDelegation({
|
|
79
|
+
type: "signature",
|
|
80
|
+
signerKey: "senderState",
|
|
81
|
+
delegatorKey: "delegatorState",
|
|
82
|
+
getRequirements: require_util.getDelegationRequirements
|
|
83
|
+
}));
|
|
84
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
85
|
+
from: "itx.parent",
|
|
86
|
+
to: "factoryState",
|
|
87
|
+
status: "OK",
|
|
88
|
+
table: "factory"
|
|
89
|
+
}));
|
|
90
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyInfo([{
|
|
91
|
+
error: "CREATE_FROM_FACTORY",
|
|
92
|
+
message: "You can only get asset from factory from acquire or mint",
|
|
93
|
+
fn: (ctx) => {
|
|
94
|
+
const { itx, factoryState } = ctx;
|
|
95
|
+
return !(itx.parent && factoryState);
|
|
96
|
+
},
|
|
97
|
+
persist: true
|
|
98
|
+
}]));
|
|
99
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
100
|
+
from: "itx.parent",
|
|
101
|
+
to: "parentAsset",
|
|
102
|
+
status: "INVALID_ASSET",
|
|
103
|
+
table: "asset"
|
|
104
|
+
}));
|
|
105
|
+
runner.use(require_pipes_ensure_gas.default(() => ({
|
|
106
|
+
create: 1,
|
|
107
|
+
update: 2,
|
|
108
|
+
payment: 0
|
|
109
|
+
})));
|
|
110
|
+
runner.use(require_pipes_ensure_cost.default({ attachSenderChanges: true }));
|
|
111
|
+
runner.use(_ocap_tx_pipeline.pipes.TakeStateSnapshot());
|
|
112
|
+
runner.use(async (context, next) => {
|
|
113
|
+
const { tx, itx, assetData, statedb, senderState, delegatorState, delegationState, senderUpdates, updateVaults } = context;
|
|
114
|
+
const owner = delegatorState ? delegatorState.address : senderState.address;
|
|
115
|
+
const [newSenderState, assetState, newDelegationState] = await Promise.all([
|
|
116
|
+
statedb.account.update(senderState.address, _ocap_state.account.update(senderState, {
|
|
117
|
+
nonce: tx.nonce,
|
|
118
|
+
pk: tx.pk,
|
|
119
|
+
...senderUpdates
|
|
120
|
+
}, context), context),
|
|
121
|
+
statedb.asset.create(itx.address, _ocap_state.asset.create({
|
|
122
|
+
...itx,
|
|
123
|
+
tags: (0, _ocap_util_lib_get_list_field.getListField)(itx, "tags"),
|
|
124
|
+
data: assetData ?? void 0,
|
|
125
|
+
owner
|
|
126
|
+
}, context), context),
|
|
127
|
+
context.isDelegationChanged && delegationState ? statedb.delegation.update(delegationState.address, _ocap_state.delegation.update(delegationState, {}, context), context) : delegationState
|
|
128
|
+
]);
|
|
129
|
+
if (updateVaults) await updateVaults();
|
|
130
|
+
context.senderState = newSenderState;
|
|
131
|
+
context.assetState = assetState;
|
|
132
|
+
context.delegationState = newDelegationState;
|
|
133
|
+
debug$1("createAsset", assetState);
|
|
134
|
+
next();
|
|
135
|
+
}, { persistError: true });
|
|
136
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyStateDiff());
|
|
137
|
+
var create_default = runner;
|
|
138
|
+
|
|
139
|
+
//#endregion
|
|
140
|
+
exports.default = create_default;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
3
|
+
const require_pipes_ensure_cost = require('../../pipes/ensure-cost.cjs');
|
|
4
|
+
const require_pipes_ensure_gas = require('../../pipes/ensure-gas.cjs');
|
|
5
|
+
const require_protocols_asset_pipes_verify_itx_address = require('./pipes/verify-itx-address.cjs');
|
|
6
|
+
const require_protocols_asset_pipes_verify_itx_assets = require('./pipes/verify-itx-assets.cjs');
|
|
7
|
+
const require_protocols_asset_pipes_verify_itx_variables = require('./pipes/verify-itx-variables.cjs');
|
|
8
|
+
const require_protocols_asset_pipes_verify_mint_limit = require('./pipes/verify-mint-limit.cjs');
|
|
9
|
+
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
10
|
+
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
11
|
+
let _ocap_state = require("@ocap/state");
|
|
12
|
+
let debug = require("debug");
|
|
13
|
+
debug = require_rolldown_runtime.__toESM(debug);
|
|
14
|
+
let _arcblock_validator = require("@arcblock/validator");
|
|
15
|
+
|
|
16
|
+
//#region src/protocols/asset/mint.ts
|
|
17
|
+
const debug$1 = (0, debug.default)("@ocap/tx-protocols:mint-asset");
|
|
18
|
+
const runner = new _ocap_tx_pipeline.Runner("mint_asset");
|
|
19
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyMultiSig(0));
|
|
20
|
+
const schema = _arcblock_validator.Joi.object({
|
|
21
|
+
factory: _arcblock_validator.Joi.DID().prefix().role("ROLE_FACTORY").required(),
|
|
22
|
+
address: _arcblock_validator.Joi.DID().prefix().role("ROLE_ASSET").required(),
|
|
23
|
+
assetsList: _arcblock_validator.Joi.array().items(_arcblock_validator.Joi.DID().prefix().role("ROLE_ASSET")).default([]),
|
|
24
|
+
variablesList: _arcblock_validator.Joi.array().items(_arcblock_validator.schemas.variableInput).optional().allow(null).default([]),
|
|
25
|
+
owner: _arcblock_validator.schemas.tokenHolder.required(),
|
|
26
|
+
data: _arcblock_validator.Joi.any().optional().allow(null)
|
|
27
|
+
}).options({
|
|
28
|
+
stripUnknown: true,
|
|
29
|
+
noDefaults: false
|
|
30
|
+
});
|
|
31
|
+
runner.use(({ itx }, next) => {
|
|
32
|
+
const { error } = schema.validate(itx);
|
|
33
|
+
if (error) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
|
|
34
|
+
return next();
|
|
35
|
+
});
|
|
36
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
37
|
+
from: "itx.address",
|
|
38
|
+
to: "duplicateAsset",
|
|
39
|
+
status: "OK",
|
|
40
|
+
table: "asset"
|
|
41
|
+
}));
|
|
42
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyInfo([{
|
|
43
|
+
error: "FORBIDDEN",
|
|
44
|
+
message: "Asset with same address already exists",
|
|
45
|
+
fn: (ctx) => {
|
|
46
|
+
return !ctx.duplicateAsset;
|
|
47
|
+
},
|
|
48
|
+
persist: true
|
|
49
|
+
}]));
|
|
50
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
51
|
+
from: "tx.from",
|
|
52
|
+
to: "senderState",
|
|
53
|
+
status: "INVALID_SENDER_STATE",
|
|
54
|
+
table: "account"
|
|
55
|
+
}));
|
|
56
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
57
|
+
stateKey: "senderState",
|
|
58
|
+
addressKey: "tx.from"
|
|
59
|
+
}));
|
|
60
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
61
|
+
from: "itx.factory",
|
|
62
|
+
to: "factoryState",
|
|
63
|
+
status: "INVALID_FACTORY_STATE",
|
|
64
|
+
table: "factory"
|
|
65
|
+
}));
|
|
66
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
67
|
+
from: "factoryState.owner",
|
|
68
|
+
to: "factoryOwnerState",
|
|
69
|
+
status: "INVALID_ISSUER_STATE",
|
|
70
|
+
table: "account"
|
|
71
|
+
}));
|
|
72
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
73
|
+
from: "factoryState.trustedIssuers",
|
|
74
|
+
to: "issuerStates",
|
|
75
|
+
status: "INVALID_ISSUER_STATE",
|
|
76
|
+
table: "account"
|
|
77
|
+
}));
|
|
78
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
79
|
+
from: "itx.owner",
|
|
80
|
+
to: "ownerState",
|
|
81
|
+
status: "OK",
|
|
82
|
+
table: "account"
|
|
83
|
+
}));
|
|
84
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyBlocked({ stateKeys: ["ownerState"] }));
|
|
85
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyInfo([{
|
|
86
|
+
error: "FORBIDDEN",
|
|
87
|
+
message: "Only factory owner and trusted issuers are allowed to mint",
|
|
88
|
+
fn: (ctx) => {
|
|
89
|
+
const context = ctx;
|
|
90
|
+
const { factoryOwnerState, senderState } = context;
|
|
91
|
+
const issuerStates = context.issuerStates || [];
|
|
92
|
+
return senderState.address === factoryOwnerState.address || issuerStates.some((x) => x.address === senderState.address);
|
|
93
|
+
},
|
|
94
|
+
persist: true
|
|
95
|
+
}]));
|
|
96
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
97
|
+
from: "itx.assetsList",
|
|
98
|
+
to: "assetStates",
|
|
99
|
+
status: "OK",
|
|
100
|
+
table: "asset"
|
|
101
|
+
}));
|
|
102
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
103
|
+
from: "factoryState.input.assets",
|
|
104
|
+
to: "expectedFactoryStates",
|
|
105
|
+
status: "OK",
|
|
106
|
+
table: "factory"
|
|
107
|
+
}));
|
|
108
|
+
runner.use(require_protocols_asset_pipes_verify_mint_limit.default);
|
|
109
|
+
runner.use(require_protocols_asset_pipes_verify_itx_variables.default);
|
|
110
|
+
runner.use(require_protocols_asset_pipes_verify_itx_address.default("mint"));
|
|
111
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyUpdater({
|
|
112
|
+
assetKey: "assetStates",
|
|
113
|
+
ownerKey: "ownerState"
|
|
114
|
+
}));
|
|
115
|
+
runner.use(require_protocols_asset_pipes_verify_itx_assets.default);
|
|
116
|
+
runner.use(require_pipes_ensure_gas.default((context) => {
|
|
117
|
+
const result = {
|
|
118
|
+
create: 1,
|
|
119
|
+
update: 2,
|
|
120
|
+
payment: 0
|
|
121
|
+
};
|
|
122
|
+
if (!context.ownerState) result.create += 1;
|
|
123
|
+
if (context.assetStates) result.update += context.assetStates.length;
|
|
124
|
+
return result;
|
|
125
|
+
}));
|
|
126
|
+
runner.use(require_pipes_ensure_cost.default({ attachSenderChanges: true }));
|
|
127
|
+
runner.use(_ocap_tx_pipeline.pipes.TakeStateSnapshot());
|
|
128
|
+
runner.use(async (context, next) => {
|
|
129
|
+
const { tx, itx, txTime, statedb, senderState, factoryState, mintedAsset, mintedAddress, ownerState, senderUpdates, assetStates = [], updateVaults, ownerAddress } = context;
|
|
130
|
+
const factoryUpdates = { numMinted: factoryState.numMinted + 1 };
|
|
131
|
+
const [newSenderState, newReceiverState, assetState, newFactoryState, newAssetStates] = await Promise.all([
|
|
132
|
+
statedb.account.update(senderState.address, _ocap_state.account.update(senderState, {
|
|
133
|
+
nonce: tx.nonce,
|
|
134
|
+
pk: tx.pk,
|
|
135
|
+
...senderUpdates
|
|
136
|
+
}, context), context),
|
|
137
|
+
ownerState ? Promise.resolve(ownerState) : statedb.account.create(ownerAddress, _ocap_state.account.create({ address: ownerAddress }, context), context),
|
|
138
|
+
statedb.asset.create(itx.address, _ocap_state.asset.create({
|
|
139
|
+
...mintedAsset,
|
|
140
|
+
owner: ownerAddress,
|
|
141
|
+
address: mintedAddress
|
|
142
|
+
}, context), context),
|
|
143
|
+
statedb.factory.update(factoryState.address, _ocap_state.factory.update(factoryState, factoryUpdates, context), context),
|
|
144
|
+
Promise.all(assetStates.map((x) => statedb.asset.update(x.address, _ocap_state.asset.update(x, { consumedTime: txTime }, context), context)))
|
|
145
|
+
]);
|
|
146
|
+
if (updateVaults) await updateVaults();
|
|
147
|
+
context.senderState = newSenderState;
|
|
148
|
+
context.receiverState = newReceiverState;
|
|
149
|
+
context.assetState = assetState;
|
|
150
|
+
context.factoryState = newFactoryState;
|
|
151
|
+
context.assetStates = newAssetStates;
|
|
152
|
+
debug$1("mint", assetState);
|
|
153
|
+
next();
|
|
154
|
+
}, { persistError: true });
|
|
155
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyStateDiff());
|
|
156
|
+
var mint_default = runner;
|
|
157
|
+
|
|
158
|
+
//#endregion
|
|
159
|
+
exports.default = mint_default;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
3
|
+
const require_protocols_asset_calls_transfer = require('../calls/transfer.cjs');
|
|
4
|
+
const require_protocols_asset_calls_transfer_token = require('../calls/transfer-token.cjs');
|
|
5
|
+
let lodash_cloneDeep = require("lodash/cloneDeep");
|
|
6
|
+
lodash_cloneDeep = require_rolldown_runtime.__toESM(lodash_cloneDeep);
|
|
7
|
+
|
|
8
|
+
//#region src/protocols/asset/pipes/exec-mint-hook.ts
|
|
9
|
+
const contractCalls = {
|
|
10
|
+
transfer: require_protocols_asset_calls_transfer.default,
|
|
11
|
+
transferToken: require_protocols_asset_calls_transfer_token.default
|
|
12
|
+
};
|
|
13
|
+
const execMintHook = async (context, next) => {
|
|
14
|
+
const { statedb, factoryState, tokenUpdates, config } = context;
|
|
15
|
+
const factory = factoryState;
|
|
16
|
+
if (factory.settlement === "instant") {
|
|
17
|
+
const mintHook = factory.hooks.find((x) => x.name === "mint");
|
|
18
|
+
if (mintHook && mintHook.type === "contract") {
|
|
19
|
+
context.updatedAccounts = context.updatedAccounts || [];
|
|
20
|
+
const clone = (0, lodash_cloneDeep.default)(mintHook.compiled);
|
|
21
|
+
const mintHookStates = {};
|
|
22
|
+
for (const x of clone) {
|
|
23
|
+
if (x.call === "transfer") {
|
|
24
|
+
x.call = "transferToken";
|
|
25
|
+
x.args.tokenAddress = config.token.address;
|
|
26
|
+
}
|
|
27
|
+
const { updateSet } = await contractCalls[x.call].runAsync({
|
|
28
|
+
states: context.states,
|
|
29
|
+
statedb,
|
|
30
|
+
txn: context.txn,
|
|
31
|
+
txTime: context.txTime,
|
|
32
|
+
txHash: context.txHash,
|
|
33
|
+
logger: context.logger,
|
|
34
|
+
args: x.args
|
|
35
|
+
});
|
|
36
|
+
mintHookStates[updateSet.address] = await statedb.account.update(updateSet.address, updateSet.updates, context);
|
|
37
|
+
context.updatedAccounts.push(updateSet);
|
|
38
|
+
}
|
|
39
|
+
context.mintHookStates = Object.values(mintHookStates);
|
|
40
|
+
}
|
|
41
|
+
} else if (tokenUpdates) {
|
|
42
|
+
const updates = tokenUpdates;
|
|
43
|
+
if (updates.tokens) context.receipts = [{
|
|
44
|
+
address: factory.address,
|
|
45
|
+
changes: Object.keys(updates.tokens).map((x) => ({
|
|
46
|
+
target: x,
|
|
47
|
+
action: "transfer",
|
|
48
|
+
value: updates.tokens[x]
|
|
49
|
+
})).filter((x) => Number(x.value) > 0)
|
|
50
|
+
}];
|
|
51
|
+
}
|
|
52
|
+
next();
|
|
53
|
+
};
|
|
54
|
+
var exec_mint_hook_default = execMintHook;
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
exports.default = exec_mint_hook_default;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { IAccountState, IAccountUpdate, IAssetFactoryState, IDecodedContext, IStateDB, TTransactionReceipt } from "@ocap/types";
|
|
2
|
+
import { PipeFunction } from "@ocap/tx-pipeline";
|
|
3
|
+
|
|
4
|
+
//#region src/protocols/asset/pipes/exec-mint-hook.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Context type for exec-mint-hook pipe.
|
|
8
|
+
* Requires: statedb, factoryState, config
|
|
9
|
+
* Optional: tokenUpdates
|
|
10
|
+
* Sets: updatedAccounts, mintHookStates, receipts
|
|
11
|
+
*/
|
|
12
|
+
type ExecMintHookContext = IDecodedContext & {
|
|
13
|
+
statedb: IStateDB;
|
|
14
|
+
factoryState?: IAssetFactoryState;
|
|
15
|
+
tokenUpdates?: Record<string, string>;
|
|
16
|
+
updatedAccounts?: IAccountUpdate[];
|
|
17
|
+
mintHookStates?: IAccountState[];
|
|
18
|
+
receipts?: TTransactionReceipt[];
|
|
19
|
+
states?: unknown;
|
|
20
|
+
txn?: unknown;
|
|
21
|
+
};
|
|
22
|
+
declare const execMintHook: PipeFunction<ExecMintHookContext>;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { execMintHook as default };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
3
|
+
let _ocap_util = require("@ocap/util");
|
|
4
|
+
let _ocap_util_lib_create_sorted_list = require("@ocap/util/lib/create-sorted-list");
|
|
5
|
+
let lodash_uniqBy = require("lodash/uniqBy");
|
|
6
|
+
lodash_uniqBy = require_rolldown_runtime.__toESM(lodash_uniqBy);
|
|
7
|
+
|
|
8
|
+
//#region src/protocols/asset/pipes/extract-factory-tokens.ts
|
|
9
|
+
const extract_factory_tokens = (context, next) => {
|
|
10
|
+
const { factoryState, config } = context;
|
|
11
|
+
const input = factoryState.input;
|
|
12
|
+
context.factoryTokens = [...input.tokens];
|
|
13
|
+
const factoryTokens = context.factoryTokens;
|
|
14
|
+
if (!factoryTokens.find((x) => x.address === config.token.address) && new _ocap_util.BN(input.value).gt(new _ocap_util.BN(0))) factoryTokens.push({
|
|
15
|
+
address: config.token.address,
|
|
16
|
+
value: input.value
|
|
17
|
+
});
|
|
18
|
+
context.factoryTokens = (0, lodash_uniqBy.default)(context.factoryTokens, "address");
|
|
19
|
+
context.tokenAddress = (0, _ocap_util_lib_create_sorted_list.createSortedList)((context.factoryTokens || []).map((x) => x.address));
|
|
20
|
+
next();
|
|
21
|
+
};
|
|
22
|
+
var extract_factory_tokens_default = extract_factory_tokens;
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
exports.default = extract_factory_tokens_default;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { IAssetFactoryState, IBaseContext } from "@ocap/types";
|
|
2
|
+
import { PipeFunction } from "@ocap/tx-pipeline";
|
|
3
|
+
|
|
4
|
+
//#region src/protocols/asset/pipes/extract-factory-tokens.d.ts
|
|
5
|
+
interface TokenInput {
|
|
6
|
+
address: string;
|
|
7
|
+
value: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Context type for extract-factory-tokens pipe.
|
|
11
|
+
* Requires: factoryState, config
|
|
12
|
+
* Sets: factoryTokens, tokenAddress (array of token addresses)
|
|
13
|
+
*/
|
|
14
|
+
type ExtractFactoryTokensContext = IBaseContext & {
|
|
15
|
+
factoryState?: IAssetFactoryState;
|
|
16
|
+
factoryTokens?: TokenInput[];
|
|
17
|
+
tokenAddress?: string[];
|
|
18
|
+
};
|
|
19
|
+
declare const extract_factory_tokens: PipeFunction<ExtractFactoryTokensContext>;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { TokenInput, extract_factory_tokens as default };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
3
|
+
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
4
|
+
let debug = require("debug");
|
|
5
|
+
debug = require_rolldown_runtime.__toESM(debug);
|
|
6
|
+
let _ocap_asset = require("@ocap/asset");
|
|
7
|
+
|
|
8
|
+
//#region src/protocols/asset/pipes/verify-itx-address.ts
|
|
9
|
+
const debug$1 = (0, debug.default)("@ocap/tx-protocols:pipes:verify-itx-address");
|
|
10
|
+
const verify_itx_address = (mode) => (context, next) => {
|
|
11
|
+
const { itx, senderState, factoryState, delegatorState, factoryInputs } = context;
|
|
12
|
+
const sender = senderState;
|
|
13
|
+
const factory = factoryState;
|
|
14
|
+
const inputs = factoryInputs;
|
|
15
|
+
let issuer = null;
|
|
16
|
+
let owner = null;
|
|
17
|
+
if (mode === "acquire-v2") {
|
|
18
|
+
owner = delegatorState || sender;
|
|
19
|
+
issuer = itx.issuer;
|
|
20
|
+
context.assetOwner = owner;
|
|
21
|
+
} else if (mode === "acquire-v3") {
|
|
22
|
+
owner = { address: itx.owner };
|
|
23
|
+
issuer = itx.issuer;
|
|
24
|
+
} else if (mode === "mint") {
|
|
25
|
+
owner = { address: itx.owner };
|
|
26
|
+
issuer = {
|
|
27
|
+
id: sender.address,
|
|
28
|
+
pk: sender.pk,
|
|
29
|
+
name: sender.moniker
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const minted = (0, _ocap_asset.mintFromFactory)({
|
|
33
|
+
factory,
|
|
34
|
+
inputs,
|
|
35
|
+
owner: owner.address,
|
|
36
|
+
issuer
|
|
37
|
+
});
|
|
38
|
+
if (minted.address !== itx.address) {
|
|
39
|
+
debug$1("asset address mismatch", {
|
|
40
|
+
owner,
|
|
41
|
+
issuer,
|
|
42
|
+
minted,
|
|
43
|
+
itx,
|
|
44
|
+
factoryInputs,
|
|
45
|
+
factoryState,
|
|
46
|
+
senderState,
|
|
47
|
+
delegatorState
|
|
48
|
+
});
|
|
49
|
+
return next(new _ocap_util_lib_error.CustomError("INVALID_ASSET", "Invalid itx.address: does not match with minted asset address"));
|
|
50
|
+
}
|
|
51
|
+
context.ownerAddress = owner.address;
|
|
52
|
+
context.mintedAsset = minted.asset;
|
|
53
|
+
context.mintedAddress = minted.address;
|
|
54
|
+
return next();
|
|
55
|
+
};
|
|
56
|
+
var verify_itx_address_default = verify_itx_address;
|
|
57
|
+
|
|
58
|
+
//#endregion
|
|
59
|
+
exports.default = verify_itx_address_default;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { IAccountState, IAssetFactoryState, IDecodedContext } from "@ocap/types";
|
|
2
|
+
import { PipeFunction } from "@ocap/tx-pipeline";
|
|
3
|
+
|
|
4
|
+
//#region src/protocols/asset/pipes/verify-itx-address.d.ts
|
|
5
|
+
type VerifyItxAddressMode = 'acquire-v2' | 'acquire-v3' | 'mint';
|
|
6
|
+
/**
|
|
7
|
+
* Inner transaction type for acquire/mint operations
|
|
8
|
+
*/
|
|
9
|
+
interface AcquireMintItx {
|
|
10
|
+
address: string;
|
|
11
|
+
issuer?: unknown;
|
|
12
|
+
owner?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Context type for verify-itx-address pipe.
|
|
16
|
+
* Requires: itx, factoryState, factoryInputs
|
|
17
|
+
* Optional: senderState, delegatorState
|
|
18
|
+
* Sets: ownerAddress, mintedAsset, mintedAddress, assetOwner (for acquire-v2)
|
|
19
|
+
*/
|
|
20
|
+
type VerifyItxAddressContext = IDecodedContext<AcquireMintItx> & {
|
|
21
|
+
senderState?: IAccountState;
|
|
22
|
+
delegatorState?: IAccountState;
|
|
23
|
+
factoryState?: IAssetFactoryState;
|
|
24
|
+
factoryInputs?: Record<string, unknown>;
|
|
25
|
+
ownerAddress?: string;
|
|
26
|
+
mintedAsset?: Record<string, unknown>;
|
|
27
|
+
mintedAddress?: string;
|
|
28
|
+
assetOwner?: IAccountState;
|
|
29
|
+
};
|
|
30
|
+
declare const verify_itx_address: (mode: VerifyItxAddressMode) => PipeFunction<VerifyItxAddressContext>;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { verify_itx_address as default };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
3
|
+
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
4
|
+
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
5
|
+
|
|
6
|
+
//#region src/protocols/asset/pipes/verify-itx-assets.ts
|
|
7
|
+
const verify_itx_assets = (context, next) => {
|
|
8
|
+
const { factoryState, expectedFactoryStates = [], assetStates: actualAssetStates = [], itx } = context;
|
|
9
|
+
const expectedAssets = factoryState.input.assets;
|
|
10
|
+
const assetStates = actualAssetStates;
|
|
11
|
+
if (expectedAssets.length === 0) return next();
|
|
12
|
+
if ((0, _ocap_util_lib_get_list_field.getListField)(itx, "assets").length > assetStates.length) return next(new _ocap_util_lib_error.CustomError("INVALID_ASSET", "Input asset does not exist on chain"));
|
|
13
|
+
if (expectedFactoryStates.length === expectedAssets.length) {
|
|
14
|
+
if (assetStates.every((x) => x.parent && expectedAssets.includes(x.parent)) === false) return next(new _ocap_util_lib_error.CustomError("INVALID_ASSET", "Input asset not minted from any of factory.input.assets"));
|
|
15
|
+
if (assetStates.every((x) => !x.consumedTime) === false) return next(new _ocap_util_lib_error.CustomError("INVALID_ASSET", "Some input asset already consumed"));
|
|
16
|
+
return next();
|
|
17
|
+
}
|
|
18
|
+
for (const address of expectedAssets) {
|
|
19
|
+
const plainAsset = assetStates.find((x) => x.address === address);
|
|
20
|
+
if (plainAsset) {
|
|
21
|
+
if (plainAsset.consumedTime) return next(new _ocap_util_lib_error.CustomError("INVALID_ASSET", `Input asset ${address} already consumed`));
|
|
22
|
+
} else if (!assetStates.find((x) => x.parent === address)) return next(new _ocap_util_lib_error.CustomError("INVALID_ASSET", `Input asset not found ${address}`));
|
|
23
|
+
}
|
|
24
|
+
return next();
|
|
25
|
+
};
|
|
26
|
+
var verify_itx_assets_default = verify_itx_assets;
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
exports.default = verify_itx_assets_default;
|