[
"autonomous agent",
{
"bounce_fees": {
"base": 10000
},
"init": "{
$BOUNCE_FEE = 10000;
$TYPICAL_FEE = 1000;
$REIMBURSEMENT = $BOUNCE_FEE - $TYPICAL_FEE;
}",
"messages": {
"cases": [
{
"if": "{ trigger.data.seller }",
"init": "{
$seller = trigger.address;
$start_price = trigger.data.start_price otherwise bounce ("start price is missing");
$lowest_price = trigger.data.lowest_price otherwise bounce ("lowest price is missing");
$time_steps = trigger.data.time_steps otherwise bounce ("time steps missing");
$price_steps = trigger.data.price_steps otherwise bounce ("price steps missing");
$product_description = trigger.data.product_description otherwise bounce ("product description is missing");
$product_url = trigger.data.product_url;
$auction_running = true;
//$cancel_time = trigger.data.cancel_time;
$reference = sha256($seller || $start_price || $lowest_price || $time_steps || $price_steps || $product_description || $auction_running || timestamp);
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{trigger.address}",
"amount": "{$REIMBURSEMENT}"
}
]
}
},
{
"app": "state",
"state": "{
var[$reference] = 'auction_created';
var[$reference||'.timestamp'] = timestamp;
var[$reference||'.seller'] = $seller;
var[$reference||'.start_price'] = $start_price;
var[$reference||'.lowest_price'] = $lowest_price;
var[$reference||'.time_steps'] = $time_steps;
var[$reference||'.price_steps'] = $price_steps;
var[$reference||'.product_description'] = $product_description;
var[$reference||'.product_url'] = $product_url;
var[$reference||'.start_time'] = $start_time;
var[$reference||'.end_time'] = $end_time;
var[$reference||'.auction_running'] = $auction_running;
response['reference'] = $reference;
response['status'] = var[$reference];
}"
}
]
},
{
"if": "{ trigger.data.buyer }",
"init": "{
$reference = trigger.data.reference;
$buyer = trigger.address;
$bid = trigger.output[[asset = base]];
$price_now = var[$reference||'.start_price']-(round((timestamp - var[$reference||'.timestamp'])/var[$reference||'.time_steps'])*var[$reference||'.price_steps']);
}",
"messages": {
"cases": [
{
"if": "{ $bid > $price_now AND var[$reference||'.auction_running'] == '1'}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{trigger.address}",
"amount": "{$bid-$price_now-$BOUNCE_FEE}"
},
{
"address": "{trigger.address}",
"amount": "{$REIMBURSEMENT}"
}
]
}
},
{
"app": "state",
"state": "{
response['message'] = 'Congratulations, you have won the auction';
response['payment'] = 'You have paid more than neccessary. We have reimbursed the exceeding amount';
}"
}
]
},
{
"if": "{ $bid < $price_now AND var[$reference||'.auction_running'] == '1'}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{trigger.address}",
"amount": "{$bid-$BOUNCE_FEE}"
},
{
"address": "{trigger.address}",
"amount": "{$REIMBURSEMENT}"
}
]
}
},
{
"app": "state",
"state": "{
response['message'] = 'Sorry, the amount is too low. We have reimbursed your payment minus transaction fees. Please bid again and pay the right amount.';
}"
}
]
},
{
"if": "{ $bid == $price_now AND var[$reference||'.auction_running'] == '1'}",
"messages": [
{
"app": "state",
"state": "{
var['auction_running'] = false;
response['message'] = 'Congratulations, you have won the auction';
}"
}
]
}
]
}
},
{
"init": "{
bounce("Enter buyer or seller");
}",
"messages": [
{
"app": "state",
"state": "{
response['usage'] = 'Enter buyer or seller';
}"
}
]
}
]
}
}
]