Skip to content

Commit 97778bc

Browse files
committed
created a manifest file for the frontend
1 parent 3aab450 commit 97778bc

File tree

3 files changed

+68
-13
lines changed

3 files changed

+68
-13
lines changed
Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,50 @@
1-
# reset the resim account
1+
reset_resim_and_publish (){
22
resim reset
33

4-
# create a new default account
54
resim new-account
6-
7-
# create a second account
85
resim new-account
6+
resim publish .
7+
8+
}
9+
#reset_resim_and_publish
10+
# resim publish .
11+
12+
export account_1=account_sim1qw24s9xf6kqndhj5xc8qrgpjl4gxuya7xskcl0x0u8ps52twte
13+
export account_2=account_sim1qwjg3j3ptcspw7f422ywd3zyffxvqj79r8gfmkd0eh2segzcw2
14+
export package_address=package_sim1qygw3gt308cn2h9vmjqrmg2gw93qknpk3xkx30kms3qq0692xm
15+
export xrd_resource_address=resource_sim1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqz8qety
16+
17+
18+
instantiate_companion (){
19+
# set the platform fee
20+
resim call-function $package_address Companion instantiate 0.01 --manifest ../frontend/src/manifes.rtm
21+
}
22+
23+
instantiate_companion
24+
25+
export component=component_sim1qf9w9rf62n2tgcmp4uddqwzqmm233cj99j7eztwmzlzqfzyuw5
26+
export component_resource=resource_sim1qp9w9rf62n2tgcmp4uddqwzqmm233cj99j7eztwmzlzqvuu83u
27+
export admin_badge=resource_sim1qqsnrgrlxn4uzemq8er2txddxrqhar2ut2jxrcvvkvxsaa2vr4
28+
29+
30+
test_investor_access(){
31+
resim call-method $component create_preference {"finance_goal": "Make some dough", "risk_appetite": "High", "yield_duration" :20, "min_yield" :0.10}
32+
}
33+
# test_investor_access
34+
#export investor_badge= [invest]
35+
36+
37+
test_invest(){
38+
resim call-method $component invest 100000.0,$xrd_resource_address -p "1,$investor_badge"
39+
40+
}
41+
#test_invest
42+
43+
test_admin_access(){
44+
resim call-method $component total_fees_collected --proofs "1,$admin_badge"
45+
resim call-method $component withdraw_fees 100.0 -p "1,$admin_badge"
46+
resim call-method $component change_platform_fee 0.3 -p "1,$admin_badge"
47+
resim call-method $component total_invested_amount -p "1,$admin_badge"
948

10-
# publish the package
11-
resim publish .
49+
}
50+
#test_admin_access

7-defi-devpost/investor_companion/auto-defi/src/lib.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ pub struct UserPreference {
1414
risk_appetite: RiskAppetite,
1515
// the minimum range of time (in Days) the user is willing to invest
1616
yield_duration: u64,
17-
// the minimum yield the user is willing to accept
18-
min_yield: u64,
17+
// the minimum yield (APY) the user is willing to accept
18+
min_yield: Decimal,
1919
}
2020

2121
#[blueprint]
2222
mod companion {
23+
use std::ptr::null;
24+
2325
struct Companion {
2426
// Total amount of XRD tokens invested by users in the vault
2527
total_invested_amount: Vault,
@@ -107,6 +109,8 @@ mod companion {
107109

108110
// This function let user invest in the vault
109111
pub fn invest(&mut self, mut amount: Bucket) {
112+
// check if the user has created their preferences
113+
require(self.investor_badge);
110114
// remove the platform fee from the total amount invested
111115
let our_fee: Bucket = amount.take(amount.amount() * self.platform_fee);
112116
let remainder: Bucket = amount.take(amount.amount() - our_fee.amount());
@@ -143,8 +147,9 @@ mod companion {
143147
}
144148

145149
// this platform let admin see the total amount of fees collected
146-
pub fn total_fees_collected(&mut self) {
147-
self.total_fees_collected.amount();
150+
pub fn total_fees_collected(&mut self) -> Decimal {
151+
let total_fees =self.total_fees_collected.amount();
152+
return total_fees;
148153
}
149154

150155
// this function let admin to withdraw the fees collected
@@ -156,9 +161,7 @@ mod companion {
156161
pub fn change_platform_fee(&mut self, platform_fee: Decimal) {
157162
// check if the platform fee is between 0 and 1
158163
// if not, throw an error
159-
if platform_fee < dec!("0") || platform_fee > dec!("1") {
160-
panic!("Platform fee must be between 0 and 1");
161-
}
164+
assert!(platform_fee >= dec!("0") && platform_fee <= dec!("1"), "Platform fee must be between 0 and 1");
162165
// else, change the platform fee
163166
self.platform_fee = platform_fee;
164167
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CALL_METHOD
2+
ComponentAddress("component_sim1qgehpqdhhr62xh76wh6gppnyn88a0uau68epljprvj3sxknsqr")
3+
"lock_fee"
4+
Decimal("100");
5+
CALL_FUNCTION
6+
PackageAddress("package_sim1qygw3gt308cn2h9vmjqrmg2gw93qknpk3xkx30kms3qq0692xm")
7+
"Companion"
8+
"instantiate"
9+
Decimal("0.01");
10+
CALL_METHOD
11+
ComponentAddress("account_sim1qw24s9xf6kqndhj5xc8qrgpjl4gxuya7xskcl0x0u8ps52twte")
12+
"deposit_batch"
13+
Expression("ENTIRE_WORKTOP");

0 commit comments

Comments
 (0)