Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Improvement & Bug Fixes #25

Merged
merged 7 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
"commands": [
"dotnet-format"
]
},
"dotnet-reportgenerator-globaltool": {
"version": "5.1.15",
"commands": [
"reportgenerator"
]
}
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -615,3 +615,4 @@ riderModule.iml
/_ReSharper.Caches/
_site/
api/
test-ledger/
205 changes: 130 additions & 75 deletions src/Solana.Unity.Dex/IDex.cs

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions src/Solana.Unity.Dex/Math/DecimalUtil.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Numerics;

namespace Solana.Unity.Dex.Math;

public class DecimalUtil
{
public static double FromUlong(ulong value, int shift = 0)
{
return value / System.Math.Pow(10, shift);
}

public static double FromBigInteger(BigInteger value, int shift = 0)
{
return FromUlong((ulong)value, shift);
}

public static ulong ToUlong(double value, int shift = 0)
{
return (ulong)(value * System.Math.Pow(10, shift));
}

public static ulong ToUlong(float value, int shift = 0)
{
return ToUlong((double)value, shift);
}
}
16 changes: 16 additions & 0 deletions src/Solana.Unity.Dex/Models/Pool.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Solana.Unity.Wallet;
using System.Numerics;

namespace Solana.Unity.Dex.Models;

public class Pool
{
public PublicKey Address { get; set; }

public PublicKey TokenMintA { get; set; }
public PublicKey TokenMintB { get; set; }

public BigInteger Liquidity { get; set; }
public ushort Fee { get; set; }
public ushort TickSpacing { get; set; }
}
4 changes: 2 additions & 2 deletions src/Solana.Unity.Dex/Orca/Math/SwapMath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ bool aToB
)
{
return (aToB == amountSpecifiedIsInput)
? TokenMath.GetAmountDeltaB(currentSqrtPrice, targetSqrtPrice, currentLiquidity, amountSpecifiedIsInput)
: TokenMath.GetAmountDeltaA(currentSqrtPrice, targetSqrtPrice, currentLiquidity, amountSpecifiedIsInput);
? TokenMath.GetAmountDeltaB(currentSqrtPrice, targetSqrtPrice, currentLiquidity, !amountSpecifiedIsInput)
: TokenMath.GetAmountDeltaA(currentSqrtPrice, targetSqrtPrice, currentLiquidity, !amountSpecifiedIsInput);
}
}
}
10 changes: 5 additions & 5 deletions src/Solana.Unity.Dex/Orca/Math/TokenMath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ bool roundUp
BigInteger numerator = currentLiquidity * sqrtPriceDiff << 64;
BigInteger denominator = sqrtPriceLower * sqrtPriceUpper;

BigInteger quotient = numerator / (denominator);
BigInteger remainder = numerator % (denominator);
BigInteger quotient = numerator / denominator;
BigInteger remainder = numerator % denominator;

var result = roundUp && remainder != 0 ? quotient + BigInteger.One : quotient;

Expand Down Expand Up @@ -59,8 +59,8 @@ BigInteger sqrtPrice1
)
{
return (sqrtPrice0 > sqrtPrice1) ?
Tuple.Create<BigInteger, BigInteger>(sqrtPrice1, sqrtPrice0) :
Tuple.Create<BigInteger, BigInteger>(sqrtPrice0, sqrtPrice1);
Tuple.Create(sqrtPrice1, sqrtPrice0) :
Tuple.Create(sqrtPrice0, sqrtPrice1);
}

public static BigInteger GetNextSqrtPrice(
Expand Down Expand Up @@ -108,7 +108,7 @@ bool amountSpecifiedIsInput

BigInteger denominator = amountSpecifiedIsInput
? currLiquidityShiftLeft + p
: currLiquidityShiftLeft + p;
: currLiquidityShiftLeft - p;

BigInteger price = BitMath.DivRoundUp(numerator, denominator);

Expand Down
Loading