-
Notifications
You must be signed in to change notification settings - Fork 346
feat(xc_admin_common): add MigrateGovernanceAndWormhole governance codec #3938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
keyvankhademi
wants to merge
3
commits into
main
Choose a base branch
from
feat/xc-admin-set-wormhole-and-datasources
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
c42b027
feat(xc_admin_common): add SetWormholeAddressAndDataSources governanc…
keyvankhademi 3106bb0
refactor(xc_admin_common): drop fee from SetWormholeAddressAndDataSou…
keyvankhademi 8c0d386
refactor(xc_admin_common): rename action 10 codec to MigrateGovernanc…
keyvankhademi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
...admin/packages/xc_admin_common/src/governance_payload/SetWormholeAddressAndDataSources.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| import * as BufferLayout from "@solana/buffer-layout"; | ||
| import type { ChainName } from "../chains"; | ||
| import { safeBufferConcat } from "../utils/buffer"; | ||
| import * as BufferLayoutExt from "./BufferLayoutExt"; | ||
| import type { ActionName, PythGovernanceAction } from "./PythGovernanceAction"; | ||
| import { PythGovernanceHeader } from "./PythGovernanceAction"; | ||
| import type { DataSource } from "./SetDataSources"; | ||
|
|
||
| const DataSourceLayout: BufferLayout.Structure<DataSource> = | ||
| BufferLayout.struct([ | ||
| BufferLayout.u16be("emitterChain"), | ||
| BufferLayoutExt.hexBytes(32, "emitterAddress"), | ||
| ]); | ||
|
|
||
| const FeeLayout: BufferLayout.Structure< | ||
| Readonly<{ newFeeValue: bigint; newFeeExpo: bigint }> | ||
| > = BufferLayout.struct([ | ||
| BufferLayoutExt.u64be("newFeeValue"), | ||
| BufferLayoutExt.u64be("newFeeExpo"), | ||
| ]); | ||
|
|
||
| /** | ||
| * Set the wormhole address, data sources, and fee on the target chain. | ||
| * | ||
| * Wire format after the governance header: | ||
| * newWormholeAddress(20) | numSources(u8) | dataSources* | newFeeValue(u64be) | newFeeExpo(u64be) | ||
| */ | ||
| export class SetWormholeAddressAndDataSources implements PythGovernanceAction { | ||
| readonly actionName: ActionName; | ||
|
|
||
| constructor( | ||
| readonly targetChainId: ChainName, | ||
| readonly address: string, | ||
| readonly dataSources: DataSource[], | ||
| readonly newFeeValue: bigint, | ||
| readonly newFeeExpo: bigint, | ||
| ) { | ||
| this.actionName = "SetWormholeAddressAndDataSources"; | ||
| } | ||
|
|
||
| static decode(data: Buffer): SetWormholeAddressAndDataSources | undefined { | ||
| const header = PythGovernanceHeader.decode(data); | ||
| if (!header || header.action !== "SetWormholeAddressAndDataSources") { | ||
| return undefined; | ||
| } | ||
|
|
||
| let index = PythGovernanceHeader.span; | ||
| const address = BufferLayoutExt.hexBytes(20).decode(data, index); | ||
| index += 20; | ||
|
|
||
| const numSources = BufferLayout.u8().decode(data, index); | ||
| index += 1; | ||
| const dataSources = []; | ||
| for (let i = 0; i < numSources; i++) { | ||
| dataSources.push(DataSourceLayout.decode(data, index)); | ||
| index += DataSourceLayout.span; | ||
| } | ||
|
|
||
| const fee = FeeLayout.decode(data, index); | ||
|
|
||
| return new SetWormholeAddressAndDataSources( | ||
| header.targetChainId, | ||
| address, | ||
| dataSources, | ||
| fee.newFeeValue, | ||
| fee.newFeeExpo, | ||
| ); | ||
| } | ||
|
|
||
| encode(): Buffer { | ||
| const headerBuffer = new PythGovernanceHeader( | ||
| this.targetChainId, | ||
| "SetWormholeAddressAndDataSources", | ||
| ).encode(); | ||
|
|
||
| const addressBuf = Buffer.alloc(20); | ||
| BufferLayoutExt.hexBytes(20).encode(this.address, addressBuf); | ||
|
|
||
| const numSourcesBuf = Buffer.alloc(1); | ||
| BufferLayout.u8().encode(this.dataSources.length, numSourcesBuf); | ||
|
|
||
| const dataSourceBufs = this.dataSources.map((source) => { | ||
| const buf = Buffer.alloc(DataSourceLayout.span); | ||
| DataSourceLayout.encode(source, buf); | ||
| return buf; | ||
| }); | ||
|
|
||
| const feeBuf = Buffer.alloc(FeeLayout.span); | ||
| FeeLayout.encode( | ||
| { | ||
| newFeeExpo: this.newFeeExpo, | ||
| newFeeValue: this.newFeeValue, | ||
| }, | ||
| feeBuf, | ||
| ); | ||
|
|
||
| return safeBufferConcat([ | ||
| headerBuffer, | ||
| addressBuf, | ||
| numSourcesBuf, | ||
| ...dataSourceBufs, | ||
| feeBuf, | ||
| ]); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔍 Wire ordering (data-source chain/address, fee value/expo) not verifiable against sibling EVM handler
The wire format encodes each data source as
emitterChain(u16be)thenemitterAddress(32)and the fee trailer asnewFeeValue(u64be)thennewFeeExpo(u64be), matching the localSetDataSources/SetFeeconventions. However the PR description states the format must match the Solidity parser in a sibling EVM PR, which is not present in this repo, so byte-for-byte compatibility with the on-chain handler could not be confirmed here. Worth confirming against the EVM handler PR before relying on cross-chain interop.Was this helpful? React with 👍 or 👎 to provide feedback.