@ocap/tx-protocols 1.28.9 → 1.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/execute.d.mts +53 -0
- package/esm/execute.mjs +225 -0
- package/esm/index.d.mts +95 -0
- package/esm/index.mjs +100 -0
- package/esm/pipes/ensure-cost.d.mts +18 -0
- package/esm/pipes/ensure-cost.mjs +136 -0
- package/esm/pipes/ensure-gas.d.mts +14 -0
- package/esm/pipes/ensure-gas.mjs +38 -0
- package/esm/protocols/account/delegate.d.mts +4 -0
- package/esm/protocols/account/delegate.mjs +195 -0
- package/esm/protocols/account/migrate.d.mts +4 -0
- package/esm/protocols/account/migrate.mjs +130 -0
- package/esm/protocols/account/revoke-delegate.d.mts +4 -0
- package/esm/protocols/account/revoke-delegate.mjs +102 -0
- package/esm/protocols/asset/acquire-v2.d.mts +9 -0
- package/esm/protocols/asset/acquire-v2.mjs +213 -0
- package/esm/protocols/asset/acquire-v3.d.mts +17 -0
- package/esm/protocols/asset/acquire-v3.mjs +265 -0
- package/esm/protocols/asset/calls/transfer-token.d.mts +4 -0
- package/esm/protocols/asset/calls/transfer-token.mjs +36 -0
- package/esm/protocols/asset/calls/transfer.d.mts +4 -0
- package/esm/protocols/asset/calls/transfer.mjs +32 -0
- package/esm/protocols/asset/consume.d.mts +4 -0
- package/esm/protocols/asset/consume.mjs +92 -0
- package/esm/protocols/asset/create.d.mts +4 -0
- package/esm/protocols/asset/create.mjs +136 -0
- package/esm/protocols/asset/mint.d.mts +4 -0
- package/esm/protocols/asset/mint.mjs +156 -0
- package/esm/protocols/asset/pipes/exec-mint-hook.d.mts +24 -0
- package/esm/protocols/asset/pipes/exec-mint-hook.mjs +54 -0
- package/esm/protocols/asset/pipes/extract-factory-tokens.d.mts +21 -0
- package/esm/protocols/asset/pipes/extract-factory-tokens.mjs +22 -0
- package/esm/protocols/asset/pipes/verify-itx-address.d.mts +32 -0
- package/esm/protocols/asset/pipes/verify-itx-address.mjs +56 -0
- package/esm/protocols/asset/pipes/verify-itx-assets.d.mts +18 -0
- package/esm/protocols/asset/pipes/verify-itx-assets.mjs +27 -0
- package/esm/protocols/asset/pipes/verify-itx-variables.d.mts +17 -0
- package/esm/protocols/asset/pipes/verify-itx-variables.mjs +20 -0
- package/esm/protocols/asset/pipes/verify-mint-limit.d.mts +15 -0
- package/esm/protocols/asset/pipes/verify-mint-limit.mjs +14 -0
- package/esm/protocols/asset/update.d.mts +4 -0
- package/esm/protocols/asset/update.mjs +111 -0
- package/esm/protocols/factory/create.d.mts +29 -0
- package/esm/protocols/factory/create.mjs +155 -0
- package/esm/protocols/governance/claim-stake.d.mts +27 -0
- package/esm/protocols/governance/claim-stake.mjs +220 -0
- package/esm/protocols/governance/return-stake.d.mts +27 -0
- package/esm/protocols/governance/return-stake.mjs +211 -0
- package/esm/protocols/governance/revoke-stake.d.mts +27 -0
- package/esm/protocols/governance/revoke-stake.mjs +178 -0
- package/esm/protocols/governance/slash-stake.d.mts +17 -0
- package/esm/protocols/governance/slash-stake.mjs +213 -0
- package/esm/protocols/governance/stake.d.mts +15 -0
- package/esm/protocols/governance/stake.mjs +270 -0
- package/esm/protocols/rollup/claim-reward.d.mts +11 -0
- package/esm/protocols/rollup/claim-reward.mjs +322 -0
- package/esm/protocols/rollup/close.d.mts +4 -0
- package/esm/protocols/rollup/close.mjs +105 -0
- package/esm/protocols/rollup/create-block.d.mts +11 -0
- package/esm/protocols/rollup/create-block.mjs +303 -0
- package/esm/protocols/rollup/create.d.mts +4 -0
- package/esm/protocols/rollup/create.mjs +164 -0
- package/esm/protocols/rollup/join.d.mts +4 -0
- package/esm/protocols/rollup/join.mjs +152 -0
- package/esm/protocols/rollup/leave.d.mts +4 -0
- package/esm/protocols/rollup/leave.mjs +137 -0
- package/esm/protocols/rollup/migrate.d.mts +4 -0
- package/esm/protocols/rollup/migrate.mjs +85 -0
- package/esm/protocols/rollup/pause.d.mts +4 -0
- package/esm/protocols/rollup/pause.mjs +76 -0
- package/esm/protocols/rollup/pipes/ensure-validator.d.mts +6 -0
- package/esm/protocols/rollup/pipes/ensure-validator.mjs +12 -0
- package/esm/protocols/rollup/pipes/verify-evidence.d.mts +15 -0
- package/esm/protocols/rollup/pipes/verify-evidence.mjs +29 -0
- package/esm/protocols/rollup/pipes/verify-signers.d.mts +15 -0
- package/esm/protocols/rollup/pipes/verify-signers.mjs +36 -0
- package/esm/protocols/rollup/pipes/verify-status.d.mts +13 -0
- package/esm/protocols/rollup/pipes/verify-status.mjs +26 -0
- package/esm/protocols/rollup/resume.d.mts +4 -0
- package/esm/protocols/rollup/resume.mjs +79 -0
- package/esm/protocols/rollup/update.d.mts +4 -0
- package/esm/protocols/rollup/update.mjs +111 -0
- package/esm/protocols/token/create.d.mts +4 -0
- package/esm/protocols/token/create.mjs +150 -0
- package/esm/protocols/token/deposit-v2.d.mts +11 -0
- package/esm/protocols/token/deposit-v2.mjs +216 -0
- package/esm/protocols/token/withdraw-v2.d.mts +9 -0
- package/esm/protocols/token/withdraw-v2.mjs +222 -0
- package/esm/protocols/token-factory/burn.d.mts +15 -0
- package/esm/protocols/token-factory/burn.mjs +233 -0
- package/esm/protocols/token-factory/create.d.mts +4 -0
- package/esm/protocols/token-factory/create.mjs +254 -0
- package/esm/protocols/token-factory/mint.d.mts +15 -0
- package/esm/protocols/token-factory/mint.mjs +234 -0
- package/esm/protocols/token-factory/pipes/calc-reserve.d.mts +21 -0
- package/esm/protocols/token-factory/pipes/calc-reserve.mjs +34 -0
- package/esm/protocols/token-factory/pipes/verify-icon.d.mts +14 -0
- package/esm/protocols/token-factory/pipes/verify-icon.mjs +18 -0
- package/esm/protocols/token-factory/pipes/verify-ownership.d.mts +12 -0
- package/esm/protocols/token-factory/pipes/verify-ownership.mjs +63 -0
- package/esm/protocols/token-factory/pipes/verify-url.d.mts +12 -0
- package/esm/protocols/token-factory/pipes/verify-url.mjs +26 -0
- package/esm/protocols/token-factory/update.d.mts +10 -0
- package/esm/protocols/token-factory/update.mjs +152 -0
- package/esm/protocols/trade/exchange-v2.d.mts +9 -0
- package/esm/protocols/trade/exchange-v2.mjs +239 -0
- package/esm/protocols/trade/transfer-v2.d.mts +9 -0
- package/esm/protocols/trade/transfer-v2.mjs +226 -0
- package/esm/protocols/trade/transfer-v3.d.mts +17 -0
- package/esm/protocols/trade/transfer-v3.mjs +270 -0
- package/esm/util.d.mts +141 -0
- package/esm/util.mjs +278 -0
- package/lib/_virtual/rolldown_runtime.cjs +29 -0
- package/lib/execute.cjs +231 -0
- package/lib/execute.d.cts +53 -0
- package/lib/index.cjs +105 -0
- package/lib/index.d.cts +95 -0
- package/lib/pipes/ensure-cost.cjs +141 -0
- package/lib/pipes/ensure-cost.d.cts +18 -0
- package/lib/pipes/ensure-gas.cjs +41 -0
- package/lib/pipes/ensure-gas.d.cts +14 -0
- package/lib/protocols/account/delegate.cjs +201 -0
- package/lib/protocols/account/delegate.d.cts +4 -0
- package/lib/protocols/account/migrate.cjs +135 -0
- package/lib/protocols/account/migrate.d.cts +4 -0
- package/lib/protocols/account/revoke-delegate.cjs +107 -0
- package/lib/protocols/account/revoke-delegate.d.cts +4 -0
- package/lib/protocols/asset/acquire-v2.cjs +216 -0
- package/lib/protocols/asset/acquire-v2.d.cts +9 -0
- package/lib/protocols/asset/acquire-v3.cjs +269 -0
- package/lib/protocols/asset/acquire-v3.d.cts +17 -0
- package/lib/protocols/asset/calls/transfer-token.cjs +40 -0
- package/lib/protocols/asset/calls/transfer-token.d.cts +4 -0
- package/lib/protocols/asset/calls/transfer.cjs +35 -0
- package/lib/protocols/asset/calls/transfer.d.cts +4 -0
- package/lib/protocols/asset/consume.cjs +95 -0
- package/lib/protocols/asset/consume.d.cts +4 -0
- package/lib/protocols/asset/create.cjs +140 -0
- package/lib/protocols/asset/create.d.cts +4 -0
- package/lib/protocols/asset/mint.cjs +159 -0
- package/lib/protocols/asset/mint.d.cts +4 -0
- package/lib/protocols/asset/pipes/exec-mint-hook.cjs +57 -0
- package/lib/protocols/asset/pipes/exec-mint-hook.d.cts +24 -0
- package/lib/protocols/asset/pipes/extract-factory-tokens.cjs +25 -0
- package/lib/protocols/asset/pipes/extract-factory-tokens.d.cts +21 -0
- package/lib/protocols/asset/pipes/verify-itx-address.cjs +59 -0
- package/lib/protocols/asset/pipes/verify-itx-address.d.cts +32 -0
- package/lib/protocols/asset/pipes/verify-itx-assets.cjs +29 -0
- package/lib/protocols/asset/pipes/verify-itx-assets.d.cts +18 -0
- package/lib/protocols/asset/pipes/verify-itx-variables.cjs +22 -0
- package/lib/protocols/asset/pipes/verify-itx-variables.d.cts +17 -0
- package/lib/protocols/asset/pipes/verify-mint-limit.cjs +16 -0
- package/lib/protocols/asset/pipes/verify-mint-limit.d.cts +15 -0
- package/lib/protocols/asset/update.cjs +114 -0
- package/lib/protocols/asset/update.d.cts +4 -0
- package/lib/protocols/factory/create.cjs +161 -0
- package/lib/protocols/factory/create.d.cts +29 -0
- package/lib/protocols/governance/claim-stake.cjs +223 -0
- package/lib/protocols/governance/claim-stake.d.cts +27 -0
- package/lib/protocols/governance/return-stake.cjs +215 -0
- package/lib/protocols/governance/return-stake.d.cts +27 -0
- package/lib/protocols/governance/revoke-stake.cjs +182 -0
- package/lib/protocols/governance/revoke-stake.d.cts +27 -0
- package/lib/protocols/governance/slash-stake.cjs +217 -0
- package/lib/protocols/governance/slash-stake.d.cts +17 -0
- package/lib/protocols/governance/stake.cjs +275 -0
- package/lib/protocols/governance/stake.d.cts +15 -0
- package/lib/protocols/rollup/claim-reward.cjs +328 -0
- package/lib/protocols/rollup/claim-reward.d.cts +11 -0
- package/lib/protocols/rollup/close.cjs +107 -0
- package/lib/protocols/rollup/close.d.cts +4 -0
- package/lib/protocols/rollup/create-block.cjs +309 -0
- package/lib/protocols/rollup/create-block.d.cts +11 -0
- package/lib/protocols/rollup/create.cjs +169 -0
- package/lib/protocols/rollup/create.d.cts +4 -0
- package/lib/protocols/rollup/join.cjs +157 -0
- package/lib/protocols/rollup/join.d.cts +4 -0
- package/lib/protocols/rollup/leave.cjs +141 -0
- package/lib/protocols/rollup/leave.d.cts +4 -0
- package/lib/protocols/rollup/migrate.cjs +87 -0
- package/lib/protocols/rollup/migrate.d.cts +4 -0
- package/lib/protocols/rollup/pause.cjs +78 -0
- package/lib/protocols/rollup/pause.d.cts +4 -0
- package/lib/protocols/rollup/pipes/ensure-validator.cjs +14 -0
- package/lib/protocols/rollup/pipes/ensure-validator.d.cts +6 -0
- package/lib/protocols/rollup/pipes/verify-evidence.cjs +32 -0
- package/lib/protocols/rollup/pipes/verify-evidence.d.cts +15 -0
- package/lib/protocols/rollup/pipes/verify-signers.cjs +39 -0
- package/lib/protocols/rollup/pipes/verify-signers.d.cts +15 -0
- package/lib/protocols/rollup/pipes/verify-status.cjs +28 -0
- package/lib/protocols/rollup/pipes/verify-status.d.cts +13 -0
- package/lib/protocols/rollup/resume.cjs +81 -0
- package/lib/protocols/rollup/resume.d.cts +4 -0
- package/lib/protocols/rollup/update.cjs +114 -0
- package/lib/protocols/rollup/update.d.cts +4 -0
- package/lib/protocols/token/create.cjs +156 -0
- package/lib/protocols/token/create.d.cts +4 -0
- package/lib/protocols/token/deposit-v2.cjs +219 -0
- package/lib/protocols/token/deposit-v2.d.cts +11 -0
- package/lib/protocols/token/withdraw-v2.cjs +225 -0
- package/lib/protocols/token/withdraw-v2.d.cts +9 -0
- package/lib/protocols/token-factory/burn.cjs +236 -0
- package/lib/protocols/token-factory/burn.d.cts +15 -0
- package/lib/protocols/token-factory/create.cjs +260 -0
- package/lib/protocols/token-factory/create.d.cts +4 -0
- package/lib/protocols/token-factory/mint.cjs +237 -0
- package/lib/protocols/token-factory/mint.d.cts +15 -0
- package/lib/protocols/token-factory/pipes/calc-reserve.cjs +38 -0
- package/lib/protocols/token-factory/pipes/calc-reserve.d.cts +21 -0
- package/lib/protocols/token-factory/pipes/verify-icon.cjs +22 -0
- package/lib/protocols/token-factory/pipes/verify-icon.d.cts +14 -0
- package/lib/protocols/token-factory/pipes/verify-ownership.cjs +66 -0
- package/lib/protocols/token-factory/pipes/verify-ownership.d.cts +12 -0
- package/lib/protocols/token-factory/pipes/verify-url.cjs +29 -0
- package/lib/protocols/token-factory/pipes/verify-url.d.cts +12 -0
- package/lib/protocols/token-factory/update.cjs +155 -0
- package/lib/protocols/token-factory/update.d.cts +10 -0
- package/lib/protocols/trade/exchange-v2.cjs +243 -0
- package/lib/protocols/trade/exchange-v2.d.cts +9 -0
- package/lib/protocols/trade/transfer-v2.cjs +229 -0
- package/lib/protocols/trade/transfer-v2.d.cts +9 -0
- package/lib/protocols/trade/transfer-v3.cjs +274 -0
- package/lib/protocols/trade/transfer-v3.d.cts +17 -0
- package/lib/util.cjs +296 -0
- package/lib/util.d.cts +141 -0
- package/package.json +49 -22
- package/tools/fixtures.ts +564 -0
- package/lib/execute.js +0 -254
- package/lib/index.js +0 -117
- package/lib/pipes/ensure-cost.js +0 -193
- package/lib/pipes/ensure-gas.js +0 -48
- package/lib/protocols/account/delegate.js +0 -223
- package/lib/protocols/account/migrate.js +0 -153
- package/lib/protocols/account/revoke-delegate.js +0 -110
- package/lib/protocols/asset/acquire-v2.js +0 -262
- package/lib/protocols/asset/acquire-v3.js +0 -330
- package/lib/protocols/asset/calls/README.md +0 -5
- package/lib/protocols/asset/calls/transfer-token.js +0 -36
- package/lib/protocols/asset/calls/transfer.js +0 -28
- package/lib/protocols/asset/consume.js +0 -105
- package/lib/protocols/asset/create.js +0 -151
- package/lib/protocols/asset/mint.js +0 -199
- package/lib/protocols/asset/pipes/exec-mint-hook.js +0 -62
- package/lib/protocols/asset/pipes/extract-factory-tokens.js +0 -18
- package/lib/protocols/asset/pipes/verify-itx-address.js +0 -54
- package/lib/protocols/asset/pipes/verify-itx-assets.js +0 -51
- package/lib/protocols/asset/pipes/verify-itx-variables.js +0 -26
- package/lib/protocols/asset/pipes/verify-mint-limit.js +0 -13
- package/lib/protocols/asset/update.js +0 -131
- package/lib/protocols/factory/create.js +0 -191
- package/lib/protocols/governance/claim-stake.js +0 -266
- package/lib/protocols/governance/return-stake.js +0 -248
- package/lib/protocols/governance/revoke-stake.js +0 -172
- package/lib/protocols/governance/slash-stake.js +0 -271
- package/lib/protocols/governance/stake.js +0 -303
- package/lib/protocols/rollup/claim-reward.js +0 -342
- package/lib/protocols/rollup/close.js +0 -104
- package/lib/protocols/rollup/create-block.js +0 -413
- package/lib/protocols/rollup/create.js +0 -197
- package/lib/protocols/rollup/join.js +0 -182
- package/lib/protocols/rollup/leave.js +0 -145
- package/lib/protocols/rollup/migrate.js +0 -85
- package/lib/protocols/rollup/pause.js +0 -75
- package/lib/protocols/rollup/pipes/ensure-validator.js +0 -12
- package/lib/protocols/rollup/pipes/verify-evidence.js +0 -37
- package/lib/protocols/rollup/pipes/verify-signers.js +0 -87
- package/lib/protocols/rollup/pipes/verify-status.js +0 -30
- package/lib/protocols/rollup/resume.js +0 -75
- package/lib/protocols/rollup/update.js +0 -122
- package/lib/protocols/token/create.js +0 -199
- package/lib/protocols/token/deposit-v2.js +0 -290
- package/lib/protocols/token/withdraw-v2.js +0 -305
- package/lib/protocols/token-factory/burn.js +0 -371
- package/lib/protocols/token-factory/create.js +0 -342
- package/lib/protocols/token-factory/mint.js +0 -385
- package/lib/protocols/token-factory/pipes/calc-reserve.js +0 -37
- package/lib/protocols/token-factory/pipes/verify-icon.js +0 -27
- package/lib/protocols/token-factory/pipes/verify-ownership.js +0 -93
- package/lib/protocols/token-factory/pipes/verify-url.js +0 -32
- package/lib/protocols/token-factory/update.js +0 -208
- package/lib/protocols/trade/exchange-v2.js +0 -239
- package/lib/protocols/trade/transfer-v2.js +0 -233
- package/lib/protocols/trade/transfer-v3.js +0 -333
- package/lib/util.js +0 -442
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { applyTokenChange, applyTokenUpdates } from "../../util.mjs";
|
|
2
|
+
import ensure_cost_default from "../../pipes/ensure-cost.mjs";
|
|
3
|
+
import ensure_gas_default from "../../pipes/ensure-gas.mjs";
|
|
4
|
+
import calc_reserve_default from "./pipes/calc-reserve.mjs";
|
|
5
|
+
import { Runner, pipes } from "@ocap/tx-pipeline";
|
|
6
|
+
import { CustomError } from "@ocap/util/lib/error";
|
|
7
|
+
import pick from "lodash/pick.js";
|
|
8
|
+
import { account, token, tokenFactory } from "@ocap/state";
|
|
9
|
+
import { BN, fromUnitToToken } from "@ocap/util";
|
|
10
|
+
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
11
|
+
import { Joi, schemas } from "@arcblock/validator";
|
|
12
|
+
|
|
13
|
+
//#region src/protocols/token-factory/burn.ts
|
|
14
|
+
const runner = new Runner("burn_token");
|
|
15
|
+
const schema = Joi.object({
|
|
16
|
+
tokenFactory: Joi.DID().prefix().role("ROLE_TOKEN_FACTORY").required(),
|
|
17
|
+
receiver: schemas.tokenHolder.required(),
|
|
18
|
+
minReserve: Joi.alternatives().try(Joi.BN().greater(0), Joi.equal("")).optional(),
|
|
19
|
+
inputsList: schemas.multiInput.min(1).required(),
|
|
20
|
+
data: Joi.any().optional().allow(null)
|
|
21
|
+
}).options({
|
|
22
|
+
stripUnknown: true,
|
|
23
|
+
noDefaults: false
|
|
24
|
+
});
|
|
25
|
+
runner.use(({ itx }, next) => {
|
|
26
|
+
const { error } = schema.validate(itx);
|
|
27
|
+
if (error) return next(new CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
|
|
28
|
+
return next();
|
|
29
|
+
});
|
|
30
|
+
runner.use(pipes.ExtractState({
|
|
31
|
+
from: "itx.tokenFactory",
|
|
32
|
+
to: "tokenFactoryState",
|
|
33
|
+
status: "INVALID_TOKEN_FACTORY",
|
|
34
|
+
table: "tokenFactory"
|
|
35
|
+
}));
|
|
36
|
+
runner.use(pipes.ExtractState({
|
|
37
|
+
from: "tokenFactoryState.tokenAddress",
|
|
38
|
+
to: "tokenState",
|
|
39
|
+
status: "INVALID_TOKEN",
|
|
40
|
+
table: "token"
|
|
41
|
+
}));
|
|
42
|
+
runner.use(pipes.VerifyTxInput({
|
|
43
|
+
fieldKey: "itx.inputs",
|
|
44
|
+
inputsKey: "inputs",
|
|
45
|
+
sendersKey: "senders",
|
|
46
|
+
tokensKey: "tokens",
|
|
47
|
+
assetsKey: null
|
|
48
|
+
}));
|
|
49
|
+
runner.use(pipes.VerifyListSize({ listKey: [
|
|
50
|
+
"inputs",
|
|
51
|
+
"senders",
|
|
52
|
+
"tokens",
|
|
53
|
+
"assets"
|
|
54
|
+
] }));
|
|
55
|
+
runner.use(pipes.VerifyMultiSigV2({ signersKey: "senders" }));
|
|
56
|
+
runner.use((context, next) => {
|
|
57
|
+
const { tokenFactoryState, inputs } = context;
|
|
58
|
+
if (!(inputs || []).every((input) => {
|
|
59
|
+
const tokensList = getListField(input, "tokens");
|
|
60
|
+
const assetsList = getListField(input, "assets");
|
|
61
|
+
return tokensList.length && tokensList.every((x) => x.address === tokenFactoryState.tokenAddress) && !assetsList.length;
|
|
62
|
+
})) return next(new CustomError("INVALID_TX", `Inputs only accept ${tokenFactoryState.tokenAddress}`));
|
|
63
|
+
return next();
|
|
64
|
+
});
|
|
65
|
+
runner.use(pipes.ExtractState({
|
|
66
|
+
from: "tx.from",
|
|
67
|
+
to: "senderState",
|
|
68
|
+
status: "OK",
|
|
69
|
+
table: "account"
|
|
70
|
+
}));
|
|
71
|
+
runner.use(pipes.VerifyAccountMigration({
|
|
72
|
+
stateKey: "senderState",
|
|
73
|
+
addressKey: "tx.from"
|
|
74
|
+
}));
|
|
75
|
+
runner.use(pipes.ExtractState({
|
|
76
|
+
from: "senders",
|
|
77
|
+
to: "signerStates",
|
|
78
|
+
status: "INVALID_SIGNER_STATE",
|
|
79
|
+
table: "account"
|
|
80
|
+
}));
|
|
81
|
+
runner.use(pipes.VerifyAccountMigration({
|
|
82
|
+
signerKey: "signerStates",
|
|
83
|
+
stateKey: "senderState",
|
|
84
|
+
addressKey: "tx.from"
|
|
85
|
+
}));
|
|
86
|
+
runner.use(pipes.ExtractState({
|
|
87
|
+
from: "itx.receiver",
|
|
88
|
+
to: "receiverState",
|
|
89
|
+
status: "OK",
|
|
90
|
+
table: "account"
|
|
91
|
+
}));
|
|
92
|
+
runner.use(pipes.VerifyAccountMigration({
|
|
93
|
+
stateKey: "receiverState",
|
|
94
|
+
addressKey: "itx.receiver"
|
|
95
|
+
}));
|
|
96
|
+
runner.use(pipes.VerifyBlocked({ stateKeys: ["signerStates", "receiverState"] }));
|
|
97
|
+
runner.use(pipes.ExtractState({
|
|
98
|
+
from: "tokenFactoryState.owner",
|
|
99
|
+
to: "ownerState",
|
|
100
|
+
status: "INVALID_OWNER_STATE",
|
|
101
|
+
table: "account"
|
|
102
|
+
}));
|
|
103
|
+
runner.use(pipes.verifyTokenAccess({
|
|
104
|
+
statesKey: "tokenState",
|
|
105
|
+
listFieldKey: "minters",
|
|
106
|
+
accountKeys: ["senderState"],
|
|
107
|
+
errorMessage: "Account {address} is not allowed to burn token {tokenAddress}"
|
|
108
|
+
}));
|
|
109
|
+
runner.use((context, next) => {
|
|
110
|
+
const { inputs = [], tokenFactoryState } = context;
|
|
111
|
+
let amount = new BN("0");
|
|
112
|
+
for (const { tokensList } of inputs) {
|
|
113
|
+
const delta = tokensList.find((x) => x.address === tokenFactoryState.tokenAddress)?.value;
|
|
114
|
+
if (!delta) return next(new CustomError("INVALID_TX", "Invalid inputs"));
|
|
115
|
+
amount = amount.add(new BN(delta));
|
|
116
|
+
}
|
|
117
|
+
context.burnAmount = amount.toString();
|
|
118
|
+
return next();
|
|
119
|
+
});
|
|
120
|
+
runner.use(calc_reserve_default({
|
|
121
|
+
tokenFactoryKey: "tokenFactoryState",
|
|
122
|
+
tokenStateKey: "tokenState",
|
|
123
|
+
reserveKey: "reserveAmount",
|
|
124
|
+
feeKey: "reserveFee",
|
|
125
|
+
amountKey: "burnAmount",
|
|
126
|
+
direction: "burn"
|
|
127
|
+
}), { shouldSkip: (ctx) => !ctx.tokenFactoryState?.curve });
|
|
128
|
+
runner.use((context, next) => {
|
|
129
|
+
const { reserveAmount = "0", reserveFee } = context;
|
|
130
|
+
const { minReserve } = context.itx;
|
|
131
|
+
if (minReserve && new BN(reserveAmount).lt(new BN(minReserve).add(new BN(reserveFee || "0")))) return next(new CustomError("SLIPPAGE_EXCEEDED", `Burn token failed due to price movement. Expected minimum: ${fromUnitToToken(minReserve)}, actual: ${fromUnitToToken(reserveAmount)}. Try reducing your minReserve.`));
|
|
132
|
+
return next();
|
|
133
|
+
}, { shouldSkip: (ctx) => !ctx.tokenFactoryState?.curve });
|
|
134
|
+
runner.use(pipes.ExtractState({
|
|
135
|
+
from: "tokens",
|
|
136
|
+
to: "tokenStates",
|
|
137
|
+
status: "INVALID_TOKEN",
|
|
138
|
+
table: "token"
|
|
139
|
+
}));
|
|
140
|
+
runner.use(pipes.VerifyTokenBalance({
|
|
141
|
+
ownerKey: "signerStates",
|
|
142
|
+
conditionKey: "inputs"
|
|
143
|
+
}));
|
|
144
|
+
runner.use((context, next) => {
|
|
145
|
+
const { tokenFactoryState, burnAmount = "0", reserveAmount = "0" } = context;
|
|
146
|
+
if (new BN(tokenFactoryState.currentSupply).lt(new BN(burnAmount))) return next(new CustomError("INSUFFICIENT_FUND", "Token factory supply is not enough"));
|
|
147
|
+
if (new BN(tokenFactoryState.reserveBalance).lt(new BN(reserveAmount))) return next(new CustomError("INSUFFICIENT_FUND", "Token factory reserve balance is not enough"));
|
|
148
|
+
return next();
|
|
149
|
+
});
|
|
150
|
+
runner.use(ensure_gas_default((context) => {
|
|
151
|
+
const result = {
|
|
152
|
+
create: 0,
|
|
153
|
+
update: 2,
|
|
154
|
+
payment: 0
|
|
155
|
+
};
|
|
156
|
+
if (context.senderState) result.update += 1;
|
|
157
|
+
else result.create += 1;
|
|
158
|
+
if (context.tokenFactoryState?.curve) if (context.receiverState) result.update += 1;
|
|
159
|
+
else result.create += 1;
|
|
160
|
+
if (context.reserveFee) result.update += 1;
|
|
161
|
+
if (context.signerStates) result.update += context.signerStates.length;
|
|
162
|
+
return result;
|
|
163
|
+
}));
|
|
164
|
+
runner.use(ensure_cost_default({ attachSenderChanges: true }));
|
|
165
|
+
runner.use(pipes.TakeStateSnapshot());
|
|
166
|
+
runner.use(async (context, next) => {
|
|
167
|
+
const { tx: tx$1, senderState, receiverState, ownerState, statedb, senderChange, updateVaults, tokenFactoryState, tokenState, reserveAmount = "0", reserveFee, itx, inputs = [], signerStates = [], burnAmount = "0" } = context;
|
|
168
|
+
const { receiver } = itx;
|
|
169
|
+
const { reserveAddress, tokenAddress } = tokenFactoryState;
|
|
170
|
+
const accountUpdates = {};
|
|
171
|
+
const inputChanges = [];
|
|
172
|
+
inputs.forEach((input) => {
|
|
173
|
+
const { owner } = input;
|
|
174
|
+
const tokenChange = getListField(input, "tokens").find((item) => item.address === tokenAddress);
|
|
175
|
+
accountUpdates[owner] = applyTokenUpdates([tokenChange], signerStates.find((s) => s.address === owner), "sub");
|
|
176
|
+
inputChanges.push({
|
|
177
|
+
address: owner,
|
|
178
|
+
token: tokenAddress,
|
|
179
|
+
delta: new BN(tokenChange.value).neg().toString()
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
if (!accountUpdates[tx$1.from]) accountUpdates[tx$1.from] = senderState || {};
|
|
183
|
+
if (reserveFee && new BN(reserveFee).gt(new BN(0))) accountUpdates[ownerState.address] = applyTokenChange(accountUpdates[ownerState.address] || ownerState, {
|
|
184
|
+
token: reserveAddress,
|
|
185
|
+
delta: reserveFee
|
|
186
|
+
});
|
|
187
|
+
if (tokenFactoryState.curve) accountUpdates[receiver] = applyTokenChange(accountUpdates[receiver] || receiverState || {
|
|
188
|
+
address: receiver,
|
|
189
|
+
tokens: {}
|
|
190
|
+
}, {
|
|
191
|
+
token: reserveAddress,
|
|
192
|
+
delta: new BN(reserveAmount).sub(new BN(reserveFee || "0")).toString()
|
|
193
|
+
});
|
|
194
|
+
if (senderChange) accountUpdates[senderChange.address] = applyTokenChange(accountUpdates[senderChange.address] || senderState, senderChange);
|
|
195
|
+
const [newAccountStates, newTokenFactoryState, newTokenState] = await Promise.all([
|
|
196
|
+
Promise.all(Object.entries(accountUpdates).map(([address, updates]) => {
|
|
197
|
+
const state = [
|
|
198
|
+
senderState,
|
|
199
|
+
receiverState,
|
|
200
|
+
ownerState,
|
|
201
|
+
...signerStates
|
|
202
|
+
].find((x) => x?.address === address);
|
|
203
|
+
const actualUpdates = state ? pick(updates, ["tokens"]) : {
|
|
204
|
+
...updates,
|
|
205
|
+
address
|
|
206
|
+
};
|
|
207
|
+
if (address === tx$1.from) {
|
|
208
|
+
actualUpdates.pk = tx$1.pk;
|
|
209
|
+
actualUpdates.nonce = tx$1.nonce;
|
|
210
|
+
}
|
|
211
|
+
return statedb.account.updateOrCreate(state ?? null, account.updateOrCreate(state ?? null, actualUpdates, context), context);
|
|
212
|
+
})),
|
|
213
|
+
statedb.tokenFactory.update(tokenFactoryState.address, tokenFactory.update(tokenFactoryState, {
|
|
214
|
+
currentSupply: new BN(tokenFactoryState.currentSupply).sub(new BN(burnAmount)).toString(),
|
|
215
|
+
reserveBalance: new BN(tokenFactoryState.reserveBalance).sub(new BN(reserveAmount)).toString()
|
|
216
|
+
}, context), context),
|
|
217
|
+
statedb.token.update(tokenAddress, token.update(tokenState, { totalSupply: new BN(tokenState.totalSupply).sub(new BN(burnAmount)).toString() }), context)
|
|
218
|
+
]);
|
|
219
|
+
context.senderState = newAccountStates.find((x) => x.address === tx$1.from);
|
|
220
|
+
context.receiverState = newAccountStates.find((x) => x.address === receiver);
|
|
221
|
+
context.ownerState = newAccountStates.find((x) => x.address === ownerState.address) || ownerState;
|
|
222
|
+
context.signerStates = newAccountStates.filter((x) => signerStates.find((s) => s.address === x.address));
|
|
223
|
+
context.tokenFactoryState = newTokenFactoryState;
|
|
224
|
+
context.tokenState = newTokenState;
|
|
225
|
+
context.inputChanges = inputChanges;
|
|
226
|
+
if (updateVaults) await updateVaults();
|
|
227
|
+
next();
|
|
228
|
+
}, { persistError: true });
|
|
229
|
+
runner.use(pipes.VerifyStateDiff());
|
|
230
|
+
var burn_default = runner;
|
|
231
|
+
|
|
232
|
+
//#endregion
|
|
233
|
+
export { burn_default as default };
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { applyTokenChange, decodeAnySafe, getDelegationRequirements } from "../../util.mjs";
|
|
2
|
+
import ensure_cost_default from "../../pipes/ensure-cost.mjs";
|
|
3
|
+
import ensure_gas_default from "../../pipes/ensure-gas.mjs";
|
|
4
|
+
import verify_icon_default from "./pipes/verify-icon.mjs";
|
|
5
|
+
import verify_ownership_default from "./pipes/verify-ownership.mjs";
|
|
6
|
+
import verify_url_default from "./pipes/verify-url.mjs";
|
|
7
|
+
import { Runner, pipes } from "@ocap/tx-pipeline";
|
|
8
|
+
import { CustomError } from "@ocap/util/lib/error";
|
|
9
|
+
import { toStakeAddress, toTokenAddress, toTokenFactoryAddress } from "@arcblock/did-util";
|
|
10
|
+
import { account, delegation, stake, token, tokenFactory } from "@ocap/state";
|
|
11
|
+
import { BN, fromTokenToUnit, fromUnitToToken } from "@ocap/util";
|
|
12
|
+
import Debug from "debug";
|
|
13
|
+
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
14
|
+
import cloneDeep from "lodash/cloneDeep.js";
|
|
15
|
+
import { Joi } from "@arcblock/validator";
|
|
16
|
+
import uniq from "lodash/uniq.js";
|
|
17
|
+
import isEmpty from "lodash/isEmpty.js";
|
|
18
|
+
|
|
19
|
+
//#region src/protocols/token-factory/create.ts
|
|
20
|
+
const debug = Debug("@ocap/tx-protocols:create-token-factory");
|
|
21
|
+
const runner = new Runner("create_token_factory");
|
|
22
|
+
const isTest = process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test" || process.env.CI;
|
|
23
|
+
runner.use(pipes.VerifyMultiSig(0));
|
|
24
|
+
const schema = Joi.object({
|
|
25
|
+
address: Joi.DID().prefix().role("ROLE_TOKEN_FACTORY").required(),
|
|
26
|
+
feeRate: Joi.number().min(0).max(2e3).required(),
|
|
27
|
+
curve: Joi.when("token.type", {
|
|
28
|
+
is: "CreditToken",
|
|
29
|
+
then: Joi.valid(null).optional().messages({ "any.only": "Should not provide curve for CreditToken" }),
|
|
30
|
+
otherwise: tokenFactory.curveSchema.required()
|
|
31
|
+
}),
|
|
32
|
+
reserveAddress: Joi.DID().prefix().role("ROLE_TOKEN").required(),
|
|
33
|
+
token: Joi.object({
|
|
34
|
+
name: Joi.string().min(1).max(32).required(),
|
|
35
|
+
description: Joi.string().min(16).max(128).required(),
|
|
36
|
+
symbol: Joi.string().min(2).max(6).uppercase().required(),
|
|
37
|
+
unit: Joi.string().min(1).max(6).lowercase().required(),
|
|
38
|
+
decimal: Joi.number().min(2).max(18).required(),
|
|
39
|
+
icon: Joi.string().optional().allow(null, ""),
|
|
40
|
+
maxTotalSupply: Joi.alternatives().try(Joi.BN().greater(0), Joi.string().valid("")).optional().allow(null),
|
|
41
|
+
website: Joi.string().uri({
|
|
42
|
+
scheme: isTest ? ["http", "https"] : ["https"],
|
|
43
|
+
allowRelative: false
|
|
44
|
+
}).max(256).optional().allow(null, ""),
|
|
45
|
+
metadata: Joi.any().required(),
|
|
46
|
+
spendersList: Joi.array().items(Joi.DID().prefix()).max(30).optional().allow(null).default(null),
|
|
47
|
+
mintersList: Joi.array().items(Joi.DID().prefix()).max(30).optional().allow(null).default(null),
|
|
48
|
+
type: Joi.string().valid("CreditToken", "BondingCurveToken").required()
|
|
49
|
+
}).required(),
|
|
50
|
+
data: Joi.any().optional().allow(null)
|
|
51
|
+
}).options({
|
|
52
|
+
stripUnknown: true,
|
|
53
|
+
noDefaults: false
|
|
54
|
+
});
|
|
55
|
+
runner.use((context, next) => {
|
|
56
|
+
const { error, value } = schema.validate(context.itx);
|
|
57
|
+
if (error) return next(new CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
|
|
58
|
+
context.itx.curve = value.curve;
|
|
59
|
+
const itxToken = context.itx.token;
|
|
60
|
+
if (itxToken.metadata) {
|
|
61
|
+
const metadata = decodeAnySafe(itxToken.metadata ?? null);
|
|
62
|
+
const { error: metadataError, value: metadataValue } = token.metadataSchema.validate(metadata?.value);
|
|
63
|
+
if (metadataError) return next(new CustomError("INVALID_TX", `Invalid metadata: ${metadataError.message}`));
|
|
64
|
+
itxToken.metadata = {
|
|
65
|
+
...metadata,
|
|
66
|
+
value: metadataValue
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
const tokenWithLists = itxToken;
|
|
70
|
+
const spendersList = getListField(itxToken, "spenders");
|
|
71
|
+
itxToken.spenders = spendersList?.length ? uniq(spendersList) : null;
|
|
72
|
+
delete tokenWithLists.spendersList;
|
|
73
|
+
const mintersList = getListField(itxToken, "minters");
|
|
74
|
+
itxToken.minters = mintersList?.length ? uniq(mintersList) : null;
|
|
75
|
+
delete tokenWithLists.mintersList;
|
|
76
|
+
return next();
|
|
77
|
+
});
|
|
78
|
+
runner.use(pipes.VerifyInfo([
|
|
79
|
+
{
|
|
80
|
+
error: "INVALID_TOKEN",
|
|
81
|
+
message: "Token address is not valid",
|
|
82
|
+
fn: (ctx) => {
|
|
83
|
+
const itxToken = ctx.itx.token;
|
|
84
|
+
return toTokenAddress({
|
|
85
|
+
...itxToken,
|
|
86
|
+
address: ""
|
|
87
|
+
}) === itxToken.address;
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
error: "INVALID_TOKEN_FACTORY",
|
|
92
|
+
message: "Token factory address is not valid",
|
|
93
|
+
fn: (ctx) => {
|
|
94
|
+
const context = ctx;
|
|
95
|
+
const itx = cloneDeep(context.itx);
|
|
96
|
+
itx.data = decodeAnySafe(itx.data ?? null);
|
|
97
|
+
itx.address = "";
|
|
98
|
+
return toTokenFactoryAddress(itx) === context.itx.address;
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
error: "INVALID_RESERVE_ADDRESS",
|
|
103
|
+
message: "Reserve address is not valid",
|
|
104
|
+
fn: (ctx) => {
|
|
105
|
+
const context = ctx;
|
|
106
|
+
return context.itx.reserveAddress === context.config.token.address;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
]));
|
|
110
|
+
runner.use(verify_icon_default());
|
|
111
|
+
runner.use(verify_url_default({ urlKeys: ["itx.token.website", "itx.token.metadata.value.communityUrl"] }));
|
|
112
|
+
runner.use(verify_ownership_default({ tokenKey: "itx.token" }));
|
|
113
|
+
runner.use((context, next) => {
|
|
114
|
+
const { reservedSymbols = [] } = context.config;
|
|
115
|
+
const { symbol } = context.itx.token;
|
|
116
|
+
if (reservedSymbols.includes(symbol.toUpperCase())) return next(new CustomError("INVALID_SYMBOL", `Token symbol can not be ${symbol}`));
|
|
117
|
+
return next();
|
|
118
|
+
});
|
|
119
|
+
runner.use(pipes.ExtractState({
|
|
120
|
+
from: "itx.address",
|
|
121
|
+
to: "tokenFactoryState",
|
|
122
|
+
table: "tokenFactory",
|
|
123
|
+
status: "OK"
|
|
124
|
+
}));
|
|
125
|
+
runner.use(pipes.VerifyInfo([{
|
|
126
|
+
error: "DUPLICATE_TOKEN_FACTORY",
|
|
127
|
+
message: "Token factory address already exists on chain",
|
|
128
|
+
fn: (ctx) => {
|
|
129
|
+
return isEmpty(ctx.tokenFactoryState);
|
|
130
|
+
}
|
|
131
|
+
}]));
|
|
132
|
+
runner.use(pipes.ExtractState({
|
|
133
|
+
from: "itx.token.address",
|
|
134
|
+
to: "tokenState",
|
|
135
|
+
table: "token",
|
|
136
|
+
status: "OK"
|
|
137
|
+
}));
|
|
138
|
+
runner.use(pipes.VerifyInfo([{
|
|
139
|
+
error: "DUPLICATE_TOKEN",
|
|
140
|
+
message: "Token address already exists on chain",
|
|
141
|
+
fn: (ctx) => {
|
|
142
|
+
return isEmpty(ctx.tokenState);
|
|
143
|
+
}
|
|
144
|
+
}]));
|
|
145
|
+
runner.use(pipes.ExtractState({
|
|
146
|
+
from: "tx.from",
|
|
147
|
+
to: "senderState",
|
|
148
|
+
status: "INVALID_SENDER_STATE",
|
|
149
|
+
table: "account"
|
|
150
|
+
}));
|
|
151
|
+
runner.use(pipes.VerifyAccountMigration({
|
|
152
|
+
stateKey: "senderState",
|
|
153
|
+
addressKey: "tx.from"
|
|
154
|
+
}));
|
|
155
|
+
runner.use(pipes.VerifyBlocked({ stateKeys: ["senderState"] }));
|
|
156
|
+
runner.use((context, next) => {
|
|
157
|
+
const { tx: tx$1, itx } = context;
|
|
158
|
+
const sender = tx$1.delegator || tx$1.from;
|
|
159
|
+
const receiver = context.config.token.address;
|
|
160
|
+
context.stakeAddress = toStakeAddress(sender, receiver, itx.token.symbol);
|
|
161
|
+
return next();
|
|
162
|
+
});
|
|
163
|
+
runner.use(pipes.ExtractState({
|
|
164
|
+
from: "stakeAddress",
|
|
165
|
+
to: "stakeState",
|
|
166
|
+
status: "INVALID_STAKE_STATE",
|
|
167
|
+
table: "stake"
|
|
168
|
+
}));
|
|
169
|
+
runner.use((context, next) => {
|
|
170
|
+
const { stakeState, config, itx } = context;
|
|
171
|
+
if (stakeState.revocable === false) return next(new CustomError("INVALID_STAKE_STATE", `Staking for token creating already locked: ${stakeState.address}`));
|
|
172
|
+
const actualStake = new BN(stakeState.tokens[config.token.address] || 0);
|
|
173
|
+
const requiredStake = fromTokenToUnit(itx.token.type === "CreditToken" ? config.transaction.txStake.createCreditToken : config.transaction.txStake.createToken, config.token.decimal);
|
|
174
|
+
if (actualStake.lt(requiredStake)) return next(new CustomError("INVALID_STAKE_STATE", `Insufficient stake amount: required ${fromUnitToToken(requiredStake, config.token.decimal)} ${config.token.symbol}`));
|
|
175
|
+
return next();
|
|
176
|
+
});
|
|
177
|
+
runner.use(pipes.ExtractState({
|
|
178
|
+
from: "tx.delegator",
|
|
179
|
+
to: "delegatorState",
|
|
180
|
+
status: "OK",
|
|
181
|
+
table: "account"
|
|
182
|
+
}));
|
|
183
|
+
runner.use(pipes.VerifyAccountMigration({
|
|
184
|
+
stateKey: "delegatorState",
|
|
185
|
+
addressKey: "tx.delegator"
|
|
186
|
+
}));
|
|
187
|
+
runner.use(pipes.VerifyDelegation({
|
|
188
|
+
type: "signature",
|
|
189
|
+
signerKey: "senderState",
|
|
190
|
+
delegatorKey: "delegatorState",
|
|
191
|
+
getRequirements: getDelegationRequirements
|
|
192
|
+
}));
|
|
193
|
+
runner.use(async function EnsureTokenSymbol(context, next) {
|
|
194
|
+
const itxToken = context.itx.token;
|
|
195
|
+
if (await context.statedb.token.existBySymbol(itxToken.symbol, context)) return next(new CustomError("DUPLICATE_SYMBOL", "Token symbol already exists"));
|
|
196
|
+
return next();
|
|
197
|
+
}, { persistError: true });
|
|
198
|
+
runner.use(ensure_gas_default((context) => {
|
|
199
|
+
const result = {
|
|
200
|
+
create: 2,
|
|
201
|
+
update: 2,
|
|
202
|
+
payment: 0
|
|
203
|
+
};
|
|
204
|
+
if (context.isDelegationChanged) result.update += 1;
|
|
205
|
+
return result;
|
|
206
|
+
}));
|
|
207
|
+
runner.use(ensure_cost_default({ attachSenderChanges: true }));
|
|
208
|
+
runner.use(pipes.TakeStateSnapshot());
|
|
209
|
+
runner.use(async (context, next) => {
|
|
210
|
+
const { tx: tx$1, itx, statedb, senderState, delegatorState, delegationState, senderChange, stakeState, stakeAddress, updateVaults, config } = context;
|
|
211
|
+
const data = decodeAnySafe(itx.data ?? null);
|
|
212
|
+
const owner = delegatorState ? delegatorState.address : senderState.address;
|
|
213
|
+
const itxToken = itx.token;
|
|
214
|
+
const { tokens: senderTokens = {} } = senderState;
|
|
215
|
+
const senderUpdates = senderChange ? applyTokenChange({ tokens: senderTokens }, senderChange) : { tokens: senderTokens };
|
|
216
|
+
const [newSenderState, newTokenState, newTokenFactoryState, newDelegationState, newStakeState] = await Promise.all([
|
|
217
|
+
statedb.account.update(senderState.address, account.update(senderState, {
|
|
218
|
+
nonce: tx$1.nonce,
|
|
219
|
+
pk: tx$1.pk,
|
|
220
|
+
...senderUpdates
|
|
221
|
+
}, context), context),
|
|
222
|
+
statedb.token.create(itxToken.address, token.create({
|
|
223
|
+
...cloneDeep(itxToken),
|
|
224
|
+
totalSupply: "0",
|
|
225
|
+
initialSupply: "0",
|
|
226
|
+
issuer: owner,
|
|
227
|
+
tokenFactoryAddress: itx.address
|
|
228
|
+
}, context), context),
|
|
229
|
+
statedb.tokenFactory.create(itx.address, tokenFactory.create({
|
|
230
|
+
...cloneDeep(itx),
|
|
231
|
+
owner,
|
|
232
|
+
tokenAddress: itxToken.address,
|
|
233
|
+
data
|
|
234
|
+
}, context), context),
|
|
235
|
+
context.isDelegationChanged ? statedb.delegation.update(delegationState.address, delegation.update(delegationState, {}, context), context) : delegationState,
|
|
236
|
+
statedb.stake.update(stakeAddress, stake.update(stakeState, {
|
|
237
|
+
revocable: false,
|
|
238
|
+
revokeWaitingPeriod: config.transaction.txStake.createTokenLockPeriod
|
|
239
|
+
}, context), context)
|
|
240
|
+
]);
|
|
241
|
+
if (updateVaults) await updateVaults();
|
|
242
|
+
context.senderState = newSenderState;
|
|
243
|
+
context.tokenState = newTokenState;
|
|
244
|
+
context.tokenFactoryState = newTokenFactoryState;
|
|
245
|
+
context.delegationState = newDelegationState;
|
|
246
|
+
context.stakeState = newStakeState;
|
|
247
|
+
debug("create token factory", newTokenFactoryState);
|
|
248
|
+
next();
|
|
249
|
+
}, { persistError: true });
|
|
250
|
+
runner.use(pipes.VerifyStateDiff());
|
|
251
|
+
var create_default = runner;
|
|
252
|
+
|
|
253
|
+
//#endregion
|
|
254
|
+
export { create_default as 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 };
|