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.
implement with mint with mercurial vault (#145)
- Loading branch information
1 parent
b3147a3
commit c7681b9
Showing
7 changed files
with
226 additions
and
8 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
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
101 changes: 101 additions & 0 deletions
101
pages/dao/[symbol]/proposal/components/instructions/UXD/MintWithMercurialVaultDepository.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,101 @@ | ||
import * as yup from 'yup'; | ||
import Select from '@components/inputs/Select'; | ||
import useInstructionFormBuilder from '@hooks/useInstructionFormBuilder'; | ||
import { getDepositoryMintSymbols } from '@tools/sdk/uxdProtocol/uxdClient'; | ||
import { GovernedMultiTypeAccount } from '@utils/tokens'; | ||
import { UXDMintWithMercurialVaultDepositoryForm } from '@utils/uiTypes/proposalCreationTypes'; | ||
import SelectOptionList from '../../SelectOptionList'; | ||
import Input from '@components/inputs/Input'; | ||
import { PublicKey } from '@solana/web3.js'; | ||
import createMintWithMercurialVaultDepositoryInstruction from '@tools/sdk/uxdProtocol/createMintWithMercurialVaultDepositoryInstruction'; | ||
|
||
const schema = yup.object().shape({ | ||
governedAccount: yup | ||
.object() | ||
.nullable() | ||
.required('Governance account is required'), | ||
uxdProgram: yup.string().required('UXD Program address is required'), | ||
collateralName: yup.string().required('Collateral Name address is required'), | ||
uiCollateralAmount: yup | ||
.number() | ||
.moreThan(0, 'Collateral amount should be more than 0') | ||
.required('Collateral Amount is required'), | ||
}); | ||
|
||
const UXDMintWithMercurialVaultDepository = ({ | ||
index, | ||
governedAccount, | ||
}: { | ||
index: number; | ||
governedAccount?: GovernedMultiTypeAccount; | ||
}) => { | ||
const { | ||
connection, | ||
form, | ||
formErrors, | ||
handleSetForm, | ||
} = useInstructionFormBuilder<UXDMintWithMercurialVaultDepositoryForm>({ | ||
index, | ||
initialFormValues: { | ||
governedAccount, | ||
}, | ||
schema, | ||
shouldSplitIntoSeparateTxs: true, | ||
buildInstruction: async function ({ form, governedAccountPubkey, wallet }) { | ||
return createMintWithMercurialVaultDepositoryInstruction({ | ||
connection, | ||
uxdProgramId: new PublicKey(form.uxdProgram!), | ||
authority: governedAccountPubkey, | ||
depositoryMintName: form.collateralName!, | ||
collateralAmount: form.uiCollateralAmount!, | ||
payer: wallet.publicKey!, | ||
}); | ||
}, | ||
}); | ||
|
||
return ( | ||
<> | ||
<Input | ||
label="UXD Program" | ||
value={form.uxdProgram} | ||
type="string" | ||
onChange={(evt) => | ||
handleSetForm({ | ||
value: evt.target.value, | ||
propertyName: 'uxdProgram', | ||
}) | ||
} | ||
error={formErrors['uxdProgram']} | ||
/> | ||
|
||
<Select | ||
label="Collateral Name" | ||
value={form.collateralName} | ||
placeholder="Please select..." | ||
onChange={(value) => | ||
handleSetForm({ value, propertyName: 'collateralName' }) | ||
} | ||
error={formErrors['collateralName']} | ||
> | ||
<SelectOptionList list={getDepositoryMintSymbols(connection.cluster)} /> | ||
</Select> | ||
|
||
<Input | ||
label="Collateral Amount" | ||
value={form.uiCollateralAmount} | ||
type="number" | ||
min={0} | ||
max={10 ** 12} | ||
onChange={(evt) => | ||
handleSetForm({ | ||
value: evt.target.value, | ||
propertyName: 'uiCollateralAmount', | ||
}) | ||
} | ||
error={formErrors['uiCollateralAmount']} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
export default UXDMintWithMercurialVaultDepository; |
54 changes: 54 additions & 0 deletions
54
tools/sdk/uxdProtocol/createMintWithMercurialVaultDepositoryInstruction.ts
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,54 @@ | ||
import { Provider } from '@project-serum/anchor'; | ||
import { TransactionInstruction, PublicKey } from '@solana/web3.js'; | ||
import { | ||
Controller, | ||
MercurialVaultDepository, | ||
UXD_DECIMALS, | ||
} from '@uxd-protocol/uxd-client'; | ||
import type { ConnectionContext } from 'utils/connection'; | ||
import { uxdClient, getDepositoryMintInfo } from './uxdClient'; | ||
|
||
const createMintWithMercurialVaultDepositoryInstruction = async ({ | ||
connection, | ||
uxdProgramId, | ||
authority, | ||
depositoryMintName, | ||
collateralAmount, | ||
payer, | ||
}: { | ||
connection: ConnectionContext; | ||
uxdProgramId: PublicKey; | ||
authority: PublicKey; | ||
depositoryMintName: string; | ||
collateralAmount: number; | ||
payer: PublicKey; | ||
}): Promise<TransactionInstruction> => { | ||
const { | ||
address: collateralMint, | ||
decimals: collateralDecimals, | ||
} = getDepositoryMintInfo(connection.cluster, depositoryMintName); | ||
|
||
const client = uxdClient(uxdProgramId); | ||
|
||
const depository = await MercurialVaultDepository.initialize({ | ||
connection: connection.current, | ||
collateralMint: { | ||
mint: collateralMint, | ||
name: depositoryMintName, | ||
symbol: depositoryMintName, | ||
decimals: collateralDecimals, | ||
}, | ||
uxdProgramId, | ||
}); | ||
|
||
return client.createMintWithMercurialVaultDepositoryInstruction( | ||
new Controller('UXD', UXD_DECIMALS, uxdProgramId), | ||
depository, | ||
authority, | ||
collateralAmount, | ||
Provider.defaultOptions(), | ||
payer, | ||
); | ||
}; | ||
|
||
export default createMintWithMercurialVaultDepositoryInstruction; |
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
c7681b9
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.uxd.fi
governance-ui-one.vercel.app
governance-ui-uxdprotocol.vercel.app
governance-ui-git-main-uxdprotocol.vercel.app