@ocap/tx-protocols 1.6.3 → 1.6.10
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/README.md +36 -0
- package/lib/execute.js +97 -30
- package/lib/index.js +56 -14
- package/lib/protocols/account/declare.js +36 -30
- package/lib/protocols/account/delegate.js +78 -40
- package/lib/protocols/account/migrate.js +65 -49
- package/lib/protocols/account/revoke-delegate.js +39 -23
- package/lib/protocols/asset/acquire-v2.js +159 -0
- package/lib/protocols/asset/acquire-v3.js +242 -0
- package/lib/protocols/asset/calls/README.md +5 -0
- package/lib/protocols/asset/calls/transfer-token.js +37 -0
- package/lib/protocols/asset/calls/transfer.js +29 -0
- package/lib/protocols/asset/create.js +85 -36
- package/lib/protocols/asset/mint.js +133 -0
- package/lib/protocols/asset/pipes/exec-mint-hook.js +59 -0
- package/lib/protocols/asset/pipes/extract-factory-tokens.js +18 -0
- package/lib/protocols/asset/pipes/verify-acquire-params.js +30 -0
- package/lib/protocols/asset/pipes/verify-itx-address.js +41 -0
- package/lib/protocols/asset/pipes/verify-itx-assets.js +49 -0
- package/lib/protocols/asset/pipes/verify-itx-variables.js +26 -0
- package/lib/protocols/asset/pipes/verify-mint-limit.js +13 -0
- package/lib/protocols/asset/update.js +76 -44
- package/lib/protocols/factory/create.js +146 -0
- package/lib/protocols/governance/claim-stake.js +219 -0
- package/lib/protocols/governance/revoke-stake.js +136 -0
- package/lib/protocols/governance/stake.js +176 -0
- package/lib/protocols/rollup/claim-reward.js +283 -0
- package/lib/protocols/rollup/create-block.js +333 -0
- package/lib/protocols/rollup/create.js +169 -0
- package/lib/protocols/rollup/join.js +156 -0
- package/lib/protocols/rollup/leave.js +127 -0
- package/lib/protocols/rollup/migrate-contract.js +53 -0
- package/lib/protocols/rollup/migrate-token.js +66 -0
- package/lib/protocols/rollup/pause.js +52 -0
- package/lib/protocols/rollup/pipes/ensure-service-fee.js +37 -0
- package/lib/protocols/rollup/pipes/ensure-validator.js +10 -0
- package/lib/protocols/rollup/pipes/verify-evidence.js +37 -0
- package/lib/protocols/rollup/pipes/verify-paused.js +10 -0
- package/lib/protocols/rollup/pipes/verify-signers.js +88 -0
- package/lib/protocols/rollup/resume.js +52 -0
- package/lib/protocols/rollup/update.js +98 -0
- package/lib/protocols/token/create.js +150 -0
- package/lib/protocols/token/deposit-v2.js +241 -0
- package/lib/protocols/token/withdraw-v2.js +255 -0
- package/lib/protocols/trade/exchange-v2.js +179 -0
- package/lib/protocols/trade/transfer-v2.js +136 -0
- package/lib/protocols/trade/transfer-v3.js +241 -0
- package/lib/util.js +325 -2
- package/package.json +23 -16
- package/lib/protocols/misc/poke.js +0 -106
- package/lib/protocols/trade/exchange.js +0 -139
- package/lib/protocols/trade/transfer.js +0 -101
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
const get = require('lodash/get');
|
|
2
|
-
const isEmpty = require('empty-value');
|
|
3
|
-
const getListField = require('@ocap/util/lib/get-list-field');
|
|
4
|
-
const { decodeBigInt } = require('@ocap/message');
|
|
5
|
-
const { fromUnitToToken, toBN } = require('@ocap/util');
|
|
6
|
-
const { Runner, pipes } = require('@ocap/tx-pipeline');
|
|
7
|
-
const { account } = require('@ocap/state');
|
|
8
|
-
|
|
9
|
-
// eslint-disable-next-line global-require
|
|
10
|
-
const debug = require('debug')(`${require('../../../package.json').name}:transfer`);
|
|
11
|
-
|
|
12
|
-
const runner = new Runner();
|
|
13
|
-
|
|
14
|
-
runner.use(pipes.VerifyMultiSig(0));
|
|
15
|
-
|
|
16
|
-
runner.use((context, next) => {
|
|
17
|
-
context.assets = getListField(context, 'itx.assets');
|
|
18
|
-
next();
|
|
19
|
-
});
|
|
20
|
-
runner.use(
|
|
21
|
-
pipes.VerifyInfo([
|
|
22
|
-
{
|
|
23
|
-
error: 'INSUFFICIENT_DATA',
|
|
24
|
-
fn: ({ itx, assets }) => {
|
|
25
|
-
if (itx.to && (itx.value || isEmpty(assets) === false)) {
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
return false;
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
error: 'INVALID_TX',
|
|
33
|
-
message: 'Can not transfer without any token or assets',
|
|
34
|
-
fn: ({ itx, config, assets }) => {
|
|
35
|
-
const decimal = get(config, 'token.decimal');
|
|
36
|
-
const amount = itx.value ? decodeBigInt(itx.value) : 0;
|
|
37
|
-
if (Number(fromUnitToToken(amount, decimal)) <= 0 && isEmpty(assets)) {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return true;
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
])
|
|
45
|
-
);
|
|
46
|
-
runner.use(pipes.VerifyItxSize({ value: ['assets'] }));
|
|
47
|
-
|
|
48
|
-
runner.use(pipes.ExtractState({ from: 'tx.from', to: 'senderState', status: 'INVALID_SENDER_STATE' }));
|
|
49
|
-
runner.use(pipes.VerifyAccountMigration({ senderKey: 'senderState' }));
|
|
50
|
-
runner.use(pipes.VerifyBalance({ state: 'senderState', value: 'itx.value' }));
|
|
51
|
-
|
|
52
|
-
runner.use(pipes.ExtractState({ from: 'tx.delegator', to: 'delegatorState', status: 'OK' }));
|
|
53
|
-
runner.use(pipes.VerifyDelegation({ type: 'signature', signerKey: 'senderState', delegatorKey: 'delegatorState' }));
|
|
54
|
-
|
|
55
|
-
runner.use(pipes.ExtractReceiver({ from: 'itx.to' }));
|
|
56
|
-
runner.use(pipes.ExtractState({ from: 'receiver', to: 'receiverState', status: 'INVALID_RECEIVER_STATE' }));
|
|
57
|
-
runner.use(pipes.AntiLandAttack({ senderState: 'senderState', receiverState: 'receiverState' }));
|
|
58
|
-
|
|
59
|
-
runner.use(pipes.ExtractState({ from: 'assets', to: 'assetStates', status: 'INVALID_ASSET' }));
|
|
60
|
-
runner.use(pipes.VerifyTransferrable({ assets: 'assetStates' }));
|
|
61
|
-
runner.use(pipes.VerifyUpdater({ assetKey: 'assetStates', ownerKey: 'senderState' }));
|
|
62
|
-
|
|
63
|
-
runner.use(pipes.UpdateOwner({ assets: 'assetStates', owner: 'receiverState' }));
|
|
64
|
-
runner.use(async (context, next) => {
|
|
65
|
-
const { tx, itx, assets, senderState, receiverState, statedb } = context;
|
|
66
|
-
const total = assets.length;
|
|
67
|
-
const token = itx.value ? decodeBigInt(itx.value) : 0;
|
|
68
|
-
const delta = toBN(token);
|
|
69
|
-
|
|
70
|
-
// Update sender state
|
|
71
|
-
const newSenderState = account.update(
|
|
72
|
-
senderState,
|
|
73
|
-
{
|
|
74
|
-
balance: toBN(senderState.balance).sub(delta).toString(),
|
|
75
|
-
nonce: tx.nonce,
|
|
76
|
-
numAssets: Math.max(0, (senderState.numAssets || 0) - total),
|
|
77
|
-
},
|
|
78
|
-
context
|
|
79
|
-
);
|
|
80
|
-
await statedb.account.update(senderState.address, newSenderState, context);
|
|
81
|
-
|
|
82
|
-
// Update receiver state
|
|
83
|
-
const newReceiverState = account.update(
|
|
84
|
-
receiverState,
|
|
85
|
-
{
|
|
86
|
-
balance: toBN(receiverState.balance).add(delta).toString(),
|
|
87
|
-
numAssets: Math.max(0, (receiverState.numAssets || 0) + total),
|
|
88
|
-
},
|
|
89
|
-
context
|
|
90
|
-
);
|
|
91
|
-
await statedb.account.update(receiverState.address, newReceiverState, context);
|
|
92
|
-
|
|
93
|
-
context.senderState = newSenderState;
|
|
94
|
-
context.receiverState = newReceiverState;
|
|
95
|
-
|
|
96
|
-
debug('transfer', { from: tx.from, to: itx.to, numAssets: total, token });
|
|
97
|
-
|
|
98
|
-
next();
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
module.exports = runner;
|