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

chore: update viem #385

Merged
merged 4 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions .changeset/fresh-avocados-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@enzymefinance/api": minor
"@enzymefinance/sdk": minor
---

Updated viem version
6 changes: 3 additions & 3 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
"@enzymefinance/sdk": "workspace:^",
"react": "latest",
"react-dom": "latest",
"viem": "^1.21.4",
"vocs": "latest"
"viem": "^2.7.16",
"vocs": "1.0.0-alpha.41"
},
"devDependencies": {
"@types/node": "^20.10.8"
"@types/node": "^20.11.22"
}
}
10 changes: 5 additions & 5 deletions examples/example-api-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
"start": "tsx src/index.ts"
},
"dependencies": {
"@bufbuild/protobuf": "^1.6.0",
"@connectrpc/connect-node": "^1.3.0",
"@connectrpc/connect-web": "^1.3.0",
"@bufbuild/protobuf": "^1.7.2",
"@connectrpc/connect-node": "^1.4.0",
"@connectrpc/connect-web": "^1.4.0",
"@enzymefinance/api": "workspace:*"
},
"devDependencies": {
"@types/node": "^20.10.8",
"tsx": "^4.7.0",
"@types/node": "^20.11.22",
"tsx": "^4.7.1",
"typescript": "^5.3.3"
}
}
26 changes: 13 additions & 13 deletions examples/example-api-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@
"preview": "vite preview"
},
"dependencies": {
"@bufbuild/protobuf": "^1.6.0",
"@connectrpc/connect-query": "^1.1.3",
"@connectrpc/connect-web": "^1.3.0",
"@bufbuild/protobuf": "^1.7.2",
"@connectrpc/connect-query": "^1.2.0",
"@connectrpc/connect-web": "^1.4.0",
"@enzymefinance/api": "workspace:*",
"@tanstack/react-query": "^5.17.9",
"@tremor/react": "^3.12.2",
"autoprefixer": "^10.4.16",
"postcss": "^8.4.33",
"@tanstack/react-query": "^5.24.1",
"@tremor/react": "^3.14.1",
"autoprefixer": "^10.4.17",
"postcss": "^8.4.35",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"tailwindcss": "^3.4.1"
},
"devDependencies": {
"@types/react": "^18.2.47",
"@types/react-dom": "^18.2.18",
"@types/web": "^0.0.128",
"@types/react": "^18.2.60",
"@types/react-dom": "^18.2.19",
"@types/web": "^0.0.140",
"@vitejs/plugin-react": "^4.2.1",
"tsx": "^4.7.0",
"tsx": "^4.7.1",
"typescript": "^5.3.3",
"vite": "^5.0.11",
"vite-tsconfig-paths": "^4.2.3"
"vite": "^5.1.4",
"vite-tsconfig-paths": "^4.3.1"
}
}
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@
"lint": "biome check ."
},
"devDependencies": {
"@babel/cli": "^7.23.4",
"@babel/core": "^7.23.7",
"@babel/cli": "^7.23.9",
"@babel/core": "^7.24.0",
"@babel/plugin-transform-export-namespace-from": "^7.23.4",
"@babel/plugin-transform-modules-commonjs": "^7.23.3",
"@biomejs/biome": "^1.4.1",
"@biomejs/biome": "^1.5.3",
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.1",
"@effect/build-utils": "^0.7.1",
"@types/node": "^20.10.8",
"@types/web": "^0.0.128",
"@effect/build-utils": "^0.7.6",
"@types/node": "^20.11.22",
"@types/web": "^0.0.140",
"babel-plugin-annotate-pure-calls": "^0.4.0",
"typescript": "^5.3.3",
"vite": "^5.0.11",
"vite-tsconfig-paths": "^4.2.3",
"vitest": "^1.1.3"
"vite": "^5.1.4",
"vite-tsconfig-paths": "^4.3.1",
"vitest": "^1.3.1"
},
"pnpm": {
"patchedDependencies": {
Expand Down
10 changes: 5 additions & 5 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
"build-annotate": "babel build --plugins annotate-pure-calls --out-dir build --source-maps"
},
"peerDependencies": {
"@bufbuild/protobuf": "^1.6.0",
"@connectrpc/connect": "^1.2.0"
"@bufbuild/protobuf": "^1.7.2",
"@connectrpc/connect": "^1.4.0"
},
"devDependencies": {
"@bufbuild/buf": "1.28.1",
"@bufbuild/protobuf": "^1.6.0",
"@connectrpc/connect": "^1.3.0"
"@bufbuild/buf": "1.29.0",
"@bufbuild/protobuf": "^1.7.2",
"@connectrpc/connect": "^1.4.0"
}
}
4 changes: 2 additions & 2 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
"peerDependencies": {
"@enzymefinance/abis": "workspace:*",
"decimal.js": "^10.4.3",
"viem": "^1.20.0"
"viem": "^2.7.16"
},
"devDependencies": {
"@enzymefinance/abis": "workspace:*",
"@viem/anvil": "^0.0.7",
"decimal.js": "^10.4.3",
"viem": "^1.21.4"
"viem": "^2.7.16"
}
}
28 changes: 19 additions & 9 deletions packages/sdk/src/Asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
hexToBytes,
parseAbi,
} from "viem";
import { readContract, simulateContract } from "viem/actions";
import { Viem } from "./Utils.js";
import { removeTrailingZeros } from "./Utils/bytes.js";

Expand Down Expand Up @@ -55,7 +56,8 @@ export async function getName(
}>,
) {
try {
const name = await Viem.readContract(client, args, {
const name = await readContract(client, {
...Viem.extractBlockParameters(args),
abi: parseAbi(["function name() view returns (string)"]),
functionName: "name",
address: args.asset,
Expand All @@ -65,7 +67,8 @@ export async function getName(
} catch (error) {
if (error instanceof ContractFunctionExecutionError) {
// TODO: Once `viem` exports the `SliceOutOfBoundsError` class, we should use that here too (`error.cause`).
const name = await Viem.readContract(client, args, {
const name = await readContract(client, {
...Viem.extractBlockParameters(args),
abi: parseAbi(["function name() view returns (bytes32)"]),
functionName: "name",
address: args.asset,
Expand All @@ -87,7 +90,8 @@ export async function getSymbol(
}>,
) {
try {
const symbol = await Viem.readContract(client, args, {
const symbol = await readContract(client, {
...Viem.extractBlockParameters(args),
abi: parseAbi(["function symbol() view returns (string)"]),
functionName: "symbol",
address: args.asset,
Expand All @@ -97,7 +101,8 @@ export async function getSymbol(
} catch (error) {
if (error instanceof ContractFunctionExecutionError) {
// TODO: Once `viem` exports the `SliceOutOfBoundsError` class, we should use that here too (`error.cause`).
const symbol = await Viem.readContract(client, args, {
const symbol = await readContract(client, {
...Viem.extractBlockParameters(args),
abi: parseAbi(["function symbol() view returns (bytes32)"]),
functionName: "symbol",
address: args.asset,
Expand All @@ -119,7 +124,8 @@ export function getBalanceOf(
asset: Address;
}>,
) {
return Viem.readContract(client, args, {
return readContract(client, {
...Viem.extractBlockParameters(args),
abi: parseAbi(["function balanceOf(address account) view returns (uint256)"]),
functionName: "balanceOf",
address: args.asset,
Expand Down Expand Up @@ -154,7 +160,8 @@ export function getAllowance(
spender: Address;
}>,
) {
return Viem.readContract(client, args, {
return readContract(client, {
...Viem.extractBlockParameters(args),
abi: parseAbi(["function allowance(address, address) view returns (uint256)"]),
functionName: "allowance",
address: args.asset,
Expand All @@ -168,7 +175,8 @@ export function getDecimals(
asset: Address;
}>,
) {
return Viem.readContract(client, args, {
return readContract(client, {
...Viem.extractBlockParameters(args),
abi: parseAbi(["function decimals() view returns (uint)"]),
functionName: "decimals",
address: args.asset,
Expand All @@ -181,7 +189,8 @@ export function getTotalSupply(
asset: Address;
}>,
) {
return Viem.readContract(client, args, {
return readContract(client, {
...Viem.extractBlockParameters(args),
abi: parseAbi(["function totalSupply() view returns (uint)"]),
functionName: "totalSupply",
address: args.asset,
Expand All @@ -197,7 +206,8 @@ export async function getCanonicalValue(
amount: bigint;
}>,
) {
const { result } = await Viem.simulateContract(client, args, {
const { result } = await simulateContract(client, {
...Viem.extractBlockParameters(args),
abi: Abis.IValueInterpreter,
functionName: "calcCanonicalAssetValue",
address: args.valueInterpreter,
Expand Down
19 changes: 13 additions & 6 deletions packages/sdk/src/Configuration.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as Abis from "@enzymefinance/abis";
import { Address, PublicClient, isAddressEqual } from "viem";
import { readContract, simulateContract } from "viem/actions";
import { getInfo } from "./Configuration/Fees/Performance.js";
import { Viem } from "./Utils.js";

Expand All @@ -16,7 +17,8 @@ export async function getEnabledFees(
feeManager: Address;
}>,
) {
return Viem.readContract(client, args, {
return readContract(client, {
...Viem.extractBlockParameters(args),
abi: Abis.IFeeManager,
functionName: "getEnabledFeesForFund",
args: [args.comptrollerProxy],
Expand All @@ -35,7 +37,8 @@ export async function getAccruedContinuousFees(
vaultProxy: Address;
}>,
) {
const continuousFees = await Viem.readContract(client, args, {
const continuousFees = await readContract(client, {
...Viem.extractBlockParameters(args),
abi: Abis.IUnpermissionedActionsWrapper,
functionName: "getContinuousFeesForFund",
address: args.unpermissionedActionsWrapper,
Expand All @@ -50,7 +53,8 @@ export async function getAccruedContinuousFees(
if (hasManagementFee) {
const {
result: [_, __, sharesDue],
} = await Viem.simulateContract(client, args, {
} = await simulateContract(client, {
...Viem.extractBlockParameters(args),
abi: Abis.IManagementFee,
functionName: "settle",
address: args.managementFee,
Expand All @@ -65,15 +69,17 @@ export async function getAccruedContinuousFees(
let highWaterMark: bigint | undefined;

if (hasPerformanceFee) {
const { result: gav } = await Viem.simulateContract(client, args, {
const { result: gav } = await simulateContract(client, {
...Viem.extractBlockParameters(args),
abi: Abis.IComptrollerLib,
functionName: "calcGav",
address: args.comptrollerProxy,
});

const {
result: [_, __, sharesDue],
} = await Viem.simulateContract(client, args, {
} = await simulateContract(client, {
...Viem.extractBlockParameters(args),
abi: Abis.IPerformanceFee,
functionName: "settle",
address: args.performanceFee,
Expand Down Expand Up @@ -106,7 +112,8 @@ export async function getEnabledPolicies(
policyManager: Address;
}>,
) {
return Viem.readContract(client, args, {
return readContract(client, {
...Viem.extractBlockParameters(args),
abi: Abis.IPolicyManager,
functionName: "getEnabledPoliciesForFund",
address: args.policyManager,
Expand Down
4 changes: 3 additions & 1 deletion packages/sdk/src/Configuration/Fee.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as Abis from "@enzymefinance/abis";
import { Address, PublicClient } from "viem";
import { readContract } from "viem/actions";
import { Viem } from "../Utils.js";

export {
Expand All @@ -20,7 +21,8 @@ export function getRecipient(
fee: Address;
}>,
) {
return Viem.readContract(client, args, {
return readContract(client, {
...Viem.extractBlockParameters(args),
abi: Abis.IFee,
functionName: "getRecipientForFund",
args: [args.comptrollerProxy],
Expand Down
4 changes: 3 additions & 1 deletion packages/sdk/src/Configuration/Fees/Entrance.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as Abis from "@enzymefinance/abis";
import { type Address, type Hex, type PublicClient, decodeAbiParameters, encodeAbiParameters, zeroAddress } from "viem";
import { readContract } from "viem/actions";
import { type Types, Viem } from "../../Utils.js";

//--------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -104,7 +105,8 @@ export async function getRate(
comptrollerProxy: Address;
}>,
) {
return Viem.readContract(client, args, {
return readContract(client, {
...Viem.extractBlockParameters(args),
abi: Abis.IEntranceRateBurnFee,
functionName: "getRateForFund",
args: [args.comptrollerProxy],
Expand Down
7 changes: 5 additions & 2 deletions packages/sdk/src/Configuration/Fees/Exit.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as Abis from "@enzymefinance/abis";
import { type Address, type Hex, type PublicClient, decodeAbiParameters, encodeAbiParameters, zeroAddress } from "viem";
import { readContract } from "viem/actions";
import { Viem } from "../../Utils.js";

//--------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -113,7 +114,8 @@ export async function getInKindRate(
comptrollerProxy: Address;
}>,
) {
return Viem.readContract(client, args, {
return readContract(client, {
...Viem.extractBlockParameters(args),
abi: Abis.IExitRateBurnFee,
functionName: "getInKindRateForFund",
args: [args.comptrollerProxy],
Expand All @@ -128,7 +130,8 @@ export async function getSpecificAssetsRate(
comptrollerProxy: Address;
}>,
) {
return Viem.readContract(client, args, {
return readContract(client, {
...Viem.extractBlockParameters(args),
abi: Abis.IExitRateBurnFee,
functionName: "getSpecificAssetsRateForFund",
args: [args.comptrollerProxy],
Expand Down
4 changes: 3 additions & 1 deletion packages/sdk/src/Configuration/Fees/Management.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as Abis from "@enzymefinance/abis";
import { type Address, type Hex, type PublicClient, decodeAbiParameters, encodeAbiParameters, zeroAddress } from "viem";
import { readContract } from "viem/actions";
import { Rates, Viem } from "../../Utils.js";

//--------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -105,7 +106,8 @@ export async function getInfo(
managementFee: Address;
}>,
) {
return Viem.readContract(client, args, {
return readContract(client, {
...Viem.extractBlockParameters(args),
abi: Abis.IManagementFee,
functionName: "getFeeInfoForFund",
args: [args.comptrollerProxy],
Expand Down
Loading
Loading