Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Conversation

@kunaljaydesai
Copy link
Contributor

@joncinque WIP to resolve #3263

Lmk what you think. I'm also having trouble running e2e tests, so this hasn't been validated. I'm getting an error with:
Screen Shot 2022-06-16 at 11 05 15 PM

Is there some set up I have to do?

@mergify mergify bot added the community Community contribution label Jun 17, 2022
Copy link
Contributor

@joncinque joncinque left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great start! Just some small points, and if you add a test for updating the rate, this should be good to go

export const interestBearingMintInitializeInstructionData = struct<InterestBearingMintInitializeInstructionData>([
u8('instruction'),
u8('interestBearingMintInstruction'),
publicKey('rateAuthority'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just realizing that this isn't done correctly with the transfer fee extension, since it's not actually a publicKey, but rather an OptionalNonZeroPublicKey, meaning that it's really publicKey?. We can keep this for now, but eventually we need to properly handle the optionality

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gotcha. is that type typicall added to @solana/buffer-layout-utils or are they usually defined in the token js library?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, we can probably add it to the token js library. If it eventually gets ported to the solana sdk, then we can also add it to buffer-layout-utils

Comment on lines 71 to 79
/**
* Construct an UpdateRateInterestBearingMint instruction
*
* @param mint Mint to initialize
* @param rate The updated interest rate
* @param programId SPL Token program account
*
* @return Instruction to add to a transaction
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also requires the rate authority to sign -- see the implementation at


export interface InterestBearingMintConfigState {
rateAuthority: PublicKey;
initializationTimestamp: number;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since timestamps are u64 under the hood, let's use a BigInt

rateAuthority: PublicKey;
initializationTimestamp: number;
preUpdateAverageRate: number;
lastUpdateTimestamp: number;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

lamports,
programId: TEST_PROGRAM_ID,
}),
createInitializeInterestBearingMintInstruction(mint, rateAuthority.publicKey, 10, TEST_PROGRAM_ID),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitty nit: we can make the 10 a constant for the tests

const interestBearingMintConfigState = getInterestBearingMintConfigState(mintInfo);
expect(interestBearingMintConfigState).to.not.be.null;
if (interestBearingMintConfigState !== null) {
expect(interestBearingMintConfigState.currentRate).to.eql(10);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you check all of the fields to be sure that it's properly initialized?

@kunaljaydesai kunaljaydesai force-pushed the kunal/interest-bearing-mint branch from 6273caa to 840a69f Compare June 18, 2022 18:37
@kunaljaydesai
Copy link
Contributor Author

@joncinque I have updated the PR with the feedback mentioned, lmk if things look ok! appreciate the review :)

Copy link
Contributor

@joncinque joncinque left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of tiny things, then we can merge this!

const keys = addSigners(
[
{ pubkey: mint, isSigner: false, isWritable: true },
{ pubkey: rateAuthority, isSigner: true, isWritable: false },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the multisig situation, the multisig doesn't sign, but all the signers do

Suggested change
{ pubkey: rateAuthority, isSigner: true, isWritable: false },
{ pubkey: rateAuthority, isSigner: !multiSigners.length, isWritable: false },

expect(interestBearingMintConfigState).to.not.be.null;
if (interestBearingMintConfigState !== null) {
expect(interestBearingMintConfigState.rateAuthority).to.eql(rateAuthority.publicKey);
expect(interestBearingMintConfigState.preUpdateAverageRate).to.eql(10);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitty nit:

Suggested change
expect(interestBearingMintConfigState.preUpdateAverageRate).to.eql(10);
expect(interestBearingMintConfigState.preUpdateAverageRate).to.eql(TEST_RATE);

@kunaljaydesai
Copy link
Contributor Author

sweet, done! sorry for the delay

@joncinque
Copy link
Contributor

Thanks for your contribution! Looks good

@joncinque joncinque merged commit 7caf27c into solana-labs:master Jun 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

community Community contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

token-js: Support InterestBearingMint instructions

2 participants