Commit Graph

70 Commits

Author SHA1 Message Date
Denali Marsh
779f8081e7
Update migrations to include uatom IBC denom money market (#1132)
* add uatom ibc denom to money markets in hard migration

* add new money market to stability committee

* clean up

* update v0_16 migration test data

* add swp, uatom ibc denoms to hard gov committee

* update committee migration testdata

* update general migration test data

* specify committee ID with vars

* fix merge var rename bug

Co-authored-by: rhuairahrighairigh <ruaridh.odonnell@gmail.com>
2022-01-15 00:12:23 +00:00
Ruaridh
ffef832d45
Upgrade to sdk v0.44.5 and add IBC (#1106)
- Upgrade cosmos-sdk to v0.44.5 from v0.39.2
- Add Legacy Tx Endpoint for backwards compatibility
- Add IBC v1.2.3 Support

Co-authored-by: DracoLi <draco@dracoli.com>
Co-authored-by: drklee3 <derrick@dlee.dev>
Co-authored-by: denalimarsh <denalimarsh@gmail.com>
Co-authored-by: Draco Li <draco@kava.io>
Co-authored-by: Nick DeLuca <nickdeluca08@gmail.com>
Co-authored-by: Kevin Davis <karzak@users.noreply.github.com>
Co-authored-by: Denali Marsh <denali@kava.io>
2022-01-07 17:39:27 -07:00
Denali Marsh
56e55cf667
Test Hard module's genesis init/export (#1011)
* introduce genesis test

* match synced deposits/borrows to expected values

* remove unnecessary assert

* pull index factor from gen accrual time
2021-09-01 13:11:15 +02:00
Ruaridh
dc6f5c6c83
Fix incentive usdx/borrow/supply reward calculation bug (#974)
* extract borrow sync logic into separate func

* fix borrow reward calculations
Use the normalized borrow as the source shares in reward calculations.

* extract supply sync logic into separate func

* prepare to fix supply reward calculations

* fix deposit reward calculations
Use the normalized deposit as the source shares in reward calculations.

* extract usdx sync logic into separate func

* prepare to fix usdx reward calculations

* fix cdp reward calculations
Use the normalized cdp debt as the source shares in reward calculations.

* fix compile error from messed up partial stage

* Fix incentive usdx reward bug (#976)

* minor test refactors

* fix overpayment bug
Init methods should not read params.
Add test to cover bug

* fix typos
2021-07-26 20:07:24 +01:00
Ruaridh
e48fed1e27
fix strings that said deposit instead of borrow (#962) 2021-07-15 09:16:25 -05:00
Ruaridh
4beaf0de54
Swap users accumulate rewards (#950)
* add swap claim type

* add store methods for swap claims

* add swap claims to genesis state

* tidy up cdp and hard hook doc comments

* add uncalled hooks to the swap keeper

* add swap rewards sync method

* add swap rewards init method

* connect swap rewards via swap hooks

* Update querier and client for swap claims (#951)

* refactor querier to dedupe code

* add swap claims querier endpoint

* add swap claim querying to rest

* add swap claim querying to cli

* add keeper method to iterate swap reward indexes

* simplify reward-factors query endpoint, add swap

* update swap hook to match latest swap branch

* rename func to not collide with latest swap branch

* Squash merge swap-acceptance branch (#956)

* add failing acceptance test for a user depositing into a pool

* implement GetAccount test helper

* implement swap.MsgDeposit for creating and adding liquidity to a pool

* update aliases, add event types, and fix typo/compiler errors in handler
test

* use only aliases names in handler test (don't use swap types -- ensures
we have run aliasgen), add assertion for even type message

* implement account and module account balance checks in handler test

* fill out handler assertions for testing keeper state and events

* update signed json representation and register swap/MsgDeposit for
proper encoding

* fill out boilerplate to get handler test to compile

* alias gen for pool

* add handling of message type; fill in deposit keeper method for
succesful compile; noop but test assertions now run up to module acc not
nil check

* add module account permissions for swap module -- fixes module account
creation; pass account keeper and supply keeper into swap keeper to
allow the ability to work with user and module accounts

* implement create pool logic for msg deposit; allows creation of a of new
pool, checking params to see if it is allowed.  Initi shares are set,
and senders number of shares are stored

* Swap migrations scaffolding (#925)

* swap module scaffolding

* global swap fee

* can't think of a reason for begin blocker; removing for abci.go for now;

* test pair types; refactor pair name logic; simplify pairs validation and
fix stack overflow error

* check comparison

* use test package

* init swap module genesis

* add basic marshall tests

* remove reward apy from pairs

* fix integration helpers

* use max swap fee constant; fix validation of swap fee; add tests to
cover param validation and param set setup

* use noerror over nil

* start genesis tests

* test param set validation mirrors param validation

* add genesis tests

* remove print statement

* add subtests for genesis test cases; add extra querier test for unknown
route; add keeper params testing

* add spec

* update swagger

* find replace hard -> swap in comments

* remove unused method

* rename pairs to allowed pools; pool is more commonly used, and
allowedPool makes it more clear what swap parameter is for.  In
addition, we won't conflict with Pool data structure for storing a
created pool in the store.

* remove generated link

* missed spec rename

* validate token order for allowed pools

* fix swagger

* json should be snakecase; change allowedPools to allowed_pools

* add legacy types

* add swap genesis to v0_15 migration

* add legacy types

* add swap genesis to v0_15 migration

* migration revisions

Co-authored-by: Nick DeLuca <nickdeluca08@gmail.com>

* keeper todos

* update keeper tests

* type todos

* update types tests

* tx deposit cli cmd

* tx deposit rest

* Swap module simulation scaffolding (#924)

* sims scaffolding

* add noop operation

* genesis revisions

* add param changes

* mvoe persistance methods to main keeper file, consolidate tests

* make helper methods private. they are tested via deposit method, and
unit testing them would make test suite brittle and refactoring
difficult

* use more clear coin variables

* code 1 is reserved, use code 2 and sequence all errors

* remove todo

* Implement deadline for swap module module message. This is implemented in
handler with a interface to easily apply to it to all messages, and
separate msg validation concerns from the keeper

* move allowed pools to params -- let pool and pool_test focus on pool domain logic, not
parameter & governance concerns

* update alias

* add unitless implementatin of constant product liquidity pool to
isolate and enapsulate liquidity logic.  Swap methods interfaces are
added, but implementation not yet added

* nits and todos

* add ErrInvalidPool

* add tests for edge cases around pool depletion; add explicit panic for
edge case that results in a pool reserve being zero; handle pool
reinitialization if it is empty

* touch up comments and flush out the rest of assertions

* add data structures for keeper state storage separate from pool domain
objects, and improve structure for easier querying

* rename pool name to pool key for events

* add support for a denominated pool that uses sdk.Coins and sdk.Coin
arguments, keeping tracking of the units in the base pool.  This gives
nice separation between pool logic, and coin/denom logic

* refactor keeper to use new records for storage, and implement pool
deposit using the denominated pool

* address previous PR comment - reminder for migration if changing
account permissions

* msg deposit should validate that denoms are not equal

* add godoc comments

* golint and some poolName -> poolID cleanup

* implement adding liquidity to an existing pool

* hardcode pools in sims

* touch up comment

* withdraw keeper logic

* withdraw type updates

* add withdraw msg tx handler

* initial withdraw test

* fix panic

* use new denominated pool with existing shares

* fix: check args on deposit cmd

* add slippage limit check for depositing to an existing pool

* send coins just before event emission

* check liquidity returned is greater than zero for both coins; ensure
returned number of shares are greater than zero

* add deadline to msgwithdraw

* register msgwithdraw

* scaffold msgwithdraw types test

* register the correct msg

* modify swap functions to also return the amount paid for the pool swap
fee.  This will be used to calculate slippage and for event tracking

* add slippage types

* add expected withdrawal coins

* calculate slippage against expected coins

* update withdraw keeper tests

* spelling, improve comments on add liquidity math

* typo

* typo

* grammer

* typo / grammer

* remove pool_id from withdraw msg

* add slippage to tx cmd

* TestWithdraw_Partial

* nit

* add withdraw no pool, no deposit record tests

* drop event check on partial withdraw test

* fix broken link

* fix broken link

* resolve merge conflicts

* ensure swap fee can not be equal to 1; add full implementation of swap
pool methods;  these implementation ensure that the pool invariant is
always greater or equal to the previous invariant

* refactor duplicated code into private swap methods

* add runtime assertion to always ensure invariant is greater or equal
to the previous invariant sub fee on swaps

* improve comments for base pool swap functions

* add swap exact input and output methods to denominated pool that wrap
the base pool interface for swapping

* comment touch ups

* more comment touchups

* fix msg deposit struct tag (#943)

* use better name for swap calculation private methods

* nits: golint

* fix misspelling in method name

* Add HARD token governance committee for Hard module (#941)

* add hard gov token committee

* revisions: update migration

* revisions: update test/data file

* initial revisions

* add TokenCommittee JSONMarshal test

* fix SetPermissions method

* remove BaseCommittee Type field

* add incentive params to allowed params

* Add SWP token governance committee for Swap module (#946)

* add swp token commitee to migration

* update test, add gen export utility method

* final revisions: add TODO

* remove slippage from withdraw to use min values for coins; add
additional validation test cases

* update alias for swap module

* add withdraw tests to handler for increased coverage; note: first pass,
improvements still yet to be made here

* refact withdraw keeper to use min amounts; panic for cases that do not
happen in normal situations

* lint fixes

* use total shares to track if pool should be deleted; add more in depth
withdraw comment

* add exact args for withdraw cmd

* extract record update methods

* update depositor share record if it exists -- do not overwrite an
existing record; ensures no loss of shares if the same address deposits
more than once

* Swap queries: deposit, pool, pools (#949)

* query deposits types

* implement deposit querier keeper methods

* query deposits CLI

* query deposits REST

* query types for pool/pools

* pool/pools querier keeper methods

* pool/pools CLI

* pool/pools REST

* basic pool/pools query tests

* basic deposit querier test

* iterate share records via owner bytes

* nit: add example for querying deposits by owner only

Co-authored-by: karzak <kjydavis3@gmail.com>

* feat: add REST tx handler for swap LP withdrawals

Co-authored-by: Nick DeLuca <nickdeluca08@gmail.com>
Co-authored-by: Denali Marsh <denali@kava.io>
Co-authored-by: denalimarsh <denalimarsh@gmail.com>
Co-authored-by: karzak <kjydavis3@gmail.com>

* expand incentive cli query docs

Co-authored-by: Nick DeLuca <nickdeluca08@gmail.com>
Co-authored-by: Denali Marsh <denali@kava.io>
Co-authored-by: denalimarsh <denalimarsh@gmail.com>
Co-authored-by: karzak <kjydavis3@gmail.com>

* minor update to godoc comment

Co-authored-by: Nick DeLuca <nickdeluca08@gmail.com>
Co-authored-by: Denali Marsh <denali@kava.io>
Co-authored-by: denalimarsh <denalimarsh@gmail.com>
Co-authored-by: karzak <kjydavis3@gmail.com>
2021-07-13 13:35:02 +01:00
Ruaridh
54c0793ced
Fix delegation claim syncing (#889)
* sync claims on validator state changes and slashes

* add test notes

* update missed sync delegator calls

* tidy up suite addresses initialization

* test claim synced when validator bonds/unbonds

* test validator slashed

* check reward factor increased

* test redelegation sync claim

* revert mistake

* resolve trailing TODOs

* call incentive hooks after hard liquidation

* check global index in tests after delegator reward sync

Co-authored-by: denalimarsh <denalimarsh@gmail.com>
Co-authored-by: karzak <kjydavis3@gmail.com>
2021-03-25 00:10:13 -06:00
Denali Marsh
eb856b5a1f
Fix: delete incentive reward factors on full withdraw/repay (#885)
* delete incentive reward index on repay/withdraw

* call hook on borrow in all cases

* additional types functionality

* extend tests to cover fix

* update naming convention in tests

* update test comment

* feat: add set difference unit tests

* clarify test names

Co-authored-by: karzak <kjydavis3@gmail.com>
2021-03-23 17:28:03 -06:00
Denali Marsh
656c5a80b8
Additional Hard module queries (#884)
* unsynced deposits/borrows queriers

* cli queriers

* rest querier

* implement interest factor querier

* querier cli

* querier rest

* fix typo in comment
2021-03-22 18:57:07 +01:00
Denali Marsh
21cf7685df
don't sync borrow on deposit - it's redundant (#876) 2021-03-15 09:29:13 -06:00
Denali Marsh
72bfee6523
Minor best practices edits in Hard module (#877)
* put err return inside conditional

* check error type instead of error msg string
2021-03-15 09:15:19 -06:00
Ruaridh
20b3fa53e3
Prevent panic-causing param values (#875)
* prevent cdp liquidation ratio being 0.0

* fix linter warning

* prevent hard conversin factor being < 1

* add liquidation tests for different keeper rewards
2021-03-15 08:44:23 -06:00
Ruaridh
7779c8ee4d
Fix hard/committee begin blocker order (#867)
* switch hard and committee begin blocker order

* udpate money market deprecation steps

* move committee begin blocker in front of cdp

Co-authored-by: karzak <kjydavis3@gmail.com>
2021-03-10 21:38:42 -07:00
Denali Marsh
8744d3210c
Genesis import/export fixes (#871)
* panic on export if prev accrual time not set

* on export if interest factor not set, set to 1.0

* fix prev accrual time in cdp export

* panic on export if prev accrual time not set

* export hard reward denom accumulation times

* init genesis starts usdx reward indexes at 0.0

* update incentive migration

* update incentive tests
2021-03-10 21:32:35 -07:00
Ruaridh
509d2edbca
fix bug that skipped minimum borrow check (#870)
add tests for non-borrower repayer address
2021-03-10 21:13:21 -07:00
Kevin Davis
829aed5256
fix: decrement coins for supply/borrow properly (#862)
* fix: decrement coins for supply/borrow properly

* fix: decrement keeper liquidation reward coins from hard total supply (#865)

* fix: use proper safe subtraction for withdraw/repay methods

* fix: decrement keeper liquidation rewards from total supply

* address review comments
2021-03-10 10:56:08 -07:00
Ruaridh
162602f390
Test users cannot borrow from reserves (#869)
* add ValidateBorrow test

* remove accidentally duplicated test
2021-03-09 12:11:13 -07:00
Kevin Davis
0865e40553
[R4R] incentive, hard migrations (#783)
* update v0_11 harvest genesis state

* wip: hard migration

* wip: incentive migration

* wip: incentive migration

* update incentive migration for multi-rewards

* address review comments

* sort slices for deterministic ordering

* update interest rate model and reserves

* fix: use correct conversion factor

* fix: remove auction size param

* remove ununsed module accounts

* update incentive claim multiplier for one month rewards

* address hard migration review comments

* add hard test

* migrate harvest mod account (#844)

* migrate harvest mod account

* update hard account permissions

* update hard module account permissions

Co-authored-by: Ruaridh <rhuairahrighairidh@users.noreply.github.com>
2021-02-22 14:08:23 -07:00
Denali Marsh
99fb79a1ae
update spec, add money market deprecation steps (#841) 2021-02-22 13:52:17 -07:00
Denali Marsh
1499a89ce5
Query Hard module reserves (#843)
* implement CLI reserves query

* implement REST reserves query
2021-02-22 13:48:52 -07:00
Denali Marsh
fe43c2bc41
Hard Audit: don't convert directly from sdk.Int to uint64 (#842)
* refactor away from sdk.Int's .Uint64() method

* refactor cdp module interest calc
2021-02-20 09:42:57 -07:00
Kevin Davis
5cd94047a4
fix: set interest accumulation time and exit when borrows are zero (#840) 2021-02-19 16:33:55 -07:00
Denali Marsh
421f774ec1
sort unique denom list (#836) 2021-02-19 14:05:17 -07:00
Denali Marsh
0b6e47ff46
call hooks in export genesis (#837) 2021-02-19 13:49:36 -07:00
Denali Marsh
0a51a737cb
fix time elapsed calculation + test (#838) 2021-02-19 13:24:00 -07:00
Denali Marsh
6c88c01eb8
validate against money markets in store (#839) 2021-02-19 13:23:19 -07:00
Kevin Davis
c5fc1c6b4f
Add hard and incentive spec updates (#817)
* wip: update hard spec

* feat: updated hard spec

* feat: updated incentive spec
2021-02-19 17:14:48 +01:00
Nick DeLuca
bdbc9b9c58
remove unused total deposit value -- not needed by ltv range calculation (#832) 2021-02-17 10:37:41 -07:00
Denali Marsh
53eab47c07
Hard Audit: don't let users borrow from reserves (#827)
* don't borrow from reserves

* use safesub and throw error
2021-02-16 07:45:57 -07:00
Kevin Davis
58573e7b26
fix: allow ltv of zero (#830) 2021-02-16 07:43:46 -07:00
Denali Marsh
e8d3d877aa
check borrow err (#828) 2021-02-15 08:30:41 -07:00
Denali Marsh
15da55b451
Hard Audit: refresh borrow/deposit after syncing (#824)
* refresh borrow/deposit after syncing

* revisions
2021-02-12 21:56:03 +01:00
Denali Marsh
a5b72363d0
Hard Audit: decrement total borrowed on liquidation (#823)
* decrement total borrow on liquidation

* copy kevin's decrement changes

* check error in liquidation

* extend decrement borrowed changes

* mimic negative check on the supplied coins side

* update liquidation test
2021-02-12 13:07:32 -07:00
Denali Marsh
fe2a131b31
Hard Audit: add minimum borrow USD value (#822)
* add module param MinimumBorrowUSDValue

* borrow/repay min limit restrictions

* add borrow/repay test cases

* update tests with new module params

* update timelock test with param

* update withdraw LTV test

* remove unused GetCurrentBorrowUSDValue method

* commit to prompt CircleCI run
2021-02-12 08:28:05 -07:00
Denali Marsh
cd7a227030
Query Hard module's supply/borrow APYs (#816)
* calculate estimated apy from internal spy

* implement interest rate query
2021-02-10 10:53:53 -07:00
Denali Marsh
802ed36846
remove auction size param (#815) 2021-02-10 07:59:23 -07:00
Kevin Davis
bc1fab7836
fix: renumber error messages (#812) 2021-02-10 07:57:28 -07:00
Kevin Davis
04b65e1d4e
fix: export synced deposits/borrows (#811)
* fix: export synced deposits/borrows

* fix: epxort synced cdps
2021-02-10 07:56:38 -07:00
Denali Marsh
b620275165
Hard Audit: remove liquidation account from Hard module (#810)
* remove liquidator macc

* remove legacy if statement
2021-02-09 13:33:58 -07:00
Denali Marsh
7465c643b8
decrement/increment coin counters on auctions (#809) 2021-02-09 13:32:28 -07:00
Kevin Davis
7d4235ca87
fix: don't accumulate if borrow interest rounds to zero (#808) 2021-02-09 10:11:12 -07:00
Denali Marsh
c60365f12e
call both incentive hooks (#804) 2021-02-08 07:13:30 -07:00
Denali Marsh
0edbdf968e
hotfix (#803) 2021-02-08 13:57:02 +01:00
Denali Marsh
5af50e1a2d
Hard Audit: enable users to repay another account's borrows (#801)
* add owner to repay msg

* pass owner and sender to repay function

* make owner arg an optional flag

* make owner optional for REST
2021-02-08 13:51:42 +01:00
Denali Marsh
1b2cfa6d1a
Hard Audit: remove LTV index from Hard module (#800)
* remove LTV index

* remove LTV param

* remove LTV param from tests

* remove LTV index from tests

* fix incentive hook not called before sync
2021-02-08 13:23:37 +01:00
Denali Marsh
c8d4c02fb7
Remove unused Hard module accounts (#796)
* remove unused hard module accs

* update tests

* update migration for compile

* maintain migration
2021-02-05 12:45:37 +01:00
Denali Marsh
0343edf0d0
Hard Audit: fix duplicate supply/borrow index factors (#794)
* types: set/get interest factor

* delete 0 balance index factors from deposit

* types: set/get borrow interest factor

* delete 0 balance index factors from borrow

* delete index factor directly
2021-02-05 12:31:38 +01:00
Denali Marsh
be498c72f5
sync supply interest before ValidateBorrow (#798) 2021-02-04 17:54:13 +01:00
Denali Marsh
9fa83f0a1e
remove GetPreviousBlockTime/SetPreviousBlockTime (#797) 2021-02-04 17:54:01 +01:00
Denali Marsh
facb357fe9
return err in ValidateBorrow (#799) 2021-02-04 17:53:50 +01:00