sushi 6.6.6 → 6.6.8
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/_cjs/evm/config/subgraphs/subgraphs/sushiswap-v2.js +2 -7
- package/_cjs/evm/config/subgraphs/subgraphs/sushiswap-v2.js.map +1 -1
- package/_cjs/evm/config/subgraphs/subgraphs/sushiswap-v3.js +2 -7
- package/_cjs/evm/config/subgraphs/subgraphs/sushiswap-v3.js.map +1 -1
- package/_cjs/generic/currency/for-chain.js +66 -0
- package/_cjs/generic/currency/for-chain.js.map +1 -0
- package/_cjs/generic/currency/index.js +1 -0
- package/_cjs/generic/currency/index.js.map +1 -1
- package/_cjs/generic/utils/normalize-address.js +29 -1
- package/_cjs/generic/utils/normalize-address.js.map +1 -1
- package/_esm/evm/config/subgraphs/subgraphs/sushiswap-v2.js +2 -7
- package/_esm/evm/config/subgraphs/subgraphs/sushiswap-v2.js.map +1 -1
- package/_esm/evm/config/subgraphs/subgraphs/sushiswap-v3.js +2 -7
- package/_esm/evm/config/subgraphs/subgraphs/sushiswap-v3.js.map +1 -1
- package/_esm/generic/currency/for-chain.js +62 -0
- package/_esm/generic/currency/for-chain.js.map +1 -0
- package/_esm/generic/currency/index.js +1 -0
- package/_esm/generic/currency/index.js.map +1 -1
- package/_esm/generic/utils/normalize-address.js +29 -1
- package/_esm/generic/utils/normalize-address.js.map +1 -1
- package/_types/evm/config/subgraphs/subgraphs/sushiswap-v2.d.ts +1 -1
- package/_types/evm/config/subgraphs/subgraphs/sushiswap-v2.d.ts.map +1 -1
- package/_types/evm/config/subgraphs/subgraphs/sushiswap-v3.d.ts +1 -1
- package/_types/evm/config/subgraphs/subgraphs/sushiswap-v3.d.ts.map +1 -1
- package/_types/evm/currency/currency.d.ts +1 -1
- package/_types/evm/currency/currency.d.ts.map +1 -1
- package/_types/generic/currency/currency.d.ts +1 -1
- package/_types/generic/currency/currency.d.ts.map +1 -1
- package/_types/generic/currency/for-chain.d.ts +25 -0
- package/_types/generic/currency/for-chain.d.ts.map +1 -0
- package/_types/generic/currency/index.d.ts +1 -0
- package/_types/generic/currency/index.d.ts.map +1 -1
- package/_types/generic/types/for-chain.d.ts +4 -0
- package/_types/generic/types/for-chain.d.ts.map +1 -1
- package/_types/generic/utils/normalize-address.d.ts +2 -1
- package/_types/generic/utils/normalize-address.d.ts.map +1 -1
- package/_types/svm/currency/currency.d.ts +1 -1
- package/_types/svm/currency/currency.d.ts.map +1 -1
- package/evm/config/subgraphs/subgraphs/sushiswap-v2.ts +5 -8
- package/evm/config/subgraphs/subgraphs/sushiswap-v3.ts +5 -8
- package/evm/currency/currency.ts +1 -1
- package/generic/currency/currency.test-d.ts +41 -0
- package/generic/currency/currency.ts +1 -1
- package/generic/currency/for-chain.test-d.ts +224 -0
- package/generic/currency/for-chain.test.ts +108 -0
- package/generic/currency/for-chain.ts +133 -0
- package/generic/currency/index.ts +1 -0
- package/generic/types/for-chain.test-d.ts +100 -1
- package/generic/types/for-chain.ts +13 -0
- package/generic/utils/normalize-address.test-d.ts +110 -0
- package/generic/utils/normalize-address.test.ts +29 -0
- package/generic/utils/normalize-address.ts +58 -16
- package/package.json +1 -1
- package/svm/currency/currency.ts +1 -1
|
@@ -1,12 +1,111 @@
|
|
|
1
1
|
import { describe, expectTypeOf, it } from 'vitest'
|
|
2
|
+
import type { EvmChainId } from '../../evm/chain/chains.js'
|
|
3
|
+
import type { EvmCurrency } from '../../evm/currency/currency.js'
|
|
4
|
+
import type { EvmNative } from '../../evm/currency/native.js'
|
|
5
|
+
import type { EvmToken } from '../../evm/currency/token.js'
|
|
6
|
+
import type { MvmChainId } from '../../mvm/chain/chains.js'
|
|
7
|
+
import type { MvmToken } from '../../mvm/currency/token.js'
|
|
2
8
|
import type { StellarAddress } from '../../stellar/address.js'
|
|
3
9
|
import type { StellarChainId } from '../../stellar/chain/chains.js'
|
|
10
|
+
import type { StellarCurrency } from '../../stellar/currency/currency.js'
|
|
11
|
+
import type { StellarToken } from '../../stellar/currency/token.js'
|
|
4
12
|
import type { StellarID } from '../../stellar/types/id.js'
|
|
13
|
+
import type { SvmCurrency } from '../../svm/currency/currency.js'
|
|
14
|
+
import type { SvmNative } from '../../svm/currency/native.js'
|
|
15
|
+
import type { SvmToken } from '../../svm/currency/token.js'
|
|
5
16
|
import type { SvmChainId } from '../../svm/index.js'
|
|
6
17
|
import type { SvmID } from '../../svm/types/id.js'
|
|
7
|
-
import type {
|
|
18
|
+
import type {
|
|
19
|
+
CurrencyFor,
|
|
20
|
+
IDFor,
|
|
21
|
+
NativeChainId,
|
|
22
|
+
NativeFor,
|
|
23
|
+
TokenFor,
|
|
24
|
+
} from './for-chain.js'
|
|
8
25
|
|
|
9
26
|
describe('generic/types/for-chain.ts types', () => {
|
|
27
|
+
type Metadata = {
|
|
28
|
+
coingeckoId: string
|
|
29
|
+
verified: boolean
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
describe('TokenFor', () => {
|
|
33
|
+
it('should return the correct token type for each chain family', () => {
|
|
34
|
+
expectTypeOf<TokenFor<EvmChainId, Metadata>>().toEqualTypeOf<
|
|
35
|
+
EvmToken<Metadata>
|
|
36
|
+
>()
|
|
37
|
+
expectTypeOf<TokenFor<MvmChainId, Metadata>>().toEqualTypeOf<
|
|
38
|
+
MvmToken<Metadata>
|
|
39
|
+
>()
|
|
40
|
+
expectTypeOf<TokenFor<SvmChainId, Metadata>>().toEqualTypeOf<
|
|
41
|
+
SvmToken<Metadata>
|
|
42
|
+
>()
|
|
43
|
+
expectTypeOf<TokenFor<StellarChainId, Metadata>>().toEqualTypeOf<
|
|
44
|
+
StellarToken<Metadata>
|
|
45
|
+
>()
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it('should distribute over chain id unions', () => {
|
|
49
|
+
expectTypeOf<TokenFor<EvmChainId | SvmChainId, Metadata>>().toEqualTypeOf<
|
|
50
|
+
EvmToken<Metadata> | SvmToken<Metadata>
|
|
51
|
+
>()
|
|
52
|
+
})
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
describe('CurrencyFor', () => {
|
|
56
|
+
it('should return the correct currency type for each chain family', () => {
|
|
57
|
+
expectTypeOf<CurrencyFor<EvmChainId, Metadata>>().toEqualTypeOf<
|
|
58
|
+
EvmCurrency<Metadata>
|
|
59
|
+
>()
|
|
60
|
+
expectTypeOf<CurrencyFor<MvmChainId, Metadata>>().toEqualTypeOf<
|
|
61
|
+
MvmToken<Metadata>
|
|
62
|
+
>()
|
|
63
|
+
expectTypeOf<CurrencyFor<SvmChainId, Metadata>>().toEqualTypeOf<
|
|
64
|
+
SvmCurrency<Metadata>
|
|
65
|
+
>()
|
|
66
|
+
expectTypeOf<CurrencyFor<StellarChainId, Metadata>>().toEqualTypeOf<
|
|
67
|
+
StellarCurrency<Metadata>
|
|
68
|
+
>()
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it('should distribute over chain id unions', () => {
|
|
72
|
+
expectTypeOf<
|
|
73
|
+
CurrencyFor<EvmChainId | SvmChainId, Metadata>
|
|
74
|
+
>().toEqualTypeOf<EvmCurrency<Metadata> | SvmCurrency<Metadata>>()
|
|
75
|
+
})
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
describe('NativeFor', () => {
|
|
79
|
+
it('should only support chain families with native currency classes', () => {
|
|
80
|
+
expectTypeOf<NativeChainId>().toEqualTypeOf<EvmChainId | SvmChainId>()
|
|
81
|
+
expectTypeOf<NativeFor<EvmChainId, Metadata>>().toEqualTypeOf<
|
|
82
|
+
EvmNative<Metadata>
|
|
83
|
+
>()
|
|
84
|
+
expectTypeOf<NativeFor<SvmChainId, Metadata>>().toEqualTypeOf<
|
|
85
|
+
SvmNative<Metadata>
|
|
86
|
+
>()
|
|
87
|
+
expectTypeOf<NativeFor<NativeChainId, Metadata>>().toEqualTypeOf<
|
|
88
|
+
EvmNative<Metadata> | SvmNative<Metadata>
|
|
89
|
+
>()
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
it('should reject token-only chain families', () => {
|
|
93
|
+
type NativeForMvm = NativeFor<
|
|
94
|
+
// @ts-expect-error MVM is intentionally excluded from NativeChainId.
|
|
95
|
+
MvmChainId,
|
|
96
|
+
Metadata
|
|
97
|
+
>
|
|
98
|
+
type NativeForStellar = NativeFor<
|
|
99
|
+
// @ts-expect-error Stellar is intentionally excluded from NativeChainId.
|
|
100
|
+
StellarChainId,
|
|
101
|
+
Metadata
|
|
102
|
+
>
|
|
103
|
+
|
|
104
|
+
expectTypeOf<NativeForMvm>().toEqualTypeOf<never>()
|
|
105
|
+
expectTypeOf<NativeForStellar>().toEqualTypeOf<never>()
|
|
106
|
+
})
|
|
107
|
+
})
|
|
108
|
+
|
|
10
109
|
describe('IDFor', () => {
|
|
11
110
|
it('should return the correct id type for SVM chains', () => {
|
|
12
111
|
expectTypeOf<IDFor<SvmChainId>>().toEqualTypeOf<SvmID>()
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { EvmChainId } from '../../evm/chain/chains.js'
|
|
2
2
|
import type { EvmCurrency } from '../../evm/currency/currency.js'
|
|
3
|
+
import type { EvmNative } from '../../evm/currency/native.js'
|
|
3
4
|
import type {
|
|
4
5
|
EvmAddress,
|
|
5
6
|
EvmToken,
|
|
@@ -19,6 +20,7 @@ import type { StellarToken } from '../../stellar/currency/token.js'
|
|
|
19
20
|
import type { StellarID } from '../../stellar/types/id.js'
|
|
20
21
|
import type { SvmChainId } from '../../svm/chain/chains.js'
|
|
21
22
|
import type { SvmCurrency } from '../../svm/currency/currency.js'
|
|
23
|
+
import type { SvmNative } from '../../svm/currency/native.js'
|
|
22
24
|
import type {
|
|
23
25
|
SvmAddress,
|
|
24
26
|
SvmToken,
|
|
@@ -54,6 +56,17 @@ export type CurrencyFor<
|
|
|
54
56
|
? StellarCurrency<Metadata>
|
|
55
57
|
: never
|
|
56
58
|
|
|
59
|
+
export type NativeChainId = EvmChainId | SvmChainId
|
|
60
|
+
|
|
61
|
+
export type NativeFor<
|
|
62
|
+
TChainId extends NativeChainId,
|
|
63
|
+
Metadata extends CurrencyMetadata = CurrencyMetadata,
|
|
64
|
+
> = TChainId extends EvmChainId
|
|
65
|
+
? EvmNative<Metadata>
|
|
66
|
+
: TChainId extends SvmChainId
|
|
67
|
+
? SvmNative<Metadata>
|
|
68
|
+
: never
|
|
69
|
+
|
|
57
70
|
export type AddressFor<TChainId extends ChainId> = TChainId extends EvmChainId
|
|
58
71
|
? EvmAddress
|
|
59
72
|
: TChainId extends MvmChainId
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { describe, expectTypeOf, it } from 'vitest'
|
|
2
|
+
import { EvmChainId } from '../../evm/chain/chains.js'
|
|
3
|
+
import type { EvmAddress } from '../../evm/currency/token.js'
|
|
4
|
+
import type { MvmAddress } from '../../mvm/currency/token.js'
|
|
5
|
+
import type {
|
|
6
|
+
StellarAccountAddress,
|
|
7
|
+
StellarContractAddress,
|
|
8
|
+
} from '../../stellar/address.js'
|
|
9
|
+
import { StellarChainId } from '../../stellar/chain/chains.js'
|
|
10
|
+
import { SvmChainId } from '../../svm/chain/chains.js'
|
|
11
|
+
import type { SvmAddress } from '../../svm/currency/token.js'
|
|
12
|
+
import { normalizeAddress } from './normalize-address.js'
|
|
13
|
+
|
|
14
|
+
describe('normalizeAddress types', () => {
|
|
15
|
+
it('preserves EVM address types', () => {
|
|
16
|
+
const address = '0x0000000000000000000000000000000000000000' as EvmAddress
|
|
17
|
+
|
|
18
|
+
expectTypeOf(
|
|
19
|
+
normalizeAddress(EvmChainId.ETHEREUM, address),
|
|
20
|
+
).toEqualTypeOf<EvmAddress>()
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it('preserves SVM address types', () => {
|
|
24
|
+
const address = 'So11111111111111111111111111111111111111112' as SvmAddress
|
|
25
|
+
|
|
26
|
+
expectTypeOf(
|
|
27
|
+
normalizeAddress(SvmChainId.SOLANA, address),
|
|
28
|
+
).toEqualTypeOf<SvmAddress>()
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it('preserves Stellar account and contract address types', () => {
|
|
32
|
+
const accountAddress =
|
|
33
|
+
'GAAZI4TCR3TY5OJHCTJC2A4QSY6CJWJH5IAJTGKIN2ER7LBNVKOCCWN7' as StellarAccountAddress
|
|
34
|
+
const contractAddress =
|
|
35
|
+
'CCRSMJDITH3VK5QOGYCVZDAKIY5GL3RCG4TCVLIAVB662IW2V5KJGZGF' as StellarContractAddress
|
|
36
|
+
|
|
37
|
+
expectTypeOf(
|
|
38
|
+
normalizeAddress(StellarChainId.STELLAR, accountAddress),
|
|
39
|
+
).toEqualTypeOf<StellarAccountAddress>()
|
|
40
|
+
expectTypeOf(
|
|
41
|
+
normalizeAddress(StellarChainId.STELLAR, contractAddress),
|
|
42
|
+
).toEqualTypeOf<StellarContractAddress>()
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('preserves same-chain address unions', () => {
|
|
46
|
+
function normalizeStellarUnion(
|
|
47
|
+
address: StellarAccountAddress | StellarContractAddress,
|
|
48
|
+
) {
|
|
49
|
+
expectTypeOf(
|
|
50
|
+
normalizeAddress(StellarChainId.STELLAR, address),
|
|
51
|
+
).toEqualTypeOf<StellarAccountAddress | StellarContractAddress>()
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
expectTypeOf(normalizeStellarUnion).returns.toEqualTypeOf<void>()
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it('preserves cross-chain address unions', () => {
|
|
58
|
+
function normalizeEvmOrSvmUnion(
|
|
59
|
+
chainId: typeof EvmChainId.ETHEREUM | typeof SvmChainId.SOLANA,
|
|
60
|
+
address: EvmAddress | SvmAddress,
|
|
61
|
+
) {
|
|
62
|
+
expectTypeOf(normalizeAddress(chainId, address)).toEqualTypeOf<
|
|
63
|
+
EvmAddress | SvmAddress
|
|
64
|
+
>()
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
expectTypeOf(normalizeEvmOrSvmUnion).returns.toEqualTypeOf<void>()
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('preserves address types without chain ids', () => {
|
|
71
|
+
const evmAddress =
|
|
72
|
+
'0x0000000000000000000000000000000000000000' as EvmAddress
|
|
73
|
+
const mvmAddress = '0x1::coin::T' as MvmAddress
|
|
74
|
+
const svmAddress =
|
|
75
|
+
'So11111111111111111111111111111111111111112' as SvmAddress
|
|
76
|
+
const stellarAccountAddress =
|
|
77
|
+
'GAAZI4TCR3TY5OJHCTJC2A4QSY6CJWJH5IAJTGKIN2ER7LBNVKOCCWN7' as StellarAccountAddress
|
|
78
|
+
const stellarContractAddress =
|
|
79
|
+
'CCRSMJDITH3VK5QOGYCVZDAKIY5GL3RCG4TCVLIAVB662IW2V5KJGZGF' as StellarContractAddress
|
|
80
|
+
|
|
81
|
+
expectTypeOf(normalizeAddress(evmAddress)).toEqualTypeOf<EvmAddress>()
|
|
82
|
+
expectTypeOf(normalizeAddress(mvmAddress)).toEqualTypeOf<MvmAddress>()
|
|
83
|
+
expectTypeOf(normalizeAddress(svmAddress)).toEqualTypeOf<SvmAddress>()
|
|
84
|
+
expectTypeOf(
|
|
85
|
+
normalizeAddress(stellarAccountAddress),
|
|
86
|
+
).toEqualTypeOf<StellarAccountAddress>()
|
|
87
|
+
expectTypeOf(
|
|
88
|
+
normalizeAddress(stellarContractAddress),
|
|
89
|
+
).toEqualTypeOf<StellarContractAddress>()
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
it('preserves address unions without chain ids', () => {
|
|
93
|
+
function normalizeStellarUnion(
|
|
94
|
+
address: StellarAccountAddress | StellarContractAddress,
|
|
95
|
+
) {
|
|
96
|
+
expectTypeOf(normalizeAddress(address)).toEqualTypeOf<
|
|
97
|
+
StellarAccountAddress | StellarContractAddress
|
|
98
|
+
>()
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function normalizeEvmOrSvmUnion(address: EvmAddress | SvmAddress) {
|
|
102
|
+
expectTypeOf(normalizeAddress(address)).toEqualTypeOf<
|
|
103
|
+
EvmAddress | SvmAddress
|
|
104
|
+
>()
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
expectTypeOf(normalizeStellarUnion).returns.toEqualTypeOf<void>()
|
|
108
|
+
expectTypeOf(normalizeEvmOrSvmUnion).returns.toEqualTypeOf<void>()
|
|
109
|
+
})
|
|
110
|
+
})
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import type { EvmAddress } from '../../evm/currency/token.js'
|
|
3
|
+
import type { MvmAddress } from '../../mvm/currency/token.js'
|
|
4
|
+
import type { StellarContractAddress } from '../../stellar/address.js'
|
|
5
|
+
import type { SvmAddress } from '../../svm/currency/token.js'
|
|
6
|
+
import { normalizeAddress } from './normalize-address.js'
|
|
7
|
+
|
|
8
|
+
describe('normalizeAddress', () => {
|
|
9
|
+
it('normalizes addresses without chain ids by address format', () => {
|
|
10
|
+
expect(
|
|
11
|
+
normalizeAddress(
|
|
12
|
+
'0x000000000000000000000000000000000000dEaD' as EvmAddress,
|
|
13
|
+
),
|
|
14
|
+
).toBe('0x000000000000000000000000000000000000dead')
|
|
15
|
+
|
|
16
|
+
const mvmAddress = '0xABC::Coin::T' as MvmAddress
|
|
17
|
+
expect(normalizeAddress(mvmAddress)).toBe(mvmAddress)
|
|
18
|
+
|
|
19
|
+
const svmAddress =
|
|
20
|
+
'So11111111111111111111111111111111111111112' as SvmAddress
|
|
21
|
+
expect(normalizeAddress(svmAddress)).toBe(svmAddress)
|
|
22
|
+
|
|
23
|
+
expect(
|
|
24
|
+
normalizeAddress(
|
|
25
|
+
'ccrsmjdith3vk5qogycvzdakiy5gl3rcg4tcvliavb662iw2v5kjgzgf' as StellarContractAddress,
|
|
26
|
+
),
|
|
27
|
+
).toBe('CCRSMJDITH3VK5QOGYCVZDAKIY5GL3RCG4TCVLIAVB662IW2V5KJGZGF')
|
|
28
|
+
})
|
|
29
|
+
})
|
|
@@ -1,46 +1,88 @@
|
|
|
1
1
|
import type { EvmChainId } from '../../evm/chain/chains.js'
|
|
2
2
|
import { isEvmChainId } from '../../evm/chain/chains.js'
|
|
3
|
+
import { type EvmAddress, isEvmAddress } from '../../evm/currency/token.js'
|
|
3
4
|
import { normalizeEvmAddress } from '../../evm/utils/normalize-address.js'
|
|
4
5
|
import type { MvmChainId } from '../../mvm/chain/chains.js'
|
|
5
6
|
import { isMvmChainId } from '../../mvm/chain/chains.js'
|
|
7
|
+
import { isMvmAddress } from '../../mvm/currency/token.js'
|
|
6
8
|
import { normalizeMvmAddress } from '../../mvm/utils/normalize-address.js'
|
|
9
|
+
import { isStellarAddress, type StellarAddress } from '../../stellar/address.js'
|
|
7
10
|
import type { StellarChainId } from '../../stellar/chain/chains.js'
|
|
8
11
|
import { isStellarChainId } from '../../stellar/chain/chains.js'
|
|
9
12
|
import { normalizeStellarAddress } from '../../stellar/utils/normalize-address.js'
|
|
10
13
|
import type { SvmChainId } from '../../svm/chain/chains.js'
|
|
11
14
|
import { isSvmChainId } from '../../svm/chain/chains.js'
|
|
15
|
+
import { isSvmAddress, type SvmAddress } from '../../svm/currency/token.js'
|
|
12
16
|
import { normalizeSvmAddress } from '../../svm/utils/normalize-address.js'
|
|
13
17
|
import type { ChainId } from '../chain/chains.js'
|
|
14
18
|
import type { AddressFor } from '../types/for-chain.js'
|
|
15
19
|
import { assertNever } from './assert-never.js'
|
|
16
20
|
|
|
17
|
-
export function normalizeAddress<
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
export function normalizeAddress<TAddress extends AddressFor<ChainId>>(
|
|
22
|
+
address: TAddress,
|
|
23
|
+
): TAddress
|
|
24
|
+
export function normalizeAddress<
|
|
25
|
+
TChainId extends ChainId,
|
|
26
|
+
TAddress extends AddressFor<TChainId>,
|
|
27
|
+
>(chainId: TChainId, address: TAddress): TAddress
|
|
28
|
+
export function normalizeAddress(
|
|
29
|
+
chainIdOrAddress: ChainId | AddressFor<ChainId>,
|
|
30
|
+
address?: AddressFor<ChainId>,
|
|
31
|
+
): AddressFor<ChainId> {
|
|
32
|
+
if (address === undefined) {
|
|
33
|
+
if (typeof chainIdOrAddress !== 'string') {
|
|
34
|
+
throw new Error(
|
|
35
|
+
`normalizeAddress, unsupported address: ${chainIdOrAddress}`,
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return normalizeAddressByFormat(chainIdOrAddress)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return normalizeAddressByChainId(chainIdOrAddress as ChainId, address)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function normalizeAddressByChainId(
|
|
46
|
+
chainId: ChainId,
|
|
47
|
+
address: AddressFor<ChainId>,
|
|
48
|
+
) {
|
|
21
49
|
if (isEvmChainId(chainId)) {
|
|
22
|
-
return normalizeEvmAddress(
|
|
23
|
-
address as AddressFor<EvmChainId>,
|
|
24
|
-
) as AddressFor<TChainId>
|
|
50
|
+
return normalizeEvmAddress(address as AddressFor<EvmChainId>)
|
|
25
51
|
}
|
|
26
52
|
|
|
27
53
|
if (isMvmChainId(chainId)) {
|
|
28
|
-
return normalizeMvmAddress(
|
|
29
|
-
address as AddressFor<MvmChainId>,
|
|
30
|
-
) as AddressFor<TChainId>
|
|
54
|
+
return normalizeMvmAddress(address as AddressFor<MvmChainId>)
|
|
31
55
|
}
|
|
32
56
|
|
|
33
57
|
if (isSvmChainId(chainId)) {
|
|
34
|
-
return normalizeSvmAddress(
|
|
35
|
-
address as AddressFor<SvmChainId>,
|
|
36
|
-
) as AddressFor<TChainId>
|
|
58
|
+
return normalizeSvmAddress(address as AddressFor<SvmChainId>)
|
|
37
59
|
}
|
|
38
60
|
|
|
39
61
|
if (isStellarChainId(chainId)) {
|
|
40
|
-
return normalizeStellarAddress(
|
|
41
|
-
address as AddressFor<StellarChainId>,
|
|
42
|
-
) as AddressFor<TChainId>
|
|
62
|
+
return normalizeStellarAddress(address as AddressFor<StellarChainId>)
|
|
43
63
|
}
|
|
44
64
|
|
|
45
65
|
assertNever(chainId, `normalizeAddress, unsupported chainId: ${chainId}`)
|
|
46
66
|
}
|
|
67
|
+
|
|
68
|
+
function normalizeAddressByFormat(
|
|
69
|
+
address: AddressFor<ChainId>,
|
|
70
|
+
): AddressFor<ChainId> {
|
|
71
|
+
if (isMvmAddress(address)) {
|
|
72
|
+
return normalizeMvmAddress(address)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (isEvmAddress(address)) {
|
|
76
|
+
return normalizeEvmAddress(address as EvmAddress)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (isSvmAddress(address)) {
|
|
80
|
+
return normalizeSvmAddress(address as SvmAddress)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (isStellarAddress(address.toUpperCase())) {
|
|
84
|
+
return normalizeStellarAddress(address as StellarAddress)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
throw new Error(`normalizeAddress, unsupported address: ${address}`)
|
|
88
|
+
}
|
package/package.json
CHANGED
package/svm/currency/currency.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { type SvmToken, serializedSvmTokenSchema } from './token.js'
|
|
|
6
6
|
|
|
7
7
|
export type SvmCurrency<
|
|
8
8
|
TMetadata extends CurrencyMetadata = Record<string, unknown>,
|
|
9
|
-
> = SvmToken<TMetadata> | SvmNative
|
|
9
|
+
> = SvmToken<TMetadata> | SvmNative<TMetadata>
|
|
10
10
|
|
|
11
11
|
export const serializedSvmCurrencySchema = <
|
|
12
12
|
TMetadata extends {} = CurrencyMetadata,
|