Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wet-poets-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@venusprotocol/evm": minor
---

add geo-block
2 changes: 2 additions & 0 deletions apps/evm/src/__mocks__/api/pools.json
Original file line number Diff line number Diff line change
Expand Up @@ -5729,6 +5729,7 @@
"name": "USDT",
"symbol": "USDT",
"decimals": 6,
"gatedCountries": ["FR"],
"createdAt": "2025-07-08T13:47:41.000Z",
"updatedAt": "2025-07-08T13:47:41.000Z",
"tokenPrices": [
Expand Down Expand Up @@ -5921,6 +5922,7 @@
"name": "BNB",
"symbol": "BNB",
"decimals": 18,
"restrictedCountries": ["FR"],
"createdAt": "2025-07-08T13:47:41.000Z",
"updatedAt": "2025-07-08T13:47:41.000Z",
"tokenPrices": [
Expand Down
8 changes: 8 additions & 0 deletions apps/evm/src/__mocks__/models/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ export const assetData: Asset[] = [
extraInfoUrl: 'https://fake.url',
},
],
isGated: false,
isRestricted: false,
},
{
vToken: vUsdc,
Expand Down Expand Up @@ -180,6 +182,8 @@ export const assetData: Asset[] = [
],
supplyPointDistributions: [],
borrowPointDistributions: [],
isRestricted: false,
isGated: false,
},
{
vToken: vUsdtCorePool,
Expand Down Expand Up @@ -272,6 +276,8 @@ export const assetData: Asset[] = [
extraInfoUrl: 'https://fake.url',
},
],
isGated: true,
isRestricted: false,
},
{
vToken: vBusdCorePool,
Expand Down Expand Up @@ -376,5 +382,7 @@ export const assetData: Asset[] = [
},
],
borrowPointDistributions: [],
isGated: false,
isRestricted: true,
},
];
25 changes: 18 additions & 7 deletions apps/evm/src/__mocks__/models/trade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,21 @@ import fakeAddress, { altAddress } from './address';
import { poolData } from './pools';

const pool = poolData[0];
const xvsAsset = pool.assets[0];
const usdcAsset = pool.assets[1];
const usdtAsset = pool.assets[2];
const busdAsset = pool.assets[3];
const tradePool = {
...pool,
assets: pool.assets.map(asset =>
asset.vToken.address === pool.assets[3].vToken.address
? {
...asset,
isRestricted: false,
}
: asset,
),
};
const xvsAsset = tradePool.assets[0];
const usdcAsset = tradePool.assets[1];
const usdtAsset = tradePool.assets[2];
const busdAsset = tradePool.assets[3];

export const apiTradePositions: ApiTradePosition[] = [
{
Expand Down Expand Up @@ -109,7 +120,7 @@ export const apiTradePositions: ApiTradePosition[] = [

export const tradePositions: TradePosition[] = [
formatToTradePosition({
pool,
pool: tradePool,
chainId: busdAsset.vToken.underlyingToken.chainId,
positionAccountAddress: fakeAddress,
dsaVTokenAddress: xvsAsset.vToken.address,
Expand All @@ -128,7 +139,7 @@ export const tradePositions: TradePosition[] = [
unrealizedPnlPercentage: 0,
})!,
formatToTradePosition({
pool,
pool: tradePool,
chainId: busdAsset.vToken.underlyingToken.chainId,
positionAccountAddress: altAddress,
dsaVTokenAddress: usdcAsset.vToken.address,
Expand All @@ -147,7 +158,7 @@ export const tradePositions: TradePosition[] = [
unrealizedPnlPercentage: 1.2,
})!,
formatToTradePosition({
pool,
pool: tradePool,
chainId: usdtAsset.vToken.underlyingToken.chainId,
positionAccountAddress: altAddress,
dsaVTokenAddress: usdcAsset.vToken.address,
Expand Down
11 changes: 11 additions & 0 deletions apps/evm/src/clients/api/__mocks__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,17 @@ export const useGetXvsVaultUserPendingWithdrawalsFromBeforeUpgrade = vi.fn(() =>
}),
);

export const getIpLocation = vi.fn(async () => ({
countryCode: 'US',
}));
export const useGetIpLocation = vi.fn((options?: Partial<QueryObserverOptions>) =>
useQuery({
queryKey: [FunctionKey.GET_IP_LOCATION],
queryFn: getIpLocation,
...options,
}),
);

export const useGetPools = vi.fn(() => ({
isLoading: false,
data: {
Expand Down
1 change: 1 addition & 0 deletions apps/evm/src/clients/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export * from './queries/getVenusVaiVaultDailyRate/useGetVenusVaiVaultDailyRate'
export * from './queries/useGetAsset';

export * from './queries/useGetPools';
export * from './queries/useGetIpLocation';

export * from './queries/useGetPool';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { ChainId } from 'types';
import type { ApiTokenPrice, ChainId } from 'types';
import { restService } from 'utilities';
import type { Address } from 'viem';
import type { ApiTokenPrice } from '../../useGetPools/getPools/getApiPools';

export interface GetApiTokenPriceInput {
tokenAddresses: string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import { logError } from 'libs/errors';
import { ChainId } from 'types';
import { formatToTradePosition, restService } from 'utilities';
import { type GetRawTradePositionsInput, getRawTradePositions } from '..';
import { getPools } from '../../useGetPools/getPools';
import { getPools } from '../../useGetPools/useGetPoolsQuery/getPools';

vi.mock('utilities/restService');
vi.mock('../../useGetPools/getPools', () => ({
vi.mock('../../useGetPools/useGetPoolsQuery/getPools', () => ({
getPools: vi.fn(),
}));
vi.mock('libs/errors', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
formatToTradePosition,
restService,
} from 'utilities';
import { getPools } from '../useGetPools/getPools';
import { getPools } from '../useGetPools/useGetPoolsQuery/getPools';
import type {
GetApiTradePositionsOutput,
GetRawTradePositionsInput,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ exports[`getSimulatedPool > recalculates Prime APYs when a Prime market is mutat
"isBorrowable": true,
"isBorrowableByUser": true,
"isCollateralOfUser": true,
"isGated": false,
"isProtectionModeEnabled": false,
"isRestricted": false,
"liquidationPenaltyPercentage": 4,
"liquidationThresholdPercentage": 50,
"liquidityCents": "8036465875",
Expand Down Expand Up @@ -168,7 +170,9 @@ exports[`getSimulatedPool > recalculates Prime APYs when a Prime market is mutat
"isBorrowable": false,
"isBorrowableByUser": false,
"isCollateralOfUser": false,
"isGated": false,
"isProtectionModeEnabled": false,
"isRestricted": false,
"liquidationPenaltyPercentage": 4,
"liquidationThresholdPercentage": 80,
"liquidityCents": "1702951959",
Expand Down Expand Up @@ -310,7 +314,9 @@ exports[`getSimulatedPool > recalculates Prime APYs when a Prime market is mutat
"isBorrowable": true,
"isBorrowableByUser": true,
"isCollateralOfUser": true,
"isGated": true,
"isProtectionModeEnabled": false,
"isRestricted": false,
"liquidationPenaltyPercentage": 4,
"liquidationThresholdPercentage": 80,
"liquidityCents": "5534102886",
Expand Down Expand Up @@ -444,7 +450,9 @@ exports[`getSimulatedPool > recalculates Prime APYs when a Prime market is mutat
"isBorrowable": true,
"isBorrowableByUser": true,
"isCollateralOfUser": false,
"isGated": false,
"isProtectionModeEnabled": false,
"isRestricted": true,
"liquidationPenaltyPercentage": 4,
"liquidationThresholdPercentage": 80,
"liquidityCents": "3654492935",
Expand Down Expand Up @@ -794,7 +802,9 @@ exports[`getSimulatedPool > returns simulated pool with updated asset balances w
"isBorrowable": true,
"isBorrowableByUser": true,
"isCollateralOfUser": true,
"isGated": false,
"isProtectionModeEnabled": false,
"isRestricted": false,
"liquidationPenaltyPercentage": 4,
"liquidationThresholdPercentage": 50,
"liquidityCents": "8036465875",
Expand Down Expand Up @@ -920,7 +930,9 @@ exports[`getSimulatedPool > returns simulated pool with updated asset balances w
"isBorrowable": false,
"isBorrowableByUser": false,
"isCollateralOfUser": false,
"isGated": false,
"isProtectionModeEnabled": false,
"isRestricted": false,
"liquidationPenaltyPercentage": 4,
"liquidationThresholdPercentage": 80,
"liquidityCents": "1702951959",
Expand Down Expand Up @@ -1062,7 +1074,9 @@ exports[`getSimulatedPool > returns simulated pool with updated asset balances w
"isBorrowable": true,
"isBorrowableByUser": true,
"isCollateralOfUser": true,
"isGated": true,
"isProtectionModeEnabled": false,
"isRestricted": false,
"liquidationPenaltyPercentage": 4,
"liquidationThresholdPercentage": 80,
"liquidityCents": "5534102886",
Expand Down Expand Up @@ -1196,7 +1210,9 @@ exports[`getSimulatedPool > returns simulated pool with updated asset balances w
"isBorrowable": true,
"isBorrowableByUser": true,
"isCollateralOfUser": false,
"isGated": false,
"isProtectionModeEnabled": false,
"isRestricted": true,
"liquidationPenaltyPercentage": 4,
"liquidationThresholdPercentage": 80,
"liquidityCents": "3654492935",
Expand Down Expand Up @@ -1546,7 +1562,9 @@ exports[`getSimulatedPool > returns simulated pool with updated asset balances w
"isBorrowable": true,
"isBorrowableByUser": true,
"isCollateralOfUser": true,
"isGated": false,
"isProtectionModeEnabled": false,
"isRestricted": false,
"liquidationPenaltyPercentage": 4,
"liquidationThresholdPercentage": 50,
"liquidityCents": "8036465875",
Expand Down Expand Up @@ -1672,7 +1690,9 @@ exports[`getSimulatedPool > returns simulated pool with updated asset balances w
"isBorrowable": false,
"isBorrowableByUser": false,
"isCollateralOfUser": true,
"isGated": false,
"isProtectionModeEnabled": false,
"isRestricted": false,
"liquidationPenaltyPercentage": 4,
"liquidationThresholdPercentage": 80,
"liquidityCents": "1702951959",
Expand Down Expand Up @@ -1814,7 +1834,9 @@ exports[`getSimulatedPool > returns simulated pool with updated asset balances w
"isBorrowable": true,
"isBorrowableByUser": true,
"isCollateralOfUser": true,
"isGated": true,
"isProtectionModeEnabled": false,
"isRestricted": false,
"liquidationPenaltyPercentage": 4,
"liquidationThresholdPercentage": 80,
"liquidityCents": "5534102886",
Expand Down Expand Up @@ -1948,7 +1970,9 @@ exports[`getSimulatedPool > returns simulated pool with updated asset balances w
"isBorrowable": true,
"isBorrowableByUser": true,
"isCollateralOfUser": false,
"isGated": false,
"isProtectionModeEnabled": false,
"isRestricted": true,
"liquidationPenaltyPercentage": 4,
"liquidationThresholdPercentage": 80,
"liquidityCents": "3654492935",
Expand Down Expand Up @@ -2310,7 +2334,9 @@ exports[`getSimulatedPool > updates simulated VAI borrow balances when VAI mutat
"isBorrowable": true,
"isBorrowableByUser": true,
"isCollateralOfUser": true,
"isGated": false,
"isProtectionModeEnabled": false,
"isRestricted": false,
"liquidationPenaltyPercentage": 4,
"liquidationThresholdPercentage": 50,
"liquidityCents": "8036465875",
Expand Down Expand Up @@ -2436,7 +2462,9 @@ exports[`getSimulatedPool > updates simulated VAI borrow balances when VAI mutat
"isBorrowable": false,
"isBorrowableByUser": false,
"isCollateralOfUser": false,
"isGated": false,
"isProtectionModeEnabled": false,
"isRestricted": false,
"liquidationPenaltyPercentage": 4,
"liquidationThresholdPercentage": 80,
"liquidityCents": "1702951959",
Expand Down Expand Up @@ -2578,7 +2606,9 @@ exports[`getSimulatedPool > updates simulated VAI borrow balances when VAI mutat
"isBorrowable": true,
"isBorrowableByUser": true,
"isCollateralOfUser": true,
"isGated": true,
"isProtectionModeEnabled": false,
"isRestricted": false,
"liquidationPenaltyPercentage": 4,
"liquidationThresholdPercentage": 80,
"liquidityCents": "5534102886",
Expand Down Expand Up @@ -2712,7 +2742,9 @@ exports[`getSimulatedPool > updates simulated VAI borrow balances when VAI mutat
"isBorrowable": true,
"isBorrowableByUser": true,
"isCollateralOfUser": false,
"isGated": false,
"isProtectionModeEnabled": false,
"isRestricted": true,
"liquidationPenaltyPercentage": 4,
"liquidationThresholdPercentage": 80,
"liquidityCents": "3654492935",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ exports[`useGetAsset > returns the correct asset 1`] = `
"isBorrowable": true,
"isBorrowableByUser": true,
"isCollateralOfUser": true,
"isGated": false,
"isProtectionModeEnabled": false,
"isRestricted": false,
"liquidationPenaltyPercentage": 4,
"liquidationThresholdPercentage": 50,
"liquidityCents": "8036465875",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { waitFor } from '@testing-library/dom';
import type { Mock } from 'vitest';

import { renderHook } from 'testUtils/render';
import { useGetIpLocation } from '..';

const mockFetch = global.fetch as Mock;

describe('useGetIpLocation', () => {
it('fetches the user country code', async () => {
mockFetch.mockResolvedValue({
ok: true,
json: async () => ({
countryCode: 'FR',
}),
} satisfies Partial<Response>);

const { result } = renderHook(() => useGetIpLocation());

await waitFor(() =>
expect(result.current.data).toEqual({
countryCode: 'FR',
}),
);
});
});
Loading
Loading