Skip to content

Commit 7f1e1ed

Browse files
authored
Merge pull request #84 from 0xwml/thala-adapter
[Thala] update adapter to include xLPT
2 parents 1ab204a + ded99b1 commit 7f1e1ed

File tree

4 files changed

+42
-12
lines changed

4 files changed

+42
-12
lines changed

constants/example_integrations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
KAMINO_SUSDE_COLLATERAL_START_BLOCK_EXAMPLE = 20471904
1919

20-
THALA_SUSDE_START_BLOCK = 2393932881
20+
THALA_SUSDE_START_BLOCK = 2641895151
2121

2222
ECHELON_SUSDE_COLLATERAL_START_BLOCK = 2379805052
2323

constants/thala.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@
99
THALASWAP_V2_ADDRESS = "0x7730cd28ee1cdc9e999336cbc430f99e7c44397c0aa77516f6f23a78559bb5"
1010

1111
SUSDE_LPT_ADDRESS = "0xce9e3b2437fd2cddc5c14f6c4259fc7d3cef160b820837591aa48170bb509368"
12+
13+
THALA_STAKED_LPT_ADDRESS = "0xbab780b31d9cb1d61a47d3a09854c765e6b04e493f112c63294fabf8376d86a1"
14+
15+
SUSDE_XLPT_ADDRESS = "0x35c3e420fa4fd925628366f1977865d62432c8856a2db147a1cb13f7207f6a79"

integrations/thala_integration.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
from constants.thala import (
1313
ETHENA_ADDRESS_API_URL,
1414
SUSDE_LPT_ADDRESS,
15+
SUSDE_XLPT_ADDRESS,
1516
SUSDE_LPT_COIN,
1617
SUSDE_LPT_PID,
1718
THALA_FARMING_V1_ADDRESS,
19+
THALA_STAKED_LPT_ADDRESS,
1820
THALASWAP_V2_ADDRESS,
1921
)
2022
from constants.chains import Chain
@@ -98,9 +100,11 @@ def get_thala_block_data(
98100
"ts-node",
99101
self.thala_ts_location,
100102
THALA_FARMING_V1_ADDRESS,
103+
THALA_STAKED_LPT_ADDRESS,
101104
THALASWAP_V2_ADDRESS,
102105
str(SUSDE_LPT_PID),
103106
str(SUSDE_LPT_ADDRESS),
107+
str(SUSDE_XLPT_ADDRESS),
104108
str(self.decimals),
105109
str(block),
106110
json.dumps(user_addresses),
@@ -139,7 +143,7 @@ def get_thala_block_data(
139143

140144
example_integration_output = example_integration.get_l2_block_balances(
141145
cached_data={},
142-
blocks=list(range(THALA_SUSDE_START_BLOCK, THALA_SUSDE_START_BLOCK + 25306000, 1500000)),
146+
blocks=list(range(THALA_SUSDE_START_BLOCK, THALA_SUSDE_START_BLOCK + 15306000, 1500000)),
143147
)
144148

145149
print("=" * 120)

ts/thala_balances.ts

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,48 @@ const client = new Aptos(config);
99

1010
const args = process.argv.slice(2);
1111
const 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

1921
async 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

Comments
 (0)