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

fix: mkr name and symbol #374

Merged
merged 4 commits into from
Jan 10, 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/early-hornets-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@enzymefinance/api": patch
"@enzymefinance/sdk": patch
---

MKR name and symbol fix
10 changes: 5 additions & 5 deletions examples/example-api-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
},
"dependencies": {
"@bufbuild/protobuf": "^1.6.0",
"@connectrpc/connect-node": "^1.2.0",
"@connectrpc/connect-web": "^1.2.0",
"@enzymefinance/api": "workspace:^"
"@connectrpc/connect-node": "^1.3.0",
"@connectrpc/connect-web": "^1.3.0",
"@enzymefinance/api": "workspace:*"
},
"devDependencies": {
"@types/node": "^20.10.5",
"tsx": "^4.6.2",
"@types/node": "^20.10.8",
"tsx": "^4.7.0",
"typescript": "^5.3.3"
}
}
22 changes: 11 additions & 11 deletions examples/example-api-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@
},
"dependencies": {
"@bufbuild/protobuf": "^1.6.0",
"@connectrpc/connect-query": "^1.1.1",
"@connectrpc/connect-web": "^1.2.0",
"@enzymefinance/api": "workspace:^",
"@tanstack/react-query": "^5.14.1",
"@tremor/react": "^3.12.1",
"@connectrpc/connect-query": "^1.1.3",
"@connectrpc/connect-web": "^1.3.0",
"@enzymefinance/api": "workspace:*",
"@tanstack/react-query": "^5.17.9",
"@tremor/react": "^3.12.2",
"autoprefixer": "^10.4.16",
"postcss": "^8.4.32",
"postcss": "^8.4.33",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"tailwindcss": "^3.3.7"
"tailwindcss": "^3.4.1"
},
"devDependencies": {
"@types/react": "^18.2.45",
"@types/react": "^18.2.47",
"@types/react-dom": "^18.2.18",
"@types/web": "^0.0.128",
"@vitejs/plugin-react": "^4.2.1",
"tsx": "^4.6.2",
"tsx": "^4.7.0",
"typescript": "^5.3.3",
"vite": "^5.0.10",
"vite-tsconfig-paths": "^4.2.2"
"vite": "^5.0.11",
"vite-tsconfig-paths": "^4.2.3"
}
}
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@
},
"devDependencies": {
"@babel/cli": "^7.23.4",
"@babel/core": "^7.23.6",
"@babel/core": "^7.23.7",
"@babel/plugin-transform-export-namespace-from": "^7.23.4",
"@babel/plugin-transform-modules-commonjs": "^7.23.3",
"@biomejs/biome": "^1.4.1",
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.1",
"@effect/build-utils": "^0.7.1",
"@types/node": "^20.10.5",
"@types/node": "^20.10.8",
"@types/web": "^0.0.128",
"babel-plugin-annotate-pure-calls": "^0.4.0",
"typescript": "^5.3.3",
"vite": "^5.0.10",
"vite-tsconfig-paths": "^4.2.2",
"vitest": "^1.0.4"
"vite": "^5.0.11",
"vite-tsconfig-paths": "^4.2.3",
"vitest": "^1.1.3"
},
"pnpm": {
"patchedDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
"devDependencies": {
"@bufbuild/buf": "1.28.1",
"@bufbuild/protobuf": "^1.6.0",
"@connectrpc/connect": "^1.2.0"
"@connectrpc/connect": "^1.3.0"
}
}
6 changes: 3 additions & 3 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
"build-annotate": "babel build --plugins annotate-pure-calls --out-dir build --source-maps"
},
"peerDependencies": {
"@enzymefinance/abis": "workspace:^",
"@enzymefinance/abis": "workspace:*",
"decimal.js": "^10.4.3",
"viem": "^1.20.0"
},
"devDependencies": {
"@enzymefinance/abis": "workspace:^",
"@enzymefinance/abis": "workspace:*",
"@viem/anvil": "^0.0.7",
"decimal.js": "^10.4.3",
"viem": "^1.20.2"
"viem": "^1.21.4"
}
}
18 changes: 15 additions & 3 deletions packages/sdk/src/Asset.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import * as Abis from "@enzymefinance/abis";
import { type Address, ContractFunctionExecutionError, type PublicClient, hexToString, parseAbi } from "viem";
import {
type Address,
ContractFunctionExecutionError,
type PublicClient,
bytesToString,
hexToBytes,
parseAbi,
} from "viem";
import { Viem } from "./Utils.js";
import { removeTrailingZeros } from "./Utils/bytes.js";

//--------------------------------------------------------------------------------------------
// TRANSACTIONS
Expand Down Expand Up @@ -63,7 +71,9 @@ export async function getName(
address: args.asset,
});

return hexToString(name).replace(/(?:\u{0000})*$/, "");
const bytes = hexToBytes(name);

return bytesToString(removeTrailingZeros(bytes));
}

throw error;
Expand Down Expand Up @@ -93,7 +103,9 @@ export async function getSymbol(
address: args.asset,
});

return hexToString(symbol).replace(/(?:\u{0000})*$/, "");
const bytes = hexToBytes(symbol);

return bytesToString(removeTrailingZeros(bytes));
}

throw error;
Expand Down
1 change: 1 addition & 0 deletions packages/sdk/src/Utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * as Address from "./Utils/address.js";
export * as Assertion from "./Utils/assertion.js";
export * as BI from "./Utils/bigint.js";
export * as Bytes from "./Utils/bytes.js";
export * as Constants from "./Utils/constants.js";
export * as Conversion from "./Utils/conversion.js";
export * as Rates from "./Utils/rates.js";
Expand Down
13 changes: 13 additions & 0 deletions packages/sdk/src/Utils/bytes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ByteArray } from "viem";

export function removeTrailingZeros(input: ByteArray): ByteArray {
let length = input.length;
for (let i = length - 1; i >= 0; i--) {
if (input[i] !== 0) {
break;
}
length = i;
}

return input.length !== length ? input.slice(0, length) : input;
}
45 changes: 45 additions & 0 deletions packages/sdk/test/tests/Asset.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Asset } from "@enzymefinance/sdk";
import { TestSetup } from "@enzymefinance/sdk/test";
import { expect, test } from "vitest";

const environment = TestSetup.mainnet();

test("DAI name should be correct", async () => {
const dai = environment.constants.dai;

const name = Asset.getName(environment.client, {
asset: dai,
});

expect(name).resolves.toBe("Dai Stablecoin");
});

test("MKR name should be correct", async () => {
const mkr = "0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2";

const name = Asset.getName(environment.client, {
asset: mkr,
});

expect(name).resolves.toBe("Maker");
});

test("DAI symbol should be correct", async () => {
const dai = environment.constants.dai;

const symbol = Asset.getSymbol(environment.client, {
asset: dai,
});

expect(symbol).resolves.toBe("DAI");
});

test("MKR symbol should be correct", async () => {
const mkr = "0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2";

const symbol = Asset.getSymbol(environment.client, {
asset: mkr,
});

expect(symbol).resolves.toBe("MKR");
});
Loading
Loading