Staking and Governance SDK
Examples of interacting with staking and governance. These functions typically require a balanceManagerKey, poolKey, or both. For details on these keys, see DeepBookV3 SDK. The SDK includes some default keys that you can view in the constants.ts file.
See Staking and Governance for more information on the staking and governance API.
How do I stake, vote, and claim rebates with the SDK?
stake
Use stake to stake an amount you specify into a specific pool. The call returns a function that takes a Transaction object.
Parameters
poolKey: String that identifies the pool.balanceManagerKey: String that identifies the balance manager.stakeAmount: Number representing the amount to stake.
stake(poolKey: string, balanceManagerKey: string, stakeAmount: number);
unstake
Use unstake to unstake from a particular pool. The call returns a function that takes a Transaction object.
Parameters
poolKey: String that identifies the pool.balanceManagerKey: String that identifies the balance manager.
unstake(poolKey: string, balanceManagerKey: string);
submitProposal
Use submitProposal to submit a governance proposal. The call returns a function that takes a Transaction object.
Parameters
params: AProposalParamsobject that defines the proposal. It containspoolKey(string),balanceManagerKey(string),takerFee(number),makerFee(number), andstakeRequired(number). See theProposalParamsinterface in the submitProposal custom function example below.
submitProposal(params: ProposalParams);
vote
Use vote to vote on a proposal. The call returns a function that takes a Transaction object.
Parameters
poolKey: String that identifies the pool.balanceManagerKey: String that identifies the balance manager.proposal_id: String that identifies the proposal to vote on.
vote(poolKey: string, balanceManagerKey: string, proposal_id: string);
claimRebates
Use claimRebates to claim maker/taker rebates for a balance manager in a specific pool. The call returns a function that takes a Transaction object.
Parameters
poolKey: String that identifies the pool.balanceManagerKey: String that identifies the balance manager.
packages/deepbook-v3/src/transactions/deepbook.ts. You probably need to run `pnpm prebuild` and restart the site.How do I call these functions from a custom class?
The following examples demonstrate custom staking and governance functions that you can place into the DeepBookMarketMaker class. Each example first shows the SDK function signature, which returns a function that takes a Transaction object, followed by a custom function that calls the SDK through this.governance and passes the result to tx.add().
stake custom function
stake = (
poolKey: string,
balanceManagerKey: string,
stakeAmount: number
) => (tx: Transaction) => {}
// Custom function to stake 100 DEEP in DeepBookMarketMaker class
stake = (tx: Transaction) => {
const poolKey = 'DBUSDT_DBUSDC';
const balanceManagerKey = 'MANAGER_1';
tx.add(this.governance.stake(poolKey, balanceManagerKey, 100));
};
unstake custom function
unstake = (
poolKey: string,
balanceManagerKey: string
) => (tx: Transaction) => {}
// Custom function to unstake in DeepBookMarketMaker class
unstake = (tx: Transaction) => {
const poolKey = 'DBUSDT_DBUSDC';
const balanceManagerKey = 'MANAGER_1';
tx.add(this.governance.unstake(poolKey, balanceManagerKey));
};
submitProposal custom function
// Proposal params
export interface ProposalParams {
poolKey: string;
balanceManagerKey: string;
takerFee: number;
makerFee: number;
stakeRequired: number;
}
submitProposal = (params: ProposalParams) => (tx: Transaction) => {}
// Custom function to submit proposal in DeepBookMarketMaker class
submitProposal = (tx: Transaction) => {
const poolKey = 'DBUSDT_DBUSDC';
const balanceManagerKey = 'MANAGER_1';
tx.add(
this.governance.submitProposal({
poolKey,
balanceManagerKey,
takerFee: 0.002,
makerFee: 0.001,
stakeRequired: 100,
}),
);
};
vote custom function
vote = (
poolKey: string,
balanceManagerKey: string,
proposal_id: string
) => (tx: Transaction) => {}
// Custom function to vote in DeepBookMarketMaker class
vote = (tx: Transaction) => {
const poolKey = 'DBUSDT_DBUSDC';
const balanceManagerKey = 'MANAGER_1';
const proposalID = '0x123456789';
tx.add(this.governance.vote(poolKey, balanceManagerKey, proposalID));
};