Round up MTM prices to nearest integer

This commit is contained in:
Adw8 2025-02-06 11:40:28 +05:30
parent affab021a3
commit d476f42066
5 changed files with 27 additions and 21 deletions

View File

@ -3,8 +3,8 @@ FAL_AI_KEY=
NEXT_PUBLIC_MTM_TOKEN_MINT=97RggLo3zV5kFGYW4yoQTxr4Xkz4Vg2WPHzNYXXWpump
NEXT_PUBLIC_PAYMENT_RECEIVER_ADDRESS=FFDx3SdAEeXrp6BTmStB4BDHpctGsaasZq4FFcowRobY
NEXT_PUBLIC_SOLANA_RPC_URL=https://young-radial-orb.solana-mainnet.quiknode.pro/67612b364664616c29514e551bf5de38447ca3d4
NEXT_PUBLIC_SOLANA_WEBSOCKET_URL=wss://young-radial-orb.solana-mainnet.quiknode.pro/67612b364664616c29514e551bf5de38447ca3d4
NEXT_PUBLIC_SOLANA_RPC_URL=https://skilled-prettiest-seed.solana-mainnet.quiknode.pro/eeecfebd04e345f69f1900cc3483cbbfea02a158
NEXT_PUBLIC_SOLANA_WEBSOCKET_URL=wss://skilled-prettiest-seed.solana-mainnet.quiknode.pro/eeecfebd04e345f69f1900cc3483cbbfea02a158
NEXT_PUBLIC_USDC_MINT=EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
# Generate a key at https://app.pinata.cloud/developers/api-keys
@ -17,3 +17,10 @@ PINATA_GATEWAY=
# For development: SITE_URL=http://localhost:3000
SITE_URL=https://memes.markto.market
NEXT_PUBLIC_ACCOUNT_HANDLE=
WSOL_LOCKER_PRIVATE_KEY=
WSOL_MINT=So11111111111111111111111111111111111111112
# Duration in seconds that WSOL will be locked for
CLIFF_TIME=172800 # 48 hours
REWARD_MULTIPLIER=4

View File

@ -27,13 +27,13 @@ async function extractInfo(transactionSignature: string) {
}
async function createRewardLock(authority: string, amount: string) {
const { USER_PRIVATE_KEY, CLIFF_TIME, WSOL_MINT, NEXT_PUBLIC_MTM_TOKEN_MINT, REWARD_MULTIPLIER } = process.env;
if (!USER_PRIVATE_KEY || !CLIFF_TIME || !WSOL_MINT || !NEXT_PUBLIC_MTM_TOKEN_MINT || !REWARD_MULTIPLIER) {
const { WSOL_LOCKER_PRIVATE_KEY, CLIFF_TIME, WSOL_MINT, NEXT_PUBLIC_MTM_TOKEN_MINT, REWARD_MULTIPLIER } = process.env;
if (!WSOL_LOCKER_PRIVATE_KEY || !CLIFF_TIME || !WSOL_MINT || !NEXT_PUBLIC_MTM_TOKEN_MINT || !REWARD_MULTIPLIER) {
throw new Error('Missing required environment variables');
}
const duration = new BN(CLIFF_TIME).add(new BN(Math.floor(Date.now() / 1000)));
const tokenLockerKeypair = Keypair.fromSecretKey(bs58.decode(USER_PRIVATE_KEY));
const tokenLockerKeypair = Keypair.fromSecretKey(bs58.decode(WSOL_LOCKER_PRIVATE_KEY));
const recipientPublicKey = new PublicKey(authority);
const url = `https://api.jup.ag/price/v2?ids=${NEXT_PUBLIC_MTM_TOKEN_MINT}&vsToken=${WSOL_MINT}`;

View File

@ -21,11 +21,11 @@ interface GenerationState {
error: string | null
}
const baseUnitToDecimalFormat = (value: BN, decimals: number): string => {
const baseUnitToWholeNumber = (value: BN, decimals: number): string => {
const bigValue = new Big(value.toString());
const factor = new Big(10).pow(decimals);
return bigValue.div(factor).toFixed(decimals);
return bigValue.div(factor).round(0, Big.roundUp).toFixed(0);
}
const AIServiceCard: React.FC<AIServiceCardProps> = ({
@ -93,11 +93,11 @@ const AIServiceCard: React.FC<AIServiceCardProps> = ({
const generateTwitterShareUrl = (imageUrl: string, transactionSignature: string): string => {
const baseUrl = window.location.href;
const cid = imageUrl.split("/image/")[1];
const memeUrl = `${baseUrl}memes/${cid}`;
const memePageUrl = `${baseUrl}memes/${cid}`;
const tweetText = `Check out this meme that I generated! \n TX Hash: '${transactionSignature}' \n @${process.env.NEXT_PUBLIC_ACCOUNT_HANDLE} \n`;
return `https://twitter.com/intent/tweet?text=${encodeURIComponent(tweetText)}&url=${encodeURIComponent(memeUrl)}`;
return `https://twitter.com/intent/tweet?text=${encodeURIComponent(tweetText)}&url=${encodeURIComponent(memePageUrl)}`;
};
return (
@ -109,7 +109,7 @@ const AIServiceCard: React.FC<AIServiceCardProps> = ({
</h2>
<p className="text-gray-400 mt-2">{description}</p>
<div className="mt-2 inline-block px-3 py-1 bg-green-500/20 rounded-full text-green-300 text-sm">
Cost: {priceMTM ? baseUnitToDecimalFormat(priceMTM, 6) : '...'} MTM
Cost: {priceMTM ? baseUnitToWholeNumber(priceMTM, 6) : '...'} MTM
</div>
</div>
@ -133,7 +133,7 @@ const AIServiceCard: React.FC<AIServiceCardProps> = ({
transition-all duration-200 shadow-lg hover:shadow-green-500/25
disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:shadow-none"
>
{generationState.loading ? 'Processing...' : `Pay ${priceMTM ? baseUnitToDecimalFormat(priceMTM, 6) : '...'} MTM & Generate`}
{generationState.loading ? 'Processing...' : `Pay ${priceMTM ? baseUnitToWholeNumber(priceMTM, 6) : '...'} MTM & Generate`}
</button>
</div>

View File

@ -35,9 +35,9 @@ import {
RemainingAccountsType,
} from './token-2022/remaining-accounts';
assert(process.env.RPC_ENDPOINT);
assert(process.env.NEXT_PUBLIC_SOLANA_RPC_URL);
const connection = new Connection(process.env.RPC_ENDPOINT);
const connection = new Connection(process.env.NEXT_PUBLIC_SOLANA_RPC_URL);
const ESCROW_USE_SPL_TOKEN = 0;
@ -116,7 +116,7 @@ export async function createVestingPlanV2(params: CreateVestingPlanParams) {
ASSOCIATED_TOKEN_PROGRAM_ID
);
let remainingAccountsInfo = null;
let remainingAccountsInfo;
let remainingAccounts: AccountMeta[] = [];
if (tokenProgram == TOKEN_2022_PROGRAM_ID) {
let inputTransferHookAccounts =
@ -225,7 +225,7 @@ export async function claimTokenV2(params: ClaimTokenParamsV2) {
ASSOCIATED_TOKEN_PROGRAM_ID
);
let remainingAccountsInfo = null;
let remainingAccountsInfo;
let remainingAccounts: AccountMeta[] | undefined = [];
if (tokenProgram == TOKEN_2022_PROGRAM_ID) {
let claimTransferHookAccounts =

View File

@ -11,16 +11,15 @@ import { Connection, PublicKey } from "@solana/web3.js";
import { createVestingPlanV2 } from '../locker-utils';
assert(process.env.RPC_ENDPOINT);
assert(process.env.USER_PRIVATE_KEY);
//assert(process.env.RECIPIENT_PUBLIC_KEY);
assert(process.env.NEXT_PUBLIC_SOLANA_RPC_URL);
assert(process.env.WSOL_LOCKER_PRIVATE_KEY);
assert(process.env.WSOL_MINT);
const RPC_ENDPOINT= process.env.RPC_ENDPOINT;
const RPC_ENDPOINT= process.env.NEXT_PUBLIC_SOLANA_RPC_URL;
const WSOL_MINT = process.env.WSOL_MINT;
const USER_PRIVATE_KEY = process.env.USER_PRIVATE_KEY;
const WSOL_LOCKER_PRIVATE_KEY = process.env.WSOL_LOCKER_PRIVATE_KEY;
const userKP = anchor.web3.Keypair.fromSecretKey(bs58.decode(USER_PRIVATE_KEY));
const userKP = anchor.web3.Keypair.fromSecretKey(bs58.decode(WSOL_LOCKER_PRIVATE_KEY));
const connection = new Connection(RPC_ENDPOINT);
const token = new PublicKey(WSOL_MINT);