Skip to content
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
wants to merge 54 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
f549f6f
add lamm coin
mkurnikov Jun 20, 2022
70bc5fb
initial staking module, moved LAMM coin to coins/
borispovod Jun 20, 2022
b04b637
comments, small refactoring, getter functions
borispovod Jun 21, 2022
21437e8
added period, added infinity inflation, small refactoring, comments
borispovod Jun 22, 2022
a635c5e
bug fixes, initial tests, updates to LAMM
borispovod Jun 22, 2022
6005830
tests are broken, distribution based on periods
borispovod Jun 27, 2022
9d8007b
distribution per periods done, yet need to cover with tests
borispovod Jun 27, 2022
6df40be
rewards distribution finally happens, yet there is bug with last peri…
borispovod Jun 28, 2022
8881408
minter, vesting escrow
borispovod Jul 7, 2022
ed986d8
distribution finally
borispovod Jul 7, 2022
226d093
Unstake
borispovod Jul 7, 2022
101efd8
refactoring, tests
borispovod Jul 10, 2022
b637d6c
minter tests & small refactoring
borispovod Jul 11, 2022
40f6d73
sorted imports
borispovod Jul 11, 2022
5feeba7
stake test
borispovod Jul 11, 2022
e11ca1c
test update
borispovod Jul 12, 2022
281f364
test stake fails, fix error codes in update test
borispovod Jul 12, 2022
b0193a7
fix bug with update stake
borispovod Jul 12, 2022
c9da4ce
stake tests
borispovod Jul 12, 2022
c501155
removed useless update
borispovod Jul 12, 2022
d060963
update with comments
borispovod Jul 12, 2022
7afcbcc
add get_burn_cap and Liquid.move tests
mkurnikov Jul 11, 2022
0bd841f
negative tests, no parameters for get_burn_cap
mkurnikov Jul 12, 2022
4cfa401
sort imports
mkurnikov Jul 12, 2022
16975cd
extract locking test
mkurnikov Jul 12, 2022
f9baf99
add two more negative cases
mkurnikov Jul 12, 2022
215f4e9
changed name
borispovod Jul 12, 2022
26e3648
Merge pull request #22 from pontem-network/burn-cap
borispovod Jul 12, 2022
1c665d2
Merge pull request #13 from pontem-network/distribution
borispovod Jul 12, 2022
26f19bb
Merge branch 'main' into staking
borispovod Jul 12, 2022
ad8cb2a
fix circulating supply
borispovod Jul 12, 2022
38e7726
Added mint, burn and lock_minting scripts to Liquid coin contract
sunmoon11100 Jul 13, 2022
eb3eedd
some clarity improvements
mkurnikov Jul 13, 2022
6bf8adf
Fixed bugs in renaming mint to mint_internal
sunmoon11100 Jul 13, 2022
d988544
Merge pull request #23 from pontem-network/apt-235
borispovod Jul 14, 2022
cab39f6
clarify improvements
mkurnikov Jul 14, 2022
a49ac9e
Re-do lock minting functional
sunmoon11100 Jul 15, 2022
5f78ded
Added tests
sunmoon11100 Jul 15, 2022
f471bf0
Fixed business logic
sunmoon11100 Jul 15, 2022
5b45531
Fixed in get_mint_cap
sunmoon11100 Jul 18, 2022
b2fe0a6
Added test for get_mint_cap
sunmoon11100 Jul 18, 2022
3c5f24b
Merge pull request #26 from pontem-network/apt-236
borispovod Jul 18, 2022
9a76d3f
made it little pretty
borispovod Jul 22, 2022
5e22803
get_point_timestamp -> VE::get_point_timestamp
borispovod Jul 22, 2022
3ffb0ab
make it pretty again
borispovod Jul 22, 2022
8141da4
Merge pull request #24 from pontem-network/some-renames
borispovod Jul 22, 2022
ced2d3d
merged with master, applied breaking changes
borispovod Jul 22, 2022
148f04b
merged
borispovod Jul 29, 2022
24a3c84
Tests for staking (#34)
sunmoon11100 Aug 10, 2022
e07b120
Merge branch 'main' into staking
sunmoon11100 Aug 19, 2022
4f9ae0b
update to devnet 18-8-22
sunmoon11100 Aug 19, 2022
d8b7ad3
Merge branch 'main' into staking
sunmoon11100 Aug 27, 2022
4a32157
Update devnet 26-8-22
sunmoon11100 Aug 28, 2022
7349712
Merge branch 'main' into staking
sunmoon11100 Sep 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Move.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ version = "0.2.3"
liquidswap = "0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9"
dao_admin = "0xb4d7b2466d211c1f4629e8340bb1a9e75e7f8fb38cc145c54c5c9f9d5017a318"
emergency_admin = "0xb4d7b2466d211c1f4629e8340bb1a9e75e7f8fb38cc145c54c5c9f9d5017a318"
staking_pool = "0x42"
Copy link
Member Author

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.


# Addresses for tests.
test_coin_admin = "0x11"
test_pool_owner = "0x12"
test_helpers = "0x12"
test_staker = "0x14"

[dependencies.MoveStdlib]
git = "https://github.com/aptos-labs/aptos-core.git"
Expand Down
126 changes: 126 additions & 0 deletions sources/coin/liquid.move
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);
}
}
Loading