Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmytro-Shashkevych committed Nov 17, 2023
1 parent c4835d0 commit ed1d1b0
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 107 deletions.
4 changes: 3 additions & 1 deletion contracts/lending/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
mod contract;
#![no_std]

mod storage;
mod test;
mod utilities;
mod contract;
105 changes: 0 additions & 105 deletions contracts/vault_contract/src/contract.rs

This file was deleted.

108 changes: 107 additions & 1 deletion contracts/vault_contract/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,109 @@
mod contract;
#![no_std]

use soroban_sdk::{contract, contractimpl, Address, Env};

use crate::utilities::*;

#[contract]
pub struct VaultContract;

#[contractimpl]
impl VaultContract {
// Initializes the contract with the specified admin, lending_contract margin_contract and addresses.
pub fn initialize(
env: Env,
lending_contract: Address,
margin_contract: Address,
admin: Address,
) {
if has_admin(&env) {
panic!("already initialized")
}

set_admin(&env, &admin);
set_lending_contract(&env, &lending_contract);
set_margin_contract(&env, &margin_contract);
}

pub fn set_lending_contract(env: Env, lending_contract: Address) {
// Admin only
let admin: Address = get_admin(&env);
admin.require_auth();

set_lending_contract(&env, &lending_contract);
}

pub fn get_lending_contract(env: Env) -> Address {
get_lending_contract(&env)
}

pub fn set_margin_positions_contract(env: Env, margin_contract: Address) {
// Admin only
let admin: Address = get_admin(&env);
admin.require_auth();

set_margin_contract(&env, &margin_contract);
}

pub fn redeem_from_vault_contract(
env: Env,
user_address: Address,
token_address: Address,
amount: u128,
) {
// Admin only
let lending_contract: Address = get_lending_contract(&env);
lending_contract.require_auth();

move_token(
&env,
&token_address,
&env.current_contract_address(),
&user_address,
amount as i128,
)
}

// // redeem_from_vault_contract_margin - for margin positions contract
// pub fn redeem_from_vault_contract_m(
// env: Env,
// user_address: Address,
// token_address: Address,
// amount: u128,
// ) {
// // Admin only
// let margin_positions_contract: Address = get_margin_contract(&env);
// margin_positions_contract.require_auth();
//
// move_token(
// &env,
// &token_address,
// &env.current_contract_address(),
// &user_address,
// amount as i128,
// )
// }
//
pub fn borrow_from_vault_contract(
env: Env,
user_address: Address,
token_address: Address,
amount: u128,
) {
// Admin only
let lending_contract: Address = get_lending_contract(&env);
lending_contract.require_auth();

move_token(
&env,
&token_address,
&env.current_contract_address(),
&user_address,
amount as i128,
)
}
}


mod storage;
mod utilities;

0 comments on commit ed1d1b0

Please sign in to comment.