diff --git a/package/README.md b/package/README.md index a14587b..ade00ec 100644 --- a/package/README.md +++ b/package/README.md @@ -12,7 +12,14 @@ The WindingTree market protocol smart contracts and utilities - Config ([0x098b1d12cAfE7315C77b6d308A62ce02806260Ee](https://explorer.public.zkevm-test.net/address/0x098b1d12cAfE7315C77b6d308A62ce02806260Ee/read-proxy#address-tabs)): the protocol configuration smart contract - EntitiesRegistry ([0x4bB51528C83844b509E1152EEb05260eE1bf60e6](https://explorer.public.zkevm-test.net/address/0x4bB51528C83844b509E1152EEb05260eE1bf60e6/read-proxy#address-tabs)): the protocol identity management - Market ([0xDd5B6ffB3585E109ECddec5293e31cdc1e9DeD57](https://explorer.public.zkevm-test.net/address/0xDd5B6ffB3585E109ECddec5293e31cdc1e9DeD57/read-proxy#address-tabs)): the protocol entry point -- LIF ([0xba515AB7FfDa899a2e6c8FDbcDf351c8c15f4009](https://explorer.public.zkevm-test.net/address/0xba515AB7FfDa899a2e6c8FDbcDf351c8c15f4009/read-proxy#address-tabs)): Test version of LIF token +- LIF ([0x4d60F4483BaA654CdAF1c5734D9E6B16735efCF8](https://explorer.public.zkevm-test.net/address/0x4d60F4483BaA654CdAF1c5734D9E6B16735efCF8/read-proxy#address-tabs)): Test version of LIF token + +#### Testing tokens + +- `STABLE6`: [ERC20, 6 decimals, no permit](https://explorer.public.zkevm-test.net/address/0x8CB96383609C56af1Fe44DB7591F94AEE2fa43b2/read-proxy#address-tabs) +- `STABLE6PERMIT`: [ERC20, 6 decimals, with permit](https://explorer.public.zkevm-test.net/address/0x4556d5C1486d799f67FA96c84F1d0552486CAAF4/read-proxy#address-tabs) +- `STABLE18`: [ERC20, 18 decimals, no permit](https://explorer.public.zkevm-test.net/address/0x4EcB659060Da61D795D777bb21BAe3599b301C66/read-proxy#address-tabs) +- `STABLE18PERMIT`: [ERC20, 18 decimals, with permit](https://explorer.public.zkevm-test.net/address/0xF54784206A53EF19fd3024D8cdc7A6251A4A0d67/read-proxy#address-tabs) ## Install package diff --git a/package/src/constants.ts b/package/src/constants.ts index 842e56f..859ad56 100644 --- a/package/src/constants.ts +++ b/package/src/constants.ts @@ -1,3 +1,13 @@ +import { encodeBytes32String } from 'ethers'; + +// Protocol entities types (kinds) as object +export const kinds = { + // ethers.encodeBytes32String('supplier') + supplier: '0x737570706c696572000000000000000000000000000000000000000000000000', + // ethers.encodeBytes32String('retailer') + retailer: '0x72657461696c6572000000000000000000000000000000000000000000000000', +}; + // ethers.solidityPackedKeccak256( // ['string'], // ['PaymentOption(bytes32 id,uint256 price,address asset)'], diff --git a/package/tsconfig.json b/package/tsconfig.json index 4c0ac90..c178f84 100644 --- a/package/tsconfig.json +++ b/package/tsconfig.json @@ -2,10 +2,10 @@ "compilerOptions": { "strict": true, "esModuleInterop": true, - "lib": ["DOM.Iterable"], - "target": "ES2022", - "module": "CommonJS", - "moduleResolution": "node", + "lib": ["ESNext", "DOM", "DOM.Iterable"], + "target": "ESNext", + "module": "ESNext", + "moduleResolution": "NodeNext", "skipLibCheck": true, "checkJs": true, "allowJs": true, diff --git a/tasks/index.ts b/tasks/index.ts index 9dfefab..e688c1c 100644 --- a/tasks/index.ts +++ b/tasks/index.ts @@ -1,14 +1,16 @@ +/* eslint-disable @typescript-eslint/require-await */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ import { task } from "hardhat/config"; import { utils, Wallet } from "ethers"; +import { randomId, createSupplierId } from "../utils"; task("debug", "Transaction debug") .addParam("tx", "Transaction hash") .setAction(async (args, hre) => { const txHash = args.tx; const trace = await hre.network.provider.send( - "eth_getTransactionReceipt", // debug_traceTransaction + "debug_traceTransaction", // debug_traceTransaction [ txHash, // { @@ -21,12 +23,38 @@ task("debug", "Transaction debug") console.log(JSON.stringify(trace, null, 2)); }); -task("wallet", "Generate random wallet") - // eslint-disable-next-line @typescript-eslint/require-await - .setAction(async () => { - const mnemonic = utils.entropyToMnemonic(utils.randomBytes(32)); - console.log(`Mnemonic: ${mnemonic}`); - const wallet = Wallet.fromMnemonic(mnemonic); - console.log("Account address:", wallet.address); - console.log("PK:", wallet.privateKey); +task("wallet", "Generate random wallet").setAction(async () => { + const mnemonic = utils.entropyToMnemonic(utils.randomBytes(32)); + console.log(`Mnemonic: ${mnemonic}`); + const wallet = Wallet.fromMnemonic(mnemonic); + console.log("Account address:", wallet.address); + console.log("PK:", wallet.privateKey); +}); + +task("entity").setAction(async () => { + const ownerMnemonic = utils.entropyToMnemonic(utils.randomBytes(32)); + console.log(`Owner mnemonic: ${ownerMnemonic}`); + const ownerWallet = Wallet.fromMnemonic(ownerMnemonic); + console.log("Owner account address:", ownerWallet.address); + console.log("Owner PK:", ownerWallet.privateKey, "\n"); + + const signerMnemonic = utils.entropyToMnemonic(utils.randomBytes(32)); + console.log(`Signer mnemonic: ${signerMnemonic}`); + const signerWallet = Wallet.fromMnemonic(signerMnemonic); + console.log("Signer account address:", signerWallet.address); + console.log("Signer PK:", signerWallet.privateKey, "\n"); + + const salt = randomId(); + console.log(`Entity Id salt: ${salt}`); + console.log(`Entity Id:`, createSupplierId(ownerWallet.address, salt)); +}); + +task("encodeBytes32String") + .addParam("string", "String to encode") + .setAction(async (args) => { + console.log("String:", args.string); + console.log( + "Bytes32String:", + utils.formatBytes32String(args.string as string) + ); }); diff --git a/utils/constants.ts b/utils/constants.ts index 53a5e2d..c8796e4 100644 --- a/utils/constants.ts +++ b/utils/constants.ts @@ -16,3 +16,35 @@ export const minDeposit = BigNumber.from("1000000000000000000000"); export const claimPeriod = BigNumber.from("60"); export const protocolFee = BigNumber.from("1"); export const retailerFee = BigNumber.from("1"); + +// ethers.solidityPackedKeccak256( +// ['string'], +// ['PaymentOption(bytes32 id,uint256 price,address asset)'], +// ); +export const PAYMENT_OPTION_TYPE_HASH = + "0x2f8fc0b3ad3f58f6deb367673d38e4112a3c8c64de033c5b780b84ef8f67cde6"; + +// ethers.solidityPackedKeccak256( +// ['string'], +// ['CancelOption(uint256 time,uint256 penalty)'], +// ); +export const CANCEL_OPTION_TYPE_HASH = + "0x8ea27057ea8a0239f02c8b75748218a035a5a2a2a0785b53aaa99af91ff538c5"; + +// ethers.solidityPackedKeccak256( +// ['string'], +// [ +// 'Offer(bytes32 id,uint256 expire,bytes32 supplierId,uint256 chainId,bytes32 requestHash,bytes32 optionsHash,bytes32 paymentHash,bytes32 cancelHash,bool transferable,uint256 checkIn)', +// ], +// ); +export const OFFER_TYPE_HASH = + "0xcf2addd2f89a78825d3f130a17e47b4e9963adfd09837fa9c454569faa073354"; + +// ethers.solidityPackedKeccak256( +// ['string'], +// [ +// 'Voucher(bytes32 id,address signer)', +// ], +// ); +export const CHECK_IN_TYPE_HASH = + "0xf811d7f3ddb148410001929e2cbfb7fea8779b9349b7c2f650fa91840528d69c"; diff --git a/utils/index.ts b/utils/index.ts index c7bb2d5..2236ffd 100644 --- a/utils/index.ts +++ b/utils/index.ts @@ -4,7 +4,7 @@ import { PAYMENT_OPTION_TYPE_HASH, CANCEL_OPTION_TYPE_HASH, OFFER_TYPE_HASH, -} from "../src/constants"; +} from "./constants"; import { MockERC20Dec18Permit } from "../typechain"; import { PaymentOption,