Skip to content

Commit

Permalink
feat: supported tokens (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
R0bi7 authored Nov 11, 2024
1 parent e572a44 commit 2815c43
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 17 deletions.
25 changes: 22 additions & 3 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { ChainConfig, Chain, EvmChainConfig, SuiChainConfig } from "./types.js"
import type { ChainConfig, ChainName, EvmChainConfig, SuiChainConfig } from "./types.js"

export const SOLVER_API_ENDPOINT = "localhost:3000" // TODO

export const chainConfig: Record<Chain, ChainConfig> = {
export const chainConfig: Record<ChainName, ChainConfig> = {
["arb"]: {
chain: {
name: "arb",
Expand All @@ -11,6 +11,18 @@ export const chainConfig: Record<Chain, ChainConfig> = {
nid: "0xaa37dc.arbitrum",
intentContract: "0x1d70D0B9c6b0508E7Bd2B379735CFF035749f187",
nativeToken: "0x0000000000000000000000000000000000000000",
supportedTokens: [
{
symbol: "ETH",
decimals: 18,
address: "0x0000000000000000000000000000000000000000",
},
{
symbol: "WETH",
decimals: 18,
address: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
},
],
} satisfies EvmChainConfig,
["sui"]: {
chain: {
Expand All @@ -21,7 +33,14 @@ export const chainConfig: Record<Chain, ChainConfig> = {
packageId: "0x2604cc95ad0b2a3e4b2e9e5df8d7a59b8a20ccb4fda58cc6fd7d06777e283a6f",
storageId: "0x490f1dbd44fd9bb1bd8fe8438bd8cb062acad8d81915fefc042f5484de7a7edc",
nativeToken: "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",
supportedTokens: [
{
symbol: "SUI",
decimals: 9,
address: "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",
},
],
} satisfies SuiChainConfig,
} as const

export const supportedChains: Chain[] = Object.keys(chainConfig) as Chain[]
export const supportedChains: ChainName[] = Object.keys(chainConfig) as ChainName[]
10 changes: 5 additions & 5 deletions src/services/IntentService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Address, type Hash } from "viem"
import type { Chain, ChainConfig, ChainType, Result } from "../types.js"
import type { ChainName, ChainConfig, ChainType, Result } from "../types.js"
import { chainConfig, supportedChains } from "../constants.js"
import { isEvmChainConfig, isSuiChainConfig } from "../guards.js"
import { type ChainProvider, type NonEmptyChainProviders, EvmProvider, SuiProvider } from "../entities/index.js"
Expand Down Expand Up @@ -32,8 +32,8 @@ export type IntentExecutionResponse = {
export type CreateIntentOrderPayload = {
fromAddress: string
toAddress: string
fromChain: Chain
toChain: Chain
fromChain: ChainName
toChain: ChainName
token: string
amount: bigint
toToken: string
Expand Down Expand Up @@ -173,11 +173,11 @@ export class IntentService {
throw new Error(`Unsupported chain type: ${chainType}`)
}

public static getSupportedChains(): Chain[] {
public static getSupportedChains(): ChainName[] {
return supportedChains
}

public static getChainConfig(chain: Chain): ChainConfig {
public static getChainConfig(chain: ChainName): ChainConfig {
const data = chainConfig[chain]

if (!chainConfig) {
Expand Down
1 change: 1 addition & 0 deletions src/services/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./IntentService.js"
export * from "./EvmIntentService.js"
export * from "./SuiIntentService.js"
24 changes: 15 additions & 9 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
import type { Address } from "viem"

export type ChainType = "evm" | "sui"
export type Chain = "sui" | "arb"
export type ChainName = "sui" | "arb"
export type ChainInfo<T extends ChainType> = {
name: Chain
name: ChainName
type: T
}

export type EvmChainConfig = {
chain: ChainInfo<"evm">
export type Token = {
symbol: string
decimals: number
address: string
}

export type BaseChainConfig<T extends ChainType> = {
chain: ChainInfo<T>
nid: string
} & {
supportedTokens: Token[]
}

export type EvmChainConfig = BaseChainConfig<"evm"> & {
intentContract: Address
nativeToken: Address
}

export type SuiChainConfig = {
chain: ChainInfo<"sui">
nid: string
} & {
export type SuiChainConfig = BaseChainConfig<"sui"> & {
packageId: string
storageId: string
nativeToken: string
Expand Down

0 comments on commit 2815c43

Please sign in to comment.