Skip to content

Commit 38ce106

Browse files
authored
Merge pull request #40 from windingtree/develop
Nodenext exports type
2 parents 9f716e5 + b8f7aad commit 38ce106

File tree

6 files changed

+92
-15
lines changed

6 files changed

+92
-15
lines changed

package/README.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@ The WindingTree market protocol smart contracts and utilities
1212
- Config ([0x098b1d12cAfE7315C77b6d308A62ce02806260Ee](https://explorer.public.zkevm-test.net/address/0x098b1d12cAfE7315C77b6d308A62ce02806260Ee/read-proxy#address-tabs)): the protocol configuration smart contract
1313
- EntitiesRegistry ([0x4bB51528C83844b509E1152EEb05260eE1bf60e6](https://explorer.public.zkevm-test.net/address/0x4bB51528C83844b509E1152EEb05260eE1bf60e6/read-proxy#address-tabs)): the protocol identity management
1414
- Market ([0xDd5B6ffB3585E109ECddec5293e31cdc1e9DeD57](https://explorer.public.zkevm-test.net/address/0xDd5B6ffB3585E109ECddec5293e31cdc1e9DeD57/read-proxy#address-tabs)): the protocol entry point
15-
- LIF ([0xba515AB7FfDa899a2e6c8FDbcDf351c8c15f4009](https://explorer.public.zkevm-test.net/address/0xba515AB7FfDa899a2e6c8FDbcDf351c8c15f4009/read-proxy#address-tabs)): Test version of LIF token
15+
- LIF ([0x4d60F4483BaA654CdAF1c5734D9E6B16735efCF8](https://explorer.public.zkevm-test.net/address/0x4d60F4483BaA654CdAF1c5734D9E6B16735efCF8/read-proxy#address-tabs)): Test version of LIF token
16+
17+
#### Testing tokens
18+
19+
- `STABLE6`: [ERC20, 6 decimals, no permit](https://explorer.public.zkevm-test.net/address/0x8CB96383609C56af1Fe44DB7591F94AEE2fa43b2/read-proxy#address-tabs)
20+
- `STABLE6PERMIT`: [ERC20, 6 decimals, with permit](https://explorer.public.zkevm-test.net/address/0x4556d5C1486d799f67FA96c84F1d0552486CAAF4/read-proxy#address-tabs)
21+
- `STABLE18`: [ERC20, 18 decimals, no permit](https://explorer.public.zkevm-test.net/address/0x4EcB659060Da61D795D777bb21BAe3599b301C66/read-proxy#address-tabs)
22+
- `STABLE18PERMIT`: [ERC20, 18 decimals, with permit](https://explorer.public.zkevm-test.net/address/0xF54784206A53EF19fd3024D8cdc7A6251A4A0d67/read-proxy#address-tabs)
1623

1724
## Install package
1825

package/src/constants.ts

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
import { encodeBytes32String } from 'ethers';
2+
3+
// Protocol entities types (kinds) as object
4+
export const kinds = {
5+
// ethers.encodeBytes32String('supplier')
6+
supplier: '0x737570706c696572000000000000000000000000000000000000000000000000',
7+
// ethers.encodeBytes32String('retailer')
8+
retailer: '0x72657461696c6572000000000000000000000000000000000000000000000000',
9+
};
10+
111
// ethers.solidityPackedKeccak256(
212
// ['string'],
313
// ['PaymentOption(bytes32 id,uint256 price,address asset)'],

package/tsconfig.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"compilerOptions": {
33
"strict": true,
44
"esModuleInterop": true,
5-
"lib": ["DOM.Iterable"],
6-
"target": "ES2022",
7-
"module": "CommonJS",
8-
"moduleResolution": "node",
5+
"lib": ["ESNext", "DOM", "DOM.Iterable"],
6+
"target": "ESNext",
7+
"module": "ESNext",
8+
"moduleResolution": "NodeNext",
99
"skipLibCheck": true,
1010
"checkJs": true,
1111
"allowJs": true,

tasks/index.ts

+37-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
/* eslint-disable @typescript-eslint/require-await */
12
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
23
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
34
import { task } from "hardhat/config";
45
import { utils, Wallet } from "ethers";
6+
import { randomId, createSupplierId } from "../utils";
57

68
task("debug", "Transaction debug")
79
.addParam("tx", "Transaction hash")
810
.setAction(async (args, hre) => {
911
const txHash = args.tx;
1012
const trace = await hre.network.provider.send(
11-
"eth_getTransactionReceipt", // debug_traceTransaction
13+
"debug_traceTransaction", // debug_traceTransaction
1214
[
1315
txHash,
1416
// {
@@ -21,12 +23,38 @@ task("debug", "Transaction debug")
2123
console.log(JSON.stringify(trace, null, 2));
2224
});
2325

24-
task("wallet", "Generate random wallet")
25-
// eslint-disable-next-line @typescript-eslint/require-await
26-
.setAction(async () => {
27-
const mnemonic = utils.entropyToMnemonic(utils.randomBytes(32));
28-
console.log(`Mnemonic: ${mnemonic}`);
29-
const wallet = Wallet.fromMnemonic(mnemonic);
30-
console.log("Account address:", wallet.address);
31-
console.log("PK:", wallet.privateKey);
26+
task("wallet", "Generate random wallet").setAction(async () => {
27+
const mnemonic = utils.entropyToMnemonic(utils.randomBytes(32));
28+
console.log(`Mnemonic: ${mnemonic}`);
29+
const wallet = Wallet.fromMnemonic(mnemonic);
30+
console.log("Account address:", wallet.address);
31+
console.log("PK:", wallet.privateKey);
32+
});
33+
34+
task("entity").setAction(async () => {
35+
const ownerMnemonic = utils.entropyToMnemonic(utils.randomBytes(32));
36+
console.log(`Owner mnemonic: ${ownerMnemonic}`);
37+
const ownerWallet = Wallet.fromMnemonic(ownerMnemonic);
38+
console.log("Owner account address:", ownerWallet.address);
39+
console.log("Owner PK:", ownerWallet.privateKey, "\n");
40+
41+
const signerMnemonic = utils.entropyToMnemonic(utils.randomBytes(32));
42+
console.log(`Signer mnemonic: ${signerMnemonic}`);
43+
const signerWallet = Wallet.fromMnemonic(signerMnemonic);
44+
console.log("Signer account address:", signerWallet.address);
45+
console.log("Signer PK:", signerWallet.privateKey, "\n");
46+
47+
const salt = randomId();
48+
console.log(`Entity Id salt: ${salt}`);
49+
console.log(`Entity Id:`, createSupplierId(ownerWallet.address, salt));
50+
});
51+
52+
task("encodeBytes32String")
53+
.addParam("string", "String to encode")
54+
.setAction(async (args) => {
55+
console.log("String:", args.string);
56+
console.log(
57+
"Bytes32String:",
58+
utils.formatBytes32String(args.string as string)
59+
);
3260
});

utils/constants.ts

+32
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,35 @@ export const minDeposit = BigNumber.from("1000000000000000000000");
1616
export const claimPeriod = BigNumber.from("60");
1717
export const protocolFee = BigNumber.from("1");
1818
export const retailerFee = BigNumber.from("1");
19+
20+
// ethers.solidityPackedKeccak256(
21+
// ['string'],
22+
// ['PaymentOption(bytes32 id,uint256 price,address asset)'],
23+
// );
24+
export const PAYMENT_OPTION_TYPE_HASH =
25+
"0x2f8fc0b3ad3f58f6deb367673d38e4112a3c8c64de033c5b780b84ef8f67cde6";
26+
27+
// ethers.solidityPackedKeccak256(
28+
// ['string'],
29+
// ['CancelOption(uint256 time,uint256 penalty)'],
30+
// );
31+
export const CANCEL_OPTION_TYPE_HASH =
32+
"0x8ea27057ea8a0239f02c8b75748218a035a5a2a2a0785b53aaa99af91ff538c5";
33+
34+
// ethers.solidityPackedKeccak256(
35+
// ['string'],
36+
// [
37+
// 'Offer(bytes32 id,uint256 expire,bytes32 supplierId,uint256 chainId,bytes32 requestHash,bytes32 optionsHash,bytes32 paymentHash,bytes32 cancelHash,bool transferable,uint256 checkIn)',
38+
// ],
39+
// );
40+
export const OFFER_TYPE_HASH =
41+
"0xcf2addd2f89a78825d3f130a17e47b4e9963adfd09837fa9c454569faa073354";
42+
43+
// ethers.solidityPackedKeccak256(
44+
// ['string'],
45+
// [
46+
// 'Voucher(bytes32 id,address signer)',
47+
// ],
48+
// );
49+
export const CHECK_IN_TYPE_HASH =
50+
"0xf811d7f3ddb148410001929e2cbfb7fea8779b9349b7c2f650fa91840528d69c";

utils/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
PAYMENT_OPTION_TYPE_HASH,
55
CANCEL_OPTION_TYPE_HASH,
66
OFFER_TYPE_HASH,
7-
} from "../src/constants";
7+
} from "./constants";
88
import { MockERC20Dec18Permit } from "../typechain";
99
import {
1010
PaymentOption,

0 commit comments

Comments
 (0)