Unit ID
84JdnHjzYVr35A4beDMFB2sdMIt2jtjzMo/WLYZ7FOo=
Received
12.04.2020 20:34:18
Confirmation delay (full node)
5 minutes 12 seconds
Confirmation delay (light node)
10 minutes 12 seconds
Messages
Definition
Definition: [ "autonomous agent", { "doc_url": "https://oswap.io/pair.json", "init": "{ $bounceFees = 1e4; $minLiquidity = 1e3; $factory = params.factory; $asset0 = params.asset0; $asset1 = params.asset1; $asset = var[$factory]['assets.' || this_address]; $supply = var['supply']; $amount0 = trigger.output[[asset=$asset0]]; $amount1 = trigger.output[[asset=$asset1]]; $amount0NoFees = ($asset0 == 'base') ? $amount0 - $bounceFees : $amount0; $amount1NoFees = ($asset1 == 'base') ? $amount1 - $bounceFees : $amount1; $reserve0 = balance[$asset0] - $amount0; $reserve1 = balance[$asset1] - $amount1; if (trigger.data.to AND !is_valid_address(trigger.data.to)) bounce('invalid recipient address'); $to = trigger.data.to OTHERWISE trigger.address; $deadline = trigger.data.deadline; if ($deadline AND $deadline < timestamp) bounce('expired'); }", "messages": { "cases": [ { "if": "{!$asset AND trigger.data.initialize AND trigger.address == $factory}", "messages": [ { "app": "asset", "payload": { "is_private": false, "is_transferrable": true, "auto_destroy": false, "fixed_denominations": false, "issued_by_definer_only": true, "cosigned_by_definer": false, "spender_attested": false } }, { "app": "payment", "payload": { "asset": "base", "outputs": [ { "address": "{$factory}" } ] } }, { "app": "data", "payload": { "finalize": "1" } }, { "app": "state", "state": "{response['type'] = 'initialize';}" } ] }, { "if": "{ $asset AND $amount0NoFees > 0 AND $amount1NoFees > 0 AND ($amount0NoFees * $amount1NoFees) >= $minLiquidity }", "init": "{ if ($reserve1 == 0 OR $reserve0 == 0) { $minted = balance[$asset0]; return; } $ratio = $reserve1 / $reserve0; $expectedAmount1 = round($ratio * $amount0); if ($expectedAmount1 != $amount1) bounce('wrong ratio of amounts, expected ' || $expectedAmount1 || ' of ' || $asset1); $investorShare = $amount0 / $reserve0; $minted = round($investorShare * $supply); }", "messages": [ { "app": "payment", "payload": { "asset": "{$asset}", "outputs": [ { "address": "{$to}", "amount": "{$minted}" } ] } }, { "app": "state", "state": "{ $comFees = unit[response_unit].headers_commission + unit[response_unit].payload_commission; var['reserve0'] = ($asset0 == 'base') ? balance[$asset0] - $comFees : balance[$asset0]; var['reserve1'] = ($asset1 == 'base') ? balance[$asset1] - $comFees : balance[$asset1]; var['supply'] += $minted; response['type'] = 'mint'; }" } ] }, { "if": "{$asset AND trigger.output[[asset=$asset]]}", "init": "{ $burned = trigger.output[[asset=$asset]]; $share = $burned / $supply; $minted0 = round($share * $reserve0); $minted1 = round($share * $reserve1); }", "messages": [ { "app": "payment", "payload": { "asset": "{$asset0}", "outputs": [ { "address": "{$to}", "amount": "{$minted0}" } ] } }, { "app": "payment", "payload": { "asset": "{$asset1}", "outputs": [ { "address": "{$to}", "amount": "{$minted1}" } ] } }, { "app": "state", "state": "{ $comFees = unit[response_unit].headers_commission + unit[response_unit].payload_commission; var['reserve0'] = (($asset0 == 'base') ? balance[$asset0] - $comFees : balance[$asset0]) - $minted0; var['reserve1'] = (($asset1 == 'base') ? balance[$asset1] - $comFees : balance[$asset1]) - $minted1; var['supply'] -= $burned; response['type'] = 'burn'; }" } ] }, { "if": "{ $asset0ToAsset1 = ($amount0NoFees > 0 AND $amount1NoFees <= 0); $asset1ToAsset0 = ($amount1NoFees > 0 AND $amount0NoFees <= 0); $asset AND $supply AND ($asset0ToAsset1 || $asset1ToAsset0) }", "init": "{ $toAsset = trigger.data.toAsset; $amountOutMin = trigger.data.amountOutMin; $in = $asset0ToAsset1 ? '0' : '1'; $out = $asset0ToAsset1 ? '1' : '0'; $numerator = ${'amount' || $in} * ${'reserve' || $out} * 997; $denominator = ${'reserve' || $in} * 1000 + ${'amount' || $in} * 997; $amount = round($numerator / $denominator); if ($amountOutMin AND $amount < $amountOutMin) bounce('insufficient output amount'); $pair = var[$factory]['all_pairs.' || ${'asset' || $out} || '_' || $toAsset]; if ($toAsset AND !$pair) bounce('invalid asset'); $address = $toAsset ? $pair : $to; }", "messages": [ { "app": "payment", "payload": { "asset": "{${'asset' || $out}}", "outputs": [ { "address": "{$address}", "amount": "{$amount}" } ] } }, { "if": "{$toAsset}", "app": "data", "payload": { "to": "{$to}" } }, { "app": "state", "state": "{ $comFees = unit[response_unit].headers_commission + unit[response_unit].payload_commission; $reserve0NoCom = ($asset0 == 'base') ? balance[$asset0] - $comFees : balance[$asset0]; $reserve1NoCom = ($asset1 == 'base') ? balance[$asset1] - $comFees : balance[$asset1]; var['reserve0'] = $reserve0NoCom - ((${'asset' || $out} == $asset0) ? $amount : 0); var['reserve1'] = $reserve1NoCom - ((${'asset' || $out} == $asset1) ? $amount : 0); response['type'] = 'swap'; }" } ] } ] } } ]
Technical information
Fees:
4,632 bytes
(353 headers, 4279 payload)
Level:1305466
Witnessed level:1305456
Main chain index:1300257
Latest included mc index:1300256
Status:stable/confirmed/final