Skip to content

Commit 4433c3d

Browse files
authored
Merge pull request #372 from NUMBER72857/feature/309-dex-liquidity-mining-rewards
DEX: add liquidity mining rewards
2 parents 251f11d + 33cfcd9 commit 4433c3d

13 files changed

Lines changed: 1260 additions & 547 deletions

File tree

contracts/bridge/src/lib.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -569,13 +569,10 @@ mod bridge {
569569
let gas_fee = if self.config.gas_limit_per_bridge == 0 {
570570
0
571571
} else {
572-
let gas_ratio_bps =
573-
(u128::from(gas_estimate).saturating_mul(10_000))
574-
/ u128::from(self.config.gas_limit_per_bridge);
572+
let gas_ratio_bps = (u128::from(gas_estimate).saturating_mul(10_000))
573+
/ u128::from(self.config.gas_limit_per_bridge);
575574
let chain_risk_bps = u128::from(chain_info.confirmation_blocks).saturating_mul(10);
576-
let adjusted_bps = gas_ratio_bps
577-
.saturating_add(chain_risk_bps)
578-
.min(2_500);
575+
let adjusted_bps = gas_ratio_bps.saturating_add(chain_risk_bps).min(2_500);
579576
amount_in.saturating_mul(adjusted_bps) / 10_000
580577
};
581578
Ok(BridgeFeeQuote {

contracts/crowdfunding/src/lib.rs

Lines changed: 70 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,13 @@ mod propchain_crowdfunding {
4545
}
4646

4747
#[derive(
48-
Debug, Clone, Copy, PartialEq, Eq,
49-
scale::Encode, scale::Decode,
48+
Debug,
49+
Clone,
50+
Copy,
51+
PartialEq,
52+
Eq,
53+
scale::Encode,
54+
scale::Decode,
5055
ink::storage::traits::StorageLayout,
5156
)]
5257
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
@@ -59,8 +64,13 @@ mod propchain_crowdfunding {
5964
}
6065

6166
#[derive(
62-
Debug, Clone, Copy, PartialEq, Eq,
63-
scale::Encode, scale::Decode,
67+
Debug,
68+
Clone,
69+
Copy,
70+
PartialEq,
71+
Eq,
72+
scale::Encode,
73+
scale::Decode,
6474
ink::storage::traits::StorageLayout,
6575
)]
6676
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
@@ -71,8 +81,13 @@ mod propchain_crowdfunding {
7181
}
7282

7383
#[derive(
74-
Debug, Clone, Copy, PartialEq, Eq,
75-
scale::Encode, scale::Decode,
84+
Debug,
85+
Clone,
86+
Copy,
87+
PartialEq,
88+
Eq,
89+
scale::Encode,
90+
scale::Decode,
7691
ink::storage::traits::StorageLayout,
7792
)]
7893
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
@@ -83,8 +98,13 @@ mod propchain_crowdfunding {
8398
}
8499

85100
#[derive(
86-
Debug, Clone, Copy, PartialEq, Eq,
87-
scale::Encode, scale::Decode,
101+
Debug,
102+
Clone,
103+
Copy,
104+
PartialEq,
105+
Eq,
106+
scale::Encode,
107+
scale::Decode,
88108
ink::storage::traits::StorageLayout,
89109
)]
90110
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
@@ -95,8 +115,13 @@ mod propchain_crowdfunding {
95115
}
96116

97117
#[derive(
98-
Debug, Clone, Copy, PartialEq, Eq,
99-
scale::Encode, scale::Decode,
118+
Debug,
119+
Clone,
120+
Copy,
121+
PartialEq,
122+
Eq,
123+
scale::Encode,
124+
scale::Decode,
100125
ink::storage::traits::StorageLayout,
101126
)]
102127
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
@@ -108,9 +133,7 @@ mod propchain_crowdfunding {
108133
}
109134

110135
#[derive(
111-
Debug, Clone, PartialEq,
112-
scale::Encode, scale::Decode,
113-
ink::storage::traits::StorageLayout,
136+
Debug, Clone, PartialEq, scale::Encode, scale::Decode, ink::storage::traits::StorageLayout,
114137
)]
115138
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
116139
pub struct Campaign {
@@ -124,9 +147,7 @@ mod propchain_crowdfunding {
124147
}
125148

126149
#[derive(
127-
Debug, Clone, PartialEq,
128-
scale::Encode, scale::Decode,
129-
ink::storage::traits::StorageLayout,
150+
Debug, Clone, PartialEq, scale::Encode, scale::Decode, ink::storage::traits::StorageLayout,
130151
)]
131152
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
132153
pub struct InvestorProfile {
@@ -137,9 +158,7 @@ mod propchain_crowdfunding {
137158
}
138159

139160
#[derive(
140-
Debug, Clone, PartialEq,
141-
scale::Encode, scale::Decode,
142-
ink::storage::traits::StorageLayout,
161+
Debug, Clone, PartialEq, scale::Encode, scale::Decode, ink::storage::traits::StorageLayout,
143162
)]
144163
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
145164
pub struct Milestone {
@@ -153,9 +172,7 @@ mod propchain_crowdfunding {
153172
}
154173

155174
#[derive(
156-
Debug, Clone, PartialEq,
157-
scale::Encode, scale::Decode,
158-
ink::storage::traits::StorageLayout,
175+
Debug, Clone, PartialEq, scale::Encode, scale::Decode, ink::storage::traits::StorageLayout,
159176
)]
160177
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
161178
pub struct Proposal {
@@ -168,9 +185,7 @@ mod propchain_crowdfunding {
168185
}
169186

170187
#[derive(
171-
Debug, Clone, PartialEq,
172-
scale::Encode, scale::Decode,
173-
ink::storage::traits::StorageLayout,
188+
Debug, Clone, PartialEq, scale::Encode, scale::Decode, ink::storage::traits::StorageLayout,
174189
)]
175190
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
176191
pub struct ShareListing {
@@ -182,9 +197,7 @@ mod propchain_crowdfunding {
182197
}
183198

184199
#[derive(
185-
Debug, Clone, PartialEq,
186-
scale::Encode, scale::Decode,
187-
ink::storage::traits::StorageLayout,
200+
Debug, Clone, PartialEq, scale::Encode, scale::Decode, ink::storage::traits::StorageLayout,
188201
)]
189202
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
190203
pub struct RiskProfile {
@@ -215,7 +228,7 @@ mod propchain_crowdfunding {
215228
admin: AccountId,
216229
campaigns: Mapping<u64, Campaign>,
217230
campaign_count: u64,
218-
campaign_ids: Vec<u64>, // index for iteration
231+
campaign_ids: Vec<u64>, // index for iteration
219232
investor_profiles: Mapping<AccountId, InvestorProfile>,
220233
investments: Mapping<(u64, AccountId), u128>,
221234
milestones: Mapping<u64, Milestone>,
@@ -457,15 +470,17 @@ mod propchain_crowdfunding {
457470
if current == 0 {
458471
campaign.investor_count += 1;
459472
}
460-
self.investments.insert((campaign_id, caller), &(current + amount));
473+
self.investments
474+
.insert((campaign_id, caller), &(current + amount));
461475
campaign.raised_amount += amount;
462476
if campaign.raised_amount >= campaign.target_amount {
463477
campaign.status = CampaignStatus::Funded;
464478
}
465479
self.campaigns.insert(campaign_id, &campaign);
466480
let shares = (amount / 1000) as u64;
467481
let current_shares = self.share_holdings.get((campaign_id, caller)).unwrap_or(0);
468-
self.share_holdings.insert((campaign_id, caller), &(current_shares + shares));
482+
self.share_holdings
483+
.insert((campaign_id, caller), &(current_shares + shares));
469484
self.env().emit_event(InvestmentMade {
470485
campaign_id,
471486
investor: caller,
@@ -794,8 +809,10 @@ mod propchain_crowdfunding {
794809
.share_holdings
795810
.get((listing.campaign_id, buyer))
796811
.unwrap_or(0);
797-
self.share_holdings
798-
.insert((listing.campaign_id, buyer), &(buyer_shares + listing.shares));
812+
self.share_holdings.insert(
813+
(listing.campaign_id, buyer),
814+
&(buyer_shares + listing.shares),
815+
);
799816
self.listings.remove(listing_id);
800817
Ok(total_cost)
801818
}
@@ -892,7 +909,9 @@ mod propchain_crowdfunding {
892909

893910
#[ink(message)]
894911
pub fn get_shares(&self, campaign_id: u64, investor: AccountId) -> u64 {
895-
self.share_holdings.get((campaign_id, investor)).unwrap_or(0)
912+
self.share_holdings
913+
.get((campaign_id, investor))
914+
.unwrap_or(0)
896915
}
897916

898917
#[ink(message)]
@@ -933,7 +952,11 @@ mod propchain_crowdfunding {
933952
}
934953
}
935954
if let Some(ref keyword) = filter.title_keyword {
936-
if !summary.title.to_lowercase().contains(&keyword.to_lowercase()) {
955+
if !summary
956+
.title
957+
.to_lowercase()
958+
.contains(&keyword.to_lowercase())
959+
{
937960
return false;
938961
}
939962
}
@@ -1001,7 +1024,8 @@ mod propchain_crowdfunding {
10011024
#[ink(message)]
10021025
pub fn get_top_campaigns(&self, n: u64) -> Vec<CampaignSummary> {
10031026
let n = n.min(50) as usize;
1004-
let mut summaries: Vec<CampaignSummary> = self.campaign_ids
1027+
let mut summaries: Vec<CampaignSummary> = self
1028+
.campaign_ids
10051029
.iter()
10061030
.filter_map(|id| self.campaigns.get(*id))
10071031
.map(|c| self.campaign_to_summary(&c))
@@ -1058,7 +1082,11 @@ mod propchain_crowdfunding {
10581082
.iter()
10591083
.filter_map(|id| {
10601084
let invested = self.investments.get((*id, investor)).unwrap_or(0);
1061-
if invested > 0 { self.campaigns.get(*id) } else { None }
1085+
if invested > 0 {
1086+
self.campaigns.get(*id)
1087+
} else {
1088+
None
1089+
}
10621090
})
10631091
.map(|c| self.campaign_to_summary(&c))
10641092
.collect()
@@ -1085,7 +1113,7 @@ mod tests {
10851113
use super::*;
10861114
use ink::env::{test, DefaultEnvironment};
10871115
use propchain_crowdfunding::{
1088-
CampaignFilter, CampaignStatus, CrowdfundingError, RiskRating, RealEstateCrowdfunding,
1116+
CampaignFilter, CampaignStatus, CrowdfundingError, RealEstateCrowdfunding, RiskRating,
10891117
};
10901118

10911119
fn setup() -> RealEstateCrowdfunding {
@@ -1373,13 +1401,15 @@ mod tests {
13731401
fn test_share_campaign() {
13741402
let mut contract = setup();
13751403
let accounts = test::default_accounts::<DefaultEnvironment>();
1376-
1404+
13771405
let campaign_id = contract
13781406
.create_campaign("Viral Project".into(), 500_000)
13791407
.unwrap();
13801408

13811409
test::set_caller::<DefaultEnvironment>(accounts.bob);
1382-
assert!(contract.share_campaign(campaign_id, "Twitter".into()).is_ok());
1410+
assert!(contract
1411+
.share_campaign(campaign_id, "Twitter".into())
1412+
.is_ok());
13831413

13841414
let emitted_events = test::recorded_events().count();
13851415
assert_eq!(emitted_events, 2); // CampaignCreated + CampaignShared

0 commit comments

Comments
 (0)