Skip to content

Commit

Permalink
Add rewards restaking option to Cosmos staking tx
Browse files Browse the repository at this point in the history
  • Loading branch information
goulinkh committed Mar 5, 2024
1 parent eaf9ab3 commit 4410cf6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/services/atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ export class AtomService extends Service {
* @param pubkey wallet pubkey, this is different from the wallet address
* @param validatorAddress validator address to delegate to
* @param amountAtom how many tokens to stake in ATOM
* @param restakeRewards If enabled, the rewards will be automatically restaked
*/
async craftStakeTx(
accountId: string,
pubkey: string,
validatorAddress: string,
amountAtom: number,
restakeRewards: boolean = false,
): Promise<CosmosTx> {

const { data } = await api.post<CosmosTx>(
Expand All @@ -42,6 +44,7 @@ export class AtomService extends Service {
pubkey: pubkey,
validator: validatorAddress,
amount_uatom: this.atomToUatom(amountAtom.toString()),
restake_rewards: restakeRewards,
});
return data;

Expand Down Expand Up @@ -75,15 +78,13 @@ export class AtomService extends Service {
*/
async craftRestakeRewardsTx(
pubkey: string,
validatorAccount: string,
validatorAddress: string,
): Promise<CosmosTx> {

const { data } = await api.post<CosmosTx>(
`/v1/atom/transaction/restake-rewards`,
{
pubkey: pubkey,
validator_account: validatorAccount,
validator_address: validatorAddress,
});
return data;
Expand Down
5 changes: 3 additions & 2 deletions src/services/osmo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ export class OsmoService extends Service {
* @param pubkey wallet pubkey, this is different from the wallet address
* @param validatorAddress validator address to delegate to
* @param amountOsmo how many tokens to stake in OSMO
* @param restakeRewards If enabled, the rewards will be automatically restaked
*/
async craftStakeTx(
accountId: string,
pubkey: string,
validatorAddress: string,
amountOsmo: number,
restakeRewards: boolean = false,
): Promise<CosmosTx> {

const { data } = await api.post<CosmosTx>(
Expand All @@ -45,6 +47,7 @@ export class OsmoService extends Service {
pubkey: pubkey,
validator: validatorAddress,
amount_uosmo: this.osmoToUosmo(amountOsmo.toString()),
restake_rewards: restakeRewards,
});
return data;

Expand Down Expand Up @@ -78,15 +81,13 @@ export class OsmoService extends Service {
*/
async craftRestakeRewardsTx(
pubkey: string,
validatorAccount: string,
validatorAddress: string,
): Promise<CosmosTx> {

const { data } = await api.post<CosmosTx>(
`/v1/osmo/transaction/restake-rewards`,
{
pubkey: pubkey,
validator_account: validatorAccount,
validator_address: validatorAddress,
});
return data;
Expand Down
5 changes: 3 additions & 2 deletions src/services/tia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ export class TiaService extends Service {
* @param pubkey wallet pubkey, this is different from the wallet address
* @param validatorAddress validator address to delegate to
* @param amountTia how many tokens to stake in TIA
* @param restakeRewards If enabled, the rewards will be automatically restaked
*/
async craftStakeTx(
accountId: string,
pubkey: string,
validatorAddress: string,
amountTia: number,
restakeRewards: boolean = false,
): Promise<CosmosTx> {

const { data } = await api.post<CosmosTx>(
Expand All @@ -41,6 +43,7 @@ export class TiaService extends Service {
pubkey: pubkey,
validator: validatorAddress,
amount_utia: this.tiaToUtia(amountTia.toString()),
restake_rewards: restakeRewards,
});
return data;

Expand Down Expand Up @@ -74,15 +77,13 @@ export class TiaService extends Service {
*/
async craftRestakeRewardsTx(
pubkey: string,
validatorAccount: string,
validatorAddress: string,
): Promise<CosmosTx> {

const { data } = await api.post<CosmosTx>(
`/v1/tia/transaction/restake-rewards`,
{
pubkey: pubkey,
validator_account: validatorAccount,
validator_address: validatorAddress,
});
return data;
Expand Down

0 comments on commit 4410cf6

Please sign in to comment.