@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,156 @@
1
+ import ensure_cost_default from "../../pipes/ensure-cost.mjs";
2
+ import ensure_gas_default from "../../pipes/ensure-gas.mjs";
3
+ import verify_itx_address_default from "./pipes/verify-itx-address.mjs";
4
+ import verify_itx_assets_default from "./pipes/verify-itx-assets.mjs";
5
+ import verify_itx_variables_default from "./pipes/verify-itx-variables.mjs";
6
+ import verify_mint_limit_default from "./pipes/verify-mint-limit.mjs";
7
+ import { Runner, pipes } from "@ocap/tx-pipeline";
8
+ import { CustomError } from "@ocap/util/lib/error";
9
+ import { account, asset, factory } from "@ocap/state";
10
+ import Debug from "debug";
11
+ import { Joi, schemas } from "@arcblock/validator";
12
+
13
+ //#region src/protocols/asset/mint.ts
14
+ const debug = Debug("@ocap/tx-protocols:mint-asset");
15
+ const runner = new Runner("mint_asset");
16
+ runner.use(pipes.VerifyMultiSig(0));
17
+ const schema = Joi.object({
18
+ factory: Joi.DID().prefix().role("ROLE_FACTORY").required(),
19
+ address: Joi.DID().prefix().role("ROLE_ASSET").required(),
20
+ assetsList: Joi.array().items(Joi.DID().prefix().role("ROLE_ASSET")).default([]),
21
+ variablesList: Joi.array().items(schemas.variableInput).optional().allow(null).default([]),
22
+ owner: schemas.tokenHolder.required(),
23
+ data: Joi.any().optional().allow(null)
24
+ }).options({
25
+ stripUnknown: true,
26
+ noDefaults: false
27
+ });
28
+ runner.use(({ itx }, next) => {
29
+ const { error } = schema.validate(itx);
30
+ if (error) return next(new CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
31
+ return next();
32
+ });
33
+ runner.use(pipes.ExtractState({
34
+ from: "itx.address",
35
+ to: "duplicateAsset",
36
+ status: "OK",
37
+ table: "asset"
38
+ }));
39
+ runner.use(pipes.VerifyInfo([{
40
+ error: "FORBIDDEN",
41
+ message: "Asset with same address already exists",
42
+ fn: (ctx) => {
43
+ return !ctx.duplicateAsset;
44
+ },
45
+ persist: true
46
+ }]));
47
+ runner.use(pipes.ExtractState({
48
+ from: "tx.from",
49
+ to: "senderState",
50
+ status: "INVALID_SENDER_STATE",
51
+ table: "account"
52
+ }));
53
+ runner.use(pipes.VerifyAccountMigration({
54
+ stateKey: "senderState",
55
+ addressKey: "tx.from"
56
+ }));
57
+ runner.use(pipes.ExtractState({
58
+ from: "itx.factory",
59
+ to: "factoryState",
60
+ status: "INVALID_FACTORY_STATE",
61
+ table: "factory"
62
+ }));
63
+ runner.use(pipes.ExtractState({
64
+ from: "factoryState.owner",
65
+ to: "factoryOwnerState",
66
+ status: "INVALID_ISSUER_STATE",
67
+ table: "account"
68
+ }));
69
+ runner.use(pipes.ExtractState({
70
+ from: "factoryState.trustedIssuers",
71
+ to: "issuerStates",
72
+ status: "INVALID_ISSUER_STATE",
73
+ table: "account"
74
+ }));
75
+ runner.use(pipes.ExtractState({
76
+ from: "itx.owner",
77
+ to: "ownerState",
78
+ status: "OK",
79
+ table: "account"
80
+ }));
81
+ runner.use(pipes.VerifyBlocked({ stateKeys: ["ownerState"] }));
82
+ runner.use(pipes.VerifyInfo([{
83
+ error: "FORBIDDEN",
84
+ message: "Only factory owner and trusted issuers are allowed to mint",
85
+ fn: (ctx) => {
86
+ const context = ctx;
87
+ const { factoryOwnerState, senderState } = context;
88
+ const issuerStates = context.issuerStates || [];
89
+ return senderState.address === factoryOwnerState.address || issuerStates.some((x) => x.address === senderState.address);
90
+ },
91
+ persist: true
92
+ }]));
93
+ runner.use(pipes.ExtractState({
94
+ from: "itx.assetsList",
95
+ to: "assetStates",
96
+ status: "OK",
97
+ table: "asset"
98
+ }));
99
+ runner.use(pipes.ExtractState({
100
+ from: "factoryState.input.assets",
101
+ to: "expectedFactoryStates",
102
+ status: "OK",
103
+ table: "factory"
104
+ }));
105
+ runner.use(verify_mint_limit_default);
106
+ runner.use(verify_itx_variables_default);
107
+ runner.use(verify_itx_address_default("mint"));
108
+ runner.use(pipes.VerifyUpdater({
109
+ assetKey: "assetStates",
110
+ ownerKey: "ownerState"
111
+ }));
112
+ runner.use(verify_itx_assets_default);
113
+ runner.use(ensure_gas_default((context) => {
114
+ const result = {
115
+ create: 1,
116
+ update: 2,
117
+ payment: 0
118
+ };
119
+ if (!context.ownerState) result.create += 1;
120
+ if (context.assetStates) result.update += context.assetStates.length;
121
+ return result;
122
+ }));
123
+ runner.use(ensure_cost_default({ attachSenderChanges: true }));
124
+ runner.use(pipes.TakeStateSnapshot());
125
+ runner.use(async (context, next) => {
126
+ const { tx: tx$1, itx, txTime, statedb, senderState, factoryState, mintedAsset, mintedAddress, ownerState, senderUpdates, assetStates = [], updateVaults, ownerAddress } = context;
127
+ const factoryUpdates = { numMinted: factoryState.numMinted + 1 };
128
+ const [newSenderState, newReceiverState, assetState, newFactoryState, newAssetStates] = await Promise.all([
129
+ statedb.account.update(senderState.address, account.update(senderState, {
130
+ nonce: tx$1.nonce,
131
+ pk: tx$1.pk,
132
+ ...senderUpdates
133
+ }, context), context),
134
+ ownerState ? Promise.resolve(ownerState) : statedb.account.create(ownerAddress, account.create({ address: ownerAddress }, context), context),
135
+ statedb.asset.create(itx.address, asset.create({
136
+ ...mintedAsset,
137
+ owner: ownerAddress,
138
+ address: mintedAddress
139
+ }, context), context),
140
+ statedb.factory.update(factoryState.address, factory.update(factoryState, factoryUpdates, context), context),
141
+ Promise.all(assetStates.map((x) => statedb.asset.update(x.address, asset.update(x, { consumedTime: txTime }, context), context)))
142
+ ]);
143
+ if (updateVaults) await updateVaults();
144
+ context.senderState = newSenderState;
145
+ context.receiverState = newReceiverState;
146
+ context.assetState = assetState;
147
+ context.factoryState = newFactoryState;
148
+ context.assetStates = newAssetStates;
149
+ debug("mint", assetState);
150
+ next();
151
+ }, { persistError: true });
152
+ runner.use(pipes.VerifyStateDiff());
153
+ var mint_default = runner;
154
+
155
+ //#endregion
156
+ export { mint_default as default };
@@ -0,0 +1,24 @@
1
+ import { PipeFunction } from "@ocap/tx-pipeline";
2
+ import { IAccountState, IAccountUpdate, IAssetFactoryState, IDecodedContext, IStateDB, TTransactionReceipt } from "@ocap/types";
3
+
4
+ //#region src/protocols/asset/pipes/exec-mint-hook.d.ts
5
+
6
+ /**
7
+ * Context type for exec-mint-hook pipe.
8
+ * Requires: statedb, factoryState, config
9
+ * Optional: tokenUpdates
10
+ * Sets: updatedAccounts, mintHookStates, receipts
11
+ */
12
+ type ExecMintHookContext = IDecodedContext & {
13
+ statedb: IStateDB;
14
+ factoryState?: IAssetFactoryState;
15
+ tokenUpdates?: Record<string, string>;
16
+ updatedAccounts?: IAccountUpdate[];
17
+ mintHookStates?: IAccountState[];
18
+ receipts?: TTransactionReceipt[];
19
+ states?: unknown;
20
+ txn?: unknown;
21
+ };
22
+ declare const execMintHook: PipeFunction<ExecMintHookContext>;
23
+ //#endregion
24
+ export { execMintHook as default };
@@ -0,0 +1,54 @@
1
+ import transfer_default from "../calls/transfer.mjs";
2
+ import transfer_token_default from "../calls/transfer-token.mjs";
3
+ import cloneDeep from "lodash/cloneDeep.js";
4
+
5
+ //#region src/protocols/asset/pipes/exec-mint-hook.ts
6
+ const contractCalls = {
7
+ transfer: transfer_default,
8
+ transferToken: transfer_token_default
9
+ };
10
+ const execMintHook = async (context, next) => {
11
+ const { statedb, factoryState, tokenUpdates, config } = context;
12
+ const factory = factoryState;
13
+ if (factory.settlement === "instant") {
14
+ const mintHook = factory.hooks.find((x) => x.name === "mint");
15
+ if (mintHook && mintHook.type === "contract") {
16
+ context.updatedAccounts = context.updatedAccounts || [];
17
+ const clone = cloneDeep(mintHook.compiled);
18
+ const mintHookStates = {};
19
+ for (const x of clone) {
20
+ if (x.call === "transfer") {
21
+ x.call = "transferToken";
22
+ x.args.tokenAddress = config.token.address;
23
+ }
24
+ const { updateSet } = await contractCalls[x.call].runAsync({
25
+ states: context.states,
26
+ statedb,
27
+ txn: context.txn,
28
+ txTime: context.txTime,
29
+ txHash: context.txHash,
30
+ logger: context.logger,
31
+ args: x.args
32
+ });
33
+ mintHookStates[updateSet.address] = await statedb.account.update(updateSet.address, updateSet.updates, context);
34
+ context.updatedAccounts.push(updateSet);
35
+ }
36
+ context.mintHookStates = Object.values(mintHookStates);
37
+ }
38
+ } else if (tokenUpdates) {
39
+ const updates = tokenUpdates;
40
+ if (updates.tokens) context.receipts = [{
41
+ address: factory.address,
42
+ changes: Object.keys(updates.tokens).map((x) => ({
43
+ target: x,
44
+ action: "transfer",
45
+ value: updates.tokens[x]
46
+ })).filter((x) => Number(x.value) > 0)
47
+ }];
48
+ }
49
+ next();
50
+ };
51
+ var exec_mint_hook_default = execMintHook;
52
+
53
+ //#endregion
54
+ export { exec_mint_hook_default as default };
@@ -0,0 +1,21 @@
1
+ import { PipeFunction } from "@ocap/tx-pipeline";
2
+ import { IAssetFactoryState, IBaseContext } from "@ocap/types";
3
+
4
+ //#region src/protocols/asset/pipes/extract-factory-tokens.d.ts
5
+ interface TokenInput {
6
+ address: string;
7
+ value: string;
8
+ }
9
+ /**
10
+ * Context type for extract-factory-tokens pipe.
11
+ * Requires: factoryState, config
12
+ * Sets: factoryTokens, tokenAddress (array of token addresses)
13
+ */
14
+ type ExtractFactoryTokensContext = IBaseContext & {
15
+ factoryState?: IAssetFactoryState;
16
+ factoryTokens?: TokenInput[];
17
+ tokenAddress?: string[];
18
+ };
19
+ declare const extract_factory_tokens: PipeFunction<ExtractFactoryTokensContext>;
20
+ //#endregion
21
+ export { TokenInput, extract_factory_tokens as default };
@@ -0,0 +1,22 @@
1
+ import { BN } from "@ocap/util";
2
+ import { createSortedList } from "@ocap/util/lib/create-sorted-list";
3
+ import uniqBy from "lodash/uniqBy.js";
4
+
5
+ //#region src/protocols/asset/pipes/extract-factory-tokens.ts
6
+ const extract_factory_tokens = (context, next) => {
7
+ const { factoryState, config } = context;
8
+ const input = factoryState.input;
9
+ context.factoryTokens = [...input.tokens];
10
+ const factoryTokens = context.factoryTokens;
11
+ if (!factoryTokens.find((x) => x.address === config.token.address) && new BN(input.value).gt(new BN(0))) factoryTokens.push({
12
+ address: config.token.address,
13
+ value: input.value
14
+ });
15
+ context.factoryTokens = uniqBy(context.factoryTokens, "address");
16
+ context.tokenAddress = createSortedList((context.factoryTokens || []).map((x) => x.address));
17
+ next();
18
+ };
19
+ var extract_factory_tokens_default = extract_factory_tokens;
20
+
21
+ //#endregion
22
+ export { extract_factory_tokens_default as default };
@@ -0,0 +1,32 @@
1
+ import { PipeFunction } from "@ocap/tx-pipeline";
2
+ import { IAccountState, IAssetFactoryState, IDecodedContext } from "@ocap/types";
3
+
4
+ //#region src/protocols/asset/pipes/verify-itx-address.d.ts
5
+ type VerifyItxAddressMode = 'acquire-v2' | 'acquire-v3' | 'mint';
6
+ /**
7
+ * Inner transaction type for acquire/mint operations
8
+ */
9
+ interface AcquireMintItx {
10
+ address: string;
11
+ issuer?: unknown;
12
+ owner?: string;
13
+ }
14
+ /**
15
+ * Context type for verify-itx-address pipe.
16
+ * Requires: itx, factoryState, factoryInputs
17
+ * Optional: senderState, delegatorState
18
+ * Sets: ownerAddress, mintedAsset, mintedAddress, assetOwner (for acquire-v2)
19
+ */
20
+ type VerifyItxAddressContext = IDecodedContext<AcquireMintItx> & {
21
+ senderState?: IAccountState;
22
+ delegatorState?: IAccountState;
23
+ factoryState?: IAssetFactoryState;
24
+ factoryInputs?: Record<string, unknown>;
25
+ ownerAddress?: string;
26
+ mintedAsset?: Record<string, unknown>;
27
+ mintedAddress?: string;
28
+ assetOwner?: IAccountState;
29
+ };
30
+ declare const verify_itx_address: (mode: VerifyItxAddressMode) => PipeFunction<VerifyItxAddressContext>;
31
+ //#endregion
32
+ export { verify_itx_address as default };
@@ -0,0 +1,56 @@
1
+ import { CustomError } from "@ocap/util/lib/error";
2
+ import Debug from "debug";
3
+ import { mintFromFactory } from "@ocap/asset";
4
+
5
+ //#region src/protocols/asset/pipes/verify-itx-address.ts
6
+ const debug = Debug("@ocap/tx-protocols:pipes:verify-itx-address");
7
+ const verify_itx_address = (mode) => (context, next) => {
8
+ const { itx, senderState, factoryState, delegatorState, factoryInputs } = context;
9
+ const sender = senderState;
10
+ const factory = factoryState;
11
+ const inputs = factoryInputs;
12
+ let issuer = null;
13
+ let owner = null;
14
+ if (mode === "acquire-v2") {
15
+ owner = delegatorState || sender;
16
+ issuer = itx.issuer;
17
+ context.assetOwner = owner;
18
+ } else if (mode === "acquire-v3") {
19
+ owner = { address: itx.owner };
20
+ issuer = itx.issuer;
21
+ } else if (mode === "mint") {
22
+ owner = { address: itx.owner };
23
+ issuer = {
24
+ id: sender.address,
25
+ pk: sender.pk,
26
+ name: sender.moniker
27
+ };
28
+ }
29
+ const minted = mintFromFactory({
30
+ factory,
31
+ inputs,
32
+ owner: owner.address,
33
+ issuer
34
+ });
35
+ if (minted.address !== itx.address) {
36
+ debug("asset address mismatch", {
37
+ owner,
38
+ issuer,
39
+ minted,
40
+ itx,
41
+ factoryInputs,
42
+ factoryState,
43
+ senderState,
44
+ delegatorState
45
+ });
46
+ return next(new CustomError("INVALID_ASSET", "Invalid itx.address: does not match with minted asset address"));
47
+ }
48
+ context.ownerAddress = owner.address;
49
+ context.mintedAsset = minted.asset;
50
+ context.mintedAddress = minted.address;
51
+ return next();
52
+ };
53
+ var verify_itx_address_default = verify_itx_address;
54
+
55
+ //#endregion
56
+ export { verify_itx_address_default as default };
@@ -0,0 +1,18 @@
1
+ import { PipeFunction } from "@ocap/tx-pipeline";
2
+ import { IAssetFactoryState, IAssetState, IDecodedContext } from "@ocap/types";
3
+
4
+ //#region src/protocols/asset/pipes/verify-itx-assets.d.ts
5
+
6
+ /**
7
+ * Context type for verify-itx-assets pipe.
8
+ * Requires: factoryState, itx
9
+ * Optional: expectedFactoryStates, assetStates
10
+ */
11
+ type VerifyItxAssetsContext = IDecodedContext & {
12
+ factoryState?: IAssetFactoryState;
13
+ expectedFactoryStates?: IAssetFactoryState[];
14
+ assetStates?: IAssetState[];
15
+ };
16
+ declare const verify_itx_assets: PipeFunction<VerifyItxAssetsContext>;
17
+ //#endregion
18
+ export { verify_itx_assets as default };
@@ -0,0 +1,27 @@
1
+ import { CustomError } from "@ocap/util/lib/error";
2
+ import { getListField } from "@ocap/util/lib/get-list-field";
3
+
4
+ //#region src/protocols/asset/pipes/verify-itx-assets.ts
5
+ const verify_itx_assets = (context, next) => {
6
+ const { factoryState, expectedFactoryStates = [], assetStates: actualAssetStates = [], itx } = context;
7
+ const expectedAssets = factoryState.input.assets;
8
+ const assetStates = actualAssetStates;
9
+ if (expectedAssets.length === 0) return next();
10
+ if (getListField(itx, "assets").length > assetStates.length) return next(new CustomError("INVALID_ASSET", "Input asset does not exist on chain"));
11
+ if (expectedFactoryStates.length === expectedAssets.length) {
12
+ if (assetStates.every((x) => x.parent && expectedAssets.includes(x.parent)) === false) return next(new CustomError("INVALID_ASSET", "Input asset not minted from any of factory.input.assets"));
13
+ if (assetStates.every((x) => !x.consumedTime) === false) return next(new CustomError("INVALID_ASSET", "Some input asset already consumed"));
14
+ return next();
15
+ }
16
+ for (const address of expectedAssets) {
17
+ const plainAsset = assetStates.find((x) => x.address === address);
18
+ if (plainAsset) {
19
+ if (plainAsset.consumedTime) return next(new CustomError("INVALID_ASSET", `Input asset ${address} already consumed`));
20
+ } else if (!assetStates.find((x) => x.parent === address)) return next(new CustomError("INVALID_ASSET", `Input asset not found ${address}`));
21
+ }
22
+ return next();
23
+ };
24
+ var verify_itx_assets_default = verify_itx_assets;
25
+
26
+ //#endregion
27
+ export { verify_itx_assets_default as default };
@@ -0,0 +1,17 @@
1
+ import { PipeFunction } from "@ocap/tx-pipeline";
2
+ import { IAssetFactoryState, IDecodedContext } from "@ocap/types";
3
+
4
+ //#region src/protocols/asset/pipes/verify-itx-variables.d.ts
5
+
6
+ /**
7
+ * Context type for verify-itx-variables pipe.
8
+ * Requires: factoryState, itx
9
+ * Sets: factoryInputs
10
+ */
11
+ type VerifyItxVariablesContext = IDecodedContext & {
12
+ factoryState?: IAssetFactoryState;
13
+ factoryInputs?: Record<string, unknown>;
14
+ };
15
+ declare const verify_itx_variables: PipeFunction<VerifyItxVariablesContext>;
16
+ //#endregion
17
+ export { verify_itx_variables as default };
@@ -0,0 +1,20 @@
1
+ import { CustomError } from "@ocap/util/lib/error";
2
+ import { getListField } from "@ocap/util/lib/get-list-field";
3
+
4
+ //#region src/protocols/asset/pipes/verify-itx-variables.ts
5
+ const verify_itx_variables = (context, next) => {
6
+ const { factoryState, itx } = context;
7
+ const variables = factoryState.input.variables;
8
+ const factoryInputs = getListField(itx, "variables").reduce((acc, x) => {
9
+ acc[x.name] = x.value;
10
+ return acc;
11
+ }, {});
12
+ const missingVariables = variables.filter((x) => x.required && !factoryInputs[x.name]);
13
+ if (missingVariables.length) return next(new CustomError("INVALID_FACTORY_INPUT", `Invalid itx.variables: missing required input variable: ${missingVariables.map((x) => x.name).join(", ")}`));
14
+ context.factoryInputs = factoryInputs;
15
+ return next();
16
+ };
17
+ var verify_itx_variables_default = verify_itx_variables;
18
+
19
+ //#endregion
20
+ export { verify_itx_variables_default as default };
@@ -0,0 +1,15 @@
1
+ import { PipeFunction } from "@ocap/tx-pipeline";
2
+ import { IAssetFactoryState, IBaseContext } from "@ocap/types";
3
+
4
+ //#region src/protocols/asset/pipes/verify-mint-limit.d.ts
5
+
6
+ /**
7
+ * Context type for verify-mint-limit pipe.
8
+ * Requires: factoryState
9
+ */
10
+ type VerifyMintLimitContext = IBaseContext & {
11
+ factoryState?: IAssetFactoryState;
12
+ };
13
+ declare const verify_mint_limit: PipeFunction<VerifyMintLimitContext>;
14
+ //#endregion
15
+ export { verify_mint_limit as default };
@@ -0,0 +1,14 @@
1
+ import { CustomError } from "@ocap/util/lib/error";
2
+
3
+ //#region src/protocols/asset/pipes/verify-mint-limit.ts
4
+ const verify_mint_limit = ({ factoryState }, next) => {
5
+ const factory = factoryState;
6
+ const limit = factory.limit;
7
+ if (limit === 0) return next();
8
+ if (factory.numMinted < limit) return next();
9
+ return next(new CustomError("EXCEED_MINT_LIMIT", "This request will exceed factory mint limit"));
10
+ };
11
+ var verify_mint_limit_default = verify_mint_limit;
12
+
13
+ //#endregion
14
+ export { verify_mint_limit_default as default };
@@ -0,0 +1,4 @@
1
+ //#region src/protocols/asset/update.d.ts
2
+ declare const runner: any;
3
+ //#endregion
4
+ export { runner as default };
@@ -0,0 +1,111 @@
1
+ import { decodeAnySafe } 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 { account, asset } from "@ocap/state";
7
+ import Debug from "debug";
8
+ import { Joi } from "@arcblock/validator";
9
+ import { diff } from "deep-diff";
10
+
11
+ //#region src/protocols/asset/update.ts
12
+ const debug = Debug("@ocap/tx-protocols:update-asset");
13
+ const runner = new Runner("update_asset");
14
+ runner.use(pipes.VerifyMultiSig(0));
15
+ const schema = Joi.object({
16
+ address: Joi.DID().prefix().role("ROLE_ASSET").required(),
17
+ moniker: Joi.string().min(2).max(255).optional().allow(null).allow(""),
18
+ consumed: Joi.boolean().optional().allow(null).default(false),
19
+ data: Joi.any().optional().allow(null)
20
+ }).options({
21
+ stripUnknown: true,
22
+ noDefaults: false
23
+ });
24
+ runner.use((context, next) => {
25
+ const { itx } = context;
26
+ const { error } = schema.validate(itx);
27
+ if (error) return next(new CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
28
+ if (!itx.moniker && !itx.data) return next(new CustomError("INVALID_TX", "itx.moniker and itx.data can not be empty at the same time"));
29
+ context.newData = decodeAnySafe(itx.data ?? null);
30
+ return next();
31
+ });
32
+ runner.use(pipes.ExtractState({
33
+ from: "itx.address",
34
+ to: "assetState",
35
+ status: "INVALID_ASSET",
36
+ table: "asset"
37
+ }));
38
+ runner.use(pipes.ExtractState({
39
+ from: "assetState.issuer",
40
+ to: "issuerState",
41
+ status: "OK",
42
+ table: "account"
43
+ }));
44
+ runner.use(pipes.ExtractState({
45
+ from: "tx.from",
46
+ to: "senderState",
47
+ status: "INVALID_SENDER_STATE",
48
+ table: "account"
49
+ }));
50
+ runner.use(pipes.VerifyAccountMigration({
51
+ stateKey: "senderState",
52
+ addressKey: "tx.from"
53
+ }));
54
+ runner.use(pipes.VerifyUpdater({
55
+ assetKey: "assetState",
56
+ ownerKey: "senderState",
57
+ updaterKey: ["owner", "issuer"]
58
+ }));
59
+ runner.use(pipes.VerifyInfo([{
60
+ error: "READONLY_ASSET",
61
+ message: "Can not update a readonly asset",
62
+ fn: (ctx) => ctx.assetState.readonly === false,
63
+ persist: true
64
+ }, {
65
+ error: "CONSUMED_ASSET",
66
+ message: "Can not consume an already consumed asset",
67
+ fn: (ctx) => {
68
+ const context = ctx;
69
+ return !(context.itx.consumed && context.assetState.consumedTime);
70
+ },
71
+ persist: true
72
+ }]));
73
+ runner.use((context, next) => {
74
+ const { itx, newData, senderState, assetState, issuerState } = context;
75
+ if (issuerState && senderState.address === issuerState.address) {
76
+ if (itx.moniker !== assetState.moniker) return next(new CustomError("FORBIDDEN", "Asset moniker can only be updated by owner"));
77
+ if (newData?.type !== assetState.data?.type) return next(new CustomError("FORBIDDEN", "Asset data type can only be updated by owner"));
78
+ if ((diff(assetState.data?.value, newData?.value) || []).every((x) => x.kind === "N" || x.kind === "A" && x.item.kind === "N") === false) return next(new CustomError("APPEND_ONLY", "Asset data value can only be updated in append only mode"));
79
+ }
80
+ return next();
81
+ });
82
+ runner.use(ensure_gas_default(() => ({
83
+ create: 0,
84
+ update: 2,
85
+ payment: 0
86
+ })));
87
+ runner.use(ensure_cost_default({ attachSenderChanges: true }));
88
+ runner.use(pipes.TakeStateSnapshot());
89
+ runner.use(async (context, next) => {
90
+ const { tx: tx$1, itx, txTime, newData, statedb, senderState, senderUpdates, assetState, updateVaults } = context;
91
+ const updates = {
92
+ moniker: itx.moniker || assetState.moniker,
93
+ data: newData || assetState.data
94
+ };
95
+ if (itx.consumed && !assetState.consumedTime) updates.consumedTime = txTime;
96
+ const [newSenderState, newAssetState] = await Promise.all([statedb.account.update(senderState.address, account.update(senderState, {
97
+ nonce: tx$1.nonce,
98
+ pk: tx$1.pk,
99
+ ...senderUpdates
100
+ }, context), context), statedb.asset.update(itx.address, asset.update(assetState, updates, context), context)]);
101
+ if (updateVaults) await updateVaults();
102
+ context.senderState = newSenderState;
103
+ context.assetState = newAssetState;
104
+ debug("update", newAssetState);
105
+ next();
106
+ }, { persistError: true });
107
+ runner.use(pipes.VerifyStateDiff());
108
+ var update_default = runner;
109
+
110
+ //#endregion
111
+ export { update_default as default };
@@ -0,0 +1,29 @@
1
+ //#region src/protocols/factory/create.d.ts
2
+ /** Formatted factory properties from formatMessage */
3
+ interface FormattedFactoryProps {
4
+ name: string;
5
+ description: string;
6
+ settlement: string;
7
+ limit: number;
8
+ trustedIssuers: string[];
9
+ input: {
10
+ value: string;
11
+ tokens: Array<{
12
+ address: string;
13
+ value: string;
14
+ }>;
15
+ assets: string[];
16
+ variables: unknown[];
17
+ };
18
+ output: {
19
+ data?: unknown;
20
+ [key: string]: unknown;
21
+ };
22
+ hooks: unknown[];
23
+ address: string;
24
+ display?: unknown;
25
+ data?: unknown;
26
+ }
27
+ declare const runner: any;
28
+ //#endregion
29
+ export { FormattedFactoryProps, runner as default };