GithubHelp home page GithubHelp logo

paltalabs / mercury-sdk Goto Github PK

View Code? Open in Web Editor NEW
4.0 4.0 3.0 336 KB

Home Page: https://mercury-sdk.paltalabs.io/

License: GNU General Public License v3.0

TypeScript 98.26% Shell 1.59% JavaScript 0.15%

mercury-sdk's People

Contributors

abstract829 avatar celadari avatar chopan123 avatar esteblock avatar mattpoblete avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

mercury-sdk's Issues

Add features to mercury-sdk

  • Add support for contract entries
    • Fix function to subscribe to contract entries (add durability)
    • Add a special case for KEY_XDR="AAAFA==" to subscribe to instance storage (with durability="persistent")
    • Add function to retrieve information from contract entries with its query
  • Factory contract
    • Use previous function to get entries from factory contract
    • Add parseFactoryInstanceEntry function, special attention with value_xdr to get the pair addresses of all pairs
  • Pair contract
    • Use previous function to get entries from pair contract
    • Add parsePairInstanceEntry function, special attention value_xdr to get the reserves

implement getLiquidityPoolDeposit and getLiquidityPoolWithdraw

Query:

{
  "data": {
    "liquidityPoolDepositByPublicKey": {
      "edges": [
        {
          "node": {
            "source": 401811,
            "sourceMuxed": null,
            "poolId": "\\xe82e661eb1a24479b34e96451908c339ad9d3f7af3aaab786f1536c4e4211f05",
            "maxAmountA": "10000000000",
            "maxAmountB": "30000000000",
            "minPriceN": 3,
            "minPriceD": 10,
            "maxPriceN": 3666667,
            "maxPriceD": 10000000,
            "ledger": 2684822
          }
        }
      ]
    }
  }
}

and

query MyQuery {
  liquidityPoolWithdrawByPublicKey(
    publicKeyText: "GBXRF7BXKPNQIIWAAO6Y6CFIUXX6GCVLILANFPSENPKAFFZA4KOVCLMB"
  ) {
    edges {
      node {
        source
        sourceMuxed
        poolId
        amount
        minAmountA
        minAmountB
        ledger
      }
    }
  }
}

Test ADdress:
GBXRF7BXKPNQIIWAAO6Y6CFIUXX6GCVLILANFPSENPKAFFZA4KOVCLMB

Add type support for getPathPaymentsStrictReceiveByPublicKey

Current Node type is

export interface Node {
    ledgerByLedger: LedgerByLedger;
    accountBySource: AccountBy;
    accountByDestination: AccountBy;
    assetByDestAsset: AssetBy;
    assetByPath1: AssetBy;
    assetByPath2: AssetBy;
    assetByPath3: AssetBy;
    assetByPath4: AssetBy;
    assetByPath5: AssetBy;
    assetBySendAsset: AssetBy;
    destAssetNative: boolean;
    destMin: string;
    path1Native: boolean;
    path2Native: boolean;
    path3Native: boolean;
    path4Native: boolean;
    path5Native: AssetBy;
    sendAmount: string;
    sendAssetNative: boolean;
}

That is for getPathPaymentsStrictSendByPublicKey but not for getPathPaymentsStrictReceiveByPublicKey

Can you add something like

export interface NodeBase {
    ledgerByLedger: LedgerByLedger;
    accountBySource: AccountBy;
    accountByDestination: AccountBy;
    assetByDestAsset: AssetBy;
    assetByPath1: AssetBy;
    assetByPath2: AssetBy;
    assetByPath3: AssetBy;
    assetByPath4: AssetBy;
    assetByPath5: AssetBy;
    assetBySendAsset: AssetBy;
    destAssetNative: boolean;
    path1Native: boolean;
    path2Native: boolean;
    path3Native: boolean;
    path4Native: boolean;
    path5Native: AssetBy;
    sendAssetNative: boolean;
}
 
 export interface NodeStrictSend extends NodeBase {
    sendAmount: string;
    destMin: string;
 }
 
 export interface NodeStrictReceive extends NodeBase {
    destAmount: string;
    sendMax: string;
 }

Extract all events from a contract

Query:

# Example variables:
# {
# contractId: "CAVKFXGNANLFPXORKNLZEFNHO2VIN54KCAILJKZZF3UUZ6OYDPVJ3V23"
# }

query getAllContractEvents($contractId: String) {
  eventByContractId(
    searchedContractId: $contractId 
  ) {
    edges {
      node {
        contractId
        data
        ledger
        ledgerTimestamp
        topic2
        topic1
        topic4
        topic3
      }
    }
  }
}

Generate documentation without warnings

Currently there are severals warnings when generating documentation:

root@5ec42bd4fde0:/workspace# yarn doc
yarn run v1.22.19
warning package.json: License should be a valid SPDX license expression
$ typedoc src/
[warning] The signature Mercury._backendRequest has an @param with name "method", which was not used.
[warning] The signature Mercury._backendRequest has an @param with name "url", which was not used.
[warning] The signature Mercury._backendRequest has an @param with name "body", which was not used.
[warning] The signature Mercury._backendRequest has an @param with name "updateToken", which was not used.
[warning] The signature Mercury._graphqlRequest has an @param with name "body", which was not used.
[warning] The signature Mercury._graphqlRequest has an @param with name "updateToken", which was not used.
[warning] The signature Mercury._graphqlRequest has an @param with name "headers", which was not used.
[warning] ParsedRouterEntry, defined in ./src/types/getContractEntries.ts, is referenced by factoryInstanceParser.factoryInstanceParser but not included in the documentation.
[warning] getLiquidityPoolDepositParsed, defined in ./src/utils/parsers/getLiquidityPoolDepositParser.ts, is referenced by getLiquidityPoolDepositParser.getLiquidityPoolDepositParser but not included in the documentation.
[warning] getLiquidityPoolWithdrawParsed, defined in ./src/utils/parsers/getLiquidityPoolWithdrawParser.ts, is referenced by getLiquidityPoolWithdrawParser.getLiquidityPoolWithdrawParser but not included in the documentation.
[warning] getPathPaymentsStrictReceiveParsed, defined in ./src/utils/parsers/getPathPaymentsStrictReceiveParser.ts, is referenced by getPathPaymentsStrictReceiveParser.getPathPaymentsStrictReceiveParser but not included in the documentation.
[warning] getPathPaymentsStrictSendParsed, defined in ./src/utils/parsers/getPathPaymentsStrictSendParser.ts, is referenced by getPathPaymentsStrictSendParser.getPathPaymentsStrictSendParser but not included in the documentation.
[warning] getReceivedPaymentsParsed, defined in ./src/utils/parsers/getReceivedPaymentsParser.ts, is referenced by getReceivedPaymentsParser.getReceivedPaymentsParser but not included in the documentation.
[warning] getSentPaymentsParsed, defined in ./src/utils/parsers/getSentPaymentsParser.ts, is referenced by getSentPaymentsParser.getSentPaymentsParser but not included in the documentation.
[warning] PairEntry, defined in ./src/types/pairEntry.ts, is referenced by pairInstanceParser.pairInstanceParser but not included in the documentation.
[warning] ApiResponse, defined in ./src/types/mercury.ts, is referenced by Mercury._backendRequest._backendRequest but not included in the documentation.
[warning] GetAllContractEventSubscriptionsResponse, defined in ./src/types/getAllContractEventSubscriptions.ts, is referenced by Mercury.getAllContractEventSubscriptions.getAllContractEventSubscriptions but not included in the documentation.
[warning] GetAllFullAccountSubscriptionsResponse, defined in ./src/types/getAllFullAccountSubscriptions.ts, is referenced by Mercury.getAllFullAccountSubscriptions.getAllFullAccountSubscriptions but not included in the documentation.
[warning] ContractEntriesResponse, defined in ./src/types/getContractEntries.ts, is referenced by Mercury.getContractEntries.getContractEntries but not included in the documentation.
[warning] GetContractEventsResponse, defined in ./src/types/getContractEvents.ts, is referenced by Mercury.getContractEvents.getContractEvents but not included in the documentation.
[warning] LiquidityPoolDepositByPublicKeyResponse, defined in ./src/types/liquidityPool.ts, is referenced by Mercury.getLiquidityPoolDeposit.getLiquidityPoolDeposit but not included in the documentation.
[warning] LiquidityPoolWithdrawByPublicKeyResponse, defined in ./src/types/liquidityPool.ts, is referenced by Mercury.getLiquidityPoolWithdraw.getLiquidityPoolWithdraw but not included in the documentation.
[warning] GetPathPaymentsStrictReceiveByPublicKeyResponse, defined in ./src/types/pathPayments.ts, is referenced by Mercury.getPathPaymentsStrictReceive.getPathPaymentsStrictReceive but not included in the documentation.
[warning] GetPathPaymentsStrictSendByPublicKeyResponse, defined in ./src/types/pathPayments.ts, is referenced by Mercury.getPathPaymentsStrictSend.getPathPaymentsStrictSend but not included in the documentation.
[warning] GetReceivedPaymentsResponse, defined in ./src/types/payments.ts, is referenced by Mercury.getReceivedPayments.getReceivedPayments but not included in the documentation.
[warning] GetSentPaymentsResponse, defined in ./src/types/payments.ts, is referenced by Mercury.getSentPayments.getSentPayments but not included in the documentation.
[warning] AuthenticateResponse, defined in ./src/types/authenticate.ts, is referenced by Mercury.updateAccessToken.updateAccessToken but not included in the documentation.
[warning] MercuryOptions, defined in ./src/Mercury.ts, is referenced by Mercury.constructor.new Mercury.options but not included in the documentation.
[warning] backendRequestArgs, defined in ./src/types/mercury.ts, is referenced by Mercury._backendRequest._backendRequest.__namedParameters but not included in the documentation.
[warning] GraphQLRequestArgs, defined in ./src/types/mercury.ts, is referenced by Mercury._graphqlRequest._graphqlRequest.__namedParameters but not included in the documentation.
[warning] SubscribeToContractEventsArgs, defined in ./src/types/subscriptions.ts, is referenced by Mercury.subscribeToContractEvents.subscribeToContractEvents.args but not included in the documentation.
[warning] SubscribeToFullAccountArgs, defined in ./src/types/subscriptions.ts, is referenced by Mercury.subscribeToFullAccount.subscribeToFullAccount.args but not included in the documentation.
[warning] SubscribeToLedgerEntriesArgs, defined in ./src/types/subscriptions.ts, is referenced by Mercury.subscribeToLedgerEntries.subscribeToLedgerEntries.args but not included in the documentation.
[warning] SubscribeToLedgerEntriesExpirationArgs, defined in ./src/types/subscriptions.ts, is referenced by Mercury.subscribeToLedgerEntriesExpiration.subscribeToLedgerEntriesExpiration.args but not included in the documentation.
[warning] SubscribeToMultipleLedgerEntriesArgs, defined in ./src/types/subscriptions.ts, is referenced by Mercury.subscribeToMultipleLedgerEntries.subscribeToMultipleLedgerEntries.args but not included in the documentation.
[info] Documentation generated at ./docs
Done in 2.07s.

Integrate Specific Module for Soroswap

Proposed Implementation:

Ideally, I envision being able to use the library as follows:

const mercury = new Mercury(...);
mercury.soroswap.getAllLiquidityPools;
mercury.soroswap.getProvidedLiquidityOperations({filters});

The above methods are just examples, but the key idea is to be able to parse specific events from Soroswap contracts seamlessly.

Additionally, considering that contract addresses may change and that other AMM should be added (Phoenix, Comet, ...), I propose the Soroswap module should adhere to the following design principles:

  1. Lazy Initialization: The Soroswap module should be lazy, meaning it doesn't need to be instantiated unless the user specifically intends to use the Soroswap functionalities.
  2. Configurable Contract Addresses: Users should have the option to specify contract addresses when instantiating the Mercury client. This adds flexibility and future-proofs the module against changes in contract addresses.
  3. Default Endpoint Utilization: If no contract addresses are provided by the user, the module should default to using standard Soroswap endpoints to retrieve the necessary information.

Motivation:

Integrating a dedicated Soroswap module into the Mercury SDK would significantly streamline the development process for projects targeting Soroswap.

I believe this addition could represent a valuable collaboration opportunity and further the SDK's adoption and utility for the Stellar/Soroban developer community.

feat: add review subscription methods

Implement this functions

Review subscriptions:

mercuryInstance.getContractSubscriptions({
    contractId:"someContractAddress"
})

or for Accounts

mercuryInstance.getFullAccountSubscriptions({
    publicKey:"someStellarAddress"
})

Also update readme

Parse contract events

Example response:

{
  "data": {
    "eventByContractId": {
      "edges": [
        {
          "node": {
            "contractId": "CAGC46HNBMEZJP62PPTSUBUCS7LWBS5QLRNFSRCA4Q2A57YSPYBKGSTM",
            "data": "AAAAEQAAAAEAAAAHAAAADwAAAAhhbW91bnRfYQAAAAoAAAAAAAAAAAAAAAAAB6EgAAAADwAAAAhhbW91bnRfYgAAAAoAAAAAAAAAAAAAAAAAB6EgAAAADwAAAAlsaXF1aWRpdHkAAAAAAAAKAAAAAAAAAAAAAAAAAAedOAAAAA8AAAAEcGFpcgAAABIAAAABKWo8s1oqRs3m6SECrLbp1lwHUFZQyZsSrXtFHvCChowAAAAPAAAAAnRvAAAAAAASAAAAAAAAAAB8PsDzDkmNms8A4lnHIdZ9cTT74tNur363of7rcGhnrAAAAA8AAAAHdG9rZW5fYQAAAAASAAAAAXUaFx81PMmF/kd4w+tGbMn5Z71hnhczKNB8SbKUEUsdAAAADwAAAAd0b2tlbl9iAAAAABIAAAABlVXiXu6Hby7pN7xOcqGomnOIu/y6TvVyHozgurQbF9E=",
            "ledger": 3029089,
            "ledgerTimestamp": 1702655890,
            "topic2": "AAAADwAAAANhZGQA",
            "topic1": "AAAADgAAAA5Tb3Jvc3dhcFJvdXRlcgAA",
            "topic4": null,
            "topic3": null
          }
        }
      ]
    }
  }
}

You can use router address : CAGC46HNBMEZJP62PPTSUBUCS7LWBS5QLRNFSRCA4Q2A57YSPYBKGSTM

parse data functions

write functions that parses data, for example:
Parse sent payments:

import { parseSentPayment } from "mercury-sdk/utils";
async function someFunction() {
    const data = await mercuryInstance.getSentPayments({
    address:"someStellarAddress"
})
    const parsedData = parseSentPayment(data)
    console.log("parsedData:", parsedData)
}

The output:

[
    {
        "from": "address1", 
        "to": "address2", 
        "asset": {
            "asset_type": "",
            "isuer":""
            },
        "amount":"1000",
]

Do it for:

  • payments (send, receive)
  • path payments (strict send, strict receive)
  • Liquidity pools (Deposit, Withdraw)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.