Skip to content

Commit 81a5da3

Browse files
committed
feat: bump version to 0.0.7-alpha.7, update image file type to PNG in MusicNFTMetadata, and add debug logging in various managers
1 parent 56b5d3c commit 81a5da3

File tree

10 files changed

+65
-28
lines changed

10 files changed

+65
-28
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@aithranetwork/sdk-aithra-toolkit",
3-
"version": "0.0.7-alpha.6",
3+
"version": "0.0.7-alpha.7",
44
"description": "The Aithra Network Toolkit SDK for the agents",
55
"main": "dist/index.js",
66
"module": "dist/index.mjs",
@@ -19,7 +19,7 @@
1919
],
2020
"scripts": {
2121
"build": "tsup ./src",
22-
"lint:fix":"eslint --fix",
22+
"lint:fix": "eslint --fix",
2323
"test": "jest --runInBand --forceExit",
2424
"test:coverage": "jest --coverage",
2525
"test:coverage:html": "jest --coverage --coverageReporters='text-summary' --coverageReporters='html' && open coverage/index.html"
@@ -63,4 +63,4 @@
6363
"peerDependencies": {
6464
"@solana/web3.js": "1.95.8"
6565
}
66-
}
66+
}

src/core/creditManager.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Wallet } from '@project-serum/anchor';
22
import { Connection, PublicKey, TransactionInstruction, AddressLookupTableAccount } from '@solana/web3.js';
33
import { ICreditManager } from './types';
4-
import {aithraToolkitLogger} from './logger';
4+
import { aithraToolkitLogger } from './logger';
55
import {
66
createTransferInstruction,
77
getAssociatedTokenAddressSync,
@@ -43,64 +43,75 @@ export class CreditManager implements ICreditManager {
4343
}
4444

4545
async fetchBalance(): Promise<Result<number, Error>> {
46+
aithraToolkitLogger.debug('Entering fetchBalance');
4647
try {
4748
const balance = await getTokenBalanceWeb3(
4849
this.connection,
4950
this.AITHRA_MINT,
5051
this.wallet.publicKey
5152
);
53+
aithraToolkitLogger.debug('Exiting fetchBalance');
5254
return Result.ok(balance);
5355
} catch (err) {
5456
return Result.err(new Error(`Failed to fetch balance: ${err.message}`));
5557
}
5658
}
5759

5860
private async syncBalance(): Promise<Result<void, Error>> {
61+
aithraToolkitLogger.debug('Entering syncBalance');
5962
const balanceResult = await this.fetchBalance();
6063
if (balanceResult.isErr()) {
6164
return Result.err(balanceResult.getErr()!);
6265
}
6366
this.balance = balanceResult.unwrap();
67+
aithraToolkitLogger.debug('Exiting syncBalance');
6468
return Result.ok();
6569
}
6670

6771
async getCost(): Promise<Result<number, Error>> {
72+
aithraToolkitLogger.debug('Entering getCost');
6873
try {
6974
const response = await fetch(`${this.apiUrl}/payment-check`);
7075
const { cost } = await response.json();
76+
aithraToolkitLogger.debug('Exiting getCost');
7177
return Result.ok(Number(cost));
7278
} catch (err) {
7379
return Result.err(new Error(`Failed to get cost: ${err.message}`));
7480
}
7581
}
7682

7783
public async getAithraPriceInUsd(): Promise<Result<number, Error>> {
84+
aithraToolkitLogger.debug('Entering getAithraPriceInUsd');
7885
try {
7986
const tokenData = await (
8087
await fetch(
8188
`https://api.jup.ag/price/v2?ids=${this.AITHRA_MINT.toString()}`
8289
)
8390
).json();
91+
aithraToolkitLogger.debug('Exiting getAithraPriceInUsd');
8492
return Result.ok(Number(tokenData.data[this.AITHRA_MINT.toString()].price));
8593
} catch (err) {
8694
return Result.err(new Error(`Failed to get USD price: ${err.message}`));
8795
}
8896
}
8997

9098
private async getAithraPriceInSol(): Promise<Result<number, Error>> {
99+
aithraToolkitLogger.debug('Entering getAithraPriceInSol');
91100
try {
92101
const tokenData = await (
93102
await fetch(
94103
`https://api.jup.ag/price/v2?ids=${this.AITHRA_MINT.toString()}&vsToken=So11111111111111111111111111111111111111112`
95104
)
96105
).json();
106+
aithraToolkitLogger.debug('Exiting getAithraPriceInSol');
97107
return Result.ok(tokenData.data[this.AITHRA_MINT.toString()].price);
98108
} catch (err) {
99109
return Result.err(new Error(`Failed to get SOL price: ${err.message}`));
100110
}
101111
}
102112

103113
async handleCredits(numberOfFiles: number): Promise<Result<CreditRequirement, Error>> {
114+
aithraToolkitLogger.debug('Entering handleCredits');
104115
const syncResult = await this.syncBalance();
105116
if (syncResult.isErr()) return Result.err(syncResult.getErr()!);
106117

@@ -113,6 +124,7 @@ export class CreditManager implements ICreditManager {
113124

114125
const currentBalance = this.balance / Math.pow(10, 9);
115126

127+
aithraToolkitLogger.debug('Exiting handleCredits');
116128
return Result.ok({
117129
requiredAmount: totalCostWithSlippage,
118130
needsTokenPurchase: currentBalance < totalCostWithSlippage,
@@ -121,6 +133,7 @@ export class CreditManager implements ICreditManager {
121133
}
122134

123135
private async swapSolForAithra(amountInSol: number): Promise<Result<string, Error>> {
136+
aithraToolkitLogger.debug('Entering swapSolForAithra');
124137
try {
125138
let lamports = Math.floor(amountInSol * Math.pow(10, 9));
126139

@@ -181,7 +194,7 @@ export class CreditManager implements ICreditManager {
181194
keys: string[]
182195
): Promise<AddressLookupTableAccount[]> => {
183196
if (!keys || keys.length === 0) return [];
184-
197+
185198
const addressLookupTableAccountInfos =
186199
await this.connection.getMultipleAccountsInfo(
187200
keys.map((key) => new PublicKey(key))
@@ -212,18 +225,20 @@ export class CreditManager implements ICreditManager {
212225
addressLookupTableAccounts, // Use the properly formatted accounts
213226
priorityFee: this.priorityFee
214227
});
215-
228+
216229
if (transactionResponse.isErr()) {
217230
return Result.err(transactionResponse.getErr());
218231
}
219232

233+
aithraToolkitLogger.debug('Exiting swapSolForAithra');
220234
return Result.ok(transactionResponse.unwrap());
221235
} catch (err) {
222236
return Result.err(new Error(`Swap failed: ${err.message}`));
223237
}
224238
}
225239

226240
public async pay(amount: number): Promise<Result<string, Error>> {
241+
aithraToolkitLogger.debug('Entering pay');
227242
try {
228243
const fromTokenAccount = getAssociatedTokenAddressSync(
229244
this.AITHRA_MINT,
@@ -253,13 +268,15 @@ export class CreditManager implements ICreditManager {
253268
return Result.err(transactionResponse.getErr());
254269
}
255270

271+
aithraToolkitLogger.debug('Exiting pay');
256272
return Result.ok(transactionResponse.unwrap());
257273
} catch (err) {
258274
return Result.err(new Error(`Payment failed: ${err.message}`));
259275
}
260276
}
261277

262278
async handlePayment(numberOfFiles: number): Promise<Result<string, Error>> {
279+
aithraToolkitLogger.debug('Entering handlePayment');
263280
const creditReqResult = await this.handleCredits(numberOfFiles);
264281
if (creditReqResult.isErr()) return Result.err(creditReqResult.getErr()!);
265282

@@ -290,7 +307,7 @@ export class CreditManager implements ICreditManager {
290307
aithraToolkitLogger.log(
291308
`Payment sent. https://solscan.io/tx/${signature}`
292309
);
293-
310+
aithraToolkitLogger.debug('Exiting handlePayment');
294311
return Result.ok(signature);
295312
}
296313
}

src/core/manager.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Connection, Keypair, PublicKey } from '@solana/web3.js';
22
import { Wallet } from '@project-serum/anchor';
3-
import { aithraToolkitLogger as logger } from './logger';
3+
import { aithraToolkitLogger, aithraToolkitLogger as logger } from './logger';
44
import {
55
MintConfig,
66
MusicNFTConfig,
@@ -38,7 +38,7 @@ interface BuildUploadMintMusicNFTsParams {
3838
animationUrl?: string;
3939
animationFile?: string;
4040
};
41-
creator?:string;
41+
creator?: string;
4242
}
4343

4444
interface ConstructorParams {
@@ -87,20 +87,20 @@ export class AithraManager {
8787

8888
async getTotalCost(numberOfSongs: number, numberOfMints: number): Promise<Result<number, Error>> {
8989
// const generateSongPrice = 0.035;
90-
90+
9191
// const priceResult = await this.mintsCreditManager.getAithraPriceInUsd();
9292
// if (priceResult.isErr()) {
9393
// return Result.err(priceResult.getErr());
9494
// }
9595
// const aithraUsdPrice = priceResult.unwrap() || 0.001;
96-
96+
9797
// const generateSongPriceAithra = generateSongPrice / aithraUsdPrice;
98-
98+
9999
// const fileCostResult = await this.filesCreditManager.getCost();
100100
// if (fileCostResult.isErr()) {
101101
// return Result.err(fileCostResult.getErr());
102102
// }
103-
103+
104104
// const mintCostResult = await this.mintsCreditManager.getCost();
105105
// if (mintCostResult.isErr()) {
106106
// return Result.err(mintCostResult.getErr());
@@ -117,18 +117,18 @@ export class AithraManager {
117117
const currentSolPrice = data.solana.usd;
118118

119119
const solAmount = GENERATE_MUSIC_MEME_PRICE_IN_USD / currentSolPrice;
120-
120+
121121
return Result.ok(Number(solAmount.toFixed(4)))
122-
122+
123123
} catch (error) {
124124
console.error("Failed to fetch SOL price:", error);
125-
Result.err(new Error(error));
125+
Result.err(new Error(error));
126126
}
127127
}
128128

129129

130130
async buildUploadMintMusicNFTs(params: BuildUploadMintMusicNFTsParams): Promise<Result<BuildMusicNFTResult, Error>> {
131-
// 1. Build playlist config
131+
aithraToolkitLogger.debug('Entering buildUploadMintMusicNFTs');
132132
const playlistResult = await buildPlaylistConfig(
133133
params.folderPath,
134134
params.playlist.name,
@@ -160,11 +160,13 @@ export class AithraManager {
160160
logger.info('Files uploaded successfully');
161161

162162
// 3. Build and upload manifest
163+
aithraToolkitLogger.debug('Getting the Manifest Builder');
163164
const builderResult = ManifestBuilderFactory.getBuilder(ManifestType.MusicPlaylist);
164165
if (builderResult.isErr()) {
165166
return Result.err(builderResult.getErr());
166167
}
167168

169+
aithraToolkitLogger.debug('Building the manifest file');
168170
const manifestResult = await builderResult.unwrap().buildManifest(
169171
ManifestType.MusicPlaylist,
170172
uploadResult.unwrap(),
@@ -240,12 +242,14 @@ export class AithraManager {
240242
logger.info('Encrypted data stream URL successfully');
241243

242244
nftConfig.itheumDataStreamUrl = encryptResult.unwrap().encryptedMessage;
243-
245+
246+
aithraToolkitLogger.debug('Getting the Nft Metadata Builder');
244247
const builderNftResult = NFTMetadataBuilderFactory.getBuilder(NFTTypes.Music);
245248
if (builderNftResult.isErr()) {
246249
return Result.err(builderNftResult.getErr());
247250
}
248251

252+
aithraToolkitLogger.debug('Building the NFT metadata');
249253
const metadataResult = builderNftResult.unwrap().buildMetadata(nftConfig);
250254
if (metadataResult.isErr()) {
251255
return Result.err(metadataResult.getErr());
@@ -300,16 +304,18 @@ export class AithraManager {
300304
`NFTs minted: ${mintResult.unwrap().length} with assetIds: ${mintResult.unwrap().join(', ')}`
301305
);
302306

307+
aithraToolkitLogger.debug('Exiting buildUploadMintMusicNFTs');
303308
return Result.ok({
304309
success: true,
305310
assetIds: mintResult.unwrap(),
306311
animationUrl: animationUrl,
307312
trackUrl: trackUrl,
308-
trackImageUrl:trackImageUrl
313+
trackImageUrl: trackImageUrl
309314
});
310315
}
311316

312317
private async handleAnimation(animation: { animationUrl?: string; animationFile?: string }): Promise<Result<string, Error>> {
318+
aithraToolkitLogger.debug('Entering handleAnimation');
313319
if (animation.animationUrl) {
314320
return Result.ok(animation.animationUrl);
315321
}
@@ -338,6 +344,7 @@ export class AithraManager {
338344
return Result.err(uploadResult.getErr());
339345
}
340346

347+
aithraToolkitLogger.debug('Exiting handleAnimation');
341348
logger.info('Animation file uploaded successfully');
342349
return Result.ok(`https://gateway.lighthouse.storage/ipfs/${uploadResult.unwrap()[0].hash}`);
343350
}

src/core/manifestFactory.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Result } from '../result';
2+
import { aithraToolkitLogger } from './logger';
23
import {
34
BaseManifest,
45
IManifestBuilder,
@@ -25,6 +26,7 @@ export class MusicPlaylistBuilder implements IManifestBuilder {
2526
uploadedFiles: UploadedFile[],
2627
config: MusicPlaylistConfig
2728
): Promise<Result<MusicPlaylistManifest, Error>> {
29+
aithraToolkitLogger.debug('Entering buildManifest');
2830
try {
2931
const now = new Date().toISOString();
3032
const date = now.split('T')[0];
@@ -80,7 +82,7 @@ export class MusicPlaylistBuilder implements IManifestBuilder {
8082
title: metadata.title
8183
});
8284
}
83-
85+
aithraToolkitLogger.debug('Exiting buildManifest');
8486
return Result.ok(manifest);
8587
} catch (err) {
8688
return Result.err(

src/core/marshalManager.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from './types';
88
import { Result } from '../result';
99
import axios from 'axios';
10+
import { aithraToolkitLogger } from './logger';
1011

1112
export class MarshalManager implements IMarshalManager {
1213
private readonly apiBaseUrl: string;
@@ -16,6 +17,7 @@ export class MarshalManager implements IMarshalManager {
1617
}
1718

1819
async encrypt(params: IEncryptParams): Promise<Result<IEncryptResponse, Error>> {
20+
aithraToolkitLogger.debug('Entering encrypt');
1921
if (!params.dataNFTStreamUrl) {
2022
return Result.err(new Error('dataNFTStreamUrl is required for generation'));
2123
}
@@ -32,6 +34,7 @@ export class MarshalManager implements IMarshalManager {
3234
}
3335
);
3436

37+
aithraToolkitLogger.debug('Exiting encrypt');
3538
return Result.ok(response.data);
3639
} catch (err) {
3740
return Result.err(
@@ -43,6 +46,7 @@ export class MarshalManager implements IMarshalManager {
4346
async decrypt(
4447
params: IMarshalDecryptParams
4548
): Promise<Result<IMarshalDecryptResponse, Error>> {
49+
aithraToolkitLogger.debug('Entering decrypt');
4650
if (!params.encryptedMessage) {
4751
return Result.err(new Error('encryptedMessage is required for decryption'));
4852
}
@@ -58,7 +62,7 @@ export class MarshalManager implements IMarshalManager {
5862
}
5963
}
6064
);
61-
65+
aithraToolkitLogger.debug('Exiting decrypt');
6266
return Result.ok(response.data);
6367
} catch (err) {
6468
return Result.err(

src/core/mintManager.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import axios from 'axios';
22
import { Result } from '../result';
33
import { MintConfig, MintManagerParams, IMintManager } from './types';
4+
import { aithraToolkitLogger } from './logger';
45

56
export class MintManager implements IMintManager {
67
private readonly apiBaseUrl: string;
@@ -10,7 +11,7 @@ export class MintManager implements IMintManager {
1011
}
1112

1213
async mint(params: MintManagerParams): Promise<Result<string[], Error>> {
13-
// Validate input parameters
14+
aithraToolkitLogger.debug('Entering mint');
1415
if (!params.config || !params.address || !params.paymentHash) {
1516
return Result.err(new Error('Missing required parameters'));
1617
}
@@ -28,6 +29,7 @@ export class MintManager implements IMintManager {
2829
}
2930
);
3031

32+
aithraToolkitLogger.debug('Exiting mint');
3133
const { assetIds } = response.data;
3234
return Result.ok(assetIds as string[]);
3335
} catch (error) {

0 commit comments

Comments
 (0)