Snowflake Safe SDK - Interact with multisig wallets on Snowflake Safe
npm install @snowflake-so/safe-sdkSnowflake Safe SDK provides an easy way to interact with the Snowflake Safe app and onchain programs
Install with npm
``bash`
npm i @snowflake-so/safe-sdk
Install with yarn
`bash`
yarn add @snowflake-so/safe-sdk
To create a new Snowflake service, we would need to initialize with the Provider.
`typescript
// if your Anchor version is older than 0.24.2,
// please use Snowflake SDK version 1.0.11 and initialize the provider as below
let provider: Provider = Provider.local(API_URL);
// if your Anchor version is 0.24.2 or later,
// please use the latest version of Snowflake SDK and initialize the provider as below
let provider: Provider = AnchorProvider.local(API_URL);
`
The API_URL is the endpoint to the Solana cluster. Empty API_URL is pointed to the local testnet
- Mainnet Beta: https://api.mainnet-beta.solana.comhttps://api.testnet.solana.com
- Testnet: https://api.devnet.solana.com
- Devnet:
`typescript`
let snowflakeSafe: SnowflakeSafe = new SnowflakeSafe(provider);
---
Fetch safe onchain information by safe address
`typescript`
await snowflakeSafe.fetchSafe(safeAddress);
Fetch all onchain proposals of the safe
`typescript`
await snowflakeSafe.fetchAllProposals(safeAddress);
Fetch onchain proposal information
`typescript`
await snowflakeSafe.fetchProposal(proposalAddress);
Fetch all safes that the provided wallet owned
`typescript`
await snowflakeSafe.fetchOwnedSafes(ownerAddress);
---
Create a new safe with one owner and approvals required as one
`typescript`
const input = {
approvalsRequired: 1,
owners: [owner],
};
const [newSafeAddress, txId] = await snowflakeSafe.createSafe(
input.owners,
input.approvalsRequired
);
Create a new proposal that can be executed by any safe owners
`typescript`
const response = await snowflakeSafe.createProposal(safeAddress, 'hello world', instructions);
Create a new recurring proposal that can be executed automatically by Snowflake node operators
`typescript
const proposal = new MultisigJobBuilder()
.jobName('hello world')
.jobInstructions(instructions)
.scheduleCron('0 0 *')
.build();
const [newProposalAddress, txId] = await snowflakeSafe.createRecurringProposal(
safeAddress,
proposal
);
`
In production, there is proposal created with multiple actions which has bunches of accounts. This method is used to solve the issue
`typescript`
const [newProposalAddress] = await snowflakeSafe.createProposal(
safeAddress,
'hello world',
instructions,
[],
DEFAULT_FLOW_SIZE,
true,
true // Set separatedActions parameter to true
);
#### Add owner proposal
The method will create a new instruction to propose adding new owner to the safe
`typescript`
const ix = await snowflakeSafe.createAddOwnerProposalInstruction(safeAddress, newOwner);
#### Remove owner proposal
The method will create a new instruction to propose removing an existing owner from the safe
`typescript`
const ix = await snowflakeSafe.createRemoveOwnerProposalInstruction(safeAddress, newOwner);
#### Change threshold proposal
The method will create a new instruction to propose changing threshold of the safe
`typescript`
const ix = await snowflakeSafe.createChangeThresholdProposalInstruction(safeAddress, newThreshold);
`typescript`
await snowflakeSafe.approveProposal(flowAddress);
`typescript`
await snowflakeSafe.rejectProposal(flowAddress);
`typescript`
await snowflakeSafe.executeProposal(flowAddress);
`typescript`
await snowflakeSafe.abortRecurringProposal(flowAddress);
---
With Snowflake SDK, you can create a job with two line of code.
`typescript`
const job = new MultisigJobBuilder()
.jobName('hello world')
.jobInstructions(instructions)
.scheduleOnce(tomorrow())
.build();
Schedule a job that runs every minute for 10 times.
`typescript`
const job = new MultisigJobBuilder()
.jobName('hello world')
.jobInstructions(instructions)
.scheduleCron(' *', 10)
.build();
Schedule a job that runs at 10:00 AM on the first day of every month .
`typescript`
const job = new MultisigJobBuilder()
.jobName('hello world')
.jobInstructions(instructions)
.scheduleCron('0 10 1 ')
.build();
Schedule a job that is triggered based on an arbitrary condition defined within the user program.
`typescript``
const job = new MultisigJobBuilder()
.jobName('hello world')
.jobInstructions(instructions)
.scheduleConditional(1)
.build();
If you have any problem with using the SDK in your system, drop a question our Snowflake Discord #sdk to receive a support from our engineers.
If you find a bug or have any problem and idea while using the SDK, you can create an issue on SDK Github.
Apache Version 2.0