Skip to content

Commit

Permalink
Merge pull request #303 from TxnLab/dev
Browse files Browse the repository at this point in the history
v0.11.0
  • Loading branch information
pbennett authored Oct 9, 2024
2 parents 1850c83 + b4f19d0 commit bb0f527
Show file tree
Hide file tree
Showing 85 changed files with 45,237 additions and 36,079 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* text=auto
* eol=lf
1 change: 1 addition & 0 deletions .github/workflows/ci-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
pull_request:
branches:
- 'main'
- 'dev'

jobs:
ci-tests:
Expand Down
3 changes: 2 additions & 1 deletion .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
{
"typescript.tsdk": "./ui/node_modules/typescript/lib"
"typescript.tsdk": "./ui/node_modules/typescript/lib",
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit",
"source.organizeImports": "explicit"
},
}
7,690 changes: 3,774 additions & 3,916 deletions contracts/__test__/contracts.test.ts

Large diffs are not rendered by default.

91 changes: 37 additions & 54 deletions contracts/bootstrap/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as algokit from '@algorandfoundation/algokit-utils'
import { AlgorandClient } from '@algorandfoundation/algokit-utils'
import { Account, secretKeyToMnemonic } from 'algosdk'
import { AlgoAmount } from '@algorandfoundation/algokit-utils/types/amount'
Expand All @@ -8,8 +7,8 @@ import yargs from 'yargs'
import prompts from 'prompts'
import { AlgoClientConfig } from '@algorandfoundation/algokit-utils/types/network-client'
import { ClientManager } from '@algorandfoundation/algokit-utils/types/client-manager'
import { StakingPoolClient } from '../contracts/clients/StakingPoolClient'
import { ValidatorRegistryClient } from '../contracts/clients/ValidatorRegistryClient'
import { StakingPoolFactory } from '../contracts/clients/StakingPoolClient'
import { ValidatorRegistryFactory } from '../contracts/clients/ValidatorRegistryClient'

function getNetworkConfig(network: string): [AlgoClientConfig, bigint, string] {
let nfdRegistryAppID: bigint
Expand Down Expand Up @@ -134,78 +133,62 @@ async function main() {
}

// Generate staking pool template instance that we load into the validator registry instance's box storage
const poolClient = new StakingPoolClient(
{
sender: creatorAcct,
resolveBy: 'id',
id: 0,
deployTimeParams: {
nfdRegistryAppId: Number(registryAppID),
},
const stakingPoolFactory = algorand.client.getTypedAppFactory(StakingPoolFactory)
const { compiledApproval } = await stakingPoolFactory.appFactory.compile({
deployTimeParams: {
nfdRegistryAppId: Number(registryAppID),
},
algorand.client.algod,
)
const { approvalCompiled } = await poolClient.appClient.compile()

})
// first we have to deploy a staking pool contract instance for future use by the staking master contract which uses it as its
// 'reference' instance when creating new staking pool contract instances.
const validatorClient = new ValidatorRegistryClient(
{
sender: creatorAcct,
resolveBy: 'id',
id: 0,
deployTimeParams: {
nfdRegistryAppId: Number(registryAppID),
},
const validatorFactory = algorand.client.getTypedAppFactory(ValidatorRegistryFactory, {
defaultSender: creatorAcct.addr,
deployTimeParams: {
nfdRegistryAppId: Number(registryAppID),
},
algorand.client.algod,
)
})
// eslint-disable-next-line @typescript-eslint/no-explicit-any
console.log(`creating application`)
if (args.network === 'localnet') {
console.log(`funding ${creatorAcct.addr}`)
await algokit.ensureFunded(
{
accountToFund: creatorAcct,
fundingSource: await algorand.account.localNetDispenser(),
minSpendingBalance: AlgoAmount.Algos(200),
},
algorand.client.algod,
await algorand.account.ensureFunded(
creatorAcct.addr,
await algorand.account.localNetDispenser(),
AlgoAmount.Algos(200),
)
}
const validatorApp = await validatorClient.create.createApplication({}, { schema: { extraPages: 3 } })
const validatorApp = await validatorFactory.send.create.createApplication({
args: [],
extraProgramPages: 3,
})

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

// Fund the validator w/ 2 ALGO for contract mbr reqs.
await algokit.transferAlgos(
{
from: creatorAcct,
to: validatorApp.appAddress,
amount: AlgoAmount.Algos(2),
},
algorand.client.algod,
)
await algorand.send.payment({
sender: creatorAcct.addr,
receiver: validatorApp.result.appAddress,
amount: AlgoAmount.Algos(3),
})

console.log(
`loading the ${approvalCompiled.compiledBase64ToBytes.length} bytes of the staking contract into the validator contracts box storage`,
`loading the ${compiledApproval!.compiledBase64ToBytes.length} bytes of the staking contract into the validator contracts box storage`,
)

// Load the staking pool contract bytecode into the validator contract via box storage so it can later deploy
const composer = validatorClient
.compose()
.initStakingContract({ approvalProgramSize: approvalCompiled.compiledBase64ToBytes.length })
const composer = validatorApp.appClient.newGroup().initStakingContract({
args: { approvalProgramSize: compiledApproval!.compiledBase64ToBytes.length },
})

// load the StakingPool contract into box storage of the validator
// call loadStakingContractData - chunking the data from approvalCompiled 2000 bytes at a time
for (let i = 0; i < approvalCompiled.compiledBase64ToBytes.length; i += 2000) {
// call loadStakingContractData - chunking the data from compiledApproval 2000 bytes at a time
for (let i = 0; i < compiledApproval!.compiledBase64ToBytes.length; i += 2000) {
composer.loadStakingContractData({
offset: i,
data: approvalCompiled.compiledBase64ToBytes.subarray(i, i + 2000),
args: { offset: i, data: compiledApproval!.compiledBase64ToBytes.subarray(i, i + 2000) },
})
}
await composer.finalizeStakingContract({}).execute({ populateAppCallResources: true, suppressLog: true })
await composer.finalizeStakingContract().send({ populateAppCallResources: true, suppressLog: true })

if (args.network === 'localnet') {
// generate two dummy stakers - each w/ 100 million
Expand All @@ -223,12 +206,12 @@ async function main() {
// Write the mnemonic to a .sandbox file in ../../nodemgr directory
fs.writeFileSync(
'../../nodemgr/.env.sandbox',
`ALGO_MNEMONIC_${creatorAcct.addr.substring(0, 4)}=${secretKeyToMnemonic(creatorAcct.sk)}\nRETI_APPID=${validatorApp.appId}\nALGO_MNEMONIC_${staker1.addr.substring(0, 4)}=${secretKeyToMnemonic(staker1.sk)}\nALGO_MNEMONIC_${staker2.addr.substring(0, 4)}=${secretKeyToMnemonic(staker2.sk)}\n`,
`ALGO_MNEMONIC_${creatorAcct.addr.substring(0, 4)}=${secretKeyToMnemonic(creatorAcct.sk)}\nRETI_APPID=${validatorApp.appClient.appId}\nALGO_MNEMONIC_${staker1.addr.substring(0, 4)}=${secretKeyToMnemonic(staker1.sk)}\nALGO_MNEMONIC_${staker2.addr.substring(0, 4)}=${secretKeyToMnemonic(staker2.sk)}\n`,
)
console.log('Modified .env.sandbox in nodemgr directory with these values for testing')

// Create a .env.localnet file in the ui directory with the validator app id
createViteEnvFileForLocalnet(validatorApp.appId ?? args.id)
createViteEnvFileForLocalnet(validatorApp.appClient.appId ?? args.id)
}
}

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.10.1",
"version": "0.11.0",
"description": "",
"main": "index.ts",
"scripts": {
Expand All @@ -11,7 +11,7 @@
},
"license": "MIT",
"dependencies": {
"@algorandfoundation/algokit-utils": "^6.2.1",
"@algorandfoundation/algokit-utils": "7.0.0-beta.11",
"algosdk": "^2.9.0",
"prompts": "^2.4.2",
"yargs": "^17.7.2"
Expand Down
63 changes: 61 additions & 2 deletions contracts/contracts/artifacts/StakingPool.approval.teal
Original file line number Diff line number Diff line change
Expand Up @@ -4321,11 +4321,70 @@ checkIfBinClosed:
setRoundsPerDay:
proto 0 0

// contracts/stakingPool.algo.ts:1022
// this.roundsPerDay.value = AVG_ROUNDS_PER_DAY
// Push empty bytes after the frame pointer to reserve space for local variables
byte 0x

// *if51_condition
// contracts/stakingPool.algo.ts:1026
// this.txn.firstValid < 12
txn FirstValid
int 12
<
bz *if51_end

// *if51_consequent
// contracts/stakingPool.algo.ts:1028
// this.roundsPerDay.value = APPROX_AVG_ROUNDS_PER_DAY
byte 0x726f756e6473506572446179 // "roundsPerDay"
int 30857
app_global_put

// contracts/stakingPool.algo.ts:1029
// return
retsub

*if51_end:
// contracts/stakingPool.algo.ts:1032
// avgBlockTimeTenths =
// blocks[this.txn.firstValid - 1].timestamp - blocks[this.txn.firstValid - 11].timestamp
txn FirstValid
int 1
-
block BlkTimestamp
txn FirstValid
int 11
-
block BlkTimestamp
-
frame_bury 0 // avgBlockTimeTenths: uint64

// *if52_condition
// contracts/stakingPool.algo.ts:1034
// avgBlockTimeTenths === 0
frame_dig 0 // avgBlockTimeTenths: uint64
int 0
==
bz *if52_end

// *if52_consequent
// contracts/stakingPool.algo.ts:1036
// this.roundsPerDay.value = APPROX_AVG_ROUNDS_PER_DAY
byte 0x726f756e6473506572446179 // "roundsPerDay"
int 30857
app_global_put

// contracts/stakingPool.algo.ts:1037
// return
retsub

*if52_end:
// contracts/stakingPool.algo.ts:1042
// this.roundsPerDay.value = (24 * 60 * 60 * 10) / avgBlockTimeTenths
byte 0x726f756e6473506572446179 // "roundsPerDay"
int 864000
frame_dig 0 // avgBlockTimeTenths: uint64
/
app_global_put
retsub

*create_NoOp:
Expand Down
3 changes: 2 additions & 1 deletion contracts/contracts/artifacts/StakingPool.arc32.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions contracts/contracts/artifacts/StakingPool.arc4.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
{
"name": "getStakerInfo",
"desc": "Retrieves the staked information for a given staker.",
"readonly": true,
"args": [
{
"name": "staker",
Expand Down
Loading

0 comments on commit bb0f527

Please sign in to comment.