From 1c2694c40a748e274c59b2cadf6219de153097d8 Mon Sep 17 00:00:00 2001 From: MarkacRobi Date: Mon, 11 Nov 2024 18:41:02 +0100 Subject: [PATCH] feat: supported tokens --- src/constants.ts | 25 ++++++++++++++++++++++--- src/services/IntentService.ts | 10 +++++----- src/services/index.ts | 1 + src/types.ts | 24 +++++++++++++++--------- 4 files changed, 43 insertions(+), 17 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index f255dd3..e79bff5 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -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 = { +export const chainConfig: Record = { ["arb"]: { chain: { name: "arb", @@ -11,6 +11,18 @@ export const chainConfig: Record = { nid: "0xaa37dc.arbitrum", intentContract: "0x1d70D0B9c6b0508E7Bd2B379735CFF035749f187", nativeToken: "0x0000000000000000000000000000000000000000", + supportedTokens: [ + { + symbol: "ETH", + decimals: 18, + address: "0x0000000000000000000000000000000000000000", + }, + { + symbol: "WETH", + decimals: 18, + address: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1", + }, + ], } satisfies EvmChainConfig, ["sui"]: { chain: { @@ -21,7 +33,14 @@ export const chainConfig: Record = { 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[] diff --git a/src/services/IntentService.ts b/src/services/IntentService.ts index fedc364..ca8db22 100644 --- a/src/services/IntentService.ts +++ b/src/services/IntentService.ts @@ -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" @@ -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 @@ -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) { diff --git a/src/services/index.ts b/src/services/index.ts index 60310d4..2cdb88b 100644 --- a/src/services/index.ts +++ b/src/services/index.ts @@ -1,2 +1,3 @@ export * from "./IntentService.js" export * from "./EvmIntentService.js" +export * from "./SuiIntentService.js" diff --git a/src/types.ts b/src/types.ts index 918a123..0d8dc9d 100644 --- a/src/types.ts +++ b/src/types.ts @@ -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 = { - name: Chain + name: ChainName type: T } -export type EvmChainConfig = { - chain: ChainInfo<"evm"> +export type Token = { + symbol: string + decimals: number + address: string +} + +export type BaseChainConfig = { + chain: ChainInfo 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