Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

fix: adds extra confirming of transactions #187

Merged
merged 2 commits into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .env.development
Original file line number Diff line number Diff line change
@@ -1 +1 @@
REACT_APP_CLUSTER=devnet
REACT_APP_CLUSTER=localnet
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ yarn-debug.log*
yarn-error.log*

.idea/
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
59 changes: 25 additions & 34 deletions src/client/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ export const depositInvestment = multiAsync(
_getCredixPassPDA,
]);

return program.rpc.depositFunds(depositAmount, {
const tx = program.rpc.depositFunds(depositAmount, {
accounts: {
investor: wallet.publicKey,
gatewayToken: gatewayToken.publicKey,
Expand All @@ -385,6 +385,8 @@ export const depositInvestment = multiAsync(
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
},
});

return tx.then((sig) => program.provider.connection.confirmTransaction(sig).then(() => sig));
}
);

Expand Down Expand Up @@ -451,7 +453,7 @@ export const withdrawInvestment = multiAsync(

const withdrawAmount = new BN(amount.toNumber());

return program.rpc.withdrawFunds(withdrawAmount, {
const tx = program.rpc.withdrawFunds(withdrawAmount, {
accounts: {
investor: wallet.publicKey,
gatewayToken: gatewayToken.publicKey,
Expand All @@ -468,6 +470,8 @@ export const withdrawInvestment = multiAsync(
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
},
});

return tx.then((sig) => program.provider.connection.confirmTransaction(sig).then(() => sig));
}
);

Expand Down Expand Up @@ -568,7 +572,7 @@ export const createDeal = multiAsync(
denominator: financingFreeFraction.d * 100,
};

return program.rpc.createDeal(
const tx = program.rpc.createDeal(
dealPDA[1],
borrowerInfoPDA[1],
principalAmount,
Expand All @@ -590,6 +594,8 @@ export const createDeal = multiAsync(
},
}
);

return tx.then((sig) => program.provider.connection.confirmTransaction(sig).then(() => sig));
}
);

Expand Down Expand Up @@ -641,7 +647,7 @@ export const activateDeal = multiAsync(
_getCredixPassPDA,
]);

return program.rpc.activateDeal({
const tx = program.rpc.activateDeal({
accounts: {
owner: wallet.publicKey,
gatewayToken: gatewayToken.publicKey,
Expand All @@ -659,6 +665,8 @@ export const activateDeal = multiAsync(
rent: web3.SYSVAR_RENT_PUBKEY,
},
});

return tx.then((sig) => program.provider.connection.confirmTransaction(sig).then(() => sig));
}
);

Expand Down Expand Up @@ -686,39 +694,16 @@ const getLPTokenPrice = multiAsync(
}
);

const getUserLPTokenAccount = multiAsync(
const getUserLPTokenAmount = multiAsync(
async (connection: Connection, wallet: typeof Wallet, globalMarketSeed: string) => {
const _lpTokenMintPK = getLPTokenMintPK(connection, wallet, globalMarketSeed);
const _investorLPAssociatedTokenAddress = getInvestorLPAssociatedTokenAddress(
const lpAssociatedAddress = await getInvestorLPAssociatedTokenAddress(
connection,
wallet,
globalMarketSeed
);

const [lpTokenMintPK, investorLPAssociatedTokenAddress] = await Promise.all([
_lpTokenMintPK,
_investorLPAssociatedTokenAddress,
]);

const tokenAccounts = await connection.getParsedTokenAccountsByOwner(wallet.publicKey, {
mint: lpTokenMintPK,
});

return tokenAccounts.value.filter((tokenAccount) =>
tokenAccount.pubkey.equals(investorLPAssociatedTokenAddress)
)[0];
}
);

const getUserLPTokenAmount = multiAsync(
async (connection: Connection, wallet: typeof Wallet, globalMarketSeed: string) => {
const userLPTokenAccount = await getUserLPTokenAccount(connection, wallet, globalMarketSeed);

if (!userLPTokenAccount) {
return ZERO;
}

return new Big(Number(userLPTokenAccount.account.data.parsed.info.tokenAmount.amount));
const lpBalance = await connection.getTokenAccountBalance(lpAssociatedAddress);
return new Big(lpBalance.value.amount);
}
);

Expand Down Expand Up @@ -802,7 +787,7 @@ export const repayDeal = multiAsync(
_getCredixPassPDA,
]);

return await program.rpc.makeDealRepayment(repayAmount, repaymentType, {
const tx = program.rpc.makeDealRepayment(repayAmount, repaymentType, {
accounts: {
borrower: wallet.publicKey,
gatewayToken: gatewayToken.publicKey,
Expand All @@ -819,6 +804,8 @@ export const repayDeal = multiAsync(
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
},
});

return tx.then((sig) => program.provider.connection.confirmTransaction(sig).then(() => sig));
}
);

Expand All @@ -839,7 +826,7 @@ export const issueCredixPass = async (
_getCredixPassPDA,
]);

return program.rpc.createCredixPass(credixPassPDA[1], isUnderwriter, isBorrower, {
const tx = program.rpc.createCredixPass(credixPassPDA[1], isUnderwriter, isBorrower, {
accounts: {
owner: wallet.publicKey,
passHolder: publicKey,
Expand All @@ -850,6 +837,8 @@ export const issueCredixPass = async (
},
signers: [],
});

return tx.then((sig) => program.provider.connection.confirmTransaction(sig).then(() => sig));
};

export const updateCredixPass = async (
Expand All @@ -871,7 +860,7 @@ export const updateCredixPass = async (
_getCredixPassPDA,
]);

return program.rpc.updateCredixPass(isActive, isUnderwriter, isBorrower, {
const tx = program.rpc.updateCredixPass(isActive, isUnderwriter, isBorrower, {
accounts: {
owner: wallet.publicKey,
passHolder: publicKey,
Expand All @@ -880,6 +869,8 @@ export const updateCredixPass = async (
},
signers: [],
});

return tx.then((sig) => program.provider.connection.confirmTransaction(sig).then(() => sig));
};

export const getCredixPassInfo = multiAsync(
Expand Down
1 change: 0 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ const getClusterConfig = (): ClusterConfig => {

export const config: Config = ((): Config => {
const clusterConfig = getClusterConfig();
// TODO: see what these options should be
// TODO: make these configurable with environment variables
const confirmOptions: ConfirmOptions = {
commitment: "confirmed",
Expand Down
5 changes: 1 addition & 4 deletions src/react/components/forms/DepositStakeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,7 @@ export const DepositStakeForm = () => {

return (
<div className="deposit-withdraw-row">
<span
className="max-button"
onClick={setMaxAmount}
>
<span className="max-button" onClick={setMaxAmount}>
max
</span>
<form onSubmit={onSubmit} className="row">
Expand Down
5 changes: 1 addition & 4 deletions src/react/components/forms/WithdrawStakeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,7 @@ export const WithdrawStakeForm = () => {

return (
<div className="deposit-withdraw-row">
<span
className="max-button"
onClick={setMaxAmount}
>
<span className="max-button" onClick={setMaxAmount}>
max
</span>
<form onSubmit={onSubmit} className="row">
Expand Down
2 changes: 1 addition & 1 deletion src/types/solana.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export enum SolanaCluster {
export enum RPCEndpoint {
LOCALNET = "http://127.0.0.1:8899",
DEVNET = "https://api.devnet.solana.com",
MAINNET = "https://ssc-dao.genesysgo.net/",
MAINNET = "https://solana-api.projectserum.com",
}

export type PdaSeeds = Array<Buffer | Uint8Array>;
Loading