|
1 | | -import { artifacts, ethers } from "hardhat"; |
| 1 | +import { getFXRPAssetManager } from "../utils/fassets"; |
| 2 | +import { prepareAttestationRequestBase } from "../utils/fdc"; |
| 3 | +import { IAssetManagerInstance } from "../../typechain-types"; |
| 4 | +import { logEvents } from "../../scripts/utils/core"; |
2 | 5 |
|
3 | | -import { prepareAttestationRequestBase } from "../fdcExample/Base"; |
4 | | -import { |
5 | | - IAssetManagerInstance, |
6 | | - IAssetManagerContract, |
7 | | -} from "../../typechain-types"; |
| 6 | +// yarn hardhat run scripts/fassets/executeMinting.ts --network coston2 |
8 | 7 |
|
9 | 8 | // 1. Environment variables |
10 | | -const { COSTON2_DA_LAYER_URL, VERIFIER_URL_TESTNET, VERIFIER_API_KEY_TESTNET } = |
11 | | - process.env; |
| 9 | +const { COSTON2_DA_LAYER_URL, VERIFIER_URL_TESTNET, VERIFIER_API_KEY_TESTNET } = process.env; |
12 | 10 |
|
13 | | -// 2. AssetManager address on Flare Testnet Coston2 network |
14 | | -const ASSET_MANAGER_ADDRESS = "0xDeD50DA9C3492Bee44560a4B35cFe0e778F41eC5"; |
| 11 | +// 2. Collateral reservation ID |
| 12 | +const COLLATERAL_RESERVATION_ID = 10255417; |
15 | 13 |
|
16 | | -// 3. Collateral reservation ID |
17 | | -const COLLATERAL_RESERVATION_ID = 18615047; |
18 | | - |
19 | | -// 4. Data to get the proof for |
20 | | -const TARGET_ROUND_ID = 987510; |
| 14 | +// 3. FDC round id to get the proof for |
| 15 | +const TARGET_ROUND_ID = 1053806; |
21 | 16 |
|
| 17 | +// 4. FDC request data |
22 | 18 | const attestationTypeBase = "Payment"; |
23 | 19 | const sourceIdBase = "testXRP"; |
24 | 20 | const verifierUrlBase = VERIFIER_URL_TESTNET; |
25 | 21 | const urlTypeBase = "xrp"; |
26 | 22 |
|
27 | | -// XRP transaction |
28 | | -const transactionId = |
29 | | - "65520665BB83D582E01D6813DA8B5ECB041F613F9891F9BE90EE2668AAC30543"; |
| 23 | +const transactionId = "EC0FC5F40FBE6AEAD31138898C71687B2902E462FD1BFEF3FB443BE5E2C018F9"; |
30 | 24 | const inUtxo = "0"; |
31 | 25 | const utxo = "0"; |
32 | 26 |
|
33 | | -// 5. Prepare FDC request |
34 | | -async function prepareFdcRequest( |
35 | | - transactionId: string, |
36 | | - inUtxo: string, |
37 | | - utxo: string, |
38 | | -) { |
39 | | - const requestBody = { |
40 | | - transactionId: transactionId, |
41 | | - inUtxo: inUtxo, |
42 | | - utxo: utxo, |
43 | | - }; |
44 | | - |
45 | | - const url = `${verifierUrlBase}verifier/${urlTypeBase}/Payment/prepareRequest`; |
46 | | - |
47 | | - return await prepareAttestationRequestBase( |
48 | | - url, |
49 | | - VERIFIER_API_KEY_TESTNET, |
50 | | - attestationTypeBase, |
51 | | - sourceIdBase, |
52 | | - requestBody, |
53 | | - ); |
| 27 | +// 5. AssetManager contract |
| 28 | +const AssetManager = artifacts.require("IAssetManager"); |
| 29 | + |
| 30 | +// 6. Prepare FDC request |
| 31 | +async function prepareFdcRequest(transactionId: string, inUtxo: string, utxo: string) { |
| 32 | + const requestBody = { |
| 33 | + transactionId: transactionId, |
| 34 | + inUtxo: inUtxo, |
| 35 | + utxo: utxo, |
| 36 | + }; |
| 37 | + |
| 38 | + const url = `${verifierUrlBase}verifier/${urlTypeBase}/Payment/prepareRequest`; |
| 39 | + |
| 40 | + return await prepareAttestationRequestBase( |
| 41 | + url, |
| 42 | + VERIFIER_API_KEY_TESTNET, |
| 43 | + attestationTypeBase, |
| 44 | + sourceIdBase, |
| 45 | + requestBody |
| 46 | + ); |
54 | 47 | } |
55 | 48 |
|
56 | | -// 6. Get proof from FDC |
| 49 | +// 7. Get proof from FDC |
57 | 50 | async function getProof(roundId: number) { |
58 | | - const request = await prepareFdcRequest(transactionId, inUtxo, utxo); |
59 | | - const proofAndData = await fetch( |
60 | | - `${COSTON2_DA_LAYER_URL}api/v0/fdc/get-proof-round-id-bytes`, |
61 | | - { |
62 | | - method: "POST", |
63 | | - headers: { |
64 | | - "Content-Type": "application/json", |
65 | | - "X-API-KEY": VERIFIER_API_KEY_TESTNET, |
66 | | - }, |
67 | | - body: JSON.stringify({ |
68 | | - votingRoundId: roundId, |
69 | | - requestBytes: request.abiEncodedRequest, |
70 | | - }), |
71 | | - }, |
72 | | - ); |
73 | | - |
74 | | - return await proofAndData.json(); |
| 51 | + const request = await prepareFdcRequest(transactionId, inUtxo, utxo); |
| 52 | + const proofAndData = await fetch(`${COSTON2_DA_LAYER_URL}api/v0/fdc/get-proof-round-id-bytes`, { |
| 53 | + method: "POST", |
| 54 | + headers: { |
| 55 | + "Content-Type": "application/json", |
| 56 | + "X-API-KEY": VERIFIER_API_KEY_TESTNET, |
| 57 | + }, |
| 58 | + body: JSON.stringify({ |
| 59 | + votingRoundId: roundId, |
| 60 | + requestBytes: request.abiEncodedRequest, |
| 61 | + }), |
| 62 | + }); |
| 63 | + |
| 64 | + return await proofAndData.json(); |
75 | 65 | } |
76 | 66 |
|
77 | | -async function parseEvents(receipt) { |
78 | | - console.log("\nParsing events...", receipt.rawLogs); |
79 | | - |
80 | | - const assetManager = (await ethers.getContractAt( |
81 | | - "IAssetManager", |
82 | | - ASSET_MANAGER_ADDRESS, |
83 | | - )) as IAssetManagerContract; |
84 | | - |
85 | | - for (const log of receipt.rawLogs) { |
86 | | - try { |
87 | | - const parsedLog = assetManager.interface.parseLog({ |
88 | | - topics: log.topics, |
89 | | - data: log.data, |
90 | | - }); |
91 | | - |
92 | | - if (!parsedLog) continue; |
93 | | - |
94 | | - const collateralReservedEvents = [ |
95 | | - "RedemptionTicketCreated", |
96 | | - "MintingExecuted", |
97 | | - ]; |
98 | | - if (!collateralReservedEvents.includes(parsedLog.name)) continue; |
99 | | - |
100 | | - console.log(`\nEvent: ${parsedLog.name}`); |
101 | | - console.log("Arguments:", parsedLog.args); |
102 | | - } catch (e) { |
103 | | - console.log("Error parsing event:", e); |
104 | | - } |
105 | | - } |
| 67 | +// 8. Parse events |
| 68 | +async function parseEvents(receipt: any) { |
| 69 | + console.log("\nParsing events...", receipt.rawLogs); |
| 70 | + |
| 71 | + logEvents(receipt.rawLogs, "RedemptionTicketCreated", AssetManager.abi); |
| 72 | + |
| 73 | + logEvents(receipt.rawLogs, "MintingExecuted", AssetManager.abi); |
106 | 74 | } |
107 | 75 |
|
108 | 76 | async function main() { |
109 | | - // 7. Get proof from FDC |
110 | | - const proof = await getProof(TARGET_ROUND_ID); |
111 | | - |
112 | | - // FAssets FXRP asset manager on Songbird Testnet Coston2 network |
113 | | - const AssetManager = artifacts.require("IAssetManager"); |
114 | | - const assetManager: IAssetManagerInstance = await AssetManager.at( |
115 | | - ASSET_MANAGER_ADDRESS, |
116 | | - ); |
117 | | - |
118 | | - // 8. Execute minting with the proof |
119 | | - const tx = await assetManager.executeMinting( |
120 | | - { |
121 | | - merkleProof: proof.proof, |
122 | | - data: proof.response, |
123 | | - }, |
124 | | - COLLATERAL_RESERVATION_ID, |
125 | | - ); |
126 | | - console.log("Transaction successful:", tx); |
127 | | - |
128 | | - // 9. Parse execute minting log events |
129 | | - await parseEvents(tx.receipt); |
| 77 | + // 9. Get proof from FDC |
| 78 | + const proof = await getProof(TARGET_ROUND_ID); |
| 79 | + |
| 80 | + const assetManager: IAssetManagerInstance = await getFXRPAssetManager(); |
| 81 | + |
| 82 | + // 10. Execute minting |
| 83 | + const tx = await assetManager.executeMinting( |
| 84 | + { |
| 85 | + merkleProof: proof.proof, |
| 86 | + data: proof.response, |
| 87 | + }, |
| 88 | + COLLATERAL_RESERVATION_ID |
| 89 | + ); |
| 90 | + console.log("Transaction successful:", tx); |
| 91 | + |
| 92 | + // 11. Parse execute minting log events |
| 93 | + await parseEvents(tx.receipt); |
130 | 94 | } |
131 | 95 |
|
132 | | -main().catch((error) => { |
133 | | - console.error(error); |
134 | | - process.exitCode = 1; |
| 96 | +main().catch(error => { |
| 97 | + console.error(error); |
| 98 | + process.exitCode = 1; |
135 | 99 | }); |
0 commit comments