forked from solana-labs/governance-ui
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
11 changed files
with
418 additions
and
5 deletions.
There are no files selected for viewing
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,91 @@ | ||
import { struct, u8, nu64 } from 'buffer-layout'; | ||
import { AccountMetaData } from '@solana/spl-governance'; | ||
import { Connection } from '@solana/web3.js'; | ||
import { CredixConfiguration } from '@tools/sdk/credix/configuration'; | ||
import { ANCHOR_DISCRIMINATOR_LAYOUT } from '@utils/helpers'; | ||
import { nativeBNToUiAmount } from '@tools/sdk/units'; | ||
import { USDC_DECIMALS } from '@uxd-protocol/uxd-client'; | ||
import { BN } from '@project-serum/anchor'; | ||
|
||
export const CREDIX_PROGRAM_INSTRUCTIONS = { | ||
[CredixConfiguration.credixProgramId.toBase58()]: { | ||
[CredixConfiguration.instructionsCode.deposit]: { | ||
name: 'Credix - Deposit USDC', | ||
accounts: [ | ||
'Investor', | ||
'Gateway Token', | ||
'Global Market State', | ||
'Signing Authority', | ||
'Investor Token Account', | ||
'Liquidity Pool Token Account', | ||
'LP Token Mint', | ||
'Investor Lp Token Account', | ||
'Credix Pass', | ||
'Base Token Mint', | ||
'Associated Token Program', | ||
'Rent', | ||
'Token Program', | ||
'System Program', | ||
], | ||
getDataUI: async ( | ||
_connection: Connection, | ||
data: Uint8Array, | ||
_accounts: AccountMetaData[], | ||
) => { | ||
const dataLayout = struct([ | ||
u8('instruction'), | ||
...ANCHOR_DISCRIMINATOR_LAYOUT, | ||
nu64('amount'), | ||
]); | ||
|
||
const { amount } = dataLayout.decode(Buffer.from(data)) as any; | ||
|
||
const uiAmount = nativeBNToUiAmount(new BN(amount), USDC_DECIMALS); | ||
|
||
return <p>{`USDC Amount: ${uiAmount.toString()}`}</p>; | ||
}, | ||
}, | ||
[CredixConfiguration.instructionsCode.withdraw]: { | ||
name: 'Credix - Withdraw USDC', | ||
accounts: [ | ||
'Investor', | ||
'Gateway Token', | ||
'Global Market State', | ||
'Signing Authority', | ||
'Investor Lp Token Account', | ||
'Investor Token Account', | ||
'Liquidity Pool Token Account', | ||
'Treasury Pool Token Account', | ||
'LP TokenMint', | ||
'Credix Pass', | ||
'Base Token Mint', | ||
'Associated Token Program', | ||
'Token Program', | ||
], | ||
getDataUI: async ( | ||
_connection: Connection, | ||
data: Uint8Array, | ||
_accounts: AccountMetaData[], | ||
) => { | ||
const dataLayout = struct([ | ||
u8('instruction'), | ||
...ANCHOR_DISCRIMINATOR_LAYOUT, | ||
nu64('baseWithdrawalAmount'), | ||
]); | ||
|
||
const { baseWithdrawalAmount } = dataLayout.decode( | ||
Buffer.from(data), | ||
) as any; | ||
|
||
const uiBaseWithdrawalAmount = nativeBNToUiAmount( | ||
new BN(baseWithdrawalAmount), | ||
USDC_DECIMALS, | ||
); | ||
|
||
return ( | ||
<p>{`Base USDC Withdrawal Amount: ${uiBaseWithdrawalAmount.toString()}`}</p> | ||
); | ||
}, | ||
}, | ||
}, | ||
}; |
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
96 changes: 96 additions & 0 deletions
96
pages/dao/[symbol]/proposal/components/instructions/Credix/Deposit.tsx
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,96 @@ | ||
import * as yup from 'yup'; | ||
import useInstructionFormBuilder from '@hooks/useInstructionFormBuilder'; | ||
import credixConfiguration from '@tools/sdk/credix/configuration'; | ||
import { GovernedMultiTypeAccount, tryGetMint } from '@utils/tokens'; | ||
import { CredixDepositForm } from '@utils/uiTypes/proposalCreationTypes'; | ||
import Input from '@components/inputs/Input'; | ||
import { uiAmountToNativeBN } from '@tools/sdk/units'; | ||
|
||
const schema = yup.object().shape({ | ||
governedAccount: yup | ||
.object() | ||
.nullable() | ||
.required('Governed account is required'), | ||
uiAmount: yup | ||
.number() | ||
.typeError('Amount has to be a number') | ||
.required('Amount is required'), | ||
}); | ||
|
||
const CredixDeposit = ({ | ||
index, | ||
governedAccount, | ||
}: { | ||
index: number; | ||
governedAccount?: GovernedMultiTypeAccount; | ||
}) => { | ||
const { | ||
form, | ||
handleSetForm, | ||
formErrors, | ||
} = useInstructionFormBuilder<CredixDepositForm>({ | ||
index, | ||
initialFormValues: { | ||
governedAccount, | ||
}, | ||
schema, | ||
buildInstruction: async function ({ | ||
cluster, | ||
governedAccountPubkey, | ||
form, | ||
connection, | ||
wallet, | ||
}) { | ||
if (cluster !== 'mainnet') { | ||
throw new Error('Other cluster than mainnet are not supported yet.'); | ||
} | ||
|
||
const client = credixConfiguration.getClient({ | ||
connection, | ||
wallet: (wallet as unknown) as any, | ||
}); | ||
|
||
// the market for which we want to deposit in the liquidity pool | ||
const market = await client.fetchMarket('credix-marketplace'); | ||
|
||
if (!market) { | ||
throw new Error( | ||
'Cannot load market information about credix-marketplace', | ||
); | ||
} | ||
|
||
const marketMintInfo = await tryGetMint(connection, market.baseMintPK); | ||
|
||
if (!marketMintInfo) { | ||
throw new Error( | ||
'Cannot load information about credix market base mint', | ||
); | ||
} | ||
|
||
const amount = uiAmountToNativeBN( | ||
form.uiAmount!, | ||
marketMintInfo.account.decimals, | ||
); | ||
|
||
return market.depositIx(amount.toNumber(), governedAccountPubkey); | ||
}, | ||
}); | ||
|
||
return ( | ||
<Input | ||
min={0} | ||
label="USDC Amount" | ||
value={form.uiAmount} | ||
type="number" | ||
onChange={(evt) => { | ||
handleSetForm({ | ||
value: evt.target.value, | ||
propertyName: 'uiAmount', | ||
}); | ||
}} | ||
error={formErrors['uiAmount']} | ||
/> | ||
); | ||
}; | ||
|
||
export default CredixDeposit; |
96 changes: 96 additions & 0 deletions
96
pages/dao/[symbol]/proposal/components/instructions/Credix/Withdraw.tsx
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,96 @@ | ||
import * as yup from 'yup'; | ||
import useInstructionFormBuilder from '@hooks/useInstructionFormBuilder'; | ||
import credixConfiguration from '@tools/sdk/credix/configuration'; | ||
import { GovernedMultiTypeAccount, tryGetMint } from '@utils/tokens'; | ||
import { CredixWithdrawForm } from '@utils/uiTypes/proposalCreationTypes'; | ||
import Input from '@components/inputs/Input'; | ||
import { uiAmountToNativeBN } from '@tools/sdk/units'; | ||
|
||
const schema = yup.object().shape({ | ||
governedAccount: yup | ||
.object() | ||
.nullable() | ||
.required('Governed account is required'), | ||
uiAmount: yup | ||
.number() | ||
.typeError('Amount has to be a number') | ||
.required('Amount is required'), | ||
}); | ||
|
||
const CredixWithdraw = ({ | ||
index, | ||
governedAccount, | ||
}: { | ||
index: number; | ||
governedAccount?: GovernedMultiTypeAccount; | ||
}) => { | ||
const { | ||
form, | ||
handleSetForm, | ||
formErrors, | ||
} = useInstructionFormBuilder<CredixWithdrawForm>({ | ||
index, | ||
initialFormValues: { | ||
governedAccount, | ||
}, | ||
schema, | ||
buildInstruction: async function ({ | ||
cluster, | ||
governedAccountPubkey, | ||
form, | ||
connection, | ||
wallet, | ||
}) { | ||
if (cluster !== 'mainnet') { | ||
throw new Error('Other cluster than mainnet are not supported yet.'); | ||
} | ||
|
||
const client = credixConfiguration.getClient({ | ||
connection, | ||
wallet: (wallet as unknown) as any, | ||
}); | ||
|
||
// the market for which we want to deposit in the liquidity pool | ||
const market = await client.fetchMarket('credix-marketplace'); | ||
|
||
if (!market) { | ||
throw new Error( | ||
'Cannot load market information about credix-marketplace', | ||
); | ||
} | ||
|
||
const marketMintInfo = await tryGetMint(connection, market.baseMintPK); | ||
|
||
if (!marketMintInfo) { | ||
throw new Error( | ||
'Cannot load information about credix market base mint', | ||
); | ||
} | ||
|
||
const amount = uiAmountToNativeBN( | ||
form.uiAmount!, | ||
marketMintInfo.account.decimals, | ||
); | ||
|
||
return market.withdrawIx(amount.toNumber(), governedAccountPubkey); | ||
}, | ||
}); | ||
|
||
return ( | ||
<Input | ||
min={0} | ||
label="USDC Amount" | ||
value={form.uiAmount} | ||
type="number" | ||
onChange={(evt) => { | ||
handleSetForm({ | ||
value: evt.target.value, | ||
propertyName: 'uiAmount', | ||
}); | ||
}} | ||
error={formErrors['uiAmount']} | ||
/> | ||
); | ||
}; | ||
|
||
export default CredixWithdraw; |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,28 @@ | ||
import { CredixClient } from '@credix/credix-client'; | ||
import { Wallet } from '@marinade.finance/marinade-ts-sdk'; | ||
import { Connection, PublicKey } from '@solana/web3.js'; | ||
|
||
export class CredixConfiguration { | ||
public static readonly credixProgramId = new PublicKey( | ||
'CRDx2YkdtYtGZXGHZ59wNv1EwKHQndnRc1gT4p8i2vPX', | ||
); | ||
|
||
public static readonly instructionsCode = { | ||
deposit: 202, | ||
withdraw: 241, | ||
}; | ||
|
||
public getClient({ | ||
connection, | ||
wallet, | ||
}: { | ||
connection: Connection; | ||
wallet: Wallet; | ||
}): CredixClient { | ||
return new CredixClient(connection, wallet, { | ||
programId: CredixConfiguration.credixProgramId, | ||
}); | ||
} | ||
} | ||
|
||
export default new CredixConfiguration(); |
Oops, something went wrong.
7654460
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
governance-ui – ./
governance-ui-uxdprotocol.vercel.app
governance-ui-one.vercel.app
governance.uxd.fi
governance-ui-git-main-uxdprotocol.vercel.app