Skip to content

Commit

Permalink
CHORES | make Types (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
ljttl3q04t authored Jun 4, 2024
1 parent 5e7bd70 commit 6d58f97
Show file tree
Hide file tree
Showing 13 changed files with 303 additions and 254 deletions.
32 changes: 16 additions & 16 deletions plutus.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions plutus.ts

Large diffs are not rendered by default.

193 changes: 92 additions & 101 deletions src/build-tx.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ export const TREASURY_MIN_ADA = 3_000_000n;
export const MANAGER_MIN_ADA = 2_000_000n;
export const SELLER_MIN_ADA = 2_000_000n;
export const MAX_PENALTY_RATE = 25n;
export const ORDER_MIN_ADA = 5_000_000n;
12 changes: 4 additions & 8 deletions src/tests/close-event.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import type {
FactoryValidateFactory,
TreasuryValidateTreasurySpending,
} from "../../plutus";
import { WarehouseBuilder, type BuildCloseEventOptions } from "../build-tx";
import {
LBE_INIT_FACTORY_HEAD,
LBE_INIT_FACTORY_TAIL,
TREASURY_MIN_ADA,
} from "../constants";
import type { UTxO } from "../types";
import type { FactoryDatum, TreasuryDatum, UTxO } from "../types";
import { computeLPAssetName } from "../utils";
import { assertValidator, loadModule } from "./utils";
import { genWarehouse } from "./warehouse";
Expand All @@ -22,7 +18,7 @@ beforeAll(async () => {
beforeEach(async () => {
W = await genWarehouse();
let builder = new WarehouseBuilder(W.warehouseOptions);
let treasuryDatum: TreasuryValidateTreasurySpending["treasuryInDatum"] = {
let treasuryDatum: TreasuryDatum = {
...W.defaultTreasuryDatum,
isCancelled: true,
isManagerCollected: true,
Expand All @@ -42,11 +38,11 @@ beforeEach(async () => {
treasuryDatum.baseAsset.policyId + treasuryDatum.baseAsset.assetName,
treasuryDatum.raiseAsset.policyId + treasuryDatum.raiseAsset.assetName,
);
let factoryHeadDatum: FactoryValidateFactory["datum"] = {
let factoryHeadDatum: FactoryDatum = {
head: LBE_INIT_FACTORY_HEAD,
tail: lpAssetName,
};
let factoryTailDatum: FactoryValidateFactory["datum"] = {
let factoryTailDatum: FactoryDatum = {
head: lpAssetName,
tail: LBE_INIT_FACTORY_TAIL,
};
Expand Down
68 changes: 68 additions & 0 deletions src/tests/collect-orders.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// import { TreasuryValidateTreasurySpending } from "../../plutus";
// import { WarehouseBuilder, type BuildCollectOrdersOptions } from "../build-tx";
// import { ORDER_MIN_ADA, TREASURY_MIN_ADA } from "../constants";
// import type { UTxO } from "../types";
// import { assertValidator, loadModule } from "./utils";
// import { genWarehouse } from "./warehouse";

// let W: GenTestWarehouse;

// beforeAll(async () => {
// await loadModule();
// });

// type GenTestWarehouse = Awaited<ReturnType<typeof genTestWarehouse>>;
// async function genTestWarehouse() {
// let warehouse = await genWarehouse();
// let builder = new WarehouseBuilder(warehouse.warehouseOptions);
// const treasuryDatum: TreasuryValidateTreasurySpending["treasuryInDatum"] = {
// ...warehouse.defaultTreasuryDatum,
// };
// const treasuryInput: UTxO = {
// txHash: "00".repeat(32),
// outputIndex: 1,
// assets: {
// [builder.treasuryToken]: 1n,
// [warehouse.minswapTokenRaw]: treasuryDatum.reserveBase,
// lovelace: TREASURY_MIN_ADA,
// },
// address: builder.treasuryAddress,
// datum: builder.toDatumTreasury(treasuryDatum),
// };
// let orderAmount = 100_000_000n;
// let orderDatum: FeedTyp = {
// ...warehouse.defaultOrderDatum,
// amount:
// };
// let orderInput: UTxO = {
// txHash: "00".repeat(32),
// outputIndex: 2,
// assets: {
// [builder.orderToken]: 1n,
// lovelace: ORDER_MIN_ADA + orderAmount,
// },
// address: builder.orderAddress,
// datum: builder.toDatumOrder(orderDatum),
// };
// const options: BuildCollectOrdersOptions = {
// treasuryInput: treasuryInput,
// orderInputs: [orderInput],
// validFrom: warehouse.t.utils.slotToUnixTime(warehouse.emulator.slot),
// validTo: warehouse.t.utils.slotToUnixTime(warehouse.emulator.slot + 100),
// };
// return {
// ...warehouse,
// treasuryInput,
// treasuryDatum,
// builder,
// options,
// };
// }

// beforeEach(async () => {
// W = await genTestWarehouse();
// });

// test("collect-orders | PASS | if you're happy!", async () => {
// assertValidator(W.builder.buildCollectOrders(W.options), "");
// });
22 changes: 8 additions & 14 deletions src/tests/collect-sellers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,20 @@ FAIL
- Manager input
- Manager output
*/
import {
ManagerValidateManagerSpending,
SellerValidateSellerSpending,
} from "../../plutus";
import invariant from "@minswap/tiny-invariant";
import * as T from "@minswap/translucent";
import { ManagerValidateManagerSpending } from "../../plutus";
import { WarehouseBuilder, type BuildCollectSellersOptions } from "../build-tx";
import { MANAGER_MIN_ADA, TREASURY_MIN_ADA } from "../constants";
import type { Assets, ManagerDatum, SellerDatum, UTxO } from "../types";
import { plutusAddress2Address } from "../utils";
import {
assertValidator,
assertValidatorFail,
genWarehouseOptions,
loadModule,
} from "./utils";
import * as T from "@minswap/translucent";
import { genWarehouse } from "./warehouse";
import type { Assets, UTxO } from "../types";
import { plutusAddress2Address } from "../utils";
import invariant from "@minswap/tiny-invariant";

let utxoIndex: number;
type AwaitedReturnType<T> = T extends Promise<infer R> ? R : T;
Expand Down Expand Up @@ -92,7 +89,7 @@ async function genTestWarehouse() {
address: builder.treasuryAddress,
datum: builder.toDatumTreasury(treasuryDatum),
};
const managerDatum: ManagerValidateManagerSpending["managerInDatum"] = {
const managerDatum: ManagerDatum = {
...defaultManagerDatum,
};
const managerUTxO = {
Expand All @@ -104,7 +101,7 @@ async function genTestWarehouse() {
address: builder.managerAddress,
datum: builder.toDatumManager(managerDatum),
};
const sellerDatums: SellerValidateSellerSpending["sellerInDatum"][] = [
const sellerDatums: SellerDatum[] = [
{
...defaultSellerDatum,
amount: -1_000n,
Expand Down Expand Up @@ -159,10 +156,7 @@ beforeEach(async () => {
warehouse = await genTestWarehouse();
});

function genSellerUTxO(
datum: SellerValidateSellerSpending["sellerInDatum"],
builder: WarehouseBuilder,
): UTxO {
function genSellerUTxO(datum: SellerDatum, builder: WarehouseBuilder): UTxO {
return {
txHash: "ce156ede4b5d1cd72b98f1d78c77c4e6bd3fc37bbe28e6c380f17a4f626e593c",
outputIndex: ++utxoIndex,
Expand Down
46 changes: 21 additions & 25 deletions src/tests/example.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { beforeEach, expect, test } from "bun:test";
import invariant from "@minswap/tiny-invariant";
import * as T from "@minswap/translucent";
import { beforeEach, expect, test } from "bun:test";
import { FactoryValidatorValidateFactory as AmmValidateFactory } from "../../amm-plutus";
import {
FeedTypeAmmPool,
FeedTypeOrder,
TreasuryValidateTreasurySpending,
} from "../../plutus";
import {
WarehouseBuilder,
type BuildAddSellersOptions,
Expand All @@ -12,41 +19,30 @@ import {
type WarehouseBuilderOptions,
} from "../build-tx";
import {
collectMinswapValidators,
collectValidators,
deployMinswapValidators,
deployValidators,
type DeployedValidators,
type Validators,
collectValidators,
type MinswapValidators,
deployMinswapValidators,
collectMinswapValidators,
type Validators,
} from "../deploy-validators";
import {
generateAccount,
quickSubmitBuilder,
type GeneratedAccount,
} from "./utils";
import type {
Address,
Assets,
Emulator,
OrderDatum,
OutputData,
Translucent,
TreasuryDatum,
UTxO,
} from "../types";
import { address2PlutusAddress, calculateInitialLiquidity } from "../utils";
import {
address2PlutusAddress,
calculateInitialLiquidity,
computeLPAssetName,
} from "../utils";
import { LBE_INIT_FACTORY_HEAD, LBE_INIT_FACTORY_TAIL } from "../constants";
import {
FactoryValidateFactory,
FeedTypeAmmPool,
FeedTypeOrder,
TreasuryValidateTreasurySpending,
} from "../../plutus";
import { FactoryValidatorValidateFactory as AmmValidateFactory } from "../../amm-plutus";
import invariant from "@minswap/tiny-invariant";
generateAccount,
quickSubmitBuilder,
type GeneratedAccount,
} from "./utils";

let ACCOUNT_0: GeneratedAccount;
let ACCOUNT_1: GeneratedAccount;
Expand Down Expand Up @@ -174,7 +170,7 @@ test("example flow", async () => {
// create treasury
const discoveryStartSlot = emulator.slot + 60 * 60;
const discoveryEndSlot = discoveryStartSlot + 60 * 60 * 24 * 2; // 2 days
const treasuryDatum: TreasuryValidateTreasurySpending["treasuryInDatum"] = {
const treasuryDatum: TreasuryDatum = {
factoryPolicyId: t.utils.validatorToScriptHash(validators.factoryValidator),
sellerHash: t.utils.validatorToScriptHash(validators.sellerValidator),
orderHash: t.utils.validatorToScriptHash(validators.orderValidator),
Expand Down Expand Up @@ -226,7 +222,7 @@ test("example flow", async () => {
t.utils.validatorToAddress(validators.treasuryValidator),
)
).find((u) => !u.scriptRef) as UTxO;
let orderDatum: FeedTypeOrder["_datum"] = {
let orderDatum: OrderDatum = {
factoryPolicyId: t.utils.validatorToScriptHash(validators.factoryValidator),
baseAsset,
raiseAsset,
Expand Down
12 changes: 5 additions & 7 deletions src/tests/init-factory.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import {
FactoryValidateFactory,
FactoryValidateFactoryMinting,
} from "../../plutus";
import * as T from "@minswap/translucent";
import { FactoryValidateFactoryMinting } from "../../plutus";
import { WarehouseBuilder } from "../build-tx";
import { LBE_INIT_FACTORY_HEAD, LBE_INIT_FACTORY_TAIL } from "../constants";
import type { FactoryDatum } from "../types";
import {
DUMMY_SEED_UTXO,
assertValidator,
genWarehouseOptions,
generateAccount,
loadModule,
} from "./utils";
import * as T from "@minswap/translucent";

let warehouse: any;

Expand Down Expand Up @@ -81,7 +79,7 @@ test("init-factory | FAIL | missing Factory Token", async () => {
builder.buildInitFactory({ seedUtxo: DUMMY_SEED_UTXO });
builder.tasks.pop();
builder.tasks.push(() => {
const factoryDatum: FactoryValidateFactory["datum"] = {
const factoryDatum: FactoryDatum = {
head: LBE_INIT_FACTORY_HEAD,
tail: LBE_INIT_FACTORY_TAIL,
};
Expand All @@ -104,7 +102,7 @@ test("init-factory | FAIL | Factory Datum is not correct", async () => {
builder.buildInitFactory({ seedUtxo: DUMMY_SEED_UTXO });
builder.tasks.pop();
builder.tasks.push(() => {
const factoryDatum: FactoryValidateFactory["datum"] = {
const factoryDatum: FactoryDatum = {
head: LBE_INIT_FACTORY_HEAD,
tail: LBE_INIT_FACTORY_HEAD, // wrong here
};
Expand Down
18 changes: 5 additions & 13 deletions src/tests/manager.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import * as T from "@minswap/translucent";
import {
TreasuryValidateTreasurySpending,
type ManagerValidateManagerSpending,
} from "../../plutus";
import { WarehouseBuilder, type BuildCollectManagerOptions } from "../build-tx";
import { TREASURY_MIN_ADA } from "../constants";
import type { UTxO } from "../types";
import type { ManagerDatum, TreasuryDatum, UTxO } from "../types";
import { assertValidator, loadModule } from "./utils";
import { genWarehouse } from "./warehouse";

Expand All @@ -18,7 +13,7 @@ beforeAll(async () => {
beforeEach(async () => {
W = await genWarehouse();
let builder = new WarehouseBuilder(W.warehouseOptions);
const managerDatum: ManagerValidateManagerSpending["managerInDatum"] = {
const managerDatum: ManagerDatum = {
...W.defaultManagerDatum,
sellerCount: 0n,
reserveRaise: 100_000_000_000n,
Expand All @@ -34,7 +29,7 @@ beforeEach(async () => {
address: builder.managerAddress,
datum: builder.toDatumManager(managerDatum),
};
const treasuryDatum: TreasuryValidateTreasurySpending["treasuryInDatum"] = {
const treasuryDatum: TreasuryDatum = {
...W.defaultTreasuryDatum,
};
const treasuryInput: UTxO = {
Expand Down Expand Up @@ -109,17 +104,14 @@ test("collect-manager | FAIL | wrong treasury out datum", async () => {
});

test("collect-manager | FAIL | LBE ID missmatch", async () => {
const { builder } = W;
let builder: WarehouseBuilder = W.builder;
const treasuryInDatum = {
...W.treasuryDatum,
baseAsset: W.adaToken,
};
const treasuryInput: UTxO = {
...W.treasuryInput,
datum: T.Data.to(
treasuryInDatum,
TreasuryValidateTreasurySpending.treasuryInDatum,
),
datum: builder.toDatumTreasury(treasuryInDatum),
};
const options = {
...W.options,
Expand Down
16 changes: 6 additions & 10 deletions src/tests/using-seller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@ FAIL:
- Update orders(withdraw fund): invalid penalty amount
- TODO: No Treasury ref inputs
*/
import { FeedTypeOrder } from "../../plutus";
import * as T from "@minswap/translucent";
import { WarehouseBuilder, type BuildUsingSellerOptions } from "../build-tx";
import { LBE_FEE, LBE_MIN_OUTPUT_ADA, TREASURY_MIN_ADA } from "../constants";
import type { OrderDatum, UTxO } from "../types";
import { plutusAddress2Address } from "../utils";
import { assertValidator, genWarehouseOptions, loadModule } from "./utils";
import * as T from "@minswap/translucent";
import { genWarehouse } from "./warehouse";
import type { UTxO } from "../types";
import { plutusAddress2Address } from "../utils";

const MINt = {
policyId: "29d222ce763455e3d7a09a665ce554f00ac89d2e99a1a83d267170c6",
Expand Down Expand Up @@ -99,7 +98,7 @@ async function genTestWarehouse() {
address: builder.sellerAddress,
datum: builder.toDatumSeller(sellerDatum),
};
const orderInDatums: FeedTypeOrder["_datum"][] = [
const orderInDatums: OrderDatum[] = [
{
...defaultOrderDatum,
amount: 12n,
Expand All @@ -116,7 +115,7 @@ async function genTestWarehouse() {
penaltyAmount: 0n,
},
];
const orderOutDatums: FeedTypeOrder["_datum"][] = [
const orderOutDatums: OrderDatum[] = [
{
...defaultOrderDatum,
amount: 100n,
Expand Down Expand Up @@ -168,10 +167,7 @@ beforeEach(async () => {
warehouse = await genTestWarehouse();
});

function genOrderUTxO(
datum: FeedTypeOrder["_datum"],
builder: WarehouseBuilder,
): UTxO {
function genOrderUTxO(datum: OrderDatum, builder: WarehouseBuilder): UTxO {
return {
txHash: "ce156ede4b5d1cd72b98f1d78c77c4e6bd3fc37bbe28e6c380f17a4f626e593c",
outputIndex: ++utxoIndex,
Expand Down
Loading

0 comments on commit 6d58f97

Please sign in to comment.