Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: referral #459

Merged
merged 11 commits into from
Jan 19, 2025
Merged

feat: referral #459

merged 11 commits into from
Jan 19, 2025

Conversation

notJoon
Copy link
Member

@notJoon notJoon commented Jan 13, 2025

Description

This PR introduces a referral system that allows authorized contracts to manage referral relationships between addresses. The system enables tracking and managing referrer-referee relationships.

Structure

classDiagram
	class ReferralKeeper {
		<<interface>>
		+register(addr, refAddr std.Address)
		+update(addr, newAddr std.Address)
		+remove(addr std.Address)
		+has(addr std.Address)
		+get(addr std.Address)
	}
	class Keeper {
		-store *avl.Tree
		+register(addr, refAddr std.Address)
		+update(addr, newRefAddr std.Address)
		+remove(addr std.Address)
		+has(addr std.Address)
		+get(addr std.Address)
	}
	class Referral {
		-keeper ReferralKeeper
		+Register(addr, refAddr std.Address)
		+Update(addr, newRefAddr std.Address)
		+Remove(addr std.Address)
		+Has(addr std.Address)
		+Get(addr std.Address)
	}
	
	Referral --> ReferralKeeper : uses
	Keeper ..|> ReferralKeeper : implements
Loading

Implementation Details

The referral system consists of the following components:

  1. Core Components:

    • ReferralKeeper interface: Defines the fundamental operations for referral management
    • AVL Tree-based storage: Efficiently stores referral relationships
  2. Main Operations:

    • Register: Create new referral relationships
    • Update: Modify existing referrals
    • Remove: Delete referral relationships
    • Query (Get, Has): Check existence and get referral information
  3. Security:

    • Strict caller validation through a lookup table
    • Address format validation
    • Zero address handling for removal operations

Permissions

Only the following addresses can modify referral data:

  • Governance contracts
  • Router
  • Position
  • Staker

@notJoon notJoon marked this pull request as draft January 13, 2025 10:19
@notJoon notJoon requested a review from onlyhyde January 13, 2025 10:19
@notJoon notJoon marked this pull request as ready for review January 14, 2025 07:18
referral/keeper.gno Outdated Show resolved Hide resolved
referral/keeper.gno Show resolved Hide resolved
referral/keeper.gno Show resolved Hide resolved
Copy link
Member

@onlyhyde onlyhyde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Referral Contract requires a book that manages Caller Address -> Referral Address.

@onlyhyde onlyhyde self-requested a review January 18, 2025 12:34
referral/keeper.gno Outdated Show resolved Hide resolved
referral/keeper.gno Outdated Show resolved Hide resolved
referral/utils.gno Show resolved Hide resolved
referral/keeper.gno Show resolved Hide resolved
@notJoon notJoon self-assigned this Jan 19, 2025
@dongwon8247
Copy link
Member

One question: Thinking about preventing people from registering their other wallets as a referral, to manipulate the system (getting more points). We only use this referral contract to know the referral-referee relationships and point calculation/prevention will be on our back-end side, correct?

@notJoon
Copy link
Member Author

notJoon commented Jan 19, 2025

One question: Thinking about preventing people from registering their other wallets as a referral, to manipulate the system (getting more points). We only use this referral contract to know the referral-referee relationships and point calculation/prevention will be on our back-end side, correct?

@dongwon8247 Yes, that's correct. This package only stores referral-referee relationships and I believe that's how it should be.

@notJoon notJoon requested a review from onlyhyde January 19, 2025 07:16
@notJoon
Copy link
Member Author

notJoon commented Jan 19, 2025

@onlyhyde

Referral Contract requires a book that manages Caller Address -> Referral Address.

The store field of the keeper handles that role.

onlyhyde
onlyhyde previously approved these changes Jan 19, 2025
@onlyhyde onlyhyde requested a review from dongwon8247 January 19, 2025 07:57
referral/keeper_test.gno Outdated Show resolved Hide resolved
referral/keeper.gno Outdated Show resolved Hide resolved
Copy link
Member

@dongwon8247 dongwon8247 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done. LGTM

@notJoon notJoon merged commit 3e7ff44 into main Jan 19, 2025
1 of 2 checks passed
@notJoon notJoon deleted the referral branch January 19, 2025 10:08
moul pushed a commit that referenced this pull request Jan 20, 2025
* demo: referral

* update considerations

* remove unused

* global getter

* update getter

* time guard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants