@ponderfinance/sdk
Version:
SDK for interacting with Ponder DEX and 55555 Launcher
1,753 lines (1,744 loc) • 219 kB
JavaScript
'use strict';
var viem = require('viem');
var chains = require('viem/chains');
var dex = require('@ponderfinance/dex');
var react = require('react');
var reactQuery = require('@tanstack/react-query');
var jsxRuntime = require('react/jsx-runtime');
// src/index.ts
var bitkubChain = {
id: 96,
name: "Bitkub",
nativeCurrency: {
decimals: 18,
name: "KUB",
symbol: "KUB"
},
rpcUrls: {
default: { http: ["https://rpc.bitkubchain.io"] },
public: { http: ["https://rpc.bitkubchain.io"] }
},
blockExplorers: {
default: { name: "Bkcscan", url: "https://bkcscan.com" }
},
testnet: false
};
var bitkubTestnetChain = {
id: 25925,
name: "Bitkub Testnet",
nativeCurrency: {
decimals: 18,
name: "KUB",
symbol: "KUB"
},
rpcUrls: {
default: { http: ["https://rpc-testnet.bitkubchain.io"] },
public: { http: ["https://rpc-testnet.bitkubchain.io"] }
},
blockExplorers: {
default: { name: "Bkcscan Testnet", url: "https://testnet.bkcscan.com" }
},
testnet: true
};
var SUPPORTED_CHAINS = {
96: bitkubChain,
25925: bitkubTestnetChain,
1: chains.mainnet
};
function getChainFromId(chainId) {
const chain = SUPPORTED_CHAINS[chainId];
if (!chain) throw new Error(`Chain ${chainId} not supported`);
return chain;
}
// src/abis/bridge.ts
var bridgeAbi = [
{
inputs: [],
name: "NATIVE_REPRESENTATION",
outputs: [{ internalType: "address", name: "", type: "address" }],
stateMutability: "view",
type: "function"
},
{
inputs: [
{ internalType: "address", name: "token_", type: "address" },
{ internalType: "uint256", name: "amount_", type: "uint256" },
{ internalType: "uint64", name: "destChainID_", type: "uint64" },
{
internalType: "enum BridgeERC20V3.DEST_TOKEN_TYPE",
name: "destTokenType_",
type: "uint8"
}
],
name: "bridge",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{ internalType: "uint64", name: "destChainID_", type: "uint64" },
{
internalType: "enum BridgeERC20V3.DEST_TOKEN_TYPE",
name: "destTokenType_",
type: "uint8"
}
],
name: "bridge",
outputs: [],
stateMutability: "payable",
type: "function"
},
{
inputs: [
{ internalType: "address", name: "", type: "address" },
{ internalType: "uint64", name: "", type: "uint64" }
],
name: "bridgeMap",
outputs: [
{ internalType: "bool", name: "enabled", type: "bool" },
{ internalType: "address", name: "token", type: "address" },
{ internalType: "uint64", name: "chainID", type: "uint64" },
{
internalType: "enum BridgeERC20V3.DEST_TOKEN_TYPE",
name: "allowedDestTokenTypes",
type: "uint8"
},
{ internalType: "address", name: "feeReceiver", type: "address" },
{ internalType: "uint256", name: "fee", type: "uint256" },
{
internalType: "enum BridgeERC20V3.FEE_TYPE",
name: "feeType",
type: "uint8"
},
{
internalType: "enum BridgeERC20V3.TOKEN_STRATEGY",
name: "strategy",
type: "uint8"
},
{ internalType: "address", name: "receiver", type: "address" }
],
stateMutability: "view",
type: "function"
},
{
inputs: [],
name: "committee",
outputs: [{ internalType: "address", name: "", type: "address" }],
stateMutability: "view",
type: "function"
},
{
inputs: [
{ internalType: "address", name: "token_", type: "address" },
{ internalType: "uint64", name: "chainID_", type: "uint64" },
{ internalType: "uint256", name: "amount_", type: "uint256" }
],
name: "computeFeeByFeeType",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
stateMutability: "view",
type: "function"
},
{
inputs: [{ internalType: "address", name: "token_", type: "address" }],
name: "getDestChainIDsAndAllowedTokenTypes",
outputs: [
{
components: [
{ internalType: "uint248", name: "chainID", type: "uint248" },
{
internalType: "enum BridgeERC20V3.DEST_TOKEN_TYPE",
name: "allowedDestTokenTypes",
type: "uint8"
}
],
internalType: "struct BridgeERC20V3.ChainIDAndAllowedDestTokenTypes[]",
name: "",
type: "tuple[]"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [],
name: "pause",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [],
name: "paused",
outputs: [{ internalType: "bool", name: "", type: "bool" }],
stateMutability: "view",
type: "function"
}
];
var bridge_default = bridgeAbi;
// src/constants/addresses.ts
var BRIDGE_ADDRESSES = {
1: {
bridge: "0x89943b2499d678fb2d382c66b7baed00b732e753"
},
96: {
bridge: "0x89943b2499d678fb2d382C66b7BaeD00b732e753"
},
25925: {
bridge: "0x0000000000000000000000000000000000000000"
}
};
var PONDER_ADDRESSES = {
25925: {
factory: "0x4a0aB14A75eB5F1E07aC8467DCE811687cFa35B3",
router: "0xAD17b142bD4AcFB4441e6586B9aBdfD40d1C2a29",
masterChef: "0x65e358F9C9e3B9F0832f001cC4Cb058931fC7D7c",
launcher: "0x0B83ecDBB4d52fb8661c0374eB20021Ef59Bfc95",
oracle: "0xce1fdA5AC44f495321C163103B11916933851B83",
kkubUnwrapper: "0x4B3C50378221080f1DA0768E7b848987c0A7412F",
ponderToken: "0x33C9B02596d7b1CB4066cC2CeEdd37f3A7c7Aa07",
staking: "0x0f9b00Cc79dFAAF3818d6219246033b4951Fb584",
feeDistributor: "0xAf7d796A6589369AB56c423a1086CB604f8b7EFD"
},
96: {
factory: "0x20b17e92dd1866ec647acaa38fe1f7075e4b359e",
router: "0xd19c5cebfa9a8919cc3db2f19163089febd9604e",
masterChef: "0x6f2b10fa6d88a0c2013d08ef9655a07356e8d53c",
launcher: "0x2a610b695e21fe6560343c003b0dd4c26ef8790d",
oracle: "0xcf814870800a3bcac4a6b858424a9370a64c75ad",
kkubUnwrapper: "0xea1b8372b2ae06e905957f82969da8e8a3ba47c4",
ponderToken: "0xe0432224871917fb5a137f4a153a51ecf9f74f57",
staking: "0x6c8119d33fd43f6b254d041cd5d2675586731dd5",
feeDistributor: "0x37196731cdf654e0572881176cb256d99c7fdc2d"
}
};
var KKUB_ADDRESS = {
25925: "0xBa71efd94be63bD47B78eF458DE982fE29f552f7",
96: "0x67eBD850304c70d983B2d1b93ea79c7CD6c3F6b5"
};
// src/contracts/factory.ts
var Factory = class {
constructor(chainId, publicClient, walletClient) {
this.chainId = chainId;
this.chain = getChainFromId(chainId);
this.address = PONDER_ADDRESSES[chainId].factory;
this.publicClient = publicClient;
this.walletClient = walletClient;
}
// Read Methods
async getPair(tokenA, tokenB) {
return this.publicClient.readContract({
address: this.address,
abi: dex.ponderfactoryAbi,
functionName: "getPair",
args: [tokenA, tokenB]
});
}
async allPairs(index) {
return this.publicClient.readContract({
address: this.address,
abi: dex.ponderfactoryAbi,
functionName: "allPairs",
args: [BigInt(index)]
});
}
async allPairsLength() {
return this.publicClient.readContract({
address: this.address,
abi: dex.ponderfactoryAbi,
functionName: "allPairsLength"
});
}
async feeTo() {
return this.publicClient.readContract({
address: this.address,
abi: dex.ponderfactoryAbi,
functionName: "feeTo"
});
}
async feeToSetter() {
return this.publicClient.readContract({
address: this.address,
abi: dex.ponderfactoryAbi,
functionName: "feeToSetter"
});
}
// Write Methods
async createPair({ tokenA, tokenB }) {
if (!this.walletClient) throw new Error("Wallet client required");
const hash = await this.walletClient.writeContract({
chain: this.chain,
address: this.address,
abi: dex.ponderfactoryAbi,
functionName: "createPair",
args: [tokenA, tokenB]
});
const wait = async () => {
const receipt = await this.publicClient.waitForTransactionReceipt({ hash });
const pairCreatedLog = receipt.logs.find(
(log) => log.topics[0] === "0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9"
// PairCreated event signature
);
if (!pairCreatedLog || pairCreatedLog.topics.length < 4) {
throw new Error("Pair creation failed");
}
const topics = pairCreatedLog.topics;
return {
pairAddress: `0x${topics?.[3]?.slice(26)}`,
token0: `0x${topics?.[1]?.slice(26)}`,
token1: `0x${topics?.[2]?.slice(26)}`
};
};
return { hash, wait };
}
async setFeeTo(newFeeTo) {
if (!this.walletClient) throw new Error("Wallet client required");
return this.walletClient.writeContract({
chain: this.chain,
address: this.address,
abi: dex.ponderfactoryAbi,
functionName: "setFeeTo",
args: [newFeeTo]
});
}
async setFeeToSetter(newFeeToSetter) {
if (!this.walletClient) throw new Error("Wallet client required");
return this.walletClient.writeContract({
chain: this.chain,
address: this.address,
abi: dex.ponderfactoryAbi,
functionName: "setFeeToSetter",
args: [newFeeToSetter]
});
}
async setMigrator(newMigrator) {
if (!this.walletClient) throw new Error("Wallet client required");
return this.walletClient.writeContract({
chain: this.chain,
address: this.address,
abi: dex.ponderfactoryAbi,
functionName: "setMigrator",
args: [newMigrator]
});
}
// Helper Methods
/**
* Get all pairs created by the factory
* @returns Array of pair addresses
*/
async getAllPairs() {
const length = await this.allPairsLength();
const pairs = [];
for (let i = 0; i < Number(length); i++) {
pairs.push(await this.allPairs(i));
}
return pairs;
}
};
// src/contracts/pair.ts
var Pair = class {
constructor(chainId, pairAddress, publicClient, walletClient) {
this.chainId = chainId;
this.chain = getChainFromId(chainId);
this.address = pairAddress;
this.publicClient = publicClient;
this.walletClient = walletClient;
}
// Read Methods
async MINIMUM_LIQUIDITY() {
return this.publicClient.readContract({
address: this.address,
abi: dex.ponderpairAbi,
functionName: "minimumLiquidity"
});
}
async factory() {
return this.publicClient.readContract({
address: this.address,
abi: dex.ponderpairAbi,
functionName: "factory"
});
}
async token0() {
return this.publicClient.readContract({
address: this.address,
abi: dex.ponderpairAbi,
functionName: "token0"
});
}
async token1() {
return this.publicClient.readContract({
address: this.address,
abi: dex.ponderpairAbi,
functionName: "token1"
});
}
async getReserves() {
const [reserve0, reserve1, blockTimestampLast] = await this.publicClient.readContract({
address: this.address,
abi: dex.ponderpairAbi,
functionName: "getReserves"
});
return {
reserve0,
reserve1,
blockTimestampLast
};
}
async price0CumulativeLast() {
return this.publicClient.readContract({
address: this.address,
abi: dex.ponderpairAbi,
functionName: "price0CumulativeLast"
});
}
async price1CumulativeLast() {
return this.publicClient.readContract({
address: this.address,
abi: dex.ponderpairAbi,
functionName: "price1CumulativeLast"
});
}
async kLast() {
return this.publicClient.readContract({
address: this.address,
abi: dex.ponderpairAbi,
functionName: "kLast"
});
}
async launcher() {
return this.publicClient.readContract({
address: this.address,
abi: dex.ponderpairAbi,
functionName: "launcher"
});
}
// ERC20 Read Methods
async name() {
return this.publicClient.readContract({
address: this.address,
abi: dex.ponderpairAbi,
functionName: "name"
});
}
async symbol() {
return this.publicClient.readContract({
address: this.address,
abi: dex.ponderpairAbi,
functionName: "symbol"
});
}
async decimals() {
return this.publicClient.readContract({
address: this.address,
abi: dex.ponderpairAbi,
functionName: "decimals"
});
}
async totalSupply() {
return this.publicClient.readContract({
address: this.address,
abi: dex.ponderpairAbi,
functionName: "totalSupply"
});
}
async balanceOf(account) {
return this.publicClient.readContract({
address: this.address,
abi: dex.ponderpairAbi,
functionName: "balanceOf",
args: [account]
});
}
async allowance(owner, spender) {
return this.publicClient.readContract({
address: this.address,
abi: dex.ponderpairAbi,
functionName: "allowance",
args: [owner, spender]
});
}
// Write Methods
async mint(to) {
if (!this.walletClient) throw new Error("Wallet client required");
const hash = await this.walletClient.writeContract({
chain: this.chain,
address: this.address,
abi: dex.ponderpairAbi,
functionName: "mint",
args: [to]
});
const wait = async () => {
const receipt = await this.publicClient.waitForTransactionReceipt({
hash
});
const mintLog = receipt.logs.find(
(log) => log.topics[0] === "0x4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f"
// Mint event signature
);
if (!mintLog || !mintLog.data) {
throw new Error("Mint failed");
}
return {
liquidity: BigInt(mintLog.data)
};
};
return { hash, wait };
}
async burn(to) {
if (!this.walletClient) throw new Error("Wallet client required");
const hash = await this.walletClient.writeContract({
chain: this.chain,
address: this.address,
abi: dex.ponderpairAbi,
functionName: "burn",
args: [to]
});
const wait = async () => {
const receipt = await this.publicClient.waitForTransactionReceipt({
hash
});
const burnLog = receipt.logs.find(
(log) => log.topics[0] === "0xdccd412f0b1252819cb1fd330b93224ca42612892bb3f4f789976e6d81936496"
// Burn event signature
);
if (!burnLog || !burnLog.data) {
throw new Error("Burn failed");
}
const data = burnLog.data.slice(2);
return {
amount0: BigInt("0x" + data.slice(0, 64)),
amount1: BigInt("0x" + data.slice(64, 128))
};
};
return { hash, wait };
}
async swap({ amount0Out, amount1Out, to, data }) {
if (!this.walletClient) throw new Error("Wallet client required");
return this.walletClient.writeContract({
chain: this.chain,
address: this.address,
abi: dex.ponderpairAbi,
functionName: "swap",
args: [amount0Out, amount1Out, to, data]
});
}
async sync() {
if (!this.walletClient) throw new Error("Wallet client required");
return this.walletClient.writeContract({
chain: this.chain,
address: this.address,
abi: dex.ponderpairAbi,
functionName: "sync"
});
}
async skim(to) {
if (!this.walletClient) throw new Error("Wallet client required");
return this.walletClient.writeContract({
chain: this.chain,
address: this.address,
abi: dex.ponderpairAbi,
functionName: "skim",
args: [to]
});
}
// Standard ERC20 write methods
async approve(spender, value) {
if (!this.walletClient) throw new Error("Wallet client required");
return this.walletClient.writeContract({
chain: this.chain,
address: this.address,
abi: dex.ponderpairAbi,
functionName: "approve",
args: [spender, value]
});
}
async transfer(to, value) {
if (!this.walletClient) throw new Error("Wallet client required");
return this.walletClient.writeContract({
chain: this.chain,
address: this.address,
abi: dex.ponderpairAbi,
functionName: "transfer",
args: [to, value]
});
}
async transferFrom(from, to, value) {
if (!this.walletClient) throw new Error("Wallet client required");
return this.walletClient.writeContract({
chain: this.chain,
address: this.address,
abi: dex.ponderpairAbi,
functionName: "transferFrom",
args: [from, to, value]
});
}
};
// src/contracts/router.ts
var Router = class {
constructor(chainId, publicClient, walletClient) {
this.chainId = chainId;
this.chain = getChainFromId(chainId);
this.address = PONDER_ADDRESSES[chainId].router;
this.publicClient = publicClient;
this.walletClient = walletClient;
}
// Read Methods
async factory() {
return this.publicClient.readContract({
address: this.address,
abi: dex.ponderrouterAbi,
functionName: "FACTORY"
});
}
async KKUB() {
return this.publicClient.readContract({
address: this.address,
abi: dex.ponderrouterAbi,
functionName: "kkub"
});
}
async getAmountOut(amountIn, path) {
return this.publicClient.readContract({
address: this.address,
abi: dex.ponderrouterAbi,
functionName: "getAmountsOut",
args: [amountIn, path]
});
}
async getAmountIn(amountOut, path) {
return this.publicClient.readContract({
address: this.address,
abi: dex.ponderrouterAbi,
functionName: "getAmountsIn",
args: [amountOut, path]
});
}
async getAmountsOut(amountIn, path) {
return this.publicClient.readContract({
address: this.address,
abi: dex.ponderrouterAbi,
functionName: "getAmountsOut",
args: [amountIn, path]
});
}
async getAmountsIn(amountOut, path) {
return this.publicClient.readContract({
address: this.address,
abi: dex.ponderrouterAbi,
functionName: "getAmountsIn",
args: [amountOut, path]
});
}
// Write Methods - Liquidity
async addLiquidity(params) {
if (!this.walletClient) throw new Error("Wallet client required");
return this.walletClient.writeContract({
chain: this.chain,
address: this.address,
abi: dex.ponderrouterAbi,
functionName: "addLiquidity",
args: [
params.tokenA,
params.tokenB,
params.amountADesired,
params.amountBDesired,
params.amountAMin,
params.amountBMin,
params.to,
params.deadline
]
});
}
async addLiquidityETH(params, value) {
if (!this.walletClient) throw new Error("Wallet client required");
return this.walletClient.writeContract({
chain: this.chain,
address: this.address,
abi: dex.ponderrouterAbi,
functionName: "addLiquidityETH",
args: [
params.token,
params.amountTokenDesired,
params.amountTokenMin,
params.amountETHMin,
params.to,
params.deadline
],
value
});
}
async removeLiquidity(params) {
if (!this.walletClient) throw new Error("Wallet client required");
return this.walletClient.writeContract({
chain: this.chain,
address: this.address,
abi: dex.ponderrouterAbi,
functionName: "removeLiquidity",
args: [
params.tokenA,
params.tokenB,
params.liquidity,
params.amountAMin,
params.amountBMin,
params.to,
params.deadline
]
});
}
async removeLiquidityETH(params) {
if (!this.walletClient) throw new Error("Wallet client required");
return this.walletClient.writeContract({
chain: this.chain,
address: this.address,
abi: dex.ponderrouterAbi,
functionName: "removeLiquidityETH",
args: [
params.token,
params.liquidity,
params.amountTokenMin,
params.amountETHMin,
params.to,
params.deadline
]
});
}
// Write Methods - Swaps
async swapExactTokensForTokens(params) {
if (!this.walletClient) throw new Error("Wallet client required");
return this.walletClient.writeContract({
chain: this.chain,
address: this.address,
abi: dex.ponderrouterAbi,
functionName: "swapExactTokensForTokens",
args: [
params.amountIn,
params.amountOutMin,
params.path,
params.to,
params.deadline
]
});
}
async swapTokensForExactTokens(params) {
if (!this.walletClient) throw new Error("Wallet client required");
return this.walletClient.writeContract({
chain: this.chain,
address: this.address,
abi: dex.ponderrouterAbi,
functionName: "swapTokensForExactTokens",
args: [
params.amountOut,
params.amountInMax,
params.path,
params.to,
params.deadline
]
});
}
};
// src/contracts/masterchef.ts
var MasterChef = class {
constructor(chainId, publicClient, walletClient) {
this.chainId = chainId;
this.chain = getChainFromId(chainId);
this.address = PONDER_ADDRESSES[chainId].masterChef;
this.publicClient = publicClient;
this.walletClient = walletClient;
}
// Read Methods
async ponder() {
return this.publicClient.readContract({
address: this.address,
abi: dex.pondermasterchefAbi,
functionName: "PONDER"
});
}
async factory() {
return this.publicClient.readContract({
address: this.address,
abi: dex.pondermasterchefAbi,
functionName: "FACTORY"
});
}
async ponderPerSecond() {
return this.publicClient.readContract({
address: this.address,
abi: dex.pondermasterchefAbi,
functionName: "ponderPerSecond"
});
}
async poolLength() {
return this.publicClient.readContract({
address: this.address,
abi: dex.pondermasterchefAbi,
functionName: "poolLength"
});
}
async poolInfo(pid) {
const [
lpToken,
allocPoint,
lastRewardTime,
accPonderPerShare,
totalStaked,
totalWeightedShares,
depositFeeBP,
boostMultiplier
] = await this.publicClient.readContract({
address: this.address,
abi: dex.pondermasterchefAbi,
functionName: "poolInfo",
args: [pid]
});
return {
lpToken,
allocPoint,
lastRewardTime,
accPonderPerShare,
totalStaked,
totalWeightedShares,
depositFeeBP,
boostMultiplier
};
}
async userInfo(pid, user) {
const [amount, rewardDebt, ponderStaked] = await this.publicClient.readContract({
address: this.address,
abi: dex.pondermasterchefAbi,
functionName: "userInfo",
args: [pid, user]
});
return {
amount,
rewardDebt,
ponderStaked
};
}
async pendingPonder(pid, user) {
return this.publicClient.readContract({
address: this.address,
abi: dex.pondermasterchefAbi,
functionName: "pendingPonder",
args: [pid, user]
});
}
async totalAllocPoint() {
return this.publicClient.readContract({
address: this.address,
abi: dex.pondermasterchefAbi,
functionName: "totalAllocPoint"
});
}
async startTime() {
return this.publicClient.readContract({
address: this.address,
abi: dex.pondermasterchefAbi,
functionName: "startTime"
});
}
async owner() {
return this.publicClient.readContract({
address: this.address,
abi: dex.pondermasterchefAbi,
functionName: "owner"
});
}
// Write Methods
async add(params) {
if (!this.walletClient) throw new Error("Wallet client required");
return this.walletClient.writeContract({
chain: this.chain,
address: this.address,
abi: dex.pondermasterchefAbi,
functionName: "add",
args: [
params.allocPoint,
params.lpToken,
params.depositFeeBP,
params.boostMultiplier,
params.withUpdate
]
});
}
async set(pid, allocPoint, withUpdate) {
if (!this.walletClient) throw new Error("Wallet client required");
return this.walletClient.writeContract({
chain: this.chain,
address: this.address,
abi: dex.pondermasterchefAbi,
functionName: "set",
args: [pid, allocPoint, withUpdate]
});
}
async deposit(pid, amount) {
if (!this.walletClient) throw new Error("Wallet client required");
return this.walletClient.writeContract({
chain: this.chain,
address: this.address,
abi: dex.pondermasterchefAbi,
functionName: "deposit",
args: [pid, amount]
});
}
async withdraw(pid, amount) {
if (!this.walletClient) throw new Error("Wallet client required");
return this.walletClient.writeContract({
chain: this.chain,
address: this.address,
abi: dex.pondermasterchefAbi,
functionName: "withdraw",
args: [pid, amount]
});
}
async emergencyWithdraw(pid) {
if (!this.walletClient) throw new Error("Wallet client required");
return this.walletClient.writeContract({
chain: this.chain,
address: this.address,
abi: dex.pondermasterchefAbi,
functionName: "emergencyWithdraw",
args: [pid]
});
}
async boostStake(pid, amount) {
if (!this.walletClient) throw new Error("Wallet client required");
return this.walletClient.writeContract({
chain: this.chain,
address: this.address,
abi: dex.pondermasterchefAbi,
functionName: "boostStake",
args: [pid, amount]
});
}
async boostUnstake(pid, amount) {
if (!this.walletClient) throw new Error("Wallet client required");
return this.walletClient.writeContract({
chain: this.chain,
address: this.address,
abi: dex.pondermasterchefAbi,
functionName: "boostUnstake",
args: [pid, amount]
});
}
// Helper Methods
async getAllPools() {
const length = await this.poolLength();
const pools = [];
for (let i = 0n; i < length; i++) {
pools.push(await this.poolInfo(i));
}
return pools;
}
async getUserInfoForPools(user, pids) {
return Promise.all(pids.map((pid) => this.userInfo(pid, user)));
}
};
var LaunchToken = class {
constructor(chainId, tokenAddress, publicClient, walletClient) {
this.chainId = chainId;
this.chain = getChainFromId(chainId);
this.address = tokenAddress;
this.publicClient = publicClient;
this.walletClient = walletClient;
}
// Read Methods
async name() {
return this.publicClient.readContract({
address: this.address,
abi: dex.launchtokenAbi,
functionName: "name"
});
}
async symbol() {
return this.publicClient.readContract({
address: this.address,
abi: dex.launchtokenAbi,
functionName: "symbol"
});
}
async decimals() {
return this.publicClient.readContract({
address: this.address,
abi: dex.launchtokenAbi,
functionName: "decimals"
});
}
async totalSupply() {
return this.publicClient.readContract({
address: this.address,
abi: dex.launchtokenAbi,
functionName: "totalSupply"
});
}
async balanceOf(account) {
return this.publicClient.readContract({
address: this.address,
abi: dex.launchtokenAbi,
functionName: "balanceOf",
args: [account]
});
}
async allowance(owner, spender) {
return this.publicClient.readContract({
address: this.address,
abi: dex.launchtokenAbi,
functionName: "allowance",
args: [owner, spender]
});
}
// Launch Token specific read methods
async launcher() {
return this.publicClient.readContract({
address: this.address,
abi: dex.launchtokenAbi,
functionName: "launcher"
});
}
async factory() {
return this.publicClient.readContract({
address: this.address,
abi: dex.launchtokenAbi,
functionName: "FACTORY"
});
}
async router() {
return this.publicClient.readContract({
address: this.address,
abi: dex.launchtokenAbi,
functionName: "ROUTER"
});
}
async creator() {
return this.publicClient.readContract({
address: this.address,
abi: dex.launchtokenAbi,
functionName: "creator"
});
}
async vestingStart() {
return this.publicClient.readContract({
address: this.address,
abi: dex.launchtokenAbi,
functionName: "vestingStart"
});
}
async vestingEnd() {
return this.publicClient.readContract({
address: this.address,
abi: dex.launchtokenAbi,
functionName: "vestingEnd"
});
}
async totalVestedAmount() {
return this.publicClient.readContract({
address: this.address,
abi: dex.launchtokenAbi,
functionName: "totalVestedAmount"
});
}
async vestedClaimed() {
return this.publicClient.readContract({
address: this.address,
abi: dex.launchtokenAbi,
functionName: "vestedClaimed"
});
}
async TOTAL_SUPPLY() {
return this.publicClient.readContract({
address: this.address,
abi: dex.launchtokenAbi,
functionName: "totalSupply"
});
}
async getVestingInfo() {
const [total, claimed, available, start, end] = await this.publicClient.readContract({
address: this.address,
abi: dex.launchtokenAbi,
functionName: "getVestingInfo"
});
return {
total,
claimed,
available,
start,
end
};
}
// Write Methods
async approve(spender, value) {
if (!this.walletClient) throw new Error("Wallet client required");
return this.walletClient.writeContract({
chain: this.chain,
address: this.address,
abi: dex.launchtokenAbi,
functionName: "approve",
args: [spender, value]
});
}
async transfer(to, value) {
if (!this.walletClient) throw new Error("Wallet client required");
return this.walletClient.writeContract({
chain: this.chain,
address: this.address,
abi: dex.launchtokenAbi,
functionName: "transfer",
args: [to, value]
});
}
async transferFrom(from, to, value) {
if (!this.walletClient) throw new Error("Wallet client required");
return this.walletClient.writeContract({
chain: this.chain,
address: this.address,
abi: dex.launchtokenAbi,
functionName: "transferFrom",
args: [from, to, value]
});
}
async setupVesting(creator, amount) {
if (!this.walletClient) throw new Error("Wallet client required");
return this.walletClient.writeContract({
chain: this.chain,
address: this.address,
abi: dex.launchtokenAbi,
functionName: "setupVesting",
args: [creator, amount]
});
}
async enableTransfers() {
if (!this.walletClient) throw new Error("Wallet client required");
return this.walletClient.writeContract({
chain: this.chain,
address: this.address,
abi: dex.launchtokenAbi,
functionName: "enableTransfers"
});
}
async claimVestedTokens() {
if (!this.walletClient) throw new Error("Wallet client required");
return this.walletClient.writeContract({
chain: this.chain,
address: this.address,
abi: dex.launchtokenAbi,
functionName: "claimVestedTokens"
});
}
};
// src/contracts/pondertoken.ts
var Pondertoken = class {
// 1 year
constructor(chainId, tokenAddress, publicClient, walletClient) {
// Contract constants from PonderToken.sol
this.MAXIMUM_SUPPLY = 1000000000n * 10n ** 18n;
// 1 billion PONDER
this.MINTING_END = 4n * 365n * 24n * 60n * 60n;
// 4 years in seconds
this.TEAM_ALLOCATION = 150000000n * 10n ** 18n;
// 15%
this.VESTING_DURATION = 365n * 24n * 60n * 60n;
this.chainId = chainId;
this.chain = getChainFromId(chainId);
this.address = tokenAddress;
this.publicClient = publicClient;
this.walletClient = walletClient;
}
// Standard ERC20 Read Methods
async name() {
return this.publicClient.readContract({
address: this.address,
abi: [
{
inputs: [],
name: "name",
outputs: [{ internalType: "string", name: "", type: "string" }],
stateMutability: "view",
type: "function"
}
],
functionName: "name"
});
}
async symbol() {
return this.publicClient.readContract({
address: this.address,
abi: [
{
inputs: [],
name: "symbol",
outputs: [{ internalType: "string", name: "", type: "string" }],
stateMutability: "view",
type: "function"
}
],
functionName: "symbol"
});
}
async decimals() {
return this.publicClient.readContract({
address: this.address,
abi: [
{
inputs: [],
name: "decimals",
outputs: [{ internalType: "uint8", name: "", type: "uint8" }],
stateMutability: "view",
type: "function"
}
],
functionName: "decimals"
});
}
async totalSupply() {
return this.publicClient.readContract({
address: this.address,
abi: [
{
inputs: [],
name: "totalSupply",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
stateMutability: "view",
type: "function"
}
],
functionName: "totalSupply"
});
}
async balanceOf(account) {
return this.publicClient.readContract({
address: this.address,
abi: [
{
inputs: [
{ internalType: "address", name: "account", type: "address" }
],
name: "balanceOf",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
stateMutability: "view",
type: "function"
}
],
functionName: "balanceOf",
args: [account]
});
}
async allowance(owner, spender) {
return this.publicClient.readContract({
address: this.address,
abi: [
{
inputs: [
{ internalType: "address", name: "owner", type: "address" },
{ internalType: "address", name: "spender", type: "address" }
],
name: "allowance",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
stateMutability: "view",
type: "function"
}
],
functionName: "allowance",
args: [owner, spender]
});
}
// PonderToken Specific Read Methods
async launcher() {
return this.publicClient.readContract({
address: this.address,
abi: [
{
inputs: [],
name: "launcher",
outputs: [{ internalType: "address", name: "", type: "address" }],
stateMutability: "view",
type: "function"
}
],
functionName: "launcher"
});
}
async totalBurned() {
return this.publicClient.readContract({
address: this.address,
abi: [
{
inputs: [],
name: "totalBurned",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
stateMutability: "view",
type: "function"
}
],
functionName: "totalBurned"
});
}
async minter() {
return this.publicClient.readContract({
address: this.address,
abi: [
{
inputs: [],
name: "minter",
outputs: [{ internalType: "address", name: "", type: "address" }],
stateMutability: "view",
type: "function"
}
],
functionName: "minter"
});
}
async deploymentTime() {
return this.publicClient.readContract({
address: this.address,
abi: [
{
inputs: [],
name: "deploymentTime",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
stateMutability: "view",
type: "function"
}
],
functionName: "deploymentTime"
});
}
async owner() {
return this.publicClient.readContract({
address: this.address,
abi: [
{
inputs: [],
name: "owner",
outputs: [{ internalType: "address", name: "", type: "address" }],
stateMutability: "view",
type: "function"
}
],
functionName: "owner"
});
}
async pendingOwner() {
return this.publicClient.readContract({
address: this.address,
abi: [
{
inputs: [],
name: "pendingOwner",
outputs: [{ internalType: "address", name: "", type: "address" }],
stateMutability: "view",
type: "function"
}
],
functionName: "pendingOwner"
});
}
async teamTokensClaimed() {
return this.publicClient.readContract({
address: this.address,
abi: [
{
inputs: [],
name: "teamTokensClaimed",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
stateMutability: "view",
type: "function"
}
],
functionName: "teamTokensClaimed"
});
}
// Write Methods
async approve(spender, amount) {
if (!this.walletClient?.account?.address) throw new Error("Wallet client required");
const { request } = await this.publicClient.simulateContract({
address: this.address,
abi: [
{
inputs: [
{ internalType: "address", name: "spender", type: "address" },
{ internalType: "uint256", name: "amount", type: "uint256" }
],
name: "approve",
outputs: [{ internalType: "bool", name: "", type: "bool" }],
stateMutability: "nonpayable",
type: "function"
}
],
functionName: "approve",
args: [spender, amount],
account: this.walletClient.account.address,
chain: this.chain
});
return this.walletClient.writeContract(request);
}
async transfer(to, amount) {
if (!this.walletClient?.account?.address) throw new Error("Wallet client required");
const { request } = await this.publicClient.simulateContract({
address: this.address,
abi: [
{
inputs: [
{ internalType: "address", name: "to", type: "address" },
{ internalType: "uint256", name: "amount", type: "uint256" }
],
name: "transfer",
outputs: [{ internalType: "bool", name: "", type: "bool" }],
stateMutability: "nonpayable",
type: "function"
}
],
functionName: "transfer",
args: [to, amount],
account: this.walletClient.account.address,
chain: this.chain
});
return this.walletClient.writeContract(request);
}
async transferFrom(from, to, amount) {
if (!this.walletClient?.account?.address) throw new Error("Wallet client required");
const { request } = await this.publicClient.simulateContract({
address: this.address,
abi: [
{
inputs: [
{ internalType: "address", name: "from", type: "address" },
{ internalType: "address", name: "to", type: "address" },
{ internalType: "uint256", name: "amount", type: "uint256" }
],
name: "transferFrom",
outputs: [{ internalType: "bool", name: "", type: "bool" }],
stateMutability: "nonpayable",
type: "function"
}
],
functionName: "transferFrom",
args: [from, to, amount],
account: this.walletClient.account.address,
chain: this.chain
});
return this.walletClient.writeContract(request);
}
async burn(amount) {
if (!this.walletClient?.account?.address) throw new Error("Wallet client required");
const { request } = await this.publicClient.simulateContract({
address: this.address,
abi: [
{
inputs: [
{ internalType: "uint256", name: "amount", type: "uint256" }
],
name: "burn",
outputs: [],
stateMutability: "nonpayable",
type: "function"
}
],
functionName: "burn",
args: [amount],
account: this.walletClient.account.address,
chain: this.chain
});
return this.walletClient.writeContract(request);
}
async claimTeamTokens() {
if (!this.walletClient?.account?.address) throw new Error("Wallet client required");
const { request } = await this.publicClient.simulateContract({
address: this.address,
abi: [
{
inputs: [],
name: "claimTeamTokens",
outputs: [],
stateMutability: "nonpayable",
type: "function"
}
],
functionName: "claimTeamTokens",
account: this.walletClient.account.address,
chain: this.chain
});
return this.walletClient.writeContract(request);
}
};
var FiveFiveFiveLauncher = class {
constructor(chainId, publicClient, walletClient) {
// Protocol constants from contract
this.TARGET_RAISE = 5555n * 10n ** 18n;
// 5,555 KUB
this.TOTAL_SUPPLY = 555555555n * 10n ** 18n;
// 555,555,555 tokens
this.LP_ALLOCATION = 10n;
// 10% of launch tokens for LP
this.CREATOR_ALLOCATION = 10n;
// 10% to creator
this.CONTRIBUTOR_ALLOCATION = 80n;
// 80% for sale
this.LP_LOCK_PERIOD = 180n * 24n * 60n * 60n;
// 180 days in seconds
// PONDER distribution ratios
this.PONDER_LP_ALLOCATION = 50n;
// 50% to launch token/PONDER LP
this.PONDER_PROTOCOL_LP = 30n;
// 30% to PONDER/KUB LP
this.PONDER_BURN = 20n;
// 20% burned
this.BASIS_POINTS = 10000n;
this.KUB_TO_MEME_KUB_LP = 6000n;
this.KUB_TO_MEME_PONDER_LP = 2000n;
this.KUB_TO_PONDER_KUB_LP = 2000n;
this.PONDER_TO_BURN = 2000n;
this.PONDER_TO_MEME_PONDER = 8000n;
this.PRICE_STALENESS_THRESHOLD = 7200n;
this.chainId = chainId;
this.chain = getChainFromId(chainId);
this.address = PONDER_ADDRESSES[chainId].launcher;
this.publicClient = publicClient;
this.walletClient = walletClient;
}
// Read Methods
async factory() {
return this.publicClient.readContract({
address: this.address,
abi: dex.fivefivefivelauncherAbi,
functionName: "FACTORY"
});
}
async router() {
return this.publicClient.readContract({
address: this.address,
abi: dex.fivefivefivelauncherAbi,
functionName: "ROUTER"
});
}
async owner() {
return this.publicClient.readContract({
address: this.address,
abi: dex.fivefivefivelauncherAbi,
functionName: "OWNER"
});
}
async feeCollector() {
return this.publicClient.readContract({
address: this.address,
abi: dex.fivefivefivelauncherAbi,
functionName: "FEE_COLLECTOR"
});
}
async launchCount() {
return this.publicClient.readContract({
address: this.address,
abi: dex.fivefivefivelauncherAbi,
functionName: "launchCount"
});
}
async getLaunchInfo(launchId) {
const info = await this.publicClient.readContract({
address: this.address,
abi: dex.fivefivefivelauncherAbi,
functionName: "getLaunchInfo",
args: [launchId]
});
return {
tokenAddress: info[0],
name: info[1],
symbol: info[2],
imageURI: info[3],
totalRaised: info[4],
launched: info[5],
creator: info[6],
lpUnlockTime: info[7],
tokenPrice: info[8],
tokensForSale: info[9],
tokensSold: info[10],
ponderRequired: info[11],
ponderCollected: info[12]
};
}
// Add new method for getting pool info
async getPoolInfo(launchId) {
const [memeKubPair, memePonderPair, hasSecondaryPool] = await this.publicClient.readContract({
address: this.address,
abi: dex.fivefivefivelauncherAbi,
functionName: "getPoolInfo",
args: [launchId]
});
return {
memeKubPair,
memePonderPair,
hasSecondaryPool
};
}
// Add method for getting contribution info
async getContributionInfo(launchId) {
const [kubCollected, ponderCollected, ponderValueCollected, totalValue] = await this.publicClient.readContract({
address: this.address,
abi: dex.fivefivefivelauncherAbi,
functionName: "getContributionInfo",
args: [launchId]
});
return {
kubCollected,
ponderCollected,
ponderValueCollected,
totalValue
};
}
async getRemainingToRaise(launchId) {
return await this.publicClient.readContract({
address: this.address,
abi: dex.fivefivefivelauncherAbi,
functionName: "getRemainingToRaise",
args: [launchId]
});
}
async calculatePonderRequirements() {
const [factoryAddress, routerAddress] = await Promise.all([
this.factory(),
this.router()
]);
try {
const KKUB = await this.publicClient.readContract({
address: routerAddress,
abi: dex.ponderrouterAbi,
functionName: "KKUB"
});
const ponderPair = await this.publicClient.readContract({
address: factoryAddress,
abi: dex.ponderfactoryAbi,
functionName: "getPair",
args: [PONDER_ADDRESSES[this.chainId].ponderToken, KKUB]
});
const requiredAmount = await this.publicClient.readContract({
address: PONDER_ADDRESSES[this.chainId].oracle,
abi: dex.ponderpriceoracleAbi,
functionName: "consult",
args: [ponderPair, KKUB, this.TARGET_RAISE, Number(15 * 60)]
});
return {
lpAllocation: requiredAmount * this.PONDER_LP_ALLOCATION / 100n,
protocolLPAllocation: requiredAmount * this.PONDER_PROTOCOL_LP / 100n,
burnAmount: requiredAmount * this.PONDER_BURN / 100n,
requiredAmount
};
} catch (error) {
console.error("Failed to get PONDER requirement:", error);
const defaultRequired = this.TARGET_RAISE;
return {
lpAllocation: defaultRequired * this.PONDER_LP_ALLOCATION / 100n,
protocolLPAllocation: defaultRequired * this.PONDER_PROTOCOL_LP / 100n,
burnAmount: defaultRequired * this.PONDER_BURN / 100n,
requiredAmount: defaultRequired
};
}
}
// Write Methods
async createLaunch(params) {
if (!this.walletClient?.account?.address)
throw new Error("Wallet client required");
const { request } = await this.publicClient.simulateContract({
address: this.address,
abi: dex.fivefivefivelauncherAbi,
functionName: "createLaunch",
args: [
{ name: params.name, symbol: params.symbol, imageURI: params.imageURI }
],
account: this.walletClient.account.address,
chain: this.chain
});
return this.walletClient.writeContract(request);
}
// Update method name to match contract
async contributeKUB(launchId, amount) {
if (!this.walletClient?.account?.address)
throw new Error("Wallet client required");
const { request } = await this.publicClient.simulateContract({
address: this.address,
abi: dex.fivefivefivelauncherAbi,
functionName: "contributeKUB",
args: [launchId],
account: this.walletClient.account.address,
chain: this.chain,
value: amount
// Now amount is defined
});
return this.walletClient.writeContract(request);
}
// Add new method for PONDER contribution
async contributePONDER(launchId, amount) {
if (!this.walletClient?.account?.address)
throw new Error("Wallet client required");
const { request } = await this.publicClient.simulateContract({
address: this.address,
abi: dex.fivefivefivelauncherAbi,
functionName: "contributePONDER",
args: [launchId, amount],
account: this.walletClient.account.address,
chain: this.chain
});
return this.walletClient.writeContract(request);
}
async withdrawLP(launchId) {
if (!this.walletClient?.account?.address)
throw new Error("Wallet client required");
const { request } = await this.publicClient.simulateContract({
address: this.address,
abi: dex.fivefivefivelauncherAbi,
functionName: "withdrawLP",
args: [launchId],
account: this.walletClient.account.address,
chain: this.chain
});
return this.walletClient.writeContract(request);
}
};
var PriceOracle = class {
// 24 hours in seconds
constructor(chainId, publicClient, walletClient) {
this.PERIOD = 86400n;
this.chainId = chainId;
this.chain = getChainFromId(chainId);
this.address = PONDER_ADDRESSES[chainId].oracle;
this.publicClient = publicClient;
this.walletClient = walletClient;
}
// Read Methods
async factory() {
return this.publicClient.readContract({
address: this.address,
abi: dex.ponderpriceoracleAbi,
functionName: "factory"
});
}
async observationLength(pair) {
return this.publicClient.readContract({
address: this.address,
abi: dex.ponderpriceoracleAbi,
functionName: "observationLength",
args: [pair]
});
}
async observations(pair, index) {
const [timestamp, price0Cumulative, price1Cumulative] = await this.publicClient.readContract({
address: this.address,
abi: dex.ponderpriceoracleAbi,
functionName: "observations",
args: [pair, index]
});
return {
timestamp,
price0Cumulative,
price1Cumulative
};
}
async consult(pair, tokenIn, amountIn, periodInSeconds) {
return this.publicClient.readContract({
address: this.address,
abi: dex.ponderpriceoracleAbi,
functionName: "consult",
args: [pair, tokenIn, amountIn, periodInSeconds]
});
}
// Write Methods
async update(pair) {
if (!this.walletClient) throw new Error("Wallet client required");
return this.walletClient.writeContra