Unit ID
ldje/rMsPXxpOQYKwSsHxq7EEbwpGSe2XINLoHihiAg=
Received
11.04.2020 07:57:34
Confirmation delay (full node)
8 minutes 21 seconds
Confirmation delay (light node)
14 minutes 34 seconds
Messages
Definition
Definition: [ "autonomous agent", { "doc_url": "https://oswap-frontend.herokuapp.com/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]]; $amount0WithoutFees = $asset0 == 'base' ? $amount0 : $amount0 - $bounceFees; $amount1WithoutFees = $asset1 == 'base' ? $amount1 : $amount1 - $bounceFees; $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; $toAsset = trigger.data.toAsset; $deadline = trigger.data.deadline; $amountOutMin = trigger.data.amountOutMin; }", "messages": { "cases": [ { "if": "{!$asset AND trigger.data.initialize}", "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": { "finalizePair": "1" } } ] }, { "if": "{ $asset AND $amount0WithoutFees > 0 AND $amount1WithoutFees > 0 AND ($amount0WithoutFees * $amount1WithoutFees) >= $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": "{var['supply'] += $minted;}" } ] }, { "if": "{$asset AND trigger.output[[asset=$asset]]}", "init": "{ $burned = trigger.output[[asset=$asset]]; $investorShare = $burned / $supply; $minted0 = round($investorShare * balance[$asset0]); $minted1 = round($investorShare * balance[$asset1]); }", "messages": [ { "app": "payment", "payload": { "asset": "{$asset0}", "outputs": [ { "address": "{$to}", "amount": "{$minted0}" } ] } }, { "app": "payment", "payload": { "asset": "{$asset1}", "outputs": [ { "address": "{$to}", "amount": "{$minted1}" } ] } }, { "app": "state", "state": "{var['supply'] = ($supply - $burned == 0) ? false : $supply - $burned;}" } ] }, { "if": "{ $asset0ToAsset1 = ($amount0WithoutFees > 0 AND $amount1WithoutFees <= 0); $asset1ToAsset0 = ($amount1WithoutFees > 0 AND $amount0WithoutFees <= 0); $asset AND $supply AND ($asset0ToAsset1 || $asset1ToAsset0) }", "init": "{ if ($deadline AND $deadline < timestamp) bounce('expired'); $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}" } } ] }, { "messages": [ { "app": "state", "state": "{ response['error'] = 'default response'; response['amount0'] = $amount0; response['amount1'] = $amount1; response['amount0WithoutFees'] = $amount0WithoutFees; response['amount1WithoutFees'] = $amount1WithoutFees; response['asset'] = $asset; response['if'] = (($amount0WithoutFees * $amount1WithoutFees) >= $minLiquidity); }" } ] } ] } } ]
Technical information
Fees:
3,871 bytes
(353 headers, 3518 payload)
Level:1303309
Witnessed level:1303302
Main chain index:1298101
Latest included mc index:1298100
Status:stable/confirmed/final