Skip to content

Commit

Permalink
Merge pull request #76 from onomyprotocol/vault/allow-multiple-currency
Browse files Browse the repository at this point in the history
Vault/allow multiple currency
  • Loading branch information
vuong177 authored Nov 11, 2024
2 parents 6cb0bdd + 8029fcc commit 2a3b39c
Show file tree
Hide file tree
Showing 64 changed files with 2,428 additions and 2,028 deletions.
4 changes: 2 additions & 2 deletions proto/reserve/auction/v1/auction.proto
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ message BidQueue {
uint64 auction_id = 1;

// array of bid entries with bidder address
repeated Bid bids = 2;
repeated Bid bids = 2 [ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ];
}

// Bids defines a list of bid entries
message Bids {
// array of bid entries with bidder address
repeated Bid bids = 1;
repeated Bid bids = 1 [ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ];
}
17 changes: 16 additions & 1 deletion proto/reserve/auction/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ service Query {
}

rpc QueryAllBids(QueryAllBidsRequest) returns (QueryAllBidsResponse){
option (google.api.http).get = "/reserve/auction/auction";
option (google.api.http).get = "/reserve/auction/bids";
}

rpc QueryAllBidderBids(QueryAllBidderBidsRequest) returns (QueryAllBidderBidsResponse){
option (google.api.http).get = "/reserve/auction/bids/{bidder}";
}
}

Expand Down Expand Up @@ -52,4 +56,15 @@ message QueryAllBidsResponse {
// params holds all the parameters of this module.
repeated Bid Bids = 1
[ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ];
}

message QueryAllBidderBidsRequest {
string bidder = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
uint64 auction_id = 2;
}

message QueryAllBidderBidsResponse {
// params holds all the parameters of this module.
repeated Bid Bids = 1
[ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ];
}
2 changes: 1 addition & 1 deletion proto/reserve/psm/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ message GenesisState {
(amino.dont_omitempty) = true
];

repeated Stablecoin stablecoins = 2
repeated StablecoinInfo stablecoins = 2
[ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ];
}
2 changes: 1 addition & 1 deletion proto/reserve/psm/v1/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import "cosmos_proto/cosmos.proto";
option go_package = "github.com/onomyprotocol/reserve/x/psm/types";

message Params {
// total $nomUSD can mint
// total $nomX can mint
bytes limit_total = 1 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
Expand Down
8 changes: 4 additions & 4 deletions proto/reserve/psm/v1/psm.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ import "cosmos/base/v1beta1/coin.proto";

option go_package = "github.com/onomyprotocol/reserve/x/psm/types";

message Stablecoin {
message StablecoinInfo {
// stablecoin name
string denom = 1;
// limit total stablecoin module support
// limit total stablecoin
bytes limit_total = 2 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true
];
// stablecoin to nomUSD exchange fee, fee_in when 1 stablecoin = 1nomUSD
// stablecoin to nom exchange fee, fee_in when 1 stablecoin = 1nomUSD
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
// nom to stablecoin exchange fee, fee_out when 1 stablecoin = 1nomUSD
bytes fee_out = 4 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
Expand Down
4 changes: 2 additions & 2 deletions proto/reserve/psm/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ message QueryStablecoinRequest {
}

message QueryStablecoinResponse {
Stablecoin stablecoin = 1 [(gogoproto.nullable) = false];
StablecoinInfo stablecoin = 1 [(gogoproto.nullable) = false];

bytes swapable_quantity = 3 [
(cosmos_proto.scalar) = "cosmos.Int",
Expand All @@ -63,7 +63,7 @@ message QueryAllStablecoinResponse {
}

message StablecoinResponse {
Stablecoin stablecoin = 1 [(gogoproto.nullable) = false];
StablecoinInfo stablecoin = 1 [(gogoproto.nullable) = false];
bytes swapable_quantity = 3 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
Expand Down
43 changes: 19 additions & 24 deletions proto/reserve/psm/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ service Msg {
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
rpc AddStableCoinProposal(MsgAddStableCoin) returns (MsgAddStableCoinResponse);
rpc UpdatesStableCoinProposal(MsgUpdatesStableCoin) returns (MsgUpdatesStableCoinResponse);
rpc SwapTonomUSD(MsgSwapTonomUSD) returns (MsgSwapTonomUSDResponse);
rpc SwapToStablecoin(MsgSwapToStablecoin) returns (MsgSwapToStablecoinResponse);
rpc StableSwap(MsgStableSwap) returns (MsgStableSwapResponse);
}

// MsgUpdateParams is the Msg/UpdateParams request type.
Expand All @@ -44,27 +43,6 @@ message MsgUpdateParams {
// MsgUpdateParams message.
message MsgUpdateParamsResponse {}

message MsgSwapTonomUSD {
option (cosmos.msg.v1.signer) = "address";

string address = 1;
cosmos.base.v1beta1.Coin coin = 2;
}
message MsgSwapTonomUSDResponse {}

message MsgSwapToStablecoin {
option (cosmos.msg.v1.signer) = "address";

string address = 1;
string to_denom = 2;
bytes amount = 3 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true
];
}
message MsgSwapToStablecoinResponse {}

message MsgAddStableCoin {
option (cosmos.msg.v1.signer) = "authority";
Expand All @@ -91,6 +69,7 @@ message MsgAddStableCoin {
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
int64 oracle_script = 6;
}

message MsgAddStableCoinResponse {}
Expand Down Expand Up @@ -120,6 +99,22 @@ message MsgUpdatesStableCoin {
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];

int64 oracle_script = 6;
}

message MsgUpdatesStableCoinResponse {}
message MsgUpdatesStableCoinResponse {}

// MsgUpdateParamsResponse defines the response structure for executing a
// MsgStableSwap message.

message MsgStableSwap {
option (cosmos.msg.v1.signer) = "address";

string address = 1;
string expected_denom = 2;
cosmos.base.v1beta1.Coin offer_coin = 3
[ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ];

}
message MsgStableSwapResponse {}
20 changes: 12 additions & 8 deletions proto/reserve/vaults/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ message Params {
(gogoproto.nullable) = false
];

string mint_denom = 2;
repeated string allowed_mint_denom = 2;

google.protobuf.Duration charging_period = 3 [
(gogoproto.stdduration) = true,
Expand All @@ -33,42 +33,44 @@ message Params {

// VaultParams defines the parameters for each collateral vault type.
message VaultMamagerParams {
string min_collateral_ratio = 1 [
string mint_denom = 1;

string min_collateral_ratio = 2 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(amino.dont_omitempty) = true,
(gogoproto.nullable) = false
];

string liquidation_ratio = 2 [
string liquidation_ratio = 3 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(amino.dont_omitempty) = true,
(gogoproto.nullable) = false
];

string max_debt = 3 [
string max_debt = 4 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(amino.dont_omitempty) = true,
(gogoproto.nullable) = false
];

string stability_fee = 4 [
string stability_fee = 5 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(amino.dont_omitempty) = true,
(gogoproto.nullable) = false
];

string liquidation_penalty = 5 [
string liquidation_penalty = 6 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(amino.dont_omitempty) = true,
(gogoproto.nullable) = false
];

string minting_fee = 6 [
string minting_fee = 7 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(amino.dont_omitempty) = true,
Expand Down Expand Up @@ -142,7 +144,9 @@ message VaultLiquidationStatus {
}

message Liquidation {
string denom = 1;
string debt_denom = 1;

string mint_denom = 2;

repeated Vault liquidating_vaults = 3;

Expand Down
14 changes: 0 additions & 14 deletions script/proposal-2.json

This file was deleted.

23 changes: 23 additions & 0 deletions script/proposal-psm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"messages": [{
"@type": "/reserve.psm.v1.MsgAddStableCoin",
"authority":"onomy10d07y265gmmuvt4z0w9aw880jnsr700jqr8n8k",
"denom": "usdt",
"limit_total": "100000000000000000000000000000",
"fee_in": "0.001000000000000000",
"fee_out": "0.001000000000000000",
"oracle_script": "44"
},
{
"@type": "/reserve.psm.v1.MsgAddStableCoin",
"authority":"onomy10d07y265gmmuvt4z0w9aw880jnsr700jqr8n8k",
"denom": "usdc",
"limit_total": "100000000000000000000000000000",
"fee_in": "0.001000000000000000",
"fee_out": "0.001000000000000000",
"oracle_script": "44"
}],
"deposit": "100000000stake",
"title": "My proposal",
"summary": "A short summary of my proposal"
}
44 changes: 20 additions & 24 deletions script/psm-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ echo $mnemonic2| reserved keys add validator2 --recover --keyring-backend=test -
echo $mnemonic3| reserved keys add validator3 --recover --keyring-backend=test --home=$HOME/.reserved/validator3

# create validator node with tokens to transfer to the three other nodes
reserved genesis add-genesis-account $(reserved keys show validator1 -a --keyring-backend=test --home=$HOME/.reserved/validator1) 10000000000000000000000000000000stake,10000000000000000000000000000000usdt --home=$HOME/.reserved/validator1
reserved genesis add-genesis-account $(reserved keys show validator2 -a --keyring-backend=test --home=$HOME/.reserved/validator2) 10000000000000000000000000000000stake,10000000000000000000000000000000usdt --home=$HOME/.reserved/validator1
reserved genesis add-genesis-account $(reserved keys show validator3 -a --keyring-backend=test --home=$HOME/.reserved/validator3) 10000000000000000000000000000000stake,10000000000000000000000000000000usdt --home=$HOME/.reserved/validator1
reserved genesis add-genesis-account $(reserved keys show validator1 -a --keyring-backend=test --home=$HOME/.reserved/validator1) 10000000000000000000000000000000stake,10000000000000000000000000000000usdt --home=$HOME/.reserved/validator2
reserved genesis add-genesis-account $(reserved keys show validator2 -a --keyring-backend=test --home=$HOME/.reserved/validator2) 10000000000000000000000000000000stake,10000000000000000000000000000000usdt --home=$HOME/.reserved/validator2
reserved genesis add-genesis-account $(reserved keys show validator3 -a --keyring-backend=test --home=$HOME/.reserved/validator3) 10000000000000000000000000000000stake,10000000000000000000000000000000usdt --home=$HOME/.reserved/validator2
reserved genesis add-genesis-account $(reserved keys show validator1 -a --keyring-backend=test --home=$HOME/.reserved/validator1) 10000000000000000000000000000000stake,10000000000000000000000000000000usdt --home=$HOME/.reserved/validator3
reserved genesis add-genesis-account $(reserved keys show validator2 -a --keyring-backend=test --home=$HOME/.reserved/validator2) 10000000000000000000000000000000stake,10000000000000000000000000000000usdt --home=$HOME/.reserved/validator3
reserved genesis add-genesis-account $(reserved keys show validator3 -a --keyring-backend=test --home=$HOME/.reserved/validator3) 10000000000000000000000000000000stake,10000000000000000000000000000000usdt --home=$HOME/.reserved/validator3
reserved genesis add-genesis-account $(reserved keys show validator1 -a --keyring-backend=test --home=$HOME/.reserved/validator1) 10000000000000000000000000000000stake,10000000000000000000000000000000usdt,10000000000000000000000000000000usdc --home=$HOME/.reserved/validator1
reserved genesis add-genesis-account $(reserved keys show validator2 -a --keyring-backend=test --home=$HOME/.reserved/validator2) 10000000000000000000000000000000stake,10000000000000000000000000000000usdt,10000000000000000000000000000000usdc --home=$HOME/.reserved/validator1
reserved genesis add-genesis-account $(reserved keys show validator3 -a --keyring-backend=test --home=$HOME/.reserved/validator3) 10000000000000000000000000000000stake,10000000000000000000000000000000usdt,10000000000000000000000000000000usdc --home=$HOME/.reserved/validator1
reserved genesis add-genesis-account $(reserved keys show validator1 -a --keyring-backend=test --home=$HOME/.reserved/validator1) 10000000000000000000000000000000stake,10000000000000000000000000000000usdt,10000000000000000000000000000000usdc --home=$HOME/.reserved/validator2
reserved genesis add-genesis-account $(reserved keys show validator2 -a --keyring-backend=test --home=$HOME/.reserved/validator2) 10000000000000000000000000000000stake,10000000000000000000000000000000usdt,10000000000000000000000000000000usdc --home=$HOME/.reserved/validator2
reserved genesis add-genesis-account $(reserved keys show validator3 -a --keyring-backend=test --home=$HOME/.reserved/validator3) 10000000000000000000000000000000stake,10000000000000000000000000000000usdt,10000000000000000000000000000000usdc --home=$HOME/.reserved/validator2
reserved genesis add-genesis-account $(reserved keys show validator1 -a --keyring-backend=test --home=$HOME/.reserved/validator1) 10000000000000000000000000000000stake,10000000000000000000000000000000usdt,10000000000000000000000000000000usdc --home=$HOME/.reserved/validator3
reserved genesis add-genesis-account $(reserved keys show validator2 -a --keyring-backend=test --home=$HOME/.reserved/validator2) 10000000000000000000000000000000stake,10000000000000000000000000000000usdt,10000000000000000000000000000000usdc --home=$HOME/.reserved/validator3
reserved genesis add-genesis-account $(reserved keys show validator3 -a --keyring-backend=test --home=$HOME/.reserved/validator3) 10000000000000000000000000000000stake,10000000000000000000000000000000usdt,10000000000000000000000000000000usdc --home=$HOME/.reserved/validator3
reserved genesis gentx validator1 1000000000000000000000stake --keyring-backend=test --home=$HOME/.reserved/validator1 --chain-id=testing-1
reserved genesis gentx validator2 1000000000000000000000stake --keyring-backend=test --home=$HOME/.reserved/validator2 --chain-id=testing-1
reserved genesis gentx validator3 1000000000000000000000stake --keyring-backend=test --home=$HOME/.reserved/validator3 --chain-id=testing-1
Expand Down Expand Up @@ -118,7 +118,7 @@ screen -S onomy3 -t onomy3 -d -m reserved start --home=$HOME/.reserved/validator

# submit proposal add usdt
sleep 7
reserved tx gov submit-proposal ./script/proposal-2.json --home=$HOME/.reserved/validator1 --from validator1 --keyring-backend test --fees 20stake --chain-id testing-1 -y
reserved tx gov submit-proposal ./script/proposal-psm.json --home=$HOME/.reserved/validator1 --from validator1 --keyring-backend test --fees 20stake --chain-id testing-1 -y

# # # vote
sleep 7
Expand All @@ -130,22 +130,18 @@ reserved tx gov vote 1 yes --from validator3 --keyring-backend test --home ~/.r
sleep 15
# echo "========sleep=========="

# # check add usdt, balances
# reserved q psm all-stablecoin
# # # check add usdt, balances
# # 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
# echo "========swap==========="
reserved tx psm swap-to-nomUSD 100000000000000000000000usdt --from validator1 --keyring-backend test --home ~/.reserved/validator1 --chain-id testing-1 -y --fees 20stake
# # # tx swap usdt to nomUSD
# # echo "========swap==========="
reserved tx psm swap 100000000000000000000000usdt nomUSD --from validator1 --keyring-backend test --home ~/.reserved/validator1 --chain-id testing-1 -y --fees 20stake

sleep 7
# # Check account after swap
reserved q bank balances $(reserved keys show validator1 -a --keyring-backend test --home /Users/donglieu/.reserved/validator1)

# # tx swap nomUSD to usdt
# reserved tx psm swap-to-stablecoin usdt 1000nomUSD --from validator1 --keyring-backend test --home ~/.reserved/validator1 --chain-id testing-1 -y --fees 20stake

# sleep 7
# # Check account after swap
# reserved q bank balances $(reserved keys show validator1 -a --keyring-backend test --home /Users/donglieu/.reserved/validator1)
# # killall reserved || true
reserved tx psm swap 1000000000usdc nomUSD --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
sleep 7
reserved tx psm swap 1000nomUSD usdt --from validator1 --keyring-backend test --home ~/.reserved/validator1 --chain-id testing-1 -y --fees 20stake
Loading

0 comments on commit 2a3b39c

Please sign in to comment.