Skip to main content

Questions tagged [math]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
0 answers

Constant Price Curve Implementation

I implemented a constant price curve using the following formula (initialDeposit/totalSupply) * 1 + log(1 + initialDeposit) But this is not fair and don't increase price until initialDeposit ...
Oasis Inc's user avatar
3 votes
1 answer

Get Fraction of SOL Balance

I have a u128 total and a u128 user_total. I also have a balance and want the user to be able to withdraw (balance * user_total) / (total * multiplier) What is the best way to do this to avoid ...
Varun Siva's user avatar
0 votes
1 answer

is 1000000 1 unit of USDC?

I'm working on a custom program that swaps coins on Jupiter Station. Is basically a Go program that connects via gRPC to a Node.js script (written entirely with Typescript) and performs the swap using ...
shackra's user avatar
  • 105
1 vote
1 answer

Creating a single sided vault, using float for calculating ratio

When making a single sided vault, aka deposit X get Y. is it safe to just use a float to get the ratio? right now I just calculate the ratio with like so: (x_underlying_token_account_amount as f64) / (...
anchor noob's user avatar
3 votes
1 answer

What is the best way to do "safe math" in rust or anchor programs?

I know with rust you need to be sure you do not cause buffer overflows/underflows when performing math operations. What are the best practices for doing common math safely within programs? Adding, ...
nickfrosty's user avatar
  • 1,048
0 votes
1 answer

fee basis points calculation in rust

This is more of a general rust question but feels like a common enough situation when writing solana contracts such that I feel justified in asking it here. Suppose I have a token with decimals set to ...
Rohan Kapur's user avatar
0 votes
1 answer

How do I include the Decimal struct in the anchor idl?

I have copied the math section from the token lending program here Decimal struct is as below // U192 ...
escargo's user avatar
  • 15
1 vote
1 answer

Basic division for token math

Here's a common scenario: Suppose an associated token account has 100 tokens of a token whose Decimal is 8. If we scale up the balance wrt the decimals of the token, the balance is 100 * 10^8, or ...
Rohan Kapur's user avatar
0 votes
1 answer

Using floating points such as f64 in your programs

What is the community take on doing fixed point arithmetic vs intermediary casting to f64 to minimize precision loss? Recently I saw code using f64 that got me wondering what the go-to way or standard ...
Nabeel Naveed's user avatar
9 votes
1 answer

Rust math library for large numbers?

I see a lot of folks rolling hairy implementations for dealing with u128, u256. Integer square roots, etc. Are there any general purpose libraries that folks have seen?
joebuild's user avatar
  • 455