@ocap/tx-protocols 1.28.9 → 1.29.1

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.
Files changed (284) hide show
  1. package/esm/execute.d.mts +53 -0
  2. package/esm/execute.mjs +225 -0
  3. package/esm/index.d.mts +95 -0
  4. package/esm/index.mjs +100 -0
  5. package/esm/pipes/ensure-cost.d.mts +18 -0
  6. package/esm/pipes/ensure-cost.mjs +136 -0
  7. package/esm/pipes/ensure-gas.d.mts +14 -0
  8. package/esm/pipes/ensure-gas.mjs +38 -0
  9. package/esm/protocols/account/delegate.d.mts +4 -0
  10. package/esm/protocols/account/delegate.mjs +195 -0
  11. package/esm/protocols/account/migrate.d.mts +4 -0
  12. package/esm/protocols/account/migrate.mjs +130 -0
  13. package/esm/protocols/account/revoke-delegate.d.mts +4 -0
  14. package/esm/protocols/account/revoke-delegate.mjs +102 -0
  15. package/esm/protocols/asset/acquire-v2.d.mts +9 -0
  16. package/esm/protocols/asset/acquire-v2.mjs +213 -0
  17. package/esm/protocols/asset/acquire-v3.d.mts +17 -0
  18. package/esm/protocols/asset/acquire-v3.mjs +265 -0
  19. package/esm/protocols/asset/calls/transfer-token.d.mts +4 -0
  20. package/esm/protocols/asset/calls/transfer-token.mjs +36 -0
  21. package/esm/protocols/asset/calls/transfer.d.mts +4 -0
  22. package/esm/protocols/asset/calls/transfer.mjs +32 -0
  23. package/esm/protocols/asset/consume.d.mts +4 -0
  24. package/esm/protocols/asset/consume.mjs +92 -0
  25. package/esm/protocols/asset/create.d.mts +4 -0
  26. package/esm/protocols/asset/create.mjs +136 -0
  27. package/esm/protocols/asset/mint.d.mts +4 -0
  28. package/esm/protocols/asset/mint.mjs +156 -0
  29. package/esm/protocols/asset/pipes/exec-mint-hook.d.mts +24 -0
  30. package/esm/protocols/asset/pipes/exec-mint-hook.mjs +54 -0
  31. package/esm/protocols/asset/pipes/extract-factory-tokens.d.mts +21 -0
  32. package/esm/protocols/asset/pipes/extract-factory-tokens.mjs +22 -0
  33. package/esm/protocols/asset/pipes/verify-itx-address.d.mts +32 -0
  34. package/esm/protocols/asset/pipes/verify-itx-address.mjs +56 -0
  35. package/esm/protocols/asset/pipes/verify-itx-assets.d.mts +18 -0
  36. package/esm/protocols/asset/pipes/verify-itx-assets.mjs +27 -0
  37. package/esm/protocols/asset/pipes/verify-itx-variables.d.mts +17 -0
  38. package/esm/protocols/asset/pipes/verify-itx-variables.mjs +20 -0
  39. package/esm/protocols/asset/pipes/verify-mint-limit.d.mts +15 -0
  40. package/esm/protocols/asset/pipes/verify-mint-limit.mjs +14 -0
  41. package/esm/protocols/asset/update.d.mts +4 -0
  42. package/esm/protocols/asset/update.mjs +111 -0
  43. package/esm/protocols/factory/create.d.mts +29 -0
  44. package/esm/protocols/factory/create.mjs +155 -0
  45. package/esm/protocols/governance/claim-stake.d.mts +27 -0
  46. package/esm/protocols/governance/claim-stake.mjs +220 -0
  47. package/esm/protocols/governance/return-stake.d.mts +27 -0
  48. package/esm/protocols/governance/return-stake.mjs +211 -0
  49. package/esm/protocols/governance/revoke-stake.d.mts +27 -0
  50. package/esm/protocols/governance/revoke-stake.mjs +178 -0
  51. package/esm/protocols/governance/slash-stake.d.mts +17 -0
  52. package/esm/protocols/governance/slash-stake.mjs +213 -0
  53. package/esm/protocols/governance/stake.d.mts +15 -0
  54. package/esm/protocols/governance/stake.mjs +270 -0
  55. package/esm/protocols/rollup/claim-reward.d.mts +11 -0
  56. package/esm/protocols/rollup/claim-reward.mjs +322 -0
  57. package/esm/protocols/rollup/close.d.mts +4 -0
  58. package/esm/protocols/rollup/close.mjs +105 -0
  59. package/esm/protocols/rollup/create-block.d.mts +11 -0
  60. package/esm/protocols/rollup/create-block.mjs +303 -0
  61. package/esm/protocols/rollup/create.d.mts +4 -0
  62. package/esm/protocols/rollup/create.mjs +164 -0
  63. package/esm/protocols/rollup/join.d.mts +4 -0
  64. package/esm/protocols/rollup/join.mjs +152 -0
  65. package/esm/protocols/rollup/leave.d.mts +4 -0
  66. package/esm/protocols/rollup/leave.mjs +137 -0
  67. package/esm/protocols/rollup/migrate.d.mts +4 -0
  68. package/esm/protocols/rollup/migrate.mjs +85 -0
  69. package/esm/protocols/rollup/pause.d.mts +4 -0
  70. package/esm/protocols/rollup/pause.mjs +76 -0
  71. package/esm/protocols/rollup/pipes/ensure-validator.d.mts +6 -0
  72. package/esm/protocols/rollup/pipes/ensure-validator.mjs +12 -0
  73. package/esm/protocols/rollup/pipes/verify-evidence.d.mts +15 -0
  74. package/esm/protocols/rollup/pipes/verify-evidence.mjs +29 -0
  75. package/esm/protocols/rollup/pipes/verify-signers.d.mts +15 -0
  76. package/esm/protocols/rollup/pipes/verify-signers.mjs +36 -0
  77. package/esm/protocols/rollup/pipes/verify-status.d.mts +13 -0
  78. package/esm/protocols/rollup/pipes/verify-status.mjs +26 -0
  79. package/esm/protocols/rollup/resume.d.mts +4 -0
  80. package/esm/protocols/rollup/resume.mjs +79 -0
  81. package/esm/protocols/rollup/update.d.mts +4 -0
  82. package/esm/protocols/rollup/update.mjs +111 -0
  83. package/esm/protocols/token/create.d.mts +4 -0
  84. package/esm/protocols/token/create.mjs +150 -0
  85. package/esm/protocols/token/deposit-v2.d.mts +11 -0
  86. package/esm/protocols/token/deposit-v2.mjs +216 -0
  87. package/esm/protocols/token/withdraw-v2.d.mts +9 -0
  88. package/esm/protocols/token/withdraw-v2.mjs +222 -0
  89. package/esm/protocols/token-factory/burn.d.mts +15 -0
  90. package/esm/protocols/token-factory/burn.mjs +233 -0
  91. package/esm/protocols/token-factory/create.d.mts +4 -0
  92. package/esm/protocols/token-factory/create.mjs +254 -0
  93. package/esm/protocols/token-factory/mint.d.mts +15 -0
  94. package/esm/protocols/token-factory/mint.mjs +234 -0
  95. package/esm/protocols/token-factory/pipes/calc-reserve.d.mts +21 -0
  96. package/esm/protocols/token-factory/pipes/calc-reserve.mjs +34 -0
  97. package/esm/protocols/token-factory/pipes/verify-icon.d.mts +14 -0
  98. package/esm/protocols/token-factory/pipes/verify-icon.mjs +18 -0
  99. package/esm/protocols/token-factory/pipes/verify-ownership.d.mts +12 -0
  100. package/esm/protocols/token-factory/pipes/verify-ownership.mjs +63 -0
  101. package/esm/protocols/token-factory/pipes/verify-url.d.mts +12 -0
  102. package/esm/protocols/token-factory/pipes/verify-url.mjs +26 -0
  103. package/esm/protocols/token-factory/update.d.mts +10 -0
  104. package/esm/protocols/token-factory/update.mjs +152 -0
  105. package/esm/protocols/trade/exchange-v2.d.mts +9 -0
  106. package/esm/protocols/trade/exchange-v2.mjs +239 -0
  107. package/esm/protocols/trade/transfer-v2.d.mts +9 -0
  108. package/esm/protocols/trade/transfer-v2.mjs +226 -0
  109. package/esm/protocols/trade/transfer-v3.d.mts +17 -0
  110. package/esm/protocols/trade/transfer-v3.mjs +270 -0
  111. package/esm/util.d.mts +141 -0
  112. package/esm/util.mjs +278 -0
  113. package/lib/_virtual/rolldown_runtime.cjs +29 -0
  114. package/lib/execute.cjs +231 -0
  115. package/lib/execute.d.cts +53 -0
  116. package/lib/index.cjs +105 -0
  117. package/lib/index.d.cts +95 -0
  118. package/lib/pipes/ensure-cost.cjs +141 -0
  119. package/lib/pipes/ensure-cost.d.cts +18 -0
  120. package/lib/pipes/ensure-gas.cjs +41 -0
  121. package/lib/pipes/ensure-gas.d.cts +14 -0
  122. package/lib/protocols/account/delegate.cjs +201 -0
  123. package/lib/protocols/account/delegate.d.cts +4 -0
  124. package/lib/protocols/account/migrate.cjs +135 -0
  125. package/lib/protocols/account/migrate.d.cts +4 -0
  126. package/lib/protocols/account/revoke-delegate.cjs +107 -0
  127. package/lib/protocols/account/revoke-delegate.d.cts +4 -0
  128. package/lib/protocols/asset/acquire-v2.cjs +216 -0
  129. package/lib/protocols/asset/acquire-v2.d.cts +9 -0
  130. package/lib/protocols/asset/acquire-v3.cjs +269 -0
  131. package/lib/protocols/asset/acquire-v3.d.cts +17 -0
  132. package/lib/protocols/asset/calls/transfer-token.cjs +40 -0
  133. package/lib/protocols/asset/calls/transfer-token.d.cts +4 -0
  134. package/lib/protocols/asset/calls/transfer.cjs +35 -0
  135. package/lib/protocols/asset/calls/transfer.d.cts +4 -0
  136. package/lib/protocols/asset/consume.cjs +95 -0
  137. package/lib/protocols/asset/consume.d.cts +4 -0
  138. package/lib/protocols/asset/create.cjs +140 -0
  139. package/lib/protocols/asset/create.d.cts +4 -0
  140. package/lib/protocols/asset/mint.cjs +159 -0
  141. package/lib/protocols/asset/mint.d.cts +4 -0
  142. package/lib/protocols/asset/pipes/exec-mint-hook.cjs +57 -0
  143. package/lib/protocols/asset/pipes/exec-mint-hook.d.cts +24 -0
  144. package/lib/protocols/asset/pipes/extract-factory-tokens.cjs +25 -0
  145. package/lib/protocols/asset/pipes/extract-factory-tokens.d.cts +21 -0
  146. package/lib/protocols/asset/pipes/verify-itx-address.cjs +59 -0
  147. package/lib/protocols/asset/pipes/verify-itx-address.d.cts +32 -0
  148. package/lib/protocols/asset/pipes/verify-itx-assets.cjs +29 -0
  149. package/lib/protocols/asset/pipes/verify-itx-assets.d.cts +18 -0
  150. package/lib/protocols/asset/pipes/verify-itx-variables.cjs +22 -0
  151. package/lib/protocols/asset/pipes/verify-itx-variables.d.cts +17 -0
  152. package/lib/protocols/asset/pipes/verify-mint-limit.cjs +16 -0
  153. package/lib/protocols/asset/pipes/verify-mint-limit.d.cts +15 -0
  154. package/lib/protocols/asset/update.cjs +114 -0
  155. package/lib/protocols/asset/update.d.cts +4 -0
  156. package/lib/protocols/factory/create.cjs +161 -0
  157. package/lib/protocols/factory/create.d.cts +29 -0
  158. package/lib/protocols/governance/claim-stake.cjs +223 -0
  159. package/lib/protocols/governance/claim-stake.d.cts +27 -0
  160. package/lib/protocols/governance/return-stake.cjs +215 -0
  161. package/lib/protocols/governance/return-stake.d.cts +27 -0
  162. package/lib/protocols/governance/revoke-stake.cjs +182 -0
  163. package/lib/protocols/governance/revoke-stake.d.cts +27 -0
  164. package/lib/protocols/governance/slash-stake.cjs +217 -0
  165. package/lib/protocols/governance/slash-stake.d.cts +17 -0
  166. package/lib/protocols/governance/stake.cjs +275 -0
  167. package/lib/protocols/governance/stake.d.cts +15 -0
  168. package/lib/protocols/rollup/claim-reward.cjs +328 -0
  169. package/lib/protocols/rollup/claim-reward.d.cts +11 -0
  170. package/lib/protocols/rollup/close.cjs +107 -0
  171. package/lib/protocols/rollup/close.d.cts +4 -0
  172. package/lib/protocols/rollup/create-block.cjs +309 -0
  173. package/lib/protocols/rollup/create-block.d.cts +11 -0
  174. package/lib/protocols/rollup/create.cjs +169 -0
  175. package/lib/protocols/rollup/create.d.cts +4 -0
  176. package/lib/protocols/rollup/join.cjs +157 -0
  177. package/lib/protocols/rollup/join.d.cts +4 -0
  178. package/lib/protocols/rollup/leave.cjs +141 -0
  179. package/lib/protocols/rollup/leave.d.cts +4 -0
  180. package/lib/protocols/rollup/migrate.cjs +87 -0
  181. package/lib/protocols/rollup/migrate.d.cts +4 -0
  182. package/lib/protocols/rollup/pause.cjs +78 -0
  183. package/lib/protocols/rollup/pause.d.cts +4 -0
  184. package/lib/protocols/rollup/pipes/ensure-validator.cjs +14 -0
  185. package/lib/protocols/rollup/pipes/ensure-validator.d.cts +6 -0
  186. package/lib/protocols/rollup/pipes/verify-evidence.cjs +32 -0
  187. package/lib/protocols/rollup/pipes/verify-evidence.d.cts +15 -0
  188. package/lib/protocols/rollup/pipes/verify-signers.cjs +39 -0
  189. package/lib/protocols/rollup/pipes/verify-signers.d.cts +15 -0
  190. package/lib/protocols/rollup/pipes/verify-status.cjs +28 -0
  191. package/lib/protocols/rollup/pipes/verify-status.d.cts +13 -0
  192. package/lib/protocols/rollup/resume.cjs +81 -0
  193. package/lib/protocols/rollup/resume.d.cts +4 -0
  194. package/lib/protocols/rollup/update.cjs +114 -0
  195. package/lib/protocols/rollup/update.d.cts +4 -0
  196. package/lib/protocols/token/create.cjs +156 -0
  197. package/lib/protocols/token/create.d.cts +4 -0
  198. package/lib/protocols/token/deposit-v2.cjs +219 -0
  199. package/lib/protocols/token/deposit-v2.d.cts +11 -0
  200. package/lib/protocols/token/withdraw-v2.cjs +225 -0
  201. package/lib/protocols/token/withdraw-v2.d.cts +9 -0
  202. package/lib/protocols/token-factory/burn.cjs +236 -0
  203. package/lib/protocols/token-factory/burn.d.cts +15 -0
  204. package/lib/protocols/token-factory/create.cjs +260 -0
  205. package/lib/protocols/token-factory/create.d.cts +4 -0
  206. package/lib/protocols/token-factory/mint.cjs +237 -0
  207. package/lib/protocols/token-factory/mint.d.cts +15 -0
  208. package/lib/protocols/token-factory/pipes/calc-reserve.cjs +38 -0
  209. package/lib/protocols/token-factory/pipes/calc-reserve.d.cts +21 -0
  210. package/lib/protocols/token-factory/pipes/verify-icon.cjs +22 -0
  211. package/lib/protocols/token-factory/pipes/verify-icon.d.cts +14 -0
  212. package/lib/protocols/token-factory/pipes/verify-ownership.cjs +66 -0
  213. package/lib/protocols/token-factory/pipes/verify-ownership.d.cts +12 -0
  214. package/lib/protocols/token-factory/pipes/verify-url.cjs +29 -0
  215. package/lib/protocols/token-factory/pipes/verify-url.d.cts +12 -0
  216. package/lib/protocols/token-factory/update.cjs +155 -0
  217. package/lib/protocols/token-factory/update.d.cts +10 -0
  218. package/lib/protocols/trade/exchange-v2.cjs +243 -0
  219. package/lib/protocols/trade/exchange-v2.d.cts +9 -0
  220. package/lib/protocols/trade/transfer-v2.cjs +229 -0
  221. package/lib/protocols/trade/transfer-v2.d.cts +9 -0
  222. package/lib/protocols/trade/transfer-v3.cjs +274 -0
  223. package/lib/protocols/trade/transfer-v3.d.cts +17 -0
  224. package/lib/util.cjs +296 -0
  225. package/lib/util.d.cts +141 -0
  226. package/package.json +49 -22
  227. package/tools/fixtures.ts +564 -0
  228. package/lib/execute.js +0 -254
  229. package/lib/index.js +0 -117
  230. package/lib/pipes/ensure-cost.js +0 -193
  231. package/lib/pipes/ensure-gas.js +0 -48
  232. package/lib/protocols/account/delegate.js +0 -223
  233. package/lib/protocols/account/migrate.js +0 -153
  234. package/lib/protocols/account/revoke-delegate.js +0 -110
  235. package/lib/protocols/asset/acquire-v2.js +0 -262
  236. package/lib/protocols/asset/acquire-v3.js +0 -330
  237. package/lib/protocols/asset/calls/README.md +0 -5
  238. package/lib/protocols/asset/calls/transfer-token.js +0 -36
  239. package/lib/protocols/asset/calls/transfer.js +0 -28
  240. package/lib/protocols/asset/consume.js +0 -105
  241. package/lib/protocols/asset/create.js +0 -151
  242. package/lib/protocols/asset/mint.js +0 -199
  243. package/lib/protocols/asset/pipes/exec-mint-hook.js +0 -62
  244. package/lib/protocols/asset/pipes/extract-factory-tokens.js +0 -18
  245. package/lib/protocols/asset/pipes/verify-itx-address.js +0 -54
  246. package/lib/protocols/asset/pipes/verify-itx-assets.js +0 -51
  247. package/lib/protocols/asset/pipes/verify-itx-variables.js +0 -26
  248. package/lib/protocols/asset/pipes/verify-mint-limit.js +0 -13
  249. package/lib/protocols/asset/update.js +0 -131
  250. package/lib/protocols/factory/create.js +0 -191
  251. package/lib/protocols/governance/claim-stake.js +0 -266
  252. package/lib/protocols/governance/return-stake.js +0 -248
  253. package/lib/protocols/governance/revoke-stake.js +0 -172
  254. package/lib/protocols/governance/slash-stake.js +0 -271
  255. package/lib/protocols/governance/stake.js +0 -303
  256. package/lib/protocols/rollup/claim-reward.js +0 -342
  257. package/lib/protocols/rollup/close.js +0 -104
  258. package/lib/protocols/rollup/create-block.js +0 -413
  259. package/lib/protocols/rollup/create.js +0 -197
  260. package/lib/protocols/rollup/join.js +0 -182
  261. package/lib/protocols/rollup/leave.js +0 -145
  262. package/lib/protocols/rollup/migrate.js +0 -85
  263. package/lib/protocols/rollup/pause.js +0 -75
  264. package/lib/protocols/rollup/pipes/ensure-validator.js +0 -12
  265. package/lib/protocols/rollup/pipes/verify-evidence.js +0 -37
  266. package/lib/protocols/rollup/pipes/verify-signers.js +0 -87
  267. package/lib/protocols/rollup/pipes/verify-status.js +0 -30
  268. package/lib/protocols/rollup/resume.js +0 -75
  269. package/lib/protocols/rollup/update.js +0 -122
  270. package/lib/protocols/token/create.js +0 -199
  271. package/lib/protocols/token/deposit-v2.js +0 -290
  272. package/lib/protocols/token/withdraw-v2.js +0 -305
  273. package/lib/protocols/token-factory/burn.js +0 -371
  274. package/lib/protocols/token-factory/create.js +0 -342
  275. package/lib/protocols/token-factory/mint.js +0 -385
  276. package/lib/protocols/token-factory/pipes/calc-reserve.js +0 -37
  277. package/lib/protocols/token-factory/pipes/verify-icon.js +0 -27
  278. package/lib/protocols/token-factory/pipes/verify-ownership.js +0 -93
  279. package/lib/protocols/token-factory/pipes/verify-url.js +0 -32
  280. package/lib/protocols/token-factory/update.js +0 -208
  281. package/lib/protocols/trade/exchange-v2.js +0 -239
  282. package/lib/protocols/trade/transfer-v2.js +0 -233
  283. package/lib/protocols/trade/transfer-v3.js +0 -333
  284. package/lib/util.js +0 -442
@@ -0,0 +1,265 @@
1
+ import { applyTokenChange, applyTokenUpdates } from "../../util.mjs";
2
+ import ensure_cost_default from "../../pipes/ensure-cost.mjs";
3
+ import ensure_gas_default from "../../pipes/ensure-gas.mjs";
4
+ import exec_mint_hook_default from "./pipes/exec-mint-hook.mjs";
5
+ import extract_factory_tokens_default from "./pipes/extract-factory-tokens.mjs";
6
+ import verify_itx_address_default from "./pipes/verify-itx-address.mjs";
7
+ import verify_itx_assets_default from "./pipes/verify-itx-assets.mjs";
8
+ import verify_itx_variables_default from "./pipes/verify-itx-variables.mjs";
9
+ import verify_mint_limit_default from "./pipes/verify-mint-limit.mjs";
10
+ import { Runner, pipes } from "@ocap/tx-pipeline";
11
+ import { CustomError } from "@ocap/util/lib/error";
12
+ import { account, asset, factory } from "@ocap/state";
13
+ import { BN } from "@ocap/util";
14
+ import Debug from "debug";
15
+ import { getListField } from "@ocap/util/lib/get-list-field";
16
+ import { Joi, schemas } from "@arcblock/validator";
17
+ import { promisify } from "node:util";
18
+ import isEqual from "lodash/isEqual.js";
19
+
20
+ //#region src/protocols/asset/acquire-v3.ts
21
+ const debug = Debug("@ocap/tx-protocols:acquire-asset-v3");
22
+ const verifyAssetOwner = promisify(pipes.VerifyUpdater({
23
+ assetKey: "assets",
24
+ ownerKey: "owner"
25
+ }));
26
+ const runner = new Runner("acquire_asset_v3");
27
+ const schema = Joi.object({
28
+ factory: Joi.DID().prefix().role("ROLE_FACTORY").required(),
29
+ address: Joi.DID().prefix().role("ROLE_ASSET").required(),
30
+ inputsList: schemas.multiInput.min(1).required(),
31
+ owner: schemas.tokenHolder.required(),
32
+ variablesList: Joi.array().items(schemas.variableInput).optional().allow(null).default([]),
33
+ issuer: schemas.nftIssuer.required(),
34
+ data: Joi.any().optional().allow(null)
35
+ }).options({
36
+ stripUnknown: true,
37
+ noDefaults: false
38
+ });
39
+ runner.use(({ itx }, next) => {
40
+ const { error } = schema.validate(itx);
41
+ if (error) return next(new CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
42
+ return next();
43
+ });
44
+ runner.use(pipes.ExtractState({
45
+ from: "itx.address",
46
+ to: "duplicateAsset",
47
+ status: "OK",
48
+ table: "asset"
49
+ }));
50
+ runner.use(pipes.VerifyInfo([{
51
+ error: "FORBIDDEN",
52
+ message: "Asset with same address already exists",
53
+ fn: (ctx) => {
54
+ return !ctx.duplicateAsset;
55
+ },
56
+ persist: true
57
+ }]));
58
+ runner.use(pipes.VerifyTxInput({
59
+ fieldKey: "itx.inputs",
60
+ inputsKey: "inputs",
61
+ sendersKey: "senders",
62
+ tokensKey: "tokens",
63
+ assetsKey: "assets"
64
+ }));
65
+ runner.use(pipes.VerifyListSize({ listKey: [
66
+ "inputs",
67
+ "senders",
68
+ "tokens",
69
+ "assets"
70
+ ] }));
71
+ runner.use(pipes.VerifyMultiSigV2({ signersKey: "senders" }));
72
+ runner.use(pipes.ExtractState({
73
+ from: "itx.factory",
74
+ to: "factoryState",
75
+ status: "INVALID_FACTORY_STATE",
76
+ table: "factory"
77
+ }));
78
+ runner.use(pipes.ExtractState({
79
+ from: "factoryState.owner",
80
+ to: "factoryOwnerState",
81
+ status: "INVALID_OWNER_STATE",
82
+ table: "account"
83
+ }));
84
+ runner.use(pipes.ExtractState({
85
+ from: "factoryState.trustedIssuers",
86
+ to: "issuerStates",
87
+ status: "INVALID_ISSUER_STATE",
88
+ table: "account"
89
+ }));
90
+ runner.use(pipes.ExtractState({
91
+ from: "itx.issuer.id",
92
+ to: "issuerState",
93
+ status: "INVALID_ISSUER_STATE",
94
+ table: "account"
95
+ }));
96
+ runner.use(pipes.VerifyAccountMigration({
97
+ stateKey: "issuerState",
98
+ addressKey: "itx.issuer.id"
99
+ }));
100
+ runner.use(pipes.VerifyInfo([{
101
+ error: "FORBIDDEN",
102
+ message: "Only factory owner and trusted issuers are allowed",
103
+ fn: (ctx) => {
104
+ const { issuerState, factoryOwnerState, issuerStates = [] } = ctx;
105
+ return factoryOwnerState.address === issuerState.address || !!issuerStates.find((x) => x.address === issuerState.address);
106
+ },
107
+ persist: true
108
+ }]));
109
+ runner.use(extract_factory_tokens_default);
110
+ runner.use(verify_mint_limit_default);
111
+ runner.use(verify_itx_variables_default);
112
+ runner.use(pipes.VerifyInfo([{
113
+ error: "INVALID_TX",
114
+ message: "Input token address does not match with factory input requirement",
115
+ fn: (ctx) => {
116
+ const context = ctx;
117
+ return isEqual(context.tokens || [], context.tokenAddress || []);
118
+ }
119
+ }, {
120
+ error: "INVALID_TX",
121
+ message: "Input token amount does not match with factory input requirement",
122
+ fn: (ctx) => {
123
+ const context = ctx;
124
+ const inputs = context.inputs || [];
125
+ const factoryTokens = context.factoryTokens || [];
126
+ const inputMap = {};
127
+ inputs.forEach((input) => {
128
+ getListField(input, "tokens").forEach(({ address, value }) => {
129
+ if (typeof inputMap[address] === "undefined") inputMap[address] = new BN(0);
130
+ inputMap[address] = inputMap[address].add(new BN(value));
131
+ });
132
+ });
133
+ const expectedTokens = factoryTokens.reduce((acc, x) => {
134
+ acc[x.address] = new BN(x.value);
135
+ return acc;
136
+ }, {});
137
+ return Object.keys(expectedTokens).every((address) => inputMap[address].eq(expectedTokens[address]));
138
+ }
139
+ }]));
140
+ runner.use(pipes.ExtractState({
141
+ from: "tx.from",
142
+ to: "senderState",
143
+ status: "OK",
144
+ table: "account"
145
+ }));
146
+ runner.use(pipes.ExtractState({
147
+ from: "senders",
148
+ to: "signerStates",
149
+ status: "INVALID_SIGNER_STATE",
150
+ table: "account"
151
+ }));
152
+ runner.use(pipes.ExtractState({
153
+ from: "itx.owner",
154
+ to: "ownerState",
155
+ status: "OK",
156
+ table: "account"
157
+ }));
158
+ runner.use(pipes.VerifyAccountMigration({
159
+ signerKey: "signerStates",
160
+ stateKey: "senderState",
161
+ addressKey: "tx.from"
162
+ }));
163
+ runner.use(pipes.VerifyBlocked({ stateKeys: ["signerStates", "ownerState"] }));
164
+ runner.use(pipes.ExtractState({
165
+ from: "tokens",
166
+ to: "tokenStates",
167
+ status: "INVALID_TOKEN",
168
+ table: "token"
169
+ }));
170
+ runner.use(pipes.VerifyTokenBalance({
171
+ ownerKey: "signerStates",
172
+ conditionKey: "inputs"
173
+ }));
174
+ runner.use(pipes.ExtractState({
175
+ from: "assets",
176
+ to: "assetStates",
177
+ status: "OK",
178
+ table: "asset"
179
+ }));
180
+ runner.use(async (context, next) => {
181
+ const { inputs = [], assetStates = [], signerStates = [] } = context;
182
+ for (const input of inputs) {
183
+ const { owner } = input;
184
+ const assetsList = getListField(input, "assets");
185
+ const states = assetStates.filter((x) => assetsList.includes(x.address));
186
+ const signer = signerStates.find((x) => x.address === owner);
187
+ try {
188
+ await verifyAssetOwner({
189
+ assets: states,
190
+ owner: signer
191
+ });
192
+ } catch (err) {
193
+ return next(err);
194
+ }
195
+ }
196
+ return next();
197
+ });
198
+ runner.use(pipes.ExtractState({
199
+ from: "factoryState.input.assets",
200
+ to: "expectedFactoryStates",
201
+ status: "OK",
202
+ table: "factory"
203
+ }));
204
+ runner.use(verify_itx_address_default("acquire-v3"));
205
+ runner.use(verify_itx_assets_default);
206
+ runner.use(ensure_gas_default((context) => {
207
+ const result = {
208
+ create: 1,
209
+ update: 2,
210
+ payment: 0
211
+ };
212
+ if (context.assetStates) result.update += context.assetStates.length;
213
+ if (context.signerStates) result.update += context.signerStates.length;
214
+ if (!context.ownerState) result.create += 1;
215
+ return result;
216
+ }));
217
+ runner.use(ensure_cost_default({ attachSenderChanges: true }));
218
+ runner.use(pipes.TakeStateSnapshot());
219
+ runner.use(async (context, next) => {
220
+ const { tx: tx$1, itx, txTime, inputs = [], statedb, senderState, ownerState, factoryState, factoryTokens = [], mintedAsset, mintedAddress, signerStates = [], senderChange, updateVaults, assetStates = [] } = context;
221
+ const signerUpdates = {};
222
+ inputs.forEach((x) => {
223
+ const { owner: owner$1 } = x;
224
+ signerUpdates[owner$1] = applyTokenUpdates(getListField(x, "tokens"), signerStates.find((s) => s.address === owner$1), "sub");
225
+ if (senderChange && owner$1 === senderChange.address) signerUpdates[owner$1] = applyTokenChange(signerUpdates[owner$1], senderChange);
226
+ });
227
+ const isAlsoSigner = !!signerUpdates[tx$1.from];
228
+ const owner = ownerState ? ownerState.address : itx.owner;
229
+ const factoryUpdates = { numMinted: factoryState.numMinted + 1 };
230
+ if (factoryState.settlement !== "instant") {
231
+ Object.assign(factoryUpdates, applyTokenUpdates(factoryTokens, factoryState, "add"));
232
+ context.tokenUpdates = applyTokenUpdates(factoryTokens, { tokens: {} }, "add");
233
+ }
234
+ const [newSenderState, newReceiverState, assetState, newSignerStates, newFactoryState, newAssetStates] = await Promise.all([
235
+ statedb.account.updateOrCreate(senderState ?? null, account.updateOrCreate(senderState ?? null, Object.assign({
236
+ address: tx$1.from,
237
+ nonce: tx$1.nonce,
238
+ pk: tx$1.pk
239
+ }, signerUpdates[tx$1.from] || (senderChange ? applyTokenChange(senderState, senderChange) : {})), context), context),
240
+ ownerState || owner === tx$1.from ? Promise.resolve(ownerState) : statedb.account.create(owner, account.create({ address: owner }, context), context),
241
+ statedb.asset.create(itx.address, asset.create({
242
+ ...mintedAsset,
243
+ owner,
244
+ address: mintedAddress
245
+ }, context), context),
246
+ Promise.all(signerStates.filter((x) => x.address !== tx$1.from).map((x) => statedb.account.update(x.address, account.update(x, signerUpdates[x.address], context), context))),
247
+ statedb.factory.update(factoryState.address, factory.update(factoryState, factoryUpdates, context), context),
248
+ Promise.all(assetStates.map((x) => statedb.asset.update(x.address, asset.update(x, { consumedTime: txTime }, context), context)))
249
+ ]);
250
+ if (updateVaults) await updateVaults();
251
+ context.senderState = newSenderState;
252
+ context.receiverState = owner === tx$1.from ? newSenderState : newReceiverState ?? void 0;
253
+ context.signerStates = isAlsoSigner ? newSignerStates.concat(newSenderState) : newSignerStates;
254
+ context.assetState = assetState;
255
+ context.factoryState = newFactoryState;
256
+ context.assetStates = newAssetStates;
257
+ debug("acquire-v3", assetState);
258
+ next();
259
+ }, { persistError: true });
260
+ runner.use(exec_mint_hook_default, { persistError: true });
261
+ runner.use(pipes.VerifyStateDiff());
262
+ var acquire_v3_default = runner;
263
+
264
+ //#endregion
265
+ export { acquire_v3_default as default };
@@ -0,0 +1,4 @@
1
+ //#region src/protocols/asset/calls/transfer-token.d.ts
2
+ declare const runner: any;
3
+ //#endregion
4
+ export { runner as default };
@@ -0,0 +1,36 @@
1
+ import { Runner, pipes } from "@ocap/tx-pipeline";
2
+ import { BN } from "@ocap/util";
3
+ import Debug from "debug";
4
+ import cloneDeep from "lodash/cloneDeep.js";
5
+
6
+ //#region src/protocols/asset/calls/transfer-token.ts
7
+ const debug = Debug("@ocap/tx-protocols:acquire-asset:transfer-token");
8
+ const runner = new Runner("transfer_token_call");
9
+ runner.use(pipes.ExtractState({
10
+ from: "args.to",
11
+ to: "receiverState",
12
+ status: "INVALID_RECEIVER_STATE"
13
+ }));
14
+ runner.use((context, next) => {
15
+ const { receiverState, args } = context;
16
+ const receiver = receiverState;
17
+ const transferArgs = args;
18
+ const statesAny = context.states;
19
+ const { tokenAddress, amount } = transferArgs;
20
+ const delta = new BN(amount);
21
+ const newTokens = cloneDeep(receiver.tokens || {});
22
+ if (newTokens[tokenAddress]) newTokens[tokenAddress] = new BN(newTokens[tokenAddress]).add(delta).toString();
23
+ else newTokens[tokenAddress] = delta.toString();
24
+ context.updateSet = {
25
+ address: receiver.address,
26
+ updates: statesAny.account.update(receiver, { tokens: newTokens }, context),
27
+ delta: amount,
28
+ token: tokenAddress
29
+ };
30
+ debug("contract.transfer-token", context.updateSet);
31
+ next();
32
+ });
33
+ var transfer_token_default = runner;
34
+
35
+ //#endregion
36
+ export { transfer_token_default as default };
@@ -0,0 +1,4 @@
1
+ //#region src/protocols/asset/calls/transfer.d.ts
2
+ declare const runner: any;
3
+ //#endregion
4
+ export { runner as default };
@@ -0,0 +1,32 @@
1
+ import { Runner, pipes } from "@ocap/tx-pipeline";
2
+ import { BN } from "@ocap/util";
3
+ import Debug from "debug";
4
+
5
+ //#region src/protocols/asset/calls/transfer.ts
6
+ const debug = Debug("@ocap/tx-protocols:acquire-asset:transfer");
7
+ const runner = new Runner("transfer_call");
8
+ runner.use(pipes.ExtractState({
9
+ from: "args.to",
10
+ to: "receiverState",
11
+ status: "INVALID_RECEIVER_STATE"
12
+ }));
13
+ runner.use((context, next) => {
14
+ const { receiverState, args } = context;
15
+ const receiver = receiverState;
16
+ const transferArgs = args;
17
+ const statesAny = context.states;
18
+ const old = new BN(receiver.balance);
19
+ const delta = new BN(transferArgs.amount);
20
+ context.updateSet = {
21
+ address: receiver.address,
22
+ updates: statesAny.account.update(receiver, { balance: old.add(delta).toString() }, context),
23
+ delta: transferArgs.amount,
24
+ token: ""
25
+ };
26
+ debug("contract.transfer", context.updateSet);
27
+ next();
28
+ });
29
+ var transfer_default = runner;
30
+
31
+ //#endregion
32
+ export { transfer_default as default };
@@ -0,0 +1,4 @@
1
+ //#region src/protocols/asset/consume.d.ts
2
+ declare const runner: any;
3
+ //#endregion
4
+ export { runner as default };
@@ -0,0 +1,92 @@
1
+ import ensure_cost_default from "../../pipes/ensure-cost.mjs";
2
+ import ensure_gas_default from "../../pipes/ensure-gas.mjs";
3
+ import { Runner, pipes } from "@ocap/tx-pipeline";
4
+ import { CustomError } from "@ocap/util/lib/error";
5
+ import { account, asset } from "@ocap/state";
6
+ import Debug from "debug";
7
+ import { Joi } from "@arcblock/validator";
8
+
9
+ //#region src/protocols/asset/consume.ts
10
+ const debug = Debug("@ocap/tx-protocols:consume-asset");
11
+ const runner = new Runner("consume_asset");
12
+ const schema = Joi.object({
13
+ address: Joi.DID().prefix().role("ROLE_ASSET").required(),
14
+ data: Joi.any().optional().allow(null)
15
+ }).options({
16
+ stripUnknown: true,
17
+ noDefaults: false
18
+ });
19
+ runner.use((context, next) => {
20
+ const { itx } = context;
21
+ const { error } = schema.validate(itx);
22
+ if (error) return next(new CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
23
+ return next();
24
+ });
25
+ runner.use(pipes.ExtractState({
26
+ from: "itx.address",
27
+ to: "assetState",
28
+ status: "INVALID_ASSET",
29
+ table: "asset"
30
+ }));
31
+ runner.use((context, next) => {
32
+ const { assetState } = context;
33
+ if (!assetState) return next(new CustomError("INVALID_TX", "Asset state not found"));
34
+ const { issuer, consumedTime } = assetState;
35
+ if (!issuer) return next(new CustomError("INVALID_TX", "Asset without issuer can not be consumed"));
36
+ if (consumedTime) return next(new CustomError("INVALID_TX", `Asset already consumed on ${consumedTime}`));
37
+ return next();
38
+ });
39
+ runner.use(pipes.ExtractState({
40
+ from: "tx.from",
41
+ to: "senderState",
42
+ status: "INVALID_SENDER_STATE",
43
+ table: "account"
44
+ }));
45
+ runner.use(pipes.VerifyAccountMigration({
46
+ stateKey: "senderState",
47
+ addressKey: "tx.from"
48
+ }));
49
+ runner.use(pipes.ExtractState({
50
+ from: "assetState.issuer",
51
+ to: "issuerState",
52
+ status: "INVALID_ISSUER_STATE",
53
+ table: "account"
54
+ }));
55
+ runner.use(pipes.ExtractState({
56
+ from: "assetState.owner",
57
+ to: "ownerState",
58
+ status: "INVALID_OWNER_STATE",
59
+ table: "account"
60
+ }));
61
+ runner.use((context, next) => {
62
+ context.signerStates = [context.ownerState, context.issuerState];
63
+ context.signers = [context.ownerState.address, context.issuerState.address];
64
+ return next();
65
+ });
66
+ runner.use(pipes.VerifyMultiSigV2({ signersKey: "signers" }));
67
+ runner.use(pipes.VerifyAccountMigration({ signerKey: "signerStates" }));
68
+ runner.use(ensure_gas_default(() => ({
69
+ create: 0,
70
+ update: 2,
71
+ payment: 0
72
+ })));
73
+ runner.use(ensure_cost_default({ attachSenderChanges: true }));
74
+ runner.use(pipes.TakeStateSnapshot());
75
+ runner.use(async (context, next) => {
76
+ const { tx: tx$1, itx, txTime, statedb, senderState, senderUpdates, assetState, updateVaults } = context;
77
+ const [newSenderState, newAssetState] = await Promise.all([statedb.account.update(senderState.address, account.update(senderState, {
78
+ nonce: tx$1.nonce,
79
+ pk: tx$1.pk,
80
+ ...senderUpdates
81
+ }, context), context), statedb.asset.update(itx.address, asset.update(assetState, { consumedTime: txTime }, context), context)]);
82
+ if (updateVaults) await updateVaults();
83
+ context.senderState = newSenderState;
84
+ context.assetState = newAssetState;
85
+ debug("consume", newAssetState);
86
+ next();
87
+ }, { persistError: true });
88
+ runner.use(pipes.VerifyStateDiff());
89
+ var consume_default = runner;
90
+
91
+ //#endregion
92
+ export { consume_default as default };
@@ -0,0 +1,4 @@
1
+ //#region src/protocols/asset/create.d.ts
2
+ declare const runner: any;
3
+ //#endregion
4
+ export { runner as default };
@@ -0,0 +1,136 @@
1
+ import { decodeAnySafe, getDelegationRequirements } from "../../util.mjs";
2
+ import ensure_cost_default from "../../pipes/ensure-cost.mjs";
3
+ import ensure_gas_default from "../../pipes/ensure-gas.mjs";
4
+ import { Runner, pipes } from "@ocap/tx-pipeline";
5
+ import { CustomError } from "@ocap/util/lib/error";
6
+ import { toAssetAddress } from "@arcblock/did-util";
7
+ import { account, asset, delegation } from "@ocap/state";
8
+ import Debug from "debug";
9
+ import { formatMessage } from "@ocap/message";
10
+ import { getListField } from "@ocap/util/lib/get-list-field";
11
+ import cloneDeep from "lodash/cloneDeep.js";
12
+
13
+ //#region src/protocols/asset/create.ts
14
+ const debug = Debug("@ocap/tx-protocols:create-asset");
15
+ const runner = new Runner("create_asset");
16
+ runner.use((context, next) => {
17
+ const itx = formatMessage("CreateAssetTx", context.itx);
18
+ const { error } = asset.schema.validate(itx);
19
+ if (error) return next(new CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
20
+ return next();
21
+ });
22
+ runner.use(pipes.VerifyInfo([{
23
+ error: "INVALID_ASSET",
24
+ message: "Asset address is not valid",
25
+ fn: (ctx) => {
26
+ const context = ctx;
27
+ const itx = cloneDeep(context.itx);
28
+ const decodedData = decodeAnySafe(itx.data ?? null);
29
+ itx.data = decodedData;
30
+ itx.address = "";
31
+ context.assetData = decodedData;
32
+ context.signers = [itx.issuer].filter(Boolean);
33
+ return toAssetAddress(itx) === context.itx.address;
34
+ }
35
+ }]));
36
+ runner.use(pipes.VerifyMultiSigV2({ signersKey: "signers" }));
37
+ runner.use(pipes.ExtractState({
38
+ from: "itx.address",
39
+ to: "assetState",
40
+ status: "OK"
41
+ }));
42
+ runner.use(pipes.VerifyInfo([{
43
+ error: "INVALID_ASSET",
44
+ message: "This asset already exist on chain",
45
+ fn: (ctx) => !ctx.assetState
46
+ }]));
47
+ runner.use(pipes.ExtractState({
48
+ from: "itx.issuer",
49
+ to: "issuerState",
50
+ status: "INVALID_ISSUER_STATE",
51
+ table: "account"
52
+ }));
53
+ runner.use(pipes.VerifyAccountMigration({ signerKey: "issuerState" }));
54
+ runner.use(pipes.ExtractState({
55
+ from: "tx.from",
56
+ to: "senderState",
57
+ status: "INVALID_SENDER_STATE",
58
+ table: "account"
59
+ }));
60
+ runner.use(pipes.VerifyAccountMigration({
61
+ stateKey: "senderState",
62
+ addressKey: "tx.from"
63
+ }));
64
+ runner.use(pipes.ExtractState({
65
+ from: "tx.delegator",
66
+ to: "delegatorState",
67
+ status: "OK",
68
+ table: "account"
69
+ }));
70
+ runner.use(pipes.VerifyAccountMigration({
71
+ stateKey: "delegatorState",
72
+ addressKey: "tx.delegator"
73
+ }));
74
+ runner.use(pipes.VerifyDelegation({
75
+ type: "signature",
76
+ signerKey: "senderState",
77
+ delegatorKey: "delegatorState",
78
+ getRequirements: getDelegationRequirements
79
+ }));
80
+ runner.use(pipes.ExtractState({
81
+ from: "itx.parent",
82
+ to: "factoryState",
83
+ status: "OK",
84
+ table: "factory"
85
+ }));
86
+ runner.use(pipes.VerifyInfo([{
87
+ error: "CREATE_FROM_FACTORY",
88
+ message: "You can only get asset from factory from acquire or mint",
89
+ fn: (ctx) => {
90
+ const { itx, factoryState } = ctx;
91
+ return !(itx.parent && factoryState);
92
+ },
93
+ persist: true
94
+ }]));
95
+ runner.use(pipes.ExtractState({
96
+ from: "itx.parent",
97
+ to: "parentAsset",
98
+ status: "INVALID_ASSET",
99
+ table: "asset"
100
+ }));
101
+ runner.use(ensure_gas_default(() => ({
102
+ create: 1,
103
+ update: 2,
104
+ payment: 0
105
+ })));
106
+ runner.use(ensure_cost_default({ attachSenderChanges: true }));
107
+ runner.use(pipes.TakeStateSnapshot());
108
+ runner.use(async (context, next) => {
109
+ const { tx: tx$1, itx, assetData, statedb, senderState, delegatorState, delegationState, senderUpdates, updateVaults } = context;
110
+ const owner = delegatorState ? delegatorState.address : senderState.address;
111
+ const [newSenderState, assetState, newDelegationState] = await Promise.all([
112
+ statedb.account.update(senderState.address, account.update(senderState, {
113
+ nonce: tx$1.nonce,
114
+ pk: tx$1.pk,
115
+ ...senderUpdates
116
+ }, context), context),
117
+ statedb.asset.create(itx.address, asset.create({
118
+ ...itx,
119
+ tags: getListField(itx, "tags"),
120
+ data: assetData ?? void 0,
121
+ owner
122
+ }, context), context),
123
+ context.isDelegationChanged && delegationState ? statedb.delegation.update(delegationState.address, delegation.update(delegationState, {}, context), context) : delegationState
124
+ ]);
125
+ if (updateVaults) await updateVaults();
126
+ context.senderState = newSenderState;
127
+ context.assetState = assetState;
128
+ context.delegationState = newDelegationState;
129
+ debug("createAsset", assetState);
130
+ next();
131
+ }, { persistError: true });
132
+ runner.use(pipes.VerifyStateDiff());
133
+ var create_default = runner;
134
+
135
+ //#endregion
136
+ export { create_default as default };
@@ -0,0 +1,4 @@
1
+ //#region src/protocols/asset/mint.d.ts
2
+ declare const runner: any;
3
+ //#endregion
4
+ export { runner as default };