Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
194 changes: 103 additions & 91 deletions contracts/__test__/contracts.test.ts

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions contracts/bootstrap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,13 @@ async function main() {
{ initialFunds: AlgoAmount.Algos(100_000_000), suppressLog: true },
algorand,
)
console.log(`Created test account 1:${staker1.addr}`)
console.log(`Created test account 2:${staker2.addr}`)
console.log(`Created test account 1: ${staker1.addr.toString()}`)
console.log(`Created test account 2: ${staker2.addr.toString()}`)

// 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.appClient.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.toString().substring(0, 4)}=${secretKeyToMnemonic(creatorAcct.sk)}\nRETI_APPID=${validatorApp.appClient.appId}\nALGO_MNEMONIC_${staker1.addr.toString().substring(0, 4)}=${secretKeyToMnemonic(staker1.sk)}\nALGO_MNEMONIC_${staker2.addr.toString().substring(0, 4)}=${secretKeyToMnemonic(staker2.sk)}\n`,
)
console.log('Modified .env.sandbox in nodemgr directory with these values for testing')

Expand Down
4 changes: 2 additions & 2 deletions contracts/bootstrap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
},
"license": "MIT",
"dependencies": {
"@algorandfoundation/algokit-utils": "7.0.0",
"algosdk": "2.9.0",
"@algorandfoundation/algokit-utils": "8.0.0",
"algosdk": "3.0.0",
"prompts": "^2.4.2",
"yargs": "^17.7.2"
},
Expand Down
24 changes: 12 additions & 12 deletions contracts/contracts/clients/StakingPoolClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AlgorandClientInterface } from '@algorandfoundation/algokit-utils/types
import { ABIReturn, AppReturn, SendAppTransactionResult } from '@algorandfoundation/algokit-utils/types/app'
import { Arc56Contract, getArc56ReturnValue, getABIStructFromABITuple } from '@algorandfoundation/algokit-utils/types/app-arc56'
import {
AppClient,
AppClient as _AppClient,
AppClientMethodCallParams,
AppClientParams,
AppClientBareCallParams,
Expand All @@ -18,7 +18,7 @@ import {
ResolveAppClientByNetwork,
CloneAppClientParams,
} from '@algorandfoundation/algokit-utils/types/app-client'
import { AppFactory, AppFactoryAppClientParams, AppFactoryResolveAppClientByCreatorAndNameParams, AppFactoryDeployParams, AppFactoryParams, CreateSchema } from '@algorandfoundation/algokit-utils/types/app-factory'
import { AppFactory as _AppFactory, AppFactoryAppClientParams, AppFactoryResolveAppClientByCreatorAndNameParams, AppFactoryDeployParams, AppFactoryParams, CreateSchema } from '@algorandfoundation/algokit-utils/types/app-factory'
import { TransactionComposer, AppCallMethodCall, AppMethodCallTransactionArgument, SimulateOptions } from '@algorandfoundation/algokit-utils/types/composer'
import { SendParams, SendSingleTransactionResult, SendAtomicTransactionComposerResults } from '@algorandfoundation/algokit-utils/types/transaction'
import { Address, encodeAddress, modelsv2, OnApplicationComplete, Transaction, TransactionSigner } from 'algosdk'
Expand Down Expand Up @@ -725,15 +725,15 @@ export class StakingPoolFactory {
/**
* The underlying `AppFactory` for when you want to have more flexibility
*/
public readonly appFactory: AppFactory
public readonly appFactory: _AppFactory

/**
* Creates a new instance of `StakingPoolFactory`
*
* @param params The parameters to initialise the app factory with
*/
constructor(params: Omit<AppFactoryParams, 'appSpec'>) {
this.appFactory = new AppFactory({
this.appFactory = new _AppFactory({
...params,
appSpec: APP_SPEC,
})
Expand Down Expand Up @@ -832,10 +832,10 @@ export class StakingPoolFactory {
* Initialize the staking pool w/ owner and manager, but can only be created by the validator contract.
*
* @param params The params for the smart contract call
* @returns The create params
* @returns The create transaction
*/
createApplication: (params: CallParams<StakingPoolArgs['obj']['createApplication(uint64,uint64,uint64,uint64)void'] | StakingPoolArgs['tuple']['createApplication(uint64,uint64,uint64,uint64)void']> & AppClientCompilationParams & CreateSchema & {onComplete?: OnApplicationComplete.NoOpOC}) => {
return this.appFactory.params.create(StakingPoolParamsFactory.create.createApplication(params))
return this.appFactory.createTransaction.create(StakingPoolParamsFactory.create.createApplication(params))
},
},

Expand Down Expand Up @@ -873,22 +873,22 @@ export class StakingPoolClient {
/**
* The underlying `AppClient` for when you want to have more flexibility
*/
public readonly appClient: AppClient
public readonly appClient: _AppClient

/**
* Creates a new instance of `StakingPoolClient`
*
* @param appClient An `AppClient` instance which has been created with the StakingPool app spec
*/
constructor(appClient: AppClient)
constructor(appClient: _AppClient)
/**
* Creates a new instance of `StakingPoolClient`
*
* @param params The parameters to initialise the app client with
*/
constructor(params: Omit<AppClientParams, 'appSpec'>)
constructor(appClientOrParams: AppClient | Omit<AppClientParams, 'appSpec'>) {
this.appClient = appClientOrParams instanceof AppClient ? appClientOrParams : new AppClient({
constructor(appClientOrParams: _AppClient | Omit<AppClientParams, 'appSpec'>) {
this.appClient = appClientOrParams instanceof _AppClient ? appClientOrParams : new _AppClient({
...appClientOrParams,
appSpec: APP_SPEC,
})
Expand All @@ -908,7 +908,7 @@ export class StakingPoolClient {
* @param params The parameters to create the app client
*/
public static async fromCreatorAndName(params: Omit<ResolveAppClientByCreatorAndName, 'appSpec'>): Promise<StakingPoolClient> {
return new StakingPoolClient(await AppClient.fromCreatorAndName({...params, appSpec: APP_SPEC}))
return new StakingPoolClient(await _AppClient.fromCreatorAndName({...params, appSpec: APP_SPEC}))
}

/**
Expand All @@ -921,7 +921,7 @@ export class StakingPoolClient {
static async fromNetwork(
params: Omit<ResolveAppClientByNetwork, 'appSpec'>
): Promise<StakingPoolClient> {
return new StakingPoolClient(await AppClient.fromNetwork({...params, appSpec: APP_SPEC}))
return new StakingPoolClient(await _AppClient.fromNetwork({...params, appSpec: APP_SPEC}))
}

/** The ID of the app instance this client is linked to. */
Expand Down
24 changes: 12 additions & 12 deletions contracts/contracts/clients/ValidatorRegistryClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AlgorandClientInterface } from '@algorandfoundation/algokit-utils/types
import { ABIReturn, AppReturn, SendAppTransactionResult } from '@algorandfoundation/algokit-utils/types/app'
import { Arc56Contract, getArc56ReturnValue, getABIStructFromABITuple } from '@algorandfoundation/algokit-utils/types/app-arc56'
import {
AppClient,
AppClient as _AppClient,
AppClientMethodCallParams,
AppClientParams,
AppClientBareCallParams,
Expand All @@ -18,7 +18,7 @@ import {
ResolveAppClientByNetwork,
CloneAppClientParams,
} from '@algorandfoundation/algokit-utils/types/app-client'
import { AppFactory, AppFactoryAppClientParams, AppFactoryResolveAppClientByCreatorAndNameParams, AppFactoryDeployParams, AppFactoryParams, CreateSchema } from '@algorandfoundation/algokit-utils/types/app-factory'
import { AppFactory as _AppFactory, AppFactoryAppClientParams, AppFactoryResolveAppClientByCreatorAndNameParams, AppFactoryDeployParams, AppFactoryParams, CreateSchema } from '@algorandfoundation/algokit-utils/types/app-factory'
import { TransactionComposer, AppCallMethodCall, AppMethodCallTransactionArgument, SimulateOptions } from '@algorandfoundation/algokit-utils/types/composer'
import { SendParams, SendSingleTransactionResult, SendAtomicTransactionComposerResults } from '@algorandfoundation/algokit-utils/types/transaction'
import { Address, encodeAddress, modelsv2, OnApplicationComplete, Transaction, TransactionSigner } from 'algosdk'
Expand Down Expand Up @@ -1440,15 +1440,15 @@ export class ValidatorRegistryFactory {
/**
* The underlying `AppFactory` for when you want to have more flexibility
*/
public readonly appFactory: AppFactory
public readonly appFactory: _AppFactory

/**
* Creates a new instance of `ValidatorRegistryFactory`
*
* @param params The parameters to initialise the app factory with
*/
constructor(params: Omit<AppFactoryParams, 'appSpec'>) {
this.appFactory = new AppFactory({
this.appFactory = new _AppFactory({
...params,
appSpec: APP_SPEC,
})
Expand Down Expand Up @@ -1543,10 +1543,10 @@ export class ValidatorRegistryFactory {
* Creates a new instance of the ValidatorRegistry smart contract using the createApplication()void ABI method.
*
* @param params The params for the smart contract call
* @returns The create params
* @returns The create transaction
*/
createApplication: (params: CallParams<ValidatorRegistryArgs['obj']['createApplication()void'] | ValidatorRegistryArgs['tuple']['createApplication()void']> & AppClientCompilationParams & CreateSchema & {onComplete?: OnApplicationComplete.NoOpOC} = {args: []}) => {
return this.appFactory.params.create(ValidatorRegistryParamsFactory.create.createApplication(params))
return this.appFactory.createTransaction.create(ValidatorRegistryParamsFactory.create.createApplication(params))
},
},

Expand Down Expand Up @@ -1582,22 +1582,22 @@ export class ValidatorRegistryClient {
/**
* The underlying `AppClient` for when you want to have more flexibility
*/
public readonly appClient: AppClient
public readonly appClient: _AppClient

/**
* Creates a new instance of `ValidatorRegistryClient`
*
* @param appClient An `AppClient` instance which has been created with the ValidatorRegistry app spec
*/
constructor(appClient: AppClient)
constructor(appClient: _AppClient)
/**
* Creates a new instance of `ValidatorRegistryClient`
*
* @param params The parameters to initialise the app client with
*/
constructor(params: Omit<AppClientParams, 'appSpec'>)
constructor(appClientOrParams: AppClient | Omit<AppClientParams, 'appSpec'>) {
this.appClient = appClientOrParams instanceof AppClient ? appClientOrParams : new AppClient({
constructor(appClientOrParams: _AppClient | Omit<AppClientParams, 'appSpec'>) {
this.appClient = appClientOrParams instanceof _AppClient ? appClientOrParams : new _AppClient({
...appClientOrParams,
appSpec: APP_SPEC,
})
Expand All @@ -1617,7 +1617,7 @@ export class ValidatorRegistryClient {
* @param params The parameters to create the app client
*/
public static async fromCreatorAndName(params: Omit<ResolveAppClientByCreatorAndName, 'appSpec'>): Promise<ValidatorRegistryClient> {
return new ValidatorRegistryClient(await AppClient.fromCreatorAndName({...params, appSpec: APP_SPEC}))
return new ValidatorRegistryClient(await _AppClient.fromCreatorAndName({...params, appSpec: APP_SPEC}))
}

/**
Expand All @@ -1630,7 +1630,7 @@ export class ValidatorRegistryClient {
static async fromNetwork(
params: Omit<ResolveAppClientByNetwork, 'appSpec'>
): Promise<ValidatorRegistryClient> {
return new ValidatorRegistryClient(await AppClient.fromNetwork({...params, appSpec: APP_SPEC}))
return new ValidatorRegistryClient(await _AppClient.fromNetwork({...params, appSpec: APP_SPEC}))
}

/** The ID of the app instance this client is linked to. */
Expand Down
20 changes: 13 additions & 7 deletions contracts/helpers/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ export async function getStakedPoolsForAccount(
validatorClient: ValidatorRegistryClient,
stakerAccount: Account,
): Promise<ValidatorPoolKey[]> {
const results = await validatorClient.send.getStakedPoolsForAccount({ args: { staker: stakerAccount.addr } })
const results = await validatorClient.send.getStakedPoolsForAccount({
args: { staker: stakerAccount.addr.toString() },
})

const retPoolKeys: ValidatorPoolKey[] = []
results.return!.forEach((poolKey) => {
Expand All @@ -188,7 +190,7 @@ export async function getStakedPoolsForAccount(
}

export async function getStakerInfo(stakeClient: StakingPoolClient, staker: Account) {
return (await stakeClient.send.getStakerInfo({ args: { staker: staker.addr } })).return!
return (await stakeClient.send.getStakerInfo({ args: { staker: staker.addr.toString() } })).return!
}

export async function getTokenPayoutRatio(validatorClient: ValidatorRegistryClient, validatorId: number) {
Expand All @@ -208,7 +210,11 @@ export async function addStake(
.newGroup()
.gas()
.findPoolForStaker({
args: { validatorId: vldtrId, staker: staker.addr, amountToStake: algoAmount.microAlgos },
args: {
validatorId: vldtrId,
staker: staker.addr.toString(),
amountToStake: algoAmount.microAlgos,
},
staticFee: AlgoAmount.MicroAlgos(2000),
})
.simulate({ allowUnnamedResources: true })
Expand Down Expand Up @@ -300,7 +306,7 @@ export async function removeStake(
.gas({ args: [], note: '1', staticFee: AlgoAmount.MicroAlgos(0) })
.gas({ args: [], note: '2', staticFee: AlgoAmount.MicroAlgos(0) })
.removeStake({
args: { staker: staker.addr, amountToUnstake: unstakeAmount.microAlgos },
args: { staker: staker.addr.toString(), amountToUnstake: unstakeAmount.microAlgos },
staticFee: AlgoAmount.MicroAlgos(240000),
sender: (altSender || staker).addr,
})
Expand All @@ -317,7 +323,7 @@ export async function removeStake(
.gas({ args: [], note: '1', staticFee: AlgoAmount.MicroAlgos(0) })
.gas({ args: [], note: '2', staticFee: AlgoAmount.MicroAlgos(0) })
.removeStake({
args: { staker: staker.addr, amountToUnstake: unstakeAmount.microAlgos },
args: { staker: staker.addr.toString(), amountToUnstake: unstakeAmount.microAlgos },
staticFee: AlgoAmount.MicroAlgos(itxnfees.microAlgo),
sender: (altSender || staker).addr,
})
Expand Down Expand Up @@ -444,7 +450,7 @@ export async function incrementRoundNumberBy(context: AlgorandTestAutomationCont
}
// Send `rounds` number of 'dummy' pay self 0 transactions
let params = await context.algod.getTransactionParams().do()
console.log('block before incrementRoundNumberBy:', params.firstRound)
console.log('block before incrementRoundNumberBy:', params.firstValid)
for (let i = 0; i < rounds; i += 1) {
await context.algorand.send.payment({
sender: context.testAccount.addr,
Expand All @@ -455,5 +461,5 @@ export async function incrementRoundNumberBy(context: AlgorandTestAutomationCont
}

params = await context.algod.getTransactionParams().do()
console.log('block AFTER incrementRoundNumberBy:', params.firstRound)
console.log('block AFTER incrementRoundNumberBy:', params.firstValid)
}
9 changes: 5 additions & 4 deletions contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
"lint": "eslint . --ext ts --max-warnings 0",
"lint:fix": "eslint . --ext ts --max-warnings 0 --fix",
"prettier": "pnpx prettier --check .",
"prettier:fix": "pnpx prettier --write ."
"prettier:fix": "pnpx prettier --write .",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@algorandfoundation/algokit-utils": "7.0.0",
"algosdk": "2.9.0"
"@algorandfoundation/algokit-utils": "8.0.0",
"algosdk": "3.0.0"
},
"devDependencies": {
"@algorandfoundation/algokit-client-generator": "4.0.0",
"@algorandfoundation/algokit-client-generator": "4.0.2",
"@algorandfoundation/tealscript": "0.106.0",
"@joe-p/algokit-generate-component": "0.2.1",
"@typescript-eslint/eslint-plugin": "8.8.1",
Expand Down
Loading