From d1d39592bc8e5d4332afe42f3f652151da13b7a2 Mon Sep 17 00:00:00 2001 From: n3wbie Date: Thu, 2 May 2024 15:15:19 +0900 Subject: [PATCH] fix: userCalled check condition --- .../r/demo/gnoswap/common/allow_non_gnoswap_contracts.gno | 4 ++-- router/router.gno | 5 ++++- staker/staker.gno | 5 ++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/_deploy/r/demo/gnoswap/common/allow_non_gnoswap_contracts.gno b/_deploy/r/demo/gnoswap/common/allow_non_gnoswap_contracts.gno index 6f190cb9d..59147e603 100644 --- a/_deploy/r/demo/gnoswap/common/allow_non_gnoswap_contracts.gno +++ b/_deploy/r/demo/gnoswap/common/allow_non_gnoswap_contracts.gno @@ -27,8 +27,8 @@ func MustCallFromAdmin() { } func DisallowCallFromUser() { - isOrigin := std.IsOriginCall() - if isOrigin { + prevRealmPath := std.PrevRealm().PkgPath() + if prevRealmPath == "" { panic("must be called by realm, not user") } } diff --git a/router/router.gno b/router/router.gno index 403460940..8c7f48676 100644 --- a/router/router.gno +++ b/router/router.gno @@ -38,7 +38,10 @@ func SwapRoute( _tokenAmountLimit string, // uint256 ) (string, string) { // tokneIn, tokenOut if common.GetLimitCaller() { - std.AssertOriginCall() + isUserCalled := std.PrevRealm().PkgPath() == "" + if !isUserCalled { + panic("[ROUTER] router.gno__SwapRoute() || only user can call this function") + } } amountSpecified := i256.MustFromDecimal(_amountSpecified) diff --git a/staker/staker.gno b/staker/staker.gno index a5125598b..9a5ce7630 100644 --- a/staker/staker.gno +++ b/staker/staker.gno @@ -57,7 +57,10 @@ func CreateExternalIncentive( endTimestamp int64, ) { if common.GetLimitCaller() { - std.AssertOriginCall() + isUserCalled := std.PrevRealm().PkgPath() == "" + if !isUserCalled { + panic("[STAKER] staker.gno__CreateExternalIncentive() || only user can call this function") + } } rewardAmount := u256.MustFromDecimal(_rewardAmount)