UNPKG

four-flap-meme-sdk

Version:

SDK for Flap bonding curve and four.meme TokenManager

42 lines (41 loc) 1.97 kB
import { Contract, JsonRpcProvider } from 'ethers'; import TM1Abi from '../abis/TokenManager.json' with { type: 'json' }; import { ADDRESSES } from '../utils/constants.js'; export class TM1 { constructor(address, provider) { this.address = address; this.provider = provider; } /** * 通过链名称连接 */ static connectByChain(chain, rpcUrl) { const address = ADDRESSES[chain].TokenManagerV1; return new TM1(address, new JsonRpcProvider(rpcUrl)); } get c() { return new Contract(this.address, TM1Abi, this.provider); } async lastPrice(token) { return await this.c.lastPrice(token); } async purchaseToken(token, amount, maxFunds, origin, to) { if (origin !== undefined && to) return await this.c.purchaseToken(origin, token, to, amount, maxFunds, { value: maxFunds }); return await this.c.purchaseToken(token, amount, maxFunds, { value: maxFunds }); } async purchaseTokenAMAP(token, funds, minAmount, origin, to) { if (origin !== undefined && to) return await this.c.purchaseTokenAMAP(origin, token, to, funds, minAmount, { value: funds }); return await this.c.purchaseTokenAMAP(token, funds, minAmount, { value: funds }); } async saleToken(token, amount, origin, from, minFunds, feeRate, feeRecipient) { if (origin !== undefined && from && minFunds !== undefined && feeRate !== undefined && feeRecipient) { return await this.c.saleToken(origin, token, from, amount, minFunds, feeRate, feeRecipient); } // 注意:如果要使用 minFunds,必须同时提供 feeRate 和 feeRecipient(使用6参数版本) // 合约中不存在4参数的 saleToken(origin, token, amount, minFunds) 方法 if (origin !== undefined) { return await this.c.saleToken(origin, token, amount); } return await this.c.saleToken(token, amount); } }