-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from onomyprotocol/pool-logic
Pool logic
- Loading branch information
Showing
14 changed files
with
5,313 additions
and
3 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
syntax = "proto3"; | ||
package onex.market; | ||
import "gogoproto/gogo.proto"; | ||
import "cosmos_proto/cosmos.proto"; | ||
|
||
option go_package = "onex/x/market/types"; | ||
|
||
// Member defines the parameters for a member of a pair for pool. | ||
message Member { | ||
string pair = 1; | ||
string denom_a = 2; | ||
string denom_b = 3; | ||
// Member Balance of denom b | ||
string balance = 4 [ | ||
(cosmos_proto.scalar) = "cosmos.Int", | ||
(gogoproto.customtype) = "cosmossdk.io/math.Int", | ||
(gogoproto.nullable) = false | ||
]; | ||
string previous = 5; | ||
uint64 limit = 6; | ||
uint64 stop = 7; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
syntax = "proto3"; | ||
package onex.market; | ||
import "gogoproto/gogo.proto"; | ||
import "cosmos_proto/cosmos.proto"; | ||
|
||
option go_package = "onex/x/market/types"; | ||
|
||
// Pool defines the parameters for | ||
message Pool { | ||
string pair = 1; | ||
string denom1 = 2; | ||
string denom2 = 3; | ||
Volume volume1 = 4; | ||
Volume volume2 = 5; | ||
repeated Leader leaders = 6; | ||
// Pool liquidity | ||
string drops = 7 [ | ||
(cosmos_proto.scalar) = "cosmos.Int", | ||
(gogoproto.customtype) = "cosmossdk.io/math.Int", | ||
(gogoproto.nullable) = false | ||
]; | ||
uint64 history = 8; | ||
} | ||
|
||
// Leader defines the parameters for | ||
message Leader { | ||
string address = 1; | ||
// Pool liquidity | ||
string drops = 7 [ | ||
(cosmos_proto.scalar) = "cosmos.Int", | ||
(gogoproto.customtype) = "cosmossdk.io/math.Int", | ||
(gogoproto.nullable) = false | ||
]; | ||
} | ||
|
||
// Volume defines the parameters for | ||
message Volume { | ||
string denom = 1; | ||
string amount = 2 [ | ||
(cosmos_proto.scalar) = "cosmos.Int", | ||
(gogoproto.customtype) = "cosmossdk.io/math.Int", | ||
(gogoproto.nullable) = false | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package keeper | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/runtime" | ||
|
||
"context" | ||
"onex/x/market/types" | ||
) | ||
|
||
// GetParams get all parameters as types.Params | ||
func (k Keeper) GetMember( | ||
ctx context.Context, | ||
denomA string, | ||
denomB string, | ||
) (member types.Member, found bool) { | ||
store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) | ||
bz := store.Get(types.MemberKey( | ||
denomA, | ||
denomB, | ||
)) | ||
if bz == nil { | ||
return member, false | ||
} | ||
|
||
k.cdc.MustUnmarshal(bz, &member) | ||
return member, true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package keeper | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/runtime" | ||
|
||
"context" | ||
"onex/x/market/types" | ||
) | ||
|
||
// GetParams get all parameters as types.Params | ||
func (k Keeper) GetPool( | ||
ctx context.Context, | ||
denomA string, | ||
denomB string, | ||
) (pool types.Pool, found bool) { | ||
store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) | ||
bz := store.Get(types.PoolKey( | ||
denomA, | ||
denomB, | ||
)) | ||
if bz == nil { | ||
return pool, false | ||
} | ||
|
||
k.cdc.MustUnmarshal(bz, &pool) | ||
return pool, true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package types | ||
|
||
const ( | ||
// MemberKeyPrefix is the prefix to retrieve all Member | ||
MemberKeyPrefix = "Member/value/" | ||
) | ||
|
||
// MemberKey returns the store key to retrieve a Member from the index fields | ||
func MemberKey( | ||
denomA string, | ||
denomB string, | ||
) []byte { | ||
var key []byte | ||
|
||
denomABytes := []byte(denomA) | ||
key = append(key, denomABytes...) | ||
key = append(key, []byte("/")...) | ||
|
||
denomBBytes := []byte(denomB) | ||
key = append(key, denomBBytes...) | ||
key = append(key, []byte("/")...) | ||
|
||
return key | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package types | ||
|
||
import ( | ||
"slices" | ||
"strings" | ||
) | ||
|
||
const ( | ||
// PoolKeyPrefix is the prefix to retrieve all Pool | ||
PoolKeyPrefix = "Pool/value/" | ||
) | ||
|
||
// PoolKey returns the store key to retrieve a Pool | ||
func PoolKey( | ||
denomA string, | ||
denomB string, | ||
) []byte { | ||
|
||
denoms := []string{denomA, denomB} | ||
// CoinAmsg and CoinBmsg pre-sort from raw msg | ||
|
||
slices.Sort(denoms) | ||
|
||
var key []byte | ||
|
||
pairBytes := []byte(strings.Join(denoms, ", ")) | ||
key = append(key, pairBytes...) | ||
key = append(key, []byte("/")...) | ||
|
||
return key | ||
} |
Oops, something went wrong.