metaplex-foundation / solita

Genrates an SDK API from solana contract IDL.
Apache License 2.0
139 stars 31 forks source link

feat: support imports from other libraries #55

Open thlorenz opened 2 years ago

thlorenz commented 2 years ago

In order to avoid the below https://github.com/metaplex-foundation/metaplex-program-library/blob/master/candy-machine/program/src/state.rs#L68-L75

// Unfortunate duplication of token metadata so that IDL picks it up.
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug)]
pub struct Creator {
    pub address: Pubkey,
    pub verified: bool,
    // In percentages, NOT basis points ;) Watch out!
    pub share: u8,
}

solita should support specitying where to import a type from that's not part of the rust program , but found in a dependenycy instead. Thus in the above example, given that token-metadata exports Creators and we have a dep on that SDK if we specify:

module.exports = {
  [..]
  imports: {
    '@metaplex-foundation/token-metadata': [ 'Creator' ]
  }
}

should add the below to all modules which refer to Creator

import { Creator } from '@metaplex-foundation/token-metadata'
samwise2 commented 2 years ago

This would be great! Running into this now, with the same struct :)

thlorenz commented 2 years ago

OK, thanks for letting me know .. will prioritize this. Do you have a small example that I could use to test this feature while I'm implementing this (since you said you're running into this)?

samwise2 commented 2 years ago

At this point I've worked around it, but I was running into it while trying to use this struct in this program. Instead I had to insert a copy here, we called it an adapter for semantics, but the adapter could have been the struct in bubblegum.

Pretty similar to your example :)

samwise2 commented 1 year ago

Are there any updates on this ticket? I've run into this again LOL