Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added getDelegationChainLength #725

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,14 @@ export interface IArmadaManagerGovernance {
* @returns The transaction information
*/
getUnstakeTx: (params: { amount: bigint }) => Promise<[UnstakeTransactionInfo]>

/**
* @method getDelegationChainLength
* @description Returns the length of the delegation chain
*
* @param user The user
*
* @returns The transaction information
*/
getDelegationChainLength: (params: { user: IUser }) => Promise<number>
piotrwitek marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,20 @@ export class ArmadaManagerGovernance implements IArmadaManagerGovernance {
},
]
}

async getDelegationChainLength(
params: Parameters<IArmadaManagerGovernance['getDelegationChainLength']>[0],
): ReturnType<IArmadaManagerGovernance['getDelegationChainLength']> {
const client = this._blockchainClientProvider.getBlockchainClient({
chainInfo: this._hubChainInfo,
})

const length = await client.readContract({
abi: SummerTokenAbi,
address: this._hubChainSummerTokenAddress.value,
functionName: 'getDelegationChainLength',
args: [params.user.wallet.address.value],
})
return Number(length.toString())
piotrwitek marked this conversation as resolved.
Show resolved Hide resolved
}
piotrwitek marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,10 @@ export class ArmadaManagerUsersClient extends IRPCClient implements IArmadaManag
): ReturnType<IArmadaManagerUsersClient['getUnstakeTx']> {
return this.rpcClient.armada.users.getUnstakeTX.query(params)
}

async getDelegationChainLength(
params: Parameters<IArmadaManagerUsersClient['getDelegationChainLength']>[0],
): ReturnType<IArmadaManagerUsersClient['getDelegationChainLength']> {
return this.rpcClient.armada.users.getDelegationChainLength.query(params)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,14 @@ export interface IArmadaManagerUsersClient {
* @returns The transaction information
*/
getUnstakeTx(params: { amount: bigint }): Promise<[UnstakeTransactionInfo]>

/**
* @method getDelegationChainLength
* @description Returns the length of the delegation chain
*
* @param user The user
*
* @returns The length of the delegation
*/
getDelegationChainLength: (params: { user: IUser }) => Promise<number>
}
2 changes: 2 additions & 0 deletions sdk/sdk-server/src/SDKAppRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import { getUnstakeTx } from './armada-protocol-handlers/users/getUnstakeTx'
import { getUserEarnedRewards } from './armada-protocol-handlers/users/getUserEarnedRewards'
import { getUserBalance } from './armada-protocol-handlers/users/getUserBalance'
import { getSummerToken } from './armada-protocol-handlers/users/getSummerToken'
import { getDelegationChainLength } from './armada-protocol-handlers/users/getDelegationChainLength'

/**
* Server
Expand Down Expand Up @@ -108,6 +109,7 @@ export const sdkAppRouter = router({
getUnstakeTX: getUnstakeTx,
getUserBalance: getUserBalance,
getSummerToken: getSummerToken,
getDelegationChainLength: getDelegationChainLength,
},
keepers: {
rebalance: rebalance,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { z } from 'zod'
import { publicProcedure } from '../../SDKTRPC'
import { isUser, type IUser } from '@summerfi/sdk-common'

export const getDelegationChainLength = publicProcedure
.input(
z.object({
user: z.custom<IUser>(isUser),
}),
)
.query(async (opts) => {
return await opts.ctx.armadaManager.governance.getDelegationChainLength(opts.input)
})
piotrwitek marked this conversation as resolved.
Show resolved Hide resolved
Loading