Unit ID
b4rSCXhg7jLDPfTy7P7TaQAvg6Ul8BldEu7kGlqOYdY=
Received
16.03.2023 07:17:12
Confirmation delay (full node)
4 minutes 7 seconds
Confirmation delay (light node)
7 minutes 10 seconds
Authors
HAXZR7GPT4ZKTQEXJPQKHY3MTBLPT2OA
Definition
Messages
Definition
Definition: [ "autonomous agent", { "bounce_fees": { "base": 10000 }, "init": "{ $PORTFOLIO_SIZE = 2; $asset = var['asset']; $total_shares = var['total_shares'] OTHERWISE 0; }", "messages": { "cases": [ { "if": "{ !$asset }", "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": "state", "state": "{ var['asset'] = response_unit; response['message'] = 'Initialized'; }" } ] }, { "if": "{ trigger.data.intent == 'issue' }", "init": "{ $total_received_amount = reduce(params.portfolio, $PORTFOLIO_SIZE, ($sum, $portfolio_spec) => { $amount = trigger.outputs[$portfolio_spec.asset] OTHERWISE 0; return $sum + $amount; }, 0); $shares = $total_received_amount; require($shares > 0, "No portfolio assets received"); require(is_valid_amount($total_shares + $shares), "Too many asset coins received"); foreach(params.portfolio, $PORTFOLIO_SIZE, ($portfolio_spec) => { $received_amount = trigger.outputs[$portfolio_spec.asset] OTHERWISE 0; $expected_amount = round($total_received_amount * $portfolio_spec.percentage); require($expected_amount > 0, "Not enough assets coins received"); require($received_amount == $expected_amount, "Incorrect ratio of assets coins received"); }); }", "messages": [ { "app": "payment", "payload": { "asset": "{$asset}", "outputs": [ { "address": "{trigger.address}", "amount": "{$shares}" } ] } }, { "app": "state", "state": "{ var['total_shares'] += $shares; response['message'] = 'Shares Issued'; response['shares'] = $shares; }" } ] }, { "if": "{ trigger.data.intent == 'redeem' }", "init": "{ $shares_returned = trigger.output[[asset=$asset]]; require($shares_returned > 0, "No shares returned"); $share = $shares_returned / $total_shares; $amounts = []; foreach(params.portfolio, $PORTFOLIO_SIZE, ($portfolio_spec) => { $amounts[$portfolio_spec.asset] = floor(balance[$portfolio_spec.asset] * $share); }); }", "messages": [ { "app": "payment", "payload": { "asset": "{params.portfolio[0].asset}", "outputs": [ { "address": "{trigger.address}", "amount": "{$amounts[params.portfolio[0].asset]}" } ] } }, { "app": "payment", "payload": { "asset": "{params.portfolio[1].asset}", "outputs": [ { "address": "{trigger.address}", "amount": "{$amounts[params.portfolio[1].asset]}" } ] } }, { "app": "state", "state": "{ var['total_shares'] -= $shares_returned; response['message'] = 'Assets Redeemed'; response['shares'] = $shares_returned; }" } ] }, { "init": "{ bounce('Bad request'); }", "messages": [ { "app": "state", "state": "{}" } ] } ] } } ]
Technical information
Fees:
3,294 bytes
(515 headers, 2779 payload)
Level:3006197
Witnessed level:3006189
Main chain index:2981185
Latest included mc index:2981184
Status:stable/confirmed/final