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
15 changes: 15 additions & 0 deletions src/lib/optimize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,21 @@ export function optimizeOpcodes(inputTeal: TEALInfo[]): TEALInfo[] {
pushTeal(`int ${length}`, node);
pushTeal('box_extract', node);
optimized = true;
} else if (start > 255 || length > 255) {
// The extract opcode uses 0 to indicate that the length is the rest of the bytes
// So when the length is 0 we need to calculate the bytes length and use substring3 instead
if (length === 0) {
pushTeal('dup', node);
pushTeal('len', node);
pushTeal(`int ${start}`, node);
pushTeal('swap', node);
pushTeal('substring3', node);
} else {
pushTeal(`int ${start}`, node);
pushTeal(`int ${length}`, node);
pushTeal('extract3', node);
}
optimized = true;
}
} else if (teal.startsWith('substring ') && outputTeal.at(-1)?.teal.startsWith('byte 0x')) {
const bytes = outputTeal.at(-1)!.teal.split(' ')[1].slice(2);
Expand Down
256 changes: 256 additions & 0 deletions tests/contracts/artifacts/TokenInfoContract.approval.teal
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
#pragma version 10
intcblock 256 1024 0 1
bytecblock 0x 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0x0000000000000000

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

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

// The following ten lines of TEAL handle initial program flow
// This pattern is used to make it easy for anyone to parse the start of the program and determine if a specific action is allowed
// Here, action refers to the OnComplete in combination with whether the app is being created or called
// Every possible action for this contract is represented in the switch statement
// If the action is not implemented in the contract, its respective branch will be "*NOT_IMPLEMENTED" which just contains "err"
txn ApplicationID
!
pushint 6
*
txn OnCompletion
+
switch *call_NoOp *NOT_IMPLEMENTED *NOT_IMPLEMENTED *NOT_IMPLEMENTED *NOT_IMPLEMENTED *NOT_IMPLEMENTED *create_NoOp *NOT_IMPLEMENTED *NOT_IMPLEMENTED *NOT_IMPLEMENTED *NOT_IMPLEMENTED *NOT_IMPLEMENTED

*NOT_IMPLEMENTED:
// The requested action is not implemented in this contract. Are you using the correct OnComplete? Did you set your app ID?
err

// doMath(uint64,string,string,string,string,string,string,string,string,uint64)void
*abi_route_doMath:
// mintedAsset: uint64
txna ApplicationArgs 10
btoi

// socialX: string
txna ApplicationArgs 9
extract 2 0

// socialDiscord: string
txna ApplicationArgs 8
extract 2 0

// socialTelegram: string
txna ApplicationArgs 7
extract 2 0

// socialWebsite: string
txna ApplicationArgs 6
extract 2 0

// description: string
txna ApplicationArgs 5
extract 2 0

// assetUrl: string
txna ApplicationArgs 4
extract 2 0

// name: string
txna ApplicationArgs 3
extract 2 0

// symbol: string
txna ApplicationArgs 2
extract 2 0

// k: uint64
txna ApplicationArgs 1
btoi

// execute doMath(uint64,string,string,string,string,string,string,string,string,uint64)void
callsub doMath
intc 3 // 1
return

// doMath(k: uint64, symbol: string, name: string, assetUrl: string, description: string, socialWebsite: string, socialTelegram: string, socialDiscord: string, socialX: string, mintedAsset: AssetID): void
doMath:
proto 10 0

// Push empty bytes after the frame pointer to reserve space for local variables
bytec 0 // 0x

// tests/contracts/token_info.algo.ts:57
// tokenData: TokenInfo = {
// tokenCreator: this.txn.sender,
// currentBonding: 0,
// bondingOn: BOND_PLATFORM_UNBONDED,
// p0: P0,
// pQ: PQ,
// k: k,
// Q: this.bondSupply.value,
// launchQ: this.createSupply.value,
// feeBpsPlatform: this.feeBpsPlatform.value,
// feeBpsCreator: this.feeBpsCreator.value,
// assetId: AssetID.fromUint64(mintedAsset.id),
// symbol: symbol as bytes<8>,
// name: name as bytes<32>,
// assetUrl: assetUrl as bytes<96>,
// description: description as bytes<1024>,
// socialWebsite: socialWebsite as bytes<256>,
// socialX: socialX as bytes<64>,
// socialTelegram: socialTelegram as bytes<64>,
// socialDiscord: socialDiscord as bytes<64>,
// }
txn Sender
pushbytes 0x00000000000003e8
concat
pushbytes 0x00000000000001f4
concat
pushbytes 0x626f6e64537570706c79 // "bondSupply"
app_global_get
itob
concat
frame_dig -1 // k: uint64
itob
concat
pushbytes 0x637265617465537570706c79 // "createSupply"
app_global_get
itob
concat
pushbytes 0x666565427073506c6174666f726d // "feeBpsPlatform"
app_global_get
itob
concat
pushbytes 0x66656542707343726561746f72 // "feeBpsCreator"
app_global_get
itob
concat
bytec 2 // 0x0000000000000000
concat
pushbytes 0x000000000000007b
concat
frame_dig -10 // mintedAsset: AssetID
itob
concat
frame_dig -2 // symbol: string
bytec 2 // 0x0000000000000000
concat
dup
extract 8 0
bytec 0 // 0x
b==
assert
extract 0 8
concat
frame_dig -3 // name: string
pushbytes 0x0000000000000000000000000000000000000000000000000000000000000000
concat
dup
extract 32 0
bytec 0 // 0x
b==
assert
extract 0 32
concat
frame_dig -4 // assetUrl: string
pushbytes 0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
concat
dup
extract 96 0
bytec 0 // 0x
b==
assert
extract 0 96
concat
frame_dig -5 // description: string
pushbytes 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
concat
dup
dup
len
intc 1 // 1024
swap
substring3
bytec 0 // 0x
b==
assert
intc 2 // 0
intc 1 // 1024
extract3
concat
frame_dig -6 // socialWebsite: string
pushbytes 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
concat
dup
dup
len
intc 0 // 256
swap
substring3
bytec 0 // 0x
b==
assert
intc 2 // 0
intc 0 // 256
extract3
concat
frame_dig -9 // socialX: string
bytec 1 // 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
concat
dup
extract 64 0
bytec 0 // 0x
b==
assert
extract 0 64
concat
frame_dig -7 // socialTelegram: string
bytec 1 // 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
concat
dup
extract 64 0
bytec 0 // 0x
b==
assert
extract 0 64
concat
frame_dig -8 // socialDiscord: string
bytec 1 // 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
concat
dup
extract 64 0
bytec 0 // 0x
b==
assert
extract 0 64
concat
frame_bury 0 // tokenData: TokenInfo

// tests/contracts/token_info.algo.ts:78
// this.tokenMap(mintedAsset).value = tokenData
pushbytes 0x74 // "t"
frame_dig -10 // mintedAsset: AssetID
itob
concat
frame_dig 0 // tokenData: TokenInfo
box_put
retsub

*abi_route_createApplication:
intc 3 // 1
return

*create_NoOp:
pushbytes 0xb8447b36 // method "createApplication()void"
txna ApplicationArgs 0
match *abi_route_createApplication

// this contract does not implement the given ABI method for create NoOp
err

*call_NoOp:
pushbytes 0x5370f8d9 // method "doMath(uint64,string,string,string,string,string,string,string,string,uint64)void"
txna ApplicationArgs 0
match *abi_route_doMath

// this contract does not implement the given ABI method for call NoOp
err
Loading