Skip to content

Commit

Permalink
Merge pull request #44 from initia-labs/feat/add-vm
Browse files Browse the repository at this point in the history
Feat/add-vm
  • Loading branch information
joon9823 authored Mar 27, 2024
2 parents 33db472 + c0f7df6 commit 9219bcb
Show file tree
Hide file tree
Showing 25 changed files with 1,649 additions and 8 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@initia/initia.js",
"version": "0.1.37",
"version": "0.1.38",
"description": "The JavaScript SDK for Initia",
"license": "MIT",
"author": "InitiaLabs",
Expand Down Expand Up @@ -86,7 +86,7 @@
"webpack-cli": "^4.10.0"
},
"dependencies": {
"@initia/initia.proto": "^0.1.27",
"@initia/initia.proto": "^0.1.29",
"@initia/opinit.proto": "^0.0.3",
"@ledgerhq/hw-transport": "^6.27.12",
"@ledgerhq/hw-transport-webhid": "^6.27.12",
Expand Down
6 changes: 6 additions & 0 deletions src/client/lcd/LCDClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
BankAPI,
DistributionAPI,
EvidenceAPI,
EvmAPI,
FeeGrantAPI,
GovAPI,
GroupAPI,
Expand All @@ -24,6 +25,7 @@ import {
RewardAPI,
SlashingAPI,
TendermintAPI,
TokenfactoryAPI,
TxAPI,
UpgradeAPI,
WasmAPI,
Expand Down Expand Up @@ -86,6 +88,7 @@ export class LCDClient {
public bank: BankAPI;
public distribution: DistributionAPI;
public evidence: EvidenceAPI;
public evm: EvmAPI;
public feeGrant: FeeGrantAPI;
public gov: GovAPI;
public group: GroupAPI;
Expand All @@ -104,6 +107,7 @@ export class LCDClient {
public reward: RewardAPI;
public slashing: SlashingAPI;
public tendermint: TendermintAPI;
public tokenfactory: TokenfactoryAPI;
public tx: TxAPI;
public upgrade: UpgradeAPI;
public wasm: WasmAPI;
Expand Down Expand Up @@ -135,6 +139,7 @@ export class LCDClient {
this.bank = new BankAPI(this.apiRequester);
this.distribution = new DistributionAPI(this.apiRequester);
this.evidence = new EvidenceAPI(this.apiRequester);
this.evm = new EvmAPI(this.apiRequester);
this.feeGrant = new FeeGrantAPI(this.apiRequester);
this.gov = new GovAPI(this.apiRequester);
this.group = new GroupAPI(this.apiRequester);
Expand All @@ -153,6 +158,7 @@ export class LCDClient {
this.reward = new RewardAPI(this.apiRequester);
this.slashing = new SlashingAPI(this.apiRequester);
this.tendermint = new TendermintAPI(this.apiRequester);
this.tokenfactory = new TokenfactoryAPI(this.apiRequester);
this.tx = new TxAPI(this);
this.upgrade = new UpgradeAPI(this.apiRequester);
this.wasm = new WasmAPI(this.apiRequester);
Expand Down
79 changes: 79 additions & 0 deletions src/client/lcd/api/EvmAPI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { AccAddress, EvmParams } from '../../../core';
import { APIParams } from '../APIRequester';
import { BaseAPI } from './BaseAPI';

export interface CallResponse {
response: string;
used_gas: string;
logs: {
address: AccAddress;
topics: string[];
data: string;
}[];
trace_output: string;
}

export class EvmAPI extends BaseAPI {
public async code(
contractAddr: AccAddress,
params: APIParams = {}
): Promise<string> {
return this.c
.get<{ code: string }>(`/minievm/evm/v1/codes/${contractAddr}`, params)
.then(d => d.code);
}

public async state(
contractAddr: AccAddress,
key: string,
params: APIParams = {}
): Promise<string> {
return this.c
.get<{ value: string }>(
`/minievm/evm/v1/states/${contractAddr}/${key}`,
params
)
.then(d => d.value);
}

public async contractAddrByDenom(
denom: string,
params: APIParams = {}
): Promise<AccAddress> {
return this.c
.get<{ address: AccAddress }>(`/minievm/evm/v1/contracts/by_denom`, {
...params,
denom,
})
.then(d => d.address);
}

public async denom(
contractAddr: AccAddress,
params: APIParams = {}
): Promise<string> {
return this.c
.get<{ denom: string }>(`/minievm/evm/v1/denoms/${contractAddr}`, params)
.then(d => d.denom);
}

public async call(
sender: AccAddress,
contractAddr: AccAddress,
input: string,
withTrace: boolean
): Promise<CallResponse> {
return this.c.post<CallResponse>(`/minievm/evm/v1/call`, {
sender,
contract_addr: contractAddr,
input,
with_trace: withTrace,
});
}

public async parameters(params: APIParams = {}): Promise<EvmParams> {
return this.c
.get<{ params: EvmParams.Data }>(`/minievm/evm/v1/params`, params)
.then(({ params: d }) => EvmParams.fromData(d));
}
}
54 changes: 54 additions & 0 deletions src/client/lcd/api/TokenfactoryAPI.ts
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));
}
}
2 changes: 2 additions & 0 deletions src/client/lcd/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export * from './AuthzAPI';
export * from './BankAPI';
export * from './DistributionAPI';
export * from './EvidenceAPI';
export * from './EvmAPI';
export * from './FeeGrantAPI';
export * from './GovAPI';
export * from './GroupAPI';
Expand All @@ -22,6 +23,7 @@ export * from './OracleAPI';
export * from './RewardAPI';
export * from './SlashingAPI';
export * from './TendermintAPI';
export * from './TokenfactoryAPI';
export * from './TxAPI';
export * from './UpgradeAPI';
export * from './WasmAPI';
Loading

0 comments on commit 9219bcb

Please sign in to comment.