Skip to content

Commit

Permalink
feat: expose defi endpoints (#1211)
Browse files Browse the repository at this point in the history
  • Loading branch information
locothedev committed Jun 18, 2024
1 parent a9caca5 commit 26d2a2e
Show file tree
Hide file tree
Showing 24 changed files with 1,300 additions and 9 deletions.
6 changes: 6 additions & 0 deletions .changeset/rude-panthers-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@moralisweb3/common-evm-utils': patch
'@moralisweb3/evm-api': patch
---

Adding new DeFi endpoints to the SDK
16 changes: 16 additions & 0 deletions demos/cli/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ async function main() {
address: '0x4a220e6096b25eadb88358cb44068a3248254675',
});
console.log('tokenStats', tokenStats.result.toJSON());

const defiSummary = await Moralis.EvmApi.wallets.getDefiSummary({
address: '0xd8da6bf26964af9d7eed9e03e53415d37aa96045',
});
console.log('defiSummary', defiSummary.result.toJSON());

const defiPositions = await Moralis.EvmApi.wallets.getDefiPositionsSummary({
address: '0xd8da6bf26964af9d7eed9e03e53415d37aa96045',
});
console.log('defiPositions', defiPositions);

const defiProtocolPositions = await Moralis.EvmApi.wallets.getDefiPositionsByProtocol({
address: '0xd8da6bf26964af9d7eed9e03e53415d37aa96045',
protocol: 'uniswap-v2',
});
console.log('defiProtocolPositions', defiProtocolPositions.result.toJSON().positions);
}

main();
5 changes: 4 additions & 1 deletion packages/common/evmUtils/generator.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@
"getWalletHistory",
"getNFTSalePrices",
"getNFTContractSalePrices",
"getTokenOwners"
"getTokenOwners",
"getDefiSummary",
"getDefiPositionsByProtocol",
"getDefiPositionsSummary"
]
}
}
Expand Down
50 changes: 49 additions & 1 deletion packages/common/evmUtils/src/generated/client/abstractClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ import { GetTopCryptoCurrenciesByTradingVolumeOperation, GetTopCryptoCurrenciesB
import { ReviewContractsOperation, ReviewContractsOperationRequest, ReviewContractsOperationRequestJSON } from '../operations/ReviewContractsOperation';
import { EvmReviewContracts, EvmReviewContractsJSON } from '../types/EvmReviewContracts';
import { EvmContractsReviewDto, EvmContractsReviewDtoInput, EvmContractsReviewDtoJSON } from '../types/EvmContractsReviewDto';
import { GetDefiSummaryOperation, GetDefiSummaryOperationRequest, GetDefiSummaryOperationRequestJSON } from '../operations/GetDefiSummaryOperation';
import { EvmWalletDefiSummary, EvmWalletDefiSummaryJSON } from '../types/EvmWalletDefiSummary';
import { GetDefiPositionsByProtocolOperation, GetDefiPositionsByProtocolOperationRequest, GetDefiPositionsByProtocolOperationRequestJSON } from '../operations/GetDefiPositionsByProtocolOperation';
import { EvmGetDefiPositionsByProtocol, EvmGetDefiPositionsByProtocolJSON } from '../types/EvmGetDefiPositionsByProtocol';
import { GetDefiPositionsSummaryOperation, GetDefiPositionsSummaryOperationRequest, GetDefiPositionsSummaryOperationRequestJSON } from '../operations/GetDefiPositionsSummaryOperation';
import { EvmDefiPositionSummaryResponse, EvmDefiPositionSummaryResponseJSON } from '../types/EvmDefiPositionSummaryResponse';
import { GetWalletActiveChainsOperation, GetWalletActiveChainsOperationRequest, GetWalletActiveChainsOperationRequestJSON } from '../operations/GetWalletActiveChainsOperation';
import { EvmWalletActiveChains, EvmWalletActiveChainsJSON } from '../types/EvmWalletActiveChains';
import { GetWalletStatsOperation, GetWalletStatsOperationRequest, GetWalletStatsOperationRequestJSON } from '../operations/GetWalletStatsOperation';
Expand Down Expand Up @@ -176,7 +182,7 @@ export abstract class AbstractClient {
};
public readonly nft = {
/**
* @description Get trades of NFTs for a given contract and marketplace.
* @description Get trades of NFTs for a given contract with the ability to filter by marketplace.
* @param request Request with parameters.
* @param {Object} request.address The address of the NFT contract
* @param {Object} [request.chain] The chain to query (optional)
Expand All @@ -193,6 +199,7 @@ export abstract class AbstractClient {
* @param {Object} [request.marketplace] Marketplace from which to get the trades. See [supported Marketplaces](https://docs.moralis.io/web3-data-api/evm/nft-marketplaces). (optional)
* @param {String} [request.cursor] The cursor returned in the previous response (used for getting the next page). (optional)
* @param {Number} [request.limit] The desired page size of the result. (optional)
* @param {Boolean} [request.nftMetadata] Include the NFT Metadata of the NFT Token (optional)
* @returns {Object} Response for the request.
*/
getNFTTrades: this.createEndpoint<
Expand Down Expand Up @@ -383,6 +390,7 @@ export abstract class AbstractClient {
* * If 'to_date' and 'to_block' are provided, 'to_block' will be used. (optional)
* @param {Boolean} [request.includeInternalTransactions] If the result should contain the internal transactions. (optional)
* @param {Boolean} [request.includeInputData] Set the input data from the result (optional)
* @param {Boolean} [request.includeLogsData] Set the logs data from the result (optional)
* @param {Boolean} [request.nftMetadata] If the result should contain the nft metadata. (optional)
* @param {String} [request.cursor] The cursor returned in the previous response (used for getting the next page). (optional)
* @param {Object} [request.order] The order of the result, in ascending (ASC) or descending (DESC) (optional)
Expand Down Expand Up @@ -430,6 +438,46 @@ export abstract class AbstractClient {
EvmNetWorthResult,
EvmNetWorthResultJSON
>(GetWalletNetWorthOperation),
/**
* @description Get the defi summary of a wallet address.
* @param request Request with parameters.
* @param {Object} request.address Wallet address
* @param {Object} [request.chain] The chain to query (optional)
* @returns {Object} Response for the request.
*/
getDefiSummary: this.createEndpoint<
GetDefiSummaryOperationRequest,
GetDefiSummaryOperationRequestJSON,
EvmWalletDefiSummary,
EvmWalletDefiSummaryJSON
>(GetDefiSummaryOperation),
/**
* @description Get the detailed defi positions by protocol for a wallet address.
* @param request Request with parameters.
* @param {Object} request.address Wallet address
* @param {Object} request.protocol The protocol to query
* @param {Object} [request.chain] The chain to query (optional)
* @returns {Object} Response for the request.
*/
getDefiPositionsByProtocol: this.createEndpoint<
GetDefiPositionsByProtocolOperationRequest,
GetDefiPositionsByProtocolOperationRequestJSON,
EvmGetDefiPositionsByProtocol,
EvmGetDefiPositionsByProtocolJSON
>(GetDefiPositionsByProtocolOperation),
/**
* @description Get the positions summary of a wallet address.
* @param request Request with parameters.
* @param {Object} request.address Wallet address
* @param {Object} [request.chain] The chain to query (optional)
* @returns {Object[]} Response for the request.
*/
getDefiPositionsSummary: this.createEndpoint<
GetDefiPositionsSummaryOperationRequest,
GetDefiPositionsSummaryOperationRequestJSON,
EvmDefiPositionSummaryResponse[],
EvmDefiPositionSummaryResponseJSON[]
>(GetDefiPositionsSummaryOperation),
/**
* @description Get the active chains for a wallet address.
* @param request Request with parameters.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { EvmChain, EvmChainInput, EvmChainJSON, EvmAddress, EvmAddressInput, EvmAddressJSON } from '../../dataTypes';
import { EvmDefiProtocolList, EvmDefiProtocolListValue, EvmDefiProtocolListInput, EvmDefiProtocolListJSON } from '../types/EvmDefiProtocolList';
import { EvmGetDefiPositionsByProtocol, EvmGetDefiPositionsByProtocolJSON } from '../types/EvmGetDefiPositionsByProtocol';

// request parameters:
// - chain ($ref: #/components/schemas/chainList)
// - address ($ref: #/paths/~1wallets~1{address}~1defi~1{protocol}~1positions/get/parameters/1/schema)
// - protocol ($ref: #/components/schemas/defiProtocolList)

export interface GetDefiPositionsByProtocolOperationRequest {
/**
* @description The chain to query
*/
readonly chain?: EvmChainInput | EvmChain;
/**
* @description Wallet address
*/
readonly address: EvmAddressInput | EvmAddress;
/**
* @description The protocol to query
*/
readonly protocol: EvmDefiProtocolListInput | EvmDefiProtocolListValue;
}

export interface GetDefiPositionsByProtocolOperationRequestJSON {
readonly chain?: EvmChainJSON;
readonly address: EvmAddressJSON;
readonly protocol: EvmDefiProtocolListJSON;
}

export type GetDefiPositionsByProtocolOperationResponse = EvmGetDefiPositionsByProtocol;
export type GetDefiPositionsByProtocolOperationResponseJSON = EvmGetDefiPositionsByProtocolJSON;

export const GetDefiPositionsByProtocolOperation = {
operationId: "getDefiPositionsByProtocol",
groupName: "wallets",
httpMethod: "get",
routePattern: "/wallets/{address}/defi/{protocol}/positions",
parameterNames: ["chain","address","protocol"],
hasResponse: true,
hasBody: false,

parseResponse(json: EvmGetDefiPositionsByProtocolJSON): EvmGetDefiPositionsByProtocol {
return EvmGetDefiPositionsByProtocol.fromJSON(json);
},

serializeRequest(request: GetDefiPositionsByProtocolOperationRequest): GetDefiPositionsByProtocolOperationRequestJSON {
const chain = request.chain ? EvmChain.create(request.chain) : undefined;
const address = EvmAddress.create(request.address);
const protocol = EvmDefiProtocolList.create(request.protocol);
return {
chain: chain ? chain.toJSON() : undefined,
address: address.toJSON(),
protocol: protocol,
};
},

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { EvmChain, EvmChainInput, EvmChainJSON, EvmAddress, EvmAddressInput, EvmAddressJSON } from '../../dataTypes';
import { EvmDefiPositionSummaryResponse, EvmDefiPositionSummaryResponseJSON } from '../types/EvmDefiPositionSummaryResponse';

// request parameters:
// - chain ($ref: #/components/schemas/chainList)
// - address ($ref: #/paths/~1wallets~1{address}~1defi~1positions/get/parameters/1/schema)

export interface GetDefiPositionsSummaryOperationRequest {
/**
* @description The chain to query
*/
readonly chain?: EvmChainInput | EvmChain;
/**
* @description Wallet address
*/
readonly address: EvmAddressInput | EvmAddress;
}

export interface GetDefiPositionsSummaryOperationRequestJSON {
readonly chain?: EvmChainJSON;
readonly address: EvmAddressJSON;
}

export type GetDefiPositionsSummaryOperationResponse = EvmDefiPositionSummaryResponse[];
export type GetDefiPositionsSummaryOperationResponseJSON = EvmDefiPositionSummaryResponseJSON[];

export const GetDefiPositionsSummaryOperation = {
operationId: "getDefiPositionsSummary",
groupName: "wallets",
httpMethod: "get",
routePattern: "/wallets/{address}/defi/positions",
parameterNames: ["chain","address"],
hasResponse: true,
hasBody: false,

parseResponse(json: EvmDefiPositionSummaryResponseJSON[]): EvmDefiPositionSummaryResponse[] {
return json.map((item) => EvmDefiPositionSummaryResponse.fromJSON(item));
},

serializeRequest(request: GetDefiPositionsSummaryOperationRequest): GetDefiPositionsSummaryOperationRequestJSON {
const chain = request.chain ? EvmChain.create(request.chain) : undefined;
const address = EvmAddress.create(request.address);
return {
chain: chain ? chain.toJSON() : undefined,
address: address.toJSON(),
};
},

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { EvmChain, EvmChainInput, EvmChainJSON, EvmAddress, EvmAddressInput, EvmAddressJSON } from '../../dataTypes';
import { EvmWalletDefiSummary, EvmWalletDefiSummaryJSON } from '../types/EvmWalletDefiSummary';

// request parameters:
// - chain ($ref: #/components/schemas/chainList)
// - address ($ref: #/paths/~1wallets~1{address}~1defi~1summary/get/parameters/1/schema)

export interface GetDefiSummaryOperationRequest {
/**
* @description The chain to query
*/
readonly chain?: EvmChainInput | EvmChain;
/**
* @description Wallet address
*/
readonly address: EvmAddressInput | EvmAddress;
}

export interface GetDefiSummaryOperationRequestJSON {
readonly chain?: EvmChainJSON;
readonly address: EvmAddressJSON;
}

export type GetDefiSummaryOperationResponse = EvmWalletDefiSummary;
export type GetDefiSummaryOperationResponseJSON = EvmWalletDefiSummaryJSON;

export const GetDefiSummaryOperation = {
operationId: "getDefiSummary",
groupName: "wallets",
httpMethod: "get",
routePattern: "/wallets/{address}/defi/summary",
parameterNames: ["chain","address"],
hasResponse: true,
hasBody: false,

parseResponse(json: EvmWalletDefiSummaryJSON): EvmWalletDefiSummary {
return EvmWalletDefiSummary.fromJSON(json);
},

serializeRequest(request: GetDefiSummaryOperationRequest): GetDefiSummaryOperationRequestJSON {
const chain = request.chain ? EvmChain.create(request.chain) : undefined;
const address = EvmAddress.create(request.address);
return {
chain: chain ? chain.toJSON() : undefined,
address: address.toJSON(),
};
},

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import { EvmTradeCollection, EvmTradeCollectionJSON } from '../types/EvmTradeCol
// - marketplace ($ref: #/paths/~1nft~1{address}~1trades/get/parameters/5/schema)
// - cursor ($ref: #/paths/~1nft~1{address}~1trades/get/parameters/6/schema)
// - limit ($ref: #/paths/~1nft~1{address}~1trades/get/parameters/7/schema)
// - address ($ref: #/paths/~1nft~1{address}~1trades/get/parameters/8/schema)
// - nft_metadata ($ref: #/paths/~1nft~1{address}~1trades/get/parameters/8/schema)
// - address ($ref: #/paths/~1nft~1{address}~1trades/get/parameters/9/schema)

export interface GetNFTTradesOperationRequest {
/**
Expand Down Expand Up @@ -52,6 +53,10 @@ export interface GetNFTTradesOperationRequest {
* @description The desired page size of the result.
*/
readonly limit?: number;
/**
* @description Include the NFT Metadata of the NFT Token
*/
readonly nftMetadata?: boolean;
/**
* @description The address of the NFT contract
*/
Expand All @@ -67,6 +72,7 @@ export interface GetNFTTradesOperationRequestJSON {
readonly marketplace?: EvmGetNFTTradesMarketplaceEnumJSON;
readonly cursor?: string;
readonly limit?: number;
readonly nft_metadata?: boolean;
readonly address: EvmAddressJSON;
}

Expand All @@ -78,7 +84,7 @@ export const GetNFTTradesOperation = {
groupName: "nft",
httpMethod: "get",
routePattern: "/nft/{address}/trades",
parameterNames: ["chain","from_block","to_block","from_date","to_date","marketplace","cursor","limit","address"],
parameterNames: ["chain","from_block","to_block","from_date","to_date","marketplace","cursor","limit","nft_metadata","address"],
hasResponse: true,
hasBody: false,

Expand All @@ -95,6 +101,7 @@ export const GetNFTTradesOperation = {
const marketplace = request.marketplace ? EvmGetNFTTradesMarketplaceEnum.create(request.marketplace) : undefined;
const cursor = request.cursor;
const limit = request.limit;
const nftMetadata = request.nftMetadata;
const address = EvmAddress.create(request.address);
return {
chain: chain ? chain.toJSON() : undefined,
Expand All @@ -105,6 +112,7 @@ export const GetNFTTradesOperation = {
marketplace: marketplace ? marketplace : undefined,
cursor: cursor,
limit: limit,
nft_metadata: nftMetadata,
address: address.toJSON(),
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import { EvmWalletHistory, EvmWalletHistoryJSON } from '../types/EvmWalletHistor
// - address ($ref: #/paths/~1wallets~1{address}~1history/get/parameters/5/schema)
// - include_internal_transactions ($ref: #/paths/~1wallets~1{address}~1history/get/parameters/6/schema)
// - include_input_data ($ref: #/paths/~1wallets~1{address}~1history/get/parameters/7/schema)
// - nft_metadata ($ref: #/paths/~1wallets~1{address}~1history/get/parameters/8/schema)
// - cursor ($ref: #/paths/~1wallets~1{address}~1history/get/parameters/9/schema)
// - include_logs_data ($ref: #/paths/~1wallets~1{address}~1history/get/parameters/8/schema)
// - nft_metadata ($ref: #/paths/~1wallets~1{address}~1history/get/parameters/9/schema)
// - cursor ($ref: #/paths/~1wallets~1{address}~1history/get/parameters/10/schema)
// - order ($ref: #/components/schemas/orderList)
// - limit ($ref: #/paths/~1wallets~1{address}~1history/get/parameters/11/schema)
// - limit ($ref: #/paths/~1wallets~1{address}~1history/get/parameters/12/schema)

export interface GetWalletHistoryOperationRequest {
/**
Expand Down Expand Up @@ -57,6 +58,10 @@ export interface GetWalletHistoryOperationRequest {
* @description Set the input data from the result
*/
readonly includeInputData?: boolean;
/**
* @description Set the logs data from the result
*/
readonly includeLogsData?: boolean;
/**
* @description If the result should contain the nft metadata.
*/
Expand Down Expand Up @@ -84,6 +89,7 @@ export interface GetWalletHistoryOperationRequestJSON {
readonly address: EvmAddressJSON;
readonly include_internal_transactions?: boolean;
readonly include_input_data?: boolean;
readonly include_logs_data?: boolean;
readonly nft_metadata?: boolean;
readonly cursor?: string;
readonly order?: EvmOrderListJSON;
Expand All @@ -98,7 +104,7 @@ export const GetWalletHistoryOperation = {
groupName: "wallets",
httpMethod: "get",
routePattern: "/wallets/{address}/history",
parameterNames: ["chain","from_block","to_block","from_date","to_date","address","include_internal_transactions","include_input_data","nft_metadata","cursor","order","limit"],
parameterNames: ["chain","from_block","to_block","from_date","to_date","address","include_internal_transactions","include_input_data","include_logs_data","nft_metadata","cursor","order","limit"],
hasResponse: true,
hasBody: false,

Expand All @@ -115,6 +121,7 @@ export const GetWalletHistoryOperation = {
const address = EvmAddress.create(request.address);
const includeInternalTransactions = request.includeInternalTransactions;
const includeInputData = request.includeInputData;
const includeLogsData = request.includeLogsData;
const nftMetadata = request.nftMetadata;
const cursor = request.cursor;
const order = request.order ? EvmOrderList.create(request.order) : undefined;
Expand All @@ -128,6 +135,7 @@ export const GetWalletHistoryOperation = {
address: address.toJSON(),
include_internal_transactions: includeInternalTransactions,
include_input_data: includeInputData,
include_logs_data: includeLogsData,
nft_metadata: nftMetadata,
cursor: cursor,
order: order ? order : undefined,
Expand Down
Loading

1 comment on commit 26d2a2e

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test coverage

Title Lines Statements Branches Functions
api-utils Coverage: 20%
20.6% (61/296) 20.48% (17/83) 19.04% (12/63)
auth Coverage: 89%
92.45% (98/106) 83.33% (20/24) 86.66% (26/30)
evm-api Coverage: 79%
80.35% (90/112) 66.66% (6/9) 71.79% (56/78)
common-aptos-utils Coverage: 4%
4.56% (151/3306) 4.49% (25/556) 5.53% (45/813)
common-evm-utils Coverage: 55%
56.75% (2108/3714) 17.37% (172/990) 37.95% (476/1254)
sol-api Coverage: 97%
97.56% (40/41) 66.66% (6/9) 93.75% (15/16)
common-sol-utils Coverage: 64%
65.42% (229/350) 41.86% (18/43) 50.89% (57/112)
common-streams-utils Coverage: 90%
90.73% (1204/1327) 73.63% (363/493) 82.07% (444/541)
streams Coverage: 91%
90.54% (603/666) 72.34% (68/94) 90.97% (131/144)

Please sign in to comment.