Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: getWalletApprovals #1230

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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(),
};
},

}
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
Loading