-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Staking #12
Open
borispovod
wants to merge
54
commits into
main
Choose a base branch
from
staking
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[WIP] Staking #12
Changes from 51 commits
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
f549f6f
add lamm coin
mkurnikov 70bc5fb
initial staking module, moved LAMM coin to coins/
borispovod b04b637
comments, small refactoring, getter functions
borispovod 21437e8
added period, added infinity inflation, small refactoring, comments
borispovod a635c5e
bug fixes, initial tests, updates to LAMM
borispovod 6005830
tests are broken, distribution based on periods
borispovod 9d8007b
distribution per periods done, yet need to cover with tests
borispovod 6df40be
rewards distribution finally happens, yet there is bug with last peri…
borispovod 8881408
minter, vesting escrow
borispovod ed986d8
distribution finally
borispovod 226d093
Unstake
borispovod 101efd8
refactoring, tests
borispovod b637d6c
minter tests & small refactoring
borispovod 40f6d73
sorted imports
borispovod 5feeba7
stake test
borispovod e11ca1c
test update
borispovod 281f364
test stake fails, fix error codes in update test
borispovod b0193a7
fix bug with update stake
borispovod c9da4ce
stake tests
borispovod c501155
removed useless update
borispovod d060963
update with comments
borispovod 7afcbcc
add get_burn_cap and Liquid.move tests
mkurnikov 0bd841f
negative tests, no parameters for get_burn_cap
mkurnikov 4cfa401
sort imports
mkurnikov 16975cd
extract locking test
mkurnikov f9baf99
add two more negative cases
mkurnikov 215f4e9
changed name
borispovod 26e3648
Merge pull request #22 from pontem-network/burn-cap
borispovod 1c665d2
Merge pull request #13 from pontem-network/distribution
borispovod 26f19bb
Merge branch 'main' into staking
borispovod ad8cb2a
fix circulating supply
borispovod 38e7726
Added mint, burn and lock_minting scripts to Liquid coin contract
sunmoon11100 eb3eedd
some clarity improvements
mkurnikov 6bf8adf
Fixed bugs in renaming mint to mint_internal
sunmoon11100 d988544
Merge pull request #23 from pontem-network/apt-235
borispovod cab39f6
clarify improvements
mkurnikov a49ac9e
Re-do lock minting functional
sunmoon11100 5f78ded
Added tests
sunmoon11100 f471bf0
Fixed business logic
sunmoon11100 5b45531
Fixed in get_mint_cap
sunmoon11100 b2fe0a6
Added test for get_mint_cap
sunmoon11100 3c5f24b
Merge pull request #26 from pontem-network/apt-236
borispovod 9a76d3f
made it little pretty
borispovod 5e22803
get_point_timestamp -> VE::get_point_timestamp
borispovod 3ffb0ab
make it pretty again
borispovod 8141da4
Merge pull request #24 from pontem-network/some-renames
borispovod ced2d3d
merged with master, applied breaking changes
borispovod 148f04b
merged
borispovod 24a3c84
Tests for staking (#34)
sunmoon11100 e07b120
Merge branch 'main' into staking
sunmoon11100 4f9ae0b
update to devnet 18-8-22
sunmoon11100 d8b7ad3
Merge branch 'main' into staking
sunmoon11100 4a32157
Update devnet 26-8-22
sunmoon11100 7349712
Merge branch 'main' into staking
sunmoon11100 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
module liquidswap::liquid { | ||
use std::string; | ||
use std::signer; | ||
|
||
use aptos_framework::coin::{Self, MintCapability, BurnCapability, Coin}; | ||
use aptos_framework::timestamp; | ||
|
||
// Erorrs. | ||
|
||
/// When capability doesn't exists on account. | ||
const ERR_CAPABILITIES_DOESNT_EXIST: u64 = 100; | ||
|
||
/// When minting locked but trying to mint. | ||
const ERR_MINTING_LOCKED: u64 = 101; | ||
|
||
// Constants. | ||
|
||
/// In 6 months we stop direct minting and issuing of mint capabilities automatically. | ||
/// Yet contracts who has mint capability can continue minting. | ||
const LOCK_MINT_AFTER_SECONDS: u64 = 15552000; // 6 months | ||
|
||
/// The Liquidswap coin. | ||
struct LAMM {} | ||
|
||
/// Capabilities stored under admin account and also we determine if minting locked with `lock_mint_cap` | ||
/// and `lock_mint_time`. | ||
struct Capabilities has key { | ||
mint_cap: MintCapability<LAMM>, | ||
burn_cap: BurnCapability<LAMM>, | ||
// If new mints and creation of new mint capabilities locked in this contract. | ||
lock_mint_cap: bool, | ||
// Time when minting automatically will be locked in this function if admin doesn't make a call. | ||
lock_mint_time: u64, | ||
} | ||
|
||
/// Initialize LAMM coin. | ||
/// Use `@liquidswap` admin account to do it. | ||
public fun initialize(admin: &signer) { | ||
let (burn_cap, freeze_cap, mint_cap) = coin::initialize<LAMM>( | ||
admin, | ||
string::utf8(b"Liquid"), | ||
string::utf8(b"LAMM"), | ||
6, | ||
true | ||
); | ||
|
||
coin::destroy_freeze_cap(freeze_cap); | ||
|
||
move_to(admin, Capabilities { | ||
mint_cap, | ||
burn_cap, | ||
lock_mint_cap: false, | ||
lock_mint_time: timestamp::now_seconds() + LOCK_MINT_AFTER_SECONDS | ||
}); | ||
} | ||
|
||
/// Lock minting public entry point. | ||
public entry fun lock_minting(admin: &signer) acquires Capabilities { | ||
lock_minting_internal(admin); | ||
} | ||
|
||
/// Lock minting using admin account. | ||
public fun lock_minting_internal(admin: &signer) acquires Capabilities { | ||
let admin_addr = signer::address_of(admin); | ||
assert!(exists<Capabilities>(admin_addr), ERR_CAPABILITIES_DOESNT_EXIST); | ||
|
||
let caps = borrow_global_mut<Capabilities>(admin_addr); | ||
caps.lock_mint_cap = true; | ||
} | ||
|
||
/// Get new mint capability for LAMM minting using admin account. | ||
public fun get_mint_cap(admin: &signer): MintCapability<LAMM> acquires Capabilities { | ||
let admin_addr = signer::address_of(admin); | ||
assert!(exists<Capabilities>(admin_addr), ERR_CAPABILITIES_DOESNT_EXIST); | ||
|
||
let caps = borrow_global<Capabilities>(admin_addr); | ||
assert!(!caps.lock_mint_cap && timestamp::now_seconds() < caps.lock_mint_time, ERR_MINTING_LOCKED); | ||
|
||
*&caps.mint_cap | ||
} | ||
|
||
/// Public entry to mint new coins for user using admin account. | ||
/// * `addr` - recipient address. | ||
/// * `amount` - amount of LAMM coins to mint. | ||
public entry fun mint(admin: &signer, addr: address, amount: u64) acquires Capabilities { | ||
mint_internal(admin, addr, amount); | ||
} | ||
|
||
/// Same like `mint` but for public functions usage (not entries). | ||
/// * `addr` - recipient address. | ||
/// * `amount` - amount of LAMM coins to mint. | ||
public fun mint_internal(admin: &signer, addr: address, amount: u64) acquires Capabilities { | ||
let admin_addr = signer::address_of(admin); | ||
assert!(exists<Capabilities>(admin_addr), ERR_CAPABILITIES_DOESNT_EXIST); | ||
|
||
let caps = borrow_global<Capabilities>(admin_addr); | ||
assert!(!caps.lock_mint_cap && timestamp::now_seconds() < caps.lock_mint_time, ERR_MINTING_LOCKED); | ||
|
||
let coins = coin::mint(amount, &caps.mint_cap); | ||
coin::deposit(addr, coins); | ||
} | ||
|
||
/// Get burn capability for LAMM coin. | ||
public fun get_burn_cap(): BurnCapability<LAMM> acquires Capabilities { | ||
assert!(exists<Capabilities>(@liquidswap), ERR_CAPABILITIES_DOESNT_EXIST); | ||
|
||
let caps = borrow_global<Capabilities>(@liquidswap); | ||
*&caps.burn_cap | ||
} | ||
|
||
/// Entry function in case `account` wants to burn LAMM coins. | ||
/// * `amount` - amount of LAMM to withdraw from account and burn. | ||
public entry fun burn(account: &signer, amount: u64) acquires Capabilities { | ||
let to_burn = coin::withdraw<LAMM>(account, amount); | ||
|
||
burn_internal(to_burn); | ||
} | ||
|
||
/// Burn LAMM coins. | ||
/// * `coins` - LAMM coins to burn. | ||
public fun burn_internal(coins: Coin<LAMM>) acquires Capabilities { | ||
assert!(exists<Capabilities>(@liquidswap), ERR_CAPABILITIES_DOESNT_EXIST); | ||
let caps = borrow_global<Capabilities>(@liquidswap); | ||
coin::burn(coins, &caps.burn_cap); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace it with
0xb4d7b2466d211c1f4629e8340bb1a9e75e7f8fb38cc145c54c5c9f9d5017a318
address, later we will replace it with real address. Otherwise it wouldn't depoy.