quoter update + desktop update

This commit is contained in:
EmberSpirit
2023-09-27 20:20:06 +02:00
parent 5c7053c0d9
commit 3d53d9e7c8
17 changed files with 1616 additions and 111 deletions
+86
View File
@@ -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;
},
},
});