Transaction
6660FEFAB2BED2…A6804B378171
Block 1,651,931 · index 0 · indexed
Summary
- Hash
- 6660FEFAB2BED2EBC885B5261720AA0E5AB1401D03D9476510A0A6804B378171
- Block
- 1,651,931
- Size
- 6568 bytes
- Gas used
- 13,871,969 / 16,646,327
- Fee
- 16647 ugnot
- Status
- success
Messages
Arguments · 21
- #1whitelist
- #2assert.gno
- #3package whitelist import ( "gno.land/p/gnoswap/order/access/manager/v1" pwhitelist "gno.land/p/gnoswap/order/whitelist/v1" prbac "gno.land/p/gnoswap/rbac/v1" ufmt "gno.land/p/nt/ufmt/v0" "gno.land/r/gnoswap/access/v1" "gno.land/r/gnoswap/common" "gno.land/r/gnoswap/order/keeper" "gno.land/r/gnoswap/pool" ) func assertIsManagerCall(_ int, rlm realm, selector manager.Selector) realm { access.AssertIsRlmCurrent(0, rlm) common.AssertIsNotHandleNativeCoin() prev := rlm.Previous() caller := prev.Address() if access.IsAuthorized(prbac.ROLE_ADMIN.String(), caller) || access.IsAuthorized(prbac.ROLE_GOVERNANCE.String(), caller) || keeper.IsAuthorized(rlm.PkgPath(), selector, caller) { return prev } panic(makeErrorWithDetails(errUnauthorized, ufmt.Sprintf("caller(%s) selector(%s)", caller.String(), string(selector))).Error()) } func assertIsValidTarget(target string) { if target != TargetDCA && target != TargetLimit { panic(makeErrorWithDetails(errInvalidTarget, ufmt.Sprintf("target(%s)", target)).Error()) } } func assertIsExistingPool(poolPath string) { if !pool.ExistsPoolPath(poolPath) { panic(makeErrorWithDetails(errInvalidPool, ufmt.Sprintf("poolPath(%s) does not exist", poolPath)).Error()) } } func assertIsNotWhitelistedPool(state *pwhitelist.State, target, poolPath string) { if state.HasPool(poolPath) { panic(makeErrorWithDetails(errInvalidPool, ufmt.Sprintf("target(%s) poolPath(%s) is already whitelisted", target, poolPath)).Error()) } } func assertIsWhitelistedPool(state *pwhitelist.State, target, poolPath string) { if !state.HasPool(poolPath) { panic(makeErrorWithDetails(errInvalidPool, ufmt.Sprintf("target(%s) poolPath(%s) is not whitelisted", target, poolPath)).Error()) } }
- #4consts.gno
- #5package whitelist // Targets select independently managed order pool whitelists. const ( TargetDCA = "dca" TargetLimit = "limit" )
- #6doc.gno
- #7// Package whitelist manages the direct pools available to GnoSwap orders. // // DCA and Limit have independent pool whitelists, selected by TargetDCA // ("dca") and TargetLimit ("limit"). Adding or removing a pool affects only // the selected target. Pools must exist before being added; removing one // prevents that target's orders from trading on it, not from cancelling. // // Admin, governance, or callers authorized by gno.land/r/gnoswap/order/keeper // can update membership. At deployment, AddWhitelistedPool and // RemoveWhitelistedPool are assigned to PoolManagerRole on this realm; // the target argument selects the pool list, not the authorization policy. // Queries expose membership, a read-only pool tree, and whether a pair has // an existing whitelisted direct pool at any registered fee tier. // // Files: // - whitelist.gno: AddWhitelistedPool and RemoveWhitelistedPool // - getters.gno: read-only queries // - state.gno: independent DCA and Limit whitelist states // - assert.gno: authorization, target, and pool validation // - consts.gno: supported target names // - emits.gno: pool membership events package whitelist
- #8emits.gno
- #9package whitelist import ( "chain" "gno.land/p/gnoswap/utils/v1" ) func emitPoolUpdated(_ int, prev realm, target, poolPath string, whitelisted bool) { chain.Emit( "OrderWhitelistedPoolUpdated", "prevAddr", prev.Address().String(), "prevRealm", prev.PkgPath(), "target", target, "poolPath", poolPath, "whitelisted", utils.FormatBool(whitelisted), ) }
- #10errors.gno
- #11package whitelist import ( ufmt "gno.land/p/nt/ufmt/v0" ) const ( errUnauthorized = "[GNOSWAP-ORDER-WHITELIST-001] unauthorized caller" errInvalidPool = "[GNOSWAP-ORDER-WHITELIST-002] invalid whitelisted pool" errInvalidTarget = "[GNOSWAP-ORDER-WHITELIST-003] invalid target" ) func makeErrorWithDetails(message string, details string) error { return ufmt.Errorf("%s || %s", message, details) }
- #12getters.gno
- #13package whitelist import ( rotree "gno.land/p/nt/bptree/rotree/v0" "gno.land/r/gnoswap/pool" ) func IsWhitelistedPool(target, poolPath string) bool { return getState(target).HasPool(poolPath) } // GetWhitelistedPools returns only target's read-only poolPath -> true tree. func GetWhitelistedPools(target string) *rotree.ReadOnlyTree { return getState(target).Pools() } // HasWhitelistedPool reports whether target allows an existing direct pool of the pair. func HasWhitelistedPool(target, tokenIn, tokenOut string) bool { state := getState(target) if tokenIn == tokenOut { return false } for fee := range pool.GetFeeAmountTickSpacings() { poolPath := pool.GetPoolPath(tokenIn, tokenOut, uint32(fee)) if state.HasPool(poolPath) && pool.ExistsPoolPath(poolPath) { return true } } return false }
- #14gnomod.toml
- #15module = "gno.land/r/gnoswap/order/whitelist" gno = "0.9"
- #16state.gno
- #17package whitelist import ( pwhitelist "gno.land/p/gnoswap/order/whitelist/v1" ) var ( dcaState pwhitelist.State limitState pwhitelist.State ) func init() { resetState() } func resetState() { dcaState = pwhitelist.NewState() limitState = pwhitelist.NewState() } func getState(target string) *pwhitelist.State { assertIsValidTarget(target) if target == TargetDCA { return &dcaState } return &limitState }
- #18whitelist.gno
- #19package whitelist import ( "gno.land/r/gnoswap/order/keeper" ) // AddWhitelistedPool permits target's orders to trade on an existing pool. // Admin, governance, or the role assigned to this selector may call it. func AddWhitelistedPool(cur realm, target, poolPath string) { prev := assertIsManagerCall(0, cur, keeper.SelectorAddWhitelistedPool) state := getState(target) assertIsExistingPool(poolPath) assertIsNotWhitelistedPool(state, target, poolPath) state.AddPool(poolPath) emitPoolUpdated(0, prev, target, poolPath, true) } // RemoveWhitelistedPool stops only target's orders from using this pool. // Existing orders remain cancellable. Authorization matches AddWhitelistedPool. func RemoveWhitelistedPool(cur realm, target, poolPath string) { prev := assertIsManagerCall(0, cur, keeper.SelectorRemoveWhitelistedPool) state := getState(target) assertIsWhitelistedPool(state, target, poolPath) state.RemovePool(poolPath) emitPoolUpdated(0, prev, target, poolPath, false) }
- #20/gno.MemPackageType
- #21 MPUserAll
Result log
msg:0,success:true,log:,events:[]