@@ -9,26 +9,48 @@ const client = new Aptos(config);
99
1010const args = process . argv . slice ( 2 ) ;
1111const THALA_V1_FARMING_ADDRESS = args [ 0 ] ;
12- const THALASWAP_V2_ADDRESS = args [ 1 ] ;
13- const SUSDE_LPT_PID = args [ 2 ] ;
14- const SUSDE_LPT_ADDRESS = args [ 3 ] ;
15- const decimals = Number ( args [ 4 ] ) ;
16- const block = Number ( args [ 5 ] ) ;
17- const user_addresses : Array < string > = JSON . parse ( args [ 6 ] ) ;
12+ const THALA_STAKED_LPT_ADDRESS = args [ 1 ] ;
13+ const THALASWAP_V2_ADDRESS = args [ 2 ] ;
14+ const SUSDE_LPT_PID = args [ 3 ] ;
15+ const SUSDE_LPT_ADDRESS = args [ 4 ] ;
16+ const SUSDE_XLPT_ADDRESS = args [ 5 ] ;
17+ const decimals = Number ( args [ 6 ] ) ;
18+ const block = Number ( args [ 7 ] ) ;
19+ const user_addresses : Array < string > = JSON . parse ( args [ 8 ] ) ;
1820
1921async function getStrategy ( ) {
2022 // iterate over all users and get their susde balance
2123 const user_balances : Record < string , number > = { } ;
2224 for ( const address of user_addresses ) {
23- const [ stake_amount , _boosted_stake_amount , _boost_multiplier ] = await client . view < string [ ] > ( {
25+ // 1. Fetch thala_v1_farming stake amount
26+ const [ stake_amount_lpt , _boosted_stake_amount_lpt , _boost_multiplier_lpt ] = await client . view < string [ ] > ( {
2427 payload : {
2528 function : `${ THALA_V1_FARMING_ADDRESS } ::farming::stake_amount` ,
2629 functionArguments : [ address , Number ( SUSDE_LPT_PID ) ] ,
2730 } ,
2831 options : { ledgerVersion : block } ,
2932 } ) ;
3033
31- // 1. preview how much sUSDE/USDC is returned when 1 LPT is removed (the pool LPT distribution)
34+ // 2. Fetch thala_staked_lpt stake amount
35+ let stake_amount_xlpt = "0" ; // default to 0 if the view fails
36+
37+ try {
38+ const [ _boosted_stake_amount_xlpt , stakeResult ] = await client . view < string [ ] > ( {
39+ payload : {
40+ function : `${ THALA_STAKED_LPT_ADDRESS } ::staked_lpt::user_stake_amount` ,
41+ functionArguments : [ address , `${ SUSDE_XLPT_ADDRESS } ` ] ,
42+ } ,
43+ options : { ledgerVersion : block } ,
44+ } ) ;
45+
46+ stake_amount_xlpt = stakeResult ;
47+ } catch ( e ) {
48+ }
49+
50+ // 3. Sum respective farming amounts
51+ let stake_amount = Number ( stake_amount_lpt ) + Number ( stake_amount_xlpt ) ;
52+
53+ // 4. preview how much sUSDE/USDC is returned when 1 LPT is removed (the pool LPT distribution)
3254 let [ lptPreview ] = await client . view < any [ ] > ( {
3355 payload : {
3456 function : `${ THALASWAP_V2_ADDRESS } ::pool::preview_remove_liquidity` ,
@@ -37,7 +59,7 @@ async function getStrategy() {
3759 options : { ledgerVersion : block } ,
3860 } ) ;
3961
40- // 2 . preview the sUSDE/USDC exchange rate of 1 sUSDE
62+ // 5 . preview the sUSDE/USDC exchange rate of 1 sUSDE
4163 let [ swapPreview ] = await client . view < any [ ] > ( {
4264 payload : {
4365 function : `${ THALASWAP_V2_ADDRESS } ::pool::preview_swap_exact_in_metastable` ,
@@ -50,7 +72,7 @@ async function getStrategy() {
5072 let lptPrice = ( ( lptPreview . withdrawn_amounts [ 0 ] / 100000000 * swapPreview . amount_out / 100000000 ) + ( lptPreview . withdrawn_amounts [ 1 ] / 100000000 ) ) * 100 ;
5173
5274 user_balances [ address ] = scaleDownByDecimals (
53- Number ( stake_amount ) ,
75+ stake_amount ,
5476 decimals
5577 ) * lptPrice ;
5678 }
0 commit comments