Skip to content

Commit

Permalink
Merge pull request #125 from TxnLab/dev
Browse files Browse the repository at this point in the history
v0.8.2
  • Loading branch information
drichar authored May 3, 2024
2 parents 7efc28d + 19d6a9e commit c58270f
Show file tree
Hide file tree
Showing 20 changed files with 459 additions and 247 deletions.
2 changes: 1 addition & 1 deletion contracts/bootstrap/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bootstrap",
"version": "0.8.1",
"version": "0.8.2",
"description": "",
"main": "index.ts",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "reti-contracts",
"version": "0.8.1",
"version": "0.8.2",
"license": "MIT",
"scripts": {
"generate-client": "algokit generate client contracts/artifacts/ --language typescript --output contracts/clients/{contract_name}Client.ts && ./update_contract_artifacts.sh``",
Expand Down
2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "reti-ui",
"version": "0.8.1",
"version": "0.8.2",
"author": {
"name": "Doug Richar",
"email": "[email protected]"
Expand Down
14 changes: 7 additions & 7 deletions ui/src/api/algod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@ const algodClient = algokit.getAlgoClient({
token: algodConfig.token,
})

export async function getAccountInformation(
export async function fetchAccountInformation(
address: string,
exclude: Exclude = 'none',
): Promise<AccountInformation> {
const accountInfo = await algodClient.accountInformation(address).exclude(exclude).do()
return accountInfo as AccountInformation
}

export async function getAccountBalance(
export async function fetchAccountBalance(
address: string,
availableBalance = false,
): Promise<number> {
const accountInfo = await getAccountInformation(address, 'all')
const accountInfo = await fetchAccountInformation(address, 'all')

return availableBalance ? accountInfo.amount - accountInfo['min-balance'] : accountInfo.amount
}

export async function getAsset(assetId: number): Promise<Asset> {
export async function fetchAsset(assetId: number): Promise<Asset> {
const asset = await algodClient.getAssetByID(assetId).do()
return asset as Asset
}
Expand All @@ -46,7 +46,7 @@ export async function fetchBalance(address: string | null): Promise<AccountBalan
if (!address) {
throw new Error('No address provided')
}
const accountInfo = await getAccountInformation(address, 'all')
const accountInfo = await fetchAccountInformation(address, 'all')

const amount = accountInfo.amount
const minimum = accountInfo['min-balance']
Expand All @@ -63,7 +63,7 @@ export async function fetchAssetHoldings(address: string | null): Promise<AssetH
if (!address) {
throw new Error('No address provided')
}
const accountInfo = await getAccountInformation(address)
const accountInfo = await fetchAccountInformation(address)
const assets = accountInfo.assets || []
return assets
}
Expand Down Expand Up @@ -91,7 +91,7 @@ export async function fetchAssetCreatorHoldings(
const batches = chunkArray(assetHoldings, batchSize)

for (const batch of batches) {
const promises = batch.map((holding) => getAsset(holding['asset-id']))
const promises = batch.map((holding) => fetchAsset(holding['asset-id']))
const assets = await Promise.all(promises)
const assetCreatorHoldings = assets.map((asset, index) => {
return {
Expand Down
89 changes: 89 additions & 0 deletions ui/src/api/clients.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import * as algokit from '@algorandfoundation/algokit-utils'
import { TransactionSignerAccount } from '@algorandfoundation/algokit-utils/types/account'
import algosdk from 'algosdk'
import { FEE_SINK } from '@/constants/accounts'
import { StakingPoolClient } from '@/contracts/StakingPoolClient'
import { ValidatorRegistryClient } from '@/contracts/ValidatorRegistryClient'
import { makeEmptyTransactionSigner } from '@/lib/makeEmptyTransactionSigner'
import { getRetiAppIdFromViteEnvironment } from '@/utils/env'
import { getAlgodConfigFromViteEnvironment } from '@/utils/network/getAlgoClientConfigs'
import { ParamsCache } from '@/utils/paramsCache'

const algodConfig = getAlgodConfigFromViteEnvironment()
const algodClient = algokit.getAlgoClient({
server: algodConfig.server,
port: algodConfig.port,
token: algodConfig.token,
})

const RETI_APP_ID = getRetiAppIdFromViteEnvironment()

export async function getValidatorClient(
signer: algosdk.TransactionSigner,
activeAddress: string,
): Promise<ValidatorRegistryClient> {
const params = await ParamsCache.getSuggestedParams()

return new ValidatorRegistryClient(
{
sender: { signer, addr: activeAddress },
resolveBy: 'id',
id: RETI_APP_ID,
params,
},
algodClient,
)
}

export async function getSimulateValidatorClient(
senderAddr: string = FEE_SINK,
authAddr?: string,
): Promise<ValidatorRegistryClient> {
const params = await ParamsCache.getSuggestedParams()

return new ValidatorRegistryClient(
{
sender: { addr: senderAddr, signer: makeEmptyTransactionSigner(authAddr) },
resolveBy: 'id',
id: RETI_APP_ID,
params,
},
algodClient,
)
}

export async function getStakingPoolClient(
poolAppId: number | bigint,
signer: algosdk.TransactionSigner,
activeAddress: string,
): Promise<StakingPoolClient> {
const params = await ParamsCache.getSuggestedParams()

return new StakingPoolClient(
{
sender: { signer, addr: activeAddress } as TransactionSignerAccount,
resolveBy: 'id',
id: poolAppId,
params,
},
algodClient,
)
}

export async function getSimulateStakingPoolClient(
poolAppId: number | bigint,
senderAddr: string = FEE_SINK,
authAddr?: string,
): Promise<StakingPoolClient> {
const params = await ParamsCache.getSuggestedParams()

return new StakingPoolClient(
{
sender: { addr: senderAddr, signer: makeEmptyTransactionSigner(authAddr) },
resolveBy: 'id',
id: poolAppId,
params,
},
algodClient,
)
}
Loading

0 comments on commit c58270f

Please sign in to comment.