-
Notifications
You must be signed in to change notification settings - Fork 1
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
Connext integration #3
base: main
Are you sure you want to change the base?
Changes from 3 commits
dad6850
fe6370a
4e377c8
62a6fd7
8939e94
8a8f32d
dd67042
428a3f7
69cf19f
74c9b07
ff1b7e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -724,4 +724,68 @@ export const getGhTokenListLogoUrl = (chainId: number, address: string) => | |
// oasis: 42262, | ||
|
||
export const UNSUPPORTED_WAGMI_CHAIN = [122, 128, 106, 42262]; | ||
|
||
export const SUPPORTED_CHAINS_BY_CONNEXT: Record<number, { domainId: string; name: string; network: string }> = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could extend de NetworkStruct type to add the domainId, and with that you would already have if it is mainnet or a testnet, plus all the names. Furthermore, i would assign keys here as |
||
1: { | ||
domainId: '6648936', | ||
// Ethereum Mainnet | ||
name: 'Ethereum', | ||
network: 'mainnet', | ||
}, | ||
10: { | ||
domainId: '1869640809', | ||
// Optimism | ||
name: 'Optimism', | ||
network: 'mainnet', | ||
}, | ||
100: { | ||
domainId: '6778479', | ||
// Gnosis Chain | ||
name: 'Gnosis', | ||
network: 'mainnet', | ||
}, | ||
137: { | ||
domainId: '1886350457', | ||
// Polygon | ||
name: 'Polygon', | ||
network: 'mainnet', | ||
}, | ||
420: { | ||
domainId: '1735356532', | ||
// Optimism-Goerli | ||
name: 'OptGoerli', | ||
network: 'testnet', | ||
}, | ||
42161: { | ||
domainId: '1634886255', | ||
// Arbitrum One | ||
name: 'Arbitrum', | ||
network: 'mainnet', | ||
}, | ||
421613: { | ||
domainId: '1734439522', | ||
// Arbitrum-Goerli | ||
name: 'ArbGoerli', | ||
network: 'testnet', | ||
}, | ||
5: { | ||
domainId: '1735353714', | ||
// Goerli | ||
name: 'Goerli', | ||
network: 'testnet', | ||
}, | ||
56: { | ||
domainId: '6450786', | ||
// BNB Chain | ||
name: 'BNB', | ||
network: 'mainnet', | ||
}, | ||
80001: { | ||
domainId: '9991', | ||
// Mumbai | ||
name: 'Mumbai', | ||
network: 'testnet', | ||
}, | ||
}; | ||
|
||
/* eslint-enable */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ import TokenIcon from 'common/token-icon'; | |
import useSelectedNetwork from 'hooks/useSelectedNetwork'; | ||
import Select from '@mui/material/Select'; | ||
import MenuItem from '@mui/material/MenuItem'; | ||
import { Button } from '@mui/material'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use our button please from |
||
// import useWalletService from 'hooks/useWalletService'; | ||
|
||
const StyledGrid = styled(Grid)<{ $show: boolean }>` | ||
|
@@ -118,6 +119,7 @@ interface SwapFirstStepProps { | |
buttonToShow: React.ReactNode; | ||
fromValueUsdPrice: number; | ||
onChangeNetwork: (chainId: number) => void; | ||
handlePolygonDestinantion: () => void; | ||
} | ||
|
||
const SwapFirstStep = React.forwardRef<HTMLDivElement, SwapFirstStepProps>((props, ref) => { | ||
|
@@ -139,6 +141,7 @@ const SwapFirstStep = React.forwardRef<HTMLDivElement, SwapFirstStepProps>((prop | |
show, | ||
fromValueUsdPrice, | ||
onChangeNetwork, | ||
handlePolygonDestinantion, | ||
} = props; | ||
|
||
// const walletService = useWalletService(); | ||
|
@@ -244,6 +247,11 @@ const SwapFirstStep = React.forwardRef<HTMLDivElement, SwapFirstStepProps>((prop | |
<TokenButton token={to} onClick={() => startSelectingCoin(to || emptyTokenWithAddress('to'))} /> | ||
</StyledTokenContainer> | ||
</StyledTokensContainer> | ||
<div style={{ width: '100%', display: 'flex', justifyContent: 'end' }}> | ||
<Button onClick={() => handlePolygonDestinantion()} style={{ display: 'flex', marginTop: '10px' }}> | ||
Select Polygon | ||
</Button> | ||
</div> | ||
</StyledContentContainer> | ||
</Grid> | ||
<Grid item xs={12}> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,6 +119,8 @@ interface SwapProps { | |
setFromYield: (newYield?: null | YieldOption) => void; | ||
setToYield: (newYield?: null | YieldOption) => void; | ||
handleChangeNetwork: (newChainId: number) => void; | ||
handlePolygonDestinantion: () => void; | ||
isPolygonDestnantion: boolean; | ||
} | ||
|
||
const Swap = ({ | ||
|
@@ -144,6 +146,8 @@ const Swap = ({ | |
setFromYield, | ||
setToYield, | ||
handleChangeNetwork, | ||
isPolygonDestnantion, | ||
handlePolygonDestinantion, | ||
}: SwapProps) => { | ||
const web3Service = useWeb3Service(); | ||
const containerRef = React.useRef(null); | ||
|
@@ -363,15 +367,21 @@ const Swap = ({ | |
), | ||
}); | ||
trackEvent('DCA - Create position submitting'); | ||
const result = await positionService.deposit( | ||
// change it to xCall here. | ||
// eslint-disable-next-line no-console | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please don't disable these lint-rules, its fine if it fails the lint action since later you can remove them There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Noted ✅ |
||
console.log('Doing xcall', { from, to, fromValue, frequencyType, frequencyValue, fromYield, toYield }); | ||
const result = await positionService.xCallDeposit( | ||
from, | ||
to, | ||
fromValue, | ||
frequencyType, | ||
frequencyValue, | ||
shouldEnableYield ? fromYield?.tokenAddress : undefined, | ||
shouldEnableYield ? toYield?.tokenAddress : undefined | ||
shouldEnableYield ? toYield?.tokenAddress : undefined, | ||
isPolygonDestnantion | ||
); | ||
// eslint-disable-next-line no-console | ||
console.log(result, 'result from Xcall from button'); | ||
trackEvent('DCA - Create position submitted'); | ||
const hubAddress = await contractService.getHUBAddress(); | ||
const companionAddress = await contractService.getHUBCompanionAddress(); | ||
|
@@ -1116,6 +1126,7 @@ const Swap = ({ | |
show={showFirstStep} | ||
fromValueUsdPrice={fromValueUsdPrice} | ||
onChangeNetwork={handleChangeNetwork} | ||
handlePolygonDestinantion={handlePolygonDestinantion} | ||
/> | ||
</Slide> | ||
<Slide | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,96 @@ | ||||||||||||||||||
import { getPoolFeeForUniV3, getXCallCallData, prepareSwapAndXCall } from '@connext/chain-abstraction'; | ||||||||||||||||||
import { DestinationCallDataParams, Swapper, SwapAndXCallParams } from '@connext/chain-abstraction/dist/types'; | ||||||||||||||||||
import { SdkConfig, create } from '@connext/sdk'; | ||||||||||||||||||
import { RAW_NETWORKS, SUPPORTED_CHAINS_BY_CONNEXT } from 'config'; | ||||||||||||||||||
import WalletService from './walletService'; | ||||||||||||||||||
|
||||||||||||||||||
interface DomainID { | ||||||||||||||||||
[key: number]: string; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
export default class ConnextService { | ||||||||||||||||||
sdkConfig: SdkConfig; | ||||||||||||||||||
|
||||||||||||||||||
walletService: WalletService; | ||||||||||||||||||
|
||||||||||||||||||
destinantionChainID: number; | ||||||||||||||||||
|
||||||||||||||||||
constructor(walletService: WalletService, destinantionChainID: number) { | ||||||||||||||||||
this.walletService = walletService; | ||||||||||||||||||
this.destinantionChainID = destinantionChainID; | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be no longer neededright? |
||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
getRPCURL(chainID: number) { | ||||||||||||||||||
const network = Object.values(RAW_NETWORKS).find((net) => net.chainId === chainID); | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to use RAW_NETWORKS. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure |
||||||||||||||||||
return network?.rpc[0]; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
async getCalculatedRelayerFees(originDomain: string, destinationDomain: string) { | ||||||||||||||||||
const domainConfig: { [domainId: string]: { providers: string[] } } = {}; | ||||||||||||||||||
|
||||||||||||||||||
const domainChainIds = Object.entries(SUPPORTED_CHAINS_BY_CONNEXT) | ||||||||||||||||||
.filter(([key]) => typeof key === 'number') | ||||||||||||||||||
.map(([key, value]) => ({ domainId: value.domainId, chainId: key })); | ||||||||||||||||||
|
||||||||||||||||||
domainChainIds.forEach((obj) => { | ||||||||||||||||||
domainConfig[obj.domainId] = { providers: [this.getRPCURL(parseInt(obj.chainId, 10)) as string] }; | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. obj.chainId is already a string, no need to parse it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should check that |
||||||||||||||||||
}); | ||||||||||||||||||
|
||||||||||||||||||
this.sdkConfig = { | ||||||||||||||||||
signerAddress: this.walletService.account as string, | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make sense, we can change that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bump to this |
||||||||||||||||||
network: 'mainnet', // can change it to testnet as well | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this parameter for? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For initing the connext core SDK There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right but I mean, what does it imply if it is "mainnet"? or "testnet"? shouldn't it work the same regardless of what type of network it is? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So for initialising the SDK we have to define if this is for |
||||||||||||||||||
chains: domainConfig, | ||||||||||||||||||
}; | ||||||||||||||||||
const { sdkBase } = await create(this.sdkConfig); | ||||||||||||||||||
const relayerFees = await sdkBase.estimateRelayerFee({ | ||||||||||||||||||
originDomain, | ||||||||||||||||||
destinationDomain, | ||||||||||||||||||
isHighPriority: true, | ||||||||||||||||||
}); | ||||||||||||||||||
return relayerFees.toString(); | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
async getPoolFeeForUniV3Helper(domainID: string, token0: string, token1: string, rpcURL: string) { | ||||||||||||||||||
if (!rpcURL || !token0 || !token1) { | ||||||||||||||||||
return null; | ||||||||||||||||||
} | ||||||||||||||||||
const poolFee = await getPoolFeeForUniV3(domainID, rpcURL, token0, token1); | ||||||||||||||||||
return poolFee; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
async getXCallCallDataHelper(domainID: string, forwardCallData: string, params: DestinationCallDataParams) { | ||||||||||||||||||
const swapper = Swapper.UniV3; | ||||||||||||||||||
const callDataForMeantTarget = await getXCallCallData(domainID, swapper, forwardCallData, params); | ||||||||||||||||||
return callDataForMeantTarget; | ||||||||||||||||||
} | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bump |
||||||||||||||||||
|
||||||||||||||||||
async prepareSwapAndXCallHelper(swapAndXCallParams: SwapAndXCallParams, signerAddress: string) { | ||||||||||||||||||
const txRequest = await prepareSwapAndXCall(swapAndXCallParams, signerAddress); | ||||||||||||||||||
return txRequest; | ||||||||||||||||||
} | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bump |
||||||||||||||||||
|
||||||||||||||||||
getDomainID(networkName: number): string { | ||||||||||||||||||
const domainID: DomainID = { | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this already on SUPPERTED_CHAINS_BY_CONNEXT? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding it as a class method so that it can be fetched by connextService itself, will move the supported chains by connext here as well There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bump to this |
||||||||||||||||||
1: '6648936', | ||||||||||||||||||
137: '1886350457', | ||||||||||||||||||
10: '1869640809', | ||||||||||||||||||
42161: '1634886255', | ||||||||||||||||||
100: '6778479', | ||||||||||||||||||
56: '6450786', | ||||||||||||||||||
}; | ||||||||||||||||||
|
||||||||||||||||||
return domainID[networkName]; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
getNativeUSDCAddress(networkName: number) { | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will connext only work with USDC? |
||||||||||||||||||
const USDC_ADDRESS: DomainID = { | ||||||||||||||||||
1: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', | ||||||||||||||||||
137: '0x2791bca1f2de4661ed88a30c99a7a9449aa84174', | ||||||||||||||||||
10: '0x7F5c764cBc14f9669B88837ca1490cCa17c31607', | ||||||||||||||||||
42161: '0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8', | ||||||||||||||||||
100: '0xDDAfbb505ad214D7b80b1f830fcCc89B60fb7A83', | ||||||||||||||||||
56: '0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d', | ||||||||||||||||||
}; | ||||||||||||||||||
return USDC_ADDRESS[networkName]; | ||||||||||||||||||
} | ||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are all of these new dependencies needed?