forked from cordialsys/crosschain
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasset.go
More file actions
828 lines (739 loc) · 26.3 KB
/
asset.go
File metadata and controls
828 lines (739 loc) · 26.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
package crosschain
import (
"fmt"
"net/http"
"slices"
"strings"
"time"
"github.com/cordialsys/crosschain/config"
"github.com/sirupsen/logrus"
"golang.org/x/time/rate"
)
type SignatureType string
const (
K256Keccak = SignatureType("k256-keccak")
K256Sha256 = SignatureType("k256-sha256")
Ed255 = SignatureType("ed255")
Schnorr = SignatureType("schnorr")
Bls12_381G2Blake2 = SignatureType("bls12-381-g2-blake2")
)
// NativeAsset is an asset on a blockchain used to pay gas fees.
// In Crosschain, for simplicity, a NativeAsset represents a chain.
type NativeAsset string
// List of supported NativeAsset
const (
ACA = NativeAsset("ACA") // Acala
ADA = NativeAsset("ADA") // Cardano
AKT = NativeAsset("AKT") // Akash
APTOS = NativeAsset("APTOS") // APTOS
ArbETH = NativeAsset("ArbETH") // Arbitrum
ASTR = NativeAsset("ASTR") // Astar
ATOM = NativeAsset("ATOM") // Cosmos
AurETH = NativeAsset("AurETH") // Aurora
AVAX = NativeAsset("AVAX") // Avalanche
BAND = NativeAsset("BAND") // Band
BASE = NativeAsset("BASE") // BASE
BABY = NativeAsset("BABY") // Babylon
BERA = NativeAsset("BERA") // Berachain
BCH = NativeAsset("BCH") // Bitcoin Cash
BNB = NativeAsset("BNB") // Binance Coin
BTC = NativeAsset("BTC") // Bitcoin
CELO = NativeAsset("CELO") // Celo
CHZ = NativeAsset("CHZ") // Chiliz
CHZ2 = NativeAsset("CHZ2") // Chiliz 2.0
DOGE = NativeAsset("DOGE") // Dogecoin
DOT = NativeAsset("DOT") // Polkadot
DUSK = NativeAsset("DUSK") // Dusk
ENJ = NativeAsset("ENJ") // Enjin
EOS = NativeAsset("EOS") // EOS
ES = NativeAsset("ES") // Eclipse
ETC = NativeAsset("ETC") // Ethereum Classic
ETH = NativeAsset("ETH") // Ethereum
ETHW = NativeAsset("ETHW") // Ethereum PoW
FIL = NativeAsset("FIL") // Filecoin
FOGO = NativeAsset("FOGO") // Fogo
FTM = NativeAsset("FTM") // Fantom
HASH = NativeAsset("HASH") // Provenance
HBAR = NativeAsset("HBAR") // Hedera
HyperEVM = NativeAsset("HyperEVM") // HyperEVM (Hyperliquid)
HYPE = NativeAsset("HYPE") // Hyperliquid
INJ = NativeAsset("INJ") // Injective
LinETH = NativeAsset("LinETH") // Linea
LTC = NativeAsset("LTC") // Litecoin
LUNA = NativeAsset("LUNA") // Terra V2
LUNC = NativeAsset("LUNC") // Terra Classic
KAR = NativeAsset("KAR") // Karura
KAS = NativeAsset("KAS") // Kaspa
KAVA = NativeAsset("KAVA") // Kava
KLAY = NativeAsset("KLAY") // Klaytn
KSM = NativeAsset("KSM") // Kusama
XDC = NativeAsset("XDC") // XinFin
MATIC = NativeAsset("MATIC") // Polygon
MON = NativeAsset("MON") // MONAD
NOBLE = NativeAsset("NOBLE") // Noble Chain
OAS = NativeAsset("OAS") // Oasys (not Oasis!)
OptETH = NativeAsset("OptETH") // Optimism
EmROSE = NativeAsset("EmROSE") // Rose (Oasis EVM-compat "Emerald" parachain)
SOL = NativeAsset("SOL") // Solana
SUI = NativeAsset("SUI") // SUI
XPLA = NativeAsset("XPLA") // XPLA
TAO = NativeAsset("TAO") // Bittensor
TIA = NativeAsset("TIA") // celestia
TON = NativeAsset("TON") // TON
TRX = NativeAsset("TRX") // TRON
SEI = NativeAsset("SEI") // Sei
SeiEVM = NativeAsset("SeiEVM") // SeiEVM
XPL = NativeAsset("XPL") // Plasma
XRP = NativeAsset("XRP") // XRP
XLM = NativeAsset("XLM") // XLM
ZETA = NativeAsset("ZETA") // ZetaChain
NIL = NativeAsset("NIL") // Nillion
ICP = NativeAsset("ICP") // Internet Computer Protocol
ZEC = NativeAsset("ZEC") // Zcash
ZeroG = NativeAsset("0G") // 0g
)
var NativeAssetList []NativeAsset = []NativeAsset{
ADA,
AKT,
BAND,
BABY,
BCH,
BTC,
DOGE,
LTC,
ACA,
APTOS,
ArbETH,
ASTR,
ATOM,
AurETH,
AVAX,
BERA,
BNB,
CELO,
CHZ,
CHZ2,
DOT,
DUSK,
ENJ,
EOS,
ES,
ETC,
ETH,
ETHW,
FIL,
FOGO,
FTM,
HBAR,
HyperEVM,
INJ,
LinETH,
HASH,
HYPE,
LUNA,
LUNC,
KAR,
KAS,
KAVA,
KLAY,
KSM,
XDC,
MATIC,
MON,
OAS,
OptETH,
EmROSE,
SOL,
SUI,
XPLA,
TAO,
TIA,
TON,
TRX,
SEI,
SeiEVM,
XRP,
BASE,
NOBLE,
XPL,
XLM,
ZETA,
NIL,
ICP,
ZEC,
ZeroG,
}
// Driver is the type of a chain
type Driver string
// List of supported Driver
const (
DriverAptos = Driver("aptos")
DriverBitcoin = Driver("bitcoin")
DriverBitcoinCash = Driver("bitcoin-cash")
DriverBitcoinLegacy = Driver("bitcoin-legacy")
DriverCardano = Driver("cardano")
DriverCosmos = Driver("cosmos")
DriverCosmosEvmos = Driver("evmos")
DriverDusk = Driver("dusk")
DriverEOS = Driver("eos")
DriverEVM = Driver("evm")
DriverEVMLegacy = Driver("evm-legacy")
DriverFilecoin = Driver("filecoin")
DriverHedera = Driver("hedera")
DriverHyperliquid = Driver("hyperliquid")
DriverInternetComputerProtocol = Driver("icp")
DriverKaspa = Driver("kaspa")
DriverSubstrate = Driver("substrate")
DriverSolana = Driver("solana")
DriverSui = Driver("sui")
DriverTron = Driver("tron")
DriverTon = Driver("ton")
DriverXrp = Driver("xrp")
DriverXlm = Driver("xlm")
DriverZcash = Driver("zcash")
// Crosschain is a client-only driver
DriverCrosschain = Driver("crosschain")
)
var SupportedDrivers = []Driver{
DriverAptos,
DriverBitcoin,
DriverBitcoinCash,
DriverBitcoinLegacy,
DriverCosmos,
DriverCosmosEvmos,
DriverEOS,
DriverEVM,
DriverEVMLegacy,
DriverFilecoin,
DriverHedera,
DriverInternetComputerProtocol,
DriverKaspa,
DriverSubstrate,
DriverSolana,
DriverSui,
DriverTron,
DriverTon,
DriverXrp,
DriverXlm,
DriverZcash,
}
type StakingProvider string
const Kiln StakingProvider = "kiln"
const Figment StakingProvider = "figment"
const Twinstake StakingProvider = "twinstake"
const Native StakingProvider = "native"
var SupportedStakingProviders = []StakingProvider{
Native,
Kiln,
Figment,
Twinstake,
}
func (stakingProvider StakingProvider) Valid() bool {
return slices.Contains(SupportedStakingProviders, stakingProvider)
}
type TxVariantInputType string
func NewMultiTransferInputType(driver Driver, variant string) TxVariantInputType {
return TxVariantInputType(fmt.Sprintf("drivers/%s/multi-transfer/%s", driver, variant))
}
func NewStakingInputType(driver Driver, variant string) TxVariantInputType {
return TxVariantInputType(fmt.Sprintf("drivers/%s/staking/%s", driver, variant))
}
func NewUnstakingInputType(driver Driver, variant string) TxVariantInputType {
return TxVariantInputType(fmt.Sprintf("drivers/%s/unstaking/%s", driver, variant))
}
func NewWithdrawingInputType(driver Driver, variant string) TxVariantInputType {
return TxVariantInputType(fmt.Sprintf("drivers/%s/withdrawing/%s", driver, variant))
}
func (variant TxVariantInputType) Driver() Driver {
return Driver(strings.Split(string(variant), "/")[1])
}
func (variant TxVariantInputType) Variant() string {
return (strings.Split(string(variant), "/")[3])
}
func (variant TxVariantInputType) Validate() error {
if len(strings.Split(string(variant), "/")) != 4 {
return fmt.Errorf("invalid input variant type: %s", variant)
}
return nil
}
func (native NativeAsset) IsValid() bool {
return NativeAsset(native).Driver() != ""
}
func (native NativeAsset) Driver() Driver {
switch native {
case BTC:
return DriverBitcoin
case BCH:
return DriverBitcoinCash
case DOGE, LTC:
return DriverBitcoinLegacy
case ZEC:
return DriverZcash
case AVAX, BNB, CELO, ETH, ETHW, MATIC, OptETH, ArbETH, BERA, BASE, SeiEVM, MON, HyperEVM, LinETH, XPL, ZeroG:
return DriverEVM
case FTM, ETC, EmROSE, AurETH, ACA, KLAY, OAS, CHZ, XDC, CHZ2:
return DriverEVMLegacy
case APTOS:
return DriverAptos
case ATOM, XPLA, INJ, HASH, LUNC, LUNA, SEI, TIA, NOBLE, AKT, BAND, ZETA, NIL, BABY, KAVA:
return DriverCosmos
case ICP:
return DriverInternetComputerProtocol
case KAS:
return DriverKaspa
case EOS:
return DriverEOS
case SUI:
return DriverSui
case SOL, ES:
return DriverSolana
case DOT, TAO, KSM, ENJ, KAR, ASTR:
return DriverSubstrate
case TRX:
return DriverTron
case TON:
return DriverTon
case XRP:
return DriverXrp
case XLM:
return DriverXlm
case FIL:
return DriverFilecoin
case FOGO:
return DriverSolana
case DUSK:
return DriverDusk
case ADA:
return DriverCardano
case HYPE:
return DriverHyperliquid
case HBAR:
return DriverHedera
}
return ""
}
// Returns the signature algorithms supported by the driver
// The first algorithm will be used as the default.
func (driver Driver) SignatureAlgorithms() []SignatureType {
switch driver {
case DriverBitcoin:
return []SignatureType{K256Sha256, Schnorr}
case DriverBitcoinCash, DriverBitcoinLegacy, DriverCosmos, DriverXrp, DriverFilecoin, DriverEOS, DriverZcash:
return []SignatureType{K256Sha256}
case DriverEVM, DriverEVMLegacy, DriverCosmosEvmos, DriverTron, DriverHyperliquid, DriverHedera:
return []SignatureType{K256Keccak}
case DriverAptos, DriverSolana, DriverSui, DriverTon, DriverSubstrate, DriverXlm, DriverCardano, DriverInternetComputerProtocol:
return []SignatureType{Ed255}
case DriverDusk:
return []SignatureType{Bls12_381G2Blake2}
case DriverKaspa:
return []SignatureType{Schnorr}
}
return []SignatureType{}
}
type PublicKeyFormat string
var Raw PublicKeyFormat = "raw"
var Compressed PublicKeyFormat = "compressed"
var Uncompressed PublicKeyFormat = "uncompressed"
func (driver Driver) PublicKeyFormat() PublicKeyFormat {
switch driver {
case DriverBitcoin, DriverCardano, DriverBitcoinCash, DriverBitcoinLegacy, DriverEOS, DriverZcash:
return Compressed
case DriverCosmos, DriverCosmosEvmos, DriverXrp, DriverXlm:
return Compressed
case DriverEVM, DriverEVMLegacy, DriverTron, DriverFilecoin, DriverHyperliquid, DriverHedera:
return Uncompressed
case DriverAptos, DriverSolana, DriverSui, DriverTon, DriverSubstrate, DriverDusk, DriverKaspa, DriverInternetComputerProtocol:
return Raw
}
return ""
}
// Network selector is used by crosschain client to select which network of a blockchain to select.
type NetworkSelector string
const Mainnets NetworkSelector = ""
const NotMainnets NetworkSelector = "!mainnet"
// ClientConfig is the model used to represent a client inside an AssetConfig
type ClientConfig struct {
Driver Driver `yaml:"driver"`
URL string `yaml:"url,omitempty"`
Auth string `yaml:"auth,omitempty"`
Provider string `yaml:"provider,omitempty"`
Network NetworkSelector `yaml:"network,omitempty"`
}
type ExplorerUrls struct {
Tx string `yaml:"tx"`
Address string `yaml:"address"`
Token string `yaml:"token"`
}
// External ID's used by other vendors for the given chain
type External struct {
Dti string `yaml:"dti,omitempty"`
CoinMarketCap struct {
// CoinMarketCap's ID for the chain
ChainId string `yaml:"chain_id,omitempty"`
// CoinMarketCap's ID for the chain's native asset, also called "UCID"
AssetId string `yaml:"asset_id,omitempty"`
} `yaml:"coin_market_cap,omitempty"`
CoinGecko struct {
// TODO: is there a chain ID for coingecko?
ChainId string `yaml:"chain_id,omitempty"`
// Coingecko's asset ID, if relevant
AssetId string `yaml:"asset_id,omitempty"`
} `yaml:"coin_gecko,omitempty"`
IndexingCo struct {
ChainId string `yaml:"chain_id,omitempty"`
Disabled bool `yaml:"disabled,omitempty"`
} `yaml:"indexing_co,omitempty"`
}
type StakingConfig struct {
// the contract used for staking, if relevant
StakeContract string `yaml:"stake_contract,omitempty"`
// the contract used for unstaking, if relevant
UnstakeContract string `yaml:"unstake_contract,omitempty"`
// Compatible providers for staking
Providers []StakingProvider `yaml:"providers,omitempty"`
}
// Optional address configuration
type AddressConfig struct {
// All formats supported by chain, including default
Formats []AddressFormat `yaml:"formats,omitempty"`
}
type AdditionalNativeAsset struct {
// The asset ID of the asset to use
AssetId string `yaml:"asset_id,omitempty"`
// The native asset that this bridged asset corresponds to or settles in (e.g., "chains/ETH/assets/ETH" for OptEth or Eclipse)
BridgedAsset string `yaml:"bridged_asset,omitempty"`
// The on-chain contract ID of the asset
ContractId ContractAddress `yaml:"contract_id,omitempty"`
// Decimals for the asset
Decimals int32 `yaml:"decimals,omitempty"`
// Maximum fee limit
FeeLimit AmountHumanReadable `yaml:"fee_limit"`
Aliases []string `yaml:"aliases,omitempty"`
}
func NewAdditionalNativeAsset(assetId, bridgedAsset string, contractId ContractAddress, decimals int32, feeLimit AmountHumanReadable, aliases ...string) *AdditionalNativeAsset {
return &AdditionalNativeAsset{
assetId,
bridgedAsset,
contractId,
decimals,
feeLimit,
aliases,
}
}
func (na *AdditionalNativeAsset) HasAlias(alias string) bool {
return slices.Contains(na.Aliases, alias)
}
type CrosschainClientConfig struct {
Url string `yaml:"url"`
Network NetworkSelector `yaml:"network,omitempty"`
}
func (staking *StakingConfig) Enabled() bool {
return len(staking.Providers) > 0
}
func NewChainConfig(nativeAsset NativeAsset, driverMaybe ...Driver) *ChainConfig {
driver := nativeAsset.Driver()
if len(driverMaybe) > 0 {
driver = driverMaybe[0]
}
cfg := &ChainConfig{
ChainBaseConfig: &ChainBaseConfig{
Chain: nativeAsset,
Driver: driver,
},
ChainClientConfig: &ChainClientConfig{},
}
cfg.Configure(0)
return cfg
}
func (chain *ChainConfig) Base() *ChainBaseConfig {
return chain.ChainBaseConfig
}
func (chain *ChainConfig) Client() *ChainClientConfig {
return chain.ChainClientConfig
}
func (chain *ChainConfig) WithDriver(driver Driver) *ChainConfig {
chain.Driver = driver
return chain
}
func (chain *ChainConfig) WithDecimals(decimals int32) *ChainConfig {
chain.Decimals = decimals
return chain
}
func (chain *ChainConfig) WithUrl(url string) *ChainConfig {
chain.ChainClientConfig.URL = url
return chain
}
func (chain *ChainConfig) WithNet(net string) *ChainConfig {
chain.ChainBaseConfig.Network = net
return chain
}
func (chain *ChainConfig) WithChainCoin(chainCoin string) *ChainConfig {
chain.ChainBaseConfig.ChainCoin = chainCoin
return chain
}
func (chain *ChainConfig) WithChainPrefix(chainPrefix string) *ChainConfig {
chain.ChainBaseConfig.ChainPrefix = StringOrInt(chainPrefix)
return chain
}
func (chain *ChainConfig) WithProvider(provider string) *ChainConfig {
chain.ChainClientConfig.Provider = provider
return chain
}
func (chain *ChainConfig) WithMinGasPrice(minGasPrice float64) *ChainConfig {
chain.ChainClientConfig.ChainMinGasPrice = minGasPrice
return chain
}
func (chain *ChainConfig) WithMaxGasPrice(maxGasPrice float64) *ChainConfig {
chain.ChainClientConfig.ChainMaxGasPrice = maxGasPrice
return chain
}
func (chain *ChainConfig) WithFeeLimit(feeLimit AmountHumanReadable) *ChainConfig {
chain.FeeLimit = feeLimit
return chain
}
func (chain *ChainConfig) WithGasPriceMultiplier(multiplier float64) *ChainConfig {
chain.ChainClientConfig.ChainGasMultiplier = multiplier
return chain
}
func (chain *ChainConfig) WithGasBudgetDefault(gasBudgetDefault AmountHumanReadable) *ChainConfig {
chain.ChainClientConfig.GasBudgetDefault = gasBudgetDefault
return chain
}
func (chain *ChainConfig) WithAuth(auth config.Secret) *ChainConfig {
chain.ChainClientConfig.Auth2 = auth
return chain
}
func (chain *ChainConfig) WithChainID(chainID string) *ChainConfig {
chain.ChainID = StringOrInt(chainID)
return chain
}
func (chain *ChainConfig) WithIndexer(indexerType string, url string) *ChainConfig {
chain.IndexerType = indexerType
chain.IndexerUrl = url
return chain
}
func (chain *ChainConfig) WithTransactionActiveTime(transactionActiveTime time.Duration) *ChainConfig {
chain.TransactionActiveTime = transactionActiveTime
return chain
}
func (chain *ChainConfig) WithHttpTimeout(httpTimeout time.Duration) *ChainConfig {
chain.HttpTimeout = httpTimeout
return chain
}
func (chain *ChainConfig) DefaultHttpClient() *http.Client {
timeout := chain.HttpTimeout
if timeout <= 0 {
// default timeout
timeout = time.Second * 60
}
return &http.Client{
Timeout: timeout,
}
}
type ChainConfig struct {
*ChainBaseConfig `yaml:",inline"`
*ChainClientConfig `yaml:",inline"`
}
type ChainBaseConfig struct {
// The crosschain symbol of the chain
Chain NativeAsset `yaml:"chain,omitempty"`
// The driver to use for the chain
Driver Driver `yaml:"driver,omitempty"`
// The network selector, if necessary (e.g. select mainnet, testnet, or devnet for bitcoin chains)
Network string `yaml:"net,omitempty"`
// Decimals for the chain's native asset (if it has one).
Decimals int32 `yaml:"decimals,omitempty"`
// The ChainID of the chain, either in integer or string format
ChainID StringOrInt `yaml:"chain_id,omitempty"`
// Human readable name of the chain, e.g. "Bitcoin"
ChainName string `yaml:"chain_name,omitempty"`
// Does the chain use a special prefix for it's address?
// E.g. most cosmos chains do this.
ChainPrefix StringOrInt `yaml:"chain_prefix,omitempty"`
// If the chain has a native asset, and it has an actual contract address, it should be set here.
// This is also referred to as the "ContractID".
// E.g.
// - APTOS has 0x1::aptos_coin::AptosCoin
// - INJ has inj
// - HASH has nhash
// - LUNA has uluna
ChainCoin string `yaml:"chain_coin,omitempty"`
// Additional native assets that may be used to pay fees on the chain.
NativeAssets []*AdditionalNativeAsset `yaml:"native_assets,omitempty"`
// If true, then the `.Chain` does not represent any native asset (i.e. no chain-coin, no decimals).
NoNativeAsset bool `yaml:"no_native_asset,omitempty"`
// If necessary, specific which asset to use to spend for gas.
GasCoin string `yaml:"gas_coin,omitempty"`
// Indicate if this chain should not be included.
Disabled *bool `yaml:"disabled,omitempty"`
// Staking configuration
Staking StakingConfig `yaml:"staking,omitempty"`
// Maximum total fee limit: required for caller to make use of with `TxInput.GetFeeLimit()`
FeeLimit AmountHumanReadable `yaml:"fee_limit,omitempty"`
// Transfer tax is percentage that the network takes from every transfer .. only used so far for Terra Classic
ChainTransferTax float64 `yaml:"chain_transfer_tax,omitempty"`
// Used only for deriving private keys from mnemonic phrases in local testing
ChainCoinHDPath uint32 `yaml:"chain_coin_hd_path,omitempty"`
// Should use `ChainID` instead
XChainIDStr string `yaml:"chain_id_str,omitempty"`
// Optional address configuration
Address AddressConfig `yaml:"address,omitempty"`
}
func (chain *ChainConfig) Configure(httpTimeout time.Duration) {
chain.ChainClientConfig.Configure()
if chain.XChainIDStr != "" {
logrus.Warnf("chain_id_str is deprecated, use chain_id instead")
chain.ChainID = StringOrInt(chain.XChainIDStr)
}
if chain.HttpTimeout <= 0 {
// use the global configuration default
chain.HttpTimeout = httpTimeout
}
}
type ConfirmationsConfig struct {
Final int `yaml:"final,omitempty"`
Tracked int `yaml:"tracked,omitempty"`
}
type ChainClientConfig struct {
////////////////////////////////
///// RPC / CLIENT CONFIGURATION
////////////////////////////////
URL string `yaml:"url,omitempty"`
SecondaryURL string `yaml:"secondary_url,omitempty"`
// Set a secret reference, see config/secret.go. Used for setting an API keys.
Auth2 config.Secret `yaml:"auth,omitempty"`
// Optional configuration of the Driver. Some chains support different kinds of RPC.
Provider string `yaml:"provider,omitempty"`
CrosschainClient CrosschainClientConfig `yaml:"crosschain_client"`
// Does the chain rely on an indexer in addition to RPC? If so, the URL and type
// may be set here.
IndexerUrl string `yaml:"indexer_url,omitempty"`
IndexerType string `yaml:"indexer_type,omitempty"`
// Maximun depth to scan for transaction, if there is no index to use (substrate...)
MaxScanDepth int `yaml:"max_scan_depth,omitempty"`
NoGasFees bool `yaml:"no_gas_fees,omitempty"`
// Default gas budget to use for client gas estimation
GasBudgetDefault AmountHumanReadable `yaml:"gas_budget_default,omitempty"`
// Gas budget that cannot be exceeded below
GasBudgetMinimum AmountHumanReadable `yaml:"gas_budget_min,omitempty"`
// A remainder balance (e.g. rent threshold) that must be maintained after a transfer.
ReserveAmount AmountHumanReadable `yaml:"reserve_amount,omitempty"`
// A default for clients to gas price if there's not better way to estimate.
ChainGasPriceDefault float64 `yaml:"chain_gas_price_default,omitempty"`
// A local multiplier for client to apply to gas estimation, if it's important/needed.
ChainGasMultiplier float64 `yaml:"chain_gas_multiplier,omitempty"`
SecondaryChainGasMultiplier float64 `yaml:"secondary_chain_gas_multiplier,omitempty"`
// for gas estimation of gas limit, for somechains the simulation may be flaky and need a multiplier
ChainGasLimitMultiplier float64 `yaml:"chain_gas_limit_multiplier,omitempty"`
// The multiplier to apply to gas when there is a minimum replacement increase.
// This is used for EVM chains, to avoid the "replacement transaction underpriced" message.
// Normally it is 10%, but on chains like Base and Optimism, it seems to be at least 25% in practice.
ReplacementTransactionMultiplier float64 `yaml:"replacement_transaction_multiplier,omitempty"`
// The max/min prices can be set to provide sanity limits for what a gas price (per gas or per byte) should be.
// This should be in the blockchain amount.
ChainMaxGasPrice float64 `yaml:"chain_max_gas_price,omitempty"`
ChainMinGasPrice float64 `yaml:"chain_min_gas_price,omitempty"`
// Default gas limit for transactions
GasLimitDefault int `yaml:"gas_limit_default,omitempty"`
// TransactionActiveTime specifies the duration for which a transaction remains valid after being submitted.
// The value is represented as a `time.Duration` string.
// This field is currently used only by the Stellar network.
//
// Example format: "30s" (30 seconds), "2m" (2 minutes), "1h" (1 hour).
TransactionActiveTime time.Duration `yaml:"transaction_active_time,omitempty"`
// How many confirmations is considered "final" for this chain?
XConfirmationsFinal int `yaml:"confirmations_final,omitempty"`
Confirmations ConfirmationsConfig `yaml:"confirmations,omitempty"`
// Gas price oracle address
// Currently this is used for EVM L2 chains that have an additional "l1" fee.
GasPriceOracleAddress string `yaml:"gas_price_oracle_address,omitempty"`
// Rate limit setting on RPC requests for client, in requests/second.
RateLimit rate.Limit `yaml:"rate_limit,omitempty"`
// Period between requests (alternative to `rate_limit`)
PeriodLimit time.Duration `yaml:"period_limit,omitempty"`
// Number of requests to permit in burst
Burst int `yaml:"burst,omitempty"`
// Rate limiter configured from `rate_limit`, `period_limit`, `burst` (requires calling .Configure after loading from config)
Limiter *rate.Limiter `yaml:"-" mapstructure:"-"`
// HTTP timeout for the client (will default to global factory configuration)
HttpTimeout time.Duration `yaml:"http_timeout,omitempty"`
// Additional metadata. Not Used in crosschain itself, but helpful to enrich API endpoints.
External External `yaml:"external,omitempty"`
// Informational URLs for the chain explorers.
ExplorerUrls ExplorerUrls `yaml:"explorer_urls,omitempty"`
// If true, this means that the chain is not intended for future use and
// is only maintained for legacy purposes (by the upstream community).
// E.g. "Terra Classic" or "Fantom" are legacy chains that each have replacements.
Legacy bool `yaml:"legacy,omitempty"`
// Indicate to the driver if additional information should be included for older crosschain clients.
IncludeLegacyInformation bool `yaml:"include_legacy_information,omitempty"`
// If true, the client will only use confirmed UTXOs for unspent output queries.
ConfirmedUtxo bool `yaml:"confirmed_utxo,omitempty"`
}
func (chain *ChainClientConfig) NewClientLimiter() *rate.Limiter {
// default no limit
burst := chain.Burst
var limiter = rate.NewLimiter(rate.Inf, burst)
if chain.PeriodLimit != 0 {
limiter = rate.NewLimiter(rate.Every(chain.PeriodLimit), burst)
}
if chain.RateLimit != 0 {
limiter = rate.NewLimiter(chain.RateLimit, burst)
}
return limiter
}
func (chain *ChainClientConfig) Configure() {
chain.Limiter = chain.NewClientLimiter()
if chain.Confirmations.Final == 0 {
chain.Confirmations.Final = chain.XConfirmationsFinal
}
}
var _ ITask = &ChainConfig{}
func (c ChainConfig) String() string {
secretRef := string(c.Auth2)
if !config.HasTypePrefix(secretRef) || strings.HasPrefix(secretRef, string(config.Raw)) {
secretRef = "<REDACTED>"
}
return fmt.Sprintf(
"NativeAssetConfig(asset=%s chainId=%s driver=%s chainCoin=%s prefix=%s net=%s url=%s auth=%s provider=%s)",
c.Chain, c.ChainID, c.Driver, c.ChainCoin, c.ChainPrefix, c.Network, c.URL, secretRef, c.Provider,
)
}
func (asset *ChainConfig) GetDecimals() int32 {
return asset.Decimals
}
func (asset *ChainConfig) GetChain() *ChainConfig {
return asset
}
func (native *ChainConfig) GetContract() string {
return ""
}
func (native *ChainConfig) GetAssetSymbol() string {
return string(native.Chain)
}
// Returns URL and driver used for the client. This will either
// Be the chain driver, or the 'special' crosschain driver.
func (native *ChainConfig) ClientURL() (string, Driver) {
if native.URL == "" || native.URL == "-" {
if native.CrosschainClient.Url != "" {
return native.CrosschainClient.Url, DriverCrosschain
}
return "https://connector.cordialapis.com", DriverCrosschain
}
return native.URL, native.Driver
}
func (native *ChainConfig) IsChain(contract ContractAddress) bool {
return contract == "" || native.Chain == NativeAsset(contract)
}
func (native *ChainConfig) FindAdditionalNativeAsset(contract ContractAddress) (*AdditionalNativeAsset, bool) {
for _, asset := range native.NativeAssets {
if asset.ContractId == contract {
return asset, true
}
if slices.Contains(asset.Aliases, string(contract)) {
return asset, true
}
}
return nil, false
}