@@ -3,79 +3,73 @@ package currencycreator
33import (
44 "math"
55 "math/big"
6+
7+ "github.com/code-payments/code-server/pkg/usdc"
68)
79
810type EstimateCurrentPriceArgs struct {
9- Curve * ExponentialCurve
1011 CurrentSupplyInQuarks uint64
11- MintDecimals uint8
1212}
1313
14- func EstimateCurrentPrice (args * EstimateCurrentPriceArgs ) * big.Float {
15- scale := big .NewFloat (math .Pow10 (int (args . MintDecimals ))).SetPrec (defaultCurvePrec )
16- unscaledCurrentSupply := big .NewFloat (float64 (args . CurrentSupplyInQuarks )).SetPrec (defaultCurvePrec )
14+ func EstimateCurrentPrice (currentSupplyInQuarks uint64 ) * big.Float {
15+ scale := big .NewFloat (math .Pow10 (int (DefaultMintDecimals ))).SetPrec (defaultCurvePrec )
16+ unscaledCurrentSupply := big .NewFloat (float64 (currentSupplyInQuarks )).SetPrec (defaultCurvePrec )
1717 scaledCurrentSupply := new (big.Float ).Quo (unscaledCurrentSupply , scale )
18- return args . Curve .SpotPriceAtSupply (scaledCurrentSupply )
18+ return DefaultExponentialCurve () .SpotPriceAtSupply (scaledCurrentSupply )
1919}
2020
21- type EstimateBuyArgs struct {
21+ type EstimateBuyInUsdcArgs struct {
2222 BuyAmountInQuarks uint64
23- Curve * ExponentialCurve
2423 CurrentSupplyInQuarks uint64
2524 BuyFeeBps uint16
26- TargetMintDecimals uint8
27- BaseMintDecimals uint8
2825}
2926
30- func EstimateBuy (args * EstimateBuyArgs ) (uint64 , uint64 ) {
31- scale := big .NewFloat (math .Pow10 (int (args . BaseMintDecimals ))).SetPrec (defaultCurvePrec )
27+ func EstimateBuyInUsdc (args * EstimateBuyInUsdcArgs ) (uint64 , uint64 ) {
28+ scale := big .NewFloat (math .Pow10 (int (usdc . Decimals ))).SetPrec (defaultCurvePrec )
3229 unscaledBuyAmount := big .NewFloat (float64 (args .BuyAmountInQuarks )).SetPrec (defaultCurvePrec )
3330 scaledBuyAmount := new (big.Float ).Quo (unscaledBuyAmount , scale )
3431
35- scale = big .NewFloat (math .Pow10 (int (args . TargetMintDecimals ))).SetPrec (defaultCurvePrec )
32+ scale = big .NewFloat (math .Pow10 (int (DefaultMintDecimals ))).SetPrec (defaultCurvePrec )
3633 unscaledCurrentSupply := big .NewFloat (float64 (args .CurrentSupplyInQuarks )).SetPrec (defaultCurvePrec )
3734 scaledCurrentSupply := new (big.Float ).Quo (unscaledCurrentSupply , scale )
3835
39- scale = big .NewFloat (math .Pow10 (int (args . TargetMintDecimals ))).SetPrec (defaultCurvePrec )
40- scaledTotalValue := args . Curve .ValueToTokens (scaledCurrentSupply , scaledBuyAmount )
41- unscaledTotalValue := new (big.Float ).Mul (scaledTotalValue , scale )
36+ scale = big .NewFloat (math .Pow10 (int (DefaultMintDecimals ))).SetPrec (defaultCurvePrec )
37+ scaledTokens := DefaultExponentialCurve () .ValueToTokens (scaledCurrentSupply , scaledBuyAmount )
38+ unscaledTokens := new (big.Float ).Mul (scaledTokens , scale )
4239
4340 feePctValue := new (big.Float ).SetPrec (defaultCurvePrec ).Quo (big .NewFloat (float64 (args .BuyFeeBps )), big .NewFloat (10000 ))
44- scaledFees := new (big.Float ).Mul (scaledTotalValue , feePctValue )
41+ scaledFees := new (big.Float ).Mul (scaledTokens , feePctValue )
4542 unscaledFees := new (big.Float ).Mul (scaledFees , scale )
4643
47- total , _ := unscaledTotalValue .Int64 ()
44+ tokens , _ := unscaledTokens .Int64 ()
4845 fees , _ := unscaledFees .Int64 ()
49- return uint64 (total - fees ), uint64 (fees )
46+ return uint64 (tokens - fees ), uint64 (fees )
5047}
5148
52- type EstimateSaleArgs struct {
53- SellAmountInQuarks uint64
54- Curve * ExponentialCurve
55- CurrentSupplyInQuarks uint64
56- SellFeeBps uint16
57- TargetMintDecimals uint8
58- BaseMintDecimals uint8
49+ type EstimateSellInUsdcArgs struct {
50+ SellAmountInQuarks uint64
51+ CurrentValueInQuarks uint64
52+ SellFeeBps uint16
5953}
6054
61- func EstimateSale (args * EstimateSaleArgs ) (uint64 , uint64 ) {
62- scale := big .NewFloat (math .Pow10 (int (args . TargetMintDecimals ))).SetPrec (defaultCurvePrec )
55+ func EstimateSellInUsdc (args * EstimateSellInUsdcArgs ) (uint64 , uint64 ) {
56+ scale := big .NewFloat (math .Pow10 (int (DefaultMintDecimals ))).SetPrec (defaultCurvePrec )
6357 unscaledSellAmount := big .NewFloat (float64 (args .SellAmountInQuarks )).SetPrec (defaultCurvePrec )
6458 scaledSellAmount := new (big.Float ).Quo (unscaledSellAmount , scale )
6559
66- scale = big .NewFloat (math .Pow10 (int (args . TargetMintDecimals ))).SetPrec (defaultCurvePrec )
67- unscaledCurrentSupply := big .NewFloat (float64 (args .CurrentSupplyInQuarks )).SetPrec (defaultCurvePrec )
68- scaledCurrentSupply := new (big.Float ).Quo (unscaledCurrentSupply , scale )
60+ scale = big .NewFloat (math .Pow10 (int (DefaultMintDecimals ))).SetPrec (defaultCurvePrec )
61+ unscaledCurrentValue := big .NewFloat (float64 (args .CurrentValueInQuarks )).SetPrec (defaultCurvePrec )
62+ scaledCurrentValue := new (big.Float ).Quo (unscaledCurrentValue , scale )
6963
70- scale = big .NewFloat (math .Pow10 (int (args . BaseMintDecimals ))).SetPrec (defaultCurvePrec )
71- scaledTotalValue := args . Curve . TokensToValue ( scaledCurrentSupply , scaledSellAmount )
72- unscaledTotalValue := new (big.Float ).Mul (scaledTotalValue , scale )
64+ scale = big .NewFloat (math .Pow10 (int (usdc . Decimals ))).SetPrec (defaultCurvePrec )
65+ scaledValue := DefaultExponentialCurve (). TokensToValueFromCurrentValue ( scaledCurrentValue , scaledSellAmount )
66+ unscaledValue := new (big.Float ).Mul (scaledValue , scale )
7367
7468 feePctValue := new (big.Float ).SetPrec (defaultCurvePrec ).Quo (big .NewFloat (float64 (args .SellFeeBps )), big .NewFloat (10000 ))
75- scaledFees := new (big.Float ).Mul (scaledTotalValue , feePctValue )
69+ scaledFees := new (big.Float ).Mul (scaledValue , feePctValue )
7670 unscaledFees := new (big.Float ).Mul (scaledFees , scale )
7771
78- total , _ := unscaledTotalValue .Int64 ()
72+ value , _ := unscaledValue .Int64 ()
7973 fees , _ := unscaledFees .Int64 ()
80- return uint64 (total - fees ), uint64 (fees )
74+ return uint64 (value - fees ), uint64 (fees )
8175}
0 commit comments