Skip to content

Commit

Permalink
Use typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
viatrix committed Dec 11, 2024
1 parent 7046c7d commit 04072c3
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 122 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
30 changes: 0 additions & 30 deletions hardhat.config.js

This file was deleted.

34 changes: 34 additions & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import "@nomicfoundation/hardhat-toolbox";
import { HardhatUserConfig } from 'hardhat/config';

import dotenv from "dotenv";

dotenv.config();

const mainnetFork = {
url: `${process.env.JSON_RPC_PROVIDER}`,
};

const config: HardhatUserConfig = {
solidity: {
version: "0.8.27",
settings: {
optimizer: {
enabled: true,
runs: 2000,
},
},
},
networks: {
hardhat: {
chainId: 1,
forking: mainnetFork,
accounts: {
count: 3,
},
},
},
};

export default config;

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"license": "LGPL-3.0-only",
"scripts": {
"compile": "npx hardhat compile",
"test": "npx hardhat test",
"test": "npx hardhat test --typecheck",
"lint": "npm run lint:solidity && npm run lint:js",
"lint:solidity": "solhint contracts/**/*.sol",
"lint:js": "npx eslint"
Expand Down
41 changes: 0 additions & 41 deletions test/helpers.js

This file was deleted.

50 changes: 50 additions & 0 deletions test/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// The Licensed Work is (c) 2022 Sygma
// SPDX-License-Identifier: LGPL-3.0-only

import { ethers } from "ethers";

const toHex = (covertThis: string | number, padding: number) : string => {
return ethers.zeroPadValue(ethers.toBeHex(covertThis), padding);
};

export function createERCDepositData(
tokenAmountOrID: number | string,
lenRecipientAddress: number,
recipientAccount: string,
): string {
return (
"0x" +
toHex(tokenAmountOrID, 32).substring(2) + // Token amount or ID to deposit (32 bytes)
toHex(lenRecipientAddress, 32).substring(2) + // len(recipientAccount) (32 bytes)
recipientAccount.substring(2) // recipientAccount (?? bytes)
);
}

export function createResourceID(
contractAddress: string,
domainID: number,
): string {
return toHex(contractAddress + toHex(domainID, 1).substring(2), 32);
}

export function createOptionalContractCallDepositData(
amount: number,
recipient: string,
executionGasAmount: number,
message: string): string {
return (
"0x" +
toHex(amount, 32).substring(2) + // uint256
toHex(recipient.substring(2).length / 2, 32).substring(2) + // uint256
recipient.substring(2) + // bytes
toHex(executionGasAmount, 32).substring(2) + // uint256
toHex(message.substring(2).length / 2, 32).substring(2) + // uint256
message.substring(2) // bytes
)
}

module.exports = {
createERCDepositData,
createResourceID,
createOptionalContractCallDepositData,
};
Loading

0 comments on commit 04072c3

Please sign in to comment.