@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,66 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
3
|
+
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
4
|
+
let lodash_get = require("lodash/get");
|
|
5
|
+
lodash_get = require_rolldown_runtime.__toESM(lodash_get);
|
|
6
|
+
let _arcblock_vc = require("@arcblock/vc");
|
|
7
|
+
let _ocap_util_lib_url = require("@ocap/util/lib/url");
|
|
8
|
+
|
|
9
|
+
//#region src/protocols/token-factory/pipes/verify-ownership.ts
|
|
10
|
+
const isTest = ["development", "test"].includes(process.env.NODE_ENV) || !!process.env.CI;
|
|
11
|
+
const verifyOwnership = ({ tokenKey = "itx.token" } = {}) => async (context, next) => {
|
|
12
|
+
const { symbol, address, website } = (0, lodash_get.default)(context, tokenKey) || {};
|
|
13
|
+
if (!website) return next();
|
|
14
|
+
try {
|
|
15
|
+
await (0, _ocap_util_lib_url.verifyUrl)(website, isTest ? {
|
|
16
|
+
protocols: ["http:", "https:"],
|
|
17
|
+
blockedHosts: [],
|
|
18
|
+
allowIp: true
|
|
19
|
+
} : { checkDns: true });
|
|
20
|
+
} catch (error) {
|
|
21
|
+
return next(new _ocap_util_lib_error.CustomError("INVALID_WEBSITE", `Website ${website} must be a valid URL: ${error.message}`));
|
|
22
|
+
}
|
|
23
|
+
const { from, delegator } = context.tx;
|
|
24
|
+
const chainId = context.config.chainId;
|
|
25
|
+
const sender = delegator || from;
|
|
26
|
+
const { origin } = new URL(website);
|
|
27
|
+
const verificationUrl = `${origin}/.well-known/ocap/tokens.json`;
|
|
28
|
+
try {
|
|
29
|
+
const response = await fetch(verificationUrl, { redirect: "manual" });
|
|
30
|
+
if (!response || !response.ok) {
|
|
31
|
+
context.logger?.info("Website verification failed", {
|
|
32
|
+
symbol,
|
|
33
|
+
website,
|
|
34
|
+
status: response?.status,
|
|
35
|
+
statusText: response?.statusText
|
|
36
|
+
});
|
|
37
|
+
return next(new _ocap_util_lib_error.CustomError("INVALID_WEBSITE", `Website ${website} verification failed`));
|
|
38
|
+
}
|
|
39
|
+
const data = await response.json();
|
|
40
|
+
if ((await Promise.all(data.filter(Boolean).filter((item) => {
|
|
41
|
+
if (item.type !== "TokenIssueCredential") return false;
|
|
42
|
+
if (item.issuer?.id !== sender) return false;
|
|
43
|
+
const { id, issued } = item.credentialSubject || {};
|
|
44
|
+
return id === sender && issued?.address === address && issued?.symbol === symbol && issued?.chainId === chainId && issued?.website === website;
|
|
45
|
+
}).map((item) => {
|
|
46
|
+
return (0, _arcblock_vc.verify)({
|
|
47
|
+
vc: item,
|
|
48
|
+
ownerDid: sender,
|
|
49
|
+
trustedIssuers: sender
|
|
50
|
+
});
|
|
51
|
+
}))).some((valid) => valid)) return next();
|
|
52
|
+
context.logger?.warn("Website verification failed", {
|
|
53
|
+
address,
|
|
54
|
+
symbol,
|
|
55
|
+
website,
|
|
56
|
+
data
|
|
57
|
+
});
|
|
58
|
+
return next(new _ocap_util_lib_error.CustomError("INVALID_WEBSITE", `Website ${website} verification failed`));
|
|
59
|
+
} catch (error) {
|
|
60
|
+
return next(new _ocap_util_lib_error.CustomError("INVALID_WEBSITE", `Website ${website} verification failed: ${error.message}`));
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
var verify_ownership_default = verifyOwnership;
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
exports.default = verify_ownership_default;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IDecodedContext } from "@ocap/types";
|
|
2
|
+
import { PipeFunction } from "@ocap/tx-pipeline";
|
|
3
|
+
|
|
4
|
+
//#region src/protocols/token-factory/pipes/verify-ownership.d.ts
|
|
5
|
+
interface IVerifyOwnershipOptions {
|
|
6
|
+
tokenKey?: string;
|
|
7
|
+
}
|
|
8
|
+
declare const verifyOwnership: ({
|
|
9
|
+
tokenKey
|
|
10
|
+
}?: IVerifyOwnershipOptions) => PipeFunction<IDecodedContext>;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { verifyOwnership as default };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
3
|
+
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
4
|
+
let lodash_get = require("lodash/get");
|
|
5
|
+
lodash_get = require_rolldown_runtime.__toESM(lodash_get);
|
|
6
|
+
let _ocap_util_lib_url = require("@ocap/util/lib/url");
|
|
7
|
+
|
|
8
|
+
//#region src/protocols/token-factory/pipes/verify-url.ts
|
|
9
|
+
const isTest = ["development", "test"].includes(process.env.NODE_ENV) || !!process.env.CI;
|
|
10
|
+
const verifyUrlPipe = ({ urlKeys = ["itx.token.website", "itx.token.metadata.value.communityUrl"] } = {}) => async (context, next) => {
|
|
11
|
+
for (const key of urlKeys) {
|
|
12
|
+
const url = (0, lodash_get.default)(context, key);
|
|
13
|
+
if (!url) continue;
|
|
14
|
+
try {
|
|
15
|
+
await (0, _ocap_util_lib_url.verifyUrl)(url, isTest ? {
|
|
16
|
+
protocols: ["http:", "https:"],
|
|
17
|
+
blockedHosts: [],
|
|
18
|
+
allowIp: true
|
|
19
|
+
} : {});
|
|
20
|
+
} catch (error) {
|
|
21
|
+
return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `${key.split(".").pop()} is not valid: ${error.message}`));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return next();
|
|
25
|
+
};
|
|
26
|
+
var verify_url_default = verifyUrlPipe;
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
exports.default = verify_url_default;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IDecodedContext } from "@ocap/types";
|
|
2
|
+
import { PipeFunction } from "@ocap/tx-pipeline";
|
|
3
|
+
|
|
4
|
+
//#region src/protocols/token-factory/pipes/verify-url.d.ts
|
|
5
|
+
interface IVerifyUrlOptions {
|
|
6
|
+
urlKeys?: string[];
|
|
7
|
+
}
|
|
8
|
+
declare const verifyUrlPipe: ({
|
|
9
|
+
urlKeys
|
|
10
|
+
}?: IVerifyUrlOptions) => PipeFunction<IDecodedContext>;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { verifyUrlPipe as default };
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
3
|
+
const require_util = require('../../util.cjs');
|
|
4
|
+
const require_pipes_ensure_cost = require('../../pipes/ensure-cost.cjs');
|
|
5
|
+
const require_pipes_ensure_gas = require('../../pipes/ensure-gas.cjs');
|
|
6
|
+
const require_protocols_token_factory_pipes_verify_icon = require('./pipes/verify-icon.cjs');
|
|
7
|
+
const require_protocols_token_factory_pipes_verify_ownership = require('./pipes/verify-ownership.cjs');
|
|
8
|
+
const require_protocols_token_factory_pipes_verify_url = require('./pipes/verify-url.cjs');
|
|
9
|
+
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
10
|
+
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
11
|
+
let _ocap_state = require("@ocap/state");
|
|
12
|
+
let debug = require("debug");
|
|
13
|
+
debug = require_rolldown_runtime.__toESM(debug);
|
|
14
|
+
let _arcblock_validator = require("@arcblock/validator");
|
|
15
|
+
|
|
16
|
+
//#region src/protocols/token-factory/update.ts
|
|
17
|
+
const debug$1 = (0, debug.default)("@ocap/tx-protocols:update-token-factory");
|
|
18
|
+
const runner = new _ocap_tx_pipeline.Runner("update_token_factory");
|
|
19
|
+
const isTest = process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test" || process.env.CI;
|
|
20
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyMultiSig(0));
|
|
21
|
+
const schema = _arcblock_validator.Joi.object({
|
|
22
|
+
address: _arcblock_validator.Joi.DID().prefix().role("ROLE_TOKEN_FACTORY").required(),
|
|
23
|
+
feeRate: _arcblock_validator.Joi.number().min(0).max(2e3).optional().allow(null),
|
|
24
|
+
token: _arcblock_validator.Joi.object({
|
|
25
|
+
icon: _arcblock_validator.Joi.string().optional().allow(null, ""),
|
|
26
|
+
website: _arcblock_validator.Joi.string().uri({
|
|
27
|
+
scheme: isTest ? ["http", "https"] : ["https"],
|
|
28
|
+
allowRelative: false
|
|
29
|
+
}).max(256).optional().allow(null, ""),
|
|
30
|
+
metadata: _arcblock_validator.Joi.any().optional().allow(null)
|
|
31
|
+
}).optional().allow(null),
|
|
32
|
+
data: _arcblock_validator.Joi.any().optional().allow(null)
|
|
33
|
+
}).options({
|
|
34
|
+
stripUnknown: true,
|
|
35
|
+
noDefaults: false
|
|
36
|
+
});
|
|
37
|
+
runner.use((context, next) => {
|
|
38
|
+
const { error } = schema.validate(context.itx);
|
|
39
|
+
if (error) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
|
|
40
|
+
if (context.itx.token?.metadata) {
|
|
41
|
+
const metadata = require_util.decodeAnySafe(context.itx.token.metadata ?? null);
|
|
42
|
+
if (metadata) {
|
|
43
|
+
const { error: metadataError, value: metadataValue } = _ocap_state.token.metadataSchema.validate(metadata.value);
|
|
44
|
+
if (metadataError) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Invalid metadata: ${metadataError.message}`));
|
|
45
|
+
context.itx.token.metadata = {
|
|
46
|
+
...metadata,
|
|
47
|
+
value: metadataValue
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return next();
|
|
52
|
+
});
|
|
53
|
+
runner.use(require_protocols_token_factory_pipes_verify_icon.default({ iconKey: "itx.token.icon" }));
|
|
54
|
+
runner.use(require_protocols_token_factory_pipes_verify_url.default({ urlKeys: ["itx.token.website", "itx.token.metadata.value.communityUrl"] }));
|
|
55
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
56
|
+
from: "itx.address",
|
|
57
|
+
to: "tokenFactoryState",
|
|
58
|
+
table: "tokenFactory",
|
|
59
|
+
status: "INVALID_TOKEN_FACTORY"
|
|
60
|
+
}));
|
|
61
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
62
|
+
from: "tokenFactoryState.tokenAddress",
|
|
63
|
+
to: "tokenState",
|
|
64
|
+
table: "token",
|
|
65
|
+
status: "INVALID_TOKEN"
|
|
66
|
+
}));
|
|
67
|
+
runner.use((context, next) => {
|
|
68
|
+
const { tokenState, itx } = context;
|
|
69
|
+
context.tokenInfoForVerification = {
|
|
70
|
+
symbol: tokenState.symbol,
|
|
71
|
+
address: tokenState.address,
|
|
72
|
+
website: itx.token?.website ?? null
|
|
73
|
+
};
|
|
74
|
+
return next();
|
|
75
|
+
});
|
|
76
|
+
runner.use(require_protocols_token_factory_pipes_verify_ownership.default({ tokenKey: "tokenInfoForVerification" }));
|
|
77
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
78
|
+
from: "tx.from",
|
|
79
|
+
to: "senderState",
|
|
80
|
+
status: "INVALID_SENDER_STATE",
|
|
81
|
+
table: "account"
|
|
82
|
+
}));
|
|
83
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
84
|
+
stateKey: "senderState",
|
|
85
|
+
addressKey: "tx.from"
|
|
86
|
+
}));
|
|
87
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyBlocked({ stateKeys: ["senderState"] }));
|
|
88
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
89
|
+
from: "tx.delegator",
|
|
90
|
+
to: "delegatorState",
|
|
91
|
+
status: "OK",
|
|
92
|
+
table: "account"
|
|
93
|
+
}));
|
|
94
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
95
|
+
stateKey: "delegatorState",
|
|
96
|
+
addressKey: "tx.delegator"
|
|
97
|
+
}));
|
|
98
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyDelegation({
|
|
99
|
+
type: "signature",
|
|
100
|
+
signerKey: "senderState",
|
|
101
|
+
delegatorKey: "delegatorState",
|
|
102
|
+
getRequirements: require_util.getDelegationRequirements
|
|
103
|
+
}));
|
|
104
|
+
runner.use((context, next) => {
|
|
105
|
+
const { tokenFactoryState, delegatorState, senderState } = context;
|
|
106
|
+
if ((delegatorState ? delegatorState.address : senderState.address) !== tokenFactoryState.owner) return next(new _ocap_util_lib_error.CustomError("FORBIDDEN", "Token factory can only be updated by owner"));
|
|
107
|
+
return next();
|
|
108
|
+
});
|
|
109
|
+
runner.use(require_pipes_ensure_gas.default((context) => {
|
|
110
|
+
const result = {
|
|
111
|
+
create: 0,
|
|
112
|
+
update: 2,
|
|
113
|
+
payment: 0
|
|
114
|
+
};
|
|
115
|
+
if (context.isDelegationChanged) result.update += 1;
|
|
116
|
+
return result;
|
|
117
|
+
}));
|
|
118
|
+
runner.use(require_pipes_ensure_cost.default({ attachSenderChanges: true }));
|
|
119
|
+
runner.use(_ocap_tx_pipeline.pipes.TakeStateSnapshot());
|
|
120
|
+
runner.use(async (context, next) => {
|
|
121
|
+
const { tx, itx, statedb, senderState, tokenFactoryState, tokenState, senderChange, updateVaults, delegationState } = context;
|
|
122
|
+
const senderStateValue = senderState;
|
|
123
|
+
const tokenFactoryStateValue = tokenFactoryState;
|
|
124
|
+
const tokenStateValue = tokenState;
|
|
125
|
+
const { tokens: senderTokens = {} } = senderStateValue;
|
|
126
|
+
const senderUpdates = senderChange ? require_util.applyTokenChange({ tokens: senderTokens }, senderChange) : { tokens: senderTokens };
|
|
127
|
+
const factoryUpdates = itx.feeRate ? { feeRate: itx.feeRate } : {};
|
|
128
|
+
const tokenUpdates = itx.token ? {
|
|
129
|
+
icon: itx.token?.icon || tokenStateValue.icon,
|
|
130
|
+
website: itx.token?.website || tokenStateValue.website,
|
|
131
|
+
metadata: itx.token?.metadata || tokenStateValue.metadata
|
|
132
|
+
} : null;
|
|
133
|
+
const [newSenderState, newTokenFactoryState, newTokenState, newDelegationState] = await Promise.all([
|
|
134
|
+
statedb.account.update(senderStateValue.address, _ocap_state.account.update(senderStateValue, {
|
|
135
|
+
nonce: tx.nonce,
|
|
136
|
+
pk: tx.pk,
|
|
137
|
+
...senderUpdates
|
|
138
|
+
}, context), context),
|
|
139
|
+
statedb.tokenFactory.update(tokenFactoryStateValue.address, _ocap_state.tokenFactory.update(tokenFactoryStateValue, factoryUpdates, context), context),
|
|
140
|
+
tokenUpdates ? statedb.token.update(tokenStateValue.address, _ocap_state.token.update(tokenStateValue, tokenUpdates), context) : tokenStateValue,
|
|
141
|
+
context.isDelegationChanged && delegationState ? statedb.delegation.update(delegationState.address, _ocap_state.delegation.update(delegationState, {}, context), context) : delegationState
|
|
142
|
+
]);
|
|
143
|
+
if (updateVaults) await updateVaults();
|
|
144
|
+
context.senderState = newSenderState;
|
|
145
|
+
context.tokenFactoryState = newTokenFactoryState;
|
|
146
|
+
context.tokenState = newTokenState;
|
|
147
|
+
context.delegationState = newDelegationState;
|
|
148
|
+
debug$1("update token factory", newTokenFactoryState, newTokenState);
|
|
149
|
+
next();
|
|
150
|
+
}, { persistError: true });
|
|
151
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyStateDiff());
|
|
152
|
+
var update_default = runner;
|
|
153
|
+
|
|
154
|
+
//#endregion
|
|
155
|
+
exports.default = update_default;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/protocols/token-factory/update.d.ts
|
|
2
|
+
/** Token info for website verification */
|
|
3
|
+
interface TokenInfoForVerification {
|
|
4
|
+
symbol: string;
|
|
5
|
+
address: string;
|
|
6
|
+
website?: string | null;
|
|
7
|
+
}
|
|
8
|
+
declare const runner: any;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { TokenInfoForVerification, runner as default };
|
|
@@ -0,0 +1,243 @@
|
|
|
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_message = require("@ocap/message");
|
|
13
|
+
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
14
|
+
let _arcblock_validator = require("@arcblock/validator");
|
|
15
|
+
let _ocap_util_lib_create_sorted_list = require("@ocap/util/lib/create-sorted-list");
|
|
16
|
+
let lodash_isEmpty = require("lodash/isEmpty");
|
|
17
|
+
lodash_isEmpty = require_rolldown_runtime.__toESM(lodash_isEmpty);
|
|
18
|
+
|
|
19
|
+
//#region src/protocols/trade/exchange-v2.ts
|
|
20
|
+
const debug$1 = (0, debug.default)("@ocap/tx-protocols:exchange-v2");
|
|
21
|
+
const runner = new _ocap_tx_pipeline.Runner("exchange_v2");
|
|
22
|
+
const exchangeInfoSchema = _arcblock_validator.Joi.object({
|
|
23
|
+
value: _arcblock_validator.Joi.any().optional().allow(null),
|
|
24
|
+
tokensList: _arcblock_validator.Joi.array().items(_arcblock_validator.schemas.tokenInput).default([]),
|
|
25
|
+
assetsList: _arcblock_validator.Joi.array().items(_arcblock_validator.Joi.DID().prefix().role("ROLE_ASSET")).default([])
|
|
26
|
+
});
|
|
27
|
+
const schema = _arcblock_validator.Joi.object({
|
|
28
|
+
to: _arcblock_validator.schemas.tokenHolder.required(),
|
|
29
|
+
sender: exchangeInfoSchema.required(),
|
|
30
|
+
receiver: exchangeInfoSchema.required(),
|
|
31
|
+
data: _arcblock_validator.Joi.any().optional().allow(null)
|
|
32
|
+
}).options({
|
|
33
|
+
stripUnknown: true,
|
|
34
|
+
noDefaults: false
|
|
35
|
+
});
|
|
36
|
+
runner.use(({ itx }, next) => {
|
|
37
|
+
const { error } = schema.validate(itx);
|
|
38
|
+
return next(error ? new _ocap_util_lib_error.CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
|
|
39
|
+
});
|
|
40
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyMultiSig(1));
|
|
41
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractReceiver({ from: [
|
|
42
|
+
"tx.signaturesList",
|
|
43
|
+
"tx.signatures",
|
|
44
|
+
"itx.to"
|
|
45
|
+
] }));
|
|
46
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyInfo([{
|
|
47
|
+
error: "INVALID_TX",
|
|
48
|
+
message: "Can not exchange without any token or assets",
|
|
49
|
+
fn: (ctx) => {
|
|
50
|
+
const context = ctx;
|
|
51
|
+
const zero = new _ocap_util.BN(0);
|
|
52
|
+
const { itx, config } = context;
|
|
53
|
+
context.senderAssets = (0, _ocap_util_lib_get_list_field.getListField)(itx, "sender.assets");
|
|
54
|
+
context.receiverAssets = (0, _ocap_util_lib_get_list_field.getListField)(itx, "receiver.assets");
|
|
55
|
+
const senderTokensLocal = (0, _ocap_util_lib_get_list_field.getListField)(itx, "sender.tokens");
|
|
56
|
+
const receiverTokensLocal = (0, _ocap_util_lib_get_list_field.getListField)(itx, "receiver.tokens");
|
|
57
|
+
const senderValue = itx.sender?.value;
|
|
58
|
+
const senderAmount = senderValue ? (0, _ocap_message.decodeBigInt)(senderValue) : 0;
|
|
59
|
+
if (new _ocap_util.BN(senderAmount).gt(zero)) {
|
|
60
|
+
senderTokensLocal.push({
|
|
61
|
+
address: config.token.address,
|
|
62
|
+
value: senderAmount
|
|
63
|
+
});
|
|
64
|
+
itx.sender.value = "0";
|
|
65
|
+
}
|
|
66
|
+
const receiverValue = itx.receiver?.value;
|
|
67
|
+
const receiverAmount = receiverValue ? (0, _ocap_message.decodeBigInt)(receiverValue) : 0;
|
|
68
|
+
if (new _ocap_util.BN(receiverAmount).gt(zero)) {
|
|
69
|
+
receiverTokensLocal.push({
|
|
70
|
+
address: config.token.address,
|
|
71
|
+
value: receiverAmount
|
|
72
|
+
});
|
|
73
|
+
itx.receiver.value = "0";
|
|
74
|
+
}
|
|
75
|
+
context.senderTokens = senderTokensLocal;
|
|
76
|
+
context.receiverTokens = receiverTokensLocal;
|
|
77
|
+
context.tokenAddress = (0, _ocap_util_lib_create_sorted_list.createSortedList)((context.senderTokens || []).concat(context.receiverTokens || []).map((x) => x.address));
|
|
78
|
+
if ((0, lodash_isEmpty.default)(context.senderAssets) && (0, lodash_isEmpty.default)(context.senderTokens)) return false;
|
|
79
|
+
if ((0, lodash_isEmpty.default)(context.receiverAssets) && (0, lodash_isEmpty.default)(context.receiverTokens)) return false;
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
}]));
|
|
83
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifySigner({ signer: "itx.to" }));
|
|
84
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyListSize({ listKey: ["senderAssets", "receiverAssets"] }));
|
|
85
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyListSize({ listKey: ["senderTokens", "receiverTokens"] }));
|
|
86
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
87
|
+
from: "tx.from",
|
|
88
|
+
to: "senderState",
|
|
89
|
+
status: "INVALID_SENDER_STATE",
|
|
90
|
+
table: "account"
|
|
91
|
+
}));
|
|
92
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
93
|
+
from: "tx.delegator",
|
|
94
|
+
to: "delegatorState",
|
|
95
|
+
status: "OK",
|
|
96
|
+
table: "account"
|
|
97
|
+
}));
|
|
98
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyDelegation({
|
|
99
|
+
type: "signature",
|
|
100
|
+
signerKey: "senderState",
|
|
101
|
+
delegatorKey: "delegatorState"
|
|
102
|
+
}));
|
|
103
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractSigner({
|
|
104
|
+
signerKey: "signerStates",
|
|
105
|
+
delegatorKey: "delegatorStates"
|
|
106
|
+
}));
|
|
107
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyDelegation({
|
|
108
|
+
type: "multisig",
|
|
109
|
+
signerKey: "signerStates",
|
|
110
|
+
delegatorKey: "delegatorStates",
|
|
111
|
+
delegationKey: "delegationStates",
|
|
112
|
+
getRequirements: () => []
|
|
113
|
+
}));
|
|
114
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
115
|
+
from: "tokenAddress",
|
|
116
|
+
to: "tokenStates",
|
|
117
|
+
status: "INVALID_TOKEN",
|
|
118
|
+
table: "token"
|
|
119
|
+
}));
|
|
120
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
121
|
+
from: "receiver",
|
|
122
|
+
to: "receiverState",
|
|
123
|
+
status: "INVALID_RECEIVER_STATE",
|
|
124
|
+
table: "account"
|
|
125
|
+
}));
|
|
126
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
127
|
+
signerKey: "signerStates",
|
|
128
|
+
stateKey: "senderState",
|
|
129
|
+
addressKey: "tx.from"
|
|
130
|
+
}));
|
|
131
|
+
runner.use((context, next) => {
|
|
132
|
+
context.senderTokenConditions = {
|
|
133
|
+
owner: context.senderState.address,
|
|
134
|
+
tokens: context.senderTokens || []
|
|
135
|
+
};
|
|
136
|
+
context.receiverTokenConditions = {
|
|
137
|
+
owner: context.receiverState.address,
|
|
138
|
+
tokens: context.receiverTokens || []
|
|
139
|
+
};
|
|
140
|
+
next();
|
|
141
|
+
});
|
|
142
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyTokenBalance({
|
|
143
|
+
ownerKey: "senderState",
|
|
144
|
+
conditionKey: "senderTokenConditions"
|
|
145
|
+
}));
|
|
146
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyTokenBalance({
|
|
147
|
+
ownerKey: "receiverState",
|
|
148
|
+
conditionKey: "receiverTokenConditions"
|
|
149
|
+
}));
|
|
150
|
+
runner.use(_ocap_tx_pipeline.pipes.AntiLandAttack({
|
|
151
|
+
senderState: "senderState",
|
|
152
|
+
receiverState: "receiverState"
|
|
153
|
+
}));
|
|
154
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyBlocked({ stateKeys: ["senderState", "receiverState"] }));
|
|
155
|
+
runner.use(_ocap_tx_pipeline.pipes.verifyTokenAccess({
|
|
156
|
+
statesKey: "tokenStates",
|
|
157
|
+
listFieldKey: "spenders",
|
|
158
|
+
accountKeys: ["senderState"],
|
|
159
|
+
errorMessage: "Account {address} is not allowed to exchange token {tokenAddress}"
|
|
160
|
+
}));
|
|
161
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
162
|
+
from: "senderAssets",
|
|
163
|
+
to: "priv.senderAssets",
|
|
164
|
+
status: "INVALID_ASSET",
|
|
165
|
+
table: "asset"
|
|
166
|
+
}));
|
|
167
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyTransferrable({ assets: "priv.senderAssets" }));
|
|
168
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyUpdater({
|
|
169
|
+
assetKey: "priv.senderAssets",
|
|
170
|
+
ownerKey: "senderState"
|
|
171
|
+
}));
|
|
172
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
173
|
+
from: "receiverAssets",
|
|
174
|
+
to: "priv.receiverAssets",
|
|
175
|
+
status: "INVALID_ASSET",
|
|
176
|
+
table: "asset"
|
|
177
|
+
}));
|
|
178
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyTransferrable({ assets: "priv.receiverAssets" }));
|
|
179
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyUpdater({
|
|
180
|
+
assetKey: "priv.receiverAssets",
|
|
181
|
+
ownerKey: "receiverState"
|
|
182
|
+
}));
|
|
183
|
+
runner.use(require_pipes_ensure_gas.default((context) => {
|
|
184
|
+
const ops = {
|
|
185
|
+
create: 0,
|
|
186
|
+
update: 3,
|
|
187
|
+
payment: 0
|
|
188
|
+
};
|
|
189
|
+
ops.update += (context.senderAssets || []).length;
|
|
190
|
+
ops.update += (context.receiverAssets || []).length;
|
|
191
|
+
return ops;
|
|
192
|
+
}));
|
|
193
|
+
runner.use(require_pipes_ensure_cost.default({ attachSenderChanges: true }));
|
|
194
|
+
runner.use(_ocap_tx_pipeline.pipes.UpdateOwner({
|
|
195
|
+
assets: "priv.senderAssets",
|
|
196
|
+
owner: "receiverState"
|
|
197
|
+
}));
|
|
198
|
+
runner.use(_ocap_tx_pipeline.pipes.UpdateOwner({
|
|
199
|
+
assets: "priv.receiverAssets",
|
|
200
|
+
owner: "senderState"
|
|
201
|
+
}));
|
|
202
|
+
runner.use(_ocap_tx_pipeline.pipes.TakeStateSnapshot());
|
|
203
|
+
runner.use(async (context, next) => {
|
|
204
|
+
const { tx, itx, senderAssets = [], receiverAssets = [], senderTokens = [], receiverTokens = [], senderState, receiverState, senderChange, updateVaults, statedb } = context;
|
|
205
|
+
const senderStateTokens = senderState?.tokens || {};
|
|
206
|
+
const receiverStateTokens = receiverState?.tokens || {};
|
|
207
|
+
for (const { address, value } of senderTokens) {
|
|
208
|
+
const delta = new _ocap_util.BN(value);
|
|
209
|
+
senderStateTokens[address] = new _ocap_util.BN(senderStateTokens[address]).sub(delta).toString();
|
|
210
|
+
receiverStateTokens[address] = new _ocap_util.BN(receiverStateTokens[address] || "0").add(delta).toString();
|
|
211
|
+
}
|
|
212
|
+
for (const { address, value } of receiverTokens) {
|
|
213
|
+
const delta = new _ocap_util.BN(value);
|
|
214
|
+
senderStateTokens[address] = new _ocap_util.BN(senderStateTokens[address]).add(delta).toString();
|
|
215
|
+
receiverStateTokens[address] = new _ocap_util.BN(receiverStateTokens[address] || "0").sub(delta).toString();
|
|
216
|
+
}
|
|
217
|
+
const senderUpdates = senderChange ? require_util.applyTokenChange({ tokens: senderStateTokens }, senderChange) : { tokens: senderStateTokens };
|
|
218
|
+
const [newSenderState, newReceiverState] = await Promise.all([statedb.account.update(senderState.address, _ocap_state.account.update(senderState, {
|
|
219
|
+
nonce: tx.nonce,
|
|
220
|
+
...senderUpdates
|
|
221
|
+
}, context), context), statedb.account.update(receiverState.address, _ocap_state.account.update(receiverState, { tokens: receiverStateTokens }, context), context)]);
|
|
222
|
+
if (updateVaults) await updateVaults();
|
|
223
|
+
context.senderState = newSenderState;
|
|
224
|
+
context.receiverState = newReceiverState;
|
|
225
|
+
debug$1("exchange", {
|
|
226
|
+
from: tx.from,
|
|
227
|
+
to: itx.to,
|
|
228
|
+
sender: {
|
|
229
|
+
assets: senderAssets.length,
|
|
230
|
+
token: senderTokens.length
|
|
231
|
+
},
|
|
232
|
+
receiver: {
|
|
233
|
+
assets: receiverAssets.length,
|
|
234
|
+
token: receiverTokens.length
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
next();
|
|
238
|
+
}, { persistError: true });
|
|
239
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyStateDiff());
|
|
240
|
+
var exchange_v2_default = runner;
|
|
241
|
+
|
|
242
|
+
//#endregion
|
|
243
|
+
exports.default = exchange_v2_default;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/protocols/trade/exchange-v2.d.ts
|
|
2
|
+
/** Token input - value can be string or number from decodeBigInt */
|
|
3
|
+
interface TokenInput {
|
|
4
|
+
address: string;
|
|
5
|
+
value: string | number;
|
|
6
|
+
}
|
|
7
|
+
declare const runner: any;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { TokenInput, runner as default };
|