Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Repo to Drift #1623

Merged
merged 43 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
c5ec6dd
Remove unnecessary morpho hyperdrive
ryangoree Oct 7, 2024
39b7839
Symlink drift packages
ryangoree Nov 3, 2024
bb0afeb
Add drift to SDK core
ryangoree Nov 3, 2024
2040ba7
Refactor sdk core to drift
ryangoree Nov 3, 2024
12ba2b0
Update exports
ryangoree Nov 3, 2024
df4c213
Remove unnecessary repetition
ryangoree Nov 4, 2024
d46c5bc
Refactor `setupReadHyperdrive` to Drift
ryangoree Nov 4, 2024
cdc88a4
Remove `syncCacheWithTransaction` in favor of `onMined`
ryangoree Nov 4, 2024
ee562a4
Remove unnecessary type casting
ryangoree Nov 4, 2024
a93a35b
Refactor tests to drift
ryangoree Nov 4, 2024
1339dff
Rename "Models" to "Clients" in sdk core
ryangoree Nov 6, 2024
2d7bfa6
Remove evm-client from sdk core
ryangoree Nov 6, 2024
2019ba2
Add drift to viem sdk
ryangoree Nov 6, 2024
e66521f
Refactor hyperdrive-viem to drift
ryangoree Nov 6, 2024
cc8d745
Remove evm-client from viem sdk
ryangoree Nov 6, 2024
6aed48a
Update appconfig for drift
ryangoree Nov 6, 2024
0631649
Add drift to UI, update SDK usage
ryangoree Nov 6, 2024
6d1bf99
Fix ReadClient
ryangoree Nov 6, 2024
a3eabf6
Remove symlinks, bump drift versions
ryangoree Nov 6, 2024
a5286b1
Add `getHyperdrive` functions
ryangoree Nov 6, 2024
9bb1611
Consolidate `client` and `drift` dirs in sdk core
ryangoree Nov 6, 2024
a3389c5
Add sdk core to sandbox and ui, bump drift-viem version
ryangoree Nov 6, 2024
393261b
Fix `getHyperdrive` in sdk core for v1.0.14 pools
ryangoree Nov 6, 2024
19a5ead
Change `HyperdriveSdkError` base to `DriftError` for better stack tra…
ryangoree Nov 6, 2024
98fb5a9
Bump drift versions
ryangoree Nov 6, 2024
38a26c6
Refactor UI to use sdk core directly
ryangoree Nov 7, 2024
87b1f5e
Remove unused prop from `OpenLongForm`
ryangoree Nov 7, 2024
ff1f8fb
Bump drift version
ryangoree Nov 8, 2024
d226fba
Copy sdk core to new pkg
ryangoree Nov 8, 2024
b7f7ee7
Switch hyperdrive-viem to new pkg
ryangoree Nov 8, 2024
bdf7c4a
Change version
ryangoree Nov 8, 2024
871ff38
Update changeset config
ryangoree Nov 8, 2024
fd6a6d0
Switch UI to new pkg
ryangoree Nov 8, 2024
a8498f6
Update sandbox
ryangoree Nov 8, 2024
8e5b5c8
Revert hyperdrive-js-core
ryangoree Nov 8, 2024
66d30ab
Remove one-off errors
ryangoree Nov 8, 2024
4fcdbbc
Consolidate hyperdrive dirs
ryangoree Nov 8, 2024
fc346ef
Move `NULL_BYTES` to base, assetId utils to new dir
ryangoree Nov 8, 2024
8b034cf
add `MarketState` to exports
ryangoree Nov 8, 2024
634f6e4
Fix exports in viem sdk
ryangoree Nov 8, 2024
2d07282
Remove comment
ryangoree Nov 9, 2024
dbf5544
Add changesets
ryangoree Nov 10, 2024
33c5b20
Remove overwriting of Registry data type
ryangoree Nov 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
["@delvtech/hyperdrive-wasm", "hyperdrive-wasm"],
["@delvtech/fixed-point-wasm", "fixed-point-wasm"]
],
"linked": [["@delvtech/hyperdrive-viem", "@delvtech/hyperdrive-js-core"]],
"linked": [["@delvtech/hyperdrive-viem", "@delvtech/hyperdrive-js"]],
"access": "restricted",
"baseBranch": "main",
"updateInternalDependencies": "patch",
Expand Down
5 changes: 5 additions & 0 deletions .changeset/gentle-llamas-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@delvtech/hyperdrive-js": patch
---

Initial release of drift based SDK
5 changes: 5 additions & 0 deletions .changeset/tall-plants-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@delvtech/hyperdrive-viem": minor
---

Refactored to drift under the hood
4 changes: 3 additions & 1 deletion apps/hyperdrive-trading/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@
"gen:walletconnect": "bash ./scripts/generate-walletconnect.sh"
},
"dependencies": {
"@delvtech/drift": "^0.0.1-beta.11",
"@delvtech/drift-viem": "^0.0.1-beta.13",
"@delvtech/fixed-point-wasm": "^0.0.6",
"@delvtech/hyperdrive-appconfig": "^0.0.1",
"@delvtech/hyperdrive-viem": "^3.0.6",
"@delvtech/hyperdrive-js": "^0.0.0",
"@headlessui/react": "^2.1.5",
"@heroicons/react": "^2.0.16",
"@radix-ui/react-tooltip": "^1.1.2",
Expand Down
23 changes: 23 additions & 0 deletions apps/hyperdrive-trading/src/drift/getDrift.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { createLruSimpleCache, Drift, DriftOptions } from "@delvtech/drift";
import { viemAdapter } from "@delvtech/drift-viem";
import { getPublicClient, GetPublicClientParameters } from "@wagmi/core";
import { wagmiConfig } from "src/network/wagmiClient";

// 1 minute TTL to match the queryClient's staleTime
export const sdkCache = createLruSimpleCache({ max: 500, ttl: 60_000 });

export function getDriftOptions({
chainId,
}: {
chainId?: number;
} = {}): DriftOptions {
return {
cache: sdkCache,
cacheNamespace: chainId,
};
}

export function getDrift(params?: GetPublicClientParameters): Drift {
const publicClient = getPublicClient(wagmiConfig as any, params) as any;

Check warning on line 21 in apps/hyperdrive-trading/src/drift/getDrift.ts

View workflow job for this annotation

GitHub Actions / verify (lint)

Unexpected any. Specify a different type

Check warning on line 21 in apps/hyperdrive-trading/src/drift/getDrift.ts

View workflow job for this annotation

GitHub Actions / verify (lint)

Unexpected any. Specify a different type
return new Drift(viemAdapter({ publicClient }), getDriftOptions(params));
}
5 changes: 3 additions & 2 deletions apps/hyperdrive-trading/src/hyperdrive/getLpApy.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Block } from "@delvtech/drift";
import { fixed } from "@delvtech/fixed-point-wasm";
import {
appConfig,
getRewardsFn,
HyperdriveConfig,
} from "@delvtech/hyperdrive-appconfig";
import { Block, ReadHyperdrive } from "@delvtech/hyperdrive-viem";
import { ReadHyperdrive } from "@delvtech/hyperdrive-js";
import { getPublicClient } from "@wagmi/core";
import { convertMillisecondsToDays } from "src/base/convertMillisecondsToDays";
import { isForkChain } from "src/chains/isForkChain";
Expand Down Expand Up @@ -45,7 +46,7 @@
readHyperdrive: ReadHyperdrive;
hyperdrive: HyperdriveConfig;
}): Promise<LpApyResult> {
const currentBlock = (await readHyperdrive.network.getBlock()) as Block;
const currentBlock = (await readHyperdrive.drift.getBlock()) as Block;
const currentBlockNumber = currentBlock.blockNumber!;
// Appconfig tells us how many days to look back for historical rates
const numBlocksForHistoricalRate = isForkChain(hyperdrive.chainId)
Expand Down Expand Up @@ -75,7 +76,7 @@
});
lpApy = lpApyResult.lpApy;
netLpApy = lpApy;
const publicClient = getPublicClient(wagmiConfig as any, {

Check warning on line 79 in apps/hyperdrive-trading/src/hyperdrive/getLpApy.ts

View workflow job for this annotation

GitHub Actions / verify (lint)

Unexpected any. Specify a different type
chainId: hyperdrive.chainId,
}) as PublicClient;
const rewardsFn = getRewardsFn({
Expand Down
90 changes: 0 additions & 90 deletions apps/hyperdrive-trading/src/hyperdrive/getReadHyperdrive.ts

This file was deleted.

85 changes: 0 additions & 85 deletions apps/hyperdrive-trading/src/hyperdrive/getReadWriteHyperdrive.ts

This file was deleted.

7 changes: 4 additions & 3 deletions apps/hyperdrive-trading/src/hyperdrive/getYieldSourceRate.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Block } from "@delvtech/drift";
import { fixed } from "@delvtech/fixed-point-wasm";
import {
AppConfig,
findHyperdriveConfig,
getRewardsFn,
HyperdriveConfig,
} from "@delvtech/hyperdrive-appconfig";
import { Block, ReadHyperdrive } from "@delvtech/hyperdrive-viem";
import { ReadHyperdrive } from "@delvtech/hyperdrive-js";
import { getPublicClient } from "@wagmi/core";
import { convertMillisecondsToDays } from "src/base/convertMillisecondsToDays";
import { isForkChain } from "src/chains/isForkChain";
Expand All @@ -16,7 +17,7 @@
readHyperdrive: ReadHyperdrive,
appConfig: AppConfig,
): Promise<{ rate: bigint; ratePeriodDays: number; netRate: bigint }> {
const hyperdriveChainId = await readHyperdrive.network.getChainId();
const hyperdriveChainId = await readHyperdrive.drift.getChainId();
const hyperdrive = findHyperdriveConfig({
hyperdriveChainId,
hyperdriveAddress: readHyperdrive.address,
Expand All @@ -28,7 +29,7 @@
hyperdrive,
});

const currentBlock = (await readHyperdrive.network.getBlock()) as Block;
const currentBlock = (await readHyperdrive.drift.getBlock()) as Block;
const initializationBlock = hyperdrive.initializationBlock;

const isPoolYoungerThanOneRatePeriod =
Expand Down Expand Up @@ -84,7 +85,7 @@
appConfig,
});
if (rewardsFn) {
const publicClient = getPublicClient(wagmiConfig as any, {

Check warning on line 88 in apps/hyperdrive-trading/src/hyperdrive/getYieldSourceRate.ts

View workflow job for this annotation

GitHub Actions / verify (lint)

Unexpected any. Specify a different type
chainId: hyperdrive.chainId,
}) as PublicClient;
const rewards = await rewardsFn(publicClient);
Expand Down
57 changes: 12 additions & 45 deletions apps/hyperdrive-trading/src/registry/data.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,19 @@
import { Hex } from "viem";

export const statusById = {
"1": "active",
"2": "sunset",
} as const;

/**
* An ID used to represent status in the registry.
*/
export type StatusId = keyof typeof statusById;

/**
* The status of an instance or factory in the registry.
*/
export type Status = (typeof statusById)[StatusId];

/**
* The decoded data of an instance in the registry.
*/
export interface InstanceData {
status: Status;
}

/**
* Decodes the `data` field of an instance in the registry according to the
* ElementDAO registry schema.
*/
export function decodeInstanceData(data: Hex): InstanceData {
const statusId = BigInt(data).toString() as StatusId;
return {
status: statusById[statusId],
};
}

/**
* The decoded data of a factory in the registry.
*/
export interface FactoryData {
status: Status;
}
export type Status = "active" | "sunset";

/**
* Decodes the `data` field of a factory in the registry according to the
* ElementDAO registry schema.
* Returns the status of an instance or factory in the registry according to the
* ElementDAO registry data schema.
*/
export function decodeFactoryData(data: Hex): FactoryData {
const statusId = BigInt(data).toString() as StatusId;
return {
status: statusById[statusId],
};
export function getStatus(statusId: bigint): Status {
switch (statusId) {
case 1n:
return "active";
case 2n:
return "sunset";
default:
throw new Error(`Unknown status ID: ${statusId}`);
}
}
4 changes: 0 additions & 4 deletions apps/hyperdrive-trading/src/sdk/sdkCache.ts

This file was deleted.

Loading
Loading