Skip to content

Commit

Permalink
feat: getWalletApprovals (#1230)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kayconfig authored Sep 3, 2024
1 parent 7fb7b3c commit 71d2b43
Show file tree
Hide file tree
Showing 27 changed files with 977 additions and 294 deletions.
7 changes: 7 additions & 0 deletions .changeset/tall-lobsters-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@moralisweb3/common-evm-utils': patch
'@moralisweb3/evm-api': patch
'moralis': patch
---

Add getWalletApprovals to SDK
3 changes: 2 additions & 1 deletion packages/common/evmUtils/generator.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@
"getWalletProfitabilitySummary",
"getWalletProfitability",
"getTopProfitableWalletPerToken",
"getNFTTradesByToken"
"getNFTTradesByToken",
"getWalletApprovals"
]
}
}
Expand Down
19 changes: 18 additions & 1 deletion packages/common/evmUtils/src/generated/client/abstractClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { EvmErc20Price, EvmErc20PriceJSON } from '../types/EvmErc20Price';
import { EvmGetMultipleTokenPricesDto, EvmGetMultipleTokenPricesDtoInput, EvmGetMultipleTokenPricesDtoJSON } from '../types/EvmGetMultipleTokenPricesDto';
import { GetTokenOwnersOperation, GetTokenOwnersOperationRequest, GetTokenOwnersOperationRequestJSON } from '../operations/GetTokenOwnersOperation';
import { EvmErc20TokenOwnerCollection, EvmErc20TokenOwnerCollectionJSON } from '../types/EvmErc20TokenOwnerCollection';
import { GetWalletApprovalsOperation, GetWalletApprovalsOperationRequest, GetWalletApprovalsOperationRequestJSON } from '../operations/GetWalletApprovalsOperation';
import { EvmWalletApprovals, EvmWalletApprovalsJSON } from '../types/EvmWalletApprovals';
import { GetWalletHistoryOperation, GetWalletHistoryOperationRequest, GetWalletHistoryOperationRequestJSON } from '../operations/GetWalletHistoryOperation';
import { EvmWalletHistory, EvmWalletHistoryJSON } from '../types/EvmWalletHistory';
import { GetWalletTokenBalancesPriceOperation, GetWalletTokenBalancesPriceOperationRequest, GetWalletTokenBalancesPriceOperationRequestJSON } from '../operations/GetWalletTokenBalancesPriceOperation';
Expand Down Expand Up @@ -368,7 +370,7 @@ export abstract class AbstractClient {
* @description Retrieves a list of the top profitable wallets for a specific ERC20 token.
* @param request Request with parameters.
* @param {Object} request.address The ERC20 token address.
* @param {String} [request.days] Timeframe in days for which profitability is calculated, Options include 'all', '7', '30', '60', '90' default is 'all'. (optional)
* @param {String} [request.days] Timeframe in days for which profitability is calculated, Options include 'all', '7', '30' default is 'all'. (optional)
* @param {Object} [request.chain] The chain to query (optional)
* @returns {Object} Response for the request.
*/
Expand Down Expand Up @@ -420,6 +422,21 @@ export abstract class AbstractClient {
>(ReviewContractsOperation),
};
public readonly wallets = {
/**
* @description Retrieve active ERC20 token approvals for the specified wallet address
* @param request Request with parameters.
* @param {Object} request.address The wallet address from which to retrieve active ERC20 token approvals
* @param {Object} [request.chain] The chain to query (optional)
* @param {Number} [request.limit] The desired page size of the result. (optional)
* @param {String} [request.cursor] The cursor returned in the previous response (used for getting the next page). (optional)
* @returns {Object} Response for the request.
*/
getWalletApprovals: this.createEndpoint<
GetWalletApprovalsOperationRequest,
GetWalletApprovalsOperationRequestJSON,
EvmWalletApprovals,
EvmWalletApprovalsJSON
>(GetWalletApprovalsOperation),
/**
* @description Get the complete history of a wallet
* @param request Request with parameters.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface GetTopProfitableWalletPerTokenOperationRequest {
*/
readonly address: EvmAddressInput | EvmAddress;
/**
* @description Timeframe in days for which profitability is calculated, Options include 'all', '7', '30', '60', '90' default is 'all'.
* @description Timeframe in days for which profitability is calculated, Options include 'all', '7', '30' default is 'all'.
*/
readonly days?: string;
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { EvmChain, EvmChainInput, EvmChainJSON, EvmAddress, EvmAddressInput, EvmAddressJSON } from '../../dataTypes';
import { EvmWalletApprovals, EvmWalletApprovalsJSON } from '../types/EvmWalletApprovals';

// request parameters:
// - chain ($ref: #/components/schemas/chainList)
// - limit ($ref: #/paths/~1wallets~1{address}~1approvals/get/parameters/1/schema)
// - cursor ($ref: #/paths/~1wallets~1{address}~1approvals/get/parameters/2/schema)
// - address ($ref: #/paths/~1wallets~1{address}~1approvals/get/parameters/3/schema)

export interface GetWalletApprovalsOperationRequest {
/**
* @description The chain to query
*/
readonly chain?: EvmChainInput | EvmChain;
/**
* @description The desired page size of the result.
*/
readonly limit?: number;
/**
* @description The cursor returned in the previous response (used for getting the next page).
*/
readonly cursor?: string;
/**
* @description The wallet address from which to retrieve active ERC20 token approvals
*/
readonly address: EvmAddressInput | EvmAddress;
}

export interface GetWalletApprovalsOperationRequestJSON {
readonly chain?: EvmChainJSON;
readonly limit?: number;
readonly cursor?: string;
readonly address: EvmAddressJSON;
}

export type GetWalletApprovalsOperationResponse = EvmWalletApprovals;
export type GetWalletApprovalsOperationResponseJSON = EvmWalletApprovalsJSON;

export const GetWalletApprovalsOperation = {
operationId: "getWalletApprovals",
groupName: "wallets",
httpMethod: "get",
routePattern: "/wallets/{address}/approvals",
parameterNames: ["chain","limit","cursor","address"],
hasResponse: true,
hasBody: false,

parseResponse(json: EvmWalletApprovalsJSON): EvmWalletApprovals {
return EvmWalletApprovals.fromJSON(json);
},

serializeRequest(request: GetWalletApprovalsOperationRequest): GetWalletApprovalsOperationRequestJSON {
const chain = request.chain ? EvmChain.create(request.chain) : undefined;
const limit = request.limit;
const cursor = request.cursor;
const address = EvmAddress.create(request.address);
return {
chain: chain ? chain.toJSON() : undefined,
limit: limit,
cursor: cursor,
address: address.toJSON(),
};
},

}
1 change: 1 addition & 0 deletions packages/common/evmUtils/src/generated/operations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export * from './GetNFTContractSalePricesOperation';
export * from './GetNFTSalePricesOperation';
export * from './GetMultipleTokenPricesOperation';
export * from './GetTokenOwnersOperation';
export * from './GetWalletApprovalsOperation';
export * from './GetWalletHistoryOperation';
export * from './GetWalletTokenBalancesPriceOperation';
export * from './GetWalletNetWorthOperation';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { GetNFTContractSalePricesOperation } from './GetNFTContractSalePricesOpe
import { GetNFTSalePricesOperation } from './GetNFTSalePricesOperation';
import { GetMultipleTokenPricesOperation } from './GetMultipleTokenPricesOperation';
import { GetTokenOwnersOperation } from './GetTokenOwnersOperation';
import { GetWalletApprovalsOperation } from './GetWalletApprovalsOperation';
import { GetWalletHistoryOperation } from './GetWalletHistoryOperation';
import { GetWalletTokenBalancesPriceOperation } from './GetWalletTokenBalancesPriceOperation';
import { GetWalletNetWorthOperation } from './GetWalletNetWorthOperation';
Expand Down Expand Up @@ -38,6 +39,7 @@ export const operations = [
GetNFTSalePricesOperation,
GetMultipleTokenPricesOperation,
GetTokenOwnersOperation,
GetWalletApprovalsOperation,
GetWalletHistoryOperation,
GetWalletTokenBalancesPriceOperation,
GetWalletNetWorthOperation,
Expand Down
64 changes: 64 additions & 0 deletions packages/common/evmUtils/src/generated/types/EvmApprovalData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { EvmTokenDetails, EvmTokenDetailsInput, EvmTokenDetailsJSON } from '../types/EvmTokenDetails';
import { EvmSpenderDetails, EvmSpenderDetailsInput, EvmSpenderDetailsJSON } from '../types/EvmSpenderDetails';

// $ref: #/components/schemas/ApprovalData
// type: ApprovalData
// properties:
// - value ($ref: #/components/schemas/ApprovalData/properties/value)
// - value_formatted ($ref: #/components/schemas/ApprovalData/properties/value_formatted)
// - token ($ref: #/components/schemas/TokenDetails)
// - spender ($ref: #/components/schemas/SpenderDetails)

export interface EvmApprovalDataJSON {
readonly value?: string;
readonly value_formatted?: string;
readonly token?: EvmTokenDetailsJSON;
readonly spender?: EvmSpenderDetailsJSON;
}

export interface EvmApprovalDataInput {
readonly value?: string;
readonly valueFormatted?: string;
readonly token?: EvmTokenDetailsInput | EvmTokenDetails;
readonly spender?: EvmSpenderDetailsInput | EvmSpenderDetails;
}

export class EvmApprovalData {
public static create(input: EvmApprovalDataInput | EvmApprovalData): EvmApprovalData {
if (input instanceof EvmApprovalData) {
return input;
}
return new EvmApprovalData(input);
}

public static fromJSON(json: EvmApprovalDataJSON): EvmApprovalData {
const input: EvmApprovalDataInput = {
value: json.value,
valueFormatted: json.value_formatted,
token: json.token ? EvmTokenDetails.fromJSON(json.token) : undefined,
spender: json.spender ? EvmSpenderDetails.fromJSON(json.spender) : undefined,
};
return EvmApprovalData.create(input);
}

public readonly value?: string;
public readonly valueFormatted?: string;
public readonly token?: EvmTokenDetails;
public readonly spender?: EvmSpenderDetails;

private constructor(input: EvmApprovalDataInput) {
this.value = input.value;
this.valueFormatted = input.valueFormatted;
this.token = input.token ? EvmTokenDetails.create(input.token) : undefined;
this.spender = input.spender ? EvmSpenderDetails.create(input.spender) : undefined;
}

public toJSON(): EvmApprovalDataJSON {
return {
value: this.value,
value_formatted: this.valueFormatted,
token: this.token ? this.token.toJSON() : undefined,
spender: this.spender ? this.spender.toJSON() : undefined,
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { EvmApprovalData, EvmApprovalDataInput, EvmApprovalDataJSON } from '../types/EvmApprovalData';

// $ref: #/components/schemas/ApprovalResponse
// type: ApprovalResponse
// properties:
// - approvals ($ref: #/components/schemas/ApprovalData)

export interface EvmApprovalResponseJSON {
readonly approvals?: EvmApprovalDataJSON[];
}

export interface EvmApprovalResponseInput {
readonly approvals?: EvmApprovalDataInput[] | EvmApprovalData[];
}

export class EvmApprovalResponse {
public static create(input: EvmApprovalResponseInput | EvmApprovalResponse): EvmApprovalResponse {
if (input instanceof EvmApprovalResponse) {
return input;
}
return new EvmApprovalResponse(input);
}

public static fromJSON(json: EvmApprovalResponseJSON): EvmApprovalResponse {
const input: EvmApprovalResponseInput = {
approvals: json.approvals ? json.approvals.map((item) => EvmApprovalData.fromJSON(item)) : undefined,
};
return EvmApprovalResponse.create(input);
}

public static isInput(input: any): input is EvmApprovalResponseInput {
return [].every((name) => input[name] !== undefined);
}

public static isJSON(json: any): json is EvmApprovalResponseJSON {
return [].every((name) => json[name] !== undefined);
}

public readonly approvals?: EvmApprovalData[];

private constructor(input: EvmApprovalResponseInput) {
this.approvals = input.approvals ? input.approvals.map((item) => EvmApprovalData.create(item)) : undefined;
}

public toJSON(): EvmApprovalResponseJSON {
return {
approvals: this.approvals ? this.approvals.map((item) => item.toJSON()) : undefined,
}
}
}

This file was deleted.

Loading

1 comment on commit 71d2b43

@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: 75%
76.92% (90/117) 66.66% (6/9) 67.46% (56/83)
common-aptos-utils Coverage: 4%
4.56% (151/3306) 4.49% (25/556) 5.53% (45/813)
common-evm-utils Coverage: 53%
54.1% (2322/4292) 15% (172/1146) 35.16% (498/1416)
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.