@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,18 @@
|
|
|
1
|
+
import { IAssetFactoryState, IAssetState, IDecodedContext } from "@ocap/types";
|
|
2
|
+
import { PipeFunction } from "@ocap/tx-pipeline";
|
|
3
|
+
|
|
4
|
+
//#region src/protocols/asset/pipes/verify-itx-assets.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Context type for verify-itx-assets pipe.
|
|
8
|
+
* Requires: factoryState, itx
|
|
9
|
+
* Optional: expectedFactoryStates, assetStates
|
|
10
|
+
*/
|
|
11
|
+
type VerifyItxAssetsContext = IDecodedContext & {
|
|
12
|
+
factoryState?: IAssetFactoryState;
|
|
13
|
+
expectedFactoryStates?: IAssetFactoryState[];
|
|
14
|
+
assetStates?: IAssetState[];
|
|
15
|
+
};
|
|
16
|
+
declare const verify_itx_assets: PipeFunction<VerifyItxAssetsContext>;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { verify_itx_assets 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 _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
5
|
+
|
|
6
|
+
//#region src/protocols/asset/pipes/verify-itx-variables.ts
|
|
7
|
+
const verify_itx_variables = (context, next) => {
|
|
8
|
+
const { factoryState, itx } = context;
|
|
9
|
+
const variables = factoryState.input.variables;
|
|
10
|
+
const factoryInputs = (0, _ocap_util_lib_get_list_field.getListField)(itx, "variables").reduce((acc, x) => {
|
|
11
|
+
acc[x.name] = x.value;
|
|
12
|
+
return acc;
|
|
13
|
+
}, {});
|
|
14
|
+
const missingVariables = variables.filter((x) => x.required && !factoryInputs[x.name]);
|
|
15
|
+
if (missingVariables.length) return next(new _ocap_util_lib_error.CustomError("INVALID_FACTORY_INPUT", `Invalid itx.variables: missing required input variable: ${missingVariables.map((x) => x.name).join(", ")}`));
|
|
16
|
+
context.factoryInputs = factoryInputs;
|
|
17
|
+
return next();
|
|
18
|
+
};
|
|
19
|
+
var verify_itx_variables_default = verify_itx_variables;
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
exports.default = verify_itx_variables_default;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { IAssetFactoryState, IDecodedContext } from "@ocap/types";
|
|
2
|
+
import { PipeFunction } from "@ocap/tx-pipeline";
|
|
3
|
+
|
|
4
|
+
//#region src/protocols/asset/pipes/verify-itx-variables.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Context type for verify-itx-variables pipe.
|
|
8
|
+
* Requires: factoryState, itx
|
|
9
|
+
* Sets: factoryInputs
|
|
10
|
+
*/
|
|
11
|
+
type VerifyItxVariablesContext = IDecodedContext & {
|
|
12
|
+
factoryState?: IAssetFactoryState;
|
|
13
|
+
factoryInputs?: Record<string, unknown>;
|
|
14
|
+
};
|
|
15
|
+
declare const verify_itx_variables: PipeFunction<VerifyItxVariablesContext>;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { verify_itx_variables as default };
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
|
|
5
|
+
//#region src/protocols/asset/pipes/verify-mint-limit.ts
|
|
6
|
+
const verify_mint_limit = ({ factoryState }, next) => {
|
|
7
|
+
const factory = factoryState;
|
|
8
|
+
const limit = factory.limit;
|
|
9
|
+
if (limit === 0) return next();
|
|
10
|
+
if (factory.numMinted < limit) return next();
|
|
11
|
+
return next(new _ocap_util_lib_error.CustomError("EXCEED_MINT_LIMIT", "This request will exceed factory mint limit"));
|
|
12
|
+
};
|
|
13
|
+
var verify_mint_limit_default = verify_mint_limit;
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
exports.default = verify_mint_limit_default;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { IAssetFactoryState, IBaseContext } from "@ocap/types";
|
|
2
|
+
import { PipeFunction } from "@ocap/tx-pipeline";
|
|
3
|
+
|
|
4
|
+
//#region src/protocols/asset/pipes/verify-mint-limit.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Context type for verify-mint-limit pipe.
|
|
8
|
+
* Requires: factoryState
|
|
9
|
+
*/
|
|
10
|
+
type VerifyMintLimitContext = IBaseContext & {
|
|
11
|
+
factoryState?: IAssetFactoryState;
|
|
12
|
+
};
|
|
13
|
+
declare const verify_mint_limit: PipeFunction<VerifyMintLimitContext>;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { verify_mint_limit as default };
|
|
@@ -0,0 +1,114 @@
|
|
|
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 _ocap_state = require("@ocap/state");
|
|
9
|
+
let debug = require("debug");
|
|
10
|
+
debug = require_rolldown_runtime.__toESM(debug);
|
|
11
|
+
let _arcblock_validator = require("@arcblock/validator");
|
|
12
|
+
let deep_diff = require("deep-diff");
|
|
13
|
+
|
|
14
|
+
//#region src/protocols/asset/update.ts
|
|
15
|
+
const debug$1 = (0, debug.default)("@ocap/tx-protocols:update-asset");
|
|
16
|
+
const runner = new _ocap_tx_pipeline.Runner("update_asset");
|
|
17
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyMultiSig(0));
|
|
18
|
+
const schema = _arcblock_validator.Joi.object({
|
|
19
|
+
address: _arcblock_validator.Joi.DID().prefix().role("ROLE_ASSET").required(),
|
|
20
|
+
moniker: _arcblock_validator.Joi.string().min(2).max(255).optional().allow(null).allow(""),
|
|
21
|
+
consumed: _arcblock_validator.Joi.boolean().optional().allow(null).default(false),
|
|
22
|
+
data: _arcblock_validator.Joi.any().optional().allow(null)
|
|
23
|
+
}).options({
|
|
24
|
+
stripUnknown: true,
|
|
25
|
+
noDefaults: false
|
|
26
|
+
});
|
|
27
|
+
runner.use((context, next) => {
|
|
28
|
+
const { itx } = context;
|
|
29
|
+
const { error } = schema.validate(itx);
|
|
30
|
+
if (error) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
|
|
31
|
+
if (!itx.moniker && !itx.data) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "itx.moniker and itx.data can not be empty at the same time"));
|
|
32
|
+
context.newData = require_util.decodeAnySafe(itx.data ?? null);
|
|
33
|
+
return next();
|
|
34
|
+
});
|
|
35
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
36
|
+
from: "itx.address",
|
|
37
|
+
to: "assetState",
|
|
38
|
+
status: "INVALID_ASSET",
|
|
39
|
+
table: "asset"
|
|
40
|
+
}));
|
|
41
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
42
|
+
from: "assetState.issuer",
|
|
43
|
+
to: "issuerState",
|
|
44
|
+
status: "OK",
|
|
45
|
+
table: "account"
|
|
46
|
+
}));
|
|
47
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
48
|
+
from: "tx.from",
|
|
49
|
+
to: "senderState",
|
|
50
|
+
status: "INVALID_SENDER_STATE",
|
|
51
|
+
table: "account"
|
|
52
|
+
}));
|
|
53
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
54
|
+
stateKey: "senderState",
|
|
55
|
+
addressKey: "tx.from"
|
|
56
|
+
}));
|
|
57
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyUpdater({
|
|
58
|
+
assetKey: "assetState",
|
|
59
|
+
ownerKey: "senderState",
|
|
60
|
+
updaterKey: ["owner", "issuer"]
|
|
61
|
+
}));
|
|
62
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyInfo([{
|
|
63
|
+
error: "READONLY_ASSET",
|
|
64
|
+
message: "Can not update a readonly asset",
|
|
65
|
+
fn: (ctx) => ctx.assetState.readonly === false,
|
|
66
|
+
persist: true
|
|
67
|
+
}, {
|
|
68
|
+
error: "CONSUMED_ASSET",
|
|
69
|
+
message: "Can not consume an already consumed asset",
|
|
70
|
+
fn: (ctx) => {
|
|
71
|
+
const context = ctx;
|
|
72
|
+
return !(context.itx.consumed && context.assetState.consumedTime);
|
|
73
|
+
},
|
|
74
|
+
persist: true
|
|
75
|
+
}]));
|
|
76
|
+
runner.use((context, next) => {
|
|
77
|
+
const { itx, newData, senderState, assetState, issuerState } = context;
|
|
78
|
+
if (issuerState && senderState.address === issuerState.address) {
|
|
79
|
+
if (itx.moniker !== assetState.moniker) return next(new _ocap_util_lib_error.CustomError("FORBIDDEN", "Asset moniker can only be updated by owner"));
|
|
80
|
+
if (newData?.type !== assetState.data?.type) return next(new _ocap_util_lib_error.CustomError("FORBIDDEN", "Asset data type can only be updated by owner"));
|
|
81
|
+
if (((0, deep_diff.diff)(assetState.data?.value, newData?.value) || []).every((x) => x.kind === "N" || x.kind === "A" && x.item.kind === "N") === false) return next(new _ocap_util_lib_error.CustomError("APPEND_ONLY", "Asset data value can only be updated in append only mode"));
|
|
82
|
+
}
|
|
83
|
+
return next();
|
|
84
|
+
});
|
|
85
|
+
runner.use(require_pipes_ensure_gas.default(() => ({
|
|
86
|
+
create: 0,
|
|
87
|
+
update: 2,
|
|
88
|
+
payment: 0
|
|
89
|
+
})));
|
|
90
|
+
runner.use(require_pipes_ensure_cost.default({ attachSenderChanges: true }));
|
|
91
|
+
runner.use(_ocap_tx_pipeline.pipes.TakeStateSnapshot());
|
|
92
|
+
runner.use(async (context, next) => {
|
|
93
|
+
const { tx, itx, txTime, newData, statedb, senderState, senderUpdates, assetState, updateVaults } = context;
|
|
94
|
+
const updates = {
|
|
95
|
+
moniker: itx.moniker || assetState.moniker,
|
|
96
|
+
data: newData || assetState.data
|
|
97
|
+
};
|
|
98
|
+
if (itx.consumed && !assetState.consumedTime) updates.consumedTime = txTime;
|
|
99
|
+
const [newSenderState, newAssetState] = await Promise.all([statedb.account.update(senderState.address, _ocap_state.account.update(senderState, {
|
|
100
|
+
nonce: tx.nonce,
|
|
101
|
+
pk: tx.pk,
|
|
102
|
+
...senderUpdates
|
|
103
|
+
}, context), context), statedb.asset.update(itx.address, _ocap_state.asset.update(assetState, updates, context), context)]);
|
|
104
|
+
if (updateVaults) await updateVaults();
|
|
105
|
+
context.senderState = newSenderState;
|
|
106
|
+
context.assetState = newAssetState;
|
|
107
|
+
debug$1("update", newAssetState);
|
|
108
|
+
next();
|
|
109
|
+
}, { persistError: true });
|
|
110
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyStateDiff());
|
|
111
|
+
var update_default = runner;
|
|
112
|
+
|
|
113
|
+
//#endregion
|
|
114
|
+
exports.default = update_default;
|
|
@@ -0,0 +1,161 @@
|
|
|
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 lodash_get = require("lodash/get");
|
|
9
|
+
lodash_get = require_rolldown_runtime.__toESM(lodash_get);
|
|
10
|
+
let _arcblock_did_util = require("@arcblock/did-util");
|
|
11
|
+
let _ocap_state = require("@ocap/state");
|
|
12
|
+
let _ocap_util = require("@ocap/util");
|
|
13
|
+
let debug = require("debug");
|
|
14
|
+
debug = require_rolldown_runtime.__toESM(debug);
|
|
15
|
+
let _ocap_message = require("@ocap/message");
|
|
16
|
+
let lodash_cloneDeep = require("lodash/cloneDeep");
|
|
17
|
+
lodash_cloneDeep = require_rolldown_runtime.__toESM(lodash_cloneDeep);
|
|
18
|
+
let _ocap_asset = require("@ocap/asset");
|
|
19
|
+
let lodash_isEmpty = require("lodash/isEmpty");
|
|
20
|
+
lodash_isEmpty = require_rolldown_runtime.__toESM(lodash_isEmpty);
|
|
21
|
+
|
|
22
|
+
//#region src/protocols/factory/create.ts
|
|
23
|
+
const debug$1 = (0, debug.default)("@ocap/tx-protocols:create-factory");
|
|
24
|
+
const runner = new _ocap_tx_pipeline.Runner("create_factory");
|
|
25
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyMultiSig(0));
|
|
26
|
+
runner.use((context, next) => {
|
|
27
|
+
const factoryProps = (0, _ocap_message.formatMessage)("CreateFactoryTx", context.itx);
|
|
28
|
+
try {
|
|
29
|
+
(0, _ocap_asset.isValidFactory)(factoryProps);
|
|
30
|
+
} catch (err) {
|
|
31
|
+
return next(new _ocap_util_lib_error.CustomError("INVALID_FACTORY_PROPS", err.message));
|
|
32
|
+
}
|
|
33
|
+
if (factoryProps.output.data) factoryProps.output.data = require_util.decodeAnySafe(factoryProps.output.data);
|
|
34
|
+
if (factoryProps.name.length < 2 || factoryProps.name.length > 255) return next(new _ocap_util_lib_error.CustomError("INVALID_FACTORY_PROPS", "Length of factory name should between 2 and 255 characters"));
|
|
35
|
+
const props = (0, lodash_cloneDeep.default)(factoryProps);
|
|
36
|
+
props.address = "";
|
|
37
|
+
if ((0, _arcblock_did_util.toFactoryAddress)(props) !== factoryProps.address) return next(new _ocap_util_lib_error.CustomError("INVALID_FACTORY_PROPS", "Factory address is not valid"));
|
|
38
|
+
const factoryTokenAddresses = (factoryProps.input.tokens || []).map((x) => x.address);
|
|
39
|
+
const maxListSize = (0, lodash_get.default)(context, "config.transaction.maxListSize");
|
|
40
|
+
if (factoryTokenAddresses.length > maxListSize) return next(new _ocap_util_lib_error.CustomError("INVALID_FACTORY_INPUT", `input.tokens exceeded max allowed length: ${maxListSize}`));
|
|
41
|
+
if (factoryProps.input.assets.length > maxListSize) return next(new _ocap_util_lib_error.CustomError("INVALID_FACTORY_INPUT", `input.assets exceeded max allowed length: ${maxListSize}`));
|
|
42
|
+
if (new _ocap_util.BN(factoryProps.input.value || 0).gt(new _ocap_util.BN(0))) {
|
|
43
|
+
factoryTokenAddresses.push(context.config.token.address);
|
|
44
|
+
factoryProps.input.tokens.push({
|
|
45
|
+
address: context.config.token.address,
|
|
46
|
+
value: factoryProps.input.value
|
|
47
|
+
});
|
|
48
|
+
factoryProps.input.value = "0";
|
|
49
|
+
}
|
|
50
|
+
context.factoryTokens = factoryTokenAddresses;
|
|
51
|
+
context.factoryProps = factoryProps;
|
|
52
|
+
return next();
|
|
53
|
+
});
|
|
54
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
55
|
+
from: "itx.address",
|
|
56
|
+
to: "factoryState",
|
|
57
|
+
status: "OK"
|
|
58
|
+
}));
|
|
59
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyInfo([{
|
|
60
|
+
error: "DUPLICATE_FACTORY",
|
|
61
|
+
message: "This asset factory already exist on chain",
|
|
62
|
+
fn: (ctx) => {
|
|
63
|
+
return (0, lodash_isEmpty.default)(ctx.factoryState);
|
|
64
|
+
}
|
|
65
|
+
}]));
|
|
66
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
67
|
+
from: "tx.from",
|
|
68
|
+
to: "senderState",
|
|
69
|
+
table: "account",
|
|
70
|
+
status: "INVALID_SENDER_STATE"
|
|
71
|
+
}));
|
|
72
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
73
|
+
stateKey: "senderState",
|
|
74
|
+
addressKey: "tx.from"
|
|
75
|
+
}));
|
|
76
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
77
|
+
from: "tx.delegator",
|
|
78
|
+
to: "delegatorState",
|
|
79
|
+
status: "OK",
|
|
80
|
+
table: "account"
|
|
81
|
+
}));
|
|
82
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
83
|
+
stateKey: "delegatorState",
|
|
84
|
+
addressKey: "tx.delegator"
|
|
85
|
+
}));
|
|
86
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyDelegation({
|
|
87
|
+
type: "signature",
|
|
88
|
+
signerKey: "senderState",
|
|
89
|
+
delegatorKey: "delegatorState",
|
|
90
|
+
getRequirements: require_util.getDelegationRequirements
|
|
91
|
+
}));
|
|
92
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
93
|
+
from: "factoryTokens",
|
|
94
|
+
to: "tokenStates",
|
|
95
|
+
table: "token",
|
|
96
|
+
status: "INVALID_FACTORY_INPUT"
|
|
97
|
+
}));
|
|
98
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
99
|
+
from: "factoryProps.input.assets",
|
|
100
|
+
to: "inputAssetStates",
|
|
101
|
+
table: "asset",
|
|
102
|
+
status: "OK"
|
|
103
|
+
}));
|
|
104
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
105
|
+
from: "factoryProps.input.assets",
|
|
106
|
+
to: "inputFactoryStates",
|
|
107
|
+
table: "factory",
|
|
108
|
+
status: "OK"
|
|
109
|
+
}));
|
|
110
|
+
runner.use((context, next) => {
|
|
111
|
+
const { inputAssetStates = [], inputFactoryStates = [], factoryProps } = context;
|
|
112
|
+
if (inputAssetStates.some((x) => !!x.consumedTime)) return next(new _ocap_util_lib_error.CustomError("INVALID_FACTORY_INPUT", "Some of input.assets already consumed"));
|
|
113
|
+
if (inputAssetStates.length + inputFactoryStates.length === factoryProps.input.assets.length) return next();
|
|
114
|
+
return next(new _ocap_util_lib_error.CustomError("INVALID_FACTORY_INPUT", "Not all input.assets exist on chain"));
|
|
115
|
+
});
|
|
116
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
117
|
+
from: "factoryProps.trustedIssuers",
|
|
118
|
+
to: "issuerStates",
|
|
119
|
+
table: "account",
|
|
120
|
+
status: "INVALID_ISSUER_STATE"
|
|
121
|
+
}));
|
|
122
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
123
|
+
stateKey: "issuerStates",
|
|
124
|
+
addressKey: "factoryProps.trustedIssuers"
|
|
125
|
+
}));
|
|
126
|
+
runner.use(require_pipes_ensure_gas.default(() => ({
|
|
127
|
+
create: 1,
|
|
128
|
+
update: 2,
|
|
129
|
+
payment: 0
|
|
130
|
+
})));
|
|
131
|
+
runner.use(require_pipes_ensure_cost.default({ attachSenderChanges: true }));
|
|
132
|
+
runner.use(_ocap_tx_pipeline.pipes.TakeStateSnapshot());
|
|
133
|
+
runner.use(async (context, next) => {
|
|
134
|
+
const { tx, itx, statedb, senderState, delegatorState, delegationState, senderUpdates, factoryProps, updateVaults } = context;
|
|
135
|
+
const tokens = { [context.config.token.address]: "0" };
|
|
136
|
+
const owner = delegatorState ? delegatorState.address : senderState.address;
|
|
137
|
+
const [newSenderState, factoryState, newDelegationState] = await Promise.all([
|
|
138
|
+
statedb.account.update(senderState.address, _ocap_state.account.update(senderState, {
|
|
139
|
+
nonce: tx.nonce,
|
|
140
|
+
pk: tx.pk,
|
|
141
|
+
...senderUpdates
|
|
142
|
+
}, context), context),
|
|
143
|
+
statedb.factory.create(itx.address, _ocap_state.factory.create({
|
|
144
|
+
...factoryProps,
|
|
145
|
+
tokens,
|
|
146
|
+
owner
|
|
147
|
+
}, context), context),
|
|
148
|
+
context.isDelegationChanged ? statedb.delegation.update(delegationState.address, _ocap_state.delegation.update(delegationState, {}, context), context) : delegationState ?? null
|
|
149
|
+
]);
|
|
150
|
+
if (updateVaults) await updateVaults();
|
|
151
|
+
context.senderState = newSenderState;
|
|
152
|
+
context.factoryState = factoryState ?? void 0;
|
|
153
|
+
context.delegationState = newDelegationState ?? void 0;
|
|
154
|
+
debug$1("createFactory", factoryState);
|
|
155
|
+
next();
|
|
156
|
+
}, { persistError: true });
|
|
157
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyStateDiff());
|
|
158
|
+
var create_default = runner;
|
|
159
|
+
|
|
160
|
+
//#endregion
|
|
161
|
+
exports.default = create_default;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region src/protocols/factory/create.d.ts
|
|
2
|
+
/** Formatted factory properties from formatMessage */
|
|
3
|
+
interface FormattedFactoryProps {
|
|
4
|
+
name: string;
|
|
5
|
+
description: string;
|
|
6
|
+
settlement: string;
|
|
7
|
+
limit: number;
|
|
8
|
+
trustedIssuers: string[];
|
|
9
|
+
input: {
|
|
10
|
+
value: string;
|
|
11
|
+
tokens: Array<{
|
|
12
|
+
address: string;
|
|
13
|
+
value: string;
|
|
14
|
+
}>;
|
|
15
|
+
assets: string[];
|
|
16
|
+
variables: unknown[];
|
|
17
|
+
};
|
|
18
|
+
output: {
|
|
19
|
+
data?: unknown;
|
|
20
|
+
[key: string]: unknown;
|
|
21
|
+
};
|
|
22
|
+
hooks: unknown[];
|
|
23
|
+
address: string;
|
|
24
|
+
display?: unknown;
|
|
25
|
+
data?: unknown;
|
|
26
|
+
}
|
|
27
|
+
declare const runner: any;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { FormattedFactoryProps, runner as default };
|
|
@@ -0,0 +1,223 @@
|
|
|
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 _ocap_state = require("@ocap/state");
|
|
9
|
+
let _ocap_util = require("@ocap/util");
|
|
10
|
+
let debug = require("debug");
|
|
11
|
+
debug = require_rolldown_runtime.__toESM(debug);
|
|
12
|
+
let _arcblock_validator = require("@arcblock/validator");
|
|
13
|
+
let _ocap_util_lib_get_related_addr = require("@ocap/util/lib/get-related-addr");
|
|
14
|
+
|
|
15
|
+
//#region src/protocols/governance/claim-stake.ts
|
|
16
|
+
const debug$1 = (0, debug.default)("@ocap/tx-protocols:claim-stake");
|
|
17
|
+
const runner = new _ocap_tx_pipeline.Runner("claim_stake");
|
|
18
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyMultiSig(0));
|
|
19
|
+
const schema = _arcblock_validator.Joi.object({
|
|
20
|
+
address: _arcblock_validator.Joi.DID().prefix().role("ROLE_STAKE").required(),
|
|
21
|
+
evidence: _arcblock_validator.Joi.object({ hash: _arcblock_validator.Joi.string().regex(_arcblock_validator.patterns.txHash).required() }).required(),
|
|
22
|
+
data: _arcblock_validator.Joi.any().optional().allow(null)
|
|
23
|
+
}).options({
|
|
24
|
+
stripUnknown: true,
|
|
25
|
+
noDefaults: false
|
|
26
|
+
});
|
|
27
|
+
runner.use(({ itx }, next) => {
|
|
28
|
+
const { error } = schema.validate(itx);
|
|
29
|
+
return next(error ? new _ocap_util_lib_error.CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
|
|
30
|
+
});
|
|
31
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
32
|
+
from: "tx.from",
|
|
33
|
+
to: "senderState",
|
|
34
|
+
status: "INVALID_SENDER_STATE",
|
|
35
|
+
table: "account"
|
|
36
|
+
}));
|
|
37
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
38
|
+
from: "itx.address",
|
|
39
|
+
to: "stakeState",
|
|
40
|
+
status: "INVALID_STAKE_STATE",
|
|
41
|
+
table: "stake"
|
|
42
|
+
}));
|
|
43
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
44
|
+
stateKey: "senderState",
|
|
45
|
+
addressKey: "tx.from"
|
|
46
|
+
}));
|
|
47
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyInfo([{
|
|
48
|
+
error: "SENDER_NOT_MATCH",
|
|
49
|
+
message: "You are not allowed to claim stake from this address",
|
|
50
|
+
fn: (ctx) => {
|
|
51
|
+
const { senderState, stakeState } = ctx;
|
|
52
|
+
return (0, _ocap_util_lib_get_related_addr.getRelatedAddresses)(senderState).includes(stakeState.sender);
|
|
53
|
+
}
|
|
54
|
+
}]));
|
|
55
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
56
|
+
from: "itx.evidence.hash",
|
|
57
|
+
to: "evidenceState",
|
|
58
|
+
status: "OK",
|
|
59
|
+
table: "evidence"
|
|
60
|
+
}));
|
|
61
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyInfo([{
|
|
62
|
+
error: "ALREADY_CLAIMED",
|
|
63
|
+
message: "Revoke evidence already seen on this chain",
|
|
64
|
+
fn: (ctx) => {
|
|
65
|
+
const { evidenceState } = ctx;
|
|
66
|
+
return !evidenceState;
|
|
67
|
+
}
|
|
68
|
+
}]));
|
|
69
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
70
|
+
from: "itx.evidence.hash",
|
|
71
|
+
to: "txState",
|
|
72
|
+
status: "INVALID_TX",
|
|
73
|
+
table: "tx"
|
|
74
|
+
}));
|
|
75
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyInfo([
|
|
76
|
+
{
|
|
77
|
+
error: "INVALID_TX",
|
|
78
|
+
message: "Evidence tx is not valid",
|
|
79
|
+
fn: (ctx) => {
|
|
80
|
+
const { txState } = ctx;
|
|
81
|
+
return txState.code === "OK";
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
error: "INVALID_TX",
|
|
86
|
+
message: "Evidence tx type is not valid",
|
|
87
|
+
fn: (ctx) => {
|
|
88
|
+
const { txState } = ctx;
|
|
89
|
+
return txState.type === "revoke_stake";
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
error: "INVALID_TX",
|
|
94
|
+
message: "Evidence tx does not belong to same stake",
|
|
95
|
+
fn: (ctx) => {
|
|
96
|
+
const { txState, itx } = ctx;
|
|
97
|
+
return txState.tx.itxJson.address === itx.address;
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
error: "WITHIN_WAITING_PERIOD",
|
|
102
|
+
message: "You can not claim stake before waiting period ends",
|
|
103
|
+
fn: (ctx) => {
|
|
104
|
+
const { txState, stakeState, txTime } = ctx;
|
|
105
|
+
const end = +new Date(txState.time) + (stakeState.revokeWaitingPeriod || 0) * 1e3;
|
|
106
|
+
return +new Date(txTime) > end;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
]));
|
|
110
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyTxInput({
|
|
111
|
+
fieldKey: "txState.tx.itxJson.outputs",
|
|
112
|
+
inputsKey: "outputs",
|
|
113
|
+
sendersKey: "receivers",
|
|
114
|
+
tokensKey: "tokens",
|
|
115
|
+
assetsKey: "assets"
|
|
116
|
+
}));
|
|
117
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
118
|
+
from: "receivers",
|
|
119
|
+
to: "receiverStates",
|
|
120
|
+
status: "INVALID_RECEIVER_STATE",
|
|
121
|
+
table: "account"
|
|
122
|
+
}));
|
|
123
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
124
|
+
from: "tokens",
|
|
125
|
+
to: "tokenStates",
|
|
126
|
+
status: "INVALID_TOKEN",
|
|
127
|
+
table: "token"
|
|
128
|
+
}));
|
|
129
|
+
runner.use((context, next) => {
|
|
130
|
+
const { outputs = [], stakeState } = context;
|
|
131
|
+
const tokensToClaim = {};
|
|
132
|
+
outputs.forEach(({ tokens }) => {
|
|
133
|
+
(tokens || []).forEach(({ address, value }) => {
|
|
134
|
+
if (typeof tokensToClaim[address] === "undefined") tokensToClaim[address] = new _ocap_util.BN(0);
|
|
135
|
+
tokensToClaim[address] = tokensToClaim[address].add(new _ocap_util.BN(value));
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
context.tokenCondition = {
|
|
139
|
+
owner: stakeState.address,
|
|
140
|
+
tokens: Object.keys(tokensToClaim).map((address) => ({
|
|
141
|
+
address,
|
|
142
|
+
value: tokensToClaim[address]
|
|
143
|
+
}))
|
|
144
|
+
};
|
|
145
|
+
next();
|
|
146
|
+
});
|
|
147
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyTokenBalance({
|
|
148
|
+
ownerKey: "stakeState",
|
|
149
|
+
conditionKey: "tokenCondition",
|
|
150
|
+
tokensKey: "revokedTokens"
|
|
151
|
+
}));
|
|
152
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
153
|
+
from: "assets",
|
|
154
|
+
to: "assetStates",
|
|
155
|
+
status: "OK",
|
|
156
|
+
table: "asset"
|
|
157
|
+
}));
|
|
158
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyTransferrable({ assets: "assetStates" }));
|
|
159
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyUpdater({
|
|
160
|
+
assetKey: "assetStates",
|
|
161
|
+
ownerKey: "stakeState"
|
|
162
|
+
}));
|
|
163
|
+
runner.use(require_pipes_ensure_gas.default((context) => {
|
|
164
|
+
const result = {
|
|
165
|
+
create: 1,
|
|
166
|
+
update: 2,
|
|
167
|
+
payment: 0
|
|
168
|
+
};
|
|
169
|
+
if (context.receiverStates) result.update += context.receiverStates.length;
|
|
170
|
+
if (context.assetStates) result.update += context.assetStates.length;
|
|
171
|
+
return result;
|
|
172
|
+
}));
|
|
173
|
+
runner.use(require_pipes_ensure_cost.default({ attachSenderChanges: true }));
|
|
174
|
+
runner.use(_ocap_tx_pipeline.pipes.TakeStateSnapshot());
|
|
175
|
+
runner.use(async (context, next) => {
|
|
176
|
+
const { tx, itx, outputs = [], statedb, senderState, senderChange, stakeState, receiverStates = [], updateVaults, assetStates = [] } = context;
|
|
177
|
+
const receiverUpdates = {};
|
|
178
|
+
const assetUpdates = {};
|
|
179
|
+
const stakeUpdates = {
|
|
180
|
+
revokedTokens: stakeState.revokedTokens || {},
|
|
181
|
+
revokedAssets: stakeState.revokedAssets || []
|
|
182
|
+
};
|
|
183
|
+
outputs.forEach((x) => {
|
|
184
|
+
const { owner, tokens, assets } = x;
|
|
185
|
+
const ownerState = receiverStates.find((s) => (0, _ocap_util_lib_get_related_addr.getRelatedAddresses)(s).includes(owner));
|
|
186
|
+
receiverUpdates[ownerState.address] = require_util.applyTokenUpdates(tokens || [], ownerState, "add");
|
|
187
|
+
if (senderChange && ownerState.address === senderChange.address) receiverUpdates[ownerState.address] = require_util.applyTokenChange(receiverUpdates[ownerState.address], senderChange);
|
|
188
|
+
(assets || []).forEach((a) => {
|
|
189
|
+
assetUpdates[a] = { owner: ownerState.address };
|
|
190
|
+
});
|
|
191
|
+
stakeUpdates.revokedTokens = require_util.applyTokenUpdates(tokens || [], { tokens: stakeUpdates.revokedTokens }, "sub").tokens;
|
|
192
|
+
stakeUpdates.revokedAssets = stakeUpdates.revokedAssets.filter((a) => (assets || []).includes(a) === false);
|
|
193
|
+
});
|
|
194
|
+
const isAlsoSigner = !!receiverUpdates[senderState.address];
|
|
195
|
+
const [newSenderState, newReceiverStates, newStakeState, newAssetStates, newEvidenceState] = await Promise.all([
|
|
196
|
+
statedb.account.update(senderState.address, _ocap_state.account.update(senderState, Object.assign({ nonce: tx.nonce }, receiverUpdates[senderState.address] || (senderChange ? require_util.applyTokenChange(senderState, senderChange) : {})), context), context),
|
|
197
|
+
Promise.all(receiverStates.filter((x) => x.address !== senderState.address).map((x) => statedb.account.update(x.address, _ocap_state.account.update(x, receiverUpdates[x.address], context), context))),
|
|
198
|
+
statedb.stake.update(stakeState.address, _ocap_state.stake.update(stakeState, stakeUpdates, context), context),
|
|
199
|
+
Promise.all(assetStates.map((x) => statedb.asset.update(x.address, _ocap_state.asset.update(x, assetUpdates[x.address], context), context))),
|
|
200
|
+
statedb.evidence.create(itx.evidence.hash, _ocap_state.evidence.create({
|
|
201
|
+
hash: itx.evidence.hash,
|
|
202
|
+
data: "claim-stake"
|
|
203
|
+
}, context), context)
|
|
204
|
+
]);
|
|
205
|
+
if (updateVaults) await updateVaults();
|
|
206
|
+
context.senderState = newSenderState;
|
|
207
|
+
context.receiverStates = isAlsoSigner ? newReceiverStates.concat(newSenderState) : newReceiverStates;
|
|
208
|
+
context.stakeState = newStakeState;
|
|
209
|
+
context.assetStates = newAssetStates;
|
|
210
|
+
context.evidenceState = newEvidenceState;
|
|
211
|
+
debug$1("claim-stake", {
|
|
212
|
+
address: itx.address,
|
|
213
|
+
stakeUpdates,
|
|
214
|
+
receiverUpdates,
|
|
215
|
+
assetUpdates
|
|
216
|
+
});
|
|
217
|
+
next();
|
|
218
|
+
}, { persistError: true });
|
|
219
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyStateDiff());
|
|
220
|
+
var claim_stake_default = runner;
|
|
221
|
+
|
|
222
|
+
//#endregion
|
|
223
|
+
exports.default = claim_stake_default;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { BN } from "@ocap/util";
|
|
2
|
+
|
|
3
|
+
//#region src/protocols/governance/claim-stake.d.ts
|
|
4
|
+
/** Token input type */
|
|
5
|
+
interface TokenInput {
|
|
6
|
+
address: string;
|
|
7
|
+
value: string;
|
|
8
|
+
}
|
|
9
|
+
/** Multi-output type */
|
|
10
|
+
interface MultiOutput {
|
|
11
|
+
owner: string;
|
|
12
|
+
tokensList?: TokenInput[];
|
|
13
|
+
tokens: TokenInput[];
|
|
14
|
+
assetsList?: string[];
|
|
15
|
+
assets: string[];
|
|
16
|
+
}
|
|
17
|
+
/** Token condition type for VerifyTokenBalance */
|
|
18
|
+
interface TokenCondition {
|
|
19
|
+
owner: string;
|
|
20
|
+
tokens: Array<{
|
|
21
|
+
address: string;
|
|
22
|
+
value: BN;
|
|
23
|
+
}>;
|
|
24
|
+
}
|
|
25
|
+
declare const runner: any;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { MultiOutput, TokenCondition, TokenInput, runner as default };
|