[
"autonomous agent",
{
"bounce_fees": {
"base": 10000
},
"init": "{
$BOUNCE_FEE = 10000;
$TYPICAL_FEE = 1300;
$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;
$encryptionAlgorithm = trigger.data.encryptionAlgorithm otherwise bounce ("the asymetric encryption to be used for the pairing key exchange, e.g. \"AES\". Use \"NONE\" if the pairing key should be stored in plain text (not recommended)");
$auction_status = 'running';
$reference = sha256($seller || $start_price || $lowest_price || $time_steps || $price_steps || $product_description || $auction_status || timestamp);
}",
"messages": [
{
"app": "state",
"state": "{
var['auction.'||$reference||'.timestamp'] = timestamp;
var['auction.'||$reference||'.seller'] = $seller;
var['auction.'||$reference||'.start_price'] = $start_price;
var['auction.'||$reference||'.lowest_price'] = $lowest_price;
var['auction.'||$reference||'.time_steps'] = $time_steps;
var['auction.'||$reference||'.price_steps'] = $price_steps;
var['auction.'||$reference||'.product_description'] = $product_description;
var['auction.'||$reference||'.product_url'] = $product_url;
var['auction.'||$reference||'.start_time'] = $start_time;
var['auction.'||$reference||'.end_time'] = $end_time;
var['auction.'||$reference||'.auction_status'] = $auction_status;
var['auction.'||$reference||'.public_key_0'] = trigger.data.public_key_0;
var['auction.'||$reference||'.public_key_1'] = trigger.data.public_key_1;
var['auction.'||$reference||'.public_key_2'] = trigger.data.public_key_2;
var['auction.'||$reference||'.public_key_3'] = trigger.data.public_key_3;
var['auction.'||$reference||'.public_key_4'] = trigger.data.public_key_4;
var['auction.'||$reference||'.public_key_5'] = trigger.data.public_key_5;
var['auction.'||$reference||'.public_key_6'] = trigger.data.public_key_6;
var['auction.'||$reference||'.public_key_7'] = trigger.data.public_key_7;
var['auction.'||$reference||'.public_key_8'] = trigger.data.public_key_8;
var['auction.'||$reference||'.public_key_9'] = trigger.data.public_key_9;
var['auction.'||$reference||'.public_key_10'] = trigger.data.public_key_10;
var['auction.'||$reference||'.public_key_11'] = trigger.data.public_key_11;
var['auction.'||$reference||'.public_key_12'] = trigger.data.public_key_12;
var['auction.'||$reference||'.public_key_13'] = trigger.data.public_key_13;
var['auction.'||$reference||'.public_key_14'] = trigger.data.public_key_14;
var['auction.'||$reference||'.encryptionAlgorithm'] = $encryptionAlgorithm;
response['reference'] = $reference;
response['status'] = $auction_status;
}"
}
]
},
{
"if": "{ trigger.data.buyer }",
"init": "{
$reference = trigger.data.reference otherwise bounce ("auction ID missing");
$pairing_code_0 = trigger.data.pairing_code_0 otherwise bounce ("encrypted / plain pairing code missing");
$buyer = trigger.address;
$bid = trigger.output[[asset = base]];
$start_price = var['auction.'||$reference||'.start_price'];
$timestamp_saved = var['auction.'||$reference||'.timestamp'];
$time_steps = var['auction.'||$reference||'.time_steps'];
$price_steps = var['auction.'||$reference||'.price_steps'];
$lowest_price = var['auction.'||$reference||'.lowest_price'];
$price_now = $start_price-(round((timestamp - $timestamp_saved)/$time_steps) * $price_steps);
$PRICE = ($price_now< $lowest_price ? $lowest_price : $price_now);
}",
"messages": {
"cases": [
{
"if": "{ $bid > $price_now AND var['auction.'||$reference||'.auction_status'] == 'running'}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{trigger.address}",
"amount": "{$bid-$PRICE-$BOUNCE_FEE}"
}
]
}
},
{
"app": "state",
"state": "{
var['auction.'||$reference||'.bid'] = $bid;
var['auction.'||$reference||'.buyer'] = $buyer;
var['auction.'||$reference||'.pairing_code_0'] = $pairing_code_0;
var['auction.'||$reference||'.pairing_code_1'] = trigger.data.pairing_code_1;
var['auction.'||$reference||'.pairing_code_2'] = trigger.data.pairing_code_2;
var['auction.'||$reference||'.pairing_code_3'] = trigger.data.pairing_code_3;
var['auction.'||$reference||'.pairing_code_4'] = trigger.data.pairing_code_4;
var['auction.'||$reference||'.pairing_code_5'] = trigger.data.pairing_code_5;
var['auction.'||$reference||'.pairing_code_6'] = trigger.data.pairing_code_6;
var['auction.'||$reference||'.pairing_code_7'] = trigger.data.pairing_code_7;
var['auction.'||$reference||'.pairing_code_8'] = trigger.data.pairing_code_8;
var['auction.'||$reference||'.pairing_code_9'] = trigger.data.pairing_code_9;
var['auction.'||$reference||'.pairing_code_10'] = trigger.data.pairing_code_10;
var['auction.'||$reference||'.pairing_code_11'] = trigger.data.pairing_code_11;
var['auction.'||$reference||'.pairing_code_12'] = trigger.data.pairing_code_12;
var['auction.'||$reference||'.pairing_code_13'] = trigger.data.pairing_code_13;
var['auction.'||$reference||'.pairing_code_14'] = trigger.data.pairing_code_14;
var['auction.'||$reference||'.auction_status'] = 'holding';
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['auction.'||$reference||'.auction_status'] == 'running'}",
"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['auction.'||$reference||'.auction_status'] == 'running'}",
"messages": [
{
"app": "state",
"state": "{
var['auction.'||$reference||'.bid'] = $bid;
var['auction.'||$reference||'.buyer'] = $buyer;
var['auction.'||$reference||'.auction_status'] = 'holding';
response['reference2'] = $reference2;
response['message'] = 'Congratulations, you have won the auction';
}"
}
]
}
]
}
},
{
"if": "{trigger.data.buyer_data_confirm}",
"init": "{
$reference = trigger.data.reference otherwise bounce ("reference is missing");
$buyer = var['auction.'||trigger.data.reference||'.buyer'];
$auction_status = var['auction.'||trigger.data.reference||'.auction_status'];
}",
"messages": {
"cases": [
{
"if": "{ trigger.address == $buyer AND $auction_status == 'holding'}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{$buyer}",
"amount": "{$REIMBURSEMENT}"
}
]
}
},
{
"app": "state",
"state": "{
var['auction.'||$reference||'.auction_status'] = 'buyer_data_confirm';
response['message'] = 'Thank you for confirming that you have sent your data to the seller!';
}"
}
]
}
]
}
},
{
"if": "{trigger.data.goods_receipt}",
"init": "{
$reference = trigger.data.reference otherwise bounce ("reference is missing");
$comment = trigger.data.comment otherwise bounce ("comment is missing");
$voting = trigger.data.voting otherwise bounce ("voting between 1 and 5 is missing"); //1-5
$auction_status = var['auction.'||trigger.data.reference||'.auction_status'];
$buyer = var['auction.'||trigger.data.reference||'.buyer'];
$seller = var['auction.'||trigger.data.reference||'.seller'];
$comment_reference = sha256($reference || $seller || timestamp);
}",
"messages": {
"cases": [
{
"if": "{ trigger.address == $buyer AND $auction_status == 'buyer_data_confirm'}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{$seller}",
"amount": "{var['auction.'||$reference||'.bid']}"
}
]
}
},
{
"app": "state",
"state": "{
var['auction.'||$reference||'.auction_status'] = 'goods_receipt';
var['seller.'||$seller||'.comment.'||$comment_reference||'.comment'] = $comment;
var['seller.'||$seller||'.comment.'||$comment_reference||'.voting'] = $voting;
var['seller.'||$seller||'.comment.'||$comment_reference||'.auction'] = $reference;
response['message'] = 'Thank you for confirming that you have received the goods! We payed the seller!';
}"
}
]
}
]
}
},
{
"if": "{trigger.data.no_goods_receipt}",
"init": "{
$reference = trigger.data.reference otherwise bounce ("reference is missing");
$comment = trigger.data.comment otherwise bounce ("comment is missing");
$voting = trigger.data.voting otherwise bounce ("voting between 1 and 5 is missing"); //1-5
$auction_status = var['auction.'||trigger.data.reference||'.auction_status'];
$buyer = var['auction.'||trigger.data.reference||'.buyer'];
$seller = var['auction.'||trigger.data.reference||'.seller'];
$comment_reference = sha256($reference || $seller || timestamp);
}",
"messages": {
"cases": [
{
"if": "{ trigger.address == $buyer AND $auction_status == 'buyer_data_confirm'}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{$buyer}",
"amount": "{$REIMBURSEMENT}"
}
]
}
},
{
"app": "state",
"state": "{
var['auction.'||$reference||'.auction_status'] = 'no_goods_receipt';
var['seller.'||$seller||'.comment.'||$comment_reference||'.comment'] = $comment;
var['seller.'||$seller||'.comment.'||$comment_reference||'.voting'] = $voting;
var['seller.'||$seller||'.comment.'||$comment_reference||'.auction'] = $reference;
response['message'] = 'Thank you for letting us know. We still hold your money as an decentralized escrow and will inform an arbiter to look into the case. After he did that you will receive your money back if the seller can´t prove that he has sent it to you.';
}"
}
]
}
]
}
},
{
"init": "{
bounce("Enter buyer, seller or one of the other options");
}",
"messages": [
{
"app": "state",
"state": "{
response['usage'] = 'Enter buyer, seller or one of the other options';
}"
}
]
}
]
}
}
]