diff --git a/pkg/assets/default_assets.go b/pkg/assets/default_assets.go index 52e436b7..9f433de7 100644 --- a/pkg/assets/default_assets.go +++ b/pkg/assets/default_assets.go @@ -53,13 +53,30 @@ func (s *AssetsStore) InitDefault() error { return err } - if _, err := os.Stat(defaultAssetsJSONPath); os.IsNotExist(err) { - if err := s.createFileDefault(defaultAssetsJSONPath); err != nil { + // if the file does not exist, create the default assets JSON file + _, err = os.Stat(defaultAssetsJSONPath) + if os.IsNotExist(err) { + // Create the default assets JSON file + return s.createFileDefault(defaultAssetsJSONPath) + } + + // if the file exists, read the content and compare it with the default assets + if err == nil { + // read the content of the default assets JSON file + content, err := os.ReadFile(defaultAssetsJSONPath) + if err != nil { return err } + + // if the content is different, overwrite the default assets JSON file + if string(content) != assetsJSON { + if err := s.createFileDefault(defaultAssetsJSONPath); err != nil { + return err + } + } } - return nil + return err } // getDefaultJSONPath returns the path to the default assets JSON file. @@ -69,7 +86,14 @@ func getDefaultJSONPath(assetsJSONDir string) (string, error) { // createFileDefault creates the default assets JSON file with the default assets. func (s *AssetsStore) createFileDefault(path string) error { - if err := os.WriteFile(path, []byte(`[ + if err := os.WriteFile(path, []byte(assetsJSON), permissionUrwGrOr); err != nil { + return err + } + + return nil +} + +const assetsJSON = `[ { "address": "AS12k8viVmqPtRuXzCm6rKXjLgpQWqbuMjc37YHhB452KSUUb9FgL", "name": "Sepolia USDC", @@ -118,10 +142,33 @@ func (s *AssetsStore) createFileDefault(path string) error { "symbol": "WETH.e", "decimals": 18, "MEXCSymbol": "ETHUSDT" + }, + { + "address": "", + "name": "Wrapped Ether", + "symbol": "WETH.b", + "decimals": 18, + "MEXCSymbol": "ETHUSDT" + }, + { + "address": "", + "name": "Wrapped Binance USD", + "symbol": "USDT.b", + "decimals": 18, + "MEXCSymbol": "USD" + }, + { + "address": "AS12RmCXTA9NZaTBUBnRJuH66AGNmtEfEoqXKxLdmrTybS6GFJPFs", + "name": "Wrapped Ether", + "symbol": "WETH.bt", + "decimals": 18, + "MEXCSymbol": "ETHUSDT" + }, + { + "address": "AS12ix1Qfpue7BB8q6mWVtjNdNE9UV3x4MaUo7WhdUubov8sJ3CuP", + "name": "Wrapped Binance USD", + "symbol": "USDT.bt", + "decimals": 18, + "MEXCSymbol": "USD" } -]`), permissionUrwGrOr); err != nil { - return err - } - - return nil -} +]`