Skip to content

Commit

Permalink
Merge pull request #146 from renproject/feat/cosmos-denom
Browse files Browse the repository at this point in the history
UST support
  • Loading branch information
jazg authored May 9, 2022
2 parents 37505a8 + 4304956 commit 4ebc519
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
2 changes: 1 addition & 1 deletion chain/cosmos/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (client *Client) Tx(ctx context.Context, txHash pack.Bytes) (account.Tx, pa
if res.Code != 0 {
return &Tx{}, pack.NewU64(0), fmt.Errorf("tx failed code: %v, log: %v", res.Code, res.RawLog)
}
return &Tx{originalTx: authStdTx, encoder: client.ctx.TxConfig.TxEncoder()}, pack.NewU64(1), nil
return &Tx{originalTx: authStdTx, encoder: client.ctx.TxConfig.TxEncoder(), denom: string(client.opts.CoinDenom)}, pack.NewU64(1), nil
}

// SubmitTx to the Cosmos based network.
Expand Down
20 changes: 14 additions & 6 deletions chain/cosmos/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ func (builder txBuilder) BuildTx(ctx context.Context, fromPubKey *id.PubKey, to
txBuilder: txBuilder,
sendMsg: &sendMsg,
memo: string(payload),
denom: string(builder.client.opts.CoinDenom),
}, nil
}

Expand Down Expand Up @@ -219,13 +220,17 @@ func (msg MsgSend) Msg() types.Msg {

// Tx is a tx.Tx wrapper
type Tx struct {
// Always present
originalTx *txTypes.Tx
encoder types.TxEncoder
sendMsg *MsgSend
memo string
signMsg []byte
sigV2 signing.SignatureV2
txBuilder client.TxBuilder
denom string

// Fields only used when constucting with a tx builder
sendMsg *MsgSend
memo string
signMsg []byte
sigV2 signing.SignatureV2
txBuilder client.TxBuilder
}

// From returns the sender of the transaction
Expand Down Expand Up @@ -261,7 +266,10 @@ func (t Tx) Value() pack.U256 {
if t.originalTx != nil {
msgs := t.originalTx.GetBody().Messages
for _, msg := range msgs {
value.AddAssign(pack.NewU64(msg.GetCachedValue().(*bankType.MsgSend).Amount[0].Amount.Uint64()))
amount := msg.GetCachedValue().(*bankType.MsgSend).Amount[0]
if amount.Denom == t.denom {
value.AddAssign(pack.NewU64(amount.Amount.Uint64()))
}
}
} else if t.sendMsg != nil {
value.AddAssign(pack.NewU64(t.sendMsg.Amount.Coins()[0].Amount.Uint64()))
Expand Down
8 changes: 5 additions & 3 deletions chain/terra/terra.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,15 @@ func NewTxBuilder(opts TxBuilderOptions, client *Client) account.TxBuilder {

type GasEstimator struct {
url string
key string
decimals int
fallbackGas pack.U256
}

func NewHttpGasEstimator(url string, decimals int, fallbackGas pack.U256) GasEstimator {
func NewHttpGasEstimator(url, key string, decimals int, fallbackGas pack.U256) GasEstimator {
return GasEstimator{
url: url,
key: key,
decimals: decimals,
fallbackGas: fallbackGas,
}
Expand All @@ -89,9 +91,9 @@ func (gasEstimator GasEstimator) EstimateGas(ctx context.Context) (pack.U256, pa
if err := json.NewDecoder(response.Body).Decode(&results); err != nil {
return gasEstimator.fallbackGas, gasEstimator.fallbackGas, err
}
gasPriceStr, ok := results["uluna"]
gasPriceStr, ok := results[gasEstimator.key]
if !ok {
return gasEstimator.fallbackGas, gasEstimator.fallbackGas, fmt.Errorf("no uluna in response")
return gasEstimator.fallbackGas, gasEstimator.fallbackGas, fmt.Errorf("no %v in response", gasEstimator.key)
}
gasPriceFloat, err := strconv.ParseFloat(gasPriceStr, 64)
if err != nil {
Expand Down
8 changes: 6 additions & 2 deletions multichain.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ const (
LUNA = Asset("LUNA") // Luna
MATIC = Asset("MATIC") // Matic PoS (Polygon)
SOL = Asset("SOL") // Solana
UST = Asset("UST") // TerraUSD
ZEC = Asset("ZEC") // Zcash

BADGER = Asset("BADGER") // Badger DAO
Expand Down Expand Up @@ -219,6 +220,8 @@ func (asset Asset) OriginChain() Chain {
return Polygon
case SOL:
return Solana
case UST:
return Terra
case ZEC:
return Zcash

Expand Down Expand Up @@ -251,7 +254,8 @@ func (asset Asset) ChainType() ChainType {
switch asset {
case BCH, BTC, DGB, DOGE, ZEC:
return ChainTypeUTXOBased
case ArbETH, AVAX, BNB, CAT, ETH, FIL, FTM, GLMR, KAVA, LUNA, MATIC, SOL:
case ArbETH, AVAX, BNB, CAT, ETH, FIL, FTM, GLMR, KAVA, LUNA, MATIC, SOL,
UST:
return ChainTypeAccountBased

case BADGER, BUSD, CRV, DAI, EURT, FTT, ibBTC, KNC, LINK, MIM, REN, ROOK,
Expand All @@ -277,7 +281,7 @@ func (asset Asset) ChainType() ChainType {
// Type returns the asset-type (Native or Token) for the given asset.
func (asset Asset) Type() AssetType {
switch asset {
case ArbETH, AVAX, BNB, CAT, ETH, FTM, GLMR, KAVA, MATIC, SOL:
case ArbETH, AVAX, BNB, CAT, ETH, FTM, GLMR, KAVA, MATIC, SOL, UST:
return AssetTypeNative

case BADGER, BUSD, CRV, DAI, EURT, FTT, ibBTC, KNC, LINK, MIM, REN, ROOK,
Expand Down

0 comments on commit 4ebc519

Please sign in to comment.