Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LockerV3: add batch vesting escrow lock creation #25

Closed
wants to merge 36 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
8a16c92
v3: batch vesting escrow
docongminh Jan 9, 2025
f883eab
merkle tree
docongminh Jan 9, 2025
0bcec0e
unittest for batch vesting escrow
docongminh Jan 9, 2025
55074e7
add close escrow vesting
docongminh Jan 9, 2025
a71b6e1
assertion validate claim status state
docongminh Jan 9, 2025
bd5374c
use safe math
docongminh Jan 10, 2025
dea637f
add cancel_mode
docongminh Jan 10, 2025
d4dc50b
update build node
docongminh Jan 10, 2025
01eede9
payer create claim status
docongminh Jan 10, 2025
3edc422
add creator cancel escrow
docongminh Jan 10, 2025
61c4ac3
update node for root
docongminh Jan 10, 2025
4cd0f8f
update node for root
docongminh Jan 10, 2025
d60910f
update unit test
docongminh Jan 10, 2025
57469a1
fix be_bytes()
docongminh Jan 10, 2025
53a51ca
add vestingStartTime to node
docongminh Jan 10, 2025
877358c
remove init if needed
docongminh Jan 10, 2025
752672f
remove init if needed
docongminh Jan 10, 2025
28fe042
add validate node data
docongminh Jan 10, 2025
e4a0eac
clean code
docongminh Jan 10, 2025
7001eba
removed mutable for unnecessary
docongminh Jan 11, 2025
1b64a24
uncheck token account
docongminh Jan 11, 2025
3a7e075
immutable signer
docongminh Jan 11, 2025
c11ab0b
add more testcase
docongminh Jan 11, 2025
8d123f3
clean coding convention
docongminh Jan 11, 2025
bdbafeb
add buffer for claim_status
docongminh Jan 11, 2025
d018d7f
add padding fields
docongminh Jan 11, 2025
27fddb4
set recipient email is empty
docongminh Jan 11, 2025
d32641b
add close claim status instruction
docongminh Jan 11, 2025
4969c1b
rename variable
docongminh Jan 11, 2025
ef05e8d
validate node data
docongminh Jan 12, 2025
96b4ee8
add rent_receiver
docongminh Jan 13, 2025
dc31f66
add comment
docongminh Jan 13, 2025
dda602f
remove close escrow instruction
docongminh Jan 14, 2025
627b234
update logic fill claim status data
docongminh Jan 19, 2025
1e7d01e
use recipient endpoint for v1 v2
docongminh Jan 19, 2025
a11684e
remove create metadata v3
docongminh Jan 20, 2025
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
Prev Previous commit
Next Next commit
add vestingStartTime to node
docongminh committed Jan 10, 2025
commit 53a51ca66ada8f36c9e8a541d0016c64a066eeef
3 changes: 2 additions & 1 deletion programs/locker/src/instructions/v3/claim.rs
Original file line number Diff line number Diff line change
@@ -39,7 +39,8 @@ impl ClaimV3Params {
&self.amount_per_period.to_le_bytes(),
&self.number_of_period.to_le_bytes(),
&self.cliff_time.to_le_bytes(),
&self.frequency.to_le_bytes()
&self.frequency.to_le_bytes(),
&self.vesting_start_time.to_le_bytes()
]);

let leaf = hashv(&[LEAF_PREFIX, &node.to_bytes()]);
15 changes: 11 additions & 4 deletions tests/locker_utils/merkle_tree/EscrowRecipientTree.ts
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ export class EscrowRecipientTree {
numberOfPeriod: BN;
cliffTime: BN;
frequency: BN;
vestingStartTime: BN;
}[]
) {
this._tree = new MerkleTree(
@@ -24,6 +25,7 @@ export class EscrowRecipientTree {
numberOfPeriod,
cliffTime,
frequency,
vestingStartTime
},
index
) => {
@@ -33,7 +35,8 @@ export class EscrowRecipientTree {
amountPerPeriod,
numberOfPeriod,
cliffTime,
frequency
frequency,
vestingStartTime
);
}
)
@@ -47,7 +50,8 @@ export class EscrowRecipientTree {
amountPerPeriod: BN,
numberOfPeriod: BN,
cliffTime: BN,
frequency: BN
frequency: BN,
vestingStartTime: BN
): Buffer {
const buf = Buffer.concat([
account.toBuffer(),
@@ -56,6 +60,7 @@ export class EscrowRecipientTree {
new BN(numberOfPeriod).toArrayLike(Buffer, "le", 8),
new BN(cliffTime).toArrayLike(Buffer, "le", 8),
new BN(frequency).toArrayLike(Buffer, "le", 8),
new BN(vestingStartTime).toArrayLike(Buffer, "le", 8),
]);

const hashedBuff = Buffer.from(sha256(buf), "hex");
@@ -74,7 +79,8 @@ export class EscrowRecipientTree {
amountPerPeriod: BN,
numberOfPeriod: BN,
cliffTime: BN,
frequency: BN
frequency: BN,
vestingStartTime: BN
): Buffer[] {
return this._tree.getProof(
EscrowRecipientTree.toNode(
@@ -83,7 +89,8 @@ export class EscrowRecipientTree {
amountPerPeriod,
numberOfPeriod,
cliffTime,
frequency
frequency,
vestingStartTime
)
);
}
7 changes: 6 additions & 1 deletion tests/locker_utils/merkle_tree/index.ts
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ export function generateMerkleTreeRoot(
numberOfPeriod: BN;
cliffTime: BN;
frequency: BN;
vestingStartTime: BN
}[]
): number[] {
const escrowRecipientTree = new EscrowRecipientTree(data);
@@ -23,6 +24,7 @@ export function getMerkleTreeProof(
numberOfPeriod: BN;
cliffTime: BN;
frequency: BN;
vestingStartTime: BN;
}[],
user: {
account: web3.PublicKey;
@@ -31,6 +33,7 @@ export function getMerkleTreeProof(
numberOfPeriod: BN;
cliffTime: BN;
frequency: BN;
vestingStartTime: BN;
}
) {
const {
@@ -40,6 +43,7 @@ export function getMerkleTreeProof(
numberOfPeriod,
cliffTime,
frequency,
vestingStartTime
} = user;
const escrowRecipientTree = new EscrowRecipientTree(data);
return escrowRecipientTree.getProof(
@@ -48,6 +52,7 @@ export function getMerkleTreeProof(
amountPerPeriod,
numberOfPeriod,
cliffTime,
frequency
frequency,
vestingStartTime
);
}
6 changes: 4 additions & 2 deletions tests/v3/test_cancel.ts
Original file line number Diff line number Diff line change
@@ -112,7 +112,8 @@ describe("[V3] Cancel escrow", () => {
amountPerPeriod,
numberOfPeriod,
cliffTime,
frequency
frequency,
vestingStartTime
};
});
const user = {
@@ -121,7 +122,8 @@ describe("[V3] Cancel escrow", () => {
amountPerPeriod,
numberOfPeriod,
cliffTime,
frequency
frequency,
vestingStartTime
};
totalDepositAmount = totalLockedAmount.muln(leaves.length);
root = generateMerkleTreeRoot(leaves);
24 changes: 16 additions & 8 deletions tests/v3/test_close_vesting_escrow.ts
Original file line number Diff line number Diff line change
@@ -145,7 +145,8 @@ describe("[V3] Close vesting escrow", () => {
amountPerPeriod,
numberOfPeriod,
cliffTime,
frequency
frequency,
vestingStartTime
};
});
const user = {
@@ -154,7 +155,8 @@ describe("[V3] Close vesting escrow", () => {
amountPerPeriod,
numberOfPeriod,
cliffTime,
frequency
frequency,
vestingStartTime
};
totalDepositAmount = totalLockedAmount.muln(leaves.length);
root = generateMerkleTreeRoot(leaves);
@@ -208,7 +210,8 @@ describe("[V3] Close vesting escrow", () => {
amountPerPeriod,
numberOfPeriod,
cliffTime,
frequency
frequency,
vestingStartTime
};
const recipientProof = getMerkleTreeProof(leaves, recipientNode);

@@ -277,7 +280,8 @@ describe("[V3] Close vesting escrow", () => {
amountPerPeriod,
numberOfPeriod,
cliffTime,
frequency
frequency,
vestingStartTime
};
const recipientProof = getMerkleTreeProof(leaves, recipientNode);

@@ -372,7 +376,8 @@ describe("[V3] Close vesting escrow", () => {
amountPerPeriod,
numberOfPeriod,
cliffTime,
frequency
frequency,
vestingStartTime
};
});
const user = {
@@ -381,7 +386,8 @@ describe("[V3] Close vesting escrow", () => {
amountPerPeriod,
numberOfPeriod,
cliffTime,
frequency
frequency,
vestingStartTime
};
totalDepositAmount = totalLockedAmount.muln(leaves.length);
root = generateMerkleTreeRoot(leaves);
@@ -435,7 +441,8 @@ describe("[V3] Close vesting escrow", () => {
amountPerPeriod,
numberOfPeriod,
cliffTime,
frequency
frequency,
vestingStartTime
};
const recipientProof = getMerkleTreeProof(leaves, recipientNode);
try {
@@ -504,7 +511,8 @@ describe("[V3] Close vesting escrow", () => {
amountPerPeriod,
numberOfPeriod,
cliffTime,
frequency
frequency,
vestingStartTime
};
const recipientProof = getMerkleTreeProof(leaves, recipientNode);
try {
4 changes: 4 additions & 0 deletions tests/v3/test_create_lock_spl_token.ts
Original file line number Diff line number Diff line change
@@ -148,6 +148,7 @@ describe("[V3] Create vesting with spl token", () => {
numberOfPeriod,
cliffTime,
frequency,
vestingStartTime
};
});
const user = {
@@ -157,6 +158,7 @@ describe("[V3] Create vesting with spl token", () => {
numberOfPeriod,
cliffTime,
frequency,
vestingStartTime
};
totalDepositAmount = totalLockedAmount.muln(leaves.length);
root = generateMerkleTreeRoot(leaves);
@@ -239,6 +241,7 @@ describe("[V3] Create vesting with spl token", () => {
numberOfPeriod,
cliffTime,
frequency,
vestingStartTime
};
const recipientProof = getMerkleTreeProof(leaves, recipientNode);
try {
@@ -302,6 +305,7 @@ describe("[V3] Create vesting with spl token", () => {
numberOfPeriod,
cliffTime,
frequency,
vestingStartTime
};
const newRecipientProof = getMerkleTreeProof(leaves, recipientNode);

4 changes: 4 additions & 0 deletions tests/v3/test_create_lock_token2022.ts
Original file line number Diff line number Diff line change
@@ -101,6 +101,7 @@ describe("[V3] Create vesting with Token2022", () => {
numberOfPeriod,
cliffTime,
frequency,
vestingStartTime
};
});
const user = {
@@ -110,6 +111,7 @@ describe("[V3] Create vesting with Token2022", () => {
numberOfPeriod,
cliffTime,
frequency,
vestingStartTime
};
totalDepositAmount = totalLockedAmount.muln(leaves.length);
root = generateMerkleTreeRoot(leaves);
@@ -182,6 +184,7 @@ describe("[V3] Create vesting with Token2022", () => {
numberOfPeriod,
cliffTime,
frequency,
vestingStartTime
};
const recipientProof = getMerkleTreeProof(leaves, recipientNode);
try {
@@ -245,6 +248,7 @@ describe("[V3] Create vesting with Token2022", () => {
numberOfPeriod,
cliffTime,
frequency,
vestingStartTime
};
const newRecipientProof = getMerkleTreeProof(leaves, recipientNode);

6 changes: 4 additions & 2 deletions tests/v3/test_escrow_metadata.ts
Original file line number Diff line number Diff line change
@@ -132,7 +132,8 @@ describe("[V3] Create vesting metadata", () => {
amountPerPeriod,
numberOfPeriod,
cliffTime,
frequency
frequency,
vestingStartTime
};
});
const user = {
@@ -141,7 +142,8 @@ describe("[V3] Create vesting metadata", () => {
amountPerPeriod,
numberOfPeriod,
cliffTime,
frequency
frequency,
vestingStartTime
};
totalDepositAmount = totalLockedAmount.muln(leaves.length);
root = generateMerkleTreeRoot(leaves);