Skip to content

Commit

Permalink
🐛 Improvement & Bug Fixes (#25)
Browse files Browse the repository at this point in the history
* 🐛 Improvement & Bug Fixes

* 🐛 Fix open/increase/decrease/collect/close with closed atas

Fix open/increase/decrease/collect/close with closed atas and added tests for native mint

* 🐛 Fix not deterministic bug with liquidity

* 🐛 Add fee payer

* 🐛 Remove test delay

* 🐛 Fix ATA & Set release to 0.1

* 🐛 Fix race condition in unit tests
  • Loading branch information
GabrielePicco authored Feb 20, 2023
1 parent 093e620 commit 29d66e2
Show file tree
Hide file tree
Showing 53 changed files with 2,762 additions and 722 deletions.
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

0 comments on commit 29d66e2

Please sign in to comment.