Skip to content

Commit

Permalink
Merge pull request #56 from lukso-network/update-issued-assets
Browse files Browse the repository at this point in the history
Update LSP12 Issued Assets Scripts
  • Loading branch information
CJ42 authored Jul 30, 2024
2 parents 455ccfc + d4564a9 commit efb63e7
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 17 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion digital-assets/extract-asset-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ERC725 } from '@erc725/erc725.js';
import LSP4Schema from '@erc725/erc725.js/schemas/LSP4DigitalAsset.json';
import { FetchDataOutput } from '@erc725/erc725.js/build/main/src/types/decodeData.js';

// https://docs.lukso.tech/networks/network/parameters
// https://docs.lukso.tech/networks/mainnet/parameters
const RPC_ENDPOINT = 'https://4201.rpc.thirdweb.com';
const IPFS_GATEWAY = 'https://api.universalprofile.cloud/ipfs';

Expand Down
4 changes: 1 addition & 3 deletions key-manager/execute-relay-call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import { EIP191Signer } from '@lukso/eip191-signer.js';
// This is the version relative to the LSP25 standard, defined as the number 25.
import { LSP25_VERSION } from '@lukso/lsp-smart-contracts/constants';

const provider = new ethers.JsonRpcProvider(
'https://rpc.testnet.lukso.network',
);
const provider = new ethers.JsonRpcProvider('https://4201.rpc.thirdweb.com');
const universalProfileAddress = '0x...';
const recipientAddress = '0x...';

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"isomorphic-fetch": "^3.0.0",
"prettier": "^3.2.4",
"prettier-plugin-solidity": "^1.3.1",
"typescript": "^5.3.3",
"@lukso/eip191-signer.js": "^0.2.2"
"typescript": "^5.3.3"
}
}
2 changes: 2 additions & 0 deletions universal-profile/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PRIVATE_KEY=0x...
UP_ADDR=0x...
2 changes: 1 addition & 1 deletion universal-profile/create-EOA.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ethers } from 'ethers';

// Static variables
const RPC_ENDPOINT = 'https://rpc.testnet.lukso.network/';
const RPC_ENDPOINT = 'https://4201.rpc.thirdweb.com/';

// Setup ethers.js provider
const provider = new ethers.JsonRpcProvider(RPC_ENDPOINT);
Expand Down
2 changes: 1 addition & 1 deletion universal-profile/get-controller-permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const erc725 = new ERC725(
// Sample Profile Address
'0xEda145b45f76EDB44F112B0d46654044E7B8F319',
// LUKSO Testnet RPC
'https://rpc.testnet.lukso.network',
'https://4201.rpc.thirdweb.com',
);

// 💡 You can debug permissions from ERC725 Tools
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { INTERFACE_IDS } from '@lukso/lsp-smart-contracts';
// - LSP12IssuedAssets[]
// - LSP12IssuedAssetsMap:<asset-address>

// add the type of asset (LSP7 or LSP8) and their address in the object list below
// Add the type of asset (LSP7 or LSP8) and their address in the object list below
const issuedAssets = [
{
interfaceId: INTERFACE_IDS.LSP7DigitalAsset,
Expand All @@ -26,16 +26,16 @@ const issuedAssets = [
// },
];

// setup: get the private key of your main controller behind the Universal Profile extension
// or any controller that has access to the Universal Profile
const UNIVERSAL_PROFILE_ADDRESS = '0x9fc7e5095A054dfA3c6b237E0e5d686638394248';
const PRIVATE_KEY = '0x...';
const RPC_ENDPOINT = 'https://rpc.testnet.lukso.network';
// Get the private key of a Universal Profile controller
const UNIVERSAL_PROFILE_ADDRESS = process.env.UP_ADDR || '';
const PRIVATE_KEY = process.env.PRIVATE_KEY || '';

const RPC_ENDPOINT = 'https://4201.rpc.thirdweb.com';

const provider = new ethers.JsonRpcProvider(RPC_ENDPOINT);
const myWallet = new ethers.Wallet(PRIVATE_KEY, provider);

// 1. encode the data keys related to LSP12IssuedAssets[]
// Encode the data keys related to LSP12IssuedAssets[]
const erc725 = new ERC725(
LSP12Schema,
UNIVERSAL_PROFILE_ADDRESS,
Expand All @@ -60,12 +60,12 @@ const { keys: lsp12DataKeys, values: lsp12Values } = erc725.encodeData([
...issuedAssetsMap,
]);

// 2. create an instance of your Universal Profile contract
// Create an instance of your Universal Profile contract
const myUPContract = new ethers.Contract(
UNIVERSAL_PROFILE_ADDRESS,
UniversalProfileArtifact.abi,
myWallet,
);

// 3. set these data keys created at step 1. using `setDataBatch` on the UP address
// Set these data keys on the Universal Profile using `setDataBatch`
await myUPContract.setDataBatch(lsp12DataKeys, lsp12Values);
92 changes: 92 additions & 0 deletions universal-profile/update-issued-assets-backend.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { ethers } from 'ethers';

import { ERC725 } from '@erc725/erc725.js';
import LSP12Schema from '@erc725/erc725.js/schemas/LSP12IssuedAssets.json';

import UniversalProfileArtifact from '@lukso/lsp-smart-contracts/artifacts/UniversalProfile.json';
import { INTERFACE_IDS } from '@lukso/lsp-smart-contracts';

// We will update the issued assets by setting the following LSP12 data keys
// - LSP12IssuedAssets[]
// - LSP12IssuedAssetsMap:<asset-address>

// Add the type of asset (LSP7 or LSP8) and their address in the object list below
const issuedAssets = [
{
interfaceId: INTERFACE_IDS.LSP7DigitalAsset,
address: '0x41b35F490EB6325001fC94E92C58b9d9CC61586D',
},
{
interfaceId: INTERFACE_IDS.LSP8IdentifiableDigitalAsset,
address: '0x2EeF6216274BF0EDe21A8A55CbB5b896Bb82AC8B',
},
// {
// interfaceId: LSP7 or LSP8 interface ID (or other),
// address: '0xasset-address',
// },
];

// Get the private key of a Universal Profile controller
const UNIVERSAL_PROFILE_ADDRESS = process.env.UP_ADDR || '';
const PRIVATE_KEY = process.env.PRIVATE_KEY || '';
const RPC_ENDPOINT = 'https://4201.rpc.thirdweb.com';

const provider = new ethers.JsonRpcProvider(RPC_ENDPOINT);
const myWallet = new ethers.Wallet(PRIVATE_KEY, provider);

// Encode the data keys related to LSP12IssuedAssets[]
const erc725 = new ERC725(
LSP12Schema,
UNIVERSAL_PROFILE_ADDRESS,
RPC_ENDPOINT,
{
ipfsGateway: 'https://api.universalprofile.cloud/ipfs',
},
);

// Get the current addresses and array length
const currentIssuedAssets = await erc725.getData('LSP12IssuedAssets[]');
let currentAssetAddresses = null;
let currentArrayLength: number = 0;

if (Array.isArray(currentIssuedAssets.value)) {
currentAssetAddresses = currentIssuedAssets.value;
currentArrayLength = currentAssetAddresses.length;
}

const newAssetAddresses = issuedAssets.map((asset) => asset.address);

const newIssuedAssetsMapElements = issuedAssets.map((asset, index) => {
return {
keyName: 'LSP12IssuedAssetsMap:<address>',
dynamicKeyParts: asset.address,
value: [
asset.interfaceId,
// index of the issued asset as uint128
// 1 => 0x00000000000000000000000000000001
// Example for adding 2 new assets at the end of the existing map
ERC725.encodeValueType('uint128', currentArrayLength + index),
],
};
});

const { keys: lsp12DataKeys, values: lsp12Values } = erc725.encodeData([
{
keyName: 'LSP12IssuedAssets[]',
value: newAssetAddresses,
// Example for adding 2 new assets at the end of the existing addresses
startingIndex: currentArrayLength,
totalArrayLength: currentArrayLength + newAssetAddresses.length,
},
...newIssuedAssetsMapElements,
]);

// Create an instance of your Universal Profile contract
const myUPContract = new ethers.Contract(
UNIVERSAL_PROFILE_ADDRESS,
UniversalProfileArtifact.abi,
myWallet,
);

// Set these data keys on the Universal Profile using `setDataBatch`
await myUPContract.setDataBatch(lsp12DataKeys, lsp12Values);

0 comments on commit efb63e7

Please sign in to comment.