@xchainjs/xchain-aggregator 2.0.25 → 2.0.27
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/lib/const.d.ts +1 -1
- package/lib/index.esm.js +108 -11
- package/lib/index.js +108 -11
- package/lib/protocols/chainflip/chainflipProtocol.d.ts +1 -1
- package/lib/types.d.ts +16 -0
- package/package.json +8 -8
package/lib/const.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Config, Protocol } from './types';
|
|
2
2
|
export declare const SupportedProtocols: Protocol[];
|
|
3
|
-
export declare const DEFAULT_CONFIG: Required<Omit<Config, 'wallet' | 'affiliate'>>;
|
|
3
|
+
export declare const DEFAULT_CONFIG: Required<Omit<Config, 'wallet' | 'affiliate' | 'brokerUrl'>>;
|
package/lib/index.esm.js
CHANGED
|
@@ -44,6 +44,7 @@ const SupportedProtocols = ['Thorchain', 'Mayachain', 'Chainflip'];
|
|
|
44
44
|
const DEFAULT_CONFIG = {
|
|
45
45
|
protocols: SupportedProtocols,
|
|
46
46
|
network: Network.Mainnet,
|
|
47
|
+
affiliateBrokers: [],
|
|
47
48
|
};
|
|
48
49
|
|
|
49
50
|
const cChainToXChain = (chain) => {
|
|
@@ -52,8 +53,6 @@ const cChainToXChain = (chain) => {
|
|
|
52
53
|
return 'BTC';
|
|
53
54
|
case 'Ethereum':
|
|
54
55
|
return 'ETH';
|
|
55
|
-
case 'Polkadot':
|
|
56
|
-
return 'POL';
|
|
57
56
|
case 'Arbitrum':
|
|
58
57
|
return 'ARB';
|
|
59
58
|
case 'Solana':
|
|
@@ -77,9 +76,10 @@ class ChainflipProtocol {
|
|
|
77
76
|
enabledFeatures: {
|
|
78
77
|
dca: true,
|
|
79
78
|
},
|
|
79
|
+
broker: (configuration === null || configuration === void 0 ? void 0 : configuration.brokerUrl) ? { url: configuration.brokerUrl } : undefined,
|
|
80
80
|
});
|
|
81
81
|
this.wallet = configuration === null || configuration === void 0 ? void 0 : configuration.wallet;
|
|
82
|
-
this.
|
|
82
|
+
this.affiliateBrokers = configuration === null || configuration === void 0 ? void 0 : configuration.affiliateBrokers;
|
|
83
83
|
this.assetsData = new CachedValue(() => {
|
|
84
84
|
return this.sdk.getAssets();
|
|
85
85
|
}, 24 * 60 * 60 * 1000);
|
|
@@ -139,6 +139,7 @@ class ChainflipProtocol {
|
|
|
139
139
|
destChain: destAssetData.chain,
|
|
140
140
|
destAsset: destAssetData.asset,
|
|
141
141
|
amount: params.amount.baseAmount.amount().toString(),
|
|
142
|
+
affiliateBrokers: this.affiliateBrokers,
|
|
142
143
|
});
|
|
143
144
|
// Find either DCA or REGULAR quote, prioritizing DCA
|
|
144
145
|
const selectedQuote = quotes.find((quote) => quote.type === 'DCA') || quotes.find((quote) => quote.type === 'REGULAR');
|
|
@@ -152,7 +153,7 @@ class ChainflipProtocol {
|
|
|
152
153
|
refundAddress: params.fromAddress,
|
|
153
154
|
retryDurationBlocks: 100,
|
|
154
155
|
},
|
|
155
|
-
|
|
156
|
+
affiliateBrokers: this.affiliateBrokers,
|
|
156
157
|
});
|
|
157
158
|
toAddress = resp.depositAddress;
|
|
158
159
|
depositChannelId = resp.depositChannelId;
|
|
@@ -167,7 +168,7 @@ class ChainflipProtocol {
|
|
|
167
168
|
refundAddress: params.fromAddress,
|
|
168
169
|
retryDurationBlocks: 100,
|
|
169
170
|
},
|
|
170
|
-
|
|
171
|
+
affiliateBrokers: this.affiliateBrokers,
|
|
171
172
|
});
|
|
172
173
|
toAddress = resp.depositAddress;
|
|
173
174
|
depositChannelId = resp.depositChannelId;
|
|
@@ -6658,8 +6659,17 @@ class MayachainProtocol {
|
|
|
6658
6659
|
return false;
|
|
6659
6660
|
if (eqAsset(asset, AssetCacao) || isSynthAsset(asset))
|
|
6660
6661
|
return true;
|
|
6661
|
-
|
|
6662
|
-
|
|
6662
|
+
try {
|
|
6663
|
+
const pools = yield this.mayachainQuery.getPools();
|
|
6664
|
+
return (pools.findIndex((pool) => pool.status === 'available' && eqAsset(asset, assetFromStringEx(pool.asset))) !== -1);
|
|
6665
|
+
}
|
|
6666
|
+
catch (error) {
|
|
6667
|
+
// Optimistic fallback: if Mayamidgard is down, assume asset is supported
|
|
6668
|
+
// This allows quoting to continue - if the asset isn't actually supported,
|
|
6669
|
+
// the quote estimation will fail gracefully with appropriate error messages
|
|
6670
|
+
console.warn(`Mayamidgard unavailable for asset validation, optimistically assuming ${asset.chain}.${asset.symbol} is supported:`, error);
|
|
6671
|
+
return true;
|
|
6672
|
+
}
|
|
6663
6673
|
});
|
|
6664
6674
|
}
|
|
6665
6675
|
/**
|
|
@@ -8960,6 +8970,75 @@ class MidgardQuery {
|
|
|
8960
8970
|
return pool;
|
|
8961
8971
|
});
|
|
8962
8972
|
}
|
|
8973
|
+
/**
|
|
8974
|
+
* Provides fallback decimal values for common assets when Midgard is unavailable.
|
|
8975
|
+
* @param {CompatibleAsset} asset - The asset to get fallback decimals for.
|
|
8976
|
+
* @returns {number} - Standard decimal places for the asset.
|
|
8977
|
+
*/
|
|
8978
|
+
getFallbackDecimals(asset) {
|
|
8979
|
+
const assetString = assetToString(asset);
|
|
8980
|
+
// Map of assets to their actual decimal places from THORChain pools
|
|
8981
|
+
// Data sourced from https://thornode-v2.ninerealms.com/thorchain/pools
|
|
8982
|
+
const fallbackDecimalMap = {
|
|
8983
|
+
// Bitcoin and forks
|
|
8984
|
+
'BTC.BTC': 8,
|
|
8985
|
+
'BCH.BCH': 8,
|
|
8986
|
+
'LTC.LTC': 8,
|
|
8987
|
+
'DOGE.DOGE': 8,
|
|
8988
|
+
// Ethereum and tokens
|
|
8989
|
+
'ETH.ETH': 18,
|
|
8990
|
+
'ETH.USDT-0xdAC17F958D2ee523a2206206994597C13D831ec7': 6,
|
|
8991
|
+
'ETH.USDC-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48': 6,
|
|
8992
|
+
'ETH.DAI-0x6B175474E89094C44Da98b954EedeAC495271d0F': 18,
|
|
8993
|
+
'ETH.WBTC-0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599': 8,
|
|
8994
|
+
'ETH.GUSD-0x056Fd409E1d7A124BD7017459dFEa2F387b6d5Cd': 2,
|
|
8995
|
+
// Binance Smart Chain
|
|
8996
|
+
'BSC.BNB': 18,
|
|
8997
|
+
'BSC.BUSD-0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56': 18,
|
|
8998
|
+
'BSC.USDT-0x55d398326f99059fF775485246999027B3197955': 6,
|
|
8999
|
+
'BSC.USDC-0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d': 6,
|
|
9000
|
+
// Cosmos ecosystem
|
|
9001
|
+
'GAIA.ATOM': 6,
|
|
9002
|
+
// Avalanche
|
|
9003
|
+
'AVAX.AVAX': 18,
|
|
9004
|
+
'AVAX.USDC-0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E': 6,
|
|
9005
|
+
'AVAX.USDT-0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7': 6,
|
|
9006
|
+
// Base
|
|
9007
|
+
'BASE.USDC-0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913': 6,
|
|
9008
|
+
// Tron
|
|
9009
|
+
'TRON.TRX': 6,
|
|
9010
|
+
'TRON.USDT-0xdAC17F958D2ee523a2206206994597C13D831ec7': 6,
|
|
9011
|
+
// XRP
|
|
9012
|
+
'XRP.XRP': 6,
|
|
9013
|
+
};
|
|
9014
|
+
// Return specific fallback or use chain-based defaults
|
|
9015
|
+
if (fallbackDecimalMap[assetString]) {
|
|
9016
|
+
return fallbackDecimalMap[assetString];
|
|
9017
|
+
}
|
|
9018
|
+
// Chain-based fallback decimals based on typical chain standards
|
|
9019
|
+
const chainDefaults = {
|
|
9020
|
+
BTC: 8,
|
|
9021
|
+
BCH: 8,
|
|
9022
|
+
LTC: 8,
|
|
9023
|
+
DOGE: 8,
|
|
9024
|
+
ETH: 18,
|
|
9025
|
+
BSC: 18,
|
|
9026
|
+
BNB: 8,
|
|
9027
|
+
GAIA: 6,
|
|
9028
|
+
AVAX: 18,
|
|
9029
|
+
BASE: 18,
|
|
9030
|
+
TRON: 6,
|
|
9031
|
+
XRP: 6,
|
|
9032
|
+
THOR: DEFAULT_THORCHAIN_DECIMALS,
|
|
9033
|
+
};
|
|
9034
|
+
const chainDefault = chainDefaults[asset.chain];
|
|
9035
|
+
if (chainDefault !== undefined) {
|
|
9036
|
+
return chainDefault;
|
|
9037
|
+
}
|
|
9038
|
+
// Ultimate fallback - use 8 decimals (most common for crypto)
|
|
9039
|
+
console.warn(`No fallback decimal configured for ${assetString}, using 8 decimals`);
|
|
9040
|
+
return 8;
|
|
9041
|
+
}
|
|
8963
9042
|
/**
|
|
8964
9043
|
* Get saver positions by an array of saver descriptions.
|
|
8965
9044
|
*
|
|
@@ -9015,8 +9094,15 @@ class MidgardQuery {
|
|
|
9015
9094
|
}
|
|
9016
9095
|
if (isAssetRuneNative(asset) || isSynthAsset(asset) || isTradeAsset(asset) || isSecuredAsset(asset))
|
|
9017
9096
|
return DEFAULT_THORCHAIN_DECIMALS;
|
|
9018
|
-
|
|
9019
|
-
|
|
9097
|
+
try {
|
|
9098
|
+
const pool = yield this.getPool(assetToString(asset));
|
|
9099
|
+
return Number(pool.nativeDecimal);
|
|
9100
|
+
}
|
|
9101
|
+
catch (error) {
|
|
9102
|
+
// Fallback: if Midgard is down, use standard decimal values for common assets
|
|
9103
|
+
console.warn(`Midgard unavailable for decimal lookup, using fallback for ${assetToString(asset)}:`, error);
|
|
9104
|
+
return this.getFallbackDecimals(asset);
|
|
9105
|
+
}
|
|
9020
9106
|
});
|
|
9021
9107
|
}
|
|
9022
9108
|
/**
|
|
@@ -9114,8 +9200,17 @@ class ThorchainProtocol {
|
|
|
9114
9200
|
return __awaiter$4(this, void 0, void 0, function* () {
|
|
9115
9201
|
if (eqAsset(asset, AssetRuneNative$1) || isTradeAsset(asset) || isSynthAsset(asset) || isSecuredAsset(asset))
|
|
9116
9202
|
return true;
|
|
9117
|
-
|
|
9118
|
-
|
|
9203
|
+
try {
|
|
9204
|
+
const pools = yield this.thorchainQuery.thorchainCache.getPools();
|
|
9205
|
+
return (Object.values(pools).findIndex((pool) => pool.isAvailable() && assetToString(asset) === pool.assetString) !== -1);
|
|
9206
|
+
}
|
|
9207
|
+
catch (error) {
|
|
9208
|
+
// Optimistic fallback: if Midgard is down, assume asset is supported
|
|
9209
|
+
// This allows quoting to continue - if the asset isn't actually supported,
|
|
9210
|
+
// the quote estimation will fail gracefully with appropriate error messages
|
|
9211
|
+
console.warn(`Midgard unavailable for asset validation, optimistically assuming ${assetToString(asset)} is supported:`, error);
|
|
9212
|
+
return true;
|
|
9213
|
+
}
|
|
9119
9214
|
});
|
|
9120
9215
|
}
|
|
9121
9216
|
/**
|
|
@@ -9192,6 +9287,8 @@ const getProtocolConfig = (name, configuration) => {
|
|
|
9192
9287
|
affiliateAddress: (_a = configuration.affiliate) === null || _a === void 0 ? void 0 : _a.affiliates[name],
|
|
9193
9288
|
affiliateBps: ((_b = configuration.affiliate) === null || _b === void 0 ? void 0 : _b.affiliates[name]) ? configuration.affiliate.basisPoints : undefined,
|
|
9194
9289
|
network: configuration.network,
|
|
9290
|
+
affiliateBrokers: configuration.affiliateBrokers,
|
|
9291
|
+
brokerUrl: configuration.brokerUrl,
|
|
9195
9292
|
};
|
|
9196
9293
|
};
|
|
9197
9294
|
class ProtocolFactory {
|
package/lib/index.js
CHANGED
|
@@ -46,6 +46,7 @@ const SupportedProtocols = ['Thorchain', 'Mayachain', 'Chainflip'];
|
|
|
46
46
|
const DEFAULT_CONFIG = {
|
|
47
47
|
protocols: SupportedProtocols,
|
|
48
48
|
network: xchainClient.Network.Mainnet,
|
|
49
|
+
affiliateBrokers: [],
|
|
49
50
|
};
|
|
50
51
|
|
|
51
52
|
const cChainToXChain = (chain) => {
|
|
@@ -54,8 +55,6 @@ const cChainToXChain = (chain) => {
|
|
|
54
55
|
return 'BTC';
|
|
55
56
|
case 'Ethereum':
|
|
56
57
|
return 'ETH';
|
|
57
|
-
case 'Polkadot':
|
|
58
|
-
return 'POL';
|
|
59
58
|
case 'Arbitrum':
|
|
60
59
|
return 'ARB';
|
|
61
60
|
case 'Solana':
|
|
@@ -79,9 +78,10 @@ class ChainflipProtocol {
|
|
|
79
78
|
enabledFeatures: {
|
|
80
79
|
dca: true,
|
|
81
80
|
},
|
|
81
|
+
broker: (configuration === null || configuration === void 0 ? void 0 : configuration.brokerUrl) ? { url: configuration.brokerUrl } : undefined,
|
|
82
82
|
});
|
|
83
83
|
this.wallet = configuration === null || configuration === void 0 ? void 0 : configuration.wallet;
|
|
84
|
-
this.
|
|
84
|
+
this.affiliateBrokers = configuration === null || configuration === void 0 ? void 0 : configuration.affiliateBrokers;
|
|
85
85
|
this.assetsData = new xchainUtil.CachedValue(() => {
|
|
86
86
|
return this.sdk.getAssets();
|
|
87
87
|
}, 24 * 60 * 60 * 1000);
|
|
@@ -141,6 +141,7 @@ class ChainflipProtocol {
|
|
|
141
141
|
destChain: destAssetData.chain,
|
|
142
142
|
destAsset: destAssetData.asset,
|
|
143
143
|
amount: params.amount.baseAmount.amount().toString(),
|
|
144
|
+
affiliateBrokers: this.affiliateBrokers,
|
|
144
145
|
});
|
|
145
146
|
// Find either DCA or REGULAR quote, prioritizing DCA
|
|
146
147
|
const selectedQuote = quotes.find((quote) => quote.type === 'DCA') || quotes.find((quote) => quote.type === 'REGULAR');
|
|
@@ -154,7 +155,7 @@ class ChainflipProtocol {
|
|
|
154
155
|
refundAddress: params.fromAddress,
|
|
155
156
|
retryDurationBlocks: 100,
|
|
156
157
|
},
|
|
157
|
-
|
|
158
|
+
affiliateBrokers: this.affiliateBrokers,
|
|
158
159
|
});
|
|
159
160
|
toAddress = resp.depositAddress;
|
|
160
161
|
depositChannelId = resp.depositChannelId;
|
|
@@ -169,7 +170,7 @@ class ChainflipProtocol {
|
|
|
169
170
|
refundAddress: params.fromAddress,
|
|
170
171
|
retryDurationBlocks: 100,
|
|
171
172
|
},
|
|
172
|
-
|
|
173
|
+
affiliateBrokers: this.affiliateBrokers,
|
|
173
174
|
});
|
|
174
175
|
toAddress = resp.depositAddress;
|
|
175
176
|
depositChannelId = resp.depositChannelId;
|
|
@@ -6660,8 +6661,17 @@ class MayachainProtocol {
|
|
|
6660
6661
|
return false;
|
|
6661
6662
|
if (xchainUtil.eqAsset(asset, xchainMayachain.AssetCacao) || xchainUtil.isSynthAsset(asset))
|
|
6662
6663
|
return true;
|
|
6663
|
-
|
|
6664
|
-
|
|
6664
|
+
try {
|
|
6665
|
+
const pools = yield this.mayachainQuery.getPools();
|
|
6666
|
+
return (pools.findIndex((pool) => pool.status === 'available' && xchainUtil.eqAsset(asset, xchainUtil.assetFromStringEx(pool.asset))) !== -1);
|
|
6667
|
+
}
|
|
6668
|
+
catch (error) {
|
|
6669
|
+
// Optimistic fallback: if Mayamidgard is down, assume asset is supported
|
|
6670
|
+
// This allows quoting to continue - if the asset isn't actually supported,
|
|
6671
|
+
// the quote estimation will fail gracefully with appropriate error messages
|
|
6672
|
+
console.warn(`Mayamidgard unavailable for asset validation, optimistically assuming ${asset.chain}.${asset.symbol} is supported:`, error);
|
|
6673
|
+
return true;
|
|
6674
|
+
}
|
|
6665
6675
|
});
|
|
6666
6676
|
}
|
|
6667
6677
|
/**
|
|
@@ -8962,6 +8972,75 @@ class MidgardQuery {
|
|
|
8962
8972
|
return pool;
|
|
8963
8973
|
});
|
|
8964
8974
|
}
|
|
8975
|
+
/**
|
|
8976
|
+
* Provides fallback decimal values for common assets when Midgard is unavailable.
|
|
8977
|
+
* @param {CompatibleAsset} asset - The asset to get fallback decimals for.
|
|
8978
|
+
* @returns {number} - Standard decimal places for the asset.
|
|
8979
|
+
*/
|
|
8980
|
+
getFallbackDecimals(asset) {
|
|
8981
|
+
const assetString = xchainUtil.assetToString(asset);
|
|
8982
|
+
// Map of assets to their actual decimal places from THORChain pools
|
|
8983
|
+
// Data sourced from https://thornode-v2.ninerealms.com/thorchain/pools
|
|
8984
|
+
const fallbackDecimalMap = {
|
|
8985
|
+
// Bitcoin and forks
|
|
8986
|
+
'BTC.BTC': 8,
|
|
8987
|
+
'BCH.BCH': 8,
|
|
8988
|
+
'LTC.LTC': 8,
|
|
8989
|
+
'DOGE.DOGE': 8,
|
|
8990
|
+
// Ethereum and tokens
|
|
8991
|
+
'ETH.ETH': 18,
|
|
8992
|
+
'ETH.USDT-0xdAC17F958D2ee523a2206206994597C13D831ec7': 6,
|
|
8993
|
+
'ETH.USDC-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48': 6,
|
|
8994
|
+
'ETH.DAI-0x6B175474E89094C44Da98b954EedeAC495271d0F': 18,
|
|
8995
|
+
'ETH.WBTC-0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599': 8,
|
|
8996
|
+
'ETH.GUSD-0x056Fd409E1d7A124BD7017459dFEa2F387b6d5Cd': 2,
|
|
8997
|
+
// Binance Smart Chain
|
|
8998
|
+
'BSC.BNB': 18,
|
|
8999
|
+
'BSC.BUSD-0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56': 18,
|
|
9000
|
+
'BSC.USDT-0x55d398326f99059fF775485246999027B3197955': 6,
|
|
9001
|
+
'BSC.USDC-0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d': 6,
|
|
9002
|
+
// Cosmos ecosystem
|
|
9003
|
+
'GAIA.ATOM': 6,
|
|
9004
|
+
// Avalanche
|
|
9005
|
+
'AVAX.AVAX': 18,
|
|
9006
|
+
'AVAX.USDC-0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E': 6,
|
|
9007
|
+
'AVAX.USDT-0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7': 6,
|
|
9008
|
+
// Base
|
|
9009
|
+
'BASE.USDC-0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913': 6,
|
|
9010
|
+
// Tron
|
|
9011
|
+
'TRON.TRX': 6,
|
|
9012
|
+
'TRON.USDT-0xdAC17F958D2ee523a2206206994597C13D831ec7': 6,
|
|
9013
|
+
// XRP
|
|
9014
|
+
'XRP.XRP': 6,
|
|
9015
|
+
};
|
|
9016
|
+
// Return specific fallback or use chain-based defaults
|
|
9017
|
+
if (fallbackDecimalMap[assetString]) {
|
|
9018
|
+
return fallbackDecimalMap[assetString];
|
|
9019
|
+
}
|
|
9020
|
+
// Chain-based fallback decimals based on typical chain standards
|
|
9021
|
+
const chainDefaults = {
|
|
9022
|
+
BTC: 8,
|
|
9023
|
+
BCH: 8,
|
|
9024
|
+
LTC: 8,
|
|
9025
|
+
DOGE: 8,
|
|
9026
|
+
ETH: 18,
|
|
9027
|
+
BSC: 18,
|
|
9028
|
+
BNB: 8,
|
|
9029
|
+
GAIA: 6,
|
|
9030
|
+
AVAX: 18,
|
|
9031
|
+
BASE: 18,
|
|
9032
|
+
TRON: 6,
|
|
9033
|
+
XRP: 6,
|
|
9034
|
+
THOR: DEFAULT_THORCHAIN_DECIMALS,
|
|
9035
|
+
};
|
|
9036
|
+
const chainDefault = chainDefaults[asset.chain];
|
|
9037
|
+
if (chainDefault !== undefined) {
|
|
9038
|
+
return chainDefault;
|
|
9039
|
+
}
|
|
9040
|
+
// Ultimate fallback - use 8 decimals (most common for crypto)
|
|
9041
|
+
console.warn(`No fallback decimal configured for ${assetString}, using 8 decimals`);
|
|
9042
|
+
return 8;
|
|
9043
|
+
}
|
|
8965
9044
|
/**
|
|
8966
9045
|
* Get saver positions by an array of saver descriptions.
|
|
8967
9046
|
*
|
|
@@ -9017,8 +9096,15 @@ class MidgardQuery {
|
|
|
9017
9096
|
}
|
|
9018
9097
|
if (isAssetRuneNative(asset) || xchainUtil.isSynthAsset(asset) || xchainUtil.isTradeAsset(asset) || xchainUtil.isSecuredAsset(asset))
|
|
9019
9098
|
return DEFAULT_THORCHAIN_DECIMALS;
|
|
9020
|
-
|
|
9021
|
-
|
|
9099
|
+
try {
|
|
9100
|
+
const pool = yield this.getPool(xchainUtil.assetToString(asset));
|
|
9101
|
+
return Number(pool.nativeDecimal);
|
|
9102
|
+
}
|
|
9103
|
+
catch (error) {
|
|
9104
|
+
// Fallback: if Midgard is down, use standard decimal values for common assets
|
|
9105
|
+
console.warn(`Midgard unavailable for decimal lookup, using fallback for ${xchainUtil.assetToString(asset)}:`, error);
|
|
9106
|
+
return this.getFallbackDecimals(asset);
|
|
9107
|
+
}
|
|
9022
9108
|
});
|
|
9023
9109
|
}
|
|
9024
9110
|
/**
|
|
@@ -9116,8 +9202,17 @@ class ThorchainProtocol {
|
|
|
9116
9202
|
return __awaiter$4(this, void 0, void 0, function* () {
|
|
9117
9203
|
if (xchainUtil.eqAsset(asset, xchainThorchain.AssetRuneNative) || xchainUtil.isTradeAsset(asset) || xchainUtil.isSynthAsset(asset) || xchainUtil.isSecuredAsset(asset))
|
|
9118
9204
|
return true;
|
|
9119
|
-
|
|
9120
|
-
|
|
9205
|
+
try {
|
|
9206
|
+
const pools = yield this.thorchainQuery.thorchainCache.getPools();
|
|
9207
|
+
return (Object.values(pools).findIndex((pool) => pool.isAvailable() && xchainUtil.assetToString(asset) === pool.assetString) !== -1);
|
|
9208
|
+
}
|
|
9209
|
+
catch (error) {
|
|
9210
|
+
// Optimistic fallback: if Midgard is down, assume asset is supported
|
|
9211
|
+
// This allows quoting to continue - if the asset isn't actually supported,
|
|
9212
|
+
// the quote estimation will fail gracefully with appropriate error messages
|
|
9213
|
+
console.warn(`Midgard unavailable for asset validation, optimistically assuming ${xchainUtil.assetToString(asset)} is supported:`, error);
|
|
9214
|
+
return true;
|
|
9215
|
+
}
|
|
9121
9216
|
});
|
|
9122
9217
|
}
|
|
9123
9218
|
/**
|
|
@@ -9194,6 +9289,8 @@ const getProtocolConfig = (name, configuration) => {
|
|
|
9194
9289
|
affiliateAddress: (_a = configuration.affiliate) === null || _a === void 0 ? void 0 : _a.affiliates[name],
|
|
9195
9290
|
affiliateBps: ((_b = configuration.affiliate) === null || _b === void 0 ? void 0 : _b.affiliates[name]) ? configuration.affiliate.basisPoints : undefined,
|
|
9196
9291
|
network: configuration.network,
|
|
9292
|
+
affiliateBrokers: configuration.affiliateBrokers,
|
|
9293
|
+
brokerUrl: configuration.brokerUrl,
|
|
9197
9294
|
};
|
|
9198
9295
|
};
|
|
9199
9296
|
class ProtocolFactory {
|
|
@@ -8,7 +8,7 @@ export declare class ChainflipProtocol implements IProtocol {
|
|
|
8
8
|
private sdk;
|
|
9
9
|
private wallet?;
|
|
10
10
|
private assetsData;
|
|
11
|
-
private
|
|
11
|
+
private affiliateBrokers?;
|
|
12
12
|
constructor(configuration?: ProtocolConfig);
|
|
13
13
|
approveRouterToSpend(_params: {
|
|
14
14
|
asset: TokenAsset;
|
package/lib/types.d.ts
CHANGED
|
@@ -53,6 +53,17 @@ export type Config = Partial<{
|
|
|
53
53
|
* Network to use for protocols. If not specified, will be inferred from wallet or default to mainnet
|
|
54
54
|
*/
|
|
55
55
|
network: Network;
|
|
56
|
+
/**
|
|
57
|
+
* Affiliate brokers configuration for Chainflip protocol
|
|
58
|
+
*/
|
|
59
|
+
affiliateBrokers: {
|
|
60
|
+
account: `cF${string}` | `0x${string}`;
|
|
61
|
+
commissionBps: number;
|
|
62
|
+
}[];
|
|
63
|
+
/**
|
|
64
|
+
* Broker URL for Chainflip protocol
|
|
65
|
+
*/
|
|
66
|
+
brokerUrl: string;
|
|
56
67
|
}>;
|
|
57
68
|
/**
|
|
58
69
|
* Protocol config
|
|
@@ -62,6 +73,11 @@ export type ProtocolConfig = Partial<{
|
|
|
62
73
|
affiliateBps: number;
|
|
63
74
|
affiliateAddress: string;
|
|
64
75
|
network: Network;
|
|
76
|
+
affiliateBrokers: {
|
|
77
|
+
account: `cF${string}` | `0x${string}`;
|
|
78
|
+
commissionBps: number;
|
|
79
|
+
}[];
|
|
80
|
+
brokerUrl: string;
|
|
65
81
|
}>;
|
|
66
82
|
/**
|
|
67
83
|
* Represents a quote for a swap operation.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xchainjs/xchain-aggregator",
|
|
3
3
|
"description": "Protocol aggregator to make actions in different protocols",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.27",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"module": "lib/index.esm.js",
|
|
@@ -29,17 +29,17 @@
|
|
|
29
29
|
"directory": "release/package"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@chainflip/sdk": "
|
|
32
|
+
"@chainflip/sdk": "1.11.0",
|
|
33
33
|
"@trpc/server": "^10.45.2",
|
|
34
34
|
"@xchainjs/xchain-client": "2.0.9",
|
|
35
|
-
"@xchainjs/xchain-mayachain": "4.0
|
|
36
|
-
"@xchainjs/xchain-mayachain-amm": "4.1.
|
|
37
|
-
"@xchainjs/xchain-mayachain-query": "2.1.
|
|
35
|
+
"@xchainjs/xchain-mayachain": "4.1.0",
|
|
36
|
+
"@xchainjs/xchain-mayachain-amm": "4.1.3",
|
|
37
|
+
"@xchainjs/xchain-mayachain-query": "2.1.2",
|
|
38
38
|
"@xchainjs/xchain-thorchain": "3.0.13",
|
|
39
|
-
"@xchainjs/xchain-thorchain-amm": "3.0.
|
|
40
|
-
"@xchainjs/xchain-thorchain-query": "2.0.
|
|
39
|
+
"@xchainjs/xchain-thorchain-amm": "3.0.24",
|
|
40
|
+
"@xchainjs/xchain-thorchain-query": "2.0.14",
|
|
41
41
|
"@xchainjs/xchain-util": "2.0.5",
|
|
42
|
-
"@xchainjs/xchain-wallet": "2.0.
|
|
42
|
+
"@xchainjs/xchain-wallet": "2.0.18"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@xchainjs/xchain-avax": "2.0.12",
|