Skip to content

Commit

Permalink
examples: Replace TransactionBlock with Transaction and improve event… (
Browse files Browse the repository at this point in the history
#20293)

… parsing logic

## Description 

Describe the changes or additions included in this PR.

## Test plan 

How did you test the new or updated feature?

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
  • Loading branch information
Birch authored Nov 17, 2024
1 parent 3b1319a commit c2b40d8
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions examples/mev_bot/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { bcs, BcsType } from '@mysten/sui/bcs';
import { SuiClient } from '@mysten/sui/client';
import { TransactionBlock } from '@mysten/sui/transactions';
import { Transaction } from '@mysten/sui/transactions';
import pLimit from 'p-limit';

const limit = pLimit(5);
Expand Down Expand Up @@ -127,9 +127,15 @@ async function retrieveAllPools() {
});
data.push(...page.data);
}

return data.map((event) => {
return PoolCreated.fromBase64(event.bcs);
});
try {
return PoolCreated.fromBase64(event.bcs);
} catch (err) {
console.error("Failed to parse event:", err, "Event:", event);
return null;
}
}).filter((pool) => pool !== null);
}

async function retrieveExpiredOrders(poolId: string) {
Expand Down Expand Up @@ -194,7 +200,7 @@ async function retrieveExpiredOrders(poolId: string) {
}

async function createCleanUpTransaction(poolOrders: { pool: any; expiredOrders: any[] }[]) {
let tx = new TransactionBlock();
let tx = new Transaction();

for (let poolOrder of poolOrders) {
let orderIds = poolOrder.expiredOrders.map((order) => tx.object(order.order_id));
Expand Down

0 comments on commit c2b40d8

Please sign in to comment.