Skip to content

Commit

Permalink
refactor: use correct address for native token (#2925)
Browse files Browse the repository at this point in the history
  • Loading branch information
therealemjy committed Jul 9, 2024
1 parent b190746 commit 3e0a942
Show file tree
Hide file tree
Showing 21 changed files with 57 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .changeset/tasty-birds-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@venusprotocol/evm": minor
---

use correct address for native token
3 changes: 2 additions & 1 deletion apps/evm/src/__mocks__/contracts/venusLens.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { NATIVE_TOKEN_ADDRESS } from 'constants/address';
import { BigNumber as BN } from 'ethers';

import type { VenusLens } from 'libs/contracts';
Expand Down Expand Up @@ -103,7 +104,7 @@ const venusLensResponses: {
isListed: true,
pausedActions: BN.from('0x00'),
collateralFactorMantissa: BN.from('0x0b1a2bc2ec500000'),
underlyingAssetAddress: '0x0000000000000000000000000000000000000000',
underlyingAssetAddress: NATIVE_TOKEN_ADDRESS,
vTokenDecimals: BN.from('0x08'),
underlyingDecimals: BN.from('0x12'),
venusBorrowSpeed: BN.from('0xb90983f22ef200'),
Expand Down
3 changes: 2 additions & 1 deletion apps/evm/src/__mocks__/models/tokens.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { NATIVE_TOKEN_ADDRESS } from 'constants/address';
import bnbLogo from 'libs/tokens/img/bnb.svg';
import busdLogo from 'libs/tokens/img/busd.svg';
import ethLogo from 'libs/tokens/img/eth.svg';
Expand Down Expand Up @@ -35,7 +36,7 @@ export const vrt: Token = {
};

export const bnb: Token = {
address: '0x0000000000000000000000000000000000000000',
address: NATIVE_TOKEN_ADDRESS,
isNative: true,
decimals: 18,
symbol: 'BNB',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import convertMantissaToTokens from 'utilities/convertMantissaToTokens';
import findTokenByAddress from 'utilities/findTokenByAddress';
import { getDisabledTokenActions } from 'utilities/getDisabledTokenActions';

import { NATIVE_TOKEN_ADDRESS, NULL_ADDRESS } from 'constants/address';
import type { GetTokenBalancesOutput } from '../../getTokenBalances';
import type { GetRewardsDistributorSettingsMappingOutput } from '../getRewardsDistributorSettingsMapping';
import type { GetTokenPriceDollarsMappingOutput } from '../getTokenPriceDollarsMapping';
Expand Down Expand Up @@ -62,10 +63,17 @@ const formatToPools = ({
return acc;
}

const underlyingTokenAddress =
// If underlying asset address is the null address, this means the VToken has no underlying
// token because it is a native token
areAddressesEqual(vTokenMetaData.underlyingAssetAddress, NULL_ADDRESS)
? NATIVE_TOKEN_ADDRESS
: vTokenMetaData.underlyingAssetAddress;

// Retrieve underlying token record
const underlyingToken = findTokenByAddress({
tokens,
address: vTokenMetaData.underlyingAssetAddress,
address: underlyingTokenAddress,
});

if (!underlyingToken) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ exports[`getLegacyPool > returns core pool in the correct format 1`] = `
"decimals": 8,
"symbol": "vBNB",
"underlyingToken": {
"address": "0x0000000000000000000000000000000000000000",
"address": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
"asset": "/src/libs/tokens/img/bnb.svg",
"decimals": 18,
"isNative": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ exports[`getLegacyPool - Feature enabled: Prime > does not fetch Prime distribut
"decimals": 8,
"symbol": "vBNB",
"underlyingToken": {
"address": "0x0000000000000000000000000000000000000000",
"address": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
"asset": "/src/libs/tokens/img/bnb.svg",
"decimals": 18,
"isNative": true,
Expand Down Expand Up @@ -905,7 +905,7 @@ exports[`getLegacyPool - Feature enabled: Prime > fetches and formats Prime dist
"decimals": 8,
"symbol": "vBNB",
"underlyingToken": {
"address": "0x0000000000000000000000000000000000000000",
"address": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
"asset": "/src/libs/tokens/img/bnb.svg",
"decimals": 18,
"isNative": true,
Expand Down Expand Up @@ -1373,7 +1373,7 @@ exports[`getLegacyPool - Feature enabled: Prime > filters out Prime distribution
"decimals": 8,
"symbol": "vBNB",
"underlyingToken": {
"address": "0x0000000000000000000000000000000000000000",
"address": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
"asset": "/src/libs/tokens/img/bnb.svg",
"decimals": 18,
"isNative": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import type { GetTokenBalancesOutput } from 'clients/api';
import {
BSC_MAINNET_UNLISTED_TOKEN_ADDRESSES,
BSC_TESTNET_UNLISTED_TOKEN_ADDRESSES,
NATIVE_TOKEN_ADDRESS,
NULL_ADDRESS,
} from 'constants/address';
import { COMPOUND_DECIMALS, COMPOUND_MANTISSA } from 'constants/compoundMantissa';
import MAX_UINT256 from 'constants/maxUint256';
Expand Down Expand Up @@ -116,9 +118,16 @@ export const formatToPool = ({
return;
}

const underlyingTokenAddress =
// If underlying asset address is the null address, this means the VToken has no underlying
// token because it is a native token
areAddressesEqual(vTokenMetaData.underlyingAssetAddress, NULL_ADDRESS)
? NATIVE_TOKEN_ADDRESS
: vTokenMetaData.underlyingAssetAddress;

const underlyingToken = findTokenByAddress({
tokens,
address: vTokenMetaData.underlyingAssetAddress,
address: underlyingTokenAddress,
});

if (!underlyingToken) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ exports[`api/queries/getTokenBalances > returns token balances, including BNB, i
{
"balanceMantissa": "1000000000000000000",
"token": {
"address": "0x0000000000000000000000000000000000000000",
"address": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
"asset": "/src/libs/tokens/img/bnb.svg",
"decimals": 18,
"isNative": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ exports[`api/queries/getVTokens > returns the vTokens on success 1`] = `
"decimals": 8,
"symbol": "vBNB",
"underlyingToken": {
"address": "0x0000000000000000000000000000000000000000",
"address": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
"asset": "/src/libs/tokens/img/bnb.svg",
"decimals": 18,
"isNative": true,
Expand Down
1 change: 1 addition & 0 deletions apps/evm/src/constants/address.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const NULL_ADDRESS = '0x0000000000000000000000000000000000000000';
export const NATIVE_TOKEN_ADDRESS = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE';

// We do not list the following tokens in the tokens package because they are not meant to be listed
// on Venus. TODO: remove these once the tokens have been unlisted from contracts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ exports[`pages/Swap/useGetSwapInfo > exactAmountIn > returns swap in correct for
"exchangeRate": "0.499374217772215269",
"expectedToTokenAmountReceivedMantissa": "499374217772215269",
"fromToken": {
"address": "0x0000000000000000000000000000000000000000",
"address": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
"asset": "/src/libs/tokens/img/bnb.svg",
"decimals": 18,
"isNative": true,
Expand Down Expand Up @@ -41,7 +41,7 @@ exports[`pages/Swap/useGetSwapInfo > exactAmountOut > returns swap in correct fo
"exchangeRate": "0.49875",
"expectedFromTokenAmountSoldMantissa": "1002506265664160402",
"fromToken": {
"address": "0x0000000000000000000000000000000000000000",
"address": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
"asset": "/src/libs/tokens/img/bnb.svg",
"decimals": 18,
"isNative": true,
Expand Down
3 changes: 2 additions & 1 deletion apps/evm/src/libs/tokens/infos/commonTokens/arbitrumOne.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { NATIVE_TOKEN_ADDRESS } from 'constants/address';
import arbLogo from 'libs/tokens/img/arb.svg';
import ethLogo from 'libs/tokens/img/eth.svg';
import usdcLogo from 'libs/tokens/img/usdc.svg';
Expand All @@ -8,7 +9,7 @@ import xvsLogo from 'libs/tokens/img/xvs.svg';
import type { Token } from 'types';

const ethToken: Token = {
address: '0x0000000000000000000000000000000000000000',
address: NATIVE_TOKEN_ADDRESS,
decimals: 18,
symbol: 'ETH',
asset: ethLogo,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { NATIVE_TOKEN_ADDRESS } from 'constants/address';
import arbLogo from 'libs/tokens/img/arb.svg';
import ethLogo from 'libs/tokens/img/eth.svg';
import usdcLogo from 'libs/tokens/img/usdc.svg';
Expand All @@ -8,7 +9,7 @@ import xvsLogo from 'libs/tokens/img/xvs.svg';
import type { Token } from 'types';

const ethToken: Token = {
address: '0x0000000000000000000000000000000000000000',
address: NATIVE_TOKEN_ADDRESS,
decimals: 18,
symbol: 'ETH',
asset: ethLogo,
Expand Down
3 changes: 2 additions & 1 deletion apps/evm/src/libs/tokens/infos/commonTokens/bscMainnet.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { NATIVE_TOKEN_ADDRESS } from 'constants/address';
import aaveLogo from 'libs/tokens/img/aave.svg';
import adaLogo from 'libs/tokens/img/ada.svg';
import alpacaLogo from 'libs/tokens/img/alpaca.png';
Expand Down Expand Up @@ -52,7 +53,7 @@ import xvsLogo from 'libs/tokens/img/xvs.svg';
import type { Token } from 'types';

const bnbToken: Token = {
address: '0x0000000000000000000000000000000000000000',
address: NATIVE_TOKEN_ADDRESS,
decimals: 18,
symbol: 'BNB',
asset: bnbLogo,
Expand Down
3 changes: 2 additions & 1 deletion apps/evm/src/libs/tokens/infos/commonTokens/bscTestnet.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { NATIVE_TOKEN_ADDRESS } from 'constants/address';
import aaveLogo from 'libs/tokens/img/aave.svg';
import adaLogo from 'libs/tokens/img/ada.svg';
import alpacaLogo from 'libs/tokens/img/alpaca.png';
Expand Down Expand Up @@ -47,7 +48,7 @@ import xvsLogo from 'libs/tokens/img/xvs.svg';
import type { Token } from 'types';

const bnbToken: Token = {
address: '0x0000000000000000000000000000000000000000',
address: NATIVE_TOKEN_ADDRESS,
decimals: 18,
symbol: 'BNB',
asset: bnbLogo,
Expand Down
3 changes: 2 additions & 1 deletion apps/evm/src/libs/tokens/infos/commonTokens/ethereum.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { NATIVE_TOKEN_ADDRESS } from 'constants/address';
import crvLogo from 'libs/tokens/img/crv.svg';
import crvUsdLogo from 'libs/tokens/img/crvUsd.svg';
import daiLogo from 'libs/tokens/img/dai.svg';
Expand All @@ -18,7 +19,7 @@ import xvsLogo from 'libs/tokens/img/xvs.svg';
import type { Token } from 'types';

const ethToken: Token = {
address: '0x0000000000000000000000000000000000000000',
address: NATIVE_TOKEN_ADDRESS,
decimals: 18,
symbol: 'ETH',
asset: ethLogo,
Expand Down
3 changes: 2 additions & 1 deletion apps/evm/src/libs/tokens/infos/commonTokens/opBnbMainnet.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { NATIVE_TOKEN_ADDRESS } from 'constants/address';
import bnbLogo from 'libs/tokens/img/bnb.svg';
import btcbLogo from 'libs/tokens/img/btcb.svg';
import ethLogo from 'libs/tokens/img/eth.svg';
Expand All @@ -8,7 +9,7 @@ import xvsLogo from 'libs/tokens/img/xvs.svg';
import type { Token } from 'types';

const bnbToken: Token = {
address: '0x0000000000000000000000000000000000000000',
address: NATIVE_TOKEN_ADDRESS,
decimals: 18,
symbol: 'BNB',
asset: bnbLogo,
Expand Down
3 changes: 2 additions & 1 deletion apps/evm/src/libs/tokens/infos/commonTokens/opBnbTestnet.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { NATIVE_TOKEN_ADDRESS } from 'constants/address';
import bnbLogo from 'libs/tokens/img/bnb.svg';
import btcbLogo from 'libs/tokens/img/btcb.svg';
import ethLogo from 'libs/tokens/img/eth.svg';
Expand All @@ -7,7 +8,7 @@ import xvsLogo from 'libs/tokens/img/xvs.svg';
import type { Token } from 'types';

const bnbToken: Token = {
address: '0x0000000000000000000000000000000000000000',
address: NATIVE_TOKEN_ADDRESS,
decimals: 18,
symbol: 'BNB',
asset: bnbLogo,
Expand Down
3 changes: 2 additions & 1 deletion apps/evm/src/libs/tokens/infos/commonTokens/sepolia.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { NATIVE_TOKEN_ADDRESS } from 'constants/address';
import crvLogo from 'libs/tokens/img/crv.svg';
import crvUsdLogo from 'libs/tokens/img/crvUsd.svg';
import daiLogo from 'libs/tokens/img/dai.svg';
Expand All @@ -18,7 +19,7 @@ import xvsLogo from 'libs/tokens/img/xvs.svg';
import type { Token } from 'types';

const ethToken: Token = {
address: '0x0000000000000000000000000000000000000000',
address: NATIVE_TOKEN_ADDRESS,
decimals: 18,
symbol: 'ETH',
asset: ethLogo,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { NATIVE_TOKEN_ADDRESS } from 'constants/address';
import type { DisabledTokenAction } from '../../types';

export const disabledTokenActions: DisabledTokenAction[] = [
// BNB
{
address: '0x0000000000000000000000000000000000000000',
address: NATIVE_TOKEN_ADDRESS,
disabledActions: ['swapAndSupply'],
},
// vAAVE - Core pool
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { NATIVE_TOKEN_ADDRESS } from 'constants/address';
import type { DisabledTokenAction } from '../../types';

export const disabledTokenActions: DisabledTokenAction[] = [
// BNB
{
address: '0x0000000000000000000000000000000000000000',
address: NATIVE_TOKEN_ADDRESS,
disabledActions: ['swapAndSupply'],
},
];

0 comments on commit 3e0a942

Please sign in to comment.