Merge branch 'fix/simplifyUniswap' into development

This commit is contained in:
EmberSpirit
2023-10-23 21:40:07 +02:00
3 changed files with 29 additions and 68 deletions
+5
View File
@@ -0,0 +1,5 @@
{
"contractName": "WETH",
"contractAddress": "0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6",
"contractAddressMainnet": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
}
+9 -9
View File
@@ -149,15 +149,15 @@ export const useSacrificeStore = defineStore("sacrifice", {
* case 2 * case 2
* user is logged in and allowance is greater or equal input and variant is sacrifice * user is logged in and allowance is greater or equal input and variant is sacrifice
*/ */
// in this case you should use eth_call, so you are showing exact reward in cases of completing cycles // in this case you should use eth_call, so you are showing exact reward in cases of completing cycles
const amountSacrifice = await readContract({ const amountSacrifice = await readContract({
address: memeburnerStore.contract.address, address: memeburnerStore.contract.address,
abi: memeburnerStore.contract.abi, abi: memeburnerStore.contract.abi,
functionName: "sacrificeMeme", functionName: "sacrificeMeme",
args: [token.contractAddress, amount.toString(), minETH.toString()], args: [token.contractAddress, amount.toString(), minETH.toString()],
account: walletStore.address, account: walletStore.address,
}); });
output = amountSacrifice; output = amountSacrifice;
} else if (walletStore.connected && variant === "buy" && token.allowance >= amount) { } else if (walletStore.connected && variant === "buy" && token.allowance >= amount) {
/** /**
* case 3 * case 3
+15 -59
View File
@@ -1,23 +1,17 @@
import { defineStore } from "pinia"; import { defineStore } from "pinia";
import { useWalletStoreV2 } from "@/stores/walletV2"; import { useWalletStoreV2 } from "@/stores/walletV2";
import QuoterJson from "@/assets/contracts/Quoter.json"; import QuoterJson from "@/assets/contracts/Quoter.json";
import UniswapPoolJson from "@/assets/contracts/UniswapPool.json"; import WethJson from "@/assets/contracts/WETH.json";
import BloodlineJson from "@/assets/contracts/Bloodline.json"; import BloodlineJson from "@/assets/contracts/Bloodline.json";
import { useMemeburnerStore } from "@/stores/memeburner";
import { useTokenStore } from "@/stores/tokens";
import { getContract, multicall } from "@wagmi/core"; import { getContract, multicall } from "@wagmi/core";
export const useUniswapStore = defineStore("uniswap", { export const useUniswapStore = defineStore("uniswap", {
state: () => ({ state: () => ({
quoateV3Contract: {}, quoateV3Contract: {},
quoateV2Contract: {}, tokenIn: WethJson.contractAddress,
uniswapPoolContract: {}, tokenOut: BloodlineJson.contractAddress,
poolData: { fee: 10000n,
token0: null,
token1: null,
fee: null,
},
}), }),
getters: {}, getters: {},
actions: { actions: {
@@ -31,38 +25,25 @@ export const useUniswapStore = defineStore("uniswap", {
walletClient: walletStore.walletClient || walletStore.publicClient, walletClient: walletStore.walletClient || walletStore.publicClient,
}); });
this.uniswapPoolContract = getContract({
address: UniswapPoolJson.contractAddress,
abi: UniswapPoolJson.abi,
walletClient: walletStore.walletClient || walletStore.publicClient,
});
this.getPoolData();
}, },
async quoteExactInputSingle(amount, ethBase) { async quoteExactInputSingle(ethBase) {
try { try {
console.log("quoteExactInputSingle"); console.log("quoteExactInputSingle");
const memeBurnerStore = useMemeburnerStore();
const tokenStore = useTokenStore();
const tokenOut = tokenStore.memeToken.contractAddress;
// tokenIn - WETH
const tokenIn = BigInt(this.poolData.token0) == BigInt(tokenOut) ? this.poolData.token1 : this.poolData.token0;
console.log("quoteExactInputSingle-parameter", { console.log("quoteExactInputSingle-parameter", {
tokenIn: tokenIn, // WETH tokenIn: this.tokenIn, // WETH
tokenOut: tokenOut, // BLOOD tokenOut: this.tokenOut, // BLOOD
fee: this.poolData.fee, fee: this.fee,
amountEthBase: ethBase, amountEthBase: ethBase,
pricelimit: 0, //sqrtPriceLimitX96 pricelimit: 0n, //sqrtPriceLimitX96
}); });
const quotedAmountOut = await this.quoateV3Contract.read.quoteExactInputSingle([ const quotedAmountOut = await this.quoateV3Contract.read.quoteExactInputSingle([
tokenIn, //weth this.tokenIn, //weth
tokenOut, //bloodline this.tokenOut, //bloodline
this.poolData.fee, this.fee,
ethBase, ethBase,
0, //sqrtPriceLimitX96 0n, //sqrtPriceLimitX96
]); ]);
console.log("quotedAmountOut", quotedAmountOut); console.log("quotedAmountOut", quotedAmountOut);
return {result: true, amount: quotedAmountOut}; return {result: true, amount: quotedAmountOut};
@@ -70,31 +51,6 @@ export const useUniswapStore = defineStore("uniswap", {
return { result: false, amount: null }; return { result: false, amount: null };
} }
}, }
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;
console.log("this.poolData", this.poolData);
},
},
}); });