-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(sdk): typing & error handling (#3)
- Loading branch information
Showing
27 changed files
with
1,746 additions
and
1,642 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,9 @@ | ||
export function toHexChainId(chainId: number): string { | ||
return `0x${chainId.toString(16)}` | ||
} | ||
|
||
export enum SupportedChainIds { | ||
Ethereum = 1, | ||
Goerli = 5, | ||
RoninMainnet = 2020, | ||
RoninTestnet = 2021, | ||
} | ||
|
||
type IRpcConfig = Record<number, string> | ||
|
||
const DEFAULT_RPC_CONFIG: IRpcConfig = { | ||
[SupportedChainIds.RoninMainnet]: "https://api.roninchain.com/rpc", | ||
[SupportedChainIds.RoninTestnet]: "https://saigon-testnet.roninchain.com/rpc", | ||
} | ||
|
||
export interface IChainInfo { | ||
chainId: number | ||
blockExplorerUrl?: string | ||
chainName: string | ||
iconUrl?: string | ||
nativeCurrency: { | ||
name: string | ||
symbol: string | ||
decimals: number | ||
} | ||
rpcUrl: string | ||
} | ||
|
||
export type IChainsConfig = Record<number, IChainInfo> | ||
|
||
export const DEFAULT_CHAINS_CONFIG: IChainsConfig = { | ||
[SupportedChainIds.RoninMainnet]: { | ||
chainId: SupportedChainIds.RoninMainnet, | ||
blockExplorerUrl: "https://app.roninchain.com", | ||
chainName: "Ronin Mainnet", | ||
iconUrl: "https://cdn.skymavis.com/explorer-cdn/asset/favicon/apple-touch-icon.png", | ||
nativeCurrency: { | ||
name: "Ronin", | ||
symbol: "RON", | ||
decimals: 18, | ||
}, | ||
rpcUrl: DEFAULT_RPC_CONFIG[SupportedChainIds.RoninMainnet], | ||
}, | ||
|
||
[SupportedChainIds.RoninTestnet]: { | ||
chainId: SupportedChainIds.RoninTestnet, | ||
blockExplorerUrl: "https://saigon-app.roninchain.com", | ||
chainName: "Saigon Testnet", | ||
iconUrl: "https://cdn.skymavis.com/explorer-cdn/asset/favicon/apple-touch-icon.png", | ||
nativeCurrency: { | ||
name: "tRonin", | ||
symbol: "tRON", | ||
decimals: 18, | ||
}, | ||
rpcUrl: DEFAULT_RPC_CONFIG[SupportedChainIds.RoninTestnet], | ||
}, | ||
import type { Chain } from "viem" | ||
import { goerli, mainnet, ronin, saigon } from "viem/chains" | ||
|
||
export const VIEM_CHAIN_MAPPING: Record<number, Chain> = { | ||
[ronin.id]: ronin, | ||
[saigon.id]: saigon, | ||
[mainnet.id]: mainnet, | ||
[goerli.id]: goerli, | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,55 @@ | ||
import { IEip1193EventEmitter } from "./eip1193-event" | ||
import type { | ||
Address, | ||
EIP1193Events, | ||
EIP1193Parameters, | ||
Hash, | ||
Hex, | ||
PublicRpcSchema, | ||
TypedDataDefinition, | ||
} from "viem" | ||
|
||
export interface IEip1193RequestArgs { | ||
readonly method: string | ||
readonly params?: Array<any> | ||
import type { GenericTransaction } from "./tx" | ||
|
||
export interface Eip1193Provider extends EIP1193Events { | ||
request: <ReturnType = unknown>( | ||
args: EIP1193Parameters<MavisIdRequestSchema>, | ||
) => Promise<ReturnType> | ||
} | ||
|
||
export interface IEip1193Provider extends IEip1193EventEmitter { | ||
request: <T = any>(args: IEip1193RequestArgs) => Promise<T> | ||
export type MavisIdRequestSchema = [ | ||
...PublicRpcSchema, | ||
|
||
{ | ||
Method: "eth_accounts" | ||
Parameters?: undefined | ||
ReturnType: Address[] | ||
}, | ||
{ | ||
Method: "eth_requestAccounts" | ||
Parameters?: undefined | ||
ReturnType: Address[] | ||
}, | ||
{ | ||
Method: "eth_sendTransaction" | ||
Parameters: [transaction: GenericTransaction] | ||
ReturnType: Hash | ||
}, | ||
{ | ||
Method: "eth_signTypedData_v4" | ||
Parameters: [address: Address, typedData: TypedDataDefinition] | ||
ReturnType: Hex | ||
}, | ||
{ | ||
Method: "personal_sign" | ||
Parameters: [data: Hex, address: Address] | ||
ReturnType: Hex | ||
}, | ||
] | ||
|
||
export enum Eip1193EventName { | ||
accountsChanged = "accountsChanged", | ||
chainChanged = "chainChanged", | ||
connect = "connect", | ||
disconnect = "disconnect", | ||
message = "message", | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,56 @@ | ||
export type AccessList = Array<{ address: string; storageKeys: Array<string> }> | ||
import type { AccessList, Address, Hex } from "viem" | ||
|
||
export type AccessListish = | ||
| AccessList | ||
| Array<[string, Array<string>]> | ||
| Record<string, Array<string>> | ||
export interface GenericTransaction { | ||
// "0x64" for ronin gas sponsor | ||
type?: "0x0" | "0x1" | "0x2" | "0x64" | ||
|
||
export type BigNumberish = bigint | string | number | ||
nonce?: Hex | ||
to: Address | null | ||
from?: Address | ||
|
||
export type Bytes = ArrayLike<number> | ||
value?: Hex | ||
input?: Hex | ||
data?: Hex | ||
|
||
export type BytesLike = Bytes | string | ||
gas?: Hex | ||
gasPrice?: Hex | ||
|
||
export const ZERO_TX_DATA = 0 | ||
// EIP-2930; Type 1 & EIP-1559; Type 2 | ||
accessList?: AccessList | ||
|
||
// EIP-1559; Type 2 | ||
maxPriorityFeePerGas?: Hex | ||
maxFeePerGas?: Hex | ||
maxFeePerBlobGas?: Hex | ||
blobVersionedHashes?: Array<Hex> | ||
blobs?: Array<Hex> | ||
|
||
chainId?: Hex | ||
} | ||
|
||
export type IUnsignedTransaction = { | ||
to: string | ||
value: string | ||
from?: string | ||
nonce?: string | ||
data?: string | ||
type?: number | ||
gas?: string | ||
gasPrice?: string | ||
input?: string | ||
s?: string | ||
r?: string | ||
v?: string | ||
chainId?: string | ||
// Typed-Transaction features | ||
export interface FilledTransaction { | ||
// "0x64" for ronin gas sponsor | ||
type: "0x0" | "0x1" | "0x2" | "0x64" | ||
|
||
nonce?: Hex | ||
to: Address | null | ||
from: Address | ||
|
||
value: Hex | ||
input: Hex | ||
|
||
gas?: Hex | ||
gasPrice?: Hex | ||
|
||
// EIP-2930; Type 1 & EIP-1559; Type 2 | ||
accessList?: AccessListish | ||
accessList: AccessList | ||
|
||
// EIP-1559; Type 2 | ||
maxPriorityFeePerGas?: BigNumberish | ||
maxFeePerGas?: BigNumberish | ||
// EIP-1559; Type 100 | ||
payerS?: string | ||
payerR?: string | ||
payerV?: string | ||
maxPriorityFeePerGas?: Hex | ||
maxFeePerGas?: Hex | ||
maxFeePerBlobGas: Hex | ||
blobVersionedHashes: Array<Hex> | ||
blobs: Array<Hex> | ||
|
||
chainId: Hex | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.