Commit Graph

559 Commits

Author SHA1 Message Date
Denali Marsh
451bc05f47
Savings module params (#1190)
* module files

* proto types

* types and generated proto types

* keeper

* client scaffold

* add savings module to app

* remove placeholder types file

* implement rest and add to module

* update proto types

* validation for supported denoms

* generate updates proto types

* update comments

* update comments

* remove unused imports from proto files

* regenerate proto files

* remove abci

* remove refs to other modules

* remove endblocker call

* genesis init test for module account

* update genesis test with params

* add get/set params test
2022-03-23 14:27:54 +01:00
Denali Marsh
8540a5c06f
Savings module scaffold (#1188)
* module files

* proto types

* types and generated proto types

* keeper

* client scaffold

* add savings module to app

* remove placeholder types file

* implement rest and add to module

* update comments

* remove unused imports from proto files

* remove abci

* remove refs to other modules

* remove endblocker call

* genesis init test for module account
2022-03-22 22:13:27 +01:00
Kevin Davis
c76b5f98b7
fix: use new bid duration params for same-bidder tests (#1163) 2022-02-08 09:33:42 -08:00
Derrick Lee
e526fd1639
Split existing auction bid_duration parameter into forward_bid_duration and reverse_bid_duration (#1158)
* Split bid_duration field into forward/reverse durations

* Update params.go

* Update params_test for forward/reverse bid durations

* Remove duplicated import

* Replace bid duration on place bids

* Fix reversed bid errors

* Update auctions test

* Update bidding test

* Update testutil suite to use default forward/reverse bid durations

* Fix missing ReverseBidDuration param field

* Check if auction is reversed on forward bid

* Add test for conversion to reverse auction that reaches maxbid

* Make proto fields backwards compatible

* Use ForwardBidDuration for debt bid

* Make copy of v16 auction types

this doesn't actually work but keeping it in history

* Disable migrations

* Update debt tests to use forward bid duration
2022-02-08 09:03:47 -08:00
Ruaridh
c0f71921d9
Test repeat auction bidding (#1159)
* improve error messages

* add tests for re-bidding with small balance
2022-02-08 08:42:00 -08:00
Derrick Lee
9f73659274
Fix committee Votes grpc query response (#1156)
* Append votes to queryResults, remove unused GetVotesByProposal

* Add Votes grpc_query test
2022-02-01 20:16:53 -08:00
Denali Marsh
03ab76bb2d
Pricefeed query fix (#1149)
* filter prices in querier

* filter prices in grpc querier

* test grpc querier
2022-01-25 15:56:51 +01:00
Ruaridh
e9a28cefd8
Reset bep3 swaps for zero height in migration (#1135)
* reinstate and expand export test

* format testdata json

* sort bep3 testdata json for easier diffing

* add more bep3 swap examples to test data

* reset swaps for zero height

* update top level migration testdata
2022-01-14 20:17:49 -07:00
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
Derrick Lee
1a51d1fb00
Add IBC markets to pricefeed migration (#1131)
* Add ibc markets to pricefeed

* Default empty oracles if no markets

* Update pricefeed migration tests

* Add ibc markets to testdata genesis pricefeed

* Add existing pricefeed markets and new ibc markets to committee permissions

* Remove stray empty branch

* Panic on committee migration if pricefeed app state is missing

* Remove redundant import
2022-01-14 14:24:57 -07:00
Draco Li
8b53fa61c5
Migrate v15 SubParamPermission to v16 ParamsChangePermission (#1115)
* migrate subparam permission to params change permission

* add new requirements for stability committee

* fix tests for stability committee
2022-01-08 01:22:00 +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
Kevin Davis
d0e9c2531c
fix: update circulating supply (#1061)
* fix: update circulating supply to accurately reflect inflationary KAVA supply

* revert lp claims subtraction

* fix: use total supply after all vesting complete
2021-11-18 11:10:50 -06:00
Derrick Lee
f84a8b0be0
Add /cdp/totalPrincipal and /cdp/totalCollateral Endpoints (#1027)
* Add cdp/totals rest endpoint for aggregated principal and fees

* Add total collateral to aggregated cdp

* Add pagination

* Update totalPrincipal endpoint to use keeper GetTotalPrincipal

* Update documentation for queryGetTotalPrincipal

Co-authored-by: Kevin Davis <karzak@users.noreply.github.com>

* Remove unused AggregatedCDP types

* Make CDP type optional, return all if not provided

* add total collateral endpoint that efficient fetches collateral
for a types, only iterating cdps for types b, etc

* correctly and efficienlty filter for a single collateral type

Co-authored-by: Kevin Davis <karzak@users.noreply.github.com>
Co-authored-by: Nick DeLuca <nickdeluca08@gmail.com>
2021-10-23 13:09:59 -05:00
Nick DeLuca
45c7785859
Add No Vote Information to Polling Status for Committee Proposals (#1023)
* add no votes information to polling status, updating events and querier
cli/rest responses.  This allows clients to differeniate between no and
abstain votes

* update querier test to include no vote assertion
2021-10-12 09:51:01 -06:00
Denali Marsh
b9c59c728b
Committee module: query next proposal ID (#1019)
* next-proposal-id cli query

* fix spelling in comments

* next-proposal-id rest query
2021-09-17 14:45:37 -06:00
Denali Marsh
0ee449e5a9
Test CDP init/export genesis (#1014)
* implement basic init/export genesis test

* update expected genesis for test
2021-09-09 11:54:39 -06:00
Kevin Davis
0b621770f8
fix: use correct format for pool names in cli help text (#1016) 2021-09-01 15:12:42 -06:00
Derrick Lee
b2aae00301
Add circulating supply endpoint for SWP (#1015)
* Add circulating supply endpoint for SWP

* Fix team SWP amount
2021-09-01 09:21:31 -06: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
Denali Marsh
0714d6120e
Certik audit revisions (#999)
* revisions: BAS-01 | Inconsistent Comment

* revisions: GEE-01 | Unsorted imports

* revisions: KEE-01 | Ambiguous Function Naming

* revisions: OPE-01 | Redundant “if” Clause
2021-08-18 06:51:09 -06:00
Ruaridh
58b3089ecd
Remove unnecessary msg field in incentive (#988)
* remove msg field that was forgotten

* fix cli tx example text
2021-08-10 22:56:19 -06:00
Kevin Davis
5981e61296
fix: typo in attribute key (#986) 2021-08-10 11:59:19 -06:00
Denali Marsh
b72815387a
Update committee spec (#981)
* concepts

* messages

* events

* begin block

* address revisions

Co-authored-by: karzak <kjydavis3@gmail.com>
2021-08-10 07:46:49 -06:00
Denali Marsh
2167b13430
update incentive spec (#982) 2021-08-06 08:12:08 -06:00
Nick DeLuca
b86cfc9f14
Add Invariants for Swap Module (#979)
* add swap module invariants

* typo

* update alias file for invariants

* typo in test name

* fix typo - method iterates share record, not pools
2021-08-05 20:43:55 -05:00
Ruaridh
20560a16d7
fix test setup to use new Multipliers type (#984) 2021-08-04 19:02:59 +01:00
Ruaridh
63c8421a81
Separate multipliers per claimed denom (#971)
* move multipliers to their own file

* add multipliers per denom to MsgClaimHardReward

* claim with multipliers per denom for hard claims

* remove unused error

* add multipliers per denom to params
connect to to hard claiming

* temporary fix migration

* update usdx claiming for new multiplier params

* claim with multipliers per denom for delegator

* claim with multipliers per denom for swap rewards

* tidy up multiplier name validation

* rename new multipliers field in params

* remove old multpliers from params

* clear up various TODOs

* add tags to new structs

* remove dead code
2021-08-04 15:55:29 +01:00
Denali Marsh
6bcc843c2e
Add SAFU fund to circulating supply (#980)
* add safu fund to circulating supply

* add parentheses
2021-08-04 13:36:03 +02:00
Denali Marsh
c252a1b99b
Swap module simulations: swap msg operations (#972)
* simulate MsgSwapExactForTokens

* extract deadline generation to custom method

* simulate MsgSwapForExactTokens

* implement simulation decoder

* decoder test

* add fee to msgs

* update comments
2021-07-27 12:57:23 +02:00
Ruaridh
b2bfe05170
Fix bug in syncing swap rewards (#977)
* fix bug in GetSyncedSwapClaim
It did not sync rewards for pools that had recently had rewards added

* remove dead code
2021-07-26 14:07:18 -06: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
6f193c7f2a
Refactor incentive accumulators to be the same (#970)
* add test for validate multi reward periods

* tidy up: combine files

* don't accumulate global indexes containing zeros
Previously if the time since last block was 0,
indexes were added containing 0s.
Now leave them out. Missing is assumed to be 0.

* move state independent test to types folder

* clarify reward source concept to "source shares"
- rename variables and update doc comments
- extract method from swap accumulation

* tidy up and expand swap accumulation unit tests

* rename swap test file to match others

* update swap pool id format in tests

* refactor borrow accumulation, use new accumulator

* refactor supply accumulation, use new accumulator

* refactor delegator accumulation, use accumulator

* refactor usdx accumulation, use new accumulator

* fix types const

* remove unsed methods

* more usdx minting param validation.
Protect against the rewards per second denom changing.
It should always be "ukava".

* add safety check in InitGenesis
It prevents huge accumulations on the first block by limiting all
previous accumulation times to be within one year of genesis

* add todo for adding swp token distirbution info
2021-07-22 13:53:18 +01:00
Nick DeLuca
cbb8b04292
Update Pool ID Separator (#968)
* update state store key separator and extract pool key sep

* update state key separater and pool id seperator to not conflict with
'/' in ibc vouchers

* fix pool ids for updated sep
2021-07-15 19:09:35 -05:00
Kevin Davis
2bbdcbb365
update swap spec: add msgs, state, events (#966) 2021-07-15 17:34:16 -05:00
Nick DeLuca
911f9f59d6
Hook Regression Test + Deposit Refactor (#967)
* add regression test for hooks; refactor deposit to commit pool and
shares in one place with commit after validation checks; panic on pool
and share set methods if the record is invalid

* use correct hook ordering; add regression test for order - fails if
hooks are not called before or after share record set
2021-07-15 17:29:11 -05:00
Kevin Davis
da5a852a6c
Misc simulation fixes (#963)
* fix: catch min swap edge case in bep3 sims

* fix: check repayment is above min in cdp sims

* remove print statement
2021-07-15 10:46:56 -05:00
Kevin Davis
290cb61882
feat: backport swap sims for deposit, withdraw (#965)
* sims: MsgDeposit operation

* implement withdraw

* update comment

* fix: add interest factors to cdp sims

Co-authored-by: denalimarsh <denalimarsh@gmail.com>
2021-07-15 10:35:24 -05:00
Kevin Davis
bb1bc7fed4
fix: update swap genesis in test (#964) 2021-07-15 10:03:30 -05:00
Kevin Davis
d45fa58f5c
Swap Genesis State (#960)
* wip: add swap state persistent to genesis

* separate pool record constructors; add tests for json and yaml encoding
of record structs

* beef up validation checks for state records

* fix integration with master - renamed method

* add test coverage for basic state array validations

* extra test around pool record reserve and id ordering to ensure no
regressions in the future

* add validations to ensure pool records and share records are unique
within the collection types

* test genesis json and yaml encoding

* validate in genesis that the total shares owned for each pool is equal
to the total shares of each pool

* update alias

* nit lint

* test genesis init and export

* add migration todo

Co-authored-by: Nick DeLuca <nickdeluca08@gmail.com>
2021-07-15 09:42:30 -05:00
Ruaridh
013093ecb5
Incentive genesis refactor: remove sync on export (#954)
* move defualt values to file where they're used

* add type to hold RewardIndexes in genesis state

* add reward indexes state to genesis

* fix genesis state importers

* add iterator keeper methods for accrual times

* remove syncing from export/init genesis

* separate incentive migration to new file

* refactor out common funcs from incentive migration

* update legacy genesis state to v0.14.3

* add test and example migrated json

* fully initialize rewards in genesis builder

* add kava-7-mainnet incentive state

* run aliasgen

* add missing type to incentive/legacy

Co-authored-by: karzak <kjydavis3@gmail.com>
2021-07-15 15:41:55 +01:00
Ruaridh
e48fed1e27
fix strings that said deposit instead of borrow (#962) 2021-07-15 09:16:25 -05:00
Ruaridh
38a98ac4fc
Refactor incentive payout (#953), Users can claim swap rewards (#955)
* split up payout.go file

* extract genesis builders to new testutil package

* move claim integration tests out of keeper

* convert claim integration tests to handler tests

* combine claim usdx minting keeper methods

* combine hard claim keeper methods

* combine delegator claim keeper methods

* add multiply coins helper method

* rename file to better match contents

* add basic claiming unit tests

* add claiming subset of delegator reward denoms

* refactor msg tests

* add msg ValidateBasic tests

* connect swap hooks into keeper methods

* tidy up delegator handler tests

* add swap claiming msgs and keeper method

* add swap claiming to client

* add subset claiming to other msg types

* split up handler test file

* connect up subset claiming for swap

* make multiplier name validation more strict

* fix: struct tag typo in swap incentives

* connect up subset claiming for hard

* connect up subset claiming for delegator

* fix: register cli tx routes for swp claiming

* fix claim amount in claim event

* fix token name in cli help docs

* remove unused field in msg tests

* tidy up swap and delegator handler tests

* refactor hard handler tests

* refactor usdx handler tests

* remove unused constant

Co-authored-by: karzak <kjydavis3@gmail.com>
2021-07-15 15:05:54 +01:00
Nick DeLuca
20437a91fb
Add E2E Swap Support (#959)
* add message types for swaps

* add tx client commands

* add test coverage for swap message deadlines

* start handler swap tests, export handler result message event into
private method, add stubbed keeper methods

* add initial swap implementation to get handler tests passing; adds event
specific for trades

* add handler acceptance test for slippage in exact input and exact output
swaps

* implement slippage limit for swap keeper methods

* add tests to ensure a user can only swap spendable coins

* test pool not found, panic on invalid pool, and panic when module
account does not have enough funds

* validate that the exact output when using for exact swaps is less than
the pool liquidity

* nit: long line

* add validation that swap output is greater than zero

* add rest txs for swap messages

* nit: lints

* dry up swap keeper methods

* from pr feedback - spelling and increase clairty around the output
amount of a swap rounding to zero
2021-07-13 17:44:05 -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
65052ce31a
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>
2021-07-13 12:38:15 +01:00
Denali Marsh
3fc2a63556
Refactor to DelegatorClaim and implement new MsgClaimDelegatorReward (#948)
* update claim attribute type to MultiRewardIndexes

* update param attribute type to MultiRewardPeriods

* keeper: update params to match types

* keeper: update delegator core keeper methods

* keeper: update InitializeHardDelegatorReward

* keeper: update SynchronizeHardDelegatorRewards

* remove reward factor in favor of reward indexes

* update querier

* fix test: delegator init test

* fix test: delegator sync test

* implement delegator reward accumulation

* fix test: delegator general tests

* add legact types, update v0_11 -> v0_14 migration

* remove duplicate import form v0_15 migration

* implement v0_15incentive migration

* test data and migration test

* add multiple reward denoms to init/sync tests

* update delegator test with multiple reward coins

* clean up simulation sync

* types: introduce DelegatorClaim, refactor HardClaim

* add core DelegateClaim store methods

* refactor delegator reward init, accumulation, sync

* update hooks

* update params and genesis logic

* update abci

* update types tests

* update querier types/keeper for compile

* update supply rewards tests

* update borrow reward tests

* update delegator reward tests

* update handler/genesis test for compile

* add new msg type

* implement delegator claim payouts

* submission + handling of new msg

* implement new querier types/keeper logic

* add new queries to cli/rest

* update migration

* register new msgs/types on codec

* remove delegator syncing from hard sync method
2021-07-07 18:50:14 +02:00
Ruaridh
c7962e45c0
Swaps accumulate global rewards (#947)
* add get set methods for swap reward indexes

* add get set methods for swap accrual time

* tidy up location of multi periods

* add swap reward periods to params

* add initial legacy types for incentive

* minor refactor of migration code

* add incentive migration for swap params

* minor incentive test refactors

* add math methods to RewardIndexes

* add keeper method to increment global indexes

* add swap keeper to incentive keeper

* indicate if pool shares were found or not

* add accumulator to compute new rewards each block

* accumulate swap rewards globally

* remove unecessary keeper method

* expand doc comments on accumulator methods

* test precision not lost in accumulation

* minor fixes from merge

* rename storeGlobalDelegatorFactor to match others

* fix migration from merge

* fix bug in app setup

* fix accumulation bug when starting with no state

* rename swap files to match others

* add swap accumulation times to genesis

* remove old migration refactor

* minor updates to spec

* add high level description of how rewards work
2021-07-07 14:23:06 +01:00
Denali Marsh
bc33b94822
Update delegator rewards to multi-reward index (#945)
* update claim attribute type to MultiRewardIndexes

* update param attribute type to MultiRewardPeriods

* keeper: update params to match types

* keeper: update delegator core keeper methods

* keeper: update InitializeHardDelegatorReward

* keeper: update SynchronizeHardDelegatorRewards

* remove reward factor in favor of reward indexes

* update querier

* fix test: delegator init test

* fix test: delegator sync test

* implement delegator reward accumulation

* fix test: delegator general tests

* add legact types, update v0_11 -> v0_14 migration

* remove duplicate import form v0_15 migration

* implement v0_15incentive migration

* test data and migration test

* add multiple reward denoms to init/sync tests

* update delegator test with multiple reward coins

* clean up simulation sync
2021-07-06 00:01:25 +02:00
Denali Marsh
baf17b4ec8
Emit final proposal tally in close proposal event (#919)
* Committee types (#899)

* committee types

* refactor to committee interface

* include tokencommitee stringer method

* add members to BaseCommittee

* address revisions

* update querier

* update querier

* fix compilation errors, tests, etc.

* Update MsgVote with vote type (#900)

* add vote to msg

* update querier/rest

* update example cli vote msg

* remove incorrect comments

* address revisions

* update handler, stub keeper method

* add vote type to vote struct

* Committee module keeper logic for token holder governance (#902)

* fix keeper/test compilation errors

* fix keeper/test compilation errors pt 2

* add setters to committee interface

* fix sims compilation errors

* fix incentive tests compilation errors

* update types, expected keepers

* core keeper logic

* don't allow bond denom

* implement vote tallying

* query proposal polling status

* update module keepers in app.go

* register committee interface

* fix failing incentive test

* commitee types tests

* refactor GetProposalResult by committee types

* update invariants

* implement most proposal keeper tests

* add nulls to custom enums

* remove abstain vote type

* add test for close proposal

* remove outdated TODOs

* update ProcessProposals

* switch on committee type directly

* reintroduce Abstain votes and update vote tallying

* don't allow divide by 0 panics

* delete unused setters on committee interface

* clean up tally methods return values for querier

* update enum validation to catch negative ints

* reintroduce setters for sims compilation

* address revisions

* remove commented out test

* implement ProcessProposals test

* additional revisions

* Committee migrations (#909)

* add committee v14 legacy types

* update migration imports for compile

* addRegisterCodec() to committee v14 legacy types

* migrate committee genesis state from v14 to v15

* set stability committee permissions properly

* fix committee allowed params

* migration test, kava-7 sample data

* add concrete types to committees (#911)

* revisions: migrate + tests

* register msgs on legacy codec

* Prepare Committee module for migrations (#906)

* remove invariants

* edits

* fix abci test

* fix keeper querier tests

* use codec.Codec

* don't allow null vote types

* don't allow null tally option

* minor spelling fixes

* update example cli proposal

* fix cli tally query

* enable vote abstain from cli

* include vote options in cli help text

* call CloseProposal from handler

* custom enum marshaling

* emit final proposal tally

* marshal proposal tally to bytes
2021-06-22 16:49:46 +02:00