Skip to content

Commit

Permalink
add stonfi v2 pool for the rates
Browse files Browse the repository at this point in the history
  • Loading branch information
zakhar-petukhov committed Oct 4, 2024
1 parent 5fe6016 commit 7284329
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pkg/rates/calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
21 changes: 16 additions & 5 deletions pkg/rates/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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,
},
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions pkg/rates/rates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
},
},
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/references/jettons.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit 7284329

Please sign in to comment.