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

Token standard #390

Merged
7 commits merged into from
Jun 23, 2022
Merged

Token standard #390

7 commits merged into from
Jun 23, 2022

Conversation

ghost
Copy link

@ghost ghost commented Jun 20, 2022

Description

Implement the token standard

Fixes #378 #303

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

To create a token, we can use the libjs example transaction builder and create transaction of type 'nft' and enter your token specification, for example:

{
   "supply": 100,
   "name": "My Token",
   "symbol": "MTK",
   "type": "fungible"
}

This should create a new transaction where the unspent outputs should be 100.
This test can also be done with fungible tokens:

{
  "supply": 3,
  "name": "MyToken",
  "symbol": "MTK",
  "type": "non-fungible",
  "properties": [
      [{ "name": "image", "value": "mylink"}],
      [{ "name": "image", "value": "mylink"}],
      [{ "name": "image", "value": "mylink"}]
   ]
}

This PR also implement a fee for the NFT creation and minting being logarithmic, so token with high supply will cost more than other with small supply as the UTXO must be created and will cost space and bandwidth.
But providing a fair transaction's fee compared to UCO transfers.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@ghost ghost added feature New feature request mining Involve transaction validation and mining labels Jun 20, 2022
@ghost ghost self-assigned this Jun 20, 2022
@ghost ghost force-pushed the token_standard branch 4 times, most recently from 3057bf5 to 4019555 Compare June 21, 2022 16:03
@ghost ghost marked this pull request as ready for review June 21, 2022 16:04
@ghost ghost requested review from Neylix and prix-uniris June 21, 2022 16:12
@apoorv-2204 apoorv-2204 mentioned this pull request Jun 22, 2022
2 tasks
@ghost ghost added UI Invole user interface serialization Involve message serialization labels Jun 22, 2022
lib/archethic/mining/fee.ex Outdated Show resolved Hide resolved
lib/archethic/mining/fee.ex Outdated Show resolved Hide resolved
Copy link
Contributor

@prix-uniris prix-uniris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added My feedback/doubts

lib/archethic/p2p/message.ex Outdated Show resolved Hide resolved
priv/json-schemas/token-core.json Show resolved Hide resolved
test/archethic/contracts/interpreter_test.exs Outdated Show resolved Hide resolved
)

assert :ok = PendingTransactionValidation.validate(tx)
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An additional Test for failing case would be better,
supply: 2 , but three properties or vice versa

lib/archethic_web/controllers/api/schema/nft_ledger.ex Outdated Show resolved Hide resolved
Copy link
Contributor

@prix-uniris prix-uniris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

properties
|> Enum.with_index()
|> Enum.map(fn {_item_properties, index} ->
%UnspentOutput{from: address, amount: 1 * @unit_uco, type: {:NFT, address, index + 1}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we need to check if the id is pre determined by the property "id" as specified in AEIP2

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes right I missed this one 👍

with {:ok, json_token} <- Jason.decode(content),
:ok <- ExJsonSchema.Validator.validate(schema, json_token),
%{"type" => "non-fungible", "supply" => supply, "properties" => properties}
when length(properties) == supply <- json_token do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As AEIP2 specifiate that we can pre determine the id, if one index of properties have the property "id", all index should have it too

Copy link
Member

@Neylix Neylix Jun 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, as the token id is use and makes sense for token and nft, I think we should rename id to id instead of nft_id as defined in AEIP2

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I will add the check

@ghost ghost force-pushed the token_standard branch 2 times, most recently from 2dc35ed to ffa51f6 Compare June 23, 2022 13:46
@ghost ghost merged commit c72ef68 into develop Jun 23, 2022
@ghost ghost deleted the token_standard branch June 23, 2022 14:23
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature request mining Involve transaction validation and mining serialization Involve message serialization UI Invole user interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants