Skip to content

Commit

Permalink
Merge pull request #226 from lukso-network/refactor/upgrade
Browse files Browse the repository at this point in the history
refactor!: upgrade to contracts v0.12.0 + add `tokenIdType` to LSP8 deployment
  • Loading branch information
CallumGrindle authored Nov 3, 2023
2 parents 4bc7edf + 1a4e210 commit 22f778c
Show file tree
Hide file tree
Showing 21 changed files with 431 additions and 402 deletions.
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"tabWidth": 2,
"semi": true,
"singleQuote": true
}
38 changes: 38 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,44 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [3.1.1](https://github.com/lukso-network/tools-lsp-factory/compare/v3.1.0...v3.1.1) (2023-09-12)


### Bug Fixes

* use default SC version ([ed4a1a2](https://github.com/lukso-network/tools-lsp-factory/commit/ed4a1a2b85a0e1283ceb2142af64a1d74080d940))

## [3.1.0](https://github.com/lukso-network/tools-lsp-factory/compare/v3.0.0...v3.1.0) (2023-09-08)


### ⚠ BREAKING CHANGES

* upgrade lsp to v0.11.1

### Features

* upgrade lsp to v0.11.1 ([ccc61f8](https://github.com/lukso-network/tools-lsp-factory/commit/ccc61f855028c617767f726e317298ee65ee358a))


### Bug Fixes

* enable source map ([e3c60b3](https://github.com/lukso-network/tools-lsp-factory/commit/e3c60b331c213ce5ce6dec8479b577471345d76e))


### Miscellaneous Chores

* release 3.1.0 ([6955282](https://github.com/lukso-network/tools-lsp-factory/commit/6955282cd707d10493dda0acd3d02d91dc607bcc))

## [3.0.0](https://github.com/lukso-network/tools-lsp-factory/compare/v2.5.1...v3.0.0) (2023-08-17)

### ⚠ BREAKING CHANGES

- upgrade smart contracts to v0.10.3 ([#204](https://github.com/lukso-network/tools-lsp-factory/issues/204))

### Features

- upgrade smart contracts to v0.10.3 ([#204](https://github.com/lukso-network/tools-lsp-factory/issues/204)) ([db9d147](https://github.com/lukso-network/tools-lsp-factory/commit/db9d147df5b11dcb95c7a8249c683db49db2cce0))

### [2.5.1](https://github.com/lukso-network/tools-lsp-factory/compare/v2.5.0...v2.5.1) (2023-03-30)

### Bug Fixes
Expand Down
311 changes: 164 additions & 147 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lukso/lsp-factory.js",
"version": "2.5.1",
"version": "3.1.1",
"description": "Helper Library to allow simple deployments of UniversalProfiles and LSP7 and LSP8 Digital Assets.",
"main": "build/main/src/index.js",
"typings": "build/main/src/index.d.ts",
Expand Down Expand Up @@ -33,7 +33,7 @@
"@erc725/erc725.js": "^0.21.0",
"@ethersproject/abi": "^5.7.0",
"@ethersproject/experimental": "^5.7.0",
"@lukso/lsp-smart-contracts": "^0.11.1",
"@lukso/lsp-smart-contracts": "^0.12.0",
"axios": "^0.23.0",
"browser-image-compression": "^2.0.0",
"ethers": "^5.7.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { SUPPORTED_VERIFICATION_FUNCTION_HASHES } from '@erc725/erc725.js/build/main/src/constants/constants';
import { ERC725YDataKeys } from '@lukso/lsp-smart-contracts';
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { providers } from 'ethers';
import { ethers } from 'hardhat';
Expand All @@ -9,8 +11,8 @@ import {
LSPFactory,
} from '../../../build/main/src/index';
import { testDeployWithSpecifiedCreators } from '../../../test/digital-asset.utils';
import { lsp4DigitalAsset } from '../../../test/lsp4-digital-asset.mock';

import { lsp4DigitalAsset } from './../../../test/lsp4-digital-asset.mock';
import { ProxyDeployer } from './proxy-deployer';

jest.setTimeout(30000);
Expand Down Expand Up @@ -228,12 +230,12 @@ describe('LSP7DigitalAsset', () => {
const ownerAddress = await digitalAsset.owner();
expect(ownerAddress).toEqual(controllerAddress);

const data = await digitalAsset.getDataBatch([
'0x9afb95cacc9f95858ec44aa8c3b685511002e30ae54415823f406128b85b238e',
]);
const data = await digitalAsset.getData(ERC725YDataKeys.LSP4.LSP4Metadata);

expect(data[0].startsWith('0x6f357c6a')).toBe(true);
expect(data[0]).toEqual(expectedLSP4Value);
expect(data.startsWith(SUPPORTED_VERIFICATION_FUNCTION_HASHES.HASH_KECCAK256_UTF8)).toBe(
true
);
expect(data).toEqual(expectedLSP4Value);
});
it('should have correct name and symbol set', async () => {
const [retrievedName, retrievedSymbol] = await digitalAsset.getDataBatch([
Expand Down
41 changes: 31 additions & 10 deletions src/lib/classes/lsp8-identifiable-digital-asset.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { SUPPORTED_VERIFICATION_FUNCTION_HASHES } from '@erc725/erc725.js/build/main/src/constants/constants';
import { ERC725YDataKeys, LSP8_TOKEN_ID_TYPES } from '@lukso/lsp-smart-contracts';
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { providers } from 'ethers';
import { ethers } from 'hardhat';
Expand Down Expand Up @@ -37,6 +39,7 @@ describe('LSP8IdentifiableDigitalAsset', () => {
controllerAddress: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
name: 'TOKEN',
symbol: 'TKN',
tokenIdType: LSP8_TOKEN_ID_TYPES.UNIQUE_ID,
});

expect(lsp8IdentifiableDigitalAsset.LSP8IdentifiableDigitalAsset.address).toBeDefined();
Expand All @@ -59,6 +62,7 @@ describe('LSP8IdentifiableDigitalAsset', () => {
controllerAddress: signer.address,
name: 'TOKEN',
symbol: 'TKN',
tokenIdType: LSP8_TOKEN_ID_TYPES.UNIQUE_ID,
},
{
LSP8IdentifiableDigitalAsset: {
Expand Down Expand Up @@ -88,6 +92,7 @@ describe('LSP8IdentifiableDigitalAsset', () => {
controllerAddress: signer.address,
name: 'TOKEN',
symbol: 'TKN',
tokenIdType: LSP8_TOKEN_ID_TYPES.UNIQUE_ID,
},
{
LSP8IdentifiableDigitalAsset: { version: baseContract.address },
Expand Down Expand Up @@ -115,6 +120,7 @@ describe('LSP8IdentifiableDigitalAsset', () => {
}
);
});

it('Should be compatible with RxJS', (done) => {
const myLSPFactory = new LSPFactory(provider, signer);
let lsp8Address: string;
Expand Down Expand Up @@ -157,6 +163,7 @@ describe('LSP8IdentifiableDigitalAsset', () => {
controllerAddress: signer.address,
name: 'TOKEN',
symbol: 'TKN',
tokenIdType: LSP8_TOKEN_ID_TYPES.UNIQUE_ID,
},
{
LSP8IdentifiableDigitalAsset: { version: baseContract.address },
Expand All @@ -176,6 +183,7 @@ describe('LSP8IdentifiableDigitalAsset', () => {
controllerAddress: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
name: 'TOKEN',
symbol: 'TKN',
tokenIdType: LSP8_TOKEN_ID_TYPES.UNIQUE_ID,
},
{
LSP8IdentifiableDigitalAsset: {
Expand Down Expand Up @@ -206,6 +214,7 @@ describe('LSP8IdentifiableDigitalAsset', () => {
controllerAddress: signer.address,
name: 'TOKEN',
symbol: 'TKN',
tokenIdType: LSP8_TOKEN_ID_TYPES.UNIQUE_ID,
},
{
LSP8IdentifiableDigitalAsset: {
Expand Down Expand Up @@ -249,6 +258,8 @@ describe('LSP8IdentifiableDigitalAsset', () => {
const controllerAddress = '0xaDa25A4424b08F5337DacD619D4bCb21536a9B95';
const name = 'TOKEN';
const symbol = 'TKN';
const tokenIdType = LSP8_TOKEN_ID_TYPES.UNIQUE_ID;

const expectedLSP4Value =
'0x6f357c6a4d81f92a409b60c056e13102169c07e03f7de2dbcb79775a8b1f66a55b6278a0697066733a2f2f516d61543479786a45464e6d7163595965547832706e5a46426d71395055737763424c446b394b716f7148504b67';

Expand All @@ -266,6 +277,7 @@ describe('LSP8IdentifiableDigitalAsset', () => {
name,
symbol,
digitalAssetMetadata: lsp4Metadata,
tokenIdType,
});

expect(lsp8DigitalAsset.LSP8IdentifiableDigitalAsset.address).toBeDefined();
Expand All @@ -276,25 +288,32 @@ describe('LSP8IdentifiableDigitalAsset', () => {
signer
);
});

it('should deploy and set LSP4DigitalAsset data', async () => {
const ownerAddress = await digitalAsset.owner();
expect(ownerAddress).toEqual(controllerAddress);

const data = await digitalAsset.getDataBatch([
'0x9afb95cacc9f95858ec44aa8c3b685511002e30ae54415823f406128b85b238e',
]);
const data = await digitalAsset.getData(ERC725YDataKeys.LSP4.LSP4Metadata);

expect(data[0].startsWith('0x6f357c6a')).toBe(true);
expect(data[0]).toEqual(expectedLSP4Value);
expect(data.startsWith(SUPPORTED_VERIFICATION_FUNCTION_HASHES.HASH_KECCAK256_UTF8)).toBe(
true
);
expect(data).toEqual(expectedLSP4Value);
});
it('should have correct name and symbol set', async () => {
const [retrievedName, retrievedSymbol] = await digitalAsset.getDataBatch([
'0xdeba1e292f8ba88238e10ab3c7f88bd4be4fac56cad5194b6ecceaf653468af1',
'0x2f0a68ab07768e01943a599e73362a0e17a63a72e94dd2e384d2c1d4db932756',
]);

it('should have correct name, symbol and token ID type set', async () => {
const [retrievedName, retrievedSymbol, retrievedTokenIdType] =
await digitalAsset.getDataBatch([
ERC725YDataKeys.LSP4.LSP4TokenName,
ERC725YDataKeys.LSP4.LSP4TokenSymbol,
ERC725YDataKeys.LSP8.LSP8TokenIdType,
]);

const tokenIdTypeDecoded = ethers.BigNumber.from(retrievedTokenIdType).toNumber();

expect(ethers.utils.toUtf8String(retrievedName)).toEqual(name);
expect(ethers.utils.toUtf8String(retrievedSymbol)).toEqual(symbol);
expect(tokenIdTypeDecoded).toEqual(tokenIdType);
});
});

Expand All @@ -307,6 +326,7 @@ describe('LSP8IdentifiableDigitalAsset', () => {
'0xFCA72D5763b8cFc686C2285099D5F35a2F094E9f',
'0x591c236982b089Ad4B60758C075fA50Ec53CD674',
];
const tokenIdType = LSP8_TOKEN_ID_TYPES.UNIQUE_ID;

let lspFactory: LSPFactory;

Expand All @@ -326,6 +346,7 @@ describe('LSP8IdentifiableDigitalAsset', () => {
name,
symbol,
creators,
tokenIdType,
});

digitalAsset = LSP8Mintable__factory.connect(
Expand Down
4 changes: 2 additions & 2 deletions src/lib/classes/lsp8-identifiable-digital-asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { LSPFactoryOptions } from '../interfaces';
import {
ContractNames,
DeployedLSP8IdentifiableDigitalAsset,
DigitalAssetDeploymentOptions,
LSP8ContractDeploymentOptions,
LSP8IdentifiableDigitalAssetDeploymentOptions,
} from '../interfaces/digital-asset-deployment';
import {
lsp8BaseContractDeployment$,
Expand Down Expand Up @@ -59,7 +59,7 @@ export class LSP8IdentifiableDigitalAsset {
*```
*/
async deploy(
digitalAssetDeploymentOptions: DigitalAssetDeploymentOptions,
digitalAssetDeploymentOptions: LSP8IdentifiableDigitalAssetDeploymentOptions,
contractDeploymentOptions?: LSP8ContractDeploymentOptions
): Promise<DeployedLSP8IdentifiableDigitalAsset> {
const digitalAssetConfiguration = contractDeploymentOptions
Expand Down
20 changes: 8 additions & 12 deletions src/lib/classes/proxy-deployer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { hexlify, randomBytes } from 'ethers/lib/utils';
import { ethers, SignerWithAddress } from 'hardhat';

import { ProxyDeployer } from './proxy-deployer';
Expand All @@ -16,24 +17,19 @@ describe('UniversalProfile', () => {
baseContracts = await proxyDeployer.deployUniversalProfileBaseContracts();
});

it('should deploy the ERC725Account proxy and setData', async () => {
it('should deploy the ERC725Account proxy and be able to set any data key/value pair', async () => {
// LSPAccount
const erc725AccountProxy = await proxyDeployer.deployProxyContract(
baseContracts.universalProfile
);
await erc725AccountProxy.initialize(await signer.getAddress());

await erc725AccountProxy.setData(
'0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
'0xbeefbeef',
{
from: await signer.getAddress(),
}
);
const data = await erc725AccountProxy.getData(
'0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5'
);
const randomDataKey = hexlify(randomBytes(32));
const randomDataValueExpected = hexlify(randomBytes(4));

expect(data).toEqual('0xbeefbeef');
await erc725AccountProxy.setData(randomDataKey, randomDataValueExpected, {
from: await signer.getAddress(),
});
expect(await erc725AccountProxy.getData(randomDataKey)).toEqual(randomDataValueExpected);
});
});
Loading

0 comments on commit 22f778c

Please sign in to comment.