Skip to content

Commit

Permalink
Merge pull request #317 from djeck1432/fix/contract-interactions
Browse files Browse the repository at this point in the history
Fix/contract interactions
  • Loading branch information
djeck1432 authored Dec 1, 2024
2 parents 9de4e20 + 0df8c00 commit b584cce
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 20 deletions.
6 changes: 3 additions & 3 deletions src/deposit.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ mod Deposit {
borrow_portion_percent > 0 && borrow_portion_percent < 100,
'Cannot calculate borrow amount'
);
assert(multiplier < 6 && multiplier > 1, 'Multiplier not supported');
assert(multiplier < 51 && multiplier > 10, 'Multiplier not supported');
assert(amount != 0 && pool_price != 0, 'Parameters cannot be zero');

let token_dispatcher = ERC20ABIDispatcher { contract_address: token };
Expand Down Expand Up @@ -244,8 +244,8 @@ mod Deposit {
let mut total_borrowed = 0;
let mut accumulated = 0;
let mut deposited = amount;

while (amount + accumulated) / amount < multiplier.into() {
while (amount + accumulated) * 10 / amount < multiplier.into() {
let borrow_capacity = ((deposited
* ZK_SCALE_DECIMALS
* collateral_factor
Expand Down
32 changes: 16 additions & 16 deletions tests/test_loop.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ fn test_loop_eth_valid() {
deposit_disp
.loop_liquidity(
DepositData {
token: eth_addr, amount: 685000000000000, multiplier: 4, borrow_portion_percent: 98
token: eth_addr, amount: 685000000000000, multiplier: 40, borrow_portion_percent: 98
},
pool_key,
get_slippage_limits(pool_key),
Expand Down Expand Up @@ -165,7 +165,7 @@ fn test_loop_eth_fuzz(amount: u64) {
if let Result::Err(panic_data) = deposit_disp
.loop_liquidity(
DepositData {
token: eth_addr, amount: amount.into(), multiplier: 4, borrow_portion_percent: 98
token: eth_addr, amount: amount.into(), multiplier: 40, borrow_portion_percent: 98
},
pool_key,
get_slippage_limits(pool_key),
Expand Down Expand Up @@ -227,7 +227,7 @@ fn test_loop_usdc_valid() {
deposit_disp
.loop_liquidity(
DepositData {
token: usdc_addr, amount: 60000000, multiplier: 4, borrow_portion_percent: 90
token: usdc_addr, amount: 60000000, multiplier: 40, borrow_portion_percent: 90
},
pool_key,
get_slippage_limits(pool_key),
Expand Down Expand Up @@ -279,7 +279,7 @@ fn test_loop_unauthorized() {
disp
.loop_liquidity(
DepositData {
token: usdc_addr, amount: 10000000, multiplier: 4, borrow_portion_percent: 90
token: usdc_addr, amount: 10000000, multiplier: 39, borrow_portion_percent: 90
},
pool_key,
get_slippage_limits(pool_key),
Expand Down Expand Up @@ -333,7 +333,7 @@ fn test_loop_position_exists() {
deposit_disp
.loop_liquidity(
DepositData {
token: usdc_addr, amount: 60000000, multiplier: 4, borrow_portion_percent: 90
token: usdc_addr, amount: 60000000, multiplier: 40, borrow_portion_percent: 90
},
pool_key,
get_slippage_limits(pool_key),
Expand All @@ -342,7 +342,7 @@ fn test_loop_position_exists() {
deposit_disp
.loop_liquidity(
DepositData {
token: usdc_addr, amount: 60000000, multiplier: 4, borrow_portion_percent: 98
token: usdc_addr, amount: 60000000, multiplier: 19, borrow_portion_percent: 98
},
pool_key,
get_slippage_limits(pool_key),
Expand Down Expand Up @@ -387,7 +387,7 @@ fn test_loop_position_exists_fuzz(amount: u64) {
if let Result::Err(_) = deposit_disp
.loop_liquidity(
DepositData {
token: eth_addr, amount: amount.into(), multiplier: 4, borrow_portion_percent: 98
token: eth_addr, amount: amount.into(), multiplier: 28, borrow_portion_percent: 98
},
pool_key,
get_slippage_limits(pool_key),
Expand All @@ -398,7 +398,7 @@ fn test_loop_position_exists_fuzz(amount: u64) {
match deposit_disp
.loop_liquidity(
DepositData {
token: eth_addr, amount: amount.into(), multiplier: 4, borrow_portion_percent: 98
token: eth_addr, amount: amount.into(), multiplier: 40, borrow_portion_percent: 98
},
pool_key,
get_slippage_limits(pool_key),
Expand Down Expand Up @@ -461,7 +461,7 @@ fn test_close_position_usdc_valid_time_passed() {
deposit_disp
.loop_liquidity(
DepositData {
token: usdc_addr, amount: 1000000000, multiplier: 4, borrow_portion_percent: 90
token: usdc_addr, amount: 1000000000, multiplier: 35, borrow_portion_percent: 90
},
pool_key,
get_slippage_limits(pool_key),
Expand Down Expand Up @@ -533,7 +533,7 @@ fn test_close_position_amounts_cleared() {
deposit_disp
.loop_liquidity(
DepositData {
token: usdc_addr, amount: 1000000000, multiplier: 4, borrow_portion_percent: 90
token: usdc_addr, amount: 1000000000, multiplier: 40, borrow_portion_percent: 90
},
pool_key,
get_slippage_limits(pool_key),
Expand Down Expand Up @@ -612,7 +612,7 @@ fn test_close_position_partial_debt_utilization() {
deposit_disp
.loop_liquidity(
DepositData {
token: eth_addr, amount: 1000000000000000, multiplier: 4, borrow_portion_percent: 98
token: eth_addr, amount: 1000000000000000, multiplier: 40, borrow_portion_percent: 98
},
pool_key,
get_slippage_limits(pool_key),
Expand Down Expand Up @@ -690,7 +690,7 @@ fn test_extra_deposit_valid() {
deposit_disp
.loop_liquidity(
DepositData {
token: usdc_addr, amount: 1000000000, multiplier: 4, borrow_portion_percent: 95
token: usdc_addr, amount: 1000000000, multiplier: 40, borrow_portion_percent: 95
},
pool_key,
get_slippage_limits(pool_key),
Expand Down Expand Up @@ -763,7 +763,7 @@ fn test_extra_deposit_supply_token_close_position_fuzz(extra_amount: u32) {
deposit_disp
.loop_liquidity(
DepositData {
token: usdc_addr, amount: 1000000000, multiplier: 4, borrow_portion_percent: 94
token: usdc_addr, amount: 1000000000, multiplier: 40, borrow_portion_percent: 94
},
pool_key,
get_slippage_limits(pool_key),
Expand Down Expand Up @@ -858,7 +858,7 @@ fn test_withdraw_valid_fuzz(amount: u32) {
deposit_disp
.loop_liquidity(
DepositData {
token: usdc_addr, amount: 1000000000, multiplier: 4, borrow_portion_percent: 90
token: usdc_addr, amount: 1000000000, multiplier: 40, borrow_portion_percent: 90
},
pool_key,
get_slippage_limits(pool_key),
Expand Down Expand Up @@ -979,7 +979,7 @@ fn test_extra_deposit_position_zero_amount() {
deposit_disp
.loop_liquidity(
DepositData {
token: eth_addr, amount: 685000000000000, multiplier: 2, borrow_portion_percent: 98
token: eth_addr, amount: 685000000000000, multiplier: 20, borrow_portion_percent: 98
},
pool_key,
get_slippage_limits(pool_key),
Expand Down Expand Up @@ -1026,7 +1026,7 @@ fn test_withdraw_position_open() {
deposit_disp
.loop_liquidity(
DepositData {
token: eth_addr, amount: 685000000000000, multiplier: 2, borrow_portion_percent: 98
token: eth_addr, amount: 685000000000000, multiplier: 20, borrow_portion_percent: 98
},
pool_key,
get_slippage_limits(pool_key),
Expand Down
2 changes: 2 additions & 0 deletions web_app/api/serializers/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class RepayTransactionDataResponse(BaseModel):
supply_price: int
debt_price: int
contract_address: str
ekubo_limits: dict[str, str]
borrow_portion_percent: int
position_id: str


Expand Down
4 changes: 3 additions & 1 deletion web_app/contract_tools/blockchain_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ async def get_loop_liquidity_data(
deposit_data = {
"token": deposit_token,
"amount": amount,
"multiplier": int(float(multiplier)),
"multiplier": int(float(multiplier) * 10), # Moves for one decimal place, from 2.5 to 25
"borrow_portion_percent": 80
}

Expand Down Expand Up @@ -230,6 +230,8 @@ async def get_repay_data(self, deposit_token: str, borrowing_token: str) -> dict
"supply_price": supply_price,
"debt_price": debt_price,
"pool_key": pool_key,
"ekubo_limits": {"lower": "18446748437148339061", "upper": "6277100250585753475930931601400621808602321654880405518632"},
"borrow_portion_percent": 93
}

async def claim_airdrop(self, contract_address: str, proofs: list[str]) -> None:
Expand Down

0 comments on commit b584cce

Please sign in to comment.