mirror of
https://github.com/galacticship/terra.git
synced 2025-04-19 09:33:12 +00:00
Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
399f71ef97 | |||
5fdd6f16ff | |||
fb1a965999 | |||
b4bed377b8 | |||
e18b524bc0 |
@ -51,6 +51,14 @@ func NewRouter(querier *terra.Querier) (terra.Router, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "init ASTROLUNA pair")
|
return nil, errors.Wrap(err, "init ASTROLUNA pair")
|
||||||
}
|
}
|
||||||
|
PRISMUST, err := NewXykPair(querier, "terra10nfk6fcz5nc5uru964qmpels9ctg6j0vczjgl7", terra.PRISM, terra.UST, terra.ASTRO_PRISMUSTLP)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "init PRISMUST pair")
|
||||||
|
}
|
||||||
|
YLUNALUNA, err := NewXykPair(querier, "terra1aa68js6yxavg9zzzle2zaynem9cstvmaj3xyu3", terra.YLUNA, terra.LUNA, terra.ASTRO_YLUNALUNALP)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "init YLUNALUNA pair")
|
||||||
|
}
|
||||||
|
|
||||||
LUNABLUNA, err := NewStablePair(querier, "terra1j66jatn3k50hjtg2xemnjm8s7y8dws9xqa5y8w", terra.LUNA, terra.BLUNA, terra.ASTRO_LUNABLUNALP)
|
LUNABLUNA, err := NewStablePair(querier, "terra1j66jatn3k50hjtg2xemnjm8s7y8dws9xqa5y8w", terra.LUNA, terra.BLUNA, terra.ASTRO_LUNABLUNALP)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -60,6 +68,14 @@ func NewRouter(querier *terra.Querier) (terra.Router, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "init MARSXMARS pair")
|
return nil, errors.Wrap(err, "init MARSXMARS pair")
|
||||||
}
|
}
|
||||||
|
KUSTUST, err := NewStablePair(querier, "terra15rx5ghq4nxrv62fqvdvm78kuasfkl95c6mcmqs", terra.KUST, terra.UST, terra.ASTRO_KUSTUSTLP)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "init KUSTUST pair")
|
||||||
|
}
|
||||||
|
PRISMXPRISM, err := NewStablePair(querier, "terra1c868juk7lk9vuvetf0644qgxscsu4xwag6yaxs", terra.PRISM, terra.XPRISM, terra.ASTRO_PRISMXPRISMLP)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "init KUSTUST pair")
|
||||||
|
}
|
||||||
|
|
||||||
r.SetPairs(
|
r.SetPairs(
|
||||||
LUNAUST,
|
LUNAUST,
|
||||||
@ -73,6 +89,10 @@ func NewRouter(querier *terra.Querier) (terra.Router, error) {
|
|||||||
ASTROLUNA,
|
ASTROLUNA,
|
||||||
LUNABLUNA,
|
LUNABLUNA,
|
||||||
MARSXMARS,
|
MARSXMARS,
|
||||||
|
KUSTUST,
|
||||||
|
PRISMUST,
|
||||||
|
PRISMXPRISM,
|
||||||
|
YLUNALUNA,
|
||||||
//{terra.VKR, terra.UST},
|
//{terra.VKR, terra.UST},
|
||||||
//{terra.APOLLO, terra.UST},
|
//{terra.APOLLO, terra.UST},
|
||||||
//{terra.ORION, terra.UST},
|
//{terra.ORION, terra.UST},
|
||||||
|
243
protocols/deviantfactions/market.go
Normal file
243
protocols/deviantfactions/market.go
Normal file
@ -0,0 +1,243 @@
|
|||||||
|
package deviantfactions
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/galacticship/terra"
|
||||||
|
"github.com/galacticship/terra/cosmos"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/shopspring/decimal"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Market struct {
|
||||||
|
*terra.Contract
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewMarket(q *terra.Querier) (*Market, error) {
|
||||||
|
contract, err := terra.NewContract(q, "terra1t37vatdcsmg4qlyy8n4fgapecce5g4gw5mlzlt")
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "init contract object")
|
||||||
|
}
|
||||||
|
|
||||||
|
return &Market{
|
||||||
|
Contract: contract,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type Listing struct {
|
||||||
|
Owner string
|
||||||
|
TokenId string
|
||||||
|
AskToken terra.Token
|
||||||
|
Price decimal.Decimal
|
||||||
|
BlockCreated int64
|
||||||
|
BlockExpires int64
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Market) AllCollections(ctx context.Context) ([]string, error) {
|
||||||
|
var res []string
|
||||||
|
startAfter := ""
|
||||||
|
for {
|
||||||
|
tmp, err := m.allCollectionsPage(ctx, 30, startAfter)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "getting page with startafter %s", startAfter)
|
||||||
|
}
|
||||||
|
res = append(res, tmp...)
|
||||||
|
if len(tmp) < 30 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
startAfter = tmp[len(tmp)-1]
|
||||||
|
}
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Market) allCollectionsPage(ctx context.Context, limit int, startAfter string) ([]string, error) {
|
||||||
|
var q struct {
|
||||||
|
AllCollections struct {
|
||||||
|
Limit int `json:"limit"`
|
||||||
|
StartAfter string `json:"start_after"`
|
||||||
|
} `json:"all_collections"`
|
||||||
|
}
|
||||||
|
q.AllCollections.Limit = limit
|
||||||
|
q.AllCollections.StartAfter = startAfter
|
||||||
|
var r struct {
|
||||||
|
Collections []string `json:"collections"`
|
||||||
|
}
|
||||||
|
err := m.QueryStore(ctx, q, &r)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "querying contract store")
|
||||||
|
}
|
||||||
|
|
||||||
|
return r.Collections, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Market) AllListedTokens(ctx context.Context, collectionIds []string) ([]Listing, error) {
|
||||||
|
var res []Listing
|
||||||
|
startAfter := ""
|
||||||
|
for {
|
||||||
|
tmp, err := m.allListedTokensPage(ctx, collectionIds, 30, startAfter)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "getting page with startafter %s", startAfter)
|
||||||
|
}
|
||||||
|
res = append(res, tmp...)
|
||||||
|
if len(tmp) < 30 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
startAfter = tmp[len(tmp)-1].TokenId
|
||||||
|
}
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Market) allListedTokensPage(ctx context.Context, collectionIds []string, limit int, startAfter string) ([]Listing, error) {
|
||||||
|
var q struct {
|
||||||
|
AllListedTokens struct {
|
||||||
|
CollectionIds []string `json:"collection_ids"`
|
||||||
|
Limit int `json:"limit"`
|
||||||
|
StartAfter string `json:"start_after"`
|
||||||
|
} `json:"all_listed_tokens"`
|
||||||
|
}
|
||||||
|
q.AllListedTokens.CollectionIds = collectionIds
|
||||||
|
q.AllListedTokens.Limit = limit
|
||||||
|
q.AllListedTokens.StartAfter = startAfter
|
||||||
|
var r struct {
|
||||||
|
Listings []struct {
|
||||||
|
Owner string `json:"owner"`
|
||||||
|
TokenId string `json:"token_id"`
|
||||||
|
Ask struct {
|
||||||
|
Denom string `json:"denom"`
|
||||||
|
Amount decimal.Decimal `json:"amount"`
|
||||||
|
} `json:"ask"`
|
||||||
|
BlockCreated int64 `json:"block_created"`
|
||||||
|
BlockExpires int64 `json:"block_expires"`
|
||||||
|
} `json:"listings"`
|
||||||
|
}
|
||||||
|
|
||||||
|
err := m.QueryStore(ctx, q, &r)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "querying store")
|
||||||
|
}
|
||||||
|
var res []Listing
|
||||||
|
for _, listing := range r.Listings {
|
||||||
|
token := terra.NativeTokenFromDenom(listing.Ask.Denom)
|
||||||
|
res = append(res, Listing{
|
||||||
|
Owner: listing.Owner,
|
||||||
|
TokenId: listing.TokenId,
|
||||||
|
AskToken: token,
|
||||||
|
Price: token.ValueFromTerra(listing.Ask.Amount),
|
||||||
|
BlockCreated: listing.BlockCreated,
|
||||||
|
BlockExpires: listing.BlockExpires,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Market) ListedTokensByUser(ctx context.Context, address cosmos.AccAddress) ([]string, error) {
|
||||||
|
var res []string
|
||||||
|
startAfter := ""
|
||||||
|
for {
|
||||||
|
tmp, err := m.listedTokensByUserPage(ctx, address, startAfter)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "getting page with startafter %s", startAfter)
|
||||||
|
}
|
||||||
|
if len(tmp) == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
res = append(res, tmp...)
|
||||||
|
startAfter = tmp[len(tmp)-1]
|
||||||
|
}
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Market) listedTokensByUserPage(ctx context.Context, address cosmos.AccAddress, startAfter string) ([]string, error) {
|
||||||
|
var q struct {
|
||||||
|
ListedTokens struct {
|
||||||
|
Owner string `json:"owner"`
|
||||||
|
StartAfter string `json:"start_after"`
|
||||||
|
} `json:"listed_tokens"`
|
||||||
|
}
|
||||||
|
q.ListedTokens.Owner = address.String()
|
||||||
|
q.ListedTokens.StartAfter = startAfter
|
||||||
|
var r struct {
|
||||||
|
Tokens []string `json:"tokens"`
|
||||||
|
}
|
||||||
|
err := m.QueryStore(ctx, q, &r)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "querying store")
|
||||||
|
}
|
||||||
|
return r.Tokens, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Market) TokensByUser(ctx context.Context, address cosmos.AccAddress) ([]string, error) {
|
||||||
|
var res []string
|
||||||
|
startAfter := ""
|
||||||
|
for {
|
||||||
|
tmp, err := m.tokensByUserPage(ctx, address, 30, startAfter)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "getting page with startafter %s", startAfter)
|
||||||
|
}
|
||||||
|
if len(tmp) == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
res = append(res, tmp...)
|
||||||
|
startAfter = tmp[len(tmp)-1]
|
||||||
|
}
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Market) tokensByUserPage(ctx context.Context, address cosmos.AccAddress, limit int, startAfter string) ([]string, error) {
|
||||||
|
var q struct {
|
||||||
|
Tokens struct {
|
||||||
|
Owner string `json:"owner"`
|
||||||
|
Limit int `json:"limit"`
|
||||||
|
StartAfter string `json:"start_after"`
|
||||||
|
} `json:"tokens"`
|
||||||
|
}
|
||||||
|
q.Tokens.Owner = address.String()
|
||||||
|
q.Tokens.Limit = limit
|
||||||
|
q.Tokens.StartAfter = startAfter
|
||||||
|
var r struct {
|
||||||
|
Tokens []string `json:"tokens"`
|
||||||
|
}
|
||||||
|
err := m.QueryStore(ctx, q, &r)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "querying store")
|
||||||
|
}
|
||||||
|
return r.Tokens, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Market) NewCancelTokenListingMessage(sender cosmos.AccAddress, tokenId string) (cosmos.Msg, error) {
|
||||||
|
var q struct {
|
||||||
|
CancelTokenListing struct {
|
||||||
|
TokenId string `json:"token_id"`
|
||||||
|
} `json:"cancel_token_listing"`
|
||||||
|
}
|
||||||
|
q.CancelTokenListing.TokenId = tokenId
|
||||||
|
return m.NewMsgExecuteContract(sender, q)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Market) NewListTokenMessage(sender cosmos.AccAddress, tokenId string, AskToken terra.NativeToken, AskPrice decimal.Decimal, BlocksToListFor int64) (cosmos.Msg, error) {
|
||||||
|
var q struct {
|
||||||
|
ListToken struct {
|
||||||
|
TokenId string `json:"token_id"`
|
||||||
|
Ask struct {
|
||||||
|
Denom string `json:"denom"`
|
||||||
|
Amount decimal.Decimal `json:"amount"`
|
||||||
|
} `json:"ask"`
|
||||||
|
BlocksToListFor int64 `json:"blocks_to_list_for"`
|
||||||
|
} `json:"list_token"`
|
||||||
|
}
|
||||||
|
q.ListToken.TokenId = tokenId
|
||||||
|
q.ListToken.Ask.Denom = AskToken.Denom()
|
||||||
|
q.ListToken.Ask.Amount = AskToken.ValueToTerra(AskPrice)
|
||||||
|
q.ListToken.BlocksToListFor = BlocksToListFor
|
||||||
|
return m.NewMsgExecuteContract(sender, q)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Market) NewBuyTokenMessage(sender cosmos.AccAddress, tokenId string, token terra.NativeToken, price decimal.Decimal) (cosmos.Msg, error) {
|
||||||
|
var q struct {
|
||||||
|
BuyToken struct {
|
||||||
|
TokenId string `json:"token_id"`
|
||||||
|
} `json:"buy_token"`
|
||||||
|
}
|
||||||
|
q.BuyToken.TokenId = tokenId
|
||||||
|
return token.NewMsgSendExecute(sender, m.Contract, price, q)
|
||||||
|
}
|
@ -40,6 +40,23 @@ func (f *Farm) WithdrawableRewards(ctx context.Context, address cosmos.AccAddres
|
|||||||
return terra.PRISM.ValueFromTerra(r.Withdrawable), nil
|
return terra.PRISM.ValueFromTerra(r.Withdrawable), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *Farm) BondAmount(ctx context.Context, address cosmos.AccAddress) (decimal.Decimal, error) {
|
||||||
|
var q struct {
|
||||||
|
RewardInfo struct {
|
||||||
|
StakerAddr string `json:"staker_addr"`
|
||||||
|
} `json:"reward_info"`
|
||||||
|
}
|
||||||
|
q.RewardInfo.StakerAddr = address.String()
|
||||||
|
var r struct {
|
||||||
|
BondAmount decimal.Decimal `json:"bond_amount"`
|
||||||
|
}
|
||||||
|
err := f.QueryStore(ctx, q, &r)
|
||||||
|
if err != nil {
|
||||||
|
return decimal.Zero, errors.Wrap(err, "querying contract store")
|
||||||
|
}
|
||||||
|
return terra.YLUNA.ValueFromTerra(r.BondAmount), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (f *Farm) NewBondMessage(sender cosmos.AccAddress, amount decimal.Decimal) (cosmos.Msg, error) {
|
func (f *Farm) NewBondMessage(sender cosmos.AccAddress, amount decimal.Decimal) (cosmos.Msg, error) {
|
||||||
var q struct {
|
var q struct {
|
||||||
Bond struct{} `json:"bond"`
|
Bond struct{} `json:"bond"`
|
||||||
|
27
tokens.go
27
tokens.go
@ -52,20 +52,25 @@ var (
|
|||||||
WHSD, _ = NewCw20Token("terra1ustvnmngueq0p4jd7gfnutgvdc6ujpsjhsjd02", "WHSD", 8)
|
WHSD, _ = NewCw20Token("terra1ustvnmngueq0p4jd7gfnutgvdc6ujpsjhsjd02", "WHSD", 8)
|
||||||
XASTRO, _ = NewCw20Token("terra14lpnyzc9z4g3ugr4lhm8s4nle0tq8vcltkhzh7", "xASTRO", 6)
|
XASTRO, _ = NewCw20Token("terra14lpnyzc9z4g3ugr4lhm8s4nle0tq8vcltkhzh7", "xASTRO", 6)
|
||||||
XMARS, _ = NewCw20Token("terra1a04v570f9cxp49mk06vjsm8axsswndpwwt67k4", "xMARS", 6)
|
XMARS, _ = NewCw20Token("terra1a04v570f9cxp49mk06vjsm8axsswndpwwt67k4", "xMARS", 6)
|
||||||
|
KUST, _ = NewCw20Token("terra1g53pyke8jtmt4lwvk4yl0xaqc4u0qlsl8dz3ex", "kUST", 6)
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ASTRO_LUNAUSTLP, _ = NewCw20Token("terra1m24f7k4g66gnh9f7uncp32p722v0kyt3q4l3u5", "uLP", 6)
|
ASTRO_LUNAUSTLP, _ = NewCw20Token("terra1m24f7k4g66gnh9f7uncp32p722v0kyt3q4l3u5", "uLP", 6)
|
||||||
ASTRO_BLUNAUSTLP, _ = NewCw20Token("terra1aaqmlv4ajsg9043zrhsd44lk8dqnv2hnakjv97", "uLP", 6)
|
ASTRO_BLUNAUSTLP, _ = NewCw20Token("terra1aaqmlv4ajsg9043zrhsd44lk8dqnv2hnakjv97", "uLP", 6)
|
||||||
ASTRO_ANCUSTLP, _ = NewCw20Token("terra1wmaty65yt7mjw6fjfymkd9zsm6atsq82d9arcd", "uLP", 6)
|
ASTRO_ANCUSTLP, _ = NewCw20Token("terra1wmaty65yt7mjw6fjfymkd9zsm6atsq82d9arcd", "uLP", 6)
|
||||||
ASTRO_MIRUSTLP, _ = NewCw20Token("terra17trxzqjetl0q6xxep0s2w743dhw2cay0x47puc", "uLP", 6)
|
ASTRO_MIRUSTLP, _ = NewCw20Token("terra17trxzqjetl0q6xxep0s2w743dhw2cay0x47puc", "uLP", 6)
|
||||||
ASTRO_MINEUSTLP, _ = NewCw20Token("terra16unvjel8vvtanxjpw49ehvga5qjlstn8c826qe", "uLP", 6)
|
ASTRO_MINEUSTLP, _ = NewCw20Token("terra16unvjel8vvtanxjpw49ehvga5qjlstn8c826qe", "uLP", 6)
|
||||||
ASTRO_SKUJIKUJILP, _ = NewCw20Token("terra1kp4n4tms5w4tvvypya7589zswssqqahtjxy6da", "uLP", 6)
|
ASTRO_SKUJIKUJILP, _ = NewCw20Token("terra1kp4n4tms5w4tvvypya7589zswssqqahtjxy6da", "uLP", 6)
|
||||||
ASTRO_MARSUSTLP, _ = NewCw20Token("terra1ww6sqvfgmktp0afcmvg78st6z89x5zr3tmvpss", "uLP", 6)
|
ASTRO_MARSUSTLP, _ = NewCw20Token("terra1ww6sqvfgmktp0afcmvg78st6z89x5zr3tmvpss", "uLP", 6)
|
||||||
ASTRO_ASTROUSTLP, _ = NewCw20Token("terra17n5sunn88hpy965mzvt3079fqx3rttnplg779g", "uLP", 6)
|
ASTRO_ASTROUSTLP, _ = NewCw20Token("terra17n5sunn88hpy965mzvt3079fqx3rttnplg779g", "uLP", 6)
|
||||||
ASTRO_ASTROLUNALP, _ = NewCw20Token("terra1ryxkslm6p04q0nl046quwz8ctdd5llkjnaccpa", "uLP", 6)
|
ASTRO_ASTROLUNALP, _ = NewCw20Token("terra1ryxkslm6p04q0nl046quwz8ctdd5llkjnaccpa", "uLP", 6)
|
||||||
ASTRO_LUNABLUNALP, _ = NewCw20Token("terra1htw7hm40ch0hacm8qpgd24sus4h0tq3hsseatl", "uLP", 6)
|
ASTRO_LUNABLUNALP, _ = NewCw20Token("terra1htw7hm40ch0hacm8qpgd24sus4h0tq3hsseatl", "uLP", 6)
|
||||||
ASTRO_MARSXMARSLP, _ = NewCw20Token("terra1cxmdyn5srv8uwvhgz5ckqf28zf8c7uwyz08f2j", "uLP", 6)
|
ASTRO_MARSXMARSLP, _ = NewCw20Token("terra1cxmdyn5srv8uwvhgz5ckqf28zf8c7uwyz08f2j", "uLP", 6)
|
||||||
|
ASTRO_KUSTUSTLP, _ = NewCw20Token("terra16aurvlp5xctv0ftcelaseypyc89ylf4y0s5q0y", "uLP", 6)
|
||||||
|
ASTRO_PRISMUSTLP, _ = NewCw20Token("terra156sdvmjkezv5yxpgcxug0s73zkvdqk72pldkva", "uLP", 6)
|
||||||
|
ASTRO_PRISMXPRISMLP, _ = NewCw20Token("terra198en0xuzldzyark7pqz409p3u2d2g3y3k8u3py", "uLP", 6)
|
||||||
|
ASTRO_YLUNALUNALP, _ = NewCw20Token("terra12kf0s56pz2xhus9cqs4wva2xgz8wdkuqmh396s", "uLP", 6)
|
||||||
|
|
||||||
TERRASWAP_LUNAUSTLP, _ = NewCw20Token("terra17dkr9rnmtmu7x4azrpupukvur2crnptyfvsrvr", "uLP", 6)
|
TERRASWAP_LUNAUSTLP, _ = NewCw20Token("terra17dkr9rnmtmu7x4azrpupukvur2crnptyfvsrvr", "uLP", 6)
|
||||||
TERRASWAP_BLUNALUNALP, _ = NewCw20Token("terra1nuy34nwnsh53ygpc4xprlj263cztw7vc99leh2", "uLP", 6)
|
TERRASWAP_BLUNALUNALP, _ = NewCw20Token("terra1nuy34nwnsh53ygpc4xprlj263cztw7vc99leh2", "uLP", 6)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user