-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tokenfactory module from miniwasm
- Loading branch information
Showing
18 changed files
with
1,146 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,54 @@ | ||
import { TokenfactoryParams } from '../../../core'; | ||
import { APIParams } from '../APIRequester'; | ||
import { BaseAPI } from './BaseAPI'; | ||
|
||
export interface AuthorityMetadata { | ||
admin: string; | ||
} | ||
|
||
export class TokenfactoryAPI extends BaseAPI { | ||
public async authorityMetadata( | ||
denom: string, | ||
params: APIParams = {} | ||
): Promise<AuthorityMetadata> { | ||
return this.c | ||
.get<{ authority_metadata: AuthorityMetadata }>( | ||
`/miniwasm/tokenfactory/v1/denoms/${denom}/authority_metadata`, | ||
params | ||
) | ||
.then(d => d.authority_metadata); | ||
} | ||
|
||
public async beforeSendHookAddr( | ||
denom: string, | ||
params: APIParams = {} | ||
): Promise<string> { | ||
return this.c | ||
.get<{ cosmwasm_address: string }>( | ||
`/miniwasm/tokenfactory/v1/denoms/${denom}/before_send_hook`, | ||
params | ||
) | ||
.then(d => d.cosmwasm_address); | ||
} | ||
|
||
public async denomsFromCreator( | ||
creator: string, | ||
params: APIParams = {} | ||
): Promise<string[]> { | ||
return this.c | ||
.get<{ denoms: string[] }>( | ||
`/miniwasm/tokenfactory/v1/denoms_from_creator/${creator}`, | ||
params | ||
) | ||
.then(d => d.denoms); | ||
} | ||
|
||
public async parameters(params: APIParams = {}): Promise<TokenfactoryParams> { | ||
return this.c | ||
.get<{ params: TokenfactoryParams.Data }>( | ||
`/miniwasm/tokenfactory/v1/params`, | ||
params | ||
) | ||
.then(({ params: d }) => TokenfactoryParams.fromData(d)); | ||
} | ||
} |
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
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,84 @@ | ||
import { JSONSerializable } from '../../util/json'; | ||
import { Coins } from '../Coins'; | ||
import { Params as Params_pb } from '@initia/initia.proto/miniwasm/tokenfactory/v1/params'; | ||
import Long from 'long'; | ||
|
||
export class TokenfactoryParams extends JSONSerializable< | ||
TokenfactoryParams.Amino, | ||
TokenfactoryParams.Data, | ||
TokenfactoryParams.Proto | ||
> { | ||
public denom_creation_fee: Coins; | ||
/** | ||
* @param denom_creation_fee the fee to be charged on the creation of a new denom | ||
* @param denom_creation_gas_consume the gas cost for creating a new denom | ||
*/ | ||
constructor( | ||
denom_creation_fee: Coins.Input, | ||
public denom_creation_gas_consume: number | ||
) { | ||
super(); | ||
this.denom_creation_fee = new Coins(denom_creation_fee); | ||
} | ||
|
||
public static fromAmino(data: TokenfactoryParams.Amino): TokenfactoryParams { | ||
const { denom_creation_fee, denom_creation_gas_consume } = data; | ||
return new TokenfactoryParams( | ||
Coins.fromAmino(denom_creation_fee), | ||
Number.parseInt(denom_creation_gas_consume) | ||
); | ||
} | ||
|
||
public toAmino(): TokenfactoryParams.Amino { | ||
const { denom_creation_fee, denom_creation_gas_consume } = this; | ||
return { | ||
denom_creation_fee: denom_creation_fee.toAmino(), | ||
denom_creation_gas_consume: denom_creation_gas_consume.toString(), | ||
}; | ||
} | ||
|
||
public static fromData(data: TokenfactoryParams.Data): TokenfactoryParams { | ||
const { denom_creation_fee, denom_creation_gas_consume } = data; | ||
return new TokenfactoryParams( | ||
Coins.fromData(denom_creation_fee), | ||
Number.parseInt(denom_creation_gas_consume) | ||
); | ||
} | ||
|
||
public toData(): TokenfactoryParams.Data { | ||
const { denom_creation_fee, denom_creation_gas_consume } = this; | ||
return { | ||
denom_creation_fee: denom_creation_fee.toData(), | ||
denom_creation_gas_consume: denom_creation_gas_consume.toString(), | ||
}; | ||
} | ||
|
||
public static fromProto(data: TokenfactoryParams.Proto): TokenfactoryParams { | ||
return new TokenfactoryParams( | ||
Coins.fromProto(data.denomCreationFee), | ||
data.denomCreationGasConsume.toNumber() | ||
); | ||
} | ||
|
||
public toProto(): TokenfactoryParams.Proto { | ||
const { denom_creation_fee, denom_creation_gas_consume } = this; | ||
return Params_pb.fromPartial({ | ||
denomCreationFee: denom_creation_fee.toProto(), | ||
denomCreationGasConsume: Long.fromNumber(denom_creation_gas_consume), | ||
}); | ||
} | ||
} | ||
|
||
export namespace TokenfactoryParams { | ||
export interface Amino { | ||
denom_creation_fee: Coins.Amino; | ||
denom_creation_gas_consume: string; | ||
} | ||
|
||
export interface Data { | ||
denom_creation_fee: Coins.Data; | ||
denom_creation_gas_consume: string; | ||
} | ||
|
||
export type Proto = Params_pb; | ||
} |
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 * from './msgs'; | ||
export * from './TokenfactoryParams'; |
Oops, something went wrong.