Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4f9b7f9
feature/proof-of-stake
Jan 5, 2024
a774058
Add transcoders for pos txn types
Jan 5, 2024
08826c8
Merge pull request #28 from deso-protocol/pos-txn-types
lazynina Feb 14, 2024
c77a5be
Check in progress on add txn construction
lazynina Jan 22, 2024
819bc0e
Merge pull request #29 from deso-protocol/pos-txn-construction
lazynina Feb 14, 2024
996d9a0
Add types for lockups
lazynina Jan 29, 2024
6d4a6e3
Merge pull request #30 from deso-protocol/lockups-types
lazynina Feb 14, 2024
beddbdd
Add support for lockup txn construction in deso-js
lazynina Jan 29, 2024
e3dabc4
Merge pull request #31 from deso-protocol/lockups-txn-construction
lazynina Feb 14, 2024
ea675d8
Update expiration block height computation
lazynina Feb 12, 2024
d4723fd
Merge pull request #32 from deso-protocol/bump-derived-key-expiration
lazynina Feb 14, 2024
e8467de
Export validator, stake, and lockup files
lazynina Feb 24, 2024
44fa06c
Merge pull request #34 from deso-protocol/fix-exports-for-pos
lazynina Feb 24, 2024
d95521b
fix hex to bytes
jackson-dean Feb 24, 2024
cb62119
fix workflow for publishing from feature branches
jackson-dean Feb 26, 2024
15ab966
Revert "fix workflow for publishing from feature branches"
jackson-dean Feb 26, 2024
37d2084
add strip hex thing
jackson-dean Feb 26, 2024
5253bee
convert stake limit maps back to arrays
jackson-dean Feb 26, 2024
bed60d8
fix hex thing
jackson-dean Feb 27, 2024
2c2d3fe
add hex padding
jackson-dean Feb 27, 2024
5feab6a
remove extra global limit amount
jackson-dean Feb 27, 2024
2040556
Add a deferred wrapper class
jackson-dean May 13, 2024
d7525ed
fix async issue
jackson-dean May 13, 2024
0d0ad9e
Merge branch 'main' into feature/proof-of-stake
jackson-dean May 13, 2024
a6fecc5
remove unneeded newline
jackson-dean Jul 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/backend-types/deso-types-custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,16 @@ export enum TransactionType {
AccessGroup = 'ACCESS_GROUP',
AccessGroupMembers = 'ACCESS_GROUP_MEMBERS',
NewMessage = 'NEW_MESSAGE',
RegisterAsValidator = 'REGISTER_AS_VALIDATOR',
UnregisterAsValidator = 'UNREGISTER_AS_VALIDATOR',
Stake = 'STAKE',
Unstake = 'UNSTAKE',
UnlockStake = 'UNLOCK_STAKE',
UnjailValidator = 'UNJAIL_VALIDATOR',
CoinLockup = 'COIN_LOCKUP',
UpdateCoinLockupParams = 'UPDATE_COIN_LOCKUP_PARAMS',
CoinLockupTransfer = 'COIN_LOCKUP_TRANSFER',
CoinUnlock = 'COIN_UNLOCK',
}

export interface IdentityDeriveParams {
Expand Down
211 changes: 211 additions & 0 deletions src/backend-types/deso-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4616,6 +4616,42 @@ export interface AccessGroupMemberLimitMapItem {
OpCount: number;
}

export type StakeLimitMapItem = {
ValidatorPublicKeyBase58Check: string;
StakeLimit: string; // Hex string
};

export type UnstakeLimitMapItem = {
ValidatorPublicKeyBase58Check: string;
UnstakeLimit: string; // Hex string
};

export type UnlockStakeLimitMapItem = {
ValidatorPublicKeyBase58Check: string;
OpCount: number;
};

export enum LockupLimitScopeType {
ANY = 'AnyCoins',
SCOPED = 'ScopedCoins',
}

export enum LockupLimitOperationString {
ANY = 'Any',
COIN_LOCKUP = 'CoinLockup',
UPDATE_COIN_LOCKUP_YIELD_CURVE = 'UpdateCoinLockupYieldCurve',
UPDATE_COIN_LOCKUP_TRANSFER_RESTRICTIONS = 'UpdateCoinLockupTransferRestrictions',
COIN_LOCKUP_TRANSFER = 'CoinLockupTransferOperationString',
COIN_UNLOCK = 'CoinLockupUnlock',
}

export type LockupLimitMapItem = {
ProfilePublicKeyBase58Check: string;
ScopeType: LockupLimitScopeType;
Operation: LockupLimitOperationString;
OpCount: number;
};

// struct2ts:types/generated/types.TransactionSpendingLimitResponse
export interface TransactionSpendingLimitResponse {
GlobalDESOLimit?: number;
Expand All @@ -4627,6 +4663,10 @@ export interface TransactionSpendingLimitResponse {
AssociationLimitMap?: AssociationLimitMapItem[];
AccessGroupLimitMap?: AccessGroupLimitMapItem[];
AccessGroupMemberLimitMap?: AccessGroupMemberLimitMapItem[];
StakeLimitMap?: StakeLimitMapItem[];
UnstakeLimitMap?: UnstakeLimitMapItem[];
UnlockStakeLimitMap?: UnlockStakeLimitMapItem[];
LockupLimitMap?: LockupLimitMapItem[];
IsUnlimited?: boolean;
}

Expand Down Expand Up @@ -5587,3 +5627,174 @@ export interface GetVideoStatusResponse {
}

export type DiamondLevelString = '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8';

export interface RegisterAsValidatorRequest {
TransactorPublicKeyBase58Check: string;
Domains: string[];
DelegatedStakeCommissionBasisPoints: number;
DisableDelegatedStake: boolean;
VotingPublicKey: string;
VotingAuthorization: string;
ExtraData: Record<string, string>;
MinFeeRateNanosPerKB: number;
TransactionFees: TransactionFee[];
}

export interface UnregisterAsValidatorRequest {
TransactorPublicKeyBase58Check: string;
ExtraData: Record<string, string>;
MinFeeRateNanosPerKB: number;
TransactionFees: TransactionFee[];
}

export interface UnjailValidatorRequest {
TransactorPublicKeyBase58Check: string;
ExtraData: Record<string, string>;
MinFeeRateNanosPerKB: number;
TransactionFees: TransactionFee[];
}

export interface ValidatorTxnResponse {
SpendAmountNanos: number;
TotalInputNanos: number;
ChangeAmountNanos: number;
FeeNanos: number;
Transaction: MsgDeSoTxn;
TransactionHex: string;
TxnHashHex: string;
}

export interface ValidatorResponse {
ValidatorPublicKeyBase58Check: string;
Domains: string[];
DisableDelegatedStake: boolean;
VotingPublicKey: string;
VotingAuthorization: string;
TotalStakeAmountNanos: string; // HEX STRING
Status: string;
LastActiveAtEpochNumber: number;
JailedAtEpochNumber: number;
ExtraData: Record<string, string>;
}

export enum StakeRewardMethod {
PayToBalance = 'PAY_TO_BALANCE',
Restake = 'RESTAKE',
}

export interface StakeRequest {
TransactorPublicKeyBase58Check: string;
ValidatorPublicKeyBase58Check: string;
RewardMethod: StakeRewardMethod;
StakeAmountNanos: string; // HEX STRING
ExtraData: Record<string, string>;
MinFeeRateNanosPerKB: number;
TransactionFees: TransactionFee[];
}

export interface UnstakeRequest {
TransactorPublicKeyBase58Check: string;
ValidatorPublicKeyBase58Check: string;
UnstakeAmountNanos: string; // HEX STRING
ExtraData: Record<string, string>;
MinFeeRateNanosPerKB: number;
TransactionFees: TransactionFee[];
}

export interface UnlockStakeRequest {
TransactorPublicKeyBase58Check: string;
ValidatorPublicKeyBase58Check: string;
StartEpochNumber: number;
EndEpochNumber: number;
ExtraData: Record<string, string>;
MinFeeRateNanosPerKB: number;
TransactionFees: TransactionFee[];
}

export interface StakeTxnResponse {
SpendAmountNanos: number;
TotalInputNanos: number;
ChangeAmountNanos: number;
FeeNanos: number;
Transaction: MsgDeSoTxn;
TransactionHex: string;
TxnHashHex: string;
}

export interface StakeEntryResponse {
StakerPublicKeyBase58Check: string;
ValidatorPublicKeyBase58Check: string;
RewardMethod: StakeRewardMethod;
StakeAmountNanos: string; // HEX string
ExtraData: Record<string, string>;
}

export interface LockedBalanceEntryResponse {
HODLerPublicKeyBase58Check: string;
ProfilePublicKeyBase58Check: string;
UnlockTimestampNanoSecs: number;
VestingEndTimestampNanoSecs: number;
BalanceBaseUnits: string; // HEX string
ProfileEntryResponse?: ProfileEntryResponse;
HODLerProfileEntryResponse?: ProfileEntryResponse;
}

export interface LockupYieldCurvePointResponse {
ProfilePublicKeyBase58Check: string;
LockupDurationNanoSecs: number;
LockupYieldAPYBasisPoints: number;
ProfileEntryResponse?: ProfileEntryResponse;
}

export interface CoinLockupRequest {
TransactorPublicKeyBase58Check: string;
ProfilePublicKeyBase58Check: string;
RecipientPublicKeyBase58Check: string;
UnlockTimestampNanoSecs: number;
VestingEndTimestampNanoSecs: number;
LockupAmountBaseUnits: string; // HEX string
ExtraData: Record<string, string>;
MinFeeRateNanosPerKB: number;
TransactionFees: TransactionFee[];
}

export interface UpdateCoinLockupParamsRequest {
TransactorPublicKeyBase58Check: string;
LockupYieldDurationNanoSecs: number;
LockupYieldAPYBasisPoints: number;
RemoveYieldCurvePoint: boolean;
NewLockupTransferRestrictions: boolean;
LockupTransferRestrictionStatus: string; // TODO: introduce TransferRestrictionStatusString enum and use everywhere.
ExtraData: Record<string, string>;
MinFeeRateNanosPerKB: number;
TransactionFees: TransactionFee[];
}

export interface CoinLockupTransferRequest {
TransactorPublicKeyBase58Check: string;
ProfilePublicKeyBase58Check: string;
RecipientPublicKeyBase58Check: string;
UnlockTimestampNanoSecs: number;
LockedCoinsToTransferBaseUnits: string; // HEX string
ExtraData: Record<string, string>;
MinFeeRateNanosPerKB: number;
TransactionFees: TransactionFee[];
}

export interface CoinUnlockRequest {
TransactorPublicKeyBase58Check: string;
ProfilePublicKeyBase58Check: string;
ExtraData: Record<string, string>;
MinFeeRateNanosPerKB: number;
TransactionFees: TransactionFee[];
}

export interface CoinLockResponse {
SpendAmountNanos: number;
TotalInputNanos: number;
ChangeAmountNanos: number;
FeeNanos: number;
Transaction: MsgDeSoTxn;
TransactionHex: string;
TxnHashHex: string;
}
17 changes: 17 additions & 0 deletions src/identity/crypto-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,23 @@ export const uint64ToBufBigEndian = (uint: number) => {
return new Uint8Array(result.reverse());
};

export const varint64ToBuf = (int: number) => {
let ux = BigInt(int) << BigInt(1);
if (int < 0) {
ux = ~ux;
}
return uvarint64ToBuf(Number(ux));
};

export const bufToVarint64 = (buffer: Uint8Array): [number, Uint8Array] => {
const [ux, n] = bufToUvarint64(buffer);
let x = BigInt(ux) >> BigInt(1);
if (ux & 1) {
x = ~x;
}
return [Number(x), n];
};

interface Base58CheckOptions {
network: Network;
}
Expand Down
4 changes: 2 additions & 2 deletions src/identity/derived-key-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export async function generateDerivedKeyPayload(
) {
const { BlockHeight } = await getAppState();

// days * (24 hours / day) * (60 minutes / hour) * (1 block / 5 minutes) = blocks
// days * (24 hours / day) * (60 minutes / hour) * (60 seconds / minute) * (1 block / 1 second) = blocks
const expirationBlockHeight =
BlockHeight + (numDaysBeforeExpiration * 24 * 60) / 5;
BlockHeight + numDaysBeforeExpiration * 24 * 60 * 60;
const ownerPublicKeyBase58 = publicKeyToBase58Check(ownerKeys.public, {
network,
});
Expand Down
1 change: 1 addition & 0 deletions src/identity/error-types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export enum ERROR_TYPES {
NO_MONEY = 'NO_MONEY',
NO_PENDING_REQUEST = 'NO_PENDING_REQUEST',
IDENTITY_WINDOW_CLOSED = 'IDENTITY_WINDOW_CLOSED',
}
2 changes: 1 addition & 1 deletion src/identity/identity.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ describe('identity', () => {
});
describe('loginWithAutoDerive()', () => {
it('it stores the expected derive data when generating a local derived key payload', async () => {
const expectedExpirationBlock = 1294652;
const expectedExpirationBlock = 315603452;
const expectedDerivePayload = {
derivedPublicKeyBase58Check:
'BC1YLhKdgXgrZ1XkCzbmP6T9bumth2DgPwNjMksCAXe5kGU9LnxQtsX',
Expand Down
Loading