Skip to content

Commit

Permalink
Merge pull request #27 from lukso-network/more-improvements
Browse files Browse the repository at this point in the history
More improvements
  • Loading branch information
Hugoo authored Feb 2, 2024
2 parents 63b569c + a9c1a40 commit 00c3c70
Show file tree
Hide file tree
Showing 18 changed files with 149 additions and 253 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ Convenient code snippets to interact with [LSP](https://docs.lukso.tech/standard
## Contents

- [`universal-profile`](./universal-profile): Universal Profile related scripts
- [`digital-assets`](./digital-assets/): Digital assets (LSP7/8) scripts
- [`interface-detection`](./interface-detection): Verify EIP165 Standard Compatibility
- [`key-manager`](./key-manager): Permission Management of Controller Keys
- [`metadata-detection`](./metadata-detection): Verify ERC725Y Storage Compatability
- [`transfer-lyx`](./transfer-lyx): Coin Transfers for Backend and Extension
- [`digital-assets`](./digital-assets/): Digital assets (LSP7/8) scripts

### 📑 Smart contracts

Expand All @@ -18,7 +18,6 @@ Convenient code snippets to interact with [LSP](https://docs.lukso.tech/standard
### LUKSO Libraries

- [`@erc725/erc725.js`](https://docs.lukso.tech/tools/erc725js/getting-started)
- [`@lukso/lsp-factory.js`](https://docs.lukso.tech/tools/lsp-factoryjs/getting-started)
- [`@lukso/lsp-smart-contracts`](https://docs.lukso.tech/tools/lsp-smart-contracts/getting-started)

Please check the versions used in the [`package.json`](./package.json)
Expand Down
Binary file modified bun.lockb
Binary file not shown.
31 changes: 20 additions & 11 deletions digital-assets/extract-asset-data.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { ERC725 } from '@erc725/erc725.js';
import LSP4Schema from '@erc725/erc725.js/schemas/LSP4DigitalAsset.json';
import 'isomorphic-fetch';
import { FetchDataOutput } from '@erc725/erc725.js/build/main/src/types/decodeData.js';

// Static variables
const RPC_ENDPOINT = 'https://rpc.testnet.lukso.gateway.fm';
// https://docs.lukso.tech/networks/mainnet/parameters
const RPC_ENDPOINT = 'https://rpc.lukso.gateway.fm';
const IPFS_GATEWAY = 'https://api.universalprofile.cloud/ipfs';
const SAMPLE_ASSET_ADDRESS = '0x6395b330F063F96579aA8F7b59f2584fb9b6c3a5';

// 💡 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';

// Parameters for the ERC725 instance
const config = { ipfsGateway: IPFS_GATEWAY };
Expand Down Expand Up @@ -43,16 +46,18 @@ async function fetchAssetData(address: string): Promise<FetchDataOutput> {
/*
* Read properties of an asset
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async function getAssetProperties(assetJSON: any) {
let assetImageData = [];
let iconImageData = [];
let assetImageData: any = [];
let iconImageData: any = [];

try {
if (assetJSON.value.LSP4Metadata.images[0]) {
assetImageData = assetJSON.value.LSP4Metadata.images;
for (const i in assetImageData) {
assetImageLinks.push([
i,
assetImageData[i].url.replace('ipfs://', IPFS_GATEWAY),
assetImageData[i][0].url.replace('ipfs://', IPFS_GATEWAY),
]);
}
console.log(
Expand Down Expand Up @@ -100,8 +105,12 @@ async function getAssetProperties(assetJSON: any) {
}

// Debug
fetch(SAMPLE_ASSET_ADDRESS).then(async () => {
const assetData = await fetchAssetData(SAMPLE_ASSET_ADDRESS);

const main = async () => {
const assetData = await fetchAssetData(SAMPLE_ASSET_CONTRACT_ADDRESS);
console.log(JSON.stringify(assetData, undefined, 2));
getAssetProperties(assetData);
});
// TODO: this does not work
// getAssetProperties(assetData);
};

main();
79 changes: 44 additions & 35 deletions interface-detection/erc165-interface-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,67 @@ import lsp4Schema from '@erc725/erc725.js/schemas/LSP4DigitalAsset.json';
import UniversalProfile from '@lukso/lsp-smart-contracts/artifacts/UniversalProfile.json';
import { INTERFACE_IDS } from '@lukso/lsp-smart-contracts';

// https://docs.lukso.tech/contracts/interface-ids
// https://docs.lukso.tech/learn/dapp-developer/standard-detection

// Asset Example
const myAsset = new ERC725(
lsp4Schema,
'0x6395b330F063F96579aA8F7b59f2584fb9b6c3a5',
'https://rpc.testnet.lukso.gateway.fm',
{
ipfsGateway: 'https://api.universalprofile.cloud/ipfs',
},
);
// 📚 https://docs.lukso.tech/contracts/interface-ids
// 📚 https://docs.lukso.tech/learn/dapp-developer/standard-detection

// 💡 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';

// https://docs.lukso.tech/networks/mainnet/parameters
const RPC_URL = 'https://rpc.lukso.gateway.fm';

const myAsset = new ERC725(lsp4Schema, SAMPLE_ASSET_CONTRACT_ADDRESS, RPC_URL, {
ipfsGateway: 'https://api.universalprofile.cloud/ipfs',
});

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

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

console.log(isLSP7, isLSP8); // true or false
if (isLSP7) {
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`,
);
}

// Profile Example
const provider = new ethers.JsonRpcProvider(
'https://rpc.testnet.lukso.network',
);
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';

// Create an instance of the Universal Profile
const myProfile = new ethers.Contract(
'0x9139def55c73c12bcda9c44f12326686e3948634',
const myProfileContract = new ethers.Contract(
universalProfileContractAddress,
UniversalProfile.abi,
provider,
);

const isLSP0 = await myProfile.supportsInterface(
const isLSP0 = await myProfileContract.supportsInterface(
INTERFACE_IDS.LSP0ERC725Account,
);
console.log(isLSP0); // true or false

if (isLSP0) {
console.log(
`✅ The contract: ${universalProfileContractAddress} supports the LSP0ERC725Account interface ID`,
);
} else {
console.log(
`❌ The address: ${universalProfileContractAddress} does not supports the LSP0ERC725Account interface ID`,
);
}

/*
Supported interfaces from lsp-smart-contracts library:
INTERFACE_IDS.ERC165 INTERFACE_IDS.ERC20
INTERFACE_IDS.ERC223 INTERFACE_IDS.ERC721
INTERFACE_IDS.ERC721Metadata INTERFACE_IDS.ERC725X
INTERFACE_IDS.ERC725Y INTERFACE_IDS.ERC777
INTERFACE_IDS.ERC1155
INTERFACE_IDS.LSP0ERC725Account INTERFACE_IDS.LSP1UniversalReceiver
INTERFACE_IDS.LSP6KeyManager INTERFACE_IDS.LSP7DigitalAsset
INTERFACE_IDS.LSP8IdentifiableDigitalAsset INTERFACE_IDS.LSP9Vault
INTERFACE_IDS.LSP11BasicSocialRecovery INTERFACE_IDS.LSP14Ownable2Step
INTERFACE_IDS.LSP17Extendable INTERFACE_IDS.LSP17Extension
INTERFACE_IDS.LSP20CallVerification INTERFACE_IDS.LSP20CallVerifier
INTERFACE_IDS.LSP25ExecuteRelayCall
https://docs.lukso.tech/tools/lsp-smart-contracts/constants
*/
2 changes: 1 addition & 1 deletion key-manager/set-permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async function setPermission() {

const permissionParams = [
bobPermissions,
3, // 3 because UP owner + Universal Receiver Delegate permission have already been set by lsp-factory
3, // 3 because UP owner + Universal Receiver Delegate permission have already been set on profile creation
bobAddress,
];

Expand Down
4 changes: 4 additions & 0 deletions metadata-detection/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ Before interacting with a smart contract, you might need to check if the contrac

- https://docs.lukso.tech/standards/standard-detection
- https://docs.lukso.tech/standards/tokens/LSP4-Digital-Asset-Metadata#supportedstandardslsp4digitalasset

## Related guides

- [Standard Detection - LUKSO Guides](https://docs.lukso.tech/learn/dapp-developer/standard-detection/#metadata-detection)
38 changes: 17 additions & 21 deletions metadata-detection/digital-asset-check.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
import { ERC725 } from '@erc725/erc725.js';
import lsp4Schema from '@erc725/erc725.js/schemas/LSP4DigitalAsset.json';

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

// Initatiate erc725.js
const erc725js = new ERC725(
lsp4Schema,
'0x6395b330F063F96579aA8F7b59f2584fb9b6c3a5',
'https://rpc.testnet.lukso.gateway.fm',
assetContractAddress,
'https://rpc.lukso.gateway.fm',
{},
);

// Fetch the supported storage standard
let isLSP4 = false;

// Verify if the standard is supported (value !== null)
// 📚 https://docs.lukso.tech/standards/tokens/LSP4-Digital-Asset-Metadata#supportedstandardslsp4digitalasset
const data = await erc725js.getData('SupportedStandards:LSP4DigitalAsset');
if (data.value !== null) {
isLSP4 = true;
}

console.log(isLSP4);
const isLSP4 = data.value !== null;

/*
Supported schemas from erc725.js library:
LSP1UniversalReceiverDelegate LSP3ProfileMetadata
LSP4DigitalAsset LSP5ReceivedAssets
LSP6KeyManager LSP8IdentifiableDigitalAsset
LSP9Vault LSP10ReceivedVaults
LSP12IssuedAssets LSP17ContractExtension
All fetchable keys can be found within @erc725/erc725.js/schemas/[schema].json
*/
if (isLSP4) {
console.log(
`✅ The contract: ${assetContractAddress} supports the LSP4DigitalAsset standard`,
);
} else {
console.log(
`❌ The address: ${assetContractAddress} does not supports the LSP4DigitalAsset standard`,
);
}
37 changes: 17 additions & 20 deletions metadata-detection/profile-check.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
import { ERC725 } from '@erc725/erc725.js';
import lsp3ProfileSchema from '@erc725/erc725.js/schemas/LSP3ProfileMetadata.json';

// 💡 Note: You can debug any smart contract by using the ERC725 Tools
// 👉 https://erc725-inspect.lukso.tech/inspector?address=0x9139def55c73c12bcda9c44f12326686e3948634&network=testnet

const profileContractAddress = '0x9139def55c73c12bcda9c44f12326686e3948634';

// Initatiate erc725.js
const erc725js = new ERC725(
lsp3ProfileSchema,
'0x9139def55c73c12bcda9c44f12326686e3948634',
profileContractAddress,
'https://rpc.testnet.lukso.gateway.fm',
{},
);

// Fetch the supported storage standard
let isLSP3 = false;

// Verify if the standard is supported (value !== null)
// 📚 https://docs.lukso.tech/standards/universal-profile/lsp3-profile-metadata/#supportedstandardslsp3profile
const data = await erc725js.getData('SupportedStandards:LSP3Profile');
if (data.value !== null) {
isLSP3 = true;
}
const isLSP3 = data.value !== null;

console.log(isLSP3);

/*
Supported schemas from erc725.js library:
LSP1UniversalReceiverDelegate LSP3ProfileMetadata
LSP4DigitalAsset LSP5ReceivedAssets
LSP6KeyManager LSP8IdentifiableDigitalAsset
LSP9Vault LSP10ReceivedVaults
LSP12IssuedAssets LSP17ContractExtension
All fetchable keys can be found within @erc725/erc725.js/schemas/[schema].json
*/
if (isLSP3) {
console.log(
`✅ The contract: ${profileContractAddress} supports the LSP3Profile standard`,
);
} else {
console.log(
`❌ The address: ${profileContractAddress} does not supports the LSP3Profile standard`,
);
}
36 changes: 16 additions & 20 deletions metadata-detection/vault-check.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
import { ERC725 } from '@erc725/erc725.js';
import lsp9VaultSchema from '@erc725/erc725.js/schemas/LSP9Vault.json';

// 📚 https://docs.lukso.tech/learn/dapp-developer/standard-detection/#metadata-detection

// TODO: this is an old vault and its interface ID is not correct
const vaultContractAddress = '0x9139def55c73c12bcda9c44f12326686e3948634';

// Initatiate erc725.js
const erc725js = new ERC725(
lsp9VaultSchema,
'0x9139def55c73c12bcda9c44f12326686e3948634',
vaultContractAddress,
'https://rpc.testnet.lukso.gateway.fm',
{},
);

// Fetch the supported storage standard
let isLSP9 = false;

// Verify if the standard is supported (value !== null)
const data = await erc725js.getData('SupportedStandards:LSP9Vault');
if (data.value !== null) {
isLSP9 = true;
}
const isLSP9 = data.value !== null;

console.log(isLSP9);

/*
Supported schemas from erc725.js library:
LSP1UniversalReceiverDelegate LSP3ProfileMetadata
LSP4DigitalAsset LSP5ReceivedAssets
LSP6KeyManager LSP8IdentifiableDigitalAsset
LSP9Vault LSP10ReceivedVaults
LSP12IssuedAssets LSP17ContractExtension
All fetchable keys can be found within @erc725/erc725.js/schemas/[schema].json
*/
if (isLSP9) {
console.log(
`✅ The contract: ${vaultContractAddress} supports the LSP9Vault standard`,
);
} else {
console.log(
`❌ The address: ${vaultContractAddress} does not supports the LSP9Vault standard`,
);
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
},
"devDependencies": {
"@erc725/erc725.js": "^0.23.0",
"@lukso/lsp-factory.js": "^3.3.1",
"@lukso/lsp-smart-contracts": "^0.14.0",
"ethers": "^6.10.0",
"@typescript-eslint/eslint-plugin": "^6.20.0",
Expand Down
5 changes: 4 additions & 1 deletion transfer-lyx/backend-lyx-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const provider = new ethers.JsonRpcProvider(RPC_ENDPOINT);
// Get the controller key of the Universal Profile
const controller = '0x...'; // Replace with the controller address

// 💡 Request LYXt from the faucet:
// 🚰 https://faucet.testnet.lukso.network/

// Instantiate Universal Profile
const userProfileAddress = '0x...'; // Replace with the user's profile address
const myUniversalProfile = new ethers.Contract(
Expand All @@ -23,7 +26,7 @@ const myUniversalProfile = new ethers.Contract(
const transaction = await myUniversalProfile.execute(
0, // operation of type CALL
'0x...', // recipient address including profiles and vaults
ethers.parseEther('3'), // amount in LYX, converting to wei
ethers.parseEther('0.5'), // amount in LYX, converting to wei
'0x...', // contract calldata, empty for regular transfer
{ gasLimit: 300000, from: controller }, // gas limit of the transaction and sender address
);
Expand Down
3 changes: 3 additions & 0 deletions transfer-lyx/regular-lyx-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const provider = new ethers.BrowserProvider(window.ethereum);

// https://docs.lukso.tech/learn/dapp-developer/transfer-lyx

// 💡 Request LYXt from the faucet:
// 🚰 https://faucet.testnet.lukso.network/

try {
// Request user accounts (connect to wallet)
const accounts = await provider.send('eth_requestAccounts', []);
Expand Down
Loading

0 comments on commit 00c3c70

Please sign in to comment.