UNPKG

@ape.swap/v2-zap-sdk

Version:
137 lines (130 loc) • 7.79 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } var sdkCore = require('@ape.swap/sdk-core'); var invariant = _interopDefault(require('tiny-invariant')); var _ZAP_ADDRESS, _MINI_APE_ADDRESS; (function (ZapType) { ZapType[ZapType["ZAP"] = 0] = "ZAP"; ZapType[ZapType["ZAP_LP_MIGRATOR"] = 1] = "ZAP_LP_MIGRATOR"; ZapType[ZapType["ZAP_LP_POOL"] = 2] = "ZAP_LP_POOL"; ZapType[ZapType["ZAP_SINGLE_ASSET_POOL"] = 3] = "ZAP_SINGLE_ASSET_POOL"; ZapType[ZapType["ZAP_T_BILL"] = 4] = "ZAP_T_BILL"; ZapType[ZapType["ZAP_MINI_APE"] = 5] = "ZAP_MINI_APE"; })(exports.ZapType || (exports.ZapType = {})); // Set the zap address for each chain var ZAP_ADDRESS = (_ZAP_ADDRESS = {}, _ZAP_ADDRESS[sdkCore.SupportedChainId.MAINNET] = '', _ZAP_ADDRESS[sdkCore.SupportedChainId.BSC] = '0x7E060D0e0563fbD4CD2b3B845a992Eab31e47f8b', _ZAP_ADDRESS[sdkCore.SupportedChainId.BSC_TESTNET] = '0xEe0e3270d2C62AC598E435212a5f87A431e4dDcF', _ZAP_ADDRESS[sdkCore.SupportedChainId.POLYGON] = '0x236290f7da54465BF7A26f279d2B3553e5402780', _ZAP_ADDRESS[sdkCore.SupportedChainId.POLYGON_MUMBAI] = '', _ZAP_ADDRESS[sdkCore.SupportedChainId.TLOS] = '0x10614e4395AAc006ca0Ef4970d1412e8e921d911', _ZAP_ADDRESS); var MINI_APE_ADDRESS = (_MINI_APE_ADDRESS = {}, _MINI_APE_ADDRESS[sdkCore.SupportedChainId.POLYGON] = '0x54aff400858Dcac39797a81894D9920f16972D1D', _MINI_APE_ADDRESS); var ZERO_HEX = '0x0'; var ZapV1 = /*#__PURE__*/function () { /** * Cannot be constructed. */ function ZapV1() {} /** * Produces the on-chain method name to call and the hex encoded parameters to pass as arguments for a given trade. * @param zap get zap values * @param options options for the call parameters */ ZapV1.zapCallParameters = function zapCallParameters(zap, options) { var _currencyIn$currency; !zap ? invariant(false, 'null Zap') : void 0; var chainId = zap.chainId, currencyIn = zap.currencyIn, currencyOut1 = zap.currencyOut1, currencyOut2 = zap.currencyOut2, pairOut = zap.pairOut; var zapType = options.zapType, maxPrice = options.maxPrice; !(chainId !== undefined) ? invariant(false, 'CHAIN_ID') : void 0; var etherIn = (_currencyIn$currency = currencyIn.currency) == null ? void 0 : _currencyIn$currency.isNative; var path1 = currencyOut1.path.map(function (token) { return token.address; }); var path2 = currencyOut2.path.map(function (token) { return token.address; }); var currencyInToken = currencyIn == null ? void 0 : currencyIn.currency; var to = sdkCore.validateAndParseAddress(options.recipient); var stakingContractAddress = options == null ? void 0 : options.stakingContractAddress; var stakingPid = options == null ? void 0 : options.stakingPid; var deadline = 'ttl' in options ? "0x" + (Math.floor(new Date().getTime() / 1000) + options.ttl).toString(16) : "0x" + options.deadline.toString(16); var methodName; var args; var value; switch (zapType) { case exports.ZapType.ZAP: if (etherIn) { methodName = 'zapNative'; args = [[currencyOut1.outputCurrency.address, currencyOut2.outputCurrency.address], path1, path2, [currencyOut1.minOutputAmount, currencyOut2.minOutputAmount], [pairOut.minInAmount.token1, pairOut.minInAmount.token2], to, deadline]; value = currencyIn.inputAmount.toString(); } else { methodName = 'zap'; args = [currencyInToken.address, currencyIn.inputAmount.toString(), [currencyOut1.outputCurrency.address, currencyOut2.outputCurrency.address], path1, path2, [currencyOut1.minOutputAmount, currencyOut2.minOutputAmount], [pairOut.minInAmount.token1, pairOut.minInAmount.token2], to, deadline]; value = ZERO_HEX; } break; case exports.ZapType.ZAP_SINGLE_ASSET_POOL: !stakingContractAddress ? invariant(false, 'Missing Pool Address') : void 0; if (etherIn) { methodName = 'zapSingleAssetPoolNative'; args = [path1, currencyOut1.minOutputAmount, deadline, stakingContractAddress]; value = currencyIn.inputAmount.toString(); } else { methodName = 'zapSingleAssetPool'; args = [currencyInToken.address, currencyIn.inputAmount.toString(), path1, currencyOut1.minOutputAmount, deadline, stakingContractAddress]; value = ZERO_HEX; } break; case exports.ZapType.ZAP_LP_POOL: !stakingContractAddress ? invariant(false, 'Missing Pool Address') : void 0; if (etherIn) { methodName = 'zapLPPoolNative'; args = [[currencyOut1.outputCurrency.address, currencyOut2.outputCurrency.address], path1, path2, [currencyOut1.minOutputAmount, currencyOut2.minOutputAmount], [pairOut.minInAmount.token1, pairOut.minInAmount.token2], deadline, stakingContractAddress]; value = currencyIn.inputAmount.toString(); } else { methodName = 'zapLPPool'; args = [currencyInToken.address, currencyIn.inputAmount.toString(), [currencyOut1.outputCurrency.address, currencyOut2.outputCurrency.address], path1, path2, [currencyOut1.minOutputAmount, currencyOut2.minOutputAmount], [pairOut.minInAmount.token1, pairOut.minInAmount.token2], deadline, stakingContractAddress]; value = ZERO_HEX; } break; case exports.ZapType.ZAP_T_BILL: !stakingContractAddress ? invariant(false, 'Missing Bill Address') : void 0; if (etherIn) { methodName = 'zapTBillNative'; args = [[currencyOut1.outputCurrency.address, currencyOut2.outputCurrency.address], path1, path2, [currencyOut1.minOutputAmount, currencyOut2.minOutputAmount], [pairOut.minInAmount.token1, pairOut.minInAmount.token2], deadline, stakingContractAddress, maxPrice || '0']; value = currencyIn.inputAmount.toString(); } else { methodName = 'zapTBill'; args = [currencyInToken.address, currencyIn.inputAmount.toString(), [currencyOut1.outputCurrency.address, currencyOut2.outputCurrency.address], path1, path2, [currencyOut1.minOutputAmount, currencyOut2.minOutputAmount], [pairOut.minInAmount.token1, pairOut.minInAmount.token2], deadline, stakingContractAddress, maxPrice || '0']; value = ZERO_HEX; } break; case exports.ZapType.ZAP_MINI_APE: !stakingPid ? invariant(false, 'Missing contract PID') : void 0; if (etherIn) { methodName = 'zapMiniApeV2Native'; args = [[currencyOut1.outputCurrency.address, currencyOut2.outputCurrency.address], path1, path2, [currencyOut1.minOutputAmount, currencyOut2.minOutputAmount], [pairOut.minInAmount.token1, pairOut.minInAmount.token2], deadline, MINI_APE_ADDRESS[sdkCore.SupportedChainId.POLYGON] || '', stakingPid]; value = currencyIn.inputAmount.toString(); } else { methodName = 'zapMiniApeV2'; args = [currencyInToken.address, currencyIn.inputAmount.toString(), [currencyOut1.outputCurrency.address, currencyOut2.outputCurrency.address], path1, path2, [currencyOut1.minOutputAmount, currencyOut2.minOutputAmount], [pairOut.minInAmount.token1, pairOut.minInAmount.token2], deadline, MINI_APE_ADDRESS[sdkCore.SupportedChainId.POLYGON] || '', stakingPid]; value = ZERO_HEX; } break; default: methodName = ''; args = []; value = '0'; } return { methodName: methodName, args: args, value: value }; }; return ZapV1; }(); exports.ZAP_ADDRESS = ZAP_ADDRESS; exports.ZapV1 = ZapV1; //# sourceMappingURL=v2-zap-sdk.cjs.development.js.map