From 72843296abebdee1cc42ffb1d31830666fe01789 Mon Sep 17 00:00:00 2001 From: Zakhar Petukhov Date: Fri, 4 Oct 2024 15:35:52 +0800 Subject: [PATCH] add stonfi v2 pool for the rates --- pkg/rates/calculator.go | 2 +- pkg/rates/market.go | 21 ++++++++++++++++----- pkg/rates/rates_test.go | 7 ++++--- pkg/references/jettons.go | 3 ++- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/pkg/rates/calculator.go b/pkg/rates/calculator.go index 9732c449..82154956 100644 --- a/pkg/rates/calculator.go +++ b/pkg/rates/calculator.go @@ -119,7 +119,7 @@ type Mock struct { // TonApiToken the token for TonApi to increase HTTP limits is obtained from https://tonconsole.com/tonapi TonApiToken string // URL to the CSV file from the analytics service https://tonconsole.com/analytics (data is sourced from the TonApi analytics database) - StonFiResultUrl string + StonV1FiResultUrl, StonV2FiResultUrl string // URL to the CSV file from the analytics service https://tonconsole.com/analytics (data is sourced from the TonApi analytics database) DedustResultUrl string } diff --git a/pkg/rates/market.go b/pkg/rates/market.go index 8472f353..be02035d 100644 --- a/pkg/rates/market.go +++ b/pkg/rates/market.go @@ -25,7 +25,8 @@ const ( okx string = "OKX" huobi string = "Huobi" dedust string = "DeDust" - stonfi string = "STON.fi" + stonfiV1 string = "STON.fi v1" + stonfiV2 string = "STON.fi v2" coinbase string = "Coinbase" ) @@ -332,8 +333,13 @@ func (m *Mock) getPools() map[ton.AccountID]float64 { PoolResponseConverter: convertedDeDustPoolResponse, }, { - Name: stonfi, - URL: m.StonFiResultUrl, + Name: stonfiV1, + URL: m.StonV1FiResultUrl, + PoolResponseConverter: convertedStonFiPoolResponse, + }, + { + Name: stonfiV2, + URL: m.StonV2FiResultUrl, PoolResponseConverter: convertedStonFiPoolResponse, }, } @@ -364,7 +370,8 @@ func (m *Mock) getPools() map[ton.AccountID]float64 { func convertedStonFiPoolResponse(pools map[ton.AccountID]float64, respBody io.ReadCloser) (map[ton.AccountID]float64, error) { defer respBody.Close() - pools[references.PTon] = 1 // pTon = TON + pools[references.PTonV1] = 1 // pTonV1 = TON + pools[references.PTonV2] = 1 // pTonV2 = TON reader := csv.NewReader(respBody) records, err := reader.ReadAll() if err != nil { @@ -455,7 +462,11 @@ func convertedStonFiPoolResponse(pools map[ton.AccountID]float64, respBody io.Re } // PTon is the primary token on StonFi, but it has only 50 holders. // To avoid missing tokens, we check for pTON - if (firstAsset.Account != references.PTon && firstAsset.HoldersCount < minHoldersCount) || (secondAsset.Account != references.PTon && secondAsset.HoldersCount < minHoldersCount) { + isNotPTon := func(account ton.AccountID) bool { + return account != references.PTonV1 && account != references.PTonV2 + } + if (isNotPTon(firstAsset.Account) && firstAsset.HoldersCount < minHoldersCount) || + (isNotPTon(secondAsset.Account) && secondAsset.HoldersCount < minHoldersCount) { continue } updateActualAssets(firstAsset, firstAsset, secondAsset) diff --git a/pkg/rates/rates_test.go b/pkg/rates/rates_test.go index 2176f4bd..24e00358 100644 --- a/pkg/rates/rates_test.go +++ b/pkg/rates/rates_test.go @@ -27,7 +27,8 @@ asset_0_account_id,asset_1_account_id,asset_0_reserve,asset_1_reserve,asset_0_me 0:b113a994b5024a16719f69139328eb759596c38a25f59028b146fecdc3621dfe,0:8cdc1d7640ad5ee326527fc1ad0514f468b30dc84b0173f0e155f451b4e11f7c,54581198678395,9745288354931876,"{""decimals"":""6"",""name"":""Tether USD"",""symbol"":""USD₮""}","{""decimals"":""9"",""name"":""Proxy TON"",""symbol"":""pTON""}",1038000,52 0:b113a994b5024a16719f69139328eb759596c38a25f59028b146fecdc3621dfe,0:afc49cb8786f21c87045b19ede78fc6b46c51048513f8e9a6d44060199c1bf0c,996119000168,921942515487299500,"{""decimals"":""6"",""name"":""Tether USD"",""symbol"":""USD₮""}","{""decimals"":""9"",""name"":""Dogs"",""symbol"":""DOGS""}",1050066,881834`, expected: map[ton.AccountID]float64{ - ton.MustParseAccountID("0:8cdc1d7640ad5ee326527fc1ad0514f468b30dc84b0173f0e155f451b4e11f7c"): 1, // Default pTon price + ton.MustParseAccountID("0:8cdc1d7640ad5ee326527fc1ad0514f468b30dc84b0173f0e155f451b4e11f7c"): 1, // Default pTonV1 price + ton.MustParseAccountID("0:671963027f7f85659ab55b821671688601cdcf1ee674fc7fbbb1a776a18d34a3"): 1, // Default pTonV2 price ton.MustParseAccountID("0:65aac9b5e380eae928db3c8e238d9bc0d61a9320fdc2bc7a2f6c87d6fedf9208"): 0.6236390657633181, ton.MustParseAccountID("0:b113a994b5024a16719f69139328eb759596c38a25f59028b146fecdc3621dfe"): 0.17854661661707652, ton.MustParseAccountID("0:afc49cb8786f21c87045b19ede78fc6b46c51048513f8e9a6d44060199c1bf0c"): 0.00019291189444059384, @@ -42,8 +43,8 @@ asset_0_account_id,asset_1_account_id,asset_0_reserve,asset_1_reserve,asset_0_me 0:8cdc1d7640ad5ee326527fc1ad0514f468b30dc84b0173f0e155f451b4e11f7c,0:65aac9b5e380eae928db3c8e238d9bc0d61a9320fdc2bc7a2f6c87d6fedf9208,356773586306,572083446808,"{""decimals"":""9"",""name"":""Proxy TON"",""symbol"":""pTON""}","{""name"":""Scaleton"",""symbol"":""SCALE""}",52,10 `, expected: map[ton.AccountID]float64{ - // Default pTon price - ton.MustParseAccountID("0:8cdc1d7640ad5ee326527fc1ad0514f468b30dc84b0173f0e155f451b4e11f7c"): 1, + ton.MustParseAccountID("0:8cdc1d7640ad5ee326527fc1ad0514f468b30dc84b0173f0e155f451b4e11f7c"): 1, // Default pTonV1 price + ton.MustParseAccountID("0:671963027f7f85659ab55b821671688601cdcf1ee674fc7fbbb1a776a18d34a3"): 1, // Default pTonV2 price }, }, } diff --git a/pkg/references/jettons.go b/pkg/references/jettons.go index 51d75ffb..b25d6f2a 100644 --- a/pkg/references/jettons.go +++ b/pkg/references/jettons.go @@ -10,4 +10,5 @@ var JUsdtSlp = ton.MustParseAccountID("EQAlM_4LY6sP1QOur5aGdFBSa5ma6nqwldflmm9ms var TonSlp = ton.MustParseAccountID("EQCNY2AQ3ZDYwJAqx_nzl9i9Xhd_Ex7izKJM6JTxXRnO6n1F") var UsdtSlp = ton.MustParseAccountID("EQCup4xxCulCcNwmOocM9HtDYPU8xe0449tQLp6a-5BLEegW") -var PTon = ton.MustParseAccountID("EQCM3B12QK1e4yZSf8GtBRT0aLMNyEsBc_DhVfRRtOEffLez") +var PTonV1 = ton.MustParseAccountID("EQCM3B12QK1e4yZSf8GtBRT0aLMNyEsBc_DhVfRRtOEffLez") +var PTonV2 = ton.MustParseAccountID("EQBnGWMCf3-FZZq1W4IWcWiGAc3PHuZ0_H-7sad2oY00o83S")