request_funds(1){
  find_account{
    currency = {"symbol":"STX", "decimals":6};
    random_account = find_balance({
      "minimum_balance":{
        "value": "0",
        "currency": {{currency}}
      },
      "create_limit":1
    });
  },

  // Create a separate scenario to request funds so that
  // the address we are using to request funds does not
  // get rolled back if funds do not yet exist.
  request{
    loaded_account = find_balance({
      "account_identifier": {{random_account.account_identifier}},
      "minimum_balance":{
        "value": "1000000000",
        "currency": {{currency}}
      }
    });
  }
}

create_account(1){
  create{
    network = {"network":"testnet", "blockchain":"stacks"};
    key = generate_key({"curve_type": "secp256k1"});
    account = derive({
      "network_identifier": {{network}},
      "public_key": {{key.public_key}}
    });
    // If the account is not saved, the key will be lost!
    save_account({
      "account_identifier": {{account.account_identifier}},
      "keypair": {{key}}
    });
       print_message({"--- created": {{key}}});
  }
}

transfer(10){
  transfer{
    transfer.network = {"network":"testnet", "blockchain":"stacks"};

    currency = {"symbol":"STX", "decimals":6};
    sender = find_balance({
      "minimum_balance":{
        "value": "1000000000",
        "currency": {{currency}}
      }
    });

    // Set the recipient_amount as some value <= sender.balance-max_fee
    max_fee = "1000";
    available_amount = "10000";
    recipient_amount = random_number({"minimum": "1", "maximum": {{available_amount}}});
    print_message({"recipient_amount":{{recipient_amount}}});

    // Find recipient and construct operations
    sender_amount = 0 - {{recipient_amount}};
    recipient = find_balance({
      "not_account_identifier":[{{sender.account_identifier}}],
      "minimum_balance":{
        "value": "0",
        "currency": {{currency}}
      },
      "create_limit": 100,
      "create_probability": 50
    });
    print_message({"---- SENDING FROM": {{sender}}});
    print_message({"---- SENDING TO": {{recipient}}});
    transfer.confirmation_depth = "1";
    transfer.operations = [
         {
        "operation_identifier":{"index":0},
        "type":"fee",
        "account":{{sender.account_identifier}},
        "amount":{
          "value":"-180",
          "currency":{{currency}}
        }
      },
      {
        "operation_identifier":{"index":1},
        "type":"token_transfer",
        "account":{{sender.account_identifier}},
        "amount":{
          "value":{{sender_amount}},
          "currency":{{currency}}
        }
      },
      {
        "operation_identifier":{"index":2},
        "type":"token_transfer",
        "account":{{recipient.account_identifier}},
        "amount":{
          "value":{{recipient_amount}},
          "currency":{{currency}}
        }
      }
    ];
    transfer.public_keys = [
        {
            "hex_bytes" : {{sender}},
            "curve_type" : "secp256k1"
        }
    ];
  }
}