Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,21 @@ First you need to install the Node dependencies:
npm install
```

### Provide the required env vars

You need to create a `.env` file with your wallet info:

```env
PLAYER_PRIVATE_KEY="1234"
PLAYER_ADDRESS="addr..."
```

### Create Ship Tx

This is the first step in order to play the game.



```bash
npm run create-ship
```
Expand Down
261 changes: 261 additions & 0 deletions experiments/params.tx3
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
party Admin;
party Player;

env {
spacetime_policy_hash: Bytes,
spacetime_policy_ref: UtxoRef,

asteria_policy_hash: Bytes,
asteria_policy_ref: UtxoRef,

pellet_policy_hash: Bytes,
pellet_policy_ref: UtxoRef,

admin_token_policy_hash: Bytes,
admin_token_name: Bytes,

initial_fuel: Int,
ship_mint_lovelace_fee: Int,
}

type AssetRecord {
policy_id: Bytes,
asset_name: Bytes,
}

type MaxSpeedRecord {
distance: Int,
time: Int,
}

type ShipDatum {
pos_x: Int,
pos_y: Int,
ship_token_name: Bytes,
pilot_token_name: Bytes,
last_move_latest_time: Int,
}

type AsteriaDatum {
ship_counter: Int,
shipyard_policy: Bytes,
}

type PelletDatum {
pos_x: Int,
pos_y: Int,
shipyard_policy: Bytes,
}

type ShipActions {
MoveShip {
delta_x: Int,
delta_y: Int,
},
GatherFuel {
gather_amount: Int,
},
}

tx create_ship(
p_pos_x: Int, // Ship Position X
p_pos_y: Int, // Ship Position Y
ship_name: Bytes, // Name of the ship
pilot_name: Bytes, // Name of the pilot
tip_slot: Int, // TODO: remove when tip_slot() implemented
last_move_timestamp: Int,
) {
validity {
until_slot: tip_slot, // tip_slot() + 300
}

reference SpacetimeRef {
ref: spacetime_policy_ref,
}

reference AsteriaRef {
ref: asteria_policy_ref,
}

reference PelletRef {
ref: pellet_policy_ref,
}

input source {
from: Player,
min_amount: fees + Ada(ship_mint_lovelace_fee)+ min_utxo(ship),
}

input asteria {
from: asteria_policy_hash,
min_amount: AnyAsset(admin_token_policy_hash, admin_token_name, 1),
datum_is: AsteriaDatum,
redeemer: (),
}

mint {
amount: AnyAsset(spacetime_policy_hash, pilot_name, 1) + AnyAsset(spacetime_policy_hash, ship_name, 1),
redeemer: (),
}

mint {
amount: AnyAsset(pellet_policy_hash, "FUEL", initial_fuel),
redeemer: (),
}

output {
to: Player,
amount: source - fees - Ada(ship_mint_lovelace_fee) + AnyAsset(spacetime_policy_hash, pilot_name, 1) - min_utxo(ship),
}

output {
to: asteria_policy_hash,
amount: asteria + Ada(ship_mint_lovelace_fee),
datum: AsteriaDatum {
ship_counter: asteria.ship_counter + 1,
shipyard_policy: asteria.shipyard_policy,
},
}

output ship {
to: spacetime_policy_hash,
amount: AnyAsset(spacetime_policy_hash, ship_name, 1) + AnyAsset(pellet_policy_hash, "FUEL", initial_fuel) + min_utxo(ship),
datum: ShipDatum {
pos_x: p_pos_x,
pos_y: p_pos_y,
ship_token_name: ship_name,
pilot_token_name: pilot_name,
last_move_latest_time: last_move_timestamp,
},
}

collateral {
from: Player,
min_amount: fees,
}
}

tx move_ship(
p_delta_x: Int,
p_delta_y: Int,
ship_name: Bytes,
pilot_name: Bytes,
required_fuel: Int,
tip_slot: Int, // TODO: remove when tip_slot() implemented
last_move_timestamp: Int,
) {
validity {
until_slot: tip_slot, // tip_slot() + 300
}

reference SpacetimeRef {
ref: spacetime_policy_ref,
}

reference PelletRef {
ref: pellet_policy_ref,
}

input source {
from: Player,
min_amount: fees,
}

input ship {
from: spacetime_policy_hash,
datum_is: ShipDatum,
min_amount: AnyAsset(spacetime_policy_hash, ship_name, 1),
redeemer: ShipActions::MoveShip {
delta_x: p_delta_x,
delta_y: p_delta_y,
},
}

input pilot {
from: Player,
min_amount: AnyAsset(spacetime_policy_hash, pilot_name, 1),
}

burn {
amount: AnyAsset(pellet_policy_hash, "FUEL", required_fuel),
redeemer: (),
}

output {
to: spacetime_policy_hash,
amount: ship - AnyAsset(pellet_policy_hash, "FUEL", required_fuel),
datum: ShipDatum {
pos_x: ship.pos_x + p_delta_x,
pos_y: ship.pos_y + p_delta_y,
last_move_latest_time: last_move_timestamp,
...ship
},
}

output {
to: Player,
amount: source - fees + pilot,
}
}

tx gather_fuel (
p_gather_amount: Int,
ship_name: Bytes,
tip_slot: Int, // TODO: remove when tip_slot() implemented
) {
validity {
since_slot: tip_slot, // tip_slot() + 300
}

reference SpacetimeRef {
ref: spacetime_policy_ref,
}

reference PelletRef {
ref: pellet_policy_ref,
}

input source {
from: Player,
min_amount: fees,
}

input ship {
from: spacetime_policy_hash,
datum_is: ShipDatum,
min_amount: AnyAsset(spacetime_policy_hash, ship_name, 1),
redeemer: ShipActions::GatherFuel {
gather_amount: p_gather_amount,
},
}

input pellet {
from: pellet_policy_hash,
datum_is: PelletDatum,
min_amount: AnyAsset(pellet_policy_hash, "FUEL", p_gather_amount),
redeemer: ShipActions::GatherFuel {
gather_amount: p_gather_amount,
},
}

output {
to: Player,
amount: source - fees,
}

output {
to: spacetime_policy_hash,
amount: ship + AnyAsset(pellet_policy_hash, "FUEL", p_gather_amount),
datum: ShipDatum {...ship},
}

output {
to: pellet_policy_hash,
amount: pellet - AnyAsset(pellet_policy_hash, "FUEL", p_gather_amount),
datum: PelletDatum {
pos_x: pellet.pos_x,
pos_y: pellet.pos_y,
shipyard_policy: spacetime_policy_hash,
},
}
}
Loading