-
Notifications
You must be signed in to change notification settings - Fork 34
/
app.ts
67 lines (61 loc) · 2.33 KB
/
app.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import {
Environment,
StandardRelayerApp,
StandardRelayerContext,
} from "@wormhole-foundation/relayer-engine";
import { CHAIN_ID_SOLANA, TokenBridgePayload } from "@certusone/wormhole-sdk";
(async function main() {
// initialize relayer engine app, pass relevant config options
const app = new StandardRelayerApp<StandardRelayerContext>(
Environment.TESTNET,
// other app specific config options can be set here for things
// like retries, logger, or redis connection settings.
{
name: `ExampleRelayer`,
},
);
// add a filter with a callback that will be
// invoked on finding a VAA that matches the filter
app.chain(CHAIN_ID_SOLANA).address(
"DZnkkTmCiFWfYTfT41X3Rd1kDgozqzxWaHqsw6W4x2oe", // emitter address on Solana
// callback function to invoke on new message
async (ctx, next) => {
ctx.logger.info(
`Got a VAA with sequence: ${ctx.vaa?.sequence} from with txhash: ${ctx.sourceTxHash}`,
);
const { payload } = ctx.tokenBridge;
// only care about transfers
// TODO: do something more interesting than logging like:
// - redemption of VAA on target chain
// - tracking transfer amounts over time
switch (payload?.payloadType) {
case TokenBridgePayload.Transfer:
ctx.logger.info(
`Transfer processing for: \n` +
`\tToken: ${payload.tokenChain}:${payload.tokenAddress.toString(
"hex",
)}\n` +
`\tAmount: ${payload.amount}\n` +
`\tReceiver: ${payload.toChain}:${payload.to.toString("hex")}\n`,
);
break;
case TokenBridgePayload.TransferWithPayload:
ctx.logger.info(
`Transfer processing for: \n` +
`\tToken: ${payload.tokenChain}:${payload.tokenAddress.toString(
"hex",
)}\n` +
`\tAmount: ${payload.amount}\n` +
`\tSender ${payload.fromAddress?.toString("hex")}\n` +
`\tReceiver: ${payload.toChain}:${payload.to.toString("hex")}\n` +
`\tPayload: ${payload.tokenTransferPayload.toString("hex")}\n`,
);
break;
}
// invoke the next layer in the middleware pipeline
next();
},
);
// start app, blocks until unrecoverable error or process is stopped
await app.listen();
})();