diff --git a/proto/reserve/psm/v1/psm.proto b/proto/reserve/psm/v1/psm.proto index 88473926..57383968 100644 --- a/proto/reserve/psm/v1/psm.proto +++ b/proto/reserve/psm/v1/psm.proto @@ -18,19 +18,19 @@ message StablecoinInfo { (gogoproto.nullable) = false, (amino.dont_omitempty) = true ]; - // stablecoin to nom exchange fee, fee_in when 1 stablecoin = 1nomUSD + // stablecoin to fxUSD exchange fee, fee_in when 1 stablecoin = 1fxUSD string fee_in = 3 [ (cosmos_proto.scalar) = "cosmos.Dec", (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", (gogoproto.nullable) = false ]; - // nom to stablecoin exchange fee, fee_out when 1 stablecoin = 1nomUSD + // fxUSD to stablecoin exchange fee, fee_out when 1 stablecoin = 1fxUSD string fee_out = 4 [ (cosmos_proto.scalar) = "cosmos.Dec", (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", (gogoproto.nullable) = false ]; - // amount of stablecoins locked in exchange for nomUSD + // amount of stablecoins locked in exchange for fxUSD string total_stablecoin_lock = 5 [ (cosmos_proto.scalar) = "cosmos.Int", (gogoproto.customtype) = "cosmossdk.io/math.Int", diff --git a/script/proposal-vault-1.json b/script/proposal-vault-1.json index 4eea5a14..588928e4 100644 --- a/script/proposal-vault-1.json +++ b/script/proposal-vault-1.json @@ -9,7 +9,7 @@ "max_debt":"1000000000000000000000000000", "collateral_oracle_script": "44", "mint_oracle_script":44, - "mint_denom": "nomUSD", + "mint_denom": "fxUSD", "mint_symbol":"USD", "stability_fee": "0.1" }, @@ -23,7 +23,7 @@ "max_debt":"1000000000000000000000000000", "collateral_oracle_script": "44", "mint_oracle_script":44, - "mint_denom": "nomUSD", + "mint_denom": "fxUSD", "mint_symbol":"USD", "stability_fee": "0.1" }], diff --git a/script/psm-test.sh b/script/psm-test.sh index 2823aa36..a3754bcb 100755 --- a/script/psm-test.sh +++ b/script/psm-test.sh @@ -134,14 +134,14 @@ sleep 15 # # reserved q psm all-stablecoin reserved q bank balances $(reserved keys show validator1 -a --keyring-backend test --home /Users/donglieu/.reserved/validator1) -# # # tx swap usdt to nomUSD +# # # tx swap usdt to fxUSD # # echo "========swap===========" -reserved tx psm swap 100000000000000000000000usdt nomUSD --from validator1 --keyring-backend test --home ~/.reserved/validator1 --chain-id testing-1 -y --fees 20stake +reserved tx psm swap 100000000000000000000000usdt fxUSD --from validator1 --keyring-backend test --home ~/.reserved/validator1 --chain-id testing-1 -y --fees 20stake sleep 7 -reserved tx psm swap 1000000000usdc nomUSD --from validator1 --keyring-backend test --home ~/.reserved/validator1 --chain-id testing-1 -y --fees 20stake +reserved tx psm swap 1000000000usdc fxUSD --from validator1 --keyring-backend test --home ~/.reserved/validator1 --chain-id testing-1 -y --fees 20stake sleep 7 -reserved tx psm swap 1000nomUSD usdc --from validator1 --keyring-backend test --home ~/.reserved/validator1 --chain-id testing-1 -y --fees 20stake +reserved tx psm swap 1000fxUSD usdc --from validator1 --keyring-backend test --home ~/.reserved/validator1 --chain-id testing-1 -y --fees 20stake sleep 7 -reserved tx psm swap 1000nomUSD usdt --from validator1 --keyring-backend test --home ~/.reserved/validator1 --chain-id testing-1 -y --fees 20stake +reserved tx psm swap 1000fxUSD usdt --from validator1 --keyring-backend test --home ~/.reserved/validator1 --chain-id testing-1 -y --fees 20stake diff --git a/script/vaults-gov-test.sh b/script/vaults-gov-test.sh index 90ee735e..3f925b3a 100755 --- a/script/vaults-gov-test.sh +++ b/script/vaults-gov-test.sh @@ -138,8 +138,8 @@ reserved tx oracle set-price atom 8 --home=$HOME/.reserved/validator2 --from v sleep 7 -reserved tx vaults create-vault 1250000000usdt 50000000nomUSD --home=$HOME/.reserved/validator1 --from validator1 --keyring-backend test --fees 20stake --chain-id testing-1 -y -reserved tx vaults create-vault 1250000000atom 50000000nomUSD --home=$HOME/.reserved/validator2 --from validator2 --keyring-backend test --fees 20stake --chain-id testing-1 -y +reserved tx vaults create-vault 1250000000usdt 50000000fxUSD --home=$HOME/.reserved/validator1 --from validator1 --keyring-backend test --fees 20stake --chain-id testing-1 -y +reserved tx vaults create-vault 1250000000atom 50000000fxUSD --home=$HOME/.reserved/validator2 --from validator2 --keyring-backend test --fees 20stake --chain-id testing-1 -y # killall reserved || true diff --git a/x/auction/client/cli/tx.go b/x/auction/client/cli/tx.go index bea4146f..320d7d62 100644 --- a/x/auction/client/cli/tx.go +++ b/x/auction/client/cli/tx.go @@ -37,7 +37,7 @@ func NewBidCmd() *cobra.Command { Long: `create new bid. Example: - $ onomyd tx bid 0 1000nomUSD 0.95 --from mykey + $ onomyd tx bid 0 1000fxUSD 0.95 --from mykey `, RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientTxContext(cmd) diff --git a/x/auction/spec/msg.md b/x/auction/spec/msg.md index 560a6239..2ad9cb8e 100644 --- a/x/auction/spec/msg.md +++ b/x/auction/spec/msg.md @@ -16,7 +16,7 @@ onomyd tx auction bid [auction-id] [amount] [recive_rate] [flags] Example: ```shell -onomyd tx bid 0 1000nomUSD 0.8 --from mykey +onomyd tx bid 0 1000fxUSD 0.8 --from mykey ``` #### Cancel bid diff --git a/x/oracle/oracle/data_source.py b/x/oracle/oracle/data_source.py index 7262cd19..f74d40cf 100644 --- a/x/oracle/oracle/data_source.py +++ b/x/oracle/oracle/data_source.py @@ -72,7 +72,7 @@ def get_price_mecx(symbols): result = [] # Set request parameters PARAMETERS = { - "symbol": "NOMUSDT", + "symbol": "FXUSDT", } diff --git a/x/psm/README.md b/x/psm/README.md index 5f39d028..42baaffd 100644 --- a/x/psm/README.md +++ b/x/psm/README.md @@ -1,6 +1,6 @@ # PSM Module -The PSM module is a stabilization mechanism for the nomUSD stablecoin, allowing users to swap approved stablecoins for nomUSD at a 1-1 ratio. +The PSM module is a stabilization mechanism for the fxUSD stablecoin, allowing users to swap approved stablecoins for fxUSD at a 1-1 ratio. ## Contents - [Concept](#concept) @@ -14,14 +14,14 @@ The PSM module is a stabilization mechanism for the nomUSD stablecoin, allowing ## Concept -PSM issues nomUSD in exchange for approved stablecoins, with a maximum issuance limit set by governance. It also allows users to swap nomUSD for stablecoins at a 1-1 ratio.nomUSD is issued from PSM which is backed by stablecoins within it. Parameters such as limit per stablecoin, swap-in fees and swap-out fees are governed and can change based on economic conditions. PSM is an effective support module for Vaults module in case users need nomUSD to repay off debts and close vault (redeem collateral). +PSM issues fxUSD in exchange for approved stablecoins, with a maximum issuance limit set by governance. It also allows users to swap fxUSD for stablecoins at a 1-1 ratio.fxUSD is issued from PSM which is backed by stablecoins within it. Parameters such as limit per stablecoin, swap-in fees and swap-out fees are governed and can change based on economic conditions. PSM is an effective support module for Vaults module in case users need fxUSD to repay off debts and close vault (redeem collateral). ### Key Features Key Features -- **Swap to nomUSD**: Users can convert from stablecoin to nomUSD provided that the stablecoin has been added to the list of accepted stablecoins. -- **Swap to Stablecoin**: Users can convert from nomUSD to stablecoin provided that the stablecoin has been added to the list of accepted stablecoins. +- **Swap to fxUSD**: Users can convert from stablecoin to fxUSD provided that the stablecoin has been added to the list of accepted stablecoins. +- **Swap to Stablecoin**: Users can convert from fxUSD to stablecoin provided that the stablecoin has been added to the list of accepted stablecoins. ## State @@ -29,13 +29,13 @@ Key Features Params contains: -- `LimitTotal`: Maximum amount of nomUSD that can be provided. -- `AcceptablePriceRatio`: The spread price between nomUSD and the stablecoins is at an acceptable level where the fees will remain the same. +- `LimitTotal`: Maximum amount of fxUSD that can be provided. +- `AcceptablePriceRatio`: The spread price between fxUSD and the stablecoins is at an acceptable level where the fees will remain the same. - `AdjustmentFee`: "AdjustmentFee" is a parameter used to adjust the amount of change in swap fees based on the deviation of the stablecoin from the target price. AdjustmentFee determines the number of iterations that one of the fees (entry fee or exit fee) will be adjusted according to the current ratio between the target price and the actual price. The larger the AdjustmentFee, the more severe the fee adjustment will be. Specifically, it affects how the feeOut or feeIn is calculated by multiplying (or dividing) it by the price ratio. ```protobuf message Params { - // total $nomUSD can mint + // total $fxUSD can mint bytes limit_total = 1 [ (cosmos_proto.scalar) = "cosmos.Int", (gogoproto.customtype) = "cosmossdk.io/math.Int", @@ -64,9 +64,9 @@ Params config for each stablecoin type: - `Denom`: stablecoin name - `LimitTotal`: limit total stablecoin -- `FeeIn`: stablecoin to nomUSD exchange fee, fee_in when 1 stablecoin = 1nomUSD -- `FeeOut`: nomUSD to stablecoin exchange fee, fee_out when 1 stablecoin = 1nomUSD -- `TotalStablecoinLock`: amount of stablecoins locked in exchange for nomUSD, default start at 0 +- `FeeIn`: stablecoin to fxUSD exchange fee, fee_in when 1 stablecoin = 1fxUSD +- `FeeOut`: fxUSD to stablecoin exchange fee, fee_out when 1 stablecoin = 1fxUSD +- `TotalStablecoinLock`: amount of stablecoins locked in exchange for fxUSD, default start at 0 - `FeeMaxStablecoin`: maximum fee for when either fee = 0, default at fee_in+fee_out ```protobuf @@ -80,19 +80,19 @@ message Stablecoin { (gogoproto.nullable) = false, (amino.dont_omitempty) = true ]; - // stablecoin to nomUSD exchange fee, fee_in when 1 stablecoin = 1nomUSD + // stablecoin to fxUSD exchange fee, fee_in when 1 stablecoin = 1fxUSD bytes fee_in = 3 [ (cosmos_proto.scalar) = "cosmos.Dec", (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", (gogoproto.nullable) = false ]; - // nomUSD to stablecoin exchange fee, fee_out when 1 stablecoin = 1nomUSD + // fxUSD to stablecoin exchange fee, fee_out when 1 stablecoin = 1fxUSD bytes fee_out = 4 [ (cosmos_proto.scalar) = "cosmos.Dec", (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", (gogoproto.nullable) = false ]; - // amount of stablecoins locked in exchange for nomUSD + // amount of stablecoins locked in exchange for fxUSD bytes total_stablecoin_lock = 5 [ (cosmos_proto.scalar) = "cosmos.Int", (gogoproto.customtype) = "cosmossdk.io/math.Int", @@ -112,8 +112,8 @@ message Stablecoin { ## Messages -### MsgStableSwap (swap to nomUSD) -Allows users to swap accepted stablecoins for nomUSD. `Address` is the sender's address, `OfferCoin` is the amount of stablecoin the user sent. `ExpectedDenom` is the type of denom expected to be received. +### MsgStableSwap (swap to fxUSD) +Allows users to swap accepted stablecoins for fxUSD. `Address` is the sender's address, `OfferCoin` is the amount of stablecoin the user sent. `ExpectedDenom` is the type of denom expected to be received. ```{.go} type MsgStableSwap struct { @@ -131,10 +131,10 @@ type MsgStableSwap struct { - Check balance user and calculate amount of coins received and fee in - Transfer stablecoin from user to psm module. -- Mint nomUSD and send for user +- Mint fxUSD and send for user ### MsgStableSwap (swap to stablecoin) -Allows users to swap accepted nomUSD for stablecoins. `Address` is the sender's address, `ExpectedDenom` is the stablecoin name to receive ,`OfferCoin` is the amount of nomUSD the user sent +Allows users to swap accepted fxUSD for stablecoins. `Address` is the sender's address, `ExpectedDenom` is the stablecoin name to receive ,`OfferCoin` is the amount of fxUSD the user sent ```{.go} type MsgStableSwap struct { @@ -151,7 +151,7 @@ type MsgStableSwap struct { - Check total stablecoin lock enough to swap - Check balance user and calculate amount of coins received and fee out -- Transfer nomUSD from user to psm module and burn. +- Transfer fxUSD from user to psm module and burn. - Transfer stablecoin to user ## Events @@ -159,26 +159,26 @@ type MsgStableSwap struct { The PSM module emits events for various operations: - **AddStablecoin**: Emitted when a new stablecoin is added. - **UpdateStablecoin**: Emitted when a stablecoin is updates -- **Swap**: Emitted when exchanging nomUSD for stablecoin. Emitted when exchanging stablecoin for nomUSD +- **Swap**: Emitted when exchanging fxUSD for stablecoin. Emitted when exchanging stablecoin for fxUSD ## ABCI ### Fee recalculate -To maintain the peg of 1 nomUSD = 1 USD, the swap fees need to be adjusted whenever the price of stablecoins fluctuates. This adjustment ensures that deviations from the target price of 1 USD per nomUSD are counterbalanced by the fees. +To maintain the peg of 1 fxUSD = 1 USD, the swap fees need to be adjusted whenever the price of stablecoins fluctuates. This adjustment ensures that deviations from the target price of 1 USD per fxUSD are counterbalanced by the fees. Adjustment Logic: -- If the stablecoin price is above 1, fee_out (the fee for converting from nomUSD to the stablecoin) will be higher, and fee_in (the fee for converting from the stablecoin to nomUSD) will be lower. This setup discourages swaps that would increase the stablecoin holdings when its value is above 1, helping to bring the price back down. -- If the stablecoin price is below 1, fee_out will be lower, and fee_in will be higher. This makes it cheaper to convert nomUSD to the stablecoin and more costly to convert the stablecoin to nomUSD, which encourages activity that pushes the price back up toward the target. +- If the stablecoin price is above 1, fee_out (the fee for converting from fxUSD to the stablecoin) will be higher, and fee_in (the fee for converting from the stablecoin to fxUSD) will be lower. This setup discourages swaps that would increase the stablecoin holdings when its value is above 1, helping to bring the price back down. +- If the stablecoin price is below 1, fee_out will be lower, and fee_in will be higher. This makes it cheaper to convert fxUSD to the stablecoin and more costly to convert the stablecoin to fxUSD, which encourages activity that pushes the price back up toward the target. #### How to calculate fee: The fee adjustments are scaled using the `AdjustmentFee` parameter (k), which controls the responsiveness of the fee to price deviations. Suppose: -- `newPrice`: new market price of stablecoin relative to nomUSD. -- `feeIn`: inbound fee (to exchange stablecoin to nomUSD). -- `feeOut`: outbound fee (to exchange nomUSD to stablecoin). +- `newPrice`: new market price of stablecoin relative to fxUSD. +- `feeIn`: inbound fee (to exchange stablecoin to fxUSD). +- `feeOut`: outbound fee (to exchange fxUSD to stablecoin). - `maxFee`: maximum total fee for both directions (usually feeIn + feeOut). - `k`: adjustment factor (`AdjustmentFee`) that controls the sensitivity of the fee to price changes. diff --git a/x/psm/client/cli/tx.go b/x/psm/client/cli/tx.go index 2614d9ee..8b366a3e 100644 --- a/x/psm/client/cli/tx.go +++ b/x/psm/client/cli/tx.go @@ -34,7 +34,7 @@ func NewSwapToNomCmd() *cobra.Command { Long: `swap between stable coins. Example: - $ onomyd tx psm swap 100000000000000000000000nomUSD ibc/xxxxx --from validator1 --keyring-backend test --home ~/.reserved/validator1 --chain-id testing-1 -y --fees 20stake + $ onomyd tx psm swap 100000000000000000000000fxUSD ibc/xxxxx --from validator1 --keyring-backend test --home ~/.reserved/validator1 --chain-id testing-1 -y --fees 20stake `, diff --git a/x/psm/keeper/abci.go b/x/psm/keeper/abci.go index ee46e802..26ef3802 100644 --- a/x/psm/keeper/abci.go +++ b/x/psm/keeper/abci.go @@ -31,7 +31,7 @@ func (k Keeper) UpdatesStablecoinEpoch(ctx context.Context) error { }) //k.IterateStablecoin(ctx, updatePrice) } -// price is $nomUSD amount to exchange for 1 $stabalecoin +// price is $fxUSD amount to exchange for 1 $stabalecoin // price taget = 1 // ex: // oldPrice:1 @@ -41,20 +41,20 @@ func (k Keeper) UpdatesStablecoinEpoch(ctx context.Context) error { // k = AdjustmentFeeIn = 40 // ---------------------------------------------------------------------------------------- // case 1: -// newPrice: 1.01 (1.01$nomUSD = 1USDT) +// newPrice: 1.01 (1.01$fxUSD = 1USDT) // rate = 1/1.01 = 0.990099 // newfeeOut = 0.01/(0.990099)**k = 0.01 * (1.01**40)= 0.014888637335882209 // newfeeIn = 0.02 - 0.014888637335882209 = 0.005111362664117791 -// So $USDT swap to $nomUSD will be cheaper than $nomUSD swap to $USDT +// So $USDT swap to $fxUSD will be cheaper than $fxUSD swap to $USDT // ---------------------------------------------------------------------------------------- // case 2: -// newPrice: 0.99 (0.98$nomUSD = 1USDT) +// newPrice: 0.99 (0.98$fxUSD = 1USDT) // rate = 1/0.99 = 1.0101010101 // deltaP < 0 // newfeeIn = 0.01 * (1.0101010101)**40 = 0.014948314143157351 // newfeeOut = 0.02 - 0.014948314143157351 = 0.005051685856842649 -// So $nomUSD swap to $USDT will be cheaper than $USDT swap to $nomUSD +// So $fxUSD swap to $USDT will be cheaper than $USDT swap to $fxUSD func (k Keeper) stablecoinUpdate(ctx context.Context, newPrice math.LegacyDec, stablecoin types.StablecoinInfo) types.StablecoinInfo { params, err := k.GetParams(ctx) diff --git a/x/psm/keeper/swap.go b/x/psm/keeper/swap.go index 0d16bc6a..51c5c10a 100644 --- a/x/psm/keeper/swap.go +++ b/x/psm/keeper/swap.go @@ -36,7 +36,7 @@ func (k Keeper) SwapToOtherStablecoin(ctx context.Context, addr sdk.AccAddress, return fmt.Errorf("amount %s locked lesser than amount desired", expectedDenom) } - // burn nomUSD + // burn fxUSD coinsBurn := sdk.NewCoins(offerCoin) err = k.BankKeeper.SendCoinsFromAccountToModule(ctx, addr, types.ModuleName, coinsBurn) if err != nil { @@ -93,7 +93,7 @@ func (k Keeper) SwapToOnomyStableToken(ctx context.Context, accAddress sdk.AccAd } // check balance user and calculate amount of coins received - receiveAmountnomUSD, fee_in, err := k.calculateSwapToOnomyStableToken(ctx, offerCoin, stablecoin.Symbol) + receiveAmountfxUSD, fee_in, err := k.calculateSwapToOnomyStableToken(ctx, offerCoin, stablecoin.Symbol) if err != nil { return err } @@ -110,8 +110,8 @@ func (k Keeper) SwapToOnomyStableToken(ctx context.Context, accAddress sdk.AccAd return err } - // mint nomUSD - coinsMint := sdk.NewCoins(sdk.NewCoin(types.ReserveStableCoinDenom, receiveAmountnomUSD)) + // mint fxUSD + coinsMint := sdk.NewCoins(sdk.NewCoin(types.ReserveStableCoinDenom, receiveAmountfxUSD)) err = k.BankKeeper.MintCoins(ctx, types.ModuleName, coinsMint) if err != nil { return err @@ -126,7 +126,7 @@ func (k Keeper) SwapToOnomyStableToken(ctx context.Context, accAddress sdk.AccAd sdkCtx := sdk.UnwrapSDKContext(ctx) sdkCtx.EventManager().EmitEvent( sdk.NewEvent( - types.EventSwapTonomUSD, + types.EventSwapTofxUSD, sdk.NewAttribute(types.AttributeAmount, offerCoin.String()), sdk.NewAttribute(types.AttributeReceive, coinsMint.String()), sdk.NewAttribute(types.AttributeFeeIn, fee_in.String()), @@ -177,13 +177,13 @@ func (k Keeper) calculateSwapToOnomyStableToken(ctx context.Context, stablecoin return math.Int{}, sdk.DecCoin{}, err } - amountnomUSD := multiplier.Mul(stablecoin.Amount.ToLegacyDec()) + amountfxUSD := multiplier.Mul(stablecoin.Amount.ToLegacyDec()) - fee, err := k.PayFeesIn(ctx, amountnomUSD.RoundInt(), stablecoin.Denom) + fee, err := k.PayFeesIn(ctx, amountfxUSD.RoundInt(), stablecoin.Denom) if err != nil { return math.Int{}, sdk.DecCoin{}, err } - receiveAmountnomUSD := amountnomUSD.Sub(fee) - return receiveAmountnomUSD.RoundInt(), sdk.NewDecCoinFromDec(types.ReserveStableCoinDenom, fee), nil + receiveAmountfxUSD := amountfxUSD.Sub(fee) + return receiveAmountfxUSD.RoundInt(), sdk.NewDecCoinFromDec(types.ReserveStableCoinDenom, fee), nil } diff --git a/x/psm/spec/concept.md b/x/psm/spec/concept.md index cb7a5774..393200ea 100644 --- a/x/psm/spec/concept.md +++ b/x/psm/spec/concept.md @@ -1,6 +1,6 @@ # PSM Module -The PSM module is a stabilization mechanism for the nomUSD stablecoin, allowing users to swap approved stablecoins for nomUSD at a 1-1 ratio. +The PSM module is a stabilization mechanism for the fxUSD stablecoin, allowing users to swap approved stablecoins for fxUSD at a 1-1 ratio. ## Contents - [Concept](#concept) @@ -14,12 +14,12 @@ The PSM module is a stabilization mechanism for the nomUSD stablecoin, allowing ## Concept -PSM issues nomUSD in exchange for approved stablecoins, with a maximum issuance limit set by governance. It also allows users to swap nomUSD for stablecoins at a 1-1 ratio.nomUSD is issued from PSM which is backed by stablecoins within it. Parameters such as limit per stablecoin, swap-in fees and swap-out fees are governed and can change based on economic conditions. PSM is an effective support module for Vaults module in case users need nomUSD to repay off debts and close vault (redeem collateral). +PSM issues fxUSD in exchange for approved stablecoins, with a maximum issuance limit set by governance. It also allows users to swap fxUSD for stablecoins at a 1-1 ratio.fxUSD is issued from PSM which is backed by stablecoins within it. Parameters such as limit per stablecoin, swap-in fees and swap-out fees are governed and can change based on economic conditions. PSM is an effective support module for Vaults module in case users need fxUSD to repay off debts and close vault (redeem collateral). ### Key Features Key Features -- **Swap to nomUSD**: Users can convert from stablecoin to nomUSD provided that the stablecoin has been added to the list of accepted stablecoins. -- **Swap to Stablecoin**: Users can convert from nomUSD to stablecoin provided that the stablecoin has been added to the list of accepted stablecoins. +- **Swap to fxUSD**: Users can convert from stablecoin to fxUSD provided that the stablecoin has been added to the list of accepted stablecoins. +- **Swap to Stablecoin**: Users can convert from fxUSD to stablecoin provided that the stablecoin has been added to the list of accepted stablecoins. diff --git a/x/psm/spec/event.md b/x/psm/spec/event.md index 6ea8c4bc..3d34d9a2 100644 --- a/x/psm/spec/event.md +++ b/x/psm/spec/event.md @@ -4,27 +4,27 @@ The PSM module emits events for various operations: - **AddStablecoin**: Emitted when a new stablecoin is added. - **UpdateStablecoin**: Emitted when a stablecoin is updates -- **SwapToStablecoin**: Emitted when exchanging nomUSD for stablecoin -- **SwapTonomUSD**: Emitted when exchanging stablecoin for nomUSD +- **SwapToStablecoin**: Emitted when exchanging fxUSD for stablecoin +- **SwapTofxUSD**: Emitted when exchanging stablecoin for fxUSD ## ABCI ### Fee recalculate -To maintain the peg of 1 nomUSD = 1 USD, the swap fees need to be adjusted whenever the price of stablecoins fluctuates. This adjustment ensures that deviations from the target price of 1 USD per nomUSD are counterbalanced by the fees. +To maintain the peg of 1 fxUSD = 1 USD, the swap fees need to be adjusted whenever the price of stablecoins fluctuates. This adjustment ensures that deviations from the target price of 1 USD per fxUSD are counterbalanced by the fees. Adjustment Logic: -- If the stablecoin price is above 1, fee_out (the fee for converting from nomUSD to the stablecoin) will be higher, and fee_in (the fee for converting from the stablecoin to nomUSD) will be lower. This setup discourages swaps that would increase the stablecoin holdings when its value is above 1, helping to bring the price back down. -- If the stablecoin price is below 1, fee_out will be lower, and fee_in will be higher. This makes it cheaper to convert nomUSD to the stablecoin and more costly to convert the stablecoin to nomUSD, which encourages activity that pushes the price back up toward the target. +- If the stablecoin price is above 1, fee_out (the fee for converting from fxUSD to the stablecoin) will be higher, and fee_in (the fee for converting from the stablecoin to fxUSD) will be lower. This setup discourages swaps that would increase the stablecoin holdings when its value is above 1, helping to bring the price back down. +- If the stablecoin price is below 1, fee_out will be lower, and fee_in will be higher. This makes it cheaper to convert fxUSD to the stablecoin and more costly to convert the stablecoin to fxUSD, which encourages activity that pushes the price back up toward the target. #### How to calculate fee: The fee adjustments are scaled using the `AdjustmentFee` parameter (k), which controls the responsiveness of the fee to price deviations. Suppose: -- `newPrice`: new market price of stablecoin relative to nomUSD. -- `feeIn`: inbound fee (to exchange stablecoin to nomUSD). -- `feeOut`: outbound fee (to exchange nomUSD to stablecoin). +- `newPrice`: new market price of stablecoin relative to fxUSD. +- `feeIn`: inbound fee (to exchange stablecoin to fxUSD). +- `feeOut`: outbound fee (to exchange fxUSD to stablecoin). - `maxFee`: maximum total fee for both directions (usually feeIn + feeOut). - `k`: adjustment factor (`AdjustmentFee`) that controls the sensitivity of the fee to price changes. diff --git a/x/psm/spec/state.md b/x/psm/spec/state.md index d53998e6..2c067cb2 100644 --- a/x/psm/spec/state.md +++ b/x/psm/spec/state.md @@ -4,13 +4,13 @@ Params contains: -- `LimitTotal`: Maximum amount of nomUSD that can be provided. -- `AcceptablePriceRatio`: The spread price between nomUSD and the stablecoins is at an acceptable level where the fees will remain the same. +- `LimitTotal`: Maximum amount of fxUSD that can be provided. +- `AcceptablePriceRatio`: The spread price between fxUSD and the stablecoins is at an acceptable level where the fees will remain the same. - `AdjustmentFee`: "AdjustmentFee" is a parameter used to adjust the amount of change in swap fees based on the deviation of the stablecoin from the target price. AdjustmentFee determines the number of iterations that one of the fees (entry fee or exit fee) will be adjusted according to the current ratio between the target price and the actual price. The larger the AdjustmentFee, the more severe the fee adjustment will be. Specifically, it affects how the feeOut or feeIn is calculated by multiplying (or dividing) it by the price ratio. ```protobuf message Params { - // total $nomUSD can mint + // total $fxUSD can mint bytes limit_total = 1 [ (cosmos_proto.scalar) = "cosmos.Int", (gogoproto.customtype) = "cosmossdk.io/math.Int", @@ -39,9 +39,9 @@ Params config for each stablecoin type: - `Denom`: stablecoin name - `LimitTotal`: limit total stablecoin -- `FeeIn`: stablecoin to nomUSD exchange fee, fee_in when 1 stablecoin = 1nomUSD -- `FeeOut`: nomUSD to stablecoin exchange fee, fee_out when 1 stablecoin = 1nomUSD -- `TotalStablecoinLock`: amount of stablecoins locked in exchange for nomUSD, default start at 0 +- `FeeIn`: stablecoin to fxUSD exchange fee, fee_in when 1 stablecoin = 1fxUSD +- `FeeOut`: fxUSD to stablecoin exchange fee, fee_out when 1 stablecoin = 1fxUSD +- `TotalStablecoinLock`: amount of stablecoins locked in exchange for fxUSD, default start at 0 - `FeeMaxStablecoin`: maximum fee for when either fee = 0, default at fee_in+fee_out ```protobuf @@ -55,19 +55,19 @@ message Stablecoin { (gogoproto.nullable) = false, (amino.dont_omitempty) = true ]; - // stablecoin to nomUSD exchange fee, fee_in when 1 stablecoin = 1nomUSD + // stablecoin to fxUSD exchange fee, fee_in when 1 stablecoin = 1fxUSD bytes fee_in = 3 [ (cosmos_proto.scalar) = "cosmos.Dec", (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", (gogoproto.nullable) = false ]; - // nomUSD to stablecoin exchange fee, fee_out when 1 stablecoin = 1nomUSD + // fxUSD to stablecoin exchange fee, fee_out when 1 stablecoin = 1fxUSD bytes fee_out = 4 [ (cosmos_proto.scalar) = "cosmos.Dec", (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", (gogoproto.nullable) = false ]; - // amount of stablecoins locked in exchange for nomUSD + // amount of stablecoins locked in exchange for fxUSD bytes total_stablecoin_lock = 5 [ (cosmos_proto.scalar) = "cosmos.Int", (gogoproto.customtype) = "cosmossdk.io/math.Int", @@ -87,11 +87,11 @@ message Stablecoin { ## Messages -### MsgSwapTonomUSD -Allows users to swap accepted stablecoins for nomUSD. `Address` is the sender's address, `Coin` is the amount of stablecoin the user sent +### MsgSwapTofxUSD +Allows users to swap accepted stablecoins for fxUSD. `Address` is the sender's address, `Coin` is the amount of stablecoin the user sent ```{.go} -type MsgSwapTonomUSD struct { +type MsgSwapTofxUSD struct { Address string Coin *types.Coin } @@ -105,10 +105,10 @@ type MsgSwapTonomUSD struct { - Check balance user and calculate amount of coins received and fee in - Transfer stablecoin from user to psm module. -- Mint nomUSD and send for user +- Mint fxUSD and send for user ### MsgSwapToStablecoin -Allows users to swap accepted nomUSD for stablecoins. `Address` is the sender's address, `ToDenom` is the stablecoin name to receive ,`Amount` is the amount of nomUSD the user sent +Allows users to swap accepted fxUSD for stablecoins. `Address` is the sender's address, `ToDenom` is the stablecoin name to receive ,`Amount` is the amount of fxUSD the user sent ```{.go} type MsgSwapToStablecoin struct { @@ -125,5 +125,5 @@ type MsgSwapToStablecoin struct { - Check total stablecoin lock enough to swap - Check balance user and calculate amount of coins received and fee out -- Transfer nomUSD from user to psm module and burn. +- Transfer fxUSD from user to psm module and burn. - Transfer stablecoin to user diff --git a/x/psm/types/event.go b/x/psm/types/event.go index 4ad5fa7b..db2c50f7 100644 --- a/x/psm/types/event.go +++ b/x/psm/types/event.go @@ -2,8 +2,8 @@ package types const ( EventAddStablecoin = "add_stablecoin" - EventSwapTonomUSD = "swap_stablecoin_to_nomUSD" - EventSwapToStablecoin = "swap_nomUSD_to_stablecoin" + EventSwapTofxUSD = "swap_stablecoin_to_fxUSD" + EventSwapToStablecoin = "swap_fxUSD_to_stablecoin" AttributeAmount = "amount" AttributeStablecoinName = "stablecoin_name" diff --git a/x/psm/types/keys.go b/x/psm/types/keys.go index 461a170c..157d23bd 100644 --- a/x/psm/types/keys.go +++ b/x/psm/types/keys.go @@ -17,7 +17,7 @@ const ( MemStoreKey = "mem_psm" // Reserve Stable Coin denom prefix - ReserveStableCoinDenom = "nomUSD" + ReserveStableCoinDenom = "fxUSD" // symbol USD SymBolUSD = "USD" diff --git a/x/psm/types/psm.pb.go b/x/psm/types/psm.pb.go index 354f0f16..32fd0709 100644 --- a/x/psm/types/psm.pb.go +++ b/x/psm/types/psm.pb.go @@ -32,11 +32,11 @@ type StablecoinInfo struct { Denom string `protobuf:"bytes,1,opt,name=denom,proto3" json:"denom,omitempty"` // limit total stablecoin LimitTotal cosmossdk_io_math.Int `protobuf:"bytes,2,opt,name=limit_total,json=limitTotal,proto3,customtype=cosmossdk.io/math.Int" json:"limit_total"` - // stablecoin to nom exchange fee, fee_in when 1 stablecoin = 1nomUSD + // stablecoin to fxUSD exchange fee, fee_in when 1 stablecoin = 1fxUSD FeeIn cosmossdk_io_math.LegacyDec `protobuf:"bytes,3,opt,name=fee_in,json=feeIn,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"fee_in"` - // nom to stablecoin exchange fee, fee_out when 1 stablecoin = 1nomUSD + // fxUSD to stablecoin exchange fee, fee_out when 1 stablecoin = 1fxUSD FeeOut cosmossdk_io_math.LegacyDec `protobuf:"bytes,4,opt,name=fee_out,json=feeOut,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"fee_out"` - // amount of stablecoins locked in exchange for nomUSD + // amount of stablecoins locked in exchange for fxUSD TotalStablecoinLock cosmossdk_io_math.Int `protobuf:"bytes,5,opt,name=total_stablecoin_lock,json=totalStablecoinLock,proto3,customtype=cosmossdk.io/math.Int" json:"total_stablecoin_lock"` // maximum fee for when either fee = 0 FeeMaxStablecoin cosmossdk_io_math.LegacyDec `protobuf:"bytes,6,opt,name=fee_max_stablecoin,json=feeMaxStablecoin,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"fee_max_stablecoin"` diff --git a/x/vaults/cli/tx.go b/x/vaults/cli/tx.go index bf423dd0..99968c9f 100644 --- a/x/vaults/cli/tx.go +++ b/x/vaults/cli/tx.go @@ -40,7 +40,7 @@ func NewCreateVaultCmd() *cobra.Command { Long: `create vaults. Example: - $ onomyd tx vautls create-vault 1000atom 8000nomUSD --from mykey + $ onomyd tx vautls create-vault 1000atom 8000fxUSD --from mykey `, RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientTxContext(cmd) diff --git a/x/vaults/keeper/abci_test.go b/x/vaults/keeper/abci_test.go index 82b48db5..89044d16 100644 --- a/x/vaults/keeper/abci_test.go +++ b/x/vaults/keeper/abci_test.go @@ -29,9 +29,9 @@ func (s *KeeperTestSuite) TestBeginBlock() { }{ { name: "success: one vault", - setup: func() { // 100000000000atom debt 210000000nomUSD(get 200000000nomUSD + 10000000nomUSD MintingFee) + setup: func() { // 100000000000atom debt 210000000fxUSD(get 200000000fxUSD + 10000000fxUSD MintingFee) err := s.k.ActiveCollateralAsset(s.Ctx, - denom, denom, "nomUSD", "USD", math.LegacyMustNewDecFromStr("1.6"), + denom, denom, "fxUSD", "USD", math.LegacyMustNewDecFromStr("1.6"), math.LegacyMustNewDecFromStr("1.5"), maxDebt, stabilityFee, types.DefaultMintingFee, @@ -60,9 +60,9 @@ func (s *KeeperTestSuite) TestBeginBlock() { }, { name: "success: no vault, LastUpdateTime updates", - setup: func() { // 100000000000atom debt 210000000nomUSD(get 200000000nomUSD + 10000000nomUSD MintingFee) + setup: func() { // 100000000000atom debt 210000000fxUSD(get 200000000fxUSD + 10000000fxUSD MintingFee) err := s.k.ActiveCollateralAsset(s.Ctx, - denom, denom, "nomUSD", "USD", math.LegacyMustNewDecFromStr("1.6"), + denom, denom, "fxUSD", "USD", math.LegacyMustNewDecFromStr("1.6"), math.LegacyMustNewDecFromStr("1.5"), maxDebt, stabilityFee, types.DefaultMintingFee, diff --git a/x/vaults/keeper/vault.go b/x/vaults/keeper/vault.go index 48a1ac51..35a31705 100644 --- a/x/vaults/keeper/vault.go +++ b/x/vaults/keeper/vault.go @@ -510,7 +510,7 @@ func (k *Keeper) GetLiquidations( } collateralSymbol := vm.Symbol mintSymbol := vm.Params.MintSymbol - + // If can not get price of denom, skip! price, err := k.OracleKeeper.GetPrice(ctx, collateralSymbol, mintSymbol) if err != nil { @@ -652,7 +652,7 @@ func (k *Keeper) Liquidate( } } } else { - // does not raise enough to cover nomUSD debt + // does not raise enough to cover fxUSD debt // Burn sold amount and increase mint available err := k.burnDebt(ctx, key, vm, sold) diff --git a/x/vaults/keeper/vaults_test.go b/x/vaults/keeper/vaults_test.go index e32a5130..8f49aa29 100644 --- a/x/vaults/keeper/vaults_test.go +++ b/x/vaults/keeper/vaults_test.go @@ -33,7 +33,7 @@ func (s *KeeperTestSuite) TestCreateNewVault() { collateral = sdk.NewCoin(denom, math.NewInt(11_000_000)) // 11 atom = 88$ maxDebt = math.NewInt(100_000_000) ) - err := s.k.ActiveCollateralAsset(s.Ctx, denom, denom, "nomUSD", "USD", math.LegacyMustNewDecFromStr("1.6"), math.LegacyMustNewDecFromStr("1.5"), maxDebt, types.DefaultStabilityFee, types.DefaultMintingFee, types.DefaultLiquidationPenalty, 1, 1, 6, 6) + err := s.k.ActiveCollateralAsset(s.Ctx, denom, denom, "fxUSD", "USD", math.LegacyMustNewDecFromStr("1.6"), math.LegacyMustNewDecFromStr("1.5"), maxDebt, types.DefaultStabilityFee, types.DefaultMintingFee, types.DefaultLiquidationPenalty, 1, 1, 6, 6) s.Require().NoError(err) tests := []struct { @@ -166,7 +166,7 @@ func (s *KeeperTestSuite) TestRepayDebt() { maxDebt = math.NewInt(2000000000) mintedCoin = sdk.NewCoin(types.DefaultMintDenoms[0], math.NewInt(300000000)) ) - err := s.k.ActiveCollateralAsset(s.Ctx, denom, denom, "nomUSD", "USD", math.LegacyMustNewDecFromStr("0.1"), math.LegacyMustNewDecFromStr("0.1"), maxDebt, types.DefaultStabilityFee, types.DefaultMintingFee, types.DefaultLiquidationPenalty, 1, 1, 6, 6) + err := s.k.ActiveCollateralAsset(s.Ctx, denom, denom, "fxUSD", "USD", math.LegacyMustNewDecFromStr("0.1"), math.LegacyMustNewDecFromStr("0.1"), maxDebt, types.DefaultStabilityFee, types.DefaultMintingFee, types.DefaultLiquidationPenalty, 1, 1, 6, 6) s.Require().NoError(err) tests := []struct { @@ -200,7 +200,7 @@ func (s *KeeperTestSuite) TestRepayDebt() { }, vaultId: 1, sender: s.TestAccs[0], - repayAsset: sdk.NewCoin("nomUSD", math.NewInt(500000000)), + repayAsset: sdk.NewCoin("fxUSD", math.NewInt(500000000)), expErr: false, isZeroDebt: true, }, @@ -284,7 +284,7 @@ func (s *KeeperTestSuite) TestDepositToVault() { maxDebt = math.NewInt(2000000000) mintedCoin = sdk.NewCoin(types.DefaultMintDenoms[0], math.NewInt(200000000)) ) - err := s.k.ActiveCollateralAsset(s.Ctx, denom, denom, "nomUSD", "USD", math.LegacyMustNewDecFromStr("0.1"), math.LegacyMustNewDecFromStr("0.1"), maxDebt, types.DefaultStabilityFee, types.DefaultMintingFee, types.DefaultLiquidationPenalty, 1, 1, 6, 6) + err := s.k.ActiveCollateralAsset(s.Ctx, denom, denom, "fxUSD", "USD", math.LegacyMustNewDecFromStr("0.1"), math.LegacyMustNewDecFromStr("0.1"), maxDebt, types.DefaultStabilityFee, types.DefaultMintingFee, types.DefaultLiquidationPenalty, 1, 1, 6, 6) s.Require().NoError(err) tests := []struct { @@ -407,7 +407,7 @@ func (s *KeeperTestSuite) TestWithdrawFromVault() { setup: func() { s.FundAccount(s.TestAccs[0], types.ModuleName, sdk.NewCoins(fund)) - err := s.k.ActiveCollateralAsset(s.Ctx, denom, denom, "nomUSD", "USD", math.LegacyMustNewDecFromStr("0.1"), math.LegacyMustNewDecFromStr("0.1"), maxDebt, types.DefaultStabilityFee, types.DefaultMintingFee, types.DefaultLiquidationPenalty, 1, 1, 6, 6) + err := s.k.ActiveCollateralAsset(s.Ctx, denom, denom, "fxUSD", "USD", math.LegacyMustNewDecFromStr("0.1"), math.LegacyMustNewDecFromStr("0.1"), maxDebt, types.DefaultStabilityFee, types.DefaultMintingFee, types.DefaultLiquidationPenalty, 1, 1, 6, 6) s.Require().NoError(err) err = s.k.CreateNewVault(s.Ctx, s.TestAccs[0], coinMintToAcc, mintedCoin) @@ -443,7 +443,7 @@ func (s *KeeperTestSuite) TestWithdrawFromVault() { setup: func() { s.FundAccount(s.TestAccs[0], types.ModuleName, sdk.NewCoins(fund)) - err := s.k.ActiveCollateralAsset(s.Ctx, denom, denom, "nomUSD", "USD", math.LegacyMustNewDecFromStr("0.1"), math.LegacyMustNewDecFromStr("0.1"), maxDebt, types.DefaultStabilityFee, types.DefaultMintingFee, types.DefaultLiquidationPenalty, 1, 1, 6, 6) + err := s.k.ActiveCollateralAsset(s.Ctx, denom, denom, "fxUSD", "USD", math.LegacyMustNewDecFromStr("0.1"), math.LegacyMustNewDecFromStr("0.1"), maxDebt, types.DefaultStabilityFee, types.DefaultMintingFee, types.DefaultLiquidationPenalty, 1, 1, 6, 6) s.Require().NoError(err) err = s.k.CreateNewVault(s.Ctx, s.TestAccs[0], coinMintToAcc, mintedCoin) @@ -460,7 +460,7 @@ func (s *KeeperTestSuite) TestWithdrawFromVault() { setup: func() { s.FundAccount(s.TestAccs[0], types.ModuleName, sdk.NewCoins(fund)) - err := s.k.ActiveCollateralAsset(s.Ctx, denom, denom, "nomUSD", "USD", math.LegacyMustNewDecFromStr("0.1"), math.LegacyMustNewDecFromStr("0.1"), maxDebt, types.DefaultStabilityFee, types.DefaultMintingFee, types.DefaultLiquidationPenalty, 1, 1, 6, 6) + err := s.k.ActiveCollateralAsset(s.Ctx, denom, denom, "fxUSD", "USD", math.LegacyMustNewDecFromStr("0.1"), math.LegacyMustNewDecFromStr("0.1"), maxDebt, types.DefaultStabilityFee, types.DefaultMintingFee, types.DefaultLiquidationPenalty, 1, 1, 6, 6) s.Require().NoError(err) err = s.k.CreateNewVault(s.Ctx, s.TestAccs[0], coinMintToAcc, mintedCoin) @@ -477,7 +477,7 @@ func (s *KeeperTestSuite) TestWithdrawFromVault() { setup: func() { s.FundAccount(s.TestAccs[0], types.ModuleName, sdk.NewCoins(fund)) - err := s.k.ActiveCollateralAsset(s.Ctx, denom, denom, "nomUSD", "USD", math.LegacyMustNewDecFromStr("0.1"), math.LegacyMustNewDecFromStr("0.1"), maxDebt, types.DefaultStabilityFee, types.DefaultMintingFee, types.DefaultLiquidationPenalty, 1, 1, 6, 6) + err := s.k.ActiveCollateralAsset(s.Ctx, denom, denom, "fxUSD", "USD", math.LegacyMustNewDecFromStr("0.1"), math.LegacyMustNewDecFromStr("0.1"), maxDebt, types.DefaultStabilityFee, types.DefaultMintingFee, types.DefaultLiquidationPenalty, 1, 1, 6, 6) s.Require().NoError(err) err = s.k.CreateNewVault(s.Ctx, s.TestAccs[0], coinMintToAcc, mintedCoin) @@ -709,7 +709,7 @@ func (s *KeeperTestSuite) TestLiquidate() { for _, t := range tests { s.Run(t.name, func() { s.SetupTest() - err := s.k.ActiveCollateralAsset(s.Ctx, "atom", "atom", "nomUSD", "USD", math.LegacyMustNewDecFromStr("0.1"), math.LegacyMustNewDecFromStr("0.1"), math.NewInt(1000_000_000), types.DefaultStabilityFee, types.DefaultMintingFee, types.DefaultLiquidationPenalty, 1, 1, 6, 6) + err := s.k.ActiveCollateralAsset(s.Ctx, "atom", "atom", "fxUSD", "USD", math.LegacyMustNewDecFromStr("0.1"), math.LegacyMustNewDecFromStr("0.1"), math.NewInt(1000_000_000), types.DefaultStabilityFee, types.DefaultMintingFee, types.DefaultLiquidationPenalty, 1, 1, 6, 6) s.Require().NoError(err) for _, vault := range t.liquidation.LiquidatingVaults { diff --git a/x/vaults/types/params.go b/x/vaults/types/params.go index 79090656..e75acd18 100644 --- a/x/vaults/types/params.go +++ b/x/vaults/types/params.go @@ -13,7 +13,7 @@ var ( DefaultLiquidationPenalty = math.LegacyMustNewDecFromStr("0.05") DefaultMinInitialDebt = math.NewInt(50_000_000) DefaultRecalculateDebtPeriod = time.Hour - DefaultMintDenoms = []string{"nomUSD", "nomEUR", "nomJPY"} + DefaultMintDenoms = []string{"fxUSD", "fxEUR", "fxJPY"} ) // NewParams creates a new Params instance.