Skip to content

Commit 002ee7c

Browse files
committed
feat: update version to 0.0.7-alpha.3 and refactor getTotalCost to fetch current SOL price
1 parent a1ae34d commit 002ee7c

File tree

2 files changed

+34
-20
lines changed

2 files changed

+34
-20
lines changed

package.json

Lines changed: 1 addition & 1 deletion
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.2",
3+
"version": "0.0.7-alpha.3",
44
"description": "The Aithra Network Toolkit SDK for the agents",
55
"main": "dist/index.js",
66
"module": "dist/index.mjs",

src/core/manager.ts

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -85,33 +85,47 @@ export class AithraManager {
8585
}
8686

8787
async getTotalCost(numberOfSongs: number, numberOfMints: number): Promise<Result<number, Error>> {
88-
const generateSongPrice = 0.035;
88+
// const generateSongPrice = 0.035;
8989

90-
const priceResult = await this.mintsCreditManager.getAithraPriceInUsd();
91-
if (priceResult.isErr()) {
92-
return Result.err(priceResult.getErr());
93-
}
94-
const aithraUsdPrice = priceResult.unwrap() || 0.001;
90+
// const priceResult = await this.mintsCreditManager.getAithraPriceInUsd();
91+
// if (priceResult.isErr()) {
92+
// return Result.err(priceResult.getErr());
93+
// }
94+
// const aithraUsdPrice = priceResult.unwrap() || 0.001;
9595

96-
const generateSongPriceAithra = generateSongPrice / aithraUsdPrice;
96+
// const generateSongPriceAithra = generateSongPrice / aithraUsdPrice;
9797

98-
const fileCostResult = await this.filesCreditManager.getCost();
99-
if (fileCostResult.isErr()) {
100-
return Result.err(fileCostResult.getErr());
101-
}
98+
// const fileCostResult = await this.filesCreditManager.getCost();
99+
// if (fileCostResult.isErr()) {
100+
// return Result.err(fileCostResult.getErr());
101+
// }
102102

103-
const mintCostResult = await this.mintsCreditManager.getCost();
104-
if (mintCostResult.isErr()) {
105-
return Result.err(mintCostResult.getErr());
106-
}
103+
// const mintCostResult = await this.mintsCreditManager.getCost();
104+
// if (mintCostResult.isErr()) {
105+
// return Result.err(mintCostResult.getErr());
106+
// }
107+
108+
// const totalCost = (numberOfSongs * fileCostResult.unwrap() + 2 * fileCostResult.unwrap()) +
109+
// (numberOfMints * mintCostResult.unwrap()) +
110+
// (numberOfSongs * generateSongPriceAithra);
107111

108-
const totalCost = (numberOfSongs * fileCostResult.unwrap() + 2 * fileCostResult.unwrap()) +
109-
(numberOfMints * mintCostResult.unwrap()) +
110-
(numberOfSongs * generateSongPriceAithra);
112+
const GENERATE_MUSIC_MEME_PRICE_IN_USD = 0.3;
113+
try {
114+
const response = await fetch("https://api.coingecko.com/api/v3/simple/price?ids=solana&vs_currencies=usd");
115+
const data = await response.json();
116+
const currentSolPrice = data.solana.usd;
111117

112-
return Result.ok(totalCost);
118+
const solAmount = GENERATE_MUSIC_MEME_PRICE_IN_USD / currentSolPrice;
119+
120+
return Result.ok(Number(solAmount.toFixed(4)))
121+
122+
} catch (error) {
123+
console.error("Failed to fetch SOL price:", error);
124+
Result.err(new Error(error));
125+
}
113126
}
114127

128+
115129
async buildUploadMintMusicNFTs(params: BuildUploadMintMusicNFTsParams): Promise<Result<BuildMusicNFTResult, Error>> {
116130
// 1. Build playlist config
117131
const playlistResult = await buildPlaylistConfig(

0 commit comments

Comments
 (0)