Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ repos:
- id: trailing-whitespace
exclude: ^swagger_client/
- repo: https://github.com/PyCQA/flake8
rev: 3.9.2
rev: 7.2.0
hooks:
- id: flake8
exclude: '^swagger_client/'
Expand Down
45 changes: 45 additions & 0 deletions goplus/locker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright 2023 The GoPlus. All rights reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from goplus.base import Base
from swagger_client.api.lock_controller_api import LockControllerApi


class Locker(Base):
def __init__(self, access_token=None):
super().__init__(access_token=access_token)
self.api = LockControllerApi()

def locker_token(
self, chain_id: str, token_address: str, page_num: int, page_size: int, **kwargs
):
return self.api.get_token_lockers_using_get(
chain_id=chain_id,
token_address=token_address,
page_num=page_num,
page_size=page_size,
**self.authorization,
**kwargs
)

def locker_lp_v3(
self, chain_id: str, pool_address: str, page_num: int, page_size: int, **kwargs
):
return self.api.get_nft_lockers_using_get(
chain_id=chain_id,
pool_address=pool_address,
page_num=page_num,
page_size=page_size,
**self.authorization,
**kwargs
)
22 changes: 22 additions & 0 deletions goplus/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

from goplus.base import Base
from swagger_client.api.token_controller_v_1_api import TokenControllerV1Api
from swagger_client.api.token_security_api_for_solana__beta_api import (
TokenSecurityAPIForSolanaBetaApi,
)
from swagger_client.api.token_security_api_for_sui_api import TokenSecurityAPIForSuiApi


class Token(Base):
Expand All @@ -23,6 +27,8 @@ class Token(Base):
def __init__(self, access_token=None):
super().__init__(access_token=access_token)
self.api = TokenControllerV1Api()
self.solana_api = TokenSecurityAPIForSolanaBetaApi()
self.sui_api = TokenSecurityAPIForSuiApi()

@staticmethod
def __check(addresses):
Expand All @@ -43,3 +49,19 @@ def token_security(self, chain_id: str, addresses: list, **kwargs):
**self.authorization,
**kwargs
)

def solana_token_security(self, addresses: list, **kwargs):

self.__check(addresses)

return self.solana_api.solana_token_security_using_get(
contract_addresses=",".join(addresses), **self.authorization, **kwargs
)

def sui_token_security(self, addresses: list, **kwargs):

self.__check(addresses)

return self.sui_api.sui_token_security_using_get(
contract_addresses=",".join(addresses), **self.authorization, **kwargs
)
28 changes: 28 additions & 0 deletions goplus/tx_simulation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2023 The GoPlus. All rights reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from goplus.base import Base
from swagger_client.api.transaction_simulation_for_solana_api import (
TransactionSimulationForSolanaApi,
)


class TxSimulation(Base):
def __init__(self, access_token=None):
super().__init__(access_token=access_token)
self.api = TransactionSimulationForSolanaApi()

def solana_tx_simulation(self, encoded_transaction: str, **kwargs):

body = {"encoded_transaction": encoded_transaction}
return self.api.prerun_tx_using_post(body=body, **self.authorization, **kwargs)
78 changes: 78 additions & 0 deletions test_goplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,40 @@
from goplus.dapp import Dapp
from goplus.decode import Decode
from goplus.errorcode import Code
from goplus.locker import Locker
from goplus.nft import Nft
from goplus.phishing_site import PushingSite
from goplus.rug_pull import RugPull
from goplus.token import Token
from goplus.tx_simulation import TxSimulation


class TokenTest(unittest.TestCase):
def test_token_security(self):
# token
res = Token().token_security(
chain_id="1", addresses=["0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"]
)
self.assertEqual(res.code, Code.SUCCESS, res.message)

def test_solana_token_security(self):

# solana
res = Token().solana_token_security(
addresses=["HZ1JovNiVvGrGNiiYvEozEVgZ58xaU3RKwX8eACQBCt3"]
)
self.assertEqual(res.code, Code.SUCCESS, res.message)

def test_sui_token_security(self):

# sui
res = Token().sui_token_security(
addresses=[
"0x40402a987c2f8a71b755561bfbd16c2cbb991e27e609ad148809491c32bacab9::kui::KUI"
]
)
self.assertEqual(res.code, Code.SUCCESS, res.message)


class AddressTest(unittest.TestCase):
def test_address_security(self):
Expand Down Expand Up @@ -105,5 +126,62 @@ def test_rug_pull_security(self):
self.assertEqual(res.code, Code.SUCCESS, res.message)


class LockerTest(unittest.TestCase):
def test_locker_token(self):
res = Locker().locker_token(
chain_id="8453",
page_num=1,
page_size=100,
token_address="0x6fd0303649296360f10c07b24521deda9223086d",
)
self.assertEqual(res.code, Code.SUCCESS, res.message)

def test_locker_lp_v3(self):
res = Locker().locker_lp_v3(
chain_id="56",
page_num=1,
page_size=100,
pool_address="0x579df956c6cE6178fBBD78bbE4f05786cFBA9B76",
)
self.assertEqual(res.code, Code.SUCCESS, res.message)


class TxSimulationTest(unittest.TestCase):
def test_solana_tx_simulation(self):
res = TxSimulation().solana_tx_simulation(
encoded_transaction="AT+Td4vATQ8bPgyQPt25Hp6Ve2jECOkwS3+PC5Z8HhLK"
"/7mDbnQ8tW3sKzQnNeVWxsJzo8knzMhQZbnL+FpzVgOAAQADGuG"
"EgGi3qMErQECfFXEVxCXlALMU02fKK0Yf27WbmN3in"
"0h2yAJOqRM87lkKfGtIJh/K1ZeTCGy7baAOhr7lAHEGm4hX/quBhPt"
"of2NGGMA12sQ53BrrO1WYoPAA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