Skip to content

Commit

Permalink
Merge branch 'main' into test/swap-pricing-utils
Browse files Browse the repository at this point in the history
  • Loading branch information
delaaxe committed Oct 31, 2023
2 parents 3f987e8 + dd0ca39 commit b0eb504
Show file tree
Hide file tree
Showing 55 changed files with 1,454 additions and 577 deletions.
29 changes: 28 additions & 1 deletion .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,35 @@
"contributions": [
"code"
]
},
{
"login": "JeanWoked",
"name": "JeanWoked",
"avatar_url": "https://avatars.githubusercontent.com/u/149107619?v=4",
"profile": "https://github.com/JeanWoked",
"contributions": [
"code"
]
},
{
"login": "vuittont60",
"name": "vuittont60",
"avatar_url": "https://avatars.githubusercontent.com/u/81072379?v=4",
"profile": "https://github.com/vuittont60",
"contributions": [
"code"
]
},
{
"login": "MavericksFive",
"name": "Arnaud Berger",
"avatar_url": "https://avatars.githubusercontent.com/u/95299145?v=4",
"profile": "https://github.com/MavericksFive",
"contributions": [
"code"
]
}
],
"contributorsPerLine": 7,
"linkToUsage": false
}
}
2 changes: 1 addition & 1 deletion .github/workflows/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

- name: Install Semgrep
run: |
pip install semgrep
pip install semgrep==1.45.0
- name: Run Semgrep
run: semgrep --config https://github.com/avnu-labs/semgrep-cairo-rules/releases/download/v0.0.1/cairo-rules.yaml ./src > semgrep-output.txt
- name: Save Semgrep Output as an Artifact
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on: [push, pull_request]

env:
SCARB_VERSION: 0.7.0
STARKNET_FOUNDRY_VERSION: 0.8.3

jobs:
check:
Expand All @@ -14,6 +13,11 @@ jobs:
- uses: software-mansion/setup-scarb@v1
with:
scarb-version: "0.7.0"
- uses: foundry-rs/setup-snfoundry@v1
with:
starknet-foundry-version: 0.8.3
- name: Run cairo tests
run: snforge test
# - name: Set up Scarb
#ses: software-mansion/setup-scarb@v1
# Install Scarb from a nightly release
Expand All @@ -22,7 +26,3 @@ jobs:
# wget https://github.com/software-mansion/scarb-nightlies/releases/download/${NIGHTLY_DATE}/scarb-${NIGHTLY_DATE}-x86_64-unknown-linux-gnu.tar.gz
# tar -xvf scarb-${NIGHTLY_DATE}-x86_64-unknown-linux-gnu.tar.gz
# sudo mv scarb-v${SCARB_VERSION}-x86_64-unknown-linux-gnu/bin/scarb /usr/local/bin
- name: Install starknet foundry
run: curl -L https://raw.githubusercontent.com/foundry-rs/starknet-foundry/master/scripts/install.sh | sh -s -- -v ${STARKNET_FOUNDRY_VERSION}
- name: Run cairo tests
run: snforge
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ snforge

## 🚀 Deploy

To deploy contracts of the saturo, you first need to setup a smart wallet :
To deploy the contracts of Satoru, you first need to setup a smart wallet :

- Create a signer by following this tutorial : [Signers](https://book.starkli.rs/signers)

Expand All @@ -63,6 +63,21 @@ cd scripts
./deploy_contract.sh
```

## Deployed Contracts

- RoleStore: 0x07eacab18c343f30edfa9336b8eacce9bc56303d43c92609a88e8da25177f5b3
- DataStore: 0x0549539da18f4d574211365b6abd678ef940444b579900efedcb935210c41481
- OrderVault: 0x01f1252d6d02feb14cfa88beff415e1524d1cebb31870056567aae257104b6fd
- Router: 0x00dd0912017ee7c8151555394380acd1012a814916d384b12ca64afa0eae2bc5
- EventEmitter: 0x0284ae712869c0af4f538e9297e6965d3c9ba9110830944047de8d35da7ea447
- MarketToken: 0x044391e9498f440cc41ace136ea317f6bfa2080311085d1846529e421974a1d3
- MarketFactory: 0x05766918626a91ca83f52003eb03bbf1f13174aa22e340c8057d8d5d6affbfcf
- WithdrawalVault: 0x050c83c2bc74cc50676fdd5598b40f9d0d6d5ccf6ea3478a7999e29473da03f1
- SwapHandler: 0x039aa67b479f4870878ec6d3002f9fa9b8e98d4d3d10c1f32b5d394a456aab28
- ReferralStorage: 0x0189463034c24b2cb091dcb515287bea13a4767534f09e52692a4cdc30254001
- DepositVault: 0x07d435e7ab3a5cd4b872e5725b02898833cb9a7c62e2d9a6a9db324d61e2925e


## 📚 Resources

Here are some resources to help you get started:
Expand Down Expand Up @@ -135,6 +150,11 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center" valign="top" width="14.28%"><a href="https://github.com/VictorONN"><img src="https://avatars.githubusercontent.com/u/73134512?v=4?s=100" width="100px;" alt="VictorONN"/><br /><sub><b>VictorONN</b></sub></a><br /><a href="https://github.com/keep-starknet-strange/satoru/commits?author=VictorONN" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/kasteph"><img src="https://avatars.githubusercontent.com/u/3408478?v=4?s=100" width="100px;" alt="kasteph"/><br /><sub><b>kasteph</b></sub></a><br /><a href="https://github.com/keep-starknet-strange/satoru/commits?author=kasteph" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/khaeljy"><img src="https://avatars.githubusercontent.com/u/1810456?v=4?s=100" width="100px;" alt="Khaeljy"/><br /><sub><b>Khaeljy</b></sub></a><br /><a href="https://github.com/keep-starknet-strange/satoru/commits?author=khaeljy" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/JeanWoked"><img src="https://avatars.githubusercontent.com/u/149107619?v=4?s=100" width="100px;" alt="JeanWoked"/><br /><sub><b>JeanWoked</b></sub></a><br /><a href="https://github.com/keep-starknet-strange/satoru/commits?author=JeanWoked" title="Code">💻</a></td>
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/vuittont60"><img src="https://avatars.githubusercontent.com/u/81072379?v=4?s=100" width="100px;" alt="vuittont60"/><br /><sub><b>vuittont60</b></sub></a><br /><a href="https://github.com/keep-starknet-strange/satoru/commits?author=vuittont60" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/MavericksFive"><img src="https://avatars.githubusercontent.com/u/95299145?v=4?s=100" width="100px;" alt="Arnaud Berger"/><br /><sub><b>Arnaud Berger</b></sub></a><br /><a href="https://github.com/keep-starknet-strange/satoru/commits?author=MavericksFive" title="Code">💻</a></td>
</tr>
</tbody>
</table>
Expand Down
6 changes: 3 additions & 3 deletions book/src/continuous-integration/workflows.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,18 +198,18 @@ on:
- main
env:
SCARB_VERSION: 0.7.0
STARKNET_FOUNDRY_VERSION: 0.8.3
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: foundry-rs/setup-snfoundry@v1
with:
starknet-foundry-version: 0.9.0
- uses: software-mansion/setup-scarb@v1
with:
scarb-version: "0.7.0"
- name: Install starknet foundry
run: curl -L https://raw.githubusercontent.com/foundry-rs/starknet-foundry/master/scripts/install.sh | sh -s -- -v ${STARKNET_FOUNDRY_VERSION}
- name: Run cairo tests
run: snforge
```
4 changes: 2 additions & 2 deletions book/src/smart-contracts-architecture/position-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The purpose of the position module is to help with management of positions.

## Fees in position

Borrowing fees for position require only a borrowing_factor to track. An example on how this works is if the global cumulative_borrowing_factor is 10020% a position would be opened with borrowingFactor as 10020%. After some time, if the cumulative\_\_borrowing_factor is updated to 10025% the position would owe 5% of the position size as borrowing fees. The total pending borrowing fees of all positions is factored into the calculation of the pool value for LPs. When a position is increased or decreased, the pending borrowing fees for the position is deducted from the position's
Borrowing fees for position require only a borrowing_factor to track. An example on how this works is if the global cumulative_borrowing_factor is 10020% a position would be opened with borrowingFactor as 10020%. After some time, if the cumulative_borrowing_factor is updated to 10025% the position would owe 5% of the position size as borrowing fees. The total pending borrowing fees of all positions is factored into the calculation of the pool value for LPs. When a position is increased or decreased, the pending borrowing fees for the position is deducted from the position's
collateral and transferred into the LP pool.

The same borrowing fee factor tracking cannot be applied for funding fees as those calculations consider pending funding fees based on the fiat value of the position sizes.
Expand All @@ -28,4 +28,4 @@ It contains the following files:
- [increase_position_utils.cairo](https://github.com/keep-starknet-strange/satoru/blob/main/src/position/increase_position_utils.cairo): Library for functions to help with increasing a position.
- [position_event_utils.cairo](https://github.com/keep-starknet-strange/satoru/blob/main/src/position/position_event_utils.cairo): Library with helper functions to emit position related events.
- [position_utils.cairo](https://github.com/keep-starknet-strange/satoru/blob/main/src/position/position_utils.cairo): Library with various utility functions for positions.
- [position.cairo](https://github.com/keep-starknet-strange/satoru/blob/main/src/position/position.cairo): Contains main Position struct.
- [position.cairo](https://github.com/keep-starknet-strange/satoru/blob/main/src/position/position.cairo): Contains main Position struct.
28 changes: 5 additions & 23 deletions src/adl/adl_utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use satoru::data::data_store::{IDataStoreDispatcher, IDataStoreDispatcherTrait};
use satoru::event::{event_emitter::{IEventEmitterDispatcher, IEventEmitterDispatcherTrait},};
use satoru::oracle::oracle::{IOracleDispatcher, IOracleDispatcherTrait};
use satoru::market::market_utils::{
MarketPrices, get_enabled_market, get_market_prices, is_pnl_factor_exceeded_direct
MarketPrices, get_enabled_market, get_market_prices, is_pnl_factor_exceeded_check
};
use satoru::adl::error::AdlError;
use satoru::data::keys;
Expand Down Expand Up @@ -100,7 +100,7 @@ fn update_adl_state(
// it is possible for a pool to be in a state where withdrawals and ADL is not allowed
// this is similar to the case where there is a large amount of open positions relative
// to the amount of tokens in the pool
let (should_enable_adl, pnl_to_pool_factor, max_pnl_factor) = is_pnl_factor_exceeded_direct(
let (should_enable_adl, pnl_to_pool_factor, max_pnl_factor) = is_pnl_factor_exceeded_check(
data_store, _market, prices, is_long, keys::max_pnl_factor_for_adl()
);
set_adl_enabled(data_store, market, is_long, should_enable_adl);
Expand All @@ -127,19 +127,9 @@ fn create_adl_order(params: CreateAdlOrderParams) -> felt252 {
let positon_key = position_utils::get_position_key(
params.account, params.market, params.collateral_token, params.is_long
);
let position_result = params.data_store.get_position(positon_key);
let mut position: Position = Default::default();
let position = params.data_store.get_position(positon_key);

// Check if the position is valid
match position_result {
Option::Some(pos) => {
assert(params.size_delta_usd <= pos.size_in_usd, AdlError::INVALID_SIZE_DELTA_FOR_ADL);
position = pos;
},
Option::None => {
panic_with_felt252(AdlError::POSTION_NOT_VALID);
}
}
assert(params.size_delta_usd <= position.size_in_usd, AdlError::INVALID_SIZE_DELTA_FOR_ADL);

// no slippage is set for this order, it may be preferrable for ADL orders
// to be executed, in case of large price impact, the user could be refunded
Expand Down Expand Up @@ -260,15 +250,7 @@ fn set_latest_adl_block(
fn get_adl_enabled(
data_store: IDataStoreDispatcher, market: ContractAddress, is_long: bool
) -> bool { // TODO
let result = data_store.get_bool(keys::is_adl_enabled_key(market, is_long));
match result {
Option::Some(data) => {
return data;
},
Option::None => {
return false;
}
}
data_store.get_bool(keys::is_adl_enabled_key(market, is_long))
}

/// Set whether ADL is enabled.
Expand Down
2 changes: 1 addition & 1 deletion src/adl/error.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ mod AdlError {
'block_no_smaller_than_required';
const INVALID_SIZE_DELTA_FOR_ADL: felt252 = 'invalid_size_delta_for_adl';
const ADL_NOT_ENABLED: felt252 = 'adl_not_enabled';
const POSTION_NOT_VALID: felt252 = 'position_not_valid';
const POSITION_NOT_VALID: felt252 = 'position_not_valid';
}
Loading

0 comments on commit b0eb504

Please sign in to comment.