Skip to content

Commit

Permalink
feat: add price
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixGibson committed Oct 10, 2023
1 parent c30f410 commit 5ea051d
Show file tree
Hide file tree
Showing 4 changed files with 386 additions and 69 deletions.
20 changes: 16 additions & 4 deletions examples/interface/src/components/ButtonClick.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const ButtonClick = () => {
const ekubo_core_address = useMemo(() => "0x031e8a7ab6a6a556548ac85cbb8b5f56e8905696e9f13e9a858142b8ee0cc221", [])
const avnu_address = useMemo(() => "0x07e36202ace0ab52bf438bd8a8b64b3731c48d09f0d8879f5b006384c2f35032", [])
const simple_swapper = useMemo(() => "0x064f7ed2dc5070133ae8ccdf85f01e82507facbe5cdde456e1418e3901dc51a0", [])
const quoter = useMemo(() => "0x042aa743335663ed9c7b52b331ab7f81cc8d65280d311506653f9b5cc22be7cb", [])
const provider = new Provider({ sequencer: { network: constants.NetworkName.SN_GOERLI } });

let wrap = new Wrap(
Expand All @@ -33,6 +34,7 @@ const ButtonClick = () => {
eth_address,
ekubo_position_address,
ekubo_core_address,
quoter,
provider
)
const getERC1155Balance = useCallback(async () => {
Expand All @@ -43,9 +45,11 @@ const ButtonClick = () => {

const getCurrentPrice = useCallback(async () => {
if (!address) return;
// let p = await Wrap.getCurrentPrice();
// setCurrentPrice(p);
}, [address, erc1155_address]);
if (!account) return;
let p = await Wrap.quoteSingle(FeeAmount.LOWEST, eth_address, BigInt(10** 7), account);
let realPrice = p / (10 ** 7);
setCurrentPrice(realPrice);
}, [address, erc1155_address, account]);

useEffect(() => {
getERC1155Balance();
Expand All @@ -55,6 +59,14 @@ const ButtonClick = () => {
return () => clearInterval(interval);
}, [getERC1155Balance]);

useEffect(() => {
getCurrentPrice();
const interval = setInterval(() => {
getCurrentPrice();
}, 3000);
return () => clearInterval(interval);
}, [getCurrentPrice]);

const handleAddLiquidity = useCallback(() => {
if (!account) return;
const realERC1155Amount = erc1155Amount;
Expand Down Expand Up @@ -114,7 +126,7 @@ const ButtonClick = () => {
<p>ERC1155 Balance: {balance}</p>
</div>
<div>
<p>Current Price : {currentPrice}</p>
<p>Current Price : 1 ETH = {currentPrice} WERC20 </p>
</div>
<div>
<h3> Mint ERC1155 </h3>
Expand Down
274 changes: 274 additions & 0 deletions sdk/packages/instaswap-core/src/abi/quoter-abi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,274 @@
[
{
"type": "impl",
"name": "QuoterLockerImpl",
"interface_name": "ekubo::interfaces::core::ILocker"
},
{
"type": "interface",
"name": "ekubo::interfaces::core::ILocker",
"items": [
{
"type": "function",
"name": "locked",
"inputs": [
{
"name": "id",
"type": "core::integer::u32"
},
{
"name": "data",
"type": "core::array::Array::<core::felt252>"
}
],
"outputs": [
{
"type": "core::array::Array::<core::felt252>"
}
],
"state_mutability": "external"
}
]
},
{
"type": "impl",
"name": "QuoterImpl",
"interface_name": "ekubo::quoter::IQuoter"
},
{
"type": "enum",
"name": "core::bool",
"variants": [
{
"name": "False",
"type": "()"
},
{
"name": "True",
"type": "()"
}
]
},
{
"type": "struct",
"name": "ekubo::types::i129::i129",
"members": [
{
"name": "mag",
"type": "core::integer::u128"
},
{
"name": "sign",
"type": "core::bool"
}
]
},
{
"type": "struct",
"name": "ekubo::types::keys::PoolKey",
"members": [
{
"name": "token0",
"type": "core::starknet::contract_address::ContractAddress"
},
{
"name": "token1",
"type": "core::starknet::contract_address::ContractAddress"
},
{
"name": "fee",
"type": "core::integer::u128"
},
{
"name": "tick_spacing",
"type": "core::integer::u128"
},
{
"name": "extension",
"type": "core::starknet::contract_address::ContractAddress"
}
]
},
{
"type": "struct",
"name": "core::array::Span::<ekubo::types::keys::PoolKey>",
"members": [
{
"name": "snapshot",
"type": "@core::array::Array::<ekubo::types::keys::PoolKey>"
}
]
},
{
"type": "struct",
"name": "ekubo::quoter::Route",
"members": [
{
"name": "pool_keys",
"type": "core::array::Span::<ekubo::types::keys::PoolKey>"
}
]
},
{
"type": "struct",
"name": "ekubo::quoter::QuoteParameters",
"members": [
{
"name": "amount",
"type": "ekubo::types::i129::i129"
},
{
"name": "specified_token",
"type": "core::starknet::contract_address::ContractAddress"
},
{
"name": "route",
"type": "ekubo::quoter::Route"
}
]
},
{
"type": "struct",
"name": "ekubo::quoter::QuoteResult",
"members": [
{
"name": "amount",
"type": "ekubo::types::i129::i129"
},
{
"name": "other_token",
"type": "core::starknet::contract_address::ContractAddress"
}
]
},
{
"type": "struct",
"name": "ekubo::quoter::QuoteSingleParameters",
"members": [
{
"name": "amount",
"type": "ekubo::types::i129::i129"
},
{
"name": "specified_token",
"type": "core::starknet::contract_address::ContractAddress"
},
{
"name": "pool_key",
"type": "ekubo::types::keys::PoolKey"
}
]
},
{
"type": "struct",
"name": "core::integer::u256",
"members": [
{
"name": "low",
"type": "core::integer::u128"
},
{
"name": "high",
"type": "core::integer::u128"
}
]
},
{
"type": "struct",
"name": "ekubo::types::delta::Delta",
"members": [
{
"name": "amount0",
"type": "ekubo::types::i129::i129"
},
{
"name": "amount1",
"type": "ekubo::types::i129::i129"
}
]
},
{
"type": "interface",
"name": "ekubo::quoter::IQuoter",
"items": [
{
"type": "function",
"name": "quote",
"inputs": [
{
"name": "params",
"type": "ekubo::quoter::QuoteParameters"
}
],
"outputs": [
{
"type": "ekubo::quoter::QuoteResult"
}
],
"state_mutability": "view"
},
{
"type": "function",
"name": "quote_single",
"inputs": [
{
"name": "params",
"type": "ekubo::quoter::QuoteSingleParameters"
}
],
"outputs": [
{
"type": "ekubo::quoter::QuoteResult"
}
],
"state_mutability": "view"
},
{
"type": "function",
"name": "delta_to_sqrt_ratio",
"inputs": [
{
"name": "pool_key",
"type": "ekubo::types::keys::PoolKey"
},
{
"name": "sqrt_ratio",
"type": "core::integer::u256"
}
],
"outputs": [
{
"type": "ekubo::types::delta::Delta"
}
],
"state_mutability": "view"
}
]
},
{
"type": "struct",
"name": "ekubo::interfaces::core::ICoreDispatcher",
"members": [
{
"name": "contract_address",
"type": "core::starknet::contract_address::ContractAddress"
}
]
},
{
"type": "constructor",
"name": "constructor",
"inputs": [
{
"name": "core",
"type": "ekubo::interfaces::core::ICoreDispatcher"
}
]
},
{
"type": "event",
"name": "ekubo::quoter::Quoter::Event",
"kind": "enum",
"variants": []
}
]
Loading

0 comments on commit 5ea051d

Please sign in to comment.