-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* validators' boilerplate. * redeemer and datum types. * updated design with new names * corrected minting policy
- Loading branch information
1 parent
bcd5fe2
commit d727845
Showing
9 changed files
with
104 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file renamed
BIN
+785 KB
onchain/docs/mvp-design/img/collect.png → onchain/docs/mvp-design/img/mineAsteria.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use aiken/transaction/value.{AssetName, PolicyId} | ||
|
||
pub type ShipDatum { | ||
fuel: Int, | ||
pos_x: Int, | ||
pos_y: Int, | ||
shipyard_policy: PolicyId, | ||
ship_token_name: AssetName, | ||
pilot_token_name: AssetName, | ||
} | ||
|
||
pub type ShipRedeemer { | ||
MoveShip { delta_x: Int, delta_y: Int } | ||
GatherFuel { amount: Int } | ||
MineAsteria | ||
Quit | ||
} | ||
|
||
pub type PelletDatum { | ||
fuel: Int, | ||
pos_x: Int, | ||
pos_y: Int, | ||
shipyard_policy: PolicyId, | ||
} | ||
|
||
pub type PelletRedeemer { | ||
Provide { amount: Int } | ||
} | ||
|
||
pub type AsteriaDatum { | ||
ship_counter: Int, | ||
shipyard_policy: PolicyId, | ||
} | ||
|
||
pub type AsteriaRedeemer { | ||
AddNewShip | ||
Mine | ||
} | ||
|
||
pub type ShipyardRedeemer { | ||
Mint | ||
Burn | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use aiken/transaction.{ScriptContext} | ||
use aiken/transaction/value.{AssetName, PolicyId} | ||
use asteria/types.{AsteriaDatum, AsteriaRedeemer} | ||
|
||
validator(_admin_token: (PolicyId, AssetName)) { | ||
fn spend( | ||
_datum: AsteriaDatum, | ||
_redeemer: AsteriaRedeemer, | ||
_ctx: ScriptContext, | ||
) -> Bool { | ||
True | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use aiken/transaction.{ScriptContext} | ||
use aiken/transaction/value.{AssetName, PolicyId} | ||
use asteria/types.{PelletDatum, PelletRedeemer} | ||
|
||
validator(_admin_token: (PolicyId, AssetName)) { | ||
fn spend( | ||
_datum: PelletDatum, | ||
_redeemer: PelletRedeemer, | ||
_ctx: ScriptContext, | ||
) -> Bool { | ||
True | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use aiken/transaction.{ScriptContext} | ||
use aiken/transaction/credential.{Address} | ||
use asteria/types.{ShipyardRedeemer} | ||
|
||
validator( | ||
_asteria_validator_address: Address, | ||
_spacetime_validator_address: Address, | ||
) { | ||
fn mint(_redeemer: ShipyardRedeemer, _ctx: ScriptContext) -> Bool { | ||
True | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,18 @@ | ||
use aiken/list | ||
use aiken/math | ||
use aiken/transaction.{InlineDatum, ScriptContext, Spend, Transaction} | ||
use aiken/transaction/value.{PolicyId, quantity_of} | ||
|
||
type Datum { | ||
pilot_token: ByteArray, | ||
pos_x: Int, | ||
pos_y: Int, | ||
fuel: Int, | ||
} | ||
|
||
type MoveRedeemer { | ||
delta_x: Int, | ||
delta_y: Int, | ||
} | ||
|
||
type GatherRedeemer {GatherRedeemer} | ||
|
||
type PotRedeemer {PotRedeemer} | ||
|
||
fn required_fuel(distance: Int, fuel_per_step: Int) -> Int { | ||
distance * fuel_per_step | ||
} | ||
|
||
fn distance(delta_x: Int, delta_y: Int) -> Int { | ||
math.abs(delta_x) + math.abs(delta_y) | ||
} | ||
|
||
// we need to enforce: | ||
// [x] that the speed (manhattan_distance/slot) doesn't exceed an upper bound | ||
// [ ] that the ship has enough fuel (token) to move the desired delta | ||
// [ ] that the new position of the ship utxo equals the last position + delta | ||
// [ ] that the fuel required for the delta has been burned | ||
// [ ] that the tx is signed by the owner of the ship (token holder) | ||
|
||
validator(ship_policy_id: PolicyId, max_speed: Int, fuel_per_step: Int) { | ||
fn spend(datum: Datum, redeemer: Redeemer, ctx: ScriptContext) -> Bool { | ||
let Redeemer { delta_x, delta_y } = redeemer | ||
|
||
let Datum { ship_id, pos_x, pos_y, fuel } = datum | ||
|
||
let ScriptContext { transaction, purpose } = ctx | ||
|
||
let Transaction { inputs, outputs, .. } = transaction | ||
|
||
expect Spend(utxo_ref) = purpose | ||
|
||
expect Some(own_input) = | ||
list.find(inputs, fn(input) { input.output_reference == utxo_ref }) | ||
|
||
expect Some(own_output) = | ||
list.find( | ||
outputs, | ||
fn(output) { quantity_of(output.value, ship_policy_id, ship_id) == 1 }, | ||
) | ||
|
||
let must_hold_ship_asset = | ||
quantity_of(own_input.output.value, ship_policy_id, ship_id) == 1 | ||
|
||
let distance = distance(delta_x, delta_y) | ||
let required_fuel = required_fuel(distance, fuel_per_step) | ||
|
||
// speed = distance since we consider each block the unit of time | ||
let must_respect_max_speed = distance <= max_speed | ||
|
||
let must_have_enough_fuel = fuel >= required_fuel | ||
|
||
expect InlineDatum(out_data) = own_output.datum | ||
|
||
expect out_data: Datum = out_data | ||
|
||
let final_pos_must_respect_movement = | ||
out_data.pos_x == pos_x + delta_x && out_data.pos_y == pos_y + delta_y | ||
|
||
let final_ship_id_must_match = out_data.ship_id == ship_id | ||
|
||
and { | ||
must_hold_ship_asset, | ||
must_respect_max_speed, | ||
must_have_enough_fuel, | ||
final_pos_must_respect_movement, | ||
final_ship_id_must_match, | ||
} | ||
use aiken/transaction.{ScriptContext} | ||
use aiken/transaction/credential.{Address} | ||
use aiken/transaction/value.{AssetName, PolicyId} | ||
use asteria/types.{ShipDatum, ShipRedeemer} | ||
|
||
validator( | ||
_pellet_validator_address: Address, | ||
_asteria_validator_address: Address, | ||
_admin_token: (PolicyId, AssetName), | ||
) { | ||
fn spend( | ||
_datum: ShipDatum, | ||
_redeemer: ShipRedeemer, | ||
_ctx: ScriptContext, | ||
) -> Bool { | ||
True | ||
} | ||
} |