Gauge
In this section, you can view Gauge and Yield boosting first to know more about dyson gauge.
Getting Start
In the previous part, after receiving $sDYSN, user can boost their pool by gauge action to get more rewards. For gauge definition, please visit here
For staking $DYSN to $sDYSN, please visit Staking
From gauge, we using farm
to get the corresponding contract address
Get Gauge info
From Factory, we can get swapConfigMap
to query gauge info. This is the basic message for checking the pools status.
import { prepareGaugeInfos } from '@dyson-finance/dyson-interface-sdk/reads';
// we pick the first pair as a sample
const pairAddressList = Object.keys(swapConfigMap);
const gaugeInfo = publicClient.readContract({
...prepareGaugeInfos(pairAddressList[0]),
address: farmContractAddress,
});
const firstGauge = {
weight: gaugeInfo[0],
rewardRate: gaugeInfo[1],
lastUpdateTime: gaugeInfo[2],
lastReserve: gaugeInfo[3],
gaugeAddress: gaugeInfo[4],
};
Fetch Gauge personal info
From Factory, we can get swapConfigMap
to query gauge info. This is the basic message for checking the pools status.
import { prepareGaugeInfos } from '@dyson-finance/dyson-interface-sdk/reads';
// we pick the first pair as a sample
const pairAddressList = Object.keys(swapConfigMap);
const gaugeInfo = publicClient.readContract({
...prepareGaugeInfos(pairAddressList[0]),
address: farmContractAddress,
});
const firstGauge = {
weight: gaugeInfo[0],
rewardRate: gaugeInfo[1],
lastUpdateTime: gaugeInfo[2],
lastReserve: gaugeInfo[3],
gaugeAddress: gaugeInfo[4],
};
Boost multiplier calculation
Boosting for each Dyson pair will affect the rewards(Points) users receive from depositing dual investments. We use Subgraph to support related data on our main app. However, we employ a straightforward contract reading approach to explain how to calculate the boost multiplier.
import { calcPoolBoosting } from '@dyson-finance/dyson-interface-sdk/calculations'
import { ABIGauge } from '@dyson-finance/dyson-interface-sdk/constants/abis'
import { formatUnits, getAbiItem } from 'viem'
import { Address } from 'wagmi'
import { getPublicClient, multicall } from 'wagmi/actions'
function prepareGaugeBalance(account: Address) {
const abiItem = getAbiItem({ abi: ABIGauge, name: 'balanceOf' })
return {
functionName: abiItem.name,
abi: [abiItem],
args: [account] as [Address],
}
}
function prepareGaugeVotingAmount() {
const abiItem = getAbiItem({ abi: ABIGauge, name: 'totalSupply' })
return {
functionName: abiItem.name,
abi: [abiItem],
}
}
// ...
const gaugeUserInfo = await multicall({
allowFailure: false,
chainId: chainId,
contracts: [
{
...prepareGaugeBalance(account as Address),
address: gaugeAddress,
},
{ ...prepareGaugeVotingAmount(), address: gaugeAddress },
],
})
const boost = 1 +
parseFloat(
formatUnits(calcPoolBoosting(gaugeUserInfo[1], gaugeUserInfo[0]), 18),
)
// ...
Deposit $sDYSN to Gauge
SDK provides two ways to deposit $sDYSN to gauge, deposit directly or via router.
To deposit tokens into the gauge, the user will need to approve the token. And there has the same action can also be achieved through the router.
If you want to avoid redundant token approval, we recommend to use router action here.
- With Router action
import { prepareGaugeDepositWithRouter } from '@dyson-finance/dyson-interface-sdk/actions';
const sDysnAmount = 100000000000n;
// with router
const config = await walletClient.simulateContract({
...prepareGaugeDepositWithRouter(walletClient, {
gaugeAddress: firstGauge.gaugeAddress,
tokenAmount: sDysnAmount,
addressTo: walletAddress,
}),
address: routerContractAddress,
});
await walletClient.writeContract(config.request);
- With Direct deposit
import { prepareGaugeDeposit } from '@dyson-finance/dyson-interface-sdk/actions';
const config = await walletClient.simulateContract({
...prepareGaugeDeposit(walletClient, {
tokenAmount: sDysnAmount,
addressTo: walletAddress,
}),
address: gaugeContractAddress,
});
await walletClient.writeContract(config.request);
Withdraw and apply withdraw
User can withdraw their $sDYSN from the gauge any time. But, according to withdrawal rule, the user should be applied for withdrawal first, and be claimable while waiting until the end of the epoch for precaution against potential attacks.
The epoch typically concludes at 00:00 UTC every Thursday.
import { prepareGaugeApplyWithdraw, prepareGaugeWithdraw } from '@dyson-finance/dyson-interface-sdk/actions';
const config = await walletClient.simulateContract({
...prepareGaugeDeposit(walletClient, {
tokenAmount: sDysnAmount,
}),
address: gaugeContractAddress,
});
await walletClient.writeContract(config.request);
// Reach the time
const withdrawConfig = await walletClient.simulateContract({
...prepareGaugeWithdraw(walletClient),
address: gaugeContractAddress,
});
await walletClient.writeContract(withdrawConfig.request);