@robertprp/intents-sdk
Version:
Shogun Network Intent-based cross-chain swaps SDK
104 lines • 4.54 kB
JavaScript
/**
* This code was AUTOGENERATED using the codama library.
* Please DO NOT EDIT THIS FILE, instead use visitors
* to add features, then rerun codama to update it.
*
* @see https://github.com/codama-idl/codama
*/
import { getAddressDecoder, getAddressEncoder, getProgramDerivedAddress } from '@solana/kit';
import { combineCodec, fixDecoderSize, fixEncoderSize, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, transformEncoder, } from '@solana/kit';
import {} from '@solana/kit';
import {} from '@solana/kit';
import { SOURCE_CHAIN_GUARD_PROGRAM_ADDRESS } from '../programs/index.js';
import { getAccountMetaFactory } from '../shared/index.js';
export const SET_AUCTIONEER_PUB_KEY_DISCRIMINATOR = new Uint8Array([153, 39, 10, 108, 220, 0, 84, 47]);
export function getSetAuctioneerPubKeyDiscriminatorBytes() {
return fixEncoderSize(getBytesEncoder(), 8).encode(SET_AUCTIONEER_PUB_KEY_DISCRIMINATOR);
}
export function getSetAuctioneerPubKeyInstructionDataEncoder() {
return transformEncoder(getStructEncoder([
['discriminator', fixEncoderSize(getBytesEncoder(), 8)],
['auctioneerPubKey', getAddressEncoder()],
]), (value) => ({
...value,
discriminator: SET_AUCTIONEER_PUB_KEY_DISCRIMINATOR,
}));
}
export function getSetAuctioneerPubKeyInstructionDataDecoder() {
return getStructDecoder([
['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
['auctioneerPubKey', getAddressDecoder()],
]);
}
export function getSetAuctioneerPubKeyInstructionDataCodec() {
return combineCodec(getSetAuctioneerPubKeyInstructionDataEncoder(), getSetAuctioneerPubKeyInstructionDataDecoder());
}
export async function getSetAuctioneerPubKeyInstructionAsync(input, config) {
// Program address.
const programAddress = config?.programAddress ?? SOURCE_CHAIN_GUARD_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
admin: { value: input.admin ?? null, isWritable: true },
adminSingleton: { value: input.adminSingleton ?? null, isWritable: false },
guard: { value: input.guard ?? null, isWritable: true },
};
const accounts = originalAccounts;
// Original args.
const args = { ...input };
// Resolve default values.
if (!accounts.adminSingleton.value) {
accounts.adminSingleton.value = await getProgramDerivedAddress({
programAddress,
seeds: [getBytesEncoder().encode(new Uint8Array([97, 100, 109, 105, 110]))],
});
}
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
const instruction = {
accounts: [getAccountMeta(accounts.admin), getAccountMeta(accounts.adminSingleton), getAccountMeta(accounts.guard)],
programAddress,
data: getSetAuctioneerPubKeyInstructionDataEncoder().encode(args),
};
return instruction;
}
export function getSetAuctioneerPubKeyInstruction(input, config) {
// Program address.
const programAddress = config?.programAddress ?? SOURCE_CHAIN_GUARD_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
admin: { value: input.admin ?? null, isWritable: true },
adminSingleton: { value: input.adminSingleton ?? null, isWritable: false },
guard: { value: input.guard ?? null, isWritable: true },
};
const accounts = originalAccounts;
// Original args.
const args = { ...input };
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
const instruction = {
accounts: [getAccountMeta(accounts.admin), getAccountMeta(accounts.adminSingleton), getAccountMeta(accounts.guard)],
programAddress,
data: getSetAuctioneerPubKeyInstructionDataEncoder().encode(args),
};
return instruction;
}
export function parseSetAuctioneerPubKeyInstruction(instruction) {
if (instruction.accounts.length < 3) {
// TODO: Coded error.
throw new Error('Not enough accounts');
}
let accountIndex = 0;
const getNextAccount = () => {
const accountMeta = instruction.accounts[accountIndex];
accountIndex += 1;
return accountMeta;
};
return {
programAddress: instruction.programAddress,
accounts: {
admin: getNextAccount(),
adminSingleton: getNextAccount(),
guard: getNextAccount(),
},
data: getSetAuctioneerPubKeyInstructionDataDecoder().decode(instruction.data),
};
}
//# sourceMappingURL=setAuctioneerPubKey.js.map