@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,229 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
3
|
+
const require_util = require('../../util.cjs');
|
|
4
|
+
const require_pipes_ensure_cost = require('../../pipes/ensure-cost.cjs');
|
|
5
|
+
const require_pipes_ensure_gas = require('../../pipes/ensure-gas.cjs');
|
|
6
|
+
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
7
|
+
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
8
|
+
let _arcblock_did_util = require("@arcblock/did-util");
|
|
9
|
+
let _ocap_state = require("@ocap/state");
|
|
10
|
+
let _ocap_util = require("@ocap/util");
|
|
11
|
+
let _ocap_message = require("@ocap/message");
|
|
12
|
+
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
13
|
+
let _arcblock_validator = require("@arcblock/validator");
|
|
14
|
+
let lodash_isEmpty = require("lodash/isEmpty");
|
|
15
|
+
lodash_isEmpty = require_rolldown_runtime.__toESM(lodash_isEmpty);
|
|
16
|
+
|
|
17
|
+
//#region src/protocols/trade/transfer-v2.ts
|
|
18
|
+
const runner = new _ocap_tx_pipeline.Runner("transfer_v2");
|
|
19
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyMultiSig(0));
|
|
20
|
+
const schema = _arcblock_validator.Joi.object({
|
|
21
|
+
to: _arcblock_validator.schemas.tokenHolder.required(),
|
|
22
|
+
value: _arcblock_validator.Joi.any().optional().allow(null),
|
|
23
|
+
tokensList: _arcblock_validator.Joi.array().items(_arcblock_validator.schemas.tokenInput).default([]),
|
|
24
|
+
assetsList: _arcblock_validator.Joi.array().items(_arcblock_validator.Joi.DID().prefix().role("ROLE_ASSET")).default([]),
|
|
25
|
+
data: _arcblock_validator.Joi.any().optional().allow(null)
|
|
26
|
+
}).options({
|
|
27
|
+
stripUnknown: true,
|
|
28
|
+
noDefaults: false
|
|
29
|
+
});
|
|
30
|
+
runner.use((context, next) => {
|
|
31
|
+
const { error } = schema.validate(context.itx);
|
|
32
|
+
if (error) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
|
|
33
|
+
return next();
|
|
34
|
+
});
|
|
35
|
+
runner.use((context, next) => {
|
|
36
|
+
context.assets = (0, _ocap_util_lib_get_list_field.getListField)(context, "itx.assets");
|
|
37
|
+
context.tokens = (0, _ocap_util_lib_get_list_field.getListField)(context, "itx.tokens");
|
|
38
|
+
context.tokenAddress = (context.tokens || []).map((x) => x.address);
|
|
39
|
+
next();
|
|
40
|
+
});
|
|
41
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyInfo([{
|
|
42
|
+
error: "INSUFFICIENT_DATA",
|
|
43
|
+
message: "Can not transfer without any primary token or assets or secondary tokens",
|
|
44
|
+
fn: (ctx) => {
|
|
45
|
+
const { itx, assets, tokens } = ctx;
|
|
46
|
+
if (itx.to && (itx.value || (0, lodash_isEmpty.default)(assets) === false || (0, lodash_isEmpty.default)(tokens) === false)) return true;
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}, {
|
|
50
|
+
error: "INVALID_TX",
|
|
51
|
+
message: "Can not transfer primary token smaller than 0",
|
|
52
|
+
fn: (ctx) => {
|
|
53
|
+
const { itx, assets, tokens } = ctx;
|
|
54
|
+
if ((0, lodash_isEmpty.default)(tokens) && (0, lodash_isEmpty.default)(assets)) {
|
|
55
|
+
if (new _ocap_util.BN(itx.value ? (0, _ocap_message.decodeBigInt)(itx.value) : 0).lte(new _ocap_util.BN(0))) return false;
|
|
56
|
+
}
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
}]));
|
|
60
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyListSize({ listKey: ["assets", "tokens"] }));
|
|
61
|
+
runner.use((context, next) => {
|
|
62
|
+
if (context.itx.value) {
|
|
63
|
+
const amount = new _ocap_util.BN((0, _ocap_message.decodeBigInt)(context.itx.value));
|
|
64
|
+
if (amount.gt(new _ocap_util.BN(0))) {
|
|
65
|
+
const tokens = context.tokens || [];
|
|
66
|
+
tokens.push({
|
|
67
|
+
address: context.config.token.address,
|
|
68
|
+
value: amount.toString()
|
|
69
|
+
});
|
|
70
|
+
context.tokens = tokens;
|
|
71
|
+
context.itx.value = void 0;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
next();
|
|
75
|
+
});
|
|
76
|
+
runner.use(require_pipes_ensure_gas.default((context) => {
|
|
77
|
+
const result = {
|
|
78
|
+
create: 0,
|
|
79
|
+
update: 2,
|
|
80
|
+
payment: 0
|
|
81
|
+
};
|
|
82
|
+
result.update += context.assetStates?.length || 0;
|
|
83
|
+
if (context.receiverState) result.update += 1;
|
|
84
|
+
else result.create += 1;
|
|
85
|
+
return result;
|
|
86
|
+
}));
|
|
87
|
+
runner.use(async (context, next) => {
|
|
88
|
+
const { statedb, tx, gasVault } = context;
|
|
89
|
+
const accounts = [
|
|
90
|
+
tx.from,
|
|
91
|
+
context.receiver,
|
|
92
|
+
gasVault
|
|
93
|
+
].filter(Boolean);
|
|
94
|
+
await Promise.all([...accounts.map((x) => statedb.account.get(x, context)), statedb.stake.get((0, _arcblock_did_util.toStakeAddress)(tx.from, tx.from), context)]);
|
|
95
|
+
next();
|
|
96
|
+
});
|
|
97
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
98
|
+
from: "tx.from",
|
|
99
|
+
to: "senderState",
|
|
100
|
+
status: "INVALID_SENDER_STATE",
|
|
101
|
+
table: "account"
|
|
102
|
+
}));
|
|
103
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
104
|
+
stateKey: "senderState",
|
|
105
|
+
addressKey: "tx.from"
|
|
106
|
+
}));
|
|
107
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
108
|
+
from: "tokenAddress",
|
|
109
|
+
to: "tokenStates",
|
|
110
|
+
status: "INVALID_TOKEN",
|
|
111
|
+
table: "token"
|
|
112
|
+
}));
|
|
113
|
+
runner.use((context, next) => {
|
|
114
|
+
context.tokenConditions = {
|
|
115
|
+
owner: context.senderState.address,
|
|
116
|
+
tokens: context.tokens || []
|
|
117
|
+
};
|
|
118
|
+
next();
|
|
119
|
+
});
|
|
120
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyTokenBalance({
|
|
121
|
+
ownerKey: "senderState",
|
|
122
|
+
conditionKey: "tokenConditions"
|
|
123
|
+
}));
|
|
124
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
125
|
+
from: "tx.delegator",
|
|
126
|
+
to: "delegatorState",
|
|
127
|
+
status: "OK",
|
|
128
|
+
table: "account"
|
|
129
|
+
}));
|
|
130
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
131
|
+
stateKey: "delegatorState",
|
|
132
|
+
addressKey: "tx.delegator"
|
|
133
|
+
}));
|
|
134
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyDelegation({
|
|
135
|
+
type: "signature",
|
|
136
|
+
signerKey: "senderState",
|
|
137
|
+
delegatorKey: "delegatorState",
|
|
138
|
+
getRequirements: (ctx) => {
|
|
139
|
+
const context = ctx;
|
|
140
|
+
const tokens = context.tokens || [];
|
|
141
|
+
const assets = context.assets || [];
|
|
142
|
+
return [...tokens.map((x) => ({
|
|
143
|
+
type: "token",
|
|
144
|
+
address: x.address,
|
|
145
|
+
value: x.value,
|
|
146
|
+
to: context.itx.to
|
|
147
|
+
})), ...assets.map((x) => ({
|
|
148
|
+
type: "asset",
|
|
149
|
+
address: x,
|
|
150
|
+
to: context.itx.to
|
|
151
|
+
}))];
|
|
152
|
+
}
|
|
153
|
+
}));
|
|
154
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractReceiver({
|
|
155
|
+
from: "itx.to",
|
|
156
|
+
to: "receiver"
|
|
157
|
+
}));
|
|
158
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
159
|
+
from: "receiver",
|
|
160
|
+
to: "receiverState",
|
|
161
|
+
status: "OK",
|
|
162
|
+
table: "account"
|
|
163
|
+
}));
|
|
164
|
+
runner.use(_ocap_tx_pipeline.pipes.AntiLandAttack({
|
|
165
|
+
senderState: "senderState",
|
|
166
|
+
receiverState: "receiverState"
|
|
167
|
+
}));
|
|
168
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyBlocked({ stateKeys: ["senderState", "receiverState"] }));
|
|
169
|
+
runner.use(_ocap_tx_pipeline.pipes.verifyTokenAccess({
|
|
170
|
+
statesKey: "tokenStates",
|
|
171
|
+
listFieldKey: "spenders",
|
|
172
|
+
accountKeys: ["senderState"],
|
|
173
|
+
errorMessage: "Account {address} is not allowed to transfer token {tokenAddress}"
|
|
174
|
+
}));
|
|
175
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
176
|
+
from: "assets",
|
|
177
|
+
to: "assetStates",
|
|
178
|
+
status: "INVALID_ASSET",
|
|
179
|
+
table: "asset"
|
|
180
|
+
}));
|
|
181
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyTransferrable({ assets: "assetStates" }));
|
|
182
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyUpdater({
|
|
183
|
+
assetKey: "assetStates",
|
|
184
|
+
ownerKey: "senderState"
|
|
185
|
+
}));
|
|
186
|
+
runner.use(require_pipes_ensure_cost.default({ attachSenderChanges: true }));
|
|
187
|
+
runner.use((context, next) => {
|
|
188
|
+
const { itx, receiverState } = context;
|
|
189
|
+
context.receiverAddr = receiverState ? receiverState.address : itx.to;
|
|
190
|
+
return next();
|
|
191
|
+
});
|
|
192
|
+
runner.use(_ocap_tx_pipeline.pipes.UpdateOwner({
|
|
193
|
+
assets: "assetStates",
|
|
194
|
+
owner: "receiverAddr"
|
|
195
|
+
}));
|
|
196
|
+
runner.use(_ocap_tx_pipeline.pipes.TakeStateSnapshot());
|
|
197
|
+
runner.use(async (context, next) => {
|
|
198
|
+
const { tx, tokens, senderState, receiverAddr, receiverState, statedb, senderChange, delegationState, updateVaults } = context;
|
|
199
|
+
const senderTokens = senderState?.tokens || {};
|
|
200
|
+
const receiverTokens = receiverState?.tokens || {};
|
|
201
|
+
for (const token of tokens || []) {
|
|
202
|
+
const delta = new _ocap_util.BN(token.value);
|
|
203
|
+
senderTokens[token.address] = new _ocap_util.BN(senderTokens[token.address]).sub(delta).toString();
|
|
204
|
+
receiverTokens[token.address] = new _ocap_util.BN(receiverTokens[token.address] || "0").add(delta).toString();
|
|
205
|
+
}
|
|
206
|
+
const senderUpdates = senderChange ? require_util.applyTokenChange({ tokens: senderTokens }, senderChange) : { tokens: senderTokens };
|
|
207
|
+
const [newSenderState, newReceiverState, newDelegationState] = await Promise.all([
|
|
208
|
+
statedb.account.update(senderState.address, _ocap_state.account.update(senderState, {
|
|
209
|
+
nonce: tx.nonce,
|
|
210
|
+
pk: tx.pk,
|
|
211
|
+
...senderUpdates
|
|
212
|
+
}, context), context),
|
|
213
|
+
statedb.account.updateOrCreate(receiverState ?? null, _ocap_state.account.updateOrCreate(receiverState ?? null, {
|
|
214
|
+
address: receiverAddr,
|
|
215
|
+
tokens: receiverTokens
|
|
216
|
+
}, context), context),
|
|
217
|
+
context.isDelegationChanged && delegationState ? statedb.delegation.update(delegationState.address, _ocap_state.delegation.update(delegationState, {}, context), context) : delegationState
|
|
218
|
+
]);
|
|
219
|
+
context.senderState = newSenderState;
|
|
220
|
+
context.receiverState = newReceiverState;
|
|
221
|
+
context.delegationState = newDelegationState;
|
|
222
|
+
if (updateVaults) await updateVaults();
|
|
223
|
+
next();
|
|
224
|
+
}, { persistError: true });
|
|
225
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyStateDiff());
|
|
226
|
+
var transfer_v2_default = runner;
|
|
227
|
+
|
|
228
|
+
//#endregion
|
|
229
|
+
exports.default = transfer_v2_default;
|
|
@@ -0,0 +1,274 @@
|
|
|
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 _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
13
|
+
let _arcblock_validator = require("@arcblock/validator");
|
|
14
|
+
let _ocap_util_lib_get_related_addr = require("@ocap/util/lib/get-related-addr");
|
|
15
|
+
let node_util = require("node:util");
|
|
16
|
+
let lodash_isEqual = require("lodash/isEqual");
|
|
17
|
+
lodash_isEqual = require_rolldown_runtime.__toESM(lodash_isEqual);
|
|
18
|
+
|
|
19
|
+
//#region src/protocols/trade/transfer-v3.ts
|
|
20
|
+
const debug$1 = (0, debug.default)("@ocap/tx-protocols:transfer-v2");
|
|
21
|
+
const runner = new _ocap_tx_pipeline.Runner("transfer_v3");
|
|
22
|
+
const verifyAssetOwner = (0, node_util.promisify)(_ocap_tx_pipeline.pipes.VerifyUpdater({
|
|
23
|
+
assetKey: "assets",
|
|
24
|
+
ownerKey: "owner"
|
|
25
|
+
}));
|
|
26
|
+
const schema = _arcblock_validator.Joi.object({
|
|
27
|
+
inputsList: _arcblock_validator.schemas.multiInput.min(1).required(),
|
|
28
|
+
outputsList: _arcblock_validator.schemas.multiInput.min(1).required(),
|
|
29
|
+
data: _arcblock_validator.Joi.any().optional().allow(null)
|
|
30
|
+
}).options({
|
|
31
|
+
stripUnknown: true,
|
|
32
|
+
noDefaults: false
|
|
33
|
+
});
|
|
34
|
+
runner.use(({ itx }, next) => {
|
|
35
|
+
const { error } = schema.validate(itx);
|
|
36
|
+
return next(error ? new _ocap_util_lib_error.CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
|
|
37
|
+
});
|
|
38
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyTxInput({
|
|
39
|
+
fieldKey: "itx.inputs",
|
|
40
|
+
inputsKey: "inputs",
|
|
41
|
+
sendersKey: "senders",
|
|
42
|
+
tokensKey: "inputTokens",
|
|
43
|
+
assetsKey: "inputAssets"
|
|
44
|
+
}));
|
|
45
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyTxInput({
|
|
46
|
+
fieldKey: "itx.outputs",
|
|
47
|
+
inputsKey: "outputs",
|
|
48
|
+
sendersKey: "receivers",
|
|
49
|
+
tokensKey: "outputTokens",
|
|
50
|
+
assetsKey: "outputAssets"
|
|
51
|
+
}));
|
|
52
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyListSize({ listKey: [
|
|
53
|
+
"inputs",
|
|
54
|
+
"outputs",
|
|
55
|
+
"senders",
|
|
56
|
+
"receivers",
|
|
57
|
+
"inputTokens",
|
|
58
|
+
"inputAssets",
|
|
59
|
+
"outputTokens",
|
|
60
|
+
"outputAssets"
|
|
61
|
+
] }));
|
|
62
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyInfo([
|
|
63
|
+
{
|
|
64
|
+
error: "INVALID_TX",
|
|
65
|
+
message: "An owner can not exist in tx input and output at the same time",
|
|
66
|
+
fn: (ctx) => {
|
|
67
|
+
const context = ctx;
|
|
68
|
+
return (context.senders || []).every((x) => (context.receivers || []).includes(x) === false);
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
error: "INVALID_TX",
|
|
73
|
+
message: "Input and output token address does not match",
|
|
74
|
+
fn: (ctx) => {
|
|
75
|
+
const context = ctx;
|
|
76
|
+
return (0, lodash_isEqual.default)(context.inputTokens || [], context.outputTokens || []);
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
error: "INVALID_TX",
|
|
81
|
+
message: "Input and output asset address does not match",
|
|
82
|
+
fn: (ctx) => {
|
|
83
|
+
const context = ctx;
|
|
84
|
+
return (0, lodash_isEqual.default)(context.inputAssets || [], context.outputAssets || []);
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
error: "INVALID_TX",
|
|
89
|
+
message: "Input and output token amount does not match",
|
|
90
|
+
fn: (ctx) => {
|
|
91
|
+
const context = ctx;
|
|
92
|
+
const inputs = context.inputs || [];
|
|
93
|
+
const outputs = context.outputs || [];
|
|
94
|
+
const inputTokens = context.inputTokens || [];
|
|
95
|
+
const inputMap = {};
|
|
96
|
+
const outputMap = {};
|
|
97
|
+
inputs.forEach((input) => {
|
|
98
|
+
(0, _ocap_util_lib_get_list_field.getListField)(input, "tokens").forEach(({ address, value }) => {
|
|
99
|
+
if (typeof inputMap[address] === "undefined") inputMap[address] = new _ocap_util.BN(0);
|
|
100
|
+
inputMap[address] = inputMap[address].add(new _ocap_util.BN(value));
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
outputs.forEach((output) => {
|
|
104
|
+
(0, _ocap_util_lib_get_list_field.getListField)(output, "tokens").forEach(({ address, value }) => {
|
|
105
|
+
if (typeof outputMap[address] === "undefined") outputMap[address] = new _ocap_util.BN(0);
|
|
106
|
+
outputMap[address] = outputMap[address].add(new _ocap_util.BN(value));
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
return inputTokens.every((address) => inputMap[address].eq(outputMap[address]));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
]));
|
|
113
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
114
|
+
from: "inputTokens",
|
|
115
|
+
to: "tokenStates",
|
|
116
|
+
status: "INVALID_TOKEN",
|
|
117
|
+
table: "token"
|
|
118
|
+
}));
|
|
119
|
+
runner.use((context, next) => {
|
|
120
|
+
const { tx, inputTokens = [], tokenStates = [] } = context;
|
|
121
|
+
if (inputTokens.every((tokenAddress) => {
|
|
122
|
+
const tokenState = tokenStates.find((t) => t.address === tokenAddress);
|
|
123
|
+
return tokenState && tokenState.type === "CreditToken" && tokenState.issuer === tx.from;
|
|
124
|
+
})) return next();
|
|
125
|
+
return _ocap_tx_pipeline.pipes.VerifyMultiSigV2({ signersKey: "senders" })(context, next);
|
|
126
|
+
});
|
|
127
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
128
|
+
from: "tx.from",
|
|
129
|
+
to: "senderState",
|
|
130
|
+
status: "OK",
|
|
131
|
+
table: "account"
|
|
132
|
+
}));
|
|
133
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
134
|
+
from: "senders",
|
|
135
|
+
to: "signerStates",
|
|
136
|
+
status: "INVALID_SIGNER_STATE",
|
|
137
|
+
table: "account"
|
|
138
|
+
}));
|
|
139
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
140
|
+
from: "receivers",
|
|
141
|
+
to: "receiverStates",
|
|
142
|
+
status: "OK",
|
|
143
|
+
table: "account"
|
|
144
|
+
}));
|
|
145
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyBlocked({ stateKeys: ["signerStates", "receiverStates"] }));
|
|
146
|
+
runner.use(_ocap_tx_pipeline.pipes.AntiLandAttack({
|
|
147
|
+
senderState: "signerStates",
|
|
148
|
+
receiverState: "receiverStates"
|
|
149
|
+
}));
|
|
150
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
151
|
+
signerKey: "signerStates",
|
|
152
|
+
stateKey: "senderState",
|
|
153
|
+
addressKey: "tx.from"
|
|
154
|
+
}));
|
|
155
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyTokenBalance({
|
|
156
|
+
ownerKey: "signerStates",
|
|
157
|
+
conditionKey: "inputs"
|
|
158
|
+
}));
|
|
159
|
+
runner.use(_ocap_tx_pipeline.pipes.verifyTokenAccess({
|
|
160
|
+
statesKey: "tokenStates",
|
|
161
|
+
listFieldKey: "spenders",
|
|
162
|
+
accountKeys: ["senderState"],
|
|
163
|
+
errorMessage: "Account {address} is not allowed to transfer token {tokenAddress}"
|
|
164
|
+
}));
|
|
165
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
166
|
+
from: "inputAssets",
|
|
167
|
+
to: "assetStates",
|
|
168
|
+
status: "INVALID_ASSET",
|
|
169
|
+
table: "asset"
|
|
170
|
+
}));
|
|
171
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyTransferrable({ assets: "assetStates" }));
|
|
172
|
+
runner.use(async (context, next) => {
|
|
173
|
+
const { inputs = [], assetStates = [], signerStates = [] } = context;
|
|
174
|
+
for (const input of inputs) {
|
|
175
|
+
const { owner } = input;
|
|
176
|
+
const assetsList = (0, _ocap_util_lib_get_list_field.getListField)(input, "assets");
|
|
177
|
+
const states = assetStates.filter((x) => assetsList.includes(x.address));
|
|
178
|
+
const signer = signerStates.find((x) => x.address === owner);
|
|
179
|
+
try {
|
|
180
|
+
await verifyAssetOwner({
|
|
181
|
+
assets: states,
|
|
182
|
+
owner: signer
|
|
183
|
+
});
|
|
184
|
+
} catch (err) {
|
|
185
|
+
return next(err);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return next();
|
|
189
|
+
});
|
|
190
|
+
runner.use(require_pipes_ensure_gas.default((context) => {
|
|
191
|
+
const ops = {
|
|
192
|
+
create: 0,
|
|
193
|
+
update: 0,
|
|
194
|
+
payment: 0
|
|
195
|
+
};
|
|
196
|
+
ops.update += (context.signerStates || []).length;
|
|
197
|
+
ops.update += (context.inputAssets || []).length;
|
|
198
|
+
(context.receivers || []).forEach((x) => {
|
|
199
|
+
if ((context.receiverStates || []).find((r) => r.address === x)) ops.update += 1;
|
|
200
|
+
else ops.create += 1;
|
|
201
|
+
});
|
|
202
|
+
if (context.senderState) ops.update += 1;
|
|
203
|
+
else ops.create += 1;
|
|
204
|
+
return ops;
|
|
205
|
+
}));
|
|
206
|
+
runner.use(require_pipes_ensure_cost.default({ attachSenderChanges: true }));
|
|
207
|
+
runner.use(_ocap_tx_pipeline.pipes.TakeStateSnapshot());
|
|
208
|
+
runner.use(async (context, next) => {
|
|
209
|
+
const { tx, inputs = [], outputs = [], receivers = [], senderState, signerStates = [], senderChange, updateVaults, receiverStates = [], assetStates = [], statedb } = context;
|
|
210
|
+
const signerUpdates = {};
|
|
211
|
+
inputs.forEach((x) => {
|
|
212
|
+
const { owner } = x;
|
|
213
|
+
signerUpdates[owner] = require_util.applyTokenUpdates((0, _ocap_util_lib_get_list_field.getListField)(x, "tokens"), signerStates.find((s) => s.address === owner), "sub");
|
|
214
|
+
if (senderChange && owner === senderChange.address) signerUpdates[owner] = require_util.applyTokenChange(signerUpdates[owner], senderChange);
|
|
215
|
+
});
|
|
216
|
+
const receiverUpdates = {};
|
|
217
|
+
const assetUpdates = {};
|
|
218
|
+
outputs.forEach((x) => {
|
|
219
|
+
const { owner } = x;
|
|
220
|
+
const tokensList = (0, _ocap_util_lib_get_list_field.getListField)(x, "tokens");
|
|
221
|
+
const assetsList = (0, _ocap_util_lib_get_list_field.getListField)(x, "assets");
|
|
222
|
+
const ownerState = receiverStates.find((s) => (0, _ocap_util_lib_get_related_addr.getRelatedAddresses)(s).includes(owner)) || { address: owner };
|
|
223
|
+
receiverUpdates[ownerState.address] = require_util.applyTokenUpdates(tokensList, ownerState, "add");
|
|
224
|
+
if (senderChange && ownerState.address === senderChange.address) receiverUpdates[ownerState.address] = require_util.applyTokenChange(receiverUpdates[ownerState.address], senderChange);
|
|
225
|
+
assetsList.forEach((address) => {
|
|
226
|
+
assetUpdates[address] = { owner: ownerState.address };
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
const sender = senderState ? senderState.address : tx.from;
|
|
230
|
+
const isAlsoSigner = !!signerUpdates[sender];
|
|
231
|
+
const isAlsoReceiver = !!receiverUpdates[sender];
|
|
232
|
+
const senderUpdatesLocal = {};
|
|
233
|
+
if (!isAlsoSigner && !isAlsoReceiver && senderState && senderChange) senderUpdatesLocal[sender] = require_util.applyTokenChange(senderState, senderChange);
|
|
234
|
+
debug$1("transfer-v3", {
|
|
235
|
+
signerUpdates,
|
|
236
|
+
receiverUpdates,
|
|
237
|
+
assetUpdates,
|
|
238
|
+
isAlsoSigner,
|
|
239
|
+
isAlsoReceiver
|
|
240
|
+
});
|
|
241
|
+
const [newSenderState, newSignerStates, newReceiverStates, newAssetStates] = await Promise.all([
|
|
242
|
+
statedb.account.updateOrCreate(senderState ?? null, _ocap_state.account.updateOrCreate(senderState ?? null, Object.assign({
|
|
243
|
+
address: sender,
|
|
244
|
+
nonce: tx.nonce,
|
|
245
|
+
pk: tx.pk
|
|
246
|
+
}, signerUpdates[sender] || {}, receiverUpdates[sender] || {}, senderUpdatesLocal[sender] || {}), context), context),
|
|
247
|
+
Promise.all(signerStates.filter((x) => x.address !== sender).map((x) => statedb.account.update(x.address, _ocap_state.account.update(x, signerUpdates[x.address], context), context))),
|
|
248
|
+
Promise.all(receivers.filter((x) => x !== sender).map((x) => {
|
|
249
|
+
const receiverState = receiverStates.find((s) => (0, _ocap_util_lib_get_related_addr.getRelatedAddresses)(s).includes(x));
|
|
250
|
+
const owner = receiverState ? receiverState.address : x;
|
|
251
|
+
const updates = receiverUpdates[owner] || {};
|
|
252
|
+
return statedb.account.updateOrCreate(receiverState ?? null, _ocap_state.account.updateOrCreate(receiverState ?? null, {
|
|
253
|
+
...updates,
|
|
254
|
+
address: owner
|
|
255
|
+
}, context), context);
|
|
256
|
+
})),
|
|
257
|
+
Promise.all(assetStates.map((x) => statedb.asset.update(x.address, _ocap_state.asset.update(x, assetUpdates[x.address], context), context)))
|
|
258
|
+
]);
|
|
259
|
+
if (updateVaults) await updateVaults();
|
|
260
|
+
context.senderState = newSenderState;
|
|
261
|
+
context.signerStates = isAlsoSigner ? newSignerStates.concat(newSenderState) : newSignerStates;
|
|
262
|
+
context.receiverStates = isAlsoReceiver ? newReceiverStates.concat(newSenderState) : newReceiverStates;
|
|
263
|
+
context.assetStates = newAssetStates;
|
|
264
|
+
debug$1("transfer-v3", {
|
|
265
|
+
inputs,
|
|
266
|
+
outputs
|
|
267
|
+
});
|
|
268
|
+
next();
|
|
269
|
+
}, { persistError: true });
|
|
270
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyStateDiff());
|
|
271
|
+
var transfer_v3_default = runner;
|
|
272
|
+
|
|
273
|
+
//#endregion
|
|
274
|
+
exports.default = transfer_v3_default;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/protocols/trade/transfer-v3.d.ts
|
|
2
|
+
/** Token input type */
|
|
3
|
+
interface TokenInput {
|
|
4
|
+
address: string;
|
|
5
|
+
value: string;
|
|
6
|
+
}
|
|
7
|
+
/** Multi-input type - uses List suffix in proto but runtime has both */
|
|
8
|
+
interface MultiInput {
|
|
9
|
+
owner: string;
|
|
10
|
+
tokensList?: TokenInput[];
|
|
11
|
+
tokens?: TokenInput[];
|
|
12
|
+
assetsList?: string[];
|
|
13
|
+
assets?: string[];
|
|
14
|
+
}
|
|
15
|
+
declare const runner: any;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { MultiInput, TokenInput, runner as default };
|