feat: convert gift card tutorial to lucid-evolution and weld

This commit is contained in:
rvcas 2024-11-25 16:09:10 -05:00 committed by Lucas
parent 7c1cd81554
commit 9d59333757
23 changed files with 8566 additions and 9995 deletions

View File

@ -4,8 +4,6 @@ artifacts/
build/
# Aiken's default documentation export
docs/
# generated by deno fresh
.vscode/
node_modules

View File

@ -2,5 +2,3 @@
package-lock.json
pnpm-lock.yaml
yarn.lock
build/
validators/

View File

@ -1,7 +1,7 @@
{
"useTabs": false,
"singleQuote": true,
"trailingComma": "all",
"printWidth": 100,
"trailingComma": "none",
"plugins": ["prettier-plugin-svelte", "prettier-plugin-tailwindcss"],
"overrides": [
{

View File

@ -1,6 +1,6 @@
# create-svelte
# sv
Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/main/packages/create-svelte).
Everything you need to build a Svelte project, powered by [`sv`](https://github.com/sveltejs/cli).
## Creating a project
@ -8,10 +8,10 @@ If you're seeing this, you've probably already done this step. Congrats!
```bash
# create a new project in the current directory
npm create svelte@latest
npx sv create
# create a new project in my-app
npm create svelte@latest my-app
npx sv create my-app
```
## Developing
@ -35,4 +35,4 @@ npm run build
You can preview the production build with `npm run preview`.
> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
> To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment.

View File

@ -13,4 +13,4 @@ requirements = []
source = "github"
[etags]
"aiken-lang/stdlib@v2" = [{ secs_since_epoch = 1725207295, nanos_since_epoch = 895782000 }, "d79382d2b6ecb3aee9b0755c31d8a5bbafe88a7b3706d7fb8a52fd4d05818501"]
"aiken-lang/stdlib@v2" = [{ secs_since_epoch = 1732568276, nanos_since_epoch = 702142000 }, "33dce3a6dbfc58a92cc372c4e15d802f079f4958af941386d18980eb98439bb4"]

View File

@ -1,28 +0,0 @@
export type Preamble = {
title: string;
description?: string;
version: string;
plutusVersion: string;
license?: string;
};
export type Argument = {
title?: string;
description?: string;
// schema: Record<string, unknown>;
};
export type Validator = {
title: string;
description?: string;
datum?: Argument;
redeemer: Argument;
parameters?: Argument[];
compiledCode: string;
hash: string;
};
export type Blueprint = {
preamble: Preamble;
validators: Validator[];
};

View File

@ -1,11 +1,10 @@
import js from '@eslint/js';
import ts from 'typescript-eslint';
import svelte from 'eslint-plugin-svelte';
import prettier from 'eslint-config-prettier';
import js from '@eslint/js';
import svelte from 'eslint-plugin-svelte';
import globals from 'globals';
import ts from 'typescript-eslint';
/** @type {import('eslint').Linter.Config[]} */
export default [
export default ts.config(
js.configs.recommended,
...ts.configs.recommended,
...svelte.configs['flat/recommended'],
@ -21,6 +20,7 @@ export default [
},
{
files: ['**/*.svelte'],
languageOptions: {
parserOptions: {
parser: ts.parser
@ -30,4 +30,4 @@ export default [
{
ignores: ['build/', '.svelte-kit/', 'dist/']
}
];
);

File diff suppressed because it is too large Load Diff

View File

@ -1,44 +1,42 @@
{
"name": "gift-card",
"name": "gift_card",
"version": "0.0.1",
"private": true,
"type": "module",
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "prettier --check . && eslint .",
"format": "prettier --write ."
"format": "prettier --write .",
"lint": "prettier --check . && eslint ."
},
"devDependencies": {
"@sveltejs/adapter-auto": "^3.0.0",
"@sveltejs/kit": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^4.0.0-next.6",
"@tailwindcss/typography": "^0.5.14",
"@types/eslint": "^9.6.0",
"@sveltejs/vite-plugin-svelte": "^4.0.0",
"autoprefixer": "^10.4.20",
"eslint": "^9.0.0",
"eslint": "^9.7.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-svelte": "^2.36.0",
"globals": "^15.0.0",
"prettier": "^3.1.1",
"prettier-plugin-svelte": "^3.1.2",
"prettier": "^3.3.2",
"prettier-plugin-svelte": "^3.2.6",
"prettier-plugin-tailwindcss": "^0.6.5",
"svelte": "^5.0.0-next.1",
"svelte-check": "^3.6.0",
"svelte": "^5.0.0",
"svelte-check": "^4.0.0",
"tailwindcss": "^3.4.9",
"typescript": "^5.0.0",
"typescript-eslint": "^8.0.0",
"vite": "^5.0.3"
},
"type": "module",
"dependencies": {
"@blaze-cardano/core": "^0.4.2",
"@blaze-cardano/query": "^0.2.11",
"@blaze-cardano/sdk": "^0.1.20",
"@blaze-cardano/tx": "^0.5.3",
"@blaze-cardano/uplc": "^0.1.14",
"@blaze-cardano/wallet": "^0.1.39"
"@ada-anvil/weld": "^0.2.1",
"@lucid-evolution/lucid": "^0.4.6",
"@tailwindcss/container-queries": "^0.1.1",
"@tailwindcss/forms": "^0.5.9",
"@tailwindcss/typography": "^0.5.15",
"vite-plugin-top-level-await": "^1.4.4",
"vite-plugin-wasm": "^3.3.0"
}
}

View File

@ -6,7 +6,7 @@
"plutusVersion": "v3",
"compiler": {
"name": "Aiken",
"version": "v1.1.0+ddfe01e"
"version": "v1.1.6+18054ee"
},
"license": "Apache-2.0"
},
@ -16,7 +16,7 @@
"datum": {
"title": "datum",
"schema": {
"$ref": "#/definitions/ByteArray"
"$ref": "#/definitions/SpendTokenName"
}
},
"redeemer": {
@ -33,8 +33,8 @@
}
}
],
"compiledCode": "59041b0101003232323232323232232253330043232323232323232325323233300f300100613232323232325333015300830163754002264a66602c6010602e6ea80044c94ccc05cc028c060dd5003099b8732325333019300b301a37540022900009bad301e301b375400264a666032601660346ea8004530103d87a8000132330010013756603e60386ea8008894ccc078004530103d87a8000132323232533301f337220100042a66603e66e3c0200084c050cc08cdd4000a5eb80530103d87a8000133006006003375a60400066eb8c078008c088008c080004cc030014008dd7180e180c9baa0064800458dd7180d980c1baa00116301a301737546034602e6ea8c068c06cc05cdd5180d180b9baa0011632330010013758603400644a6660320022980103d87a80001323253330183375e601c60346ea80080204c034cc0700092f5c0266008008002603a00460360026eacc060c064c064c064c064004c050dd5006980b180b801180a80098089baa0071533300f3002006132323253330123005001132533301600116132533333301b0011616161325333018301b0031500516375a0022c603000260286ea802c54ccc048c01000454ccc054c050dd50058a8010b0b18091baa00a1323232323232325333017300a3018375402026464a66603266002008466e3c0600044c8c8cc004004014894ccc07c004528899191919299981019804004919b8f00100315333020323300100100e22533302500114a0264a6660466464a66604a66ebcc0a8c0acc0ac008cdd2a4008660526ea401d2f5c0266ebcc06cc09cdd50008060a50302900130253754605000429444cc00c00c004c0a000454ccc080c0480044cc01801800c5280b0b1bad3021003375c603e0046046004604200266e9520023301d375201497ae014a044646600200200644a66603e00229404c94ccc074c010dd718110010a5113300300300130220013232333001001375a603c60366ea80492f5c0444a666036601c0042002266600600666e0000920013301f37526e50cdc58010020009bb3300d30193754603800c2646600200200444a66603800229444c94ccc068cdc39bad301c301f002480044cc00c00c004528180f80099299980b9804980c1baa00114bd6f7b63009bab301c30193754002660146eacc06c00801cdd6180d180d980d980d980d800980d180d0011bac3018001301830180023758602c00260246ea802cdd7180a18089baa00716370e90011b874800088c8cc00400400c894ccc04c004530103d87a800013232323253330143372200e0042a66602866e3c01c0084c024cc060dd3000a5eb80530103d87a80001330060060033756602a0066eb8c04c008c05c008c054004dd2a40004602000260146ea8004c034c038008c030004c030008c028004c018dd50008a4c26cac6eb80055cd2ab9d5573caae7d5d02ba15744ae91",
"hash": "06ffde77d3c5775acc98a1a6a00e6bd9870f22261210ae61f77190dd"
"compiledCode": "59040a01010032323232323232232253330043232323232323232325323233300f300100613233223232325333015300830163754002264a66602c6010602e6ea80044c94ccc05cc028c060dd5003099b8732325333019300b301a37540022900009bad301e301b375400264a666032601660346ea8004530103d87a8000132330010013756603e60386ea8008894ccc078004530103d87a8000132333222533301f337220100062a66603e66e3c02000c4c050cc08cdd400125eb80530103d87a8000133006006001375c603a0026eb4c078004c088008c080004cc030014008dd7180e180c9baa0064800458dd7180d980c1baa00116301a301737546034602e6ea8c068c06cc05cdd5180d180b9baa0011632330010013758603400644a6660320022980103d87a80001332253330183375e601c60346ea80080204c034cc0700092f5c0266008008002603600260380026eacc060c064c064c064c064004c050dd5006180a800980a980b00098089baa0071533300f3002006132323253330123005001132325333017301a00200416375a603000260286ea802c54ccc048c01000454ccc054c050dd50058010b0b18091baa00a1323232323232325333017300a3018375402026464a66603266002008466e3c0600044c8c8cc004004014894ccc07c004528899199911299981019804004919b8f00100415333020323300100100d22533302500114a026644a6660486464a66604c66ebcc0acc0b0c0b0008cdd2a4008660546ea40252f5c0266ebcc070c0a0dd50008068a50302a0013026375400429444cc010010004c09c004c0a000454ccc080c0480084cc0180180045280b0b1bae301e001375a603e0026046004604200266e9520023301d375201497ae014a044646600200200644a66603e00229404cc894ccc078c0140085288998020020009bae302100130220013232333001001375a603c60366ea80492f5c0444a666036601c0042002266600600666e0000920013301f37526e50cdc58010020009bb3300d3019375460380082646600200200444a66603800229444cc894ccc06ccdc39bad301d002480044cc010010004528180f000980f80099299980b9804980c1baa00114bd6f7b63009bab301c30193754002660146eacc06c01001cdd6180d180d980d980d980d8019bac30190033758603000660306030002602e602e00260246ea8028dd7180a18089baa00716370e90011b874800088c8cc00400400c894ccc04c0045300103d87a800013233322253330143372200e0062a66602866e3c01c00c4c024cc060dd300125eb80530103d87a8000133006006001375c60240026eacc04c004c05c008c054004dd2a40004602000260146ea8004c034c03800cc030008c02c008c02c004c018dd50008a4c26cac6eb80055cd2ab9d5573caae7d5d02ba15745",
"hash": "3fe854a1171108b9af1e064ee47af2f81c9788104a6f49213dec8bb7"
},
{
"title": "multi.redeem.mint",
@ -52,11 +52,14 @@
}
}
],
"compiledCode": "59041b0101003232323232323232232253330043232323232323232325323233300f300100613232323232325333015300830163754002264a66602c6010602e6ea80044c94ccc05cc028c060dd5003099b8732325333019300b301a37540022900009bad301e301b375400264a666032601660346ea8004530103d87a8000132330010013756603e60386ea8008894ccc078004530103d87a8000132323232533301f337220100042a66603e66e3c0200084c050cc08cdd4000a5eb80530103d87a8000133006006003375a60400066eb8c078008c088008c080004cc030014008dd7180e180c9baa0064800458dd7180d980c1baa00116301a301737546034602e6ea8c068c06cc05cdd5180d180b9baa0011632330010013758603400644a6660320022980103d87a80001323253330183375e601c60346ea80080204c034cc0700092f5c0266008008002603a00460360026eacc060c064c064c064c064004c050dd5006980b180b801180a80098089baa0071533300f3002006132323253330123005001132533301600116132533333301b0011616161325333018301b0031500516375a0022c603000260286ea802c54ccc048c01000454ccc054c050dd50058a8010b0b18091baa00a1323232323232325333017300a3018375402026464a66603266002008466e3c0600044c8c8cc004004014894ccc07c004528899191919299981019804004919b8f00100315333020323300100100e22533302500114a0264a6660466464a66604a66ebcc0a8c0acc0ac008cdd2a4008660526ea401d2f5c0266ebcc06cc09cdd50008060a50302900130253754605000429444cc00c00c004c0a000454ccc080c0480044cc01801800c5280b0b1bad3021003375c603e0046046004604200266e9520023301d375201497ae014a044646600200200644a66603e00229404c94ccc074c010dd718110010a5113300300300130220013232333001001375a603c60366ea80492f5c0444a666036601c0042002266600600666e0000920013301f37526e50cdc58010020009bb3300d30193754603800c2646600200200444a66603800229444c94ccc068cdc39bad301c301f002480044cc00c00c004528180f80099299980b9804980c1baa00114bd6f7b63009bab301c30193754002660146eacc06c00801cdd6180d180d980d980d980d800980d180d0011bac3018001301830180023758602c00260246ea802cdd7180a18089baa00716370e90011b874800088c8cc00400400c894ccc04c004530103d87a800013232323253330143372200e0042a66602866e3c01c0084c024cc060dd3000a5eb80530103d87a80001330060060033756602a0066eb8c04c008c05c008c054004dd2a40004602000260146ea8004c034c038008c030004c030008c028004c018dd50008a4c26cac6eb80055cd2ab9d5573caae7d5d02ba15744ae91",
"hash": "06ffde77d3c5775acc98a1a6a00e6bd9870f22261210ae61f77190dd"
"compiledCode": "59040a01010032323232323232232253330043232323232323232325323233300f300100613233223232325333015300830163754002264a66602c6010602e6ea80044c94ccc05cc028c060dd5003099b8732325333019300b301a37540022900009bad301e301b375400264a666032601660346ea8004530103d87a8000132330010013756603e60386ea8008894ccc078004530103d87a8000132333222533301f337220100062a66603e66e3c02000c4c050cc08cdd400125eb80530103d87a8000133006006001375c603a0026eb4c078004c088008c080004cc030014008dd7180e180c9baa0064800458dd7180d980c1baa00116301a301737546034602e6ea8c068c06cc05cdd5180d180b9baa0011632330010013758603400644a6660320022980103d87a80001332253330183375e601c60346ea80080204c034cc0700092f5c0266008008002603600260380026eacc060c064c064c064c064004c050dd5006180a800980a980b00098089baa0071533300f3002006132323253330123005001132325333017301a00200416375a603000260286ea802c54ccc048c01000454ccc054c050dd50058010b0b18091baa00a1323232323232325333017300a3018375402026464a66603266002008466e3c0600044c8c8cc004004014894ccc07c004528899199911299981019804004919b8f00100415333020323300100100d22533302500114a026644a6660486464a66604c66ebcc0acc0b0c0b0008cdd2a4008660546ea40252f5c0266ebcc070c0a0dd50008068a50302a0013026375400429444cc010010004c09c004c0a000454ccc080c0480084cc0180180045280b0b1bae301e001375a603e0026046004604200266e9520023301d375201497ae014a044646600200200644a66603e00229404cc894ccc078c0140085288998020020009bae302100130220013232333001001375a603c60366ea80492f5c0444a666036601c0042002266600600666e0000920013301f37526e50cdc58010020009bb3300d3019375460380082646600200200444a66603800229444cc894ccc06ccdc39bad301d002480044cc010010004528180f000980f80099299980b9804980c1baa00114bd6f7b63009bab301c30193754002660146eacc06c01001cdd6180d180d980d980d980d8019bac30190033758603000660306030002602e602e00260246ea8028dd7180a18089baa00716370e90011b874800088c8cc00400400c894ccc04c0045300103d87a800013233322253330143372200e0062a66602866e3c01c00c4c024cc060dd300125eb80530103d87a8000133006006001375c60240026eacc04c004c05c008c054004dd2a40004602000260146ea8004c034c03800cc030008c02c008c02c004c018dd50008a4c26cac6eb80055cd2ab9d5573caae7d5d02ba15745",
"hash": "3fe854a1171108b9af1e064ee47af2f81c9788104a6f49213dec8bb7"
},
{
"title": "multi.redeem.else",
"redeemer": {
"schema": {}
},
"parameters": [
{
"title": "creator",
@ -65,8 +68,8 @@
}
}
],
"compiledCode": "59041b0101003232323232323232232253330043232323232323232325323233300f300100613232323232325333015300830163754002264a66602c6010602e6ea80044c94ccc05cc028c060dd5003099b8732325333019300b301a37540022900009bad301e301b375400264a666032601660346ea8004530103d87a8000132330010013756603e60386ea8008894ccc078004530103d87a8000132323232533301f337220100042a66603e66e3c0200084c050cc08cdd4000a5eb80530103d87a8000133006006003375a60400066eb8c078008c088008c080004cc030014008dd7180e180c9baa0064800458dd7180d980c1baa00116301a301737546034602e6ea8c068c06cc05cdd5180d180b9baa0011632330010013758603400644a6660320022980103d87a80001323253330183375e601c60346ea80080204c034cc0700092f5c0266008008002603a00460360026eacc060c064c064c064c064004c050dd5006980b180b801180a80098089baa0071533300f3002006132323253330123005001132533301600116132533333301b0011616161325333018301b0031500516375a0022c603000260286ea802c54ccc048c01000454ccc054c050dd50058a8010b0b18091baa00a1323232323232325333017300a3018375402026464a66603266002008466e3c0600044c8c8cc004004014894ccc07c004528899191919299981019804004919b8f00100315333020323300100100e22533302500114a0264a6660466464a66604a66ebcc0a8c0acc0ac008cdd2a4008660526ea401d2f5c0266ebcc06cc09cdd50008060a50302900130253754605000429444cc00c00c004c0a000454ccc080c0480044cc01801800c5280b0b1bad3021003375c603e0046046004604200266e9520023301d375201497ae014a044646600200200644a66603e00229404c94ccc074c010dd718110010a5113300300300130220013232333001001375a603c60366ea80492f5c0444a666036601c0042002266600600666e0000920013301f37526e50cdc58010020009bb3300d30193754603800c2646600200200444a66603800229444c94ccc068cdc39bad301c301f002480044cc00c00c004528180f80099299980b9804980c1baa00114bd6f7b63009bab301c30193754002660146eacc06c00801cdd6180d180d980d980d980d800980d180d0011bac3018001301830180023758602c00260246ea802cdd7180a18089baa00716370e90011b874800088c8cc00400400c894ccc04c004530103d87a800013232323253330143372200e0042a66602866e3c01c0084c024cc060dd3000a5eb80530103d87a80001330060060033756602a0066eb8c04c008c05c008c054004dd2a40004602000260146ea8004c034c038008c030004c030008c028004c018dd50008a4c26cac6eb80055cd2ab9d5573caae7d5d02ba15744ae91",
"hash": "06ffde77d3c5775acc98a1a6a00e6bd9870f22261210ae61f77190dd"
"compiledCode": "59040a01010032323232323232232253330043232323232323232325323233300f300100613233223232325333015300830163754002264a66602c6010602e6ea80044c94ccc05cc028c060dd5003099b8732325333019300b301a37540022900009bad301e301b375400264a666032601660346ea8004530103d87a8000132330010013756603e60386ea8008894ccc078004530103d87a8000132333222533301f337220100062a66603e66e3c02000c4c050cc08cdd400125eb80530103d87a8000133006006001375c603a0026eb4c078004c088008c080004cc030014008dd7180e180c9baa0064800458dd7180d980c1baa00116301a301737546034602e6ea8c068c06cc05cdd5180d180b9baa0011632330010013758603400644a6660320022980103d87a80001332253330183375e601c60346ea80080204c034cc0700092f5c0266008008002603600260380026eacc060c064c064c064c064004c050dd5006180a800980a980b00098089baa0071533300f3002006132323253330123005001132325333017301a00200416375a603000260286ea802c54ccc048c01000454ccc054c050dd50058010b0b18091baa00a1323232323232325333017300a3018375402026464a66603266002008466e3c0600044c8c8cc004004014894ccc07c004528899199911299981019804004919b8f00100415333020323300100100d22533302500114a026644a6660486464a66604c66ebcc0acc0b0c0b0008cdd2a4008660546ea40252f5c0266ebcc070c0a0dd50008068a50302a0013026375400429444cc010010004c09c004c0a000454ccc080c0480084cc0180180045280b0b1bae301e001375a603e0026046004604200266e9520023301d375201497ae014a044646600200200644a66603e00229404cc894ccc078c0140085288998020020009bae302100130220013232333001001375a603c60366ea80492f5c0444a666036601c0042002266600600666e0000920013301f37526e50cdc58010020009bb3300d3019375460380082646600200200444a66603800229444cc894ccc06ccdc39bad301d002480044cc010010004528180f000980f80099299980b9804980c1baa00114bd6f7b63009bab301c30193754002660146eacc06c01001cdd6180d180d980d980d980d8019bac30190033758603000660306030002602e602e00260246ea8028dd7180a18089baa00716370e90011b874800088c8cc00400400c894ccc04c0045300103d87a800013233322253330143372200e0062a66602866e3c01c00c4c024cc060dd300125eb80530103d87a8000133006006001375c60240026eacc04c004c05c008c054004dd2a40004602000260146ea8004c034c03800cc030008c02c008c02c004c018dd50008a4c26cac6eb80055cd2ab9d5573caae7d5d02ba15745",
"hash": "3fe854a1171108b9af1e064ee47af2f81c9788104a6f49213dec8bb7"
},
{
"title": "oneshot.gift_card.spend",
@ -96,8 +99,8 @@
}
}
],
"compiledCode": "5902750101003232323232323223222533300532323232323232323232532333010300500613232323232325333016300730173754002264a66602e601860306ea80044c8c94ccc070c07c0084c94ccc068cdc39bad301c002480044cdc780080c0a50375c60340022c603a002660160066eb8c070c064dd50008b1804980c1baa3009301837546036603860306ea8c06cc060dd50008b198039bac301a00223375e601260306ea8004014dd5980c980d180d180d180d000980a9baa00d3017301800230160013012375400e2a666020600200c2646464a66602660080022a66602c602a6ea802c540085854ccc04cc02000454ccc058c054dd50058a8010b0b18099baa00a1323232325333018301b00213232533301730083018375401e2a66602e601060306ea8cc0240148cdd79805980d1baa00101515333017300c00113371e00402a29405854ccc05ccdc3800a4002266e3c0080545281bad3018002375c602c0022c60320026600e6eacc060c064c064c064c06400800cdd6180b80098099baa00b375c602a60246ea801c58dc3a400044646600200200644a66602a0022980103d87a8000132325333014300500213374a90001980c00125eb804cc010010004c064008c05c0048c04c00488c94ccc03cc010c040dd50008a5eb7bdb1804dd5980a18089baa001323300100100322533301300114c103d87a800013232323253330143372200e0042a66602866e3c01c0084cdd2a4000660306e980052f5c02980103d87a80001330060060033756602a0066eb8c04c008c05c008c054004dc3a400460166ea8004c038c03c008c034004c034008c02c004c01cdd50008a4c26cac6eb80055cd2ab9d5573caae7d5d02ba15745",
"hash": "e8498b6e37da9406494b7512fab69256e7c25204130909fae35822a2"
"compiledCode": "5902730101003232323232323223222533300532323232323232323232532333010300500613233223232325333016300730173754002264a66602e601860306ea80044c8c94ccc070c07c0084c94ccc068cdc39bad301c002480044cdc780080c0a50375c60340022c603a002660160066eb8c070c064dd50008b1804980c1baa3009301837546036603860306ea8c06cc060dd50008b198039bac301a00223375e601260306ea8004014dd5980c980d180d180d180d000980a9baa00c3016001301630170013012375400e2a666020600200c2646464a66602660080022a66602c602a6ea802c0085854ccc04cc02000454ccc058c054dd50058010b0b18099baa00a1323232325333018301b00213232533301730083018375401e2a66602e601060306ea8cc0240148cdd79805980d1baa00101515333017300c00113371e00402a29405854ccc05ccdc3800a4002266e3c0080545281bad3018002375c602c0022c60320026600e6eacc060c064c064c064c06400800cdd6180b80098099baa00a375c602a60246ea801c58dc3a400044646600200200644a66602a0022980103d87a8000133225333014300500213374a90001980c00125eb804cc010010004c05c004c0600048c04c00488c94ccc03cc010c040dd50008a5eb7bdb1804dd5980a18089baa001323300100100322533301300114c103d87a800013233322253330143372200e0062a66602866e3c01c00c4cdd2a4000660306e980092f5c02980103d87a8000133006006001375c60240026eacc04c004c05c008c054004dc3a400460166ea8004c038c03c00cc034008c030008c030004c01cdd50008a4c26cac6eb80055cd2ab9d5573caae7d5d02ba15745",
"hash": "675eda685b40c32d3d2413fd2027d9f0cd7a07dcb3015fb70c5dc28d"
},
{
"title": "oneshot.gift_card.mint",
@ -121,11 +124,14 @@
}
}
],
"compiledCode": "5902750101003232323232323223222533300532323232323232323232532333010300500613232323232325333016300730173754002264a66602e601860306ea80044c8c94ccc070c07c0084c94ccc068cdc39bad301c002480044cdc780080c0a50375c60340022c603a002660160066eb8c070c064dd50008b1804980c1baa3009301837546036603860306ea8c06cc060dd50008b198039bac301a00223375e601260306ea8004014dd5980c980d180d180d180d000980a9baa00d3017301800230160013012375400e2a666020600200c2646464a66602660080022a66602c602a6ea802c540085854ccc04cc02000454ccc058c054dd50058a8010b0b18099baa00a1323232325333018301b00213232533301730083018375401e2a66602e601060306ea8cc0240148cdd79805980d1baa00101515333017300c00113371e00402a29405854ccc05ccdc3800a4002266e3c0080545281bad3018002375c602c0022c60320026600e6eacc060c064c064c064c06400800cdd6180b80098099baa00b375c602a60246ea801c58dc3a400044646600200200644a66602a0022980103d87a8000132325333014300500213374a90001980c00125eb804cc010010004c064008c05c0048c04c00488c94ccc03cc010c040dd50008a5eb7bdb1804dd5980a18089baa001323300100100322533301300114c103d87a800013232323253330143372200e0042a66602866e3c01c0084cdd2a4000660306e980052f5c02980103d87a80001330060060033756602a0066eb8c04c008c05c008c054004dc3a400460166ea8004c038c03c008c034004c034008c02c004c01cdd50008a4c26cac6eb80055cd2ab9d5573caae7d5d02ba15745",
"hash": "e8498b6e37da9406494b7512fab69256e7c25204130909fae35822a2"
"compiledCode": "5902730101003232323232323223222533300532323232323232323232532333010300500613233223232325333016300730173754002264a66602e601860306ea80044c8c94ccc070c07c0084c94ccc068cdc39bad301c002480044cdc780080c0a50375c60340022c603a002660160066eb8c070c064dd50008b1804980c1baa3009301837546036603860306ea8c06cc060dd50008b198039bac301a00223375e601260306ea8004014dd5980c980d180d180d180d000980a9baa00c3016001301630170013012375400e2a666020600200c2646464a66602660080022a66602c602a6ea802c0085854ccc04cc02000454ccc058c054dd50058010b0b18099baa00a1323232325333018301b00213232533301730083018375401e2a66602e601060306ea8cc0240148cdd79805980d1baa00101515333017300c00113371e00402a29405854ccc05ccdc3800a4002266e3c0080545281bad3018002375c602c0022c60320026600e6eacc060c064c064c064c06400800cdd6180b80098099baa00a375c602a60246ea801c58dc3a400044646600200200644a66602a0022980103d87a8000133225333014300500213374a90001980c00125eb804cc010010004c05c004c0600048c04c00488c94ccc03cc010c040dd50008a5eb7bdb1804dd5980a18089baa001323300100100322533301300114c103d87a800013233322253330143372200e0062a66602866e3c01c00c4cdd2a4000660306e980092f5c02980103d87a8000133006006001375c60240026eacc04c004c05c008c054004dc3a400460166ea8004c038c03c00cc034008c030008c030004c01cdd50008a4c26cac6eb80055cd2ab9d5573caae7d5d02ba15745",
"hash": "675eda685b40c32d3d2413fd2027d9f0cd7a07dcb3015fb70c5dc28d"
},
{
"title": "oneshot.gift_card.else",
"redeemer": {
"schema": {}
},
"parameters": [
{
"title": "token_name",
@ -140,8 +146,8 @@
}
}
],
"compiledCode": "5902750101003232323232323223222533300532323232323232323232532333010300500613232323232325333016300730173754002264a66602e601860306ea80044c8c94ccc070c07c0084c94ccc068cdc39bad301c002480044cdc780080c0a50375c60340022c603a002660160066eb8c070c064dd50008b1804980c1baa3009301837546036603860306ea8c06cc060dd50008b198039bac301a00223375e601260306ea8004014dd5980c980d180d180d180d000980a9baa00d3017301800230160013012375400e2a666020600200c2646464a66602660080022a66602c602a6ea802c540085854ccc04cc02000454ccc058c054dd50058a8010b0b18099baa00a1323232325333018301b00213232533301730083018375401e2a66602e601060306ea8cc0240148cdd79805980d1baa00101515333017300c00113371e00402a29405854ccc05ccdc3800a4002266e3c0080545281bad3018002375c602c0022c60320026600e6eacc060c064c064c064c06400800cdd6180b80098099baa00b375c602a60246ea801c58dc3a400044646600200200644a66602a0022980103d87a8000132325333014300500213374a90001980c00125eb804cc010010004c064008c05c0048c04c00488c94ccc03cc010c040dd50008a5eb7bdb1804dd5980a18089baa001323300100100322533301300114c103d87a800013232323253330143372200e0042a66602866e3c01c0084cdd2a4000660306e980052f5c02980103d87a80001330060060033756602a0066eb8c04c008c05c008c054004dc3a400460166ea8004c038c03c008c034004c034008c02c004c01cdd50008a4c26cac6eb80055cd2ab9d5573caae7d5d02ba15745",
"hash": "e8498b6e37da9406494b7512fab69256e7c25204130909fae35822a2"
"compiledCode": "5902730101003232323232323223222533300532323232323232323232532333010300500613233223232325333016300730173754002264a66602e601860306ea80044c8c94ccc070c07c0084c94ccc068cdc39bad301c002480044cdc780080c0a50375c60340022c603a002660160066eb8c070c064dd50008b1804980c1baa3009301837546036603860306ea8c06cc060dd50008b198039bac301a00223375e601260306ea8004014dd5980c980d180d180d180d000980a9baa00c3016001301630170013012375400e2a666020600200c2646464a66602660080022a66602c602a6ea802c0085854ccc04cc02000454ccc058c054dd50058010b0b18099baa00a1323232325333018301b00213232533301730083018375401e2a66602e601060306ea8cc0240148cdd79805980d1baa00101515333017300c00113371e00402a29405854ccc05ccdc3800a4002266e3c0080545281bad3018002375c602c0022c60320026600e6eacc060c064c064c064c06400800cdd6180b80098099baa00a375c602a60246ea801c58dc3a400044646600200200644a66602a0022980103d87a8000133225333014300500213374a90001980c00125eb804cc010010004c05c004c0600048c04c00488c94ccc03cc010c040dd50008a5eb7bdb1804dd5980a18089baa001323300100100322533301300114c103d87a800013233322253330143372200e0062a66602866e3c01c00c4cdd2a4000660306e980092f5c02980103d87a8000133006006001375c60240026eacc04c004c05c008c054004dc3a400460166ea8004c038c03c00cc034008c030008c030004c01cdd50008a4c26cac6eb80055cd2ab9d5573caae7d5d02ba15745",
"hash": "675eda685b40c32d3d2413fd2027d9f0cd7a07dcb3015fb70c5dc28d"
}
],
"definitions": {
@ -155,6 +161,10 @@
"Int": {
"dataType": "integer"
},
"SpendTokenName": {
"title": "SpendTokenName",
"dataType": "bytes"
},
"cardano/transaction/OutputReference": {
"title": "OutputReference",
"description": "An `OutputReference` is a unique reference to an output on-chain. The `output_index`\n corresponds to the position in the output list of the transaction (identified by its id)\n that produced that output",

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,4 @@
import type { CIP30Interface } from '@blaze-cardano/wallet';
// See https://kit.svelte.dev/docs/types#app
// See https://svelte.dev/docs/kit/types#app.d.ts
// for information about these interfaces
declare global {
namespace App {
@ -12,22 +10,4 @@ declare global {
}
}
type WalletOption = {
name: string;
icon: string;
apiVersion: string;
enable(): Promise<CIP30Interface>;
isEnabled(): Promise<boolean>;
};
type Cardano = {
[key: string]: WalletOption;
};
declare global {
interface Window {
cardano?: Cardano;
}
}
export {};

View File

@ -6,7 +6,7 @@
children: Snippet<[]>;
}
let { id, children, ...props }: Props = $props();
let { id, children, value = $bindable(), ...props }: Props = $props();
</script>
<div>
@ -14,6 +14,7 @@
{@render children()}
</label>
<input
bind:value
{...props}
{id}
class="block w-full appearance-none rounded-md border border-gray-200 bg-gray-50 px-3 py-2 text-gray-900 placeholder-gray-400 focus:border-blue-500 focus:bg-white focus:outline-none focus:ring-blue-500 sm:text-sm"

View File

@ -1,11 +1,38 @@
import {
applyDoubleCborEncoding,
applyParamsToScript,
Constr,
fromText,
validatorToAddress,
validatorToScriptHash,
type MintingPolicy,
type OutRef,
type SpendingValidator
} from '@lucid-evolution/lucid';
import blueprint from '../../plutus.json' assert { type: 'json' };
export type Validators = {
giftCard: string;
};
export type LocalCache = {
tokenName: string;
giftADA: string;
lockTxHash: string;
parameterizedValidators: AppliedValidators;
};
export type AppliedValidators = {
redeem: SpendingValidator;
giftCard: MintingPolicy;
policyId: string;
lockAddress: string;
};
export function readValidators(): Validators {
const giftCard = blueprint.validators.find((v) => v.title === 'oneshot.gift_card.spend');
const giftCard = blueprint.validators.find(
(v) => v.title === 'oneshot.gift_card.spend'
);
if (!giftCard) {
throw new Error('Gift Card validator not found');
@ -15,3 +42,36 @@ export function readValidators(): Validators {
giftCard: giftCard.compiledCode
};
}
export function applyParams(
tokenName: string,
outputReference: OutRef,
validator: string
): AppliedValidators {
const outRef = new Constr(0, [
new Constr(0, [outputReference.txHash]),
BigInt(outputReference.outputIndex)
]);
const giftCard = applyParamsToScript(validator, [
fromText(tokenName),
outRef
]);
const policyId = validatorToScriptHash({
type: 'PlutusV2',
script: giftCard
});
const lockAddress = validatorToAddress('Preprod', {
type: 'PlutusV2',
script: giftCard
});
return {
redeem: { type: 'PlutusV2', script: applyDoubleCborEncoding(giftCard) },
giftCard: { type: 'PlutusV2', script: applyDoubleCborEncoding(giftCard) },
policyId,
lockAddress
};
}

View File

@ -0,0 +1,43 @@
import { createWeldInstance, type WeldConfig } from '@ada-anvil/weld';
import { getContext, setContext } from 'svelte';
export class Weld {
weld = createWeldInstance();
// Use the $state rune to create a reactive object for each Weld store
config = $state(this.weld.config.getState());
wallet = $state(this.weld.wallet.getState());
extensions = $state(this.weld.extensions.getState());
constructor(persist?: Partial<WeldConfig>) {
this.weld.config.update({ updateInterval: 2000 });
if (persist) this.weld.persist(persist);
$effect(() => {
this.weld.init();
// Subscribe to Weld stores and update reactive objects when changse occur
// Note: No need to use subscribeWithSelector as $state objects are deeply reactive
this.weld.config.subscribe((s) => (this.config = s));
this.weld.wallet.subscribe((s) => (this.wallet = s));
this.weld.extensions.subscribe((s) => (this.extensions = s));
return () => this.weld.cleanup();
});
}
}
// Use the context API to scope weld stores and prevent unwanted sharing
// of data between clients when rendering on the server
const weldKey = Symbol('weld');
export function setWeldContext(persist?: Partial<WeldConfig>) {
const value = new Weld(persist);
setContext(weldKey, value);
return value;
}
export function getWeldContext() {
return getContext<ReturnType<typeof setWeldContext>>(weldKey);
}

View File

@ -1,5 +1,11 @@
<script>
<script lang="ts">
import '../app.css';
import { setWeldContext } from '$lib/wallet.svelte';
let { children } = $props();
setWeldContext({ enablePersistence: true });
</script>
<slot></slot>
{@render children()}

View File

@ -1,10 +1,26 @@
<script lang="ts">
import { Blaze, Blockfrost, WebWallet } from '@blaze-cardano/sdk';
import { onMount } from 'svelte';
import { getWeldContext } from '$lib/wallet.svelte';
import {
Lucid,
Blockfrost,
type LucidEvolution,
Data,
Constr,
fromText
} from '@lucid-evolution/lucid';
// Components
import Input from '$lib/components/Input.svelte';
import Button from '$lib/components/Button.svelte';
// Utils
import {
applyParams,
type AppliedValidators,
type LocalCache
} from '$lib/utils';
// Local Types
import type { PageData } from './$types';
@ -15,30 +31,167 @@
let { data }: Props = $props();
// Page Local State
let blaze: Blaze<Blockfrost, WebWallet> | undefined = $state();
const weld = getWeldContext();
const displayedBalance = $derived(weld.wallet.balanceAda?.toFixed(2) ?? '-');
let blockfrostAPIKey = $state('');
let tokenName = $state('');
let giftADA: string | undefined = $state();
let lockTxHash: string | undefined = $state();
let unlockTxHash: string | undefined = $state();
let parameterizedContracts: AppliedValidators | undefined = $state();
async function setupBlaze(e: Event) {
let waitingLockTx = $state(false);
let waitingUnlockTx = $state(false);
let lucid: LucidEvolution | undefined = $state();
onMount(() => {
weld.wallet.connect('eternl');
});
async function setupBlockfrost(e: Event) {
e.preventDefault();
const walletApi = await window.cardano?.eternl.enable();
if (walletApi) {
blaze = await Blaze.from(
new Blockfrost({ network: 'cardano-preview', projectId: blockfrostAPIKey }),
new WebWallet(walletApi)
lucid = await Lucid(
new Blockfrost(
'https://cardano-preprod.blockfrost.io/api/v0',
blockfrostAPIKey
),
'Preprod'
);
}
const cache = localStorage.getItem('cache');
if (cache) {
const localCache: LocalCache = JSON.parse(cache);
tokenName = localCache.tokenName;
giftADA = localCache.giftADA;
parameterizedContracts = localCache.parameterizedValidators;
lockTxHash = localCache.lockTxHash;
}
function submitTokenName(e: Event) {
// @ts-expect-error this is normal
lucid.selectWallet.fromAPI(weld.wallet.handler!.enabledApi);
}
async function submitTokenName(e: Event) {
e.preventDefault();
console.log('TODO: apply params to raw validators');
const utxos = await lucid!.wallet().getUtxos()!;
const utxo = utxos[0];
const outputReference = {
txHash: utxo.txHash,
outputIndex: utxo.outputIndex
};
const contracts = applyParams(tokenName, outputReference, data.validator);
parameterizedContracts = contracts;
}
async function createGiftCard(e: Event) {
e.preventDefault();
waitingLockTx = true;
try {
const lovelace = Number(giftADA) * 1000000;
const assetName = `${parameterizedContracts!.policyId}${fromText(
tokenName
)}`;
// Action::Mint
const mintRedeemer = Data.to(new Constr(0, []));
const utxos = await lucid!.wallet().getUtxos()!;
const utxo = utxos[0];
const tx = await lucid!
.newTx()
.collectFrom([utxo])
.attach.MintingPolicy(parameterizedContracts!.giftCard)
.mintAssets({ [assetName]: BigInt(1) }, mintRedeemer)
.pay.ToContract(
parameterizedContracts!.lockAddress,
{ kind: 'inline', value: Data.void() },
{ lovelace: BigInt(lovelace) }
)
.complete();
const txSigned = await tx.sign.withWallet().complete();
const txHash = await txSigned.submit();
const success = await lucid!.awaitTx(txHash);
// Wait a little bit longer so ExhaustedUTxOError doesn't happen
// in the next Tx
setTimeout(() => {
waitingLockTx = false;
if (success) {
localStorage.setItem(
'cache',
JSON.stringify({
tokenName,
giftADA,
parameterizedValidators: parameterizedContracts,
lockTxHash: txHash
})
);
lockTxHash = txHash;
}
}, 3000);
} catch {
waitingLockTx = false;
}
}
async function redeemGiftCard(e: Event) {
e.preventDefault();
waitingUnlockTx = true;
try {
const utxos = await lucid!.utxosAt(parameterizedContracts!.lockAddress);
const assetName = `${parameterizedContracts!.policyId}${fromText(
tokenName
)}`;
// Action::Burn
const burnRedeemer = Data.to(new Constr(1, []));
const tx = await lucid!
.newTx()
.collectFrom(utxos, Data.void())
.attach.MintingPolicy(parameterizedContracts!.giftCard)
.attach.SpendingValidator(parameterizedContracts!.redeem)
.mintAssets({ [assetName]: BigInt(-1) }, burnRedeemer)
.complete();
const txSigned = await tx.sign.withWallet().complete();
const txHash = await txSigned.submit();
const success = await lucid!.awaitTx(txHash);
waitingUnlockTx = false;
if (success) {
localStorage.removeItem('cache');
unlockTxHash = txHash;
}
} catch {
waitingUnlockTx = false;
}
}
</script>
@ -48,29 +201,100 @@
<div class="mx-auto mb-10 mt-20 max-w-2xl">
<div class="mb-10">
<h2 class="text-lg font-semibold text-gray-900">Make a one shot minting and lock contract</h2>
<h2 class="text-lg font-semibold text-gray-900">
Make a one shot minting and lock contract
</h2>
<h3 class="mb-2 mt-4">Gift Card</h3>
<pre class="overflow-x-scroll rounded bg-gray-200 p-2">{data.validator}</pre>
balance: {displayedBalance}
<h3 class="mb-2 mt-4">Gift Card Template</h3>
<pre
class="overflow-x-scroll rounded bg-gray-200 p-2">{data.validator}</pre>
</div>
<div>
{#if blaze}
<form class="mt-10 grid grid-cols-1 gap-y-8" onsubmit={setupBlaze}>
<Input type="password" id="blockfrostAPIKey" bind:value={blockfrostAPIKey}>
{#if !lucid}
<form class="mt-10 grid grid-cols-1 gap-y-8" onsubmit={setupBlockfrost}>
<Input
type="password"
id="blockfrostAPIKey"
bind:value={blockfrostAPIKey}
>
Blockfrost API Key
</Input>
<Button type="submit">Setup Blaze</Button>
<Button type="submit">Setup Wallet</Button>
</form>
{:else}
<form class="mt-10 grid grid-cols-1 gap-y-8" onsubmit={submitTokenName}>
<Input type="text" name="tokenName" id="tokenName" bind:value={tokenName}>Token Name</Input>
<Input
type="text"
name="tokenName"
id="tokenName"
bind:value={tokenName}>Token Name</Input
>
{#if tokenName.length > 0}
<Button type="submit">Make Contracts</Button>
{/if}
</form>
{/if}
{#if lucid && parameterizedContracts}
<h3 class="mb-2 mt-4">New Gift Card</h3>
<pre
class="overflow-x-scroll rounded bg-gray-200 p-2">{parameterizedContracts
.redeem.script}</pre>
<div class="mt-10 grid grid-cols-1 gap-y-8">
<form onsubmit={createGiftCard}>
<Input type="text" name="giftADA" id="giftADA" bind:value={giftADA}>
ADA Amount
</Input>
<Button type="submit" disabled={waitingLockTx || !!lockTxHash}>
{#if waitingLockTx}
Waiting for Tx...
{:else}
Create Gift Card (Locks ADA)
{/if}
</Button>
</form>
{#if lockTxHash}
<h3 class="mb-2 mt-4">ADA Locked</h3>
<a
class="mb-2"
target="_blank"
href={`https://preprod.cardanoscan.io/transaction/${lockTxHash}`}
>
{lockTxHash}
</a>
<form onsubmit={redeemGiftCard}>
<Button type="submit" disabled={waitingLockTx || !!unlockTxHash}>
{#if waitingUnlockTx}
Waiting for Tx...
{:else}
Redeem Gift Card (Unlocks ADA)
{/if}
</Button>
</form>
{/if}
{#if unlockTxHash}
<h3 class="mb-2 mt-4">ADA Unlocked</h3>
<a
class="mb-2"
target="_blank"
href={`https://preprod.cardanoscan.io/transaction/${unlockTxHash}`}
>
{unlockTxHash}
</a>
{/if}
</div>
{/if}
</div>
</div>

View File

@ -3,14 +3,14 @@ import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
// Consult https://svelte.dev/docs/kit/integrations
// for more information about preprocessors
preprocess: vitePreprocess(),
kit: {
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
// adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list.
// If your environment is not supported, or you settled on a specific environment, switch out the adapter.
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
// See https://svelte.dev/docs/kit/adapters for more information about adapters.
adapter: adapter()
}
};

View File

@ -1,3 +1,6 @@
import containerQueries from '@tailwindcss/container-queries';
import forms from '@tailwindcss/forms';
import typography from '@tailwindcss/typography';
import type { Config } from 'tailwindcss';
export default {
@ -7,5 +10,5 @@ export default {
extend: {}
},
plugins: [require('@tailwindcss/typography')]
} as Config;
plugins: [typography, forms, containerQueries]
} satisfies Config;

View File

@ -11,8 +11,8 @@
"strict": true,
"moduleResolution": "bundler"
}
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
// except $lib which is handled by https://kit.svelte.dev/docs/configuration#files
// Path aliases are handled by https://svelte.dev/docs/kit/configuration#alias
// except $lib which is handled by https://svelte.dev/docs/kit/configuration#files
//
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
// from the referenced tsconfig.json - TypeScript does not merge them in

View File

@ -1,6 +1,14 @@
import { sveltekit } from '@sveltejs/kit/vite';
import wasm from 'vite-plugin-wasm';
import topLevelAwait from 'vite-plugin-top-level-await';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [sveltekit()]
plugins: [sveltekit(), wasm(), topLevelAwait()],
server: {
fs: {
// Allow serving files from one level up to the project root
allow: ['plutus.json']
}
}
});