From 1fad24fe0c9fe1756e988e6e78e415827887fe89 Mon Sep 17 00:00:00 2001 From: mootz12 Date: Tue, 26 Mar 2024 13:11:27 -0400 Subject: [PATCH] chore: add missing vote functions and fix misc bugs --- package-lock.json | 4 ++-- package.json | 2 +- src/governor.ts | 4 ++-- src/votes.ts | 45 ++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 49 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index b587361..9aeba02 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "soroban-governor-js-sdk", - "version": "0.4.0", + "version": "0.5.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "soroban-governor-js-sdk", - "version": "0.4.0", + "version": "0.5.0", "dependencies": { "@stellar/freighter-api": "1.7.1", "@stellar/stellar-sdk": "11.2.2", diff --git a/package.json b/package.json index 481142b..4304c8c 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "0.4.0", + "version": "0.5.0", "name": "soroban-governor-js-sdk", "dependencies": { "@stellar/freighter-api": "1.7.1", diff --git a/src/governor.ts b/src/governor.ts index b127399..dc328b4 100644 --- a/src/governor.ts +++ b/src/governor.ts @@ -256,7 +256,7 @@ export enum ProposalStatus { } export class GovernorContract extends Contract { - static readonly spec = new ContractSpec([ + static spec = new ContractSpec([ "AAAAAAAAAAAAAAAKaW5pdGlhbGl6ZQAAAAAAAgAAAAAAAAAFdm90ZXMAAAAAAAATAAAAAAAAAAhzZXR0aW5ncwAAB9AAAAAQR292ZXJub3JTZXR0aW5ncwAAAAA=", "AAAAAAAAAAAAAAAIc2V0dGluZ3MAAAAAAAAAAQAAB9AAAAAQR292ZXJub3JTZXR0aW5ncw==", "AAAAAAAAAAAAAAAHcHJvcG9zZQAAAAAEAAAAAAAAAAdjcmVhdG9yAAAAABMAAAAAAAAABXRpdGxlAAAAAAAAEAAAAAAAAAALZGVzY3JpcHRpb24AAAAAEAAAAAAAAAAGYWN0aW9uAAAAAA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ZAAAAAADAAAAHlRoZSBwcm9wb3NhbCBoYXMgYmVlbiBleGVjdXRlZAAAAAAACEV4ZWN1dGVkAAAABAAAAB5UaGUgcHJvcG9zYWwgaGFzIGJlZW4gY2FuY2VsZWQAAAAAAAhDYW5jZWxlZAAAAAU=", + "AAAAAwAAAAAAAAAAAAAADlByb3Bvc2FsU3RhdHVzAAAAAAAGAAAAMlRoZSBwcm9wb3NhbCBleGlzdHMgYW5kIHZvdGluZyBoYXMgbm90IGJlZW4gY2xvc2VkAAAAAAAET3BlbgAAAAAAAABqVGhlIHByb3Bvc2FsIHdhcyB2b3RlZCBmb3IuIElmIHRoZSBwcm9wb3NhbCBpcyBleGVjdXRhYmxlLCB0aGUgdGltZWxvY2sgYmVnaW5zIG9uY2UgdGhpcyBzdGF0ZSBpcyByZWFjaGVkLgAAAAAAClN1Y2Nlc3NmdWwAAAAAAAEAAAAeVGhlIHByb3Bvc2FsIHdhcyB2b3RlZCBhZ2FpbnN0AAAAAAAIRGVmZWF0ZWQAAAACAAAAbVRoZSBwcm9wb3NhbCBkaWQgbm90IHJlYWNoIHF1b3J1bSBiZWZvcmUgdGhlIHZvdGluZyBwZXJpb2QgZW5kZWQsIG9yIHdhcyBzdGFsbGVkIG91dCBkdXJpbmcgdGhlIGdyYWNlIHBlcmlvZC4AAAAAAAAHRXhwaXJlZAAAAAADAAAAHlRoZSBwcm9wb3NhbCBoYXMgYmVlbiBleGVjdXRlZAAAAAAACEV4ZWN1dGVkAAAABAAAAB5UaGUgcHJvcG9zYWwgaGFzIGJlZW4gY2FuY2VsZWQAAAAAAAhDYW5jZWxlZAAAAAU=", ]); static readonly parsers = { diff --git a/src/votes.ts b/src/votes.ts index 62f37d2..d7e2316 100644 --- a/src/votes.ts +++ b/src/votes.ts @@ -215,6 +215,8 @@ export class StakingVotesContract extends Contract { ...StakingVotesContract.spec.funcArgsToScVals("initialize", { token: new Address(token), governor: new Address(governor), + name, + symbol, }) ).toXDR("base64"); } @@ -334,7 +336,7 @@ export class StakingVotesContract extends Contract { */ withdraw({ from, amount }: { from: string; amount: i128 }): string { return this.call( - "withdraw_to", + "withdraw", ...StakingVotesContract.spec.funcArgsToScVals("withdraw", { from: new Address(from), amount, @@ -756,4 +758,45 @@ export class TokenVotesContract extends Contract { }) ).toXDR("base64"); } + + /** + * Construct a mint operation + * @param to The address of the account to mint to + * @param amount The amount of tokens to mint + * @returns A base64 XDR string of the operation + */ + mint({ to, amount }: { to: string; amount: i128 }): string { + return this.call( + "mint", + ...TokenVotesContract.spec.funcArgsToScVals("mint", { + to: new Address(to), + amount, + }) + ).toXDR("base64"); + } + + /** + * Construct a set_admin operation + * @param new_admin The address of the account to set the admin as + * @returns A base64 XDR string of the operation + */ + setAdmin({ new_admin }: { new_admin: string }): string { + return this.call( + "set_admin", + ...TokenVotesContract.spec.funcArgsToScVals("set_admin", { + new_admin: new Address(new_admin), + }) + ).toXDR("base64"); + } + + /** + * Construct a get admin operation (READ ONLY: Operation should only be simulated) + * @returns A base64 XDR string of the operation + */ + admin(): string { + return this.call( + "admin", + ...TokenVotesContract.spec.funcArgsToScVals("admin", {}) + ).toXDR("base64"); + } }