diff --git a/openapi.json b/openapi.json index 37c5ac9f..560fdf22 100644 --- a/openapi.json +++ b/openapi.json @@ -1,7 +1,7 @@ { "swagger": "2.0", "info": { - "version": "1.26.15", + "version": "1.26.16", "title": "THX API Specification", "description": "User guides are available at https://docs.thx.network." }, @@ -772,6 +772,12 @@ }, "description": { "example": "any" + }, + "royaltyAddress": { + "example": "any" + }, + "royaltyPercentage": { + "example": "any" } } } @@ -3203,6 +3209,24 @@ } } }, + "royaltyRecipient": { + "type": "object", + "properties": { + "type": { + "type": "string", + "example": "string" + } + } + }, + "royaltyBps": { + "type": "object", + "properties": { + "type": { + "type": "string", + "example": "number" + } + } + }, "logoImgUrl": { "type": "object", "properties": { diff --git a/src/controllers/erc721/erc721.test.ts b/src/controllers/erc721/erc721.test.ts index 181143ee..ed29246b 100644 --- a/src/controllers/erc721/erc721.test.ts +++ b/src/controllers/erc721/erc721.test.ts @@ -16,7 +16,9 @@ describe('ERC721', () => { schema = [ { name: 'color', propType: 'string', description: 'lorem ipsum' }, { name: 'size', propType: 'string', description: 'lorem ipsum dolor sit' }, - ]; + ], + royaltyAddress = '0x00', + royaltyPercentage = 5; let erc721ID: string; beforeAll(beforeAllCallback); @@ -34,6 +36,8 @@ describe('ERC721', () => { name, symbol, description, + royaltyAddress, + royaltyPercentage, schema: JSON.stringify(schema), }) .expect(({ body }: request.Response) => { @@ -50,6 +54,8 @@ describe('ERC721', () => { expect(body.properties[1].propType).toBe(schema[1].propType); expect(isAddress(body.address)).toBe(true); expect(body.archived).toBe(false); + expect(body.royaltyRecipient).toBe(royaltyAddress); + expect(body.royaltyBps).toBe(royaltyPercentage * 1000); expect(body.logoImgUrl).toBeDefined(); erc721ID = body._id; }) @@ -73,6 +79,8 @@ describe('ERC721', () => { expect(body.properties[1].description).toBe(schema[1].description); expect(body.properties[1].name).toBe(schema[1].name); expect(body.properties[1].propType).toBe(schema[1].propType); + expect(body.royaltyRecipient).toBe(royaltyAddress); + expect(body.royaltyBps).toBe(royaltyPercentage * 1000); expect(isAddress(body.address)).toBe(true); expect(body.logoImgUrl).toBeDefined(); }) diff --git a/src/controllers/erc721/post.controller.ts b/src/controllers/erc721/post.controller.ts index 198154a3..8f519ade 100644 --- a/src/controllers/erc721/post.controller.ts +++ b/src/controllers/erc721/post.controller.ts @@ -1,6 +1,7 @@ import { Request, Response } from 'express'; import { body, check } from 'express-validator'; import ERC721Service from '@/services/ERC721Service'; +import { ADDRESS_ZERO } from '@/config/secrets'; import ImageService from '@/services/ImageService'; import { BadRequestError } from '@/util/errors'; @@ -9,6 +10,8 @@ const validation = [ body('symbol').exists().isString(), body('description').exists().isString(), body('chainId').exists().isNumeric(), + body('royaltyAddress').optional().isString(), + body('royaltyPercentage').optional().isInt({ max: 100 }), body('schema').exists(), check('file') .optional() @@ -44,6 +47,8 @@ const controller = async (req: Request, res: Response) => { description: req.body.description, properties, archived: false, + royaltyRecipient: req.body.royaltyAddress ? req.body.royaltyAddress : ADDRESS_ZERO, + royaltyBps: req.body.royaltyPercentage ? Number(req.body.royaltyPercentage) * 1000 : 0, logoImgUrl, }); diff --git a/src/models/ERC721.ts b/src/models/ERC721.ts index 0a789c70..65b3644c 100644 --- a/src/models/ERC721.ts +++ b/src/models/ERC721.ts @@ -17,6 +17,8 @@ const ERC721Schema = new mongoose.Schema( baseURL: String, properties: [{ name: String, propType: String, description: String }], archived: Boolean, + royaltyRecipient: String, + royaltyBps: Number, logoImgUrl: String, }, { timestamps: true }, diff --git a/src/services/ERC721Service.ts b/src/services/ERC721Service.ts index d62b2270..13818dc6 100644 --- a/src/services/ERC721Service.ts +++ b/src/services/ERC721Service.ts @@ -29,7 +29,7 @@ async function deploy(data: TERC721): Promise { const contract = await TransactionService.deploy( abi, bytecode, - [erc721.name, erc721.symbol, erc721.baseURL, defaultAccount], + [erc721.name, erc721.symbol, erc721.baseURL, defaultAccount, erc721.royaltyRecipient, erc721.royaltyBps], erc721.chainId, ); diff --git a/src/types/TERC721.ts b/src/types/TERC721.ts index 3071b28b..dcf6903d 100644 --- a/src/types/TERC721.ts +++ b/src/types/TERC721.ts @@ -46,6 +46,8 @@ export type TERC721 = { createdAt?: Date; updatedAt?: Date; archived?: boolean; + royaltyRecipient?: string; + royaltyBps?: number; logoImgUrl?: string; };