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

chore: incentives wasm query and execute #271

Merged
merged 2 commits into from
Dec 15, 2023
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
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'
10 changes: 8 additions & 2 deletions packages/sdk-ts/src/core/modules/wasm/exec-args.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
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 ExecArgFundCampaign from './exec-args/ExecArgFundCampaign'
import ExecArgDepositTokens from './exec-args/ExecArgDepositTokens'
import ExecArgSwapMinOutput from './exec-args/ExecArgSwapMinOutput'
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 @@ -19,14 +22,17 @@ import ExecPrivilegedArgOffChainVaultSubscribe from './exec-priv-args/ExecPrivil
export type ExecArgs =
| ExecArgCW20Send
| ExecArgSubmitVaa
| ExecArgCreateRound
| ExecArgCW20Transfer
| ExecArgFundCampaign
| 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
rewards: Coin[]
inRound: number
marketId: string
description: string
subaccountIdSuffix: string
}

export interface Data {
name: string
rewards: Coin[]
in_round: number
market_id: string
description: string
subaccount_id_suffix: string
}
}

/**
* @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())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {
dataToExecData,
ExecArgBase,
ExecDataRepresentation,
} from '../ExecArgBase'

export declare namespace ExecArgFundCampaign {
export interface Params {
campaignId: number
}

export interface Data {
campaign_id: number
}
}

/**
* @category Contract Exec Arguments
*/
export default class ExecArgFundCampaign extends ExecArgBase<
ExecArgFundCampaign.Params,
ExecArgFundCampaign.Data
> {
static fromJSON(params: ExecArgFundCampaign.Params): ExecArgFundCampaign {
return new ExecArgFundCampaign(params)
}

toData(): ExecArgFundCampaign.Data {
const { params } = this

return {
campaign_id: params.campaignId,
}
}

toExecData(): ExecDataRepresentation<ExecArgFundCampaign.Data> {
return dataToExecData('fund_campaign', this.toData())
}
}
6 changes: 6 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,11 @@
import ExecArgCW20Send from './exec-args/ExecArgCW20Send'
import ExecArgSubmitVaa from './exec-args/ExecArgSubmitVaa'
import ExecArgCreateRound from './exec-args/ExecArgCreateRound'
import ExecArgFundCampaign from './exec-args/ExecArgFundCampaign'
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 +31,12 @@ export * from './exec-args'
export {
ExecArgCW20Send,
ExecArgSubmitVaa,
ExecArgCreateRound,
ExecArgCW20Transfer,
ExecArgFundCampaign,
ExecArgSwapMinOutput,
ExecArgDepositTokens,
ExecArgCreateCampaign,
ExecArgSwapExactOutput,
ExecArgInitiateTransfer,
ExecArgIncreaseAllowance,
Expand Down
18 changes: 18 additions & 0 deletions packages/sdk-ts/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ export const CW20_SWAP_CONTRACT_BY_NETWORK = {
[Network.Local]: 'inj177yh38g3ctu7cemxpa3c2kvwh2yslfxfmfa66h',
}

export const INCENTIVES_CONTRACT_BY_NETWORK = {
[Network.Mainnet]: '',
[Network.MainnetLB]: '',
[Network.MainnetK8s]: '',
[Network.MainnetSentry]: '',
[Network.Public]: '',
[Network.Staging]: '',
[Network.Internal]: '',
[Network.Testnet]: 'inj1gc7hu92ct7gd4nc6mv39m3anf0cnzml220epze',
[Network.TestnetK8s]: 'inj1gc7hu92ct7gd4nc6mv39m3anf0cnzml220epze',
[Network.TestnetSentry]: 'inj1gc7hu92ct7gd4nc6mv39m3anf0cnzml220epze',
[Network.TestnetOld]: 'inj1gc7hu92ct7gd4nc6mv39m3anf0cnzml220epze',
[Network.Devnet]: '',
[Network.Devnet1]: '',
[Network.Devnet2]: '',
[Network.Local]: '',
}

export const INJ_NAME_REGISTRY_CONTRACT_BY_NETWORK = {
[Network.Mainnet]: 'inj1hm8vs8sr2h9nk0x66vctfs528wrp6k3gtgg275',
[Network.MainnetLB]: 'inj1hm8vs8sr2h9nk0x66vctfs528wrp6k3gtgg275',
Expand Down