@@ -3,8 +3,6 @@ package currencycreator
33import (
44 "math"
55 "math/big"
6-
7- "github.com/code-payments/code-server/pkg/usdc"
86)
97
108func EstimateCurrentPrice (currentSupplyInQuarks uint64 ) * big.Float {
@@ -14,14 +12,38 @@ func EstimateCurrentPrice(currentSupplyInQuarks uint64) *big.Float {
1412 return DefaultExponentialCurve ().SpotPriceAtSupply (scaledCurrentSupply )
1513}
1614
17- type EstimateBuyInUsdcArgs struct {
15+ type EstimateValueExchangeArgs struct {
16+ ValueInQuarks uint64
17+ CurrentSupplyInQuarks uint64
18+ ValueMintDecimals uint8
19+ }
20+
21+ func EstimateValueExchange (args * EstimateValueExchangeArgs ) uint64 {
22+ scale := big .NewFloat (math .Pow10 (int (args .ValueMintDecimals ))).SetPrec (defaultCurvePrec )
23+ unscaledValue := big .NewFloat (float64 (args .ValueInQuarks )).SetPrec (defaultCurvePrec )
24+ scaledValue := new (big.Float ).Quo (unscaledValue , scale )
25+
26+ scale = big .NewFloat (math .Pow10 (int (DefaultMintDecimals ))).SetPrec (defaultCurvePrec )
27+ unscaledCurrentSupply := big .NewFloat (float64 (args .CurrentSupplyInQuarks )).SetPrec (defaultCurvePrec )
28+ scaledCurrentSupply := new (big.Float ).Quo (unscaledCurrentSupply , scale )
29+
30+ scale = big .NewFloat (math .Pow10 (int (DefaultMintDecimals ))).SetPrec (defaultCurvePrec )
31+ scaledTokens := DefaultExponentialCurve ().TokensForValueExchange (scaledCurrentSupply , scaledValue )
32+ unscaledTokens := new (big.Float ).Mul (scaledTokens , scale )
33+
34+ quarks , _ := unscaledTokens .Int64 ()
35+ return uint64 (quarks )
36+ }
37+
38+ type EstimateBuyArgs struct {
1839 BuyAmountInQuarks uint64
1940 CurrentSupplyInQuarks uint64
41+ ValueMintDecimals uint8
2042 BuyFeeBps uint16
2143}
2244
23- func EstimateBuyInUsdc (args * EstimateBuyInUsdcArgs ) (uint64 , uint64 ) {
24- scale := big .NewFloat (math .Pow10 (int (usdc . Decimals ))).SetPrec (defaultCurvePrec )
45+ func EstimateBuy (args * EstimateBuyArgs ) (uint64 , uint64 ) {
46+ scale := big .NewFloat (math .Pow10 (int (args . ValueMintDecimals ))).SetPrec (defaultCurvePrec )
2547 unscaledBuyAmount := big .NewFloat (float64 (args .BuyAmountInQuarks )).SetPrec (defaultCurvePrec )
2648 scaledBuyAmount := new (big.Float ).Quo (unscaledBuyAmount , scale )
2749
@@ -30,7 +52,7 @@ func EstimateBuyInUsdc(args *EstimateBuyInUsdcArgs) (uint64, uint64) {
3052 scaledCurrentSupply := new (big.Float ).Quo (unscaledCurrentSupply , scale )
3153
3254 scale = big .NewFloat (math .Pow10 (int (DefaultMintDecimals ))).SetPrec (defaultCurvePrec )
33- scaledTokens := DefaultExponentialCurve ().ValueToTokens (scaledCurrentSupply , scaledBuyAmount )
55+ scaledTokens := DefaultExponentialCurve ().TokensBoughtForValue (scaledCurrentSupply , scaledBuyAmount )
3456 unscaledTokens := new (big.Float ).Mul (scaledTokens , scale )
3557
3658 scale = big .NewFloat (math .Pow10 (int (DefaultMintDecimals ))).SetPrec (defaultCurvePrec )
@@ -43,26 +65,27 @@ func EstimateBuyInUsdc(args *EstimateBuyInUsdcArgs) (uint64, uint64) {
4365 return uint64 (tokens - fees ), uint64 (fees )
4466}
4567
46- type EstimateSellInUsdcArgs struct {
68+ type EstimateSellArgs struct {
4769 SellAmountInQuarks uint64
4870 CurrentValueInQuarks uint64
71+ ValueMintDecimals uint8
4972 SellFeeBps uint16
5073}
5174
52- func EstimateSellInUsdc (args * EstimateSellInUsdcArgs ) (uint64 , uint64 ) {
75+ func EstimateSell (args * EstimateSellArgs ) (uint64 , uint64 ) {
5376 scale := big .NewFloat (math .Pow10 (int (DefaultMintDecimals ))).SetPrec (defaultCurvePrec )
5477 unscaledSellAmount := big .NewFloat (float64 (args .SellAmountInQuarks )).SetPrec (defaultCurvePrec )
5578 scaledSellAmount := new (big.Float ).Quo (unscaledSellAmount , scale )
5679
57- scale = big .NewFloat (math .Pow10 (int (usdc . Decimals ))).SetPrec (defaultCurvePrec )
80+ scale = big .NewFloat (math .Pow10 (int (args . ValueMintDecimals ))).SetPrec (defaultCurvePrec )
5881 unscaledCurrentValue := big .NewFloat (float64 (args .CurrentValueInQuarks )).SetPrec (defaultCurvePrec )
5982 scaledCurrentValue := new (big.Float ).Quo (unscaledCurrentValue , scale )
6083
61- scale = big .NewFloat (math .Pow10 (int (usdc . Decimals ))).SetPrec (defaultCurvePrec )
62- scaledValue := DefaultExponentialCurve ().TokensToValueFromCurrentValue (scaledCurrentValue , scaledSellAmount )
84+ scale = big .NewFloat (math .Pow10 (int (args . ValueMintDecimals ))).SetPrec (defaultCurvePrec )
85+ scaledValue := DefaultExponentialCurve ().ValueFromSellingTokens (scaledCurrentValue , scaledSellAmount )
6386 unscaledValue := new (big.Float ).Mul (scaledValue , scale )
6487
65- scale = big .NewFloat (math .Pow10 (int (usdc . Decimals ))).SetPrec (defaultCurvePrec )
88+ scale = big .NewFloat (math .Pow10 (int (args . ValueMintDecimals ))).SetPrec (defaultCurvePrec )
6689 feePctValue := new (big.Float ).SetPrec (defaultCurvePrec ).Quo (big .NewFloat (float64 (args .SellFeeBps )), big .NewFloat (10000 ))
6790 scaledFees := new (big.Float ).Mul (scaledValue , feePctValue )
6891 unscaledFees := new (big.Float ).Mul (scaledFees , scale )
0 commit comments