Skip to content

Commit

Permalink
Misc cleanup (#1105)
Browse files Browse the repository at this point in the history
* Move artifacts dependency to core

* Format comment for typedoc and tooltips

* Remove confusing  indirection

* Cleanup compliance folder

* Inline SDK options and callback to infer types
  • Loading branch information
ryangoree authored May 29, 2024
1 parent 8c60425 commit 9a8dd75
Show file tree
Hide file tree
Showing 24 changed files with 214 additions and 190 deletions.
2 changes: 1 addition & 1 deletion apps/hyperdrive-trading/src/ui/app/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createRouter, RouterProvider } from "@tanstack/react-router";

// Import the generated route tree
import { routeTree } from "src/routeTree.gen";
import { TermsOfUseAndPrivacyPolicyModal } from "src/ui/compliance/TermsOfUseAndPrivacyPolicyModal/TermsOfUseAndPrivacyPolicyModal";
import { TermsOfUseAndPrivacyPolicyModal } from "src/ui/compliance/TermsOfUseAndPrivacyPolicyModal";
import { useClearLocalStorageOnNewVersion } from "src/ui/version/useClearLocalStorageOnNewVersion";

// Create a new router instance
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ReactElement } from "react";
import { Modal } from "src/ui/base/components/Modal/Modal";
import { useTermsOfUseAndPrivacyPolicyAccepted } from "src/ui/compliance/hooks/useTermsOfUseAndPrivacyPolicyAccepted";
import { privacyPolicyUrl } from "src/ui/compliance/privacyPolicy";
import { termsOfUseUrl } from "src/ui/compliance/termsOfUse";
import { useTermsOfUseAndPrivacyPolicyAccepted } from "src/ui/compliance/useTermsOfUseAndPrivacyPolicyAccepted";

export function TermsOfUseAndPrivacyPolicyModal(): ReactElement {
const {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ContractWriteOptions } from "@delvtech/hyperdrive-viem";
import { useAddRecentTransaction } from "@rainbow-me/rainbowkit";
import { MutationStatus } from "@tanstack/query-core";
import { useMutation, useQueryClient } from "@tanstack/react-query";
Expand All @@ -8,7 +7,7 @@ import TransactionToast from "src/ui/base/components/Toaster/TransactionToast";
import { SUCCESS_TOAST_DURATION } from "src/ui/base/toasts";
import { useReadWriteHyperdrive } from "src/ui/hyperdrive/hooks/useReadWriteHyperdrive";
import { toastWarpcast } from "src/ui/social/WarpcastToast";
import { Address, Hash } from "viem";
import { Address } from "viem";
import { usePublicClient } from "wagmi";

interface UseOpenLongOptions {
Expand Down Expand Up @@ -61,38 +60,35 @@ export function useOpenLong({
return;
}

const options: ContractWriteOptions = {
value: ethValue,
};

function onTransactionCompleted(txHash: Hash) {
queryClient.invalidateQueries();
toast.success(
<TransactionToast message="Long opened" txHash={txHash} />,
{ id: txHash, duration: SUCCESS_TOAST_DURATION },
);
setTimeout(() => {
toastWarpcast();
}, SUCCESS_TOAST_DURATION);
onExecuted?.(txHash);
}

const hash = await readWriteHyperdrive.openLong({
args: {
amount,
minBondsOut: minBondsOut,
minBondsOut,
destination,
minVaultSharePrice: minSharePrice,
asBase,
},
options,
onTransactionCompleted,
options: {
value: ethValue,
},
onTransactionCompleted: (txHash) => {
queryClient.invalidateQueries();
toast.success(
<TransactionToast message="Long opened" txHash={txHash} />,
{ id: txHash, duration: SUCCESS_TOAST_DURATION },
);
setTimeout(() => {
toastWarpcast();
}, SUCCESS_TOAST_DURATION);
onExecuted?.(txHash);
},
});

toast.loading(
<TransactionToast txHash={hash} message="Opening a Long..." />,
{ id: hash },
);

onSubmitted?.(hash);

addTransaction({
Expand Down
5 changes: 2 additions & 3 deletions packages/hyperdrive-js-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@
"typecheck": "tsc --noEmit"
},
"peerDependencies": {
"@delvtech/evm-client": "^0.5.1",
"@delvtech/hyperdrive-artifacts": "^0.3.0"
"@delvtech/evm-client": "^0.5.1"
},
"dependencies": {
"@delvtech/hyperdrive-artifacts": "^0.3.0",
"@delvtech/hyperdrive-wasm": "^0.14.0",
"lodash.groupby": "^4.6.0",
"lodash.mapvalues": "^4.6.0"
},
"devDependencies": {
"@delvtech/evm-client": "^0.5.1",
"@delvtech/hyperdrive-artifacts": "^0.3.0",
"@hyperdrive/eslint-config": "*",
"@hyperdrive/prettier-config": "*",
"@hyperdrive/tsconfig": "*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,25 @@ import { Abi } from "abitype";
* This decorator accepts an argument of cache keys to clear. By default it will
* clear the entire cache.
*
* Example:
*
* @example
* ```ts
* class ReadWriteFooBar extends CachedReadWriteContract {
*
* // Listen for tx complete and clear the entire cache
* @syncCacheWithTransaction()
* setFoo() {
* return this.contract.write("setFoo", []);
* return this.contract.write("setFoo", []);
* }
*
* // Listen for tx complete and clear a partial or specific cache entry
* @syncCacheWithTransaction({ cacheEntries: [{ functionName: "getBar" }]})
* setBar() {
* return this.contract.write("setBar", []);
* return this.contract.write("setBar", []);
* }
* }
* ```
*
* @internal
*/
export function syncCacheWithTransaction<TAbi extends Abi>(options?: {
cacheEntries?: {
Expand Down
1 change: 0 additions & 1 deletion packages/hyperdrive-viem/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"viem": "^2.7.8"
},
"dependencies": {
"@delvtech/hyperdrive-artifacts": "^0.3.0",
"@delvtech/hyperdrive-js-core": "^2.0.0",
"@delvtech/evm-client-viem": "^0.6.1"
},
Expand Down

This file was deleted.

This file was deleted.

19 changes: 12 additions & 7 deletions packages/hyperdrive-viem/src/hyperdrive/ReadHyperdrive.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { createNetwork } from "@delvtech/evm-client-viem";
import {
createCachedReadContract,
createNetwork,
} from "@delvtech/evm-client-viem";
import {
ReadHyperdrive as ReadHyperdriveBase,
ReadHyperdriveOptions as ReadHyperdriveOptionsBase,
} from "@delvtech/hyperdrive-js-core";
import { createReadContractFactory } from "src/evm-client/createReadContractFactory";
import { ReadModelOptions } from "src/model/types";

export interface ReadHyperdriveOptions
Expand All @@ -20,11 +22,14 @@ export class ReadHyperdrive extends ReadHyperdriveBase {
super({
address,
cache,
contractFactory: createReadContractFactory({
publicClient,
cache,
namespace,
}),
contractFactory: (options) => {
return createCachedReadContract({
publicClient,
cache,
namespace,
...options,
});
},
name,
namespace,
network: createNetwork(publicClient),
Expand Down
21 changes: 13 additions & 8 deletions packages/hyperdrive-viem/src/hyperdrive/ReadWriteHyperdrive.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { createNetwork } from "@delvtech/evm-client-viem";
import {
createCachedReadWriteContract,
createNetwork,
} from "@delvtech/evm-client-viem";
import {
ReadWriteHyperdrive as ReadWriteHyperdriveBase,
ReadWriteHyperdriveOptions as ReadWriteHyperdriveOptionsBase,
} from "@delvtech/hyperdrive-js-core";
import { createReadWriteContractFactory } from "src/evm-client/createReadWriteContractFactory";
import { ReadWriteModelOptions } from "src/model/types";

export interface ReadWriteHyperdriveOptions
Expand All @@ -21,12 +23,15 @@ export class ReadWriteHyperdrive extends ReadWriteHyperdriveBase {
super({
address,
cache,
contractFactory: createReadWriteContractFactory({
publicClient,
walletClient,
cache,
namespace,
}),
contractFactory: (options) => {
return createCachedReadWriteContract({
publicClient,
walletClient,
cache,
namespace,
...options,
});
},
name,
namespace,
network: createNetwork(publicClient),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { createNetwork } from "@delvtech/evm-client-viem";
import {
createCachedReadContract,
createNetwork,
} from "@delvtech/evm-client-viem";
import { ReadErc4626Hyperdrive as ReadErc4626HyperdriveBase } from "@delvtech/hyperdrive-js-core";
import { createReadContractFactory } from "src/evm-client/createReadContractFactory";
import { ReadHyperdriveOptions } from "src/hyperdrive/ReadHyperdrive";

export class ReadErc4626Hyperdrive extends ReadErc4626HyperdriveBase {
Expand All @@ -14,11 +16,14 @@ export class ReadErc4626Hyperdrive extends ReadErc4626HyperdriveBase {
super({
address,
cache,
contractFactory: createReadContractFactory({
publicClient,
cache,
namespace,
}),
contractFactory: (options) => {
return createCachedReadContract({
publicClient,
cache,
namespace,
...options,
});
},
name,
namespace,
network: createNetwork(publicClient),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { createNetwork } from "@delvtech/evm-client-viem";
import {
createCachedReadContract,
createNetwork,
} from "@delvtech/evm-client-viem";
import { ReadMockErc4626Hyperdrive as ReadMockErc4626HyperdriveBase } from "@delvtech/hyperdrive-js-core";
import { createReadContractFactory } from "src/evm-client/createReadContractFactory";
import { ReadHyperdriveOptions } from "src/hyperdrive/ReadHyperdrive";

export class ReadMockErc4626Hyperdrive extends ReadMockErc4626HyperdriveBase {
Expand All @@ -14,11 +16,14 @@ export class ReadMockErc4626Hyperdrive extends ReadMockErc4626HyperdriveBase {
super({
address,
cache,
contractFactory: createReadContractFactory({
publicClient,
cache,
namespace,
}),
contractFactory: (options) => {
return createCachedReadContract({
publicClient,
cache,
namespace,
...options,
});
},
name,
namespace,
network: createNetwork(publicClient),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { createNetwork } from "@delvtech/evm-client-viem";
import {
createCachedReadWriteContract,
createNetwork,
} from "@delvtech/evm-client-viem";
import { ReadWriteErc4626Hyperdrive as ReadWriteErc4626HyperdriveBase } from "@delvtech/hyperdrive-js-core";
import { createReadWriteContractFactory } from "src/evm-client/createReadWriteContractFactory";
import { ReadWriteHyperdriveOptions } from "src/hyperdrive/ReadWriteHyperdrive";

export class ReadWriteErc4626Hyperdrive extends ReadWriteErc4626HyperdriveBase {
Expand All @@ -15,12 +17,15 @@ export class ReadWriteErc4626Hyperdrive extends ReadWriteErc4626HyperdriveBase {
super({
address,
cache,
contractFactory: createReadWriteContractFactory({
publicClient,
walletClient,
cache,
namespace,
}),
contractFactory: (options) => {
return createCachedReadWriteContract({
publicClient,
walletClient,
cache,
namespace,
...options,
});
},
name,
namespace,
network: createNetwork(publicClient),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { createNetwork } from "@delvtech/evm-client-viem";
import {
createCachedReadWriteContract,
createNetwork,
} from "@delvtech/evm-client-viem";
import { ReadWriteMockErc4626Hyperdrive as ReadWriteMockErc4626HyperdriveBase } from "@delvtech/hyperdrive-js-core";
import { createReadWriteContractFactory } from "src/evm-client/createReadWriteContractFactory";
import { ReadWriteHyperdriveOptions } from "src/hyperdrive/ReadWriteHyperdrive";

export class ReadWriteMockErc4626Hyperdrive extends ReadWriteMockErc4626HyperdriveBase {
Expand All @@ -15,12 +17,15 @@ export class ReadWriteMockErc4626Hyperdrive extends ReadWriteMockErc4626Hyperdri
super({
address,
cache,
contractFactory: createReadWriteContractFactory({
publicClient,
walletClient,
cache,
namespace,
}),
contractFactory: (options) => {
return createCachedReadWriteContract({
publicClient,
walletClient,
cache,
namespace,
...options,
});
},
name,
namespace,
network: createNetwork(publicClient),
Expand Down
Loading

0 comments on commit 9a8dd75

Please sign in to comment.