Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Feat/portal poc #39

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import { ListButtonsColumn } from '../ListButtonsColumn';
import { ListItemUsedAsCollateral } from '../ListItemUsedAsCollateral';
import { ListItemWrapper } from '../ListItemWrapper';
import { ListValueColumn } from '../ListValueColumn';
import { useWeb3React } from '@web3-react/core';
import { BigNumber, constants, Contract, providers } from 'ethers';
import { useWeb3Context } from 'src/libs/hooks/useWeb3Context';
import { PortalSend, PortalSendABI } from '../../../../utils/contracts/PortalSend';
import { ERC20, ERC20ABI } from '../../../../utils/contracts/ERC20';
import { ChainId } from 'src/ui-config/networksConfig';

export const SuppliedPositionsListItem = ({
reserve,
Expand All @@ -28,6 +34,9 @@ export const SuppliedPositionsListItem = ({
const { openSupply, openWithdraw, openCollateralChange, openSwap } = useModalContext();
const { debtCeiling } = useAssetCaps();
const isSwapButton = isFeatureEnabled.liquiditySwap(currentMarketData);
const { library: provider } = useWeb3React<providers.Web3Provider>();
const { currentAccount } = useWeb3Context();
const { reserves } = useAppDataContext();

const canBeEnabledAsCollateral =
!debtCeiling.isMaxed &&
Expand All @@ -36,6 +45,76 @@ export const SuppliedPositionsListItem = ({
user.isolatedReserve?.underlyingAsset === reserve.underlyingAsset ||
(reserve.isIsolated && user.totalCollateralMarketReferenceCurrency === '0'));

const doPortalSend = async (underlyingAsset: string) => {
console.log("underlyingAsset", underlyingAsset);
const portalSender = currentMarketData.addresses.PORTAL_SENDER;
console.log("portalSender", portalSender);
const signer = provider?.getSigner(currentAccount);
const portalSendContract = new Contract(
portalSender!,
PortalSendABI,
signer
) as PortalSend;

const aTokenAddress = reserves.filter((item) => item.symbol === 'WETH')[0].aTokenAddress;
const asset_address = reserves.filter((item) => item.symbol === 'WETH')[0].underlyingAsset;

console.log("aTokenAddress", aTokenAddress);
console.log("asset_address", asset_address);

const aTokenInstance = new Contract(aTokenAddress, ERC20ABI, signer) as ERC20;


const approvalAmt = await aTokenInstance.allowance(
currentAccount,
portalSender!
);

// console.log("approvalAmt", approvalAmt);
if (approvalAmt.eq(BigNumber.from('0'))) {
console.log("approvalAmt is 0");
const aTokenTx = await aTokenInstance.approve(
portalSender!,
constants.MaxUint256.toString()
);
await aTokenTx.wait(1);
// console.log(aTokenTx);
}



const sendAmount = 0.01 * Math.pow(10, 18);
const relayFees = 0.000001 * Math.pow(10, 18);

// console.log("sendAmount", sendAmount);
// console.log("relayFees", relayFees);

// log all params
// console.log("ChainId", currentMarketData.chainId === ChainId.amoy ?
// "Arbitrum" : "Amoy");
// console.log("asset_address", asset_address);
// console.log("sendAmount", sendAmount.toString());
// console.log("relayFees", relayFees.toString());
// console.log("currentAccount", currentAccount);

const tx = await portalSendContract.bridgeTokens(
currentMarketData.chainId === ChainId.amoy ?
"Arbitrum" : "Amoy",
currentAccount,
asset_address.trim(),
sendAmount.toString(),
relayFees.toString(),
);

console.log("tx", tx);

await tx.wait(1);
console.log(tx);

// const portalSend = getPortalSend(underlyingAsset);
// portalSend.withdraw();
}

return (
<ListItemWrapper
symbol={reserve.symbol}
Expand All @@ -44,9 +123,8 @@ export const SuppliedPositionsListItem = ({
detailsAddress={underlyingAsset}
currentMarket={currentMarket}
frozen={reserve.isFrozen}
data-cy={`dashboardSuppliedListItem_${reserve.symbol.toUpperCase()}_${
canBeEnabledAsCollateral && usageAsCollateralEnabledOnUser ? 'Collateral' : 'NoCollateral'
}`}
data-cy={`dashboardSuppliedListItem_${reserve.symbol.toUpperCase()}_${canBeEnabledAsCollateral && usageAsCollateralEnabledOnUser ? 'Collateral' : 'NoCollateral'
}`}
showSupplyCapTooltips
showDebtCeilingTooltips
>
Expand Down Expand Up @@ -84,6 +162,17 @@ export const SuppliedPositionsListItem = ({
<Trans>Withdraw</Trans>
</Button>

{(reserve.symbol === 'ETH' || reserve.symbol === 'WETH') && (
<Button
disabled={!isActive || isFrozen}
variant="outlined"
onClick={() => doPortalSend(underlyingAsset)}
data-cy={`swapButton`}
>
<Trans>Move</Trans>
</Button>
)}

{isSwapButton ? (
<Button
disabled={!isActive || isFrozen}
Expand Down
43 changes: 43 additions & 0 deletions src/ui-config/marketsConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export type MarketDataType = {
CHAINLOG?: string;
SAVINGS_DAI?: string;
V3_MIGRATOR?: string;
PORTAL_SENDER?: string;
};
faucetUrl: string;
/**
Expand All @@ -53,6 +54,8 @@ export type MarketDataType = {

export enum CustomMarket {
etherlink_testnet = 'etherlink_testnet',
arb_sepolia = 'arb_sepolia',
polygon_amoy = 'polygon_amoy',
}

export const marketsData: {
Expand All @@ -77,4 +80,44 @@ export const marketsData: {
},
faucetUrl: 'https://faucet.plend.finance/receiveFaucetTokens',
},
[CustomMarket.arb_sepolia]: {
marketTitle: 'Arbitrum Sepolia',
chainId: 421614, //ChainId.etherlink_testnet,
v3: true,
enabledFeatures: {
liquiditySwap: false,
collateralRepay: false,
faucet: false,
},
addresses: {
LENDING_POOL_ADDRESS_PROVIDER: '0xfAF21dcB6185571128306B2ffAdef9600cF6E922',
LENDING_POOL: '0xa8b69d6fE496554d0292D058aDd7DC858CA95E5F',
WALLET_BALANCE_PROVIDER: '0xBAF39030C44Ef4E959aFb47F1B7820F562F4CC94',
UI_POOL_DATA_PROVIDER: '0x9C937bf9377Cf90Eea5Dbe3aA2F101E286958509',
UI_INCENTIVE_DATA_PROVIDER: '0xeFcDF7327c897812f2e09442a579Db942F2486ba',
WETH_GATEWAY: '0xC947242338Eb580E2F8212586755F36D20449153',
PORTAL_SENDER: '0x4923c0ccb6E11B75f80aFB3707b49EAbd461Db23',
},
faucetUrl: 'https://faucet.plend.finance/receiveFaucetTokens',
},
[CustomMarket.polygon_amoy]: {
marketTitle: 'Polygon Amoy',
chainId: 80002, //ChainId.etherlink_testnet,
v3: true,
enabledFeatures: {
liquiditySwap: false,
collateralRepay: false,
faucet: false,
},
addresses: {
LENDING_POOL_ADDRESS_PROVIDER: '0xb764c672f31A83B3929845E737DB6F20928890C9',
LENDING_POOL: '0x1fe68e15Ec31894501667129615117f5AA37fa68',
WALLET_BALANCE_PROVIDER: '0x14D5EA200025011533cB5A5954Ab3e08116EddDC',
UI_POOL_DATA_PROVIDER: '0x1b8A658e134883194A16c85622Ad35ceE14c46F8',
UI_INCENTIVE_DATA_PROVIDER: '0x855FEEf492CA6Da186a4F4F98e9D5B8b689E7aAA',
WETH_GATEWAY: '0x56130f7f03600FC86aa3c49C72d7e3C7C3b3394E',
PORTAL_SENDER: '0xC590F21651cF0370b803Ba2ee4B493213Ef15c80',
},
faucetUrl: 'https://faucet.plend.finance/receiveFaucetTokens',
},
} as const;
27 changes: 27 additions & 0 deletions src/ui-config/networksConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,15 @@ export type BaseNetworkConfig = Omit<NetworkConfig, 'explorerLinkBuilder'>;
export enum ChainId {
mainnet = 1,
etherlink_testnet = 128123,
arb_sepolia = 421614,
amoy = 80002,
}

export const ChainIdToNetwork: Record<number, string> = {
1: 'mainnet',
128123: 'etherlink_testnet',
421614: 'arb_sepolia',
80002: 'amoy',
};

export const networkConfigs: Record<string, BaseNetworkConfig> = {
Expand Down Expand Up @@ -94,4 +98,27 @@ export const networkConfigs: Record<string, BaseNetworkConfig> = {
isTestnet: true,
networkLogoPath: '/icons/networks/etherlink.svg',
},
[ChainId.arb_sepolia]: {
name: 'Arbitrum Sepolia',
publicJsonRPCUrl: ['https://arb-sepolia.g.alchemy.com/v2/yCPtGQdadgolaqzEQN5WJUt50kGyM939'],
publicJsonRPCWSUrl: 'wss://arb-sepolia.g.alchemy.com/v2/yCPtGQdadgolaqzEQN5WJUt50kGyM939',
baseUniswapAdapter: '0x0',
baseAssetSymbol: 'ETH',
wrappedBaseAssetSymbol: 'WETH',
baseAssetDecimals: 18,
explorerLink: 'https://sepolia.arbiscan.io',
isTestnet: true,
networkLogoPath: '/icons/networks/arbitrum.svg',
},
[ChainId.amoy]: {
name: 'Amoy',
publicJsonRPCUrl: ['https://rpc-amoy.polygon.technology'],
baseUniswapAdapter: '0x0',
baseAssetSymbol: 'MATIC',
wrappedBaseAssetSymbol: 'WMATIC',
baseAssetDecimals: 18,
explorerLink: 'https://amoyscan.io',
isTestnet: true,
networkLogoPath: '/icons/networks/polygon.svg',
},
} as const;
Loading