Skip to content

Commit

Permalink
fixed arb issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Thorian1te committed Oct 11, 2024
1 parent d9fb794 commit b21e0fb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "asgardex",
"productName": "ASGARDEX",
"version": "1.22.5",
"version": "1.22.6",
"description": "WALLET AND EXCHANGE CLIENT FOR THORCHAIN",
"main": "index.js",
"scripts": {
Expand Down
36 changes: 23 additions & 13 deletions src/renderer/services/arb/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ import {
IsApprovedLD,
SendPoolTxParams,
IsApproveParams,
SendTxParams
SendTxParams,
EvmTxParams
} from '../evm/types'
import { ApiError, ErrorId, TxHashLD } from '../wallet/types'
import { Client$, Client as ArbClient } from './types'
Expand Down Expand Up @@ -83,19 +84,28 @@ export const createTransactionService = (client$: Client$, network$: Network$):
const nativeAsset = client.getAssetInfo()

return Rx.from(routerContract.populateTransaction.depositWithExpiry(...depositParams)).pipe(
RxOp.switchMap((unsignedTx) =>
Rx.from(
client.transfer({
asset: nativeAsset.asset,
amount: isERC20 ? baseAmount(0, nativeAsset.decimal) : params.amount,
memo: unsignedTx.data,
recipient: router,
gasPrice: gasPrices[params.feeOption],
isMemoEncoded: true,
gasLimit: ethers.BigNumber.from(160000)
})
RxOp.switchMap((unsignedTx) => {
const tx: EvmTxParams = {
asset: nativeAsset.asset,
amount: isERC20 ? baseAmount(0, nativeAsset.decimal) : params.amount,
memo: unsignedTx.data, // Use the `data` from unsignedTx as the memo
recipient: router, // Assuming the router address is passed in params
gasPrice: gasPrices[params.feeOption], // Use the appropriate gas price option
isMemoEncoded: true // Memo is encoded
}

// Estimate gas and return the transfer transaction as an observable
return Rx.from(client.estimateGasLimit(tx)).pipe(
RxOp.switchMap((gasLimit) =>
Rx.from(
client.transfer({
...tx, // Spread the original tx object
gasLimit // Use the estimated gas limit
})
)
)
)
)
})
)
}),
RxOp.map((txResult) => txResult),
Expand Down
10 changes: 9 additions & 1 deletion src/renderer/services/evm/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as RD from '@devexperts/remote-data-ts'
import { FeeOption, Network } from '@xchainjs/xchain-client'
import { FeesWithGasPricesAndLimits } from '@xchainjs/xchain-evm'
import { Address, AnyAsset, Asset, BaseAmount } from '@xchainjs/xchain-util'
import { TxParams as BaseEvmTxParams } from '@xchainjs/xchain-evm'
import { Address, AnyAsset, Asset, BaseAmount, TokenAsset } from '@xchainjs/xchain-util'
import { ethers } from 'ethers'
import * as O from 'fp-ts/lib/Option'

Expand Down Expand Up @@ -35,6 +36,13 @@ export type SendPoolTxParams = SendTxParams & {
router: O.Option<Address>
}

/**
* EVM transfer params
*/
export type EvmTxParams = BaseEvmTxParams & {
asset: Asset | TokenAsset
}

/**
* `ApproveParams`
* are used to `approve but also to estimate `approveFees`
Expand Down

0 comments on commit b21e0fb

Please sign in to comment.