Skip to content

Commit

Permalink
Merge pull request #89 from cardano2vn/refactor
Browse files Browse the repository at this point in the history
feat: update compiler version and refactor reference script handling …
  • Loading branch information
tidvn authored Nov 16, 2024
2 parents d621d68 + d8d449f commit 83fee92
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 223 deletions.
2 changes: 1 addition & 1 deletion contract/aiken.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "cardano2vn/cip68generator"
version = "0.0.0"
compiler = "v1.1.0"
compiler = "v1.1.6"
plutus = "v3"
license = "Apache-2.0"
description = "Aiken contracts for project 'cardano2vn/cip68generator'"
Expand Down
17 changes: 7 additions & 10 deletions contract/script/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
export const EXCHANGE_FEE_ADDRESS = process.env.EXCHANGE_FEE_ADDRESS || "";
export const MINT_REFERENCE_SCRIPT_ADDRESS =
process.env.MINT_REFERENCE_SCRIPT_ADDRESS || "";
export const STORE_REFERENCE_SCRIPT_ADDRESS =
process.env.STORE_REFERENCE_SCRIPT_ADDRESS || "";
export const MINT_REFERENCE_SCRIPT_HASH =
process.env.MINT_REFERENCE_SCRIPT_HASH || "";
export const STORE_REFERENCE_SCRIPT_HASH =
process.env.STORE_REFERENCE_SCRIPT_HASH || "";
export const REFERENCE_SCRIPT_ADDRESS =
process.env.REFERENCE_SCRIPT_ADDRESS || "";

export const REFERENCE_SCRIPT_HASH = process.env.REFERENCE_SCRIPT_HASH || "";

export const EXCHANGE_FEE_PRICE = process.env.EXCHANGE_FEE_PRICE || "";

export const title = {
mint: "mint.mint.mint",
store: "store.store.spend",
mint: "cip68generator.cip68generator.mint",
store: "cip68generator.cip68generator.spend",
};
37 changes: 5 additions & 32 deletions contract/script/txbuilder/cip68.txbuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ import { MeshAdapter } from "../adapters/mesh.adapter";
import plutus from "../../plutus.json";
import {
EXCHANGE_FEE_ADDRESS,
MINT_REFERENCE_SCRIPT_HASH,
STORE_REFERENCE_SCRIPT_HASH,
MINT_REFERENCE_SCRIPT_ADDRESS,
STORE_REFERENCE_SCRIPT_ADDRESS,
REFERENCE_SCRIPT_HASH,
REFERENCE_SCRIPT_ADDRESS,
title,
} from "../constants";
import { Plutus } from "../types";
Expand Down Expand Up @@ -289,7 +287,7 @@ export class Cip68Contract extends MeshAdapter implements ICip68Contract {
/**
* @description Create reference script for mint transaction
*/
createReferenceScriptMint = async () => {
createReferenceScript = async () => {
const { walletAddress, utxos, collateral } = await this.getWalletForTx();

const unsignedTx = await this.meshTxBuilder
Expand All @@ -299,10 +297,10 @@ export class Cip68Contract extends MeshAdapter implements ICip68Contract {
collateral.output.amount,
collateral.output.address,
)
.txOut(MINT_REFERENCE_SCRIPT_ADDRESS, [
.txOut(REFERENCE_SCRIPT_ADDRESS, [
{
unit: "lovelace",
quantity: "5000000",
quantity: "15000000",
},
])

Expand All @@ -319,29 +317,4 @@ export class Cip68Contract extends MeshAdapter implements ICip68Contract {

return unsignedTx.complete();
};

createReferenceScriptStore = async () => {
const { walletAddress, utxos, collateral } = await this.getWalletForTx();
const unsignedTx = await this.meshTxBuilder
.txIn(collateral.input.txHash, collateral.input.outputIndex)
.txOut(STORE_REFERENCE_SCRIPT_ADDRESS, [
{
unit: "lovelace",
quantity: "7000000",
},
])

.txOutReferenceScript(this.storeScriptCbor, "V3")
.txOutInlineDatumValue("")
.changeAddress(walletAddress)
.selectUtxosFrom(utxos)
.txInCollateral(
collateral.input.txHash,
collateral.input.outputIndex,
collateral.output.amount,
collateral.output.address,
);

return unsignedTx.complete();
};
}
33 changes: 10 additions & 23 deletions contract/tests/cip68.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,29 +119,16 @@ describe("Mint, Burn, Update, Remove Assets (NFT/TOKEN) CIP68", function () {
// expect(txHash.length).toBe(64);
// });

// test('Mint Reference Script', async function () {
// const cip68Contract: Cip68Contract = new Cip68Contract({
// fetcher: blockfrostProvider,
// wallet: wallet,
// meshTxBuilder: meshTxBuilder,
// });
// const unsignedTx: string = await cip68Contract.createReferenceScriptMint();
// const signedTx = await wallet.signTx(unsignedTx, true);
// const txHash = await wallet.submitTx(signedTx);
// console.log(txHash);
// expect(txHash.length).toBe(64);
// test(" Reference Script", async function () {
// const cip68Contract: Cip68Contract = new Cip68Contract({
// fetcher: blockfrostProvider,
// wallet: wallet,
// meshTxBuilder: meshTxBuilder,
// });

// test('Store Reference Script', async function () {
// const cip68Contract: Cip68Contract = new Cip68Contract({
// fetcher: blockfrostProvider,
// wallet: wallet,
// meshTxBuilder: meshTxBuilder,
// });
// const unsignedTx: string = await cip68Contract.createReferenceScriptStore();
// const signedTx = await wallet.signTx(unsignedTx, true);
// const txHash = await wallet.submitTx(signedTx);
// console.log(txHash);
// expect(txHash.length).toBe(64);
// const unsignedTx: string = await cip68Contract.createReferenceScript();
// const signedTx = await wallet.signTx(unsignedTx, true);
// const txHash = await wallet.submitTx(signedTx);
// console.log(txHash);
// expect(txHash.length).toBe(64);
// });
});
27 changes: 27 additions & 0 deletions contract/validators/cip68generator.ak
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use aiken/crypto.{ScriptHash, VerificationKeyHash}
use cardano/assets.{PolicyId}
use cardano/transaction.{OutputReference,Transaction}
use cip68generator/types.{MintRedeemer,StoreRedeemer}
use types/cip68.{CIP68}

validator cip68generator(
_exchange: VerificationKeyHash,
_exchange_fee: Int,
_store: ScriptHash,
) {
mint(_redeemer: MintRedeemer, _policy_id: PolicyId, _transaction: Transaction) {
True
}
spend(
_datum: Option<CIP68>,
_redeemer: StoreRedeemer,
_output_reference: OutputReference,
_transaction: Transaction,
) {
True
}

else(_) {
fail
}
}
103 changes: 0 additions & 103 deletions contract/validators/mint.ak

This file was deleted.

54 changes: 0 additions & 54 deletions contract/validators/store.ak

This file was deleted.

0 comments on commit 83fee92

Please sign in to comment.