Skip to content

Commit

Permalink
feat: add optional program id
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Maldonado <[email protected]>
  • Loading branch information
md0x committed Dec 18, 2024
1 parent 97973eb commit d3a8991
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/svm/programConnectors.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
import { Idl, Program, Provider } from "@coral-xyz/anchor";
import {
SvmSpokeIdl,
SvmSpokeAnchor,
MessageTransmitterAnchor,
MessageTransmitterIdl,
TokenMessengerMinterAnchor,
TokenMessengerMinterIdl,
MulticallHandlerAnchor,
MulticallHandlerIdl,
SvmSpokeAnchor,
SvmSpokeIdl,
TokenMessengerMinterAnchor,
TokenMessengerMinterIdl,
} from "./assets";

export function getConnectedProgram<P extends Idl>(idl: P, provider: Provider) {
export function getConnectedProgram<P extends Idl>(idl: P, provider: Provider, programId?: string) {
if (programId) {
// An IDL must have been previously initialized
return Program.at<P>(programId, provider);
}
return new Program<P>(idl, provider);
}

export function getSpokePoolProgram(provider: Provider) {
return getConnectedProgram<SvmSpokeAnchor>(SvmSpokeIdl, provider);
export function getSpokePoolProgram(provider: Provider, programId?: string) {
return getConnectedProgram<SvmSpokeAnchor>(SvmSpokeIdl, provider, programId);
}

export function getMessageTransmitterProgram(provider: Provider) {
return getConnectedProgram<MessageTransmitterAnchor>(MessageTransmitterIdl, provider);
export function getMessageTransmitterProgram(provider: Provider, programId?: string) {
return getConnectedProgram<MessageTransmitterAnchor>(MessageTransmitterIdl, provider, programId);
}

export function getTokenMessengerMinterProgram(provider: Provider) {
return getConnectedProgram<TokenMessengerMinterAnchor>(TokenMessengerMinterIdl, provider);
export function getTokenMessengerMinterProgram(provider: Provider, programId?: string) {
return getConnectedProgram<TokenMessengerMinterAnchor>(TokenMessengerMinterIdl, provider, programId);
}

export function getMulticallHandlerProgram(provider: Provider) {
return getConnectedProgram<MulticallHandlerAnchor>(MulticallHandlerIdl, provider);
export function getMulticallHandlerProgram(provider: Provider, programId?: string) {
return getConnectedProgram<MulticallHandlerAnchor>(MulticallHandlerIdl, provider, programId);
}

0 comments on commit d3a8991

Please sign in to comment.