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

feat: Added awesome defi ink #57

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file added .DS_Store
Binary file not shown.
Binary file added ink-awesome-defi/.DS_Store
Binary file not shown.
15 changes: 15 additions & 0 deletions ink-awesome-defi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Ink! Awesome DeFi


This is a Repo of Notable Smart contracts re-writen in Ink! domain (pallet-smart-contract) specific lanaguage. it outlines how production worthy smart contract should be built and structured. Smart contracts within this repo utilizes the awesome [Openbrush](https://openbrush.brushfam.io/) library of smart contract and utilities. This repo contains;

1. Uniswap V2 Ink! Implementation.
2. Synthetix staking reward contract
3. Uniswap V3 still in the works (it complicated math libs got me lazy. Ticks 😒)


My hopes for this Repo is for it to be a good resource for engineers/teams looking to build production worth smart contracts and wish other awesome developers would build into this repo other more complicated smart contracts making this Repo more useful to a wider range of teams in the polkaDeFI space.


## Want to contribute?
My buddy [Ayo](https://github.com/Adebara123), built a [template](https://github.com/Adebara123/Ink-Contract-Template) which I used to build these smart contracts and I would be employing you contributor to use that also.
Binary file not shown.
1 change: 1 addition & 0 deletions ink-awesome-defi/synthetix-staking-reward/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
33 changes: 33 additions & 0 deletions ink-awesome-defi/synthetix-staking-reward/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[package]
name = "contracts"
version = "0.1.0"
authors = ["developreuche <[email protected]>"]
edition = "2021"

[dependencies]
ink = { version = "4.2.1", default-features = false }

openbrush = { git = "https://github.com/727-Ventures/openbrush-contracts", version = "4.0.0-beta.1", default-features = false, features = ["psp22","ownable","access_control", "psp34", "reentrancy_guard", "pausable"] }
psp22_lp = { path = "contracts/modules/psp22_lp", default-features = false }
staking_reward = { path = "contracts/modules/staking_reward", default-features = false }
global = {path = "contracts", default-features = false}
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true }

[dev-dependencies]
ink_e2e = "4.2.0"

[lib]
path = "contracts.rs"

[features]
default = ["std"]
std = [
"ink/std",
"scale/std",
"scale-info/std",

"openbrush/std",
]
ink-as-dependency = []
e2e-tests = []
3 changes: 3 additions & 0 deletions ink-awesome-defi/synthetix-staking-reward/contracts.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#![cfg_attr(not(feature = "std"), no_std, no_main)]

pub use global;
Binary file not shown.
39 changes: 39 additions & 0 deletions ink-awesome-defi/synthetix-staking-reward/contracts/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[package]
name = "global"
version = "0.1.0"
authors = ["developeruche <[email protected]>"]
edition = "2021"

[dependencies]
ink = { version = "4.2.0", default-features = false }

openbrush = { git = "https://github.com/727-Ventures/openbrush-contracts", version = "4.0.0-beta.1", default-features = false, features = ["psp22","ownable","access_control", "psp34", "reentrancy_guard", "pausable"]}

scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true }
sp-arithmetic = { version = "15", default-features = false }

[dev-dependencies]
ink_e2e = "4.2.0"

[lib]
path = "global.rs"

[features]
default = ["std"]
std = [
"ink/std",
"scale/std",
"scale-info/std",

"openbrush/std",
"sp-arithmetic/std",
]
ink-as-dependency = []
e2e-tests = []

[profile.dev]
overflow-checks = false

[profile.release]
overflow-checks = false
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod staking_reward;
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@

use openbrush::traits::AccountId;
use openbrush::traits::Balance;
use crate::providers::common::errors::StakingRewardsErrors;



#[openbrush::wrapper]
pub type StakingRewardRef = dyn StakingRewardController;

#[openbrush::trait_definition]
pub trait StakingRewardController {
#[ink(message)]
fn get_reward_token(&self) -> AccountId;

#[ink(message)]
fn get_staked_token(&self) -> AccountId;

#[ink(message)]
fn get_reward_rate(&self) -> Balance;

#[ink(message)]
fn get_period_finish(&self) -> Balance;

#[ink(message)]
fn get_reward_duration(&self) -> Balance;

#[ink(message)]
fn get_last_update_time(&self) -> Balance;

#[ink(message)]
fn get_reward_per_token_stored(&self) -> Balance;

#[ink(message)]
fn get_user_reward_per_token_paid(&self, _account: AccountId) -> Balance;

#[ink(message)]
fn get_rewards(&self, _account: AccountId) -> Balance;

#[ink(message)]
fn total_supply(&self) -> Balance;

#[ink(message)]
fn balance_of(&self, _account: AccountId) -> Balance;

#[ink(message)]
fn last_time_reward_applicable(&self) -> Balance;

#[ink(message)]
fn reward_per_token(&self) -> Balance;

#[ink(message)]
fn earned(&self, _account: AccountId) -> Balance;

#[ink(message)]
fn get_reward_for_duration(&self) -> Balance;



#[ink(message)]
fn stake(&mut self, _amount: Balance) -> Result<(), StakingRewardsErrors>;

#[ink(message)]
fn withdraw(&mut self, _amount: Balance) -> Result<(), StakingRewardsErrors>;

#[ink(message)]
fn get_reward(&mut self) -> Result<(), StakingRewardsErrors>;

#[ink(message)]
fn exit(&mut self) -> Result<(), StakingRewardsErrors>;

#[ink(message)]
fn notify_reward_amount(&mut self, _reward: Balance) -> Result<(), StakingRewardsErrors>;

#[ink(message)]
fn recover_erc20(&mut self, _token: AccountId, _amount: Balance) -> Result<(), StakingRewardsErrors>;

#[ink(message)]
fn set_reward_duration(&mut self, _duration: Balance) -> Result<(), StakingRewardsErrors>;
}
4 changes: 4 additions & 0 deletions ink-awesome-defi/synthetix-staking-reward/contracts/global.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#![cfg_attr(not(feature = "std"), no_std, no_main)]

pub mod controllers;
pub mod providers;
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Ignore build artifacts from the local tests sub-crate.
/target/

# Ignore backup files creates by cargo fmt.
**/*.rs.bk

# Remove Cargo.lock when creating an executable, leave it for libraries
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
Cargo.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[package]
name = "psp22_lp"
version = "0.1.0"
authors = ["developeruche <[email protected]>"]
edition = "2021"

[dependencies]
ink = { version = "4.2.0", default-features = false }
openbrush = { git = "https://github.com/727-Ventures/openbrush-contracts", version = "4.0.0-beta.1", default-features = false, features = ["psp22","ownable","access_control", "psp34", "reentrancy_guard", "pausable"] }
global = {path = "./../../", default-features = false}

scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true }

[dev-dependencies]
ink_e2e = "4.2.0"

[lib]
path = "psp22_lp.rs"

[features]
default = ["std"]
std = [
"ink/std",
"scale/std",
"scale-info/std",

"openbrush/std",
]
ink-as-dependency = []
e2e-tests = []
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#![cfg_attr(not(feature = "std"), no_std, no_main)]





#[openbrush::implementation(PSP22, PSP22Permit, Nonces, PSP22Mintable, Ownable, PSP22Metadata)]
#[openbrush::contract]
pub mod psp22_permit {
use openbrush::{traits::Storage, modifiers};


#[ink(storage)]
#[derive(Default, Storage)]
pub struct PSP22Lp {
#[storage_field]
psp22: psp22::Data,
#[storage_field]
metadata: metadata::Data,
#[storage_field]
ownable: ownable::Data,
#[storage_field]
nonces: nonces::Data,
#[storage_field]
psp22_permit: psp22::extensions::permit::Data,

}


#[default_impl(PSP22Mintable)]
#[modifiers(only_owner)]
fn mint(&mut self) {}






impl PSP22Lp {
#[ink(constructor)]
pub fn new(total_supply: Balance, name: Option<String>, symbol: Option<String>, decimal: u8) -> Self {
let mut instance = Self::default();
let caller = instance.env().caller();

instance.metadata.name.set(&name);
instance.metadata.symbol.set(&symbol);
instance.metadata.decimals.set(&decimal);

ownable::Internal::_init_with_owner(&mut instance, Self::env().caller());
psp22::Internal::_mint_to(&mut instance, caller, total_supply).expect("Should mint total_supply");


instance
}



#[ink(message)]
pub fn burn(&mut self, _amount: Balance) -> Result<(), PSP22Error> {
let caller = self.env().caller();
psp22::Internal::_burn_from(self, caller, _amount)
}
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Ignore build artifacts from the local tests sub-crate.
/target/

# Ignore backup files creates by cargo fmt.
**/*.rs.bk

# Remove Cargo.lock when creating an executable, leave it for libraries
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
Cargo.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[package]
name = "staking_reward"
version = "0.1.0"
authors = ["developeruche <[email protected]>"]
edition = "2021"

[dependencies]
ink = { version = "4.2.0", default-features = false }

openbrush = { git = "https://github.com/727-Ventures/openbrush-contracts", version = "4.0.0-beta.1", default-features = false , features = ["psp22","ownable","access_control", "psp34", "reentrancy_guard", "pausable"]}
global = {path = "./../../", default-features = false}


scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true }

[dev-dependencies]
ink_e2e = "4.2.0"

[lib]
path = "staking_reward.rs"

[features]
default = ["std"]
std = [
"ink/std",
"scale/std",
"scale-info/std",

"openbrush/std",
"global/std"
]
ink-as-dependency = []
e2e-tests = []


[profile.dev]
overflow-checks = false

[profile.release]
overflow-checks = false
Loading