UNPKG

goodrdotfun-sdk

Version:

SDK for interacting with goodr.fun and Sonic on Solana

145 lines (144 loc) 6.82 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ProgramError = exports.ProgramErrorCodeTs = exports.TokenMetadata = exports.TokenMetadataAttributeKeys = exports.DECIMALS = void 0; const class_validator_1 = require("class-validator"); exports.DECIMALS = 6; exports.TokenMetadataAttributeKeys = { DonationDestination: 'Donation Destination', DonationAmount: 'Donation Amount', TwitterUrl: 'Twitter URL', TelegramUrl: 'Telegram URL', WebsiteUrl: 'Website URL', }; class TokenMetadata { constructor(params) { Object.assign(this, params); } static fromJSON(json) { return new TokenMetadata({ name: json.name, ticker: json.symbol, description: json.description, imageUrl: json.image, donationAmount: json.attributes.find(attr => attr.trait_type === exports.TokenMetadataAttributeKeys.DonationAmount)?.value, twitterUrl: json.attributes.find(attr => attr.trait_type === exports.TokenMetadataAttributeKeys.TwitterUrl)?.value, telegramUrl: json.attributes.find(attr => attr.trait_type === exports.TokenMetadataAttributeKeys.TelegramUrl)?.value, websiteUrl: json.attributes.find(attr => attr.trait_type === exports.TokenMetadataAttributeKeys.WebsiteUrl)?.value, donationDestinationId: parseInt(json.attributes.find(attr => attr.trait_type === exports.TokenMetadataAttributeKeys.DonationDestination)?.value || '0'), }); } toJSON() { const result = { name: this.name || '', symbol: this.ticker || '', description: this.description || '', image: this.imageUrl || '', animation_url: '', external_url: 'https://goodr.fun/tokens', attributes: [], }; // Add attributes // donationDestinationId result.attributes.push({ trait_type: exports.TokenMetadataAttributeKeys.DonationDestination, value: this.donationDestinationId?.toString() || '0', }); // donationAmount result.attributes.push({ trait_type: exports.TokenMetadataAttributeKeys.DonationAmount, value: this.donationAmount || '', }); // twitterUrl result.attributes.push({ trait_type: exports.TokenMetadataAttributeKeys.TwitterUrl, value: this.twitterUrl || '', }); // telegramUrl result.attributes.push({ trait_type: exports.TokenMetadataAttributeKeys.TelegramUrl, value: this.telegramUrl || '', }); // websiteUrl result.attributes.push({ trait_type: exports.TokenMetadataAttributeKeys.WebsiteUrl, value: this.websiteUrl || '', }); return result; } } exports.TokenMetadata = TokenMetadata; __decorate([ (0, class_validator_1.IsString)(), (0, class_validator_1.IsNotEmpty)(), __metadata("design:type", String) ], TokenMetadata.prototype, "name", void 0); __decorate([ (0, class_validator_1.IsString)(), (0, class_validator_1.IsNotEmpty)(), __metadata("design:type", String) ], TokenMetadata.prototype, "description", void 0); __decorate([ (0, class_validator_1.IsString)(), (0, class_validator_1.IsNotEmpty)(), __metadata("design:type", String) ], TokenMetadata.prototype, "ticker", void 0); __decorate([ (0, class_validator_1.IsString)(), __metadata("design:type", String) ], TokenMetadata.prototype, "donationAmount", void 0); __decorate([ (0, class_validator_1.IsString)(), __metadata("design:type", String) ], TokenMetadata.prototype, "twitterUrl", void 0); __decorate([ (0, class_validator_1.IsString)(), __metadata("design:type", String) ], TokenMetadata.prototype, "telegramUrl", void 0); __decorate([ (0, class_validator_1.IsString)(), __metadata("design:type", String) ], TokenMetadata.prototype, "websiteUrl", void 0); __decorate([ (0, class_validator_1.IsNumber)(), (0, class_validator_1.IsNotEmpty)(), __metadata("design:type", Number) ], TokenMetadata.prototype, "donationDestinationId", void 0); __decorate([ (0, class_validator_1.IsString)(), __metadata("design:type", String) ], TokenMetadata.prototype, "imageUrl", void 0); var ProgramErrorCodeTs; (function (ProgramErrorCodeTs) { ProgramErrorCodeTs["AlreadyInitialized"] = "The program is already initialized."; ProgramErrorCodeTs["NotAuthorized"] = "The given account is not authorized to execute this instruction."; ProgramErrorCodeTs["TooMuchSolRequired"] = "slippage: Too much SOL required to buy the given amount of tokens."; ProgramErrorCodeTs["TooLittleSolReceived"] = "slippage: Too little SOL received to sell the given amount of tokens."; ProgramErrorCodeTs["MintDoesNotMatchBondingCurve"] = "The mint does not match the bonding curve."; ProgramErrorCodeTs["BondingCurveComplete"] = "The bonding curve has completed and liquidity migrated to raydium."; ProgramErrorCodeTs["BondingCurveNotComplete"] = "The bonding curve has not completed yet."; ProgramErrorCodeTs["NotInitialized"] = "The program is not initialized."; ProgramErrorCodeTs["NotAuthorizedDonationDestination"] = "The donation destination is not authorized."; ProgramErrorCodeTs["InsufficientTokens"] = "Insufficient Tokens"; ProgramErrorCodeTs["MinBuy"] = "Min buy is 1 Token"; ProgramErrorCodeTs["MinSell"] = "Min sell is 1 Token"; ProgramErrorCodeTs["InsufficientSOL"] = "Insufficient SOL"; ProgramErrorCodeTs["InvalidMintAccountSpace"] = "Invalid Mint Account Space"; ProgramErrorCodeTs["CantInitializeMetadataPointer"] = "Can't Initialize Metadata Pointer"; })(ProgramErrorCodeTs || (exports.ProgramErrorCodeTs = ProgramErrorCodeTs = {})); class ProgramError extends Error { constructor(code, message) { super(message || ProgramErrorCodeTs[code]); this.name = 'ProgramError'; this.code = code; } } exports.ProgramError = ProgramError;