UNPKG

@f5i23q999d/cow-sdk

Version:

<p align="center"> <img width="400" src="https://github.com/cowprotocol/cow-sdk/raw/main/docs/images/CoW.png" /> </p>

141 lines 6.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AcrossBridgeProvider = exports.ACROSS_SUPPORTED_NETWORKS = void 0; const const_1 = require("../../const.js"); const tokens_1 = require("./const/tokens.js"); const mainnet_1 = require("../../../chains/details/mainnet.js"); const polygon_1 = require("../../../chains/details/polygon.js"); const arbitrum_1 = require("../../../chains/details/arbitrum.js"); const base_1 = require("../../../chains/details/base.js"); const optimism_1 = require("../../../chains/details/optimism.js"); const AcrossApi_1 = require("./AcrossApi.js"); const util_1 = require("./util.js"); const cow_shed_1 = require("../../../cow-shed/index.js"); const createAcrossDepositCall_1 = require("./createAcrossDepositCall.js"); const contracts_1 = require("@cowprotocol/contracts"); const HOOK_DAPP_ID = 'cow-sdk://bridging/providers/across'; exports.ACROSS_SUPPORTED_NETWORKS = [mainnet_1.mainnet, polygon_1.polygon, arbitrum_1.arbitrumOne, base_1.base, optimism_1.optimism]; // We need to review if we should set an additional slippage tolerance, for now assuming the quote gives you the exact price of bridging and no further slippage is needed const SLIPPAGE_TOLERANCE_BPS = 0; class AcrossBridgeProvider { options; api; cowShedSdk; constructor(options = {}) { this.options = options; this.api = new AcrossApi_1.AcrossApi(options.apiOptions); this.cowShedSdk = new cow_shed_1.CowShedSdk(options.cowShedOptions); } info = { name: 'Across', logoUrl: `${const_1.RAW_PROVIDERS_FILES_PATH}/across/across-logo.png`, }; async getNetworks() { return exports.ACROSS_SUPPORTED_NETWORKS; } async getBuyTokens(targetChainId) { if (!this.options.getTokenInfos) { throw new Error("'getTokenInfos' parameter is required for AcrossBridgeProvider constructor"); } const chainConfig = tokens_1.ACROSS_TOKEN_MAPPING[targetChainId]; if (!chainConfig) { return []; } const tokenAddresses = Object.values(chainConfig.tokens).filter((address) => Boolean(address)); return this.options.getTokenInfos(targetChainId, tokenAddresses); } async getIntermediateTokens(request) { if (request.kind !== contracts_1.OrderKind.SELL) { throw new Error('Only SELL is supported for now'); } const { sellTokenChainId, buyTokenChainId, buyTokenAddress } = request; const chainConfigs = (0, util_1.getChainConfigs)(sellTokenChainId, buyTokenChainId); if (!chainConfigs) return []; const { sourceChainConfig, targetChainConfig } = chainConfigs; // Find the token symbol for the target token const targetTokenSymbol = (0, util_1.getTokenSymbol)(buyTokenAddress, targetChainConfig); if (!targetTokenSymbol) return []; // Use the tokenSymbol to find the outputToken in the target chain const intermediateToken = (0, util_1.getTokenAddress)(targetTokenSymbol, sourceChainConfig); return intermediateToken ? [intermediateToken] : []; } async getQuote(request) { const { sellTokenAddress, sellTokenChainId, buyTokenChainId, amount, receiver } = request; const suggestedFees = await this.api.getSuggestedFees({ token: sellTokenAddress, // inputToken: sellTokenAddress, // outputToken: buyTokenAddress, originChainId: sellTokenChainId, destinationChainId: buyTokenChainId, amount, recipient: receiver ?? undefined, }); // TODO: The suggested fees contain way more information. As we review more bridge providers we should revisit the // facade of the quote result. // // For example, this contains also information on the limits, so you don't need to quote again for the same pair. // potentially, this could be cached for a short period of time in the SDK so we can resolve quotes with less // requests. return (0, util_1.toBridgeQuoteResult)(request, SLIPPAGE_TOLERANCE_BPS, suggestedFees); } async getUnsignedBridgeCall(request, quote) { return (0, createAcrossDepositCall_1.createAcrossDepositCall)({ request, quote, cowShedSdk: this.cowShedSdk, }); } getGasLimitEstimationForHook(_request) { return const_1.DEFAULT_GAS_COST_FOR_HOOK_ESTIMATION; } async getSignedHook(chainId, unsignedCall, signer) { // Sign the multicall const { signedMulticall, cowShedAccount, gasLimit } = await this.cowShedSdk.signCalls({ calls: [ { target: unsignedCall.to, value: unsignedCall.value, callData: unsignedCall.data, allowFailure: false, isDelegateCall: true, }, ], chainId, signer, }); const { to, data } = signedMulticall; return { postHook: { target: to, callData: data, gasLimit: gasLimit.toString(), dappId: HOOK_DAPP_ID, // TODO: I think we should have some additional parameter to type the hook (using dappId for now) }, recipient: cowShedAccount, }; } async decodeBridgeHook(_hook) { throw new Error('Not implemented'); } async getBridgingId(_orderUid, _settlementTx) { // TODO: get events from the mined transaction, extract the deposit id throw new Error('Not implemented'); } getExplorerUrl(bridgingId) { // TODO: Review with across how we get the explorer url based on the bridgingId return `https://app.across.to/transactions/${bridgingId}`; } async getStatus(_bridgingId) { throw new Error('Not implemented'); } async getCancelBridgingTx(_bridgingId) { throw new Error('Not implemented'); } async getRefundBridgingTx(_bridgingId) { throw new Error('Not implemented'); } } exports.AcrossBridgeProvider = AcrossBridgeProvider; //# sourceMappingURL=AcrossBridgeProvider.js.map