Skip to content

Commit

Permalink
fix api integ tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yurushao committed Aug 11, 2024
1 parent 3933911 commit 96018eb
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 24 deletions.
4 changes: 3 additions & 1 deletion anchor/src/client/jupiter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,9 @@ export class JupiterClient {
);
const delta = amount - wsolBalance;
if (solBalance < delta) {
throw new Error("Insufficient balance in treasury for swap");
throw new Error(
`Insufficient balance in treasury (${treasuryPda.toBase58()}) for swap. solBalance: ${solBalance}, lamports needed: ${delta}`
);
}
if (delta > 0 && solBalance > delta) {
preInstructions.push(
Expand Down
3 changes: 0 additions & 3 deletions anchor/src/client/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,6 @@ export class StakingClient {
withdrawAuthority
);

console.log("withdrawAuthority:", withdrawAuthority);
console.log("validatorStakeAccounts:", validatorStakeAccounts);

const stakeAccountId = Date.now().toString();
const [stakeAccountPda, bump] = this.getStakeAccountPDA(
fund,
Expand Down
20 changes: 10 additions & 10 deletions anchor/tests/glam_api_tx.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,13 @@ describe("glam_api_tx", () => {
}, 30_000);

it("Natively stake 2 SOL to a validator", async () => {
const response = await fetch(`${API}/tx/stake/deposit`, {
const response = await fetch(`${API}/tx/stake/delegate`, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({
fund,
signer: manager,
validator_vote: "J2nUHEAgZFRyuJbFjdqPrAa9gyWDuc7hErtDQHPhsYRp",
validator_vote: "GJQjnyhSG9jN1AdMHTSyTxUR44hJHEGCmNzkidw9z3y8",
amount: 2_000_000_000,
}),
});
Expand All @@ -212,7 +212,7 @@ describe("glam_api_tx", () => {
});

it("Stake 2 SOL to jito", async () => {
const response = await fetch(`${API}/tx/stakepool/deposit`, {
const response = await fetch(`${API}/tx/stakepool/deposit_sol`, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({
Expand All @@ -236,7 +236,7 @@ describe("glam_api_tx", () => {
});

it("Withdraw 1 jitoSOL to a stake account", async () => {
const response = await fetch(`${API}/tx/stakepool/withdraw`, {
const response = await fetch(`${API}/tx/stakepool/withdraw_stake`, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({
Expand Down Expand Up @@ -317,7 +317,7 @@ describe("glam_api_tx", () => {
});

it("Stake 0.1 SOL to marinade", async () => {
const response = await fetch(`${API}/tx/marinade/stake`, {
const response = await fetch(`${API}/tx/marinade/deposit_sol`, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ manager, fund, amount: 100_000_000 }),
Expand All @@ -336,7 +336,7 @@ describe("glam_api_tx", () => {
}, 30_000);

it("Order unstake #0: 0.01 mSOL", async () => {
const response = await fetch(`${API}/tx/marinade/unstake`, {
const response = await fetch(`${API}/tx/marinade/delayed_unstake`, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ manager, fund, amount: 20_000_000 }),
Expand All @@ -355,7 +355,7 @@ describe("glam_api_tx", () => {
}, 30_000);

it("Order unstake #1: 0.02 mSOL", async () => {
const response = await fetch(`${API}/tx/marinade/unstake`, {
const response = await fetch(`${API}/tx/marinade/delayed_unstake`, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ manager, fund, amount: 10_000_000 }),
Expand All @@ -376,15 +376,15 @@ describe("glam_api_tx", () => {
it("Claim marinade tickets", async () => {
// Before claiming we should have 2 tickets
const { tickets } = await (
await fetch(`${API}/fund/${fund}/tickets`)
await fetch(`${API}/funds/${fund}/tickets`)
).json();
expect(tickets.length).toBe(2);

// Wait for the next epoch
await sleep(30_000);

// Claim tickets
const response = await fetch(`${API}/tx/marinade/unstake/claim`, {
const response = await fetch(`${API}/tx/marinade/claim_tickets`, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ manager, fund, tickets }),
Expand All @@ -403,7 +403,7 @@ describe("glam_api_tx", () => {

// After claiming we should have 0 tickets
const { tickets: _tickets } = await (
await fetch(`${API}/fund/${fund}/tickets`)
await fetch(`${API}/funds/${fund}/tickets`)
).json();
expect(_tickets.length).toBe(0);
}, 35_000);
Expand Down
2 changes: 1 addition & 1 deletion anchor/tests/glam_staking.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe("glam_staking", () => {
try {
const txSig = await glamClient.staking.initializeAndDelegateStake(
fundPDA,
new PublicKey("J2nUHEAgZFRyuJbFjdqPrAa9gyWDuc7hErtDQHPhsYRp"),
new PublicKey("GJQjnyhSG9jN1AdMHTSyTxUR44hJHEGCmNzkidw9z3y8"),
new BN(10_000_000_000)
);
console.log("nativeStakeDeposit tx:", txSig);
Expand Down
22 changes: 13 additions & 9 deletions api/src/routers/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,23 @@ router.post("/tx/jupiter/swap", async (req, res) => {
* Marinade
*/

router.post("/tx/marinade/stake", async (req, res) => {
router.post("/tx/marinade/deposit_sol", async (req, res) => {
const fund = validatePubkey(req.body.fund);
const amount = validateBN(req.body.amount);

if (!fund || !amount) {
return res.status(400).send({ error: "Invalid fund or amount" });
}

const tx = await req.client.marinade.stakeTx(fund, amount, req.apiOptions);
const tx = await req.client.marinade.depositSolTx(
fund,
amount,
req.apiOptions
);
return await serializeTx(tx, res);
});

router.post("/tx/marinade/unstake", async (req, res) => {
router.post("/tx/marinade/delayed_unstake", async (req, res) => {
const fund = validatePubkey(req.body.fund);
const amount = validateBN(req.body.amount);

Expand All @@ -119,7 +123,7 @@ router.post("/tx/marinade/unstake", async (req, res) => {
return await serializeTx(tx, res);
});

router.post("/tx/marinade/unstake/claim", async (req, res) => {
router.post("/tx/marinade/claim_tickets", async (req, res) => {
const fund = validatePubkey(req.body.fund);
if (!fund) {
return res.status(400).send({ error: "Invalid fund" });
Expand All @@ -138,7 +142,7 @@ router.post("/tx/marinade/unstake/claim", async (req, res) => {
return validTicket;
});

const tx = await req.client.marinade.delayedUnstakeClaimTx(
const tx = await req.client.marinade.claimTicketsTx(
fund,
validatedTickets,
req.apiOptions
Expand All @@ -149,7 +153,7 @@ router.post("/tx/marinade/unstake/claim", async (req, res) => {
/*
* Stake pools
*/
router.post("/tx/stakepool/deposit", async (req, res) => {
router.post("/tx/stakepool/deposit_sol", async (req, res) => {
const fund = validatePubkey(req.body.fund);
const stakePool = validatePubkey(req.body.stake_pool);
const amount = validateBN(req.body.amount);
Expand All @@ -169,7 +173,7 @@ router.post("/tx/stakepool/deposit", async (req, res) => {
return await serializeTx(tx, res);
});

router.post("/tx/stakepool/withdraw", async (req, res) => {
router.post("/tx/stakepool/withdraw_stake", async (req, res) => {
const fund = validatePubkey(req.body.fund);
const stakePool = validatePubkey(req.body.stake_pool);
const amount = validateBN(req.body.amount);
Expand All @@ -193,7 +197,7 @@ router.post("/tx/stakepool/withdraw", async (req, res) => {
* Stake program (aka native staking)
*/

router.post("/tx/stake/deposit", async (req, res) => {
router.post("/tx/stake/delegate", async (req, res) => {
const fund = validatePubkey(req.body.fund);
const vote = validatePubkey(req.body.validator_vote);
const amount = validateBN(req.body.amount);
Expand All @@ -204,7 +208,7 @@ router.post("/tx/stake/deposit", async (req, res) => {
.send({ error: "Invalid input of fund, stakePool, or amount" });
}

const tx = await req.client.staking.nativeStakeDepositTx(
const tx = await req.client.staking.initializeAndDelegateStakeTx(
fund,
vote,
amount,
Expand Down

0 comments on commit 96018eb

Please sign in to comment.