Skip to content

Commit

Permalink
fix some governance checks
Browse files Browse the repository at this point in the history
  • Loading branch information
MicroProofs committed Jul 2, 2024
1 parent 68f0675 commit 8864856
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 68 deletions.
2 changes: 1 addition & 1 deletion aiken.lock
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ requirements = []
source = "github"

[etags]
"aiken-lang/fuzz@main" = [{ secs_since_epoch = 1719790322, nanos_since_epoch = 181253000 }, "a8294651f1577c671d580c99c9bc5445ef1fd44e4aa3dde550434a4cbc8d50b6"]
"aiken-lang/fuzz@main" = [{ secs_since_epoch = 1719959323, nanos_since_epoch = 698487000 }, "a8294651f1577c671d580c99c9bc5445ef1fd44e4aa3dde550434a4cbc8d50b6"]
108 changes: 88 additions & 20 deletions miner/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ app
}

targetHash = await sha256(await sha256(targetState));

trie = await trie.insert(Buffer.from(blake256(targetHash)), Buffer.from(targetHash));
}

hashCounter++;
Expand Down Expand Up @@ -1287,11 +1289,14 @@ app
const provider = new Kupmios(kupoUrl, ogmiosUrl);
const lucid = await Lucid.new(provider, preview ? 'Preview' : 'Mainnet');

lucid.selectWalletFromSeed(fs.readFileSync('seed.txt', { encoding: 'utf-8' }));

const {
tunaV2MintValidator: {
validatorHash: tunav2ValidatorHash,
validatorAddress: tunav2ValidatorAddress,
},
forkValidator: { validatorAddress: forkValidatorAddress },
}: GenesisV2 = JSON.parse(
fs.readFileSync(`genesis/${preview ? 'previewV2' : 'mainnetV2'}.json`, {
encoding: 'utf8',
Expand Down Expand Up @@ -1321,31 +1326,94 @@ app

const spendNominateRedeemer = new Constr(2, []);

const setupTx = await lucid
.newTx()
.collectFrom([utxos[1]])
.payToContract(newSpendAddress, { inline: Data.to(0n) }, { lovelace: 1500000n })
.complete();
const antiScriptHash = toHex(
fromHex(newSpendHash).map((i) => {
return i ^ 0xff;
}),
);

const timeNow = Date.now() - 90000;

const spendOutputNominateDatum = new Constr(0, [
newSpendHash,
0n,
antiScriptHash,
0n,
// 20 minutes for testing
BigInt(timeNow + 1000 * 60 * 20),
]);

try {
console.log(newSpendAddress);
console.log(newSpendHash);

const setupTx = await lucid
.newTx()
.collectFrom([utxos[2]])
.payToContract(
newSpendAddress,
{ inline: Data.to(0n), scriptRef: newSpendScript },
{ lovelace: 50n },
)
.complete();
console.log('here');

const setupTxSigned = await setupTx.sign().complete();
const setupTxSigned = await setupTx.sign().complete();

await setupTxSigned.submit();
await setupTxSigned.submit();

lucid.awaitTx(setupTxSigned.toHash());
await lucid.awaitTx(setupTxSigned.toHash());

const contractUtxo = await lucid.utxosByOutRef([
{ txHash: setupTxSigned.toHash(), outputIndex: 0 },
]);
console.log(setupTxSigned.toHash());

const nominateTx = await lucid
.newTx()
.collectFrom(contractUtxo, Data.to(spendNominateRedeemer))
.mintAssets(
{ [tunav2ValidatorHash + fromText('NOMA') + newSpendHash]: 1n },
Data.to(mintNominateRedeemer),
)
.payToContract(address, outputData, assets)
.complete();
const contractUtxo = await lucid.utxosAt(newSpendAddress);

console.log(contractUtxo);
console.log('here2');

const readUtxos = await lucid.utxosAt(forkValidatorAddress);

const nominateTx = await lucid
.newTx()
.readFrom(readUtxos)
.collectFrom(contractUtxo, Data.to(spendNominateRedeemer))
.mintAssets(
{ [tunav2ValidatorHash + fromText('NOMA') + newSpendHash]: 1n },
Data.to(mintNominateRedeemer),
)
.payToContract(
tunav2ValidatorAddress,
{ inline: Data.to(spendOutputNominateDatum) },
{ [tunav2ValidatorHash + fromText('NOMA') + newSpendHash]: 1n },
)
.complete();

console.log('here3');

const nominateTxSigned = await nominateTx.sign().complete();

await nominateTxSigned.submit();

console.log(`Nominated new spending contract: ${newSpendHash}`);

await lucid.awaitTx(nominateTxSigned.toHash());

console.log(`Completed and saving governance file.`);

fs.writeFileSync(
`governance/${preview ? 'previewV2' : 'mainnetV2'}.json`,
JSON.stringify({
tunaV3SpendValidator: {
validator: newSpendScript,
validatorHash: newSpendHash,
validatorAddress: newSpendAddress,
},
}),
{ encoding: 'utf-8' },
);
} catch (e) {
console.log(e);
}
});

app.parse();
Loading

0 comments on commit 8864856

Please sign in to comment.