Skip to content

Commit

Permalink
all pairs fetched from multicontract handling
Browse files Browse the repository at this point in the history
  • Loading branch information
vnaysngh-mudrex committed Feb 14, 2024
1 parent 3a4c3cc commit 296359a
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 201 deletions.
317 changes: 118 additions & 199 deletions src/contracts/factoryAddress/abi.json
Original file line number Diff line number Diff line change
@@ -1,248 +1,167 @@
[
{
"name": "JediSwapV2FactoryImpl",
"type": "impl",
"interface_name": "jediswap_v2_core::jediswap_v2_factory::IJediSwapV2Factory"
},
{
"name": "jediswap_v2_core::jediswap_v2_factory::IJediSwapV2Factory",
"type": "interface",
"items": [
{
"name": "fee_amount_tick_spacing",
"type": "function",
"inputs": [
{
"name": "fee",
"type": "core::integer::u32"
}
],
"outputs": [
{
"type": "core::integer::u32"
}
],
"state_mutability": "view"
"data": [
{
"name": "token0",
"type": "felt"
},
{
"name": "get_pool",
"type": "function",
"inputs": [
{
"name": "token_a",
"type": "core::starknet::contract_address::ContractAddress"
},
{
"name": "token_b",
"type": "core::starknet::contract_address::ContractAddress"
},
{
"name": "fee",
"type": "core::integer::u32"
}
],
"outputs": [
{
"type": "core::starknet::contract_address::ContractAddress"
}
],
"state_mutability": "view"
"name": "token1",
"type": "felt"
},
{
"name": "create_pool",
"type": "function",
"inputs": [
{
"name": "token_a",
"type": "core::starknet::contract_address::ContractAddress"
},
{
"name": "token_b",
"type": "core::starknet::contract_address::ContractAddress"
},
{
"name": "fee",
"type": "core::integer::u32"
}
],
"outputs": [
{
"type": "core::starknet::contract_address::ContractAddress"
}
],
"state_mutability": "external"
"name": "pair",
"type": "felt"
},
{
"name": "enable_fee_amount",
"type": "function",
"inputs": [
{
"name": "fee",
"type": "core::integer::u32"
},
{
"name": "tick_spacing",
"type": "core::integer::u32"
}
],
"outputs": [],
"state_mutability": "external"
"name": "total_pairs",
"type": "felt"
}
]
],
"keys": [],
"name": "pair_created",
"type": "event"
},
{
"name": "OwnableImpl",
"type": "impl",
"interface_name": "openzeppelin::access::ownable::interface::IOwnable"
},
{
"name": "openzeppelin::access::ownable::interface::IOwnable",
"type": "interface",
"items": [
{
"name": "owner",
"type": "function",
"inputs": [],
"outputs": [
{
"type": "core::starknet::contract_address::ContractAddress"
}
],
"state_mutability": "view"
},
"inputs": [
{
"name": "transfer_ownership",
"type": "function",
"inputs": [
{
"name": "new_owner",
"type": "core::starknet::contract_address::ContractAddress"
}
],
"outputs": [],
"state_mutability": "external"
"name": "pair_contract_class_hash",
"type": "felt"
},
{
"name": "renounce_ownership",
"type": "function",
"inputs": [],
"outputs": [],
"state_mutability": "external"
"name": "fee_to_setter",
"type": "felt"
}
]
],
"name": "constructor",
"outputs": [],
"type": "constructor"
},
{
"name": "constructor",
"type": "constructor",
"inputs": [
{
"name": "owner",
"type": "core::starknet::contract_address::ContractAddress"
"name": "token0",
"type": "felt"
},
{
"name": "pool_class_hash",
"type": "core::starknet::class_hash::ClassHash"
"name": "token1",
"type": "felt"
}
],
"name": "get_pair",
"outputs": [
{
"name": "pair",
"type": "felt"
}
]
],
"stateMutability": "view",
"type": "function"
},
{
"kind": "struct",
"name": "jediswap_v2_core::jediswap_v2_factory::JediSwapV2Factory::PoolCreated",
"type": "event",
"members": [
"inputs": [],
"name": "get_all_pairs",
"outputs": [
{
"kind": "data",
"name": "token0",
"type": "core::starknet::contract_address::ContractAddress"
"name": "all_pairs_len",
"type": "felt"
},
{
"kind": "data",
"name": "token1",
"type": "core::starknet::contract_address::ContractAddress"
},
"name": "all_pairs",
"type": "felt*"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "get_num_of_pairs",
"outputs": [
{
"kind": "data",
"name": "fee",
"type": "core::integer::u32"
},
"name": "num_of_pairs",
"type": "felt"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "get_fee_to",
"outputs": [
{
"kind": "data",
"name": "tick_spacing",
"type": "core::integer::u32"
},
"name": "address",
"type": "felt"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "get_fee_to_setter",
"outputs": [
{
"kind": "data",
"name": "pool",
"type": "core::starknet::contract_address::ContractAddress"
"name": "address",
"type": "felt"
}
]
],
"stateMutability": "view",
"type": "function"
},
{
"kind": "struct",
"name": "jediswap_v2_core::jediswap_v2_factory::JediSwapV2Factory::FeeAmountEnabled",
"type": "event",
"members": [
{
"kind": "data",
"name": "fee",
"type": "core::integer::u32"
},
"inputs": [],
"name": "get_pair_contract_class_hash",
"outputs": [
{
"kind": "data",
"name": "tick_spacing",
"type": "core::integer::u32"
"name": "class_hash",
"type": "felt"
}
]
],
"stateMutability": "view",
"type": "function"
},
{
"kind": "struct",
"name": "openzeppelin::access::ownable::ownable::OwnableComponent::OwnershipTransferred",
"type": "event",
"members": [
{
"kind": "data",
"name": "previous_owner",
"type": "core::starknet::contract_address::ContractAddress"
"inputs": [
{
"name": "tokenA",
"type": "felt"
},
{
"kind": "data",
"name": "new_owner",
"type": "core::starknet::contract_address::ContractAddress"
"name": "tokenB",
"type": "felt"
}
]
],
"name": "create_pair",
"outputs": [
{
"name": "pair",
"type": "felt"
}
],
"type": "function"
},
{
"kind": "enum",
"name": "openzeppelin::access::ownable::ownable::OwnableComponent::Event",
"type": "event",
"variants": [
{
"kind": "nested",
"name": "OwnershipTransferred",
"type": "openzeppelin::access::ownable::ownable::OwnableComponent::OwnershipTransferred"
"inputs": [
{
"name": "new_fee_to",
"type": "felt"
}
]
],
"name": "set_fee_to",
"outputs": [],
"type": "function"
},
{
"kind": "enum",
"name": "jediswap_v2_core::jediswap_v2_factory::JediSwapV2Factory::Event",
"type": "event",
"variants": [
{
"kind": "nested",
"name": "PoolCreated",
"type": "jediswap_v2_core::jediswap_v2_factory::JediSwapV2Factory::PoolCreated"
},
{
"kind": "nested",
"name": "FeeAmountEnabled",
"type": "jediswap_v2_core::jediswap_v2_factory::JediSwapV2Factory::FeeAmountEnabled"
},
"inputs": [
{
"kind": "flat",
"name": "OwnableEvent",
"type": "openzeppelin::access::ownable::ownable::OwnableComponent::Event"
"name": "new_fee_to_setter",
"type": "felt"
}
]
],
"name": "set_fee_to_setter",
"outputs": [],
"type": "function"
}
]
6 changes: 4 additions & 2 deletions src/hooks/useV2Pairs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export function useV2Pairs(
[currencies]
)

const allPairs = useAllPairs()

const pairAddresses = useMemo(
() =>
tokens.map(([tokenA, tokenB]) => {
Expand All @@ -38,8 +40,8 @@ export function useV2Pairs(
)

const validatedPairAddress = useMemo(
() => pairAddresses.map((addr) => (addr && pairs.includes(addr) ? addr : undefined)),
[pairs, pairAddresses]
() => pairAddresses.map((addr) => (addr && allPairs.includes(addr) ? addr : undefined)),
[allPairs, pairAddresses]
)

const results = useMultipleContractSingleData(validatedPairAddress, JediswapPairABI, 'get_reserves')
Expand Down

0 comments on commit 296359a

Please sign in to comment.