-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
118 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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 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
67 changes: 67 additions & 0 deletions
67
cross-chain/solana/tests/helpers/wormholeGatewayHelpers.ts
This file contains 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,67 @@ | ||
import * as anchor from "@coral-xyz/anchor"; | ||
import { Program } from "@coral-xyz/anchor"; | ||
import * as web3 from '@solana/web3.js'; | ||
import { WormholeGateway } from "../../target/types/wormhole_gateway"; | ||
|
||
export function getCustodianPDA( | ||
program: Program<WormholeGateway>, | ||
): [anchor.web3.PublicKey, number] { | ||
return web3.PublicKey.findProgramAddressSync( | ||
[ | ||
Buffer.from('custodian'), | ||
], | ||
program.programId | ||
); | ||
} | ||
|
||
export function getGatewayInfoPDA( | ||
program: Program<WormholeGateway>, | ||
targetChain | ||
): [anchor.web3.PublicKey, number] { | ||
return web3.PublicKey.findProgramAddressSync( | ||
[ | ||
Buffer.from('gateway-info'), | ||
toBytesLE(targetChain), | ||
], | ||
program.programId | ||
); | ||
} | ||
|
||
export function getWrappedTbtcTokenPDA( | ||
program: Program<WormholeGateway>, | ||
): [anchor.web3.PublicKey, number] { | ||
return web3.PublicKey.findProgramAddressSync( | ||
[ | ||
Buffer.from('wrapped-token'), | ||
], | ||
program.programId | ||
); | ||
} | ||
|
||
export function getTokenBridgeSenderPDA( | ||
program: Program<WormholeGateway>, | ||
): [anchor.web3.PublicKey, number] { | ||
return web3.PublicKey.findProgramAddressSync( | ||
[ | ||
Buffer.from('sender'), | ||
], | ||
program.programId | ||
); | ||
} | ||
|
||
export function getTokenBridgeRedeemerPDA( | ||
program: Program<WormholeGateway>, | ||
): [anchor.web3.PublicKey, number] { | ||
return web3.PublicKey.findProgramAddressSync( | ||
[ | ||
Buffer.from('redeemer'), | ||
], | ||
program.programId | ||
); | ||
} | ||
|
||
function toBytesLE(x): Buffer { | ||
const buf = Buffer.alloc(2); | ||
buf.writeUint16LE(x); | ||
return buf; | ||
} |