From ee5f8449202f9adb8b23a551e7961c3724ddc659 Mon Sep 17 00:00:00 2001 From: Laukik verma Date: Tue, 31 Dec 2024 15:40:39 +0530 Subject: [PATCH 1/6] add: hyperliquid (998) evm chain --- example-next/src/components/Tokens.tsx | 8 ++++++ packages/react/src/actions/evm/getEVMToken.ts | 13 +++++++++ packages/react/src/chains/evm/hyperliquid.ts | 28 +++++++++++++++++++ packages/react/src/chains/evm/index.ts | 1 + packages/react/src/constants/index.ts | 2 ++ .../src/utils/getDefaultSupportedChains.ts | 1 + 6 files changed, 53 insertions(+) create mode 100644 packages/react/src/chains/evm/hyperliquid.ts diff --git a/example-next/src/components/Tokens.tsx b/example-next/src/components/Tokens.tsx index 7cae2cb2..097d8723 100644 --- a/example-next/src/components/Tokens.tsx +++ b/example-next/src/components/Tokens.tsx @@ -65,6 +65,14 @@ const tokens: TokenMetadata[] = [ chainId: 'osmosis-1', isNative: true, }, + { + address: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', + decimals: 6, + name: 'USDC', + symbol: 'USDC', + chainId: '998', + isNative: false, + }, { address: ETH_ADDRESS, decimals: 18, diff --git a/packages/react/src/actions/evm/getEVMToken.ts b/packages/react/src/actions/evm/getEVMToken.ts index e62a7d0d..d1855333 100644 --- a/packages/react/src/actions/evm/getEVMToken.ts +++ b/packages/react/src/actions/evm/getEVMToken.ts @@ -2,6 +2,13 @@ import { Config, multicall } from '@wagmi/core'; import { Address, erc20Abi } from 'viem'; export const getEVMTokenMetadata = async (address: string, chainId: number, wagmiConfig: Config) => { + if (chainId === 998) { + return { + name: 'USDC', + symbol: 'USDC', + decimals: 6, + }; + } const tokenData = await multicall(wagmiConfig, { contracts: [ { @@ -38,6 +45,12 @@ export const getEVMTokenBalanceAndAllowance = async ( chainId: number, wagmiConfig: Config, ) => { + if (chainId === 998) { + return { + balance: BigInt(0), + allowance: BigInt(0), + }; + } const calls = [ { address: address as Address, diff --git a/packages/react/src/chains/evm/hyperliquid.ts b/packages/react/src/chains/evm/hyperliquid.ts new file mode 100644 index 00000000..92669ba8 --- /dev/null +++ b/packages/react/src/chains/evm/hyperliquid.ts @@ -0,0 +1,28 @@ +import { EVMChain } from '../../types/index.js'; + +export const hyperliquid: EVMChain = { + id: 998, + name: 'hyperliquid', + type: 'evm', + nativeCurrency: { + decimals: 6, + name: 'USDC', + symbol: 'USDC', + }, + rpcUrls: { + default: { + http: [], + }, + }, + blockExplorers: { + default: { + name: 'Hyperliquid explorer', + url: 'http://hypurrscan.io/', + }, + }, + contracts: { + multicall3: { + address: '0xca11bde05977b3631167028862be2a173976ca11', + }, + }, +}; diff --git a/packages/react/src/chains/evm/index.ts b/packages/react/src/chains/evm/index.ts index 9be9fab6..4b553ce9 100644 --- a/packages/react/src/chains/evm/index.ts +++ b/packages/react/src/chains/evm/index.ts @@ -55,6 +55,7 @@ export const vanar: EVMChain = { ...vVanar, type: 'evm' } as const; export const xLayer: EVMChain = { ...vxLayer, type: 'evm' } as const; export const zkSync: EVMChain = { ...vZkSync, type: 'evm' } as const; export * from './arthera.js'; +export * from './hyperliquid.js'; export * from './nahmii.js'; export * from './nero.js'; export * from './oasisSapphire.js'; diff --git a/packages/react/src/constants/index.ts b/packages/react/src/constants/index.ts index 234366bf..e00f43c1 100644 --- a/packages/react/src/constants/index.ts +++ b/packages/react/src/constants/index.ts @@ -20,6 +20,7 @@ export const CHAIN_ID = { mantle: '5000', matchain: '698', metis: '1088', + hyperliquid: '998', mode: '34443', nahmii: '4061', nero: '1689', @@ -123,6 +124,7 @@ export const CHAIN_DATA: Record = { [CHAIN_ID.vanar]: chains.vanar, [CHAIN_ID.zksync]: chains.zkSync, [CHAIN_ID.xLayer]: chains.xLayer, + [CHAIN_ID.hyperliquid]: chains.hyperliquid, //cosmos [CHAIN_ID.osmosis]: chains.osmosis, diff --git a/packages/react/src/utils/getDefaultSupportedChains.ts b/packages/react/src/utils/getDefaultSupportedChains.ts index 6195c521..6b62b3b9 100644 --- a/packages/react/src/utils/getDefaultSupportedChains.ts +++ b/packages/react/src/utils/getDefaultSupportedChains.ts @@ -46,6 +46,7 @@ const getDefaultSupportedChains = (testnet?: boolean): SupportedChainsByType => evm.mantle, evm.matchain, evm.metis, + evm.hyperliquid, evm.mode, evm.nahmii, evm.nero, From 70647d4c785d6a689d0ff33f8b779b2869e742a5 Mon Sep 17 00:00:00 2001 From: Jayesh Bhole <111138421+jayeshbhole-rp@users.noreply.github.com> Date: Tue, 31 Dec 2024 16:24:21 +0530 Subject: [PATCH 2/6] publish: 1.16.0 --- packages/react/CHANGELOG.md | 6 ++++++ packages/react/package.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/react/CHANGELOG.md b/packages/react/CHANGELOG.md index bd172b2a..a4b999f6 100644 --- a/packages/react/CHANGELOG.md +++ b/packages/react/CHANGELOG.md @@ -1,5 +1,11 @@ # @tangled3/react +## 1.16.0 + +### Minor Changes + +- feat: add hyperliquid + ## 1.15.14 ### Patch Changes diff --git a/packages/react/package.json b/packages/react/package.json index 468dbeab..ea4951f0 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -1,7 +1,7 @@ { "name": "@tangled3/react", "private": false, - "version": "1.15.14", + "version": "1.16.0", "type": "module", "license": "MIT", "main": "./src/index.ts", From 1ccd2f6223afe723fe7983b5fab165b81e27e480 Mon Sep 17 00:00:00 2001 From: Jayesh Bhole <111138421+jayeshbhole-rp@users.noreply.github.com> Date: Wed, 1 Jan 2025 12:33:06 +0530 Subject: [PATCH 3/6] fix: add tron token handler --- packages/react/CHANGELOG.md | 6 +++++ packages/react/package.json | 2 +- packages/react/src/hooks/useTokenHandlers.tsx | 26 ++++++++++++++++++- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/packages/react/CHANGELOG.md b/packages/react/CHANGELOG.md index a4b999f6..e35146cd 100644 --- a/packages/react/CHANGELOG.md +++ b/packages/react/CHANGELOG.md @@ -1,5 +1,11 @@ # @tangled3/react +## 1.16.1 + +### Patch Changes + +- fix: add tron token handler + ## 1.16.0 ### Minor Changes diff --git a/packages/react/package.json b/packages/react/package.json index ea4951f0..f06419f0 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -1,7 +1,7 @@ { "name": "@tangled3/react", "private": false, - "version": "1.16.0", + "version": "1.16.1", "type": "module", "license": "MIT", "main": "./src/index.ts", diff --git a/packages/react/src/hooks/useTokenHandlers.tsx b/packages/react/src/hooks/useTokenHandlers.tsx index 3dbd2d04..b006984c 100644 --- a/packages/react/src/hooks/useTokenHandlers.tsx +++ b/packages/react/src/hooks/useTokenHandlers.tsx @@ -4,7 +4,7 @@ import { useMutation } from '@tanstack/react-query'; import { useCallback } from 'react'; import { Address, encodeFunctionData, erc20Abi } from 'viem'; import { getProgramId } from '../actions/solana/getProgramId.js'; -import { ChainData, ChainId, OtherChainData } from '../types/index.js'; +import { ChainData, ChainId, OtherChainData, TronChain } from '../types/index.js'; import { useChain } from './useChain.js'; import { useConnectionOrConfig } from './useConnectionOrConfig.js'; import { useCurrentAccount } from './useCurrentAccount.js'; @@ -110,6 +110,27 @@ const useTokenHandlers = ({ chainId, token, spender, owner, amount }: UseTokenHa [account, connectionOrConfig, sendTransaction], ); + const increaseTronAllowance = useCallback( + async (spender: string, owner: string, amount: bigint, token: string, chain: TronChain) => { + const calldata = encodeFunctionData({ + abi: erc20Abi, + functionName: 'approve', + args: [spender, amount] as [Address, bigint], + }); + return await sendTransaction({ + args: { + calldata, + }, + chain, + from: owner, + overrides: {}, + to: token, + value: 0n, + }); + }, + [sendTransaction], + ); + return useMutation({ mutationKey: ['approve', chain?.id, token], mutationFn: async () => { @@ -122,6 +143,9 @@ const useTokenHandlers = ({ chainId, token, spender, owner, amount }: UseTokenHa if (chain.type === 'solana') { return createAssociatedTokenAccount(owner, token, chain as OtherChainData<'solana'>); } + if (chain.type === 'tron') { + return increaseTronAllowance(spender, owner, amount, token, chain); + } throw new Error('Chain type not supported'); }, From 9c2580f5e295b73a03ad7f31674166075998dae8 Mon Sep 17 00:00:00 2001 From: Jayesh Bhole <111138421+jayeshbhole-rp@users.noreply.github.com> Date: Wed, 1 Jan 2025 12:57:57 +0530 Subject: [PATCH 4/6] fix: tron multicall abi --- packages/react/CHANGELOG.md | 6 ++ packages/react/package.json | 2 +- .../react/src/constants/abi/tronMulticall.ts | 63 +++++++++++++++++++ 3 files changed, 70 insertions(+), 1 deletion(-) diff --git a/packages/react/CHANGELOG.md b/packages/react/CHANGELOG.md index e35146cd..1a7becd7 100644 --- a/packages/react/CHANGELOG.md +++ b/packages/react/CHANGELOG.md @@ -1,5 +1,11 @@ # @tangled3/react +## 1.16.2 + +### Patch Changes + +- fix tron multicall abi + ## 1.16.1 ### Patch Changes diff --git a/packages/react/package.json b/packages/react/package.json index f06419f0..297caca3 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -1,7 +1,7 @@ { "name": "@tangled3/react", "private": false, - "version": "1.16.1", + "version": "1.16.2", "type": "module", "license": "MIT", "main": "./src/index.ts", diff --git a/packages/react/src/constants/abi/tronMulticall.ts b/packages/react/src/constants/abi/tronMulticall.ts index 8ede7d87..be5bd73f 100644 --- a/packages/react/src/constants/abi/tronMulticall.ts +++ b/packages/react/src/constants/abi/tronMulticall.ts @@ -19,6 +19,69 @@ export const tronMulticallAbi = [ stateMutability: 'view', type: 'function', }, + { + inputs: [], + name: 'getBasefee', + outputs: [{ internalType: 'uint256', name: 'basefee', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [{ internalType: 'uint256', name: 'blockNumber', type: 'uint256' }], + name: 'getBlockHash', + outputs: [{ internalType: 'bytes32', name: 'blockHash', type: 'bytes32' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'getBlockNumber', + outputs: [{ internalType: 'uint256', name: 'blockNumber', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'getChainId', + outputs: [{ internalType: 'uint256', name: 'chainid', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'getCurrentBlockCoinbase', + outputs: [{ internalType: 'address', name: 'coinbase', type: 'address' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'getCurrentBlockDifficulty', + outputs: [{ internalType: 'uint256', name: 'difficulty', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'getCurrentBlockTimestamp', + outputs: [{ internalType: 'uint256', name: 'timestamp', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [{ internalType: 'address', name: 'addr', type: 'address' }], + name: 'getEthBalance', + outputs: [{ internalType: 'uint256', name: 'balance', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'getLastBlockHash', + outputs: [{ internalType: 'bytes32', name: 'blockHash', type: 'bytes32' }], + stateMutability: 'view', + type: 'function', + }, { inputs: [ { internalType: 'address', name: 'accountAddress', type: 'address' }, From 562bc8219bc830653ed52580a06c37105645a203 Mon Sep 17 00:00:00 2001 From: Jayesh Bhole <111138421+jayeshbhole-rp@users.noreply.github.com> Date: Wed, 1 Jan 2025 14:59:29 +0530 Subject: [PATCH 5/6] chore: update trc20 --- packages/react/src/constants/abi/trc20.ts | 311 ++++++++++++++++++---- 1 file changed, 266 insertions(+), 45 deletions(-) diff --git a/packages/react/src/constants/abi/trc20.ts b/packages/react/src/constants/abi/trc20.ts index 6fec8a0c..d7c3718d 100644 --- a/packages/react/src/constants/abi/trc20.ts +++ b/packages/react/src/constants/abi/trc20.ts @@ -1,79 +1,300 @@ export const trc20Abi = [ - { outputs: [{ type: 'string' }], name: 'currency', stateMutability: 'View', type: 'Function' }, - { outputs: [{ type: 'uint8' }], name: 'decimals', stateMutability: 'View', type: 'Function' }, - { outputs: [{ type: 'string' }], name: 'name', stateMutability: 'View', type: 'Function' }, - { outputs: [{ type: 'string' }], name: 'symbol', stateMutability: 'View', type: 'Function' }, { - outputs: [{ type: 'uint256' }], + constant: false, + inputs: [ + { + name: 'spender', + type: 'address', + }, + { + name: 'value', + type: 'uint256', + }, + ], + name: 'approve', + outputs: [ + { + name: '', + type: 'bool', + }, + ], + payable: false, + stateMutability: 'nonpayable', + type: 'function', + signature: '0x095ea7b3', + }, + { + constant: true, + inputs: [], name: 'totalSupply', - stateMutability: 'View', - type: 'Function', + outputs: [ + { + name: '', + type: 'uint256', + }, + ], + payable: false, + stateMutability: 'view', + type: 'function', + signature: '0x18160ddd', }, { - outputs: [{ type: 'uint256' }], - inputs: [{ name: '_owner', type: 'address' }], - name: 'balanceOf', - stateMutability: 'View', - type: 'Function', + constant: false, + inputs: [ + { + name: 'from', + type: 'address', + }, + { + name: 'to', + type: 'address', + }, + { + name: 'value', + type: 'uint256', + }, + ], + name: 'transferFrom', + outputs: [ + { + name: '', + type: 'bool', + }, + ], + payable: false, + stateMutability: 'nonpayable', + type: 'function', + signature: '0x23b872dd', }, { - outputs: [{ type: 'bool' }], + constant: false, inputs: [ - { name: '_to', type: 'address' }, - { name: '_value', type: 'uint256' }, + { + name: 'spender', + type: 'address', + }, + { + name: 'addedValue', + type: 'uint256', + }, ], - name: 'transfer', - stateMutability: 'Nonpayable', - type: 'Function', + name: 'increaseAllowance', + outputs: [ + { + name: '', + type: 'bool', + }, + ], + payable: false, + stateMutability: 'nonpayable', + type: 'function', + signature: '0x39509351', }, { - outputs: [{ type: 'bool' }], + constant: true, inputs: [ - { name: '_from', type: 'address' }, - { name: '_to', type: 'address' }, - { name: '_value', type: 'uint256' }, + { + name: 'owner', + type: 'address', + }, ], - name: 'transferFrom', - stateMutability: 'Nonpayable', - type: 'Function', + name: 'balanceOf', + outputs: [ + { + name: '', + type: 'uint256', + }, + ], + payable: false, + stateMutability: 'view', + type: 'function', + signature: '0x70a08231', }, { - outputs: [{ type: 'bool' }], + constant: false, inputs: [ - { name: '_spender', type: 'address' }, - { name: '_value', type: 'uint256' }, + { + name: 'spender', + type: 'address', + }, + { + name: 'subtractedValue', + type: 'uint256', + }, ], - name: 'approve', - stateMutability: 'Nonpayable', - type: 'Function', + name: 'decreaseAllowance', + outputs: [ + { + name: '', + type: 'bool', + }, + ], + payable: false, + stateMutability: 'nonpayable', + type: 'function', + signature: '0xa457c2d7', }, { - outputs: [{ type: 'uint256' }], + constant: false, inputs: [ - { name: '_owner', type: 'address' }, - { name: '_spender', type: 'address' }, + { + name: 'to', + type: 'address', + }, + { + name: 'value', + type: 'uint256', + }, + ], + name: 'transfer', + outputs: [ + { + name: '', + type: 'bool', + }, + ], + payable: false, + stateMutability: 'nonpayable', + type: 'function', + signature: '0xa9059cbb', + }, + { + constant: true, + inputs: [ + { + name: 'owner', + type: 'address', + }, + { + name: 'spender', + type: 'address', + }, ], name: 'allowance', - stateMutability: 'View', - type: 'Function', + outputs: [ + { + name: '', + type: 'uint256', + }, + ], + payable: false, + stateMutability: 'view', + type: 'function', + signature: '0xdd62ed3e', + }, + { + inputs: [ + { + name: 'name', + type: 'string', + }, + { + name: 'symbol', + type: 'string', + }, + { + name: 'decimals', + type: 'uint8', + }, + { + name: 'cap', + type: 'uint256', + }, + ], + payable: false, + stateMutability: 'nonpayable', + type: 'constructor', + signature: 'constructor', }, - { + anonymous: false, inputs: [ - { indexed: true, name: '_from', type: 'address' }, - { indexed: true, name: '_to', type: 'address' }, - { name: '_value', type: 'uint256' }, + { + indexed: true, + name: 'from', + type: 'address', + }, + { + indexed: true, + name: 'to', + type: 'address', + }, + { + indexed: false, + name: 'value', + type: 'uint256', + }, ], name: 'Transfer', - type: 'Event', + type: 'event', + signature: '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef', }, { + anonymous: false, inputs: [ - { indexed: true, name: '_owner', type: 'address' }, - { indexed: true, name: '_spender', type: 'address' }, - { name: '_value', type: 'uint256' }, + { + indexed: true, + name: 'owner', + type: 'address', + }, + { + indexed: true, + name: 'spender', + type: 'address', + }, + { + indexed: false, + name: 'value', + type: 'uint256', + }, ], name: 'Approval', - type: 'Event', + type: 'event', + signature: '0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925', + }, + { + constant: true, + inputs: [], + name: 'name', + outputs: [ + { + name: '', + type: 'string', + }, + ], + payable: false, + stateMutability: 'view', + type: 'function', + signature: '0x06fdde03', + }, + { + constant: true, + inputs: [], + name: 'symbol', + outputs: [ + { + name: '', + type: 'string', + }, + ], + payable: false, + stateMutability: 'view', + type: 'function', + signature: '0x95d89b41', + }, + { + constant: true, + inputs: [], + name: 'decimals', + outputs: [ + { + name: '', + type: 'uint8', + }, + ], + payable: false, + stateMutability: 'view', + type: 'function', + signature: '0x313ce567', }, ] as const; From 6ed8a7b6c07d1e8fb7b165ef991eae9d292dfbbf Mon Sep 17 00:00:00 2001 From: Jayesh Bhole <111138421+jayeshbhole-rp@users.noreply.github.com> Date: Wed, 1 Jan 2025 15:00:09 +0530 Subject: [PATCH 6/6] fix: trc20 abi --- packages/react/CHANGELOG.md | 6 ++++++ packages/react/package.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/react/CHANGELOG.md b/packages/react/CHANGELOG.md index 1a7becd7..f80f9c46 100644 --- a/packages/react/CHANGELOG.md +++ b/packages/react/CHANGELOG.md @@ -1,5 +1,11 @@ # @tangled3/react +## 1.16.3 + +### Patch Changes + +- fix trc20 abi + ## 1.16.2 ### Patch Changes diff --git a/packages/react/package.json b/packages/react/package.json index 297caca3..0ddc0aee 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -1,7 +1,7 @@ { "name": "@tangled3/react", "private": false, - "version": "1.16.2", + "version": "1.16.3", "type": "module", "license": "MIT", "main": "./src/index.ts",