Skip to content

Commit

Permalink
refactor: type and name (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickfrosty authored Feb 17, 2025
1 parent dc635bb commit a1e342a
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 78 deletions.
5 changes: 5 additions & 0 deletions .changeset/big-mugs-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gill": patch
---

refactor common type and use `feePayer` vs `payer` for consistency
6 changes: 3 additions & 3 deletions examples/esrun/src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ console.log("latestBlockhash:", latestBlockhash);
const createTokenTx = await buildCreateTokenTransaction({
mint,
latestBlockhash,
payer: signer,
// mintAuthority, // default=same as the `payer`
feePayer: signer,
// mintAuthority, // default=same as the `feePayer`
metadata: {
isMutable: true, // if the `updateAuthority` can change this metadata in the future
name: "Only Possible On Solana",
Expand Down Expand Up @@ -115,7 +115,7 @@ const destination = address("nicktrLHhYzLmoVbuZQzHUTicd2sfP571orwo9jfc8c");
* - ensure the `mintAuthority` is the correct signer in order to actually mint new tokens
*/
const mintTokensTx = await buildMintTokensTransaction({
payer: signer,
feePayer: signer,
latestBlockhash,
mint,
mintAuthority: signer,
Expand Down
24 changes: 12 additions & 12 deletions packages/gill/src/__tests__/create-token-instructions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe("getCreateTokenInstructions", () => {

it("should create basic token instructions with default values", () => {
const args: GetCreateTokenInstructionsArgs = {
payer: mockPayer,
feePayer: mockPayer,
mint: mockMint,
metadataAddress: mockMetadataAddress,
metadata,
Expand Down Expand Up @@ -174,7 +174,7 @@ describe("getCreateTokenInstructions", () => {

it("should throw error for unsupported token program", () => {
const args: GetCreateTokenInstructionsArgs = {
payer: mockPayer,
feePayer: mockPayer,
mint: mockMint,
metadataAddress: mockMetadataAddress,
metadata,
Expand All @@ -189,7 +189,7 @@ describe("getCreateTokenInstructions", () => {
describe("should use original token program", () => {
it("should use original token program when specified", () => {
const args: GetCreateTokenInstructionsArgs = {
payer: mockPayer,
feePayer: mockPayer,
mint: mockMint,
metadataAddress: mockMetadataAddress,
tokenProgram: TOKEN_PROGRAM_ADDRESS,
Expand All @@ -214,7 +214,7 @@ describe("getCreateTokenInstructions", () => {

it("should use custom decimals when provided", () => {
const args: GetCreateTokenInstructionsArgs = {
payer: mockPayer,
feePayer: mockPayer,
metadataAddress: mockMetadataAddress,
mint: mockMint,
decimals: 6,
Expand All @@ -233,7 +233,7 @@ describe("getCreateTokenInstructions", () => {

it("should use custom mint and freeze authorities when provided", () => {
const args: GetCreateTokenInstructionsArgs = {
payer: mockPayer,
feePayer: mockPayer,
mint: mockMint,
metadataAddress: mockMetadataAddress,
metadata,
Expand All @@ -260,7 +260,7 @@ describe("getCreateTokenInstructions", () => {
};

const args: GetCreateTokenInstructionsArgs = {
payer: mockPayer,
feePayer: mockPayer,
mint: mockMint,
metadataAddress: mockMetadataAddress,
metadata,
Expand Down Expand Up @@ -297,7 +297,7 @@ describe("getCreateTokenInstructions", () => {
const customUpdateAuthority = { address: "customUpdateAuth" } as KeyPairSigner;

const args: GetCreateTokenInstructionsArgs = {
payer: mockPayer,
feePayer: mockPayer,
mint: mockMint,
metadataAddress: mockMetadataAddress,
updateAuthority: customUpdateAuthority,
Expand All @@ -317,7 +317,7 @@ describe("getCreateTokenInstructions", () => {
describe("should use token22 program", () => {
it("should use Token-2022 program when specified", () => {
const args: GetCreateTokenInstructionsArgs = {
payer: mockPayer,
feePayer: mockPayer,
mint: mockMint,
metadataAddress: mockMint.address,
tokenProgram: TOKEN_2022_PROGRAM_ADDRESS,
Expand All @@ -342,7 +342,7 @@ describe("getCreateTokenInstructions", () => {

it("should use custom decimals when provided", () => {
const args: GetCreateTokenInstructionsArgs = {
payer: mockPayer,
feePayer: mockPayer,
mint: mockMint,
metadataAddress: mockMint.address,
decimals: 6,
Expand All @@ -362,7 +362,7 @@ describe("getCreateTokenInstructions", () => {

it("should use custom mint and freeze authorities when provided", () => {
const args: GetCreateTokenInstructionsArgs = {
payer: mockPayer,
feePayer: mockPayer,
mint: mockMint,
metadataAddress: mockMint.address,
metadata,
Expand Down Expand Up @@ -390,7 +390,7 @@ describe("getCreateTokenInstructions", () => {
};

const args: GetCreateTokenInstructionsArgs = {
payer: mockPayer,
feePayer: mockPayer,
mint: mockMint,
metadataAddress: mockMint.address,
metadata,
Expand Down Expand Up @@ -435,7 +435,7 @@ describe("getCreateTokenInstructions", () => {
const customUpdateAuthority = { address: "customUpdateAuth" } as KeyPairSigner;

const args: GetCreateTokenInstructionsArgs = {
payer: mockPayer,
feePayer: mockPayer,
mint: mockMint,
metadataAddress: mockMint.address,
updateAuthority: customUpdateAuthority,
Expand Down
10 changes: 5 additions & 5 deletions packages/gill/src/__tests__/mint-tokens-instructions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe("getMintTokensInstructions", () => {

it("should create instructions with default token program", () => {
const args: GetMintTokensInstructionsArgs = {
payer: mockPayer,
feePayer: mockPayer,
mint: mockMint.address,
mintAuthority: mockMintAuthority,
destination: mockDestination.address,
Expand Down Expand Up @@ -80,7 +80,7 @@ describe("getMintTokensInstructions", () => {

it("should create instructions with Token-2022 program", () => {
const args: GetMintTokensInstructionsArgs = {
payer: mockPayer,
feePayer: mockPayer,
mint: mockMint.address,
mintAuthority: mockMintAuthority,
destination: mockDestination.address,
Expand All @@ -103,7 +103,7 @@ describe("getMintTokensInstructions", () => {

it("should accept Address type for mint, mintAuthority, and destination", () => {
const args: GetMintTokensInstructionsArgs = {
payer: mockPayer,
feePayer: mockPayer,
mint: "mintAddress" as Address,
mintAuthority: "mintAuthorityAddress" as Address,
destination: "ownerAddress" as Address,
Expand Down Expand Up @@ -138,7 +138,7 @@ describe("getMintTokensInstructions", () => {

it("should accept number type for amount", () => {
const args: GetMintTokensInstructionsArgs = {
payer: mockPayer,
feePayer: mockPayer,
mint: mockMint.address,
mintAuthority: mockMintAuthority,
destination: mockDestination.address,
Expand All @@ -164,7 +164,7 @@ describe("getMintTokensInstructions", () => {

it("should throw error for unsupported token program", () => {
const args: GetMintTokensInstructionsArgs = {
payer: mockPayer,
feePayer: mockPayer,
mint: mockMint.address,
mintAuthority: mockMintAuthority,
destination: mockDestination.address,
Expand Down
14 changes: 7 additions & 7 deletions packages/gill/src/__typetests__/create-token-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ async () => {
// Legacy transaction
{
(await buildCreateTokenTransaction({
payer: signer,
feePayer: signer,
mint,
metadata,
})) satisfies BaseTransactionMessage<"legacy">;

(await buildCreateTokenTransaction({
payer: signer,
feePayer: signer,
version: "legacy",
mint,
metadata,
})) satisfies BaseTransactionMessage<"legacy">;

const txNotSignable = (await buildCreateTokenTransaction({
payer: signer,
feePayer: signer,
version: "legacy",
mint,
metadata,
Expand All @@ -43,7 +43,7 @@ async () => {
signTransactionMessageWithSigners(txNotSignable);

const txSignable = (await buildCreateTokenTransaction({
payer: signer,
feePayer: signer,
version: "legacy",
mint,
metadata,
Expand All @@ -57,14 +57,14 @@ async () => {
// Version 0 transaction
{
(await buildCreateTokenTransaction({
payer: signer,
feePayer: signer,
version: 0,
mint,
metadata,
})) satisfies BaseTransactionMessage<0>;

const txNotSignable = (await buildCreateTokenTransaction({
payer: signer,
feePayer: signer,
version: 0,
mint,
metadata,
Expand All @@ -75,7 +75,7 @@ async () => {
signTransactionMessageWithSigners(txNotSignable);

const txSignable = (await buildCreateTokenTransaction({
payer: signer,
feePayer: signer,
version: 0,
mint,
metadata,
Expand Down
14 changes: 7 additions & 7 deletions packages/gill/src/__typetests__/mint-tokens-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async () => {
// Legacy transaction
{
(await buildMintTokensTransaction({
payer: signer,
feePayer: signer,
mint,
destination,
amount: 0,
Expand All @@ -32,7 +32,7 @@ async () => {
})) satisfies BaseTransactionMessage<"legacy">;

(await buildMintTokensTransaction({
payer: signer,
feePayer: signer,
version: "legacy",
mint,
destination,
Expand All @@ -42,7 +42,7 @@ async () => {
})) satisfies BaseTransactionMessage<"legacy">;

const txNotSignable = (await buildMintTokensTransaction({
payer: signer,
feePayer: signer,
version: "legacy",
mint,
destination,
Expand All @@ -56,7 +56,7 @@ async () => {
signTransactionMessageWithSigners(txNotSignable);

const txSignable = (await buildMintTokensTransaction({
payer: signer,
feePayer: signer,
version: "legacy",
mint,
destination,
Expand All @@ -73,7 +73,7 @@ async () => {
// Version 0 transaction
{
(await buildMintTokensTransaction({
payer: signer,
feePayer: signer,
version: 0,
mint,
destination,
Expand All @@ -83,7 +83,7 @@ async () => {
})) satisfies BaseTransactionMessage<0>;

const txNotSignable = (await buildMintTokensTransaction({
payer: signer,
feePayer: signer,
version: 0,
mint,
destination,
Expand All @@ -97,7 +97,7 @@ async () => {
signTransactionMessageWithSigners(txNotSignable);

const txSignable = (await buildMintTokensTransaction({
payer: signer,
feePayer: signer,
version: 0,
mint,
destination,
Expand Down
30 changes: 10 additions & 20 deletions packages/gill/src/programs/token/instructions/create-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@ import {
getInitializeTokenMetadataInstruction,
getInitializeMetadataPointerInstruction,
} from "@solana-program/token-2022";
import { checkedTokenProgramAddress, type TOKEN_PROGRAM_ADDRESS } from "../addresses";
import { checkedTokenProgramAddress } from "../addresses";
import type { TokenInstructionBase } from "./types";

export type GetCreateTokenInstructionsArgs = {
/** Signer that will pay for the rent storage deposit fee */
payer: KeyPairSigner;
/** Token mint to be created (aka token address) */
mint: KeyPairSigner;
export type GetCreateTokenInstructionsArgs = TokenInstructionBase<KeyPairSigner> & {
/**
* The number of decimal places this token should have
*
Expand All @@ -32,7 +29,7 @@ export type GetCreateTokenInstructionsArgs = {
/**
* Authority address that is allowed to mint new tokens
*
* When not provided, defaults to: `payer`
* When not provided, defaults to: `feePayer`
**/
mintAuthority?: KeyPairSigner;
/**
Expand All @@ -45,7 +42,7 @@ export type GetCreateTokenInstructionsArgs = {
/**
* Authority address that is allowed to update the metadata
*
* When not provided, defaults to: `payer`
* When not provided, defaults to: `feePayer`
**/
updateAuthority?: KeyPairSigner;
/**
Expand Down Expand Up @@ -77,13 +74,6 @@ export type GetCreateTokenInstructionsArgs = {
* ```
* */
metadataAddress: Address;
/**
* Token program used to create the token's `mint`
*
* - (default) {@link TOKEN_PROGRAM_ADDRESS} - the original SPL Token Program
* - {@link TOKEN_2022_PROGRAM_ADDRESS} - the SPL Token Extensions Program (aka Token22)
**/
tokenProgram?: Address;
// extensions // todo
};

Expand All @@ -94,8 +84,8 @@ export function getCreateTokenInstructions(args: GetCreateTokenInstructionsArgs)
args.tokenProgram = checkedTokenProgramAddress(args.tokenProgram);

if (!args.decimals) args.decimals = 9;
if (!args.mintAuthority) args.mintAuthority = args.payer;
if (!args.updateAuthority) args.updateAuthority = args.payer;
if (!args.mintAuthority) args.mintAuthority = args.feePayer;
if (!args.updateAuthority) args.updateAuthority = args.feePayer;
if (args.freezeAuthority) args.freezeAuthority = checkedAddress(args.freezeAuthority);

if (args.tokenProgram === TOKEN_2022_PROGRAM_ADDRESS) {
Expand All @@ -118,7 +108,7 @@ export function getCreateTokenInstructions(args: GetCreateTokenInstructionsArgs)

return [
getCreateAccountInstruction({
payer: args.payer,
payer: args.feePayer,
newAccount: args.mint,
/**
* token22 requires only the pre-mint-initialization extensions (like metadata pointer)
Expand Down Expand Up @@ -162,7 +152,7 @@ export function getCreateTokenInstructions(args: GetCreateTokenInstructionsArgs)

return [
getCreateAccountInstruction({
payer: args.payer,
payer: args.feePayer,
newAccount: args.mint,
lamports: getMinimumBalanceForRentExemption(space),
space,
Expand All @@ -178,7 +168,7 @@ export function getCreateTokenInstructions(args: GetCreateTokenInstructionsArgs)
metadata: args.metadataAddress,
mint: args.mint.address,
mintAuthority: args.mintAuthority,
payer: args.payer,
payer: args.feePayer,
updateAuthority: args.updateAuthority,
data: {
name: args.metadata.name,
Expand Down
Loading

0 comments on commit a1e342a

Please sign in to comment.