Commit Graph

52 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
Denali Marsh
0c1fa5d27b
emit hard liquidation event (#790) 2021-02-03 23:23:17 +01:00
Denali Marsh
7be0c8b48e
decrement supplied coins (#791) 2021-02-03 23:23:03 +01:00
Denali Marsh
58494fe357
Hard: fix liquidation engine (#771)
* initial

* liquidation debugging

* max lot == macc coin balance

* add print statements

* add test for pricefeed liquidation scenarios

* skip zero lot

* add insolvency liquidation test scenario

* remove debugging statements

* fix tests after rebase

Co-authored-by: karzak <kjydavis3@gmail.com>
2021-02-01 14:13:17 -07:00
Kevin Davis
dc330d02bf
Update hard genesis state (#777)
* feat: update hard genesis state and init/export methods

* address review comments
2021-01-22 22:17:40 -07:00
Denali Marsh
4e6f6d1e9c
Incentive/Hard rebase to master (#773)
* spike: incentive/types

* spike: incentive/types tests

* spike: incentive/types/expected_keepers.go

* spike: incentive/keeper

* spike: incentive/keeper tests

* spike: incentive/sims and incentive/sims tests

* spike: incentive/module

* spike: incentive/module tests

* spike: hard/types

* spike: hard/types hooks

* spike: hard/types

* spike: hard/keeper basics

* spike: hard/keeper hooks

* integrate hard/keeper/borrow.go

* integrate hard/keeper/deposit.go

* integrate hard/keeper/liquidation.go

* integrate hard/keeper/withdraw.go

* integrate hard/keeper/repay.go

* spike: hard/sims

* spike: hard/sims tests

* spike: hard/client

* spike: hard/module

* integrate app.go

* spike: x/hard/keeper compile tests

* incentive/keeper test clean up

* validate usdx incentive types in genesis

* refactoring & fix deposit test

* fix liquidaton tests

* fix incentive tests for hard supply rewards

* fix hard genesis tests

* update incentive genesis state and params

* update cdp rewards accumulation

* update app init order and begin blocker order

Co-authored-by: karzak <kjydavis3@gmail.com>
2021-01-21 14:52:09 +01:00
Denali Marsh
fba6b8c4f2
Hard: delete borrow/deposit from store on 0 amount (#766)
* delete borrow/deposit on 0 balance

* add/update tests to ensure deletion

* delete from LTV index
2021-01-18 10:43:20 +01:00
Denali Marsh
34a7172581
Hard: refactor borrow/borrows and deposit/deposits query (#761)
* refactor cli borrows query

* rest api feature parity for borrows query

* refactor deposits cli query

* remove deposit/borrow query names from types

* add named deposit/borrow queries back into types

* rest api feature parity for deposits query

* load synced deposit instead of synced balance

* deposits query returns synced deposits

* borrows query returns synced borrows

* refactor querier types

* update comment for accuracy

* add deposit/borrow slice types

* refactor 'borrowed' query

* implement 'deposited' query types

* implement 'deposited' query keeper function

* implement 'deposited' query CLI

* implement 'deposited' query rest endpoint

* update naming conventions to 'total'
2021-01-13 19:14:58 +01:00
Denali Marsh
d05516bbe0
Hard: sync supply interest on attempted liquidation (#763)
* sync supply interest on attempted liquidation

* update tests with supply interest accrual
2021-01-13 12:59:39 +01:00
Denali Marsh
f6efc2597b
Hard: investigate sdk.RelativePow runtime panic (#762)
* interest rate practical test

* add clarification comment
2021-01-12 10:03:09 +01:00
Denali Marsh
bc110ce609
Hard: LTV index refactor (#758)
* add set/delete/update ltv methods

* refactor borrow logic

* basic updates to keeper logic for compile

* Add deposit index set/delete/update keeper methods

* refactor deposit logic

* refactor repay logic

* update withdraw logic

* introduce DeleteDepositBorrowAndLtvIndex

* remove unused bool from AttemptKeeperLiquidation

* remove comments (transitioned to asana cards)

* catch multiple error types in liquidation loop
2021-01-07 22:40:25 +01:00
Denali Marsh
38306e5465
add deposit balance query (#759) 2021-01-07 17:22:00 +01:00
Denali Marsh
f7a73c9245
Hard: suppliers earn interest (#749)
* update to borrow interest factor

* add supply interest factor to accrue interest

* supply interest factor keeper methods

* fix potential bug with user borrow indexing

* sync supply interest on deposit/withdraw

* separate withdraw/deposit

* relocate interest sync methods

* update comment

* simplify supply interest statement

* check truncated int not zero

* add .sub(storedAmount) back

* add store key suppliedcoins

* increment/decrement supplied coins

* update withdraw with new accounting

* update withdraw test

* catch repay edge case

* unit tests

* TestSupplyInterest scaffolding

* test notes

* temp: interest test

* example test

* changes, test checks more state

* fix: calculate supply interest directly

* fix: catch divide by zero

* add state checks back into interest test

* add snapshot test cases

* test owed supplied interest paid at correct ratio

* test user supply syncs user's borrow interest

* remove print statements and clean up

* refactor indented logic

* test supply/borrow multiple coins

* update decoder test

Co-authored-by: karzak <kjydavis3@gmail.com>
2021-01-07 11:23:05 +01:00
Denali Marsh
e9f5043c84
Hard: update REST API (#748)
* borrows, borrow, borrowed queries

* update deposit, withdraw, claim rest txs

* add borrow, repay, liquidate rest tx

* update liquidate on handler
2020-12-22 17:08:27 +01:00