Skip to content

Commit

Permalink
update modular funds hook
Browse files Browse the repository at this point in the history
  • Loading branch information
dangell7 committed May 6, 2024
1 parent 2f0e5d5 commit e985b7f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 26 deletions.
2 changes: 1 addition & 1 deletion contracts/funds/modular/master.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ int64_t hook(uint32_t r)
NOPE("Master: Must provide AMT param when performing refund.");

if (float_compare(sig_amt, xfl_bal, COMPARE_GREATER))
NOPE("Master: Balance not high enough for this debit.");
NOPE("Master: Balance not high enough for this refund.");

// write payment amount
float_sto(OUTAMT, 49, amt + 8, 20, amt + 28, 20, sig_amt, sfAmount);
Expand Down
29 changes: 9 additions & 20 deletions contracts/funds/modular/user.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,20 +210,24 @@ int64_t hook(uint32_t r)

// Operation
uint8_t op;
if (otxn_param(&op, 1, "OP", 2) != 1)
if (otxn_param(&op, 1, "OP", 2) != 1 && tt != ttPAYMENT)
NOPE("User: Missing OP parameter on Invoke.");

// Sub Operation
uint8_t sop;
if ((op == 'W' || op == 'A') && otxn_param(&sop, 1, "SOP", 3) != 1)
NOPE("User: Missing SOP parameter on Invoke.");
NOPE("User: Missing SOP parameter on Withdraw or Asset Operation.");

int64_t xfl_in;
uint32_t flags;
// enforced pausedness
uint8_t paused;
state_foreign(&paused, 1, "P", 1, SBUF(ns), SBUF(master_accid));
if (paused)
NOPE("User: Paused.");

if (tt == ttPAYMENT)
{
// this will fail if flags isn't in the txn, that's also ok.
uint32_t flags;
otxn_field(&flags, 4, sfFlags);

// check for partial payments (0x00020000) -> (0x00000200 LE)
Expand All @@ -232,24 +236,14 @@ int64_t hook(uint32_t r)

otxn_field(SBUF(amt), sfAmount);

xfl_in = slot_float(2);
int64_t xfl_in = slot_float(2);

if (xfl_in < 0 || !float_compare(xfl_in, 0, COMPARE_GREATER))
NOPE("User: Invalid sfAmount.");
}

// enforced pausedness
uint8_t paused;
state_foreign(&paused, 1, "P", 1, SBUF(ns), SBUF(master_accid));
if (paused)
NOPE("User: Paused.");

int64_t is_stl = BUFFER_EQUAL_20(otxn_accid + 12, stl);

// sanity check
if ((op == 'D') && tt != ttPAYMENT)
NOPE("User: Deposit operations must be a payment transaction.");

// permission check
if (!is_stl && (op == 'B'))
NOPE("User: Settler only operation.");
Expand Down Expand Up @@ -376,11 +370,6 @@ int64_t hook(uint32_t r)
}
}

case 'D':
{
DONE("User: Deposited.");
}

// debit
case 'B':
{
Expand Down
5 changes: 0 additions & 5 deletions test/integration/funds/modular.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,16 +302,11 @@ describe('modular - Success Group', () => {
currency: testContext.ic.currency,
value: '100',
}
const otxnParam1 = new iHookParamEntry(
new iHookParamName('OP'),
new iHookParamValue('D')
)
const builtTx: Payment = {
TransactionType: 'Payment',
Account: aliceWallet.classicAddress,
Destination: hookWallet.classicAddress,
Amount: amount,
HookParameters: [otxnParam1.toXrpl()],
}
const result = await Xrpld.submit(testContext.client, {
wallet: aliceWallet,
Expand Down

0 comments on commit e985b7f

Please sign in to comment.