-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add getTokenOwners function to sdk
- Loading branch information
Showing
16 changed files
with
324 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 getTokenOwners function to SDK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
packages/common/evmUtils/src/generated/operations/GetTokenOwnersOperation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { EvmChain, EvmChainInput, EvmChainJSON } from '../../dataTypes'; | ||
import { EvmOrderList, EvmOrderListValue, EvmOrderListInput, EvmOrderListJSON } from '../types/EvmOrderList'; | ||
import { EvmErc20TokenOwnerCollection, EvmErc20TokenOwnerCollectionJSON } from '../types/EvmErc20TokenOwnerCollection'; | ||
|
||
// request parameters: | ||
// - chain ($ref: #/components/schemas/chainList) | ||
// - token_address ($ref: #/paths/~1erc20~1{token_address}~1owners/get/parameters/1/schema) | ||
// - limit ($ref: #/paths/~1erc20~1{token_address}~1owners/get/parameters/2/schema) | ||
// - cursor ($ref: #/paths/~1erc20~1{token_address}~1owners/get/parameters/3/schema) | ||
// - order ($ref: #/components/schemas/orderList) | ||
|
||
export interface GetTokenOwnersOperationRequest { | ||
/** | ||
* @description The chain to query | ||
*/ | ||
readonly chain?: EvmChainInput | EvmChain; | ||
/** | ||
* @description The address of the token contract | ||
*/ | ||
readonly tokenAddress: string; | ||
/** | ||
* @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 order of the result, in ascending (ASC) or descending (DESC) | ||
*/ | ||
readonly order?: EvmOrderListInput | EvmOrderListValue; | ||
} | ||
|
||
export interface GetTokenOwnersOperationRequestJSON { | ||
readonly chain?: EvmChainJSON; | ||
readonly token_address: string; | ||
readonly limit?: number; | ||
readonly cursor?: string; | ||
readonly order?: EvmOrderListJSON; | ||
} | ||
|
||
export type GetTokenOwnersOperationResponse = EvmErc20TokenOwnerCollection; | ||
export type GetTokenOwnersOperationResponseJSON = EvmErc20TokenOwnerCollectionJSON; | ||
|
||
export const GetTokenOwnersOperation = { | ||
operationId: "getTokenOwners", | ||
groupName: "token", | ||
httpMethod: "get", | ||
routePattern: "/erc20/{token_address}/owners", | ||
parameterNames: ["chain","token_address","limit","cursor","order"], | ||
hasResponse: true, | ||
hasBody: false, | ||
|
||
parseResponse(json: EvmErc20TokenOwnerCollectionJSON): EvmErc20TokenOwnerCollection { | ||
return EvmErc20TokenOwnerCollection.fromJSON(json); | ||
}, | ||
|
||
serializeRequest(request: GetTokenOwnersOperationRequest): GetTokenOwnersOperationRequestJSON { | ||
const chain = request.chain ? EvmChain.create(request.chain) : undefined; | ||
const tokenAddress = request.tokenAddress; | ||
const limit = request.limit; | ||
const cursor = request.cursor; | ||
const order = request.order ? EvmOrderList.create(request.order) : undefined; | ||
return { | ||
chain: chain ? chain.toJSON() : undefined, | ||
token_address: tokenAddress, | ||
limit: limit, | ||
cursor: cursor, | ||
order: order ? order : undefined, | ||
}; | ||
}, | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
packages/common/evmUtils/src/generated/types/EvmErc20TokenOwner.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// $ref: #/components/schemas/erc20TokenOwner | ||
// type: erc20TokenOwner | ||
// properties: | ||
// - owner_address ($ref: #/components/schemas/erc20TokenOwner/properties/owner_address) | ||
// - owner_address_label ($ref: #/components/schemas/erc20TokenOwner/properties/owner_address_label) | ||
// - balance ($ref: #/components/schemas/erc20TokenOwner/properties/balance) | ||
// - balance_formatted ($ref: #/components/schemas/erc20TokenOwner/properties/balance_formatted) | ||
// - usd_value ($ref: #/components/schemas/erc20TokenOwner/properties/usd_value) | ||
// - is_contract ($ref: #/components/schemas/erc20TokenOwner/properties/is_contract) | ||
// - percentage_relative_to_total_supply ($ref: #/components/schemas/erc20TokenOwner/properties/percentage_relative_to_total_supply) | ||
|
||
export interface EvmErc20TokenOwnerJSON { | ||
readonly owner_address: string; | ||
readonly owner_address_label: string; | ||
readonly balance: string; | ||
readonly balance_formatted: string; | ||
readonly usd_value: string; | ||
readonly is_contract: boolean; | ||
readonly percentage_relative_to_total_supply: number; | ||
} | ||
|
||
export interface EvmErc20TokenOwnerInput { | ||
readonly ownerAddress: string; | ||
readonly ownerAddressLabel: string; | ||
readonly balance: string; | ||
readonly balanceFormatted: string; | ||
readonly usdValue: string; | ||
readonly isContract: boolean; | ||
readonly percentageRelativeToTotalSupply: number; | ||
} | ||
|
||
export class EvmErc20TokenOwner { | ||
public static create(input: EvmErc20TokenOwnerInput | EvmErc20TokenOwner): EvmErc20TokenOwner { | ||
if (input instanceof EvmErc20TokenOwner) { | ||
return input; | ||
} | ||
return new EvmErc20TokenOwner(input); | ||
} | ||
|
||
public static fromJSON(json: EvmErc20TokenOwnerJSON): EvmErc20TokenOwner { | ||
const input: EvmErc20TokenOwnerInput = { | ||
ownerAddress: json.owner_address, | ||
ownerAddressLabel: json.owner_address_label, | ||
balance: json.balance, | ||
balanceFormatted: json.balance_formatted, | ||
usdValue: json.usd_value, | ||
isContract: json.is_contract, | ||
percentageRelativeToTotalSupply: json.percentage_relative_to_total_supply, | ||
}; | ||
return EvmErc20TokenOwner.create(input); | ||
} | ||
|
||
/** | ||
* @description The address of the erc20 token owner | ||
*/ | ||
public readonly ownerAddress: string; | ||
/** | ||
* @description The label of the owner_address | ||
*/ | ||
public readonly ownerAddressLabel: string; | ||
/** | ||
* @description The amount holding of the ERC20 token | ||
*/ | ||
public readonly balance: string; | ||
/** | ||
* @description The amount holding of the ERC20 token in decimaal | ||
*/ | ||
public readonly balanceFormatted: string; | ||
/** | ||
* @description The USD value of the balance | ||
*/ | ||
public readonly usdValue: string; | ||
/** | ||
* @description Indicates if the token address is for a contract or not | ||
*/ | ||
public readonly isContract: boolean; | ||
/** | ||
* @description The percentage of total supply held by the owner | ||
*/ | ||
public readonly percentageRelativeToTotalSupply: number; | ||
|
||
private constructor(input: EvmErc20TokenOwnerInput) { | ||
this.ownerAddress = input.ownerAddress; | ||
this.ownerAddressLabel = input.ownerAddressLabel; | ||
this.balance = input.balance; | ||
this.balanceFormatted = input.balanceFormatted; | ||
this.usdValue = input.usdValue; | ||
this.isContract = input.isContract; | ||
this.percentageRelativeToTotalSupply = input.percentageRelativeToTotalSupply; | ||
} | ||
|
||
public toJSON(): EvmErc20TokenOwnerJSON { | ||
return { | ||
owner_address: this.ownerAddress, | ||
owner_address_label: this.ownerAddressLabel, | ||
balance: this.balance, | ||
balance_formatted: this.balanceFormatted, | ||
usd_value: this.usdValue, | ||
is_contract: this.isContract, | ||
percentage_relative_to_total_supply: this.percentageRelativeToTotalSupply, | ||
} | ||
} | ||
} |
Oops, something went wrong.
92ef94d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test coverage