Skip to content

Commit

Permalink
Merge branch 'main' into egor/maxborrow
Browse files Browse the repository at this point in the history
  • Loading branch information
kosegor committed Mar 29, 2023
2 parents 3f17001 + 10547c8 commit 8557750
Show file tree
Hide file tree
Showing 16 changed files with 318 additions and 91 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Fixes

- [1929](https://github.com/umee-network/umee/pull/1929) Leverage: `MaxWithdraw` now accounts for `MinCollateralLiquidity`
- [1957](https://github.com/umee-network/umee/pull/1957) Leverage: Reserved amount per block now rounds up.
- [1956](https://github.com/umee-network/umee/pull/1956) Leverage: token liquidation threshold must be bigger than collateral_weight.
- [1954](https://github.com/umee-network/umee/pull/1954) Leverage: `MaxBorrow` now accounts for
`MinCollateralLiquidity` and `MaxSupplyUtilization`
Expand Down
43 changes: 27 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,36 @@ Umee will allow a multitude of decentralized debt products.

See [Release procedure](CONTRIBUTING.md#release-procedure) for more information about the release model.

Since `umeed v3.2` there is a new runtime dependency: `libwasmvm.x86_64.so v1.1.1` is required.
Building from source will automatically link the `libwasmvm.x86_64.so` created as a part of the build process (you must build on same host as you run the binary, or copy the `libwasmvm.x86_64.so` your lib directory).
### Release Compatibility Matrix

After `Price Feeder v2.1.0` the recommended oracle price feeder has been moved to this [repository](https://github.com/ojo-network/price-feeder/tree/umee) with the version prefix `umee/v.x`.
| Umee Version | Mainnet | Cosmos SDK | IBC | Peggo | Price Feeder | Gravity Bridge | libwasmvm |
| :----------: | :-----: | :--------: | :----: | :-----: | :----------: | :------------------------: | :-------: |
| v0.8.x || v0.45.x | v2.0.x | v0.2.x | v0.1.x | | |
| v1.x.x || v0.45.x | v2.0.x | v0.2.x | N/A | umee/v1 module/v1.4.x-umee | |
| v2.x.x || v0.45.x | v2.3.x | v0.2.x | v0.2.x | umee/v2 module/v1.4.x | |
| v3.0-1.x || v0.46.x | v5.0.x | v1.3.x+ | v1.0.x | umee/v3 module/v1.5.x-umee | |
| v3.1.0-cw1 || v0.46.x | v5.0.x | v1.3.x+ | v2.0.x | umee/v3 module/v1.5.x-umee | |
| v3.2.x || v0.46.6+ | v5.1.x | v1.3.x+ | v2.0.x | umee/v3 v1.5.3-umee-3 | v1.1.1 |
| v3.3.x || v0.46.6+ | v5.1.x | v1.3.x+ | v2.0.2 | umee/v3 v1.5.3-umee-3 | v1.1.1 |
| v4.0.x || v0.46.6+ | v5.1.x | v1.3.x+ | v2.0.3 | umee/v4 v1.5.3-umee-4 | v1.1.1 |
| v4.1.x || v0.46.7+ | v5.2.x | v1.3.x+ | v2.1.0 | umee/v4 v1.5.3-umee-4 | v1.1.1 |
| v4.2.x || v0.46.10+ | v5.2.x | v1.3.x+ | umee/v2.1.1 | umee/v4 v1.5.3-umee-4 | v1.1.1 |
| v4.3.x || v0.46.11+ | v6.1.x | v1.3.x+ | umee/v2.1.1 | umee/v4 v1.5.3-umee-5 | v1.2.1 |

### Release Compatibility Matrix
#### Price Feeder

Since `Price Feeder v2.1.0` the recommended oracle price feeder has been moved to this [repository](https://github.com/ojo-network/price-feeder/tree/umee) with the version prefix `umee/v.x`.

#### libwasmvm

When you build the binary from source on the server machine you probably don't need any change. Building from source automatically link the `libwasmvm.$(uname -m).so` created as a part of the build process.

However when you download a binary from GitHub, or from other source, make sure you have required version of `libwasmvm.<cpu_arch>.so` (should be in your lib directory, e.g.: `/usr/local/lib/`). You can get it:

- from you build machine: copy `$GOPATH/pkg/mod/github.com/!cosm!wasm/wasmvm@v<version>/internal/api/libwasmvm.$(uname -m).so`
- or download from CosmWasm GitHub `wget https://raw.githubusercontent.com/CosmWasm/wasmvm/v<version>/internal/api/libwasmvm.$(uname -m).so -O /lib/libwasmvm.$(uname -m).so`

| Umee Version | Mainnet | Experimental | Cosmos SDK | IBC | Peggo | Price Feeder | Gravity Bridge |
| :----------: | :-----: | :----------: | :--------: | :----: | :-----: | :----------: | :------------------------: |
| v0.8.x ||| v0.45.x | v2.0.x | v0.2.x | v0.1.x | |
| v1.x.x ||| v0.45.x | v2.0.x | v0.2.x | N/A | umee/v1 module/v1.4.x-umee |
| v2.x.x ||| v0.45.x | v2.3.x | v0.2.x | v0.2.x | umee/v2 module/v1.4.x |
| v3.0-1.x ||| v0.46.x | v5.0.x | v1.3.x+ | v1.0.x | umee/v3 module/v1.5.x-umee |
| v3.1.0-cw1 ||| v0.46.x | v5.0.x | v1.3.x+ | v2.0.x | umee/v3 module/v1.5.x-umee |
| v3.2.x ||| v0.46.6+ | v5.1.x | v1.3.x+ | v2.0.x | umee/v3 v1.5.3-umee-3 |
| v3.3.x ||| v0.46.6+ | v5.1.x | v1.3.x+ | v2.0.2 | umee/v3 v1.5.3-umee-3 |
| v4.0.x ||| v0.46.6+ | v5.1.x | v1.3.x+ | v2.0.3 | umee/v4 v1.5.3-umee-4 |
| v4.1.x ||| v0.46.7+ | v5.2.x | v1.3.x+ | v2.1.0 | umee/v4 v1.5.3-umee-4 |
| v4.2.x ||| v0.46.10+ | v5.2.x | v1.3.x+ | umee/v2.1.1 | umee/v4 v1.5.3-umee-4 |
You don't need to do anything if you are using our Docker image.

### Active Networks

Expand Down
57 changes: 32 additions & 25 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,38 @@

Release Procedure is defined in the [CONTRIBUTING](CONTRIBUTING.md#release-procedure) document.

## v4.3.0

Highlights:

- ICA

### Upgrade instructions

- Note: Skip this step if you build binary from source and are able to properly link libwasmvm.

- Download `libwasmvm`:

```bash
$ wget https://raw.githubusercontent.com/CosmWasm/wasmvm/v1.1.1/internal/api/libwasmvm.$(uname -m).so -O /lib/libwasmvm.$(uname -m).so
```

- Download latest binary or build from source.
- Run the binary to make sure it works for you: `umeed --version`
- Wait for software upgrade proposal to pass and trigger the chain upgrade.
- Swap binaries.
- Restart the chain.
- Ensure latest Peggo (v1.4.0) is running
- Ensure latest Price Feeder (v2.1.0) is running and check your price feeder config is up to date.

You can use Cosmovisor → see [instructions](https://github.com/umee-network/umee/#cosmovisor).

NOTE: BEFORE the upgrade, make sure the binary is working and libwasmvm is in your system. You can test it by running `./umeed-v4.3.0 version`.

#### Docker

Docker images are available in [ghcr.io umee-network](https://github.com/umee-network/umee/pkgs/container/umeed) repository.

## v4.2.0

The main highlight of this release is new `x/uibc` module which introduces IBC Quota functionality.
Expand Down Expand Up @@ -41,31 +73,6 @@ Related to min gas price updates, you MUST also set the related parameter when s
--cosmos-gas-prices="0.1uumee"
```

### Upgrade instructions

- Note: Skip this step if you build binary from source and are able to properly link libwasmvm.
- Download `libwasmvm`:

```bash
$ wget https://raw.githubusercontent.com/CosmWasm/wasmvm/v1.1.1/internal/api/libwasmvm.$(uname -m).so -O /lib/libwasmvm.$(uname -m).so
```

- Download latest binary or build from source.
- Run the binary to make sure it works for you: `umeed --version`
- Wait for software upgrade proposal to pass and trigger the chain upgrade.
- Swap binaries.
- Restart the chain.
- Ensure latest Peggo (v1.4.0) is running
- Ensure latest Price Feeder (v2.1.0) is running and check your price feeder config is up to date.

You can use Cosmovisor → see [instructions](https://github.com/umee-network/umee/#cosmovisor).

NOTE: BEFORE the upgrade, make sure the binary is working and libwasmvm is in your system. You can test it by running `./umeed-v4.1.0 --version`.

#### Docker

Docker images are available in [ghcr.io umee-network](https://github.com/umee-network/umee/pkgs/container/umeed) repository.

## v4.1.0

This release contains several fixes designed to make lending and borrowing more resilient during price outages. Short summary of changes is available in the [Changelog](./CHANGELOG.md)
Expand Down
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ func New(
// create IBC module from bottom to top of stack
var transferStack ibcporttypes.IBCModule
transferStack = uics20transfer.NewIBCModule(
app.LeverageKeeper,
ibctransfer.NewIBCModule(ibcTransferKeeper),
app.UIBCTransferKeeper,
)
Expand Down
7 changes: 7 additions & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ func (app UmeeApp) RegisterUpgradeHandlers(bool) {
app.registerUpgrade4_0_1(upgradeInfo)
app.registerUpgrade4_1(upgradeInfo)
app.registerUpgrade4_2(upgradeInfo)
app.registerUpgrade4_3(upgradeInfo)
}

// performs upgrade from v4.2 to v4.3
func (app *UmeeApp) registerUpgrade4_3(_ upgradetypes.Plan) {
const planName = "v4.3-beta" // TODO: change before the main release
app.UpgradeKeeper.SetUpgradeHandler(planName, onlyModuleMigrations(app, planName))
}

// performs upgrade from v4.1 to v4.2
Expand Down
2 changes: 1 addition & 1 deletion contrib/scripts/mockgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

mockgen_cmd="go run github.com/golang/mock/mockgen"

$mockgen_cmd -source ./x/uibc/expected_keepers.go -package mocks -destination ./x/uibc/mocks/keepers.go
$mockgen_cmd -source ./x/uibc/expected_keepers.go -package mocks -destination ./x/uibc/mocks/keepers.go
5 changes: 3 additions & 2 deletions tests/e2e/e2e_ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ func (s *IntegrationTestSuite) TestIBCTokenTransfer() {
})

// Non registered tokens (not exists in oracle for quota test)
// IBC Transfer will failed because it is not registered in leverage on receiver chain (UMEE)
s.Run("send_stake_to_umee", func() {
// require the recipient account receives the IBC tokens (IBC packets ACKd)
var (
Expand All @@ -185,12 +186,12 @@ func (s *IntegrationTestSuite) TestIBCTokenTransfer() {
func() bool {
balances, err = queryUmeeAllBalances(umeeAPIEndpoint, recipient)
s.Require().NoError(err)
return token.Amount.Equal(balances.AmountOf(stakeIBCHash))
return math.ZeroInt().Equal(balances.AmountOf(stakeIBCHash))
},
time.Minute,
5*time.Second,
)
s.checkSupply(umeeAPIEndpoint, stakeIBCHash, token.Amount)
s.checkSupply(umeeAPIEndpoint, stakeIBCHash, math.ZeroInt())
})

var ibcStakeERC20Addr string
Expand Down
43 changes: 43 additions & 0 deletions util/ibc/ibc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package ibc

import (
"encoding/json"
"strings"

sdkmath "cosmossdk.io/math"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
transfertypes "github.com/cosmos/ibc-go/v5/modules/apps/transfer/types"
"github.com/cosmos/ibc-go/v5/modules/core/exported"
)

// GetFundsFromPacket returns transfer amount and denom
func GetFundsFromPacket(packet exported.PacketI) (sdkmath.Int, string, error) {
var packetData transfertypes.FungibleTokenPacketData
err := json.Unmarshal(packet.GetData(), &packetData)
if err != nil {
return sdkmath.Int{}, "", err
}

amount, ok := sdkmath.NewIntFromString(packetData.Amount)
if !ok {
return sdkmath.Int{}, "", sdkerrors.ErrInvalidRequest.Wrapf("invalid transfer amount %s", packetData.Amount)
}

return amount, GetLocalDenom(packetData.Denom), nil
}

// GetLocalDenom retruns ibc denom
// Expected denoms in the following cases:
//
// send non-native: transfer/channel-0/denom -> ibc/xxx
// send native: denom -> denom
// recv (B)non-native: denom
// recv (B)native: transfer/channel-0/denom
func GetLocalDenom(denom string) string {
if strings.HasPrefix(denom, "transfer/") {
denomTrace := transfertypes.ParseDenomTrace(denom)
return denomTrace.IBCDenom()
}

return denom
}
62 changes: 62 additions & 0 deletions util/ibc/ibc_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package ibc

import (
"strconv"
"strings"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
ibctransfertypes "github.com/cosmos/ibc-go/v5/modules/apps/transfer/types"
clienttypes "github.com/cosmos/ibc-go/v5/modules/core/02-client/types"
channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types"
"github.com/tendermint/tendermint/crypto"
"gotest.tools/v3/assert"
)

func TestGetFundsFromPacket(t *testing.T) {
denom := strings.Join([]string{
"transfer",
"dest_chain",
"quark",
}, "/")

amount := strconv.Itoa(1)
data := ibctransfertypes.NewFungibleTokenPacketData(
denom,
amount,
AddressFromString("a3"),
AddressFromString("a4"),
)

packet := channeltypes.NewPacket(
data.GetBytes(),
uint64(1),
"transfer",
"channel-0",
"transfer",
"channel-0",
clienttypes.NewHeight(0, 100),
0,
)

famount, fdenom, err := GetFundsFromPacket(packet)

assert.NilError(t, err)
assert.Equal(t, denom, fdenom)
assert.Equal(t, famount.String(), amount)
}

func TestGetLocalDenom(t *testing.T) {
denom := strings.Join([]string{
"transfer",
"dest_chain",
"quark",
}, "/")

rdenom := GetLocalDenom(denom)
assert.Equal(t, rdenom, denom)
}

func AddressFromString(address string) string {
return sdk.AccAddress(crypto.AddressHash([]byte(address))).String()
}
15 changes: 9 additions & 6 deletions x/leverage/keeper/interest.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (k Keeper) AccrueAllInterest(ctx sdk.Context) error {

// calculate time elapsed since last interest accrual (measured in years for APR math)
if currentTime < prevInterestTime {
// TODO fix this when tendermint solves https://github.com/tendermint/tendermint/issues/8773
// precaution against this and similar issues: https://github.com/tendermint/tendermint/issues/8773
k.Logger(ctx).With("AccrueAllInterest will wait for block time > prevInterestTime").Error(
types.ErrNegativeTimeElapsed.Error(),
"current", currentTime,
Expand Down Expand Up @@ -133,11 +133,14 @@ func (k Keeper) AccrueAllInterest(ctx sdk.Context) error {
interestAccrued.TruncateInt(),
))

// calculate new reserves accrued for this denom
newReserves = newReserves.Add(sdk.NewCoin(
token.BaseDenom,
interestAccrued.Mul(token.ReserveFactor).TruncateInt(),
))
// if interest accrued on this denom is at least one base token
if interestAccrued.GT(sdk.OneDec()) {
// calculate new reserves gained for this denom, rounding up
newReserves = newReserves.Add(sdk.NewCoin(
token.BaseDenom,
interestAccrued.Mul(token.ReserveFactor).Ceil().TruncateInt(),
))
}

// calculate oracle rewards accrued for this denom
oracleRewards = oracleRewards.Add(sdk.NewCoin(
Expand Down
44 changes: 43 additions & 1 deletion x/uibc/ics20/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,31 @@ package ics20

import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
ibctransfer "github.com/cosmos/ibc-go/v5/modules/apps/transfer"
ibctransfertypes "github.com/cosmos/ibc-go/v5/modules/apps/transfer/types"
channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types"
ibcexported "github.com/cosmos/ibc-go/v5/modules/core/exported"

ltypes "github.com/umee-network/umee/v4/x/leverage/types"
"github.com/umee-network/umee/v4/x/uibc"
"github.com/umee-network/umee/v4/x/uibc/ics20/keeper"
)

// IBCModule embeds the ICS-20 transfer IBCModule where we only override specific
// methods.
type IBCModule struct {
// leverage keeper
lkeeper uibc.LeverageKeeper
// embed the ICS-20 transfer's AppModule
ibctransfer.IBCModule

keeper keeper.Keeper
}

func NewIBCModule(am ibctransfer.IBCModule, k keeper.Keeper) IBCModule {
func NewIBCModule(leverageKeeper uibc.LeverageKeeper, am ibctransfer.IBCModule, k keeper.Keeper) IBCModule {
return IBCModule{
lkeeper: leverageKeeper,
IBCModule: am,
keeper: k,
}
Expand All @@ -33,6 +39,19 @@ func (am IBCModule) OnRecvPacket(
packet channeltypes.Packet,
relayer sdk.AccAddress,
) ibcexported.Acknowledgement {
var data ibctransfertypes.FungibleTokenPacketData
if err := ibctransfertypes.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil {
ackErr := sdkerrors.ErrInvalidType.Wrap("cannot unmarshal ICS-20 transfer packet data")
return channeltypes.NewErrorAcknowledgement(ackErr)
}

// Allowing only registered token for ibc transfer
isSourceChain := ibctransfertypes.SenderChainIsSource(packet.GetSourcePort(), packet.GetSourceChannel(), data.Denom)
ackErr := CheckIBCInflow(ctx, packet, am.lkeeper, data.Denom, isSourceChain)
if ackErr != nil {
return ackErr
}

ack := am.IBCModule.OnRecvPacket(ctx, packet, relayer)
if ack.Success() {
var data ibctransfertypes.FungibleTokenPacketData
Expand All @@ -44,3 +63,26 @@ func (am IBCModule) OnRecvPacket(

return ack
}

func CheckIBCInflow(ctx sdk.Context,
packet channeltypes.Packet,
lkeeper uibc.LeverageKeeper,
dataDenom string, isSourceChain bool,
) ibcexported.Acknowledgement {
// if chain is recevier and sender chain is source then we need create ibc_denom (ibc/hash(channel,denom)) to
// check ibc_denom is exists in leverage token registry
if isSourceChain {
// since SendPacket did not prefix the denomination, we must prefix denomination here
sourcePrefix := ibctransfertypes.GetDenomPrefix(packet.GetDestPort(), packet.GetDestChannel())
// NOTE: sourcePrefix contains the trailing "/"
prefixedDenom := sourcePrefix + dataDenom
// construct the denomination trace from the full raw denomination and get the ibc_denom
ibcDenom := ibctransfertypes.ParseDenomTrace(prefixedDenom).IBCDenom()
_, err := lkeeper.GetTokenSettings(ctx, ibcDenom)
if err != nil && ltypes.ErrNotRegisteredToken.Is(err) {
return channeltypes.NewErrorAcknowledgement(err)
}
}

return nil
}
Loading

0 comments on commit 8557750

Please sign in to comment.