-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c4835d0
commit ed1d1b0
Showing
3 changed files
with
110 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |