UNPKG

@ghostspeak/sdk

Version:

TypeScript SDK for GhostSpeak AI Agent Commerce Protocol - Production Ready Beta

231 lines (229 loc) 7.88 kB
import { GHOSTSPEAK_MARKETPLACE_PROGRAM_ADDRESS, expectAddress, expectSome, getAccountMetaFactory } from './chunk-AWMGX3OX.js'; import { fixEncoderSize, getBytesEncoder, transformEncoder, getStructEncoder, getI64Encoder, addEncoderSizePrefix, getOptionEncoder, getUtf8Encoder, getU32Encoder, getStructDecoder, fixDecoderSize, getI64Decoder, addDecoderSizePrefix, getOptionDecoder, getBytesDecoder, getUtf8Decoder, getU32Decoder, combineCodec, getProgramDerivedAddress, getAddressEncoder } from '@solana/kit'; var UPDATE_REPUTATION_WITH_AUTH_DISCRIMINATOR = new Uint8Array([ 61, 236, 225, 167, 134, 43, 53, 93 ]); function getUpdateReputationWithAuthDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( UPDATE_REPUTATION_WITH_AUTH_DISCRIMINATOR ); } function getUpdateReputationWithAuthInstructionDataEncoder() { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], ["reputationChange", getI64Encoder()], [ "transactionSignature", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder()) ], [ "metadata", getOptionEncoder( addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder()) ) ], [ "nonce", getOptionEncoder( addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder()) ) ] ]), (value) => ({ ...value, discriminator: UPDATE_REPUTATION_WITH_AUTH_DISCRIMINATOR }) ); } function getUpdateReputationWithAuthInstructionDataDecoder() { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["reputationChange", getI64Decoder()], [ "transactionSignature", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder()) ], [ "metadata", getOptionDecoder(addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())) ], [ "nonce", getOptionDecoder(addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())) ] ]); } function getUpdateReputationWithAuthInstructionDataCodec() { return combineCodec( getUpdateReputationWithAuthInstructionDataEncoder(), getUpdateReputationWithAuthInstructionDataDecoder() ); } async function getUpdateReputationWithAuthInstructionAsync(input, config) { const programAddress = config?.programAddress ?? GHOSTSPEAK_MARKETPLACE_PROGRAM_ADDRESS; const originalAccounts = { agent: { value: input.agent ?? null, isWritable: false }, reputationMetrics: { value: input.reputationMetrics ?? null, isWritable: true }, authorization: { value: input.authorization ?? null, isWritable: true }, usageRecord: { value: input.usageRecord ?? null, isWritable: true }, authorizedSource: { value: input.authorizedSource ?? null, isWritable: true }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, clock: { value: input.clock ?? null, isWritable: false } }; const accounts = originalAccounts; const args = { ...input }; if (!accounts.reputationMetrics.value) { accounts.reputationMetrics.value = await getProgramDerivedAddress({ programAddress, seeds: [ getBytesEncoder().encode( new Uint8Array([ 114, 101, 112, 117, 116, 97, 116, 105, 111, 110, 95, 109, 101, 116, 114, 105, 99, 115 ]) ), getAddressEncoder().encode(expectAddress(accounts.agent.value)) ] }); } if (!accounts.authorization.value) { accounts.authorization.value = await getProgramDerivedAddress({ programAddress, seeds: [ getBytesEncoder().encode( new Uint8Array([97, 103, 101, 110, 116, 95, 97, 117, 116, 104]) ), getAddressEncoder().encode(expectAddress(accounts.agent.value)), getAddressEncoder().encode( expectAddress(accounts.authorizedSource.value) ), getOptionEncoder( addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder()) ).encode(expectSome(args.nonce)) ] }); } if (!accounts.systemProgram.value) { accounts.systemProgram.value = "11111111111111111111111111111111"; } if (!accounts.clock.value) { accounts.clock.value = "SysvarC1ock11111111111111111111111111111111"; } const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta(accounts.agent), getAccountMeta(accounts.reputationMetrics), getAccountMeta(accounts.authorization), getAccountMeta(accounts.usageRecord), getAccountMeta(accounts.authorizedSource), getAccountMeta(accounts.systemProgram), getAccountMeta(accounts.clock) ], data: getUpdateReputationWithAuthInstructionDataEncoder().encode( args ), programAddress }); } function getUpdateReputationWithAuthInstruction(input, config) { const programAddress = config?.programAddress ?? GHOSTSPEAK_MARKETPLACE_PROGRAM_ADDRESS; const originalAccounts = { agent: { value: input.agent ?? null, isWritable: false }, reputationMetrics: { value: input.reputationMetrics ?? null, isWritable: true }, authorization: { value: input.authorization ?? null, isWritable: true }, usageRecord: { value: input.usageRecord ?? null, isWritable: true }, authorizedSource: { value: input.authorizedSource ?? null, isWritable: true }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, clock: { value: input.clock ?? null, isWritable: false } }; const accounts = originalAccounts; const args = { ...input }; if (!accounts.systemProgram.value) { accounts.systemProgram.value = "11111111111111111111111111111111"; } if (!accounts.clock.value) { accounts.clock.value = "SysvarC1ock11111111111111111111111111111111"; } const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta(accounts.agent), getAccountMeta(accounts.reputationMetrics), getAccountMeta(accounts.authorization), getAccountMeta(accounts.usageRecord), getAccountMeta(accounts.authorizedSource), getAccountMeta(accounts.systemProgram), getAccountMeta(accounts.clock) ], data: getUpdateReputationWithAuthInstructionDataEncoder().encode( args ), programAddress }); } function parseUpdateReputationWithAuthInstruction(instruction) { if (instruction.accounts.length < 7) { 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: { agent: getNextAccount(), reputationMetrics: getNextAccount(), authorization: getNextAccount(), usageRecord: getNextAccount(), authorizedSource: getNextAccount(), systemProgram: getNextAccount(), clock: getNextAccount() }, data: getUpdateReputationWithAuthInstructionDataDecoder().decode( instruction.data ) }; } export { UPDATE_REPUTATION_WITH_AUTH_DISCRIMINATOR, getUpdateReputationWithAuthDiscriminatorBytes, getUpdateReputationWithAuthInstruction, getUpdateReputationWithAuthInstructionAsync, getUpdateReputationWithAuthInstructionDataCodec, getUpdateReputationWithAuthInstructionDataDecoder, getUpdateReputationWithAuthInstructionDataEncoder, parseUpdateReputationWithAuthInstruction }; //# sourceMappingURL=chunk-QLRWUHN2.js.map //# sourceMappingURL=chunk-QLRWUHN2.js.map