Skip to content

Commit

Permalink
use maxIssueance on base
Browse files Browse the repository at this point in the history
  • Loading branch information
jankjr committed Oct 19, 2023
1 parent 630df95 commit 5876739
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@popperjs/core": "^2.11.5",
"@rainbow-me/rainbowkit": "1.0.11",
"@react-spring/web": "^9.7.1",
"@reserve-protocol/token-zapper": "2.6.9",
"@reserve-protocol/token-zapper": "2.6.10",
"@uiw/react-md-editor": "^3.20.5",
"@uniswap/permit2-sdk": "^1.2.0",
"@viem/anvil": "^0.0.6",
Expand Down
26 changes: 18 additions & 8 deletions src/views/issuance/components/zap/state/atoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { loadable } from 'jotai/utils'
import {
balancesAtom,
blockAtom,
chainIdAtom,
isSmartWalletAtom,
rTokenAtom,
walletAtom,
Expand Down Expand Up @@ -186,7 +187,6 @@ export const zapQuotePromise = loadable(

export const zapQuote = simplifyLoadable(zapQuotePromise)


const approximateGasUsage: Record<string, bigint> = {
'0xa0d69e286b938e21cbf7e51d71f6a4c8918f482f': 3_000_000n,
'0xe72b141df173b999ae7c1adcbf60cc9833ce56a8': 3_000_000n,
Expand All @@ -195,7 +195,7 @@ const approximateGasUsage: Record<string, bigint> = {
'0x9b451beb49a03586e6995e5a93b9c745d068581e': 3_000_000n,
'0xfc0b1eef20e4c68b3dcf36c4537cfa7ce46ca70b': 3_000_000n,
'0x50249c768a6d3cb4b6565c0a2bfbdb62be94915c': 3_000_000n,
'0xcc7ff230365bd730ee4b352cc2492cedac49383e': 6_000_000n
'0xcc7ff230365bd730ee4b352cc2492cedac49383e': 6_000_000n,
}
export const selectedZapTokenBalance = atom((get) => {
const token = get(selectedZapTokenAtom)
Expand All @@ -207,7 +207,7 @@ export const selectedZapTokenBalance = atom((get) => {
return null
}
const quantities = get(balancesAtom) ?? {}
const fr = quantities[token.address.address as any]?.balance ?? "0"
const fr = quantities[token.address.address as any]?.balance ?? '0'
let bal = token.from(fr)
return bal
})
Expand All @@ -224,10 +224,14 @@ export const maxSelectedZapTokenBalance = atom((get) => {
const rtoken = get(rTokenAtom)
const zapTransaction = get(resolvedZapTransaction)
const quantities = get(balancesAtom) ?? {}
const fr = quantities[token.address.address as any]?.balance ?? "0"
const fr = quantities[token.address.address as any]?.balance ?? '0'
let bal = token.from(fr)
if (token.address.address === '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE') {
const a = zapState.gasPrice * (zapTransaction?.transaction.gasEstimate ?? approximateGasUsage[rtoken?.address.toLowerCase() ?? ""] ?? 2_500_000n);
const a =
zapState.gasPrice *
(zapTransaction?.transaction.gasEstimate ??
approximateGasUsage[rtoken?.address.toLowerCase() ?? ''] ??
2_500_000n)
bal = bal.sub(token.from(a))
bal = bal.amount < 0n ? token.zero : bal
}
Expand Down Expand Up @@ -333,8 +337,13 @@ export const approvalTxFee = loadable(

export const resolvedApprovalTxFee = simplifyLoadable(approvalTxFee)

const useMaxIssueance: Record<number, boolean> = {
1: false,
8453: true,
}
const zapTxAtom = atom(async (get) => {
const result = get(zapQuote)
const chainId = get(chainIdAtom)
const approvalNeeded = get(resolvedApprovalNeeded)
if (!(approvalNeeded && result)) {
return null
Expand All @@ -347,13 +356,14 @@ const zapTxAtom = atom(async (get) => {
permit2 =
signature != null && permit != null
? {
permit: permit.permit,
signature,
}
permit: permit.permit,
signature,
}
: undefined
}
const tx = await result.toTransaction({
permit2,
maxIssueance: useMaxIssueance[chainId] ?? false,
returnDust: get(collectDust),
})
// console.log("=== abstract zap transaction ===")
Expand Down

0 comments on commit 5876739

Please sign in to comment.