violet-swapr
Version:
An SDK for building applications on top of DXswap.
2,011 lines (1,872 loc) • 115 kB
JavaScript
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var JSBI = _interopDefault(require('jsbi'));
var invariant = _interopDefault(require('tiny-invariant'));
var warning = _interopDefault(require('tiny-warning'));
var address = require('@ethersproject/address');
var _contracts_json = require('@swapr/core/.contracts.json');
var _contracts_json$1 = require('@swapr/periphery/.contracts.json');
var _Big = _interopDefault(require('big.js'));
var toFormat = _interopDefault(require('toformat'));
var _Decimal = _interopDefault(require('decimal.js-light'));
var solidity = require('@ethersproject/solidity');
var ethers = require('ethers');
var entities = require('entities');
var contracts = require('@ethersproject/contracts');
var networks = require('@ethersproject/networks');
var providers = require('@ethersproject/providers');
var IDXswapPair = _interopDefault(require('@swapr/core/build/IDXswapPair.json'));
var IDXswapFactory = _interopDefault(require('@swapr/core/build/IDXswapFactory.json'));
var stakingRewardsDistributionFactory = [
{
inputs: [
{
internalType: "address",
name: "_rewardTokensValidatorAddress",
type: "address"
},
{
internalType: "address",
name: "_stakableTokenValidatorAddress",
type: "address"
}
],
stateMutability: "nonpayable",
type: "constructor"
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: "address",
name: "owner",
type: "address"
},
{
indexed: false,
internalType: "address",
name: "deployedAt",
type: "address"
}
],
name: "DistributionCreated",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "previousOwner",
type: "address"
},
{
indexed: true,
internalType: "address",
name: "newOwner",
type: "address"
}
],
name: "OwnershipTransferred",
type: "event"
},
{
inputs: [
{
internalType: "address[]",
name: "_rewardTokensAddresses",
type: "address[]"
},
{
internalType: "address",
name: "_stakableTokenAddress",
type: "address"
},
{
internalType: "uint256[]",
name: "_rewardAmounts",
type: "uint256[]"
},
{
internalType: "uint64",
name: "_startingTimestamp",
type: "uint64"
},
{
internalType: "uint64",
name: "_endingTimestmp",
type: "uint64"
},
{
internalType: "bool",
name: "_locked",
type: "bool"
},
{
internalType: "uint256",
name: "_stakingCap",
type: "uint256"
}
],
name: "createDistribution",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "uint256",
name: "",
type: "uint256"
}
],
name: "distributions",
outputs: [
{
internalType: "contract ERC20StakingRewardsDistribution",
name: "",
type: "address"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
],
name: "getDistributionsAmount",
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
],
name: "owner",
outputs: [
{
internalType: "address",
name: "",
type: "address"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
],
name: "renounceOwnership",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
],
name: "rewardTokensValidator",
outputs: [
{
internalType: "contract IRewardTokensValidator",
name: "",
type: "address"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "_rewardTokensValidatorAddress",
type: "address"
}
],
name: "setRewardTokensValidator",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "_stakableTokenValidatorAddress",
type: "address"
}
],
name: "setStakableTokenValidator",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
],
name: "stakableTokenValidator",
outputs: [
{
internalType: "contract IStakableTokenValidator",
name: "",
type: "address"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "newOwner",
type: "address"
}
],
name: "transferOwnership",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
}
];
var stakingRewardsDistribution = [
{
anonymous: false,
inputs: [
],
name: "Canceled",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "claimer",
type: "address"
},
{
indexed: false,
internalType: "uint256[]",
name: "amounts",
type: "uint256[]"
}
],
name: "Claimed",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: "address[]",
name: "rewardsTokenAddresses",
type: "address[]"
},
{
indexed: false,
internalType: "address",
name: "stakableTokenAddress",
type: "address"
},
{
indexed: false,
internalType: "uint256[]",
name: "rewardsAmounts",
type: "uint256[]"
},
{
indexed: false,
internalType: "uint64",
name: "startingTimestamp",
type: "uint64"
},
{
indexed: false,
internalType: "uint64",
name: "endingTimestamp",
type: "uint64"
},
{
indexed: false,
internalType: "bool",
name: "locked",
type: "bool"
},
{
indexed: false,
internalType: "uint256",
name: "stakingCap",
type: "uint256"
}
],
name: "Initialized",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "previousOwner",
type: "address"
},
{
indexed: true,
internalType: "address",
name: "newOwner",
type: "address"
}
],
name: "OwnershipTransferred",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: "uint256[]",
name: "amounts",
type: "uint256[]"
}
],
name: "Recovered",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "staker",
type: "address"
},
{
indexed: false,
internalType: "uint256",
name: "amount",
type: "uint256"
}
],
name: "Staked",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "withdrawer",
type: "address"
},
{
indexed: false,
internalType: "uint256",
name: "amount",
type: "uint256"
}
],
name: "Withdrawn",
type: "event"
},
{
inputs: [
{
internalType: "address",
name: "",
type: "address"
},
{
internalType: "address",
name: "",
type: "address"
}
],
name: "claimedReward",
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "",
type: "address"
},
{
internalType: "address",
name: "",
type: "address"
}
],
name: "consolidatedRewardsPerStakedToken",
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "",
type: "address"
},
{
internalType: "address",
name: "",
type: "address"
}
],
name: "earnedRewards",
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
],
name: "endingTimestamp",
outputs: [
{
internalType: "uint64",
name: "",
type: "uint64"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
],
name: "initialized",
outputs: [
{
internalType: "bool",
name: "",
type: "bool"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
],
name: "lastConsolidationTimestamp",
outputs: [
{
internalType: "uint64",
name: "",
type: "uint64"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
],
name: "locked",
outputs: [
{
internalType: "bool",
name: "",
type: "bool"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
],
name: "owner",
outputs: [
{
internalType: "address",
name: "",
type: "address"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "",
type: "address"
}
],
name: "recoverableUnassignedReward",
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
],
name: "renounceOwnership",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "",
type: "address"
}
],
name: "rewardAmount",
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "",
type: "address"
}
],
name: "rewardPerStakedToken",
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "uint256",
name: "",
type: "uint256"
}
],
name: "rewardTokens",
outputs: [
{
internalType: "contract ERC20",
name: "",
type: "address"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
],
name: "secondsDuration",
outputs: [
{
internalType: "uint64",
name: "",
type: "uint64"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
],
name: "stakableToken",
outputs: [
{
internalType: "contract ERC20",
name: "",
type: "address"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "",
type: "address"
}
],
name: "stakedTokenAmount",
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "",
type: "address"
}
],
name: "stakedTokensOf",
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
],
name: "stakingCap",
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
],
name: "startingTimestamp",
outputs: [
{
internalType: "uint64",
name: "",
type: "uint64"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "",
type: "address"
}
],
name: "totalClaimedRewards",
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
],
name: "totalStakedTokensAmount",
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "newOwner",
type: "address"
}
],
name: "transferOwnership",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
],
name: "getRewardTokens",
outputs: [
{
internalType: "contract ERC20[]",
name: "",
type: "address[]"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "_claimer",
type: "address"
}
],
name: "getClaimedRewards",
outputs: [
{
internalType: "uint256[]",
name: "",
type: "uint256[]"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "address[]",
name: "_rewardTokenAddresses",
type: "address[]"
},
{
internalType: "address",
name: "_stakableTokenAddress",
type: "address"
},
{
internalType: "uint256[]",
name: "_rewardAmounts",
type: "uint256[]"
},
{
internalType: "uint64",
name: "_startingTimestamp",
type: "uint64"
},
{
internalType: "uint64",
name: "_endingTimestamp",
type: "uint64"
},
{
internalType: "bool",
name: "_locked",
type: "bool"
},
{
internalType: "uint256",
name: "_stakingCap",
type: "uint256"
}
],
name: "initialize",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
],
name: "cancel",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
],
name: "recoverUnassignedRewards",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "uint256",
name: "_amount",
type: "uint256"
}
],
name: "stake",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "uint256",
name: "_amount",
type: "uint256"
}
],
name: "withdraw",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "uint256[]",
name: "_amounts",
type: "uint256[]"
},
{
internalType: "address",
name: "_recipient",
type: "address"
}
],
name: "claim",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "_recipient",
type: "address"
}
],
name: "claimAll",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "_recipient",
type: "address"
}
],
name: "exit",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
],
name: "consolidateReward",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "_staker",
type: "address"
}
],
name: "claimableRewards",
outputs: [
{
internalType: "uint256[]",
name: "",
type: "uint256[]"
}
],
stateMutability: "view",
type: "function"
}
];
var swprClaimer = [
{
inputs: [
{
internalType: "address",
name: "_swprToken",
type: "address"
},
{
internalType: "bytes32",
name: "_merkleRoot",
type: "bytes32"
},
{
internalType: "uint256",
name: "_claimTimeLimit",
type: "uint256"
}
],
stateMutability: "nonpayable",
type: "constructor"
},
{
inputs: [
],
name: "AlreadyClaimed",
type: "error"
},
{
inputs: [
],
name: "ClaimTimeLimitNotYetReached",
type: "error"
},
{
inputs: [
],
name: "ClaimTimeLimitReached",
type: "error"
},
{
inputs: [
],
name: "InvalidMerkleProof",
type: "error"
},
{
inputs: [
],
name: "InvalidMerkleRoot",
type: "error"
},
{
inputs: [
],
name: "PastClaimTimeLimit",
type: "error"
},
{
inputs: [
],
name: "ZeroAddressInput",
type: "error"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "previousOwner",
type: "address"
},
{
indexed: true,
internalType: "address",
name: "newOwner",
type: "address"
}
],
name: "OwnershipTransferred",
type: "event"
},
{
inputs: [
{
internalType: "uint256",
name: "_amount",
type: "uint256"
},
{
internalType: "bytes32[]",
name: "_proof",
type: "bytes32[]"
}
],
name: "claim",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
],
name: "claimTimeLimit",
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "",
type: "address"
}
],
name: "claimed",
outputs: [
{
internalType: "bool",
name: "",
type: "bool"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
],
name: "merkleRoot",
outputs: [
{
internalType: "bytes32",
name: "",
type: "bytes32"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
],
name: "owner",
outputs: [
{
internalType: "address",
name: "",
type: "address"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
],
name: "recover",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
],
name: "renounceOwnership",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
],
name: "swprToken",
outputs: [
{
internalType: "address",
name: "",
type: "address"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "newOwner",
type: "address"
}
],
name: "transferOwnership",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
}
];
var MULTICALL_ABI = [
{
constant: true,
inputs: [
],
name: "getCurrentBlockTimestamp",
outputs: [
{
name: "timestamp",
type: "uint256"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [
{
components: [
{
name: "target",
type: "address"
},
{
name: "callData",
type: "bytes"
}
],
name: "calls",
type: "tuple[]"
}
],
name: "aggregate",
outputs: [
{
name: "blockNumber",
type: "uint256"
},
{
name: "returnData",
type: "bytes[]"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [
],
name: "getLastBlockHash",
outputs: [
{
name: "blockHash",
type: "bytes32"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [
{
name: "addr",
type: "address"
}
],
name: "getEthBalance",
outputs: [
{
name: "balance",
type: "uint256"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [
],
name: "getCurrentBlockDifficulty",
outputs: [
{
name: "difficulty",
type: "uint256"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [
],
name: "getCurrentBlockGasLimit",
outputs: [
{
name: "gaslimit",
type: "uint256"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [
],
name: "getCurrentBlockCoinbase",
outputs: [
{
name: "coinbase",
type: "address"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [
{
name: "blockNumber",
type: "uint256"
}
],
name: "getBlockHash",
outputs: [
{
name: "blockHash",
type: "bytes32"
}
],
payable: false,
stateMutability: "view",
type: "function"
}
];
var _FACTORY_ADDRESS, _ROUTER_ADDRESS, _STAKING_REWARDS_FACT, _SWPR_CLAIMER_ADDRESS, _SWPR_CONVERTER_ADDRE, _SOLIDITY_TYPE_MAXIMA, _MULTICALL_ADDRESS;
(function (ChainId) {
ChainId[ChainId["MAINNET"] = 1] = "MAINNET";
ChainId[ChainId["RINKEBY"] = 4] = "RINKEBY";
ChainId[ChainId["XDAI"] = 100] = "XDAI";
ChainId[ChainId["ARBITRUM_ONE"] = 42161] = "ARBITRUM_ONE";
ChainId[ChainId["ARBITRUM_RINKEBY"] = 421611] = "ARBITRUM_RINKEBY";
})(exports.ChainId || (exports.ChainId = {}));
(function (TradeType) {
TradeType[TradeType["EXACT_INPUT"] = 0] = "EXACT_INPUT";
TradeType[TradeType["EXACT_OUTPUT"] = 1] = "EXACT_OUTPUT";
})(exports.TradeType || (exports.TradeType = {}));
(function (Rounding) {
Rounding[Rounding["ROUND_DOWN"] = 0] = "ROUND_DOWN";
Rounding[Rounding["ROUND_HALF_UP"] = 1] = "ROUND_HALF_UP";
Rounding[Rounding["ROUND_UP"] = 2] = "ROUND_UP";
})(exports.Rounding || (exports.Rounding = {}));
var ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
var FACTORY_ADDRESS = (_FACTORY_ADDRESS = {}, _FACTORY_ADDRESS[exports.ChainId.MAINNET] = _contracts_json.mainnet.factory, _FACTORY_ADDRESS[exports.ChainId.RINKEBY] = _contracts_json.rinkeby.factory, _FACTORY_ADDRESS[exports.ChainId.ARBITRUM_ONE] = _contracts_json.arbitrumOne.factory, _FACTORY_ADDRESS[exports.ChainId.ARBITRUM_RINKEBY] = _contracts_json.arbitrumRinkebyTestnet.factory, _FACTORY_ADDRESS[exports.ChainId.XDAI] = _contracts_json.xdai.factory, _FACTORY_ADDRESS);
var ROUTER_ADDRESS = (_ROUTER_ADDRESS = {}, _ROUTER_ADDRESS[exports.ChainId.RINKEBY] = _contracts_json$1.rinkeby.router, _ROUTER_ADDRESS[exports.ChainId.MAINNET] = _contracts_json$1.mainnet.router, _ROUTER_ADDRESS[exports.ChainId.XDAI] = _contracts_json$1.xdai.router, _ROUTER_ADDRESS[exports.ChainId.ARBITRUM_ONE] = _contracts_json$1.arbitrumOne.router, _ROUTER_ADDRESS[exports.ChainId.ARBITRUM_RINKEBY] = _contracts_json$1.arbitrumRinkebyTestnet.router, _ROUTER_ADDRESS);
var STAKING_REWARDS_FACTORY_ADDRESS = (_STAKING_REWARDS_FACT = {}, _STAKING_REWARDS_FACT[exports.ChainId.MAINNET] = '0x156F0568a6cE827e5d39F6768A5D24B694e1EA7b', _STAKING_REWARDS_FACT[exports.ChainId.RINKEBY] = '0x0f9E49d473B813abe33F1BAB11fa9E16eE850EBa', _STAKING_REWARDS_FACT[exports.ChainId.XDAI] = '0xa039793Af0bb060c597362E8155a0327d9b8BEE8', _STAKING_REWARDS_FACT[exports.ChainId.ARBITRUM_ONE] = '0xecA7F78d59D16812948849663b26FE10E320f80C', _STAKING_REWARDS_FACT[exports.ChainId.ARBITRUM_RINKEBY] = '0x41e657cAdE74f45b7E2F0F4a5AeE0239f2fB4E1F', _STAKING_REWARDS_FACT);
var SWPR_CLAIMER_ADDRESS = (_SWPR_CLAIMER_ADDRESS = {}, _SWPR_CLAIMER_ADDRESS[exports.ChainId.MAINNET] = '0x0000000000000000000000000000000000001234', _SWPR_CLAIMER_ADDRESS[exports.ChainId.RINKEBY] = '0x6D525E4115d339aD4e336bCF4C85A1Fb8f4a594C', _SWPR_CLAIMER_ADDRESS[exports.ChainId.ARBITRUM_RINKEBY] = '0x99583f330814E04de96C0288FBF82B5E35A009dc', _SWPR_CLAIMER_ADDRESS[exports.ChainId.ARBITRUM_ONE] = '0xe54942077Df7b8EEf8D4e6bCe2f7B58B0082b0cd', _SWPR_CLAIMER_ADDRESS[exports.ChainId.XDAI] = '0x0000000000000000000000000000000000001234', _SWPR_CLAIMER_ADDRESS); // converter only deployed on Arb1
var SWPR_CONVERTER_ADDRESS = (_SWPR_CONVERTER_ADDRE = {}, _SWPR_CONVERTER_ADDRE[exports.ChainId.MAINNET] = '0x0000000000000000000000000000000000001234', _SWPR_CONVERTER_ADDRE[exports.ChainId.RINKEBY] = '0x0000000000000000000000000000000000001234', _SWPR_CONVERTER_ADDRE[exports.ChainId.ARBITRUM_RINKEBY] = '0x0000000000000000000000000000000000001234', _SWPR_CONVERTER_ADDRE[exports.ChainId.ARBITRUM_ONE] = '0x2b058af96175A847Bf3E5457B3A702F807daDdFd', _SWPR_CONVERTER_ADDRE[exports.ChainId.XDAI] = '0x0000000000000000000000000000000000001234', _SWPR_CONVERTER_ADDRE);
var SWPR_WHITELIST_IPFS_HASH = 'QmcjTAvDJZU339jrc9Ky2pXKR68R1SjnwdyGSQjt1kad9r';
var INIT_CODE_HASH = '0xd306a548755b9295ee49cc729e13ca4a45e00199bbd890fa146da43a50571776';
var MINIMUM_LIQUIDITY = /*#__PURE__*/JSBI.BigInt(1000); // exports for internal consumption
var ZERO = /*#__PURE__*/JSBI.BigInt(0);
var ONE = /*#__PURE__*/JSBI.BigInt(1);
var TWO = /*#__PURE__*/JSBI.BigInt(2);
var THREE = /*#__PURE__*/JSBI.BigInt(3);
var FIVE = /*#__PURE__*/JSBI.BigInt(5);
var TEN = /*#__PURE__*/JSBI.BigInt(10);
var _25 = /*#__PURE__*/JSBI.BigInt(25);
var SECONDS_IN_YEAR = /*#__PURE__*/JSBI.BigInt(31536000);
var _30 = /*#__PURE__*/JSBI.BigInt(30);
var _100 = /*#__PURE__*/JSBI.BigInt(100);
var _1000 = /*#__PURE__*/JSBI.BigInt(1000);
var _10000 = /*#__PURE__*/JSBI.BigInt(10000);
var defaultSwapFee = _25;
var defaultProtocolFeeDenominator = FIVE;
(function (SolidityType) {
SolidityType["uint8"] = "uint8";
SolidityType["uint256"] = "uint256";
})(exports.SolidityType || (exports.SolidityType = {}));
var SOLIDITY_TYPE_MAXIMA = (_SOLIDITY_TYPE_MAXIMA = {}, _SOLIDITY_TYPE_MAXIMA[exports.SolidityType.uint8] = /*#__PURE__*/JSBI.BigInt('0xff'), _SOLIDITY_TYPE_MAXIMA[exports.SolidityType.uint256] = /*#__PURE__*/JSBI.BigInt('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'), _SOLIDITY_TYPE_MAXIMA);
var MULTICALL_ADDRESS = (_MULTICALL_ADDRESS = {}, _MULTICALL_ADDRESS[exports.ChainId.MAINNET] = '0xeefba1e63905ef1d7acba5a8513c70307c1ce441', _MULTICALL_ADDRESS[exports.ChainId.RINKEBY] = '0x42ad527de7d4e9d9d011ac45b31d8551f8fe9821', _MULTICALL_ADDRESS[exports.ChainId.ARBITRUM_ONE] = '0xF718F2bd590E5621e53f7b89398e52f7Acced8ca', _MULTICALL_ADDRESS[exports.ChainId.XDAI] = '0xb5b692a88bdfc81ca69dcb1d924f59f0413a602a', _MULTICALL_ADDRESS[exports.ChainId.ARBITRUM_RINKEBY] = '0xf1f8AAc64036cdd399886b1C157B7e3b361093F3', _MULTICALL_ADDRESS);
function validateSolidityTypeInstance(value, solidityType) {
!JSBI.greaterThanOrEqual(value, ZERO) ? invariant(false, value + " is not a " + solidityType + ".") : void 0;
!JSBI.lessThanOrEqual(value, SOLIDITY_TYPE_MAXIMA[solidityType]) ? invariant(false, value + " is not a " + solidityType + ".") : void 0;
} // warns if addresses are not checksummed
function validateAndParseAddress(address$1) {
try {
var checksummedAddress = address.getAddress(address$1);
"development" !== "production" ? warning(address$1 === checksummedAddress, address$1 + " is not checksummed.") : void 0;
return checksummedAddress;
} catch (error) {
invariant(false, address$1 + " is not a valid address.") ;
}
}
function parseBigintIsh(bigintIsh) {
return bigintIsh instanceof JSBI ? bigintIsh : typeof bigintIsh === 'bigint' ? JSBI.BigInt(bigintIsh.toString()) : JSBI.BigInt(bigintIsh);
} // mock the on-chain sqrt function
function sqrt(y) {
validateSolidityTypeInstance(y, exports.SolidityType.uint256);
var z = ZERO;
var x;
if (JSBI.greaterThan(y, THREE)) {
z = y;
x = JSBI.add(JSBI.divide(y, TWO), ONE);
while (JSBI.lessThan(x, z)) {
z = x;
x = JSBI.divide(JSBI.add(JSBI.divide(y, x), x), TWO);
}
} else if (JSBI.notEqual(y, ZERO)) {
z = ONE;
}
return z;
} // given an array of items sorted by `comparator`, insert an item into its sort index and constrain the size to
// `maxSize` by removing the last item
function sortedInsert(items, add, maxSize, comparator) {
!(maxSize > 0) ? invariant(false, 'MAX_SIZE_ZERO') : void 0; // this is an invariant because the interface cannot return multiple removed items if items.length exceeds maxSize
!(items.length <= maxSize) ? invariant(false, 'ITEMS_SIZE') : void 0; // short circuit first item add
if (items.length === 0) {
items.push(add);
return null;
} else {
var isFull = items.length === maxSize; // short circuit if full and the additional item does not come before the last item
if (isFull && comparator(items[items.length - 1], add) <= 0) {
return add;
}
var lo = 0,
hi = items.length;
while (lo < hi) {
var mid = lo + hi >>> 1;
if (comparator(items[mid], add) <= 0) {
lo = mid + 1;
} else {
hi = mid;
}
}
items.splice(lo, 0, add);
return isFull ? items.pop() : null;
}
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}
function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
subClass.__proto__ = superClass;
}
function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);
};
return _getPrototypeOf(o);
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
function _isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
return true;
} catch (e) {
return false;
}
}
function _construct(Parent, args, Class) {
if (_isNativeReflectConstruct()) {
_construct = Reflect.construct;
} else {
_construct = function _construct(Parent, args, Class) {
var a = [null];
a.push.apply(a, args);
var Constructor = Function.bind.apply(Parent, a);
var instance = new Constructor();
if (Class) _setPrototypeOf(instance, Class.prototype);
return instance;
};
}
return _construct.apply(null, arguments);
}
function _isNativeFunction(fn) {
return Function.toString.call(fn).indexOf("[native code]") !== -1;
}
function _wrapNativeSuper(Class) {
var _cache = typeof Map === "function" ? new Map() : undefined;
_wrapNativeSuper = function _wrapNativeSuper(Class) {
if (Class === null || !_isNativeFunction(Class)) return Class;
if (typeof Class !== "function") {
throw new TypeError("Super expression must either be null or a function");
}
if (typeof _cache !== "undefined") {
if (_cache.has(Class)) return _cache.get(Class);
_cache.set(Class, Wrapper);
}
function Wrapper() {
return _construct(Class, arguments, _getPrototypeOf(this).constructor);
}
Wrapper.prototype = Object.create(Class.prototype, {
constructor: {
value: Wrapper,
enumerable: false,
writable: true,
configurable: true
}
});
return _setPrototypeOf(Wrapper, Class);
};
return _wrapNativeSuper(Class);
}
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _createForOfIteratorHelperLoose(o, allowArrayLike) {
var it;
if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
if (it) o = it;
var i = 0;
return function () {
if (i >= o.length) return {
done: true
};
return {
done: false,
value: o[i++]
};
};
}
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
it = o[Symbol.iterator]();
return it.next.bind(it);
}
// see https://stackoverflow.com/a/41102306
var CAN_SET_PROTOTYPE = ('setPrototypeOf' in Object);
/**
* Indicates that the pair has insufficient reserves for a desired output amount. I.e. the amount of output cannot be
* obtained by sending any amount of input.
*/
var InsufficientReservesError = /*#__PURE__*/function (_Error) {
_inheritsLoose(InsufficientReservesError, _Error);
function InsufficientReservesError() {
var _this;
_this = _Error.call(this) || this;
_this.isInsufficientReservesError = true;
_this.name = _this.constructor.name;
if (CAN_SET_PROTOTYPE) Object.setPrototypeOf(_assertThisInitialized(_this), (this instanceof InsufficientReservesError ? this.constructor : void 0).prototype);
return _this;
}
return InsufficientReservesError;
}( /*#__PURE__*/_wrapNativeSuper(Error));
/**
* Indicates that the input amount is too small to produce any amount of output. I.e. the amount of input sent is less
* than the price of a single unit of output after fees.
*/
var InsufficientInputAmountError = /*#__PURE__*/function (_Error2) {
_inheritsLoose(InsufficientInputAmountError, _Error2);
function InsufficientInputAmountError() {
var _this2;
_this2 = _Error2.call(this) || this;
_this2.isInsufficientInputAmountError = true;
_this2.name = _this2.constructor.name;
if (CAN_SET_PROTOTYPE) Object.setPrototypeOf(_assertThisInitialized(_this2), (this instanceof InsufficientInputAmountError ? this.constructor : void 0).prototype);
return _this2;
}
return InsufficientInputAmountError;
}( /*#__PURE__*/_wrapNativeSuper(Error));
var _Currency$NATIVE_CURR;
/**
* A currency is any fungible financial instrument on the target chain.
*
* The only instances of the base class `Currency` are native currencies such as Ether for Ethereum and xDAI for xDAI.
*/
var Currency = /*#__PURE__*/function () {
/**
* Constructs an instance of the base class `Currency`. The only instance of the base class `Currency` is `Currency.ETHER`.
* @param decimals decimals of the currency
* @param symbol symbol of the currency
* @param name of the currency
*/
function Currency(decimals, symbol, name) {
validateSolidityTypeInstance(JSBI.BigInt(decimals), exports.SolidityType.uint8);
this.decimals = decimals;
this.symbol = symbol;
this.name = name;
}
Currency.isNative = function isNative(currency) {
return Object.values(Currency.NATIVE_CURRENCY).indexOf(currency) >= 0;
};
Currency.getNative = function getNative(chainId) {
return Currency.NATIVE_CURRENCY[chainId];
};
return Currency;
}(); // fiat currencies used to represent countervalues
Currency.USD = /*#__PURE__*/new Currency(18, 'USD', 'US dollar'); // Native currencies for deployment chains
Currency.ETHER = /*#__PURE__*/new Currency(18, 'ETH', 'Ether');
Currency.XDAI = /*#__PURE__*/new Currency(18, 'XDAI', 'xDAI');
Currency.NATIVE_CURRENCY = (_Currency$NATIVE_CURR = {}, _Currency$NATIVE_CURR[exports.ChainId.MAINNET] = Currency.ETHER, _Currency$NATIVE_CURR[exports.ChainId.RINKEBY] = Currency.ETHER, _Currency$NATIVE_CURR[exports.ChainId.ARBITRUM_ONE] = Currency.ETHER, _Currency$NATIVE_CURR[exports.ChainId.ARBITRUM_RINKEBY] = Currency.ETHER, _Currency$NATIVE_CURR[exports.ChainId.XDAI] = Currency.XDAI, _Currency$NATIVE_CURR);
var USD = Currency.USD;
var ETHER = Currency.ETHER;
var XDAI = Currency.XDAI;
var _Token$WETH, _Token$WXDAI, _Token$DXD, _Token$SWPR, _Token$NATIVE_CURRENC;
/**
* Represents an ERC20 token with a unique address and some metadata.
*/
var Token = /*#__PURE__*/function (_Currency) {
_inheritsLoose(Token, _Currency);
function Token(chainId, address, decimals, symbol, name) {
var _this;
_this = _Currency.call(this, decimals, symbol, name) || this;
_this.chainId = chainId;
_this.address = validateAndParseAddress(address);
return _this;
}
/**
* Returns true if the two tokens are equivalent, i.e. have the same chainId and address.
* @param other other token to compare
*/
var _proto = Token.prototype;
_proto.equals = function equals(other) {
// short circuit on reference equality
if (this === other) {
return true;
}
return this.chainId === other.chainId && this.address === other.address;
}
/**
* Returns true if the address of this token sorts before the address of the other token
* @param other other token to compare
* @throws if the tokens have the same address
* @throws if the tokens are on different chains
*/
;
_proto.sortsBefore = function sortsBefore(other) {
!(this.chainId === other.chainId) ? invariant(false, 'CHAIN_IDS') : void 0;
!(this.address !== other.address) ? invariant(false, 'ADDRESSES') : void 0;
return this.address.toLowerCase() < other.address.toLowerCase();
};
Token.getNativeWrapper = function getNativeWrapper(chainId) {
return Token.NATIVE_CURRENCY_WRAPPER[chainId];
};
Token.isNativeWrapper = function isNativeWrapper(token) {
return Token.NATIVE_CURRENCY_WRAPPER[token.chainId].equals(token);
};
return Token;
}(Currency);
Token.WETH = (_Token$WETH = {}, _Token$WETH[exports.ChainId.MAINNET] = /*#__PURE__*/new Token(exports.ChainId.MAINNET, '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', 18, 'WETH', 'Wrapped Ether'), _Token$WETH[exports.ChainId.RINKEBY] = /*#__PURE__*/new Token(exports.ChainId.RINKEBY, '0xc778417E063141139Fce010982780140Aa0cD5Ab', 18, 'WETH', 'Wrapped Ether'), _Token$WETH[exports.ChainId.ARBITRUM_ONE] = /*#__PURE__*/new Token(exports.ChainId.ARBITRUM_ONE, '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1', 18, 'WETH', 'Wrapped Ether'), _Token$WETH[exports.ChainId.ARBITRUM_RINKEBY] = /*#__PURE__*/new Token(exports.ChainId.ARBITRUM_RINKEBY, '0xB47e6A5f8b33b3F17603C83a0535A9dcD7E32681', 18, 'WETH', 'Wrapped Ether'), _Token$WETH[exports.ChainId.XDAI] = /*#__PURE__*/new Token(exports.ChainId.XDAI, '0x6A023CCd1ff6F2045C3309768eAd9E68F978f6e1', 18, 'WETH', 'Wrapped Ether on xDai'), _Token$WETH);
Token.WXDAI = (_Token$WXDAI = {}, _Token$WXDAI[exports.ChainId.XDAI] = /*#__PURE__*/new Token(exports.ChainId.XDAI, '0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d', 18, 'WXDAI', 'Wrapped xDAI'), _Token$WXDAI);
Token.DXD = (_Token$DXD = {}, _Token$DXD[exports.ChainId.MAINNET] = /*#__PURE__*/new Token(exports.ChainId.MAINNET, '0xa1d65E8fB6e87b60FECCBc582F7f97804B725521', 18, 'DXD', 'DXdao'), _Token$DXD[exports.ChainId.RINKEBY] = /*#__PURE__*/new Token(exports.ChainId.RINKEBY, '0x554898A0BF98aB0C03ff86C7DccBE29269cc4d29', 18, 'DXD', 'DXdao'), _Token$DXD[exports.ChainId.XDAI] = /*#__PURE__*/new Token(exports.ChainId.XDAI, '0xb90d6bec20993be5d72a5ab353343f7a0281f158', 18, 'DXD', 'DXdao from Ethereum'), _Token$DXD[exports.ChainId.ARBITRUM_ONE] = /*#__PURE__*/new Token(exports.ChainId.ARBITRUM_ONE, '0xC3Ae0333F0F34aa734D5493276223d95B8F9Cb37', 18, 'DXD', 'DXdao from Ethereum'), _Token$DXD[exports.ChainId.ARBITRUM_RINKEBY] = /*#__PURE__*/new Token(exports.ChainId.ARBITRUM_RINKEBY, '0x5d47100B0854525685907D5D773b92c22c0c745e', 18, 'DXD', 'DXdao from Ethereum'), _Token$DXD);
Token.SWPR = (_Token$SWPR = {}, _Token$SWPR[exports.ChainId.MAINNET] = /*#__PURE__*/new Token(exports.ChainId.MAINNET, '0x6cAcDB97e3fC8136805a9E7c342d866ab77D0957', 18, 'SWPR', 'Swapr'), _Token$SWPR[exports.ChainId.RINKEBY] = /*#__PURE__*/new Token(exports.ChainId.RINKEBY, '0xDcb0BeB93139c3e5eD0Edb749baccADd6badAc4f', 18, 'SWPR', 'Swapr'), _Token$SWPR[exports.ChainId.XDAI] = /*#__PURE__*/new Token(exports.ChainId.XDAI, '0x532801ED6f82FFfD2DAB70A19fC2d7B2772C4f4b', 18, 'SWPR', 'Swapr'), _Token$SWPR[exports.ChainId.ARBITRUM_RINKEBY] = /*#__PURE__*/new Token(exports.ChainId.ARBITRUM_RINKEBY, '0x8f2072c2142D9fFDc785955E0Ce71561753D44Fb', 18, 'SWPR', 'Swapr'), _Token$SWPR[exports.ChainId.ARBITRUM_ONE] = /*#__PURE__*/new Token(exports.ChainId.ARBITRUM_ONE, '0xdE903E2712288A1dA82942DDdF2c20529565aC30', 18, 'SWPR', 'Swapr'), _Token$SWPR);
Token.NATIVE_CURRENCY_WRAPPER = (_Token$NATIVE_CURRENC = {}, _Token$NATIVE_CURRENC[exports.ChainId.MAINNET] = Token.WETH[exports.ChainId.MAINNET], _Token$NATIVE_CURRENC[exports.ChainId.RINKEBY] = Token.WETH[exports.ChainId.RINKEBY], _Token$NATIVE_CURRENC[exports.ChainId.ARBITRUM_ONE] = Token.WETH[exports.ChainId.ARBITRUM_ONE], _Token$NATIVE_CURRENC[exports.ChainId.ARBITRUM_RINKEBY] = Token.WETH[exports.ChainId.ARBITRUM_RINKEBY], _Token$NATIVE_CURRENC[exports.ChainId.XDAI] = Token.WXDAI[exports.ChainId.XDAI], _Token$NATIVE_CURRENC);
/**
* Compares two currencies for equality
*/
function currencyEquals(currencyA, currencyB) {
if (currencyA instanceof Token && currencyB instanceof Token) {
return currencyA.equals(currencyB);
} else if (currencyA instanceof Token) {
return false;
} else if (currencyB instanceof Token) {
return false;
} else {
return currencyA === currencyB;
}
} // reexport for convenience
var WETH = Token.WETH;
var DXD = Token.DXD;
var WXDAI = Token.WXDAI;
var SWPR = Token.SWPR;
var _toSignificantRoundin, _toFixedRounding;
var Decimal = /*#__PURE__*/toFormat(_Decimal);
var Big = /*#__PURE__*/toFormat(_Big);
var toSignificantRounding = (_toSignificantRoundin = {}, _toSignificantRoundin[exports.Rounding.ROUND_DOWN] = Decimal.ROUND_DOWN, _toSignificantRoundin[exports.Rounding.ROUND_HALF_UP] = Decimal.ROUND_HALF_UP, _toSignificantRoundin[exports.Rounding.ROUND_UP] = Decimal.ROUND_UP, _toSignificantRoundin);
var toFixedRounding = (_toFixedRounding = {}, _toFixedRounding[exports.Rounding.ROUND_DOWN] = 0, _toFixedRounding[exports.Rounding.ROUND_HALF_UP] = 1, _toFixedRounding[exports.Rounding.ROUND_UP] = 3, _toFixedRounding);
var Fraction = /*#__PURE__*/function () {
function Fraction(numerator, denominator) {
if (denominator === void 0) {
denominator = ONE;
}
this.numerator = parseBigintIsh(numerator);
this.denominator = parseBigintIsh(denominator);
} // performs floor division
var _proto = Fraction.prototype;
_proto.invert = function invert() {
return new Fraction(this.denominator, this.numerator);
};
_proto.add = function add(other) {
var otherParsed = other instanceof Fraction ? other : new Fraction(parseBigintIsh(other));
if (JSBI.equal(this.denominator, otherParsed.denominator)) {
return new Fraction(JSBI.add(this.numerator, otherParsed.numerator), this.denominator);
}
return new Fraction(JSBI.add(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(otherParsed.numerator, this.denominator)), JSBI.multiply(this.denominator, otherParsed.denominator));
};
_proto.subtract = function subtract(other) {
var otherParsed = other instanceof Fraction ? other : new Fraction(parseBigintIsh(other));
if (JSBI.equal(this.denominator, otherParsed.denominator)) {
return new Fraction(JSBI.subtract(this.numerator, otherParsed.numerator), this.denominator);
}
return new Fraction(JSBI.subtract(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(otherParsed.numerator, this.denominator)), JSBI.multiply(this.denominator, otherParsed.denominator));
};
_proto.lessThan = function lessThan(other) {
var otherParsed = other instanceof Fraction ? other : new Fraction(parseBigintIsh(other));
return JSBI.lessThan(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(otherParsed.numerator, this.denominator));
};
_proto.equalTo = function equalTo(other) {
var otherParsed = other instanceof Fraction ? other : new Fraction(parseBigintIsh(other));
return JSBI.equal(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(otherParsed.numerator, this.denominator));
};
_proto.greaterThan = function greaterThan(other) {
var otherParsed = other instanceof Fraction ? other : new Fraction(parseBigintIsh(other));
return JSBI.greaterThan(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(otherParsed.numerator, this.denominator));
};
_proto.multiply = function multiply(other) {
var otherParsed = other instanceof Fraction ? other : new Fraction(parseBigintIsh(other));
return new Fraction(JSBI.multiply(this.numerator, otherParsed.numerator), JSBI.multiply(this.denominator, otherParsed.denominator));
};
_proto.divide = function divide(other) {
var otherParsed = other instanceof Fraction ? other : new Fraction(parseBigintIsh(other));
return new Fraction(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(this.denominator, otherParsed.numerator));
};
_proto.toSignificant = function toSignificant(significantDigits, format, rounding) {
if (format === void 0) {
format = {
groupSeparator: ''
};
}
if (rounding === void 0) {
rounding = exports.Rounding.ROUND_HALF_UP;
}
!Number.isInteger(significantDigits) ? invariant(false, significantDigits + " is not an integer.") : void 0;
!(significantDigits > 0) ? invariant(false, significantDigits + " is not positive.") : void 0;
Decimal.set({
precision: significantDigits + 1,
rounding: toSignificantRounding[rounding]
});
var quotient = new Decimal(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(significantDigits);
return quotient.toFormat(quotient.decimalPlaces(), format);
};
_proto.toFixed = function toFixed(decimalPlaces, format, rounding) {
if (format === void 0) {
format = {
groupSeparator: ''
};
}
if (rounding === void 0) {
rounding = exports.Rounding.ROUND_HALF_UP;
}
!Number.isInteger(decimalPlaces) ? invariant(false, decimalPlaces + " is not an integer.") : void 0;
!(decimalPlaces >= 0) ? invariant(false, decimalPlaces + " is negative.") : void 0;
Big.DP = decimalPlaces;
Big.RM = toFixedRounding[rounding];
return new Big(this.numerator.toString()).div(this.denominator.toString()).toFormat(decimalPlaces, format);
};
_createClass(Fraction, [{
key: "quotient",
get: function get() {
return JSBI.divide(this.numerator, this.denominator);
} // remainder after floor division
}, {
key: "remainder",
get: function get() {
return new Fraction(JSBI.remainder(this.numerator, this.denominator), this.denominator);
}
}]);
return Fraction;
}();
var Big$1 = /*#__PURE__*/toFormat(_Big);
var CurrencyAmount = /*#__PURE__*/function (_Fraction) {
_inheritsLoose(CurrencyAmount, _Fraction);
// amount _must_ be raw, i.e. in the native representation
function CurrencyAmount(currency, amount) {
var _this;
var parsedAmount = parseBigintIsh(amount);
validateSolidityTypeInstance(parsedAmount, exports.SolidityType.uint256);
_this = _Fraction.call(this, parsedAmount, JSBI.exponentiate(TEN, JSBI.BigInt(currency.decimals))) || this;
_this.currency = currency;
return _this;
}
/**
* Helper that calls the constructor with the ETHER currency
* @param amount ether amount in wei
*/
CurrencyAmount.nativeCurrency = function nativeCurrency(amount, chainId) {
var nativeCurrency = Currency.getNative(chainId);
!!!nativeCurrency ? invariant(false, 'NO_NATIVE_CURRENCY') : void 0;
return new CurrencyAmount(nativeCurrency, amount);
}
/**
* Helper that calls the constructor with the USD currency
* @param amount amount of usd experessed in wei (with 18 decimals resolution)
*/
;
CurrencyAmount.usd = function usd(amount) {
return new CurrencyAmount(USD, amount);
};
var _proto = CurrencyAmount.prototype;
_proto.add = function add(other) {
!currencyEquals(this.currency, other.currency) ? invariant(false, 'TOKEN') : void 0;
return new CurrencyAmount(this.currency, JSBI.add(this.raw, other.raw));
};
_proto.subtract = function subtract(other) {
!currencyEquals(this.currency, other.currency) ? invariant(false, 'TOKEN') : void 0;
return new CurrencyAmount(this.currency, JSBI.subtract(this.raw, other.raw));
};
_proto.toSignificant = function toSignificant(significantDigits, format, rounding) {
if (significantDigits === void 0) {
significantDigits = 6;
}
if (rounding === void 0) {
rounding = exports.Rounding.ROUND_DOWN;
}
return _Fraction.prototype.toSignificant.call(this, significantDigits, format, rounding);
};
_proto.toFixed = function toFixed(decimalPlaces, format, rounding) {
if (decimalPlaces === void 0) {
decimalPlaces = this.currency.decimals;
}
if (rounding === void 0) {
rounding = exports.Rounding.ROUND_DOWN;
}
!(decimalPlaces <= this.currency.decimals) ? invariant(false, 'DECIMALS') : void 0;
return _Fraction.prototype.toFixed.call(this, decimalPlaces, format, rounding);
};
_proto.toExact = function toExact(format) {
if (format === void 0) {
format = {
groupSeparator: ''
};
}
Big$1.DP = this.currency.decimals;
return new Big$1(this.numerator.toString()).div(this.denominator.toString()).toFormat(format);
};
_createClass(CurrencyAmount, [{
key: "raw",
get: function get() {
return this.numerator;
}
}]);
return CurrencyAmount;
}(Fraction);
var TokenAmount = /*#__PURE__*/function (_CurrencyAmount) {
_inheritsLoose(TokenAmount, _CurrencyAmount);
//