quoter update + desktop update
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { useWalletStoreV2 } from "@/stores/walletV2";
|
||||
import QuoterJson from "@/assets/contracts/Quoter.json";
|
||||
import UniswapPoolJson from "@/assets/contracts/UniswapPool.json";
|
||||
import { useMemeburnerStore } from "@/stores/memeburner";
|
||||
|
||||
import { getContract, multicall } from "@wagmi/core";
|
||||
|
||||
export const useUniswapStore = defineStore("uniswap", {
|
||||
state: () => ({
|
||||
quoateV3Contract: {},
|
||||
quoateV2Contract: {},
|
||||
uniswapPoolContract: {},
|
||||
poolData: {
|
||||
token0: null,
|
||||
token1: null,
|
||||
fee: null,
|
||||
},
|
||||
}),
|
||||
getters: {},
|
||||
actions: {
|
||||
init() {
|
||||
console.log("init uniswap");
|
||||
const walletStore = useWalletStoreV2();
|
||||
|
||||
this.quoateV3Contract = getContract({
|
||||
address: QuoterJson.contractAddress,
|
||||
abi: QuoterJson.abi,
|
||||
walletClient: walletStore.walletClient || walletStore.publicClient,
|
||||
});
|
||||
|
||||
this.uniswapPoolContract = getContract({
|
||||
address: UniswapPoolJson.contractAddress,
|
||||
abi: UniswapPoolJson.abi,
|
||||
walletClient: walletStore.walletClient || walletStore.publicClient,
|
||||
});
|
||||
|
||||
this.getPoolData();
|
||||
},
|
||||
|
||||
async quoteExactInputSingle(amount) {
|
||||
console.log("quoteExactInputSingle");
|
||||
const memeBurnerStore = useMemeburnerStore();
|
||||
var amountEthBase = await memeBurnerStore.getAmountETHBase(amount);
|
||||
console.log("123", {
|
||||
token1: this.poolData.token1,
|
||||
token0: this.poolData.token0,
|
||||
fee: this.poolData.fee,
|
||||
amountEthBase,
|
||||
pricelimit: 0, //sqrtPriceLimitX96
|
||||
});
|
||||
const quotedAmountOut = await this.quoateV3Contract.read.quoteExactInputSingle([
|
||||
this.poolData.token1,
|
||||
this.poolData.token0,
|
||||
this.poolData.fee,
|
||||
amountEthBase,
|
||||
0, //sqrtPriceLimitX96
|
||||
]);
|
||||
return quotedAmountOut;
|
||||
},
|
||||
async getPoolData() {
|
||||
console.log("getPoolData");
|
||||
const contracts = [];
|
||||
contracts.push(
|
||||
{
|
||||
...this.uniswapPoolContract,
|
||||
functionName: "token0",
|
||||
},
|
||||
{
|
||||
...this.uniswapPoolContract,
|
||||
functionName: "token1",
|
||||
},
|
||||
{
|
||||
...this.uniswapPoolContract,
|
||||
functionName: "fee",
|
||||
}
|
||||
);
|
||||
const data = await multicall({
|
||||
contracts,
|
||||
});
|
||||
this.poolData.token0 = data[0].result;
|
||||
this.poolData.token1 = data[1].result;
|
||||
this.poolData.fee = data[2].result;
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user