Skip to content

Commit

Permalink
Merge main into release
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored May 21, 2024
2 parents dde51c7 + 383ebaa commit 8ae3005
Show file tree
Hide file tree
Showing 7 changed files with 407 additions and 259 deletions.
24 changes: 12 additions & 12 deletions docs/code/classes/types_composer.default.md
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ The built atomic transaction composer and the transactions

#### Defined in

[src/types/composer.ts:711](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L711)
[src/types/composer.ts:724](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L724)

___

Expand All @@ -488,7 +488,7 @@ ___

#### Defined in

[src/types/composer.ts:590](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L590)
[src/types/composer.ts:603](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L603)

___

Expand All @@ -509,7 +509,7 @@ ___

#### Defined in

[src/types/composer.ts:539](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L539)
[src/types/composer.ts:552](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L552)

___

Expand All @@ -530,7 +530,7 @@ ___

#### Defined in

[src/types/composer.ts:519](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L519)
[src/types/composer.ts:532](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L532)

___

Expand All @@ -551,7 +551,7 @@ ___

#### Defined in

[src/types/composer.ts:554](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L554)
[src/types/composer.ts:567](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L567)

___

Expand All @@ -572,7 +572,7 @@ ___

#### Defined in

[src/types/composer.ts:564](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L564)
[src/types/composer.ts:577](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L577)

___

Expand All @@ -593,7 +593,7 @@ ___

#### Defined in

[src/types/composer.ts:576](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L576)
[src/types/composer.ts:589](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L589)

___

Expand Down Expand Up @@ -634,7 +634,7 @@ ___

#### Defined in

[src/types/composer.ts:630](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L630)
[src/types/composer.ts:643](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L643)

___

Expand Down Expand Up @@ -676,7 +676,7 @@ ___

#### Defined in

[src/types/composer.ts:507](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L507)
[src/types/composer.ts:520](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L520)

___

Expand All @@ -697,7 +697,7 @@ ___

#### Defined in

[src/types/composer.ts:648](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L648)
[src/types/composer.ts:661](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L661)

___

Expand Down Expand Up @@ -743,7 +743,7 @@ The execution result

#### Defined in

[src/types/composer.ts:753](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L753)
[src/types/composer.ts:766](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L766)

___

Expand All @@ -762,4 +762,4 @@ The newly built atomic transaction composer and the transactions

#### Defined in

[src/types/composer.ts:743](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L743)
[src/types/composer.ts:756](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L756)
16 changes: 8 additions & 8 deletions docs/code/modules/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ the estimated rate.

#### Defined in

[src/transaction/transaction.ts:764](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L764)
[src/transaction/transaction.ts:777](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L777)

___

Expand Down Expand Up @@ -426,7 +426,7 @@ Allows for control of fees on a `Transaction` or `SuggestedParams` object

#### Defined in

[src/transaction/transaction.ts:787](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L787)
[src/transaction/transaction.ts:800](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L800)

___

Expand Down Expand Up @@ -1605,7 +1605,7 @@ The array of transactions with signers

#### Defined in

[src/transaction/transaction.ts:819](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L819)
[src/transaction/transaction.ts:832](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L832)

___

Expand Down Expand Up @@ -1938,7 +1938,7 @@ The suggested transaction parameters

#### Defined in

[src/transaction/transaction.ts:810](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L810)
[src/transaction/transaction.ts:823](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L823)

___

Expand Down Expand Up @@ -2300,7 +2300,7 @@ The dryrun result

#### Defined in

[src/transaction/transaction.ts:644](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L644)
[src/transaction/transaction.ts:657](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L657)

___

Expand Down Expand Up @@ -2591,7 +2591,7 @@ An object with transaction IDs, transactions, group transaction ID (`groupTransa

#### Defined in

[src/transaction/transaction.ts:509](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L509)
[src/transaction/transaction.ts:522](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L522)

___

Expand All @@ -2616,7 +2616,7 @@ An object with transaction IDs, transactions, group transaction ID (`groupTransa

#### Defined in

[src/transaction/transaction.ts:662](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L662)
[src/transaction/transaction.ts:675](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L675)

___

Expand Down Expand Up @@ -2895,4 +2895,4 @@ Throws an error if the transaction is not confirmed or rejected in the next `tim

#### Defined in

[src/transaction/transaction.ts:707](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L707)
[src/transaction/transaction.ts:720](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L720)
41 changes: 27 additions & 14 deletions src/transaction/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,15 @@ export async function populateAppCallResources(atc: algosdk.AtomicTransactionCom

// Do accounts first because the account limit is 4
r.accounts?.forEach((a) => {
group[i].txn.appAccounts?.push(algosdk.decodeAddress(a))
group[i].txn.appAccounts = [...(group[i].txn.appAccounts ?? []), algosdk.decodeAddress(a)]
})

r.apps?.forEach((a) => {
group[i].txn.appForeignApps?.push(Number(a))
group[i].txn.appForeignApps = [...(group[i].txn.appForeignApps ?? []), Number(a)]
})

r.assets?.forEach((a) => {
group[i].txn.appForeignAssets?.push(Number(a))
group[i].txn.appForeignAssets = [...(group[i].txn.appForeignAssets ?? []), Number(a)]
})

const accounts = group[i].txn.appAccounts?.length || 0
Expand Down Expand Up @@ -366,10 +366,10 @@ export async function populateAppCallResources(atc: algosdk.AtomicTransactionCom
if (txnIndex > -1) {
if (type === 'assetHolding') {
const { asset } = reference as algosdk.modelsv2.AssetHoldingReference
txns[txnIndex].txn.appForeignAssets?.push(Number(asset))
txns[txnIndex].txn.appForeignAssets = [...(txns[txnIndex].txn.appForeignAssets ?? []), Number(asset)]
} else {
const { app } = reference as algosdk.modelsv2.ApplicationLocalReference
txns[txnIndex].txn.appForeignApps?.push(Number(app))
txns[txnIndex].txn.appForeignApps = [...(txns[txnIndex].txn.appForeignApps ?? []), Number(app)]
}
return
}
Expand All @@ -393,7 +393,7 @@ export async function populateAppCallResources(atc: algosdk.AtomicTransactionCom
if (txnIndex > -1) {
const { account } = reference as algosdk.modelsv2.AssetHoldingReference | algosdk.modelsv2.ApplicationLocalReference

txns[txnIndex].txn.appAccounts?.push(algosdk.decodeAddress(account))
txns[txnIndex].txn.appAccounts = [...(txns[txnIndex].txn.appAccounts ?? []), algosdk.decodeAddress(account)]

return
}
Expand Down Expand Up @@ -421,22 +421,32 @@ export async function populateAppCallResources(atc: algosdk.AtomicTransactionCom
}

if (type === 'account') {
txns[txnIndex].txn.appAccounts?.push(algosdk.decodeAddress(reference as string))
txns[txnIndex].txn.appAccounts = [...(txns[txnIndex].txn.appAccounts ?? []), algosdk.decodeAddress(reference as string)]
} else if (type === 'app') {
txns[txnIndex].txn.appForeignApps?.push(Number(reference))
txns[txnIndex].txn.appForeignApps = [...(txns[txnIndex].txn.appForeignApps ?? []), Number(reference)]
} else if (type === 'box') {
const { app, name } = reference as algosdk.modelsv2.BoxReference
txns[txnIndex].txn.boxes?.push({ appIndex: Number(app), name: name })
txns[txnIndex].txn.boxes = [...(txns[txnIndex].txn.boxes ?? []), { appIndex: Number(app), name }]

if (app.toString() !== '0') {
// Add the app if it is not already available
let appAlreadyAvailable = false
for (const t of txns) {
appAlreadyAvailable = t.txn.appForeignApps?.includes(Number(app)) || t.txn.appIndex === Number(app)
if (appAlreadyAvailable) break
}
if (!appAlreadyAvailable) populateGroupResource(txns, app, 'app')
}
} else if (type === 'assetHolding') {
const { asset, account } = reference as algosdk.modelsv2.AssetHoldingReference
txns[txnIndex].txn.appForeignAssets?.push(Number(asset))
txns[txnIndex].txn.appAccounts?.push(algosdk.decodeAddress(account))
txns[txnIndex].txn.appForeignAssets = [...(txns[txnIndex].txn.appForeignAssets ?? []), Number(asset)]
txns[txnIndex].txn.appAccounts = [...(txns[txnIndex].txn.appAccounts ?? []), algosdk.decodeAddress(account)]
} else if (type === 'appLocal') {
const { app, account } = reference as algosdk.modelsv2.ApplicationLocalReference
txns[txnIndex].txn.appAccounts?.push(algosdk.decodeAddress(account))
txns[txnIndex].txn.appForeignApps?.push(Number(app))
txns[txnIndex].txn.appAccounts = [...(txns[txnIndex].txn.appAccounts ?? []), algosdk.decodeAddress(account)]
txns[txnIndex].txn.appForeignApps = [...(txns[txnIndex].txn.appForeignApps ?? []), Number(app)]
} else if (type === 'asset') {
txns[txnIndex].txn.appForeignAssets?.push(Number(reference))
txns[txnIndex].txn.appForeignAssets = [...(txns[txnIndex].txn.appForeignAssets ?? []), Number(reference)]
}
}

Expand Down Expand Up @@ -468,6 +478,9 @@ export async function populateAppCallResources(atc: algosdk.AtomicTransactionCom

g.boxes?.forEach((b) => {
populateGroupResource(group, b, 'box')

// Remove resources from the group if we're adding them here
g.apps = g.apps?.filter((app) => BigInt(app) !== BigInt(b.app))
})

g.assets?.forEach((a) => {
Expand Down
22 changes: 21 additions & 1 deletion src/types/algorand-client.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
/* eslint-disable no-console */
import { TestContractClient } from '../../tests/example-contracts/client/TestContractClient'
import algosdk from 'algosdk'
import { APP_SPEC, TestContractClient } from '../../tests/example-contracts/client/TestContractClient'
import * as algokit from '../index'
import { algorandFixture } from '../testing'
import { TransactionSignerAccount } from './account'
import AlgorandClient from './algorand-client'
import { MethodCallParams } from './composer'

async function compileProgram(algorand: AlgorandClient, b64Teal: string) {
const teal = new Uint8Array(Buffer.from(b64Teal, 'base64'))
const result = await algorand.client.algod.compile(teal).do()

return new Uint8Array(Buffer.from(result.result, 'base64'))
}

describe('AlgorandClient', () => {
let algorand: AlgorandClient
let alice: TransactionSignerAccount
Expand Down Expand Up @@ -196,4 +204,16 @@ describe('AlgorandClient', () => {
})
expect(await algod.accountAssetInformation(alice.addr, Number(assetId)).do()).toBeDefined()
})

test('methodCall create', async () => {
const contract = new algosdk.ABIContract(APP_SPEC.contract)

await algorand.send.methodCall({
sender: alice.addr,
appId: 0n,
method: contract.getMethodByName('createApplication'),
approvalProgram: await compileProgram(algorand, APP_SPEC.source.approval),
clearProgram: await compileProgram(algorand, APP_SPEC.source.clear),
})
})
})
17 changes: 15 additions & 2 deletions src/types/composer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,23 @@ export default class AlgokitComposer {

const methodAtc = new algosdk.AtomicTransactionComposer()

const appID = Number(params.appId || 0)
methodAtc.addMethodCall({
...params,
appID: Number(params.appId || 0),
appID,
sender: params.sender,
suggestedParams,
onComplete: params.onComplete,
appAccounts: params.accountReferences,
appForeignApps: params.appReferences?.map((x) => Number(x)),
appForeignAssets: params.assetReferences?.map((x) => Number(x)),
approvalProgram: params.approvalProgram,
clearProgram: params.clearProgram,
extraPages: params.extraPages,
numLocalInts: params.schema?.localUints || (appID === 0 ? 0 : undefined),
numLocalByteSlices: params.schema?.localByteSlices || (appID === 0 ? 0 : undefined),
numGlobalInts: params.schema?.globalUints || (appID === 0 ? 0 : undefined),
numGlobalByteSlices: params.schema?.globalByteSlices || (appID === 0 ? 0 : undefined),
method: params.method,
signer: params.signer ? ('signer' in params.signer ? params.signer.signer : params.signer) : this.getSigner(params.sender),
methodArgs: methodArgs,
// note, lease, and rekeyTo are set in the common build step
Expand Down
Loading

0 comments on commit 8ae3005

Please sign in to comment.