Mine $DYSN with Points
There are two ways to earn Points:
- When a user with membership makes a deposit in the dual investment.
- When a referee swaps their Points for $DYSN, the user can receive 1/3 of the Points.
We will explain how to check user's Points balance and guide you through the process of swapping Points for $DYSN.
Retrieving Points balance
Let's make a async function to retrieve user's balance of Points. For further details, please refer to IFarmRewardInfo to verify data types.
Exploring farmInfo.userInfo, we uncover the following:
- spBalance is in BigInt format with 18 decimals.
- coolDownTime is represented in BigInt format as a Unix timestamp (in seconds). Users are unable to swap points when the current time is earlier than coolDownTime.
import { getFarmRewardInfo } from '@dyson-finance/dyson-interface-sdk/reads'
import { IFarmRewardInfo } from '@dyson-finance/dyson-interface-sdk/dist/constants'
//...
const client = getPublicClient({
chainId: selectChain,
})
const farmInfo: IFarmRewardInfo = await getFarmRewardInfo(client, {
farmAddress,
account: (account as Address) || zeroAddress,
})
//...
Calculate the exchange rate
We have created a function to compute the exchange rate from Points to $DYSN. However, it requires fetching certain data with the IFarmRewardInfo interface.
For a detailed explanation of the formula implemented here, please refer to our documentation on convert Points to $DYSN.
import {
getCurrentReserve,
globalApToGOV,
} from '@dyson-finance/dyson-interface-sdk/calculations'
//...
const dysnAmountOut = useMemo(() => {
const globalW = farmInfo.w
const reserveGlobal = getCurrentReserve(
farmInfo.rewardRate,
farmInfo.lastReserve,
farmInfo.lastUpdateTime,
)
return globalApToGOV(parseFloat(formatUnits(spBalance, 18)), reserveGlobal, globalW)
}, [
farmInfo.w,
farmInfo.rewardRate,
farmInfo.lastReserve,
farmInfo.lastUpdateTime,
spBalance,
])
//...
Swap action
For the rate of swap point to $DYSN amount, please visit farm.
User can help others to swap their points to the governance token($DYSN). During the process, there are some key rules should be noticed.
- Accessibility: Any third party can trigger this function.
- Cooldown Requirement: Users can only perform a swap after their cooldown period ends, determined by their generation in the referral system.
- Referral System Registration: To initiate a swap, users must be registered in the referral system. Upon swapping, the user's referrer receives
1/3
of the user's Points.
import { prepareSpSwap } from '@dyson-finance/dyson-interface-sdk/actions'
const config = await walletClient.simulateContract({
address: FarmContractAddress,
...prepareSpSwap(walletClient, address),
})
await walletClient.writeContract(config.request)