-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apply the changes of lbm v0.4.0-rc1 (#25)
* feat: apply lbm-sdk v0.46.0-rc1 - add `x/foundation` module Signed-off-by: zemyblue <zemyblue@gmail.com> * chore: change the version to `0.4.0-rc2`. Signed-off-by: zemyblue <zemyblue@gmail.com> * fix: fix faucet docker bug of issue #24. Signed-off-by: zemyblue <zemyblue@gmail.com> * feat: add x/foundation unittest and tx encodeObject. Signed-off-by: zemyblue <zemyblue@gmail.com> * feat: add `UpdateDecisionPolicy` unittest Signed-off-by: zemyblue <zemyblue@gmail.com>
- Loading branch information
Showing
18 changed files
with
557 additions
and
35 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
.yarn/cache/lbmjs-types-npm-0.46.0-rc1-85a2c1c7cb-72ca870440.zip
This file was deleted.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
.yarn/cache/lbmjs-types-npm-0.46.0-rc2-d0ca857389-07b1125ff6.zip
Git LFS file not shown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
import { Decimal } from "@cosmjs/math"; | ||
import { EncodeObject, GeneratedType } from "@lbmjs/proto-signing/build"; | ||
import { Duration } from "lbmjs-types/google/protobuf/duration"; | ||
import { Coin } from "lbmjs-types/lbm/base/v1/coin"; | ||
import { ReceiveFromTreasuryAuthorization } from "lbmjs-types/lbm/foundation/v1/authz"; | ||
import { | ||
DecisionPolicyWindows, | ||
Member, | ||
PercentageDecisionPolicy, | ||
ThresholdDecisionPolicy, | ||
} from "lbmjs-types/lbm/foundation/v1/foundation"; | ||
import { | ||
Exec, | ||
MsgExec, | ||
MsgFundTreasury, | ||
MsgGrant, | ||
MsgLeaveFoundation, | ||
MsgRevoke, | ||
MsgSubmitProposal, | ||
MsgUpdateDecisionPolicy, | ||
MsgUpdateMembers, | ||
MsgVote, | ||
MsgWithdrawFromTreasury, | ||
MsgWithdrawProposal, | ||
} from "lbmjs-types/lbm/foundation/v1/tx"; | ||
|
||
import { longify } from "../../queryclient"; | ||
|
||
export const foundationTypes: ReadonlyArray<[string, GeneratedType]> = [ | ||
["/lbm.foundation.v1.MsgFundTreasury", MsgFundTreasury], | ||
["/lbm.foundation.v1.MsgWithdrawFromTreasury", MsgWithdrawFromTreasury], | ||
["/lbm.foundation.v1.MsgUpdateMembers", MsgUpdateMembers], | ||
["/lbm.foundation.v1.MsgUpdateDecisionPolicy", MsgUpdateDecisionPolicy], | ||
["/lbm.foundation.v1.MsgSubmitProposal", MsgSubmitProposal], | ||
["/lbm.foundation.v1.MsgWithdrawProposal", MsgWithdrawProposal], | ||
["/lbm.foundation.v1.MsgVote", MsgVote], | ||
["/lbm.foundation.v1.MsgExec", MsgExec], | ||
["/lbm.foundation.v1.MsgLeaveFoundation", MsgLeaveFoundation], | ||
["/lbm.foundation.v1.MsgGrant", MsgGrant], | ||
["/lbm.foundation.v1.MsgRevoke", MsgRevoke], | ||
["/lbm.foundation.v1.ReceiveFromTreasuryAuthorization", ReceiveFromTreasuryAuthorization], | ||
["/lbm.foundation.v1.DecisionPolicyWindows", DecisionPolicyWindows], | ||
["/lbm.foundation.v1.ThresholdDecisionPolicy", ThresholdDecisionPolicy], | ||
["/lbm.foundation.v1.PercentageDecisionPolicy", PercentageDecisionPolicy], | ||
]; | ||
|
||
export function createMsgSubmitProposal( | ||
proposers: string[], | ||
messages: EncodeObject[], | ||
metadata = "", | ||
exec: Exec = Exec.EXEC_TRY, | ||
): EncodeObject { | ||
return { | ||
typeUrl: "/lbm.foundation.v1.MsgSubmitProposal", | ||
value: { | ||
proposers: proposers, | ||
metadata: metadata, | ||
messages: messages, | ||
exec: exec, | ||
}, | ||
}; | ||
} | ||
|
||
export function createMsgGrant(operator: string, grantee: string): EncodeObject { | ||
return { | ||
typeUrl: "/lbm.foundation.v1.MsgGrant", | ||
value: Uint8Array.from( | ||
MsgGrant.encode({ | ||
operator: operator, | ||
grantee: grantee, | ||
authorization: { | ||
typeUrl: "/lbm.foundation.v1.ReceiveFromTreasuryAuthorization", | ||
value: Uint8Array.from(ReceiveFromTreasuryAuthorization.encode({}).finish()), | ||
}, | ||
}).finish(), | ||
), | ||
}; | ||
} | ||
|
||
export function createMsgRevoke(operator: string, grantee: string, msgTypeUrl: string): EncodeObject { | ||
return { | ||
typeUrl: "/lbm.foundation.v1.MsgRevoke", | ||
value: Uint8Array.from( | ||
MsgRevoke.encode({ | ||
operator: operator, | ||
grantee: grantee, | ||
msgTypeUrl: msgTypeUrl, | ||
}).finish(), | ||
), | ||
}; | ||
} | ||
|
||
export function createMsgWithdrawFromTreasury( | ||
operator: string, | ||
toAddress: string, | ||
amount: Coin[], | ||
): EncodeObject { | ||
return { | ||
typeUrl: "/lbm.foundation.v1.MsgWithdrawFromTreasury", | ||
value: Uint8Array.from( | ||
MsgWithdrawFromTreasury.encode({ | ||
operator: operator, | ||
to: toAddress, | ||
amount: amount, | ||
}).finish(), | ||
), | ||
}; | ||
} | ||
|
||
export function createMsgUpdateMembers(operator: string, members: Member[]): EncodeObject { | ||
return { | ||
typeUrl: "/lbm.foundation.v1.MsgUpdateMembers", | ||
value: Uint8Array.from( | ||
MsgUpdateMembers.encode({ | ||
operator: operator, | ||
memberUpdates: members, | ||
}).finish(), | ||
), | ||
}; | ||
} | ||
|
||
export function createMsgUpdateDecisionPolicy( | ||
operator: string, | ||
decisionPolicy: ThresholdDecisionPolicyEncodeObject | PercentageDecisionPolicyEncodeObject, | ||
): EncodeObject { | ||
return { | ||
typeUrl: "/lbm.foundation.v1.MsgUpdateDecisionPolicy", | ||
value: Uint8Array.from( | ||
MsgUpdateDecisionPolicy.encode({ | ||
operator: operator, | ||
decisionPolicy: decisionPolicy, | ||
}).finish(), | ||
), | ||
}; | ||
} | ||
|
||
export interface ThresholdDecisionPolicyEncodeObject extends EncodeObject { | ||
readonly typeUrl: "/lbm.foundation.v1.ThresholdDecisionPolicy"; | ||
readonly value: Uint8Array; | ||
} | ||
|
||
export function isThresholdDecisionPolicyEncodeObject( | ||
object: EncodeObject, | ||
): object is ThresholdDecisionPolicyEncodeObject { | ||
return ( | ||
(object as ThresholdDecisionPolicyEncodeObject).typeUrl === "/lbm.foundation.v1.ThresholdDecisionPolicy" | ||
); | ||
} | ||
|
||
export function createThresholdDecisionPolicy( | ||
threshold: string, | ||
votingPeriod = "86400", | ||
minExecutionPeriod = "0", | ||
): ThresholdDecisionPolicyEncodeObject { | ||
return { | ||
typeUrl: "/lbm.foundation.v1.ThresholdDecisionPolicy", | ||
value: Uint8Array.from( | ||
ThresholdDecisionPolicy.encode({ | ||
threshold: Decimal.fromUserInput(threshold, 18).atomics, | ||
windows: { | ||
votingPeriod: Duration.fromPartial({ seconds: longify(votingPeriod) }), | ||
minExecutionPeriod: Duration.fromPartial({ seconds: longify(minExecutionPeriod) }), | ||
}, | ||
}).finish(), | ||
), | ||
}; | ||
} | ||
|
||
export interface PercentageDecisionPolicyEncodeObject extends EncodeObject { | ||
readonly typeUrl: "/lbm.foundation.v1.PercentageDecisionPolicy"; | ||
readonly value: Uint8Array; | ||
} | ||
|
||
export function isPercentageDecisionPolicyEncodeObject( | ||
object: EncodeObject, | ||
): object is PercentageDecisionPolicyEncodeObject { | ||
return ( | ||
(object as PercentageDecisionPolicyEncodeObject).typeUrl === "/lbm.foundation.v1.PercentageDecisionPolicy" | ||
); | ||
} | ||
|
||
export function createPercentageDecisionPolicy( | ||
percentage: string, | ||
votingPeriod = "86400", | ||
minExecutionPeriod = "0", | ||
): PercentageDecisionPolicyEncodeObject { | ||
return { | ||
typeUrl: "/lbm.foundation.v1.PercentageDecisionPolicy", | ||
value: Uint8Array.from( | ||
PercentageDecisionPolicy.encode({ | ||
percentage: Decimal.fromUserInput(percentage, 18).atomics, | ||
windows: { | ||
votingPeriod: Duration.fromPartial({ seconds: longify(votingPeriod) }), | ||
minExecutionPeriod: Duration.fromPartial({ seconds: longify(minExecutionPeriod) }), | ||
}, | ||
}).finish(), | ||
), | ||
}; | ||
} |
Oops, something went wrong.