Skip to content

Commit

Permalink
Merge pull request #273 from TxnLab/dev
Browse files Browse the repository at this point in the history
0.9.9
  • Loading branch information
pbennett authored Sep 12, 2024
2 parents 5c193a6 + e12d469 commit b05151e
Show file tree
Hide file tree
Showing 38 changed files with 75,144 additions and 25,671 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion Dockerfile-nodemgr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.22-alpine as builder
FROM golang:1.23-alpine as builder

Check warning on line 1 in Dockerfile-nodemgr

View workflow job for this annotation

GitHub Actions / docker

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/
ARG REL_VER
# Install git and certificates
RUN apk --no-cache add tzdata zip ca-certificates git
Expand Down
595 changes: 578 additions & 17 deletions contracts/__test__/contracts.test.ts

Large diffs are not rendered by default.

141 changes: 50 additions & 91 deletions contracts/bootstrap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,41 @@ import { AlgoClientConfig } from '@algorandfoundation/algokit-utils/types/networ
import { ClientManager } from '@algorandfoundation/algokit-utils/types/client-manager'
import { StakingPoolClient } from '../contracts/clients/StakingPoolClient'
import { ValidatorRegistryClient } from '../contracts/clients/ValidatorRegistryClient'
import { getPools } from '../helpers/helpers'

function getNetworkConfig(network: string): [AlgoClientConfig, bigint, string] {
let registryAppID: bigint
let nfdRegistryAppID: bigint
let feeSink: string
switch (network) {
case 'devnet':
case 'localnet':
registryAppID = 0n
nfdRegistryAppID = 0n
feeSink = 'A7NMWS3NT3IUDMLVO26ULGXGIIOUQ3ND2TXSER6EBGRZNOBOUIQXHIBGDE'
return [ClientManager.getConfigFromEnvironmentOrLocalNet().algodConfig, registryAppID, feeSink]
return [ClientManager.getConfigFromEnvironmentOrLocalNet().algodConfig, nfdRegistryAppID, feeSink]
case 'fnet':
nfdRegistryAppID = 0n
feeSink = 'FEESINK7OJKODDB5ZB4W2SRYPUSTOTK65UDCUYZ5DB4BW3VOHDHGO6JUNE'
break
case 'betanet':
registryAppID = 842656530n
nfdRegistryAppID = 842656530n
feeSink = 'A7NMWS3NT3IUDMLVO26ULGXGIIOUQ3ND2TXSER6EBGRZNOBOUIQXHIBGDE'
break
case 'testnet':
registryAppID = 84366825n
nfdRegistryAppID = 84366825n
feeSink = 'A7NMWS3NT3IUDMLVO26ULGXGIIOUQ3ND2TXSER6EBGRZNOBOUIQXHIBGDE'
break
case 'mainnet':
registryAppID = 760937186n
nfdRegistryAppID = 760937186n
feeSink = 'Y76M3MSY6DKBRHBL7C3NNDXGS5IIMQVQVUAB6MP4XEMMGVF2QWNPL226CA'
break
default:
throw new Error(`Unsupported network network: ${network}`)
}
const config = {
server: `https://${network}-api.algonode.cloud/`,
server: `https://${network}-api.4160.nodely.dev/`,
port: 443,
} as AlgoClientConfig

return [config, registryAppID, feeSink]
return [config, nfdRegistryAppID, feeSink]
}

/**
Expand Down Expand Up @@ -79,23 +82,22 @@ function createViteEnvFileForLocalnet(validatorAppId: number | bigint): void {
}

async function main() {
const args = await yargs
.option('network', {
default: 'localnet',
choices: ['localnet', 'betanet', 'testnet', 'mainnet'],
demandOption: true,
})
.option('update', { type: 'boolean', default: false })
.option('id', { type: 'number', default: 0 }).argv
const args = await yargs.option('network', {
default: 'localnet',
choices: ['localnet', 'fnet', 'betanet', 'testnet', 'mainnet'],
demandOption: true,
}).argv

console.log(`Network:${args.network}`)
const [algodConfig, registryAppID, feeSink] = getNetworkConfig(args.network)

// default to localnet
let algorand: AlgorandClient = algokit.AlgorandClient.defaultLocalNet()
let algorand: AlgorandClient = AlgorandClient.defaultLocalNet()
// let compileClient: AlgorandClient
if (args.network !== 'localnet') {
algorand = algokit.AlgorandClient.fromConfig({ algodConfig, indexerConfig: undefined, kmdConfig: undefined })
algorand = AlgorandClient.fromConfig({ algodConfig, indexerConfig: undefined, kmdConfig: undefined })
}
// const algorand = algokit.AlgorandClient.fromConfig({ algodConfig: algodconfig, kmdConfig })
console.log(`algo config is:${JSON.stringify(algodConfig)}`)

let creatorAcct: Account

Expand Down Expand Up @@ -137,72 +139,55 @@ async function main() {
sender: creatorAcct,
resolveBy: 'id',
id: 0,
deployTimeParams: {
nfdRegistryAppId: Number(registryAppID),
feeSinkAddr: decodeAddress(feeSink).publicKey,
},
},
algorand.client.algod,
)
const { approvalCompiled } = await poolClient.appClient.compile({
deployTimeParams: {
nfdRegistryAppId: registryAppID,
feeSinkAddr: decodeAddress(feeSink).publicKey,
},
})
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: args.id,
id: 0,
deployTimeParams: {
nfdRegistryAppId: registryAppID,
nfdRegistryAppId: Number(registryAppID),
},
},
algorand.client.algod,
)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let validatorApp: any
if (!args.update) {
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,
)
}
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(
console.log(`creating application`)
if (args.network === 'localnet') {
console.log(`funding ${creatorAcct.addr}`)
await algokit.ensureFunded(
{
from: creatorAcct,
to: validatorApp.appAddress,
amount: AlgoAmount.Algos(2),
accountToFund: creatorAcct,
fundingSource: await algorand.account.localNetDispenser(),
minSpendingBalance: AlgoAmount.Algos(200),
},
algorand.client.algod,
)
} else {
if (args.id === 0) {
// error - id must be defined!
console.error('Error: id must be defined!')
process.exit(1)
}
console.log(`updating application ${args.id}`)
validatorApp = await validatorClient.update.updateApplication(
{},
{ sendParams: { populateAppCallResources: true } },
)
console.log(`application ${args.id} updated`)
console.log(`Validator Contract HASH is:${validatorApp.compiledApproval.compiledHash}`)
}
const 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(
{
from: creatorAcct,
to: validatorApp.appAddress,
amount: AlgoAmount.Algos(2),
},
algorand.client.algod,
)

console.log(
`loading the ${approvalCompiled.compiledBase64ToBytes.length} bytes of the staking contract into the validator contracts box storage`,
Expand Down Expand Up @@ -246,32 +231,6 @@ async function main() {
// Create a .env.localnet file in the ui directory with the validator app id
createViteEnvFileForLocalnet(validatorApp.appId ?? args.id)
}

if (args.update) {
// Fetch all validators, and all their pools - updating all of them.
const numV = (await validatorClient.getGlobalState()).numV!.asNumber()
for (let valId = 1; valId <= numV; valId += 1) {
// const state = await getValidatorState(validatorClient, valId)
const pools = await getPools(validatorClient, valId)
for (const pool of pools) {
const updPoolClient = new StakingPoolClient(
{
sender: creatorAcct,
resolveBy: 'id',
id: pool.poolAppId,
deployTimeParams: {
nfdRegistryAppId: registryAppID,
feeSinkAddr: decodeAddress(feeSink).publicKey,
},
},
algorand.client.algod,
)
console.log(`updating validator:${valId}, pool appid: ${pool.poolAppId}`)
// eslint-disable-next-line no-await-in-loop
await updPoolClient.update.updateApplication({})
}
}
}
}

main()
6 changes: 3 additions & 3 deletions contracts/bootstrap/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bootstrap",
"version": "0.9.8",
"version": "0.9.9",
"description": "",
"main": "index.ts",
"scripts": {
Expand All @@ -11,8 +11,8 @@
},
"license": "MIT",
"dependencies": {
"@algorandfoundation/algokit-utils": "^6.1.2",
"algosdk": "^2.8.0",
"@algorandfoundation/algokit-utils": "^6.2.1",
"algosdk": "^2.9.0",
"prompts": "^2.4.2",
"yargs": "^17.7.2"
},
Expand Down
Loading

0 comments on commit b05151e

Please sign in to comment.