From 77763d94dd09336988f011f7ce7b2c58dfc13662 Mon Sep 17 00:00:00 2001 From: Josh Siegel Date: Tue, 27 Sep 2022 05:44:29 -0500 Subject: [PATCH] algo/cleanup: cleanup --- algorand/Makefile | 2 +- algorand/admin.py | 22 +++++++- algorand/teal/core_approve.teal | 49 ++++++++-------- algorand/teal/token_approve.teal | 35 ++++++------ algorand/test/whinfo.ts | 97 ++++++++++++++++++++++++++++++++ algorand/token_bridge.py | 21 +++++++ 6 files changed, 179 insertions(+), 47 deletions(-) create mode 100644 algorand/test/whinfo.ts diff --git a/algorand/Makefile b/algorand/Makefile index 8bb4386fb..ca07b1ff4 100644 --- a/algorand/Makefile +++ b/algorand/Makefile @@ -10,6 +10,6 @@ artifacts: @echo "Building artifacts for algorand" DOCKER_BUILDKIT=1 docker build -f Dockerfile.build -t algorand-builder -o type=local,dest=$@ . ../scripts/contract-upgrade-governance.sh -m token_bridge -c algorand -a `cat artifacts/token_approve.teal.hash` -o artifacts - ../scripts/contract-upgrade-governance.sh -m core -c algorand -a `cat artifacts/core_approve.teal.hash` -o artifacts + ../scripts/contract-upgrade-governance.sh -m core -c algorand -a `cat artifacts/core_approve.teal.hash` -o artifacts > artifacts/README.md diff --git a/algorand/admin.py b/algorand/admin.py index 7a35d7288..29bf02203 100644 --- a/algorand/admin.py +++ b/algorand/admin.py @@ -1312,12 +1312,27 @@ class PortalCore: print("complete") def updateToken(self) -> None: - approval, clear = get_token_bridge(False, self.args.token_approve, self.args.token_clear, self.client, seed_amt=self.seed_amt, tmpl_sig=self.tsig, devMode = self.devnet or self.args.testnet) + if self.args.approve == "" and self.args.clear == "": + approval, clear = get_token_bridge(False, self.args.token_approve, self.args.token_clear, self.client, seed_amt=self.seed_amt, tmpl_sig=self.tsig, devMode = self.devnet or self.args.testnet) + else: + pprint.pprint([self.args.approve, self.args.clear]) + with open(self.args.approve, encoding = 'utf-8') as f: + approval = {"result": f.readlines()[0]} + pprint.pprint(approval) + with open(self.args.clear, encoding = 'utf-8') as f: + clear = {"result": f.readlines()[0]} + pprint.pprint(clear) - print("token " + decode_address(approval["hash"]).hex()) +# print("token " + decode_address(approval["hash"]).hex()) print("Updating the token contracts: " + str(len(b64decode(approval["result"])))) + state = self.read_global_state(self.client, self.foundation.addr, self.tokenid) + pprint.pprint( { + "validUpdateApproveHash": b64decode(state["validUpdateApproveHash"]).hex(), + "validUpdateClearHash": b64decode(state["validUpdateClearHash"]).hex() + }) + txn = transaction.ApplicationUpdateTxn( index=self.tokenid, sender=self.foundation.getAddress(), @@ -1375,7 +1390,7 @@ class PortalCore: self.tokenid = 842126029 if self.args.coreid != 4: self.coreid = self.args.coreid - if self.args.coreid != 6: + if self.args.tokenid != 6: self.tokenid = self.args.tokenid def setup_args(self) -> None: @@ -1491,6 +1506,7 @@ class PortalCore: if args.devnet and self.foundation == None: print("Generating the foundation account...") self.foundation = self.getTemporaryAccount(self.client) + print("Foundation account: " + self.foundation.getMnemonic()) if self.args.fund: sys.exit(0) diff --git a/algorand/teal/core_approve.teal b/algorand/teal/core_approve.teal index 35334eb0a..8128d6873 100644 --- a/algorand/teal/core_approve.teal +++ b/algorand/teal/core_approve.teal @@ -1,6 +1,6 @@ #pragma version 6 intcblock 1 0 127 2 1000 86400 128 255 -bytecblock 0x 0x0008 0x677561726469616e 0x63757272656e74477561726469616e536574496e646578 0x6e6f70 0x76657269667953696773 0x4d657373616765466565 0x76616c6964557064617465417070726f766548617368 0x767068617368 0x766572696679564141 0x50726f6772616d 0x7075626c6973684d657373616765 0x0001 0x0000000000000000000000000000000000000000000000000000000000000004 0x00000000000000000000000000000000000000000000000000000000436f7265 0x0000 0x626f6f746564 0x76616c6964557064617465436c65617248617368 0x6d657461 +bytecblock 0x 0x0008 0x677561726469616e 0x63757272656e74477561726469616e536574496e646578 0x6e6f70 0x76657269667953696773 0x4d657373616765466565 0x76616c6964557064617465417070726f766548617368 0x767068617368 0x766572696679564141 0x7075626c6973684d657373616765 0x0001 0x0000000000000000000000000000000000000000000000000000000000000004 0x00000000000000000000000000000000000000000000000000000000436f7265 0x0000 0x626f6f746564 0x50726f6772616d 0x6d657461 txn ApplicationID intc_1 // 0 == @@ -24,7 +24,7 @@ bnz main_l6 err main_l6: txna ApplicationArgs 0 -bytec 11 // "publishMessage" +bytec 10 // "publishMessage" == bnz main_l69 txna ApplicationArgs 0 @@ -150,7 +150,7 @@ txna ApplicationArgs 1 load 21 intc_3 // 2 extract3 -bytec 12 // 0x0001 +bytec 11 // 0x0001 == assert txna ApplicationArgs 1 @@ -159,7 +159,7 @@ intc_3 // 2 + pushint 32 // 32 extract3 -bytec 13 // 0x0000000000000000000000000000000000000000000000000000000000000004 +bytec 12 // 0x0000000000000000000000000000000000000000000000000000000000000004 == assert load 21 @@ -170,7 +170,7 @@ txna ApplicationArgs 1 load 21 pushint 32 // 32 extract3 -bytec 14 // 0x00000000000000000000000000000000000000000000000000000000436f7265 +bytec 13 // 0x00000000000000000000000000000000000000000000000000000000436f7265 == assert load 21 @@ -280,7 +280,7 @@ load 28 bytec_1 // 0x0008 == load 28 -bytec 15 // 0x0000 +bytec 14 // 0x0000 == || assert @@ -701,12 +701,12 @@ txn Sender global CreatorAddress == assert -bytec 16 // "booted" +bytec 15 // "booted" app_global_get intc_1 // 0 == assert -bytec 16 // "booted" +bytec 15 // "booted" pushbytes 0x74727565 // "true" app_global_put callsub checkForDuplicate_11 @@ -730,7 +730,7 @@ txna ApplicationArgs 1 load 2 intc_3 // 2 extract3 -bytec 12 // 0x0001 +bytec 11 // 0x0001 == assert txna ApplicationArgs 1 @@ -739,7 +739,7 @@ intc_3 // 2 + pushint 32 // 32 extract3 -bytec 13 // 0x0000000000000000000000000000000000000000000000000000000000000004 +bytec 12 // 0x0000000000000000000000000000000000000000000000000000000000000004 == assert load 2 @@ -750,7 +750,7 @@ txna ApplicationArgs 1 load 2 pushint 32 // 32 extract3 -bytec 14 // 0x00000000000000000000000000000000000000000000000000000000436f7265 +bytec 13 // 0x00000000000000000000000000000000000000000000000000000000436f7265 == assert load 2 @@ -858,7 +858,7 @@ load 9 bytec_1 // 0x0008 == load 9 -bytec 15 // 0x0000 +bytec 14 // 0x0000 == || assert @@ -1004,7 +1004,7 @@ pop load 0 log intc_0 // 1 -bytec 11 // "publishMessage" +bytec 10 // "publishMessage" callsub meta_5 intc_0 // 1 return @@ -1045,7 +1045,7 @@ main_l73: intc_1 // 0 return main_l74: -bytec 10 // "Program" +bytec 16 // "Program" txn ApprovalProgram concat sha512_256 @@ -1053,13 +1053,15 @@ bytec 7 // "validUpdateApproveHash" app_global_get == assert -bytec 10 // "Program" txn ClearStateProgram -concat -sha512_256 -bytec 17 // "validUpdateClearHash" -app_global_get +len +pushint 4 // 4 == +txn ClearStateProgram +extract 1 3 +pushbytes 0x810143 // 0x810143 +== +&& assert intc_0 // 1 return @@ -1076,9 +1078,6 @@ app_global_put bytec 7 // "validUpdateApproveHash" bytec_0 // "" app_global_put -bytec 17 // "validUpdateClearHash" -pushbytes 0x73be5fd7cd378289177bf4a7ca5433ab30d91b417381bba8bd704aff2dec424f // 0x73be5fd7cd378289177bf4a7ca5433ab30d91b417381bba8bd704aff2dec424f -app_global_put intc_0 // 1 return @@ -1218,7 +1217,7 @@ retsub // meta meta_5: store 37 -bytec 18 // "meta" +bytec 17 // "meta" load 37 app_local_put retsub @@ -1226,7 +1225,7 @@ retsub // checkMeta checkMeta_6: store 38 -bytec 18 // "meta" +bytec 17 // "meta" app_local_get load 38 == @@ -1390,7 +1389,7 @@ retsub getsigaddress_9: store 48 store 47 -bytec 10 // "Program" +bytec 16 // "Program" pushbytes 0x0620010181 // 0x0620010181 concat load 47 diff --git a/algorand/teal/token_approve.teal b/algorand/teal/token_approve.teal index 952342bd6..1a6713e14 100644 --- a/algorand/teal/token_approve.teal +++ b/algorand/teal/token_approve.teal @@ -1,6 +1,6 @@ #pragma version 6 intcblock 0 1 2 127 133 128 255 -bytecblock 0x 0x636f72656964 0x436861696e 0x6e6174697665 0x7075626c6973684d657373616765 0x6e6f70 0x766572696679564141 0x0008 0x76616c6964557064617465417070726f766548617368 0x50726f6772616d 0x414c474f 0x76616c6964557064617465436c65617248617368 0x636f726541646472 +bytecblock 0x 0x636f72656964 0x436861696e 0x6e6174697665 0x7075626c6973684d657373616765 0x6e6f70 0x766572696679564141 0x0008 0x76616c6964557064617465417070726f766548617368 0x414c474f 0x50726f6772616d 0x636f726541646472 txn ApplicationID intc_0 // 0 == @@ -1137,9 +1137,9 @@ b main_l63 main_l67: pushbytes 0x06 // 0x06 store 35 -bytec 10 // "ALGO" +bytec 9 // "ALGO" store 36 -bytec 10 // "ALGO" +bytec 9 // "ALGO" store 37 b main_l64 main_l68: @@ -1509,7 +1509,7 @@ load 30 itxn_field ConfigAssetName load 29 itxn_field ConfigAssetUnitName -pushint 18446744073709551614 // 18446744073709551614 +pushint 18446744073709550000 // 18446744073709550000 itxn_field ConfigAssetTotal load 28 itxn_field ConfigAssetDecimals @@ -1517,9 +1517,9 @@ global CurrentApplicationAddress itxn_field ConfigAssetManager txna Accounts 3 itxn_field ConfigAssetReserve -global ZeroAddress +global CurrentApplicationAddress itxn_field ConfigAssetFreeze -global ZeroAddress +global CurrentApplicationAddress itxn_field ConfigAssetClawback intc_0 // 0 itxn_field Fee @@ -1555,7 +1555,7 @@ main_l79: intc_0 // 0 return main_l80: -bytec 9 // "Program" +bytec 10 // "Program" txn ApprovalProgram concat sha512_256 @@ -1563,13 +1563,15 @@ bytec 8 // "validUpdateApproveHash" app_global_get == assert -bytec 9 // "Program" txn ClearStateProgram -concat -sha512_256 -bytec 11 // "validUpdateClearHash" -app_global_get +len +pushint 4 // 4 == +txn ClearStateProgram +extract 1 3 +pushbytes 0x810143 // 0x810143 +== +&& assert intc_1 // 1 return @@ -1578,15 +1580,12 @@ bytec_1 // "coreid" txna ApplicationArgs 0 btoi app_global_put -bytec 12 // "coreAddr" +bytec 11 // "coreAddr" txna ApplicationArgs 1 app_global_put bytec 8 // "validUpdateApproveHash" bytec_0 // "" app_global_put -bytec 11 // "validUpdateClearHash" -pushbytes 0x73be5fd7cd378289177bf4a7ca5433ab30d91b417381bba8bd704aff2dec424f // 0x73be5fd7cd378289177bf4a7ca5433ab30d91b417381bba8bd704aff2dec424f -app_global_put intc_1 // 1 return @@ -1942,7 +1941,7 @@ intc_0 // 0 bz sendMfee_11_l2 intc_1 // pay itxn_field TypeEnum -bytec 12 // "coreAddr" +bytec 11 // "coreAddr" app_global_get itxn_field Receiver load 23 @@ -2067,7 +2066,7 @@ retsub getsigaddress_15: store 82 store 81 -bytec 9 // "Program" +bytec 10 // "Program" pushbytes 0x0620010181 // 0x0620010181 concat load 81 diff --git a/algorand/test/whinfo.ts b/algorand/test/whinfo.ts new file mode 100644 index 000000000..f5fe52b86 --- /dev/null +++ b/algorand/test/whinfo.ts @@ -0,0 +1,97 @@ +const algosdk = require("@certusone/wormhole-sdk/node_modules/algosdk"); + +import { calcLogicSigAccount } from "@certusone/wormhole-sdk/lib/cjs/algorand"; + +export async function getNativeAlgoAddress( + algoClient: any, + token_bridge: any, + assetId: any +) { + const { doesExist, lsa } = await calcLogicSigAccount( + algoClient, + BigInt(token_bridge), + BigInt(assetId), + Buffer.from("native", "binary").toString("hex") + ); + return lsa.address(); +} + +async function firstTransaction() { + let algodToken; + let algodServer; + let algodPort; + let server; + let port; + let token; + let appid; + + const mainnet = true; + + if (mainnet) { + appid = 842126029; + algodToken = ""; + algodServer = "https://mainnet-api.algonode.cloud"; + algodPort = 443; + server = "https://mainnet-idx.algonode.cloud"; + port = 443; + token = ""; + } else { + appid = 6; + algodToken = + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; + algodServer = "http://localhost"; + algodPort = 4001; + server = "http://localhost"; + port = 8980; + token = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; + } + + let algodClient = new algosdk.Algodv2(algodToken, algodServer, algodPort); + let indexerClient = new algosdk.Indexer(token, server, port); + let addr = algosdk.getApplicationAddress(appid); // mainnet token bridge account + + let ret = await indexerClient + .searchAccounts() + .authAddr(addr) + .applicationID(appid) + .do(); + + let wormholeAssets: any = []; + let nativeAssets: any = []; + + while (true) { + ret["accounts"].forEach((x: any) => { + let amt = x["amount"]; + if (x["assets"] != undefined) { + x["assets"].forEach((a: any) => { + if (x["created-assets"] != undefined) { + wormholeAssets.push(a); + } else { + nativeAssets.push(a); + } + }); + } + }); + if (ret["next-token"] == undefined) { + break; + } + ret = await indexerClient + .searchAccounts() + .authAddr(addr) + .applicationID(appid) + .nextToken(ret["next-token"]) + .do(); + } + + console.log("wormhole assets"); + for (let i = 0; i < wormholeAssets.length; i++) { + let assetId = wormholeAssets[i]["asset-id"]; + let assetInfo = await algodClient.getAssetByID(assetId).do(); + let acctInfo = await algodClient.accountInformation(assetInfo["params"]["creator"]).do(); + + console.log(assetId, assetInfo, acctInfo); + + } +} + +firstTransaction(); diff --git a/algorand/token_bridge.py b/algorand/token_bridge.py index 9707578a1..829af4023 100644 --- a/algorand/token_bridge.py +++ b/algorand/token_bridge.py @@ -293,6 +293,27 @@ def approve_token_bridge(seed_amt: int, tmpl_sig: TmplSig, devMode: bool): Approve() ]) + +# # This blows up an asset on algorand. This will be added temporarily (and then removed) to clean some stuff before we relaunch +# def killAsset(): +# return Seq([ +# MagicAssert(Txn.sender() == Global.creator_address()), +# +# blob.zero(Int(1)), +# +# InnerTxnBuilder.Begin(), +# InnerTxnBuilder.SetFields( +# { +# TxnField.sender: Global.current_application_address(), +# TxnField.type_enum: TxnType.AssetConfig, +# TxnField.config_asset: Btoi(Txn.application_args[1]), +# TxnField.fee: Int(0), +# } +# ), +# InnerTxnBuilder.Submit(), +# +# Approve() +# ]) def receiveAttest(): me = Global.current_application_address()