@mimicprotocol/lib-ts 0.0.1-rc.14 → 0.0.1-rc.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mimicprotocol/lib-ts",
3
- "version": "0.0.1-rc.14",
3
+ "version": "0.0.1-rc.15",
4
4
  "license": "GPL-3.0",
5
5
  "private": false,
6
6
  "type": "module",
@@ -0,0 +1,13 @@
1
+ import { ERC20Token } from '../tokens'
2
+ import { ChainId } from '../types'
3
+
4
+ /* eslint-disable no-secrets/no-secrets */
5
+
6
+ export namespace Sonic {
7
+ export const CHAIN_ID = ChainId.SONIC
8
+ export const SONIC = ERC20Token.native(CHAIN_ID)
9
+ export const USDC = ERC20Token.fromString('0x29219dd400f2Bf60E5a23d13Be72B486D4038894', CHAIN_ID, 6, 'USDC')
10
+ export const USDT = ERC20Token.fromString('0x6047828dc181963ba44974801ff68e538da5eaf9', CHAIN_ID, 6, 'USDT')
11
+ export const WETH = ERC20Token.fromString('0x50c42dEAcD8Fc9773493ED674b675bE577f2634b', CHAIN_ID, 18, 'WETH')
12
+ export const WSONIC = ERC20Token.fromString('0x039e2fB66102314Ce7b64Ce5Ce3E5183bc94aD38', CHAIN_ID, 18, 'WSONIC')
13
+ }
@@ -3,3 +3,4 @@ export * from './Base'
3
3
  export * from './Ethereum'
4
4
  export * from './Gnosis'
5
5
  export * from './Optimism'
6
+ export * from './Sonic'
@@ -1,5 +1,6 @@
1
1
  export const NULL_ADDRESS = '0x0000000000000000000000000000000000000000'
2
- export const NATIVE_ADDRESS = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'
2
+ export const EVM_NATIVE_ADDRESS = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'
3
+ export const SVM_NATIVE_ADDRESS = 'Nativeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'
3
4
  export const USD_ADDRESS = '0x0000000000000000000000000000000000000348'
4
5
 
5
6
  export const STANDARD_DECIMALS: u8 = 18
@@ -11,7 +11,7 @@ export class DenominationToken extends Token {
11
11
  * @returns A new Denomination Token instance for USD
12
12
  */
13
13
  static USD(): DenominationToken {
14
- return new DenominationToken(Address.USD(), 6, 'USD')
14
+ return new DenominationToken(Address.USD(), 18, 'USD')
15
15
  }
16
16
 
17
17
  /**
@@ -1,6 +1,6 @@
1
1
  import { environment } from '../environment'
2
2
  import { evm } from '../evm'
3
- import { NATIVE_ADDRESS } from '../helpers'
3
+ import { EVM_NATIVE_ADDRESS } from '../helpers'
4
4
  import { Address, ChainId, EvmDecodeParam } from '../types'
5
5
 
6
6
  import { Token } from './Token'
@@ -27,9 +27,11 @@ export class ERC20Token extends Token {
27
27
  case ChainId.BASE:
28
28
  case ChainId.ARBITRUM:
29
29
  case ChainId.OPTIMISM:
30
- return ERC20Token.fromString(NATIVE_ADDRESS, chainId, 18, 'ETH')
30
+ return ERC20Token.fromString(EVM_NATIVE_ADDRESS, chainId, 18, 'ETH')
31
31
  case ChainId.GNOSIS:
32
- return ERC20Token.fromString(NATIVE_ADDRESS, chainId, 18, 'xDAI')
32
+ return ERC20Token.fromString(EVM_NATIVE_ADDRESS, chainId, 18, 'xDAI')
33
+ case ChainId.SONIC:
34
+ return ERC20Token.fromString(EVM_NATIVE_ADDRESS, chainId, 18, 'SONIC')
33
35
  default:
34
36
  throw new Error(`Unsupported chainId: ${chainId}`)
35
37
  }
@@ -88,6 +90,7 @@ export class ERC20Token extends Token {
88
90
  symbol: string = ERC20Token.EMPTY_SYMBOL,
89
91
  timestamp: Date | null = null
90
92
  ) {
93
+ if (!address.isEVM()) throw new Error(`Address ${address} must be an EVM address.`)
91
94
  super(address, decimals, symbol)
92
95
  this._chainId = chainId
93
96
  this._timestamp = timestamp
@@ -0,0 +1,113 @@
1
+ import { SVM_NATIVE_ADDRESS } from '../helpers'
2
+ import { Address, ChainId } from '../types'
3
+
4
+ import { Token } from './Token'
5
+
6
+ /**
7
+ * Represents a token on a blockchain network including data like symbol, decimals, and address.
8
+ */
9
+ export class SPLToken extends Token {
10
+ private _chainId: ChainId
11
+
12
+ /**
13
+ * Creates a Token instance representing the native SOL token.
14
+ * @returns A new Token instance for the native token
15
+ */
16
+ static native(): SPLToken {
17
+ return SPLToken.fromString(SVM_NATIVE_ADDRESS, 9, 'SOL')
18
+ }
19
+
20
+ /**
21
+ * Creates a Token instance from an Address object.
22
+ * @param address - The token mint address
23
+ * @param decimals - Number of decimal places
24
+ * @param symbol - Token symbol
25
+ * @returns A new Token instance
26
+ */
27
+ static fromAddress(address: Address, decimals: u8, symbol: string): SPLToken {
28
+ return new SPLToken(address, decimals, symbol)
29
+ }
30
+
31
+ /**
32
+ * Creates a Token instance from a string address.
33
+ * @param address - The token mint address as a base58 string
34
+ * @param decimals - Number of decimal places
35
+ * @param symbol - Token symbol
36
+ * @returns A new Token instance
37
+ */
38
+ static fromString(address: string, decimals: u8, symbol: string): SPLToken {
39
+ return SPLToken.fromAddress(Address.fromString(address), decimals, symbol)
40
+ }
41
+
42
+ /**
43
+ * Creates a new Token instance.
44
+ * @param address - The token mint address
45
+ * @param decimals - Number of decimal places
46
+ * @param symbol - Token symbol
47
+ */
48
+ constructor(address: Address, decimals: u8, symbol: string) {
49
+ if (!address.isSVM()) throw new Error(`Address ${address} must be an SVM address.`)
50
+ super(address, decimals, symbol)
51
+ this._chainId = ChainId.SOLANA_MAINNET
52
+ }
53
+
54
+ /**
55
+ * Gets the blockchain network identifier where this token is deployed.
56
+ * This value is assigned during construction and remains constant throughout the token's lifecycle.
57
+ * @returns The `ChainId` representing the token's network.
58
+ */
59
+ get chainId(): ChainId {
60
+ return this._chainId
61
+ }
62
+
63
+ /**
64
+ * Gets the token's symbol (e.g., "SOL", "USDC").
65
+ * @returns A string containing the token symbol.
66
+ */
67
+ get symbol(): string {
68
+ return this._symbol
69
+ }
70
+
71
+ /**
72
+ * Gets the token's decimals (number of decimal places used).
73
+ * @returns A `u8` representing the number of decimals of the token.
74
+ */
75
+ get decimals(): u8 {
76
+ return this._decimals
77
+ }
78
+
79
+ /**
80
+ * Checks if this token is equal to another token.
81
+ * SPL Tokens are considered equal if they have the same address.
82
+ * @param other - The token to compare with
83
+ * @returns True if both tokens represent the same asset
84
+ */
85
+ equals(other: Token): boolean {
86
+ return other instanceof SPLToken && super.equals(other)
87
+ }
88
+
89
+ /**
90
+ * Checks if this token is the USD denomination.
91
+ * @returns False always
92
+ */
93
+ isUSD(): boolean {
94
+ return false
95
+ }
96
+
97
+ /**
98
+ * Checks if this token is the native token.
99
+ * @returns True if the token is the native token
100
+ */
101
+ isNative(): boolean {
102
+ return this.equals(SPLToken.native())
103
+ }
104
+
105
+ /**
106
+ * Checks if this token belongs to the requested chain.
107
+ * @param chain - The chain ID asking for
108
+ * @returns True if chains are equal
109
+ */
110
+ hasChain(chain: ChainId): boolean {
111
+ return this.chainId === chain
112
+ }
113
+ }
@@ -2,7 +2,7 @@ import { Address, ChainId } from '../types'
2
2
 
3
3
  /**
4
4
  * Represents a token on a blockchain network including data like symbol, decimals, and address.
5
- * Supports both ERC-20 and denomination tokens.
5
+ * Supports both ERC-20, SPL, and denomination tokens.
6
6
  */
7
7
  export abstract class Token {
8
8
  protected _symbol: string
@@ -4,7 +4,7 @@
4
4
  // Copyright (c) 2018 Graph Protocol, Inc. and contributors.
5
5
  // Modified by Mimic Protocol, 2025.
6
6
 
7
- import { isHex, NATIVE_ADDRESS, USD_ADDRESS } from '../helpers'
7
+ import { EVM_NATIVE_ADDRESS, isHex, USD_ADDRESS } from '../helpers'
8
8
 
9
9
  import { ByteArray } from './ByteArray'
10
10
  import { Bytes } from './Bytes'
@@ -32,7 +32,7 @@ export class Address extends Bytes {
32
32
  * Returns the native address.
33
33
  */
34
34
  static native(): Address {
35
- return Address.fromString(NATIVE_ADDRESS)
35
+ return Address.fromString(EVM_NATIVE_ADDRESS)
36
36
  }
37
37
 
38
38
  /**
@@ -8,4 +8,6 @@ export enum ChainId {
8
8
  ARBITRUM = 42161,
9
9
  BASE = 8453,
10
10
  GNOSIS = 100,
11
+ SOLANA_MAINNET = 507424,
12
+ SONIC = 146,
11
13
  }