Skip to content

Commit

Permalink
fix calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronmgdr committed Jun 18, 2024
1 parent 5808b1d commit 84e2e89
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
10 changes: 8 additions & 2 deletions packages/sdk/contractkit/src/kit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ testWithAnvil('kit', (web3) => {
{
"feeCurrency": "0x2A3733dBc31980f02b12135C809b5da33BF3a1e9",
"gas": 53001,
"maxFeeInFeeCurrency": "53001000000000",
"maxFeeInFeeCurrency": "106002000000000",
"maxFeePerGas": "2000000000",
"maxPriorityFeePerGas": "1000000000",
}
Expand Down Expand Up @@ -276,7 +276,13 @@ testWithAnvil('kit', (web3) => {
feeCurrency: feeToken,
gas: '102864710371401736267367367',
})
).resolves.toEqual({})
).resolves.toEqual({
feeCurrency: '0x2A3733dBc31980f02b12135C809b5da33BF3a1e9',
gas: '102864710371401736267367367',
maxFeeInFeeCurrency: '205729420742803472534734734000000000',
maxFeePerGas: '2000000000',
maxPriorityFeePerGas: '1000000000',
})
})
})
})
Expand Down
9 changes: 7 additions & 2 deletions packages/sdk/contractkit/src/kit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export class ContractKit {
const maxFeeInFeeCurrency = await this.estimateMaxFeeInFeeToken({
feeCurrency: tx.feeCurrency,
gasLimit: BigInt(tx.gas),
maxFeePerGas: BigInt(maxPriorityFeePerGas),
maxFeePerGas: BigInt(maxFeePerGas),
})

tx.maxFeeInFeeCurrency = maxFeeInFeeCurrency.toString(10)
Expand All @@ -279,10 +279,15 @@ export class ContractKit {
maxFeePerGas: bigint
feeCurrency: StrongAddress
}) {
// 2 percent wriggle room
const slippage = BigInt(102) / BigInt(100)
const maxGasFeesInCELO = gasLimit * maxFeePerGas
const fcd = await this.contracts.getFeeCurrencyDirectory()
const { numerator: ratioTOKEN, denominator: ratioCELO } = await fcd.getExchangeRate(feeCurrency)
return (maxGasFeesInCELO * BigInt(ratioCELO.toString(10))) / BigInt(ratioTOKEN.toString(10))
return (
((maxGasFeesInCELO * BigInt(ratioCELO.toString(10))) / BigInt(ratioTOKEN.toString(10))) *
slippage
)
}

// *** NOTICE ***
Expand Down

0 comments on commit 84e2e89

Please sign in to comment.