Skip to content

Commit 14a0ede

Browse files
committed
feat: add custom actions doc for event listener state machines
1 parent 2016736 commit 14a0ede

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

packages/event-listener/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,27 @@ async function bridgeBaseSepoliaUSDCToEthereumSepolia() {
254254
const ethPrivateKey = '0xTHE_PKP_AUTHORIZED_SIGNER_PRIVATE_KEY';
255255

256256
const stateMachine = StateMachine.fromDefinition({
257+
// Extend the action respository with a custom action we will define later. For example to send notification to the machine owner on transactions
258+
actionRepository: {
259+
notify: class NotificationAction extends Action {
260+
constructor({
261+
stateMachine,
262+
customParam,
263+
}: {
264+
stateMachine: StateMachine;
265+
customParam: string;
266+
}) {
267+
super({
268+
debug,
269+
function: async () => {
270+
const transferData = stateMachine.getFromContext('transfer');
271+
console.log('customParam', customParam);
272+
console.log('transferData', transferData);
273+
},
274+
});
275+
}
276+
},
277+
},
257278
privateKey: ethPrivateKey, // Used only for authorization here, minting was done previously
258279
context: {
259280
// We can prepopulate the context, for example setting the pkp here instead of using state.usePkp later
@@ -371,6 +392,11 @@ async function bridgeBaseSepoliaUSDCToEthereumSepolia() {
371392
},
372393
],
373394
},
395+
{
396+
// Our custom action to notify about the just executed transfer transaction
397+
key: 'notify',
398+
customParam: 'OUR_CUSTOM_PARAM',
399+
},
374400
],
375401
// Going back to waitForFunds to suspend machine if we need more sepolia eth or sepolia USDC
376402
transitions: [{ toState: 'waitForFunds' }],

packages/event-listener/src/lib/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ export interface UpdatesContext {
3838
// Action Types
3939
export type ActionConstructor = new (params: any) => Action;
4040

41-
export interface RawActionDefinition extends ActionParams {
41+
export interface RawActionDefinition {
4242
key: string;
43+
[actionProperty: string]: unknown;
4344
}
4445

4546
export interface LitActionActionDefinition {

0 commit comments

Comments
 (0)