Skip to main content

Membership

Getting started

This will let user known how to build and share an invite code, register a position, and query member's info.

The Alpha version of Dyson Finance contracts operates on Sepolia testnet. To interactive this, we can start from getting position via faucet.

Faucet Contract: 0x889a28163f08CdCF079C0692b23E4C586e811889

Generate a Invite code

All the things should be start with invite code. This step shows how to let user create an invite code by sdk, and register a membership from an invite code.

After getting a position from faucet, you can generate a invite code by using:

import { signReferral } from '@dyson-finance/dyson-interface-sdk/actions'

/** this invite code will be expired after 4 days */
const deadline = Math.floor(Date.now() / 1000) + 4 * TimeUnits.Day
const { parentSig, onceAddress, onceKey, deadline } =
await signReferral(walletClient, chainId, agencyAddress, deadline, false /* is contract wallet */)

Contract Wallet InviteCode

For those using contract wallet, sdk provide a way to pre-sign and also can use buildReferralCode to create a legal invite code to share to others. This way is to prevent some unpredictable error when user do the normal signature on their contract wallet.

import { signReferral } from '@dyson-finance/dyson-interface-sdk/actions'

const token = await signReferral(
walletClient,
chainId,
agencyContractAddress,
deadline,
true,
)

Then user can pre-sign parentSig on chain.

import { prepareSign } from '@dyson-finance/dyson-interface-sdk/actions'

const config = await walletClient.simulateContract({
...await prepareSign(token.parentSig),
address: agencyContractAddress,
})
await walletClient.writeContract(config.request)
Notice

If isContractWallet is true, this will trigger a transaction to pre-sign parentSig on chain. Make sure you need this feature.

For more info, please visit here

For parentSig, onceSig and deadline, please forward to Contract for more information.

Once get the parentSig, onceSig and deadline, there are buildReferralCode and parseReferralCode to help user building a string token.

import { buildReferralCode } from '@dyson-finance/dyson-interface-sdk/actions'

const InviteCode = buildReferralCode({
parentSig,
onceKey,
deadline
})

for contract wallet

// build invite code
const inviteCode = buildReferralCode({...token, parentSig: referrerAddress})

The difference between two, is the parentSig should be referrer address.

The invite code can only be used in once, and would be recorded on the contract. Thus, user can do the validate and check referrer info by using validate functions such as validateReferral or getParentNodeAddressByReferralCode. Both of them have same return type 0x${string}, which meaning the referrer address.

import { validateReferral, getParentNodeAddressByReferralCode } from '@dyson-finance/dyson-interface-sdk/actions'

const { parentAddress, onceAddress } = await validateReferral(InviteCode, chainId, agencyContractAddress)

// or
const { parentAddress, onceAddress } = await getParentNodeAddressByReferralCode(chainId, parentSig, onceKey, deadline, agencyContractAddress)

With the address, we can get it's generation and basic info in membership.

Get address gen info

  • Retrieves user's agent data
import { getAgencyReferrerGenInfo } from '@dyson-finance/dyson-interface-sdk/reads'

const [referrer, gen] = publicClient.readContract({
...getAgencyReferrerGenInfo(address),
address: agencyContractAddress,
})

referrer is the address that created the referral code, and gen means generation. The detail can visit here Agency

Get Member's Information

In agency contract, query data for specific agency should used id instead of wallet address. Therefore, we have to used whois to find out the id and address mapping.

import { getAgencyWhois } from '@dyson-finance/dyson-interface-sdk/reads'

const userId = publicClient.readContract({
address: contractAddress,
...getAgencyWhois(address)
})

Then we can use userId to query the agency information by using getAgentInfo.

import { getAgentInfo } from '@dyson-finance/dyson-interface-sdk/reads'

const [owner, gen, birth, parentId, childrenId] = publicClient.readContract({
address: contractAddress,
...getAgentInfo(userId)
})

And also verify invite code used or not

import { getReferralCodeUsed } from '@dyson-finance/dyson-interface-sdk/reads'
// onceAddress can be assign array.
const [oneTimeCode] = await getReferralCodeUsed(publicClient, [onceAddress], agencyContractAddress)
// oneTimeCode.result should be false if none used.

Register as a member

This step is show how to use the invite code to register as a member.

import { prepareRegister } from '@dyson-finance/dyson-interface-sdk/actions'

const config = await walletClient.simulateContract({
...await prepareRegister(walletClient, { deadline, parentSig, onceKey, contractAddress, chainId }),
address: contractAddress,
})
const result = await walletClient.writeContract(config.request)

Once transaction success, you can check the status changed on the contract.