diff --git a/packages/sdk-ts/src/client/indexer/types/incentives.ts b/packages/sdk-ts/src/client/indexer/types/incentives.ts new file mode 100644 index 000000000..cb4db367c --- /dev/null +++ b/packages/sdk-ts/src/client/indexer/types/incentives.ts @@ -0,0 +1,22 @@ +import { Coin } from '@injectivelabs/ts-types' + +export interface IncentivesRound { + id: number + name: string + endDate: number + startDate: number + campaigns: string[] +} + +export interface IncentivesCampaign { + id: number + name: string + rewards: Coin[] + inRound: number + marketId: string + isFunded: boolean + description: string + totalRewards: string + isFinalized: boolean + subaccountIdSuffix: string +} diff --git a/packages/sdk-ts/src/client/indexer/types/index.ts b/packages/sdk-ts/src/client/indexer/types/index.ts index a899d327f..e19f2fc9d 100644 --- a/packages/sdk-ts/src/client/indexer/types/index.ts +++ b/packages/sdk-ts/src/client/indexer/types/index.ts @@ -11,6 +11,7 @@ export * from './exchange' export * from './explorer' export * from './campaign' export * from './spot-rest' +export * from './incentives' export * from './derivatives' export * from './explorer-rest' export * from './insurance-funds' diff --git a/packages/sdk-ts/src/client/wasm/incentives/index.ts b/packages/sdk-ts/src/client/wasm/incentives/index.ts new file mode 100644 index 000000000..b31e7023e --- /dev/null +++ b/packages/sdk-ts/src/client/wasm/incentives/index.ts @@ -0,0 +1,3 @@ +export * from './types' +export * from './queries' +export * from './transformer' diff --git a/packages/sdk-ts/src/client/wasm/incentives/queries/QueryAllRounds.ts b/packages/sdk-ts/src/client/wasm/incentives/queries/QueryAllRounds.ts new file mode 100644 index 000000000..7dc270868 --- /dev/null +++ b/packages/sdk-ts/src/client/wasm/incentives/queries/QueryAllRounds.ts @@ -0,0 +1,26 @@ +import { BaseWasmQuery } from '../../BaseWasmQuery' +import { toBase64 } from '../../../../utils' + +export declare namespace QueryAllRoundsArg { + export interface Params { + startAfter?: string + limit?: number + } +} + +export class QueryAllRounds extends BaseWasmQuery { + toPayload() { + const payload = { + all_rounds: { + ...(this.params.limit ? { limit: this.params.limit } : {}), + ...(this.params.startAfter + ? { + start_after: this.params.startAfter, + } + : {}), + }, + } + + return toBase64(payload) + } +} diff --git a/packages/sdk-ts/src/client/wasm/incentives/queries/QueryGetCampaigns.ts b/packages/sdk-ts/src/client/wasm/incentives/queries/QueryGetCampaigns.ts new file mode 100644 index 000000000..10bf5cc36 --- /dev/null +++ b/packages/sdk-ts/src/client/wasm/incentives/queries/QueryGetCampaigns.ts @@ -0,0 +1,20 @@ +import { BaseWasmQuery } from '../../BaseWasmQuery' +import { toBase64 } from '../../../../utils' + +export declare namespace QueryGetCampaignsArg { + export interface Params { + campaigns: string[] + } +} + +export class QueryGetCampaigns extends BaseWasmQuery { + toPayload() { + const payload = { + get_campaigns: { + campaigns: this.params.campaigns, + }, + } + + return toBase64(payload) + } +} diff --git a/packages/sdk-ts/src/client/wasm/incentives/queries/index.ts b/packages/sdk-ts/src/client/wasm/incentives/queries/index.ts new file mode 100644 index 000000000..cf8b9124d --- /dev/null +++ b/packages/sdk-ts/src/client/wasm/incentives/queries/index.ts @@ -0,0 +1,2 @@ +export { QueryAllRounds } from './QueryAllRounds' +export { QueryGetCampaigns } from './QueryGetCampaigns' diff --git a/packages/sdk-ts/src/client/wasm/incentives/transformer.ts b/packages/sdk-ts/src/client/wasm/incentives/transformer.ts new file mode 100644 index 000000000..12bc6ff85 --- /dev/null +++ b/packages/sdk-ts/src/client/wasm/incentives/transformer.ts @@ -0,0 +1,38 @@ +import { QueryRoundResponse, QueryCampaignResponse } from './types' +import { WasmContractQueryResponse } from '../types' +import { toUtf8 } from '../../../utils' + +export class IncentivesQueryTransformer { + static contractRoundResponseToContractRound( + response: WasmContractQueryResponse, + ) { + const data = JSON.parse(toUtf8(response.data)) as QueryRoundResponse[] + + return data.map((round: QueryRoundResponse) => ({ + id: round.id, + name: round.name, + endDate: round.end_date, + campaigns: round.campaigns, + startDate: round.start_date, + })) + } + + static contractCampaignResponseToContractCampaign( + response: WasmContractQueryResponse, + ) { + const data = JSON.parse(toUtf8(response.data)) as QueryCampaignResponse[] + + return data.map((campaign: QueryCampaignResponse) => ({ + id: campaign.id, + name: campaign.name, + rewards: campaign.rewards, + inRound: campaign.in_round, + marketId: campaign.market_id, + isFunded: campaign.is_funded, + description: campaign.description, + isFinalized: campaign.is_finalized, + totalRewards: campaign.total_rewards, + subaccountIdSuffix: campaign.subaccount_id_suffix, + })) + } +} diff --git a/packages/sdk-ts/src/client/wasm/incentives/types.ts b/packages/sdk-ts/src/client/wasm/incentives/types.ts new file mode 100644 index 000000000..f4cfbe678 --- /dev/null +++ b/packages/sdk-ts/src/client/wasm/incentives/types.ts @@ -0,0 +1,22 @@ +import { Coin } from '@injectivelabs/ts-types' + +export interface QueryRoundResponse { + id: number + name: string + end_date: number + start_date: number + campaigns: string[] +} + +export interface QueryCampaignResponse { + id: number + name: string + rewards: Coin[] + in_round: number + market_id: string + is_funded: boolean + description: string + total_rewards: string + is_finalized: boolean + subaccount_id_suffix: string +} diff --git a/packages/sdk-ts/src/client/wasm/index.ts b/packages/sdk-ts/src/client/wasm/index.ts index 93c4cea8e..cedc2a149 100644 --- a/packages/sdk-ts/src/client/wasm/index.ts +++ b/packages/sdk-ts/src/client/wasm/index.ts @@ -1,3 +1,4 @@ export * from './swap' export * from './types' +export * from './incentives' export * from './nameservice' diff --git a/packages/sdk-ts/src/core/modules/wasm/exec-args.ts b/packages/sdk-ts/src/core/modules/wasm/exec-args.ts index 38448dcb3..ae2e604bf 100644 --- a/packages/sdk-ts/src/core/modules/wasm/exec-args.ts +++ b/packages/sdk-ts/src/core/modules/wasm/exec-args.ts @@ -8,6 +8,8 @@ import ExecArgInitiateTransfer from './exec-args/ExecArgInitiateTransfer' import ExecArgIncreaseAllowance from './exec-args/ExecArgIncreaseAllowance' import ExecArgRemoveGridStrategy from './exec-args/ExecArgRemoveGridStrategy' import ExecArgCreateSpotGridStrategy from './exec-args/ExecArgCreateSpotGridStrategy' +import ExecArgCreateRound from './exec-args/ExecArgCreateRound' +import ExecArgCreateCampaign from './exec-args/ExecArgCreateCampaign' import ExecArgCW20AdapterRedeemAndTransfer from './exec-args/ExecArgCW20AdapterRedeemAndTransfer' @@ -19,14 +21,16 @@ import ExecPrivilegedArgOffChainVaultSubscribe from './exec-priv-args/ExecPrivil export type ExecArgs = | ExecArgCW20Send | ExecArgSubmitVaa + | ExecArgCreateRound | ExecArgCW20Transfer | ExecArgSwapMinOutput | ExecArgDepositTokens - | ExecArgCreateSpotGridStrategy - | ExecArgRemoveGridStrategy + | ExecArgCreateCampaign | ExecArgSwapExactOutput | ExecArgInitiateTransfer | ExecArgIncreaseAllowance + | ExecArgRemoveGridStrategy + | ExecArgCreateSpotGridStrategy | ExecArgCW20AdapterRedeemAndTransfer export type ExecPrivilegedArgs = diff --git a/packages/sdk-ts/src/core/modules/wasm/exec-args/ExecArgCreateCampaign.ts b/packages/sdk-ts/src/core/modules/wasm/exec-args/ExecArgCreateCampaign.ts new file mode 100644 index 000000000..9f1135ffd --- /dev/null +++ b/packages/sdk-ts/src/core/modules/wasm/exec-args/ExecArgCreateCampaign.ts @@ -0,0 +1,55 @@ +import { + dataToExecData, + ExecArgBase, + ExecDataRepresentation, +} from '../ExecArgBase' +import { Coin } from '@injectivelabs/ts-types' + +export declare namespace ExecArgCreateCampaign { + export interface Params { + name: string + marketId: string + inRound: boolean + description: string + subaccountIdSuffix: string + rewards: Coin[] + } + + export interface Data { + name: string + market_id: string + in_round: boolean + description: string + subaccount_id_suffix: string + rewards: Coin[] + } +} + +/** + * @category Contract Exec Arguments + */ +export default class ExecArgCreateCampaign extends ExecArgBase< + ExecArgCreateCampaign.Params, + ExecArgCreateCampaign.Data +> { + static fromJSON(params: ExecArgCreateCampaign.Params): ExecArgCreateCampaign { + return new ExecArgCreateCampaign(params) + } + + toData(): ExecArgCreateCampaign.Data { + const { params } = this + + return { + name: params.name, + rewards: params.rewards, + in_round: params.inRound, + market_id: params.marketId, + description: params.description, + subaccount_id_suffix: params.subaccountIdSuffix, + } + } + + toExecData(): ExecDataRepresentation { + return dataToExecData('create_campaign', this.toData()) + } +} diff --git a/packages/sdk-ts/src/core/modules/wasm/exec-args/ExecArgCreateRound.ts b/packages/sdk-ts/src/core/modules/wasm/exec-args/ExecArgCreateRound.ts new file mode 100644 index 000000000..978f8766c --- /dev/null +++ b/packages/sdk-ts/src/core/modules/wasm/exec-args/ExecArgCreateRound.ts @@ -0,0 +1,45 @@ +import { + dataToExecData, + ExecArgBase, + ExecDataRepresentation, +} from '../ExecArgBase' + +export declare namespace ExecArgCreateRound { + export interface Params { + name: string + endDate: number + startDate: number + } + + export interface Data { + name: string + end_date: number + start_date: number + } +} + +/** + * @category Contract Exec Arguments + */ +export default class ExecArgCreateRound extends ExecArgBase< + ExecArgCreateRound.Params, + ExecArgCreateRound.Data +> { + static fromJSON(params: ExecArgCreateRound.Params): ExecArgCreateRound { + return new ExecArgCreateRound(params) + } + + toData(): ExecArgCreateRound.Data { + const { params } = this + + return { + name: params.name, + start_date: params.startDate, + end_date: params.endDate, + } + } + + toExecData(): ExecDataRepresentation { + return dataToExecData('create_round', this.toData()) + } +} diff --git a/packages/sdk-ts/src/core/modules/wasm/index.ts b/packages/sdk-ts/src/core/modules/wasm/index.ts index 9eeacc0a5..de7a8512c 100644 --- a/packages/sdk-ts/src/core/modules/wasm/index.ts +++ b/packages/sdk-ts/src/core/modules/wasm/index.ts @@ -1,8 +1,10 @@ import ExecArgCW20Send from './exec-args/ExecArgCW20Send' import ExecArgSubmitVaa from './exec-args/ExecArgSubmitVaa' +import ExecArgCreateRound from './exec-args/ExecArgCreateRound' import ExecArgCW20Transfer from './exec-args/ExecArgCW20Transfer' import ExecArgSwapMinOutput from './exec-args/ExecArgSwapMinOutput' import ExecArgDepositTokens from './exec-args/ExecArgDepositTokens' +import ExecArgCreateCampaign from './exec-args/ExecArgCreateCampaign' import ExecArgSwapExactOutput from './exec-args/ExecArgSwapExactOutput' import ExecArgInitiateTransfer from './exec-args/ExecArgInitiateTransfer' import ExecArgIncreaseAllowance from './exec-args/ExecArgIncreaseAllowance' @@ -28,9 +30,11 @@ export * from './exec-args' export { ExecArgCW20Send, ExecArgSubmitVaa, + ExecArgCreateRound, ExecArgCW20Transfer, ExecArgSwapMinOutput, ExecArgDepositTokens, + ExecArgCreateCampaign, ExecArgSwapExactOutput, ExecArgInitiateTransfer, ExecArgIncreaseAllowance,