Skip to content

Commit

Permalink
chore: unused fn
Browse files Browse the repository at this point in the history
  • Loading branch information
bangjelkoski committed Feb 12, 2025
1 parent a66fa2f commit 1a45dfb
Showing 1 changed file with 0 additions and 213 deletions.
213 changes: 0 additions & 213 deletions packages/sdk-ts/src/core/tx/eip712/maps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,219 +256,6 @@ export const stringTypeToReflectionStringType = (property?: string) => {
}
}

/**
* ONLY USED FOR EIP712_V1
*
* We need to represent some of the values in a proper format acceptable by the chain.
*
* 1. We need to represent some values from a number to string
* This needs to be done for every number value except for maps (ex: vote option)
*
* 2. We need to convert every `sdk.Dec` value from a raw value to shifted by 1e18 value
* ex: 0.01 -> 0.01000000000000000000, 1 -> 1.000000000000000000
*
* 3. For some fields, like 'amount' in the 'MsgIncreasePositionMargin' we have
* to also specify the Message type to apply the sdk.Dec conversion because there
* are other amount fields in other messages as well and we don't want to affect them
*
* @deprecated - it's done within the Msg itself for better clarity
*/
export const mapValuesToProperValueType = <T extends Record<string, unknown>>(
object: T,
messageTypeUrl?: string,
): T => {
const numberToStringKeys = [
'proposal_id',
'remaining',
'round',
'oracle_scale_factor',
'timeout_timestamp',
'revision_height',
'revision_number',
'expiry',
]
const stringToNumberKeysTypeMaps = {
'cosmos-sdk/MsgSubmitProposal': ['oracle_scale_factor'],
}
const sdkDecKeys = ['price', 'quantity', 'margin', 'trigger_price']
const sdkDecKeyWithTypeMaps = {
'exchange/MsgIncreasePositionMargin': ['amount'],
}
const nullableStringsTypeMaps = {
'wasmx/MsgExecuteContractCompat': ['funds'],
}
const amountToCosmosSdkDecAmountTypeMaps = {
'cosmos-sdk/MsgSubmitProposal': [
'initial_margin_ratio',
'maintenance_margin_ratio',
'min_notional',
'min_price_tick_size',
'min_quantity_tick_size',
'maker_fee_rate',
'taker_fee_rate',
'relayer_fee_share_rate',
],
'exchange/MsgInstantSpotMarketLaunch': [
'min_price_tick_size',
'min_quantity_tick_size',
'min_notional',
],
'cosmos-sdk/MsgEditValidator': ['commission_rate'],
}

const nullableStrings = ['uri', 'uri_hash']

return Object.keys(object).reduce((result, key) => {
const value = object[key]

if (!value) {
// Message Type Specific checks
if (messageTypeUrl) {
const typeInMap = Object.keys(nullableStringsTypeMaps).find(
(key) => key === messageTypeUrl,
)

if (typeInMap) {
const nullableStringKeys =
nullableStringsTypeMaps[
typeInMap as keyof typeof nullableStringsTypeMaps
]

if (nullableStringKeys.includes(key)) {
return {
...result,
[key]: value,
}
}
}
}

if (nullableStrings.includes(key)) {
return {
...result,
[key]: value,
}
}

return result
}

if (typeof value === 'object') {
if (value instanceof Date) {
return {
...result,
[key]: value.toJSON().split('.')[0] + 'Z',
}
}

if (Array.isArray(value)) {
return {
...result,
[key]: value.every((i) => typeof i === 'string')
? value
: value.map((item) =>
mapValuesToProperValueType(
item as Record<string, unknown>,
messageTypeUrl,
),
),
}
}

return {
...result,
[key]: mapValuesToProperValueType(
value as Record<string, unknown>,
messageTypeUrl,
),
}
}

if (isNumber(value as string | number)) {
// Message Type Specific checks
if (messageTypeUrl) {
let typeInMap = Object.keys(amountToCosmosSdkDecAmountTypeMaps).find(
(key) => key === messageTypeUrl,
)

if (typeInMap) {
const cosmosSdkDecKeys =
amountToCosmosSdkDecAmountTypeMaps[
typeInMap as keyof typeof amountToCosmosSdkDecAmountTypeMaps
]

if (cosmosSdkDecKeys.includes(key)) {
return {
...result,
[key]: amountToCosmosSdkDecAmount(value.toString()).toFixed(),
}
}
}

typeInMap = Object.keys(stringToNumberKeysTypeMaps).find(
(key) => key === messageTypeUrl,
)

if (typeInMap) {
const stringToNumberKeys =
stringToNumberKeysTypeMaps[
typeInMap as keyof typeof stringToNumberKeysTypeMaps
]

if (stringToNumberKeys.includes(key)) {
return {
...result,
[key]: Number(value),
}
}
}
}

if (numberToStringKeys.includes(key)) {
return {
...result,
[key]: value.toString(),
}
}
}

if (typeof value === 'string') {
if (sdkDecKeys.includes(key)) {
return {
...result,
[key]: numberToCosmosSdkDecString(value),
}
}

// Message Type Specific checks
if (messageTypeUrl) {
const typeInMap = Object.keys(sdkDecKeyWithTypeMaps).find(
(key) => key === messageTypeUrl,
)

if (typeInMap) {
const sdkDecKeys =
sdkDecKeyWithTypeMaps[
typeInMap as keyof typeof sdkDecKeyWithTypeMaps
]

if (sdkDecKeys.includes(key)) {
return {
...result,
[key]: numberToCosmosSdkDecString(value),
}
}
}
}
}

return {
...result,
[key]: value,
}
}, {} as T)
}

export const getObjectEip712PropertyType = ({
property,
parentProperty,
Expand Down

0 comments on commit 1a45dfb

Please sign in to comment.