@ocap/tx-protocols 1.29.4 → 1.29.6
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 +5 -0
- package/esm/execute.mjs +61 -4
- package/esm/index.d.mts +737 -73
- package/esm/index.mjs +2 -1
- package/esm/pipes/write-ledger.d.mts +73 -0
- package/esm/pipes/write-ledger.mjs +97 -0
- package/esm/protocols/account/delegate.d.mts +52 -1
- package/esm/protocols/account/migrate.d.mts +15 -1
- package/esm/protocols/account/revoke-delegate.d.mts +14 -1
- package/esm/protocols/asset/acquire-v2.d.mts +39 -1
- package/esm/protocols/asset/acquire-v3.d.mts +43 -1
- package/esm/protocols/asset/calls/transfer-token.d.mts +4 -1
- package/esm/protocols/asset/calls/transfer.d.mts +4 -1
- package/esm/protocols/asset/consume.d.mts +14 -1
- package/esm/protocols/asset/create.d.mts +23 -1
- package/esm/protocols/asset/mint.d.mts +28 -1
- package/esm/protocols/asset/update.d.mts +15 -1
- package/esm/protocols/factory/create.d.mts +23 -1
- package/esm/protocols/governance/claim-stake.d.mts +24 -1
- package/esm/protocols/governance/return-stake.d.mts +20 -1
- package/esm/protocols/governance/revoke-stake.d.mts +20 -1
- package/esm/protocols/governance/slash-stake.d.mts +30 -1
- package/esm/protocols/governance/stake.d.mts +27 -1
- package/esm/protocols/rollup/claim-reward.d.mts +57 -1
- package/esm/protocols/rollup/close.d.mts +16 -1
- package/esm/protocols/rollup/create-block.d.mts +42 -1
- package/esm/protocols/rollup/create.d.mts +28 -1
- package/esm/protocols/rollup/join.d.mts +18 -1
- package/esm/protocols/rollup/leave.d.mts +16 -1
- package/esm/protocols/rollup/migrate.d.mts +11 -1
- package/esm/protocols/rollup/pause.d.mts +11 -1
- package/esm/protocols/rollup/resume.d.mts +11 -1
- package/esm/protocols/rollup/update.d.mts +11 -1
- package/esm/protocols/token/create.d.mts +14 -1
- package/esm/protocols/token/deposit-v2.d.mts +23 -1
- package/esm/protocols/token/withdraw-v2.d.mts +33 -1
- package/esm/protocols/token-factory/burn.d.mts +29 -1
- package/esm/protocols/token-factory/create.d.mts +16 -1
- package/esm/protocols/token-factory/mint.d.mts +27 -1
- package/esm/protocols/token-factory/update.d.mts +15 -1
- package/esm/protocols/trade/exchange-v2.d.mts +40 -1
- package/esm/protocols/trade/transfer-v2.d.mts +32 -1
- package/esm/protocols/trade/transfer-v3.d.mts +31 -1
- package/esm/util.d.mts +1 -1
- package/lib/execute.cjs +61 -4
- package/lib/execute.d.cts +5 -0
- package/lib/index.cjs +2 -0
- package/lib/index.d.cts +737 -73
- package/lib/pipes/write-ledger.cjs +102 -0
- package/lib/pipes/write-ledger.d.cts +73 -0
- package/lib/protocols/account/delegate.d.cts +52 -1
- package/lib/protocols/account/migrate.d.cts +15 -1
- package/lib/protocols/account/revoke-delegate.d.cts +14 -1
- package/lib/protocols/asset/acquire-v2.d.cts +39 -1
- package/lib/protocols/asset/acquire-v3.d.cts +43 -1
- package/lib/protocols/asset/calls/transfer-token.d.cts +4 -1
- package/lib/protocols/asset/calls/transfer.d.cts +4 -1
- package/lib/protocols/asset/consume.d.cts +14 -1
- package/lib/protocols/asset/create.d.cts +23 -1
- package/lib/protocols/asset/mint.d.cts +28 -1
- package/lib/protocols/asset/update.d.cts +15 -1
- package/lib/protocols/factory/create.d.cts +23 -1
- package/lib/protocols/governance/claim-stake.d.cts +24 -1
- package/lib/protocols/governance/return-stake.d.cts +20 -1
- package/lib/protocols/governance/revoke-stake.d.cts +20 -1
- package/lib/protocols/governance/slash-stake.d.cts +30 -1
- package/lib/protocols/governance/stake.d.cts +27 -1
- package/lib/protocols/rollup/claim-reward.d.cts +57 -1
- package/lib/protocols/rollup/close.d.cts +16 -1
- package/lib/protocols/rollup/create-block.d.cts +42 -1
- package/lib/protocols/rollup/create.d.cts +28 -1
- package/lib/protocols/rollup/join.d.cts +18 -1
- package/lib/protocols/rollup/leave.d.cts +16 -1
- package/lib/protocols/rollup/migrate.d.cts +11 -1
- package/lib/protocols/rollup/pause.d.cts +11 -1
- package/lib/protocols/rollup/resume.d.cts +11 -1
- package/lib/protocols/rollup/update.d.cts +11 -1
- package/lib/protocols/token/create.d.cts +14 -1
- package/lib/protocols/token/deposit-v2.d.cts +23 -1
- package/lib/protocols/token/withdraw-v2.d.cts +33 -1
- package/lib/protocols/token-factory/burn.d.cts +29 -1
- package/lib/protocols/token-factory/create.d.cts +16 -1
- package/lib/protocols/token-factory/mint.d.cts +27 -1
- package/lib/protocols/token-factory/update.d.cts +15 -1
- package/lib/protocols/trade/exchange-v2.d.cts +40 -1
- package/lib/protocols/trade/transfer-v2.d.cts +32 -1
- package/lib/protocols/trade/transfer-v3.d.cts +31 -1
- package/lib/util.d.cts +2 -2
- package/package.json +20 -19
|
@@ -1,9 +1,40 @@
|
|
|
1
|
+
import { Runner } from "@ocap/tx-pipeline";
|
|
2
|
+
import { IAssetState, IReadyContext, ITokenState, IWithDelegation, IWithDelegator, IWithReceiver, IWithSender, TTransferV2Tx } from "@ocap/types";
|
|
3
|
+
|
|
1
4
|
//#region src/protocols/trade/transfer-v2.d.ts
|
|
2
5
|
/** Token input */
|
|
3
6
|
interface TokenInput {
|
|
4
7
|
address: string;
|
|
5
8
|
value: string;
|
|
6
9
|
}
|
|
7
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Context type for transfer-v2 protocol.
|
|
12
|
+
* Phase: IReadyContext (after TakeStateSnapshot)
|
|
13
|
+
* Mixins: IWithSender, IWithReceiver, IWithDelegator, IWithDelegation (all optional as states may not exist)
|
|
14
|
+
*/
|
|
15
|
+
type Context = IReadyContext<TTransferV2Tx> & Partial<IWithSender> & Partial<IWithReceiver> & Partial<IWithDelegator> & Partial<IWithDelegation> & {
|
|
16
|
+
/** Asset addresses to transfer */
|
|
17
|
+
assets?: string[];
|
|
18
|
+
/** Token inputs to transfer */
|
|
19
|
+
tokens?: TokenInput[];
|
|
20
|
+
/** Token addresses extracted from inputs */
|
|
21
|
+
tokenAddress?: string[];
|
|
22
|
+
/** Token conditions for balance verification */
|
|
23
|
+
tokenConditions?: {
|
|
24
|
+
owner: string;
|
|
25
|
+
tokens: TokenInput[];
|
|
26
|
+
};
|
|
27
|
+
/** Token states for transferred tokens */
|
|
28
|
+
tokenStates?: ITokenState[];
|
|
29
|
+
/** Asset states for transferred assets */
|
|
30
|
+
assetStates?: IAssetState[];
|
|
31
|
+
/** Receiver address (extracted from itx.to) */
|
|
32
|
+
receiver?: string;
|
|
33
|
+
/** Resolved receiver address */
|
|
34
|
+
receiverAddr?: string;
|
|
35
|
+
/** Whether delegation was changed during tx */
|
|
36
|
+
isDelegationChanged?: boolean;
|
|
37
|
+
};
|
|
38
|
+
declare const runner: Runner<Context>;
|
|
8
39
|
//#endregion
|
|
9
40
|
export { TokenInput, runner as default };
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { Runner } from "@ocap/tx-pipeline";
|
|
2
|
+
import { IAssetState, IReadyContext, ITokenState, IWithReceivers, IWithSender, IWithSigners, TTransferV3Tx } from "@ocap/types";
|
|
3
|
+
|
|
1
4
|
//#region src/protocols/trade/transfer-v3.d.ts
|
|
2
5
|
/** Token input type */
|
|
3
6
|
interface TokenInput {
|
|
@@ -12,6 +15,33 @@ interface MultiInput {
|
|
|
12
15
|
assetsList?: string[];
|
|
13
16
|
assets?: string[];
|
|
14
17
|
}
|
|
15
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Context type for transfer-v3 protocol.
|
|
20
|
+
* Phase: IReadyContext (after TakeStateSnapshot)
|
|
21
|
+
* Mixins: IWithSender, IWithSigners, IWithReceivers (all optional as states may not exist initially)
|
|
22
|
+
*/
|
|
23
|
+
type Context = IReadyContext<TTransferV3Tx> & Partial<IWithSender> & Partial<IWithSigners> & Partial<IWithReceivers> & {
|
|
24
|
+
/** Parsed inputs from itx */
|
|
25
|
+
inputs?: MultiInput[];
|
|
26
|
+
/** Parsed outputs from itx */
|
|
27
|
+
outputs?: MultiInput[];
|
|
28
|
+
/** Sender addresses extracted from inputs */
|
|
29
|
+
senders?: string[];
|
|
30
|
+
/** Receiver addresses extracted from outputs */
|
|
31
|
+
receivers?: string[];
|
|
32
|
+
/** Token addresses from inputs */
|
|
33
|
+
inputTokens?: string[];
|
|
34
|
+
/** Asset addresses from inputs */
|
|
35
|
+
inputAssets?: string[];
|
|
36
|
+
/** Token addresses from outputs */
|
|
37
|
+
outputTokens?: string[];
|
|
38
|
+
/** Asset addresses from outputs */
|
|
39
|
+
outputAssets?: string[];
|
|
40
|
+
/** Token states for transferred tokens */
|
|
41
|
+
tokenStates?: ITokenState[];
|
|
42
|
+
/** Asset states for transferred assets */
|
|
43
|
+
assetStates?: IAssetState[];
|
|
44
|
+
};
|
|
45
|
+
declare const runner: Runner<Context>;
|
|
16
46
|
//#endregion
|
|
17
47
|
export { MultiInput, TokenInput, runner as default };
|
package/esm/util.d.mts
CHANGED
|
@@ -111,7 +111,7 @@ interface ITokenInputForFix {
|
|
|
111
111
|
value: string;
|
|
112
112
|
}>;
|
|
113
113
|
}
|
|
114
|
-
declare const RATE_BASE:
|
|
114
|
+
declare const RATE_BASE: BN;
|
|
115
115
|
declare const decodeAnySafe: (encoded: AnyData | null) => AnyData | null;
|
|
116
116
|
declare const applyTokenUpdates: (tokens: ITokenUpdateInput[], state: IStateWithTokens | IStateWithTokens[] | null | undefined, operator: "add" | "sub") => IStateWithTokens | IStateWithTokens[] | Record<string, string>;
|
|
117
117
|
declare const applyTokenChange: (state: IStateWithTokens | IStateWithTokens[], change: ITokenChange) => IStateWithTokens | IStateWithTokens[] | Record<string, never>;
|
package/lib/execute.cjs
CHANGED
|
@@ -2,6 +2,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
2
2
|
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
3
3
|
const require_pipes_ensure_cost = require('./pipes/ensure-cost.cjs');
|
|
4
4
|
const require_pipes_ensure_gas = require('./pipes/ensure-gas.cjs');
|
|
5
|
+
const require_pipes_write_ledger = require('./pipes/write-ledger.cjs');
|
|
5
6
|
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
6
7
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
7
8
|
let lodash_camelCase = require("lodash/camelCase");
|
|
@@ -58,6 +59,7 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
58
59
|
});
|
|
59
60
|
pre.use(_ocap_tx_pipeline.pipes.VerifyTxSize);
|
|
60
61
|
pre.use(_ocap_tx_pipeline.pipes.VerifySignature);
|
|
62
|
+
pre.use(require_pipes_write_ledger.WriteLedger);
|
|
61
63
|
const ensureGasFeePaid = (context) => {
|
|
62
64
|
const gasRunner = new _ocap_tx_pipeline.Runner("ensure-gas-fee-paid");
|
|
63
65
|
gasRunner.use(ensureTxGas);
|
|
@@ -148,11 +150,13 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
148
150
|
"txBase64",
|
|
149
151
|
"statedb",
|
|
150
152
|
"indexdb",
|
|
153
|
+
"ledger",
|
|
151
154
|
"config",
|
|
152
155
|
"states",
|
|
153
156
|
"filter",
|
|
154
157
|
"extra",
|
|
155
|
-
"logger"
|
|
158
|
+
"logger",
|
|
159
|
+
"ledgerSequence"
|
|
156
160
|
]);
|
|
157
161
|
ctx.txn = txn;
|
|
158
162
|
await execute(ctx, protocols, true);
|
|
@@ -162,9 +166,27 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
162
166
|
}, {
|
|
163
167
|
cleanWorkingSet: true,
|
|
164
168
|
verifyHash: true,
|
|
165
|
-
context: ctx
|
|
169
|
+
context: ctx,
|
|
170
|
+
onCommit: async (stateCommitHash) => {
|
|
171
|
+
if (ctx.txHash && ctx.ledger && ctx.ledgerSequence && ctx.txBase64) try {
|
|
172
|
+
await ctx.ledger.finalizeEntry(ctx.txHash, stateCommitHash || "", ctx.ledgerSequence, ctx.txBase64);
|
|
173
|
+
ctx.stateCommitHash = stateCommitHash || "";
|
|
174
|
+
} catch (err) {
|
|
175
|
+
ctx.logger?.error("Failed to finalize ledger entry", {
|
|
176
|
+
txHash: ctx.txHash,
|
|
177
|
+
stateCommitHash,
|
|
178
|
+
error: err
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
166
182
|
});
|
|
167
183
|
flushEvents(ctx, { txState });
|
|
184
|
+
ctx.ledger?.createCheckpointIfNeeded()?.catch((err) => {
|
|
185
|
+
ctx.logger?.error("Background checkpoint creation failed", {
|
|
186
|
+
txHash: ctx.txHash,
|
|
187
|
+
error: err
|
|
188
|
+
});
|
|
189
|
+
});
|
|
168
190
|
ctx.logger?.info("Tx finalized", {
|
|
169
191
|
txHash: ctx.txHash,
|
|
170
192
|
txState,
|
|
@@ -196,9 +218,27 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
196
218
|
}, {
|
|
197
219
|
cleanWorkingSet: true,
|
|
198
220
|
verifyHash: true,
|
|
199
|
-
context: ctx
|
|
221
|
+
context: ctx,
|
|
222
|
+
onCommit: async (stateCommitHash) => {
|
|
223
|
+
if (ctx.txHash && ctx.ledger && ctx.ledgerSequence && ctx.txBase64) try {
|
|
224
|
+
await ctx.ledger.finalizeEntry(ctx.txHash, stateCommitHash || "", ctx.ledgerSequence, ctx.txBase64);
|
|
225
|
+
ctx.stateCommitHash = stateCommitHash || "";
|
|
226
|
+
} catch (err$1) {
|
|
227
|
+
ctx.logger?.error("Failed to finalize ledger entry", {
|
|
228
|
+
txHash: ctx.txHash,
|
|
229
|
+
stateCommitHash,
|
|
230
|
+
error: err$1
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
}
|
|
200
234
|
});
|
|
201
235
|
flushEvents(ctx, { txState });
|
|
236
|
+
ctx.ledger?.createCheckpointIfNeeded()?.catch((err$1) => {
|
|
237
|
+
ctx.logger?.error("Background checkpoint creation failed", {
|
|
238
|
+
txHash: ctx.txHash,
|
|
239
|
+
error: err$1
|
|
240
|
+
});
|
|
241
|
+
});
|
|
202
242
|
ctx.logger?.info("Tx finalized", {
|
|
203
243
|
txHash: ctx.txHash,
|
|
204
244
|
txState,
|
|
@@ -223,7 +263,24 @@ const createExecute = ({ filter, runAsLambda }) => {
|
|
|
223
263
|
}
|
|
224
264
|
return ctx;
|
|
225
265
|
};
|
|
226
|
-
return
|
|
266
|
+
return async (context, protocols) => {
|
|
267
|
+
const result = await execute(context, protocols);
|
|
268
|
+
if (result.ledger && result.txHash && result.ledgerSequence && result.txBase64) try {
|
|
269
|
+
await result.ledger.finalizeEntry(result.txHash, "", result.ledgerSequence, result.txBase64);
|
|
270
|
+
} catch (err) {
|
|
271
|
+
result.logger?.error("Failed to finalize ledger entry (fallback)", {
|
|
272
|
+
txHash: result.txHash,
|
|
273
|
+
error: err
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
result.ledger?.createCheckpointIfNeeded()?.catch((err) => {
|
|
277
|
+
result.logger?.error("Background checkpoint creation failed", {
|
|
278
|
+
txHash: result.txHash,
|
|
279
|
+
error: err
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
return result;
|
|
283
|
+
};
|
|
227
284
|
};
|
|
228
285
|
var execute_default = createExecute;
|
|
229
286
|
|
package/lib/execute.d.cts
CHANGED
|
@@ -27,6 +27,10 @@ interface IExecutionContext extends IGasContext {
|
|
|
27
27
|
txn?: unknown;
|
|
28
28
|
cacheStates?: unknown;
|
|
29
29
|
senderState?: IAccountState;
|
|
30
|
+
/** Ledger sequence number set by WriteLedger pipe */
|
|
31
|
+
ledgerSequence?: number;
|
|
32
|
+
/** State commit hash set by onCommit callback (Dolt only) */
|
|
33
|
+
stateCommitHash?: string;
|
|
30
34
|
}
|
|
31
35
|
/** Protocol runner interface */
|
|
32
36
|
interface IProtocolRunner {
|
|
@@ -41,6 +45,7 @@ interface IExecuteOptions {
|
|
|
41
45
|
cleanWorkingSet: boolean;
|
|
42
46
|
verifyHash: boolean;
|
|
43
47
|
context: IExecutionContext;
|
|
48
|
+
onCommit?: (commitHash?: string) => void | Promise<void>;
|
|
44
49
|
}) => Promise<T>;
|
|
45
50
|
}
|
|
46
51
|
/** Execute function type */
|
package/lib/index.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
2
|
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
3
|
+
const require_pipes_write_ledger = require('./pipes/write-ledger.cjs');
|
|
3
4
|
const require_execute = require('./execute.cjs');
|
|
4
5
|
const require_protocols_account_delegate = require('./protocols/account/delegate.cjs');
|
|
5
6
|
const require_protocols_account_migrate = require('./protocols/account/migrate.cjs');
|
|
@@ -100,6 +101,7 @@ const { execute } = defaultExecutor;
|
|
|
100
101
|
var src_default = defaultExecutor;
|
|
101
102
|
|
|
102
103
|
//#endregion
|
|
104
|
+
exports.WriteLedger = require_pipes_write_ledger.WriteLedger;
|
|
103
105
|
exports.createExecutor = createExecutor;
|
|
104
106
|
exports.default = src_default;
|
|
105
107
|
exports.execute = execute;
|