test-maven-sdk
v1.0.3
Published
sdk to interact with echo safe smart contract
Downloads
24
Readme
Start a localnet and deploy contract
- Install SUI and add to path. Build SUI location.
yarn deps
If there is any issue regarding installation with rust, please check out the prerequisites and requirements in Sui official installation guide.
- Start SUI localnet
yarn localnet
- Clone ESafe repo
Clone ESafe
repository to directory ../ESafe
.
The repository need to be located at location ../ESafe
- Deploy ESafe smart contract
Go to Maven-SDK
, deploy ESafe contract to localnet.
yarn deploy
At the end of execution, two contract addresses are given:
contract address of ./move: 0x5691dd8cec80295b52817695a2c53598817332c276ae58d46bfc3643b1d64d05
global_pause of ./move: 0xcf540a9fa0da8ce7b15b6504f1e1668b731f727f002cfa0541a136e3c5223bf6
- Copy the addresses to SDK repo
The target contants is stored at src/constants/maven.ts
.
Both the address need to be replaced.
- Run tests to verify
yarn test
All tests shall pass.
=======
Doc
High Level Operations
Init
// implement a customized signer by using browser wallet
class WebSigner extends SignerProvider {}
// instantiate provider and clientt
const signerProvider = new WebSigner(CHAIN_ID);
const client = new TreasuryClient(signerProvider);
Create
//create a treasury with only one owner, which is the creator itself
const {treasury} = await client.create("Treasury")
CreateWithOwners
//create a treasury with two owners, the creator itself and account2
const account2 = await createKeypair();
const {treasury} = await client.createWithOwners("Test", [account2.getPublicKey().toSuiAddress()], 2, "");
//create from existing treasury
client.getTreasuryFromId("1", "2")
Treasury Information Read
//read the permissions of the treasury
await treasury.permissionBook()
//read the roles of the treasury
await treasury.roles()
//get the treasury owned coins
await treasury.ownedCoins()
//get all proposed transactions
await treasury.pendingTransactions()
//get treasury owners
await treasury.owners()
//get treasury threshold
await treasury.threshold()
DepositCoin
//deposit some amount of coin into the Treasury
await treasury.depositCoin(1000n, "0x02::sui::SUI");
//deposit multiple coins
await treasury.depositCoins([10n, 10n], ["0x02::sui::SUI", "dummyCoin"]);
TransferCoin
await treasury.proposeTransferCoin("0x02::sui::SUI", "0xreceiver", 1000n)
//transfer coins
await treasury.proposeTransferCoins([{coin: "dummyCoin", amount: 1n, receiver: "dummyReceiver"}])
DepositObject
//deposit object to treasury
await treasury.depositObject("1");
//depost multiple objects to treasury
await treasury.depositObjects([{objectId: "1"}])
TransferObject
//transfer object
await treasury.proposeTransferObject("id", "receiver");
//transfer multiple objects
await treasury.proposeTransferObjects([{id: "id", receiver: "receiver"}])
Simulation
//simulate single coin transfer
await treasury.transferCoin("dummyoin", "receiver", 100n, {simulation: true})
//simulate multiple coin transfer
await treasury.transferCoins([
{coin: "coin1", receiver: "receiver", amount: 1n},
{coin: "coin2", receiver: "receiver", amount: 1n},
], {simulation: true})
Update Threshold / Owners
await treasury.updateTreasury({addedOwners: ["a"], removedOwners: ["b"], threshold: 10})
Get wallet coins
// To be deprecated
await client.coinList()
Helper functions
await client.helper.coinList(address);
await client.helper.getBalance(owner, "0x2::sui::SUI");
await client.helper.getOwnedObjects(owner)
await client.helper.getCoinMeta(coinType);
await client.helper.isMavenAccount(mavenAddress);
await client.helper.isSuiAddress("0x123");