From ad861a449bd40d8fcdfe2cc31befb92242bec1b5 Mon Sep 17 00:00:00 2001 From: donnyquixotic Date: Wed, 31 Jan 2024 23:37:40 -0600 Subject: [PATCH 01/25] feat: erc20 TLOS OFT transfers --- CONTRACTS.md | 23 +- src/abi/bridgeAbi.js | 2 + src/abi/oftAbi.js | 0 src/bootstrap.ts | 5 + src/config.ts | 58 +++- src/features/bridge/stores/bridgeStore.tsx | 351 ++++++++++++++++++--- src/features/core/ui/CurrencyIcon.tsx | 2 + 7 files changed, 393 insertions(+), 48 deletions(-) create mode 100644 src/abi/bridgeAbi.js create mode 100644 src/abi/oftAbi.js diff --git a/CONTRACTS.md b/CONTRACTS.md index 1a75a43..9c0bec7 100644 --- a/CONTRACTS.md +++ b/CONTRACTS.md @@ -23,23 +23,27 @@ * ETH: `0xA0fB8cd450c8Fd3a11901876cD5f17eB47C6bc50` * BNB: `0x26Ed0F16e777C94A6FE798F9E20298034930Bae8` +## TLOS OFT +* telos: `0x7B5250Ad9aE6445e75E01Cd4bB070aECBf8DB92E` +* ethereum: `0x5Aa352551d39F5ce592260e0D26818e7d780867f` +* bsc: `0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E` +* polygon: `0x1cF0636abbc569fB413A20bd7964712e6b4d1161` +* arbitrum: `0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E` +* avalanche: `0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E` ## Testnet ### Endpoint * chainId: `10199` * address `0x83c73Da98cf733B03315aFa8758834b36a195b87` - ### OriginalTokenBridge * goerli: `0xBCD4a2c19DC010d1Da2D7985CF18A5251774dF46` * arbitrum-goerli: `0xbF625D717de1a6e5a8446424CF08D4269D51ab96` * bsc-testnet: `0x8168C0704Ff49F8e89AF45f04f898144C459b156` * mumbai: `0x0c372d3f89d1ce9f11a50b98374f7846a37f7d99` * fuji: `0x2a3a50f458AaAae618C54C1670fD49e338b795c2` - ### WrappedTokenBridge * telos-testnet: `0x137d4e9C2431A3DCBa6e615E9438F2c558353a17` - ### USDC * goerli: `0x31190a205713Bd825a0c237E26f67CE89B5C4dD8` * arbitrum-goerli: `0x6463C73809EE3F85BeCD0a82c55cb808474101D0` @@ -47,16 +51,15 @@ * telos-testnet: `0x22FdA4Efc62d72f0E0804e205c2c858D5c2cF959` ### USDT -* goerli: `0xdddacBBFa219b9579596886032b826552c8E9810` +* goerli: `0xdddacBBFa219b9579596886032b826552c8E9810` * mumbai: `0x6cc732BB947569e5560F380c8d3E24844bA2DDb3` * telos-testnet: `0xe1aFB545B5701D884a674d90b31927BBd0fcA380` -### BTCb -* fuji: `0x576d96722c79aB0469BE3a632521d100de0AE3E3` -* telos-testnet: `0xDbCE5f022203c36578F5D751E9c5e669AF35C62B` - -### WETH -* telos-testnet: `0xe83F5959A58cb21E3B3B1682a898143C3f4AFEe0` + @@ -60,3 +68,7 @@ ### WBNB * telos-testnet: `0x15a7cad43E5F24d1B08fDE151CE00D1cf360f6C7` + +## TLOS OFT +* telos: `0xAEa017740a2e7608F873CB130e7B3c335A4a1940` +* fuji: `0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E` \ No newline at end of file diff --git a/src/abi/bridgeAbi.js b/src/abi/bridgeAbi.js new file mode 100644 index 0000000..852c90b --- /dev/null +++ b/src/abi/bridgeAbi.js @@ -0,0 +1,2 @@ +// wrapped token bridge abi used for TLOS OFT transfers +export const bridgeAbi = [{"inputs":[{"internalType":"address","name":"_endpoint","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint16","name":"_srcChainId","type":"uint16"},{"indexed":false,"internalType":"bytes","name":"_srcAddress","type":"bytes"},{"indexed":false,"internalType":"uint64","name":"_nonce","type":"uint64"},{"indexed":false,"internalType":"bytes","name":"_payload","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"_reason","type":"bytes"}],"name":"MessageFailed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"localToken","type":"address"},{"indexed":false,"internalType":"uint16","name":"remoteChainId","type":"uint16"},{"indexed":false,"internalType":"address","name":"remoteToken","type":"address"}],"name":"RegisterToken","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint16","name":"_srcChainId","type":"uint16"},{"indexed":false,"internalType":"bytes","name":"_srcAddress","type":"bytes"},{"indexed":false,"internalType":"uint64","name":"_nonce","type":"uint64"},{"indexed":false,"internalType":"bytes32","name":"_payloadHash","type":"bytes32"}],"name":"RetryMessageSuccess","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint16","name":"_dstChainId","type":"uint16"},{"indexed":false,"internalType":"uint16","name":"_type","type":"uint16"},{"indexed":false,"internalType":"uint256","name":"_minDstGas","type":"uint256"}],"name":"SetMinDstGas","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"precrime","type":"address"}],"name":"SetPrecrime","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint16","name":"_remoteChainId","type":"uint16"},{"indexed":false,"internalType":"bytes","name":"_path","type":"bytes"}],"name":"SetTrustedRemote","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint16","name":"_remoteChainId","type":"uint16"},{"indexed":false,"internalType":"bytes","name":"_remoteAddress","type":"bytes"}],"name":"SetTrustedRemoteAddress","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"useCustomAdapterParams","type":"bool"}],"name":"SetUseCustomAdapterParams","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint16","name":"withdrawalFeeBps","type":"uint16"}],"name":"SetWithdrawalFeeBps","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"localToken","type":"address"},{"indexed":false,"internalType":"address","name":"remoteToken","type":"address"},{"indexed":false,"internalType":"uint16","name":"remoteChainId","type":"uint16"},{"indexed":false,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"UnwrapToken","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"localToken","type":"address"},{"indexed":false,"internalType":"address","name":"remoteToken","type":"address"},{"indexed":false,"internalType":"uint16","name":"remoteChainId","type":"uint16"},{"indexed":false,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"WrapToken","type":"event"},{"inputs":[],"name":"PT_MINT","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PT_UNLOCK","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TOTAL_BPS","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"localToken","type":"address"},{"internalType":"uint16","name":"remoteChainId","type":"uint16"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"bool","name":"unwrapWeth","type":"bool"},{"components":[{"internalType":"address payable","name":"refundAddress","type":"address"},{"internalType":"address","name":"zroPaymentAddress","type":"address"}],"internalType":"struct LzLib.CallParams","name":"callParams","type":"tuple"},{"internalType":"bytes","name":"adapterParams","type":"bytes"}],"name":"bridge","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint16","name":"remoteChainId","type":"uint16"},{"internalType":"bool","name":"useZro","type":"bool"},{"internalType":"bytes","name":"adapterParams","type":"bytes"}],"name":"estimateBridgeFee","outputs":[{"internalType":"uint256","name":"nativeFee","type":"uint256"},{"internalType":"uint256","name":"zroFee","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint16","name":"","type":"uint16"},{"internalType":"bytes","name":"","type":"bytes"},{"internalType":"uint64","name":"","type":"uint64"}],"name":"failedMessages","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint16","name":"_srcChainId","type":"uint16"},{"internalType":"bytes","name":"_srcAddress","type":"bytes"}],"name":"forceResumeReceive","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"_version","type":"uint16"},{"internalType":"uint16","name":"_chainId","type":"uint16"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"_configType","type":"uint256"}],"name":"getConfig","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint16","name":"_remoteChainId","type":"uint16"}],"name":"getTrustedRemoteAddress","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint16","name":"_srcChainId","type":"uint16"},{"internalType":"bytes","name":"_srcAddress","type":"bytes"}],"name":"isTrustedRemote","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint16","name":"","type":"uint16"}],"name":"localToRemote","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lzEndpoint","outputs":[{"internalType":"contract ILayerZeroEndpoint","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint16","name":"_srcChainId","type":"uint16"},{"internalType":"bytes","name":"_srcAddress","type":"bytes"},{"internalType":"uint64","name":"_nonce","type":"uint64"},{"internalType":"bytes","name":"_payload","type":"bytes"}],"name":"lzReceive","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"","type":"uint16"},{"internalType":"uint16","name":"","type":"uint16"}],"name":"minDstGasLookup","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint16","name":"_srcChainId","type":"uint16"},{"internalType":"bytes","name":"_srcAddress","type":"bytes"},{"internalType":"uint64","name":"_nonce","type":"uint64"},{"internalType":"bytes","name":"_payload","type":"bytes"}],"name":"nonblockingLzReceive","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"precrime","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"localToken","type":"address"},{"internalType":"uint16","name":"remoteChainId","type":"uint16"},{"internalType":"address","name":"remoteToken","type":"address"}],"name":"registerToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint16","name":"","type":"uint16"}],"name":"remoteToLocal","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"_srcChainId","type":"uint16"},{"internalType":"bytes","name":"_srcAddress","type":"bytes"},{"internalType":"uint64","name":"_nonce","type":"uint64"},{"internalType":"bytes","name":"_payload","type":"bytes"}],"name":"retryMessage","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint16","name":"_version","type":"uint16"},{"internalType":"uint16","name":"_chainId","type":"uint16"},{"internalType":"uint256","name":"_configType","type":"uint256"},{"internalType":"bytes","name":"_config","type":"bytes"}],"name":"setConfig","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"_dstChainId","type":"uint16"},{"internalType":"uint16","name":"_packetType","type":"uint16"},{"internalType":"uint256","name":"_minGas","type":"uint256"}],"name":"setMinDstGas","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_precrime","type":"address"}],"name":"setPrecrime","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"_version","type":"uint16"}],"name":"setReceiveVersion","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"_version","type":"uint16"}],"name":"setSendVersion","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"_srcChainId","type":"uint16"},{"internalType":"bytes","name":"_path","type":"bytes"}],"name":"setTrustedRemote","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"_remoteChainId","type":"uint16"},{"internalType":"bytes","name":"_remoteAddress","type":"bytes"}],"name":"setTrustedRemoteAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_useCustomAdapterParams","type":"bool"}],"name":"setUseCustomAdapterParams","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"_withdrawalFeeBps","type":"uint16"}],"name":"setWithdrawalFeeBps","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"","type":"uint16"},{"internalType":"address","name":"","type":"address"}],"name":"totalValueLocked","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"","type":"uint16"}],"name":"trustedRemoteLookup","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"useCustomAdapterParams","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"withdrawalFeeBps","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"}] \ No newline at end of file diff --git a/src/abi/oftAbi.js b/src/abi/oftAbi.js new file mode 100644 index 0000000..e69de29 diff --git a/src/bootstrap.ts b/src/bootstrap.ts index f144430..a9c0b8a 100644 --- a/src/bootstrap.ts +++ b/src/bootstrap.ts @@ -69,6 +69,8 @@ import {walletStore} from '@/core/stores/walletStore'; import {onftStore} from '@/onft/stores/onftStore'; import {initOnftStore} from '@/onft/stores/onftStore'; +import { telosNativeOft } from './config'; + export async function bootstrap(lzAppConfig: AppConfig, providerFactory: ProviderFactory) { const aptos = { mainnet: createAptosModule(ChainStage.MAINNET), @@ -144,6 +146,9 @@ export async function bootstrap(lzAppConfig: AppConfig, providerFactory: Provide bridgeStore.addCurrencies(oftConfig.tokens); } + // Add Native TLOS OFT + bridgeStore.addCurrencies([telosNativeOft.token]) + // WrappedAssetBridge // https://github.com/LayerZero-Labs/wrapped-asset-bridge for (const wrappedAssetConfig of lzAppConfig.bridge.wrappedToken) { diff --git a/src/config.ts b/src/config.ts index 56a9b18..f9dd602 100644 --- a/src/config.ts +++ b/src/config.ts @@ -2,7 +2,9 @@ import {ChainId} from '@layerzerolabs/lz-sdk'; import {AppConfig, createAppConfig} from '@layerzerolabs/ui-app-config'; import {OnftBridgeConfig, OnftStandard} from '@layerzerolabs/ui-bridge-onft'; import {WrappedTokenBridgeConfig} from '@layerzerolabs/ui-bridge-wrapped-token'; -import {Coin, Token} from '@layerzerolabs/ui-core'; +import {Coin, Currency, Token} from '@layerzerolabs/ui-core'; + +import { bridgeAbi } from './abi/bridgeAbi'; export const wrapped_mainnet: WrappedTokenBridgeConfig = { version: 2, @@ -230,6 +232,27 @@ const RF = { sharedDecimals: 4, } +const TLOS = { + version: 2, + tokens: [ + new Token(ChainId.ARBITRUM, '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E', 18, 'TLOS'), + new Token(ChainId.AVALANCHE, '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E', 18, 'TLOS'), + new Token(ChainId.BSC, '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E', 18, 'TLOS'), + new Token(ChainId.POLYGON, '0x1cF0636abbc569fB413A20bd7964712e6b4d1161', 18, 'TLOS'), + new Token(ChainId.ETHEREUM, '0x5Aa352551d39F5ce592260e0D26818e7d780867f', 18, 'TLOS'), + ], + proxy: [ + {chainId: ChainId.ARBITRUM, address: '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E'}, + {chainId: ChainId.AVALANCHE, address: '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E'}, + {chainId: ChainId.BSC, address: '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E'}, + {chainId: ChainId.POLYGON, address: '0x1cF0636abbc569fB413A20bd7964712e6b4d1161'}, + {chainId: ChainId.ETHEREUM, address: '0x5Aa352551d39F5ce592260e0D26818e7d780867f'}, + {chainId: ChainId.TELOS, address: '0x7B5250Ad9aE6445e75E01Cd4bB070aECBf8DB92E'} + ], + fee: false, + sharedDecimals: 4, +} + export const appConfig: AppConfig = createAppConfig({ bridge: { aptos: [], @@ -238,6 +261,7 @@ export const appConfig: AppConfig = createAppConfig({ LVC, VC, RF, + TLOS ], wrappedToken: [ wrapped_mainnet, @@ -249,3 +273,35 @@ export const appConfig: AppConfig = createAppConfig({ ], }, }); + +/***NATIVE OFT CONFIG***/ + +enum ChainListId { + TELOS = 40, + TELOS_TESTNET = 41, +} + +type BridgeSettings = { + address: string; + chainId: ChainId; + chainListId: ChainListId; + rpc: string; + abi: typeof bridgeAbi +} + +export type ProxyConfig = { + chainId: number; + address: string; +} + +type NativeOftConfig = { + bridge: BridgeSettings; + token: Currency; + proxy: ProxyConfig; +} + +export const telosNativeOft: NativeOftConfig = { + bridge: {address: '0x9c5ebCbE531aA81bD82013aBF97401f5C6111d76', chainId: ChainId.TELOS, chainListId: ChainListId.TELOS, rpc: 'https://mainnet.telos.net/evm', abi: bridgeAbi}, + token: new Coin(ChainId.TELOS, 18, 'TLOS'), + proxy: {chainId: ChainId.TELOS, address: '0x7B5250Ad9aE6445e75E01Cd4bB070aECBf8DB92E'} +} \ No newline at end of file diff --git a/src/features/bridge/stores/bridgeStore.tsx b/src/features/bridge/stores/bridgeStore.tsx index 2f1f07b..31524cc 100644 --- a/src/features/bridge/stores/bridgeStore.tsx +++ b/src/features/bridge/stores/bridgeStore.tsx @@ -3,6 +3,7 @@ import {waitForMessageReceived} from '@layerzerolabs/scan-client'; import type {BridgeApi, TransferInput} from '@layerzerolabs/ui-bridge-sdk'; import { AdapterParams, + BigintIsh, castCurrencyAmountUnsafe, Currency, CurrencyAmount, @@ -16,16 +17,15 @@ import { isEvmChainId, isNativeCurrency, isSolanaChainId, - Percent, TransactionResult, tryGetNetwork, tryParseCurrencyAmount, tryParseNumber, - tryParsePercent, } from '@layerzerolabs/ui-core'; -import {ONE_ADDRESS} from '@layerzerolabs/ui-evm'; +import {ONE_ADDRESS, serializeAdapterParams} from '@layerzerolabs/ui-evm'; import {assertWallet, Wallet} from '@layerzerolabs/ui-wallet'; import assert from 'assert'; +import { Contract,Signer,ethers } from 'ethers'; import {autorun, computed, flow, makeAutoObservable} from 'mobx'; import {fromPromise} from 'mobx-utils'; import {toast} from 'react-toastify'; @@ -43,6 +43,8 @@ import {FromPromise, fromPromiseValue} from '@/core/utils/fromPromise'; import {handleError} from '@/core/utils/handleError'; import {parseWalletError} from '@/core/utils/parseWalletError'; +import { oftAbi } from '../../../abi/oftAbi'; +import { ProxyConfig, telosNativeOft } from '../../../config'; import {unclaimedStore} from './unclaimedStore'; export enum DstNativeAmount { @@ -109,7 +111,7 @@ export class BridgeStore { // views get output(): BridgeOutput | undefined { - return fromPromiseValue(this.promise.output); + return this.isTelos ? this.promise.output as BridgeOutput : fromPromiseValue(this.promise.output as FromPromise); } get messageFee(): FeeQuote | undefined { @@ -134,6 +136,16 @@ export class BridgeStore { const {srcCurrency, dstCurrency} = this.form; if (!srcCurrency) return undefined; if (!dstCurrency) return undefined; + + function findTelosOftTransferApi(api: any ): boolean { + return api.config.proxy.some((p: ProxyConfig) => p.address === telosNativeOft.proxy.address); + } + + if (dstCurrency.chainId === ChainId.TELOS && dstCurrency.symbol === "TLOS"){ + debugger; + const test = this.apis.find(findTelosOftTransferApi); + return test; + } return this.apis.find((s) => s.supportsTransfer(srcCurrency, dstCurrency)); } @@ -422,9 +434,10 @@ export class BridgeStore { if (srcCurrency && dstCurrency && !isValidPair(srcCurrency, dstCurrency)) { addError('Select other pair'); } + debugger; if (!this.messageFee) addError('Checking fee ...'); if (!this.output) addError('Checking fee ...'); - if (!limitAmount) addError('Checking limit...'); + if (!this.isTelos && !limitAmount) addError('Checking limit...'); return errors; } get unclaimed(): CurrencyAmount[] { @@ -453,6 +466,26 @@ export class BridgeStore { }); } + get isTelos(): boolean { + return this.form.srcCurrency?.symbol === 'TLOS' && this.form.srcChainId === ChainId.TELOS; + } + + get srcContractInstance(): Contract | undefined { + const wallet = walletStore.evm; + // only entry is + const proxyAddress = telosNativeOft.proxy.address as string; + const provider = telosNativeOft.bridge.chainListId === wallet?.nativeChainId ? + wallet?.signer : + ethers.getDefaultProvider(telosNativeOft.bridge.rpc); + + return new ethers.Contract(proxyAddress, oftAbi, provider) + } + + get srcBridgeContractInstance(): Contract | undefined { + const provider = ethers.getDefaultProvider(telosNativeOft.bridge.rpc); + return new ethers.Contract(telosNativeOft.bridge.address, telosNativeOft.bridge.abi, provider) + } + // actions async updateAllowance(): Promise { @@ -470,6 +503,10 @@ export class BridgeStore { setAmount(amount: string) { if (tryParseNumber(amount) !== undefined) { this.form.amount = amount; + // if (this.isTelos){ + // this.updateOutput(); + // this.updateMessageFee(); + // } } } @@ -533,6 +570,7 @@ export class BridgeStore { } } setDstCurrency(currency: Currency) { + debugger; this.form.dstCurrency = currency; this.form.dstChainId = currency.chainId; } @@ -544,7 +582,11 @@ export class BridgeStore { form.dstCurrency, form.srcCurrency, ]; + // if (this.isTelos){ + // this.setDstNativeAmount('0'); + // } } + transfer = flow(function* (this: BridgeStore) { try { this.isExecuting = true; @@ -581,21 +623,25 @@ export class BridgeStore { assert(dstWallet?.address, 'dstWallet'); assert(dstNativeBalance, 'dstNativeBalance'); assert(transferApi, 'transferApi'); - assert(registerApi, 'registerApi'); - // try to register if possible - let isRegistered: boolean = yield registerApi.isRegistered(dstCurrency, dstWallet.address); - if (!isRegistered) { - const unsignedTransaction: Awaited> = - yield registerApi.register(dstCurrency); + let isRegistered = false; + if (!(dstCurrency.symbol === "TLOS") && !(dstChainId === ChainId.TELOS)){ + assert(registerApi, 'registerApi'); + + // try to register if possible, exclude registration when src or dst is native OFT + isRegistered = yield registerApi.isRegistered(dstCurrency, dstWallet.address); + if (!isRegistered) { + const unsignedTransaction: Awaited> = + yield registerApi.register(dstCurrency); - const estimatedGasAmount: Awaited< - ReturnType - > = yield unsignedTransaction.estimateNative(dstWallet); + const estimatedGasAmount: Awaited< + ReturnType + > = yield unsignedTransaction.estimateNative(dstWallet); - if (dstNativeBalance.greaterThan(estimatedGasAmount)) { - yield this.register(); - isRegistered = true; + if (dstNativeBalance.greaterThan(estimatedGasAmount)) { + yield this.register(); + isRegistered = true; + } } } @@ -635,7 +681,8 @@ export class BridgeStore { yield transactionResult.wait(); this.isMining = false; - if (!isRegistered) { + // exclude registration when src or dst is native OFT + if (!this.isTelos && !(dstChainId === ChainId.TELOS && dstCurrency.symbol === 'TLOS') && !isRegistered) { uiStore.claimReminderAlert.open(); } @@ -693,6 +740,213 @@ export class BridgeStore { } }); + // transfer = flow(function* (this: BridgeStore) { + // try { + // this.isExecuting = true; + + // const { + // form, + // srcWallet, + // dstWallet, + // messageFee: fee, + // amount, + // minAmount, + // srcAddress, + // dstAddress, + // adapterParams, + // outputAmount, + // dstNativeBalance, + // transferApi, + // registerApi, + // } = this; + // const {srcChainId, dstChainId, dstCurrency, srcCurrency} = form; + + // assert(srcChainId, 'srcChainId'); + // assert(dstChainId, 'dstChainId'); + // assert(srcCurrency, 'srcCurrency'); + // assert(dstCurrency, 'dstCurrency'); + // assert(srcAddress, 'srcAddress'); + // assert(dstAddress, 'dstAddress'); + // assert(fee, 'fee'); + // assert(amount, 'amount'); + // assert(minAmount, 'minAmount'); + // assert(adapterParams, 'adapterParams'); + // assert(outputAmount, 'outputAmount'); + // assert(srcWallet?.address, 'srcWallet'); + // assert(dstWallet?.address, 'dstWallet'); + // assert(dstNativeBalance, 'dstNativeBalance'); + + // let isRegistered = false; + + // if (!this.isTelos){ + // assert(transferApi, 'transferApi'); + // assert(registerApi, 'registerApi'); + + // // try to register if possible + // isRegistered = yield registerApi.isRegistered(dstCurrency, dstWallet.address); + // if (!isRegistered) { + // const unsignedTransaction: Awaited> = + // yield registerApi.register(dstCurrency); + + // const estimatedGasAmount: Awaited< + // ReturnType + // > = yield unsignedTransaction.estimateNative(dstWallet); + + // if (dstNativeBalance.greaterThan(estimatedGasAmount)) { + // yield this.register(); + // isRegistered = true; + // } + // } + + // if (!this.isApproved) { + // yield this.approve(); + // } + // } + + // const input: TransferInput = { + // srcChainId, + // dstChainId, + // srcCurrency, + // dstCurrency, + // srcAddress, + // dstAddress, + // amount, + // minAmount, + // fee, + // adapterParams, + // }; + + // yield srcWallet.switchChain(srcChainId); + // this.isSigning = true; + + // let transactionResult: any; + + // if (this.isTelos){ + // transactionResult = yield this.sendNative(); + // // ensure correct wallet + // yield assertWallet(srcWallet, {chainId: srcChainId, address: srcAddress}); + + // this.isSigning = false; + // this.isMining = true; + // transactionResult.wait(); + + // }else if(transferApi){ + // const unsignedTransaction: Awaited> = + // yield transferApi.transfer(input); + + // // ensure correct wallet + // yield assertWallet(srcWallet, {chainId: srcChainId, address: srcAddress}); + + // const transaction: Awaited< + // ReturnType + // > = yield unsignedTransaction.signAndSubmitTransaction(srcWallet.signer); + // this.isSigning = false; + // this.isMining = true; + // const receipt: Awaited> = yield transaction.wait(); + // this.isMining = false; + // transactionResult.hash = receipt.txHash; + // } + + // if (!this.isTelos && !isRegistered) { + // uiStore.claimReminderAlert.open(); + // } + + // toast.success( + // + //

Transaction Submitted

+ //

+ // + // View on block explorer + // + //

+ //
, + // ); + + // const tx = transactionStore.create({ + // chainId: srcChainId, + // txHash: transactionResult.hash, + // type: 'TRANSFER', + // input, + // expectedDate: getExpectedDate(srcChainId, dstChainId), + // }); + // // this.updateBalances(); + + // waitForMessageReceived(srcChainId, transactionResult.hash) + // .then((message) => { + // // never mark tx as failed + // // we will eventually deliver the tx + // tx.update({ + // completed: true, + // confirmation: { + // chainId: message.dstChainId, + // txHash: message.dstTxHash, + // }, + // }); + // if (isAptosChainId(dstChainId)) { + // unclaimedStore.updateUnclaimedBalance(dstCurrency, dstAddress); + // } + // }) + // .finally(() => { + // this.updateBalances(); + // }); + // } catch (e) { + // handleError(e, () => { + // const {message, title} = parseWalletError(e); + // toast.error( + // + //

{title}

+ //

{message}

+ //
, + // ); + // }); + // throw e; + // } finally { + // this.isSigning = false; + // this.isMining = false; + // this.isExecuting = false; + // } + // }); + + sendNative: () => unknown = flow(function* (this: BridgeStore) { + + const {srcCurrency, srcChainId, dstChainId, amount} = this.form; + + assert(srcChainId, 'srcChainId'); + assert(dstChainId, 'dstChainId'); + assert(srcCurrency, 'srcCurrency'); + assert(this.adapterParams, 'adapterParams'); + assert(this.messageFee, 'messageFee'); + assert(this.srcContractInstance, 'srcContractInstance'); + assert(this.dstNativeAmount, 'dstNativeAmount'); + + const qty = ethers.utils.parseEther(amount) + const toAddress = walletStore.evm?.address; + const toAddressBytes = ethers.utils.defaultAbiCoder.encode(["address"], [toAddress]) + + // if sending from Telos network, include amount in total native token sent + const fee = srcChainId === ChainId.TELOS ? + this.messageFee.nativeFee.add(CurrencyAmount.fromRawAmount(srcCurrency, qty.toBigInt())): + this.messageFee.nativeFee; + + const totalEth = ethers.BigNumber.from(fee.quotient); + const serializedAdapterParams = serializeAdapterParams(this.adapterParams); + + const tx: unknown = yield this.srcContractInstance.sendFrom( + toAddress, // 'from' address to send tokens + dstChainId, // remote LayerZero chainId + toAddressBytes, // 'to' address to send tokens + qty, // amount of tokens to send (in wei) + { + refundAddress: toAddress, + zroPaymentAddress: ethers.constants.AddressZero, + adapterParams: serializedAdapterParams, + }, + { value: totalEth } + ) + + return tx; + }) + register: () => Promise = flow(function* (this: BridgeStore) { this.isRegistering = true; try { @@ -780,25 +1034,33 @@ export class BridgeStore { const {amount, transferApi} = this; if (!amount) return; if (!dstCurrency) return; - if (!transferApi) return; - - yield (this.promise.output = fromPromise( - transferApi.getOutput(amount, dstCurrency).then((output) => ({ - amount: output.amount, - fees: toBridgeFee(output.fee), - })), - )); + if(this.isTelos){ + yield (this.promise.output = + { + amount, + fees: { totalFee: CurrencyAmount.fromRawAmount(dstCurrency, 0)} + } + ); + }else if (transferApi){ + yield (this.promise.output = fromPromise( + transferApi.getOutput(amount, dstCurrency).then((output) => ({ + amount: output.amount, + fees: toBridgeFee(output.fee), + })), + )); + } }); updateMessageFee = flow(function* (this: BridgeStore) { + debugger; + this.promise.messageFee = undefined; const {srcCurrency, dstCurrency} = this.form; - const {transferApi, adapterParams} = this; + const {transferApi, adapterParams, srcBridgeContractInstance} = this; if (!srcCurrency) return; if (!dstCurrency) return; - if (!transferApi) return; if (!adapterParams) return; // We want to introduce a buffer to avoid any gas price fluctuations @@ -806,13 +1068,27 @@ export class BridgeStore { // // The user will be refunded so this increase does not affect the actual price const multiplier = new Fraction(110, 100); - - yield (this.promise.messageFee = fromPromise( - transferApi.getMessageFee(srcCurrency, dstCurrency, adapterParams).then((fee) => ({ - nativeFee: fee.nativeFee.multiply(multiplier), - zroFee: fee.zroFee.multiply(multiplier), - })), - )); + if (this.isTelos && srcBridgeContractInstance){ + const args: [ChainId, boolean, string] = [dstCurrency.chainId, false, serializeAdapterParams(adapterParams)]; + const nativeCurrency = getNativeCurrency(ChainId.TELOS); + + yield this.promise.messageFee = fromPromise( + (srcBridgeContractInstance.estimateBridgeFee(...args)).then((fee: {nativeFee: BigintIsh, zroFee: BigintIsh}) => ({ + nativeFee: CurrencyAmount.fromRawAmount(nativeCurrency, fee.nativeFee).multiply(multiplier), + zroFee: CurrencyAmount.fromRawAmount(nativeCurrency, fee.zroFee).multiply(multiplier), + })) + ); + }else if (transferApi){ + debugger; + const test = yield transferApi.getMessageFee(srcCurrency, dstCurrency, adapterParams); + debugger; + yield (this.promise.messageFee = fromPromise( + transferApi.getMessageFee(srcCurrency, dstCurrency, adapterParams).then((fee) => ({ + nativeFee: fee.nativeFee.multiply(multiplier), + zroFee: fee.zroFee.multiply(multiplier), + })), + )); + } }); updateExtraGas = flow(function* (this: BridgeStore) { @@ -853,7 +1129,8 @@ export class BridgeStore { function isValidPair(srcCurrency: Currency, dstCurrency: Currency): boolean { if (srcCurrency.chainId === dstCurrency.chainId) return false; - return bridgeStore.apis.some((api) => api.supportsTransfer(srcCurrency, dstCurrency)); + // confirm valid pair via asset api or if pair is TLOS oft + return bridgeStore.apis.some((api) => api.supportsTransfer(srcCurrency, dstCurrency)) || srcCurrency.symbol === 'TLOS' && dstCurrency.symbol === 'TLOS'; } function findMatchingCurrency(currency: Currency) { @@ -939,7 +1216,7 @@ type BridgeFrom = { }; type BridgePromise = { - output: FromPromise | undefined; + output: FromPromise | BridgeOutput | undefined; allowance: FromPromise | undefined; limitAmount: FromPromise | undefined; extraGas: FromPromise | undefined; diff --git a/src/features/core/ui/CurrencyIcon.tsx b/src/features/core/ui/CurrencyIcon.tsx index 10bde66..fcda6e7 100644 --- a/src/features/core/ui/CurrencyIcon.tsx +++ b/src/features/core/ui/CurrencyIcon.tsx @@ -23,6 +23,8 @@ const getTokenIcon = (symbol: string): string => { return 'https://raw.githubusercontent.com/telosnetwork/token-list/master/logos/RF.webp'; case 'VC': return 'https://raw.githubusercontent.com/telosnetwork/token-list/master/logos/VC.png'; + case 'TLOS': + return 'https://raw.githubusercontent.com/telosnetwork/token-list/main/logos/telos.png'; default: return getCurrencyIcon(symbol); } From 738cdc16334f2bf2d3c06dc5e13eb616f1ebca58 Mon Sep 17 00:00:00 2001 From: donnyquixotic Date: Thu, 1 Feb 2024 16:28:08 -0600 Subject: [PATCH 02/25] refactor: source is native Telos OFT, dst is native Telos OFT --- src/features/bridge/stores/bridgeStore.tsx | 33 ++++++++++------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/features/bridge/stores/bridgeStore.tsx b/src/features/bridge/stores/bridgeStore.tsx index 31524cc..d6d1bb3 100644 --- a/src/features/bridge/stores/bridgeStore.tsx +++ b/src/features/bridge/stores/bridgeStore.tsx @@ -53,6 +53,7 @@ export enum DstNativeAmount { } export type ValidationError = string; +const TLOS_SYMBOL = 'TLOS'; export class BridgeStore { // isLoading = false; @@ -111,7 +112,7 @@ export class BridgeStore { // views get output(): BridgeOutput | undefined { - return this.isTelos ? this.promise.output as BridgeOutput : fromPromiseValue(this.promise.output as FromPromise); + return this.srcIsNativeTelos ? this.promise.output as BridgeOutput : fromPromiseValue(this.promise.output as FromPromise); } get messageFee(): FeeQuote | undefined { @@ -142,9 +143,7 @@ export class BridgeStore { } if (dstCurrency.chainId === ChainId.TELOS && dstCurrency.symbol === "TLOS"){ - debugger; - const test = this.apis.find(findTelosOftTransferApi); - return test; + return this.apis.find(findTelosOftTransferApi); } return this.apis.find((s) => s.supportsTransfer(srcCurrency, dstCurrency)); } @@ -434,10 +433,9 @@ export class BridgeStore { if (srcCurrency && dstCurrency && !isValidPair(srcCurrency, dstCurrency)) { addError('Select other pair'); } - debugger; if (!this.messageFee) addError('Checking fee ...'); if (!this.output) addError('Checking fee ...'); - if (!this.isTelos && !limitAmount) addError('Checking limit...'); + if (!this.srcIsNativeTelos && !limitAmount) addError('Checking limit...'); return errors; } get unclaimed(): CurrencyAmount[] { @@ -466,8 +464,12 @@ export class BridgeStore { }); } - get isTelos(): boolean { - return this.form.srcCurrency?.symbol === 'TLOS' && this.form.srcChainId === ChainId.TELOS; + get srcIsNativeTelos(): boolean { + return this.form.srcCurrency?.symbol === TLOS_SYMBOL && this.form.srcChainId === ChainId.TELOS; + } + + get dstIsNativeTelos(): boolean { + return this.form.dstCurrency?.symbol === TLOS_SYMBOL && this.form.dstChainId === ChainId.TELOS } get srcContractInstance(): Contract | undefined { @@ -570,7 +572,6 @@ export class BridgeStore { } } setDstCurrency(currency: Currency) { - debugger; this.form.dstCurrency = currency; this.form.dstChainId = currency.chainId; } @@ -625,7 +626,8 @@ export class BridgeStore { assert(transferApi, 'transferApi'); let isRegistered = false; - if (!(dstCurrency.symbol === "TLOS") && !(dstChainId === ChainId.TELOS)){ + + if (!(dstCurrency.symbol === "TLOS" && dstChainId === ChainId.TELOS)){ assert(registerApi, 'registerApi'); // try to register if possible, exclude registration when src or dst is native OFT @@ -682,7 +684,7 @@ export class BridgeStore { this.isMining = false; // exclude registration when src or dst is native OFT - if (!this.isTelos && !(dstChainId === ChainId.TELOS && dstCurrency.symbol === 'TLOS') && !isRegistered) { + if (!this.srcIsNativeTelos && !this.dstIsNativeTelos && !isRegistered) { uiStore.claimReminderAlert.open(); } @@ -1034,7 +1036,7 @@ export class BridgeStore { const {amount, transferApi} = this; if (!amount) return; if (!dstCurrency) return; - if(this.isTelos){ + if(this.srcIsNativeTelos){ yield (this.promise.output = { amount, @@ -1052,8 +1054,6 @@ export class BridgeStore { }); updateMessageFee = flow(function* (this: BridgeStore) { - debugger; - this.promise.messageFee = undefined; const {srcCurrency, dstCurrency} = this.form; @@ -1068,7 +1068,7 @@ export class BridgeStore { // // The user will be refunded so this increase does not affect the actual price const multiplier = new Fraction(110, 100); - if (this.isTelos && srcBridgeContractInstance){ + if (this.srcIsNativeTelos && srcBridgeContractInstance){ const args: [ChainId, boolean, string] = [dstCurrency.chainId, false, serializeAdapterParams(adapterParams)]; const nativeCurrency = getNativeCurrency(ChainId.TELOS); @@ -1079,9 +1079,6 @@ export class BridgeStore { })) ); }else if (transferApi){ - debugger; - const test = yield transferApi.getMessageFee(srcCurrency, dstCurrency, adapterParams); - debugger; yield (this.promise.messageFee = fromPromise( transferApi.getMessageFee(srcCurrency, dstCurrency, adapterParams).then((fee) => ({ nativeFee: fee.nativeFee.multiply(multiplier), From a692353ebd9d20571971843a9875df3aee3e8ed6 Mon Sep 17 00:00:00 2001 From: donnyquixotic Date: Thu, 1 Feb 2024 16:45:03 -0600 Subject: [PATCH 03/25] fix: regitster api for dst telos OFT --- src/features/bridge/stores/bridgeStore.tsx | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/features/bridge/stores/bridgeStore.tsx b/src/features/bridge/stores/bridgeStore.tsx index d6d1bb3..3f51969 100644 --- a/src/features/bridge/stores/bridgeStore.tsx +++ b/src/features/bridge/stores/bridgeStore.tsx @@ -138,19 +138,21 @@ export class BridgeStore { if (!srcCurrency) return undefined; if (!dstCurrency) return undefined; - function findTelosOftTransferApi(api: any ): boolean { - return api.config.proxy.some((p: ProxyConfig) => p.address === telosNativeOft.proxy.address); + if (this.dstIsNativeTelos){ + return this.apis.find(this.findTelosOftTransferApi); } - if (dstCurrency.chainId === ChainId.TELOS && dstCurrency.symbol === "TLOS"){ - return this.apis.find(findTelosOftTransferApi); - } return this.apis.find((s) => s.supportsTransfer(srcCurrency, dstCurrency)); } get registerApi(): BridgeApi | undefined { const {dstCurrency} = this.form; if (!dstCurrency) return undefined; + + if (this.dstIsNativeTelos){ + return this.apis.find(this.findTelosOftTransferApi); + } + return this.apis.find((s) => s.supportsRegister(dstCurrency)); } @@ -490,6 +492,10 @@ export class BridgeStore { // actions + findTelosOftTransferApi(api: any ): boolean { + return api.config.proxy.some((p: ProxyConfig) => p.address === telosNativeOft.proxy.address); + } + async updateAllowance(): Promise { this.promise.allowance = undefined; const {transferApi, srcAddress} = this; @@ -627,7 +633,7 @@ export class BridgeStore { let isRegistered = false; - if (!(dstCurrency.symbol === "TLOS" && dstChainId === ChainId.TELOS)){ + if (!this.srcIsNativeTelos){ assert(registerApi, 'registerApi'); // try to register if possible, exclude registration when src or dst is native OFT @@ -684,7 +690,7 @@ export class BridgeStore { this.isMining = false; // exclude registration when src or dst is native OFT - if (!this.srcIsNativeTelos && !this.dstIsNativeTelos && !isRegistered) { + if (/*!this.srcIsNativeTelos */ !isRegistered) { uiStore.claimReminderAlert.open(); } From 6aadf4f8d56e7ee30de87e1bddbf018361e56fa0 Mon Sep 17 00:00:00 2001 From: donnyquixotic Date: Thu, 1 Feb 2024 17:28:40 -0600 Subject: [PATCH 04/25] feat: native OFT to dst fix: restore oft abi --- src/abi/oftAbi.js | 1425 ++++++++++++++++++++ src/features/bridge/stores/bridgeStore.tsx | 244 +--- 2 files changed, 1469 insertions(+), 200 deletions(-) diff --git a/src/abi/oftAbi.js b/src/abi/oftAbi.js index e69de29..1e7e291 100644 --- a/src/abi/oftAbi.js +++ b/src/abi/oftAbi.js @@ -0,0 +1,1425 @@ +// OFT abi used for TLOS OFT transfers +export const oftAbi = [ + { + "inputs": [ + { + "internalType": "address", + "name": "_layerZeroEndpoint", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_initialSupply", + "type": "uint256" + }, + { + "internalType": "uint8", + "name": "_sharedDecimals", + "type": "uint8" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint16", + "name": "_srcChainId", + "type": "uint16" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "_srcAddress", + "type": "bytes" + }, + { + "indexed": false, + "internalType": "uint64", + "name": "_nonce", + "type": "uint64" + }, + { + "indexed": false, + "internalType": "bytes32", + "name": "_hash", + "type": "bytes32" + } + ], + "name": "CallOFTReceivedSuccess", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint16", + "name": "_srcChainId", + "type": "uint16" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "_srcAddress", + "type": "bytes" + }, + { + "indexed": false, + "internalType": "uint64", + "name": "_nonce", + "type": "uint64" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "_payload", + "type": "bytes" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "_reason", + "type": "bytes" + } + ], + "name": "MessageFailed", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "_address", + "type": "address" + } + ], + "name": "NonContractAddress", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint16", + "name": "_srcChainId", + "type": "uint16" + }, + { + "indexed": true, + "internalType": "address", + "name": "_to", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + } + ], + "name": "ReceiveFromChain", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint16", + "name": "_srcChainId", + "type": "uint16" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "_srcAddress", + "type": "bytes" + }, + { + "indexed": false, + "internalType": "uint64", + "name": "_nonce", + "type": "uint64" + }, + { + "indexed": false, + "internalType": "bytes32", + "name": "_payloadHash", + "type": "bytes32" + } + ], + "name": "RetryMessageSuccess", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint16", + "name": "_dstChainId", + "type": "uint16" + }, + { + "indexed": true, + "internalType": "address", + "name": "_from", + "type": "address" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "_toAddress", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + } + ], + "name": "SendToChain", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint16", + "name": "_dstChainId", + "type": "uint16" + }, + { + "indexed": false, + "internalType": "uint16", + "name": "_type", + "type": "uint16" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "_minDstGas", + "type": "uint256" + } + ], + "name": "SetMinDstGas", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "precrime", + "type": "address" + } + ], + "name": "SetPrecrime", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint16", + "name": "_remoteChainId", + "type": "uint16" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "_path", + "type": "bytes" + } + ], + "name": "SetTrustedRemote", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint16", + "name": "_remoteChainId", + "type": "uint16" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "_remoteAddress", + "type": "bytes" + } + ], + "name": "SetTrustedRemoteAddress", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "inputs": [], + "name": "DEFAULT_PAYLOAD_SIZE_LIMIT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "NO_EXTRA_GAS", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "PT_SEND", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "PT_SEND_AND_CALL", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "internalType": "address", + "name": "spender", + "type": "address" + } + ], + "name": "allowance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "approve", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "balanceOf", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "_srcChainId", + "type": "uint16" + }, + { + "internalType": "bytes", + "name": "_srcAddress", + "type": "bytes" + }, + { + "internalType": "uint64", + "name": "_nonce", + "type": "uint64" + }, + { + "internalType": "bytes32", + "name": "_from", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "_to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "_payload", + "type": "bytes" + }, + { + "internalType": "uint256", + "name": "_gasForCall", + "type": "uint256" + } + ], + "name": "callOnOFTReceived", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "circulatingSupply", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "", + "type": "uint16" + }, + { + "internalType": "bytes", + "name": "", + "type": "bytes" + }, + { + "internalType": "uint64", + "name": "", + "type": "uint64" + } + ], + "name": "creditedPackets", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "decimals", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "subtractedValue", + "type": "uint256" + } + ], + "name": "decreaseAllowance", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "_dstChainId", + "type": "uint16" + }, + { + "internalType": "bytes32", + "name": "_toAddress", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "_payload", + "type": "bytes" + }, + { + "internalType": "uint64", + "name": "_dstGasForCall", + "type": "uint64" + }, + { + "internalType": "bool", + "name": "_useZro", + "type": "bool" + }, + { + "internalType": "bytes", + "name": "_adapterParams", + "type": "bytes" + } + ], + "name": "estimateSendAndCallFee", + "outputs": [ + { + "internalType": "uint256", + "name": "nativeFee", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "zroFee", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "_dstChainId", + "type": "uint16" + }, + { + "internalType": "bytes32", + "name": "_toAddress", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "_useZro", + "type": "bool" + }, + { + "internalType": "bytes", + "name": "_adapterParams", + "type": "bytes" + } + ], + "name": "estimateSendFee", + "outputs": [ + { + "internalType": "uint256", + "name": "nativeFee", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "zroFee", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "", + "type": "uint16" + }, + { + "internalType": "bytes", + "name": "", + "type": "bytes" + }, + { + "internalType": "uint64", + "name": "", + "type": "uint64" + } + ], + "name": "failedMessages", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "_srcChainId", + "type": "uint16" + }, + { + "internalType": "bytes", + "name": "_srcAddress", + "type": "bytes" + } + ], + "name": "forceResumeReceive", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "_version", + "type": "uint16" + }, + { + "internalType": "uint16", + "name": "_chainId", + "type": "uint16" + }, + { + "internalType": "address", + "name": "", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_configType", + "type": "uint256" + } + ], + "name": "getConfig", + "outputs": [ + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "_remoteChainId", + "type": "uint16" + } + ], + "name": "getTrustedRemoteAddress", + "outputs": [ + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "addedValue", + "type": "uint256" + } + ], + "name": "increaseAllowance", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "_srcChainId", + "type": "uint16" + }, + { + "internalType": "bytes", + "name": "_srcAddress", + "type": "bytes" + } + ], + "name": "isTrustedRemote", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "lzEndpoint", + "outputs": [ + { + "internalType": "contract ILayerZeroEndpoint", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "_srcChainId", + "type": "uint16" + }, + { + "internalType": "bytes", + "name": "_srcAddress", + "type": "bytes" + }, + { + "internalType": "uint64", + "name": "_nonce", + "type": "uint64" + }, + { + "internalType": "bytes", + "name": "_payload", + "type": "bytes" + } + ], + "name": "lzReceive", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "", + "type": "uint16" + }, + { + "internalType": "uint16", + "name": "", + "type": "uint16" + } + ], + "name": "minDstGasLookup", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "name", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "_srcChainId", + "type": "uint16" + }, + { + "internalType": "bytes", + "name": "_srcAddress", + "type": "bytes" + }, + { + "internalType": "uint64", + "name": "_nonce", + "type": "uint64" + }, + { + "internalType": "bytes", + "name": "_payload", + "type": "bytes" + } + ], + "name": "nonblockingLzReceive", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "", + "type": "uint16" + } + ], + "name": "payloadSizeLimitLookup", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "precrime", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "renounceOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "_srcChainId", + "type": "uint16" + }, + { + "internalType": "bytes", + "name": "_srcAddress", + "type": "bytes" + }, + { + "internalType": "uint64", + "name": "_nonce", + "type": "uint64" + }, + { + "internalType": "bytes", + "name": "_payload", + "type": "bytes" + } + ], + "name": "retryMessage", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_from", + "type": "address" + }, + { + "internalType": "uint16", + "name": "_dstChainId", + "type": "uint16" + }, + { + "internalType": "bytes32", + "name": "_toAddress", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "_payload", + "type": "bytes" + }, + { + "internalType": "uint64", + "name": "_dstGasForCall", + "type": "uint64" + }, + { + "components": [ + { + "internalType": "address payable", + "name": "refundAddress", + "type": "address" + }, + { + "internalType": "address", + "name": "zroPaymentAddress", + "type": "address" + }, + { + "internalType": "bytes", + "name": "adapterParams", + "type": "bytes" + } + ], + "internalType": "struct ICommonOFT.LzCallParams", + "name": "_callParams", + "type": "tuple" + } + ], + "name": "sendAndCall", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_from", + "type": "address" + }, + { + "internalType": "uint16", + "name": "_dstChainId", + "type": "uint16" + }, + { + "internalType": "bytes32", + "name": "_toAddress", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + }, + { + "components": [ + { + "internalType": "address payable", + "name": "refundAddress", + "type": "address" + }, + { + "internalType": "address", + "name": "zroPaymentAddress", + "type": "address" + }, + { + "internalType": "bytes", + "name": "adapterParams", + "type": "bytes" + } + ], + "internalType": "struct ICommonOFT.LzCallParams", + "name": "_callParams", + "type": "tuple" + } + ], + "name": "sendFrom", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "_version", + "type": "uint16" + }, + { + "internalType": "uint16", + "name": "_chainId", + "type": "uint16" + }, + { + "internalType": "uint256", + "name": "_configType", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "_config", + "type": "bytes" + } + ], + "name": "setConfig", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "_dstChainId", + "type": "uint16" + }, + { + "internalType": "uint16", + "name": "_packetType", + "type": "uint16" + }, + { + "internalType": "uint256", + "name": "_minGas", + "type": "uint256" + } + ], + "name": "setMinDstGas", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "_dstChainId", + "type": "uint16" + }, + { + "internalType": "uint256", + "name": "_size", + "type": "uint256" + } + ], + "name": "setPayloadSizeLimit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_precrime", + "type": "address" + } + ], + "name": "setPrecrime", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "_version", + "type": "uint16" + } + ], + "name": "setReceiveVersion", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "_version", + "type": "uint16" + } + ], + "name": "setSendVersion", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "_remoteChainId", + "type": "uint16" + }, + { + "internalType": "bytes", + "name": "_path", + "type": "bytes" + } + ], + "name": "setTrustedRemote", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "_remoteChainId", + "type": "uint16" + }, + { + "internalType": "bytes", + "name": "_remoteAddress", + "type": "bytes" + } + ], + "name": "setTrustedRemoteAddress", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "sharedDecimals", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes4", + "name": "interfaceId", + "type": "bytes4" + } + ], + "name": "supportsInterface", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "symbol", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "token", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalSupply", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "transfer", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "transferFrom", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "", + "type": "uint16" + } + ], + "name": "trustedRemoteLookup", + "outputs": [ + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "stateMutability": "view", + "type": "function" + } +] \ No newline at end of file diff --git a/src/features/bridge/stores/bridgeStore.tsx b/src/features/bridge/stores/bridgeStore.tsx index 3f51969..02ee936 100644 --- a/src/features/bridge/stores/bridgeStore.tsx +++ b/src/features/bridge/stores/bridgeStore.tsx @@ -138,6 +138,7 @@ export class BridgeStore { if (!srcCurrency) return undefined; if (!dstCurrency) return undefined; + // use TLOS OFT api when destination currency is native TLOS if (this.dstIsNativeTelos){ return this.apis.find(this.findTelosOftTransferApi); } @@ -149,6 +150,7 @@ export class BridgeStore { const {dstCurrency} = this.form; if (!dstCurrency) return undefined; + // use TLOS OFT api when destination currency is native TLOS if (this.dstIsNativeTelos){ return this.apis.find(this.findTelosOftTransferApi); } @@ -476,13 +478,12 @@ export class BridgeStore { get srcContractInstance(): Contract | undefined { const wallet = walletStore.evm; - // only entry is - const proxyAddress = telosNativeOft.proxy.address as string; + // use default provider if signer not available const provider = telosNativeOft.bridge.chainListId === wallet?.nativeChainId ? wallet?.signer : ethers.getDefaultProvider(telosNativeOft.bridge.rpc); - return new ethers.Contract(proxyAddress, oftAbi, provider) + return new ethers.Contract(telosNativeOft.proxy.address, oftAbi, provider) } get srcBridgeContractInstance(): Contract | undefined { @@ -629,7 +630,6 @@ export class BridgeStore { assert(srcWallet?.address, 'srcWallet'); assert(dstWallet?.address, 'dstWallet'); assert(dstNativeBalance, 'dstNativeBalance'); - assert(transferApi, 'transferApi'); let isRegistered = false; @@ -653,7 +653,7 @@ export class BridgeStore { } } - if (!this.isApproved) { + if (!this.srcIsNativeTelos && !this.isApproved) { yield this.approve(); } @@ -673,46 +673,59 @@ export class BridgeStore { yield srcWallet.switchChain(srcChainId); this.isSigning = true; - const unsignedTransaction: Awaited> = - yield transferApi.transfer(input); - // ensure correct wallet - yield assertWallet(srcWallet, {chainId: srcChainId, address: srcAddress}); + let transactionResult: any = {}; - const transactionResult: Awaited< - ReturnType - > = yield unsignedTransaction.signAndSubmitTransaction(srcWallet.signer); + if (this.srcIsNativeTelos){ + transactionResult = yield this.sendNative(); + // ensure correct wallet + yield assertWallet(srcWallet, {chainId: srcChainId, address: srcAddress}); - this.isSigning = false; - this.isMining = true; - const receipt: Awaited> = - yield transactionResult.wait(); - this.isMining = false; + this.isSigning = false; + this.isMining = true; + transactionResult.wait(); + + }else if(transferApi){ + const unsignedTransaction: Awaited> = + yield transferApi.transfer(input); - // exclude registration when src or dst is native OFT - if (/*!this.srcIsNativeTelos */ !isRegistered) { + // ensure correct wallet + yield assertWallet(srcWallet, {chainId: srcChainId, address: srcAddress}); + + const transaction: Awaited< + ReturnType + > = yield unsignedTransaction.signAndSubmitTransaction(srcWallet.signer); + this.isSigning = false; + this.isMining = true; + const receipt: Awaited> = yield transaction.wait(); + this.isMining = false; + transactionResult.hash = receipt.txHash; + } + if (!isRegistered) { uiStore.claimReminderAlert.open(); } - const tx = transactionStore.create({ - chainId: srcChainId, - txHash: receipt.txHash, - type: 'TRANSFER', - input, - expectedDate: getExpectedDate(srcChainId, dstChainId), - }); - this.updateBalances(); toast.success(

Transaction Submitted

- + View on block explorer

, ); - waitForMessageReceived(srcChainId, receipt.txHash) + + const tx = transactionStore.create({ + chainId: srcChainId, + txHash: transactionResult.hash, + type: 'TRANSFER', + input, + expectedDate: getExpectedDate(srcChainId, dstChainId), + }); + // this.updateBalances(); + + waitForMessageReceived(srcChainId, transactionResult.hash) .then((message) => { // never mark tx as failed // we will eventually deliver the tx @@ -748,173 +761,6 @@ export class BridgeStore { } }); - // transfer = flow(function* (this: BridgeStore) { - // try { - // this.isExecuting = true; - - // const { - // form, - // srcWallet, - // dstWallet, - // messageFee: fee, - // amount, - // minAmount, - // srcAddress, - // dstAddress, - // adapterParams, - // outputAmount, - // dstNativeBalance, - // transferApi, - // registerApi, - // } = this; - // const {srcChainId, dstChainId, dstCurrency, srcCurrency} = form; - - // assert(srcChainId, 'srcChainId'); - // assert(dstChainId, 'dstChainId'); - // assert(srcCurrency, 'srcCurrency'); - // assert(dstCurrency, 'dstCurrency'); - // assert(srcAddress, 'srcAddress'); - // assert(dstAddress, 'dstAddress'); - // assert(fee, 'fee'); - // assert(amount, 'amount'); - // assert(minAmount, 'minAmount'); - // assert(adapterParams, 'adapterParams'); - // assert(outputAmount, 'outputAmount'); - // assert(srcWallet?.address, 'srcWallet'); - // assert(dstWallet?.address, 'dstWallet'); - // assert(dstNativeBalance, 'dstNativeBalance'); - - // let isRegistered = false; - - // if (!this.isTelos){ - // assert(transferApi, 'transferApi'); - // assert(registerApi, 'registerApi'); - - // // try to register if possible - // isRegistered = yield registerApi.isRegistered(dstCurrency, dstWallet.address); - // if (!isRegistered) { - // const unsignedTransaction: Awaited> = - // yield registerApi.register(dstCurrency); - - // const estimatedGasAmount: Awaited< - // ReturnType - // > = yield unsignedTransaction.estimateNative(dstWallet); - - // if (dstNativeBalance.greaterThan(estimatedGasAmount)) { - // yield this.register(); - // isRegistered = true; - // } - // } - - // if (!this.isApproved) { - // yield this.approve(); - // } - // } - - // const input: TransferInput = { - // srcChainId, - // dstChainId, - // srcCurrency, - // dstCurrency, - // srcAddress, - // dstAddress, - // amount, - // minAmount, - // fee, - // adapterParams, - // }; - - // yield srcWallet.switchChain(srcChainId); - // this.isSigning = true; - - // let transactionResult: any; - - // if (this.isTelos){ - // transactionResult = yield this.sendNative(); - // // ensure correct wallet - // yield assertWallet(srcWallet, {chainId: srcChainId, address: srcAddress}); - - // this.isSigning = false; - // this.isMining = true; - // transactionResult.wait(); - - // }else if(transferApi){ - // const unsignedTransaction: Awaited> = - // yield transferApi.transfer(input); - - // // ensure correct wallet - // yield assertWallet(srcWallet, {chainId: srcChainId, address: srcAddress}); - - // const transaction: Awaited< - // ReturnType - // > = yield unsignedTransaction.signAndSubmitTransaction(srcWallet.signer); - // this.isSigning = false; - // this.isMining = true; - // const receipt: Awaited> = yield transaction.wait(); - // this.isMining = false; - // transactionResult.hash = receipt.txHash; - // } - - // if (!this.isTelos && !isRegistered) { - // uiStore.claimReminderAlert.open(); - // } - - // toast.success( - // - //

Transaction Submitted

- //

- // - // View on block explorer - // - //

- //
, - // ); - - // const tx = transactionStore.create({ - // chainId: srcChainId, - // txHash: transactionResult.hash, - // type: 'TRANSFER', - // input, - // expectedDate: getExpectedDate(srcChainId, dstChainId), - // }); - // // this.updateBalances(); - - // waitForMessageReceived(srcChainId, transactionResult.hash) - // .then((message) => { - // // never mark tx as failed - // // we will eventually deliver the tx - // tx.update({ - // completed: true, - // confirmation: { - // chainId: message.dstChainId, - // txHash: message.dstTxHash, - // }, - // }); - // if (isAptosChainId(dstChainId)) { - // unclaimedStore.updateUnclaimedBalance(dstCurrency, dstAddress); - // } - // }) - // .finally(() => { - // this.updateBalances(); - // }); - // } catch (e) { - // handleError(e, () => { - // const {message, title} = parseWalletError(e); - // toast.error( - // - //

{title}

- //

{message}

- //
, - // ); - // }); - // throw e; - // } finally { - // this.isSigning = false; - // this.isMining = false; - // this.isExecuting = false; - // } - // }); - sendNative: () => unknown = flow(function* (this: BridgeStore) { const {srcCurrency, srcChainId, dstChainId, amount} = this.form; @@ -1069,10 +915,8 @@ export class BridgeStore { if (!dstCurrency) return; if (!adapterParams) return; - // We want to introduce a buffer to avoid any gas price fluctuations - // to affect the user experience - // - // The user will be refunded so this increase does not affect the actual price + // introduce buffer to avoid any gas price fluctuations that may affect user expereience + // increase does not affect the actual price const multiplier = new Fraction(110, 100); if (this.srcIsNativeTelos && srcBridgeContractInstance){ const args: [ChainId, boolean, string] = [dstCurrency.chainId, false, serializeAdapterParams(adapterParams)]; From 7ab2f4a9af18fab3ac378311f45de9fdc823b62b Mon Sep 17 00:00:00 2001 From: donnyquixotic Date: Thu, 1 Feb 2024 17:31:27 -0600 Subject: [PATCH 05/25] refactor: remove unused method style: lint imports --- src/features/bridge/stores/bridgeStore.tsx | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/src/features/bridge/stores/bridgeStore.tsx b/src/features/bridge/stores/bridgeStore.tsx index 02ee936..d69ab2c 100644 --- a/src/features/bridge/stores/bridgeStore.tsx +++ b/src/features/bridge/stores/bridgeStore.tsx @@ -25,7 +25,7 @@ import { import {ONE_ADDRESS, serializeAdapterParams} from '@layerzerolabs/ui-evm'; import {assertWallet, Wallet} from '@layerzerolabs/ui-wallet'; import assert from 'assert'; -import { Contract,Signer,ethers } from 'ethers'; +import { Contract,ethers } from 'ethers'; import {autorun, computed, flow, makeAutoObservable} from 'mobx'; import {fromPromise} from 'mobx-utils'; import {toast} from 'react-toastify'; @@ -1021,19 +1021,6 @@ function toBridgeFee(fees: AnyFee): BridgeFee { return fees; } -function isDstCurrencyValid(dstCurrency: Currency) { - const {srcChainId, srcCurrency} = bridgeStore.form; - if (!srcChainId) return true; - // both can't be aptos - if (isAptosChainId(srcChainId) && isAptosChainId(dstCurrency.chainId)) return false; - // one has to be aptos - if (!isAptosChainId(srcChainId) && !isAptosChainId(dstCurrency.chainId)) return false; - if (srcCurrency) { - return isValidPair(srcCurrency, dstCurrency); - } - return true; -} - export type CurrencyOption = { currency: Currency; disabled?: boolean; From b575bba58ef8c3431d263550464605b7b20f9f2f Mon Sep 17 00:00:00 2001 From: donnyquixotic Date: Thu, 1 Feb 2024 18:24:30 -0600 Subject: [PATCH 06/25] fix: include registration for source native OFT --- src/features/bridge/stores/bridgeStore.tsx | 48 ++++++++-------------- 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/src/features/bridge/stores/bridgeStore.tsx b/src/features/bridge/stores/bridgeStore.tsx index d69ab2c..2ee6af9 100644 --- a/src/features/bridge/stores/bridgeStore.tsx +++ b/src/features/bridge/stores/bridgeStore.tsx @@ -55,7 +55,6 @@ export type ValidationError = string; const TLOS_SYMBOL = 'TLOS'; export class BridgeStore { - // isLoading = false; isSigning = false; isMining = false; @@ -71,11 +70,10 @@ export class BridgeStore { amount: '', dstNativeAmount: DstNativeAmount.DEFAULT, }; - // + apis: BridgeApi[] = []; currencies: Currency[] = []; - // promise: BridgePromise = { output: undefined, allowance: undefined, @@ -512,10 +510,6 @@ export class BridgeStore { setAmount(amount: string) { if (tryParseNumber(amount) !== undefined) { this.form.amount = amount; - // if (this.isTelos){ - // this.updateOutput(); - // this.updateMessageFee(); - // } } } @@ -590,9 +584,6 @@ export class BridgeStore { form.dstCurrency, form.srcCurrency, ]; - // if (this.isTelos){ - // this.setDstNativeAmount('0'); - // } } transfer = flow(function* (this: BridgeStore) { @@ -629,27 +620,21 @@ export class BridgeStore { assert(outputAmount, 'outputAmount'); assert(srcWallet?.address, 'srcWallet'); assert(dstWallet?.address, 'dstWallet'); - assert(dstNativeBalance, 'dstNativeBalance'); - - let isRegistered = false; - - if (!this.srcIsNativeTelos){ - assert(registerApi, 'registerApi'); - - // try to register if possible, exclude registration when src or dst is native OFT - isRegistered = yield registerApi.isRegistered(dstCurrency, dstWallet.address); - if (!isRegistered) { - const unsignedTransaction: Awaited> = - yield registerApi.register(dstCurrency); - - const estimatedGasAmount: Awaited< - ReturnType - > = yield unsignedTransaction.estimateNative(dstWallet); - - if (dstNativeBalance.greaterThan(estimatedGasAmount)) { - yield this.register(); - isRegistered = true; - } + assert(dstNativeBalance, 'dstNativeBalance'); + assert(registerApi, 'registerApi'); + + // try to register if possible + let isRegistered = yield registerApi.isRegistered(dstCurrency, dstWallet.address); + if (!isRegistered) { + const unsignedTransaction: Awaited> = + yield registerApi.register(dstCurrency); + + const estimatedGasAmount: Awaited> = + yield unsignedTransaction.estimateNative(dstWallet); + + if (dstNativeBalance.greaterThan(estimatedGasAmount)) { + yield this.register(); + isRegistered = true; } } @@ -723,7 +708,6 @@ export class BridgeStore { input, expectedDate: getExpectedDate(srcChainId, dstChainId), }); - // this.updateBalances(); waitForMessageReceived(srcChainId, transactionResult.hash) .then((message) => { From 9c6ae5065c021880e09c3b64823ee571d94d00f7 Mon Sep 17 00:00:00 2001 From: donnyquixotic Date: Thu, 1 Feb 2024 23:39:56 -0600 Subject: [PATCH 07/25] fix: token order --- src/bootstrap.ts | 16 ++++--- src/config.ts | 2 +- .../bridge/hooks/useDefaultSrcCurrency.ts | 48 ++++++++++++------- src/features/bridge/stores/bridgeStore.tsx | 22 +++++---- src/features/bridge/ui/CurrencySelect.tsx | 13 ++++- src/features/core/stores/fiatStore.tsx | 18 +++++++ 6 files changed, 84 insertions(+), 35 deletions(-) diff --git a/src/bootstrap.ts b/src/bootstrap.ts index a9c0b8a..5f2147e 100644 --- a/src/bootstrap.ts +++ b/src/bootstrap.ts @@ -69,7 +69,7 @@ import {walletStore} from '@/core/stores/walletStore'; import {onftStore} from '@/onft/stores/onftStore'; import {initOnftStore} from '@/onft/stores/onftStore'; -import { telosNativeOft } from './config'; +import { TLOS, telosNativeOft } from './config'; export async function bootstrap(lzAppConfig: AppConfig, providerFactory: ProviderFactory) { const aptos = { @@ -140,14 +140,18 @@ export async function bootstrap(lzAppConfig: AppConfig, providerFactory: Provide } } + // add OFT tokens for (const oftConfig of lzAppConfig.bridge.oft) { - addEvmOft(oftConfig); - addAptosOft(oftConfig); - bridgeStore.addCurrencies(oftConfig.tokens); + addEvmOft(oftConfig); + addAptosOft(oftConfig); + bridgeStore.addCurrencies(oftConfig.tokens); } - // Add Native TLOS OFT + // add Telos Native for OFT bridge bridgeStore.addCurrencies([telosNativeOft.token]) + + // add wrapped assets + bridgeStore.addCurrencies(currencies); // WrappedAssetBridge // https://github.com/LayerZero-Labs/wrapped-asset-bridge @@ -216,8 +220,6 @@ export async function bootstrap(lzAppConfig: AppConfig, providerFactory: Provide } } - bridgeStore.addCurrencies(currencies); - tokenStore.addProviders([ // new TokenListProvider(), diff --git a/src/config.ts b/src/config.ts index f9dd602..07562c5 100644 --- a/src/config.ts +++ b/src/config.ts @@ -232,7 +232,7 @@ const RF = { sharedDecimals: 4, } -const TLOS = { +export const TLOS = { version: 2, tokens: [ new Token(ChainId.ARBITRUM, '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E', 18, 'TLOS'), diff --git a/src/features/bridge/hooks/useDefaultSrcCurrency.ts b/src/features/bridge/hooks/useDefaultSrcCurrency.ts index 702844a..ab760fb 100644 --- a/src/features/bridge/hooks/useDefaultSrcCurrency.ts +++ b/src/features/bridge/hooks/useDefaultSrcCurrency.ts @@ -1,11 +1,12 @@ +import {ChainId} from '@layerzerolabs/lz-sdk'; import {chainKeyToEndpointId} from '@layerzerolabs/ui-core'; -import {maxBy} from 'lodash-es'; import {useEffect} from 'react'; -import {bridgeStore} from '@/bridge/stores/bridgeStore'; +import {bridgeStore,CurrencyOption, TLOS_SYMBOL} from '@/bridge/stores/bridgeStore'; import {balanceStore} from '@/core/stores/balanceStore'; import {walletStore} from '@/core/stores/walletStore'; + export function useDefaultSrcCurrency() { const {address, chainKey} = walletStore.evm ?? {}; const {form} = bridgeStore; @@ -27,6 +28,31 @@ export function useDefaultSrcCurrency() { // eslint-disable-next-line react-hooks/exhaustive-deps }, [address, srcChainId]); + // useEffect(() => { + // if (!isReady) return; + // if (!address) return; + // if (!form.srcChainId) return; + // if (form.srcCurrency) return; + // if (form.dstCurrency) return; + // const {srcCurrencyOptions} = bridgeStore; + // const balances = srcCurrencyOptions + // .filter((o) => o.currency.chainId === srcChainId) + // .map(({currency}) => balanceStore.getBalance(currency, address)) + // .flatMap((balance) => (balance ? [balance] : [])); + + // const maxBalance = maxBy(balances, (b) => { + // try { + // return parseFloat(b.toExact()); + // } catch { + // return 0; + // } + // }); + // if (maxBalance) { + // bridgeStore.setSrcCurrency(maxBalance.currency); + // } + // /* eslint-disable-next-line react-hooks/exhaustive-deps */ + // }, [address, form.srcChainId, srcChainId, isReady]); + useEffect(() => { if (!isReady) return; if (!address) return; @@ -34,20 +60,10 @@ export function useDefaultSrcCurrency() { if (form.srcCurrency) return; if (form.dstCurrency) return; const {srcCurrencyOptions} = bridgeStore; - const balances = srcCurrencyOptions - .filter((o) => o.currency.chainId === srcChainId) - .map(({currency}) => balanceStore.getBalance(currency, address)) - .flatMap((balance) => (balance ? [balance] : [])); - - const maxBalance = maxBy(balances, (b) => { - try { - return parseFloat(b.toExact()); - } catch { - return 0; - } - }); - if (maxBalance) { - bridgeStore.setSrcCurrency(maxBalance.currency); + // set default Native TLOS as default + const telosNative = srcCurrencyOptions.find((option: CurrencyOption) => option.currency.chainId === ChainId.TELOS && option.currency.symbol === TLOS_SYMBOL) + if (telosNative) { + bridgeStore.setSrcCurrency(telosNative.currency); } /* eslint-disable-next-line react-hooks/exhaustive-deps */ }, [address, form.srcChainId, srcChainId, isReady]); diff --git a/src/features/bridge/stores/bridgeStore.tsx b/src/features/bridge/stores/bridgeStore.tsx index 2ee6af9..bb0e72f 100644 --- a/src/features/bridge/stores/bridgeStore.tsx +++ b/src/features/bridge/stores/bridgeStore.tsx @@ -53,7 +53,7 @@ export enum DstNativeAmount { } export type ValidationError = string; -const TLOS_SYMBOL = 'TLOS'; +export const TLOS_SYMBOL = 'TLOS'; export class BridgeStore { isLoading = false; isSigning = false; @@ -168,7 +168,7 @@ export class BridgeStore { } get srcCurrencyOptions(): CurrencyOption[] { - return this.currencies.map((currency) => { + const currencyOptions = this.currencies.map((currency) => { const disabled = false; const balance = getWalletBalance(currency); const isZero = !balance || balance?.equalTo(0); @@ -178,6 +178,8 @@ export class BridgeStore { overlay: disabled && !isZero ? 'Not available' : undefined, }; }); + + return currencyOptions; } get dstCurrencyOptions(): CurrencyOption[] { @@ -198,20 +200,22 @@ export class BridgeStore { get srcCurrencyOptionsGroups(): OptionGroup[] { const {srcChainId} = this.form; const {srcCurrencyOptions} = this; + const srcOptions = srcCurrencyOptions + .filter((o) => o.currency.chainId === srcChainId) + + const allOptions = srcCurrencyOptions + .filter((o) => o.currency.chainId !== srcChainId) + const src: OptionGroup = { title: tryGetNetwork(srcChainId)?.name + ' Network', key: 'src', - items: srcCurrencyOptions - // - .filter((o) => o.currency.chainId === srcChainId), + items: srcOptions, }; const all: OptionGroup = { title: 'All networks', key: 'all', - items: srcCurrencyOptions - // - .filter((o) => o.currency.chainId !== srcChainId), + items: allOptions, }; return [src, all].filter((g) => g.items.length > 0); @@ -489,8 +493,6 @@ export class BridgeStore { return new ethers.Contract(telosNativeOft.bridge.address, telosNativeOft.bridge.abi, provider) } - // actions - findTelosOftTransferApi(api: any ): boolean { return api.config.proxy.some((p: ProxyConfig) => p.address === telosNativeOft.proxy.address); } diff --git a/src/features/bridge/ui/CurrencySelect.tsx b/src/features/bridge/ui/CurrencySelect.tsx index 0c40156..7ff1c8f 100644 --- a/src/features/bridge/ui/CurrencySelect.tsx +++ b/src/features/bridge/ui/CurrencySelect.tsx @@ -2,7 +2,7 @@ import {Currency, getNetwork, isCurrency} from '@layerzerolabs/ui-core'; import {observer} from 'mobx-react'; import React, {useState} from 'react'; -import {CurrencyOption, OptionGroup} from '@/bridge/stores/bridgeStore'; +import {CurrencyOption, OptionGroup, TLOS_SYMBOL} from '@/bridge/stores/bridgeStore'; import {useToggle} from '@/core/hooks/useToggle'; import {fiatStore} from '@/core/stores/fiatStore'; import {getWalletBalance} from '@/core/stores/utils'; @@ -109,6 +109,7 @@ export const CurrencySelect: React.FC = observer( if (bBalance === undefined) bBalance = -1; return aBalance - bBalance; }) + .sort(sortTokens) .sort((a) => (a.option.disabled ? 1 : -1)); return ( @@ -176,6 +177,16 @@ function matchSearch(currency: Currency, query?: string) { return currency.symbol.toLowerCase().includes(text); } +type NestedCurrencyOption = { + option: CurrencyOption; +} +// sort TLOS tokens to top of list +function sortTokens(a:NestedCurrencyOption, b:NestedCurrencyOption){ + return (a.option.currency.symbol === TLOS_SYMBOL && b.option.currency.symbol !== TLOS_SYMBOL) ? 1 + : (a.option.currency.symbol !== TLOS_SYMBOL && b.option.currency.symbol === TLOS_SYMBOL ? -1 + : 0) +} + function toOption(option: CurrencyOption | Currency): CurrencyOption { if (isCurrency(option)) { return { diff --git a/src/features/core/stores/fiatStore.tsx b/src/features/core/stores/fiatStore.tsx index 652718f..ce8db2d 100644 --- a/src/features/core/stores/fiatStore.tsx +++ b/src/features/core/stores/fiatStore.tsx @@ -1,4 +1,5 @@ import {Currency, CurrencyAmount, FiatAmount} from '@layerzerolabs/ui-core'; +import axios from 'axios'; import {makeAutoObservable, ObservableMap} from 'mobx'; import {tokenStore} from './tokenStore'; @@ -90,3 +91,20 @@ export class FiatStore { } export const fiatStore = new FiatStore(); + +export interface PriceStats { + data: { + [tokenId: string]: { + usd: number; + }; + }; +} + +export const getTlosUsdPrice = async ( + ): Promise => { + const stats: PriceStats = await axios.get( + `https://api.coingecko.com/api/v3/simple/price?ids=telos&vs_currencies=USD` + ); + + return stats.data.telos.usd; + }; From 818a3f4e349666538846edb5434990a9e1a94b6f Mon Sep 17 00:00:00 2001 From: donnyquixotic Date: Thu, 1 Feb 2024 23:49:48 -0600 Subject: [PATCH 08/25] refactor: currency select filter, lint imports --- src/bootstrap.ts | 8 ++--- .../bridge/hooks/useDefaultSrcCurrency.ts | 31 ++++++++++--------- src/features/bridge/stores/bridgeStore.tsx | 11 ++----- 3 files changed, 23 insertions(+), 27 deletions(-) diff --git a/src/bootstrap.ts b/src/bootstrap.ts index 5f2147e..370f963 100644 --- a/src/bootstrap.ts +++ b/src/bootstrap.ts @@ -69,7 +69,7 @@ import {walletStore} from '@/core/stores/walletStore'; import {onftStore} from '@/onft/stores/onftStore'; import {initOnftStore} from '@/onft/stores/onftStore'; -import { TLOS, telosNativeOft } from './config'; +import { telosNativeOft } from './config'; export async function bootstrap(lzAppConfig: AppConfig, providerFactory: ProviderFactory) { const aptos = { @@ -142,9 +142,9 @@ export async function bootstrap(lzAppConfig: AppConfig, providerFactory: Provide // add OFT tokens for (const oftConfig of lzAppConfig.bridge.oft) { - addEvmOft(oftConfig); - addAptosOft(oftConfig); - bridgeStore.addCurrencies(oftConfig.tokens); + addEvmOft(oftConfig); + addAptosOft(oftConfig); + bridgeStore.addCurrencies(oftConfig.tokens); } // add Telos Native for OFT bridge diff --git a/src/features/bridge/hooks/useDefaultSrcCurrency.ts b/src/features/bridge/hooks/useDefaultSrcCurrency.ts index ab760fb..3433aa4 100644 --- a/src/features/bridge/hooks/useDefaultSrcCurrency.ts +++ b/src/features/bridge/hooks/useDefaultSrcCurrency.ts @@ -28,6 +28,22 @@ export function useDefaultSrcCurrency() { // eslint-disable-next-line react-hooks/exhaustive-deps }, [address, srcChainId]); + useEffect(() => { + if (!isReady) return; + if (!address) return; + if (!form.srcChainId) return; + if (form.srcCurrency) return; + if (form.dstCurrency) return; + const {srcCurrencyOptions} = bridgeStore; + // set default Native TLOS as default + const telosNative = srcCurrencyOptions.find((option: CurrencyOption) => option.currency.chainId === ChainId.TELOS && option.currency.symbol === TLOS_SYMBOL) + if (telosNative) { + bridgeStore.setSrcCurrency(telosNative.currency); + } + /* eslint-disable-next-line react-hooks/exhaustive-deps */ + }, [address, form.srcChainId, srcChainId, isReady]); + + /*** set max balance as default token ***/ // useEffect(() => { // if (!isReady) return; // if (!address) return; @@ -52,19 +68,4 @@ export function useDefaultSrcCurrency() { // } // /* eslint-disable-next-line react-hooks/exhaustive-deps */ // }, [address, form.srcChainId, srcChainId, isReady]); - - useEffect(() => { - if (!isReady) return; - if (!address) return; - if (!form.srcChainId) return; - if (form.srcCurrency) return; - if (form.dstCurrency) return; - const {srcCurrencyOptions} = bridgeStore; - // set default Native TLOS as default - const telosNative = srcCurrencyOptions.find((option: CurrencyOption) => option.currency.chainId === ChainId.TELOS && option.currency.symbol === TLOS_SYMBOL) - if (telosNative) { - bridgeStore.setSrcCurrency(telosNative.currency); - } - /* eslint-disable-next-line react-hooks/exhaustive-deps */ - }, [address, form.srcChainId, srcChainId, isReady]); } diff --git a/src/features/bridge/stores/bridgeStore.tsx b/src/features/bridge/stores/bridgeStore.tsx index bb0e72f..3f72fb6 100644 --- a/src/features/bridge/stores/bridgeStore.tsx +++ b/src/features/bridge/stores/bridgeStore.tsx @@ -200,22 +200,17 @@ export class BridgeStore { get srcCurrencyOptionsGroups(): OptionGroup[] { const {srcChainId} = this.form; const {srcCurrencyOptions} = this; - const srcOptions = srcCurrencyOptions - .filter((o) => o.currency.chainId === srcChainId) - - const allOptions = srcCurrencyOptions - .filter((o) => o.currency.chainId !== srcChainId) - + const src: OptionGroup = { title: tryGetNetwork(srcChainId)?.name + ' Network', key: 'src', - items: srcOptions, + items: srcCurrencyOptions.filter((o) => o.currency.chainId === srcChainId), }; const all: OptionGroup = { title: 'All networks', key: 'all', - items: allOptions, + items: srcCurrencyOptions.filter((o) => o.currency.chainId !== srcChainId), }; return [src, all].filter((g) => g.items.length > 0); From ded56f415e18d65632d2bc416ffad02f22d7085f Mon Sep 17 00:00:00 2001 From: donnyquixotic Date: Fri, 2 Feb 2024 00:29:27 -0600 Subject: [PATCH 09/25] feat: add fiat price for native TLOS & OFT --- src/bootstrap.ts | 1 - .../bridge/hooks/useDefaultSrcCurrency.ts | 4 ++++ src/features/core/stores/fiatStore.tsx | 17 ----------------- src/tokenList.ts | 8 ++++++++ 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/bootstrap.ts b/src/bootstrap.ts index 370f963..329c23e 100644 --- a/src/bootstrap.ts +++ b/src/bootstrap.ts @@ -221,7 +221,6 @@ export async function bootstrap(lzAppConfig: AppConfig, providerFactory: Provide } tokenStore.addProviders([ - // new TokenListProvider(), ]); diff --git a/src/features/bridge/hooks/useDefaultSrcCurrency.ts b/src/features/bridge/hooks/useDefaultSrcCurrency.ts index 3433aa4..d123983 100644 --- a/src/features/bridge/hooks/useDefaultSrcCurrency.ts +++ b/src/features/bridge/hooks/useDefaultSrcCurrency.ts @@ -35,9 +35,13 @@ export function useDefaultSrcCurrency() { if (form.srcCurrency) return; if (form.dstCurrency) return; const {srcCurrencyOptions} = bridgeStore; + // set default Native TLOS as default const telosNative = srcCurrencyOptions.find((option: CurrencyOption) => option.currency.chainId === ChainId.TELOS && option.currency.symbol === TLOS_SYMBOL) if (telosNative) { + if (srcChainId !== ChainId.TELOS){ + bridgeStore.setSrcChainId(ChainId.TELOS); + } bridgeStore.setSrcCurrency(telosNative.currency); } /* eslint-disable-next-line react-hooks/exhaustive-deps */ diff --git a/src/features/core/stores/fiatStore.tsx b/src/features/core/stores/fiatStore.tsx index ce8db2d..3f3bc7e 100644 --- a/src/features/core/stores/fiatStore.tsx +++ b/src/features/core/stores/fiatStore.tsx @@ -91,20 +91,3 @@ export class FiatStore { } export const fiatStore = new FiatStore(); - -export interface PriceStats { - data: { - [tokenId: string]: { - usd: number; - }; - }; -} - -export const getTlosUsdPrice = async ( - ): Promise => { - const stats: PriceStats = await axios.get( - `https://api.coingecko.com/api/v3/simple/price?ids=telos&vs_currencies=USD` - ); - - return stats.data.telos.usd; - }; diff --git a/src/tokenList.ts b/src/tokenList.ts index b03a997..1fbce68 100644 --- a/src/tokenList.ts +++ b/src/tokenList.ts @@ -1,6 +1,14 @@ import {TokenListItem} from '@layerzerolabs/ui-core'; export const tokenList = createTokenList([ + // TLOS + ['TLOS', 'TLOS', null, 18, 'telos', 4660, 'telos'], + ['TLOS', 'TLOS', '0x5Aa352551d39F5ce592260e0D26818e7d780867f', 18, 'ethereum', 4660, 'telos'], + ['TLOS', 'TLOS', '0x1cF0636abbc569fB413A20bd7964712e6b4d1161', 18, 'polygon', 4660, 'telos'], + ['TLOS', 'TLOS', '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E', 18, 'bsc', 4660, 'telos'], + ['TLOS', 'TLOS', '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E', 18, 'avalanche', 4660, 'telos'], + ['TLOS', 'TLOS', '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E', 18, 'arbitrum', 4660, 'telos'], + // USDC ['USDC', 'USDC', '0x8D97Cea50351Fb4329d591682b148D43a0C3611b', 6, 'telos', 3408, 'usd-coin'], ['USDC', 'USDC', '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 6, 'ethereum', 3408, 'usd-coin'], From 25ee43e255d02e8fdf5c8a37d2f56eb04c648e41 Mon Sep 17 00:00:00 2001 From: donnyquixotic Date: Fri, 2 Feb 2024 00:45:51 -0600 Subject: [PATCH 10/25] fix: update fiat token list --- src/tokenList.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/tokenList.ts b/src/tokenList.ts index 1fbce68..67c6214 100644 --- a/src/tokenList.ts +++ b/src/tokenList.ts @@ -27,9 +27,12 @@ export const tokenList = createTokenList([ // ETH ['ETH', 'ETH', null, 18, 'ethereum', 1027, 'ethereum'], + ['ETH', 'ETH', null, 18, 'arbitrum', 1027, 'ethereum'], + ['ETH', 'ETH', '0xA0fB8cd450c8Fd3a11901876cD5f17eB47C6bc50', 18, 'telos', 1027, 'ethereum'], + ['ETH', 'ETH', '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619', 18, 'polygon', 1027, 'ethereum'], // WETH - ['WETH', 'Wrapped Ether', '0xA0fB8cd450c8Fd3a11901876cD5f17eB47C6bc50', 18, 'telos', 2396, 'weth'], // prettier-ignore + // ['WETH', 'Wrapped Ether', '0xA0fB8cd450c8Fd3a11901876cD5f17eB47C6bc50', 18, 'telos', 2396, 'weth'], // prettier-ignore //['WETH', 'Wrapped Ether', '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', 18, 'ethereum', 2396, 'weth'], // prettier-ignore ['WETH', 'Wrapped Ether', '0x82af49447d8a07e3bd95bd0d56f35241523fbab1', 18, 'arbitrum', 2396, 'weth'], // prettier-ignore @@ -43,9 +46,10 @@ export const tokenList = createTokenList([ // BNB ['BNB', 'BNB', null, 18, 'bsc', 1, 'binancecoin'], + ['BNB', 'BNB', '0x26Ed0F16e777C94A6FE798F9E20298034930Bae8', 18, 'telos', 1, 'binancecoin'], // WBNB - ['WBNB', 'WBNB', '0x26Ed0F16e777C94A6FE798F9E20298034930Bae8', 18, 'telos', 1, 'wbnb'], + // ['WBNB', 'WBNB', '0x26Ed0F16e777C94A6FE798F9E20298034930Bae8', 18, 'telos', 1, 'wbnb'], //['WBNB', 'WBNB', '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c', 18, 'bsc', 1, 'wbnb'], ]); From 0c1fa69c707a9d68fc8c53a17834e7951ee4aeff Mon Sep 17 00:00:00 2001 From: donnyquixotic Date: Fri, 2 Feb 2024 01:52:51 -0600 Subject: [PATCH 11/25] fix: order tokens w/out fiat by quantity --- src/features/bridge/ui/CurrencySelect.tsx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/features/bridge/ui/CurrencySelect.tsx b/src/features/bridge/ui/CurrencySelect.tsx index 7ff1c8f..4f85efd 100644 --- a/src/features/bridge/ui/CurrencySelect.tsx +++ b/src/features/bridge/ui/CurrencySelect.tsx @@ -109,7 +109,21 @@ export const CurrencySelect: React.FC = observer( if (bBalance === undefined) bBalance = -1; return aBalance - bBalance; }) + .sort((a,b) => { + // if no fiat value, order by token quantity + if (a.fiatBalance?.value === undefined && b.fiatBalance?.value === undefined){ + let aBalance = a.balance?.quotient; + let bBalance = b.balance?.quotient; + if (aBalance === undefined) aBalance = 0n; + if (bBalance === undefined) bBalance = 0n; + return aBalance - bBalance > 0 ? -1 + : aBalance - bBalance < 0 ? 1 + : 0 + } + return 0; + }) .sort(sortTokens) + .sort((a) => (a.option.disabled ? 1 : -1)); return ( From 1f03f982823f976b74c33195509c2078e4c5e6d2 Mon Sep 17 00:00:00 2001 From: donnyquixotic Date: Fri, 2 Feb 2024 02:19:44 -0600 Subject: [PATCH 12/25] doc: comment contract method, conditional --- src/features/bridge/stores/bridgeStore.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/features/bridge/stores/bridgeStore.tsx b/src/features/bridge/stores/bridgeStore.tsx index 3f72fb6..147f2ba 100644 --- a/src/features/bridge/stores/bridgeStore.tsx +++ b/src/features/bridge/stores/bridgeStore.tsx @@ -658,6 +658,7 @@ export class BridgeStore { let transactionResult: any = {}; + // if sending TLOS from Telos EVM, use contract method if (this.srcIsNativeTelos){ transactionResult = yield this.sendNative(); // ensure correct wallet @@ -742,6 +743,7 @@ export class BridgeStore { } }); + // bridge Telos EVM TLOS by calling `sendFrom` directly on the native oft contract instance sendNative: () => unknown = flow(function* (this: BridgeStore) { const {srcCurrency, srcChainId, dstChainId, amount} = this.form; From 259c6540b6d825870a0671fcee2d4e333efa706f Mon Sep 17 00:00:00 2001 From: donnyquixotic Date: Fri, 2 Feb 2024 02:47:14 -0600 Subject: [PATCH 13/25] doc: TLOS conditionals & methods refactor: remove unused import, formatting --- src/config.ts | 2 +- src/features/bridge/hooks/useDefaultSrcCurrency.ts | 2 +- src/features/bridge/stores/bridgeStore.tsx | 8 ++++---- src/features/bridge/ui/CurrencySelect.tsx | 5 ++--- src/features/core/stores/fiatStore.tsx | 1 - 5 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/config.ts b/src/config.ts index 07562c5..ca92637 100644 --- a/src/config.ts +++ b/src/config.ts @@ -304,4 +304,4 @@ export const telosNativeOft: NativeOftConfig = { bridge: {address: '0x9c5ebCbE531aA81bD82013aBF97401f5C6111d76', chainId: ChainId.TELOS, chainListId: ChainListId.TELOS, rpc: 'https://mainnet.telos.net/evm', abi: bridgeAbi}, token: new Coin(ChainId.TELOS, 18, 'TLOS'), proxy: {chainId: ChainId.TELOS, address: '0x7B5250Ad9aE6445e75E01Cd4bB070aECBf8DB92E'} -} \ No newline at end of file +} diff --git a/src/features/bridge/hooks/useDefaultSrcCurrency.ts b/src/features/bridge/hooks/useDefaultSrcCurrency.ts index d123983..5d62d2b 100644 --- a/src/features/bridge/hooks/useDefaultSrcCurrency.ts +++ b/src/features/bridge/hooks/useDefaultSrcCurrency.ts @@ -36,7 +36,7 @@ export function useDefaultSrcCurrency() { if (form.dstCurrency) return; const {srcCurrencyOptions} = bridgeStore; - // set default Native TLOS as default + // set Telos EVM TLOS as default const telosNative = srcCurrencyOptions.find((option: CurrencyOption) => option.currency.chainId === ChainId.TELOS && option.currency.symbol === TLOS_SYMBOL) if (telosNative) { if (srcChainId !== ChainId.TELOS){ diff --git a/src/features/bridge/stores/bridgeStore.tsx b/src/features/bridge/stores/bridgeStore.tsx index 147f2ba..389466d 100644 --- a/src/features/bridge/stores/bridgeStore.tsx +++ b/src/features/bridge/stores/bridgeStore.tsx @@ -168,7 +168,7 @@ export class BridgeStore { } get srcCurrencyOptions(): CurrencyOption[] { - const currencyOptions = this.currencies.map((currency) => { + return this.currencies.map((currency) => { const disabled = false; const balance = getWalletBalance(currency); const isZero = !balance || balance?.equalTo(0); @@ -178,8 +178,6 @@ export class BridgeStore { overlay: disabled && !isZero ? 'Not available' : undefined, }; }); - - return currencyOptions; } get dstCurrencyOptions(): CurrencyOption[] { @@ -901,6 +899,8 @@ export class BridgeStore { // introduce buffer to avoid any gas price fluctuations that may affect user expereience // increase does not affect the actual price const multiplier = new Fraction(110, 100); + + // if source is telos EVM OFT get fees directly from bridge contract if (this.srcIsNativeTelos && srcBridgeContractInstance){ const args: [ChainId, boolean, string] = [dstCurrency.chainId, false, serializeAdapterParams(adapterParams)]; const nativeCurrency = getNativeCurrency(ChainId.TELOS); @@ -959,7 +959,7 @@ export class BridgeStore { function isValidPair(srcCurrency: Currency, dstCurrency: Currency): boolean { if (srcCurrency.chainId === dstCurrency.chainId) return false; - // confirm valid pair via asset api or if pair is TLOS oft + // validate TLOS OFT pairs in addition to available api check return bridgeStore.apis.some((api) => api.supportsTransfer(srcCurrency, dstCurrency)) || srcCurrency.symbol === 'TLOS' && dstCurrency.symbol === 'TLOS'; } diff --git a/src/features/bridge/ui/CurrencySelect.tsx b/src/features/bridge/ui/CurrencySelect.tsx index 4f85efd..68ba1ae 100644 --- a/src/features/bridge/ui/CurrencySelect.tsx +++ b/src/features/bridge/ui/CurrencySelect.tsx @@ -122,8 +122,7 @@ export const CurrencySelect: React.FC = observer( } return 0; }) - .sort(sortTokens) - + .sort(sortTlos) // TLOS to top .sort((a) => (a.option.disabled ? 1 : -1)); return ( @@ -195,7 +194,7 @@ type NestedCurrencyOption = { option: CurrencyOption; } // sort TLOS tokens to top of list -function sortTokens(a:NestedCurrencyOption, b:NestedCurrencyOption){ +function sortTlos(a:NestedCurrencyOption, b:NestedCurrencyOption){ return (a.option.currency.symbol === TLOS_SYMBOL && b.option.currency.symbol !== TLOS_SYMBOL) ? 1 : (a.option.currency.symbol !== TLOS_SYMBOL && b.option.currency.symbol === TLOS_SYMBOL ? -1 : 0) diff --git a/src/features/core/stores/fiatStore.tsx b/src/features/core/stores/fiatStore.tsx index 3f3bc7e..652718f 100644 --- a/src/features/core/stores/fiatStore.tsx +++ b/src/features/core/stores/fiatStore.tsx @@ -1,5 +1,4 @@ import {Currency, CurrencyAmount, FiatAmount} from '@layerzerolabs/ui-core'; -import axios from 'axios'; import {makeAutoObservable, ObservableMap} from 'mobx'; import {tokenStore} from './tokenStore'; From 126a1f46d449c0d798a969d2712e2000035cd476 Mon Sep 17 00:00:00 2001 From: donnyquixotic Date: Fri, 2 Feb 2024 02:56:51 -0600 Subject: [PATCH 14/25] refactor: order by tokens w/out fiat value by quantity --- src/features/bridge/ui/CurrencySelect.tsx | 35 ++++++++++++++--------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/features/bridge/ui/CurrencySelect.tsx b/src/features/bridge/ui/CurrencySelect.tsx index 68ba1ae..1df0849 100644 --- a/src/features/bridge/ui/CurrencySelect.tsx +++ b/src/features/bridge/ui/CurrencySelect.tsx @@ -1,4 +1,4 @@ -import {Currency, getNetwork, isCurrency} from '@layerzerolabs/ui-core'; +import {Currency, CurrencyAmount, FiatAmount, getNetwork, isCurrency} from '@layerzerolabs/ui-core'; import {observer} from 'mobx-react'; import React, {useState} from 'react'; @@ -109,19 +109,7 @@ export const CurrencySelect: React.FC = observer( if (bBalance === undefined) bBalance = -1; return aBalance - bBalance; }) - .sort((a,b) => { - // if no fiat value, order by token quantity - if (a.fiatBalance?.value === undefined && b.fiatBalance?.value === undefined){ - let aBalance = a.balance?.quotient; - let bBalance = b.balance?.quotient; - if (aBalance === undefined) aBalance = 0n; - if (bBalance === undefined) bBalance = 0n; - return aBalance - bBalance > 0 ? -1 - : aBalance - bBalance < 0 ? 1 - : 0 - } - return 0; - }) + .sort(sortTokenQuantity) // order tokens w/out fiat value by token quantity .sort(sortTlos) // TLOS to top .sort((a) => (a.option.disabled ? 1 : -1)); @@ -200,6 +188,25 @@ function sortTlos(a:NestedCurrencyOption, b:NestedCurrencyOption){ : 0) } +type TokenOption = { + option: CurrencyOption; + balance: CurrencyAmount | undefined; + fiatBalance: FiatAmount | undefined; +} + +function sortTokenQuantity(a: TokenOption, b: TokenOption){ + if (a.fiatBalance?.value === undefined && b.fiatBalance?.value === undefined){ + let aBalance = a.balance?.quotient; + let bBalance = b.balance?.quotient; + if (aBalance === undefined) aBalance = 0n; + if (bBalance === undefined) bBalance = 0n; + return aBalance - bBalance > 0 ? -1 + : aBalance - bBalance < 0 ? 1 + : 0 + } + return 0; +} + function toOption(option: CurrencyOption | Currency): CurrencyOption { if (isCurrency(option)) { return { From f9bd4366295db712588e53b1bbed9c89bc882416 Mon Sep 17 00:00:00 2001 From: donnyquixotic Date: Tue, 6 Feb 2024 17:27:09 -0600 Subject: [PATCH 15/25] refactor: TLOS symbol --- CONTRACTS.md | 3 +++ src/config.ts | 14 ++++++++------ src/features/bridge/stores/bridgeStore.tsx | 2 +- src/features/core/ui/CurrencyIcon.tsx | 3 ++- src/tokenList.ts | 14 ++++++++------ 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/CONTRACTS.md b/CONTRACTS.md index 9c0bec7..281d518 100644 --- a/CONTRACTS.md +++ b/CONTRACTS.md @@ -36,14 +36,17 @@ ### Endpoint * chainId: `10199` * address `0x83c73Da98cf733B03315aFa8758834b36a195b87` + ### OriginalTokenBridge * goerli: `0xBCD4a2c19DC010d1Da2D7985CF18A5251774dF46` * arbitrum-goerli: `0xbF625D717de1a6e5a8446424CF08D4269D51ab96` * bsc-testnet: `0x8168C0704Ff49F8e89AF45f04f898144C459b156` * mumbai: `0x0c372d3f89d1ce9f11a50b98374f7846a37f7d99` * fuji: `0x2a3a50f458AaAae618C54C1670fD49e338b795c2` + ### WrappedTokenBridge * telos-testnet: `0x137d4e9C2431A3DCBa6e615E9438F2c558353a17` + ### USDC * goerli: `0x31190a205713Bd825a0c237E26f67CE89B5C4dD8` * arbitrum-goerli: `0x6463C73809EE3F85BeCD0a82c55cb808474101D0` diff --git a/src/config.ts b/src/config.ts index ca92637..b6c2289 100644 --- a/src/config.ts +++ b/src/config.ts @@ -4,6 +4,8 @@ import {OnftBridgeConfig, OnftStandard} from '@layerzerolabs/ui-bridge-onft'; import {WrappedTokenBridgeConfig} from '@layerzerolabs/ui-bridge-wrapped-token'; import {Coin, Currency, Token} from '@layerzerolabs/ui-core'; +import { TLOS_SYMBOL } from '@/bridge/stores/bridgeStore'; + import { bridgeAbi } from './abi/bridgeAbi'; export const wrapped_mainnet: WrappedTokenBridgeConfig = { @@ -235,11 +237,11 @@ const RF = { export const TLOS = { version: 2, tokens: [ - new Token(ChainId.ARBITRUM, '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E', 18, 'TLOS'), - new Token(ChainId.AVALANCHE, '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E', 18, 'TLOS'), - new Token(ChainId.BSC, '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E', 18, 'TLOS'), - new Token(ChainId.POLYGON, '0x1cF0636abbc569fB413A20bd7964712e6b4d1161', 18, 'TLOS'), - new Token(ChainId.ETHEREUM, '0x5Aa352551d39F5ce592260e0D26818e7d780867f', 18, 'TLOS'), + new Token(ChainId.ARBITRUM, '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E', 18, TLOS_SYMBOL), + new Token(ChainId.AVALANCHE, '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E', 18, TLOS_SYMBOL), + new Token(ChainId.BSC, '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E', 18, TLOS_SYMBOL), + new Token(ChainId.POLYGON, '0x1cF0636abbc569fB413A20bd7964712e6b4d1161', 18, TLOS_SYMBOL), + new Token(ChainId.ETHEREUM, '0x5Aa352551d39F5ce592260e0D26818e7d780867f', 18, TLOS_SYMBOL), ], proxy: [ {chainId: ChainId.ARBITRUM, address: '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E'}, @@ -302,6 +304,6 @@ type NativeOftConfig = { export const telosNativeOft: NativeOftConfig = { bridge: {address: '0x9c5ebCbE531aA81bD82013aBF97401f5C6111d76', chainId: ChainId.TELOS, chainListId: ChainListId.TELOS, rpc: 'https://mainnet.telos.net/evm', abi: bridgeAbi}, - token: new Coin(ChainId.TELOS, 18, 'TLOS'), + token: new Coin(ChainId.TELOS, 18, TLOS_SYMBOL), proxy: {chainId: ChainId.TELOS, address: '0x7B5250Ad9aE6445e75E01Cd4bB070aECBf8DB92E'} } diff --git a/src/features/bridge/stores/bridgeStore.tsx b/src/features/bridge/stores/bridgeStore.tsx index 389466d..7427c53 100644 --- a/src/features/bridge/stores/bridgeStore.tsx +++ b/src/features/bridge/stores/bridgeStore.tsx @@ -960,7 +960,7 @@ export class BridgeStore { function isValidPair(srcCurrency: Currency, dstCurrency: Currency): boolean { if (srcCurrency.chainId === dstCurrency.chainId) return false; // validate TLOS OFT pairs in addition to available api check - return bridgeStore.apis.some((api) => api.supportsTransfer(srcCurrency, dstCurrency)) || srcCurrency.symbol === 'TLOS' && dstCurrency.symbol === 'TLOS'; + return bridgeStore.apis.some((api) => api.supportsTransfer(srcCurrency, dstCurrency)) || srcCurrency.symbol === TLOS_SYMBOL && dstCurrency.symbol === TLOS_SYMBOL; } function findMatchingCurrency(currency: Currency) { diff --git a/src/features/core/ui/CurrencyIcon.tsx b/src/features/core/ui/CurrencyIcon.tsx index fcda6e7..ab636aa 100644 --- a/src/features/core/ui/CurrencyIcon.tsx +++ b/src/features/core/ui/CurrencyIcon.tsx @@ -1,5 +1,6 @@ import {Currency, getCurrencyIcon} from '@layerzerolabs/ui-core'; +import { TLOS_SYMBOL } from '@/bridge/stores/bridgeStore'; import {styled} from '@/core/ui/system'; import {overrideImageSrcOnError} from '@/core/utils/overrideImageSrcOnError'; @@ -23,7 +24,7 @@ const getTokenIcon = (symbol: string): string => { return 'https://raw.githubusercontent.com/telosnetwork/token-list/master/logos/RF.webp'; case 'VC': return 'https://raw.githubusercontent.com/telosnetwork/token-list/master/logos/VC.png'; - case 'TLOS': + case TLOS_SYMBOL: return 'https://raw.githubusercontent.com/telosnetwork/token-list/main/logos/telos.png'; default: return getCurrencyIcon(symbol); diff --git a/src/tokenList.ts b/src/tokenList.ts index 67c6214..04505ab 100644 --- a/src/tokenList.ts +++ b/src/tokenList.ts @@ -1,13 +1,15 @@ import {TokenListItem} from '@layerzerolabs/ui-core'; +import { TLOS_SYMBOL } from '@/bridge/stores/bridgeStore'; + export const tokenList = createTokenList([ // TLOS - ['TLOS', 'TLOS', null, 18, 'telos', 4660, 'telos'], - ['TLOS', 'TLOS', '0x5Aa352551d39F5ce592260e0D26818e7d780867f', 18, 'ethereum', 4660, 'telos'], - ['TLOS', 'TLOS', '0x1cF0636abbc569fB413A20bd7964712e6b4d1161', 18, 'polygon', 4660, 'telos'], - ['TLOS', 'TLOS', '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E', 18, 'bsc', 4660, 'telos'], - ['TLOS', 'TLOS', '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E', 18, 'avalanche', 4660, 'telos'], - ['TLOS', 'TLOS', '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E', 18, 'arbitrum', 4660, 'telos'], + [TLOS_SYMBOL, TLOS_SYMBOL, null, 18, 'telos', 4660, 'telos'], + [TLOS_SYMBOL, TLOS_SYMBOL, '0x5Aa352551d39F5ce592260e0D26818e7d780867f', 18, 'ethereum', 4660, 'telos'], + [TLOS_SYMBOL, TLOS_SYMBOL, '0x1cF0636abbc569fB413A20bd7964712e6b4d1161', 18, 'polygon', 4660, 'telos'], + [TLOS_SYMBOL, TLOS_SYMBOL, '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E', 18, 'bsc', 4660, 'telos'], + [TLOS_SYMBOL, TLOS_SYMBOL, '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E', 18, 'avalanche', 4660, 'telos'], + [TLOS_SYMBOL, TLOS_SYMBOL, '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E', 18, 'arbitrum', 4660, 'telos'], // USDC ['USDC', 'USDC', '0x8D97Cea50351Fb4329d591682b148D43a0C3611b', 6, 'telos', 3408, 'usd-coin'], From 215fe948cb9be7b7d60e4c442a113b9cb3d755b1 Mon Sep 17 00:00:00 2001 From: donnyquixotic Date: Tue, 6 Feb 2024 17:35:04 -0600 Subject: [PATCH 16/25] fix: move TLOS_SYMBOL assignment to config --- src/config.ts | 4 ++-- src/features/bridge/hooks/useDefaultSrcCurrency.ts | 4 +++- src/features/bridge/stores/bridgeStore.tsx | 3 +-- src/features/bridge/ui/CurrencySelect.tsx | 4 +++- src/features/core/ui/CurrencyIcon.tsx | 2 +- src/tokenList.ts | 2 +- 6 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/config.ts b/src/config.ts index b6c2289..67cf263 100644 --- a/src/config.ts +++ b/src/config.ts @@ -4,10 +4,10 @@ import {OnftBridgeConfig, OnftStandard} from '@layerzerolabs/ui-bridge-onft'; import {WrappedTokenBridgeConfig} from '@layerzerolabs/ui-bridge-wrapped-token'; import {Coin, Currency, Token} from '@layerzerolabs/ui-core'; -import { TLOS_SYMBOL } from '@/bridge/stores/bridgeStore'; - import { bridgeAbi } from './abi/bridgeAbi'; +export const TLOS_SYMBOL = 'TLOS'; + export const wrapped_mainnet: WrappedTokenBridgeConfig = { version: 2, original: [ diff --git a/src/features/bridge/hooks/useDefaultSrcCurrency.ts b/src/features/bridge/hooks/useDefaultSrcCurrency.ts index 5d62d2b..7fcf730 100644 --- a/src/features/bridge/hooks/useDefaultSrcCurrency.ts +++ b/src/features/bridge/hooks/useDefaultSrcCurrency.ts @@ -2,10 +2,12 @@ import {ChainId} from '@layerzerolabs/lz-sdk'; import {chainKeyToEndpointId} from '@layerzerolabs/ui-core'; import {useEffect} from 'react'; -import {bridgeStore,CurrencyOption, TLOS_SYMBOL} from '@/bridge/stores/bridgeStore'; +import {bridgeStore,CurrencyOption } from '@/bridge/stores/bridgeStore'; import {balanceStore} from '@/core/stores/balanceStore'; import {walletStore} from '@/core/stores/walletStore'; +import { TLOS_SYMBOL } from '../../../config'; + export function useDefaultSrcCurrency() { const {address, chainKey} = walletStore.evm ?? {}; diff --git a/src/features/bridge/stores/bridgeStore.tsx b/src/features/bridge/stores/bridgeStore.tsx index 7427c53..6e25ef3 100644 --- a/src/features/bridge/stores/bridgeStore.tsx +++ b/src/features/bridge/stores/bridgeStore.tsx @@ -44,7 +44,7 @@ import {handleError} from '@/core/utils/handleError'; import {parseWalletError} from '@/core/utils/parseWalletError'; import { oftAbi } from '../../../abi/oftAbi'; -import { ProxyConfig, telosNativeOft } from '../../../config'; +import { ProxyConfig, telosNativeOft,TLOS_SYMBOL } from '../../../config'; import {unclaimedStore} from './unclaimedStore'; export enum DstNativeAmount { @@ -53,7 +53,6 @@ export enum DstNativeAmount { } export type ValidationError = string; -export const TLOS_SYMBOL = 'TLOS'; export class BridgeStore { isLoading = false; isSigning = false; diff --git a/src/features/bridge/ui/CurrencySelect.tsx b/src/features/bridge/ui/CurrencySelect.tsx index 1df0849..49b2cbc 100644 --- a/src/features/bridge/ui/CurrencySelect.tsx +++ b/src/features/bridge/ui/CurrencySelect.tsx @@ -2,7 +2,7 @@ import {Currency, CurrencyAmount, FiatAmount, getNetwork, isCurrency} from '@lay import {observer} from 'mobx-react'; import React, {useState} from 'react'; -import {CurrencyOption, OptionGroup, TLOS_SYMBOL} from '@/bridge/stores/bridgeStore'; +import {CurrencyOption, OptionGroup} from '@/bridge/stores/bridgeStore'; import {useToggle} from '@/core/hooks/useToggle'; import {fiatStore} from '@/core/stores/fiatStore'; import {getWalletBalance} from '@/core/stores/utils'; @@ -13,6 +13,8 @@ import {SearchBar} from '@/core/ui/SearchBar'; import {SelectButton} from '@/core/ui/SelectButton'; import {styled, SxProps, Theme} from '@/core/ui/system'; +import { TLOS_SYMBOL } from '../../../config'; + interface CommonProps { theme?: Theme; as?: React.ElementType; diff --git a/src/features/core/ui/CurrencyIcon.tsx b/src/features/core/ui/CurrencyIcon.tsx index ab636aa..202c36f 100644 --- a/src/features/core/ui/CurrencyIcon.tsx +++ b/src/features/core/ui/CurrencyIcon.tsx @@ -1,9 +1,9 @@ import {Currency, getCurrencyIcon} from '@layerzerolabs/ui-core'; -import { TLOS_SYMBOL } from '@/bridge/stores/bridgeStore'; import {styled} from '@/core/ui/system'; import {overrideImageSrcOnError} from '@/core/utils/overrideImageSrcOnError'; +import { TLOS_SYMBOL } from '../../../config'; import {fiatStore} from '../stores/fiatStore'; import {Icon} from './Icon'; diff --git a/src/tokenList.ts b/src/tokenList.ts index 04505ab..270b81a 100644 --- a/src/tokenList.ts +++ b/src/tokenList.ts @@ -1,6 +1,6 @@ import {TokenListItem} from '@layerzerolabs/ui-core'; -import { TLOS_SYMBOL } from '@/bridge/stores/bridgeStore'; +import { TLOS_SYMBOL } from './config'; export const tokenList = createTokenList([ // TLOS From 8a5e705b3e7fde2fb1b7140bd74844f5de6316d8 Mon Sep 17 00:00:00 2001 From: tomtomcrypto Date: Mon, 13 May 2024 19:45:20 +0000 Subject: [PATCH 17/25] upgradeable deploy test --- CONTRACTS.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRACTS.md b/CONTRACTS.md index 281d518..57dfee2 100644 --- a/CONTRACTS.md +++ b/CONTRACTS.md @@ -24,12 +24,12 @@ * BNB: `0x26Ed0F16e777C94A6FE798F9E20298034930Bae8` ## TLOS OFT -* telos: `0x7B5250Ad9aE6445e75E01Cd4bB070aECBf8DB92E` +* telos: `0x685ae711Ba61084881fd9431095B6B6697573c73` * ethereum: `0x5Aa352551d39F5ce592260e0D26818e7d780867f` * bsc: `0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E` * polygon: `0x1cF0636abbc569fB413A20bd7964712e6b4d1161` * arbitrum: `0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E` -* avalanche: `0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E` +* avalanche: `0xB037eA50debc46E6F70f246cD12d48fe4f13FaFf` ## Testnet From ae51b87f8b37cddda1a33a7d036fad9ff9b3857f Mon Sep 17 00:00:00 2001 From: tomtomcrypto Date: Mon, 13 May 2024 20:03:20 +0000 Subject: [PATCH 18/25] upgrade deploy test --- CONTRACTS.md | 4 ++-- src/config.ts | 6 +++--- src/tokenList.ts | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CONTRACTS.md b/CONTRACTS.md index 57dfee2..f9981a8 100644 --- a/CONTRACTS.md +++ b/CONTRACTS.md @@ -64,5 +64,5 @@ * telos-testnet: `0x15a7cad43E5F24d1B08fDE151CE00D1cf360f6C7` ## TLOS OFT -* telos: `0xAEa017740a2e7608F873CB130e7B3c335A4a1940` -* fuji: `0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E` \ No newline at end of file +* telos: `0x685ae711Ba61084881fd9431095B6B6697573c73` +* fuji: `0xB037eA50debc46E6F70f246cD12d48fe4f13FaFf` \ No newline at end of file diff --git a/src/config.ts b/src/config.ts index 67cf263..e55b4e9 100644 --- a/src/config.ts +++ b/src/config.ts @@ -238,14 +238,14 @@ export const TLOS = { version: 2, tokens: [ new Token(ChainId.ARBITRUM, '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E', 18, TLOS_SYMBOL), - new Token(ChainId.AVALANCHE, '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E', 18, TLOS_SYMBOL), + new Token(ChainId.AVALANCHE, '0xB037eA50debc46E6F70f246cD12d48fe4f13FaFf', 18, TLOS_SYMBOL), new Token(ChainId.BSC, '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E', 18, TLOS_SYMBOL), new Token(ChainId.POLYGON, '0x1cF0636abbc569fB413A20bd7964712e6b4d1161', 18, TLOS_SYMBOL), new Token(ChainId.ETHEREUM, '0x5Aa352551d39F5ce592260e0D26818e7d780867f', 18, TLOS_SYMBOL), ], proxy: [ {chainId: ChainId.ARBITRUM, address: '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E'}, - {chainId: ChainId.AVALANCHE, address: '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E'}, + {chainId: ChainId.AVALANCHE, address: '0xB037eA50debc46E6F70f246cD12d48fe4f13FaFf'}, {chainId: ChainId.BSC, address: '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E'}, {chainId: ChainId.POLYGON, address: '0x1cF0636abbc569fB413A20bd7964712e6b4d1161'}, {chainId: ChainId.ETHEREUM, address: '0x5Aa352551d39F5ce592260e0D26818e7d780867f'}, @@ -305,5 +305,5 @@ type NativeOftConfig = { export const telosNativeOft: NativeOftConfig = { bridge: {address: '0x9c5ebCbE531aA81bD82013aBF97401f5C6111d76', chainId: ChainId.TELOS, chainListId: ChainListId.TELOS, rpc: 'https://mainnet.telos.net/evm', abi: bridgeAbi}, token: new Coin(ChainId.TELOS, 18, TLOS_SYMBOL), - proxy: {chainId: ChainId.TELOS, address: '0x7B5250Ad9aE6445e75E01Cd4bB070aECBf8DB92E'} + proxy: {chainId: ChainId.TELOS, address: '0x685ae711Ba61084881fd9431095B6B6697573c73'} } diff --git a/src/tokenList.ts b/src/tokenList.ts index 270b81a..eca6139 100644 --- a/src/tokenList.ts +++ b/src/tokenList.ts @@ -8,7 +8,7 @@ export const tokenList = createTokenList([ [TLOS_SYMBOL, TLOS_SYMBOL, '0x5Aa352551d39F5ce592260e0D26818e7d780867f', 18, 'ethereum', 4660, 'telos'], [TLOS_SYMBOL, TLOS_SYMBOL, '0x1cF0636abbc569fB413A20bd7964712e6b4d1161', 18, 'polygon', 4660, 'telos'], [TLOS_SYMBOL, TLOS_SYMBOL, '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E', 18, 'bsc', 4660, 'telos'], - [TLOS_SYMBOL, TLOS_SYMBOL, '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E', 18, 'avalanche', 4660, 'telos'], + [TLOS_SYMBOL, TLOS_SYMBOL, '0xB037eA50debc46E6F70f246cD12d48fe4f13FaFf', 18, 'avalanche', 4660, 'telos'], [TLOS_SYMBOL, TLOS_SYMBOL, '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E', 18, 'arbitrum', 4660, 'telos'], // USDC From 282dd0e146e99fa39e3e2679db2a0542eef0b399 Mon Sep 17 00:00:00 2001 From: tomtomcrypto Date: Mon, 13 May 2024 20:08:43 +0000 Subject: [PATCH 19/25] upgrade deploy test --- src/config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.ts b/src/config.ts index e55b4e9..aba5157 100644 --- a/src/config.ts +++ b/src/config.ts @@ -249,7 +249,7 @@ export const TLOS = { {chainId: ChainId.BSC, address: '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E'}, {chainId: ChainId.POLYGON, address: '0x1cF0636abbc569fB413A20bd7964712e6b4d1161'}, {chainId: ChainId.ETHEREUM, address: '0x5Aa352551d39F5ce592260e0D26818e7d780867f'}, - {chainId: ChainId.TELOS, address: '0x7B5250Ad9aE6445e75E01Cd4bB070aECBf8DB92E'} + {chainId: ChainId.TELOS, address: '0x685ae711Ba61084881fd9431095B6B6697573c73'} ], fee: false, sharedDecimals: 4, From f932e592a00ee77ae8db09c8652ab5af94c67b17 Mon Sep 17 00:00:00 2001 From: tomtomcrypto Date: Tue, 14 May 2024 11:38:56 +0000 Subject: [PATCH 20/25] more new deploy test --- src/config.ts | 4 ++-- src/tokenList.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/config.ts b/src/config.ts index aba5157..48a1d41 100644 --- a/src/config.ts +++ b/src/config.ts @@ -238,14 +238,14 @@ export const TLOS = { version: 2, tokens: [ new Token(ChainId.ARBITRUM, '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E', 18, TLOS_SYMBOL), - new Token(ChainId.AVALANCHE, '0xB037eA50debc46E6F70f246cD12d48fe4f13FaFf', 18, TLOS_SYMBOL), + new Token(ChainId.AVALANCHE, '0xe8eaca8d99119548B1887932d9E95cdceA6172d2', 18, TLOS_SYMBOL), new Token(ChainId.BSC, '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E', 18, TLOS_SYMBOL), new Token(ChainId.POLYGON, '0x1cF0636abbc569fB413A20bd7964712e6b4d1161', 18, TLOS_SYMBOL), new Token(ChainId.ETHEREUM, '0x5Aa352551d39F5ce592260e0D26818e7d780867f', 18, TLOS_SYMBOL), ], proxy: [ {chainId: ChainId.ARBITRUM, address: '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E'}, - {chainId: ChainId.AVALANCHE, address: '0xB037eA50debc46E6F70f246cD12d48fe4f13FaFf'}, + {chainId: ChainId.AVALANCHE, address: '0xe8eaca8d99119548B1887932d9E95cdceA6172d2'}, {chainId: ChainId.BSC, address: '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E'}, {chainId: ChainId.POLYGON, address: '0x1cF0636abbc569fB413A20bd7964712e6b4d1161'}, {chainId: ChainId.ETHEREUM, address: '0x5Aa352551d39F5ce592260e0D26818e7d780867f'}, diff --git a/src/tokenList.ts b/src/tokenList.ts index eca6139..b176fca 100644 --- a/src/tokenList.ts +++ b/src/tokenList.ts @@ -8,7 +8,7 @@ export const tokenList = createTokenList([ [TLOS_SYMBOL, TLOS_SYMBOL, '0x5Aa352551d39F5ce592260e0D26818e7d780867f', 18, 'ethereum', 4660, 'telos'], [TLOS_SYMBOL, TLOS_SYMBOL, '0x1cF0636abbc569fB413A20bd7964712e6b4d1161', 18, 'polygon', 4660, 'telos'], [TLOS_SYMBOL, TLOS_SYMBOL, '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E', 18, 'bsc', 4660, 'telos'], - [TLOS_SYMBOL, TLOS_SYMBOL, '0xB037eA50debc46E6F70f246cD12d48fe4f13FaFf', 18, 'avalanche', 4660, 'telos'], + [TLOS_SYMBOL, TLOS_SYMBOL, '0xe8eaca8d99119548B1887932d9E95cdceA6172d2', 18, 'avalanche', 4660, 'telos'], [TLOS_SYMBOL, TLOS_SYMBOL, '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E', 18, 'arbitrum', 4660, 'telos'], // USDC From 6f0547ba9a3cf7a0e9539ef6380d04a91df33ca9 Mon Sep 17 00:00:00 2001 From: tomtomcrypto Date: Tue, 14 May 2024 13:15:44 +0000 Subject: [PATCH 21/25] more new deploy test --- CONTRACTS.md | 2 +- src/config.ts | 4 ++-- src/tokenList.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CONTRACTS.md b/CONTRACTS.md index f9981a8..500e796 100644 --- a/CONTRACTS.md +++ b/CONTRACTS.md @@ -29,7 +29,7 @@ * bsc: `0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E` * polygon: `0x1cF0636abbc569fB413A20bd7964712e6b4d1161` * arbitrum: `0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E` -* avalanche: `0xB037eA50debc46E6F70f246cD12d48fe4f13FaFf` +* avalanche: `0x276B2D865Cc809DDFbC780A03fC81537a499a8e5` ## Testnet diff --git a/src/config.ts b/src/config.ts index 48a1d41..c776a6c 100644 --- a/src/config.ts +++ b/src/config.ts @@ -238,14 +238,14 @@ export const TLOS = { version: 2, tokens: [ new Token(ChainId.ARBITRUM, '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E', 18, TLOS_SYMBOL), - new Token(ChainId.AVALANCHE, '0xe8eaca8d99119548B1887932d9E95cdceA6172d2', 18, TLOS_SYMBOL), + new Token(ChainId.AVALANCHE, '0x276B2D865Cc809DDFbC780A03fC81537a499a8e5', 18, TLOS_SYMBOL), new Token(ChainId.BSC, '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E', 18, TLOS_SYMBOL), new Token(ChainId.POLYGON, '0x1cF0636abbc569fB413A20bd7964712e6b4d1161', 18, TLOS_SYMBOL), new Token(ChainId.ETHEREUM, '0x5Aa352551d39F5ce592260e0D26818e7d780867f', 18, TLOS_SYMBOL), ], proxy: [ {chainId: ChainId.ARBITRUM, address: '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E'}, - {chainId: ChainId.AVALANCHE, address: '0xe8eaca8d99119548B1887932d9E95cdceA6172d2'}, + {chainId: ChainId.AVALANCHE, address: '0x276B2D865Cc809DDFbC780A03fC81537a499a8e5'}, {chainId: ChainId.BSC, address: '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E'}, {chainId: ChainId.POLYGON, address: '0x1cF0636abbc569fB413A20bd7964712e6b4d1161'}, {chainId: ChainId.ETHEREUM, address: '0x5Aa352551d39F5ce592260e0D26818e7d780867f'}, diff --git a/src/tokenList.ts b/src/tokenList.ts index b176fca..659b1cf 100644 --- a/src/tokenList.ts +++ b/src/tokenList.ts @@ -8,7 +8,7 @@ export const tokenList = createTokenList([ [TLOS_SYMBOL, TLOS_SYMBOL, '0x5Aa352551d39F5ce592260e0D26818e7d780867f', 18, 'ethereum', 4660, 'telos'], [TLOS_SYMBOL, TLOS_SYMBOL, '0x1cF0636abbc569fB413A20bd7964712e6b4d1161', 18, 'polygon', 4660, 'telos'], [TLOS_SYMBOL, TLOS_SYMBOL, '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E', 18, 'bsc', 4660, 'telos'], - [TLOS_SYMBOL, TLOS_SYMBOL, '0xe8eaca8d99119548B1887932d9E95cdceA6172d2', 18, 'avalanche', 4660, 'telos'], + [TLOS_SYMBOL, TLOS_SYMBOL, '0x276B2D865Cc809DDFbC780A03fC81537a499a8e5', 18, 'avalanche', 4660, 'telos'], [TLOS_SYMBOL, TLOS_SYMBOL, '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E', 18, 'arbitrum', 4660, 'telos'], // USDC From 8e72c2ca7889d5d356767e3ac311496e55909541 Mon Sep 17 00:00:00 2001 From: tomtomcrypto Date: Thu, 16 May 2024 15:14:47 +0000 Subject: [PATCH 22/25] more new deploy test --- src/tokenList.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tokenList.ts b/src/tokenList.ts index 659b1cf..551033d 100644 --- a/src/tokenList.ts +++ b/src/tokenList.ts @@ -8,7 +8,7 @@ export const tokenList = createTokenList([ [TLOS_SYMBOL, TLOS_SYMBOL, '0x5Aa352551d39F5ce592260e0D26818e7d780867f', 18, 'ethereum', 4660, 'telos'], [TLOS_SYMBOL, TLOS_SYMBOL, '0x1cF0636abbc569fB413A20bd7964712e6b4d1161', 18, 'polygon', 4660, 'telos'], [TLOS_SYMBOL, TLOS_SYMBOL, '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E', 18, 'bsc', 4660, 'telos'], - [TLOS_SYMBOL, TLOS_SYMBOL, '0x276B2D865Cc809DDFbC780A03fC81537a499a8e5', 18, 'avalanche', 4660, 'telos'], + [TLOS_SYMBOL, TLOS_SYMBOL, '0x92928a1aBB12b0EC5C621E6BfFf806efE85C0683', 18, 'avalanche', 4660, 'telos'], [TLOS_SYMBOL, TLOS_SYMBOL, '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E', 18, 'arbitrum', 4660, 'telos'], // USDC From 74684ce82f5c25b42d5885f9bb923d835c238339 Mon Sep 17 00:00:00 2001 From: tomtomcrypto Date: Fri, 17 May 2024 14:20:00 +0000 Subject: [PATCH 23/25] more new deploy test --- src/config.ts | 22 +++++++++++----------- src/tokenList.ts | 10 +++++----- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/config.ts b/src/config.ts index c776a6c..7c6df86 100644 --- a/src/config.ts +++ b/src/config.ts @@ -237,19 +237,19 @@ const RF = { export const TLOS = { version: 2, tokens: [ - new Token(ChainId.ARBITRUM, '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E', 18, TLOS_SYMBOL), - new Token(ChainId.AVALANCHE, '0x276B2D865Cc809DDFbC780A03fC81537a499a8e5', 18, TLOS_SYMBOL), - new Token(ChainId.BSC, '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E', 18, TLOS_SYMBOL), - new Token(ChainId.POLYGON, '0x1cF0636abbc569fB413A20bd7964712e6b4d1161', 18, TLOS_SYMBOL), - new Token(ChainId.ETHEREUM, '0x5Aa352551d39F5ce592260e0D26818e7d780867f', 18, TLOS_SYMBOL), + new Token(ChainId.ARBITRUM, '0x193f4A4a6ea24102F49b931DEeeb931f6E32405d', 18, TLOS_SYMBOL), + new Token(ChainId.AVALANCHE, '0xed667dC80a45b77305Cc395DB56D997597Dc6DdD', 18, TLOS_SYMBOL), + new Token(ChainId.BSC, '0x193f4A4a6ea24102F49b931DEeeb931f6E32405d', 18, TLOS_SYMBOL), + new Token(ChainId.POLYGON, '0x193f4A4a6ea24102F49b931DEeeb931f6E32405d', 18, TLOS_SYMBOL), + new Token(ChainId.ETHEREUM, '0x193f4A4a6ea24102F49b931DEeeb931f6E32405d', 18, TLOS_SYMBOL), ], proxy: [ - {chainId: ChainId.ARBITRUM, address: '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E'}, - {chainId: ChainId.AVALANCHE, address: '0x276B2D865Cc809DDFbC780A03fC81537a499a8e5'}, - {chainId: ChainId.BSC, address: '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E'}, - {chainId: ChainId.POLYGON, address: '0x1cF0636abbc569fB413A20bd7964712e6b4d1161'}, - {chainId: ChainId.ETHEREUM, address: '0x5Aa352551d39F5ce592260e0D26818e7d780867f'}, - {chainId: ChainId.TELOS, address: '0x685ae711Ba61084881fd9431095B6B6697573c73'} + {chainId: ChainId.ARBITRUM, address: '0x193f4A4a6ea24102F49b931DEeeb931f6E32405d'}, + {chainId: ChainId.AVALANCHE, address: '0xed667dC80a45b77305Cc395DB56D997597Dc6DdD'}, + {chainId: ChainId.BSC, address: '0x193f4A4a6ea24102F49b931DEeeb931f6E32405d'}, + {chainId: ChainId.POLYGON, address: '0x193f4A4a6ea24102F49b931DEeeb931f6E32405d'}, + {chainId: ChainId.ETHEREUM, address: '0x193f4A4a6ea24102F49b931DEeeb931f6E32405d'}, + {chainId: ChainId.TELOS, address: '0x02Ea28694Ae65358Be92bAFeF5Cb8C211f33Db1A'} ], fee: false, sharedDecimals: 4, diff --git a/src/tokenList.ts b/src/tokenList.ts index 551033d..be7d87d 100644 --- a/src/tokenList.ts +++ b/src/tokenList.ts @@ -5,11 +5,11 @@ import { TLOS_SYMBOL } from './config'; export const tokenList = createTokenList([ // TLOS [TLOS_SYMBOL, TLOS_SYMBOL, null, 18, 'telos', 4660, 'telos'], - [TLOS_SYMBOL, TLOS_SYMBOL, '0x5Aa352551d39F5ce592260e0D26818e7d780867f', 18, 'ethereum', 4660, 'telos'], - [TLOS_SYMBOL, TLOS_SYMBOL, '0x1cF0636abbc569fB413A20bd7964712e6b4d1161', 18, 'polygon', 4660, 'telos'], - [TLOS_SYMBOL, TLOS_SYMBOL, '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E', 18, 'bsc', 4660, 'telos'], - [TLOS_SYMBOL, TLOS_SYMBOL, '0x92928a1aBB12b0EC5C621E6BfFf806efE85C0683', 18, 'avalanche', 4660, 'telos'], - [TLOS_SYMBOL, TLOS_SYMBOL, '0x5e3a61B39FfffA983b1E7133e408545A21Ca1C3E', 18, 'arbitrum', 4660, 'telos'], + [TLOS_SYMBOL, TLOS_SYMBOL, '0x193f4A4a6ea24102F49b931DEeeb931f6E32405d', 18, 'ethereum', 4660, 'telos'], + [TLOS_SYMBOL, TLOS_SYMBOL, '0x193f4A4a6ea24102F49b931DEeeb931f6E32405d', 18, 'polygon', 4660, 'telos'], + [TLOS_SYMBOL, TLOS_SYMBOL, '0x193f4A4a6ea24102F49b931DEeeb931f6E32405d', 18, 'bsc', 4660, 'telos'], + [TLOS_SYMBOL, TLOS_SYMBOL, '0xed667dC80a45b77305Cc395DB56D997597Dc6DdD', 18, 'avalanche', 4660, 'telos'], + [TLOS_SYMBOL, TLOS_SYMBOL, '0x193f4A4a6ea24102F49b931DEeeb931f6E32405d', 18, 'arbitrum', 4660, 'telos'], // USDC ['USDC', 'USDC', '0x8D97Cea50351Fb4329d591682b148D43a0C3611b', 6, 'telos', 3408, 'usd-coin'], From 502176fa2acc8bd2e319171f11aa5a60d058e68c Mon Sep 17 00:00:00 2001 From: tomtomcrypto Date: Fri, 17 May 2024 14:41:18 +0000 Subject: [PATCH 24/25] more new deploy test --- src/config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.ts b/src/config.ts index 7c6df86..95a83b1 100644 --- a/src/config.ts +++ b/src/config.ts @@ -305,5 +305,5 @@ type NativeOftConfig = { export const telosNativeOft: NativeOftConfig = { bridge: {address: '0x9c5ebCbE531aA81bD82013aBF97401f5C6111d76', chainId: ChainId.TELOS, chainListId: ChainListId.TELOS, rpc: 'https://mainnet.telos.net/evm', abi: bridgeAbi}, token: new Coin(ChainId.TELOS, 18, TLOS_SYMBOL), - proxy: {chainId: ChainId.TELOS, address: '0x685ae711Ba61084881fd9431095B6B6697573c73'} + proxy: {chainId: ChainId.TELOS, address: '0x02Ea28694Ae65358Be92bAFeF5Cb8C211f33Db1A'} } From b6d99da087a443f736176b8b2e401deaa3cb2dc0 Mon Sep 17 00:00:00 2001 From: tomtomcrypto Date: Mon, 20 May 2024 09:39:56 +0000 Subject: [PATCH 25/25] merge master --- src/element.tsx | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/element.tsx b/src/element.tsx index 085e9f9..797f18e 100644 --- a/src/element.tsx +++ b/src/element.tsx @@ -29,7 +29,7 @@ const failoverProvider = createFailoverProviderFactory(); const multicallProvider = createMulticallProviderFactory(failoverProvider); class LzTrackerElement extends HTMLElement { - private root: Root = null!; + private root: Root | undefined; connectedCallback() { this.root = createRoot(this); @@ -37,11 +37,13 @@ class LzTrackerElement extends HTMLElement { } private render() { - this.root.render( - - - , - ); + if (this.root) { + this.root.render( + + + , + ); + } } }