Skip to content

Commit

Permalink
added constants file.
Browse files Browse the repository at this point in the history
Co-authored-by: Sofia Bobbiesi <sofia-bobbiesi@users.noreply.github.com>
  • Loading branch information
franciscojoray and sofia-bobbiesi committed Apr 23, 2024
1 parent 7ab8c2a commit 591d3d9
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 71 deletions.
25 changes: 25 additions & 0 deletions offchain/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { fromText } from "https://deno.land/x/lucid@0.10.7/mod.ts";
import { AssetClassT } from "./types.ts";

const admin_token: AssetClassT = {
policy: "f8ab3db3bc88f892d843e6d82ae78cee28c4eb073a6774390b880c7d",
name: fromText("admin"),
};
const ship_mint_lovelace_fee = 3_000_000n;
const max_asteria_mining = 50n;
const max_moving_distance = 20n;
const max_ship_fuel = 100n;
const fuel_per_step = 1n;
const initial_fuel = 30n;
const min_asteria_distance = 10n;

export {
admin_token,
ship_mint_lovelace_fee,
max_asteria_mining,
max_moving_distance,
max_ship_fuel,
fuel_per_step,
initial_fuel,
min_asteria_distance,
};
8 changes: 1 addition & 7 deletions offchain/tests/create-asteria.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { fromText } from "https://deno.land/x/lucid@0.10.7/mod.ts";
import { admin_token } from "../constants.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);

Expand Down
8 changes: 1 addition & 7 deletions offchain/tests/create-pellet.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import { fromText } from "https://deno.land/x/lucid@0.10.7/mod.ts";
import { AssetClassT } from "../types.ts";
import { admin_token } from "../constants.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);
13 changes: 5 additions & 8 deletions offchain/tests/create-ship.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { fromText } from "https://deno.land/x/lucid@0.10.7/mod.ts";
import { AssetClassT } from "../types.ts";
import {
admin_token,
initial_fuel,
ship_mint_lovelace_fee,
} from "../constants.ts";
import { createShip } from "../transactions/create-ship.ts";

const admin_token: AssetClassT = {
policy: "0298aa99f95e2fe0a0132a6bb794261fb7e7b0d988215da2f2de2005",
name: fromText("tokenA"),
};
const ship_mint_lovelace_fee = 3_000_000n;
const initial_fuel = 30n;
const pos_x = 7n;
const pos_y = -10n;
const asteria_tx_hash =
Expand Down
14 changes: 5 additions & 9 deletions offchain/tests/deploy/deploy-asteria.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { fromText } from "https://deno.land/x/lucid@0.10.7/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 = 3_000_000n;
const max_asteria_mining = 50n;
import {
admin_token,
max_asteria_mining,
ship_mint_lovelace_fee,
} from "../../constants.ts";

const txHash = await deployAsteria(
admin_token,
Expand Down
8 changes: 1 addition & 7 deletions offchain/tests/deploy/deploy-pellet.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { fromText } from "https://deno.land/x/lucid@0.10.7/mod.ts";
import { deployPellet } from "../../transactions/deploy/deploy-pellet.ts";
import { AssetClassT } from "../../types.ts";

const admin_token: AssetClassT = {
policy: "0298aa99f95e2fe0a0132a6bb794261fb7e7b0d988215da2f2de2005",
name: fromText("tokenA"),
};
import { admin_token } from "../../constants.ts";

const txHash = await deployPellet(admin_token);

Expand Down
20 changes: 8 additions & 12 deletions offchain/tests/deploy/deploy-spacetime.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { fromText } from "https://deno.land/x/lucid@0.10.7/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 = 30n;
const min_asteria_distance = 10n;
import {
admin_token,
max_moving_distance,
max_ship_fuel,
fuel_per_step,
initial_fuel,
min_asteria_distance,
} from "../../constants.ts";

const txHash = await deploySpacetime(
admin_token,
Expand Down
9 changes: 2 additions & 7 deletions offchain/tests/deploy/spend-refs.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { fromText } from "https://deno.land/x/lucid@0.10.7/mod.ts";
import { spendRefUTxOs } from "../../transactions/deploy/spend-refs.ts";
import { AssetClassT } from "../../types.ts";

const admin_token: AssetClassT = {
policy: "0298aa99f95e2fe0a0132a6bb794261fb7e7b0d988215da2f2de2005",
name: fromText("tokenA"),
};
import { admin_token } from "../../constants.ts";

const txHash = await spendRefUTxOs(admin_token);

console.log(txHash);
7 changes: 1 addition & 6 deletions offchain/tests/gather-fuel.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { fromText } from "https://deno.land/x/lucid@0.10.7/mod.ts";
import { AssetClassT } from "../types.ts";
import { admin_token } from "../constants.ts";
import { gatherFuel } from "../transactions/gather-fuel.ts";

const admin_token: AssetClassT = {
policy: "0298aa99f95e2fe0a0132a6bb794261fb7e7b0d988215da2f2de2005",
name: fromText("tokenA"),
};
const gather_amount = 20n;
const ship_tx_hash =
"6ca378639a51b1283ec2c84deb772f62bff59603eca230aeb711fedee8389d69";
Expand Down
7 changes: 1 addition & 6 deletions offchain/tests/mine-asteria.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { fromText } from "https://deno.land/x/lucid@0.10.7/mod.ts";
import { AssetClassT } from "../types.ts";
import { admin_token } from "../constants.ts";
import { mineAsteria } from "../transactions/mine-asteria.ts";

const admin_token: AssetClassT = {
policy: "0298aa99f95e2fe0a0132a6bb794261fb7e7b0d988215da2f2de2005",
name: fromText("tokenA"),
};
const ship_tx_hash =
"40930f706ba2bb29be56326a3171ffa17e2d7f4e1d9cdeac347e05f3559efcd8";
const asteria_tx_hash =
Expand Down
2 changes: 1 addition & 1 deletion offchain/tests/move-ship.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fuel_per_step } from "../constants.ts";
import { moveShip } from "../transactions/move-ship.ts";

const fuel_per_step = 1n;
const delta_x = -7n;
const delta_y = 10n;
const ship_tx_hash =
Expand Down
46 changes: 46 additions & 0 deletions offchain/transactions/mint-admin-token.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { lucidBase } from "../utils.ts";
import {
toUnit,
fromText,
Assets,
} from "https://deno.land/x/lucid@0.10.7/mod.ts";

const lucid = await lucidBase();
const seed = Deno.env.get("SEED");
if (!seed) {
throw Error("Unable to read wallet's seed from env");
}
lucid.selectWalletFromSeed(seed);
const address = await lucid.wallet.address();

const { paymentCredential } = lucid.utils.getAddressDetails(address);

const beforeSlot = lucid.currentSlot() + 60;
const mintingPolicy = lucid.utils.nativeScriptFromJson({
type: "all",
scripts: [
{ type: "sig", keyHash: paymentCredential?.hash },
{
type: "before",
slot: beforeSlot,
},
],
});

const policyId = lucid.utils.mintingPolicyToId(mintingPolicy);

const policyUnit = toUnit(policyId, fromText("admin"));
const policyAsset: Assets = { [policyUnit]: 10000n };

const tx = await lucid
.newTx()
.mintAssets(policyAsset)
.attachMintingPolicy(mintingPolicy)
.payToAddress(address, policyAsset)
.validTo(lucid.utils.slotToUnixTime(beforeSlot))
.complete();

const signedTx = await lucid.fromTx(tx.toString()).sign().complete();
const txid = await signedTx.submit();
const cExplorerTxURL = "https://preview.cexplorer.io/tx/";
console.log(`${cExplorerTxURL}${txid}`);
2 changes: 1 addition & 1 deletion offchain/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Lucid, Blockfrost } from "https://deno.land/x/lucid@0.10.7/mod.ts";
const lucidBase = async (): Promise<Lucid> => {
const lucid = await Lucid.new(
new Blockfrost(
"https://cardano-preprod.blockfrost.io/api/v0",
"https://cardano-preview.blockfrost.io/api/v0",
Deno.env.get("BLOCKFROST_PROJECT_ID")
),
"Preprod"
Expand Down

0 comments on commit 591d3d9

Please sign in to comment.