@ocap/tx-protocols 1.28.8 → 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,260 @@
|
|
|
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_verify_icon = require('./pipes/verify-icon.cjs');
|
|
7
|
+
const require_protocols_token_factory_pipes_verify_ownership = require('./pipes/verify-ownership.cjs');
|
|
8
|
+
const require_protocols_token_factory_pipes_verify_url = require('./pipes/verify-url.cjs');
|
|
9
|
+
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
10
|
+
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
11
|
+
let _arcblock_did_util = require("@arcblock/did-util");
|
|
12
|
+
let _ocap_state = require("@ocap/state");
|
|
13
|
+
let _ocap_util = require("@ocap/util");
|
|
14
|
+
let debug = require("debug");
|
|
15
|
+
debug = require_rolldown_runtime.__toESM(debug);
|
|
16
|
+
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
17
|
+
let lodash_cloneDeep = require("lodash/cloneDeep");
|
|
18
|
+
lodash_cloneDeep = require_rolldown_runtime.__toESM(lodash_cloneDeep);
|
|
19
|
+
let _arcblock_validator = require("@arcblock/validator");
|
|
20
|
+
let lodash_uniq = require("lodash/uniq");
|
|
21
|
+
lodash_uniq = require_rolldown_runtime.__toESM(lodash_uniq);
|
|
22
|
+
let lodash_isEmpty = require("lodash/isEmpty");
|
|
23
|
+
lodash_isEmpty = require_rolldown_runtime.__toESM(lodash_isEmpty);
|
|
24
|
+
|
|
25
|
+
//#region src/protocols/token-factory/create.ts
|
|
26
|
+
const debug$1 = (0, debug.default)("@ocap/tx-protocols:create-token-factory");
|
|
27
|
+
const runner = new _ocap_tx_pipeline.Runner("create_token_factory");
|
|
28
|
+
const isTest = process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test" || process.env.CI;
|
|
29
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyMultiSig(0));
|
|
30
|
+
const schema = _arcblock_validator.Joi.object({
|
|
31
|
+
address: _arcblock_validator.Joi.DID().prefix().role("ROLE_TOKEN_FACTORY").required(),
|
|
32
|
+
feeRate: _arcblock_validator.Joi.number().min(0).max(2e3).required(),
|
|
33
|
+
curve: _arcblock_validator.Joi.when("token.type", {
|
|
34
|
+
is: "CreditToken",
|
|
35
|
+
then: _arcblock_validator.Joi.valid(null).optional().messages({ "any.only": "Should not provide curve for CreditToken" }),
|
|
36
|
+
otherwise: _ocap_state.tokenFactory.curveSchema.required()
|
|
37
|
+
}),
|
|
38
|
+
reserveAddress: _arcblock_validator.Joi.DID().prefix().role("ROLE_TOKEN").required(),
|
|
39
|
+
token: _arcblock_validator.Joi.object({
|
|
40
|
+
name: _arcblock_validator.Joi.string().min(1).max(32).required(),
|
|
41
|
+
description: _arcblock_validator.Joi.string().min(16).max(128).required(),
|
|
42
|
+
symbol: _arcblock_validator.Joi.string().min(2).max(6).uppercase().required(),
|
|
43
|
+
unit: _arcblock_validator.Joi.string().min(1).max(6).lowercase().required(),
|
|
44
|
+
decimal: _arcblock_validator.Joi.number().min(2).max(18).required(),
|
|
45
|
+
icon: _arcblock_validator.Joi.string().optional().allow(null, ""),
|
|
46
|
+
maxTotalSupply: _arcblock_validator.Joi.alternatives().try(_arcblock_validator.Joi.BN().greater(0), _arcblock_validator.Joi.string().valid("")).optional().allow(null),
|
|
47
|
+
website: _arcblock_validator.Joi.string().uri({
|
|
48
|
+
scheme: isTest ? ["http", "https"] : ["https"],
|
|
49
|
+
allowRelative: false
|
|
50
|
+
}).max(256).optional().allow(null, ""),
|
|
51
|
+
metadata: _arcblock_validator.Joi.any().required(),
|
|
52
|
+
spendersList: _arcblock_validator.Joi.array().items(_arcblock_validator.Joi.DID().prefix()).max(30).optional().allow(null).default(null),
|
|
53
|
+
mintersList: _arcblock_validator.Joi.array().items(_arcblock_validator.Joi.DID().prefix()).max(30).optional().allow(null).default(null),
|
|
54
|
+
type: _arcblock_validator.Joi.string().valid("CreditToken", "BondingCurveToken").required()
|
|
55
|
+
}).required(),
|
|
56
|
+
data: _arcblock_validator.Joi.any().optional().allow(null)
|
|
57
|
+
}).options({
|
|
58
|
+
stripUnknown: true,
|
|
59
|
+
noDefaults: false
|
|
60
|
+
});
|
|
61
|
+
runner.use((context, next) => {
|
|
62
|
+
const { error, value } = schema.validate(context.itx);
|
|
63
|
+
if (error) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
|
|
64
|
+
context.itx.curve = value.curve;
|
|
65
|
+
const itxToken = context.itx.token;
|
|
66
|
+
if (itxToken.metadata) {
|
|
67
|
+
const metadata = require_util.decodeAnySafe(itxToken.metadata ?? null);
|
|
68
|
+
const { error: metadataError, value: metadataValue } = _ocap_state.token.metadataSchema.validate(metadata?.value);
|
|
69
|
+
if (metadataError) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Invalid metadata: ${metadataError.message}`));
|
|
70
|
+
itxToken.metadata = {
|
|
71
|
+
...metadata,
|
|
72
|
+
value: metadataValue
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
const tokenWithLists = itxToken;
|
|
76
|
+
const spendersList = (0, _ocap_util_lib_get_list_field.getListField)(itxToken, "spenders");
|
|
77
|
+
itxToken.spenders = spendersList?.length ? (0, lodash_uniq.default)(spendersList) : null;
|
|
78
|
+
delete tokenWithLists.spendersList;
|
|
79
|
+
const mintersList = (0, _ocap_util_lib_get_list_field.getListField)(itxToken, "minters");
|
|
80
|
+
itxToken.minters = mintersList?.length ? (0, lodash_uniq.default)(mintersList) : null;
|
|
81
|
+
delete tokenWithLists.mintersList;
|
|
82
|
+
return next();
|
|
83
|
+
});
|
|
84
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyInfo([
|
|
85
|
+
{
|
|
86
|
+
error: "INVALID_TOKEN",
|
|
87
|
+
message: "Token address is not valid",
|
|
88
|
+
fn: (ctx) => {
|
|
89
|
+
const itxToken = ctx.itx.token;
|
|
90
|
+
return (0, _arcblock_did_util.toTokenAddress)({
|
|
91
|
+
...itxToken,
|
|
92
|
+
address: ""
|
|
93
|
+
}) === itxToken.address;
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
error: "INVALID_TOKEN_FACTORY",
|
|
98
|
+
message: "Token factory address is not valid",
|
|
99
|
+
fn: (ctx) => {
|
|
100
|
+
const context = ctx;
|
|
101
|
+
const itx = (0, lodash_cloneDeep.default)(context.itx);
|
|
102
|
+
itx.data = require_util.decodeAnySafe(itx.data ?? null);
|
|
103
|
+
itx.address = "";
|
|
104
|
+
return (0, _arcblock_did_util.toTokenFactoryAddress)(itx) === context.itx.address;
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
error: "INVALID_RESERVE_ADDRESS",
|
|
109
|
+
message: "Reserve address is not valid",
|
|
110
|
+
fn: (ctx) => {
|
|
111
|
+
const context = ctx;
|
|
112
|
+
return context.itx.reserveAddress === context.config.token.address;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
]));
|
|
116
|
+
runner.use(require_protocols_token_factory_pipes_verify_icon.default());
|
|
117
|
+
runner.use(require_protocols_token_factory_pipes_verify_url.default({ urlKeys: ["itx.token.website", "itx.token.metadata.value.communityUrl"] }));
|
|
118
|
+
runner.use(require_protocols_token_factory_pipes_verify_ownership.default({ tokenKey: "itx.token" }));
|
|
119
|
+
runner.use((context, next) => {
|
|
120
|
+
const { reservedSymbols = [] } = context.config;
|
|
121
|
+
const { symbol } = context.itx.token;
|
|
122
|
+
if (reservedSymbols.includes(symbol.toUpperCase())) return next(new _ocap_util_lib_error.CustomError("INVALID_SYMBOL", `Token symbol can not be ${symbol}`));
|
|
123
|
+
return next();
|
|
124
|
+
});
|
|
125
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
126
|
+
from: "itx.address",
|
|
127
|
+
to: "tokenFactoryState",
|
|
128
|
+
table: "tokenFactory",
|
|
129
|
+
status: "OK"
|
|
130
|
+
}));
|
|
131
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyInfo([{
|
|
132
|
+
error: "DUPLICATE_TOKEN_FACTORY",
|
|
133
|
+
message: "Token factory address already exists on chain",
|
|
134
|
+
fn: (ctx) => {
|
|
135
|
+
return (0, lodash_isEmpty.default)(ctx.tokenFactoryState);
|
|
136
|
+
}
|
|
137
|
+
}]));
|
|
138
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
139
|
+
from: "itx.token.address",
|
|
140
|
+
to: "tokenState",
|
|
141
|
+
table: "token",
|
|
142
|
+
status: "OK"
|
|
143
|
+
}));
|
|
144
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyInfo([{
|
|
145
|
+
error: "DUPLICATE_TOKEN",
|
|
146
|
+
message: "Token address already exists on chain",
|
|
147
|
+
fn: (ctx) => {
|
|
148
|
+
return (0, lodash_isEmpty.default)(ctx.tokenState);
|
|
149
|
+
}
|
|
150
|
+
}]));
|
|
151
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
152
|
+
from: "tx.from",
|
|
153
|
+
to: "senderState",
|
|
154
|
+
status: "INVALID_SENDER_STATE",
|
|
155
|
+
table: "account"
|
|
156
|
+
}));
|
|
157
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
158
|
+
stateKey: "senderState",
|
|
159
|
+
addressKey: "tx.from"
|
|
160
|
+
}));
|
|
161
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyBlocked({ stateKeys: ["senderState"] }));
|
|
162
|
+
runner.use((context, next) => {
|
|
163
|
+
const { tx, itx } = context;
|
|
164
|
+
const sender = tx.delegator || tx.from;
|
|
165
|
+
const receiver = context.config.token.address;
|
|
166
|
+
context.stakeAddress = (0, _arcblock_did_util.toStakeAddress)(sender, receiver, itx.token.symbol);
|
|
167
|
+
return next();
|
|
168
|
+
});
|
|
169
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
170
|
+
from: "stakeAddress",
|
|
171
|
+
to: "stakeState",
|
|
172
|
+
status: "INVALID_STAKE_STATE",
|
|
173
|
+
table: "stake"
|
|
174
|
+
}));
|
|
175
|
+
runner.use((context, next) => {
|
|
176
|
+
const { stakeState, config, itx } = context;
|
|
177
|
+
if (stakeState.revocable === false) return next(new _ocap_util_lib_error.CustomError("INVALID_STAKE_STATE", `Staking for token creating already locked: ${stakeState.address}`));
|
|
178
|
+
const actualStake = new _ocap_util.BN(stakeState.tokens[config.token.address] || 0);
|
|
179
|
+
const requiredStake = (0, _ocap_util.fromTokenToUnit)(itx.token.type === "CreditToken" ? config.transaction.txStake.createCreditToken : config.transaction.txStake.createToken, config.token.decimal);
|
|
180
|
+
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}`));
|
|
181
|
+
return next();
|
|
182
|
+
});
|
|
183
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
184
|
+
from: "tx.delegator",
|
|
185
|
+
to: "delegatorState",
|
|
186
|
+
status: "OK",
|
|
187
|
+
table: "account"
|
|
188
|
+
}));
|
|
189
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
190
|
+
stateKey: "delegatorState",
|
|
191
|
+
addressKey: "tx.delegator"
|
|
192
|
+
}));
|
|
193
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyDelegation({
|
|
194
|
+
type: "signature",
|
|
195
|
+
signerKey: "senderState",
|
|
196
|
+
delegatorKey: "delegatorState",
|
|
197
|
+
getRequirements: require_util.getDelegationRequirements
|
|
198
|
+
}));
|
|
199
|
+
runner.use(async function EnsureTokenSymbol(context, next) {
|
|
200
|
+
const itxToken = context.itx.token;
|
|
201
|
+
if (await context.statedb.token.existBySymbol(itxToken.symbol, context)) return next(new _ocap_util_lib_error.CustomError("DUPLICATE_SYMBOL", "Token symbol already exists"));
|
|
202
|
+
return next();
|
|
203
|
+
}, { persistError: true });
|
|
204
|
+
runner.use(require_pipes_ensure_gas.default((context) => {
|
|
205
|
+
const result = {
|
|
206
|
+
create: 2,
|
|
207
|
+
update: 2,
|
|
208
|
+
payment: 0
|
|
209
|
+
};
|
|
210
|
+
if (context.isDelegationChanged) result.update += 1;
|
|
211
|
+
return result;
|
|
212
|
+
}));
|
|
213
|
+
runner.use(require_pipes_ensure_cost.default({ attachSenderChanges: true }));
|
|
214
|
+
runner.use(_ocap_tx_pipeline.pipes.TakeStateSnapshot());
|
|
215
|
+
runner.use(async (context, next) => {
|
|
216
|
+
const { tx, itx, statedb, senderState, delegatorState, delegationState, senderChange, stakeState, stakeAddress, updateVaults, config } = context;
|
|
217
|
+
const data = require_util.decodeAnySafe(itx.data ?? null);
|
|
218
|
+
const owner = delegatorState ? delegatorState.address : senderState.address;
|
|
219
|
+
const itxToken = itx.token;
|
|
220
|
+
const { tokens: senderTokens = {} } = senderState;
|
|
221
|
+
const senderUpdates = senderChange ? require_util.applyTokenChange({ tokens: senderTokens }, senderChange) : { tokens: senderTokens };
|
|
222
|
+
const [newSenderState, newTokenState, newTokenFactoryState, newDelegationState, newStakeState] = await Promise.all([
|
|
223
|
+
statedb.account.update(senderState.address, _ocap_state.account.update(senderState, {
|
|
224
|
+
nonce: tx.nonce,
|
|
225
|
+
pk: tx.pk,
|
|
226
|
+
...senderUpdates
|
|
227
|
+
}, context), context),
|
|
228
|
+
statedb.token.create(itxToken.address, _ocap_state.token.create({
|
|
229
|
+
...(0, lodash_cloneDeep.default)(itxToken),
|
|
230
|
+
totalSupply: "0",
|
|
231
|
+
initialSupply: "0",
|
|
232
|
+
issuer: owner,
|
|
233
|
+
tokenFactoryAddress: itx.address
|
|
234
|
+
}, context), context),
|
|
235
|
+
statedb.tokenFactory.create(itx.address, _ocap_state.tokenFactory.create({
|
|
236
|
+
...(0, lodash_cloneDeep.default)(itx),
|
|
237
|
+
owner,
|
|
238
|
+
tokenAddress: itxToken.address,
|
|
239
|
+
data
|
|
240
|
+
}, context), context),
|
|
241
|
+
context.isDelegationChanged ? statedb.delegation.update(delegationState.address, _ocap_state.delegation.update(delegationState, {}, context), context) : delegationState,
|
|
242
|
+
statedb.stake.update(stakeAddress, _ocap_state.stake.update(stakeState, {
|
|
243
|
+
revocable: false,
|
|
244
|
+
revokeWaitingPeriod: config.transaction.txStake.createTokenLockPeriod
|
|
245
|
+
}, context), context)
|
|
246
|
+
]);
|
|
247
|
+
if (updateVaults) await updateVaults();
|
|
248
|
+
context.senderState = newSenderState;
|
|
249
|
+
context.tokenState = newTokenState;
|
|
250
|
+
context.tokenFactoryState = newTokenFactoryState;
|
|
251
|
+
context.delegationState = newDelegationState;
|
|
252
|
+
context.stakeState = newStakeState;
|
|
253
|
+
debug$1("create token factory", newTokenFactoryState);
|
|
254
|
+
next();
|
|
255
|
+
}, { persistError: true });
|
|
256
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyStateDiff());
|
|
257
|
+
var create_default = runner;
|
|
258
|
+
|
|
259
|
+
//#endregion
|
|
260
|
+
exports.default = create_default;
|
|
@@ -0,0 +1,237 @@
|
|
|
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/mint.ts
|
|
17
|
+
const runner = new _ocap_tx_pipeline.Runner("mint_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
|
+
amount: _arcblock_validator.Joi.BN().greater(0).required(),
|
|
22
|
+
data: _arcblock_validator.Joi.any().optional().allow(null),
|
|
23
|
+
inputsList: _arcblock_validator.schemas.multiInput.optional()
|
|
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
|
+
}), { shouldSkip: (ctx) => !ctx.tokenFactoryState?.curve });
|
|
52
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyListSize({ listKey: [
|
|
53
|
+
"inputs",
|
|
54
|
+
"senders",
|
|
55
|
+
"tokens",
|
|
56
|
+
"assets"
|
|
57
|
+
] }), { shouldSkip: (ctx) => !ctx.tokenFactoryState?.curve });
|
|
58
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyMultiSigV2({ signersKey: "senders" }), { shouldSkip: (ctx) => !ctx.tokenFactoryState?.curve });
|
|
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.reserveAddress) && !assetsList.length;
|
|
65
|
+
})) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Inputs only accept ${tokenFactoryState.reserveAddress}`));
|
|
66
|
+
return next();
|
|
67
|
+
}, { shouldSkip: (ctx) => !ctx.tokenFactoryState?.curve });
|
|
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.ExtractState({
|
|
75
|
+
from: "senders",
|
|
76
|
+
to: "signerStates",
|
|
77
|
+
status: "INVALID_SIGNER_STATE",
|
|
78
|
+
table: "account"
|
|
79
|
+
}), { shouldSkip: (ctx) => !ctx.tokenFactoryState?.curve });
|
|
80
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
81
|
+
signerKey: "signerStates",
|
|
82
|
+
stateKey: "senderState",
|
|
83
|
+
addressKey: "tx.from"
|
|
84
|
+
}), { shouldSkip: (ctx) => !ctx.tokenFactoryState?.curve });
|
|
85
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
86
|
+
from: "itx.receiver",
|
|
87
|
+
to: "receiverState",
|
|
88
|
+
status: "OK",
|
|
89
|
+
table: "account"
|
|
90
|
+
}));
|
|
91
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
92
|
+
stateKey: "receiverState",
|
|
93
|
+
addressKey: "itx.receiver"
|
|
94
|
+
}));
|
|
95
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyBlocked({ stateKeys: ["signerStates", "receiverState"] }));
|
|
96
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
97
|
+
from: "tokenFactoryState.owner",
|
|
98
|
+
to: "ownerState",
|
|
99
|
+
status: "INVALID_OWNER_STATE",
|
|
100
|
+
table: "account"
|
|
101
|
+
}));
|
|
102
|
+
runner.use(_ocap_tx_pipeline.pipes.verifyTokenAccess({
|
|
103
|
+
statesKey: "tokenState",
|
|
104
|
+
listFieldKey: "minters",
|
|
105
|
+
accountKeys: ["senderState"],
|
|
106
|
+
errorMessage: "Account {address} is not allowed to mint token {tokenAddress}"
|
|
107
|
+
}));
|
|
108
|
+
runner.use(require_protocols_token_factory_pipes_calc_reserve.default({
|
|
109
|
+
tokenFactoryKey: "tokenFactoryState",
|
|
110
|
+
tokenStateKey: "tokenState",
|
|
111
|
+
reserveKey: "reserveAmount",
|
|
112
|
+
amountKey: "itx.amount"
|
|
113
|
+
}), { shouldSkip: (ctx) => !ctx.tokenFactoryState?.curve });
|
|
114
|
+
runner.use((context, next) => {
|
|
115
|
+
const { tokenState, itx } = context;
|
|
116
|
+
if (tokenState.maxTotalSupply) {
|
|
117
|
+
const availableSupply = new _ocap_util.BN(tokenState.maxTotalSupply).sub(new _ocap_util.BN(tokenState.totalSupply));
|
|
118
|
+
if (new _ocap_util.BN(itx.amount).gt(availableSupply)) return next(new _ocap_util_lib_error.CustomError("INVALID_TOKEN", `Maximum mintable tokens are ${(0, _ocap_util.fromUnitToToken)(availableSupply, tokenState.decimal)} ${tokenState.symbol}`));
|
|
119
|
+
}
|
|
120
|
+
next();
|
|
121
|
+
});
|
|
122
|
+
runner.use((context, next) => {
|
|
123
|
+
const { reserveAmount, reserveFee, inputs = [], tokenFactoryState } = context;
|
|
124
|
+
const maxReserve = inputs.reduce((total, input) => {
|
|
125
|
+
const reserveToken = (0, _ocap_util_lib_get_list_field.getListField)(input, "tokens").find((x) => x.address === tokenFactoryState.reserveAddress);
|
|
126
|
+
if (reserveToken) return total.add(new _ocap_util.BN(reserveToken.value));
|
|
127
|
+
return total;
|
|
128
|
+
}, new _ocap_util.BN(0));
|
|
129
|
+
const actual = new _ocap_util.BN(reserveAmount ?? "0").add(new _ocap_util.BN(reserveFee || "0"));
|
|
130
|
+
if (actual.gt(maxReserve)) return next(new _ocap_util_lib_error.CustomError("SLIPPAGE_EXCEEDED", `Mint token failed due to price movement. Expected maximum: ${(0, _ocap_util.fromUnitToToken)(maxReserve)}, actual: ${(0, _ocap_util.fromUnitToToken)(actual)}. Try increasing your inputs.`));
|
|
131
|
+
next();
|
|
132
|
+
}, { shouldSkip: (ctx) => !ctx.tokenFactoryState?.curve });
|
|
133
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
134
|
+
from: "tokens",
|
|
135
|
+
to: "tokenStates",
|
|
136
|
+
status: "INVALID_TOKEN",
|
|
137
|
+
table: "token"
|
|
138
|
+
}));
|
|
139
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyTokenBalance({
|
|
140
|
+
ownerKey: "signerStates",
|
|
141
|
+
conditionKey: "inputs"
|
|
142
|
+
}), { shouldSkip: (ctx) => !ctx.tokenFactoryState?.curve });
|
|
143
|
+
runner.use(require_pipes_ensure_gas.default((context) => {
|
|
144
|
+
const result = {
|
|
145
|
+
create: 0,
|
|
146
|
+
update: 2,
|
|
147
|
+
payment: 0
|
|
148
|
+
};
|
|
149
|
+
if (context.senderState) result.update += 1;
|
|
150
|
+
else result.create += 1;
|
|
151
|
+
if (context.receiverState) result.update += 1;
|
|
152
|
+
else result.create += 1;
|
|
153
|
+
if (context.reserveFee) result.update += 1;
|
|
154
|
+
if (context.signerStates) result.update += context.signerStates.length;
|
|
155
|
+
return result;
|
|
156
|
+
}));
|
|
157
|
+
runner.use(require_pipes_ensure_cost.default({ attachSenderChanges: true }));
|
|
158
|
+
runner.use(_ocap_tx_pipeline.pipes.TakeStateSnapshot());
|
|
159
|
+
runner.use(async (context, next) => {
|
|
160
|
+
const { tx, senderState, receiverState, ownerState, statedb, senderChange, updateVaults, tokenFactoryState, tokenState, reserveAmount, reserveFee, itx } = context;
|
|
161
|
+
const { amount, receiver } = itx;
|
|
162
|
+
const { reserveAddress, tokenAddress } = tokenFactoryState;
|
|
163
|
+
const signerStates = tokenFactoryState.curve ? context.signerStates || [] : [];
|
|
164
|
+
const inputs = tokenFactoryState.curve ? context.inputs || [] : [];
|
|
165
|
+
const totalReserveCost = new _ocap_util.BN(reserveAmount || "0").add(new _ocap_util.BN(reserveFee || "0"));
|
|
166
|
+
let currentReserveCost = new _ocap_util.BN("0");
|
|
167
|
+
const accountUpdates = {};
|
|
168
|
+
const inputChanges = [];
|
|
169
|
+
inputs.forEach((input) => {
|
|
170
|
+
const { owner } = input;
|
|
171
|
+
const reserveTokenChange = (0, _ocap_util_lib_get_list_field.getListField)(input, "tokens").find((item) => item.address === reserveAddress);
|
|
172
|
+
if (!reserveTokenChange) return;
|
|
173
|
+
let reserveValue = new _ocap_util.BN(reserveTokenChange.value);
|
|
174
|
+
if (currentReserveCost.add(reserveValue).gt(totalReserveCost)) {
|
|
175
|
+
reserveTokenChange.value = totalReserveCost.sub(currentReserveCost).toString();
|
|
176
|
+
reserveValue = new _ocap_util.BN(reserveTokenChange.value);
|
|
177
|
+
}
|
|
178
|
+
currentReserveCost = currentReserveCost.add(reserveValue);
|
|
179
|
+
accountUpdates[owner] = require_util.applyTokenUpdates([reserveTokenChange], signerStates.find((s) => s.address === owner), "sub");
|
|
180
|
+
inputChanges.push({
|
|
181
|
+
address: owner,
|
|
182
|
+
token: reserveAddress,
|
|
183
|
+
delta: reserveValue.neg().toString()
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
if (!accountUpdates[tx.from]) accountUpdates[tx.from] = senderState || {};
|
|
187
|
+
if (reserveFee && new _ocap_util.BN(reserveFee).gt(new _ocap_util.BN(0))) accountUpdates[ownerState.address] = require_util.applyTokenChange(accountUpdates[ownerState.address] || ownerState, {
|
|
188
|
+
token: reserveAddress,
|
|
189
|
+
delta: reserveFee
|
|
190
|
+
});
|
|
191
|
+
accountUpdates[receiver] = require_util.applyTokenChange(accountUpdates[receiver] || receiverState || {
|
|
192
|
+
address: receiver,
|
|
193
|
+
tokens: {}
|
|
194
|
+
}, {
|
|
195
|
+
token: tokenAddress,
|
|
196
|
+
delta: String(amount)
|
|
197
|
+
});
|
|
198
|
+
if (senderChange) accountUpdates[senderChange.address] = require_util.applyTokenChange(accountUpdates[senderChange.address] || senderState, senderChange);
|
|
199
|
+
const [newAccountStates, newTokenFactoryState, newTokenState] = await Promise.all([
|
|
200
|
+
Promise.all(Object.entries(accountUpdates).map(([address, updates]) => {
|
|
201
|
+
const state = [
|
|
202
|
+
senderState,
|
|
203
|
+
receiverState,
|
|
204
|
+
ownerState,
|
|
205
|
+
...signerStates
|
|
206
|
+
].find((x) => x?.address === address);
|
|
207
|
+
const actualUpdates = state ? (0, lodash_pick.default)(updates, ["tokens"]) : {
|
|
208
|
+
...updates,
|
|
209
|
+
address
|
|
210
|
+
};
|
|
211
|
+
if (address === tx.from) {
|
|
212
|
+
actualUpdates.pk = tx.pk;
|
|
213
|
+
actualUpdates.nonce = tx.nonce;
|
|
214
|
+
}
|
|
215
|
+
return statedb.account.updateOrCreate(state ?? null, _ocap_state.account.updateOrCreate(state ?? null, actualUpdates, context), context);
|
|
216
|
+
})),
|
|
217
|
+
statedb.tokenFactory.update(tokenFactoryState.address, _ocap_state.tokenFactory.update(tokenFactoryState, {
|
|
218
|
+
currentSupply: new _ocap_util.BN(tokenFactoryState.currentSupply).add(new _ocap_util.BN(amount)).toString(),
|
|
219
|
+
reserveBalance: new _ocap_util.BN(tokenFactoryState.reserveBalance).add(new _ocap_util.BN(reserveAmount || "0")).toString()
|
|
220
|
+
}, context), context),
|
|
221
|
+
statedb.token.update(tokenAddress, _ocap_state.token.update(tokenState, { totalSupply: new _ocap_util.BN(tokenState.totalSupply).add(new _ocap_util.BN(amount)).toString() }), context)
|
|
222
|
+
]);
|
|
223
|
+
context.senderState = newAccountStates.find((x) => x.address === tx.from);
|
|
224
|
+
context.receiverState = newAccountStates.find((x) => x.address === receiver);
|
|
225
|
+
context.ownerState = newAccountStates.find((x) => x.address === ownerState.address) || ownerState;
|
|
226
|
+
context.signerStates = newAccountStates.filter((x) => signerStates.find((s) => s.address === x.address));
|
|
227
|
+
context.tokenFactoryState = newTokenFactoryState;
|
|
228
|
+
context.tokenState = newTokenState;
|
|
229
|
+
context.inputChanges = inputChanges;
|
|
230
|
+
if (updateVaults) await updateVaults();
|
|
231
|
+
next();
|
|
232
|
+
}, { persistError: true });
|
|
233
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyStateDiff());
|
|
234
|
+
var mint_default = runner;
|
|
235
|
+
|
|
236
|
+
//#endregion
|
|
237
|
+
exports.default = mint_default;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/protocols/token-factory/mint.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 };
|
|
@@ -0,0 +1,38 @@
|
|
|
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 lodash_get = require("lodash/get");
|
|
5
|
+
lodash_get = require_rolldown_runtime.__toESM(lodash_get);
|
|
6
|
+
let _ocap_util_lib_curve = require("@ocap/util/lib/curve");
|
|
7
|
+
let lodash_set = require("lodash/set");
|
|
8
|
+
lodash_set = require_rolldown_runtime.__toESM(lodash_set);
|
|
9
|
+
|
|
10
|
+
//#region src/protocols/token-factory/pipes/calc-reserve.ts
|
|
11
|
+
const calcReserve = ({ tokenFactoryKey = "tokenFactoryState", tokenStateKey = "tokenState", reserveKey = "reserveAmount", feeKey = "reserveFee", amountKey = "itx.amount", direction = "mint" } = {}) => (context, next) => {
|
|
12
|
+
const tokenFactoryState = (0, lodash_get.default)(context, tokenFactoryKey);
|
|
13
|
+
const tokenState = (0, lodash_get.default)(context, tokenStateKey);
|
|
14
|
+
const amount = (0, lodash_get.default)(context, amountKey);
|
|
15
|
+
if (!tokenFactoryState) return next(new _ocap_util_lib_error.CustomError("INVALID_TOKEN_FACTORY", "Token factory state not found"));
|
|
16
|
+
if (!tokenState) return next(new _ocap_util_lib_error.CustomError("INVALID_TOKEN", "Token state not found"));
|
|
17
|
+
const factoryState = tokenFactoryState;
|
|
18
|
+
const tokenStateTyped = tokenState;
|
|
19
|
+
const { curve, currentSupply, feeRate } = factoryState;
|
|
20
|
+
const { decimal } = tokenStateTyped;
|
|
21
|
+
const reserveAmount = (0, _ocap_util_lib_curve.calcCost)({
|
|
22
|
+
amount,
|
|
23
|
+
decimal,
|
|
24
|
+
currentSupply,
|
|
25
|
+
direction,
|
|
26
|
+
curve
|
|
27
|
+
});
|
|
28
|
+
(0, lodash_set.default)(context, reserveKey, reserveAmount?.toString());
|
|
29
|
+
(0, lodash_set.default)(context, feeKey, (0, _ocap_util_lib_curve.calcFee)({
|
|
30
|
+
reserveAmount: reserveAmount?.toString() || "0",
|
|
31
|
+
feeRate: String(feeRate)
|
|
32
|
+
})?.toString());
|
|
33
|
+
return next();
|
|
34
|
+
};
|
|
35
|
+
var calc_reserve_default = calcReserve;
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
exports.default = calc_reserve_default;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { PipeFunction } from "@ocap/tx-pipeline";
|
|
2
|
+
|
|
3
|
+
//#region src/protocols/token-factory/pipes/calc-reserve.d.ts
|
|
4
|
+
interface ICalcReserveOptions {
|
|
5
|
+
tokenFactoryKey?: string;
|
|
6
|
+
tokenStateKey?: string;
|
|
7
|
+
reserveKey?: string;
|
|
8
|
+
feeKey?: string;
|
|
9
|
+
amountKey?: string;
|
|
10
|
+
direction?: 'mint' | 'burn';
|
|
11
|
+
}
|
|
12
|
+
declare const calcReserve: ({
|
|
13
|
+
tokenFactoryKey,
|
|
14
|
+
tokenStateKey,
|
|
15
|
+
reserveKey,
|
|
16
|
+
feeKey,
|
|
17
|
+
amountKey,
|
|
18
|
+
direction
|
|
19
|
+
}?: ICalcReserveOptions) => PipeFunction<any>;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { calcReserve as default };
|
|
@@ -0,0 +1,22 @@
|
|
|
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 lodash_get = require("lodash/get");
|
|
5
|
+
lodash_get = require_rolldown_runtime.__toESM(lodash_get);
|
|
6
|
+
let lodash_set = require("lodash/set");
|
|
7
|
+
lodash_set = require_rolldown_runtime.__toESM(lodash_set);
|
|
8
|
+
let _blocklet_xss = require("@blocklet/xss");
|
|
9
|
+
|
|
10
|
+
//#region src/protocols/token-factory/pipes/verify-icon.ts
|
|
11
|
+
const verifyIcon = ({ iconKey = "itx.token.icon", size = 16 * 1024 } = {}) => (context, next) => {
|
|
12
|
+
const icon = (0, lodash_get.default)(context, iconKey);
|
|
13
|
+
if (!icon) return next();
|
|
14
|
+
if (!(0, _blocklet_xss.isSvgFile)(icon)) return next(new _ocap_util_lib_error.CustomError("INVALID_ICON", "Token Icon is not a valid SVG file"));
|
|
15
|
+
if (Buffer.from(icon, "utf8").length > size) return next(new _ocap_util_lib_error.CustomError("INVALID_ICON", `Token Icon must be less than ${Math.floor(size / 1024)}k`));
|
|
16
|
+
(0, lodash_set.default)(context, iconKey, (0, _blocklet_xss.sanitizeSvg)(icon, { preserveCase: true }));
|
|
17
|
+
return next();
|
|
18
|
+
};
|
|
19
|
+
var verify_icon_default = verifyIcon;
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
exports.default = verify_icon_default;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IDecodedContext } from "@ocap/types";
|
|
2
|
+
import { PipeFunction } from "@ocap/tx-pipeline";
|
|
3
|
+
|
|
4
|
+
//#region src/protocols/token-factory/pipes/verify-icon.d.ts
|
|
5
|
+
interface IVerifyIconOptions {
|
|
6
|
+
iconKey?: string;
|
|
7
|
+
size?: number;
|
|
8
|
+
}
|
|
9
|
+
declare const verifyIcon: ({
|
|
10
|
+
iconKey,
|
|
11
|
+
size
|
|
12
|
+
}?: IVerifyIconOptions) => PipeFunction<IDecodedContext>;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { verifyIcon as default };
|