Skip to main content

Staking

If want to know more about sDYSN contract, please visit here

Getting started

This will let user known how to stake, re-stake, and redeem their sDYSN with sdk.

Stake

For staking, in StakingRateModel, we define the lock duration between 1461 days and 30 minutes or transaction would be reverted.

import {
prepareStake,
getStakeGasFee,
} from '@dyson-finance/dyson-interface-sdk/actions';
import { TimeUnits } from '@dyson-finance/dyson-interface-sdk/constants';

const config = await walletClient.simulateContract({
...prepareStake({
to: walletAddress,
tokenAmount: DYSNAmount,
stakeTime: 30 * TimeUnits.Day, // stake 30 days
}),
});

await walletClient.writeContract(config.request);
Notice

For staking, user can also stake DYSN to another wallet.

Vaults reading

After staking, we can use getVaultCount and getVaults to read user's sDYSN vault.

import {
getVaultCount,
getVaults,
} from '@dyson-finance/dyson-interface-sdk/reads';

const totalVaultsCount = await publicClient.readContract({
...getVaultCount(walletAddress),
address: sDysnContractAddress,
});

const vaults = await getVaults(
publicClient,
sDysnContractAddress,
walletAddress,
Number(totalVaultsCount)
);
// first vault

const firstVault = vaults[0].result;
const [dysonAmount, sDysonAmount, unlockTime] = firstVault;

Re-Stake

For re-staking, extending lock duration formula is lockDuration = current + extends and it should be longer than vault.unlockTime and less than 1461 days (4 years)

Here is a way to solve this.

We assume this vault is not in the redeem status.

const extendedLockDuration = 20 * 60; // 20 minutes
// current diff for unlock time
const diff = Number(unlockTime) - Math.floor(Date.now() / 1000);
const newLockDuration = diff + extendedLockDuration + 30; // Stake buffer time for edge case
Notice

newLockDuration should not less than 30 minutes or get the revert message.

Then, put it together.

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

// 1 Dysn stake
const stakeDysnAmount = 1_000_000_000_000_000_000n;
const extendedLockDuration = 20 * 60;
const diff = Number(unlockTime) - Math.floor(Date.now() / 1000);
const newLockDuration = diff + extendedLockDuration + 30;

const config = await walletClient.simulateContract({
...prepareRestake({
index: 0,
tokenAmount: stakeDysnAmount,
stakeTime: newLockDuration,
}),
address: sDysnContractAddress,
});

await walletClient.writeContract(config.request);

Redeem position

When reach the vault unlockTime, the vault can be redeemed.

Although the vault reach unlock time, user still can decide to restake the position.

import {
prepareUnstake,
getUnstakeGasFee,
} from '@dyson-finance/dyson-interface-sdk/actions';

const args = {
to: walletAddress,
index: 0,
sDYSNAmount: sDysonAmount,
};
const config = await walletClient.simulateContract({
...prepareUnstake(args),
gas: await getUnstakeGasFee({
client: publicClient,
...args,
contractAddress: sDysnContractAddress,
userAddress: walletAddress,
}),
address: sDysnContractAddress,
});
await walletClient.writeContract(config.request)