Skip to content

Commit

Permalink
Merge branch 'lsp-monorepo' into package/lukso-lsp-smart-contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
CJ42 committed Feb 29, 2024
2 parents 207b816 + d41145c commit 1a00ad2
Show file tree
Hide file tree
Showing 29 changed files with 129 additions and 137 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,34 @@ For more information see [Documentation](https://docs.lukso.tech/standards/smart
| :warning: | _This package is currently in early stages of development,<br/> use for testing or experimentation purposes only._ |
| :-------: | :----------------------------------------------------------------------------------------------------------------- |

## Packages

This repo contains packages for the Solidity implementation of the LSP smart contracts.

| Package | NPM | Description |
| ---------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------- |
| [`@lukso/lsp0-contracts`](./packages/lsp0-contracts) | [![npm version](https://img.shields.io/npm/v/@lukso/lsp0-contracts.svg?style=flat)](https://www.npmjs.com/package/@lukso/lsp0-contracts) | LSP0 ERC725Account |
| [`@lukso/lsp1-contracts`](./packages/lsp1-contracts) | [![npm version](https://img.shields.io/npm/v/@lukso/lsp1-contracts.svg?style=flat)](https://www.npmjs.com/package/@lukso/lsp1-contracts) | LSP1 Universal Receiver |
| [`@lukso/lsp1delegate-contracts`](./packages/lsp1delegate-contracts) | [![npm version](https://img.shields.io/npm/v/@lukso/lsp1delegate-contracts.svg?style=flat)](https://www.npmjs.com/package/@lukso/lsp1delegate-contracts) | LSP1 Universal Receiver Delegate |
| [`@lukso/lsp2-contracts`](./packages/lsp2-contracts) | [![npm version](https://img.shields.io/npm/v/@lukso/lsp2-contracts.svg?style=flat)](https://www.npmjs.com/package/@lukso/lsp2-contracts) | LSP2 ERC725Y JSON Schema |
| [`@lukso/lsp3-contracts`](./packages/lsp3-contracts) | [![npm version](https://img.shields.io/npm/v/@lukso/lsp3-contracts.svg?style=flat)](https://www.npmjs.com/package/@lukso/lsp3-contracts) | LSP3 Profile Metadata |
| [`@lukso/lsp4-contracts`](./packages/lsp4-contracts) | [![npm version](https://img.shields.io/npm/v/@lukso/lsp4-contracts.svg?style=flat)](https://www.npmjs.com/package/@lukso/lsp4-contracts) | LSP4 Digital Asset Metadata |
| [`@lukso/lsp5-contracts`](./packages/lsp5-contracts) | [![npm version](https://img.shields.io/npm/v/@lukso/lsp5-contracts.svg?style=flat)](https://www.npmjs.com/package/@lukso/lsp5-contracts) | LSP5 Received Assets |
| [`@lukso/lsp6-contracts`](./packages/lsp6-contracts) | [![npm version](https://img.shields.io/npm/v/@lukso/lsp6-contracts.svg?style=flat)](https://www.npmjs.com/package/@lukso/lsp6-contracts) | LSP6 Key Manager |
| [`@lukso/lsp7-contracts`](./packages/lsp7-contracts) | [![npm version](https://img.shields.io/npm/v/@lukso/lsp7-contracts.svg?style=flat)](https://www.npmjs.com/package/@lukso/lsp7-contracts) | LSP7 Digital Asset |
| [`@lukso/lsp8-contracts`](./packages/lsp8-contracts) | [![npm version](https://img.shields.io/npm/v/@lukso/lsp8-contracts.svg?style=flat)](https://www.npmjs.com/package/@lukso/lsp8-contracts) | LSP8 Identifiable Digital Asset |
| [`@lukso/lsp9-contracts`](./packages/lsp9-contracts) | [![npm version](https://img.shields.io/npm/v/@lukso/lsp9-contracts.svg?style=flat)](https://www.npmjs.com/package/@lukso/lsp9-contracts) | LSP9 Vault |
| [`@lukso/lsp10-contracts`](./packages/lsp10-contracts) | [![npm version](https://img.shields.io/npm/v/@lukso/lsp10-contracts.svg?style=flat)](https://www.npmjs.com/package/@lukso/lsp10-contracts) | LSP10 Received Vaults |
| [`@lukso/lsp12-contracts`](./packages/lsp12-contracts) | [![npm version](https://img.shields.io/npm/v/@lukso/lsp12-contracts.svg?style=flat)](https://www.npmjs.com/package/@lukso/lsp12-contracts) | LSP12 Issued Assets |
| [`@lukso/lsp14-contracts`](./packages/lsp14-contracts) | [![npm version](https://img.shields.io/npm/v/@lukso/lsp14-contracts.svg?style=flat)](https://www.npmjs.com/package/@lukso/lsp14-contracts) | LSP14 Ownable 2 Step |
| [`@lukso/lsp16-contracts`](./packages/lsp16-contracts) | [![npm version](https://img.shields.io/npm/v/@lukso/lsp16-contracts.svg?style=flat)](https://www.npmjs.com/package/@lukso/lsp16-contracts) | LSP16 Universal Factory |
| [`@lukso/lsp17-contracts`](./packages/lsp17-contracts) | [![npm version](https://img.shields.io/npm/v/@lukso/lsp17-contracts.svg?style=flat)](https://www.npmjs.com/package/@lukso/lsp17-contracts) | LSP17 Extensions Package |
| [`@lukso/lsp17contractextension-contracts`](./packages/lsp17contractextension-contracts) | [![npm version](https://img.shields.io/npm/v/@lukso/lsp17contractextension-contracts.svg?style=flat)](https://www.npmjs.com/package/@lukso/lsp17contractextension-contracts) | LSP17 Contract Extension Package |
| [`@lukso/lsp20-contracts`](./packages/lsp20-contracts) | [![npm version](https://img.shields.io/npm/v/@lukso/lsp20-contracts.svg?style=flat)](https://www.npmjs.com/package/@lukso/lsp20-contracts) | LSP20 Call Verification |
| [`@lukso/lsp23-contracts`](./packages/lsp23-contracts) | [![npm version](https://img.shields.io/npm/v/@lukso/lsp23-contracts.svg?style=flat)](https://www.npmjs.com/package/@lukso/lsp23-contracts) | LSP23 Linked Contracts Factory |
| [`@lukso/lsp25-contracts`](./packages/lsp25-contracts) | [![npm version](https://img.shields.io/npm/v/@lukso/lsp25-contracts.svg?style=flat)](https://www.npmjs.com/package/@lukso/lsp25-contracts) | LSP25 Execute Relay Call |
| [`@lukso/universalprofile-contracts`](./packages/universalprofile-contracts) | [![npm version](https://img.shields.io/npm/v/@lukso/universalprofile-contracts.svg?style=flat)](https://www.npmjs.com/package/@lukso/universalprofile-contracts) | Universal Profile |

## Installation

### npm
Expand Down
10 changes: 4 additions & 6 deletions packages/lsp-smart-contracts/dodoc/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ethers } from 'ethers';
import { keccak256, toUtf8Bytes } from 'ethers';
import { HelperContent } from 'squirrelly/dist/types/containers';

export const dodocConfig = {
Expand Down Expand Up @@ -331,9 +331,7 @@ const generateAdditionalMethodInfo = (contract: string, code: string) => {
) {
infoBlock +=
`- Function signature: \`${formatedCode}\`\n` +
`- Function selector: \`${ethers
.keccak256(ethers.toUtf8Bytes(formatedCode))
.substring(0, 10)}\``;
`- Function selector: \`${keccak256(toUtf8Bytes(formatedCode)).substring(0, 10)}\``;
}

return infoBlock;
Expand All @@ -350,7 +348,7 @@ const generateAdditionalEventInfo = (contract: string, code: string) => {
.toLowerCase()})\n` +
`- Solidity implementation: [\`${contract}.sol\`](${contractLink})\n` +
`- Event signature: \`${formatedCode}\`\n` +
`- Event topic hash: \`${ethers.keccak256(ethers.toUtf8Bytes(formatedCode))}\``
`- Event topic hash: \`${keccak256(toUtf8Bytes(formatedCode))}\``
);
};

Expand All @@ -365,7 +363,7 @@ const generateAdditionalErrorInfo = (contract: string, code: string) => {
.toLowerCase()})\n` +
`- Solidity implementation: [\`${contract}.sol\`](${contractLink})\n` +
`- Error signature: \`${formatedCode}\`\n` +
`- Error hash: \`${ethers.keccak256(ethers.toUtf8Bytes(formatedCode)).substring(0, 10)}\``
`- Error hash: \`${keccak256(toUtf8Bytes(formatedCode)).substring(0, 10)}\``
);
};

Expand Down
4 changes: 2 additions & 2 deletions packages/lsp-smart-contracts/scripts/ci/docs-generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from 'fs';
import path from 'path';
import { task } from 'hardhat/config';
import { TASK_COMPILE } from 'hardhat/builtin-tasks/task-names';
import { ethers } from 'ethers';
import { keccak256, toUtf8Bytes } from 'ethers';
import pluralize from 'pluralize';
import { mkdir, rm, stat, writeFile } from 'fs/promises';
import { CompilerOutputContract } from 'hardhat/types';
Expand Down Expand Up @@ -239,7 +239,7 @@ task('ts-gen', 'Generate NatSpec documentation automatically on compilation')
} = allMembers;

for (const [sig, member] of Object.entries(allMembers)) {
const hash = ethers.keccak256(ethers.toUtf8Bytes(sig));
const hash = keccak256(toUtf8Bytes(sig));
member.hash = member.type === 'event' ? hash : hash.slice(0, 10);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import { getBytes, dataSlice, keccak256, BytesLike } from 'ethers';
import { Wallet } from 'ethers';
import {
getBytes,
dataSlice,
keccak256,
BytesLike,
AbiCoder,
toBigInt,
toBeHex,
hexlify,
toNumber,
Wallet,
} from 'ethers';
import { AddressZero, callDataCost } from './utils';
import { ecsign, toRpcSig, keccak256 as keccak256_buffer } from 'ethereumjs-util';
import { Create2Factory } from './Create2Factory';
import { EntryPoint } from '@account-abstraction/contracts';
import { ethers } from 'ethers';
import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers';
import * as typ from './solidityTypes';
import { ethers as hreEther } from 'hardhat';
Expand All @@ -26,7 +35,7 @@ export interface UserOperation {
export function packUserOp(op: UserOperation, forSignature = true): string {
if (forSignature) {
// Encoding the UserOperation object fields into a single string for signature
return ethers.AbiCoder.defaultAbiCoder().encode(
return AbiCoder.defaultAbiCoder().encode(
[
'address',
'uint256',
Expand Down Expand Up @@ -54,7 +63,7 @@ export function packUserOp(op: UserOperation, forSignature = true): string {
);
} else {
// Encoding the UserOperation object fields into a single string including the signature
return ethers.AbiCoder.defaultAbiCoder().encode(
return AbiCoder.defaultAbiCoder().encode(
[
'address',
'uint256',
Expand Down Expand Up @@ -88,7 +97,7 @@ export function packUserOp(op: UserOperation, forSignature = true): string {
export function getUserOpHash(op: UserOperation, entryPoint: string, chainId: number): string {
const userOpHash = keccak256(packUserOp(op, true));
// Encoding the UserOperation hash, entryPoint address, and chainId for final hash computation
const enc = ethers.AbiCoder.defaultAbiCoder().encode(
const enc = AbiCoder.defaultAbiCoder().encode(
['bytes32', 'address', 'uint256'],
[userOpHash, entryPoint, chainId],
);
Expand Down Expand Up @@ -189,14 +198,13 @@ export async function fillUserOp(
data: initCallData,
gasLimit: 10e6,
});
op1.verificationGasLimit =
ethers.toBigInt(DefaultsForUserOp.verificationGasLimit) + initEstimate;
op1.verificationGasLimit = toBigInt(DefaultsForUserOp.verificationGasLimit) + initEstimate;
}
}
if (op1.nonce == null) {
if (provider == null) throw new Error('must have entryPoint to autofill nonce');

const signerKeyAsUint192 = ethers.toBeHex(ethers.toBigInt(signer.address));
const signerKeyAsUint192 = toBeHex(toBigInt(signer.address));

try {
op1.nonce = await entryPoint.getNonce(op1.sender, signerKeyAsUint192);
Expand All @@ -209,7 +217,7 @@ export async function fillUserOp(
const gasEtimated = await provider.estimateGas({
from: entryPoint?.target,
to: op1.sender,
data: ethers.hexlify(op1.callData as BytesLike),
data: hexlify(op1.callData as BytesLike),
});

op1.callGasLimit = gasEtimated;
Expand Down Expand Up @@ -242,9 +250,7 @@ export async function fillAndSign(
const op2 = await fillUserOp(op, signer, entryPoint);

const chainId = await provider.getNetwork().then((net) => net.chainId);
const message = getBytes(
getUserOpHash(op2, entryPoint.target as string, ethers.toNumber(chainId)),
);
const message = getBytes(getUserOpHash(op2, entryPoint.target as string, toNumber(chainId)));

return {
...op2,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import { ethers } from 'ethers';
import { hashMessage, parseEther, toUtf8Bytes } from 'ethers';
import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers';

import {
Expand Down Expand Up @@ -166,7 +166,7 @@ export const shouldBehaveLikePermissionStaticCall = (
});

it('should revert with error `ERC725X_MsgValueDisallowedInStaticCall` if `value` param is not 0', async () => {
const LyxAmount = ethers.parseEther('3');
const LyxAmount = parseEther('3');

const targetContractPayload = targetContract.interface.encodeFunctionData('getName');

Expand All @@ -191,7 +191,7 @@ export const shouldBehaveLikePermissionStaticCall = (
it('should pass and return data when `value` param is 0', async () => {
const message = 'some message to sign';
const signature = await context.mainController.signMessage(message);
const messageHash = ethers.hashMessage(message);
const messageHash = hashMessage(message);

const erc1271ContractPayload = signatureValidator.interface.encodeFunctionData(
'isValidSignature',
Expand All @@ -216,11 +216,11 @@ export const shouldBehaveLikePermissionStaticCall = (
});

it('should revert with error `ERC725X_MsgValueDisallowedInStaticCall` if `value` param is not 0', async () => {
const lyxAmount = ethers.parseEther('3');
const lyxAmount = parseEther('3');

const message = 'some message to sign';
const signature = await context.mainController.signMessage(message);
const messageHash = ethers.hashMessage(message);
const messageHash = hashMessage(message);

const erc1271ContractPayload = signatureValidator.interface.encodeFunctionData(
'isValidSignature',
Expand Down Expand Up @@ -252,7 +252,7 @@ export const shouldBehaveLikePermissionStaticCall = (
context.mainController.address,
context.mainController.address,
1,
ethers.toUtf8Bytes('some data'),
toUtf8Bytes('some data'),
],
);

Expand All @@ -279,7 +279,7 @@ export const shouldBehaveLikePermissionStaticCall = (
});

it('should revert with error `ERC725X_MsgValueDisallowedInStaticCall` if `value` param is not 0', async () => {
const lyxAmount = ethers.parseEther('3');
const lyxAmount = parseEther('3');

// the params are not relevant for this test and just used as placeholders.
const onERC721Payload = onERC721ReceivedContract.interface.encodeFunctionData(
Expand All @@ -288,7 +288,7 @@ export const shouldBehaveLikePermissionStaticCall = (
context.mainController.address,
context.mainController.address,
1,
ethers.toUtf8Bytes('some data'),
toUtf8Bytes('some data'),
],
);

Expand Down Expand Up @@ -332,7 +332,7 @@ export const shouldBehaveLikePermissionStaticCall = (
});

it('should revert with error `ERC725X_MsgValueDisallowedInStaticCall` if `value` parameter is not 0', async () => {
const lyxAmount = ethers.parseEther('3');
const lyxAmount = parseEther('3');

const targetContractPayload = targetContract.interface.encodeFunctionData('setName', [
'modified name',
Expand Down Expand Up @@ -655,7 +655,7 @@ export const shouldBehaveLikePermissionStaticCall = (
it('should revert with error `ERC725X_MsgValueDisallowedInStaticCall` when `value` param is not 0', async () => {
const randomContract = await new TargetContract__factory(context.accounts[0]).deploy();

const lyxAmount = ethers.parseEther('3');
const lyxAmount = parseEther('3');

const payload = context.universalProfile.interface.encodeFunctionData('execute', [
OPERATION_TYPES.STATICCALL,
Expand Down Expand Up @@ -815,7 +815,7 @@ export const shouldBehaveLikePermissionStaticCall = (
const executePayload = context.universalProfile.interface.encodeFunctionData('execute', [
OPERATION_TYPES.STATICCALL,
await allowedTargetContracts[0].getAddress(),
ethers.parseEther('3'),
parseEther('3'),
targetPayload,
]);

Expand Down Expand Up @@ -857,7 +857,7 @@ export const shouldBehaveLikePermissionStaticCall = (
const executePayload = context.universalProfile.interface.encodeFunctionData('execute', [
OPERATION_TYPES.STATICCALL,
await allowedTargetContracts[1].getAddress(),
ethers.parseEther('3'),
parseEther('3'),
targetPayload,
]);

Expand Down
Loading

0 comments on commit 1a00ad2

Please sign in to comment.