Unit ID
fEKXwHU1Y4QnZy3YPdygRSRshBP0eWnuYuHLdyjrWQU=
Received
30.06.2023 00:18:01
Confirmation delay (full node)
10 minutes 26 seconds
Messages
Payments
Data
arb: 1
share: 0.8
AA responses
From 224BTCQE7WJPJ7OCFHZOEDVHP4FZM54R
  • Bounced
  • Response: { "error": "formula $do_arb = trigger.data.arb; $share = trigger.data.share OTHERWISE 1; // for incomplete arb $precalculated = trigger.data.amount AND trigger.data.new_arb; if (!$precalculated) { $max_amount = balance[$reserve_asset] - ($reserve_asset == 'base' ? 10000 : 0); $stable_balances = var[$stable_oswap_aa]['balances']; $stable_l_balances = var[$stable_oswap_aa]['leveraged_balances']; $reserve_balances = var[$reserve_oswap_aa]['balances']; $reserve_l_balances = var[$reserve_oswap_aa]['leveraged_balances']; $shifts = $get_shifts(); $stable_alpha = $get_stable_oswap_param('alpha', 0.5); $stable_beta = 1 - $stable_alpha; $reserve_alpha = $get_reserve_oswap_param('alpha', 0.5); $reserve_beta = 1 - $reserve_alpha; $pxy_stable = $stable_alpha/$stable_beta * ($stable_balances.y + $shifts.y0) / ($stable_balances.x + $shifts.x0); $pxy_reserve = $reserve_alpha/$reserve_beta * $reserve_balances.y / $reserve_balances.x; $stable_oswap_x_is_imported = $stable_oswap_params.x_asset == $stable_imported_asset; $reserve_oswap_x_is_reserve = $reserve_oswap_params.x_asset == $reserve_asset; $p_stable_in_imported = $stable_oswap_x_is_imported ? 1/$pxy_stable : $pxy_stable; $p_reserve_in_imported = $reserve_oswap_x_is_reserve ? $pxy_reserve : 1/$pxy_reserve; $p_oswap = $p_stable_in_imported / $p_reserve_in_imported; // stable in reserve $p_imported_in_stable = 1/$p_stable_in_imported; $p_imported_in_reserve = 1/$p_reserve_in_imported; $p_oswap_minus_fee = $p_oswap * $oswap_net; $p_oswap_plus_fee = $p_oswap / $oswap_net; $Lambda = $get_reserve_oswap_param('pool_leverage', 1); // $x_is_underleveraged = $reserve_balances.xn > ceil($reserve_balances.x/$Lambda); // $along_x = !$x_is_underleveraged; $denoms = $arblib#1.$get_denoms( $stable_balances, $reserve_balances, $stable_l_balances, $reserve_l_balances, $shifts, $pxy_stable, $pxy_reserve, $stable_oswap_x_is_imported, $reserve_oswap_x_is_reserve, $stable_alpha, $reserve_alpha ); $stable_denom = $denoms.stable_denom; $reserve_denom = $denoms.reserve_denom; $reserve_b = $denoms.reserve_b; $stable_a = $denoms.stable_a; require($stable_denom > 0, "negative stable denom "||$stable_denom); require($reserve_denom > 0, "negative reserve denom "||$reserve_denom); // bonding curve $mul_price_display_to_pennies = $mul_r/$mul2; $r = var[$curve_aa]['reserve']; $s2 = var[$curve_aa]['supply2'] / $mul2; $p2 = var[$curve_aa]['p2']; $fc = var[$curve_aa]['fast_capacity'] / $mul_r; $target_p2 = $get_target_p2(); $reward_share = ($n-1)*$fc/abs($target_p2-$p2)/$s2; // $p2_at_oswap = $p_oswap_plus_fee*$g/$mul_price_display_to_pennies; $fee_share = $get_fee_share($p2, $target_p2); // $fee_share = $get_fee_share(($p2_at_oswap + $p2)/2, $target_p2); // worst case, overestimated $p_stable = $p2/$g * $mul_price_display_to_pennies; $p_stable_with_reward = $p_stable * (1 - $reward_share); $p_stable_with_fee = $p_stable * (1 - $fee_share); // log({p2: $p2, p_stable: $p_stable, p_stable_with_reward: $p_stable_with_reward, reward_share: $reward_share, p_stable_with_fee: $p_stable_with_fee, fee_share: $fee_share, p2_at_oswap: $p2_at_oswap}); if (trigger.data.swap_imported){ $imported_balance = balance[$stable_imported_asset]; $amount = $imported_balance / $p_reserve_in_imported * $share; $final_p_reserve_in_imported = $p_reserve_in_imported * (1 + $amount / ($reserve_denom + $reserve_b * $Lambda * $amount)); } else if (trigger.data.swap_stable){ $stable_balance = balance[$stable_asset]; $dp = $stable_balance / ($stable_denom + $stable_a * $stable_balance) * $share; $final_p_imported_in_stable = $p_imported_in_stable * (1 + $dp); } // profitable to buy on ostable and sell on oswap else if ($p2 < $target_p2 AND $reward_share < 1 AND $get_distance($p2, $target_p2) > 0.0001 AND $p_stable_with_reward < $p_oswap_minus_fee) { $delta_r = $r * ($p_oswap_minus_fee - $p_stable_with_reward)/$p_oswap_minus_fee / ($n-1 + $r/$p_stable_with_reward/$stable_denom + $r/$reserve_denom); require($delta_r > 0, "negative delta_r when buying " || $delta_r); $delta_r_sent = min($delta_r, $max_amount * 0.7); $delta_s = $delta_r_sent/$p_oswap_minus_fee; $delta_s2 = $delta_s/$g; $tokens2 = floor($delta_s2); $amount = $get_amount_for_buying($tokens2, $target_p2); $from = 'curve'; $stable_tokens = floor($tokens2*$g); $dp = $stable_tokens / ($stable_denom + $stable_a * $stable_tokens) * $share; $final_p_imported_in_stable = $p_imported_in_stable * (1 + $dp); $final_p_reserve_in_imported = $p_reserve_in_imported * (1 + $amount / ($reserve_denom + $reserve_b * $Lambda * $amount) * $share * $share); $new_arb = { final_p_imported_in_reserve: 1/$final_p_reserve_in_imported, final_p_stable_in_reserve: 1/$final_p_imported_in_stable/$final_p_reserve_in_imported, }; /* log({ p2: $p2, target_p2: $target_p2, reward_share: $reward_share, p_stable: $p_stable, p_stable_with_reward: $p_stable_with_reward, p_stable_in_imported: $p_stable_in_imported, p_reserve_in_imported: $p_reserve_in_imported, p_oswap: $p_oswap, r: $r, delta_r: $delta_r, tokens2: $tokens2, amount: $amount, final_p_imported_in_stable: $final_p_imported_in_stable, final_p_reserve_in_imported: $final_p_reserve_in_imported, final_p_stable_in_reserve: 1/($final_p_reserve_in_imported * $final_p_imported_in_stable), });*/ $oswap_data = { final_price: $final_p_imported_in_stable, hops: [ { // next oswap in the chain address: $reserve_oswap_aa, change_address: this_address, data: {final_price: $final_p_reserve_in_imported}, }, {address: this_address}, ] }; } // profitable to buy on oswap and sell on ostable else if ($p_stable_with_fee > $p_oswap_plus_fee) { $get_arb_params = ($upper_p, $divisor) => { $dr = $r * ($upper_p - $p_oswap_plus_fee)/$upper_p / ($n-1 + $r/$p_oswap_plus_fee/$stable_denom + $r/$reserve_denom) / $divisor; require($dr > 0, "negative delta_r when selling " || $dr); $dr_sent = min($dr, $max_amount); $ds = $dr_sent/$upper_p; $amount_r = floor($dr_sent); $final_p_imported_in_reserve = $p_imported_in_reserve * (1 + $amount_r / ($reserve_denom + $reserve_b * $Lambda * $amount_r) * $share); $final_p_stable_in_imported = $p_stable_in_imported * (1 + $ds / ($stable_denom + $stable_a * $ds) * $share * $share); $final_p_stable_in_reserve = $final_p_stable_in_imported*$final_p_imported_in_reserve; { delta_r: $dr, delta_s: $ds, ds2: $ds/$g/$mul2, amount: $amount_r, final_p_imported_in_reserve: $final_p_imported_in_reserve, final_p_stable_in_imported: $final_p_stable_in_imported, final_p_stable_in_reserve: $final_p_stable_in_reserve, } }; $params1 = $get_arb_params($p_stable_with_fee, 1); // $p2_final = $params1.final_p_stable_in_reserve/$g / $mul_price_display_to_pennies; $dp2 = ($n-1)*$p2*$params1.ds2/$s2; $p2_avg = $p2-$dp2/2; // better approximation of p2 for the fee $fee_share2 = $get_fee_share($p2_avg, $target_p2); $p_stable_with_fee2 = $p_stable * (1 - $fee_share2); // log({dp2: $dp2, p2_avg: $p2_avg, fee_share2: $fee_share2, p_stable_with_fee2: $p_stable_with_fee2, reserve_balances: $reserve_balances, params1: $params1}); if ($p_stable_with_fee2 > $p_oswap_plus_fee){ $params2 = $get_arb_params($p_stable_with_fee2, 1); $p_stable_adjustment = ($p_stable_with_fee - $p_stable_with_fee2)/$p_stable_with_fee*100; // log({p_stable_adjustment: $p_stable_adjustment}); response['p_stable_adjustment'] = $p_stable_adjustment || '%'; } else{ $params2 = $get_arb_params($p_stable_with_fee, 2); // log({half: $params2.delta_r}); response['half'] = $params2.delta_r; } // $delta_r = $params2.delta_r; $delta_s = $params2.delta_s; $amount = min(ceil($params1.amount * $p_stable_with_fee/$p_oswap_plus_fee * 1.3), $max_amount); // larger, based on lower fee in params1 $final_p_imported_in_reserve = $params2.final_p_imported_in_reserve; $final_p_stable_in_imported = $params2.final_p_stable_in_imported; $final_p_stable_in_reserve = $params2.final_p_stable_in_reserve; $new_arb = { final_p_imported_in_reserve: $final_p_imported_in_reserve, final_p_stable_in_reserve: $final_p_stable_in_reserve, }; $from = 'oswap'; /* log({ // p2: $p2, // target_p2: $target_p2, // fee_share: $fee_share, // p_stable: $p_stable, // p_stable_with_fee: $p_stable_with_fee, p_stable_in_imported: $p_stable_in_imported, p_reserve_in_imported: $p_reserve_in_imported, p_oswap: $p_oswap, r: $r, // delta_r: $delta_r, amount: $amount, delta_s: $delta_s, final_p_imported_in_reserve: $final_p_imported_in_reserve, final_p_stable_in_imported: $final_p_stable_in_imported, final_p_stable_in_reserve: $new_arb.final_p_stable_in_reserve, });*/ require($amount >= $min_reserve_delta, "amount too small " || $amount); } else bounce("no arb opportunity exists"); } else { // overriden in the request, don't calc $amount = trigger.data.amount; $tokens2 = trigger.data.tokens2; $final_p_imported_in_reserve = trigger.data.final_p_imported_in_reserve; $final_p_stable_in_imported = trigger.data.final_p_stable_in_imported; $final_p_stable_in_reserve = $final_p_stable_in_imported*$final_p_imported_in_reserve; $new_arb = { final_p_imported_in_reserve: $final_p_imported_in_reserve, final_p_stable_in_reserve: $final_p_stable_in_reserve, }; $oswap_data = trigger.data.oswap_data; $from = $tokens2 ? 'curve' : 'oswap'; } failed: not finite in /" }
Technical information
Fees:
878 bytes
(451 headers, 427 payload)
Level:10306857
Witnessed level:10306845
Main chain index:9936889
Latest included mc index:9936888
Status:stable/confirmed/final