Skip to content

Commit

Permalink
chore: incentives wasm query and execute
Browse files Browse the repository at this point in the history
  • Loading branch information
shane-moore committed Dec 11, 2023
1 parent 49a841c commit 7ebc541
Show file tree
Hide file tree
Showing 13 changed files with 245 additions and 2 deletions.
22 changes: 22 additions & 0 deletions packages/sdk-ts/src/client/indexer/types/incentives.ts
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions packages/sdk-ts/src/client/indexer/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 3 additions & 0 deletions packages/sdk-ts/src/client/wasm/incentives/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './types'
export * from './queries'
export * from './transformer'
Original file line number Diff line number Diff line change
@@ -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<QueryAllRoundsArg.Params> {
toPayload() {
const payload = {
all_rounds: {
...(this.params.limit ? { limit: this.params.limit } : {}),
...(this.params.startAfter
? {
start_after: this.params.startAfter,
}
: {}),
},
}

return toBase64(payload)
}
}
Original file line number Diff line number Diff line change
@@ -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<QueryGetCampaignsArg.Params> {
toPayload() {
const payload = {
get_campaigns: {
campaigns: this.params.campaigns,
},
}

return toBase64(payload)
}
}
2 changes: 2 additions & 0 deletions packages/sdk-ts/src/client/wasm/incentives/queries/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { QueryAllRounds } from './QueryAllRounds'
export { QueryGetCampaigns } from './QueryGetCampaigns'
38 changes: 38 additions & 0 deletions packages/sdk-ts/src/client/wasm/incentives/transformer.ts
Original file line number Diff line number Diff line change
@@ -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,
}))
}
}
22 changes: 22 additions & 0 deletions packages/sdk-ts/src/client/wasm/incentives/types.ts
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions packages/sdk-ts/src/client/wasm/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './swap'
export * from './types'
export * from './incentives'
export * from './nameservice'
8 changes: 6 additions & 2 deletions packages/sdk-ts/src/core/modules/wasm/exec-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ExecArgCreateCampaign.Data> {
return dataToExecData('create_campaign', this.toData())
}
}
Original file line number Diff line number Diff line change
@@ -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<ExecArgCreateRound.Data> {
return dataToExecData('create_round', this.toData())
}
}
4 changes: 4 additions & 0 deletions packages/sdk-ts/src/core/modules/wasm/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -28,9 +30,11 @@ export * from './exec-args'
export {
ExecArgCW20Send,
ExecArgSubmitVaa,
ExecArgCreateRound,
ExecArgCW20Transfer,
ExecArgSwapMinOutput,
ExecArgDepositTokens,
ExecArgCreateCampaign,
ExecArgSwapExactOutput,
ExecArgInitiateTransfer,
ExecArgIncreaseAllowance,
Expand Down

0 comments on commit 7ebc541

Please sign in to comment.