-
Notifications
You must be signed in to change notification settings - Fork 635
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
125 additions
and
6 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { ActionProps, RapActionResult } from '../references'; | ||
import { executeClaim } from '@/screens/claimables/transaction/claim'; | ||
|
||
export async function claimClaimable({ wallet, parameters }: ActionProps<'claimClaimable'>): Promise<RapActionResult> { | ||
const { claimTx, asset } = parameters; | ||
|
||
return executeClaim({ asset, claimTx, wallet }); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { Address } from 'viem'; | ||
import { createNewAction, createNewRap } from './common'; | ||
import { RapAction, RapSwapActionParameters } from './references'; | ||
import { RainbowError } from '@/logger'; | ||
import { CrosschainQuote } from '@rainbow-me/swaps'; | ||
import { assetNeedsUnlocking } from './actions'; | ||
|
||
export async function createClaimClaimableRap(parameters: RapSwapActionParameters<'claimClaimable'>) { | ||
let actions: RapAction<'claimClaimable' | 'crosschainSwap' | 'unlock' | 'swap'>[] = []; | ||
|
||
const { sellAmount, assetToBuy, quote, chainId, toChainId, assetToSell, meta, gasFeeParamsBySpeed, gasParams, additionalParams } = | ||
parameters; | ||
|
||
if (!additionalParams?.claimTx) throw new RainbowError('[raps/claimClaimable]: claimTx is undefined'); | ||
|
||
const claim = createNewAction('claimClaimable', { | ||
claimTx: additionalParams.claimTx, | ||
asset: assetToSell, | ||
}); | ||
actions = actions.concat(claim); | ||
|
||
const { | ||
from: accountAddress, | ||
allowanceTarget, | ||
allowanceNeeded, | ||
} = quote as { | ||
from: Address; | ||
allowanceTarget: Address; | ||
allowanceNeeded: boolean; | ||
}; | ||
|
||
let swapAssetNeedsUnlocking = false; | ||
|
||
if (allowanceNeeded) { | ||
swapAssetNeedsUnlocking = await assetNeedsUnlocking({ | ||
owner: accountAddress, | ||
amount: sellAmount, | ||
assetToUnlock: assetToSell, | ||
spender: allowanceTarget, | ||
chainId, | ||
}); | ||
} | ||
|
||
if (swapAssetNeedsUnlocking) { | ||
if (!quote.to) throw new RainbowError('[raps/claimClaimable]: quote.to is undefined'); | ||
|
||
const unlock = createNewAction('unlock', { | ||
fromAddress: accountAddress, | ||
assetToUnlock: assetToSell, | ||
chainId, | ||
contractAddress: quote.to as Address, | ||
}); | ||
actions = actions.concat(unlock); | ||
} | ||
|
||
if (chainId === toChainId) { | ||
// create a swap rap | ||
const swap = createNewAction('swap', { | ||
chainId: chainId, | ||
requiresApprove: swapAssetNeedsUnlocking, | ||
quote: quote as CrosschainQuote, | ||
meta: meta, | ||
assetToSell, | ||
sellAmount, | ||
assetToBuy, | ||
gasParams, | ||
gasFeeParamsBySpeed, | ||
}); | ||
actions = actions.concat(swap); | ||
} else { | ||
// create a crosschain swap rap | ||
const crosschainSwap = createNewAction('crosschainSwap', { | ||
chainId: chainId, | ||
requiresApprove: swapAssetNeedsUnlocking, | ||
quote: quote as CrosschainQuote, | ||
meta: meta, | ||
assetToSell, | ||
sellAmount, | ||
assetToBuy, | ||
gasParams, | ||
gasFeeParamsBySpeed, | ||
}); | ||
actions = actions.concat(crosschainSwap); | ||
} | ||
|
||
// create the overall rap | ||
const newRap = createNewRap(actions); | ||
return newRap; | ||
} |
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