@@ -4,68 +4,70 @@ import { run } from "hardhat";
44import { SwapAndRedeemInstance } from "../../typechain-types" ;
55import { ERC20Instance } from "../../typechain-types/@openzeppelin/contracts/token/ERC20/ERC20" ;
66
7- // AssetManager address on Songbird Testnet Coston network
8- const ASSET_MANAGER_ADDRESS = "0x56728e46908fB6FcC5BCD2cc0c0F9BB91C3e4D34" ;
7+ import { getAssetManagerFXRP } from "../utils/getters" ;
8+
9+ // yarn hardhat run scripts/fassets/swapAndRedeem.ts --network coston2
10+
911const LOTS_TO_REDEEM = 1 ;
1012const UNDERLYING_ADDRESS = "rSHYuiEvsYsKR8uUHhBTuGP5zjRcGt4nm" ;
11- // BlazeSwap router address on Songbird Testnet Coston network
12- const SWAP_ROUTER_ADDRESS = "0xf0D01450C037DB2903CF5Ff638Dd1e2e6B0EEDF4" ;
13- const SWAP_PATH = [
14- "0x767b25A658E8FC8ab6eBbd52043495dB61b4ea91" , // WCFLR
15- "0x36be8f2e1CC3339Cf6702CEfA69626271C36E2fd" , // FXRP
16- ] ;
13+
14+ // BlazeSwap router address on Flare Testnet Coston2 network
15+ const SWAP_ROUTER_ADDRESS = "0x8D29b61C41CF318d15d031BE2928F79630e068e6" ;
16+ const WC2FLR = "0xC67DCE33D7A8efA5FfEB961899C73fe01bCe9273" ;
17+
18+ const SwapAndRedeem = artifacts . require ( "SwapAndRedeem" ) ;
1719
1820// 2. Deploy and verify the `SwapAndRedeem` smart contract
1921async function deployAndVerifyContract ( ) {
20- const SwapAndRedeem = artifacts . require ( "SwapAndRedeem" ) ;
21- const args = [ SWAP_ROUTER_ADDRESS , ASSET_MANAGER_ADDRESS , SWAP_PATH ] ;
22- const swapAndRedeem : SwapAndRedeemInstance = await SwapAndRedeem . new ( ...args ) ;
22+ const assetManager = await getAssetManagerFXRP ( ) ;
23+ const fassetAddress = await assetManager . fAsset ( ) ;
24+ const swapPath = [ WC2FLR , fassetAddress ] ;
25+
26+ const args = [ SWAP_ROUTER_ADDRESS , swapPath ] ;
27+ const swapAndRedeem : SwapAndRedeemInstance = await SwapAndRedeem . new ( ...args ) ;
2328
24- const fassetsSwapAndRedeemAddress = await swapAndRedeem . address ;
29+ const fassetsSwapAndRedeemAddress = await swapAndRedeem . address ;
2530
26- try {
27- await run ( "verify:verify" , {
28- address : fassetsSwapAndRedeemAddress ,
29- constructorArguments : args ,
30- } ) ;
31- } catch ( e ) {
32- console . log ( e ) ;
33- }
31+ try {
32+ await run ( "verify:verify" , {
33+ address : fassetsSwapAndRedeemAddress ,
34+ constructorArguments : args ,
35+ } ) ;
36+ } catch ( e : any ) {
37+ console . log ( e ) ;
38+ }
3439
35- console . log ( "FAssetsSwapAndRedeem deployed to:" , fassetsSwapAndRedeemAddress ) ;
40+ console . log ( "FAssetsSwapAndRedeem deployed to:" , fassetsSwapAndRedeemAddress ) ;
3641
37- return swapAndRedeem ;
42+ return swapAndRedeem ;
3843}
3944
4045async function main ( ) {
41- // 2. Deploy and verify the `SwapAndRedeem` smart contract
42- const swapAndRedeem : SwapAndRedeemInstance = await deployAndVerifyContract ( ) ;
43-
44- // 3. Calculate Required Amounts
45- const swapAndRedeemAddress = await swapAndRedeem . address ;
46- const amounts =
47- await swapAndRedeem . calculateRedemptionAmountIn ( LOTS_TO_REDEEM ) ;
48- const amountIn = amounts . amountIn ;
49- const amountOut = amounts . amountOut ;
50- console . log ( "Amount of tokens out (FXRP): " , amountOut . toString ( ) ) ;
51- console . log ( "Amount of tokens in (WCFLR): " , amountIn . toString ( ) ) ;
52-
53- // 4. Approve spending WCFLR tokens
54- const ERC20 = artifacts . require ( "ERC20" ) ;
55- const wcflr : ERC20Instance = await ERC20 . at ( SWAP_PATH [ 0 ] ) ;
56-
57- const approveTx = await wcflr . approve ( swapAndRedeemAddress , amountOut ) ;
58- console . log ( "Approve transaction: " , approveTx ) ;
59-
60- // 5. Swap WCFLR for FXRP and redeem to underlying XRP token on XRP Ledger
61- const swapResult = await swapAndRedeemAddress . swapAndRedeem (
62- LOTS_TO_REDEEM ,
63- UNDERLYING_ADDRESS ,
64- ) ;
65- console . log ( "Swap and redeem transaction: " , swapResult ) ;
46+ // 2. Deploy and verify the `SwapAndRedeem` smart contract
47+ const swapAndRedeem : SwapAndRedeemInstance = await deployAndVerifyContract ( ) ;
48+
49+ // 3. Calculate Required Amounts
50+ const swapAndRedeemAddress = await swapAndRedeem . address ;
51+ const amounts = await swapAndRedeem . calculateRedemptionAmountIn ( LOTS_TO_REDEEM ) ;
52+ const amountIn = amounts . amountIn ;
53+ const amountOut = amounts . amountOut ;
54+ console . log ( "Amount of tokens out (FXRP): " , amountOut . toString ( ) ) ;
55+ console . log ( "Amount of tokens in (WCFLR): " , amountIn . toString ( ) ) ;
56+
57+ // 4. Approve spending WCFLR tokens
58+ // Get WCFLR token
59+ const ERC20 = artifacts . require ( "ERC20" ) ;
60+ const wcflr : ERC20Instance = await ERC20 . at ( WC2FLR ) ;
61+
62+ const approveTx = await wcflr . approve ( swapAndRedeemAddress , amountOut ) ;
63+ console . log ( "Approve transaction: " , approveTx ) ;
64+
65+ // 5. Swap WCFLR for FXRP and redeem to underlying XRP token on XRP Ledger
66+ const swapResult = await swapAndRedeem . swapAndRedeem ( LOTS_TO_REDEEM , UNDERLYING_ADDRESS ) ;
67+ console . log ( "Swap and redeem transaction: " , swapResult ) ;
6668}
6769
68- main ( ) . catch ( ( error ) => {
69- console . error ( error ) ;
70- process . exitCode = 1 ;
70+ main ( ) . catch ( error => {
71+ console . error ( error ) ;
72+ process . exitCode = 1 ;
7173} ) ;
0 commit comments