Skip to content

Commit

Permalink
fix: add post conditions for staking/unstaking USDA (#597)
Browse files Browse the repository at this point in the history
* fix: add post conditions for staking/unstaking USDA

* wip

* wip

* fix: staking PC

* fix: claim pending rewards PCs

---------

Co-authored-by: --global <--global>
  • Loading branch information
philiphacks authored Sep 26, 2024
1 parent 1d6839d commit 35cd8e1
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 33 deletions.
62 changes: 33 additions & 29 deletions web/components/liquidations-reward.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,40 +33,44 @@ export const LiquidationReward: React.FC<LiquidationRewardProps> = ({
const { doContractCall } = useConnect();
const stxAddress = useSTXAddress();
const contractAddress = process.env.REACT_APP_CONTRACT_ADDRESS || '';
const xbtcContractAddress = process.env.XBTC_CONTRACT_ADDRESS || '';
const stStxContractAddress = process.env.STSTX_CONTRACT_ADDRESS || '';

const [state, setState] = useContext(AppContext);

const claim = async () => {
var contract = 'arkadiko-vaults-pool-liq-v1-2';

const postConditions = [];
if (tokenIsStx) {
// PC
postConditions.push(
makeContractSTXPostCondition(
contractAddress,
contract,
FungibleConditionCode.Equal,
uintCV(claimable).value,
)
)
} else {
// FT name
const tokenTraitsKey = Object.keys(tokenTraits).filter((key) =>
(tokenTraits[key].address == token.split('.')[0] && tokenTraits[key].swap == token.split('.')[1])
);
const tokenName = tokenTraits[tokenTraitsKey].ft;

// PC
postConditions.push(
makeContractFungiblePostCondition(
contractAddress,
contract,
FungibleConditionCode.Equal,
uintCV(claimable).value,
createAssetInfo(token.split('.')[0], token.split('.')[1], tokenName)
)
const postConditions = [
makeContractFungiblePostCondition(
contractAddress,
'arkadiko-vaults-pool-liq-v1-2',
FungibleConditionCode.GreaterEqual,
0,
createAssetInfo(contractAddress, 'arkadiko-token', 'diko')
),
makeContractFungiblePostCondition(
contractAddress,
'arkadiko-vaults-pool-liq-v1-2',
FungibleConditionCode.GreaterEqual,
0,
createAssetInfo(contractAddress, 'wstx-token', 'wstx')
),
makeContractFungiblePostCondition(
contractAddress,
'arkadiko-vaults-pool-liq-v1-2',
FungibleConditionCode.GreaterEqual,
0,
createAssetInfo(stStxContractAddress, 'ststx-token', 'ststx')
),
makeContractFungiblePostCondition(
contractAddress,
'arkadiko-vaults-pool-liq-v1-2',
FungibleConditionCode.GreaterEqual,
0,
createAssetInfo(xbtcContractAddress, 'Wrapped-Bitcoin', 'wrapped-bitcoin')
)
}
];

// Call
await doContractCall({
Expand All @@ -78,7 +82,7 @@ export const LiquidationReward: React.FC<LiquidationRewardProps> = ({
functionArgs: [
contractPrincipalCV(token.split('.')[0], token.split('.')[1])
],
postConditionMode: 0x01,
postConditions,
onFinish: data => {
setState(prevState => ({
...prevState,
Expand Down
43 changes: 39 additions & 4 deletions web/components/liquidations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,17 @@ export const Liquidations: React.FC = () => {
const postConditions = [
makeStandardFungiblePostCondition(
stxAddress || '',
FungibleConditionCode.Equal,
uintCV(Number((parseFloat(stakeAmount) * 1000000).toFixed(0))).value,
FungibleConditionCode.LessEqual,
uintCV(Number((parseFloat(stakeAmount) * 1000000 * 1.01).toFixed(0))).value,
createAssetInfo(contractAddress, 'usda-token', 'usda')
),
makeContractFungiblePostCondition(
contractAddress,
'arkadiko-vaults-pool-liq-v1-2',
FungibleConditionCode.GreaterEqual,
0,
createAssetInfo(contractAddress, 'arkadiko-token', 'diko')
),
];

await doContractCall({
Expand All @@ -120,7 +127,7 @@ export const Liquidations: React.FC = () => {
contractPrincipalCV(xbtcContractAddress, 'Wrapped-Bitcoin')
])
],
postConditionMode: 0x01,
postConditions,
onFinish: data => {
setState(prevState => ({
...prevState,
Expand All @@ -141,6 +148,34 @@ export const Liquidations: React.FC = () => {
uintCV(Number((parseFloat(unstakeAmount) * 1000000).toFixed(0))).value,
createAssetInfo(contractAddress, 'usda-token', 'usda')
),
makeContractFungiblePostCondition(
contractAddress,
'arkadiko-vaults-pool-liq-v1-2',
FungibleConditionCode.GreaterEqual,
0,
createAssetInfo(contractAddress, 'arkadiko-token', 'diko')
),
makeContractFungiblePostCondition(
contractAddress,
'arkadiko-vaults-pool-liq-v1-2',
FungibleConditionCode.GreaterEqual,
0,
createAssetInfo(contractAddress, 'wstx-token', 'wstx')
),
makeContractFungiblePostCondition(
contractAddress,
'arkadiko-vaults-pool-liq-v1-2',
FungibleConditionCode.GreaterEqual,
0,
createAssetInfo(stStxContractAddress, 'ststx-token', 'ststx')
),
makeContractFungiblePostCondition(
contractAddress,
'arkadiko-vaults-pool-liq-v1-2',
FungibleConditionCode.GreaterEqual,
0,
createAssetInfo(xbtcContractAddress, 'Wrapped-Bitcoin', 'wrapped-bitcoin')
)
];

await doContractCall({
Expand All @@ -158,7 +193,7 @@ export const Liquidations: React.FC = () => {
contractPrincipalCV(xbtcContractAddress, 'Wrapped-Bitcoin')
])
],
postConditionMode: 0x01,
postConditions,
onFinish: data => {
setState(prevState => ({
...prevState,
Expand Down

0 comments on commit 35cd8e1

Please sign in to comment.