@pancakeswap/swap-sdk-evm
Version:
An SDK for Pancakeswap EVM based chains
394 lines (389 loc) • 10.1 kB
JavaScript
import { ChainId } from '@pancakeswap/chains';
import { Percent, Token, NativeCurrency } from '@pancakeswap/swap-sdk-core';
import { getAddress } from 'viem';
import invariant2 from 'tiny-invariant';
import warning from 'tiny-warning';
// src/constants.ts
function validateAndParseAddress(address) {
try {
const checksummedAddress = getAddress(address);
warning(address === checksummedAddress, `${address} is not checksummed.`);
return checksummedAddress;
} catch (error) {
invariant2(false, `${address} is not a valid address.`);
}
}
// src/entities/erc20Token.ts
var ERC20Token = class extends Token {
constructor(chainId, address, decimals, symbol, name, projectLink) {
super(chainId, validateAndParseAddress(address), decimals, symbol, name, projectLink);
}
};
// src/constants.ts
var ZERO_PERCENT = new Percent("0");
var ONE_HUNDRED_PERCENT = new Percent("1");
var WETH9 = {
[ ]: new ERC20Token(
ChainId.ETHEREUM,
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
18,
"WETH",
"Wrapped Ether",
"https://weth.io"
),
[ ]: new ERC20Token(
ChainId.GOERLI,
"0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6",
18,
"WETH",
"Wrapped Ether",
"https://weth.io"
),
[ ]: new ERC20Token(
ChainId.BSC,
"0x2170Ed0880ac9A755fd29B2688956BD959F933F8",
18,
"ETH",
"Binance-Peg Ethereum Token",
"https://ethereum.org"
),
[ ]: new ERC20Token(
ChainId.BSC,
"0xE7bCB9e341D546b66a46298f4893f5650a56e99E",
18,
"ETH",
"ETH",
"https://ethereum.org"
),
[ ]: new ERC20Token(
ChainId.ARBITRUM_ONE,
"0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
18,
"WETH",
"Wrapped Ether",
"https://weth.io"
),
[ ]: new ERC20Token(
ChainId.ARBITRUM_GOERLI,
"0xEe01c0CD76354C383B8c7B4e65EA88D00B06f36f",
18,
"WETH",
"Wrapped Ether",
"https://weth.io"
),
[ ]: new ERC20Token(
ChainId.ZKSYNC,
"0x5AEa5775959fBC2557Cc8789bC1bf90A239D9a91",
18,
"WETH",
"Wrapped Ether",
"https://weth.io"
),
[ ]: new ERC20Token(
ChainId.ZKSYNC_TESTNET,
"0x02968DB286f24cB18bB5b24903eC8eBFAcf591C0",
18,
"WETH",
"Wrapped Ether",
"https://weth.io"
),
[ ]: new ERC20Token(
ChainId.POLYGON_ZKEVM,
"0x4F9A0e7FD2Bf6067db6994CF12E4495Df938E6e9",
18,
"WETH",
"Wrapped Ether",
"https://weth.io"
),
[ ]: new ERC20Token(
ChainId.POLYGON_ZKEVM_TESTNET,
"0x30ec47F7DFae72eA79646e6cf64a8A7db538915b",
18,
"WETH",
"Wrapped Ether",
"https://weth.io"
),
[ ]: new ERC20Token(
ChainId.LINEA,
"0xe5D7C2a44FfDDf6b295A15c148167daaAf5Cf34f",
18,
"WETH",
"Wrapped Ether",
"https://weth.io"
),
[ ]: new ERC20Token(
ChainId.LINEA_TESTNET,
"0x2C1b868d6596a18e32E61B901E4060C872647b6C",
18,
"WETH",
"Wrapped Ether",
"https://weth.io"
),
[ ]: new ERC20Token(
ChainId.OPBNB_TESTNET,
"0x584f7b986d9942B0859a1E6921efA5342A673d04",
18,
"WETH",
"Wrapped Ether",
"https://weth.io"
),
[ ]: new ERC20Token(
ChainId.OPBNB,
"0xE7798f023fC62146e8Aa1b36Da45fb70855a77Ea",
18,
"ETH",
"Binance-Peg Ethereum Token",
"https://ethereum.org"
),
[ ]: new ERC20Token(
ChainId.BASE,
"0x4200000000000000000000000000000000000006",
18,
"WETH",
"Wrapped Ether",
"https://weth.io"
),
[ ]: new ERC20Token(
ChainId.BASE_TESTNET,
"0x4200000000000000000000000000000000000006",
18,
"WETH",
"Wrapped Ether",
"https://weth.io"
),
[ ]: new ERC20Token(
ChainId.SCROLL_SEPOLIA,
"0x5300000000000000000000000000000000000004",
18,
"WETH",
"Wrapped Ether",
"https://weth.io"
),
[ ]: new ERC20Token(
ChainId.SEPOLIA,
"0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14",
18,
"WETH",
"Wrapped Ether",
"https://weth.io"
),
[ ]: new ERC20Token(
ChainId.ARBITRUM_SEPOLIA,
"0x1bdc540dEB9Ed1fA29964DeEcCc524A8f5e2198e",
18,
"WETH",
"Wrapped Ether",
"https://weth.io"
),
[ ]: new ERC20Token(
ChainId.BASE_SEPOLIA,
"0x4200000000000000000000000000000000000006",
18,
"WETH",
"Wrapped Ether",
"https://weth.io"
),
[ ]: new ERC20Token(
ChainId.MONAD_TESTNET,
"0x760AfE86e5de5fa0Ee542fc7B7B713e1c5425701",
18,
"WMON",
"Wrapped Monad",
"https://www.monad.xyz/"
)
};
var WBNB = {
[ ]: new ERC20Token(
ChainId.ETHEREUM,
"0x418D75f65a02b3D53B2418FB8E1fe493759c7605",
18,
"WBNB",
"Wrapped BNB",
"https://www.binance.org"
),
[ ]: new ERC20Token(
ChainId.BSC,
"0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
18,
"WBNB",
"Wrapped BNB",
"https://www.binance.org"
),
[ ]: new ERC20Token(
ChainId.BSC_TESTNET,
"0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd",
18,
"WBNB",
"Wrapped BNB",
"https://www.binance.org"
),
[ ]: new ERC20Token(
ChainId.OPBNB_TESTNET,
"0x4200000000000000000000000000000000000006",
18,
"WBNB",
"Wrapped BNB",
"https://www.binance.org"
),
[ ]: new ERC20Token(
ChainId.OPBNB,
"0x4200000000000000000000000000000000000006",
18,
"WBNB",
"Wrapped BNB",
"https://www.binance.org"
)
};
var WNATIVE = {
[ ]: WETH9[ChainId.ETHEREUM],
[ ]: WETH9[ChainId.GOERLI],
[ ]: WBNB[ChainId.BSC],
[ ]: WBNB[ChainId.BSC_TESTNET],
[ ]: WETH9[ChainId.ARBITRUM_ONE],
[ ]: WETH9[ChainId.ARBITRUM_GOERLI],
[ ]: WETH9[ChainId.POLYGON_ZKEVM],
[ ]: WETH9[ChainId.POLYGON_ZKEVM_TESTNET],
[ ]: WETH9[ChainId.ZKSYNC],
[ ]: WETH9[ChainId.ZKSYNC_TESTNET],
[ ]: WETH9[ChainId.LINEA],
[ ]: WETH9[ChainId.LINEA_TESTNET],
[ ]: WBNB[ChainId.OPBNB_TESTNET],
[ ]: WBNB[ChainId.OPBNB],
[ ]: WETH9[ChainId.BASE],
[ ]: WETH9[ChainId.BASE_TESTNET],
[ ]: WETH9[ChainId.SCROLL_SEPOLIA],
[ ]: WETH9[ChainId.SEPOLIA],
[ ]: WETH9[ChainId.ARBITRUM_SEPOLIA],
[ ]: WETH9[ChainId.BASE_SEPOLIA],
[ ]: WETH9[ChainId.MONAD_TESTNET]
};
var ETHER = { name: "Ether", symbol: "ETH", decimals: 18 };
var BNB = {
name: "Binance Chain Native Token",
symbol: "BNB",
decimals: 18
};
var NATIVE = {
[ ]: ETHER,
[ ]: { name: "Goerli Ether", symbol: "GOR", decimals: 18 },
[ ]: BNB,
[ ]: {
name: "Binance Chain Native Token",
symbol: "tBNB",
decimals: 18
},
[ ]: ETHER,
[ ]: {
name: "Arbitrum Goerli Ether",
symbol: "AGOR",
decimals: 18
},
[ ]: ETHER,
[ ]: ETHER,
[ ]: ETHER,
[ ]: ETHER,
[ ]: ETHER,
[ ]: ETHER,
[ ]: BNB,
[ ]: {
name: "Binance Chain Native Token",
symbol: "tBNB",
decimals: 18
},
[ ]: ETHER,
[ ]: ETHER,
[ ]: ETHER,
[ ]: {
name: "Sepolia Ether",
symbol: "SEP",
decimals: 18
},
[ ]: {
name: "Arbitrum Sepolia Ether",
symbol: "ETH",
decimals: 18
},
[ ]: {
name: "Sepolia Ether",
symbol: "ETH",
decimals: 18
},
[ ]: {
name: "Monad Testnet Ether",
symbol: "MON",
decimals: 18
}
};
var _Native = class extends NativeCurrency {
constructor({
chainId,
decimals,
name,
symbol
}) {
super(chainId, decimals, symbol, name);
}
get wrapped() {
const wnative = WNATIVE[this.chainId];
invariant2(!!wnative, "WRAPPED");
return wnative;
}
static onChain(chainId) {
if (chainId in this.cache) {
return this.cache[chainId];
}
invariant2(!!NATIVE[chainId], "NATIVE_CURRENCY");
const { decimals, name, symbol } = NATIVE[chainId];
return this.cache[chainId] = new _Native({ chainId, decimals, symbol, name });
}
equals(other) {
return other.isNative && other.chainId === this.chainId;
}
};
var Native = _Native;
Native.cache = {};
// src/abis/ERC20.ts
var erc20Abi = [
{
constant: true,
inputs: [],
name: "decimals",
outputs: [{ name: "", type: "uint8" }],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [{ name: "", type: "address" }],
name: "balanceOf",
outputs: [{ name: "", type: "uint256" }],
payable: false,
stateMutability: "view",
type: "function"
}
];
var _Ether = class extends NativeCurrency {
constructor(chainId) {
super(chainId, 18, "ETH", "Ether");
}
get wrapped() {
const weth9 = WETH9[this.chainId];
invariant2(!!weth9, "WRAPPED");
return weth9;
}
static onChain(chainId) {
if (!this._etherCache[chainId]) {
this._etherCache[chainId] = new _Ether(chainId);
}
return this._etherCache[chainId];
}
equals(other) {
return other.isNative && other.chainId === this.chainId;
}
};
var Ether = _Ether;
Ether._etherCache = {};
export { ERC20Token, Ether, NATIVE, Native, ONE_HUNDRED_PERCENT, WBNB, WETH9, WNATIVE, ZERO_PERCENT, erc20Abi, validateAndParseAddress };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=index.mjs.map