Skip to content

Commit

Permalink
Merge pull request #44 from orcaprotocol/willkim/test-scripts
Browse files Browse the repository at this point in the history
fix: update super/sub proposal logic, add test scripts
  • Loading branch information
Will Kim authored May 10, 2022
2 parents 132df94 + 6d297db commit d491ab1
Show file tree
Hide file tree
Showing 20 changed files with 922 additions and 167 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ test
dist
jest.config.ts
docs
scripts
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
.nvmrc
dist
env.json
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,7 @@ import { Pod, Proposal } from '@orcaprotocol/orca-sdk';
### Additional Documentation

Additional documentation can be found [here](https://orcaprotocol.github.io/orca-sdk/)

## Test Scripts

We have some test scripts to test approve/reject proposals and super proposals. They can be executed by duplicating the `env-examples.json` with private keys in `env.json`, and executing the transactions with `npx ts-node ./scripts/reject-superproposal.ts`.
9 changes: 9 additions & 0 deletions env-example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"accountOne": "0xf0C7d25c942264D6F21871c05d3dB3b98344b499",
"accountOnePrivateKey": "",
"accountTwo": "0xA56b297065D814988080b8E765D953651059539c",
"accountTwoPrivateKey": "",
"dummyAccount": "0x1cC62cE7cb56ed99513823064295761f9b7C856e",
"adminPodAddress": "0xBe71ECaA104645ab78ed62A52763b2854e6DaD2E",
"subPodAddress": "0x4d3ba1AdabA15796CC3d11E48e8EC28e3A5F7C41"
}
80 changes: 32 additions & 48 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"babel-jest": "^27.4.6",
"cod-scripts": "^10.0.0",
"jest": "^27.4.7",
"ts-node": "^10.7.0",
"typedoc": "^0.22.15"
},
"dependencies": {
Expand Down
40 changes: 40 additions & 0 deletions scripts/approve-proposal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { getPod } from '../src';
import { adminPodAddress, dummyAccount } from '../env.json';
import { setup, sleep } from './utils';

async function main() {
const { walletOne, walletTwo } = setup();

// Get the pod we're working with

const pod = await getPod(adminPodAddress);

if ((await pod.getProposals({ queued: true }))[0].status !== 'executed') {
throw new Error(
'Super pod had an active/queued transaction. This script expects no enqueued transactions',
);
}

// We mint/burn the dummy account based on whether its a member or not.
const isMember = await pod.isMember(dummyAccount);
if (isMember) {
await pod.proposeBurnMember(dummyAccount, walletOne);
} else {
await pod.proposeMintMember(dummyAccount, walletOne);
}

const proposal = (await pod.getProposals())[0];

await proposal.approve(walletTwo);
await proposal.executeApprove(walletTwo);

// Let gnosis catch up.
await sleep(5000);

if (proposal.status !== 'executed') throw new Error('Proposal status not right');
const refetchProposal = (await pod.getProposals())[0];
if (!refetchProposal.safeTransaction.isExecuted)
throw new Error('Proposal not executed according to gnosis');
}

main();
67 changes: 67 additions & 0 deletions scripts/approve-superproposal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/* eslint-disable no-console */
import { getPod } from '../src';
import { adminPodAddress, dummyAccount, subPodAddress, subPodTwoAddress } from '../env.json';
import { setup, sleep } from './utils';

async function main() {
const { walletOne, walletTwo } = setup();

const superPod = await getPod(adminPodAddress);
const subPod = await getPod(subPodAddress);
const subPodTwo = await getPod(subPodTwoAddress);

if (
(await superPod.getProposals({ queued: true }))[0].status !== 'executed' ||
(await subPod.getProposals({ queued: true }))[0].status !== 'executed' ||
(await subPodTwo.getProposals({ queued: true }))[0].status !== 'executed'
) {
throw new Error(
'Admin or sub pod had an active/queued transaction. This script expects no enqueued transactions',
);
}

// We mint/burn the dummy account based on whether its a member or not.
const isMember = await superPod.isMember(dummyAccount);
console.log('Creating super proposal + sub proposal on subPod');
try {
if (isMember) {
await superPod.proposeBurnMemberFromPod(subPod, dummyAccount, walletOne);
} else {
await superPod.proposeMintMemberFromPod(subPod, dummyAccount, walletOne);
}
} catch (err) {
console.log(err);
throw new Error('Error creating proposal on subpod');
}

await sleep(5000);

let [superProposal] = await superPod.getProposals();
if (superProposal.status !== 'active') {
await sleep(5000);
[superProposal] = await superPod.getProposals();
}

console.log('Approving super proposal from sub pod two');
await superProposal.approveFromSubPod(subPodTwo, walletOne);
await sleep(5000);

console.log('Executing both sub proposals');
const subProposal = (await subPod.getProposals())[0];
await subProposal.executeApprove(walletOne);

const subProposalTwo = (await subPodTwo.getProposals())[0];
await subProposalTwo.executeApprove(walletOne);

console.log('Letting the blockchain + transaction service catch up');
await sleep(40000);

console.log('Approving + executing superproposal');
[superProposal] = await superPod.getProposals();
await superProposal.executeApprove(walletOne);

console.log('We did it! 🎉');
console.log('At least I think so. Check the pod page to be sure lol');
}

main();
Loading

0 comments on commit d491ab1

Please sign in to comment.