openapi: "3.0.2"
info:
  title: ERC20 Application
  version: "1.0.1"
  description: "ERC20 Application servicing the erc20-banking,
    can deploy muti-contract and listening event on Polygon,
    which one is a popular layer2 solution.
    service will response to callback server when get deposit event,
    and withdraw native and erc20 token from serving contract"
servers:
  - url: http://localhost:8888/api
    description: admin API is used to call admin method for management and should not be exposed to the external network.
  - url: http://localhost:8080/api
    description: user API is used to call usermethod method for recharge the lost deposit record
tags:
  - name: Admin
    description: Operations related to Admin
  - name: User
    description: Operations related to User
paths:
  /admin/addendpoint:
    post:
      tags:
        - Admin
      description:
        add the eth api endpoint, the contract is listened one-to-one by ethendpoint,
        if you want to deploy new serve contract, you should need create the endpoint first
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                URL:
                  type: string
                  description: the URL of endpoint
                  example: "wss://polygon-mumbai.g.alchemy.com/v2/*******"
                Key:
                  type: string
                  description: the security key get from GET
                  example: "kXVbWGvbqzgexyALBsdjSGpngCwFkDifIBuufFMoWdiTskZoQJMqrTICT"
                Value:
                  type: string
                  description: md5(key + Secret key)
                  example: "5c73761abab06e8c7247f55f95197ef3"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  URL:
                    type: string
                    description: the URL of endpoint
                    example: "wss://polygon-mumbai.g.alchemy.com/v2/*******"
                  Status:
                    type: string
                    description: All is well
                    example: "the end point is useable,everything is ok"
        "400":
          description: the endpoint is not useable
        "500":
          description: something wrong in database
  /admin/deploy:
    post:
      tags:
        - Admin
      description: deploy the new service contract to blockchain,
        and set the ERC20{WETH,USDT} contract address which are configed by server.
        it will return the contract address, and record the cost of process in to db.
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                ServiceName:
                  type: string
                  description: the name of service
                  example: "so much super cool application-erc20banking"
                Description:
                  type: string
                  description: the Description of Service
                  example: "the builder of the application has an huge capacity SSD"
                Key:
                  type: string
                  description: the security key get from GET
                  example: "kXVbWGvbqzgexyALBsdjSGpngCwFkDifIBuufFMoWdiTskZoQJMqrTICT"
                Value:
                  type: string
                  description: md5(key + Secret key)
                  example: "5c73761abab06e8c7247f55f95197ef3"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  ServiceName:
                    type: string
                    description: the name of service
                    example: "so much super cool application-erc20banking"
                  Description:
                    type: string
                    description: the Description of Service
                    example: "the builder of the application has an huge capacity SSD"
                  ContractAddress:
                    type: string
                    description: the Contract Address of Service which one just deploy
                    example: "0xDA6B6505A88f57139F30df8CE69354CeE987bEf4"
                  Status:
                    type: string
                    example: "ok"
                  Tx:
                    type: object
                    properties:
                      Err:
                        type: string
                        example: null
                        description: tx error message
                      Hash:
                        type: string
                        example: "0xdc07dea3fac6d36d68efb196ab8b03cedfd7e64032af52ec98898c5018562443"
                        description: the denerate index of wallet
                      GasFee:
                        type: number
                        example: 51228042724152
                        description: the cost deploy
                      BlockNumber:
                        type: number
                        example: 37497802
                        description: BlockNumber height of contract deploy
                      Nonce:
                        type: number
                        example: 69
                        description: nonce used to send tx
        "400":
          description: BadRequest, something wrong of body
          content:
            text/string:
              example: duplicate ServiceName
        "500":
          description: InternalServerError,something wrong of server's network or database
        "503":
          description: ServiceUnavailable,something wrong of erc20 contract config and caused error when set contract
  /admin/withdraw/native:
    post:
      tags:
        - Admin
      description:
        withdraw the native token of blockchain, which one is call "MATIC" on polygon
        it will withdraw from service contract to specific wallet address
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                ServiceName:
                  type: string
                  description: the name of service, it would be ignored when pass specific ContractAddress
                  example: "so much super cool application-erc20banking"
                ContractAddress:
                  type: string
                  description: the specific contract,can be empty when pass specific ServiceName
                  example: "0xDA6B6505A88f57139F30df8CE69354CeE987bEf4"
                Amount:
                  type: string
                  description: Amount of token want to withdraw
                  example: "100000000000000"
                Key:
                  type: string
                  description: the security key get from GET
                  example: "kXVbWGvbqzgexyALBsdjSGpngCwFkDifIBuufFMoWdiTskZoQJMqrTICT"
                Value:
                  type: string
                  description: md5(key + Secret key)
                  example: "5c73761abab06e8c7247f55f95197ef3"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  ServiceName:
                    type: string
                    description: the name of service
                    example: "so much super cool application-erc20banking"
                  ContractAddress:
                    type: string
                    description: the Contract Address of Service which one just deploy
                    example: "0xDA6B6505A88f57139F30df8CE69354CeE987bEf4"
                  Amount:
                    type: string
                    description: Amount of token want to withdraw
                    example: "100000000000000"
                  Status:
                    type: string
                    example: "succeed and everything is ok"
                  Tx:
                    type: object
                    properties:
                      Err:
                        type: string
                        example: null
                        description: tx error message
                      TxHash:
                        type: string
                        example: "0xdc07dea3fac6d36d68efb196ab8b03cedfd7e64032af52ec98898c5018562443"
                        description: the denerate index of wallet
                      GasFee:
                        type: number
                        example: 51228042724152
                        description: the cost deploy
        "400":
          description: BadRequest, something wrong of body
          content:
            text/string:
              example: "ERROR: serviceOperator not found, please check the service alive or not"
        "500":
          description: InternalServerError,something wrong of server's network or database
        "503":
          description: ServiceUnavailable,something wrong of tx, it maybe lack gas of mainwallet,have no permision, withdraw exceed balance...
  /admin/withdraw/erc20:
    post:
      tags:
        - Admin
      description:
        withdraw the erc20 token on blockchain, which one is like "Wrapped-ETH" or "USTD"
        it will withdraw from service contract to specific wallet address
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                ServiceName:
                  type: string
                  description: the name of service, it would be ignored when pass specific ContractAddress
                  example: "so much super cool application-erc20banking"
                ContractAddress:
                  type: string
                  description: the specific contract,can be empty when pass specific ServiceName
                  example: "0xDA6B6505A88f57139F30df8CE69354CeE987bEf4"
                TokenType:
                  type: string
                  description: the name-contract pair set when deploy service contract, in this project, it provide "WETH" and "USTD"
                  example: "WETH"
                Amount:
                  type: string
                  description: Amount of token want to withdraw
                  example: "100000000000000"
                Key:
                  type: string
                  description: the security key get from GET
                  example: "kXVbWGvbqzgexyALBsdjSGpngCwFkDifIBuufFMoWdiTskZoQJMqrTICT"
                Value:
                  type: string
                  description: md5(key + Secret key)
                  example: "5c73761abab06e8c7247f55f95197ef3"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  ServiceName:
                    type: string
                    description: the name of service
                    example: "so much super cool application-erc20banking"
                  ContractAddress:
                    type: string
                    description: the Contract Address of Service which one just deploy
                    example: "0xDA6B6505A88f57139F30df8CE69354CeE987bEf4"
                  Amount:
                    type: string
                    description: Amount of token want to withdraw
                    example: "100000000000000"
                  Status:
                    type: string
                    example: "succeed and everything is ok"
                  Tx:
                    type: object
                    properties:
                      Err:
                        type: string
                        example: null
                        description: tx error message
                      TxHash:
                        type: string
                        example: "0xdc07dea3fac6d36d68efb196ab8b03cedfd7e64032af52ec98898c5018562443"
                        description: the denerate index of wallet
                      GasFee:
                        type: number
                        example: 51228042724152
                        description: the cost deploy
        "400":
          description: BadRequest, something wrong of body
          content:
            text/string:
              example: "ERROR: serviceOperator not found, please check the service alive or not"
        "500":
          description: InternalServerError,something wrong of server's network or database
        "503":
          description: ServiceUnavailable,something wrong of tx, it maybe lack gas of mainwallet,have no permision, withdraw exceed balance...
  /admin/balance/{tokenType}:
    post:
      tags:
        - Admin
      parameters:
        - name: tokenType
          in: path
          description: The tokenType of the user, provide "Native","USDT","WETH"
          required: true
          schema:
            type: string
            example: Native
      description: Query the balance of serve contract
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                ServiceName:
                  type: string
                  description: the name of service, it would be ignored when pass specific ContractAddress
                  example: "so much super cool application-erc20banking"
                ContractAddress:
                  type: string
                  description: the specific contract,can be empty when pass specific ServiceName
                  example: "0xDA6B6505A88f57139F30df8CE69354CeE987bEf4"
                Key:
                  type: string
                  description: the security key get from GET
                  example: "kXVbWGvbqzgexyALBsdjSGpngCwFkDifIBuufFMoWdiTskZoQJMqrTICT"
                Value:
                  type: string
                  description: md5(key + Secret key)
                  example: "5c73761abab06e8c7247f55f95197ef3"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  ServiceName:
                    type: string
                    description: the name of service, it would be ignored when pass specific ContractAddress
                    example: "so much super cool application-erc20banking"
                  ContractAddress:
                    type: string
                    description: the specific contract,can be empty when pass specific ServiceName
                    example: "0xDA6B6505A88f57139F30df8CE69354CeE987bEf4"
                  Value:
                    type: string
                    description: All is well
                    example: "0"
        "400":
          description: BadRequest, something wrong of body
          content:
            text/string:
              example: "ERROR: serviceOperator not found, please check the service alive or not"
        "503":
          description: something wrong in view blockchain
  /admin/secret:
    get:
      tags:
        - Admin
      description: get the key for admin api
      responses:
        "200":
          description: the key is used to calculate secret value for use admin api
          content:
            text/string:
              example: "CZGiaGNtoWPE"

        "429":
          description: trigged the limit
  /admin/transfer/native:
    post:
      tags:
        - Admin
      description:
        transfer the native token of blockchain, which one is call "MATIC" on polygon
        it will transfer native token from checkout wallet to specific wallet address
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                ToAddress:
                  type: string
                  description: the specific wallet address
                  example: "0xCb740b3FB4B848aA1e022a839fD59ECdC0C04335"
                Amount:
                  type: string
                  description: Amount of token want to withdraw
                  example: "100000000000000"
                Timeout:
                  type: integer
                  description: specific time for getTransfer lock, it will not less 20s (time<20?:20:time)
                  example: 0
                Key:
                  type: string
                  description: the security key get from GET
                  example: "kXVbWGvbqzgexyALBsdjSGpngCwFkDifIBuufFMoWdiTskZoQJMqrTICT"
                Value:
                  type: string
                  description: md5(key + Secret key)
                  example: "5c73761abab06e8c7247f55f95197ef3"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  ToAddress:
                    type: string
                    description: specific wallet address
                    example: "0xCb740b3FB4B848aA1e022a839fD59ECdC0C04335"
                  TokenType:
                    type: string
                    description: the native token name of blockchain
                    example: "MATIC"
                  Amount:
                    type: string
                    description: Amount of token want to withdraw
                    example: "100000000000000"
                  Status:
                    type: string
                    example: "succeed and everything is ok"
                  Tx:
                    type: object
                    properties:
                      Err:
                        type: string
                        example: null
                        description: tx error message
                      Hash:
                        type: string
                        example: "0xdc07dea3fac6d36d68efb196ab8b03cedfd7e64032af52ec98898c5018562443"
                        description: the denerate index of wallet
                      GasFee:
                        type: number
                        example: 51228042724152
                        description: the cost deploy
                      BlockNumber:
                        type: number
                        example: 38218945
                        description: the BlockNumber of transaction
                      Nonce:
                        type: number
                        example: 7
                        description: the nonce of transaction
        "400":
          description: BadRequest, something wrong of body
          content:
            text/string:
              example: "ERROR: serviceOperator not found, please check the service alive or not"
        "404":
          description: failed in security
        "500":
          description: InternalServerError,something wrong of server's network or database
        "503":
          description: ServiceUnavailable,something wrong of tx, the service maybe in busy, lack gas of mainwallet ,have no permision, withdraw exceed balance...
  /admin/transfer/erc20:
    post:
      tags:
        - Admin
      description:
        transfer the erc20 token of blockchain, the server provides USDT and WETH transfer
        it will transfer erc20 token from checkout wallet to specific wallet address
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                ToAddress:
                  type: string
                  description: the specific wallet address
                  example: "0xCb740b3FB4B848aA1e022a839fD59ECdC0C04335"
                TokenType:
                  type: string
                  description: the token type want to transfer
                  example: "WETH"
                Amount:
                  type: string
                  description: Amount of token want to withdraw
                  example: "100000000000000"
                Timeout:
                  type: integer
                  description: specific time for getTransfer lock, it will not less 20s (time<20?:20:time)
                  example: 0
                Key:
                  type: string
                  description: the security key get from GET
                  example: "kXVbWGvbqzgexyALBsdjSGpngCwFkDifIBuufFMoWdiTskZoQJMqrTICT"
                Value:
                  type: string
                  description: md5(key + Secret key)
                  example: "5c73761abab06e8c7247f55f95197ef3"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  ToAddress:
                    type: string
                    description: specific wallet address
                    example: "0xCb740b3FB4B848aA1e022a839fD59ECdC0C04335"
                  TokenType:
                    type: string
                    description: the token name transfered of tx
                    example: "WETH"
                  Amount:
                    type: string
                    description: Amount of token want to withdraw
                    example: "100000000000000"
                  Status:
                    type: string
                    example: "succeed and everything is ok"
                  Tx:
                    type: object
                    properties:
                      Err:
                        type: string
                        example: null
                        description: tx error message
                      Hash:
                        type: string
                        example: "0xdc07dea3fac6d36d68efb196ab8b03cedfd7e64032af52ec98898c5018562443"
                        description: the denerate index of wallet
                      GasFee:
                        type: number
                        example: 51228042724152
                        description: the cost deploy
        "400":
          description: BadRequest, something wrong of body
          content:
            text/string:
              example: "ERROR: serviceOperator not found, please check the service alive or not"
        "404":
          description: failed in security
        "500":
          description: InternalServerError,something wrong of server's network or database
        "503":
          description: ServiceUnavailable,something wrong of tx, the service maybe in busy, lack gas of mainwallet ,have no permision, withdraw exceed balance...
  /user/recharge:
    post:
      tags:
        - User
      description: recharge the accidentally lost deposit record
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                TxHash:
                  type: string
                  description: the hash of transaction
                  example: "0xcaed11912b4c8d14adc5e258c35c70fdbe3bb355f2b7bc3330cfe2845fc124e7"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  URL:
                    type: string
                    description: the URL of endpoint
                    example: "wss://polygon-mumbai.g.alchemy.com/v2/*******"
                  Status:
                    type: string
                    description: All is well
                    example: "the end point is useable,everything is ok"
        "400":
          description: something wrong in body
        "500":
          description: something wrong in database,callback server or network
