Skip to content

margin trading #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ref-exchange/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ref-exchange"
version = "1.9.1"
version = "1.9.2"
authors = ["Illia Polosukhin <illia.polosukhin@gmail.com>"]
edition = "2018"
publish = false
Expand Down
5 changes: 5 additions & 0 deletions ref-exchange/release_notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Release Notes

### Version 1.9.2
```
52Fmd38fqZbHoGQGRTmoXxr9xMu8zKQWaGggHSJYi23T
```
1. margin trading

### Version 1.9.1
```
Expand Down
28 changes: 27 additions & 1 deletion ref-exchange/src/account_deposit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use near_sdk::{
AccountId, Balance, PromiseResult, StorageUsage,
};
use crate::legacy::{AccountV1, AccountV2};
use crate::utils::{ext_self, ext_wrap_near, GAS_FOR_FT_TRANSFER, GAS_FOR_RESOLVE_TRANSFER, GAS_FOR_NEAR_WITHDRAW};
use crate::utils::{ext_self, ext_wrap_near, GAS_FOR_FT_TRANSFER, GAS_FOR_FT_TRANSFER_CALL, GAS_FOR_RESOLVE_TRANSFER, GAS_FOR_NEAR_WITHDRAW};
use crate::*;

// [AUDIT_01]
Expand Down Expand Up @@ -635,4 +635,30 @@ impl Contract {
))
}
}

pub(crate) fn internal_send_token_with_msg(
&self,
sender_id: &AccountId,
token_id: &AccountId,
amount: Balance,
msg: String
) -> Promise {
ext_fungible_token::ft_transfer_call(
sender_id.clone(),
U128(amount),
None,
msg,
token_id,
1,
GAS_FOR_FT_TRANSFER_CALL,
)
.then(ext_self::exchange_callback_post_withdraw(
token_id.clone(),
sender_id.clone(),
U128(amount),
&env::current_account_id(),
0,
GAS_FOR_RESOLVE_TRANSFER,
))
}
}
13 changes: 12 additions & 1 deletion ref-exchange/src/token_receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ enum TokenReceiverMessage {
referral_id: Option<ValidAccountId>,
/// List of sequential actions.
actions: Vec<Action>,
/// If not None, use ft_transfer_call
/// to send token_out back to predecessor with this msg.
client_echo: Option<String>,
skip_unwrap_near: Option<bool>,
},
HotZap {
Expand Down Expand Up @@ -100,6 +103,7 @@ impl FungibleTokenReceiver for Contract {
TokenReceiverMessage::Execute {
referral_id,
actions,
client_echo,
skip_unwrap_near
} => {
let referral_id = referral_id.map(|x| x.to_string());
Expand All @@ -109,8 +113,15 @@ impl FungibleTokenReceiver for Contract {
referral_id,
&actions,
);
if client_echo.is_some() && sender_id.to_string() == self.burrowland_id {
assert!(out_amounts.len() == 1, "Invalid actions, only one out token is allowed");
}
for (token_out, amount_out) in out_amounts.into_iter() {
self.internal_send_tokens(sender_id.as_ref(), &token_out, amount_out, skip_unwrap_near);
if let Some(ref message) = client_echo {
self.internal_send_token_with_msg(sender_id.as_ref(), &token_out, amount_out, message.clone());
} else {
self.internal_send_tokens(sender_id.as_ref(), &token_out, amount_out, skip_unwrap_near);
}
}
// Even if send tokens fails, we don't return funds back to sender.
PromiseOrValue::Value(U128(0))
Expand Down
8 changes: 5 additions & 3 deletions ref-exchange/tests/test_migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::common::utils::*;
pub mod common;

near_sdk_sim::lazy_static_include::lazy_static_include_bytes! {
PREV_EXCHANGE_WASM_BYTES => "../releases/ref_exchange_release.wasm",
PREV_EXCHANGE_WASM_BYTES => "../releases/ref_exchange_release_v191.wasm",
EXCHANGE_WASM_BYTES => "../res/ref_exchange.wasm",
}

Expand All @@ -26,7 +26,9 @@ fn test_upgrade() {
ValidAccountId::try_from("boost_farm".to_string()).unwrap(),
ValidAccountId::try_from("burrowland".to_string()).unwrap(), 4, 1)
);

let metadata = get_metadata(&pool);
assert_eq!(metadata.version, "1.9.1".to_string());

// Failed upgrade with no permissions.
let result = test_user
.call(
Expand All @@ -49,7 +51,7 @@ fn test_upgrade() {
.assert_success();
let metadata = get_metadata(&pool);
// println!("{:#?}", metadata);
assert_eq!(metadata.version, "1.9.1".to_string());
assert_eq!(metadata.version, "1.9.2".to_string());
assert_eq!(metadata.admin_fee_bps, 5);
assert_eq!(metadata.boost_farm_id, "boost_farm".to_string());
assert_eq!(metadata.burrowland_id, "burrowland".to_string());
Expand Down
Binary file modified releases/ref_exchange_release.wasm
Binary file not shown.
Binary file added releases/ref_exchange_release_v191.wasm
Binary file not shown.
Loading