From ead46731dd22e165d72672ba8d3b71aff596a1bb Mon Sep 17 00:00:00 2001 From: 0xCipherCoder Date: Thu, 14 Nov 2024 07:25:54 +0530 Subject: [PATCH] Added interest bearing mint extension --- .../js/src/generated/instructions/index.ts | 2 + .../initializeInterestBearingMint.ts | 212 ++++++++++++++++ .../instructions/updateInterestBearingRate.ts | 234 ++++++++++++++++++ .../js/src/generated/programs/token2022.ts | 22 ++ .../getInitializeInstructionsForExtensions.ts | 9 + .../initializeInterestBearingMint.test.ts | 77 ++++++ .../updateInterestBearingRate.test.ts | 69 ++++++ program/idl.json | 182 ++++++++++++++ 8 files changed, 807 insertions(+) create mode 100644 clients/js/src/generated/instructions/initializeInterestBearingMint.ts create mode 100644 clients/js/src/generated/instructions/updateInterestBearingRate.ts create mode 100644 clients/js/test/extensions/interestBearingMint/initializeInterestBearingMint.test.ts create mode 100644 clients/js/test/extensions/interestBearingMint/updateInterestBearingRate.test.ts diff --git a/clients/js/src/generated/instructions/index.ts b/clients/js/src/generated/instructions/index.ts index ccbf600..5284794 100644 --- a/clients/js/src/generated/instructions/index.ts +++ b/clients/js/src/generated/instructions/index.ts @@ -42,6 +42,7 @@ export * from './initializeDefaultAccountState'; export * from './initializeGroupMemberPointer'; export * from './initializeGroupPointer'; export * from './initializeImmutableOwner'; +export * from './initializeInterestBearingMint'; export * from './initializeMetadataPointer'; export * from './initializeMint'; export * from './initializeMint2'; @@ -73,6 +74,7 @@ export * from './updateConfidentialTransferMint'; export * from './updateDefaultAccountState'; export * from './updateGroupMemberPointer'; export * from './updateGroupPointer'; +export * from './updateInterestBearingRate'; export * from './updateMetadataPointer'; export * from './updateTokenGroupMaxSize'; export * from './updateTokenGroupUpdateAuthority'; diff --git a/clients/js/src/generated/instructions/initializeInterestBearingMint.ts b/clients/js/src/generated/instructions/initializeInterestBearingMint.ts new file mode 100644 index 0000000..1e3fa9d --- /dev/null +++ b/clients/js/src/generated/instructions/initializeInterestBearingMint.ts @@ -0,0 +1,212 @@ +/** + * 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 { + combineCodec, + getAddressDecoder, + getAddressEncoder, + getI16Decoder, + getI16Encoder, + getOptionDecoder, + getOptionEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type Address, + type Codec, + type Decoder, + type Encoder, + type IAccountMeta, + type IInstruction, + type IInstructionWithAccounts, + type IInstructionWithData, + type Option, + type OptionOrNullable, + type WritableAccount, +} from '@solana/web3.js'; +import { TOKEN_2022_PROGRAM_ADDRESS } from '../programs'; +import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; + +export const INITIALIZE_INTEREST_BEARING_MINT_DISCRIMINATOR = 33; + +export function getInitializeInterestBearingMintDiscriminatorBytes() { + return getU8Encoder().encode(INITIALIZE_INTEREST_BEARING_MINT_DISCRIMINATOR); +} + +export const INITIALIZE_INTEREST_BEARING_MINT_INTEREST_BEARING_DISCRIMINATOR = 0; + +export function getInitializeInterestBearingMintInterestBearingDiscriminatorBytes() { + return getU8Encoder().encode( + INITIALIZE_INTEREST_BEARING_MINT_INTEREST_BEARING_DISCRIMINATOR + ); +} + +export type InitializeInterestBearingMintInstruction< + TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountMint extends string | IAccountMeta = string, + TRemainingAccounts extends readonly IAccountMeta[] = [], +> = IInstruction & + IInstructionWithData & + IInstructionWithAccounts< + [ + TAccountMint extends string + ? WritableAccount + : TAccountMint, + ...TRemainingAccounts, + ] + >; + +export type InitializeInterestBearingMintInstructionData = { + discriminator: number; + interestBearingDiscriminator: number; + /** The public key for the account that can update the rate */ + rateAuthority: Option
; + /** The initial interest rate in basis points */ + rate: number; +}; + +export type InitializeInterestBearingMintInstructionDataArgs = { + /** The public key for the account that can update the rate */ + rateAuthority: OptionOrNullable
; + /** The initial interest rate in basis points */ + rate: number; +}; + +export function getInitializeInterestBearingMintInstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ['discriminator', getU8Encoder()], + ['interestBearingDiscriminator', getU8Encoder()], + [ + 'rateAuthority', + getOptionEncoder(getAddressEncoder(), { + prefix: null, + noneValue: 'zeroes', + }), + ], + ['rate', getI16Encoder()], + ]), + (value) => ({ + ...value, + discriminator: INITIALIZE_INTEREST_BEARING_MINT_DISCRIMINATOR, + interestBearingDiscriminator: + INITIALIZE_INTEREST_BEARING_MINT_INTEREST_BEARING_DISCRIMINATOR, + }) + ); +} + +export function getInitializeInterestBearingMintInstructionDataDecoder(): Decoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['interestBearingDiscriminator', getU8Decoder()], + [ + 'rateAuthority', + getOptionDecoder(getAddressDecoder(), { + prefix: null, + noneValue: 'zeroes', + }), + ], + ['rate', getI16Decoder()], + ]); +} + +export function getInitializeInterestBearingMintInstructionDataCodec(): Codec< + InitializeInterestBearingMintInstructionDataArgs, + InitializeInterestBearingMintInstructionData +> { + return combineCodec( + getInitializeInterestBearingMintInstructionDataEncoder(), + getInitializeInterestBearingMintInstructionDataDecoder() + ); +} + +export type InitializeInterestBearingMintInput< + TAccountMint extends string = string, +> = { + /** The mint to initialize. */ + mint: Address; + rateAuthority: InitializeInterestBearingMintInstructionDataArgs['rateAuthority']; + rate: InitializeInterestBearingMintInstructionDataArgs['rate']; +}; + +export function getInitializeInterestBearingMintInstruction< + TAccountMint extends string, + TProgramAddress extends Address = typeof TOKEN_2022_PROGRAM_ADDRESS, +>( + input: InitializeInterestBearingMintInput, + config?: { programAddress?: TProgramAddress } +): InitializeInterestBearingMintInstruction { + // Program address. + const programAddress = config?.programAddress ?? TOKEN_2022_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + mint: { value: input.mint ?? null, isWritable: true }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [getAccountMeta(accounts.mint)], + programAddress, + data: getInitializeInterestBearingMintInstructionDataEncoder().encode( + args as InitializeInterestBearingMintInstructionDataArgs + ), + } as InitializeInterestBearingMintInstruction; + + return instruction; +} + +export type ParsedInitializeInterestBearingMintInstruction< + TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], +> = { + programAddress: Address; + accounts: { + /** The mint to initialize. */ + mint: TAccountMetas[0]; + }; + data: InitializeInterestBearingMintInstructionData; +}; + +export function parseInitializeInterestBearingMintInstruction< + TProgram extends string, + TAccountMetas extends readonly IAccountMeta[], +>( + instruction: IInstruction & + IInstructionWithAccounts & + IInstructionWithData +): ParsedInitializeInterestBearingMintInstruction { + if (instruction.accounts.length < 1) { + // 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: { + mint: getNextAccount(), + }, + data: getInitializeInterestBearingMintInstructionDataDecoder().decode( + instruction.data + ), + }; +} diff --git a/clients/js/src/generated/instructions/updateInterestBearingRate.ts b/clients/js/src/generated/instructions/updateInterestBearingRate.ts new file mode 100644 index 0000000..dff7a5c --- /dev/null +++ b/clients/js/src/generated/instructions/updateInterestBearingRate.ts @@ -0,0 +1,234 @@ +/** + * 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 { + AccountRole, + combineCodec, + getI16Decoder, + getI16Encoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type Address, + type Codec, + type Decoder, + type Encoder, + type IAccountMeta, + type IAccountSignerMeta, + type IInstruction, + type IInstructionWithAccounts, + type IInstructionWithData, + type ReadonlyAccount, + type ReadonlySignerAccount, + type TransactionSigner, + type WritableAccount, +} from '@solana/web3.js'; +import { TOKEN_2022_PROGRAM_ADDRESS } from '../programs'; +import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; + +export const UPDATE_INTEREST_BEARING_RATE_DISCRIMINATOR = 33; + +export function getUpdateInterestBearingRateDiscriminatorBytes() { + return getU8Encoder().encode(UPDATE_INTEREST_BEARING_RATE_DISCRIMINATOR); +} + +export const UPDATE_INTEREST_BEARING_RATE_INTEREST_BEARING_DISCRIMINATOR = 1; + +export function getUpdateInterestBearingRateInterestBearingDiscriminatorBytes() { + return getU8Encoder().encode( + UPDATE_INTEREST_BEARING_RATE_INTEREST_BEARING_DISCRIMINATOR + ); +} + +export type UpdateInterestBearingRateInstruction< + TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountMint extends string | IAccountMeta = string, + TAccountRateAuthority extends string | IAccountMeta = string, + TRemainingAccounts extends readonly IAccountMeta[] = [], +> = IInstruction & + IInstructionWithData & + IInstructionWithAccounts< + [ + TAccountMint extends string + ? WritableAccount + : TAccountMint, + TAccountRateAuthority extends string + ? ReadonlyAccount + : TAccountRateAuthority, + ...TRemainingAccounts, + ] + >; + +export type UpdateInterestBearingRateInstructionData = { + discriminator: number; + interestBearingDiscriminator: number; + /** The new interest rate in basis points */ + rate: number; +}; + +export type UpdateInterestBearingRateInstructionDataArgs = { + /** The new interest rate in basis points */ + rate: number; +}; + +export function getUpdateInterestBearingRateInstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ['discriminator', getU8Encoder()], + ['interestBearingDiscriminator', getU8Encoder()], + ['rate', getI16Encoder()], + ]), + (value) => ({ + ...value, + discriminator: UPDATE_INTEREST_BEARING_RATE_DISCRIMINATOR, + interestBearingDiscriminator: + UPDATE_INTEREST_BEARING_RATE_INTEREST_BEARING_DISCRIMINATOR, + }) + ); +} + +export function getUpdateInterestBearingRateInstructionDataDecoder(): Decoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['interestBearingDiscriminator', getU8Decoder()], + ['rate', getI16Decoder()], + ]); +} + +export function getUpdateInterestBearingRateInstructionDataCodec(): Codec< + UpdateInterestBearingRateInstructionDataArgs, + UpdateInterestBearingRateInstructionData +> { + return combineCodec( + getUpdateInterestBearingRateInstructionDataEncoder(), + getUpdateInterestBearingRateInstructionDataDecoder() + ); +} + +export type UpdateInterestBearingRateInput< + TAccountMint extends string = string, + TAccountRateAuthority extends string = string, +> = { + /** The mint. */ + mint: Address; + /** The mint rate authority. */ + rateAuthority: + | Address + | TransactionSigner; + rate: UpdateInterestBearingRateInstructionDataArgs['rate']; + multiSigners?: Array; +}; + +export function getUpdateInterestBearingRateInstruction< + TAccountMint extends string, + TAccountRateAuthority extends string, + TProgramAddress extends Address = typeof TOKEN_2022_PROGRAM_ADDRESS, +>( + input: UpdateInterestBearingRateInput, + config?: { programAddress?: TProgramAddress } +): UpdateInterestBearingRateInstruction< + TProgramAddress, + TAccountMint, + (typeof input)['rateAuthority'] extends TransactionSigner + ? ReadonlySignerAccount & + IAccountSignerMeta + : TAccountRateAuthority +> { + // Program address. + const programAddress = config?.programAddress ?? TOKEN_2022_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + mint: { value: input.mint ?? null, isWritable: true }, + rateAuthority: { value: input.rateAuthority ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Remaining accounts. + const remainingAccounts: IAccountMeta[] = (args.multiSigners ?? []).map( + (signer) => ({ + address: signer.address, + role: AccountRole.READONLY_SIGNER, + signer, + }) + ); + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [ + getAccountMeta(accounts.mint), + getAccountMeta(accounts.rateAuthority), + ...remainingAccounts, + ], + programAddress, + data: getUpdateInterestBearingRateInstructionDataEncoder().encode( + args as UpdateInterestBearingRateInstructionDataArgs + ), + } as UpdateInterestBearingRateInstruction< + TProgramAddress, + TAccountMint, + (typeof input)['rateAuthority'] extends TransactionSigner + ? ReadonlySignerAccount & + IAccountSignerMeta + : TAccountRateAuthority + >; + + return instruction; +} + +export type ParsedUpdateInterestBearingRateInstruction< + TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], +> = { + programAddress: Address; + accounts: { + /** The mint. */ + mint: TAccountMetas[0]; + /** The mint rate authority. */ + rateAuthority: TAccountMetas[1]; + }; + data: UpdateInterestBearingRateInstructionData; +}; + +export function parseUpdateInterestBearingRateInstruction< + TProgram extends string, + TAccountMetas extends readonly IAccountMeta[], +>( + instruction: IInstruction & + IInstructionWithAccounts & + IInstructionWithData +): ParsedUpdateInterestBearingRateInstruction { + if (instruction.accounts.length < 2) { + // 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: { + mint: getNextAccount(), + rateAuthority: getNextAccount(), + }, + data: getUpdateInterestBearingRateInstructionDataDecoder().decode( + instruction.data + ), + }; +} diff --git a/clients/js/src/generated/programs/token2022.ts b/clients/js/src/generated/programs/token2022.ts index 093b4b3..e76befb 100644 --- a/clients/js/src/generated/programs/token2022.ts +++ b/clients/js/src/generated/programs/token2022.ts @@ -47,6 +47,7 @@ import { type ParsedInitializeGroupMemberPointerInstruction, type ParsedInitializeGroupPointerInstruction, type ParsedInitializeImmutableOwnerInstruction, + type ParsedInitializeInterestBearingMintInstruction, type ParsedInitializeMetadataPointerInstruction, type ParsedInitializeMint2Instruction, type ParsedInitializeMintCloseAuthorityInstruction, @@ -77,6 +78,7 @@ import { type ParsedUpdateDefaultAccountStateInstruction, type ParsedUpdateGroupMemberPointerInstruction, type ParsedUpdateGroupPointerInstruction, + type ParsedUpdateInterestBearingRateInstruction, type ParsedUpdateMetadataPointerInstruction, type ParsedUpdateTokenGroupMaxSizeInstruction, type ParsedUpdateTokenGroupUpdateAuthorityInstruction, @@ -167,6 +169,8 @@ export enum Token2022Instruction { EnableMemoTransfers, DisableMemoTransfers, InitializeNonTransferableMint, + InitializeInterestBearingMint, + UpdateInterestBearingRate, EnableCpiGuard, DisableCpiGuard, InitializePermanentDelegate, @@ -421,6 +425,18 @@ export function identifyToken2022Instruction( if (containsBytes(data, getU8Encoder().encode(32), 0)) { return Token2022Instruction.InitializeNonTransferableMint; } + if ( + containsBytes(data, getU8Encoder().encode(33), 0) && + containsBytes(data, getU8Encoder().encode(0), 1) + ) { + return Token2022Instruction.InitializeInterestBearingMint; + } + if ( + containsBytes(data, getU8Encoder().encode(33), 0) && + containsBytes(data, getU8Encoder().encode(1), 1) + ) { + return Token2022Instruction.UpdateInterestBearingRate; + } if ( containsBytes(data, getU8Encoder().encode(34), 0) && containsBytes(data, getU8Encoder().encode(0), 1) @@ -721,6 +737,12 @@ export type ParsedToken2022Instruction< | ({ instructionType: Token2022Instruction.InitializeNonTransferableMint; } & ParsedInitializeNonTransferableMintInstruction) + | ({ + instructionType: Token2022Instruction.InitializeInterestBearingMint; + } & ParsedInitializeInterestBearingMintInstruction) + | ({ + instructionType: Token2022Instruction.UpdateInterestBearingRate; + } & ParsedUpdateInterestBearingRateInstruction) | ({ instructionType: Token2022Instruction.EnableCpiGuard; } & ParsedEnableCpiGuardInstruction) diff --git a/clients/js/src/getInitializeInstructionsForExtensions.ts b/clients/js/src/getInitializeInstructionsForExtensions.ts index 4791e4a..69ed645 100644 --- a/clients/js/src/getInitializeInstructionsForExtensions.ts +++ b/clients/js/src/getInitializeInstructionsForExtensions.ts @@ -23,6 +23,7 @@ import { getInitializeNonTransferableMintInstruction, getInitializeTransferHookInstruction, getInitializePermanentDelegateInstruction, + getInitializeInterestBearingMintInstruction, } from './generated'; /** @@ -100,6 +101,14 @@ export function getPreInitializeInstructionsForMintExtensions( mint, delegate: extension.delegate, }); + case 'InterestBearingConfig': + return [ + getInitializeInterestBearingMintInstruction({ + mint, + rateAuthority: extension.rateAuthority, + rate: extension.currentRate, + }), + ]; default: return []; } diff --git a/clients/js/test/extensions/interestBearingMint/initializeInterestBearingMint.test.ts b/clients/js/test/extensions/interestBearingMint/initializeInterestBearingMint.test.ts new file mode 100644 index 0000000..090b571 --- /dev/null +++ b/clients/js/test/extensions/interestBearingMint/initializeInterestBearingMint.test.ts @@ -0,0 +1,77 @@ +import { generateKeyPairSigner, some } from '@solana/web3.js'; +import test from 'ava'; +import { + extension, + fetchMint, + getInitializeInterestBearingMintInstruction, +} from '../../../src'; +import { + createDefaultSolanaClient, + generateKeyPairSignerWithSol, + getCreateMintInstructions, + sendAndConfirmInstructions, +} from '../../_setup'; + +test('it initializes a mint with interest bearing configuration', async (t) => { + // Given some signer accounts + const client = createDefaultSolanaClient(); + const [authority, mint] = await Promise.all([ + generateKeyPairSignerWithSol(client), + generateKeyPairSigner(), + ]); + + // And an interest bearing extension + const interestBearingExtension = extension('InterestBearingConfig', { + rateAuthority: authority.address, + initializationTimestamp: 0n, + preUpdateAverageRate: 500, + lastUpdateTimestamp: 0n, + currentRate: 500, + }); + + // When we create and initialize a mint account with this extension + const [createMintInstruction, initMintInstruction] = + await getCreateMintInstructions({ + authority: authority.address, + client, + extensions: [interestBearingExtension], + mint, + payer: authority, + }); + + await sendAndConfirmInstructions(client, authority, [ + createMintInstruction, + getInitializeInterestBearingMintInstruction({ + mint: mint.address, + rateAuthority: some(authority.address), + rate: 500, + }), + initMintInstruction, + ]); + + // Then we expect the mint account to exist with interest bearing configuration + const mintAccount = await fetchMint(client.rpc, mint.address); + + // Verify account basics + t.deepEqual(mintAccount.address, mint.address); + t.deepEqual(mintAccount.data.mintAuthority, some(authority.address)); + t.true(mintAccount.data.isInitialized); + + // Get extension from the option value + const extensions = + mintAccount.data.extensions.__option === 'Some' + ? mintAccount.data.extensions.value + : []; + + // Verify extension exists + t.is(extensions.length, 1); + const extensionData = extensions[0]; + t.is(extensionData.__kind, 'InterestBearingConfig'); + t.deepEqual(extensionData.rateAuthority, authority.address); + t.is(extensionData.currentRate, 500); + t.is(extensionData.preUpdateAverageRate, 500); + + // Verify timestamps exist but don't check specific values + t.true(typeof extensionData.initializationTimestamp === 'bigint'); + t.true(typeof extensionData.lastUpdateTimestamp === 'bigint'); +}); diff --git a/clients/js/test/extensions/interestBearingMint/updateInterestBearingRate.test.ts b/clients/js/test/extensions/interestBearingMint/updateInterestBearingRate.test.ts new file mode 100644 index 0000000..e56fd8b --- /dev/null +++ b/clients/js/test/extensions/interestBearingMint/updateInterestBearingRate.test.ts @@ -0,0 +1,69 @@ +import { some } from '@solana/web3.js'; +import test from 'ava'; +import { + Extension, + extension, + fetchMint, + getUpdateInterestBearingRateInstruction, +} from '../../../src'; +import { + createDefaultSolanaClient, + generateKeyPairSignerWithSol, + createMint, + sendAndConfirmInstructions, +} from '../../_setup'; + +test('it updates interest rate on a mint', async (t) => { + // Given a mint with interest bearing configuration + const client = createDefaultSolanaClient(); + const authority = await generateKeyPairSignerWithSol(client); + + // Initialize mint with interest bearing extension + const interestBearingExtension = extension('InterestBearingConfig', { + rateAuthority: authority.address, + initializationTimestamp: 0n, + preUpdateAverageRate: 500, + lastUpdateTimestamp: 0n, + currentRate: 500, + }); + + const mint = await createMint({ + authority, + client, + extensions: [interestBearingExtension], + payer: authority, + }); + + // When we update the interest rate + await sendAndConfirmInstructions(client, authority, [ + getUpdateInterestBearingRateInstruction({ + mint: mint, + rateAuthority: authority, + rate: 1000, // New rate of 10% + }), + ]); + + // Then we expect the mint account to have the updated rate + const mintAccount = await fetchMint(client.rpc, mint); + + // Verify base account state + t.deepEqual(mintAccount.address, mint); + t.deepEqual(mintAccount.data.mintAuthority, some(authority.address)); + t.true(mintAccount.data.isInitialized); + + // Get typed extension + const extensions = + mintAccount.data.extensions.__option === 'Some' + ? (mintAccount.data.extensions.value as Extension[]) + : []; + + t.is(extensions.length, 1); + const extensionData = extensions[0]; + t.is(extensionData.__kind, 'InterestBearingConfig'); + + // Verify updated rate configuration + if (extensionData.__kind === 'InterestBearingConfig') { + t.deepEqual(extensionData.rateAuthority, authority.address); + t.is(extensionData.currentRate, 1000); + } +}); diff --git a/program/idl.json b/program/idl.json index 18c000b..1184c67 100644 --- a/program/idl.json +++ b/program/idl.json @@ -5389,6 +5389,188 @@ } ] }, + { + "kind": "instructionNode", + "name": "initializeInterestBearingMint", + "docs": [ + "Initialize a new mint with interest accrual.", + "", + "Fails if the mint has already been initialized, so must be called before `InitializeMint`.", + "", + "The mint must have exactly enough space allocated for the base mint (82 bytes),", + "plus 83 bytes of padding, 1 byte reserved for the account type,", + "then space required for this extension, plus any others." + ], + "optionalAccountStrategy": "programId", + "accounts": [ + { + "kind": "instructionAccountNode", + "name": "mint", + "isWritable": true, + "isSigner": false, + "isOptional": false, + "docs": ["The mint to initialize."] + } + ], + "arguments": [ + { + "kind": "instructionArgumentNode", + "name": "discriminator", + "defaultValueStrategy": "omitted", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + }, + "defaultValue": { + "kind": "numberValueNode", + "number": 33 + } + }, + { + "kind": "instructionArgumentNode", + "name": "interestBearingDiscriminator", + "defaultValueStrategy": "omitted", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + }, + "defaultValue": { + "kind": "numberValueNode", + "number": 0 + } + }, + { + "kind": "instructionArgumentNode", + "name": "rateAuthority", + "docs": ["The public key for the account that can update the rate"], + "type": { + "kind": "zeroableOptionTypeNode", + "item": { + "kind": "publicKeyTypeNode" + } + } + }, + { + "kind": "instructionArgumentNode", + "name": "rate", + "docs": ["The initial interest rate in basis points"], + "type": { + "kind": "numberTypeNode", + "format": "i16", + "endian": "le" + } + } + ], + "discriminators": [ + { + "kind": "fieldDiscriminatorNode", + "name": "discriminator", + "offset": 0 + }, + { + "kind": "fieldDiscriminatorNode", + "name": "interestBearingDiscriminator", + "offset": 1 + } + ] + }, + { + "kind": "instructionNode", + "name": "updateInterestBearingRate", + "docs": [ + "Update the interest rate. Only supported for mints that include the", + "`InterestBearingConfig` extension." + ], + "optionalAccountStrategy": "programId", + "accounts": [ + { + "kind": "instructionAccountNode", + "name": "mint", + "isWritable": true, + "isSigner": false, + "isOptional": false, + "docs": ["The mint."] + }, + { + "kind": "instructionAccountNode", + "name": "rateAuthority", + "isWritable": false, + "isSigner": "either", + "isOptional": false, + "docs": ["The mint rate authority."] + } + ], + "arguments": [ + { + "kind": "instructionArgumentNode", + "name": "discriminator", + "defaultValueStrategy": "omitted", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + }, + "defaultValue": { + "kind": "numberValueNode", + "number": 33 + } + }, + { + "kind": "instructionArgumentNode", + "name": "interestBearingDiscriminator", + "defaultValueStrategy": "omitted", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + }, + "defaultValue": { + "kind": "numberValueNode", + "number": 1 + } + }, + { + "kind": "instructionArgumentNode", + "name": "rate", + "docs": ["The new interest rate in basis points"], + "type": { + "kind": "numberTypeNode", + "format": "i16", + "endian": "le" + } + } + ], + "remainingAccounts": [ + { + "kind": "instructionRemainingAccountsNode", + "isOptional": true, + "isSigner": true, + "docs": [], + "value": { + "kind": "argumentValueNode", + "name": "multiSigners" + } + } + ], + "discriminators": [ + { + "kind": "fieldDiscriminatorNode", + "name": "discriminator", + "offset": 0 + }, + { + "kind": "fieldDiscriminatorNode", + "name": "interestBearingDiscriminator", + "offset": 1 + } + ] + }, { "kind": "instructionNode", "name": "enableCpiGuard",