Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Harshal/referral #202

Open
wants to merge 64 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
a64b5dc
add referral page
harshal2608 Apr 7, 2024
f917f64
add referralCode in swap
harshal2608 Apr 8, 2024
08951b2
add set_trader_referral_code to pool
harshal2608 Apr 9, 2024
c90bf6b
fix referral UI
harshal2608 Apr 16, 2024
3dd5b29
fix referral page UI
harshal2608 Apr 16, 2024
8eedd12
feat: trader cant update referral code
harshal2608 Apr 17, 2024
6236c15
Merge branch 'vinaysingh/v2-goerli-to-sepolia-migration' into harshal…
harshal2608 Apr 20, 2024
1425e81
fix loading issues
harshal2608 Apr 20, 2024
46658cb
fix deployment break
harshal2608 Apr 20, 2024
71efcd4
add console
harshal2608 Apr 20, 2024
e15e862
fix loading if user comes from swap
harshal2608 Apr 20, 2024
e8c88e1
add referral page
harshal2608 Apr 7, 2024
a860ceb
add referralCode in swap
harshal2608 Apr 8, 2024
d9a04d4
add set_trader_referral_code to pool
harshal2608 Apr 9, 2024
38b91fa
fix referral page UI
harshal2608 Apr 16, 2024
e0b122e
feat: trader cant update referral code
harshal2608 Apr 17, 2024
60e1153
fix loading issues
harshal2608 Apr 20, 2024
58caf95
add console
harshal2608 Apr 20, 2024
796db93
fix loading if user comes from swap
harshal2608 Apr 20, 2024
2cf775c
rebase
harshal2608 Apr 20, 2024
bb90788
Merge branch 'harshal/referral' of github.com-personal:jediswaplabs/j…
harshal2608 Apr 20, 2024
133a0c2
default env testnet
harshal2608 Apr 20, 2024
ace3bae
add refetch interval in user code
harshal2608 Apr 20, 2024
f677aba
fix delay in block data
harshal2608 Apr 21, 2024
18e40f7
block pending for get_code_owner
harshal2608 Apr 21, 2024
f5e03ac
fix referral page
harshal2608 May 5, 2024
59db53b
update contracts
harshal2608 May 6, 2024
a342de9
save to local on any page
harshal2608 May 8, 2024
0f9bb91
Merge branch 'main' into harshal/referral
harshal2608 May 8, 2024
ec8c1b7
remove duplicate imports
harshal2608 May 8, 2024
ec0af87
update referral UI
harshal2608 May 13, 2024
10eb43d
add testnet warning on referral page
harshal2608 May 20, 2024
c897f95
add validation for self referral
harshal2608 May 20, 2024
12e6ddf
add banners for referral codes for user
harshal2608 Jun 4, 2024
897d91e
update referral contract
harshal2608 Jun 5, 2024
becf7f4
Merge branch 'main' into harshal/referral
harshal2608 Jun 5, 2024
b5c9a6d
add rewards route
harshal2608 Jun 5, 2024
0244644
fix type errors
harshal2608 Jun 5, 2024
6f6711f
fix banner
harshal2608 Jun 5, 2024
e4e75c4
fix set_referrer
harshal2608 Jun 5, 2024
564cd4f
Merge branch 'main' into harshal/referral
harshal2608 Jun 11, 2024
af725fc
update contract
harshal2608 Jun 11, 2024
4e26db8
fix checksum address problem
harshal2608 Jun 12, 2024
6f54a4c
remove banner on different page
harshal2608 Jun 12, 2024
c1c851c
fix: self referral
harshal2608 Jun 12, 2024
b2f7bcd
Merge branch 'main' into harshal/referral
harshal2608 Jun 30, 2024
90c7d8b
referral code revamp
harshal2608 Jul 1, 2024
0efbd67
fix page break
harshal2608 Jul 1, 2024
55651cf
console local storage data
harshal2608 Jul 1, 2024
53c4926
fix localstorage access
harshal2608 Jul 1, 2024
12a11f2
fix localstorage updation
harshal2608 Jul 1, 2024
6528a67
fix swap function
harshal2608 Jul 1, 2024
174066d
save notif closed state
harshal2608 Jul 15, 2024
3c3761e
refactor and better comments
harshal2608 Jul 15, 2024
c64d123
fix page break
harshal2608 Jul 15, 2024
3a2ef5e
save the code if wallet not connected
harshal2608 Jul 15, 2024
b2a97ea
add mainnet contract address
harshal2608 Jul 21, 2024
5935b2e
add lowercase support for referral code
harshal2608 Jul 22, 2024
a9aca33
fix lowercase support
harshal2608 Jul 23, 2024
12f80ed
add set_referral in vaults
harshal2608 Jul 23, 2024
685bd5c
fix the nowalletstate
harshal2608 Jul 29, 2024
d76b444
add chainId in url
harshal2608 Jul 30, 2024
0d8ce8a
fix usereferral
harshal2608 Jul 30, 2024
ccd1815
fix nowallet state
harshal2608 Jul 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/api/fetchReferrer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { ChainId } from '@vnaysn/jediswap-sdk-core'
import { REFERRAL_ADDRESS } from 'contracts/referralAddress'
import { providerInstance } from 'utils/getLibrary'

const options = {
method: 'POST',
headers: { accept: 'application/json' },
}

const fetchReferrer = async (chainId: ChainId, userAddress: string) => {
try {
const api = providerInstance(chainId)
const response = await fetch(api.nodeUrl, {
...options,
body: JSON.stringify({
id: 0,
jsonrpc: '2.0',
method: 'starknet_call',
params: {
request: {
contract_address: REFERRAL_ADDRESS[chainId],
entry_point_selector: '0x1c65c19ac21767e7d0fb5d7500ead907f9a06f684490b0ec509db48cbc4aadd',
calldata: [userAddress],
},
block_id: 'pending',
},
}),
})

if (!response.ok) {
throw new Error('Failed to fetch data')
}
const data = await response.json()
return data
} catch (error) {
throw new Error('An error occurred while fetching data')
}
}

export default fetchReferrer
4 changes: 3 additions & 1 deletion src/components/NavBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import MobileLogo from 'assets/jedi/squareLogo.png'
import { useAccountDrawer } from 'components/AccountDrawer'
import Web3Status from 'components/Web3Status'
import { useIsPoolsPage } from 'hooks/useIsPoolsPage'
import { NetworkName } from './NetworkName'
import {
ActiveMenuItem,
ExternalMenuItem,
Expand Down Expand Up @@ -61,6 +60,9 @@ export const PageTabs = () => {
<ExternalMenuItemLink to="https://app.v1.jediswap.xyz/">
<Trans>V1</Trans>
</ExternalMenuItemLink>
<MenuItemLink to="/referral" isActive={pathname.startsWith('/referral')}>
<Trans>Referral</Trans>
</MenuItemLink>
<MenuItemLink to="/rewards" isActive={pathname.startsWith('/rewards')}>
<img src={StarkIcon} style={{ marginRight: '2px' }} alt="starknet_logo" />
<Trans>Rewards</Trans>
Expand Down
218 changes: 218 additions & 0 deletions src/contracts/referralAddress/abi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
[
{
"name": "ReferralStorage",
"type": "impl",
"interface_name": "jediswap_referral::referral_storage::IReferralStorage"
},
{
"name": "jediswap_referral::referral_storage::IReferralStorage",
"type": "interface",
"items": [
{
"name": "get_referrer",
"type": "function",
"inputs": [
{
"name": "account",
"type": "core::starknet::contract_address::ContractAddress"
}
],
"outputs": [
{
"type": "core::starknet::contract_address::ContractAddress"
}
],
"state_mutability": "view"
},
{
"name": "set_referrer",
"type": "function",
"inputs": [
{
"name": "address",
"type": "core::starknet::contract_address::ContractAddress"
}
],
"outputs": [],
"state_mutability": "external"
},
{
"name": "upgrade",
"type": "function",
"inputs": [
{
"name": "new_class_hash",
"type": "core::starknet::class_hash::ClassHash"
}
],
"outputs": [],
"state_mutability": "external"
}
]
},
{
"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"
},
{
"name": "transfer_ownership",
"type": "function",
"inputs": [
{
"name": "new_owner",
"type": "core::starknet::contract_address::ContractAddress"
}
],
"outputs": [],
"state_mutability": "external"
},
{
"name": "renounce_ownership",
"type": "function",
"inputs": [],
"outputs": [],
"state_mutability": "external"
}
]
},
{
"name": "constructor",
"type": "constructor",
"inputs": [
{
"name": "owner",
"type": "core::starknet::contract_address::ContractAddress"
}
]
},
{
"kind": "struct",
"name": "jediswap_referral::referral_storage::ReferralStorage::SetReferrer",
"type": "event",
"members": [
{
"kind": "data",
"name": "account",
"type": "core::starknet::contract_address::ContractAddress"
},
{
"kind": "data",
"name": "referrer",
"type": "core::starknet::contract_address::ContractAddress"
}
]
},
{
"kind": "struct",
"name": "openzeppelin::access::ownable::ownable::OwnableComponent::OwnershipTransferred",
"type": "event",
"members": [
{
"kind": "key",
"name": "previous_owner",
"type": "core::starknet::contract_address::ContractAddress"
},
{
"kind": "key",
"name": "new_owner",
"type": "core::starknet::contract_address::ContractAddress"
}
]
},
{
"kind": "struct",
"name": "openzeppelin::access::ownable::ownable::OwnableComponent::OwnershipTransferStarted",
"type": "event",
"members": [
{
"kind": "key",
"name": "previous_owner",
"type": "core::starknet::contract_address::ContractAddress"
},
{
"kind": "key",
"name": "new_owner",
"type": "core::starknet::contract_address::ContractAddress"
}
]
},
{
"kind": "enum",
"name": "openzeppelin::access::ownable::ownable::OwnableComponent::Event",
"type": "event",
"variants": [
{
"kind": "nested",
"name": "OwnershipTransferred",
"type": "openzeppelin::access::ownable::ownable::OwnableComponent::OwnershipTransferred"
},
{
"kind": "nested",
"name": "OwnershipTransferStarted",
"type": "openzeppelin::access::ownable::ownable::OwnableComponent::OwnershipTransferStarted"
}
]
},
{
"kind": "struct",
"name": "openzeppelin::upgrades::upgradeable::UpgradeableComponent::Upgraded",
"type": "event",
"members": [
{
"kind": "data",
"name": "class_hash",
"type": "core::starknet::class_hash::ClassHash"
}
]
},
{
"kind": "enum",
"name": "openzeppelin::upgrades::upgradeable::UpgradeableComponent::Event",
"type": "event",
"variants": [
{
"kind": "nested",
"name": "Upgraded",
"type": "openzeppelin::upgrades::upgradeable::UpgradeableComponent::Upgraded"
}
]
},
{
"kind": "enum",
"name": "jediswap_referral::referral_storage::ReferralStorage::Event",
"type": "event",
"variants": [
{
"kind": "nested",
"name": "SetReferrer",
"type": "jediswap_referral::referral_storage::ReferralStorage::SetReferrer"
},
{
"kind": "flat",
"name": "OwnableEvent",
"type": "openzeppelin::access::ownable::ownable::OwnableComponent::Event"
},
{
"kind": "flat",
"name": "UpgradeableEvent",
"type": "openzeppelin::upgrades::upgradeable::UpgradeableComponent::Event"
}
]
}
]
12 changes: 12 additions & 0 deletions src/contracts/referralAddress/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ChainId } from '@vnaysn/jediswap-sdk-core'

import REFERRAL_ABI from './abi.json'

// change ABI and Contracts

const REFERRAL_ADDRESS: { [chainId in ChainId]: string } = {
[ChainId.MAINNET]: '0x3a762f53edac9c5c85394898f637eb0e6ffc11ec9b01e5edb289c31c0e0f613',
[ChainId.GOERLI]: '0x02da52b8745fd5f6c83dd9e375de4a18fa625a38ac2891b4c2822f5b669398ad',
}

export { REFERRAL_ABI, REFERRAL_ADDRESS }
28 changes: 19 additions & 9 deletions src/hooks/useContractV2.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import { Contract } from 'starknet'
import { useMemo } from 'react'
import { FACTORY_ADDRESS, FACTORY_ABI } from 'contracts/factoryAddress'
import { useAccountDetails } from './starknet-react'
import { Contract } from 'starknet'

import ERC20_ABI from 'abis/erc20.json'
import { DEFAULT_CHAIN_ID, NONFUNGIBLE_POOL_MANAGER_ADDRESS } from 'constants/tokens'
import { getContractV2 } from 'utils/getContract'
import { FACTORY_ABI, FACTORY_ADDRESS } from 'contracts/factoryAddress'
import { MULTICALL_ABI, MULTICALL_NETWORKS } from 'contracts/multicall'
import NFTPositionManagerABI from 'contracts/nonfungiblepositionmanager/abi.json'
import ERC20_ABI from 'abis/erc20.json'
import { REFERRAL_ABI, REFERRAL_ADDRESS } from 'contracts/referralAddress'
import { getContractV2 } from 'utils/getContract'
import { useAccountDetails } from './starknet-react'

// returns null on errors
function useContract(address: string | undefined, ABI: any, withSignerIfPossible = true): Contract | null {
const { account, chainId, connector } = useAccountDetails()
return useMemo(() => {
if (!address || !ABI || !account) return null
if (!address || !ABI || !account) {
return null
}

try {
const contract = getContractV2(address, ABI, account, connector) //line 26
const contract = getContractV2(address, ABI, account, connector) // line 26
return contract
} catch (error) {
console.error('Failed to get contract', error)
Expand All @@ -31,19 +35,25 @@ export function useTokenContract(tokenAddress?: string, withSignerIfPossible?: b
// export function usePairContract(pairAddress?: string, withSignerIfPossible?: boolean): Contract | null {
// return useContract(pairAddress, PAIR_ABI, withSignerIfPossible)
// }
//Change here
// Change here
export function useFactoryContract(): Contract | null {
const { chainId } = useAccountDetails()

return useContract(FACTORY_ADDRESS[chainId ?? DEFAULT_CHAIN_ID], FACTORY_ABI, true)
}
//Change Here
// Change Here
// export function useRouterContract(): Contract | null {
// const { account, chainId } = useAccountDetails()

// return useContract(ROUTER_ADDRESS[chainId ?? DEFAULT_CHAIN_ID], ROUTER_ABI, true)
// }

export function useReferralContract(): Contract | null {
const { account, chainId } = useAccountDetails()

return useContract(REFERRAL_ADDRESS[chainId ?? DEFAULT_CHAIN_ID], REFERRAL_ABI, true)
}

export function useMulticallContract(): Contract | null {
const { chainId } = useAccountDetails()

Expand Down
5 changes: 3 additions & 2 deletions src/hooks/usePositionTokenURI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import JSBI from 'jsbi'
import { NEVER_RELOAD, useSingleCallResult } from 'lib/hooks/multicall'
import { useMemo } from 'react'
import NFTPositionManagerABI from 'contracts/nonfungiblepositionmanager/abi.json'
import { useContractRead } from '@starknet-react/core'
import { useV3NFTPositionManagerContract } from './useContract'
import { DEFAULT_CHAIN_ID, NONFUNGIBLE_POOL_MANAGER_ADDRESS } from 'constants/tokens'
import { cairo, CallData, encode, num } from 'starknet'
import { useAccountDetails } from './starknet-react'
import { useQuery } from 'react-query'
import { providerInstance } from 'utils/getLibrary'
import { useAccountDetails } from './starknet-react'

type TokenId = number | JSBI | BigNumber

Expand Down Expand Up @@ -84,7 +85,7 @@ export function usePositionTokenURI(tokenId: TokenId | undefined): UsePositionTo
}, [error, loading, result, tokenId, valid])
}

const feltArrToStr = (felts: bigint[]): string | undefined => {
export const feltArrToStr = (felts: bigint[]): string | undefined => {
if (!felts || !felts.length) return undefined
return felts.reduce((memo, felt) => memo + Buffer.from(felt.toString(16), 'hex').toString(), '')
}
Expand Down
Loading