-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from trustenterprises/feature-token-issuance
Beta token issuance
- Loading branch information
Showing
8 changed files
with
493 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import createTokenRequest from "app/validators/createTokenRequest" | ||
import Response from "app/response" | ||
import Specification from "app/hashgraph/tokens/specifications" | ||
|
||
async function CreateTokenHandler(req, res) { | ||
const validationErrors = createTokenRequest(req.body) | ||
|
||
if (validationErrors) { | ||
return Response.unprocessibleEntity(res, validationErrors) | ||
} | ||
|
||
const { | ||
symbol, | ||
name, | ||
supply, | ||
memo, | ||
requires_kyc = false, | ||
can_freeze = false | ||
} = req.body | ||
|
||
const { hashgraphClient } = req.context | ||
|
||
const token = await hashgraphClient.createToken({ | ||
specification: Specification.Fungible, | ||
memo, | ||
name, | ||
symbol, | ||
supply, | ||
requires_kyc, | ||
can_freeze | ||
}) | ||
|
||
Response.json(res, token) | ||
} | ||
|
||
export default CreateTokenHandler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/** | ||
* Update the type definition of Specification when new bits are required | ||
*/ | ||
// export type Specification = { | ||
// reference: string; | ||
// decimals: number; | ||
// kyc: boolean; | ||
// wipe: boolean; | ||
// freeze: boolean; | ||
// } | ||
|
||
/** | ||
* TODO: more conversations and design about interop and bridging required to reduce precision loss | ||
* | ||
* This is a prototype spec that describes the interop for trading | ||
* imported ERC20 tokens with minted HTS tokens. This provides a | ||
* common shared attributes, the decimal places have been reduced to | ||
* 6 as we wish to have enough precision but not lose the max limit | ||
* for (2 - 1) * (10 ** 64) | ||
* | ||
* As at 01/02/21 provides a precision loss of 1.3 cents for 0.000001 eth | ||
* | ||
* With 6 digits of precision we have have a max HTS limit of for this spec | ||
* | ||
* 9,223,372,036,854.775 (9 trillion) | ||
* | ||
* @type {{decimals: number}} | ||
*/ | ||
const Fungible = { | ||
reference: "basic.fungible", | ||
decimals: 6, | ||
kyc: false, | ||
wipe: false, | ||
freeze: false | ||
} | ||
|
||
/** | ||
* When creating NFT representations of tokens we require a token to be unique | ||
* and non fungible, it cannot be divided. | ||
* | ||
* @type {{decimals: number}} | ||
*/ | ||
const NonFungible = { | ||
reference: "basic.nonfungible", | ||
decimals: 0, | ||
kyc: false, | ||
wipe: false, | ||
freeze: false | ||
} | ||
|
||
/** | ||
* A KYC, freeze and wipe compliant fungible token, based on ERC20 that enables a token that has more control | ||
* for regulatory and stricter requirements for investment purposes. | ||
* | ||
* @type {{decimals: number}} | ||
*/ | ||
const CompliantFungible = { | ||
...Fungible, | ||
reference: "compliance.fungible", | ||
kyc: true, | ||
wipe: true, | ||
freeze: true | ||
} | ||
|
||
/** | ||
* A KYC, freeze and wipe compliant fungible token, based on ERC721/Non fungible that enables a token | ||
* that has more control for regulatory and stricter use cases. | ||
* | ||
* @type {{decimals: number}} | ||
*/ | ||
const CompliantNonFungible = { | ||
...NonFungible, | ||
reference: "compliance.nonfungible", | ||
kyc: true, | ||
wipe: true, | ||
freeze: true | ||
} | ||
|
||
/** | ||
* A special token that acts as a receipt for deposited assets in a pool. These | ||
* can be returned to the treasury account that minted them. Upon receipt a claimant | ||
* will be returned all tokens deposited and their fair share of the reward distribution. | ||
* | ||
* @type {{decimals: number}} | ||
*/ | ||
const UnibarLiquidityProviderReceipt = { | ||
...NonFungible, | ||
reference: "lp.reward.receipt" | ||
} | ||
|
||
export default { | ||
Fungible, | ||
NonFungible, | ||
CompliantFungible, | ||
CompliantNonFungible, | ||
UnibarLiquidityProviderReceipt | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const Joi = require("@hapi/joi") | ||
|
||
const TRILLION = 10 ** 12 | ||
|
||
const schema = Joi.object({ | ||
symbol: Joi.string() | ||
.max(100) | ||
.required(), | ||
name: Joi.string() | ||
.max(100) | ||
.required(), | ||
memo: Joi.string() | ||
.max(100) | ||
.optional(), | ||
supply: Joi.number() | ||
.positive() | ||
.max(TRILLION) | ||
.min(1) | ||
.required(), | ||
requires_kyc: Joi.bool().default(false), | ||
can_freeze: Joi.bool().default(false) | ||
}).options({ allowUnknown: true }) | ||
|
||
function createTokenRequest(candidate = {}) { | ||
const validation = schema.validate(candidate || {}) | ||
|
||
if (validation.error) { | ||
return validation.error.details.map(error => error.message) | ||
} | ||
} | ||
|
||
export default createTokenRequest |
Oops, something went wrong.