@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.
- 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
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
const { promisify } = require('node:util');
|
|
2
|
-
const { Runner, pipes } = require('@ocap/tx-pipeline');
|
|
3
|
-
const { account, asset, factory, delegation } = require('@ocap/state');
|
|
4
|
-
const { CustomError: Error } = require('@ocap/util/lib/error');
|
|
5
|
-
const { Joi, schemas } = require('@arcblock/validator');
|
|
6
|
-
|
|
7
|
-
const debug = require('debug')(`${require('../../../package.json').name}:acquire-asset-v2`);
|
|
8
|
-
|
|
9
|
-
// custom pipes
|
|
10
|
-
const verifyMintLimit = require('./pipes/verify-mint-limit');
|
|
11
|
-
const verifyItxVariables = require('./pipes/verify-itx-variables');
|
|
12
|
-
const verifyItxAssets = require('./pipes/verify-itx-assets');
|
|
13
|
-
const verifyItxAddress = require('./pipes/verify-itx-address');
|
|
14
|
-
const execMintHook = require('./pipes/exec-mint-hook');
|
|
15
|
-
const extractFactoryTokens = require('./pipes/extract-factory-tokens');
|
|
16
|
-
|
|
17
|
-
const EnsureTxGas = require('../../pipes/ensure-gas');
|
|
18
|
-
const EnsureTxCost = require('../../pipes/ensure-cost');
|
|
19
|
-
|
|
20
|
-
const { applyTokenUpdates, applyTokenChange } = require('../../util');
|
|
21
|
-
|
|
22
|
-
const verifyTokenBalance = promisify(pipes.VerifyTokenBalance({ ownerKey: 'senders', conditionKey: 'conditions' }));
|
|
23
|
-
|
|
24
|
-
const runner = new Runner();
|
|
25
|
-
|
|
26
|
-
runner.use(pipes.VerifyMultiSig(0));
|
|
27
|
-
|
|
28
|
-
// verify itx
|
|
29
|
-
const schema = Joi.object({
|
|
30
|
-
factory: Joi.DID().prefix().role('ROLE_FACTORY').required(),
|
|
31
|
-
address: Joi.DID().prefix().role('ROLE_ASSET').required(),
|
|
32
|
-
assetsList: Joi.array().items(Joi.DID().prefix().role('ROLE_ASSET')).default([]),
|
|
33
|
-
variablesList: Joi.array().items(schemas.variableInput).optional().allow(null).default([]),
|
|
34
|
-
issuer: schemas.nftIssuer.required(),
|
|
35
|
-
data: Joi.any().optional().allow(null),
|
|
36
|
-
}).options({ stripUnknown: true, noDefaults: false });
|
|
37
|
-
runner.use(({ itx }, next) => {
|
|
38
|
-
const { error } = schema.validate(itx);
|
|
39
|
-
if (error) {
|
|
40
|
-
return next(new Error('INVALID_TX', `Invalid itx: ${error.message}`));
|
|
41
|
-
}
|
|
42
|
-
return next();
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
// ensure asset not exist
|
|
46
|
-
runner.use(pipes.ExtractState({ from: 'itx.address', to: 'duplicateAsset', status: 'OK', table: 'asset' }));
|
|
47
|
-
runner.use(
|
|
48
|
-
pipes.VerifyInfo([
|
|
49
|
-
{
|
|
50
|
-
error: 'FORBIDDEN',
|
|
51
|
-
message: 'Asset with same address already exists',
|
|
52
|
-
fn: ({ duplicateAsset }) => !duplicateAsset,
|
|
53
|
-
persist: true,
|
|
54
|
-
},
|
|
55
|
-
])
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
runner.use(
|
|
59
|
-
pipes.ExtractState({ from: 'tx.from', to: 'senderState', status: 'INVALID_SENDER_STATE', table: 'account' })
|
|
60
|
-
);
|
|
61
|
-
runner.use(pipes.VerifyAccountMigration({ stateKey: 'senderState', addressKey: 'tx.from' }));
|
|
62
|
-
|
|
63
|
-
runner.use(pipes.ExtractState({ from: 'tx.delegator', to: 'delegatorState', status: 'OK' }));
|
|
64
|
-
runner.use(
|
|
65
|
-
pipes.ExtractState({ from: 'itx.factory', to: 'factoryState', status: 'INVALID_FACTORY_STATE', table: 'factory' })
|
|
66
|
-
);
|
|
67
|
-
runner.use(
|
|
68
|
-
pipes.VerifyDelegation({
|
|
69
|
-
type: 'signature',
|
|
70
|
-
signerKey: 'senderState',
|
|
71
|
-
delegatorKey: 'delegatorState',
|
|
72
|
-
getRequirements: (context) => context.factoryState.input.tokens.map((x) => ({ type: 'token', ...x })),
|
|
73
|
-
})
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
runner.use(
|
|
77
|
-
pipes.ExtractState({
|
|
78
|
-
from: 'factoryState.owner',
|
|
79
|
-
to: 'factoryOwnerState',
|
|
80
|
-
status: 'INVALID_OWNER_STATE',
|
|
81
|
-
table: 'account',
|
|
82
|
-
})
|
|
83
|
-
);
|
|
84
|
-
runner.use(
|
|
85
|
-
pipes.ExtractState({
|
|
86
|
-
from: 'factoryState.trustedIssuers',
|
|
87
|
-
to: 'issuerStates',
|
|
88
|
-
status: 'INVALID_ISSUER_STATE',
|
|
89
|
-
table: 'account',
|
|
90
|
-
})
|
|
91
|
-
);
|
|
92
|
-
runner.use(
|
|
93
|
-
pipes.ExtractState({ from: 'itx.issuer.id', to: 'issuerState', status: 'INVALID_ISSUER_STATE', table: 'account' })
|
|
94
|
-
);
|
|
95
|
-
runner.use(pipes.VerifyAccountMigration({ stateKey: 'issuerState', addressKey: 'itx.issuer.id' }));
|
|
96
|
-
|
|
97
|
-
runner.use(
|
|
98
|
-
pipes.VerifyInfo([
|
|
99
|
-
{
|
|
100
|
-
error: 'FORBIDDEN',
|
|
101
|
-
message: 'Only factory owner and trusted issuers are allowed',
|
|
102
|
-
fn: ({ issuerState, factoryOwnerState, issuerStates = [] }) => {
|
|
103
|
-
return (
|
|
104
|
-
factoryOwnerState.address === issuerState.address ||
|
|
105
|
-
issuerStates.find((x) => x.address === issuerState.address)
|
|
106
|
-
);
|
|
107
|
-
},
|
|
108
|
-
persist: true,
|
|
109
|
-
},
|
|
110
|
-
])
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
runner.use(pipes.ExtractState({ from: 'itx.assetsList', to: 'assetStates', status: 'OK', table: 'asset' }));
|
|
114
|
-
runner.use(
|
|
115
|
-
pipes.ExtractState({
|
|
116
|
-
from: 'factoryState.input.assets',
|
|
117
|
-
to: 'expectedFactoryStates',
|
|
118
|
-
status: 'OK',
|
|
119
|
-
table: 'factory',
|
|
120
|
-
})
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
// Though tokens are verified on factory creating phase, we need them here to construct tokenSymbols
|
|
124
|
-
runner.use(extractFactoryTokens);
|
|
125
|
-
runner.use(pipes.ExtractState({ from: 'tokenAddress', to: 'tokenStates', status: 'INVALID_TOKEN', table: 'token' }));
|
|
126
|
-
|
|
127
|
-
// Verify itx
|
|
128
|
-
runner.use(verifyMintLimit);
|
|
129
|
-
runner.use(verifyItxVariables);
|
|
130
|
-
runner.use(verifyItxAddress('acquire-v2'));
|
|
131
|
-
runner.use(pipes.VerifyBlocked({ stateKeys: ['assetOwner'] }));
|
|
132
|
-
runner.use(async (context, next) => {
|
|
133
|
-
const { factoryTokens, senderState } = context;
|
|
134
|
-
const condition = {
|
|
135
|
-
owner: senderState.address,
|
|
136
|
-
tokens: [...factoryTokens],
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
try {
|
|
140
|
-
await verifyTokenBalance({ senders: [senderState], conditions: [condition] });
|
|
141
|
-
return next();
|
|
142
|
-
} catch (err) {
|
|
143
|
-
return next(err);
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
runner.use(pipes.VerifyUpdater({ assetKey: 'assetStates', ownerKey: 'assetOwner' }));
|
|
147
|
-
runner.use(verifyItxAssets);
|
|
148
|
-
|
|
149
|
-
// Ensure tx fee and gas
|
|
150
|
-
runner.use(
|
|
151
|
-
EnsureTxGas((context) => {
|
|
152
|
-
// FIXME: payment check
|
|
153
|
-
const result = { create: 1, update: 3, payment: 0 };
|
|
154
|
-
if (context.assetStates) {
|
|
155
|
-
result.update += context.assetStates.length;
|
|
156
|
-
}
|
|
157
|
-
if (context.delegatorState) {
|
|
158
|
-
result.update += 1;
|
|
159
|
-
}
|
|
160
|
-
return result;
|
|
161
|
-
})
|
|
162
|
-
);
|
|
163
|
-
runner.use(EnsureTxCost({ attachSenderChanges: true }));
|
|
164
|
-
|
|
165
|
-
// Save context snapshot before updating states
|
|
166
|
-
runner.use(pipes.TakeStateSnapshot());
|
|
167
|
-
|
|
168
|
-
// update statedb
|
|
169
|
-
runner.use(
|
|
170
|
-
async (context, next) => {
|
|
171
|
-
const {
|
|
172
|
-
tx,
|
|
173
|
-
itx,
|
|
174
|
-
txTime,
|
|
175
|
-
statedb,
|
|
176
|
-
senderState,
|
|
177
|
-
assetOwner,
|
|
178
|
-
factoryState,
|
|
179
|
-
factoryTokens,
|
|
180
|
-
delegationState,
|
|
181
|
-
mintedAsset,
|
|
182
|
-
mintedAddress,
|
|
183
|
-
senderChange,
|
|
184
|
-
updateVaults,
|
|
185
|
-
assetStates = [],
|
|
186
|
-
} = context;
|
|
187
|
-
|
|
188
|
-
// Sender updates
|
|
189
|
-
const senderUpdates = {
|
|
190
|
-
nonce: tx.nonce,
|
|
191
|
-
pk: tx.pk,
|
|
192
|
-
...applyTokenUpdates(
|
|
193
|
-
factoryTokens,
|
|
194
|
-
senderChange ? applyTokenChange(senderState, senderChange) : senderState,
|
|
195
|
-
'sub'
|
|
196
|
-
),
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
// Owner updates
|
|
200
|
-
const ownerUpdates = {};
|
|
201
|
-
|
|
202
|
-
// Factory updates
|
|
203
|
-
const factoryUpdates = { numMinted: factoryState.numMinted + 1 };
|
|
204
|
-
if (factoryState.settlement !== 'instant') {
|
|
205
|
-
// Move primary/secondary tokens to factory if we are not doing instant settlement
|
|
206
|
-
Object.assign(factoryUpdates, applyTokenUpdates(factoryTokens, factoryState, 'add'));
|
|
207
|
-
context.tokenUpdates = applyTokenUpdates(factoryTokens, { tokens: {} }, 'add');
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
const [newSenderState, assetState, newFactoryState, newAssetStates, newDelegationState] = await Promise.all([
|
|
211
|
-
// Update sender state
|
|
212
|
-
statedb.account.update(senderState.address, account.update(senderState, senderUpdates, context), context),
|
|
213
|
-
|
|
214
|
-
// Create new asset
|
|
215
|
-
statedb.asset.create(
|
|
216
|
-
itx.address,
|
|
217
|
-
asset.create({ ...mintedAsset, owner: assetOwner.address, address: mintedAddress }, context),
|
|
218
|
-
context
|
|
219
|
-
),
|
|
220
|
-
|
|
221
|
-
// Update factory state
|
|
222
|
-
statedb.factory.update(factoryState.address, factory.update(factoryState, factoryUpdates, context), context),
|
|
223
|
-
|
|
224
|
-
// Mark input assets as consumed
|
|
225
|
-
Promise.all(
|
|
226
|
-
assetStates.map((x) =>
|
|
227
|
-
statedb.asset.update(x.address, asset.update(x, { consumedTime: txTime }, context), context)
|
|
228
|
-
)
|
|
229
|
-
),
|
|
230
|
-
|
|
231
|
-
// Update delegation state
|
|
232
|
-
context.isDelegationChanged
|
|
233
|
-
? statedb.delegation.update(delegationState.address, delegation.update(delegationState, {}, context), context)
|
|
234
|
-
: delegationState,
|
|
235
|
-
|
|
236
|
-
// Update delegator state
|
|
237
|
-
context.delegatorState
|
|
238
|
-
? statedb.account.update(assetOwner.address, account.update(assetOwner, ownerUpdates, context), context)
|
|
239
|
-
: null,
|
|
240
|
-
]);
|
|
241
|
-
|
|
242
|
-
await updateVaults();
|
|
243
|
-
|
|
244
|
-
context.senderState = newSenderState;
|
|
245
|
-
context.assetState = assetState;
|
|
246
|
-
context.factoryState = newFactoryState;
|
|
247
|
-
context.assetStates = newAssetStates;
|
|
248
|
-
context.delegationState = newDelegationState;
|
|
249
|
-
|
|
250
|
-
debug('acquire-v2', assetState);
|
|
251
|
-
|
|
252
|
-
next();
|
|
253
|
-
},
|
|
254
|
-
{ persistError: true }
|
|
255
|
-
);
|
|
256
|
-
|
|
257
|
-
// run minting hooks for instant settlement
|
|
258
|
-
runner.use(execMintHook, { persistError: true });
|
|
259
|
-
|
|
260
|
-
runner.use(pipes.VerifyStateDiff());
|
|
261
|
-
|
|
262
|
-
module.exports = runner;
|
|
@@ -1,330 +0,0 @@
|
|
|
1
|
-
const { promisify } = require('node:util');
|
|
2
|
-
const isEqual = require('lodash/isEqual');
|
|
3
|
-
const { BN } = require('@ocap/util');
|
|
4
|
-
const { Runner, pipes } = require('@ocap/tx-pipeline');
|
|
5
|
-
const { account, asset, factory } = require('@ocap/state');
|
|
6
|
-
const { CustomError: Error } = require('@ocap/util/lib/error');
|
|
7
|
-
const { Joi, schemas } = require('@arcblock/validator');
|
|
8
|
-
|
|
9
|
-
const debug = require('debug')(`${require('../../../package.json').name}:acquire-asset-v3`);
|
|
10
|
-
|
|
11
|
-
const { applyTokenUpdates, applyTokenChange } = require('../../util');
|
|
12
|
-
|
|
13
|
-
// custom pipes
|
|
14
|
-
const verifyMintLimit = require('./pipes/verify-mint-limit');
|
|
15
|
-
const verifyItxVariables = require('./pipes/verify-itx-variables');
|
|
16
|
-
const verifyItxAssets = require('./pipes/verify-itx-assets');
|
|
17
|
-
const verifyItxAddress = require('./pipes/verify-itx-address');
|
|
18
|
-
const execMintHook = require('./pipes/exec-mint-hook');
|
|
19
|
-
const extractFactoryTokens = require('./pipes/extract-factory-tokens');
|
|
20
|
-
|
|
21
|
-
const EnsureTxGas = require('../../pipes/ensure-gas');
|
|
22
|
-
const EnsureTxCost = require('../../pipes/ensure-cost');
|
|
23
|
-
|
|
24
|
-
const verifyAssetOwner = promisify(pipes.VerifyUpdater({ assetKey: 'assets', ownerKey: 'owner' }));
|
|
25
|
-
|
|
26
|
-
const runner = new Runner();
|
|
27
|
-
|
|
28
|
-
// 1. extract & verify itx input
|
|
29
|
-
const schema = Joi.object({
|
|
30
|
-
factory: Joi.DID().prefix().role('ROLE_FACTORY').required(),
|
|
31
|
-
address: Joi.DID().prefix().role('ROLE_ASSET').required(),
|
|
32
|
-
inputsList: schemas.multiInput.min(1).required(),
|
|
33
|
-
owner: schemas.tokenHolder.required(),
|
|
34
|
-
variablesList: Joi.array().items(schemas.variableInput).optional().allow(null).default([]),
|
|
35
|
-
issuer: schemas.nftIssuer.required(),
|
|
36
|
-
data: Joi.any().optional().allow(null),
|
|
37
|
-
}).options({ stripUnknown: true, noDefaults: false });
|
|
38
|
-
runner.use(({ itx }, next) => {
|
|
39
|
-
const { error } = schema.validate(itx);
|
|
40
|
-
if (error) {
|
|
41
|
-
return next(new Error('INVALID_TX', `Invalid itx: ${error.message}`));
|
|
42
|
-
}
|
|
43
|
-
return next();
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
// ensure asset not exist
|
|
47
|
-
runner.use(pipes.ExtractState({ from: 'itx.address', to: 'duplicateAsset', status: 'OK', table: 'asset' }));
|
|
48
|
-
runner.use(
|
|
49
|
-
pipes.VerifyInfo([
|
|
50
|
-
{
|
|
51
|
-
error: 'FORBIDDEN',
|
|
52
|
-
message: 'Asset with same address already exists',
|
|
53
|
-
fn: ({ duplicateAsset }) => !duplicateAsset,
|
|
54
|
-
persist: true,
|
|
55
|
-
},
|
|
56
|
-
])
|
|
57
|
-
);
|
|
58
|
-
runner.use(
|
|
59
|
-
pipes.VerifyTxInput({
|
|
60
|
-
fieldKey: 'itx.inputs',
|
|
61
|
-
inputsKey: 'inputs',
|
|
62
|
-
sendersKey: 'senders',
|
|
63
|
-
tokensKey: 'tokens',
|
|
64
|
-
assetsKey: 'assets',
|
|
65
|
-
})
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
// 2. verify itx size: set hard limit here because more inputs leads to longer tx execute time
|
|
69
|
-
runner.use(pipes.VerifyListSize({ listKey: ['inputs', 'senders', 'tokens', 'assets'] }));
|
|
70
|
-
|
|
71
|
-
// 3. verify multi sig
|
|
72
|
-
runner.use(pipes.VerifyMultiSigV2({ signersKey: 'senders' }));
|
|
73
|
-
|
|
74
|
-
// 4. verify against factory state
|
|
75
|
-
runner.use(
|
|
76
|
-
pipes.ExtractState({ from: 'itx.factory', to: 'factoryState', status: 'INVALID_FACTORY_STATE', table: 'factory' })
|
|
77
|
-
);
|
|
78
|
-
runner.use(
|
|
79
|
-
pipes.ExtractState({
|
|
80
|
-
from: 'factoryState.owner',
|
|
81
|
-
to: 'factoryOwnerState',
|
|
82
|
-
status: 'INVALID_OWNER_STATE',
|
|
83
|
-
table: 'account',
|
|
84
|
-
})
|
|
85
|
-
);
|
|
86
|
-
runner.use(
|
|
87
|
-
pipes.ExtractState({
|
|
88
|
-
from: 'factoryState.trustedIssuers',
|
|
89
|
-
to: 'issuerStates',
|
|
90
|
-
status: 'INVALID_ISSUER_STATE',
|
|
91
|
-
table: 'account',
|
|
92
|
-
})
|
|
93
|
-
);
|
|
94
|
-
runner.use(
|
|
95
|
-
pipes.ExtractState({ from: 'itx.issuer.id', to: 'issuerState', status: 'INVALID_ISSUER_STATE', table: 'account' })
|
|
96
|
-
);
|
|
97
|
-
runner.use(pipes.VerifyAccountMigration({ stateKey: 'issuerState', addressKey: 'itx.issuer.id' }));
|
|
98
|
-
runner.use(
|
|
99
|
-
pipes.VerifyInfo([
|
|
100
|
-
{
|
|
101
|
-
error: 'FORBIDDEN',
|
|
102
|
-
message: 'Only factory owner and trusted issuers are allowed',
|
|
103
|
-
fn: ({ issuerState, factoryOwnerState, issuerStates = [] }) => {
|
|
104
|
-
return (
|
|
105
|
-
factoryOwnerState.address === issuerState.address ||
|
|
106
|
-
issuerStates.find((x) => x.address === issuerState.address)
|
|
107
|
-
);
|
|
108
|
-
},
|
|
109
|
-
persist: true,
|
|
110
|
-
},
|
|
111
|
-
])
|
|
112
|
-
);
|
|
113
|
-
runner.use(extractFactoryTokens);
|
|
114
|
-
runner.use(verifyMintLimit);
|
|
115
|
-
runner.use(verifyItxVariables);
|
|
116
|
-
runner.use(
|
|
117
|
-
pipes.VerifyInfo([
|
|
118
|
-
{
|
|
119
|
-
error: 'INVALID_TX',
|
|
120
|
-
message: 'Input token address does not match with factory input requirement',
|
|
121
|
-
fn: (ctx) => isEqual(ctx.tokens, ctx.tokenAddress),
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
error: 'INVALID_TX',
|
|
125
|
-
message: 'Input token amount does not match with factory input requirement',
|
|
126
|
-
fn: ({ inputs, factoryTokens }) => {
|
|
127
|
-
const inputMap = {};
|
|
128
|
-
|
|
129
|
-
inputs.forEach(({ tokensList }) => {
|
|
130
|
-
tokensList.forEach(({ address, value }) => {
|
|
131
|
-
if (typeof inputMap[address] === 'undefined') {
|
|
132
|
-
inputMap[address] = new BN(0);
|
|
133
|
-
}
|
|
134
|
-
inputMap[address] = inputMap[address].add(new BN(value));
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
const expectedTokens = factoryTokens.reduce((acc, x) => {
|
|
139
|
-
acc[x.address] = new BN(x.value);
|
|
140
|
-
return acc;
|
|
141
|
-
}, {});
|
|
142
|
-
|
|
143
|
-
return Object.keys(expectedTokens).every((address) => inputMap[address].eq(expectedTokens[address]));
|
|
144
|
-
},
|
|
145
|
-
},
|
|
146
|
-
])
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
// 5. verify sender & signer & owner
|
|
150
|
-
runner.use(pipes.ExtractState({ from: 'tx.from', to: 'senderState', status: 'OK', table: 'account' }));
|
|
151
|
-
runner.use(
|
|
152
|
-
pipes.ExtractState({ from: 'senders', to: 'signerStates', status: 'INVALID_SIGNER_STATE', table: 'account' })
|
|
153
|
-
);
|
|
154
|
-
runner.use(pipes.ExtractState({ from: 'itx.owner', to: 'ownerState', status: 'OK', table: 'account' }));
|
|
155
|
-
runner.use(pipes.VerifyAccountMigration({ signerKey: 'signerStates', stateKey: 'senderState', addressKey: 'tx.from' }));
|
|
156
|
-
runner.use(pipes.VerifyBlocked({ stateKeys: ['signerStates', 'ownerState'] }));
|
|
157
|
-
|
|
158
|
-
// 6. verify token state and balance
|
|
159
|
-
runner.use(pipes.ExtractState({ from: 'tokens', to: 'tokenStates', status: 'INVALID_TOKEN', table: 'token' }));
|
|
160
|
-
runner.use(pipes.VerifyTokenBalance({ ownerKey: 'signerStates', conditionKey: 'inputs' }));
|
|
161
|
-
|
|
162
|
-
// 7. verify asset state and ownership
|
|
163
|
-
runner.use(pipes.ExtractState({ from: 'assets', to: 'assetStates', status: 'OK', table: 'asset' }));
|
|
164
|
-
runner.use(async (context, next) => {
|
|
165
|
-
const { inputs, assetStates = [], signerStates } = context;
|
|
166
|
-
for (const input of inputs) {
|
|
167
|
-
const { owner, assetsList } = input;
|
|
168
|
-
const states = assetStates.filter((x) => assetsList.includes(x.address));
|
|
169
|
-
const signer = signerStates.find((x) => x.address === owner);
|
|
170
|
-
|
|
171
|
-
try {
|
|
172
|
-
await verifyAssetOwner({ assets: states, owner: signer });
|
|
173
|
-
} catch (err) {
|
|
174
|
-
return next(err);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
return next();
|
|
179
|
-
});
|
|
180
|
-
runner.use(
|
|
181
|
-
pipes.ExtractState({
|
|
182
|
-
from: 'factoryState.input.assets',
|
|
183
|
-
to: 'expectedFactoryStates',
|
|
184
|
-
status: 'OK',
|
|
185
|
-
table: 'factory',
|
|
186
|
-
})
|
|
187
|
-
);
|
|
188
|
-
|
|
189
|
-
// Verify itx
|
|
190
|
-
runner.use(verifyItxAddress('acquire-v3'));
|
|
191
|
-
runner.use(verifyItxAssets);
|
|
192
|
-
|
|
193
|
-
// Ensure tx fee and gas
|
|
194
|
-
runner.use(
|
|
195
|
-
EnsureTxGas((context) => {
|
|
196
|
-
// FIXME: payment check
|
|
197
|
-
const result = { create: 1, update: 2, payment: 0 };
|
|
198
|
-
if (context.assetStates) {
|
|
199
|
-
result.update += context.assetStates.length;
|
|
200
|
-
}
|
|
201
|
-
if (context.signerStates) {
|
|
202
|
-
result.update += context.signerStates.length;
|
|
203
|
-
}
|
|
204
|
-
if (!context.ownerState) {
|
|
205
|
-
result.create += 1;
|
|
206
|
-
}
|
|
207
|
-
return result;
|
|
208
|
-
})
|
|
209
|
-
);
|
|
210
|
-
runner.use(EnsureTxCost({ attachSenderChanges: true }));
|
|
211
|
-
|
|
212
|
-
// Save context snapshot before updating states
|
|
213
|
-
runner.use(pipes.TakeStateSnapshot());
|
|
214
|
-
|
|
215
|
-
// update statedb
|
|
216
|
-
runner.use(
|
|
217
|
-
async (context, next) => {
|
|
218
|
-
const {
|
|
219
|
-
tx,
|
|
220
|
-
itx,
|
|
221
|
-
txTime,
|
|
222
|
-
inputs,
|
|
223
|
-
statedb,
|
|
224
|
-
senderState,
|
|
225
|
-
ownerState,
|
|
226
|
-
factoryState,
|
|
227
|
-
factoryTokens,
|
|
228
|
-
mintedAsset,
|
|
229
|
-
mintedAddress,
|
|
230
|
-
signerStates,
|
|
231
|
-
senderChange,
|
|
232
|
-
updateVaults,
|
|
233
|
-
assetStates = [],
|
|
234
|
-
} = context;
|
|
235
|
-
|
|
236
|
-
const signerUpdates = {};
|
|
237
|
-
inputs.forEach((x) => {
|
|
238
|
-
const { owner, tokensList } = x;
|
|
239
|
-
signerUpdates[owner] = applyTokenUpdates(
|
|
240
|
-
tokensList,
|
|
241
|
-
signerStates.find((s) => s.address === owner),
|
|
242
|
-
'sub'
|
|
243
|
-
);
|
|
244
|
-
if (senderChange && owner === senderChange.address) {
|
|
245
|
-
signerUpdates[owner] = applyTokenChange(signerUpdates[owner], senderChange);
|
|
246
|
-
}
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
const isAlsoSigner = !!signerUpdates[tx.from];
|
|
250
|
-
const owner = ownerState ? ownerState.address : itx.owner;
|
|
251
|
-
|
|
252
|
-
// Factory updates
|
|
253
|
-
const factoryUpdates = { numMinted: factoryState.numMinted + 1 };
|
|
254
|
-
|
|
255
|
-
// Move primary/secondary tokens to factory if we are not doing instant settlement
|
|
256
|
-
if (factoryState.settlement !== 'instant') {
|
|
257
|
-
Object.assign(factoryUpdates, applyTokenUpdates(factoryTokens, factoryState, 'add'));
|
|
258
|
-
context.tokenUpdates = applyTokenUpdates(factoryTokens, { tokens: {} }, 'add');
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
const [newSenderState, newReceiverState, assetState, newSignerStates, newFactoryState, newAssetStates] =
|
|
262
|
-
await Promise.all([
|
|
263
|
-
// update sender
|
|
264
|
-
statedb.account.updateOrCreate(
|
|
265
|
-
senderState,
|
|
266
|
-
account.updateOrCreate(
|
|
267
|
-
senderState,
|
|
268
|
-
Object.assign(
|
|
269
|
-
{ address: tx.from, nonce: tx.nonce, pk: tx.pk },
|
|
270
|
-
signerUpdates[tx.from] || (senderChange ? applyTokenChange(senderState, senderChange) : {})
|
|
271
|
-
),
|
|
272
|
-
context
|
|
273
|
-
),
|
|
274
|
-
context
|
|
275
|
-
),
|
|
276
|
-
|
|
277
|
-
// create receiver if not exist: asset owner
|
|
278
|
-
ownerState || owner === tx.from
|
|
279
|
-
? Promise.resolve(ownerState)
|
|
280
|
-
: statedb.account.create(owner, account.create({ address: owner }, context), context),
|
|
281
|
-
|
|
282
|
-
// Create asset
|
|
283
|
-
statedb.asset.create(
|
|
284
|
-
itx.address,
|
|
285
|
-
asset.create({ ...mintedAsset, owner, address: mintedAddress }, context),
|
|
286
|
-
context
|
|
287
|
-
),
|
|
288
|
-
|
|
289
|
-
// Update signer state
|
|
290
|
-
Promise.all(
|
|
291
|
-
signerStates
|
|
292
|
-
.filter((x) => x.address !== tx.from)
|
|
293
|
-
.map((x) =>
|
|
294
|
-
statedb.account.update(x.address, account.update(x, signerUpdates[x.address], context), context)
|
|
295
|
-
)
|
|
296
|
-
),
|
|
297
|
-
|
|
298
|
-
// Update factory state
|
|
299
|
-
statedb.factory.update(factoryState.address, factory.update(factoryState, factoryUpdates, context), context),
|
|
300
|
-
|
|
301
|
-
// Mark asset as consumed
|
|
302
|
-
Promise.all(
|
|
303
|
-
assetStates.map((x) =>
|
|
304
|
-
statedb.asset.update(x.address, asset.update(x, { consumedTime: txTime }, context), context)
|
|
305
|
-
)
|
|
306
|
-
),
|
|
307
|
-
]);
|
|
308
|
-
|
|
309
|
-
await updateVaults();
|
|
310
|
-
|
|
311
|
-
context.senderState = newSenderState;
|
|
312
|
-
context.receiverState = owner === tx.from ? newSenderState : newReceiverState;
|
|
313
|
-
context.signerStates = isAlsoSigner ? newSignerStates.concat(newSenderState) : newSignerStates;
|
|
314
|
-
context.assetState = assetState;
|
|
315
|
-
context.factoryState = newFactoryState;
|
|
316
|
-
context.assetStates = newAssetStates;
|
|
317
|
-
|
|
318
|
-
debug('acquire-v3', assetState);
|
|
319
|
-
|
|
320
|
-
next();
|
|
321
|
-
},
|
|
322
|
-
{ persistError: true }
|
|
323
|
-
);
|
|
324
|
-
|
|
325
|
-
// run minting hooks for instant settlement
|
|
326
|
-
runner.use(execMintHook, { persistError: true });
|
|
327
|
-
|
|
328
|
-
runner.use(pipes.VerifyStateDiff());
|
|
329
|
-
|
|
330
|
-
module.exports = runner;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
const cloneDeep = require('lodash/cloneDeep');
|
|
2
|
-
const { BN } = require('@ocap/util');
|
|
3
|
-
const { Runner, pipes } = require('@ocap/tx-pipeline');
|
|
4
|
-
|
|
5
|
-
const debug = require('debug')(`${require('../../../../package.json').name}:acquire-asset:transfer-token`);
|
|
6
|
-
|
|
7
|
-
const runner = new Runner();
|
|
8
|
-
|
|
9
|
-
runner.use(pipes.ExtractState({ from: 'args.to', to: 'receiverState', status: 'INVALID_RECEIVER_STATE' }));
|
|
10
|
-
|
|
11
|
-
runner.use((context, next) => {
|
|
12
|
-
const { states, receiverState, args } = context;
|
|
13
|
-
const { tokenAddress, amount } = args;
|
|
14
|
-
|
|
15
|
-
const delta = new BN(amount);
|
|
16
|
-
const newTokens = cloneDeep(receiverState.tokens || {});
|
|
17
|
-
if (newTokens[tokenAddress]) {
|
|
18
|
-
const old = new BN(newTokens[tokenAddress]);
|
|
19
|
-
newTokens[tokenAddress] = old.add(delta).toString();
|
|
20
|
-
} else {
|
|
21
|
-
newTokens[tokenAddress] = delta.toString();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
context.updateSet = {
|
|
25
|
-
address: receiverState.address,
|
|
26
|
-
updates: states.account.update(receiverState, { tokens: newTokens }, context),
|
|
27
|
-
delta: amount,
|
|
28
|
-
token: tokenAddress,
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
debug('contract.transfer-token', context.updateSet);
|
|
32
|
-
|
|
33
|
-
next();
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
module.exports = runner;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
const { BN } = require('@ocap/util');
|
|
2
|
-
const { Runner, pipes } = require('@ocap/tx-pipeline');
|
|
3
|
-
|
|
4
|
-
const debug = require('debug')(`${require('../../../../package.json').name}:acquire-asset:transfer`);
|
|
5
|
-
|
|
6
|
-
const runner = new Runner();
|
|
7
|
-
|
|
8
|
-
runner.use(pipes.ExtractState({ from: 'args.to', to: 'receiverState', status: 'INVALID_RECEIVER_STATE' }));
|
|
9
|
-
|
|
10
|
-
runner.use((context, next) => {
|
|
11
|
-
const { states, receiverState, args } = context;
|
|
12
|
-
|
|
13
|
-
const old = new BN(receiverState.balance);
|
|
14
|
-
const delta = new BN(args.amount);
|
|
15
|
-
|
|
16
|
-
context.updateSet = {
|
|
17
|
-
address: receiverState.address,
|
|
18
|
-
updates: states.account.update(receiverState, { balance: old.add(delta).toString() }, context),
|
|
19
|
-
delta: args.amount,
|
|
20
|
-
token: '',
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
debug('contract.transfer', context.updateSet);
|
|
24
|
-
|
|
25
|
-
next();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
module.exports = runner;
|