deploy.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. import { Wallet, LCDClient, MnemonicKey } from "@terra-money/terra.js";
  2. import { StdFee, MsgInstantiateContract, MsgExecuteContract, MsgStoreCode } from "@terra-money/terra.js";
  3. import { readFileSync, readdirSync } from "fs";
  4. // TODO: Workaround /tx/estimate_fee errors.
  5. const gas_prices = {
  6. uluna: "0.15",
  7. usdr: "0.1018",
  8. uusd: "0.15",
  9. ukrw: "178.05",
  10. umnt: "431.6259",
  11. ueur: "0.125",
  12. ucny: "0.97",
  13. ujpy: "16",
  14. ugbp: "0.11",
  15. uinr: "11",
  16. ucad: "0.19",
  17. uchf: "0.13",
  18. uaud: "0.19",
  19. usgd: "0.2",
  20. };
  21. async function main() {
  22. const terra = new LCDClient({
  23. URL: "http://localhost:1317",
  24. chainID: "localterra",
  25. });
  26. const wallet = terra.wallet(
  27. new MnemonicKey({
  28. mnemonic:
  29. "notice oak worry limit wrap speak medal online prefer cluster roof addict wrist behave treat actual wasp year salad speed social layer crew genius",
  30. })
  31. );
  32. await wallet.sequence();
  33. // Deploy WASM blobs.
  34. const artifacts = readdirSync('../artifacts/');
  35. artifacts.sort();
  36. for (const artifact in artifacts) {
  37. console.log(artifact);
  38. console.log(artifacts.hasOwnProperty(artifact));
  39. if(artifacts.hasOwnProperty(artifact) && artifacts[artifact].includes('.wasm')) {
  40. const file = artifacts[artifact];
  41. const contract_bytes = readFileSync(`../artifacts/${file}`);
  42. console.log(`Storing Bytes, ${contract_bytes.length}, for ${file}`);
  43. const store_code = new MsgStoreCode(
  44. wallet.key.accAddress,
  45. contract_bytes.toString('base64'),
  46. );
  47. try {
  48. const tx = await wallet.createAndSignTx({
  49. msgs: [store_code],
  50. memo: '',
  51. fee: new StdFee(
  52. 3000000,
  53. { uluna: "100000" }
  54. )
  55. });
  56. const rs = await terra.tx.broadcast(tx);
  57. console.log(JSON.stringify(rs, null, 2));
  58. await wallet.sequence();
  59. } catch (e) {
  60. console.log('Failed to Execute');
  61. }
  62. }
  63. }
  64. const govChain = 1;
  65. const govAddress = "0000000000000000000000000000000000000000000000000000000000000004";
  66. //Instantiate Contracts
  67. wallet.createAndSignTx({
  68. msgs: [
  69. new MsgInstantiateContract(
  70. wallet.key.accAddress,
  71. undefined,
  72. 2,
  73. {
  74. gov_chain: govChain,
  75. gov_address: Buffer.from(govAddress, 'hex').toString('base64'),
  76. guardian_set_expirity: 86400,
  77. initial_guardian_set: {
  78. addresses: [
  79. {
  80. bytes: Buffer.from('beFA429d57cD18b7F8A4d91A2da9AB4AF05d0FBe', 'hex').toString('base64'),
  81. }
  82. ],
  83. expiration_time: 0
  84. },
  85. },
  86. )
  87. ],
  88. memo:'',
  89. })
  90. .then(tx => terra.tx.broadcast(tx))
  91. .then(rs => console.log(rs));
  92. wallet.createAndSignTx({
  93. msgs: [
  94. new MsgInstantiateContract(
  95. wallet.key.accAddress,
  96. undefined,
  97. 4,
  98. {
  99. owner: deployer.key.accAddress,
  100. gov_chain: govChain,
  101. gov_address: Buffer.from(govAddress, 'hex').toString('base64'),
  102. wormhole_contract: "",
  103. wrapped_asset_code_id: 2,
  104. },
  105. )
  106. ],
  107. memo:'',
  108. })
  109. .then(tx => terra.tx.broadcast(tx))
  110. .then(rs => console.log(rs));
  111. wallet.createAndSignTx({
  112. msgs: [
  113. new MsgInstantiateContract(
  114. wallet.key.accAddress,
  115. undefined,
  116. 3,
  117. {
  118. name: "MOCK",
  119. symbol: "MCK",
  120. decimals: 6,
  121. initial_balances: [
  122. {
  123. "address": deployer.key.acc_address,
  124. "amount": "100000000"
  125. }
  126. ],
  127. mint: null,
  128. },
  129. )
  130. ],
  131. memo:'',
  132. })
  133. .then(tx => terra.tx.broadcast(tx))
  134. .then(rs => console.log(rs));
  135. const registrations = [
  136. '01000000000100c9f4230109e378f7efc0605fb40f0e1869f2d82fda5b1dfad8a5a2dafee85e033d155c18641165a77a2db6a7afbf2745b458616cb59347e89ae0c7aa3e7cc2d400000000010000000100010000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000546f6b656e4272696467650100000001c69a1b1a65dd336bf1df6a77afb501fc25db7fc0938cb08595a9ef473265cb4f',
  137. '01000000000100e2e1975d14734206e7a23d90db48a6b5b6696df72675443293c6057dcb936bf224b5df67d32967adeb220d4fe3cb28be515be5608c74aab6adb31099a478db5c01000000010000000100010000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000546f6b656e42726964676501000000020000000000000000000000000290fb167208af455bb137780163b7b7a9a10c16'
  138. ];
  139. registrations.forEach(registration => {
  140. wallet.createAndSignTx({
  141. msgs: [
  142. new MsgExecuteContract(
  143. wallet.key.accAddress,
  144. "",
  145. {
  146. submit_vaa: {
  147. data: Buffer.from(registration, 'hex'),
  148. },
  149. },
  150. { uluna: 1000 }
  151. ),
  152. ],
  153. memo: '',
  154. })
  155. .then(tx => terra.tx.broadcast(tx))
  156. .then(rs => console.log(rs));
  157. });
  158. }
  159. main()