-
Notifications
You must be signed in to change notification settings - Fork 10
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
Separate Routes between MRL and XCM and get moon chain fee balance in source #366
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
737ed0a
add peaq evm alphanet configuration
mmaurello 69ff80e
Add moonChainFee and separate MrlChainRoute from ChainRoute
mmaurello e6f382a
Update packages/mrl/src/getTransferData/getSourceData.ts
mmaurello 743096b
remove optional in moonChainfee
mmaurello File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
import type { ChainRoutes } from '../types/ChainRoutes'; | ||
import type { MrlChainRoutes } from '../types/MrlChainRoutes'; | ||
import { fantomTestnetRoutes } from './fantomTestnet'; | ||
import { moonbaseAlphaRoutes } from './moonbaseAlpha'; | ||
import { moonbaseBetaRoutes } from './moonbaseBeta'; | ||
import { peaqAlphanetRoutes } from './peaqAlphanet'; | ||
import { peaqEvmAlphanetRoutes } from './peaqEvmAlphanet'; | ||
|
||
export const mrlRoutesList: ChainRoutes[] = [ | ||
export const mrlRoutesList: MrlChainRoutes[] = [ | ||
fantomTestnetRoutes, | ||
moonbaseAlphaRoutes, | ||
moonbaseBetaRoutes, | ||
peaqAlphanetRoutes, | ||
peaqEvmAlphanetRoutes, | ||
]; | ||
|
||
export const mrlRoutesMap = new Map<string, ChainRoutes>( | ||
export const mrlRoutesMap = new Map<string, MrlChainRoutes>( | ||
mrlRoutesList.map((config) => [config.chain.key, config]), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { BalanceBuilder, MrlBuilder } from '@moonbeam-network/xcm-builder'; | ||
import { agng, dev, ftm, ftmwh } from '../assets'; | ||
import { fantomTestnet, peaqEvmAlphanet } from '../chains'; | ||
import { MrlChainRoutes } from '../types/MrlChainRoutes'; | ||
|
||
export const peaqEvmAlphanetRoutes = new MrlChainRoutes({ | ||
chain: peaqEvmAlphanet, | ||
routes: [ | ||
{ | ||
source: { | ||
asset: ftmwh, | ||
balance: BalanceBuilder().evm().erc20(), | ||
destinationFee: { | ||
asset: ftmwh, | ||
balance: BalanceBuilder().evm().erc20(), | ||
}, | ||
moonChainFee: { | ||
asset: dev, | ||
balance: BalanceBuilder().evm().erc20(), | ||
}, | ||
fee: { | ||
asset: agng, | ||
balance: BalanceBuilder().substrate().system().accountEvmTo32(), | ||
}, | ||
}, | ||
destination: { | ||
asset: ftm, | ||
chain: fantomTestnet, | ||
balance: BalanceBuilder().evm().native(), | ||
fee: { | ||
asset: ftm, | ||
amount: 0, | ||
}, | ||
}, | ||
mrl: { | ||
isAutomaticPossible: true, | ||
transfer: MrlBuilder() | ||
.wormhole() | ||
.contract() | ||
.TokenBridgeRelayer() | ||
.transferTokensWithRelay(), | ||
moonChain: { | ||
asset: ftmwh, | ||
fee: { | ||
asset: dev, | ||
amount: 0.1, | ||
balance: BalanceBuilder().substrate().system().account(), | ||
}, | ||
}, | ||
}, | ||
}, | ||
], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import type { BalanceConfigBuilder } from '@moonbeam-network/xcm-builder'; | ||
import type { Asset } from '@moonbeam-network/xcm-types'; | ||
import { | ||
AssetRoute, | ||
type AssetRouteConstructorParams, | ||
type SourceConfig, | ||
} from './AssetRoute'; | ||
|
||
export interface MrlAssetRouteConstructorParams | ||
extends AssetRouteConstructorParams { | ||
source: MrlSourceConfig; | ||
} | ||
|
||
export interface MrlSourceConfig extends SourceConfig { | ||
moonChainFee?: { | ||
asset: Asset; | ||
balance: BalanceConfigBuilder; | ||
}; | ||
} | ||
|
||
export class MrlAssetRoute extends AssetRoute { | ||
readonly source: MrlSourceConfig; | ||
|
||
constructor({ | ||
source, | ||
destination, | ||
contract, | ||
extrinsic, | ||
mrl, | ||
}: MrlAssetRouteConstructorParams & { source: MrlSourceConfig }) { | ||
super({ source, destination, contract, extrinsic, mrl }); | ||
this.source = source; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { ChainRoutes, type ChainRoutesConstructorParams } from './ChainRoutes'; | ||
import { | ||
MrlAssetRoute, | ||
type MrlAssetRouteConstructorParams, | ||
type MrlSourceConfig, | ||
} from './MrlAssetRoute'; | ||
|
||
export interface MrlChainRoutesConstructorParams | ||
extends ChainRoutesConstructorParams { | ||
routes: MrlRoutesParam[]; | ||
} | ||
|
||
interface MrlRoutesParam | ||
extends Omit<MrlAssetRouteConstructorParams, 'source'> { | ||
source: Omit<MrlSourceConfig, 'chain'>; | ||
} | ||
|
||
export class MrlChainRoutes extends ChainRoutes { | ||
readonly #routes: Map<string, MrlAssetRoute>; | ||
|
||
constructor({ chain, routes }: MrlChainRoutesConstructorParams) { | ||
super({ chain, routes }); | ||
this.#routes = new Map( | ||
routes.map(({ source, destination, contract, extrinsic, mrl }) => [ | ||
`${source.asset.key}-${destination.chain.key}`, | ||
new MrlAssetRoute({ | ||
source: { ...source, chain }, | ||
destination, | ||
contract, | ||
extrinsic, | ||
mrl, | ||
}), | ||
]), | ||
); | ||
} | ||
|
||
getRoutes(): MrlAssetRoute[] { | ||
return Array.from(this.#routes.values()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,7 +4,7 @@ import { | |||||
MrlBuilder, | ||||||
WormholeConfig, | ||||||
} from '@moonbeam-network/xcm-builder'; | ||||||
import type { AssetRoute, FeeConfig } from '@moonbeam-network/xcm-config'; | ||||||
import type { FeeConfig, MrlAssetRoute } from '@moonbeam-network/xcm-config'; | ||||||
import { | ||||||
getAssetMin, | ||||||
getBalance, | ||||||
|
@@ -30,7 +30,7 @@ import { | |||||
} from './getTransferData.utils'; | ||||||
|
||||||
export interface GetSourceDataParams { | ||||||
route: AssetRoute; | ||||||
route: MrlAssetRoute; | ||||||
destinationAddress: string; | ||||||
destinationFee: AssetAmount; | ||||||
sourceAddress: string; | ||||||
|
@@ -68,13 +68,21 @@ export async function getSourceData({ | |||||
chain: source, | ||||||
}) | ||||||
: balance; | ||||||
|
||||||
const destinationFeeBalance = await getDestinationFeeBalance({ | ||||||
balance, | ||||||
feeBalance, | ||||||
route, | ||||||
sourceAddress, | ||||||
}); | ||||||
|
||||||
const moonChainFeeBalance = await getMoonChainFeeBalance({ | ||||||
balance, | ||||||
feeBalance, | ||||||
route, | ||||||
sourceAddress, | ||||||
}); | ||||||
|
||||||
const existentialDeposit = await getExistentialDeposit(source); | ||||||
const min = await getAssetMin({ | ||||||
asset, | ||||||
|
@@ -121,6 +129,7 @@ export async function getSourceData({ | |||||
balance, | ||||||
chain: source, | ||||||
destinationFeeBalance, | ||||||
moonChainFeeBalance, | ||||||
existentialDeposit, | ||||||
fee, | ||||||
feeBalance, | ||||||
|
@@ -235,3 +244,42 @@ async function getWormholeFee({ | |||||
|
||||||
return; | ||||||
} | ||||||
|
||||||
export interface GetMoonChainFeeBalanceParams { | ||||||
balance: AssetAmount; | ||||||
feeBalance: AssetAmount; | ||||||
route: MrlAssetRoute; | ||||||
sourceAddress: string; | ||||||
} | ||||||
|
||||||
export async function getMoonChainFeeBalance({ | ||||||
balance, | ||||||
feeBalance, | ||||||
route, | ||||||
sourceAddress, | ||||||
}: GetMoonChainFeeBalanceParams): Promise<AssetAmount | undefined> { | ||||||
if (!route.source.moonChainFee) { | ||||||
return undefined; | ||||||
} | ||||||
|
||||||
if (route.mrl?.moonChain.fee.asset.isEqual(balance)) { | ||||||
return balance; | ||||||
} | ||||||
|
||||||
if (route.mrl?.moonChain.fee.asset.isEqual(feeBalance)) { | ||||||
return feeBalance; | ||||||
} | ||||||
|
||||||
if (!route.source.moonChainFee?.balance) { | ||||||
throw new Error( | ||||||
'BalanceBuilder must be defined for source.moonChainFee.balance for AssetRoute', | ||||||
mmaurello marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
); | ||||||
} | ||||||
|
||||||
return getBalance({ | ||||||
address: sourceAddress, | ||||||
asset: route.source.chain.getChainAsset(route.source.moonChainFee.asset), | ||||||
builder: route.source.moonChainFee?.balance, | ||||||
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
|
||||||
chain: route.source.chain, | ||||||
}); | ||||||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think we could just use 1 class for both, but we would need to make types more complex. Don't spend time for that right now. If it will be needed, we can come back to it.