Skip to content

Commit

Permalink
Apply updates from core
Browse files Browse the repository at this point in the history
  • Loading branch information
joon9823 committed Jan 9, 2025
1 parent 53d0260 commit d59c008
Show file tree
Hide file tree
Showing 10 changed files with 253 additions and 39 deletions.
13 changes: 7 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.2.24",
"version": "0.2.25",
"description": "The JavaScript SDK for Initia",
"license": "Apache-2.0",
"author": "Initia Foundation",
Expand Down Expand Up @@ -57,7 +57,7 @@
},
"dependencies": {
"@bitcoinerlab/secp256k1": "^1.1.1",
"@initia/initia.proto": "^0.2.4",
"@initia/initia.proto": "^0.2.5",
"@initia/opinit.proto": "^0.0.11",
"@ledgerhq/hw-transport": "^6.31.4",
"@ledgerhq/hw-transport-webhid": "^6.29.4",
Expand Down
11 changes: 11 additions & 0 deletions src/client/rest/api/EvmAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ export class EvmAPI extends BaseAPI {
.then((d) => d.address)
}

/**
* Query the ERC20Wrapper contract address.
*/
public async erc20Wrapper(params: APIParams = {}): Promise<string> {
return this.c
.get<{
address: string
}>(`/minievm/evm/v1/contracts/erc20_wrapper`, params)
.then((d) => d.address)
}

/**
* Query the contract address by denom.
* @param denom denom to look up
Expand Down
22 changes: 22 additions & 0 deletions src/client/rest/api/TxAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
num,
TxLog,
Event,
Denom,
Coin,
} from '../../../core'
import { hashToHex } from '../../../util'
import { RESTClient } from '../RESTClient'
Expand Down Expand Up @@ -609,4 +611,24 @@ export class TxAPI extends BaseAPI {

return targetEvents
}

/**
* Query the gas prices for the network.
*/
public async gasPrices(params: APIParams = {}): Promise<Coins> {
return this.c
.get<{ gas_prices: Coins.Data }>(`/initia/tx/v1/gas_prices`, params)
.then((d) => Coins.fromData(d.gas_prices))
}

/**
* Query the gas price of a denom for the network.
*/
public async gasPrice(denom: Denom, params: APIParams = {}): Promise<Coin> {
return this.c
.get<{
gas_price: Coin.Data
}>(`/initia/tx/v1/gas_prices/${denom}`, params)
.then((d) => Coin.fromData(d.gas_price))
}
}
69 changes: 69 additions & 0 deletions src/core/evm/AccessTuple.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { JSONSerializable } from '../../util/json'
import { AccAddress } from '../bech32'
import { AccessTuple as AccessTuple_pb } from '@initia/initia.proto/minievm/evm/v1/types'

/**
* AccessTuple is the tuple for address and storage keys.
*/
export class AccessTuple extends JSONSerializable<
AccessTuple.Amino,
AccessTuple.Data,
AccessTuple.Proto
> {
/**
* @param address address of the contract that will be accessed during the transaction execution
* @param storage_keys list of storage keys that the transaction will interact with within the specified contract
*/
constructor(
public address: AccAddress,
public storage_keys: string[]
) {
super()
}

public static fromAmino(data: AccessTuple.Amino): AccessTuple {
const { address, storage_keys } = data
return new AccessTuple(address, storage_keys)
}

public toAmino(): AccessTuple.Amino {
const { address, storage_keys } = this
return { address, storage_keys }
}

public static fromData(data: AccessTuple.Data): AccessTuple {
const { address, storage_keys } = data
return new AccessTuple(address, storage_keys)
}

public toData(): AccessTuple.Data {
const { address, storage_keys } = this
return { address, storage_keys }
}

public static fromProto(data: AccessTuple.Proto): AccessTuple {
return new AccessTuple(data.address, data.storageKeys)
}

public toProto(): AccessTuple.Proto {
const { address, storage_keys } = this
return AccessTuple_pb.fromPartial({
address,
storageKeys: storage_keys,
})
}
}

export namespace AccessTuple {
export interface Amino {
address: AccAddress
storage_keys: string[]
}

export interface Data {
address: AccAddress
storage_keys: string[]
}

export type Proto = AccessTuple_pb
}
43 changes: 39 additions & 4 deletions src/core/evm/EvmParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ export class EvmParams extends JSONSerializable<
* @param allow_custom_erc20 whether the chain allows custom erc20 tokens to be registered on cosmos bank interface
* @param allowed_custom_erc20s
* @param fee_denom the fee denom for the evm transactions
* @param gas_refund_ratio the gas refund ratio for the evm transactions; 0 to disable
* @param num_retain_block_hashes the number of block hashes to retain for the evm opcode `BLOCKHASH`; minimum 256 and 0 to disable
*/
constructor(
public extra_eips: number[],
public allowed_publishers: string[],
public allow_custom_erc20: boolean,
public allowed_custom_erc20s: string[],
public fee_denom: string
public fee_denom: string,
public gas_refund_ratio: string,
public num_retain_block_hashes: number
) {
super()
}
Expand All @@ -33,13 +37,18 @@ export class EvmParams extends JSONSerializable<
allow_custom_erc20,
allowed_custom_erc20s,
fee_denom,
gas_refund_ratio,
num_retain_block_hashes,
} = data

return new EvmParams(
extra_eips.map(parseInt),
allowed_publishers,
allow_custom_erc20,
allowed_custom_erc20s,
fee_denom
fee_denom,
gas_refund_ratio,
parseInt(num_retain_block_hashes)
)
}

Expand All @@ -50,13 +59,18 @@ export class EvmParams extends JSONSerializable<
allow_custom_erc20,
allowed_custom_erc20s,
fee_denom,
gas_refund_ratio,
num_retain_block_hashes,
} = this

return {
extra_eips: extra_eips.map((eip) => eip.toFixed()),
allowed_publishers,
allow_custom_erc20,
allowed_custom_erc20s,
fee_denom,
gas_refund_ratio,
num_retain_block_hashes: num_retain_block_hashes.toFixed(),
}
}

Expand All @@ -67,13 +81,18 @@ export class EvmParams extends JSONSerializable<
allow_custom_erc20,
allowed_custom_erc20s,
fee_denom,
gas_refund_ratio,
num_retain_block_hashes,
} = data

return new EvmParams(
extra_eips.map(parseInt),
allowed_publishers,
allow_custom_erc20,
allowed_custom_erc20s,
fee_denom
fee_denom,
gas_refund_ratio,
parseInt(num_retain_block_hashes)
)
}

Expand All @@ -84,13 +103,18 @@ export class EvmParams extends JSONSerializable<
allow_custom_erc20,
allowed_custom_erc20s,
fee_denom,
gas_refund_ratio,
num_retain_block_hashes,
} = this

return {
extra_eips: extra_eips.map((eip) => eip.toFixed()),
allowed_publishers,
allow_custom_erc20,
allowed_custom_erc20s,
fee_denom,
gas_refund_ratio,
num_retain_block_hashes: num_retain_block_hashes.toFixed(),
}
}

Expand All @@ -100,7 +124,9 @@ export class EvmParams extends JSONSerializable<
proto.allowedPublishers,
proto.allowCustomErc20,
proto.allowedCustomErc20s,
proto.feeDenom
proto.feeDenom,
proto.gasRefundRatio,
Number(proto.numRetainBlockHashes)
)
}

Expand All @@ -111,13 +137,18 @@ export class EvmParams extends JSONSerializable<
allow_custom_erc20,
allowed_custom_erc20s,
fee_denom,
gas_refund_ratio,
num_retain_block_hashes,
} = this

return Params_pb.fromPartial({
extraEips: extra_eips.map((eip) => BigInt(eip)),
allowedPublishers: allowed_publishers,
allowCustomErc20: allow_custom_erc20,
allowedCustomErc20s: allowed_custom_erc20s,
feeDenom: fee_denom,
gasRefundRatio: gas_refund_ratio,
numRetainBlockHashes: BigInt(num_retain_block_hashes),
})
}
}
Expand All @@ -129,6 +160,8 @@ export namespace EvmParams {
allow_custom_erc20: boolean
allowed_custom_erc20s: string[]
fee_denom: string
gas_refund_ratio: string
num_retain_block_hashes: string
}

export interface Data {
Expand All @@ -137,6 +170,8 @@ export namespace EvmParams {
allow_custom_erc20: boolean
allowed_custom_erc20s: string[]
fee_denom: string
gas_refund_ratio: string
num_retain_block_hashes: string
}

export type Proto = Params_pb
Expand Down
1 change: 1 addition & 0 deletions src/core/evm/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './msgs'
export * from './EvmParams'
export * from './AccessTuple'
Loading

0 comments on commit d59c008

Please sign in to comment.