Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Draft]: Add Solidity code samples to migrate from ERC20/721 to LSP7/8 #54

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft
9 changes: 9 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
image: gitpod/workspace-full

# Commands that will run on workspace start
tasks:
- name: Setup, Install & Build
init: |
cd ./smart-contracts-hardhat
npm install
npm run build
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
smart-contract-hardhat
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

Convenient code snippets to interact with [LSP](https://docs.lukso.tech/standards/standards-roadmap) standards on LUKSO. Code examples are taken from the [LUKSO Tech Docs](https://docs.lukso.tech/) and are working as standalone scripts.

## Want to get started quickly?

**Start prototyping quickly on a [Gitpod](https://gitpod.io/)!**

_This will open the repository and setup everything for you automatically (install dependencies 📦, build contracts 🏗️, etc...)_

[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/CJ42/lukso-playground/tree/migrate-erc-lsp)

## Contents

- [`universal-profile`](./universal-profile): Universal Profile related scripts
Expand Down
Binary file modified smart-contracts-hardhat/bun.lockb
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDC-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.17;

// interfaces
Expand Down
49 changes: 49 additions & 0 deletions smart-contracts-hardhat/contracts/MigrateERCToLSP/ERC20ToLSP7.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// SPDX-License-Identifier: MIT
// Compatible with OpenZeppelin Contracts <4.9.6
pragma solidity ^0.8.19;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract EcoCoinAsERC20 is ERC20, ERC20Burnable, Ownable {
constructor(address initialOwner) ERC20("EcoCoin", "ECN") {
_transferOwnership(initialOwner);
_mint(msg.sender, 10000 * 10 ** decimals());
}

function mint(address to, uint256 amount) public onlyOwner {
_mint(to, amount);
}
}

// --------

// modules
import {
LSP7DigitalAsset
} from "@lukso/lsp7-contracts/contracts/LSP7DigitalAsset.sol";
import {
LSP7Burnable
} from "@lukso/lsp7-contracts/contracts/extensions/LSP7Burnable.sol";

// constants
import {
_LSP4_TOKEN_TYPE_TOKEN
} from "@lukso/lsp4-contracts/contracts/LSP4Constants.sol";

contract EcoCoinAsLSP7 is LSP7DigitalAsset, LSP7Burnable {
constructor(
address initialOwner
)
LSP7DigitalAsset(
"EcoCoin",
"ECN",
initialOwner,
_LSP4_TOKEN_TYPE_TOKEN,
false
)
{
_mint(msg.sender, 10_000 * 10 ** decimals(), true, "0x");
}
}
47 changes: 47 additions & 0 deletions smart-contracts-hardhat/contracts/MigrateERCToLSP/ERC721ToLSP8.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// SPDX-License-Identifier: MIT
// Compatible with OpenZeppelin Contracts <4.9.6
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract TimeCapsulezAsERC721 is ERC721, ERC721Burnable, Ownable {
constructor(address initialOwner) ERC721("Time Capsulez", "TCZ") {
_transferOwnership(initialOwner);
}

function safeMint(address to, uint256 tokenId) public onlyOwner {
_safeMint(to, tokenId);
}
}

// modules
import {
LSP8Mintable
} from "@lukso/lsp8-contracts/contracts/presets/LSP8Mintable.sol";
import {
LSP8Burnable
} from "@lukso/lsp-smart-contracts/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Burnable.sol";

// constants
import {
_LSP4_TOKEN_TYPE_COLLECTION
} from "@lukso/lsp4-contracts/contracts/LSP4Constants.sol";
import {
_LSP8_TOKENID_FORMAT_NUMBER
} from "@lukso/lsp8-contracts/contracts/LSP8Constants.sol";

contract TimeCapsulezAsLSP8 is LSP8Mintable, LSP8Burnable {
constructor(
address initialOwner
)
LSP8Mintable(
"Time Capsulez",
"TCZ",
initialOwner,
_LSP4_TOKEN_TYPE_COLLECTION, // number `2`
_LSP8_TOKENID_FORMAT_NUMBER // number `0`
)
{}
}
44 changes: 44 additions & 0 deletions smart-contracts-hardhat/contracts/MigrateERCToLSP/MyToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// SPDX-License-Identifier: MIT
// Compatible with OpenZeppelin Contracts ^4.9.3
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

// modules
import {
LSP7DigitalAsset
} from "@lukso/lsp7-contracts/contracts/LSP7DigitalAsset.sol";
import {
LSP7Burnable
} from "@lukso/lsp7-contracts/contracts/extensions/LSP7Burnable.sol";
import {
LSP7Mintable
} from "@lukso/lsp7-contracts/contracts/presets/LSP7Mintable.sol";

// constants
import {
_LSP4_TOKEN_TYPE_TOKEN
} from "@lukso/lsp4-contracts/contracts/LSP4Constants.sol";

contract EcoCoin is LSP7Burnable, LSP7Mintable {
constructor(
address initialOwner
)
LSP7Mintable(
"EcoCoin", // name
"ECN", // symbol
initialOwner, // contract owner
_LSP4_TOKEN_TYPE_TOKEN, // token type
false // is non divisible
)
{
_mint({
to: initialOwner,
amount: 10_000 * 10 ** decimals(), // 10_000_000_000_000_000_000_000
force: true, // allowing to send to EOA as well
data: bytes(unicode"Minting some tokens!!! 🔥🫡")
});
}
}

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion smart-contracts-hardhat/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LoadEnv();
const config: HardhatUserConfig = {
solidity: {
// Default compiler version for all contracts
version: '0.8.19',
version: '0.8.20',
settings: {
optimizer: {
enabled: true,
Expand Down
Loading
Loading