Skip to content

Commit

Permalink
set higher default gas for cpk txs (#1719)
Browse files Browse the repository at this point in the history
Co-authored-by: Thomas Pulber <[email protected]>
  • Loading branch information
hexyls and pimato authored Mar 10, 2021
1 parent 9db24e6 commit de189ba
Showing 1 changed file with 10 additions and 38 deletions.
48 changes: 10 additions & 38 deletions app/src/services/cpk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { XdaiService } from './xdai'

const logger = getLogger('Services::CPKService')

const compoundServiceGasNeeded = 1500000
const defaultGas = 1500000

interface CPKBuyOutcomesParams {
amount: BigNumber
Expand Down Expand Up @@ -203,15 +203,6 @@ class CPKService {
return transactionReceipt
}

getGas = async (gas: number): Promise<number> => {
const deployed = await this.cpk.isProxyDeployed()
if (deployed) {
return gas
}
const addProxyDeploymentGas = 500000
return gas + addProxyDeploymentGas
}

buyOutcomes = async ({
amount,
collateral,
Expand All @@ -229,10 +220,7 @@ class CPKService {
const transactions = []

const txOptions: TxOptions = {}

if (!this.isSafeApp && collateral.address === pseudoNativeAssetAddress) {
txOptions.gas = await this.getGas(500000)
}
txOptions.gas = defaultGas

let collateralAddress
let collateralSymbol = ''
Expand All @@ -256,8 +244,8 @@ class CPKService {
// we need to send the funding amount in native ether
if (!this.isSafeApp) {
txOptions.value = amount
txOptions.gas = 500000
}

// Step 0: Wrap ether
transactions.push({
to: collateralAddress,
Expand All @@ -268,7 +256,6 @@ class CPKService {
// If base token is ETH then we don't need to transfer to cpk
if (!this.isSafeApp) {
txOptions.value = amount
txOptions.gas = compoundServiceGasNeeded
}
const encodedMintFunction = CompoundService.encodeMintTokens(collateralSymbol, amount.toString())
transactions.push({
Expand Down Expand Up @@ -382,10 +369,7 @@ class CPKService {

const transactions = []
const txOptions: TxOptions = {}

if (!this.isSafeApp && marketData.collateral.address === pseudoNativeAssetAddress) {
txOptions.gas = await this.getGas(1200000)
}
txOptions.gas = defaultGas

let collateral

Expand All @@ -404,7 +388,6 @@ class CPKService {
value: marketData.funding,
})
} else if (useCompoundReserve && compoundTokenDetails) {
txOptions.gas = await this.getGas(compoundServiceGasNeeded)
if (userInputCollateral.address === pseudoNativeAssetAddress) {
// If user chosen collateral is ETH
collateral = marketData.collateral
Expand Down Expand Up @@ -608,10 +591,7 @@ class CPKService {

const transactions = []
const txOptions: TxOptions = {}

if (!this.isSafeApp && marketData.collateral.address === pseudoNativeAssetAddress) {
txOptions.gas = await this.getGas(1500000)
}
txOptions.gas = defaultGas

let collateral

Expand Down Expand Up @@ -769,6 +749,7 @@ class CPKService {

const transactions = []
const txOptions: TxOptions = {}
txOptions.gas = defaultGas

const network = await this.provider.getNetwork()
const networkId = network.chainId
Expand All @@ -785,10 +766,6 @@ class CPKService {
}
}

if (this.isSafeApp) {
txOptions.gas = await this.getGas(500000)
}

const isAlreadyApprovedForMarketMaker = await conditionalTokens.isApprovedForAll(
this.cpk.address,
marketMaker.address,
Expand Down Expand Up @@ -817,8 +794,6 @@ class CPKService {
data: encodedWithdrawFunction,
})
} else {
// cToken to base token conversion flow
txOptions.gas = await this.getGas(compoundServiceGasNeeded)
// Convert cpk token to base token if user wants to redeem in base
const encodedRedeemFunction = CompoundService.encodeRedeemTokens(collateralSymbol, amount.toString())
// Approve cToken for the cpk contract
Expand Down Expand Up @@ -882,15 +857,12 @@ class CPKService {
const transactions = []

const txOptions: TxOptions = {}
txOptions.gas = defaultGas

let collateralSymbol = ''
let userInputCollateralSymbol: KnownToken
let userInputCollateral: Token = collateral

if (!this.isSafeApp && collateral.address === pseudoNativeAssetAddress) {
txOptions.gas = await this.getGas(500000)
}

let collateralAddress
if (collateral.address === pseudoNativeAssetAddress) {
// ultimately WETH will be the collateral if we fund with native ether
Expand Down Expand Up @@ -938,7 +910,6 @@ class CPKService {
if (!this.isSafeApp && collateral.address !== pseudoNativeAssetAddress) {
// Step 4: Transfer funding from user
if (useBaseToken) {
txOptions.gas = await this.getGas(compoundServiceGasNeeded)
// If use base token then transfer the base token amount from the user
if (collateral.address !== pseudoNativeAssetAddress) {
transactions.push({
Expand Down Expand Up @@ -1027,6 +998,7 @@ class CPKService {
transactions.push(mergePositionsTx)

const txOptions: TxOptions = {}
txOptions.gas = defaultGas

const collateralToken = getTokenFromAddress(networkId, collateralAddress)
const collateralSymbol = collateralToken.symbol.toLowerCase()
Expand Down Expand Up @@ -1147,6 +1119,7 @@ class CPKService {

const transactions = []
const txOptions: TxOptions = {}
txOptions.gas = defaultGas

if (!isConditionResolved) {
transactions.push({
Expand Down Expand Up @@ -1196,8 +1169,7 @@ class CPKService {
upgradeProxyImplementation = async (): Promise<TransactionReceipt> => {
try {
const txOptions: TxOptions = {}
// add plenty of gas to avoid locked proxy https://github.com/gnosis/contract-proxy-kit/issues/132
txOptions.gas = 500000
txOptions.gas = defaultGas
const network = await this.provider.getNetwork()
const targetGnosisSafeImplementation = getTargetSafeImplementation(network.chainId)
const transactions = [
Expand Down

0 comments on commit de189ba

Please sign in to comment.