denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
94.04k stars 5.23k forks source link

npm compat: Unable to use @solana/spl-governance #23458

Closed juchiast closed 4 months ago

juchiast commented 5 months ago

Version: Deno 1.42.4

Code:

import { getRealms } from "@solana/spl-governance";
import { Connection, PublicKey } from "@solana/web3.js";

const connection = new Connection(
  "https://api.mainnet-beta.solana.com",
  "recent"
);
const programId = new PublicKey("GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw");

const realms = await getRealms(connection, programId);
console.log(realms);

deno.json:

{
  "imports": {
    "@solana/spl-governance": "npm:@solana/spl-governance@^0.3.28",
    "@solana/web3.js": "npm:@solana/web3.js@^1.91.7"
  }
}

Error:

error: Uncaught SyntaxError: The requested module '@solana/spl-governance' does not provide an export named 'getRealms'
import { getRealms } from "@solana/spl-governance";
         ^

The function is available in LSP suggestion, although it shown 3 entries? Screenshot from 2024-04-19 21-32-38

When console.log the package:

[Module: null prototype] {
  ACCOUNT_VERSION_V1: 1,
  ACCOUNT_VERSION_V2: 2,
  BN_ZERO: <BN: 0>,
  BPF_UPGRADE_LOADER_ID: PublicKey [PublicKey(BPFLoaderUpgradeab1e11111111111111111111111)] {
    _bn: <BN: 2a8f6914e88a1b0e210153ef763ae2b00c2b93d16c124d2c0537a1004800000>
  },
  GOVERNANCE_ADDINS_SCHEMA: Map(2) {
    [Function: MaxVoterWeightRecord] => {
      kind: "struct",
      fields: [
        [ "accountDiscriminator", [Array] ],
        [ "realm", "pubkey" ],
        [ "governingTokenMint", "pubkey" ],
        [ "maxVoterWeight", "u64" ],
        [ "maxVoterWeightExpiry", [Object] ]
      ]
    },
    [Function: VoterWeightRecord] => {
      kind: "struct",
      fields: [
        [ "accountDiscriminator", [Array] ],
        [ "realm", "pubkey" ],
        [ "governingTokenMint", "pubkey" ],
        [ "governingTokenOwner", "pubkey" ],
        [ "voterWeight", "u64" ],
        [ "voterWeightExpiry", [Object] ],
        [ "weightAction", [Object] ],
        [ "weightActionTarget", [Object] ]
      ]
    }
  },
  GovernanceAddinAccountParser: [Function: GovernanceAddinAccountParser],
  GovernanceChatInstruction: { "0": "PostMessage", PostMessage: 0 },
  GovernanceError: [
    "Invalid instruction passed to program",
    "Realm with the given name and governing mints already exists",
    "Invalid realm",
    "Invalid Governing Token Mint",
    "Governing Token Owner must sign transaction",
    "Governing Token Owner or Delegate  must sign transaction",
    "All votes must be relinquished to withdraw governing tokens",
    "Invalid Token Owner Record account address",
    "Invalid GoverningMint for TokenOwnerRecord",
    "Invalid Realm for TokenOwnerRecord",
    "Invalid Proposal for ProposalTransaction",
    "Invalid Signatory account address",
    "Signatory already signed off",
    "Signatory must sign",
    "Invalid Proposal Owner",
    "Invalid Proposal for VoterRecord",
    "Invalid GoverningTokenOwner for VoteRecord",
    "Invalid Governance config: Vote threshold percentage out of range",
    "Proposal for the given Governance, Governing Token Mint and index already exists",
    "Token Owner already voted on the Proposal",
    "Owner doesn't have enough governing tokens to create Proposal",
    "Invalid State: Can't edit Signatories",
    "Invalid Proposal state",
    "Invalid State: Can't edit instructions",
    "Invalid State: Can't execute instruction",
    "Can't execute instruction within its hold up time",
    "Instruction already executed",
    "Invalid Instruction index",
    "Instruction hold up time is below the min specified by Governance",
    "Instruction at the given index for the Proposal already exists",
    "Invalid State: Can't sign off",
    "Invalid State: Can't vote",
    "Invalid State: Can't finalize vote",
    "Invalid State: Can't cancel Proposal",
    "Vote already relinquished",
    "Can't finalize vote. Voting still in progress",
    "Proposal voting time expired",
    "Invalid Signatory Mint",
    "Proposal does not belong to the given Governance",
    "Proposal does not belong to given Governing Mint",
    "Current mint authority must sign transaction",
    "Invalid mint authority",
    "Mint has no authority",
    "Invalid Token account owner",
    "Invalid Mint account owner",
    "Token Account is not initialized",
    "Token Account doesn't exist",
    "Token account data is invalid",
    "Token mint account data is invalid",
    "Token Mint account is not initialized",
    "Token Mint account doesn't exist",
    "Invalid ProgramData account address",
    "Invalid ProgramData account Data",
    "Provided upgrade authority doesn't match current program upgrade authority",
    "Current program upgrade authority must sign transaction",
    "Given program is not upgradable",
    "Invalid token owner",
    "Current token owner must sign transaction",
    "Given VoteThresholdType is not supported",
    "Given VoteWeightSource is not supported",
    "Legacy1",
    "Governance PDA must sign",
    "Instruction already flagged with error",
    "Invalid Realm for Governance",
    "Invalid Authority for Realm",
    "Realm has no authority",
    "Realm authority must sign",
    "Invalid governing token holding account",
    "Realm council mint change is not supported",
    "Not supported mint max vote weight source",
    "Invalid max vote weight supply fraction",
    "Owner doesn't have enough governing tokens to create Governance",
    "Too many outstanding proposals",
    "All proposals must be finalized to withdraw governing tokens",
    "Invalid VoterWeightRecord for Realm",
    "Invalid VoterWeightRecord for GoverningTokenMint",
    "Invalid VoterWeightRecord for TokenOwner",
    "VoterWeightRecord expired",
    "Invalid RealmConfig for Realm",
    "TokenOwnerRecord already exists",
    "Governing token deposits not allowed",
    "Invalid vote choice weight percentage",
    "Vote type not supported",
    "Invalid proposal options",
    "Proposal is not not executable",
    "Invalid vote",
    "Cannot execute defeated option",
    "VoterWeightRecord invalid action",
    "VoterWeightRecord invalid action target",
    "Invalid MaxVoterWeightRecord for Realm",
    "MaxVoterWeightRecord expired",
    "Cannot execute defeated option",
    "Not supported VoteType",
    "RealmConfig change not allowed",
    "At least one VoteThreshold is required",
    "Reserved buffer must be empty",
    "Cannot Relinquish in Finalizing state",
    "Invalid RealmConfig account address",
    "Cannot deposit dormant tokens",
    "Cannot withdraw membership tokens",
    ... 11 more items
  ],
  GovernanceToolsError: [
    "Account already initialized",
    "Account doesn't exist",
    "Invalid account owner",
    "Invalid account type",
    "Invalid new account size"
  ],
  GovernanceType: {
    "0": "Account",
    "1": "Program",
    "2": "Mint",
    "3": "Token",
    Account: 0,
    Program: 1,
    Mint: 2,
    Token: 3
  },
  GoverningTokenRole: { "0": "Community", "1": "Council", Community: 0, Council: 1 },
  MaxVoterWeightRecord: [Function: MaxVoterWeightRecord],
  PROGRAM_VERSION: 3,
  PROGRAM_VERSION_V1: 1,
  PROGRAM_VERSION_V2: 2,
  PROGRAM_VERSION_V3: 3,
  PostChatMessageArgs: [Function: PostChatMessageArgs],
  ProgramDataAccountInfo: Struct {
    TYPE: undefined,
    type: "type",
    schema: {
      authority: Struct {
        TYPE: undefined,
        type: "instance",
        schema: null,
        coercer: [Function: coercer],
        validator: [Function (anonymous)],
        refiner: [Function (anonymous)],
        entries: [GeneratorFunction: entries]
      },
      slot: Struct {
        TYPE: undefined,
        type: "number",
        schema: null,
        coercer: [Function: coercer],
        validator: [Function (anonymous)],
        refiner: [Function (anonymous)],
        entries: [GeneratorFunction: entries]
      }
    },
    coercer: [Function: coercer],
    validator: [Function (anonymous)],
    refiner: [Function (anonymous)],
    entries: [GeneratorFunction: entries]
  },
  PublicKeyFromString: Struct {
    TYPE: undefined,
    type: "instance",
    schema: null,
    coercer: [Function: coercer],
    validator: [Function (anonymous)],
    refiner: [Function (anonymous)],
    entries: [GeneratorFunction: entries]
  },
  SYSTEM_PROGRAM_ID: PublicKey [PublicKey(11111111111111111111111111111111)] {
    _bn: <BN: 0>
  },
  SendTransactionError: [Function: SendTransactionError],
  TOKEN_PROGRAM_ID: PublicKey [PublicKey(TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA)] {
    _bn: <BN: 6ddf6e1d765a193d9cbe146ceeb79ac1cb485ed5f5b37913a8cf5857eff00a9>
  },
  TokenError: [
    "Lamport balance below rent-exempt threshold",
    "Insufficient funds",
    "Invalid Mint",
    "Account not associated with this Mint",
    "Owner does not match",
    "Fixed supply",
    "Already in use",
    "Invalid number of provided signers",
    "Invalid number of required signers",
    "State is uninitialized",
    "Instruction does not support native tokens",
    "Non-native account can only be closed if its balance is zero",
    "Invalid instruction",
    "State is invalid for requested operation",
    "Operation overflowed",
    "Account does not support specified authority type",
    "This token mint cannot freeze accounts",
    "Account is frozen",
    "The provided decimals value different from the Mint decimals"
  ],
  VoterWeightAction: {
    "0": "CastVote",
    "1": "CommentProposal",
    "2": "CreateGovernance",
    "3": "CreateProposal",
    "4": "SignOffProposal",
    CastVote: 0,
    CommentProposal: 1,
    CreateGovernance: 2,
    CreateProposal: 3,
    SignOffProposal: 4
  },
  VoterWeightRecord: [Function: VoterWeightRecord],
  __esModule: true,
  createRevokeGoverningTokens: [Function: createRevokeGoverningTokens],
  createSetGovernanceConfig: [Function: createSetGovernanceConfig],
  createSetRealmAuthority: [Function: createSetRealmAuthority],
  createSetRealmConfig: [Function: createSetRealmConfig],
  default: {
    VoterWeightAction: [Getter],
    VoterWeightRecord: [Getter],
    getVoterWeightRecordAddress: [Getter],
    MaxVoterWeightRecord: [Getter],
    getMaxVoterWeightRecordAddress: [Getter],
    getMaxVoterWeightRecord: [Getter],
    getVoterWeightRecord: [Getter],
    getGovernanceAddinAccount: [Getter],
    GOVERNANCE_ADDINS_SCHEMA: [Getter],
    GovernanceAddinAccountParser: [Getter],
    GOVERNANCE_CHAT_PROGRAM_ID: [Getter],
    GovernanceChatAccountType: [Getter],
    ChatMessageBodyType: [Getter],
    ChatMessageBody: [Getter],
    ChatMessage: [Getter],
    getGovernanceChatMessages: [Getter],
    getGovernanceChatMessagesByVoter: [Getter],
    GovernanceChatInstruction: [Getter],
    PostChatMessageArgs: [Getter],
    GOVERNANCE_CHAT_SCHEMA: [Getter],
    ChatAccountParser: [Getter],
    withPostChatMessage: [Getter],
    RpcContext: [Getter],
    MemcmpFilter: [Getter],
    pubkeyFilter: [Getter],
    booleanFilter: [Getter],
    getBorshProgramAccounts: [Getter],
    BorshAccountParser: [Getter],
    GOVERNANCE_PROGRAM_SEED: [Getter],
    GovernanceAccountType: [Getter],
    getAccountTypes: [Getter],
    getGovernanceAccountVersion: [Getter],
    VoteThresholdType: [Getter],
    VoteThreshold: [Getter],
    VoteTipping: [Getter],
    InstructionExecutionStatus: [Getter],
    InstructionExecutionFlags: [Getter],
    MintMaxVoteWeightSourceType: [Getter],
    MintMaxVoteWeightSource: [Getter],
    VoteTypeKind: [Getter],
    MultiChoiceType: [Getter],
    VoteType: [Getter],
    RealmConfigArgs: [Getter],
    GoverningTokenType: [Getter],
    GoverningTokenConfigArgs: [Getter],
    GoverningTokenConfigAccountArgs: [Getter],
    RealmConfig: [Getter],
    Realm: [Getter],
    getTokenHoldingAddress: [Getter],
    GoverningTokenConfig: [Getter],
    RealmConfigAccount: [Getter],
    getRealmConfigAddress: [Getter],
    GovernanceConfig: [Getter],
    Governance: [Getter],
    TokenOwnerRecord: [Getter],
    getTokenOwnerRecordAddress: [Getter],
    ProposalState: [Getter],
    OptionVoteResult: [Getter],
    ProposalOption: [Getter],
    Proposal: [Getter],
    ProposalDeposit: [Getter],
    SignatoryRecord: [Getter],
    getSignatoryRecordAddress: [Getter],
    VoteWeight: [Getter],
    VoteRecord: [Getter],
    getVoteRecordAddress: [Getter],
    AccountMetaData: [Getter],
    InstructionData: [Getter],
    ProposalTransaction: [Getter],
    getProposalTransactionAddress: [Getter],
    ProgramMetadata: [Getter],
    getProgramMetadataAddress: [Getter],
    getNativeTreasuryAddress: [Getter],
    getGoverningTokenHoldingAddress: [Getter],
    getProposalDepositAddress: [Getter],
    getRealm: [Getter],
    getRealms: [Getter],
    tryGetRealmConfig: [Getter],
    getRealmConfig: [Getter],
    getVoteRecord: [Getter],
    getVoteRecordsByVoter: [Getter],
    getTokenOwnerRecordForRealm: [Getter],
    getTokenOwnerRecord: [Getter],
    getTokenOwnerRecordsByOwner: [Getter],
    getAllTokenOwnerRecords: [Getter],
    getGovernance: [Getter],
    getAllGovernances: [Getter],
    getProposal: [Getter],
    getProposalsByGovernance: [Getter],
    getAllProposals: [Getter],
    getProposalDepositsByDepositPayer: [Getter],
    getGovernanceAccounts: [Getter],
    getGovernanceAccount: [Getter],
    tryGetGovernanceAccount: [Getter],
    createRevokeGoverningTokens: [Getter],
    createSetGovernanceConfig: [Getter],
    createSetRealmConfig: [Getter],
    createSetRealmAuthority: [Getter],
    GoverningTokenRole: [Getter],
    GovernanceType: [Getter],
    GovernanceError: [Getter],
    TokenError: [Getter],
    GovernanceToolsError: [Getter],
    getTransactionErrorMsg: [Getter],
    GovernanceInstruction: [Getter],
    CreateRealmArgs: [Getter],
    DepositGoverningTokensArgs: [Getter],
    WithdrawGoverningTokensArgs: [Getter],
    CreateGovernanceArgs: [Getter],
    CreateProgramGovernanceArgs: [Getter],
    CreateMintGovernanceArgs: [Getter],
    CreateTokenGovernanceArgs: [Getter],
    SetGovernanceConfigArgs: [Getter],
    CreateProposalArgs: [Getter],
    AddSignatoryArgs: [Getter],
    SignOffProposalArgs: [Getter],
    CancelProposalArgs: [Getter],
    YesNoVote: [Getter],
    VoteChoice: [Getter],
    VoteKind: [Getter],
    Vote: [Getter],
    CastVoteArgs: [Getter],
    RelinquishVoteArgs: [Getter],
    FinalizeVoteArgs: [Getter],
    InsertTransactionArgs: [Getter],
    RemoveTransactionArgs: [Getter],
    ExecuteTransactionArgs: [Getter],
    FlagTransactionErrorArgs: [Getter],
    SetRealmAuthorityAction: [Getter],
    SetRealmAuthorityArgs: [Getter],
    SetRealmConfigArgs: [Getter],
    CreateTokenOwnerRecordArgs: [Getter],
    UpdateProgramMetadataArgs: [Getter],
    CreateNativeTreasuryArgs: [Getter],
    SetGovernanceDelegateArgs: [Getter],
    RevokeGoverningTokensArgs: [Getter],
    RefundProposalDepositArgs: [Getter],
    serializeInstructionToBase64: [Getter],
    createInstructionData: [Getter],
    GOVERNANCE_INSTRUCTION_SCHEMA_V1: [Getter],
    GOVERNANCE_INSTRUCTION_SCHEMA_V2: [Getter],
    GOVERNANCE_INSTRUCTION_SCHEMA_V3: [Getter],
    getGovernanceInstructionSchema: [Getter],
    GOVERNANCE_ACCOUNT_SCHEMA_V1: [Getter],
    GOVERNANCE_ACCOUNT_SCHEMA_V2: [Getter],
    getGovernanceAccountSchema: [Getter],
    getGovernanceSchemaForAccount: [Getter],
    GovernanceAccountParser: [Getter],
    getInstructionDataFromBase64: [Getter],
    createRealmConfigArgs: [Getter],
    withTokenConfigAccounts: [Getter],
    withV3RealmConfigAccount: [Getter],
    withAddSignatory: [Getter],
    getGovernanceProgramVersion: [Getter],
    withCancelProposal: [Getter],
    withCastVote: [Getter],
    withCreateGovernance: [Getter],
    withCreateMintGovernance: [Getter],
    withCreateNativeTreasury: [Getter],
    withCreateProgramGovernance: [Getter],
    withCreateProposal: [Getter],
    withCreateRealm: [Getter],
    withCreateTokenGovernance: [Getter],
    withCreateTokenOwnerRecord: [Getter],
    withDepositGoverningTokens: [Getter],
    withExecuteTransaction: [Getter],
    withFinalizeVote: [Getter],
    withFlagTransactionError: [Getter],
    withInsertTransaction: [Getter],
    withRefundProposalDeposit: [Getter],
    withRelinquishVote: [Getter],
    withRemoveTransaction: [Getter],
    withRevokeGoverningTokens: [Getter],
    withSetRealmAuthority: [Getter],
    withSetRealmConfig: [Getter],
    withSetGovernanceDelegate: [Getter],
    withSignOffProposal: [Getter],
    withUpdateProgramMetadata: [Getter],
    withWithdrawGoverningTokens: [Getter],
    PROGRAM_VERSION_V1: [Getter],
    PROGRAM_VERSION_V2: [Getter],
    PROGRAM_VERSION_V3: [Getter],
    PROGRAM_VERSION: [Getter],
    ACCOUNT_VERSION_V1: [Getter],
    ACCOUNT_VERSION_V2: [Getter],
    BPF_UPGRADE_LOADER_ID: [Getter],
    PublicKeyFromString: [Getter],
    ProgramDataAccountInfo: [Getter],
    getProgramDataAddress: [Getter],
    getProgramDataAccount: [Getter],
    SYSTEM_PROGRAM_ID: [Getter],
    simulateTransaction: [Getter],
    SendTransactionError: [Getter],
    TOKEN_PROGRAM_ID: [Getter],
    deserializeBorsh: [Getter],
    BN_ZERO: [Getter],
    getErrorMessage: [Getter],
    parseVersion: [Getter],
    isWalletNotConnectedError: [Getter]
  },
  deserializeBorsh: [Function: deserializeBorsh],
  getErrorMessage: [Function: getErrorMessage],
  getGovernanceAddinAccount: [Function: getGovernanceAddinAccount],
  getGovernanceProgramVersion: [Function: getGovernanceProgramVersion],
  getMaxVoterWeightRecord: [Function: getMaxVoterWeightRecord],
  getMaxVoterWeightRecordAddress: [Function: getMaxVoterWeightRecordAddress],
  getProgramDataAccount: [Function: getProgramDataAccount],
  getProgramDataAddress: [Function: getProgramDataAddress],
  getTransactionErrorMsg: [Function: getTransactionErrorMsg],
  getVoterWeightRecord: [Function: getVoterWeightRecord],
  getVoterWeightRecordAddress: [Function: getVoterWeightRecordAddress],
  isWalletNotConnectedError: [Function: isWalletNotConnectedError],
  simulateTransaction: [Function: simulateTransaction],
  withAddSignatory: [Function: withAddSignatory],
  withCancelProposal: [Function: withCancelProposal],
  withCastVote: [Function: withCastVote],
  withCreateGovernance: [Function: withCreateGovernance],
  withCreateMintGovernance: [Function: withCreateMintGovernance],
  withCreateNativeTreasury: [Function: withCreateNativeTreasury],
  withCreateProgramGovernance: [Function: withCreateProgramGovernance],
  withCreateProposal: [Function: withCreateProposal],
  withCreateRealm: [Function: withCreateRealm],
  withCreateTokenGovernance: [Function: withCreateTokenGovernance],
  withCreateTokenOwnerRecord: [Function: withCreateTokenOwnerRecord],
  withDepositGoverningTokens: [Function: withDepositGoverningTokens],
  withExecuteTransaction: [Function: withExecuteTransaction],
  withFinalizeVote: [Function: withFinalizeVote],
  withFlagTransactionError: [Function: withFlagTransactionError],
  withInsertTransaction: [Function: withInsertTransaction],
  withPostChatMessage: [Function: withPostChatMessage],
  withRefundProposalDeposit: [Function: withRefundProposalDeposit],
  withRelinquishVote: [Function: withRelinquishVote],
  withRemoveTransaction: [Function: withRemoveTransaction],
  withRevokeGoverningTokens: [Function: withRevokeGoverningTokens],
  withSetGovernanceDelegate: [Function: withSetGovernanceDelegate],
  withSetRealmAuthority: [Function: withSetRealmAuthority],
  withSetRealmConfig: [Function: withSetRealmConfig],
  withSignOffProposal: [Function: withSignOffProposal],
  withUpdateProgramMetadata: [Function: withUpdateProgramMetadata],
  withWithdrawGoverningTokens: [Function: withWithdrawGoverningTokens]
}

Calling with .default.getRealms worked:

import * as lib from "@solana/spl-governance";
console.log(lib.default.getRealms);
dsherret commented 4 months ago

This looks like an actual Deno bug. Node is able to figure it out from an mjs file.