Skip to content

Commit b2be32c

Browse files
committed
fix: improve error handling and logging in proposer server; refactor LazerExecute instruction creation
1 parent 5f2ba2e commit b2be32c

File tree

5 files changed

+50
-39
lines changed

5 files changed

+50
-39
lines changed

governance/xc_admin/packages/proposer_server/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,10 @@ app.post("/api/propose", async (req: Request, res: Response) => {
9090
res.status(200).json({ proposalPubkey: proposalPubkey });
9191
} catch (error) {
9292
if (error instanceof Error) {
93+
console.error(error);
9394
res.status(500).json(error.message);
9495
} else {
96+
console.error(error);
9597
res.status(500).json("An unknown error occurred");
9698
}
9799
}

governance/xc_admin/packages/xc_admin_common/src/programs/lazer/lazer_functions.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
import { PublicKey, TransactionInstruction } from "@solana/web3.js";
22
import { PythCluster } from "@pythnetwork/client";
33
import {
4-
ValidationResult,
54
LazerValidationResult,
65
ProgramType,
76
LazerConfig,
87
LazerState,
98
LazerFeedMetadata,
10-
LazerFeed,
11-
LazerPublisher,
129
ShardChange,
1310
FeedChange,
1411
PublisherChange,
1512
LazerConfigChanges,
1613
} from "../types";
1714
import { pyth_lazer_transaction } from "@pythnetwork/pyth-lazer-state-sdk/governance";
18-
import { ChainName, LazerExecute } from "../..";
15+
import { ChainName, LazerExecute, WORMHOLE_ADDRESS } from "../..";
1916

2017
/**
2118
* Converts LazerFeedMetadata to protobuf IMap format using protobufjs fromObject
@@ -605,11 +602,13 @@ export async function generateInstructions(
605602
}
606603
}
607604

608-
// Create a single LazerExecute instruction with all directives if we have any
609-
if (directives.length > 0) {
605+
// Create one LazerExecute instruction per directive
606+
for (let i = 0; i < directives.length; i++) {
607+
const directive = directives[i];
608+
610609
const lazerExecute = new LazerExecute(
611610
targetChainId,
612-
directives,
611+
[directive], // Single directive per instruction
613612
undefined, // minExecutionTimestamp
614613
undefined, // maxExecutionTimestamp
615614
undefined, // governanceSequenceNo

governance/xc_admin/packages/xc_admin_frontend/components/programs/PythLazer.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
import { capitalizeFirstLetter } from '../../utils/capitalizeFirstLetter'
2424
import { generateInstructions } from '@pythnetwork/xc-admin-common/lib/programs/lazer/lazer_functions'
2525
import { useMultisigContext } from '../../contexts/MultisigContext'
26+
import axios from 'axios'
2627

2728
interface PythLazerProps {
2829
proposerServerUrl: string
@@ -363,7 +364,7 @@ const ModalContent: React.FC<ModalContentProps> = ({
363364
}
364365

365366
const PythLazer = ({
366-
proposerServerUrl: _proposerServerUrl,
367+
proposerServerUrl: proposerServerUrl,
367368
}: PythLazerProps) => {
368369
const { dataIsLoading, lazerState } = usePythContext()
369370
const { cluster } = useContext(ClusterContext)
@@ -465,17 +466,20 @@ const PythLazer = ({
465466

466467
console.log('Generated instructions:', instructions)
467468

468-
// In a real implementation, this would send the proposal to the server
469-
await new Promise((resolve) => setTimeout(resolve, 2000)) // Mock delay
470-
471-
// Close the modal and show success notification
472-
setIsModalOpen(false)
473-
toast.success('Proposal sent successfully!')
469+
const response = await axios.post(proposerServerUrl + '/api/propose', {
470+
instructions,
471+
cluster,
472+
})
473+
const { proposalPubkey } = response.data
474+
toast.success(`Proposal sent! 🚀 Proposal Pubkey: ${proposalPubkey}`)
475+
setIsSendProposalButtonLoading(false)
476+
closeModal()
474477
} catch (error) {
475-
if (error instanceof Error) {
478+
if (axios.isAxiosError(error) && error.response) {
479+
toast.error(capitalizeFirstLetter(error.response.data))
480+
} else if (error instanceof Error) {
476481
toast.error(capitalizeFirstLetter(error.message))
477482
}
478-
} finally {
479483
setIsSendProposalButtonLoading(false)
480484
}
481485
}

lazer/state_sdk/js/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,7 @@
4040
"oracle"
4141
],
4242
"license": "Apache-2.0",
43-
"dependencies": {}
43+
"dependencies": {
44+
"protobufjs": "^7.5.3"
45+
}
4446
}

pnpm-lock.yaml

Lines changed: 26 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)