From 3c107c5cfa92ec8f0b2461ef27e2cd48cd1a92b4 Mon Sep 17 00:00:00 2001 From: ahmadyazdanii Date: Sun, 9 Jun 2024 14:28:17 +0330 Subject: [PATCH 1/4] update [ergo]: add dex service components doc --- src/chains/ergo/dex.service.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/chains/ergo/dex.service.ts b/src/chains/ergo/dex.service.ts index d21a7b3fa6..5dbf1e9842 100644 --- a/src/chains/ergo/dex.service.ts +++ b/src/chains/ergo/dex.service.ts @@ -1,6 +1,12 @@ import axios from 'axios'; import { DEXTokensResponse } from './interfaces/dex.interface'; +/** + * This class allows you to access elements of a DEX + * @class + * @param {string} dexURL - The DEX's base URL + * @param {number} [timeout=5000] - Timeout + */ export class DexService { constructor( private dexURL: string, @@ -25,6 +31,11 @@ export class DexService { return response.data; } + /** + * This function allow you to get Ergo's token list from DEX + * @function + * @async + */ async getTokens() { return this.request('GET', '/ergo-token-list.json'); } From ce08b2758588bc30f6510c9bf96ad5f781399da0 Mon Sep 17 00:00:00 2001 From: ahmadyazdanii Date: Sun, 9 Jun 2024 16:09:56 +0330 Subject: [PATCH 2/4] update [ergo]: add ergo config docs --- src/chains/ergo/ergo.config.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/chains/ergo/ergo.config.ts b/src/chains/ergo/ergo.config.ts index 469336ff3a..2da63f956d 100644 --- a/src/chains/ergo/ergo.config.ts +++ b/src/chains/ergo/ergo.config.ts @@ -2,6 +2,12 @@ import { ConfigManagerV2 } from '../../services/config-manager-v2'; import { NetworkPrefix } from 'ergo-lib-wasm-nodejs'; import { ErgoConfig } from './interfaces/ergo.interface'; +/** + * This function return configuration for Ergo + * @param {string} network - mainnet or testnet + * @returns ErgoConfig + * @function + */ export function getErgoConfig(network: string): ErgoConfig { return { network: { From d72bd93af1fabf864c41650a42f270c5e16ff413 Mon Sep 17 00:00:00 2001 From: ahmadyazdanii Date: Mon, 10 Jun 2024 17:29:31 +0330 Subject: [PATCH 3/4] update [ergo]: update document of ergo file --- src/chains/ergo/ergo.ts | 71 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/src/chains/ergo/ergo.ts b/src/chains/ergo/ergo.ts index 89344129ff..7fb9ca55d8 100644 --- a/src/chains/ergo/ergo.ts +++ b/src/chains/ergo/ergo.ts @@ -22,6 +22,7 @@ import { Explorer } from '@ergolabs/ergo-sdk'; class Pool extends AmmPool { private name: string; + constructor(public pool: AmmPool) { super(pool.id, pool.lp, pool.x, pool.y, pool.poolFeeNum); @@ -52,6 +53,11 @@ class Pool extends AmmPool { // } } +/** + * Ergo chain class + * @param {string} network - mainnet or testnet + * @class + */ export class Ergo { private _assetMap: Record = {}; private static _instances: LRUCache; @@ -105,10 +111,16 @@ export class Ergo { return Object.values(this._assetMap); } - public ready(): boolean { + public get ready(): boolean { return this._ready; } + /** + * This function initializes the Ergo class' instance + * @returns + * @function + * @async + */ public async init(): Promise { await this.loadAssets(); await this.loadPools(); @@ -120,6 +132,13 @@ export class Ergo { return; } + /** + * This static function returns the exists or create new Ergo class' instance based on the network + * @param {string} network - mainnet or testnet + * @returns Ergo + * @function + * @static + */ public static getInstance(network: string): Ergo { const config = getErgoConfig(network); @@ -142,6 +161,12 @@ export class Ergo { return Ergo._instances.get(config.network.name) as Ergo; } + /** + * This static function returns the connected instances + * @returns ErgoConnectedInstance + * @function + * @static + */ public static getConnectedInstances(): ErgoConnectedInstance { const connectedInstances: ErgoConnectedInstance = {}; @@ -158,11 +183,23 @@ export class Ergo { return connectedInstances; } + /** + * This function returns the current network height(Block number) + * @returns number + * @function + * @async + */ async getCurrentBlockNumber(): Promise { const status = await this._node.getNetworkHeight(); return status + 1; } + /** + * This function returns the unspent boxes based on the address from node + * @returns ErgoBox[] + * @function + * @async + */ async getAddressUnspentBoxes(address: string) { let utxos: Array = []; let offset = 0; @@ -185,6 +222,12 @@ export class Ergo { return utxos; } + /** + * Retrieves Ergo Account from secret key + * @param {string} secret - Secret key + * @returns ErgoAccount + * @function + */ public getAccountFromSecretKey(secret: string): ErgoAccount { const sks = new SecretKeys(); const secretKey = SecretKey.dlog_from_bytes(Buffer.from(secret, 'hex')); @@ -200,6 +243,13 @@ export class Ergo { }; } + /** + * Encrypt secret via password + * @param {string} secret - Secret key + * @param {string} password - password + * @returns string + * @function + */ public encrypt(secret: string, password: string): string { const iv = randomBytes(16); const key = Buffer.alloc(32); @@ -212,6 +262,13 @@ export class Ergo { return `${iv.toString('hex')}:${encrypted.toString('hex')}`; } + /** + * Decrypt encrypted secret key via password + * @param {string} encryptedSecret - Secret key + * @param {string} password - password + * @returns string + * @function + */ public decrypt(encryptedSecret: string, password: string): string { const [iv, encryptedKey] = encryptedSecret.split(':'); const key = Buffer.alloc(32); @@ -231,6 +288,14 @@ export class Ergo { return decrypted.toString(); } + /** + * Gets asset balance from unspent boxes + * @param {ErgoAccount} account + * @param {string} assetName + * @returns string + * @function + * @async + */ public async getAssetBalance( account: ErgoAccount, assetName: string, @@ -298,6 +363,10 @@ export class Ergo { return await makeNativePools(this._explorer).getAll({ limit, offset }); } + /** + * Returns a map of asset name and Ergo Asset + * @returns assetMap + */ public get storedTokenList() { return this._assetMap; } From 1546a0ebd3edeb556253eedce316a84404790234 Mon Sep 17 00:00:00 2001 From: ahmadyazdanii Date: Mon, 10 Jun 2024 17:33:29 +0330 Subject: [PATCH 4/4] update [ergo]: add node documentation --- src/chains/ergo/node.service.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/chains/ergo/node.service.ts b/src/chains/ergo/node.service.ts index f65f1020a8..439d67831d 100644 --- a/src/chains/ergo/node.service.ts +++ b/src/chains/ergo/node.service.ts @@ -2,6 +2,12 @@ import axios from 'axios'; import { NodeInfoResponse } from './interfaces/node.interface'; import { NodeErgoBoxResponse } from './types/node.type'; +/** + * This class allows you to access elements of a node + * @class + * @param {string} nodeURL - The node's base URL + * @param {number} timeout - Timeout + */ export class NodeService { constructor( private nodeURL: string, @@ -26,12 +32,28 @@ export class NodeService { return response.data; } + /** + * Gets network full height + * @returns number + * @function + * @async + */ async getNetworkHeight(): Promise { const info = await this.request('GET', '/info'); return info.fullHeight; } + /** + * Get unspent boxes via wallet address + * @param {string} address + * @param {string} offset + * @param {string} limit + * @param {string} sortDirection + * @returns NodeErgoBoxResponse + * @function + * @async + */ async getUnspentBoxesByAddress( address: string, offset: number,