Skip to content

Commit

Permalink
add locking tx
Browse files Browse the repository at this point in the history
  • Loading branch information
MicroProofs committed May 29, 2024
1 parent 165b85a commit 94e17e8
Showing 1 changed file with 53 additions and 11 deletions.
64 changes: 53 additions & 11 deletions src/routes/hardfork/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<script lang="ts">
import { onMount } from 'svelte';
import { v1TunaAmount } from '$lib/store';
import UisPadlock from '~icons/uis/padlock'
import IonFishOutline from '~icons/ion/fish-outline'
import MaterialSymbolsAddShoppingCartSharp from '~icons/material-symbols/add-shopping-cart-sharp'
import { translucent, v1TunaAmount } from '$lib/store';
import UisPadlock from '~icons/uis/padlock';
import IonFishOutline from '~icons/ion/fish-outline';
import MaterialSymbolsAddShoppingCartSharp from '~icons/material-symbols/add-shopping-cart-sharp';
import { Constr, Data, fromText } from 'translucent-cardano';
// types
interface TimeLeft {
Expand All @@ -13,7 +14,8 @@
seconds: number;
}
let timeLeft: TimeLeft;
let lockTxHash: string | undefined;
// parse address transactions / mint transactions or any other data to check how many tuna was sent already
let lockedTuna = 89400;
Expand Down Expand Up @@ -45,9 +47,47 @@
return () => clearInterval(interval);
});
const tunaTx = () => {
const tunaTx = async () => {
const hardforkHash = '';
const tunaV1Hash = '';
const tunaV2Hash = '';
const tunaV2Redeem = new Constr(1, []);
const hardforkRedeem = new Constr(1, [0n, $v1TunaAmount]);
const lockUtxo = (await $translucent?.utxosAtWithUnit(
'',
hardforkHash + fromText('lock_state'),
))!;
const lockDatum = Data.from(lockUtxo[0].datum!) as Constr<bigint>;
const blockheight = lockDatum.fields[0];
const currentLocked = lockDatum.fields[1];
const inputUtxos = (await $translucent?.utxosAtWithUnit(
await $translucent.wallet.address(),
tunaV1Hash + fromText('TUNA'),
))!;
const outputLockDatum = new Constr(0, [blockheight, currentLocked + $v1TunaAmount]);
// add tuna tx logic or import a function to lock tuna here
alert('Locking Tuna');
const lockTx = await $translucent
?.newTx()
.mintAssets({ [tunaV2Hash + fromText('TUNA')]: $v1TunaAmount }, Data.to(tunaV2Redeem))
.collectFrom(lockUtxo, '00')
.collectFrom(inputUtxos)
.withdraw('', 0n, Data.to(hardforkRedeem))
.payToContract('', Data.to(outputLockDatum), { [hardforkHash + fromText('lock_state')]: 1n })
.payToContract('', Data.to(0n), { [tunaV1Hash + fromText('TUNA')]: $v1TunaAmount })
.complete();
const signed = await lockTx?.sign().complete();
await signed?.submit();
lockTxHash = signed?.toHash();
};
</script>

Expand Down Expand Up @@ -83,7 +123,8 @@
<div class="stat-value text-orange-500">0%</div>
</div>

<div class="stat border border-base-100 border-l-8 border-l-green-500 row-start-1 xl:row-start-auto">
<div
class="stat border border-base-100 border-l-8 border-l-green-500 row-start-1 xl:row-start-auto">
<div class="stat-figure text-primary"></div>
<div class="stat-title">Time left</div>

Expand All @@ -103,7 +144,8 @@
</div>
</div>

<div class="col-start-1 row-start-1 xl:col-start-2 card max-w-full xl:min-w-[40vw] justify-center shadow-xl mt-5 bg-base-300">
<div
class="col-start-1 row-start-1 xl:col-start-2 card max-w-full xl:min-w-[40vw] justify-center shadow-xl mt-5 bg-base-300">
<div class="stats bg-base-300 stats-vertical lg:stats-horizontal">
<div class="stat">
<div class="stat-title text-success">$TUNA V1 Available</div>
Expand All @@ -117,7 +159,7 @@
<button class="btn btn-md btn-warning"
><a href={tunaMinswap} target="_blank" class="hidden md:flex">Get v1 $TUNA</a>
<a href={tunaMinswap} target="_blank" class="md:hidden">Buy Some</a>
<MaterialSymbolsAddShoppingCartSharp class="text-black"/></button>
<MaterialSymbolsAddShoppingCartSharp class="text-black" /></button>
{/if}
</div>
<div class="stat-value text-white">{$v1TunaAmount.toLocaleString('en-US')}</div>
Expand All @@ -127,7 +169,7 @@
<div class="stat">
<div class="stat-title text-success">My Locked Tuna</div>
<div class="stat-figure text-primary">
<IonFishOutline class="text-primary text-3xl"/>
<IonFishOutline class="text-primary text-3xl" />
</div>
<div class="stat-value text-white">{lockedTuna.toLocaleString('en-US')}</div>
<div class="stat-actions"></div>
Expand Down

0 comments on commit 94e17e8

Please sign in to comment.