-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add fund route and approval funcitons
- Loading branch information
Showing
10 changed files
with
1,036 additions
and
84 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,99 @@ | ||
import { stylusDevnetEc2 } from "@/lib/stylus"; | ||
import { Token } from "@renegade-fi/renegade-js"; | ||
import { createPublicClient, createWalletClient, formatEther, formatUnits, http, parseEther, parseUnits } from "viem"; | ||
import { privateKeyToAccount } from "viem/accounts"; | ||
import { parseAbi } from 'viem' | ||
|
||
const abi = parseAbi([ | ||
'function transfer(address to, uint256 amount) returns (bool)', | ||
'event Transfer(address indexed from, address indexed to, uint256 amount)', | ||
]) | ||
|
||
export async function GET(request: Request) { | ||
if (!process.env.DEV_PRIVATE_KEY) { | ||
return new Response("DEV_PRIVATE_KEY is required", { | ||
status: 400, | ||
}) | ||
} | ||
|
||
const { searchParams } = new URL(request.url) | ||
const recipient = searchParams.get('address') as `0x${string}` | ||
if (!recipient) { | ||
return new Response("Address is required", { | ||
status: 400, | ||
}) | ||
} | ||
|
||
try { | ||
// Account to fund from | ||
const account = privateKeyToAccount(process.env.DEV_PRIVATE_KEY as `0x${string}`); | ||
|
||
const publicClient = createPublicClient({ | ||
chain: stylusDevnetEc2, | ||
transport: http(), | ||
}); | ||
|
||
const walletClient = createWalletClient({ | ||
account, | ||
chain: stylusDevnetEc2, | ||
transport: http(), | ||
}); | ||
|
||
// TODO: Check if already funded? | ||
|
||
const ethAmount = parseEther("0.1") | ||
const wethAmount = parseEther("1") | ||
const usdcAmount = parseUnits("3000", 18) | ||
|
||
// TODO: Parallelize | ||
// Fund with ETH | ||
const hash = await walletClient.sendTransaction({ | ||
account, | ||
to: recipient, | ||
value: ethAmount, | ||
}) | ||
const transaction = await publicClient.waitForTransactionReceipt({ | ||
hash | ||
}) | ||
console.log(`Funded ${recipient} with ${formatEther(ethAmount)} ETH. Transaction hash: ${transaction.transactionHash}`) | ||
|
||
// Fund with WETH | ||
const { request: wethRequest } = await publicClient.simulateContract({ | ||
account, | ||
address: Token.findAddressByTicker("WETH") as `0x${string}`, | ||
abi, | ||
functionName: "transfer", | ||
args: [recipient, wethAmount], | ||
}) | ||
|
||
const wethHash = await walletClient.writeContract(wethRequest) | ||
const wethTransaction = await publicClient.waitForTransactionReceipt({ | ||
hash: wethHash | ||
}) | ||
console.log(`Funded ${recipient} with ${formatUnits(wethAmount, 18)} WETH. Transaction hash: ${wethTransaction.transactionHash}`) | ||
|
||
// Fund with UDSC | ||
const { request: usdcRequest } = await publicClient.simulateContract({ | ||
account, | ||
address: Token.findAddressByTicker("USDC") as `0x${string}`, | ||
abi, | ||
functionName: "transfer", | ||
args: [recipient, usdcAmount], | ||
}) | ||
|
||
const usdcHash = await walletClient.writeContract(usdcRequest) | ||
const usdcTransaction = await publicClient.waitForTransactionReceipt({ | ||
hash: usdcHash | ||
}) | ||
console.log(`Funded ${recipient} with ${formatUnits(usdcAmount, 18)} USDC. Transaction hash: ${usdcTransaction.transactionHash}`) | ||
|
||
return new Response("Success!", { | ||
status: 200, | ||
}) | ||
} catch (error) { | ||
return new Response(`Error funding ${recipient}: ${error}`, { | ||
status: 500, | ||
}) | ||
} | ||
} | ||
|
44 changes: 0 additions & 44 deletions
44
trade.renegade.fi/components/steppers/testnet-stepper/steps/approval-loading-step.tsx
This file was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.