-
Notifications
You must be signed in to change notification settings - Fork 0
Executor Contracts #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
7f10e0b
init arbitrary executor
etzellux fe7afb7
fix cast error in arbitrary executor
etzellux ab56782
add arbitrary_executor_clear_state
etzellux 64f15a1
add initial test
etzellux dee010a
add test_execute_proposal
etzellux 092ca1b
update test_execute_proposal
etzellux 2007c4f
add executor logic signature
etzellux f6515fb
add fee_management_executor contracts
etzellux 6e20eed
add fee_management_executor tests
etzellux 6201f0d
update test_set_fee_for_pool_execution
etzellux fe72cd9
add treasury_management_executor contracts
etzellux e25bcdd
add TreasuryManagementExecutorTestCase
etzellux 1bb0053
update test and executors
etzellux dd5fb4c
remove sha256 from arbitrary methods
etzellux 5362922
update fee_management_executor and tests
etzellux e002106
update treasury_management_executor and tests
etzellux 260330c
update arbitrary_executor_logic_signature
etzellux 099172a
add set_proposal_as_executed to executors
etzellux 9058eee
update tests with sdk functions
etzellux 4217e5d
minor updates on contracts and tests
etzellux File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
158 changes: 158 additions & 0 deletions
158
contracts/arbitrary_executor/arbitrary_executor_approval.tl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| #pragma version 8 | ||
| #tealish version git+https://github.com/Hipo/tealish.git@e8d1b27620220bc4e520d7d3b6d62523e13a7723 | ||
|
|
||
| # Taken from Proposal Voting App | ||
| # Size: 123 bytes | ||
| struct Proposal: | ||
| index: int | ||
| creation_timestamp: int | ||
| voting_start_timestamp: int | ||
| voting_end_timestamp: int | ||
| snapshot_total_voting_power: int | ||
| vote_count: int | ||
| quorum_threshold: int | ||
| against_voting_power: int | ||
| for_voting_power: int | ||
| abstain_voting_power: int | ||
| is_approved: bytes[1] | ||
| is_cancelled: bytes[1] | ||
| is_executed: bytes[1] | ||
| is_quorum_reached: bytes[1] | ||
| proposer: bytes[32] | ||
| execution_hash: bytes[128] | ||
| executor: bytes[32] | ||
| end | ||
|
|
||
| # 24 * 60 * 60 | ||
| const int DAY = 86400 | ||
| const bytes BYTES_FALSE = "\x00" | ||
| const bytes BYTES_TRUE = "\x80" | ||
|
|
||
| const bytes MANAGER_KEY = "manager" | ||
| const bytes PROPOSAL_VOTING_APP_ID_KEY = "proposal_voting_app_id" | ||
|
|
||
| # Proposal States | ||
| const int PROPOSAL_STATE_WAITING_FOR_APPROVAL = 0 | ||
| const int PROPOSAL_STATE_CANCELLED = 1 | ||
| const int PROPOSAL_STATE_PENDING = 2 | ||
| const int PROPOSAL_STATE_ACTIVE = 3 | ||
| const int PROPOSAL_STATE_DEFEATED = 4 | ||
| const int PROPOSAL_STATE_SUCCEEDED = 5 | ||
| const int PROPOSAL_STATE_EXECUTED = 6 | ||
|
|
||
| if !Txn.ApplicationID: | ||
| jump create_app | ||
| end | ||
|
|
||
| switch Txn.OnCompletion: | ||
| NoOp: main | ||
| OptIn: fail | ||
| CloseOut: fail | ||
| UpdateApplication: update_app | ||
| DeleteApplication: fail | ||
| end | ||
|
|
||
| block fail: | ||
| exit(0) | ||
| end | ||
|
|
||
| block create_app: | ||
| app_global_put(PROPOSAL_VOTING_APP_ID_KEY, btoi(Txn.ApplicationArgs[0])) | ||
|
|
||
| app_global_put(MANAGER_KEY, Txn.Sender) | ||
| exit(1) | ||
| end | ||
|
|
||
| block update_app: | ||
| bytes user_address = Txn.Sender | ||
| assert(user_address == app_global_get(MANAGER_KEY)) | ||
| exit(1) | ||
| end | ||
|
|
||
| block main: | ||
| switch Txn.ApplicationArgs[0]: | ||
| "validate_transaction": validate_transaction | ||
| "validate_group": validate_group | ||
| end | ||
|
|
||
| block validate_transaction: | ||
|
|
||
| bytes proposal_id = Txn.ApplicationArgs[1] | ||
|
|
||
| # read proposal from proposal_voting app | ||
| inner_txn: | ||
| TypeEnum: Appl | ||
| ApplicationID: app_global_get(PROPOSAL_VOTING_APP_ID_KEY) | ||
| ApplicationArgs[0]: "get_proposal" | ||
| ApplicationArgs[1]: proposal_id | ||
| Fee: 0 | ||
| end | ||
|
|
||
| Proposal proposal = Cast(extract(4, 0, Itxn.LastLog), Proposal) | ||
|
|
||
| inner_txn: | ||
| TypeEnum: Appl | ||
| ApplicationID: app_global_get(PROPOSAL_VOTING_APP_ID_KEY) | ||
| ApplicationArgs[0]: "get_proposal_state" | ||
| ApplicationArgs[1]: proposal_id | ||
| Fee: 0 | ||
| end | ||
|
|
||
| int proposal_state = extract_uint64(Itxn.LastLog, 4) | ||
|
|
||
| # proposal checks | ||
| assert(proposal_state == PROPOSAL_STATE_SUCCEEDED) | ||
|
|
||
| # Assert Gtxn[1]'s transaction_id. | ||
| bytes execution_hash = Lpad(Gtxn[1].TxID, 128) | ||
| assert(execution_hash == proposal.execution_hash) | ||
|
gokselcoban marked this conversation as resolved.
|
||
|
|
||
| set_proposal_as_executed(proposal_id) | ||
| exit(1) | ||
| end | ||
|
|
||
| block validate_group: | ||
| bytes proposal_id = Txn.ApplicationArgs[1] | ||
|
|
||
| # read proposal from proposal_voting app | ||
| inner_txn: | ||
| TypeEnum: Appl | ||
| ApplicationID: app_global_get(PROPOSAL_VOTING_APP_ID_KEY) | ||
| ApplicationArgs[0]: "get_proposal" | ||
| ApplicationArgs[1]: proposal_id | ||
| Fee: 0 | ||
| end | ||
|
|
||
| Proposal proposal = Cast(extract(4, 0, Itxn.LastLog), Proposal) | ||
|
|
||
| inner_txn: | ||
| TypeEnum: Appl | ||
| ApplicationID: app_global_get(PROPOSAL_VOTING_APP_ID_KEY) | ||
| ApplicationArgs[0]: "get_proposal_state" | ||
| ApplicationArgs[1]: proposal_id | ||
| Fee: 0 | ||
| end | ||
|
|
||
| int proposal_state = extract_uint64(Itxn.LastLog, 4) | ||
|
|
||
| # proposal checks | ||
| assert(proposal_state == PROPOSAL_STATE_SUCCEEDED) | ||
|
|
||
| bytes execution_hash = Lpad(Global.GroupID, 128) | ||
| assert(execution_hash == proposal.execution_hash) | ||
|
|
||
| set_proposal_as_executed(proposal_id) | ||
| exit(1) | ||
| end | ||
| end | ||
|
|
||
| func set_proposal_as_executed(proposal_id: bytes): | ||
| inner_txn: | ||
| TypeEnum: Appl | ||
| ApplicationID: app_global_get(PROPOSAL_VOTING_APP_ID_KEY) | ||
| ApplicationArgs[0]: "execute_proposal" | ||
| ApplicationArgs[1]: proposal_id | ||
| Fee: 0 | ||
| end | ||
| return | ||
| end | ||
4 changes: 4 additions & 0 deletions
4
contracts/arbitrary_executor/arbitrary_executor_clear_state.tl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| #pragma version 8 | ||
| #tealish version git+https://github.com/Hipo/tealish.git@e8d1b27620220bc4e520d7d3b6d62523e13a7723 | ||
|
|
||
| exit(1) |
23 changes: 23 additions & 0 deletions
23
contracts/arbitrary_executor/arbitrary_executor_logic_signature.tl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #pragma version 8 | ||
| #tealish version git+https://github.com/Hipo/tealish.git@e8d1b27620220bc4e520d7d3b6d62523e13a7723 | ||
|
|
||
| # Assert that Gtxn[0] is an appcall to execution validator | ||
| assert(Gtxn[0].ApplicationID == 10000) | ||
|
|
||
| assert(Txn.GroupIndex == 1) | ||
|
|
||
| if Gtxn[0].ApplicationArgs[0] == "validate_transaction": | ||
| assert(Global.GroupSize == 2) | ||
| elif Gtxn[0].ApplicationArgs[0] == "validate_group": | ||
| assert(Global.GroupSize >= 2) | ||
| else: | ||
| exit(0) | ||
| end | ||
|
|
||
| # Assert that there is no rekeying | ||
| int start = 0 | ||
| int end = Global.GroupSize | ||
| for i in start:end: | ||
| assert(Gtxn[i].RekeyTo == Global.ZeroAddress) | ||
| end | ||
|
Comment on lines
+17
to
+22
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally, Governors should know the TXN fields before approving it. |
||
| exit(1) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.