diff --git a/packages/sdk-ts/package.json b/packages/sdk-ts/package.json index ef10e0a0e..50ab40657 100644 --- a/packages/sdk-ts/package.json +++ b/packages/sdk-ts/package.json @@ -45,7 +45,7 @@ "@injectivelabs/grpc-web-node-http-transport": "^0.0.2", "@injectivelabs/grpc-web-react-native-transport": "^0.0.2", "@injectivelabs/indexer-proto-ts": "1.11.9", - "@injectivelabs/mito-proto-ts": "1.0.45", + "@injectivelabs/mito-proto-ts": "1.0.46", "@injectivelabs/networks": "^1.12.2-beta.4", "@injectivelabs/test-utils": "^1.12.1", "@injectivelabs/token-metadata": "^1.12.2-beta.12", diff --git a/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcMitoApi.spec.ts b/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcMitoApi.spec.ts index 352d8a321..2f74e5a1d 100644 --- a/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcMitoApi.spec.ts +++ b/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcMitoApi.spec.ts @@ -5,6 +5,7 @@ import { IndexerGrpcMitoApi } from './IndexerGrpcMitoApi' const injectiveAddress = mockFactory.injectiveAddress const vaultAddress = 'inj1zwv6feuzhy6a9wekh96cd57lsarmqlwxvdl4nk' +const idoAddress = 'inj1zwv6feuzhy6a9wekh96cd57lsarmqlwxvdl4nk' const endpoints = getNetworkEndpoints(Network.Devnet) const indexerGrpcMitoApi = new IndexerGrpcMitoApi(endpoints.indexer) @@ -433,4 +434,29 @@ describe('IndexerGrpcMitoApi', () => { ) } }) + + test('fetchIDOWhitelist', async () => { + try { + const response = await indexerGrpcMitoApi.fetchIDOWhitelist({ + idoAddress, + }) + + if (response.accounts.length === 0) { + console.warn('fetchIDOWhitelist.responseIsEmptyArray') + } + + expect(response).toBeDefined() + expect(response).toEqual( + expect.objectContaining< + ReturnType< + typeof IndexerGrpcMitoTransformer.mitoWhitelistAccountResponseToWhitelistAccount + > + >(response), + ) + } catch (e) { + console.error( + 'IndexerGrpcMitoApi.fetchIDOWhitelist => ' + (e as any).message, + ) + } + }) }) diff --git a/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcMitoApi.ts b/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcMitoApi.ts index 7492c7a81..38a628953 100644 --- a/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcMitoApi.ts +++ b/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcMitoApi.ts @@ -890,4 +890,50 @@ export class IndexerGrpcMitoApi extends BaseGrpcConsumer { }) } } + + async fetchIDOWhitelist({ + skip, + limit, + idoAddress, + }: { + skip?: number + limit?: number + idoAddress: string + }) { + const request = MitoApi.GetWhitelistRequest.create() + + request.idoAddress = idoAddress + + if (skip) { + request.skip = skip + } + + if (limit) { + request.limit = limit + } + + try { + const response = await this.retry(() => + this.client.GetWhitelist(request), + ) + + return IndexerGrpcMitoTransformer.mitoWhitelistAccountResponseToWhitelistAccount( + response, + ) + } catch (e: unknown) { + if (e instanceof InjectiveMetaRpc.GrpcWebError) { + throw new GrpcUnaryRequestException(new Error(e.toString()), { + code: e.code, + context: 'GetWhitelist', + contextModule: this.module, + }) + } + + throw new GrpcUnaryRequestException(e as Error, { + code: UnspecifiedErrorCode, + context: 'GetWhitelist', + contextModule: this.module, + }) + } + } } diff --git a/packages/sdk-ts/src/client/indexer/transformers/IndexerGrpcMitoTransformer.ts b/packages/sdk-ts/src/client/indexer/transformers/IndexerGrpcMitoTransformer.ts index 474be50f8..d5ce175b5 100644 --- a/packages/sdk-ts/src/client/indexer/transformers/IndexerGrpcMitoTransformer.ts +++ b/packages/sdk-ts/src/client/indexer/transformers/IndexerGrpcMitoTransformer.ts @@ -17,6 +17,7 @@ import { MitoIDOSubscriber, MitoPriceSnapshot, MitoIDOSubscription, + MitoWhitelistAccount, MitoLeaderboardEpoch, MitoSubaccountBalance, MitoMissionLeaderboard, @@ -335,6 +336,7 @@ export class IndexerGrpcMitoTransformer { status: IDO.status, tokenPrice: IDO.tokenPrice, quoteDenom: IDO.quoteDenom, + useWhitelist: IDO.useWhitelist, capPerAddress: IDO.capPerAddress, contractAddress: IDO.contractAddress, subscribedAmount: IDO.subscribedAmount, @@ -432,6 +434,15 @@ export class IndexerGrpcMitoTransformer { } } + static mitoWhitelistAccountToWhitelistAccount( + account: MitoApi.WhitelistAccount, + ): MitoWhitelistAccount { + return { + accountAddress: account.accountAddress, + updatedAt: parseInt(account.updatedAt, 10), + } + } + static vaultResponseToVault(response: MitoApi.GetVaultResponse): MitoVault { const [vault] = response.vault @@ -615,4 +626,18 @@ export class IndexerGrpcMitoTransformer { ), } } + + static mitoWhitelistAccountResponseToWhitelistAccount( + response: MitoApi.GetWhitelistResponse, + ) { + return { + idoAddress: response.idoAddress, + accounts: response.accounts.map( + IndexerGrpcMitoTransformer.mitoWhitelistAccountToWhitelistAccount, + ), + pagination: IndexerGrpcMitoTransformer.mitoPaginationToPagination( + response.pagination, + ), + } + } } diff --git a/packages/sdk-ts/src/client/indexer/types/mito.ts b/packages/sdk-ts/src/client/indexer/types/mito.ts index 7ef895136..909d18925 100644 --- a/packages/sdk-ts/src/client/indexer/types/mito.ts +++ b/packages/sdk-ts/src/client/indexer/types/mito.ts @@ -206,6 +206,7 @@ export interface MitoIDO { progress: MitoIDOProgress[] quoteDenom: string stakeToSubscription: MitoStakeToSubscription[] + useWhitelist: boolean } export interface MitoIDOSubscriber { @@ -238,6 +239,11 @@ export interface MitoIDOSubscription { claimTxHash?: string } +export interface MitoWhitelistAccount { + accountAddress: string + updatedAt: number +} + export type GrpcMitoIDO = MitoApi.IDO export type GrpcMitoVault = MitoApi.Vault export type GrpcMitoMission = MitoApi.Mission @@ -257,6 +263,7 @@ export type GrpcMitoLeaderboardEntry = MitoApi.LeaderboardEntry export type GrpcMitoLeaderboardEpoch = MitoApi.LeaderboardEpoch export type GrpcMitoStakingStakingReward = MitoApi.StakingReward export type GrpcMitoSubaccountBalance = MitoApi.SubaccountBalance +export type GrpcMitoWhitelistAccount = MitoApi.WhitelistAccount export type GrpcMitoStakingStakingActivity = MitoApi.StakingActivity export type GrpcMitoMissionLeaderboardEntry = MitoApi.MissionLeaderboardEntry export type GrpcMitoIDOSubscriptionActivity = MitoApi.IDOSubscriptionActivity diff --git a/packages/sdk-ts/src/utils/constants.ts b/packages/sdk-ts/src/utils/constants.ts index 460326a6c..aa8c1c284 100644 --- a/packages/sdk-ts/src/utils/constants.ts +++ b/packages/sdk-ts/src/utils/constants.ts @@ -49,40 +49,6 @@ export const CW20_SWAP_CONTRACT_BY_NETWORK = { [Network.Local]: 'inj177yh38g3ctu7cemxpa3c2kvwh2yslfxfmfa66h', } -export const CW20_STAKING_CONTRACT_BY_NETWORK = { - [Network.Mainnet]: '', - [Network.MainnetLB]: '', - [Network.MainnetK8s]: '', - [Network.Public]: '', - [Network.Staging]: '', - [Network.Internal]: 'inj1pxzykc8qry3ytxwxr3ua72tn6e4wvusj40yy2w', - [Network.Testnet]: 'inj1pxzykc8qry3ytxwxr3ua72tn6e4wvusj40yy2w', - [Network.TestnetK8s]: 'inj1pxzykc8qry3ytxwxr3ua72tn6e4wvusj40yy2w', - [Network.TestnetOld]: 'inj1pxzykc8qry3ytxwxr3ua72tn6e4wvusj40yy2w', - [Network.TestnetSentry]: 'inj1pxzykc8qry3ytxwxr3ua72tn6e4wvusj40yy2w', - [Network.Devnet]: 'inj15r735cjk9m6ujxtqn9zgxtdhd2lfzslde6c0s5', - [Network.Devnet1]: 'inj15r735cjk9m6ujxtqn9zgxtdhd2lfzslde6c0s5', - [Network.Devnet2]: 'inj15r735cjk9m6ujxtqn9zgxtdhd2lfzslde6c0s5', - [Network.Local]: 'inj15r735cjk9m6ujxtqn9zgxtdhd2lfzslde6c0s5', -} - -export const CW20_ALLOCATOR_CONTRACT_BY_NETWORK = { - [Network.Mainnet]: '', - [Network.MainnetLB]: '', - [Network.MainnetK8s]: '', - [Network.Public]: '', - [Network.Staging]: '', - [Network.Internal]: 'inj1qsft9ptmywulv5hjzufl77j784sr9hf5yj6fwx', - [Network.Testnet]: 'inj1qsft9ptmywulv5hjzufl77j784sr9hf5yj6fwx', - [Network.TestnetK8s]: 'inj1qsft9ptmywulv5hjzufl77j784sr9hf5yj6fwx', - [Network.TestnetSentry]: 'inj1qsft9ptmywulv5hjzufl77j784sr9hf5yj6fwx', - [Network.TestnetOld]: 'inj1qsft9ptmywulv5hjzufl77j784sr9hf5yj6fwx', - [Network.Devnet]: 'inj1nu9wf9dw384attnpu0pwfet5fajn05w2xp99u3', - [Network.Devnet1]: 'inj1nu9wf9dw384attnpu0pwfet5fajn05w2xp99u3', - [Network.Devnet2]: 'inj1nu9wf9dw384attnpu0pwfet5fajn05w2xp99u3', - [Network.Local]: 'inj1nu9wf9dw384attnpu0pwfet5fajn05w2xp99u3', -} - export const INJ_NAME_REGISTRY_CONTRACT_BY_NETWORK = { [Network.Mainnet]: 'inj1hm8vs8sr2h9nk0x66vctfs528wrp6k3gtgg275', [Network.MainnetLB]: 'inj1hm8vs8sr2h9nk0x66vctfs528wrp6k3gtgg275', diff --git a/yarn.lock b/yarn.lock index 8211c2c5a..b048e307a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2176,10 +2176,10 @@ protobufjs "^7.0.0" rxjs "^7.4.0" -"@injectivelabs/mito-proto-ts@1.0.45": - version "1.0.45" - resolved "https://registry.yarnpkg.com/@injectivelabs/mito-proto-ts/-/mito-proto-ts-1.0.45.tgz#1d2f7bb2d91de5ee87801815178090878533287f" - integrity sha512-YFyT+7d09VFGuwE7UXBkfK+XlU/MNc7ZM0UKB460I3zB1yXU7RttME5eM8W2eJvej04cf109DlZVG4yAw60gZA== +"@injectivelabs/mito-proto-ts@1.0.46": + version "1.0.46" + resolved "https://registry.yarnpkg.com/@injectivelabs/mito-proto-ts/-/mito-proto-ts-1.0.46.tgz#d0e31c4ca2f76940771621b2fe88f9bc40c7a891" + integrity sha512-K1g5udssQd4pDNzMteUQiI3PLHsuBhCKT6wli2h05ImB0NFQcGbLQlk3lpzsdfE9Usx2hCmZiQNUfUouRrTBpQ== dependencies: "@injectivelabs/grpc-web" "^0.0.1" google-protobuf "^3.14.0"