-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add getTokenMetadata to solana api. (#1171)
* feat: add getTokenMetadata to solana api. * update swagger.
- Loading branch information
Showing
15 changed files
with
309 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@moralisweb3/common-sol-utils': patch | ||
'@moralisweb3/sol-api': patch | ||
'moralis': patch | ||
--- | ||
|
||
This version adds a new `getTokenMetadata` endpoint to the Solana API. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@moralisweb3/common-sol-utils': minor | ||
'@moralisweb3/sol-api': minor | ||
'moralis': minor | ||
--- | ||
|
||
`nativePrice`, `exchangeName` and `exchangeAddress` properties in the `SolSPLTokenPrice` class are now optional. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
packages/common/solUtils/src/generated/operations/GetTokenMetadataOperation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { SolNetwork, SolNetworkInput, SolNetworkJSON, SolAddress, SolAddressInput, SolAddressJSON } from '../../dataTypes'; | ||
import { SolTokenMetadata, SolTokenMetadataJSON } from '../types/SolTokenMetadata'; | ||
|
||
// request parameters: | ||
// - network ($ref: #/paths/~1token~1{network}~1{address}~1metadata/get/parameters/0/schema) | ||
// - address ($ref: #/paths/~1token~1{network}~1{address}~1metadata/get/parameters/1/schema) | ||
|
||
export interface GetTokenMetadataOperationRequest { | ||
/** | ||
* @description The network to query | ||
*/ | ||
readonly network: SolNetworkInput | SolNetwork; | ||
/** | ||
* @description The address of the contract | ||
*/ | ||
readonly address: SolAddressInput | SolAddress; | ||
} | ||
|
||
export interface GetTokenMetadataOperationRequestJSON { | ||
readonly network: SolNetworkJSON; | ||
readonly address: SolAddressJSON; | ||
} | ||
|
||
export type GetTokenMetadataOperationResponse = SolTokenMetadata; | ||
export type GetTokenMetadataOperationResponseJSON = SolTokenMetadataJSON; | ||
|
||
export const GetTokenMetadataOperation = { | ||
operationId: "getTokenMetadata", | ||
groupName: "token", | ||
httpMethod: "get", | ||
routePattern: "/token/{network}/{address}/metadata", | ||
parameterNames: ["network","address"], | ||
hasResponse: true, | ||
hasBody: false, | ||
|
||
parseResponse(json: SolTokenMetadataJSON): SolTokenMetadata { | ||
return SolTokenMetadata.fromJSON(json); | ||
}, | ||
|
||
serializeRequest(request: GetTokenMetadataOperationRequest): GetTokenMetadataOperationRequestJSON { | ||
const network = SolNetwork.create(request.network); | ||
const address = SolAddress.create(request.address); | ||
return { | ||
network: network.toJSON(), | ||
address: address.toJSON(), | ||
}; | ||
}, | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './GetTokenPriceOperation'; | ||
export * from './GetTokenMetadataOperation'; | ||
export * from './operations'; |
2 changes: 2 additions & 0 deletions
2
packages/common/solUtils/src/generated/operations/operations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import { GetTokenPriceOperation } from './GetTokenPriceOperation'; | ||
import { GetTokenMetadataOperation } from './GetTokenMetadataOperation'; | ||
|
||
export const operations = [ | ||
GetTokenPriceOperation, | ||
GetTokenMetadataOperation, | ||
]; |
16 changes: 16 additions & 0 deletions
16
packages/common/solUtils/src/generated/types/SolGetTokenMetadataNetworkEnum.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// $ref: #/paths/~1token~1{network}~1{address}~1metadata/get/parameters/0/schema | ||
// typeName: getTokenMetadata_network_Enum | ||
|
||
export type SolGetTokenMetadataNetworkEnumJSON = "mainnet" | "devnet"; | ||
export type SolGetTokenMetadataNetworkEnumInput = "mainnet" | "devnet"; | ||
export type SolGetTokenMetadataNetworkEnumValue = "mainnet" | "devnet"; | ||
|
||
export abstract class SolGetTokenMetadataNetworkEnum { | ||
public static create(input: SolGetTokenMetadataNetworkEnumInput | SolGetTokenMetadataNetworkEnumValue): SolGetTokenMetadataNetworkEnumValue { | ||
return input; | ||
} | ||
|
||
public static fromJSON(json: SolGetTokenMetadataNetworkEnumJSON): SolGetTokenMetadataNetworkEnumValue { | ||
return json; | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
packages/common/solUtils/src/generated/types/SolMetaplexToken.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// $ref: #/components/schemas/MetaplexToken | ||
// type: MetaplexToken | ||
// properties: | ||
// - metadataUri ($ref: #/components/schemas/MetaplexToken/properties/metadataUri) | ||
// - masterEdition ($ref: #/components/schemas/MetaplexToken/properties/masterEdition) | ||
// - isMutable ($ref: #/components/schemas/MetaplexToken/properties/isMutable) | ||
// - primarySaleHappened ($ref: #/components/schemas/MetaplexToken/properties/primarySaleHappened) | ||
// - sellerFeeBasisPoints ($ref: #/components/schemas/MetaplexToken/properties/sellerFeeBasisPoints) | ||
// - updateAuthority ($ref: #/components/schemas/MetaplexToken/properties/updateAuthority) | ||
|
||
export interface SolMetaplexTokenJSON { | ||
readonly metadataUri: string; | ||
readonly masterEdition: boolean; | ||
readonly isMutable: boolean; | ||
readonly primarySaleHappened: number; | ||
readonly sellerFeeBasisPoints: number; | ||
readonly updateAuthority: string; | ||
} | ||
|
||
export interface SolMetaplexTokenInput { | ||
readonly metadataUri: string; | ||
readonly masterEdition: boolean; | ||
readonly isMutable: boolean; | ||
readonly primarySaleHappened: number; | ||
readonly sellerFeeBasisPoints: number; | ||
readonly updateAuthority: string; | ||
} | ||
|
||
export class SolMetaplexToken { | ||
public static create(input: SolMetaplexTokenInput | SolMetaplexToken): SolMetaplexToken { | ||
if (input instanceof SolMetaplexToken) { | ||
return input; | ||
} | ||
return new SolMetaplexToken(input); | ||
} | ||
|
||
public static fromJSON(json: SolMetaplexTokenJSON): SolMetaplexToken { | ||
const input: SolMetaplexTokenInput = { | ||
metadataUri: json.metadataUri, | ||
masterEdition: json.masterEdition, | ||
isMutable: json.isMutable, | ||
primarySaleHappened: json.primarySaleHappened, | ||
sellerFeeBasisPoints: json.sellerFeeBasisPoints, | ||
updateAuthority: json.updateAuthority, | ||
}; | ||
return SolMetaplexToken.create(input); | ||
} | ||
|
||
public readonly metadataUri: string; | ||
public readonly masterEdition: boolean; | ||
public readonly isMutable: boolean; | ||
public readonly primarySaleHappened: number; | ||
public readonly sellerFeeBasisPoints: number; | ||
public readonly updateAuthority: string; | ||
|
||
private constructor(input: SolMetaplexTokenInput) { | ||
this.metadataUri = input.metadataUri; | ||
this.masterEdition = input.masterEdition; | ||
this.isMutable = input.isMutable; | ||
this.primarySaleHappened = input.primarySaleHappened; | ||
this.sellerFeeBasisPoints = input.sellerFeeBasisPoints; | ||
this.updateAuthority = input.updateAuthority; | ||
} | ||
|
||
public toJSON(): SolMetaplexTokenJSON { | ||
return { | ||
metadataUri: this.metadataUri, | ||
masterEdition: this.masterEdition, | ||
isMutable: this.isMutable, | ||
primarySaleHappened: this.primarySaleHappened, | ||
sellerFeeBasisPoints: this.sellerFeeBasisPoints, | ||
updateAuthority: this.updateAuthority, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
packages/common/solUtils/src/generated/types/SolTokenMetadata.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { SolMetaplexToken, SolMetaplexTokenInput, SolMetaplexTokenJSON } from '../types/SolMetaplexToken'; | ||
|
||
// $ref: #/components/schemas/TokenMetadata | ||
// type: TokenMetadata | ||
// properties: | ||
// - mint ($ref: #/components/schemas/TokenMetadata/properties/mint) | ||
// - standard ($ref: #/components/schemas/TokenMetadata/properties/standard) | ||
// - name ($ref: #/components/schemas/TokenMetadata/properties/name) | ||
// - symbol ($ref: #/components/schemas/TokenMetadata/properties/symbol) | ||
// - metaplex ($ref: #/components/schemas/MetaplexToken) | ||
|
||
export interface SolTokenMetadataJSON { | ||
readonly mint: string; | ||
readonly standard: string; | ||
readonly name: string; | ||
readonly symbol: string; | ||
readonly metaplex: SolMetaplexTokenJSON; | ||
} | ||
|
||
export interface SolTokenMetadataInput { | ||
readonly mint: string; | ||
readonly standard: string; | ||
readonly name: string; | ||
readonly symbol: string; | ||
readonly metaplex: SolMetaplexTokenInput | SolMetaplexToken; | ||
} | ||
|
||
export class SolTokenMetadata { | ||
public static create(input: SolTokenMetadataInput | SolTokenMetadata): SolTokenMetadata { | ||
if (input instanceof SolTokenMetadata) { | ||
return input; | ||
} | ||
return new SolTokenMetadata(input); | ||
} | ||
|
||
public static fromJSON(json: SolTokenMetadataJSON): SolTokenMetadata { | ||
const input: SolTokenMetadataInput = { | ||
mint: json.mint, | ||
standard: json.standard, | ||
name: json.name, | ||
symbol: json.symbol, | ||
metaplex: SolMetaplexToken.fromJSON(json.metaplex), | ||
}; | ||
return SolTokenMetadata.create(input); | ||
} | ||
|
||
public readonly mint: string; | ||
public readonly standard: string; | ||
public readonly name: string; | ||
public readonly symbol: string; | ||
public readonly metaplex: SolMetaplexToken; | ||
|
||
private constructor(input: SolTokenMetadataInput) { | ||
this.mint = input.mint; | ||
this.standard = input.standard; | ||
this.name = input.name; | ||
this.symbol = input.symbol; | ||
this.metaplex = SolMetaplexToken.create(input.metaplex); | ||
} | ||
|
||
public toJSON(): SolTokenMetadataJSON { | ||
return { | ||
mint: this.mint, | ||
standard: this.standard, | ||
name: this.name, | ||
symbol: this.symbol, | ||
metaplex: this.metaplex.toJSON(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
export * from './SolGetTokenPriceNetworkEnum'; | ||
export * from './SolGetTokenMetadataNetworkEnum'; | ||
export * from './SolSPLTokenPrice'; | ||
export * from './SolTokenMetadata'; | ||
export * from './SolSPLNativePrice'; | ||
export * from './SolMetaplexToken'; |
Oops, something went wrong.
444c0dd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test coverage