Skip to content

Commit

Permalink
Merge branch 'main' into lsp23-script
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugoo authored Feb 22, 2024
2 parents ec4e5a3 + bc0079d commit c842992
Show file tree
Hide file tree
Showing 27 changed files with 235 additions and 91 deletions.
18 changes: 0 additions & 18 deletions .eslintrc.cjs

This file was deleted.

19 changes: 19 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"plugins": ["@typescript-eslint", "prettier"],
"env": {
"browser": true,
"es2021": true,
"node": true
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
},
"rules": {
"prettier/prettier": "error",
"@typescript-eslint/no-explicit-any": "off"
},
"ignorePatterns": ["smart-contracts-hardhat/"]
}
1 change: 0 additions & 1 deletion .github/workflows/build-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ on:
jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
smart-contract-hardhat
25 changes: 4 additions & 21 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
{
"plugins": ["prettier-plugin-solidity"],
"overrides": [
{
"files": ["*.js", "*.ts"],
"options": {
"tabWidth": 2,
"printWidth": 100,
"trailingComma": "all",
"singleQuote": true,
"semi": true
}
},
{
"files": "*.sol",
"options": {
"tabWidth": 4,
"printWidth": 80,
"compiler": "0.8.15"
}
}
]
"trailingComma": "all",
"tabWidth": 2,
"semi": true,
"singleQuote": true
}
29 changes: 29 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 💁‍♂️ Contributing to LUKSO Playground

We're thrilled you're interested in contributing to the LUKSO Playground! This space is dedicated to providing developers with code snippets and tools for interacting with LUKSO standards efficiently.

## Getting Started

1. Create a fork of this repository.
2. Clone your repository to make changes.
3. Follow the installation within the [README.md](./README.md)

## Making Changes

1. **Create a separate branch**: For each new feature, docs, or fix, create a new branch in your fork like the following structure: `feature/feature-name` or `fix/issue-fix`, `docs/added-content`. The naming helps organize your contributions and separates them from your main branch.
2. **Commit your changes**: After running `npm run build` and applying styles using `prettier`, you can commit your local changes to your branch. Please ensure that changes are regularly pulled from the `main` branch of the original repository to stay up-to-date and avoid conflicts.
3. **Submit a pull request**: Once your changes are ready and tested, you can push the latest changes to your GitHub fork and `submit a pull request` to this repository. Please provide a clear and detailed explanation of the changes and why they are needed. Include any relevant `issue numbers`.
4. **Review Process**: The project maintainers will review your pull request. Be open to feedback and be prepared to make further changes if requested. Once approved, a maintainer will `merge` your changes into the `main` branch.

## Contribution Guidelines

To ensure a smooth contribution process for everyone, please follow these guidelines:

- **Maintain Generality**: This repository is designed as a generic foundation for developers to start building with LSPs efficiently. Contributions should not introduce features too specific or outside of the LSP ecosystem.
- **Follow Code Styles**: Follow the coding conventions used throughout the project, including indentation, naming conventions, and comments.
- **Build and Test**: Ensure your code does not break the existing functionality. Add tests for any new features or fixes when possible. Any upcoming features should not break existing scripts or contracts.
- **Create Documentation**: Add or update any relevant documentation with your changes, especially if adding new features.

## Report Bugs

If you've found issues within contracts or scripts, please [open a new issue](https://github.com/lukso-network/lukso-playground/issues).
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Please check the versions used in the [`package.json`](./package.json)

> A lot of these scripts should run with `ts-node` in development environnements, but you might be encountering issues because of ESM dependencies.
**The scripts will be run using [`bun`](https://bun.sh/docs/installation) and `bunx`. Make sure you have `bun` installed first.**
**This repository uses the [bun](https://bun.sh) toolkit to manage packages and run scripts.Make sure to [install it](https://bun.sh/docs/installation) first.**

Then clone this repository and install its dependencies.

Expand All @@ -38,7 +38,7 @@ cd lukso-playground && bun install

### Run locally

Run the Typescript code of one file within the terminal using `bun`.
Run the TypeScript code of one file within the terminal using `bun`.

```bash
bun file-path/script.ts
Expand All @@ -51,7 +51,3 @@ We highly recommend that developers fetch and store profile or asset data using
- IPFS Gateway: `https://api.universalprofile.cloud/ipfs`

> LUKSO does not provide an official gateway for uploading asset data.
### Run in browser

Open this project on [StackBlitz](https://stackblitz.com/github/lukso-network/lukso-playground) and start coding right away.
6 changes: 5 additions & 1 deletion digital-assets/backend-token-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ const controller = '0x...'; // Replace with the controller address

// Instantiate the profile contract with an address
const userProfileAddress = '0x...'; // Replace with the user's profile address
const myUniversalProfile = new ethers.Contract(userProfileAddress, UniversalProfile.abi, provider);
const myUniversalProfile = new ethers.Contract(
userProfileAddress,
UniversalProfile.abi,
provider,
);

// Instantiate the token contract with an address
const tokenAddress = '0x...'; // Replace with the token contract address
Expand Down
14 changes: 11 additions & 3 deletions digital-assets/encode-metadata.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ERC725 } from '@erc725/erc725.js';
import { EncodeDataInput } from '@erc725/erc725.js/build/main/src/types/decodeData.js';
import LSP4DigitalAssetSchema from '@erc725/erc725.js/schemas/LSP4DigitalAsset.json';
import { EncodeDataInput } from '@erc725/erc725.js/build/main/src/types/decodeData';

const LSP4SampleJSON = {
LSP4Metadata: {
Expand Down Expand Up @@ -71,11 +71,19 @@ const lsp4SampleMetadata: EncodeDataInput[] = [

// Encode the new LSP4 metadata as Verifiable URI
// https://docs.lukso.tech/tools/erc725js/classes/ERC725#encodedata
const encodedLSP4Metadata = ERC725.encodeData(lsp4SampleMetadata, LSP4DigitalAssetSchema);
const encodedLSP4Metadata = ERC725.encodeData(
lsp4SampleMetadata,
LSP4DigitalAssetSchema,
);
console.log(encodedLSP4Metadata);

const decodedLSP4Metadata = ERC725.decodeData(
[{ keyName: encodedLSP4Metadata.keys[0], value: encodedLSP4Metadata.values[0] }],
[
{
keyName: encodedLSP4Metadata.keys[0],
value: encodedLSP4Metadata.values[0],
},
],
LSP4DigitalAssetSchema,
);

Expand Down
33 changes: 25 additions & 8 deletions digital-assets/extract-asset-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const IPFS_GATEWAY = 'https://api.universalprofile.cloud/ipfs';

// 💡 Note: You can debug any smart contract by using the ERC725 Tools
// 👉 https://erc725-inspect.lukso.tech/inspector?address=0x61b083f1fb63ba2F064990f01B233B547ED4F5Cb&network=mainnet
const SAMPLE_ASSET_CONTRACT_ADDRESS = '0x61b083f1fb63ba2F064990f01B233B547ED4F5Cb';
const SAMPLE_ASSET_CONTRACT_ADDRESS =
'0x61b083f1fb63ba2F064990f01B233B547ED4F5Cb';

// Parameters for the ERC725 instance
const config = { ipfsGateway: IPFS_GATEWAY };
Expand Down Expand Up @@ -51,7 +52,10 @@ async function getAssetProperties(assetJSON: any) {

try {
// Check if images are available
if (assetJSON.value.LSP4Metadata.images && assetJSON.value.LSP4Metadata.images.length > 0) {
if (
assetJSON.value.LSP4Metadata.images &&
assetJSON.value.LSP4Metadata.images.length > 0
) {
assetImageData = assetJSON.value.LSP4Metadata.images;
for (const imageData of assetImageData[0]) {
// Assuming the first set of images is what we want
Expand All @@ -61,26 +65,39 @@ async function getAssetProperties(assetJSON: any) {
url: imageData.url.replace('ipfs://', IPFS_GATEWAY),
});
}
console.log('Asset Image Links: ' + JSON.stringify(assetImageLinks, undefined, 2) + '\n');

fullSizeAssetImage = assetImageLinks.length > 0 ? assetImageLinks[0].url : null;
console.log(
'Asset Image Links: ' +
JSON.stringify(assetImageLinks, undefined, 2) +
'\n',
);

fullSizeAssetImage =
assetImageLinks.length > 0 ? assetImageLinks[0].url : null;
console.log('Full Size Asset Image Link: ' + fullSizeAssetImage + '\n');
} else {
console.log('Asset does not have image data \n');
}

// Check if icons are available
if (assetJSON.value.LSP4Metadata.icon && assetJSON.value.LSP4Metadata.icon.length > 0) {
if (
assetJSON.value.LSP4Metadata.icon &&
assetJSON.value.LSP4Metadata.icon.length > 0
) {
iconImageData = assetJSON.value.LSP4Metadata.icon;
for (const iconData of iconImageData) {
assetIconLinks.push({
url: iconData.url.replace('ipfs://', IPFS_GATEWAY),
});
}

console.log('Asset Icon Links: ' + JSON.stringify(assetIconLinks, undefined, 2) + '\n');
console.log(
'Asset Icon Links: ' +
JSON.stringify(assetIconLinks, undefined, 2) +
'\n',
);

fullSizeIconImage = assetIconLinks.length > 0 ? assetIconLinks[0].url : null;
fullSizeIconImage =
assetIconLinks.length > 0 ? assetIconLinks[0].url : null;
console.log('Full Size Icon Image Link: ' + fullSizeIconImage + '\n');
} else {
console.log('Asset does not have icon data');
Expand Down
23 changes: 18 additions & 5 deletions digital-assets/fetch-tokenid-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { ethers } from 'ethers';
import { ERC725 } from '@erc725/erc725.js';

import lsp4Schema from '@erc725/erc725.js/schemas/LSP4DigitalAsset.json';
import { INTERFACE_IDS, ERC725YDataKeys } from '@lukso/lsp-smart-contracts/constants';
import {
INTERFACE_IDS,
ERC725YDataKeys,
} from '@lukso/lsp-smart-contracts/constants';
import lsp8Artifact from '@lukso/lsp-smart-contracts/artifacts/LSP8IdentifiableDigitalAsset.json';

async function fetchTokenIdMetadata() {
Expand All @@ -16,13 +19,20 @@ async function fetchTokenIdMetadata() {
const provider = new ethers.JsonRpcProvider(RPC_URL);

// Create contract instance
const myAsset = new ethers.Contract(SAMPLE_LSP8_ASSET, lsp8Artifact.abi, provider);
const myAsset = new ethers.Contract(
SAMPLE_LSP8_ASSET,
lsp8Artifact.abi,
provider,
);

const isLSP8 = await myAsset.supportsInterface(INTERFACE_IDS.LSP8IdentifiableDigitalAsset);
const isLSP8 = await myAsset.supportsInterface(
INTERFACE_IDS.LSP8IdentifiableDigitalAsset,
);

if (isLSP8) {
// Token ID as Bytes32 value (1)
const tokenID = '0x0000000000000000000000000000000000000000000000000000000000000001';
const tokenID =
'0x0000000000000000000000000000000000000000000000000000000000000001';

// Get the encoded asset metadata
const tokenIdMetadata = await myAsset.getDataForTokenId(
Expand All @@ -40,7 +50,10 @@ async function fetchTokenIdMetadata() {
},
]);

console.log('Contract Metadata: ', JSON.stringify(decodedMetadata, undefined, 2));
console.log(
'Contract Metadata: ',
JSON.stringify(decodedMetadata, undefined, 2),
);

// Prepare IPFS link to fetch
const contentID = decodedMetadata[0].value.url.replace('ipfs://', '');
Expand Down
22 changes: 16 additions & 6 deletions interface-detection/erc165-interface-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { INTERFACE_IDS } from '@lukso/lsp-smart-contracts';

// 💡 Note: You can debug any smart contract by using the ERC725 Tools
// 👉 https://erc725-inspect.lukso.tech/inspector?address=0x61b083f1fb63ba2F064990f01B233B547ED4F5Cb&network=mainnet
const SAMPLE_ASSET_CONTRACT_ADDRESS = '0x61b083f1fb63ba2F064990f01B233B547ED4F5Cb';
const SAMPLE_ASSET_CONTRACT_ADDRESS =
'0x61b083f1fb63ba2F064990f01B233B547ED4F5Cb';

// https://docs.lukso.tech/networks/mainnet/parameters
const RPC_URL = 'https://rpc.lukso.gateway.fm';
Expand All @@ -20,20 +21,27 @@ const myAsset = new ERC725(lsp4Schema, SAMPLE_ASSET_CONTRACT_ADDRESS, RPC_URL, {

const isLSP7 = await myAsset.supportsInterface(INTERFACE_IDS.LSP7DigitalAsset);

const isLSP8 = await myAsset.supportsInterface(INTERFACE_IDS.LSP8IdentifiableDigitalAsset);
const isLSP8 = await myAsset.supportsInterface(
INTERFACE_IDS.LSP8IdentifiableDigitalAsset,
);

if (isLSP7) {
console.log(`✅ The contract: ${SAMPLE_ASSET_CONTRACT_ADDRESS} supports the LSP7 interface ID`);
console.log(
`✅ The contract: ${SAMPLE_ASSET_CONTRACT_ADDRESS} supports the LSP7 interface ID`,
);
}
if (isLSP8) {
console.log(`✅ The contract: ${SAMPLE_ASSET_CONTRACT_ADDRESS} supports the LSP8 interface ID`);
console.log(
`✅ The contract: ${SAMPLE_ASSET_CONTRACT_ADDRESS} supports the LSP8 interface ID`,
);
}

const provider = new ethers.JsonRpcProvider(RPC_URL);

// 💡 Note: You can debug any smart contract by using the ERC725 Tools
// 👉 https://erc725-inspect.lukso.tech/inspector?address=0xe65e927d0eccaaab6972170b489d3c1455955116&network=mainnet
const universalProfileContractAddress = '0xe65e927d0eccaaab6972170b489d3c1455955116';
const universalProfileContractAddress =
'0xe65e927d0eccaaab6972170b489d3c1455955116';

// Create an instance of the Universal Profile
const myProfileContract = new ethers.Contract(
Expand All @@ -42,7 +50,9 @@ const myProfileContract = new ethers.Contract(
provider,
);

const isLSP0 = await myProfileContract.supportsInterface(INTERFACE_IDS.LSP0ERC725Account);
const isLSP0 = await myProfileContract.supportsInterface(
INTERFACE_IDS.LSP0ERC725Account,
);

if (isLSP0) {
console.log(
Expand Down
14 changes: 10 additions & 4 deletions key-manager/set-permissions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { ethers } from 'ethers';
import { PERMISSIONS, ERC725YDataKeys } from '@lukso/lsp-smart-contracts/constants';
import {
PERMISSIONS,
ERC725YDataKeys,
} from '@lukso/lsp-smart-contracts/constants';
import UniversalProfile from '@lukso/lsp-smart-contracts/artifacts/UniversalProfile.json';

// Connect to the LUKSO Testnet
Expand All @@ -9,7 +12,8 @@ const provider = new ethers.JsonRpcProvider(RPC_ENDPOINT);
const myUniversalProfileAddress = '0x9fc7e5095A054dfA3c6b237E0e5d686638394248';
const myKeyManagerAddress = '0x87fa9105cA247897Acb4F12Ddf6EC3CEF23F6059';

const walletPrivateKey = '0x...'; // Replace with your wallet's private key
const walletPrivateKey =
'0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'; // Replace with your wallet's private key
const wallet = new ethers.Wallet(walletPrivateKey, provider);

const universalProfile = new ethers.Contract(
Expand All @@ -26,9 +30,11 @@ const bobPermissions = PERMISSIONS.SETDATA;
async function setPermission() {
try {
const permissionData = [
ERC725YDataKeys.LSP6['AddressPermissions:Permissions'] + bobAddress.substring(2), // allow Bob to setData on your UP
ERC725YDataKeys.LSP6['AddressPermissions:Permissions'] +
bobAddress.substring(2), // allow Bob to setData on your UP
ERC725YDataKeys.LSP6['AddressPermissions[]'].length, // length of AddressPermissions[]
ERC725YDataKeys.LSP6['AddressPermissions[]'].index + '00000000000000000000000000000001', // add Bob's address into the list of permissions
ERC725YDataKeys.LSP6['AddressPermissions[]'].index +
'00000000000000000000000000000001', // add Bob's address into the list of permissions
];

const permissionParams = [
Expand Down
Loading

0 comments on commit c842992

Please sign in to comment.