DocumentationsdkDelegation Module

Delegation Module

Methods for delegating and managing voting power in CredDAO.

delegate

Delegate your voting power to another member.

async delegate(params: DelegateParams): Promise<TransactionResult>

Parameters

interface DelegateParams {
  delegate: PublicKey;
}

Public key of the member to delegate to.

Returns

interface TransactionResult {
  signature: string;
  efficiency: number;
}

Example

const delegateAddress = new PublicKey('7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU');
 
const result = await client.delegate({
  delegate: delegateAddress,
});
 
console.log('Delegated with efficiency:', result.efficiency);

Errors

ErrorCause
DelegationAlreadyActiveAlready delegating to someone
InvalidDelegationTargetTrying to delegate to yourself

revokeDelegation

Revoke your active delegation.

async revokeDelegation(): Promise<TransactionResult>

Example

const result = await client.revokeDelegation();
console.log('Delegation revoked:', result.signature);
Note:

After revoking, you can vote directly on proposals again.


getDelegationRecord

Get the delegation record for a wallet.

async getDelegationRecord(wallet: PublicKey): Promise<DelegationRecord>

Returns

interface DelegationRecord {
  delegator: PublicKey;
  delegate: PublicKey;
  delegatedPower: BN;
  delegateScore: BN;
  delegateParticipationRate: BN;
  delegationEfficiency: BN;
  active: boolean;
  createdAt: BN;
}

Example

const record = await client.getDelegationRecord(wallet.publicKey);
 
if (record.active) {
  console.log('Delegating to:', record.delegate.toBase58());
  console.log('Efficiency:', record.delegationEfficiency.toNumber());
  console.log('Delegate Score:', record.delegateScore.toNumber());
}

getTopDelegates

Get top delegates sorted by various metrics.

async getTopDelegates(options?: {
  sortBy?: 'efficiency' | 'delegators' | 'votingPower';
  limit?: number;
}): Promise<DelegateInfo[]>

Parameters

Sort metric: efficiency, delegators, or votingPower.

Maximum number of delegates to return.

Returns

interface DelegateInfo {
  address: PublicKey;
  name?: string;
  fairscore: number;
  tier: ReputationTier;
  votingPower: number;
  delegatedPower: number;
  delegators: number;
  efficiency: number;
}

Example

// Get top delegates by efficiency
const topDelegates = await client.getTopDelegates({
  sortBy: 'efficiency',
  limit: 10,
});
 
topDelegates.forEach((d, i) => {
  console.log(`${i + 1}. ${d.name || d.address.toBase58().slice(0, 8)}`);
  console.log(`   Efficiency: ${d.efficiency}%`);
  console.log(`   Tier: ${d.tier}`);
  console.log(`   Delegators: ${d.delegators}`);
});

getDelegators

Get all wallets delegating to a specific delegate.

async getDelegators(delegate: PublicKey): Promise<DelegationRecord[]>

Example

const delegators = await client.getDelegators(delegateAddress);
 
console.log(`${delegators.length} delegators`);
console.log('Total power:', delegators.reduce(
  (sum, d) => sum + d.delegatedPower.toNumber(), 0
));

calculateDelegationEfficiency

Calculate expected delegation efficiency.

calculateDelegationEfficiency(
  delegateProfile: MemberProfile
): DelegationEfficiency

Returns

interface DelegationEfficiency {
  delegateScore: number;
  participationRate: number;
  tierMultiplier: number;
  efficiency: number;
}

Example

const delegateProfile = await client.getMemberProfile(delegateAddress);
const efficiency = client.calculateDelegationEfficiency(delegateProfile);
 
console.log('Efficiency breakdown:');
console.log('  Score:', efficiency.delegateScore);
console.log('  Participation:', efficiency.participationRate + '%');
console.log('  Tier Multiplier:', efficiency.tierMultiplier + '%');
console.log('  Total Efficiency:', efficiency.efficiency);

Delegation Workflow

// 1. Browse delegates
const delegates = await client.getTopDelegates({ sortBy: 'efficiency' });
 
// 2. Choose a delegate
const chosen = delegates[0];
console.log('Delegating to:', chosen.name);
 
// 3. Delegate
const result = await client.delegate({
  delegate: chosen.address,
});
 
// 4. Monitor delegation
const record = await client.getDelegationRecord(wallet.publicKey);
console.log('Active:', record.active);
 
// 5. Revoke if needed
await client.revokeDelegation();

Best Practices

Before Delegating

  • Research delegate’s voting history
  • Check their FairScore and tier
  • Review participation rate
  • Understand their voting philosophy

After Delegating

  • Monitor their voting activity
  • Communicate preferences
  • Revoke if unsatisfied
  • Consider re-delegating