Skip to content

Commit

Permalink
remove viem encoding #53
Browse files Browse the repository at this point in the history
  • Loading branch information
ukorvl committed Jul 3, 2024
1 parent 08a7f90 commit 99fbe9d
Show file tree
Hide file tree
Showing 35 changed files with 247 additions and 155 deletions.
5 changes: 5 additions & 0 deletions .changeset/fluffy-paws-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nilfoundation/niljs": minor
---

Remove viem encoding and replace with local implementation
1 change: 1 addition & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Release
on:
pull_request:
types: [closed]
branches: [master]
workflow_dispatch:

concurrency:
Expand Down
2 changes: 1 addition & 1 deletion examples/asyncCall.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { bytesToHex } from "viem";
import {
Faucet,
HttpTransport,
LocalECDSAKeySigner,
PublicClient,
WalletV1,
bytesToHex,
generateRandomPrivateKey,
waitTillCompleted,
} from "../src";
Expand Down
3 changes: 2 additions & 1 deletion examples/bounce.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { bytesToHex, encodeFunctionData } from "viem";
import { encodeFunctionData } from "viem";
import {
Faucet,
HttpTransport,
LocalECDSAKeySigner,
PublicClient,
WalletV1,
bytesToHex,
generateRandomPrivateKey,
waitTillCompleted,
} from "../src";
Expand Down
2 changes: 1 addition & 1 deletion examples/deployInternalMessage.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { Abi } from "abitype";
import { bytesToHex } from "viem";
import {
Faucet,
HttpTransport,
LocalECDSAKeySigner,
PublicClient,
WalletV1,
bytesToHex,
generateRandomPrivateKey,
waitTillCompleted,
} from "../src";
Expand Down
2 changes: 1 addition & 1 deletion examples/deployWallet.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { bytesToHex } from "viem";
import {
Faucet,
HttpTransport,
LocalECDSAKeySigner,
PublicClient,
WalletV1,
bytesToHex,
generateRandomPrivateKey,
} from "../src";

Expand Down
2 changes: 1 addition & 1 deletion examples/externalContractDeployment.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { bytesToHex } from "viem";
import {
Faucet,
HttpTransport,
LocalECDSAKeySigner,
PublicClient,
WalletV1,
bytesToHex,
externalDeploymentMessage,
generateRandomPrivateKey,
} from "../src";
Expand Down
2 changes: 1 addition & 1 deletion examples/syncCall.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { bytesToHex } from "viem";
import {
Faucet,
HttpTransport,
LocalECDSAKeySigner,
PublicClient,
WalletV1,
bytesToHex,
convertEthToWei,
generateRandomPrivateKey,
} from "../src";
Expand Down
4 changes: 3 additions & 1 deletion examples/tokenMint.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bytesToHex, encodeFunctionData, hexToBigInt } from "viem";
import { encodeFunctionData } from "viem";
import {
Faucet,
HttpTransport,
Expand All @@ -7,7 +7,9 @@ import {
MINTER_ADDRESS,
PublicClient,
WalletV1,
bytesToHex,
generateRandomPrivateKey,
hexToBigInt,
waitTillCompleted,
} from "../src";

Expand Down
107 changes: 20 additions & 87 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"@scure/bip39": "^1.3.0",
"abitype": "^1.0.2",
"tiny-invariant": "^1.3.3",
"viem": "^2.16.3"
"viem": "^2.17.0"
},
"keywords": [
"nil",
Expand Down
12 changes: 8 additions & 4 deletions src/clients/PublicClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { bytesToHex } from "@noble/curves/abstract/utils";
import { hexToBytes, numberToHex } from "viem";
import { hexToBigInt, hexToNumber } from "../encoding/index.js";
import {
bytesToHex,
hexToBigInt,
hexToBytes,
hexToNumber,
toHex,
} from "../encoding/index.js";
import { BlockNotFoundError } from "../errors/block.js";
import { type Hex, assertIsValidShardId } from "../index.js";
import type { IAddress } from "../signers/types/IAddress.js";
Expand Down Expand Up @@ -410,7 +414,7 @@ class PublicClient extends BaseClient {
typeof callArgs.data === "string"
? callArgs.data
: addHexPrefix(bytesToHex(callArgs.data)),
value: numberToHex(callArgs.value || 0n),
value: toHex(callArgs.value || 0n),
gasLimit: (callArgs.gasLimit || 5_000_000n).toString(10),
};

Expand Down
10 changes: 6 additions & 4 deletions src/contracts/Faucet/Faucet.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { bytesToHex } from "viem";
import { generatePrivateKey } from "viem/accounts";
import { PublicClient } from "../../clients/index.js";
import { LocalECDSAKeySigner } from "../../signers/index.js";
import { bytesToHex } from "../../index.js";
import {
LocalECDSAKeySigner,
generateRandomPrivateKey,
} from "../../signers/index.js";
import { MockTransport } from "../../transport/MockTransport.js";
import { WalletV1 } from "../WalletV1/WalletV1.js";
import { Faucet } from "./Faucet.js";

const signer = new LocalECDSAKeySigner({
privateKey: generatePrivateKey(),
privateKey: generateRandomPrivateKey(),
});

test("Faucet with retry", async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/contracts/Faucet/Faucet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { type Hex, bytesToHex, encodeFunctionData, hexToBytes } from "viem";
import { type Hex, bytesToHex, encodeFunctionData } from "viem";
import type { PublicClient } from "../../clients/PublicClient.js";
import { ExternalMessageEnvelope } from "../../encoding/externalMessage.js";
import { hexToBytes } from "../../index.js";
import type { IReceipt } from "../../types/IReceipt.js";
import { getShardIdFromAddress } from "../../utils/address.js";
import { waitTillCompleted } from "../../utils/receipt.js";
Expand All @@ -9,7 +10,6 @@ import FaucetAbi from "./Faucet.abi.json";
/**
* Faucet is a special contract that is used to top up other contracts in the =nil; devnet.
*
* @class Faucet
* @typedef {Faucet}
*/
Expand Down
4 changes: 2 additions & 2 deletions src/contracts/WalletV1/WalletV1.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { generatePrivateKey } from "viem/accounts";
import { PublicClient } from "../../clients/index.js";
import { generateRandomPrivateKey } from "../../index.js";
import { LocalECDSAKeySigner } from "../../signers/LocalECDSAKeySigner.js";
import { MockTransport } from "../../transport/MockTransport.js";
import { HttpTransport } from "../../transport/index.js";
import { WalletV1 } from "./WalletV1.js";

const signer = new LocalECDSAKeySigner({
privateKey: generatePrivateKey(),
privateKey: generateRandomPrivateKey(),
});
const pubkey = await signer.getPublicKey();
const client = new PublicClient({
Expand Down
9 changes: 5 additions & 4 deletions src/contracts/WalletV1/WalletV1.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { Abi } from "abitype";
import invariant from "tiny-invariant";
import { bytesToHex, encodeFunctionData, hexToBytes } from "viem";
import { bytesToHex, encodeFunctionData } from "viem";
import type { PublicClient } from "../../clients/PublicClient.js";
import { prepareDeployPart } from "../../encoding/deployPart.js";
import { externalMessageEncode } from "../../encoding/externalMessage.js";
import { hexToBytes, toHex } from "../../index.js";
import type { ISigner } from "../../signers/index.js";
import type { IDeployData } from "../../types/IDeployData.js";
import { getShardIdFromAddress, refineAddress } from "../../utils/address.js";
Expand All @@ -19,9 +20,9 @@ import type {
} from "./types/index.js";

/**
* WalletV1 is a class used for performing operations on the cluster that require authentication.
* WalletV1 is a class used for performing operations on the cluster that require authentication.
*
* @class WalletV1
* @typedef {WalletV1}
*/
Expand Down Expand Up @@ -166,7 +167,7 @@ export class WalletV1 {
if (salt) {
this.salt = refineSalt(salt);
}
this.shardId = getShardIdFromAddress(this.address);
this.shardId = getShardIdFromAddress(toHex(this.address));
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/encoding/deployPart.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { bytesToHex, encodeDeployData, hexToBytes } from "viem";
import { encodeDeployData } from "viem";
import type { IDeployData } from "../types/IDeployData.js";
import { calculateAddress } from "../utils/address.js";
import { refineSalt } from "../utils/refiners.js";
import { bytesToHex } from "./fromBytes.js";
import { hexToBytes } from "./fromHex.js";

/**
* Refines the provided salt and generates the full bytecode for deployment. Returns the bytecode and the deployment address.
Expand Down
Loading

0 comments on commit 99fbe9d

Please sign in to comment.