-
Notifications
You must be signed in to change notification settings - Fork 92
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
Save sub bridge transaction fees in runtime tx processing #1088
Merged
Merged
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
8f48eea
fix hashi bridge
Nikita-Polyakov 6bcc53a
fetch sub bridgeassets
Nikita-Polyakov 1bbea87
update wallet
Nikita-Polyakov 54b0fa1
fix external account check
Nikita-Polyakov ab3e7a8
remove unnecessary codeline
Nikita-Polyakov f8f77bb
remove console.log
Nikita-Polyakov 8b66c3e
demo for fetching extrinsic fee
Nikita-Polyakov 4313870
Merge remote-tracking branch 'origin/develop' into tech/sub-fetch-ext…
Nikita-Polyakov 524f7e4
fix merge conflict
Nikita-Polyakov 9b364ae
merge origin/develop
Nikita-Polyakov fbe6b61
save tx fee & xcm fee
Nikita-Polyakov dae1f6b
remove duplicated code from bridge reducers
Nikita-Polyakov d213e02
improve network restoration
Nikita-Polyakov f5d39b1
refactoring external native token balance
Nikita-Polyakov 50a9295
refactoring registered asset naming
Nikita-Polyakov 36ea6ed
Merge branch 'develop' into tech/sub-fetch-extrinsic-fee
Nikita-Polyakov c4481ac
update evm gas price
Nikita-Polyakov df90c60
update evm gas price
Nikita-Polyakov 78e5013
improve gas fee calculation
Nikita-Polyakov fe2526d
remove mainnet from evm networks ids
Nikita-Polyakov 7205bda
merge fee update
Nikita-Polyakov 788707b
update gasLimits
Nikita-Polyakov 2c39d78
Merge branch 'develop' into fix/evm-expected-fee
Nikita-Polyakov 6a2963e
add external fee warning
Nikita-Polyakov 250192c
refactoring externalBalance
Nikita-Polyakov f5c9aff
Merge branch 'fix/evm-expected-fee' of github.com:sora-xor/polkaswap-…
Nikita-Polyakov 9cc07dc
update locales
Nikita-Polyakov 1f3896e
update translations from localisr
Nikita-Polyakov 28e29ff
Merge branch 'fix/evm-expected-fee' into tech/sub-fetch-extrinsic-fee
Nikita-Polyakov 958ce96
impove outgoing tracking
Nikita-Polyakov c3d2c2a
wip locked balance
Nikita-Polyakov b263f85
use locked balance in bridge calculations
Nikita-Polyakov c351bd4
refactoring
Nikita-Polyakov c6819e6
update BridgeTransaction asset locked balance check
Nikita-Polyakov f06aa0d
merge origin/develop
Nikita-Polyakov f84b603
merge origin/develop
Nikita-Polyakov 75f2325
refactoring event search
Nikita-Polyakov b4ec5f7
merge origin/develop
Nikita-Polyakov 288f10b
get bridge contract asset locked balance
Nikita-Polyakov 50f1b20
remove Karura from config
Nikita-Polyakov 1f3d8af
refactoring before wallet update
Nikita-Polyakov a1505f7
update wallet 1.18.1
Nikita-Polyakov bc32ea2
calc evm fee based on asset kind
Nikita-Polyakov e2db5c0
fix sonar issues
Nikita-Polyakov 246df42
fix naming
Nikita-Polyakov 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
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 |
---|---|---|
|
@@ -33,12 +33,11 @@ import SelectAssetMixin from '@/components/mixins/SelectAssetMixin'; | |
import TranslationMixin from '@/components/mixins/TranslationMixin'; | ||
import { Components, ObjectInit } from '@/consts'; | ||
import { lazyComponent } from '@/router'; | ||
import type { BridgeAccountAsset } from '@/store/assets/types'; | ||
import type { BridgeRegisteredAsset } from '@/store/assets/types'; | ||
import { state, getter } from '@/store/decorators'; | ||
import type { NetworkData } from '@/types/bridge'; | ||
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. the same |
||
|
||
import type { RegisteredAccountAsset } from '@sora-substrate/util'; | ||
import type { AccountAsset } from '@sora-substrate/util/build/assets/types'; | ||
import type { AccountAsset, RegisteredAccountAsset } from '@sora-substrate/util/build/assets/types'; | ||
|
||
@Component({ | ||
components: { | ||
|
@@ -51,7 +50,7 @@ export default class BridgeSelectAsset extends Mixins(TranslationMixin, SelectAs | |
@Prop({ default: ObjectInit, type: Object }) readonly asset!: AccountAsset; | ||
|
||
@getter.web3.selectedNetwork private selectedNetwork!: Nullable<NetworkData>; | ||
@state.assets.registeredAssets private registeredAssets!: Record<string, BridgeAccountAsset>; | ||
@state.assets.registeredAssets private registeredAssets!: Record<string, BridgeRegisteredAsset>; | ||
@state.bridge.isSoraToEvm isSoraToEvm!: boolean; | ||
@state.wallet.settings.shouldBalanceBeHidden shouldBalanceBeHidden!: boolean; | ||
|
||
|
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 |
---|---|---|
|
@@ -5,7 +5,7 @@ import { Component, Mixins } from 'vue-property-decorator'; | |
import BridgeHistoryMixin from '@/components/mixins/BridgeHistoryMixin'; | ||
import WalletConnectMixin from '@/components/mixins/WalletConnectMixin'; | ||
import { MoonpayNotifications } from '@/components/pages/Moonpay/consts'; | ||
import type { RegisteredAccountAssetObject, BridgeAccountAsset } from '@/store/assets/types'; | ||
import type { BridgeRegisteredAsset } from '@/store/assets/types'; | ||
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. the same |
||
import { state, action, mutation, getter } from '@/store/decorators'; | ||
import type { BridgeTxData } from '@/store/moonpay/types'; | ||
import { getMaxValue, hasInsufficientEvmNativeTokenForFee } from '@/utils'; | ||
|
@@ -14,6 +14,7 @@ import type { MoonpayTransaction } from '@/utils/moonpay'; | |
import { MoonpayEVMTransferAssetData, MoonpayApi } from '@/utils/moonpay'; | ||
|
||
import type { CodecString, BridgeHistory } from '@sora-substrate/util'; | ||
import type { Asset, AccountBalance } from '@sora-substrate/util/build/assets/types'; | ||
import type { EvmNetwork } from '@sora-substrate/util/build/bridgeProxy/evm/types'; | ||
import type { WALLET_CONSTS } from '@soramitsu/soraneo-wallet-web'; | ||
|
||
|
@@ -29,10 +30,10 @@ export default class MoonpayBridgeInitMixin extends Mixins(BridgeHistoryMixin, W | |
@state.moonpay.bridgeTransactionData bridgeTransactionData!: Nullable<BridgeHistory>; | ||
@state.web3.ethBridgeEvmNetwork ethBridgeEvmNetwork!: EvmNetwork; | ||
@state.wallet.settings.soraNetwork soraNetwork!: Nullable<WALLET_CONSTS.SoraNetwork>; | ||
@state.assets.registeredAssets private registeredAssets!: Record<string, BridgeAccountAsset>; | ||
@state.assets.registeredAssets private registeredAssets!: Record<string, BridgeRegisteredAsset>; | ||
|
||
@getter.settings.moonpayApiKey moonpayApiKey!: string; | ||
@getter.assets.assetsDataTable assetsDataTable!: RegisteredAccountAssetObject; | ||
@getter.assets.assetsDataTable assetsDataTable!: Record<string, Asset>; | ||
|
||
@mutation.moonpay.setConfirmationVisibility setConfirmationVisibility!: (flag: boolean) => void; | ||
@mutation.moonpay.setNotificationVisibility setNotificationVisibility!: (flag: boolean) => void; | ||
|
@@ -123,31 +124,40 @@ export default class MoonpayBridgeInitMixin extends Mixins(BridgeHistoryMixin, W | |
); | ||
} | ||
|
||
const [soraAddress] = | ||
const [soraAddress, registeredAsset] = | ||
Object.entries(this.registeredAssets).find(([soraAddress, registeredAsset]) => | ||
ethersUtil.addressesAreEqual(registeredAsset.address, ethTransferData.address) | ||
) ?? []; | ||
|
||
if (!soraAddress) { | ||
if (!(soraAddress && registeredAsset)) { | ||
throw createError( | ||
`Asset is not registered: ethereum address ${ethTransferData.address}`, | ||
MoonpayNotifications.SupportError | ||
); | ||
} | ||
|
||
const asset = this.assetsDataTable[soraAddress]; | ||
|
||
const externalBalance = (await ethersUtil.getAccountAssetBalance(ethTransferData.to, asset.externalAddress)) | ||
const externalBalance = (await ethersUtil.getAccountAssetBalance(ethTransferData.to, registeredAsset.address)) | ||
.value; | ||
const evmNetworkFee: CodecString = await ethersUtil.getEvmNetworkFee(soraAddress, false); | ||
const evmNetworkFee: CodecString = await ethersUtil.getEvmNetworkFee( | ||
registeredAsset.address, | ||
registeredAsset.kind, | ||
false | ||
); | ||
const evmNativeBalance = await ethersUtil.getAccountBalance(ethTransferData.to); | ||
const hasEthForFee = !hasInsufficientEvmNativeTokenForFee(evmNativeBalance, evmNetworkFee); | ||
|
||
if (!hasEthForFee) { | ||
throw createError('Insufficient ETH for fee', MoonpayNotifications.FeeError); | ||
} | ||
|
||
const maxAmount = getMaxValue({ ...asset, externalBalance }, evmNetworkFee, true); // max balance (minus fee if eth asset) | ||
const accountAsset = { | ||
...this.assetsDataTable[soraAddress], | ||
balance: {} as AccountBalance, | ||
externalBalance, | ||
externalAddress: registeredAsset.address, | ||
externalDecimals: registeredAsset.decimals, | ||
}; | ||
const maxAmount = getMaxValue(accountAsset, evmNetworkFee, true); // max balance (minus fee if eth asset) | ||
const amount = Math.min(Number(maxAmount), Number(ethTransferData.amount)); | ||
|
||
if (amount <= 0) { | ||
|
@@ -157,8 +167,8 @@ export default class MoonpayBridgeInitMixin extends Mixins(BridgeHistoryMixin, W | |
return { | ||
type: Operation.EthBridgeIncoming, | ||
amount: String(amount), | ||
symbol: asset.symbol, | ||
assetAddress: asset.address, | ||
symbol: accountAsset.symbol, | ||
assetAddress: accountAsset.address, | ||
soraNetworkFee: this.networkFees[Operation.EthBridgeIncoming], | ||
externalNetworkFee: evmNetworkFee, | ||
externalNetwork: this.ethBridgeEvmNetwork, | ||
|
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
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.
please don't use
@
for types imports cuz it breaks js lint sorting rulesThere 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.
Will try to fix this in another PR (because of a lot of changes after linting)