Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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.3",
"algosdk": "3.0.0",
"prompts": "^2.4.2",
"yargs": "^17.7.2"
},
Expand Down
2 changes: 1 addition & 1 deletion contracts/contracts/artifacts/StakingPool.approval.teal
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
intcblock 0 1 6 64 32 16 128 200 5 1_000_000 300 1000 4 2_100_000 8 100000 400 30857 2 40 48 TMPL_nfdRegistryAppId
bytecblock 0x 0x63726561746f72417070 0x7374616b657273 0x76616c696461746f724964 0x706f6f6c4964 0x0a8101 0x7374616b6564 0x726f756e6473506572446179 0x7374616b65416363756d756c61746f72 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 0x0000000000000000 0x62696e526f756e645374617274 0x726577617264416363756d756c61746f72 0x6e756d5374616b657273 0x6c6173745061796f7574 0x75aff61d 0x00000000000000000000000000000000 0x00000000000000000000000000000064 0x6d696e456e7472795374616b65 0x65706f63684e756d626572 0x65776d61 0x151f7c75 0xa2dc51b5 0x572767d1 0x4df8d86e 0x0c2245e1 0x00

// This TEAL was generated by TEALScript v0.106.0
// This TEAL was generated by TEALScript v0.106.1
// https://github.com/algorandfoundation/TEALScript

// This contract is compliant with and/or implements the following ARCs: [ ARC4 ]
Expand Down
2 changes: 1 addition & 1 deletion contracts/contracts/artifacts/StakingPool.arc32.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
intcblock 0 1 8 24 18 268 32 6 3 242 2 10 252 260 700 4 100000 900 16 200 40 72 192 244 1000000 4096 5 226 TMPL_nfdRegistryAppId 300 432 892 1000 28500 50000 11 80 145 153 209
bytecblock 0x76 0x 0x151f7c75 0x737073 0x7374616b6564 0x00 0x6e756d5374616b657273 0x0000000000000000 0x0a8101 0x706f6f6c54656d706c617465417070726f76616c4279746573 0x692e6f776e65722e61 0x6e756d56 0x696e6974 0x63f3f28b 0x12f4bd4b

// This TEAL was generated by TEALScript v0.106.0
// This TEAL was generated by TEALScript v0.106.1
// https://github.com/algorandfoundation/TEALScript

// This contract is compliant with and/or implements the following ARCs: [ ARC4 ]
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

68 changes: 36 additions & 32 deletions contracts/contracts/clients/StakingPoolClient.ts

Large diffs are not rendered by default.

137 changes: 70 additions & 67 deletions contracts/contracts/clients/ValidatorRegistryClient.ts

Large diffs are not rendered by default.

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)
}
11 changes: 6 additions & 5 deletions contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
"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.3",
"algosdk": "3.0.0"
},
"devDependencies": {
"@algorandfoundation/algokit-client-generator": "4.0.0",
"@algorandfoundation/tealscript": "0.106.0",
"@algorandfoundation/algokit-client-generator": "4.0.6",
"@algorandfoundation/tealscript": "0.106.1",
"@joe-p/algokit-generate-component": "0.2.1",
"@typescript-eslint/eslint-plugin": "8.8.1",
"@typescript-eslint/parser": "8.8.1",
Expand Down
30 changes: 15 additions & 15 deletions nodemgr/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func initApp() *RetiApp {
Name: "réti node manager",
Usage: "Configuration tool and background daemon for Algorand validator pools",
Version: getVersionInfo(),
Before: func(ctx context.Context, cmd *cli.Command) error {
Before: func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
// This is further bootstrap of the 'app' but within context of 'cli' helper as it will
// have access to flags and options (network to use for eg) already set.
return appConfig.initClients(ctx, cmd)
Expand Down Expand Up @@ -143,20 +143,20 @@ type RetiApp struct {
// initClients initializes both an algod client (to correct network - which it
// also validates) and a nfd nfdApi client - for nfd updates or fetches if caller
// desires
func (ac *RetiApp) initClients(ctx context.Context, cmd *cli.Command) error {
func (ac *RetiApp) initClients(ctx context.Context, cmd *cli.Command) (context.Context, error) {
network := cmd.String("network")

if envfile := cmd.String("envfile"); envfile != "" {
err := loadNamedEnvFile(ctx, envfile)
newCtx, err := loadNamedEnvFile(ctx, envfile)
if err != nil {
return err
return newCtx, err
}
}
// quick validity check on possible network names...
switch network {
case "sandbox", "fnet", "betanet", "testnet", "mainnet":
default:
return fmt.Errorf("unknown network:%s", network)
return ctx, fmt.Errorf("unknown network:%s", network)
}
var (
algoClient *algod.Client
Expand All @@ -172,7 +172,7 @@ func (ac *RetiApp) initClients(ctx context.Context, cmd *cli.Command) error {
cfg := algo.GetNetworkConfig(network)
algoClient, err = algo.GetAlgoClient(ac.logger, cfg)
if err != nil {
return err
return ctx, err
}
ac.retiAppID = cfg.RetiAppID
// allow secondary override of the IDs via the network specific .env file we just loaded which we couldn't
Expand Down Expand Up @@ -202,7 +202,7 @@ func (ac *RetiApp) initClients(ctx context.Context, cmd *cli.Command) error {
}

if ac.retiAppID == 0 {
return fmt.Errorf("the id of the Reti Validator contract must be set using either -retiid or RETI_APPID env var!")
return ctx, fmt.Errorf("the id of the Reti Validator contract must be set using either -retiid or RETI_APPID env var!")
}

// This will load and initialize mnemonics from the environment - and handles all 'local' signing for the app
Expand All @@ -218,17 +218,17 @@ func (ac *RetiApp) initClients(ctx context.Context, cmd *cli.Command) error {
ac.nfdApi = api
nfdOnChain, err := nfdonchain.NewNfdApi(algoClient, cmd.String("network"))
if err != nil {
return fmt.Errorf("failed to initialize nfd onchain api client: %v", err)
return ctx, fmt.Errorf("failed to initialize nfd onchain api client: %v", err)
}
ac.nfdOnChain = nfdOnChain

// Initialize the 'reti' client
retiClient, err := reti.New(ac.retiAppID, ac.logger, ac.algoClient, ac.signer, ac.retiValidatorID, ac.retiNodeNum)
if err != nil {
return err
return ctx, err
}
ac.retiClient = retiClient
return retiClient.LoadState(ctx)
return ctx, retiClient.LoadState(ctx)
}

func setIntFromEnv(val *uint64, envName string) error {
Expand All @@ -242,16 +242,16 @@ func setIntFromEnv(val *uint64, envName string) error {
return nil
}

func checkConfigured(ctx context.Context, command *cli.Command) error {
func checkConfigured(ctx context.Context, command *cli.Command) (context.Context, error) {
if !App.retiClient.IsConfigured() {
return errors.New("validator not configured")
return ctx, errors.New("validator not configured")
}
return nil
return ctx, nil
}

func loadNamedEnvFile(ctx context.Context, envFile string) error {
func loadNamedEnvFile(ctx context.Context, envFile string) (context.Context, error) {
misc.Infof(App.logger, "loading env file:%s", envFile)
return godotenv.Load(envFile)
return ctx, godotenv.Load(envFile)
}

// Version is replaced at build time during docker builds w/ 'release' version
Expand Down
15 changes: 7 additions & 8 deletions nodemgr/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ module github.com/algorandfoundation/reti
go 1.23

require (
github.com/algorand/go-algorand-sdk/v2 v2.6.0
github.com/algorand/go-algorand-sdk/v2 v2.7.0
github.com/antihax/optional v1.0.0
github.com/joho/godotenv v1.5.1
github.com/mailgun/holster/v4 v4.20.3
github.com/manifoldco/promptui v0.9.0
github.com/prometheus/client_golang v1.20.4
github.com/prometheus/client_golang v1.20.5
github.com/ssgreg/repeat v1.5.1
github.com/urfave/cli/v3 v3.0.0-alpha9.1
golang.org/x/crypto v0.28.0
golang.org/x/oauth2 v0.23.0
golang.org/x/term v0.25.0
github.com/urfave/cli/v3 v3.0.0-beta1
golang.org/x/crypto v0.31.0
golang.org/x/oauth2 v0.24.0
golang.org/x/term v0.27.0
)

require (
Expand All @@ -28,7 +28,6 @@ require (
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/sys v0.28.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
)
Loading