@@ -12,15 +12,12 @@ require('dotenv').config({ path: '../../../.env' });
1212 * Step 1. GET /assets API
1313 * Retrieves:
1414 * - The list of assets supported for burning
15+ * - Treasury Account Wallet ID for the specified stablecoin, to which the funds need to be sent
1516 *
16- * Step 2. GET /{token}/constants API
17- * Retrieves:
18- * - Treasury Account Wallet ID for the specified stablecoin
19- *
20- * Step 3. POST /order API
17+ * Step 2. POST /order API
2118 * Creates a Burn Order with the specified parameters
2219 *
23- * Step 4 . Transfer the assets to be burnt, to the treasury account
20+ * Step 3 . Transfer the assets to be burnt, to the treasury account
2421 * Initiates the send transaction to the Treasury Account using sendMany
2522 */
2623
@@ -34,7 +31,7 @@ const walletPassphrase = ''; // Wallet passphrase
3431const usdcoin = 'tfiatusd' ; // USD asset token
3532const stablecoin = 'tbsc:usd1' ; // Stablecoin to burn
3633const ofcStablecoin = `ofc${ stablecoin } ` ; // ofc stablecoin (for initiating the send from the specified GoAccount wallet to the Treasury Go Account)
37- const fromAmountInFullUnits = '100' ; // Amount in full units of the stablecoin (3 tbsc:usd1) - Must be an integer
34+ const fromAmountInFullUnits = '100' ; // Amount in full units of the stablecoin (100 tbsc:usd1) - Must be an integer
3835// Note: fromAmount will be calculated dynamically using asset decimals
3936
4037// Initialize BitGo SDK
@@ -46,24 +43,6 @@ function createStablecoinUrl(path: string): string {
4643 return common . Environments [ bitgo . getEnv ( ) ] . uri + '/api/stablecoin/v1' + path ;
4744}
4845
49- /**
50- * Fetch treasury wallet ID from the constants API
51- * @param token - The stablecoin token to get constants for
52- * @returns The treasury account wallet ID
53- */
54- async function fetchTreasuryWalletId ( token : string ) : Promise < string > {
55- console . log ( `\n🔍 STEP 2: Fetching treasury wallet ID from constants API for ${ token } ...` ) ;
56- const constants = await bitgo . get ( createStablecoinUrl ( `/${ token } /constants` ) ) ;
57- const treasuryAccountWalletId = constants . body . trustAccountWalletId ;
58-
59- if ( ! treasuryAccountWalletId ) {
60- throw new Error ( `Treasury account wallet ID not found in constants for ${ token } ` ) ;
61- }
62-
63- console . log ( `🏦 Treasury Account Wallet ID (from constants): ${ treasuryAccountWalletId } ` ) ;
64- return treasuryAccountWalletId ;
65- }
66-
6746/**
6847 * Main function to execute the stablecoin burn order process
6948 */
@@ -77,8 +56,7 @@ async function main() {
7756 console . log ( '=' . repeat ( 50 ) ) ;
7857
7958 // Execute the burn order process step by step
80- const { usdAsset, stablecoinAsset, fromAmount } = await fetchAndValidateAssets ( ) ;
81- const treasuryAccountWalletId = await fetchTreasuryWalletId ( stablecoin ) ;
59+ const { usdAsset, stablecoinAsset, treasuryAccountWalletId, fromAmount } = await fetchAndValidateAssets ( ) ;
8260 const newOrder = await createBurnOrder ( stablecoinAsset , usdAsset , fromAmount ) ;
8361 await sendTokensToTreasury ( treasuryAccountWalletId , newOrder . id , fromAmount ) ;
8462 const order = await fetchOrderDetails ( newOrder . id ) ;
@@ -119,9 +97,14 @@ async function fetchAndValidateAssets() {
11997 console . log ( `📋 USD Asset: ${ usdAsset . token } (ID: ${ usdAsset . id } )` ) ;
12098 console . log ( `🪙 Stablecoin Asset: ${ stablecoinAsset . token } (ID: ${ stablecoinAsset . id } )` ) ;
12199
100+ const treasuryAccountWalletId = stablecoinAsset . treasuryAccountWalletId ;
122101 // Calculate fromAmount using stablecoin asset decimals
123102 const decimals = stablecoinAsset . decimals ;
124103
104+ if ( ! treasuryAccountWalletId ) {
105+ throw new Error ( `Treasury account wallet ID not found for ${ stablecoin } ` ) ;
106+ }
107+
125108 if ( decimals === undefined ) {
126109 throw new Error ( `Decimals not found for ${ stablecoin } ` ) ;
127110 }
@@ -133,8 +116,9 @@ async function fetchAndValidateAssets() {
133116 console . log ( ` • Full Units: ${ fromAmountInFullUnits } ${ stablecoinAsset . token } ` ) ;
134117 console . log ( ` • Decimals: ${ decimals } ` ) ;
135118 console . log ( ` • Base Units: ${ fromAmount } ` ) ;
119+ console . log ( `🏦 Treasury Account Wallet ID: ${ treasuryAccountWalletId } ` ) ;
136120
137- return { usdAsset, stablecoinAsset, fromAmount } ;
121+ return { usdAsset, stablecoinAsset, treasuryAccountWalletId , fromAmount } ;
138122}
139123
140124/**
@@ -145,7 +129,7 @@ async function fetchAndValidateAssets() {
145129 * @returns The created order object
146130 */
147131async function createBurnOrder ( stablecoinAsset : any , usdAsset : any , fromAmount : string ) {
148- console . log ( '\n🔥 STEP 3 : Creating burn order...' ) ;
132+ console . log ( '\n🔥 STEP 2 : Creating burn order...' ) ;
149133
150134 const orderRequestBody = {
151135 sourceWalletId : walletId ,
@@ -181,7 +165,7 @@ async function createBurnOrder(stablecoinAsset: any, usdAsset: any, fromAmount:
181165 * @returns The transaction object
182166 */
183167async function sendTokensToTreasury ( treasuryAccountWalletId : string , orderId : string , fromAmount : string ) {
184- console . log ( '\n💸 STEP 4 : Sending stablecoin to treasury account...' ) ;
168+ console . log ( '\n💸 STEP 3 : Sending stablecoin to treasury account...' ) ;
185169
186170 const walletInstance = await basecoin . wallets ( ) . get ( { id : walletId } ) ;
187171
@@ -208,7 +192,7 @@ async function sendTokensToTreasury(treasuryAccountWalletId: string, orderId: st
208192}
209193
210194async function fetchOrderDetails ( orderId : string ) {
211- console . log ( '\n🔍 STEP 5 : Fetching final order details...' ) ;
195+ console . log ( '\n🔍 STEP 4 : Fetching final order details...' ) ;
212196 const orderResponse = await bitgo . get ( createStablecoinUrl ( `/enterprise/${ enterpriseId } /orders/${ orderId } ` ) ) . send ( ) ;
213197 return orderResponse . body ;
214198}
0 commit comments