Skip to content

Commit

Permalink
Merge pull request #255 from TxnLab/dev
Browse files Browse the repository at this point in the history
v0.9.6
  • Loading branch information
drichar authored Jul 25, 2024
2 parents d130fdb + daabc8a commit dc2e664
Show file tree
Hide file tree
Showing 42 changed files with 6,157 additions and 4,805 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: [TxnLab]
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "all",
"tabWidth": 2,
"semi": false,
"singleQuote": true
}
479 changes: 201 additions & 278 deletions contracts/__test__/contracts.test.ts

Large diffs are not rendered by default.

48 changes: 24 additions & 24 deletions contracts/bootstrap/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import * as algokit from '@algorandfoundation/algokit-utils'
import { mnemonicAccountFromEnvironment } from '@algorandfoundation/algokit-utils'
import { Account, decodeAddress, Kmd, secretKeyToMnemonic } from 'algosdk'
import { AlgorandClient } from '@algorandfoundation/algokit-utils'
import { Account, decodeAddress, secretKeyToMnemonic } from 'algosdk'
import { AlgoAmount } from '@algorandfoundation/algokit-utils/types/amount'
import { getTestAccount } from '@algorandfoundation/algokit-utils/testing'
import * as fs from 'fs'
import { AlgoClientConfig } from '@algorandfoundation/algokit-utils/types/network-client'
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 { getPools } from '../helpers/helpers'
Expand All @@ -19,7 +20,7 @@ function getNetworkConfig(network: string): [AlgoClientConfig, bigint, string] {
case 'localnet':
registryAppID = 0n
feeSink = 'A7NMWS3NT3IUDMLVO26ULGXGIIOUQ3ND2TXSER6EBGRZNOBOUIQXHIBGDE'
return [algokit.getConfigFromEnvOrDefaults().algodConfig, registryAppID, feeSink]
return [ClientManager.getConfigFromEnvironmentOrLocalNet().algodConfig, registryAppID, feeSink]
case 'betanet':
registryAppID = 842656530n
feeSink = 'A7NMWS3NT3IUDMLVO26ULGXGIIOUQ3ND2TXSER6EBGRZNOBOUIQXHIBGDE'
Expand Down Expand Up @@ -87,13 +88,16 @@ async function main() {
.option('update', { type: 'boolean', default: false })
.option('id', { type: 'number', default: 0 }).argv

const [algodconfig, registryAppID, feeSink] = getNetworkConfig(args.network)
const [algodConfig, registryAppID, feeSink] = getNetworkConfig(args.network)

const algod = algokit.getAlgoClient(algodconfig)
const localConfig = algokit.getConfigFromEnvOrDefaults()
// default to localnet
let algorand: AlgorandClient = algokit.AlgorandClient.defaultLocalNet()
if (args.network !== 'localnet') {
algorand = algokit.AlgorandClient.fromConfig({ algodConfig, indexerConfig: undefined, kmdConfig: undefined })
}
// const algorand = algokit.AlgorandClient.fromConfig({ algodConfig: algodconfig, kmdConfig })

let creatorAcct: Account
let kmd: Kmd

// Confirm the network choice by prompting the user if they want to continue if !localnet
if (args.network !== 'localnet') {
Expand All @@ -102,7 +106,7 @@ async function main() {
console.error('Environment variable CREATOR_MNEMONIC is not defined')
process.exit(1)
}
creatorAcct = await mnemonicAccountFromEnvironment('CREATOR', algod)
creatorAcct = (await algorand.account.fromEnvironment('CREATOR')).account
console.log(`using ${creatorAcct.addr} as Reti creator. MAKE SURE THIS IS CORRECT!`)

console.log(`You've specified you want to DEPLOY to ${args.network}! This is permanent !`)
Expand All @@ -116,12 +120,11 @@ async function main() {
return
}
} else {
kmd = algokit.getAlgoKmdClient(localConfig.kmdConfig)
if (!process.env.CREATOR_MNEMONIC) {
console.log('no creator account specified - using dispenser account as creator')
creatorAcct = await algokit.getDispenserAccount(algod, kmd)
creatorAcct = (await algorand.account.dispenserFromEnvironment()).account
} else {
creatorAcct = await mnemonicAccountFromEnvironment('CREATOR', algod)
creatorAcct = (await algorand.account.fromEnvironment('CREATOR')).account
console.log(`using ${creatorAcct.addr} as Reti creator. MAKE SURE THIS IS CORRECT!`)
}

Expand All @@ -135,7 +138,7 @@ async function main() {
resolveBy: 'id',
id: 0,
},
algod,
algorand.client.algod,
)
const { approvalCompiled } = await poolClient.appClient.compile({
deployTimeParams: {
Expand All @@ -144,7 +147,7 @@ async function main() {
},
})

// first we have to deploy a staking pool contract instance for future use by the staking master contract (which uses it as its
// 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(
{
Expand All @@ -155,7 +158,7 @@ async function main() {
nfdRegistryAppId: registryAppID,
},
},
algod,
algorand.client.algod,
)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let validatorApp: any
Expand All @@ -166,10 +169,10 @@ async function main() {
await algokit.ensureFunded(
{
accountToFund: creatorAcct,
fundingSource: await algokit.getDispenserAccount(algod, kmd!),
fundingSource: await algorand.account.localNetDispenser(),
minSpendingBalance: AlgoAmount.Algos(200),
},
algod,
algorand.client.algod,
)
}
validatorApp = await validatorClient.create.createApplication({}, { schema: { extraPages: 3 } })
Expand All @@ -184,7 +187,7 @@ async function main() {
to: validatorApp.appAddress,
amount: AlgoAmount.Algos(2),
},
algod,
algorand.client.algod,
)
} else {
if (args.id === 0) {
Expand Down Expand Up @@ -221,17 +224,14 @@ async function main() {
await composer.finalizeStakingContract({}).execute({ populateAppCallResources: true, suppressLog: true })

if (args.network === 'localnet') {
kmd = algokit.getAlgoKmdClient(localConfig.kmdConfig)
// generate two dummy stakers - each w/ 100 million
const staker1 = await getTestAccount(
{ initialFunds: AlgoAmount.Algos(100_000_000), suppressLog: true },
algod,
kmd,
algorand,
)
const staker2 = await getTestAccount(
{ initialFunds: AlgoAmount.Algos(100_000_000), suppressLog: true },
algod,
kmd,
algorand,
)
console.log(`Created test account 1:${staker1.addr}`)
console.log(`Created test account 2:${staker2.addr}`)
Expand Down Expand Up @@ -264,7 +264,7 @@ async function main() {
feeSinkAddr: decodeAddress(feeSink).publicKey,
},
},
algod,
algorand.client.algod,
)
console.log(`updating validator:${valId}, pool appid: ${pool.poolAppId}`)
// eslint-disable-next-line no-await-in-loop
Expand Down
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.5",
"version": "0.9.6",
"description": "",
"main": "index.ts",
"scripts": {
Expand All @@ -11,8 +11,8 @@
},
"license": "MIT",
"dependencies": {
"@algorandfoundation/algokit-utils": "6.0.5",
"algosdk": "2.8.0",
"@algorandfoundation/algokit-utils": "^6.1.2",
"algosdk": "^2.8.0",
"prompts": "^2.4.2",
"yargs": "^17.7.2"
},
Expand Down
Loading

0 comments on commit dc2e664

Please sign in to comment.