forked from byeongsu-hong/terra.go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
market.go
52 lines (41 loc) · 1.15 KB
/
market.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package market
import (
"context"
"github.com/cawabunga/terra.go/bind"
"github.com/cawabunga/terra.go/interface/standard/cw20"
"github.com/airbloc/logger"
cosmostypes "github.com/cosmos/cosmos-sdk/types"
"github.com/pkg/errors"
)
type Market interface {
StableDenom() string
Anchored() cw20.Token
bind.BaseContract
Executor
ExecutorMsg
Querier
}
type market struct {
stableDenom string
anchored cw20.Token
logger logger.Logger
bind.BaseContract
}
func (m market) StableDenom() string { return m.stableDenom }
func (m market) Anchored() cw20.Token { return m.anchored }
func NewContract(ctx context.Context, addr cosmostypes.AccAddress, client terra.Client) (Market, error) {
m := market{
BaseContract: bind.NewBaseContract(addr, client),
logger: logger.New("anchor/money-market/market"),
}
configResp, err := m.GetConfig(ctx)
if err != nil {
return nil, errors.Wrap(err, "fetch market contract config")
}
m.stableDenom = configResp.StableDenom
m.anchored, err = cw20.NewTokenContract(ctx, configResp.ATerraContract, client)
if err != nil {
return nil, errors.Wrap(err, "new cw20 token contract")
}
return m, nil
}