Skip to content

Commit

Permalink
Merge pull request #189 from TxnLab/dev
Browse files Browse the repository at this point in the history
v0.8.15
  • Loading branch information
pbennett authored May 28, 2024
2 parents c755603 + ac138c8 commit 90e8fc0
Show file tree
Hide file tree
Showing 36 changed files with 17,685 additions and 15,897 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ This section provides instructions for running the protocol and UI in a local Al
## Additional Resources

- **TEALScript Contracts**: Explore the smart contracts that power the protocol. [Read more](./contracts/README.md)
- **Node Daemon**: Learn about the CLI / service daemon which node runners will run as a background service. [Read more](./docs/technical-implementation/reti-node-daemon/README.md)
- **Node Daemon**: Learn about the CLI / service daemon which node runners will run as a background service. [Read more](https://txnlab.gitbook.io/reti-open-pooling/technical-implementation/reti-node-daemon)
- **Example UI**: A Vite React project that serves as a dashboard for staking and validator management. [Read more](./ui/README.md)

## Discord
Expand Down
56 changes: 54 additions & 2 deletions contracts/__test__/contracts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ beforeAll(async () => {
algod,
)

const validatorApp = await validatorMasterClient.create.createApplication({})
const validatorApp = await validatorMasterClient.create.createApplication({}, { schema: { extraPages: 3 } })
// verify that the constructed validator contract is initialized as expected
expect(validatorApp.appId).toBeDefined()
expect(validatorApp.appAddress).toBeDefined()
Expand Down Expand Up @@ -1749,6 +1749,7 @@ describe('StakeWTokenWRewards', () => {

let validatorId: number
let validatorOwnerAccount: Account
let tokenCreatorAccount: Account
let validatorConfig: ValidatorConfig
const stakerAccounts: Account[] = []
let poolAppId: bigint
Expand All @@ -1764,7 +1765,7 @@ describe('StakeWTokenWRewards', () => {
// add validator and 1 pool for subsequent stake tests
beforeAll(async () => {
// Create a reward token to pay out to stakers
const tokenCreatorAccount = await getTestAccount(
tokenCreatorAccount = await getTestAccount(
{ initialFunds: AlgoAmount.Algos(5000), suppressLog: true },
fixture.context.algod,
fixture.context.kmd,
Expand Down Expand Up @@ -2077,6 +2078,57 @@ describe('StakeWTokenWRewards', () => {
stakersAfterReward,
epochRoundLength,
)

// DON'T claim! we want some tokens remaining to be paid out left for following reclaimTokenRewards test
})

test('reclaimTokenRewards', async () => {
// as 'owner' get tokens back from reward pool - but we should only get back what's not held back
// so we verify some are held back and that we receive everything but that.
const pool1Address = getApplicationAddress(firstPoolKey.poolAppId)
const rewardTokenBalance = await fixture.context.algod
.accountAssetInformation(pool1Address, Number(rewardTokenID))
.do()

const validatorCurState = await getValidatorState(validatorMasterClient, validatorId)
const tokensHeldBack = validatorCurState.rewardTokenHeldBack
expect(tokensHeldBack).toBeGreaterThan(0n)

const ownerTokenBalPre = await fixture.context.algod
.accountAssetInformation(tokenCreatorAccount.addr, Number(rewardTokenID))
.do()

// should fail - not owner of validator
await expect(
validatorMasterClient.emptyTokenRewards(
{ validatorId, receiver: tokenCreatorAccount.addr },
{ sendParams: { fee: AlgoAmount.MicroAlgos(3000), populateAppCallResources: true } },
),
).rejects.toThrowError()
// now get client with our owner as caller
const valAppRef = await validatorMasterClient.appClient.getAppReference()
const validatorClient = new ValidatorRegistryClient(
{
sender: validatorOwnerAccount,
resolveBy: 'id',
id: valAppRef.appId,
},
fixture.context.algod,
)

const sentAmount = (
await validatorClient.emptyTokenRewards(
{ validatorId, receiver: tokenCreatorAccount.addr },
{ sendParams: { fee: AlgoAmount.MicroAlgos(3000), populateAppCallResources: true } },
)
).return!
expect(sentAmount).toEqual(BigInt(rewardTokenBalance['asset-holding'].amount) - tokensHeldBack)
const ownerTokenBal = await fixture.context.algod
.accountAssetInformation(tokenCreatorAccount.addr, Number(rewardTokenID))
.do()
expect(ownerTokenBal['asset-holding'].amount).toEqual(
ownerTokenBalPre['asset-holding'].amount + Number(sentAmount),
)
})
})

Expand Down
8 changes: 5 additions & 3 deletions contracts/bootstrap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,10 @@ async function main() {
algod,
)
}
validatorApp = await validatorClient.create.createApplication({})
validatorApp = await validatorClient.create.createApplication({}, { schema: { extraPages: 3 } })

console.log(`Validator registry app id is:${validatorApp.appId}`)
console.log(`Validator Contract HASH is:${validatorApp.compiledApproval.compiledHash}`)

// Fund the validator w/ 2 ALGO for contract mbr reqs.
await algokit.transferAlgos(
Expand All @@ -194,6 +197,7 @@ async function main() {
{},
{ sendParams: { populateAppCallResources: true } },
)
console.log(`application ${args.id} updated`)
}

console.log(
Expand All @@ -215,8 +219,6 @@ async function main() {
}
await composer.finalizeStakingContract({}).execute({ populateAppCallResources: true, suppressLog: true })

console.log(`Validator registry app id is:${validatorApp.appId}`)

if (args.network === 'localnet') {
kmd = algokit.getAlgoKmdClient(localConfig.kmdConfig)
// generate two dummy stakers - each w/ 100 million
Expand Down
4 changes: 2 additions & 2 deletions contracts/bootstrap/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bootstrap",
"version": "0.8.14",
"version": "0.8.15",
"description": "",
"main": "index.ts",
"scripts": {
Expand All @@ -11,7 +11,7 @@
},
"license": "MIT",
"dependencies": {
"@algorandfoundation/algokit-utils": "6.0.5-beta.1",
"@algorandfoundation/algokit-utils": "6.0.5",
"algosdk": "2.7.0",
"prompts": "^2.4.2",
"yargs": "^17.7.2"
Expand Down
Loading

0 comments on commit 90e8fc0

Please sign in to comment.