Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
Governance SDK: Create proposal test (#492)
Browse files Browse the repository at this point in the history
* chore: create test createRealmWithGovernanceAndProposal

* wip: use simple return

* chore: update spl-token version

* chore: upgrade @solana/spl-token to 0.1.3

* chore: fix compilation

* chore: fix build
  • Loading branch information
SebastianBor authored Jan 20, 2022
1 parent 281aeb3 commit c5f7cd1
Show file tree
Hide file tree
Showing 30 changed files with 343 additions and 165 deletions.
4 changes: 2 additions & 2 deletions packages/bridge-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"dependencies": {
"@babel/preset-typescript": "^7.13.0",
"@oyster/common": "0.0.2",
"@solana/spl-token": "0.0.13",
"@solana/spl-token": "0.1.3",
"@solana/spl-token-swap": "0.1.0",
"@solana/web3.js": "^1.22.0",
"bignumber.js": "^9.0.1",
Expand Down Expand Up @@ -80,4 +80,4 @@
"jest": "^27.4.7",
"prettier": "^2.1.2"
}
}
}
4 changes: 2 additions & 2 deletions packages/bridge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"@project-serum/serum": "^0.13.11",
"@react-three/drei": "^3.8.0",
"@solana/bridge-sdk": "0.0.1",
"@solana/spl-token": "0.0.13",
"@solana/spl-token": "0.1.3",
"@solana/spl-token-registry": "^0.2.0",
"@solana/spl-token-swap": "0.1.0",
"@solana/web3.js": "^1.22.0",
Expand Down Expand Up @@ -116,4 +116,4 @@
"react": "16.13.1",
"react-dom": "16.13.1"
}
}
}
4 changes: 2 additions & 2 deletions packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"dependencies": {
"@project-serum/serum": "^0.13.11",
"@solana/spl-token": "0.0.13",
"@solana/spl-token": "0.1.3",
"@solana/spl-token-swap": "0.1.0",
"@solana/wallet-adapter-base": "^0.6.0",
"@solana/wallet-adapter-react": "^0.12.6",
Expand Down Expand Up @@ -77,4 +77,4 @@
"react": "16.13.1",
"react-dom": "16.13.1"
}
}
}
1 change: 1 addition & 0 deletions packages/common/src/contexts/accounts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ function wrapNativeAccount(
pubkey: pubkey,
account,
info: {
address: pubkey,
mint: WRAPPED_SOL_MINT,
owner: pubkey,
amount: new u64(account.lamports),
Expand Down
25 changes: 12 additions & 13 deletions packages/common/src/contexts/connection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ interface ConnectionConfig {

const ConnectionContext = React.createContext<ConnectionConfig>({
endpoint: DEFAULT,
setEndpoint: () => {},
setEndpoint: () => { },
slippage: DEFAULT_SLIPPAGE,
setSlippage: (val: number) => {},
setSlippage: (val: number) => { },
connection: new Connection(DEFAULT, 'recent'),
sendConnection: new Connection(DEFAULT, 'recent'),
env: ENDPOINTS[0].name,
Expand Down Expand Up @@ -120,7 +120,7 @@ export function ConnectionProvider({ children = undefined as any }) {
.excludeByTag('nft')
.filterByChainId(
ENDPOINTS.find(end => end.endpoint === endpoint)?.ChainId ||
ChainId.MainnetBeta,
ChainId.MainnetBeta,
)
.getList();

Expand Down Expand Up @@ -153,7 +153,7 @@ export function ConnectionProvider({ children = undefined as any }) {
// is empty after opening its first time, preventing subsequent subscriptions from receiving responses.
// This is a hack to prevent the list from every getting empty
useEffect(() => {
const id = connection.onAccountChange(new Account().publicKey, () => {});
const id = connection.onAccountChange(new Account().publicKey, () => { });
return () => {
connection.removeAccountChangeListener(id);
};
Expand All @@ -169,7 +169,7 @@ export function ConnectionProvider({ children = undefined as any }) {
useEffect(() => {
const id = sendConnection.onAccountChange(
new Account().publicKey,
() => {},
() => { },
);
return () => {
sendConnection.removeAccountChangeListener(id);
Expand Down Expand Up @@ -270,7 +270,7 @@ export const sendTransactions = async (
signersSet: Account[][],
sequenceType: SequenceType = SequenceType.Parallel,
commitment: Commitment = 'singleGossip',
successCallback: (txid: string, ind: number) => void = (txid, ind) => {},
successCallback: (txid: string, ind: number) => void = (txid, ind) => { },
failCallback: (reason: string, ind: number) => boolean = (txid, ind) => false,
block?: BlockhashAndFeeCalculator,
): Promise<number> => {
Expand Down Expand Up @@ -382,7 +382,7 @@ export const sendTransaction = async (
try {
transaction = await wallet.signTransaction(transaction);
} catch (ex) {
throw new SignTransactionError(ex);
throw new SignTransactionError(JSON.stringify(ex));
}
}

Expand Down Expand Up @@ -415,11 +415,10 @@ export const sendTransaction = async (
console.error('getErrorForTransaction() error', ex);
}

if ('timeout' in confirmationStatus.err) {
if ('timeout' in (confirmationStatus.err as any)) {
notify({
message: `Transaction hasn't been confirmed within ${
DEFAULT_TIMEOUT / 1000
}s. Please check on Solana Explorer`,
message: `Transaction hasn't been confirmed within ${DEFAULT_TIMEOUT / 1000
}s. Please check on Solana Explorer`,
description: (
<>
<ExplorerLink
Expand Down Expand Up @@ -566,15 +565,15 @@ export async function sendSignedTransaction({

slot = confirmation?.slot || 0;
} catch (err) {
if (err.timeout) {
if ((err as any).timeout) {
throw new Error('Timed out awaiting confirmation on transaction');
}
let simulateResult: SimulatedTransactionResponse | null = null;
try {
simulateResult = (
await simulateTransaction(connection, signedTransaction, 'single')
).value;
} catch (e) {}
} catch (e) { }
if (simulateResult && simulateResult.err) {
if (simulateResult.logs) {
for (let i = simulateResult.logs.length - 1; i >= 0; --i) {
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/contracts/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export const mintNFT = async (
TOKEN_PROGRAM_ID,
mintAccount.publicKey,
null,
'MintTokens',
wallet.publicKey,
[],
),
Expand Down
7 changes: 4 additions & 3 deletions packages/governance-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@solana/spl-governance",
"version": "0.0.14",
"version": "0.0.15",
"description": "SPL Governance Client API",
"author": "Solana Maintainers <[email protected]>",
"homepage": "https://github.com/solana-labs/oyster/blob/main/packages/governance-sdk/README.md",
Expand Down Expand Up @@ -39,11 +39,12 @@
"esbuild": "^0.14.11",
"esbuild-jest": "^0.5.0",
"jest": "^27.4.7",
"typescript": "^4.5.4"
"typescript": "^4.5.4",
"@solana/spl-token": "0.1.3"
},
"jest": {
"transform": {
"^.+\\.tsx?$": "esbuild-jest"
}
}
}
}
11 changes: 8 additions & 3 deletions packages/governance-sdk/src/governance/serialisation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,14 @@ import { deserializeBorsh } from '../tools/borsh';
export const serializeInstructionToBase64 = (
instruction: TransactionInstruction,
) => {
let data = new InstructionData({
let data = createInstructionData(instruction);

return Buffer.from(serialize(GOVERNANCE_SCHEMA, data)).toString('base64');
};

// Converts TransactionInstruction to InstructionData format
export const createInstructionData = (instruction: TransactionInstruction) => {
return new InstructionData({
programId: instruction.programId,
data: instruction.data,
accounts: instruction.keys.map(
Expand All @@ -168,8 +175,6 @@ export const serializeInstructionToBase64 = (
}),
),
});

return Buffer.from(serialize(GOVERNANCE_SCHEMA, data)).toString('base64');
};

export const GOVERNANCE_SCHEMA_V1 = createGovernanceSchema(1);
Expand Down
2 changes: 1 addition & 1 deletion packages/governance-sdk/src/governance/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { withUpdateProgramMetadata } from './withUpdateProgramMetadata';
export async function getGovernanceProgramVersion(
connection: Connection,
programId: PublicKey,
env: string,
env?: string,
) {
// Try get program metadata
const programMetadataPk = await getProgramMetadataAddress(programId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const withCreateAccountGovernance = async (
payer: PublicKey,
governanceAuthority: PublicKey,
voterWeightRecord?: PublicKey,
): Promise<{ governanceAddress: PublicKey }> => {
) => {
const args = new CreateAccountGovernanceArgs({ config });
const data = Buffer.from(serialize(GOVERNANCE_SCHEMA, args));

Expand Down Expand Up @@ -86,5 +86,5 @@ export const withCreateAccountGovernance = async (
}),
);

return { governanceAddress };
return governanceAddress;
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { CreateMintGovernanceArgs } from './instructions';
import { TOKEN_PROGRAM_ID } from '../tools/sdk/splToken';
import { SYSTEM_PROGRAM_ID } from '../tools/sdk/runtime';
import { withVoterWeightAccounts } from './withVoterWeightAccounts';
import { GOVERNANCE_PROGRAM_SEED } from '.';

export const withCreateMintGovernance = async (
instructions: TransactionInstruction[],
Expand All @@ -23,14 +24,14 @@ export const withCreateMintGovernance = async (
payer: PublicKey,
governanceAuthority: PublicKey,
voterWeightRecord?: PublicKey,
): Promise<{ governanceAddress: PublicKey }> => {
) => {
const args = new CreateMintGovernanceArgs({
config,
transferMintAuthority,
});
const data = Buffer.from(serialize(GOVERNANCE_SCHEMA, args));

const [mintGovernanceAddress] = await PublicKey.findProgramAddress(
const [governanceAddress] = await PublicKey.findProgramAddress(
[Buffer.from('mint-governance'), realm.toBuffer(), governedMint.toBuffer()],
programId,
);
Expand All @@ -42,7 +43,7 @@ export const withCreateMintGovernance = async (
isSigner: false,
},
{
pubkey: mintGovernanceAddress,
pubkey: governanceAddress,
isWritable: true,
isSigner: false,
},
Expand Down Expand Up @@ -98,5 +99,5 @@ export const withCreateMintGovernance = async (
}),
);

return { governanceAddress: mintGovernanceAddress };
return governanceAddress;
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const withCreateProgramGovernance = async (
payer: PublicKey,
governanceAuthority: PublicKey,
voterWeightRecord?: PublicKey,
): Promise<{ governanceAddress: PublicKey }> => {
) => {
const args = new CreateProgramGovernanceArgs({
config,
transferUpgradeAuthority,
Expand Down Expand Up @@ -112,5 +112,5 @@ export const withCreateProgramGovernance = async (
}),
);

return { governanceAddress };
return governanceAddress;
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ export const withCreateTokenGovernance = async (
payer: PublicKey,
governanceAuthority: PublicKey,
voterWeightRecord?: PublicKey,
): Promise<{ governanceAddress: PublicKey }> => {
) => {
const args = new CreateTokenGovernanceArgs({
config,
transferTokenOwner,
});
const data = Buffer.from(serialize(GOVERNANCE_SCHEMA, args));

const [tokenGovernanceAddress] = await PublicKey.findProgramAddress(
const [governanceAddress] = await PublicKey.findProgramAddress(
[
Buffer.from('token-governance'),
realm.toBuffer(),
Expand All @@ -46,7 +46,7 @@ export const withCreateTokenGovernance = async (
isSigner: false,
},
{
pubkey: tokenGovernanceAddress,
pubkey: governanceAddress,
isWritable: true,
isSigner: false,
},
Expand Down Expand Up @@ -102,5 +102,5 @@ export const withCreateTokenGovernance = async (
}),
);

return { governanceAddress: tokenGovernanceAddress };
return governanceAddress;
};
Loading

1 comment on commit c5f7cd1

@vercel
Copy link

@vercel vercel bot commented on c5f7cd1 Jan 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.