Skip to content

Commit

Permalink
fix(ui): Fixed some comparisons to fix bigint/number issues at runtim…
Browse files Browse the repository at this point in the history
…e that was preventing adding additional stake or unstaking

Also updated calls to some of the 'variable cost' methods to use the new extraFee support in the new algokit beta clients.
  • Loading branch information
pbennett committed Oct 16, 2024
1 parent 33f19a8 commit 6d1169c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 28 deletions.
52 changes: 27 additions & 25 deletions ui/src/api/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ export async function addStake(

const simulateComposer = simulateValidatorClient
.newGroup()
.gas({ args: {}, validityWindow: 200 })
.gas({ args: {} })
.addStake(
// This the actual send of stake to the ac
{
Expand Down Expand Up @@ -535,17 +535,20 @@ export async function addStake(

stakeTransferPayment.group = undefined

// @todo: switch to Joe's new method(s)
const feeAmount = AlgoAmount.MicroAlgos(
3000 + 1000 * ((simulateResults.simulateResponse.txnGroups[0].appBudgetAdded as number) / 700),
1000 *
Math.floor(
((simulateResults.simulateResponse.txnGroups[0].appBudgetAdded as number) + 699) / 700,
) -
1000, // subtract back out the opcodes added from the gas call(s) which were paid as part of their normal fees,
)

let requiredBalance =
BigInt(stakeTransferPayment.amount) + BigInt(stakeTransferPayment.fee) + feeAmount.microAlgos

const composer = validatorClient
.newGroup()
.gas({ args: [], staticFee: AlgoAmount.MicroAlgos(0) })
.gas({ args: [] })
.addStake({
args: {
// --
Expand All @@ -555,7 +558,7 @@ export async function addStake(
validatorId,
valueToVerify,
},
staticFee: feeAmount,
extraFee: feeAmount,
})

if (needsOptInTxn) {
Expand Down Expand Up @@ -788,12 +791,12 @@ export async function removeStake(
allowUnnamedResources: true,
})

// @todo: switch to Joe's new method(s)
const feeAmount = AlgoAmount.MicroAlgos(
1000 *
Math.floor(
((simulateResult.simulateResponse.txnGroups[0].appBudgetAdded as number) + 699) / 700,
),
) -
2000, // subtract back out the opcodes added from the two gas calls which were paid as part of their normal fees,
)

let requiredBalance = feeAmount.microAlgos
Expand All @@ -802,11 +805,11 @@ export async function removeStake(

const composer = stakingPoolClient
.newGroup()
.gas({ args: [], note: '1', staticFee: AlgoAmount.MicroAlgos(0) })
.gas({ args: [], note: '2', staticFee: AlgoAmount.MicroAlgos(0) })
.gas({ args: [], note: '1' })
.gas({ args: [], note: '2' })
.removeStake({
args: { staker: activeAddress, amountToUnstake },
staticFee: feeAmount,
extraFee: feeAmount,
})

if (needsOptInTxn) {
Expand Down Expand Up @@ -869,9 +872,12 @@ export async function epochBalanceUpdate(
})
.simulate({ allowEmptySignatures: true, allowUnnamedResources: true })

// @todo: switch to Joe's new method(s)
const feeAmount = AlgoAmount.MicroAlgos(
3000 + 1000 * ((simulateResult.simulateResponse.txnGroups[0].appBudgetAdded as number) / 700),
1000 *
Math.floor(
((simulateResult.simulateResponse.txnGroups[0].appBudgetAdded as number) + 699) / 700,
) -
2000, // subtract back out the opcodes added from the gas call(s) which were paid as part of their normal fees,
)

// Check balance
Expand All @@ -882,9 +888,9 @@ export async function epochBalanceUpdate(

await stakingPoolClient
.newGroup()
.gas({ args: [], note: '1', staticFee: AlgoAmount.MicroAlgos(0) })
.gas({ args: [], note: '2', staticFee: AlgoAmount.MicroAlgos(0) })
.epochBalanceUpdate({ args: {}, staticFee: feeAmount })
.gas({ args: [], note: '1' })
.gas({ args: [], note: '2' })
.epochBalanceUpdate({ args: {}, extraFee: feeAmount })
.send({ populateAppCallResources: true })
} catch (error) {
console.error(error)
Expand Down Expand Up @@ -1003,12 +1009,12 @@ export async function claimTokens(
allowUnnamedResources: true,
})

// @todo: switch to Joe's new method(s)
const feeAmount = AlgoAmount.MicroAlgos(
1000 *
Math.floor(
((simulateResult.simulateResponse.txnGroups[0].appBudgetAdded as number) + 699) / 700,
),
) -
2000, // subtract back out the opcodes added from the gas call(s) which were paid as part of their normal fees,
)

const composer = algorand.newGroup()
Expand All @@ -1021,13 +1027,9 @@ export async function claimTokens(
defaultSigner: signer,
})
composer
.addAppCallMethodCall(
await client.params.gas({ args: [], note: '1', staticFee: (0).microAlgo() }),
)
.addAppCallMethodCall(
await client.params.gas({ args: [], note: '2', staticFee: (0).microAlgo() }),
)
.addAppCallMethodCall(await client.params.claimTokens({ args: {}, staticFee: feeAmount }))
.addAppCallMethodCall(await client.params.gas({ args: [], note: '1' }))
.addAppCallMethodCall(await client.params.gas({ args: [], note: '2' }))
.addAppCallMethodCall(await client.params.claimTokens({ args: {}, extraFee: feeAmount }))
}

await composer.send({ populateAppCallResources: true })
Expand Down Expand Up @@ -1211,7 +1213,7 @@ export async function linkPoolToNfd(
.newGroup()
.addTransaction(payBoxStorageMbrTxn)
.addTransaction(updateNfdAppCall)
.linkToNfd({ args: { nfdAppId, nfdName }, staticFee: feeAmount })
.linkToNfd({ args: { nfdAppId, nfdName }, extraFee: feeAmount })
.send({ populateAppCallResources: true })
} catch (error) {
console.error(error)
Expand Down
6 changes: 4 additions & 2 deletions ui/src/components/StakingTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ export function StakingTable({
header: ({ column }) => <DataTableColumnHeader column={column} title="Reward Eligibility" />,
cell: ({ row }) => {
const stakerValidatorData = row.original
const validator = validators.find((v) => BigInt(v.id) === stakerValidatorData.validatorId)
const validator = validators.find(
(v) => BigInt(v.id) === BigInt(stakerValidatorData.validatorId),
)
const { epochRoundLength } = validator?.config || {}

const allPoolsEligibility = stakerValidatorData.pools.map((poolData) => {
Expand All @@ -202,7 +204,7 @@ export function StakingTable({
id: 'actions',
cell: ({ row }) => {
const validatorId = row.original.validatorId
const validator = validators.find((v) => BigInt(v.id) === validatorId)
const validator = validators.find((v) => BigInt(v.id) === BigInt(validatorId))

if (!validator || !activeAddress) return null

Expand Down
2 changes: 1 addition & 1 deletion ui/src/utils/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export function isUnstakingDisabled(
}
const noPools = validator.state.numPools === 0
const validatorHasStake = stakesByValidator.some(
(stake) => stake.validatorId === BigInt(validator.id),
(stake) => BigInt(stake.validatorId) === BigInt(validator.id),
)

return noPools || !validatorHasStake
Expand Down

0 comments on commit 6d1169c

Please sign in to comment.