Skip to content

Commit

Permalink
wip: metadata for blaze
Browse files Browse the repository at this point in the history
  • Loading branch information
cjkoepke committed Aug 15, 2024
1 parent 52481fd commit 3cd4645
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 34 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/@types/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { QueryProvider } from "../Abstracts/QueryProvider.abstract.class.js";
import { TWalletBuilder } from "./txbuilders.js";
import type { QueryProvider } from "../Abstracts/QueryProvider.abstract.class.js";
import type { TWalletBuilder } from "./txbuilders.js";

/**
* The SundaeSDK options argument when creating a new instance.
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/TxBuilders/TxBuilder.Blaze.V1.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ export class TxBuilderBlazeV1 extends TxBuilderV1 {
"0x"
),
});
data.metadata()?.setMetadata(map);
data.setMetadata(Core.Metadata.fromCore(map));
tx.setAuxiliaryData(data);

return this.completeTx({
Expand Down
7 changes: 2 additions & 5 deletions packages/demo/src/components/Actions/Actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@ import { useAppState } from "../../state/context";
import { CancelSwap } from "./modules/CancelSwap";
import { CreatePool } from "./modules/CreatePool";
import { Deposit } from "./modules/Deposit";
import { Lock } from "./modules/LockAssets";
import { Migrate } from "./modules/MigrateV1LiquidityToV3";
import { OrderRouting } from "./modules/OrderRouting";
import { SwapAB } from "./modules/SwapAB";
import { SwapBA } from "./modules/SwapBA";
import { Unlock } from "./modules/UnlockAssets";
import { UnlockV1 } from "./modules/UnlockAssetsV1";
import { UpdateSwap } from "./modules/UpdateSwap";
import { Withdraw } from "./modules/Withdraw";
import { Zap } from "./modules/Zap";
Expand Down Expand Up @@ -117,9 +114,9 @@ export const Actions: FC = () => {
<h4 className="w-32">Yield Farming</h4>
<hr className="my-10 w-full" />
</div>
<Lock setFees={setFees} setCBOR={setCBOR} submit={submit} />
{/* <Lock setFees={setFees} setCBOR={setCBOR} submit={submit} />
<Unlock setFees={setFees} setCBOR={setCBOR} submit={submit} />
<UnlockV1 setFees={setFees} setCBOR={setCBOR} submit={submit} />
<UnlockV1 setFees={setFees} setCBOR={setCBOR} submit={submit} /> */}

<div className="col-span-2 flex items-center justify-between gap-2">
<h4 className="w-24">Taste Tests</h4>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
QueryProviderSundaeSwapLegacy,
} from "@sundaeswap/core";
import { FC, useCallback, useState } from "react";

import {
V3_CONTRACT_POOL_RBERRY,
V3_CONTRACT_POOL_TINDY,
Expand All @@ -26,6 +27,8 @@ export const Migrate: FC<IActionArgs> = ({ setCBOR, setFees, submit }) => {
} = useAppState();
const [migrating, setMigrating] = useState(false);

console.log(SDK);

const handleMigrating = useCallback(async () => {
if (!SDK) {
return;
Expand Down
18 changes: 13 additions & 5 deletions packages/demo/src/components/Actions/modules/OrderRouting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ enum ERoute {
type TDirection = "forward" | "backward";

export const OrderRouting: FC<IActionArgs> = ({ setCBOR, setFees, submit }) => {
const { SDK, ready, activeWalletAddr, useReferral } = useAppState();
const { SDK, ready, activeWalletAddr, useReferral, builderLib } =
useAppState();

const [direction, setDirection] = useState<TDirection>("forward");
const [route, setRoute] = useState<ERoute>(ERoute.V1TOV1);
Expand Down Expand Up @@ -71,8 +72,6 @@ export const OrderRouting: FC<IActionArgs> = ({ setCBOR, setFees, submit }) => {
? v3PoolRberry
: v1PoolRberry;

console.log(swapAPool, swapBPool);

const args: IOrderRouteSwapArgs = {
ownerAddress: activeWalletAddr,
swapA: {
Expand Down Expand Up @@ -120,7 +119,8 @@ export const OrderRouting: FC<IActionArgs> = ({ setCBOR, setFees, submit }) => {
await SDK.builder(
route === ERoute.V3TOV1 || route === ERoute.V3TOV3
? EContractVersion.V3
: EContractVersion.V1
: EContractVersion.V1,
builderLib
)
.orderRouteSwap(args)
.then(async ({ build, fees }) => {
Expand All @@ -143,7 +143,15 @@ export const OrderRouting: FC<IActionArgs> = ({ setCBOR, setFees, submit }) => {
}

setSwapping(false);
}, [SDK, submit, activeWalletAddr, useReferral, route, direction]);
}, [
SDK,
submit,
activeWalletAddr,
useReferral,
route,
direction,
builderLib,
]);

if (!SDK) {
return null;
Expand Down
16 changes: 12 additions & 4 deletions packages/demo/src/components/Settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
QueryProviderSundaeSwapLegacy,
SundaeSDK,
} from "@sundaeswap/core";
import { FC, useEffect, useState } from "react";
import { FC, useEffect } from "react";

import { useAppState } from "../../state/context";

Expand All @@ -14,8 +14,14 @@ const SelectBuilderOption: FC<{
}> = ({ builder, name }) => <option value={builder}>{name}</option>;

const SelectBuilder: FC = () => {
const { setSDK, setBuilderLib, builderLib, useV3Contracts } = useAppState();
const [network, setNetwork] = useState<0 | 1>(0);
const {
setSDK,
setBuilderLib,
builderLib,
useV3Contracts,
network,
setNetwork,
} = useAppState();

const handleTxBuilderLoaderSelect = (key: ETxBuilderType) => {
setBuilderLib(key);
Expand Down Expand Up @@ -66,7 +72,9 @@ const SelectBuilder: FC = () => {
const { Lucid, Blockfrost } = await import("lucid-cardano");
const lucidInstance = await Lucid.new(
new Blockfrost(
"https://cardano-mainnet.blockfrost.io/api/v0/",
`https://cardano-${
network ? "mainnet" : "preview"
}.blockfrost.io/api/v0/`,
network
? // @ts-ignore
window.__APP_CONFIG.blockfrostAPIMainnet
Expand Down
68 changes: 51 additions & 17 deletions packages/demo/src/state/context.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ETxBuilderType, SundaeSDK } from "@sundaeswap/core";
import { C, getAddressDetails } from "lucid-cardano";
import {
Dispatch,
FC,
Expand All @@ -24,6 +23,8 @@ interface IAppState {
setUseReferral: Dispatch<SetStateAction<boolean>>;
useV3Contracts: boolean;
setUseV3Contracts: Dispatch<SetStateAction<boolean>>;
network: 0 | 1;
setNetwork: Dispatch<SetStateAction<0 | 1>>;
}

const defaultState: IAppState = {
Expand All @@ -38,6 +39,8 @@ const defaultState: IAppState = {
setUseReferral: () => {},
useV3Contracts: false,
setUseV3Contracts: () => {},
network: 0,
setNetwork: () => {},
};

const AppState = createContext(defaultState);
Expand All @@ -57,6 +60,7 @@ export const AppStateProvider: FC<
const [builderLib, setBuilderLib] = useState<ETxBuilderType>(
ETxBuilderType.BLAZE
);
const [network, setNetwork] = useState<0 | 1>(0);

useEffect(() => {
(async () => {
Expand All @@ -68,27 +72,55 @@ export const AppStateProvider: FC<
const address =
(await api.getUsedAddresses())?.[0] ??
(await api.getUnusedAddresses())?.[0];
const {
address: { bech32 },
paymentCredential,
} = getAddressDetails(address);
setActiveWalletAddr(bech32);

const keyhash = C.Ed25519KeyHash.from_hex(
paymentCredential?.hash as string
);
setReady(false);
if (builderLib === ETxBuilderType.LUCID) {
const { getAddressDetails, C } = await import("lucid-cardano");
const {
address: { bech32 },
paymentCredential,
} = getAddressDetails(address);
setActiveWalletAddr(bech32);

const enterprise = C.EnterpriseAddress.new(
0,
C.StakeCredential.from_keyhash(keyhash)
)
?.to_address()
.to_bech32("addr_test");
const keyhash = C.Ed25519KeyHash.from_hex(
paymentCredential?.hash as string
);

const enterprise = C.EnterpriseAddress.new(
0,
C.StakeCredential.from_keyhash(keyhash)
)
?.to_address()
.to_bech32("addr_test");

setNonStakedWalletAddr(enterprise);
} else if (builderLib === ETxBuilderType.BLAZE) {
const { Core } = await import("@blaze-cardano/sdk");
const activeAddress = Core.Address.fromString(address);
if (activeAddress) {
setActiveWalletAddr(activeAddress.toBech32());
const paymentHash = activeAddress
.asBase()
?.getPaymentCredential().hash;
const enterprise =
paymentHash &&
new Core.Address({
type: Core.AddressType.EnterpriseKey,
paymentPart: {
hash: Core.Hash28ByteBase16(paymentHash),
type: Core.CredentialType.KeyHash,
},
networkId: network,
});
if (enterprise) {
setNonStakedWalletAddr(enterprise.toBech32());
}
}
}

setNonStakedWalletAddr(enterprise);
setReady(true);
})();
}, []);
}, [builderLib, network]);

return (
<AppState.Provider
Expand All @@ -105,6 +137,8 @@ export const AppStateProvider: FC<
setUseReferral,
useV3Contracts,
setUseV3Contracts,
network,
setNetwork,
...defaultValue,
}}
>
Expand Down

0 comments on commit 3cd4645

Please sign in to comment.