Skip to content

Commit 26d2a2e

Browse files
authored
feat: expose defi endpoints (#1211)
1 parent a9caca5 commit 26d2a2e

24 files changed

+1300
-9
lines changed

.changeset/rude-panthers-tell.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@moralisweb3/common-evm-utils': patch
3+
'@moralisweb3/evm-api': patch
4+
---
5+
6+
Adding new DeFi endpoints to the SDK

demos/cli/src/main.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,22 @@ async function main() {
4646
address: '0x4a220e6096b25eadb88358cb44068a3248254675',
4747
});
4848
console.log('tokenStats', tokenStats.result.toJSON());
49+
50+
const defiSummary = await Moralis.EvmApi.wallets.getDefiSummary({
51+
address: '0xd8da6bf26964af9d7eed9e03e53415d37aa96045',
52+
});
53+
console.log('defiSummary', defiSummary.result.toJSON());
54+
55+
const defiPositions = await Moralis.EvmApi.wallets.getDefiPositionsSummary({
56+
address: '0xd8da6bf26964af9d7eed9e03e53415d37aa96045',
57+
});
58+
console.log('defiPositions', defiPositions);
59+
60+
const defiProtocolPositions = await Moralis.EvmApi.wallets.getDefiPositionsByProtocol({
61+
address: '0xd8da6bf26964af9d7eed9e03e53415d37aa96045',
62+
protocol: 'uniswap-v2',
63+
});
64+
console.log('defiProtocolPositions', defiProtocolPositions.result.toJSON().positions);
4965
}
5066

5167
main();

packages/common/evmUtils/generator.config.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,10 @@
121121
"getWalletHistory",
122122
"getNFTSalePrices",
123123
"getNFTContractSalePrices",
124-
"getTokenOwners"
124+
"getTokenOwners",
125+
"getDefiSummary",
126+
"getDefiPositionsByProtocol",
127+
"getDefiPositionsSummary"
125128
]
126129
}
127130
}

packages/common/evmUtils/src/generated/client/abstractClient.ts

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ import { GetTopCryptoCurrenciesByTradingVolumeOperation, GetTopCryptoCurrenciesB
3636
import { ReviewContractsOperation, ReviewContractsOperationRequest, ReviewContractsOperationRequestJSON } from '../operations/ReviewContractsOperation';
3737
import { EvmReviewContracts, EvmReviewContractsJSON } from '../types/EvmReviewContracts';
3838
import { EvmContractsReviewDto, EvmContractsReviewDtoInput, EvmContractsReviewDtoJSON } from '../types/EvmContractsReviewDto';
39+
import { GetDefiSummaryOperation, GetDefiSummaryOperationRequest, GetDefiSummaryOperationRequestJSON } from '../operations/GetDefiSummaryOperation';
40+
import { EvmWalletDefiSummary, EvmWalletDefiSummaryJSON } from '../types/EvmWalletDefiSummary';
41+
import { GetDefiPositionsByProtocolOperation, GetDefiPositionsByProtocolOperationRequest, GetDefiPositionsByProtocolOperationRequestJSON } from '../operations/GetDefiPositionsByProtocolOperation';
42+
import { EvmGetDefiPositionsByProtocol, EvmGetDefiPositionsByProtocolJSON } from '../types/EvmGetDefiPositionsByProtocol';
43+
import { GetDefiPositionsSummaryOperation, GetDefiPositionsSummaryOperationRequest, GetDefiPositionsSummaryOperationRequestJSON } from '../operations/GetDefiPositionsSummaryOperation';
44+
import { EvmDefiPositionSummaryResponse, EvmDefiPositionSummaryResponseJSON } from '../types/EvmDefiPositionSummaryResponse';
3945
import { GetWalletActiveChainsOperation, GetWalletActiveChainsOperationRequest, GetWalletActiveChainsOperationRequestJSON } from '../operations/GetWalletActiveChainsOperation';
4046
import { EvmWalletActiveChains, EvmWalletActiveChainsJSON } from '../types/EvmWalletActiveChains';
4147
import { GetWalletStatsOperation, GetWalletStatsOperationRequest, GetWalletStatsOperationRequestJSON } from '../operations/GetWalletStatsOperation';
@@ -176,7 +182,7 @@ export abstract class AbstractClient {
176182
};
177183
public readonly nft = {
178184
/**
179-
* @description Get trades of NFTs for a given contract and marketplace.
185+
* @description Get trades of NFTs for a given contract with the ability to filter by marketplace.
180186
* @param request Request with parameters.
181187
* @param {Object} request.address The address of the NFT contract
182188
* @param {Object} [request.chain] The chain to query (optional)
@@ -193,6 +199,7 @@ export abstract class AbstractClient {
193199
* @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)
194200
* @param {String} [request.cursor] The cursor returned in the previous response (used for getting the next page). (optional)
195201
* @param {Number} [request.limit] The desired page size of the result. (optional)
202+
* @param {Boolean} [request.nftMetadata] Include the NFT Metadata of the NFT Token (optional)
196203
* @returns {Object} Response for the request.
197204
*/
198205
getNFTTrades: this.createEndpoint<
@@ -383,6 +390,7 @@ export abstract class AbstractClient {
383390
* * If 'to_date' and 'to_block' are provided, 'to_block' will be used. (optional)
384391
* @param {Boolean} [request.includeInternalTransactions] If the result should contain the internal transactions. (optional)
385392
* @param {Boolean} [request.includeInputData] Set the input data from the result (optional)
393+
* @param {Boolean} [request.includeLogsData] Set the logs data from the result (optional)
386394
* @param {Boolean} [request.nftMetadata] If the result should contain the nft metadata. (optional)
387395
* @param {String} [request.cursor] The cursor returned in the previous response (used for getting the next page). (optional)
388396
* @param {Object} [request.order] The order of the result, in ascending (ASC) or descending (DESC) (optional)
@@ -430,6 +438,46 @@ export abstract class AbstractClient {
430438
EvmNetWorthResult,
431439
EvmNetWorthResultJSON
432440
>(GetWalletNetWorthOperation),
441+
/**
442+
* @description Get the defi summary of a wallet address.
443+
* @param request Request with parameters.
444+
* @param {Object} request.address Wallet address
445+
* @param {Object} [request.chain] The chain to query (optional)
446+
* @returns {Object} Response for the request.
447+
*/
448+
getDefiSummary: this.createEndpoint<
449+
GetDefiSummaryOperationRequest,
450+
GetDefiSummaryOperationRequestJSON,
451+
EvmWalletDefiSummary,
452+
EvmWalletDefiSummaryJSON
453+
>(GetDefiSummaryOperation),
454+
/**
455+
* @description Get the detailed defi positions by protocol for a wallet address.
456+
* @param request Request with parameters.
457+
* @param {Object} request.address Wallet address
458+
* @param {Object} request.protocol The protocol to query
459+
* @param {Object} [request.chain] The chain to query (optional)
460+
* @returns {Object} Response for the request.
461+
*/
462+
getDefiPositionsByProtocol: this.createEndpoint<
463+
GetDefiPositionsByProtocolOperationRequest,
464+
GetDefiPositionsByProtocolOperationRequestJSON,
465+
EvmGetDefiPositionsByProtocol,
466+
EvmGetDefiPositionsByProtocolJSON
467+
>(GetDefiPositionsByProtocolOperation),
468+
/**
469+
* @description Get the positions summary of a wallet address.
470+
* @param request Request with parameters.
471+
* @param {Object} request.address Wallet address
472+
* @param {Object} [request.chain] The chain to query (optional)
473+
* @returns {Object[]} Response for the request.
474+
*/
475+
getDefiPositionsSummary: this.createEndpoint<
476+
GetDefiPositionsSummaryOperationRequest,
477+
GetDefiPositionsSummaryOperationRequestJSON,
478+
EvmDefiPositionSummaryResponse[],
479+
EvmDefiPositionSummaryResponseJSON[]
480+
>(GetDefiPositionsSummaryOperation),
433481
/**
434482
* @description Get the active chains for a wallet address.
435483
* @param request Request with parameters.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { EvmChain, EvmChainInput, EvmChainJSON, EvmAddress, EvmAddressInput, EvmAddressJSON } from '../../dataTypes';
2+
import { EvmDefiProtocolList, EvmDefiProtocolListValue, EvmDefiProtocolListInput, EvmDefiProtocolListJSON } from '../types/EvmDefiProtocolList';
3+
import { EvmGetDefiPositionsByProtocol, EvmGetDefiPositionsByProtocolJSON } from '../types/EvmGetDefiPositionsByProtocol';
4+
5+
// request parameters:
6+
// - chain ($ref: #/components/schemas/chainList)
7+
// - address ($ref: #/paths/~1wallets~1{address}~1defi~1{protocol}~1positions/get/parameters/1/schema)
8+
// - protocol ($ref: #/components/schemas/defiProtocolList)
9+
10+
export interface GetDefiPositionsByProtocolOperationRequest {
11+
/**
12+
* @description The chain to query
13+
*/
14+
readonly chain?: EvmChainInput | EvmChain;
15+
/**
16+
* @description Wallet address
17+
*/
18+
readonly address: EvmAddressInput | EvmAddress;
19+
/**
20+
* @description The protocol to query
21+
*/
22+
readonly protocol: EvmDefiProtocolListInput | EvmDefiProtocolListValue;
23+
}
24+
25+
export interface GetDefiPositionsByProtocolOperationRequestJSON {
26+
readonly chain?: EvmChainJSON;
27+
readonly address: EvmAddressJSON;
28+
readonly protocol: EvmDefiProtocolListJSON;
29+
}
30+
31+
export type GetDefiPositionsByProtocolOperationResponse = EvmGetDefiPositionsByProtocol;
32+
export type GetDefiPositionsByProtocolOperationResponseJSON = EvmGetDefiPositionsByProtocolJSON;
33+
34+
export const GetDefiPositionsByProtocolOperation = {
35+
operationId: "getDefiPositionsByProtocol",
36+
groupName: "wallets",
37+
httpMethod: "get",
38+
routePattern: "/wallets/{address}/defi/{protocol}/positions",
39+
parameterNames: ["chain","address","protocol"],
40+
hasResponse: true,
41+
hasBody: false,
42+
43+
parseResponse(json: EvmGetDefiPositionsByProtocolJSON): EvmGetDefiPositionsByProtocol {
44+
return EvmGetDefiPositionsByProtocol.fromJSON(json);
45+
},
46+
47+
serializeRequest(request: GetDefiPositionsByProtocolOperationRequest): GetDefiPositionsByProtocolOperationRequestJSON {
48+
const chain = request.chain ? EvmChain.create(request.chain) : undefined;
49+
const address = EvmAddress.create(request.address);
50+
const protocol = EvmDefiProtocolList.create(request.protocol);
51+
return {
52+
chain: chain ? chain.toJSON() : undefined,
53+
address: address.toJSON(),
54+
protocol: protocol,
55+
};
56+
},
57+
58+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { EvmChain, EvmChainInput, EvmChainJSON, EvmAddress, EvmAddressInput, EvmAddressJSON } from '../../dataTypes';
2+
import { EvmDefiPositionSummaryResponse, EvmDefiPositionSummaryResponseJSON } from '../types/EvmDefiPositionSummaryResponse';
3+
4+
// request parameters:
5+
// - chain ($ref: #/components/schemas/chainList)
6+
// - address ($ref: #/paths/~1wallets~1{address}~1defi~1positions/get/parameters/1/schema)
7+
8+
export interface GetDefiPositionsSummaryOperationRequest {
9+
/**
10+
* @description The chain to query
11+
*/
12+
readonly chain?: EvmChainInput | EvmChain;
13+
/**
14+
* @description Wallet address
15+
*/
16+
readonly address: EvmAddressInput | EvmAddress;
17+
}
18+
19+
export interface GetDefiPositionsSummaryOperationRequestJSON {
20+
readonly chain?: EvmChainJSON;
21+
readonly address: EvmAddressJSON;
22+
}
23+
24+
export type GetDefiPositionsSummaryOperationResponse = EvmDefiPositionSummaryResponse[];
25+
export type GetDefiPositionsSummaryOperationResponseJSON = EvmDefiPositionSummaryResponseJSON[];
26+
27+
export const GetDefiPositionsSummaryOperation = {
28+
operationId: "getDefiPositionsSummary",
29+
groupName: "wallets",
30+
httpMethod: "get",
31+
routePattern: "/wallets/{address}/defi/positions",
32+
parameterNames: ["chain","address"],
33+
hasResponse: true,
34+
hasBody: false,
35+
36+
parseResponse(json: EvmDefiPositionSummaryResponseJSON[]): EvmDefiPositionSummaryResponse[] {
37+
return json.map((item) => EvmDefiPositionSummaryResponse.fromJSON(item));
38+
},
39+
40+
serializeRequest(request: GetDefiPositionsSummaryOperationRequest): GetDefiPositionsSummaryOperationRequestJSON {
41+
const chain = request.chain ? EvmChain.create(request.chain) : undefined;
42+
const address = EvmAddress.create(request.address);
43+
return {
44+
chain: chain ? chain.toJSON() : undefined,
45+
address: address.toJSON(),
46+
};
47+
},
48+
49+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { EvmChain, EvmChainInput, EvmChainJSON, EvmAddress, EvmAddressInput, EvmAddressJSON } from '../../dataTypes';
2+
import { EvmWalletDefiSummary, EvmWalletDefiSummaryJSON } from '../types/EvmWalletDefiSummary';
3+
4+
// request parameters:
5+
// - chain ($ref: #/components/schemas/chainList)
6+
// - address ($ref: #/paths/~1wallets~1{address}~1defi~1summary/get/parameters/1/schema)
7+
8+
export interface GetDefiSummaryOperationRequest {
9+
/**
10+
* @description The chain to query
11+
*/
12+
readonly chain?: EvmChainInput | EvmChain;
13+
/**
14+
* @description Wallet address
15+
*/
16+
readonly address: EvmAddressInput | EvmAddress;
17+
}
18+
19+
export interface GetDefiSummaryOperationRequestJSON {
20+
readonly chain?: EvmChainJSON;
21+
readonly address: EvmAddressJSON;
22+
}
23+
24+
export type GetDefiSummaryOperationResponse = EvmWalletDefiSummary;
25+
export type GetDefiSummaryOperationResponseJSON = EvmWalletDefiSummaryJSON;
26+
27+
export const GetDefiSummaryOperation = {
28+
operationId: "getDefiSummary",
29+
groupName: "wallets",
30+
httpMethod: "get",
31+
routePattern: "/wallets/{address}/defi/summary",
32+
parameterNames: ["chain","address"],
33+
hasResponse: true,
34+
hasBody: false,
35+
36+
parseResponse(json: EvmWalletDefiSummaryJSON): EvmWalletDefiSummary {
37+
return EvmWalletDefiSummary.fromJSON(json);
38+
},
39+
40+
serializeRequest(request: GetDefiSummaryOperationRequest): GetDefiSummaryOperationRequestJSON {
41+
const chain = request.chain ? EvmChain.create(request.chain) : undefined;
42+
const address = EvmAddress.create(request.address);
43+
return {
44+
chain: chain ? chain.toJSON() : undefined,
45+
address: address.toJSON(),
46+
};
47+
},
48+
49+
}

packages/common/evmUtils/src/generated/operations/GetNFTTradesOperation.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import { EvmTradeCollection, EvmTradeCollectionJSON } from '../types/EvmTradeCol
1111
// - marketplace ($ref: #/paths/~1nft~1{address}~1trades/get/parameters/5/schema)
1212
// - cursor ($ref: #/paths/~1nft~1{address}~1trades/get/parameters/6/schema)
1313
// - limit ($ref: #/paths/~1nft~1{address}~1trades/get/parameters/7/schema)
14-
// - address ($ref: #/paths/~1nft~1{address}~1trades/get/parameters/8/schema)
14+
// - nft_metadata ($ref: #/paths/~1nft~1{address}~1trades/get/parameters/8/schema)
15+
// - address ($ref: #/paths/~1nft~1{address}~1trades/get/parameters/9/schema)
1516

1617
export interface GetNFTTradesOperationRequest {
1718
/**
@@ -52,6 +53,10 @@ export interface GetNFTTradesOperationRequest {
5253
* @description The desired page size of the result.
5354
*/
5455
readonly limit?: number;
56+
/**
57+
* @description Include the NFT Metadata of the NFT Token
58+
*/
59+
readonly nftMetadata?: boolean;
5560
/**
5661
* @description The address of the NFT contract
5762
*/
@@ -67,6 +72,7 @@ export interface GetNFTTradesOperationRequestJSON {
6772
readonly marketplace?: EvmGetNFTTradesMarketplaceEnumJSON;
6873
readonly cursor?: string;
6974
readonly limit?: number;
75+
readonly nft_metadata?: boolean;
7076
readonly address: EvmAddressJSON;
7177
}
7278

@@ -78,7 +84,7 @@ export const GetNFTTradesOperation = {
7884
groupName: "nft",
7985
httpMethod: "get",
8086
routePattern: "/nft/{address}/trades",
81-
parameterNames: ["chain","from_block","to_block","from_date","to_date","marketplace","cursor","limit","address"],
87+
parameterNames: ["chain","from_block","to_block","from_date","to_date","marketplace","cursor","limit","nft_metadata","address"],
8288
hasResponse: true,
8389
hasBody: false,
8490

@@ -95,6 +101,7 @@ export const GetNFTTradesOperation = {
95101
const marketplace = request.marketplace ? EvmGetNFTTradesMarketplaceEnum.create(request.marketplace) : undefined;
96102
const cursor = request.cursor;
97103
const limit = request.limit;
104+
const nftMetadata = request.nftMetadata;
98105
const address = EvmAddress.create(request.address);
99106
return {
100107
chain: chain ? chain.toJSON() : undefined,
@@ -105,6 +112,7 @@ export const GetNFTTradesOperation = {
105112
marketplace: marketplace ? marketplace : undefined,
106113
cursor: cursor,
107114
limit: limit,
115+
nft_metadata: nftMetadata,
108116
address: address.toJSON(),
109117
};
110118
},

packages/common/evmUtils/src/generated/operations/GetWalletHistoryOperation.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ import { EvmWalletHistory, EvmWalletHistoryJSON } from '../types/EvmWalletHistor
1111
// - address ($ref: #/paths/~1wallets~1{address}~1history/get/parameters/5/schema)
1212
// - include_internal_transactions ($ref: #/paths/~1wallets~1{address}~1history/get/parameters/6/schema)
1313
// - include_input_data ($ref: #/paths/~1wallets~1{address}~1history/get/parameters/7/schema)
14-
// - nft_metadata ($ref: #/paths/~1wallets~1{address}~1history/get/parameters/8/schema)
15-
// - cursor ($ref: #/paths/~1wallets~1{address}~1history/get/parameters/9/schema)
14+
// - include_logs_data ($ref: #/paths/~1wallets~1{address}~1history/get/parameters/8/schema)
15+
// - nft_metadata ($ref: #/paths/~1wallets~1{address}~1history/get/parameters/9/schema)
16+
// - cursor ($ref: #/paths/~1wallets~1{address}~1history/get/parameters/10/schema)
1617
// - order ($ref: #/components/schemas/orderList)
17-
// - limit ($ref: #/paths/~1wallets~1{address}~1history/get/parameters/11/schema)
18+
// - limit ($ref: #/paths/~1wallets~1{address}~1history/get/parameters/12/schema)
1819

1920
export interface GetWalletHistoryOperationRequest {
2021
/**
@@ -57,6 +58,10 @@ export interface GetWalletHistoryOperationRequest {
5758
* @description Set the input data from the result
5859
*/
5960
readonly includeInputData?: boolean;
61+
/**
62+
* @description Set the logs data from the result
63+
*/
64+
readonly includeLogsData?: boolean;
6065
/**
6166
* @description If the result should contain the nft metadata.
6267
*/
@@ -84,6 +89,7 @@ export interface GetWalletHistoryOperationRequestJSON {
8489
readonly address: EvmAddressJSON;
8590
readonly include_internal_transactions?: boolean;
8691
readonly include_input_data?: boolean;
92+
readonly include_logs_data?: boolean;
8793
readonly nft_metadata?: boolean;
8894
readonly cursor?: string;
8995
readonly order?: EvmOrderListJSON;
@@ -98,7 +104,7 @@ export const GetWalletHistoryOperation = {
98104
groupName: "wallets",
99105
httpMethod: "get",
100106
routePattern: "/wallets/{address}/history",
101-
parameterNames: ["chain","from_block","to_block","from_date","to_date","address","include_internal_transactions","include_input_data","nft_metadata","cursor","order","limit"],
107+
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"],
102108
hasResponse: true,
103109
hasBody: false,
104110

@@ -115,6 +121,7 @@ export const GetWalletHistoryOperation = {
115121
const address = EvmAddress.create(request.address);
116122
const includeInternalTransactions = request.includeInternalTransactions;
117123
const includeInputData = request.includeInputData;
124+
const includeLogsData = request.includeLogsData;
118125
const nftMetadata = request.nftMetadata;
119126
const cursor = request.cursor;
120127
const order = request.order ? EvmOrderList.create(request.order) : undefined;
@@ -128,6 +135,7 @@ export const GetWalletHistoryOperation = {
128135
address: address.toJSON(),
129136
include_internal_transactions: includeInternalTransactions,
130137
include_input_data: includeInputData,
138+
include_logs_data: includeLogsData,
131139
nft_metadata: nftMetadata,
132140
cursor: cursor,
133141
order: order ? order : undefined,

0 commit comments

Comments
 (0)