-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: incentives wasm query and execute
- Loading branch information
1 parent
49a841c
commit 7ebc541
Showing
13 changed files
with
245 additions
and
2 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,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 | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './types' | ||
export * from './queries' | ||
export * from './transformer' |
26 changes: 26 additions & 0 deletions
26
packages/sdk-ts/src/client/wasm/incentives/queries/QueryAllRounds.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,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) | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
packages/sdk-ts/src/client/wasm/incentives/queries/QueryGetCampaigns.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,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) | ||
} | ||
} |
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,2 @@ | ||
export { QueryAllRounds } from './QueryAllRounds' | ||
export { QueryGetCampaigns } from './QueryGetCampaigns' |
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,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, | ||
})) | ||
} | ||
} |
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,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 | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './swap' | ||
export * from './types' | ||
export * from './incentives' | ||
export * from './nameservice' |
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
55 changes: 55 additions & 0 deletions
55
packages/sdk-ts/src/core/modules/wasm/exec-args/ExecArgCreateCampaign.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,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()) | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
packages/sdk-ts/src/core/modules/wasm/exec-args/ExecArgCreateRound.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,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()) | ||
} | ||
} |
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