-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
20 implement lucid offchain tx building for grid creation 1 (#42)
* script for creating Asteria. * script for creating pellet. * create ship: minting tokens. Co-authored-by: Sofia Bobbiesi <[email protected]> * Using reference scripts. Co-authored-by: Sofia Bobbiesi <[email protected]> * script for ship movement. * separated minAda from Asteria rewards. * Joined spacetime validator & shipyard policy as multivalidator. Co-authored-by: Sofia Bobbiesi <[email protected]> * deploy validator checking admin token. * script for spending deployed script UTxOs. * fixed minAda. * moving ship by txHash. --------- Co-authored-by: Sofia Bobbiesi <[email protected]>
- Loading branch information
1 parent
48ccb0a
commit 1291e39
Showing
37 changed files
with
1,369 additions
and
363 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"txHash":"48eefd160b9114e80dea85404446947e5e15d19e96914ce1182b05ee7a36fd98"} |
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 @@ | ||
{"txHash":"eb2f88f353163aeb0abcafa040b6e6d8f64ea39c5064134061b44fd3bedb23a9"} |
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,44 @@ | ||
import { | ||
Data, | ||
SpendingValidator, | ||
applyParamsToScript, | ||
} from "https://deno.land/x/[email protected]/mod.ts"; | ||
import plutusBlueprint from "../../onchain/src/plutus.json" with { type: "json" }; | ||
import { AssetClass, AssetClassT } from "../types.ts"; | ||
|
||
const asteriaValidator = plutusBlueprint.validators.find( | ||
({ title }) => title === "asteria.spend" | ||
); | ||
|
||
if (!asteriaValidator) { | ||
throw new Error("Asteria validator indexed with 'asteria.spend' failed!"); | ||
} | ||
|
||
const ASTERIA_SCRIPT: SpendingValidator["script"] = | ||
asteriaValidator.compiledCode; | ||
|
||
const ValidatorParam = Data.Tuple([ | ||
AssetClass, | ||
Data.Integer({ minimum: 0 }), | ||
Data.Integer({ minimum: 0, maximum: 100 }), | ||
]); | ||
type ValidatorParamT = Data.Static<typeof ValidatorParam>; | ||
|
||
function buildAsteriaValidator( | ||
admin_token: AssetClassT, | ||
ship_mint_lovelace_fee: bigint, | ||
max_asteria_mining: bigint | ||
): SpendingValidator { | ||
const appliedValidator = applyParamsToScript<ValidatorParamT>( | ||
ASTERIA_SCRIPT, | ||
[admin_token, ship_mint_lovelace_fee, max_asteria_mining], | ||
ValidatorParam as unknown as ValidatorParamT | ||
); | ||
|
||
return { | ||
type: "PlutusV2", | ||
script: appliedValidator, | ||
}; | ||
} | ||
|
||
export { buildAsteriaValidator }; |
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,37 @@ | ||
import { | ||
Data, | ||
SpendingValidator, | ||
applyParamsToScript, | ||
} from "https://deno.land/x/[email protected]/mod.ts"; | ||
import plutusBlueprint from "../../onchain/src/plutus.json" with { type: "json" }; | ||
import { AssetClass, AssetClassT } from "../types.ts"; | ||
|
||
const deployValidator = plutusBlueprint.validators.find( | ||
({ title }) => title === "deploy.spend" | ||
); | ||
|
||
if (!deployValidator) { | ||
throw new Error("Deploy validator indexed with 'deploy.spend' failed!"); | ||
} | ||
|
||
const DEPLOY_SCRIPT: SpendingValidator["script"] = | ||
deployValidator.compiledCode; | ||
|
||
|
||
const ValidatorParam = Data.Tuple([AssetClass]); | ||
type ValidatorParamT = Data.Static<typeof ValidatorParam>; | ||
|
||
function buildDeployValidator(admin_token: AssetClassT): SpendingValidator { | ||
const appliedValidator = applyParamsToScript<ValidatorParamT>( | ||
DEPLOY_SCRIPT, | ||
[admin_token], | ||
ValidatorParam as unknown as ValidatorParamT | ||
); | ||
|
||
return { | ||
type: "PlutusV2", | ||
script: appliedValidator, | ||
}; | ||
} | ||
|
||
export { buildDeployValidator }; |
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,35 @@ | ||
import { | ||
Data, | ||
SpendingValidator, | ||
applyParamsToScript, | ||
} from "https://deno.land/x/[email protected]/mod.ts"; | ||
import plutusBlueprint from "../../onchain/src/plutus.json" with { type: "json" }; | ||
import { AssetClass, AssetClassT } from "../types.ts"; | ||
|
||
const pelletValidator = plutusBlueprint.validators.find( | ||
({ title }) => title === "pellet.spend" | ||
); | ||
|
||
if (!pelletValidator) { | ||
throw new Error("Pellet validator indexed with 'pellet.spend' failed!"); | ||
} | ||
|
||
const PELLET_SCRIPT: SpendingValidator["script"] = pelletValidator.compiledCode; | ||
|
||
const ValidatorParam = Data.Tuple([AssetClass]); | ||
type ValidatorParamT = Data.Static<typeof ValidatorParam>; | ||
|
||
function buildPelletValidator(admin_token: AssetClassT): SpendingValidator { | ||
const appliedValidator = applyParamsToScript<ValidatorParamT>( | ||
PELLET_SCRIPT, | ||
[admin_token], | ||
ValidatorParam as unknown as ValidatorParamT | ||
); | ||
|
||
return { | ||
type: "PlutusV2", | ||
script: appliedValidator, | ||
}; | ||
} | ||
|
||
export { buildPelletValidator }; |
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,59 @@ | ||
import { Address, Data, SpendingValidator, applyParamsToScript } from "https://deno.land/x/[email protected]/mod.ts"; | ||
import plutusBlueprint from "../../onchain/src/plutus.json" with { type: "json" }; | ||
import { AssetClass, AssetClassT } from "../types.ts"; | ||
|
||
const spacetimeValidator = plutusBlueprint.validators.find( | ||
({ title }) => title === "spacetime.spend" | ||
); | ||
|
||
if (!spacetimeValidator) { | ||
throw new Error("Spacetime validator indexed with 'spacetime.spend' failed!"); | ||
} | ||
|
||
const SPACETIME_SCRIPT: SpendingValidator["script"] = | ||
spacetimeValidator.compiledCode; | ||
|
||
const ValidatorParam = Data.Tuple([ | ||
Data.Bytes(), | ||
Data.Bytes(), | ||
AssetClass, | ||
Data.Integer({ minimum: 0 }), | ||
Data.Integer({ minimum: 0 }), | ||
Data.Integer({ minimum: 0 }), | ||
Data.Integer({ minimum: 0 }), | ||
Data.Integer({ minimum: 0 }), | ||
]); | ||
type ValidatorParamT = Data.Static<typeof ValidatorParam>; | ||
|
||
function buildSpacetimeValidator( | ||
pellet_validator_address: Address, | ||
asteria_validator_address: Address, | ||
admin_token: AssetClassT, | ||
max_moving_distance: bigint, | ||
max_ship_fuel: bigint, | ||
fuel_per_step: bigint, | ||
initial_fuel: bigint, | ||
min_asteria_distance: bigint, | ||
): SpendingValidator { | ||
const appliedValidator = applyParamsToScript<ValidatorParamT>( | ||
SPACETIME_SCRIPT, | ||
[ | ||
pellet_validator_address, | ||
asteria_validator_address, | ||
admin_token, | ||
max_moving_distance, | ||
max_ship_fuel, | ||
fuel_per_step, | ||
initial_fuel, | ||
min_asteria_distance | ||
], | ||
ValidatorParam as unknown as ValidatorParamT | ||
); | ||
|
||
return { | ||
type: "PlutusV2", | ||
script: appliedValidator, | ||
}; | ||
} | ||
|
||
export { buildSpacetimeValidator }; |
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 @@ | ||
{"txHash":"1af0fb23fb9b1a16e31c7f46bbf6f2464fc4f1795773cd8a9425133ba46c8540"} |
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 @@ | ||
import { fromText } from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { createAsteria } from "../transactions/create-asteria.ts"; | ||
import { AssetClassT } from "../types.ts"; | ||
|
||
const admin_token: AssetClassT = { | ||
policy: "0298aa99f95e2fe0a0132a6bb794261fb7e7b0d988215da2f2de2005", | ||
name: fromText("tokenA"), | ||
}; | ||
|
||
const txHash = await createAsteria(admin_token); | ||
|
||
console.log(txHash); |
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,15 @@ | ||
import { fromText } from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { AssetClassT } from "../types.ts"; | ||
import { createPellet } from "../transactions/create-pellet.ts"; | ||
|
||
const admin_token: AssetClassT = { | ||
policy: "0298aa99f95e2fe0a0132a6bb794261fb7e7b0d988215da2f2de2005", | ||
name: fromText("tokenA"), | ||
}; | ||
const fuel = 40n; | ||
const pos_x = 7n; | ||
const pos_y = -10n; | ||
|
||
const txHash = await createPellet(admin_token, fuel, pos_x, pos_y); | ||
|
||
console.log(txHash); |
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,22 @@ | ||
import { fromText } from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { AssetClassT } from "../types.ts"; | ||
import { createShip } from "../transactions/create-ship.ts"; | ||
|
||
const admin_token: AssetClassT = { | ||
policy: "0298aa99f95e2fe0a0132a6bb794261fb7e7b0d988215da2f2de2005", | ||
name: fromText("tokenA"), | ||
}; | ||
const ship_mint_lovelace_fee = 3000n; | ||
const initial_fuel = 15n; | ||
const pos_x = 20n; | ||
const pos_y = -13n; | ||
|
||
const txHash = await createShip( | ||
admin_token, | ||
ship_mint_lovelace_fee, | ||
initial_fuel, | ||
pos_x, | ||
pos_y | ||
); | ||
|
||
console.log(txHash); |
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,18 @@ | ||
import { fromText } from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { deployAsteria } from "../../transactions/deploy/deploy-asteria.ts"; | ||
import { AssetClassT } from "../../types.ts"; | ||
|
||
const admin_token: AssetClassT = { | ||
policy: "0298aa99f95e2fe0a0132a6bb794261fb7e7b0d988215da2f2de2005", | ||
name: fromText("tokenA"), | ||
}; | ||
const ship_mint_lovelace_fee = 3000n; | ||
const max_asteria_mining = 50n; | ||
|
||
const txHash = await deployAsteria( | ||
admin_token, | ||
ship_mint_lovelace_fee, | ||
max_asteria_mining | ||
); | ||
|
||
console.log(txHash); |
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 @@ | ||
import { fromText } from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { deployPellet } from "../../transactions/deploy/deploy-pellet.ts"; | ||
import { AssetClassT } from "../../types.ts"; | ||
|
||
const admin_token: AssetClassT = { | ||
policy: "0298aa99f95e2fe0a0132a6bb794261fb7e7b0d988215da2f2de2005", | ||
name: fromText("tokenA"), | ||
}; | ||
|
||
const txHash = await deployPellet(admin_token); | ||
|
||
console.log(txHash); |
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,24 @@ | ||
import { fromText } from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { deploySpacetime } from "../../transactions/deploy/deploy-spacetime.ts"; | ||
import { AssetClassT } from "../../types.ts"; | ||
|
||
const admin_token: AssetClassT = { | ||
policy: "0298aa99f95e2fe0a0132a6bb794261fb7e7b0d988215da2f2de2005", | ||
name: fromText("tokenA"), | ||
}; | ||
const max_moving_distance = 20n; | ||
const max_ship_fuel = 100n; | ||
const fuel_per_step = 1n; | ||
const initial_fuel = 15n; | ||
const min_asteria_distance = 10n; | ||
|
||
const txHash = await deploySpacetime( | ||
admin_token, | ||
max_moving_distance, | ||
max_ship_fuel, | ||
fuel_per_step, | ||
initial_fuel, | ||
min_asteria_distance | ||
); | ||
|
||
console.log(txHash); |
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,11 @@ | ||
import { fromText } from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { spendRefUTxOs } from "../../transactions/deploy/spend-refs.ts"; | ||
import { AssetClassT } from "../../types.ts"; | ||
|
||
const admin_token: AssetClassT = { | ||
policy: "0298aa99f95e2fe0a0132a6bb794261fb7e7b0d988215da2f2de2005", | ||
name: fromText("tokenA"), | ||
}; | ||
|
||
const txHash = await spendRefUTxOs(admin_token); | ||
console.log(txHash); |
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,21 @@ | ||
import { fromText } from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { moveShip } from "../transactions/move-ship.ts"; | ||
|
||
const fuel_per_step = 1n; | ||
const delta_x = 2n; | ||
const delta_y = -3n; | ||
const ship_token_name = fromText("SHIP0"); | ||
const pilot_token_name = fromText("PILOT0"); | ||
const shipTxHash = | ||
"ca30a841e582f284b7b71d39c2cbc8b9a7fca9476d921b6b9d97c0c7e31bf2bc"; | ||
|
||
const txHash = await moveShip( | ||
fuel_per_step, | ||
delta_x, | ||
delta_y, | ||
ship_token_name, | ||
pilot_token_name, | ||
shipTxHash | ||
); | ||
|
||
console.log(txHash); |
Oops, something went wrong.