-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #582 from djeck1432/feat/margin-contract-setup
Base margin project structure
- Loading branch information
Showing
10 changed files
with
156 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
target | ||
.snfoundry_cache/ |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Margin Leverage | ||
This is the repository for our margin leverage smart contract's internals. | ||
|
||
### Project structure | ||
|
||
### Running tests | ||
To run tests with a shortcut, give the `test.sh` appropriate permissions: | ||
```sh | ||
chmod +x ./test.sh | ||
``` | ||
Then, run all tests with backtrace(where it is supported by Foundry): | ||
```sh | ||
./test.sh | ||
``` |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Code generated by scarb DO NOT EDIT. | ||
version = 1 | ||
|
||
[[package]] | ||
name = "margin" | ||
version = "0.1.0" | ||
dependencies = [ | ||
"snforge_std", | ||
] | ||
|
||
[[package]] | ||
name = "snforge_scarb_plugin" | ||
version = "0.32.0" | ||
source = "git+https://github.com/foundry-rs/starknet-foundry?tag=v0.32.0#3817c903b640201c72e743b9bbe70a97149828a2" | ||
|
||
[[package]] | ||
name = "snforge_std" | ||
version = "0.32.0" | ||
source = "git+https://github.com/foundry-rs/starknet-foundry?tag=v0.32.0#3817c903b640201c72e743b9bbe70a97149828a2" | ||
dependencies = [ | ||
"snforge_scarb_plugin", | ||
] |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
[package] | ||
name = "margin" | ||
version = "0.1.0" | ||
edition = "2023_11" | ||
|
||
# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html | ||
|
||
[dependencies] | ||
starknet = "2.9.4" | ||
|
||
[dev-dependencies] | ||
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.32.0" } | ||
assert_macros = "2.9.4" | ||
|
||
[[target.starknet-contract]] | ||
sierra = true | ||
|
||
[scripts] | ||
test = "snforge test" | ||
|
||
[profile.dev.cairo] | ||
unstable-add-statements-code-locations-debug-info = true | ||
unstable-add-statements-functions-debug-info = true | ||
inlining-strategy = "avoid" | ||
|
||
[tool.snforge] | ||
fuzzer_runs = 50 | ||
|
||
[[tool.snforge.fork]] | ||
name = "MAINNET" | ||
url = "http://51.195.57.196:6060/v0_7" | ||
block_id.tag = "latest" | ||
|
||
[[tool.snforge.fork]] | ||
name = "SEPOLIA" | ||
url = "http://51.195.57.196:6062/v0_7" | ||
block_id.tag = "latest" | ||
|
||
# Visit https://foundry-rs.github.io/starknet-foundry/appendix/scarb-toml.html for more information |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Visit https://foundry-rs.github.io/starknet-foundry/appendix/snfoundry-toml.html for more information | ||
|
||
# [sncast.myprofile1] # Define a profile name | ||
# url = "http://127.0.0.1:5050/" # Url of the RPC provider | ||
# accounts_file = "../account-file" # Path to the file with the account data | ||
# account = "mainuser" # Account from `accounts_file` or default account file that will be used for the transactions | ||
# keystore = "~/keystore" # Path to the keystore file | ||
# wait_params = { timeout = 500, retry_interval = 10 } # Wait for submitted transaction parameters | ||
# block_explorer = "StarkScan" # Block explorer service used to display links to transaction details |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use starknet::ContractAddress; | ||
use crate::types::{TokenAmount, PositionParameters}; | ||
|
||
#[starknet::interface] | ||
pub trait IMargin<TContractState> { | ||
fn deposit(ref self: TContractState, token: ContractAddress, amount: TokenAmount); | ||
fn withdraw(ref self: TContractState, token: ContractAddress, amount: TokenAmount); | ||
|
||
// TODO: Add Ekubo data for swap | ||
fn open_margin_position(ref self: TContractState, position_parameters: PositionParameters); | ||
fn close_position(ref self: TContractState); | ||
|
||
fn liquidate(ref self: TContractState, user: ContractAddress); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod margin; | ||
pub mod types; | ||
pub mod interface; |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#[starknet::contract] | ||
pub mod Margin { | ||
use starknet::{ | ||
event::EventEmitter, | ||
storage::{StoragePointerReadAccess, StoragePointerWriteAccess, StoragePathEntry, Map}, | ||
ContractAddress, get_contract_address, get_caller_address, ClassHash, | ||
}; | ||
use margin::{ | ||
interface::IMargin, | ||
types::{Position, TokenAmount, PositionParameters} | ||
}; | ||
|
||
|
||
#[storage] | ||
struct Storage { | ||
treasury_balances: Map<(ContractAddress, ContractAddress), TokenAmount>, | ||
pools: Map<ContractAddress, TokenAmount>, | ||
positions: Map<ContractAddress, Position>, | ||
} | ||
|
||
#[abi(embed_v0)] | ||
impl Margin of IMargin<ContractState>{ | ||
fn deposit(ref self: ContractState, token: ContractAddress, amount: TokenAmount) {} | ||
fn withdraw(ref self: ContractState, token: ContractAddress, amount: TokenAmount) {} | ||
|
||
// TODO: Add Ekubo data for swap | ||
fn open_margin_position(ref self: ContractState, position_parameters: PositionParameters) {} | ||
fn close_position(ref self: ContractState) {} | ||
fn liquidate(ref self: ContractState, user: ContractAddress) {} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use starknet::ContractAddress; | ||
|
||
pub type TokenAmount = u256; | ||
pub type Timestamp = u128; | ||
|
||
#[derive(Serde, Drop)] | ||
pub struct PositionParameters { | ||
pub initial_token: ContractAddress, | ||
pub debt_token: ContractAddress, | ||
pub amount: TokenAmount, | ||
} | ||
|
||
#[derive(Serde, starknet::Store)] | ||
pub struct Position { | ||
pub initial_token: ContractAddress, | ||
pub traded_token: ContractAddress, | ||
pub traded_amount: TokenAmount, | ||
pub debt: TokenAmount, | ||
pub is_open: bool, | ||
pub open_time: Timestamp, | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
SNFORGE_BACKTRACE=1 snforge test |